ONOS-6084 Statistics were absent for the flows posted when device master was null. The issue is fixed with this code change
Change-Id: I15be1c65955e9ede797fa3438f70426db0c078a6
diff --git a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
index a2c0299..04b73d0 100644
--- a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
+++ b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
@@ -398,7 +398,7 @@
}
- private void flowMissing(FlowEntry flowRule) {
+ private void flowMissing(FlowEntry flowRule, boolean isFlowOnlyInStore) {
checkNotNull(flowRule, FLOW_RULE_NULL);
checkValidity();
FlowRuleProvider frp = getProvider(flowRule.deviceId());
@@ -407,10 +407,18 @@
case PENDING_REMOVE:
case REMOVED:
event = store.removeFlowRule(flowRule);
+ log.debug("Flow {} removed", flowRule);
break;
case ADDED:
case PENDING_ADD:
event = store.pendingFlowRule(flowRule);
+ if (isFlowOnlyInStore) {
+ // Publishing RULE_ADD_REQUESTED event facilitates
+ // preparation of statistics for the concerned rule
+ if (event == null) {
+ event = new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADD_REQUESTED, flowRule);
+ }
+ }
try {
frp.applyFlowRule(flowRule);
} catch (UnsupportedOperationException e) {
@@ -426,7 +434,6 @@
}
if (event != null) {
- log.debug("Flow {} removed", flowRule);
post(event);
}
}
@@ -525,7 +532,7 @@
// the two rules are not an exact match - remove the
// switch's rule and install our rule
extraneousFlow(rule);
- flowMissing(storedRule);
+ flowMissing(storedRule, false);
}
} else {
// the device has a rule the store does not have
@@ -544,8 +551,8 @@
for (FlowEntry rule : storedRules.keySet()) {
try {
// there are rules in the store that aren't on the switch
- log.debug("Adding rule in store, but not on switch {}", rule);
- flowMissing(rule);
+ log.debug("Adding the rule that is present in store but not on switch : {}", rule);
+ flowMissing(rule, true);
} catch (Exception e) {
log.warn("Can't add missing flow rule:", e);
}
diff --git a/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java b/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
index bd96bdf..08f3373 100644
--- a/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
@@ -360,7 +360,7 @@
f3, FlowEntryState.PENDING_ADD)));
validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED,
- RULE_ADDED, RULE_ADDED);
+ RULE_ADDED, RULE_ADDED, RULE_ADD_REQUESTED);
}
@Test
diff --git a/core/store/dist/src/main/java/org/onosproject/store/flow/impl/DistributedFlowRuleStore.java b/core/store/dist/src/main/java/org/onosproject/store/flow/impl/DistributedFlowRuleStore.java
index 83df014..59d476b 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/flow/impl/DistributedFlowRuleStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/flow/impl/DistributedFlowRuleStore.java
@@ -409,7 +409,7 @@
NodeId master = mastershipService.getMasterFor(deviceId);
if (master == null) {
- log.warn("No master for {} : flows will be marked for removal", deviceId);
+ log.warn("No master for {} ", deviceId);
updateStoreInternal(operation);