Committed by
Gerrit Code Review
Add configurable method to SimpleFlowRuleStore
- Add @Modified annotation - Delete TODO annotation Change-Id: Ida2855c23105f68cfa2f2b7bb4ec3f384a2de838
Showing
2 changed files
with
58 additions
and
16 deletions
... | @@ -27,8 +27,11 @@ import com.google.common.util.concurrent.SettableFuture; | ... | @@ -27,8 +27,11 @@ import com.google.common.util.concurrent.SettableFuture; |
27 | import org.apache.felix.scr.annotations.Activate; | 27 | import org.apache.felix.scr.annotations.Activate; |
28 | import org.apache.felix.scr.annotations.Component; | 28 | import org.apache.felix.scr.annotations.Component; |
29 | import org.apache.felix.scr.annotations.Deactivate; | 29 | import org.apache.felix.scr.annotations.Deactivate; |
30 | +import org.apache.felix.scr.annotations.Modified; | ||
31 | +import org.apache.felix.scr.annotations.Property; | ||
30 | import org.apache.felix.scr.annotations.Service; | 32 | import org.apache.felix.scr.annotations.Service; |
31 | import org.onlab.util.NewConcurrentHashMap; | 33 | import org.onlab.util.NewConcurrentHashMap; |
34 | +import org.onlab.util.Tools; | ||
32 | import org.onosproject.net.DeviceId; | 35 | import org.onosproject.net.DeviceId; |
33 | import org.onosproject.net.flow.CompletedBatchOperation; | 36 | import org.onosproject.net.flow.CompletedBatchOperation; |
34 | import org.onosproject.net.flow.DefaultFlowEntry; | 37 | import org.onosproject.net.flow.DefaultFlowEntry; |
... | @@ -48,10 +51,12 @@ import org.onosproject.net.flow.FlowRuleStoreDelegate; | ... | @@ -48,10 +51,12 @@ import org.onosproject.net.flow.FlowRuleStoreDelegate; |
48 | import org.onosproject.net.flow.StoredFlowEntry; | 51 | import org.onosproject.net.flow.StoredFlowEntry; |
49 | import org.onosproject.net.flow.TableStatisticsEntry; | 52 | import org.onosproject.net.flow.TableStatisticsEntry; |
50 | import org.onosproject.store.AbstractStore; | 53 | import org.onosproject.store.AbstractStore; |
54 | +import org.osgi.service.component.ComponentContext; | ||
51 | import org.slf4j.Logger; | 55 | import org.slf4j.Logger; |
52 | 56 | ||
53 | import java.util.ArrayList; | 57 | import java.util.ArrayList; |
54 | import java.util.Collections; | 58 | import java.util.Collections; |
59 | +import java.util.Dictionary; | ||
55 | import java.util.List; | 60 | import java.util.List; |
56 | import java.util.concurrent.ConcurrentHashMap; | 61 | import java.util.concurrent.ConcurrentHashMap; |
57 | import java.util.concurrent.ConcurrentMap; | 62 | import java.util.concurrent.ConcurrentMap; |
... | @@ -87,8 +92,10 @@ public class SimpleFlowRuleStore | ... | @@ -87,8 +92,10 @@ public class SimpleFlowRuleStore |
87 | 92 | ||
88 | private final AtomicInteger localBatchIdGen = new AtomicInteger(); | 93 | private final AtomicInteger localBatchIdGen = new AtomicInteger(); |
89 | 94 | ||
90 | - // TODO: make this configurable | 95 | + private static final int DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES = 5; |
91 | - private int pendingFutureTimeoutMinutes = 5; | 96 | + @Property(name = "pendingFutureTimeoutMinutes", intValue = DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES, |
97 | + label = "Expiration time after an entry is created that it should be automatically removed") | ||
98 | + private int pendingFutureTimeoutMinutes = DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES; | ||
92 | 99 | ||
93 | private Cache<Integer, SettableFuture<CompletedBatchOperation>> pendingFutures = | 100 | private Cache<Integer, SettableFuture<CompletedBatchOperation>> pendingFutures = |
94 | CacheBuilder.newBuilder() | 101 | CacheBuilder.newBuilder() |
... | @@ -108,6 +115,21 @@ public class SimpleFlowRuleStore | ... | @@ -108,6 +115,21 @@ public class SimpleFlowRuleStore |
108 | log.info("Stopped"); | 115 | log.info("Stopped"); |
109 | } | 116 | } |
110 | 117 | ||
118 | + @Modified | ||
119 | + public void modified(ComponentContext context) { | ||
120 | + | ||
121 | + readComponentConfiguration(context); | ||
122 | + | ||
123 | + // Reset Cache and copy all. | ||
124 | + Cache<Integer, SettableFuture<CompletedBatchOperation>> prevFutures = pendingFutures; | ||
125 | + pendingFutures = CacheBuilder.newBuilder() | ||
126 | + .expireAfterWrite(pendingFutureTimeoutMinutes, TimeUnit.MINUTES) | ||
127 | + .removalListener(new TimeoutFuture()) | ||
128 | + .build(); | ||
129 | + | ||
130 | + pendingFutures.putAll(prevFutures.asMap()); | ||
131 | + } | ||
132 | + | ||
111 | 133 | ||
112 | @Override | 134 | @Override |
113 | public int getFlowRuleCount() { | 135 | public int getFlowRuleCount() { |
... | @@ -120,6 +142,27 @@ public class SimpleFlowRuleStore | ... | @@ -120,6 +142,27 @@ public class SimpleFlowRuleStore |
120 | return sum; | 142 | return sum; |
121 | } | 143 | } |
122 | 144 | ||
145 | + /** | ||
146 | + * Extracts properties from the component configuration context. | ||
147 | + * | ||
148 | + * @param context the component context | ||
149 | + */ | ||
150 | + private void readComponentConfiguration(ComponentContext context) { | ||
151 | + Dictionary<?, ?> properties = context.getProperties(); | ||
152 | + | ||
153 | + Integer newPendingFutureTimeoutMinutes = | ||
154 | + Tools.getIntegerProperty(properties, "pendingFutureTimeoutMinutes"); | ||
155 | + if (newPendingFutureTimeoutMinutes == null) { | ||
156 | + pendingFutureTimeoutMinutes = DEFAULT_PENDING_FUTURE_TIMEOUT_MINUTES; | ||
157 | + log.info("Pending future timeout is not configured, " + | ||
158 | + "using current value of {}", pendingFutureTimeoutMinutes); | ||
159 | + } else { | ||
160 | + pendingFutureTimeoutMinutes = newPendingFutureTimeoutMinutes; | ||
161 | + log.info("Configured. Pending future timeout is configured to {}", | ||
162 | + pendingFutureTimeoutMinutes); | ||
163 | + } | ||
164 | + } | ||
165 | + | ||
123 | private static NewConcurrentHashMap<FlowId, List<StoredFlowEntry>> lazyEmptyFlowTable() { | 166 | private static NewConcurrentHashMap<FlowId, List<StoredFlowEntry>> lazyEmptyFlowTable() { |
124 | return NewConcurrentHashMap.<FlowId, List<StoredFlowEntry>>ifNeeded(); | 167 | return NewConcurrentHashMap.<FlowId, List<StoredFlowEntry>>ifNeeded(); |
125 | } | 168 | } |
... | @@ -332,19 +375,6 @@ public class SimpleFlowRuleStore | ... | @@ -332,19 +375,6 @@ public class SimpleFlowRuleStore |
332 | notifyDelegate(event); | 375 | notifyDelegate(event); |
333 | } | 376 | } |
334 | 377 | ||
335 | - private static final class TimeoutFuture | ||
336 | - implements RemovalListener<Integer, SettableFuture<CompletedBatchOperation>> { | ||
337 | - @Override | ||
338 | - public void onRemoval(RemovalNotification<Integer, SettableFuture<CompletedBatchOperation>> notification) { | ||
339 | - // wrapping in ExecutionException to support Future.get | ||
340 | - if (notification.wasEvicted()) { | ||
341 | - notification.getValue() | ||
342 | - .setException(new ExecutionException("Timed out", | ||
343 | - new TimeoutException())); | ||
344 | - } | ||
345 | - } | ||
346 | - } | ||
347 | - | ||
348 | @Override | 378 | @Override |
349 | public FlowRuleEvent updateTableStatistics(DeviceId deviceId, | 379 | public FlowRuleEvent updateTableStatistics(DeviceId deviceId, |
350 | List<TableStatisticsEntry> tableStats) { | 380 | List<TableStatisticsEntry> tableStats) { |
... | @@ -360,4 +390,17 @@ public class SimpleFlowRuleStore | ... | @@ -360,4 +390,17 @@ public class SimpleFlowRuleStore |
360 | } | 390 | } |
361 | return ImmutableList.copyOf(tableStats); | 391 | return ImmutableList.copyOf(tableStats); |
362 | } | 392 | } |
393 | + | ||
394 | + private static final class TimeoutFuture | ||
395 | + implements RemovalListener<Integer, SettableFuture<CompletedBatchOperation>> { | ||
396 | + @Override | ||
397 | + public void onRemoval(RemovalNotification<Integer, SettableFuture<CompletedBatchOperation>> notification) { | ||
398 | + // wrapping in ExecutionException to support Future.get | ||
399 | + if (notification.wasEvicted()) { | ||
400 | + notification.getValue() | ||
401 | + .setException(new ExecutionException("Timed out", | ||
402 | + new TimeoutException())); | ||
403 | + } | ||
404 | + } | ||
405 | + } | ||
363 | } | 406 | } | ... | ... |
... | @@ -148,7 +148,6 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -148,7 +148,6 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
148 | 148 | ||
149 | private final InternalDeviceProvider listener = new InternalDeviceProvider(); | 149 | private final InternalDeviceProvider listener = new InternalDeviceProvider(); |
150 | 150 | ||
151 | - // TODO: We need to make the poll interval configurable. | ||
152 | static final int POLL_INTERVAL = 5; | 151 | static final int POLL_INTERVAL = 5; |
153 | @Property(name = "PortStatsPollFrequency", intValue = POLL_INTERVAL, | 152 | @Property(name = "PortStatsPollFrequency", intValue = POLL_INTERVAL, |
154 | label = "Frequency (in seconds) for polling switch Port statistics") | 153 | label = "Frequency (in seconds) for polling switch Port statistics") | ... | ... |
-
Please register or login to post a comment