alshabib

flow service idle timeout based on wall clock

Change-Id: Ifb2c15ab9e5c5b07c58f3194ff2152cef650a6ae
...@@ -7,7 +7,6 @@ import java.util.Iterator; ...@@ -7,7 +7,6 @@ import java.util.Iterator;
7 import java.util.List; 7 import java.util.List;
8 import java.util.Map; 8 import java.util.Map;
9 import java.util.concurrent.ConcurrentHashMap; 9 import java.util.concurrent.ConcurrentHashMap;
10 -import java.util.concurrent.atomic.AtomicInteger;
11 10
12 import org.apache.felix.scr.annotations.Activate; 11 import org.apache.felix.scr.annotations.Activate;
13 import org.apache.felix.scr.annotations.Component; 12 import org.apache.felix.scr.annotations.Component;
...@@ -62,7 +61,7 @@ implements FlowRuleService, FlowRuleProviderRegistry { ...@@ -62,7 +61,7 @@ implements FlowRuleService, FlowRuleProviderRegistry {
62 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 61 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 protected DeviceService deviceService; 62 protected DeviceService deviceService;
64 63
65 - private final Map<FlowRule, AtomicInteger> deadRounds = new ConcurrentHashMap<>(); 64 + private final Map<FlowRule, Long> idleTime = new ConcurrentHashMap<>();
66 65
67 @Activate 66 @Activate
68 public void activate() { 67 public void activate() {
...@@ -89,7 +88,7 @@ implements FlowRuleService, FlowRuleProviderRegistry { ...@@ -89,7 +88,7 @@ implements FlowRuleService, FlowRuleProviderRegistry {
89 FlowRule f = flowRules[i]; 88 FlowRule f = flowRules[i];
90 final Device device = deviceService.getDevice(f.deviceId()); 89 final Device device = deviceService.getDevice(f.deviceId());
91 final FlowRuleProvider frp = getProvider(device.providerId()); 90 final FlowRuleProvider frp = getProvider(device.providerId());
92 - deadRounds.put(f, new AtomicInteger(0)); 91 + idleTime.put(f, System.currentTimeMillis());
93 store.storeFlowRule(f); 92 store.storeFlowRule(f);
94 frp.applyFlowRule(f); 93 frp.applyFlowRule(f);
95 } 94 }
...@@ -104,7 +103,7 @@ implements FlowRuleService, FlowRuleProviderRegistry { ...@@ -104,7 +103,7 @@ implements FlowRuleService, FlowRuleProviderRegistry {
104 f = flowRules[i]; 103 f = flowRules[i];
105 device = deviceService.getDevice(f.deviceId()); 104 device = deviceService.getDevice(f.deviceId());
106 frp = getProvider(device.providerId()); 105 frp = getProvider(device.providerId());
107 - deadRounds.remove(f); 106 + idleTime.remove(f);
108 store.deleteFlowRule(f); 107 store.deleteFlowRule(f);
109 frp.removeFlowRule(f); 108 frp.removeFlowRule(f);
110 } 109 }
...@@ -225,7 +224,7 @@ implements FlowRuleService, FlowRuleProviderRegistry { ...@@ -225,7 +224,7 @@ implements FlowRuleService, FlowRuleProviderRegistry {
225 checkNotNull(flowRule, FLOW_RULE_NULL); 224 checkNotNull(flowRule, FLOW_RULE_NULL);
226 checkValidity(); 225 checkValidity();
227 226
228 - if (deadRounds.containsKey(flowRule) && 227 + if (idleTime.containsKey(flowRule) &&
229 checkRuleLiveness(flowRule, store.getFlowRule(flowRule))) { 228 checkRuleLiveness(flowRule, store.getFlowRule(flowRule))) {
230 229
231 FlowRuleEvent event = store.addOrUpdateFlowRule(flowRule); 230 FlowRuleEvent event = store.addOrUpdateFlowRule(flowRule);
...@@ -242,16 +241,14 @@ implements FlowRuleService, FlowRuleProviderRegistry { ...@@ -242,16 +241,14 @@ implements FlowRuleService, FlowRuleProviderRegistry {
242 } 241 }
243 242
244 private boolean checkRuleLiveness(FlowRule swRule, FlowRule storedRule) { 243 private boolean checkRuleLiveness(FlowRule swRule, FlowRule storedRule) {
245 - return true; 244 + long timeout = storedRule.timeout() * 1000;
246 -// int timeout = storedRule.timeout(); 245 + Long currentTime = System.currentTimeMillis();
247 -// if (storedRule.packets() != swRule.packets()) { 246 + if (storedRule.packets() != swRule.packets()) {
248 -// deadRounds.get(swRule).set(0); 247 + idleTime.put(swRule, currentTime);
249 -// return true; 248 + return true;
250 -// } 249 + }
251 -// 250 + return (currentTime - idleTime.get(swRule)) <= timeout;
252 -// return (deadRounds.get(swRule).getAndIncrement() * 251 +
253 -// FlowRuleProvider.POLL_INTERVAL) <= timeout;
254 -//
255 } 252 }
256 253
257 // Posts the specified event to the local event dispatcher. 254 // Posts the specified event to the local event dispatcher.
......