flowrule states functional
Change-Id: Id310f146d4ef2a59993f31d60062464a24df4560
diff --git a/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java b/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
index 5bd6fed..1cee01a 100644
--- a/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/flow/impl/FlowRuleManager.java
@@ -3,7 +3,6 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -73,18 +72,14 @@
}
@Override
- public List<FlowRule> applyFlowRules(FlowRule... flowRules) {
- List<FlowRule> entries = new ArrayList<FlowRule>();
-
+ public void applyFlowRules(FlowRule... flowRules) {
for (int i = 0; i < flowRules.length; i++) {
FlowRule f = new DefaultFlowRule(flowRules[i], FlowRuleState.PENDING_ADD);
final Device device = deviceService.getDevice(f.deviceId());
final FlowRuleProvider frp = getProvider(device.providerId());
- entries.add(store.storeFlowRule(f));
+ store.storeFlowRule(f);
frp.applyFlowRule(f);
}
-
- return entries;
}
@Override
@@ -93,7 +88,7 @@
FlowRule f = new DefaultFlowRule(flowRules[i], FlowRuleState.PENDING_REMOVE);
final Device device = deviceService.getDevice(f.deviceId());
final FlowRuleProvider frp = getProvider(device.providerId());
- store.removeFlowRule(f);
+ store.deleteFlowRule(f);
frp.removeFlowRule(f);
}
@@ -139,22 +134,30 @@
public void flowMissing(FlowRule flowRule) {
checkNotNull(flowRule, FLOW_RULE_NULL);
checkValidity();
- // TODO Auto-generated method stub
+ log.info("Flow {} has not been installed.");
}
@Override
+ public void extraneousFlow(FlowRule flowRule) {
+ checkNotNull(flowRule, FLOW_RULE_NULL);
+ checkValidity();
+ log.info("Flow {} is on switch but not in store.");
+ }
+
+ @Override
public void flowAdded(FlowRule flowRule) {
checkNotNull(flowRule, FLOW_RULE_NULL);
checkValidity();
FlowRuleEvent event = store.addOrUpdateFlowRule(flowRule);
if (event == null) {
- log.debug("Flow {} updated", flowRule);
+ log.debug("No flow store event generated.");
} else {
- log.debug("Flow {} added", flowRule);
+ log.debug("Flow {} {}", flowRule, event.type());
post(event);
}
+
}
// Posts the specified event to the local event dispatcher.
@@ -167,31 +170,23 @@
@Override
public void pushFlowMetrics(DeviceId deviceId, Iterable<FlowRule> flowEntries) {
List<FlowRule> storedRules = Lists.newLinkedList(store.getFlowEntries(deviceId));
- List<FlowRule> switchRules = Lists.newLinkedList(flowEntries);
- Iterator<FlowRule> switchRulesIterator = switchRules.iterator();
- List<FlowRule> extraRules = Lists.newLinkedList();
+ //List<FlowRule> switchRules = Lists.newLinkedList(flowEntries);
+ Iterator<FlowRule> switchRulesIterator = flowEntries.iterator(); //switchRules.iterator();
while (switchRulesIterator.hasNext()) {
FlowRule rule = switchRulesIterator.next();
if (storedRules.remove(rule)) {
- // we both have the rule let's update some info then.
- log.info("rule {} is added. {}", rule.id(), rule.state());
+ // we both have the rule, let's update some info then.
flowAdded(rule);
} else {
- // the device a rule the store does not have
- extraRules.add(rule);
+ // the device has a rule the store does not have
+ extraneousFlow(rule);
}
}
for (FlowRule rule : storedRules) {
// there are rules in the store that aren't on the switch
flowMissing(rule);
}
- if (extraRules.size() > 0) {
- log.warn("Device {} has extra flow rules: {}", deviceId, extraRules);
- // TODO do something with this.
- }
-
-
}
}
diff --git a/core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java b/core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
index b164015..564bea2 100644
--- a/core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
+++ b/core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
@@ -6,6 +6,7 @@
import static org.junit.Assert.assertTrue;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED;
import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
+import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_UPDATED;
import java.util.ArrayList;
import java.util.List;
@@ -37,10 +38,10 @@
import org.onlab.onos.net.flow.instructions.Instruction;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
+import org.onlab.onos.net.trivial.impl.SimpleFlowRuleStore;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
-import org.onlab.onos.net.trivial.impl.SimpleFlowRuleStore;
/**
* Test codifying the flow rule service & flow rule provider service contracts.
@@ -131,7 +132,7 @@
addFlowRule(1);
assertEquals("should still be 2 rules", 2, flowCount());
- validateEvents();
+ validateEvents(RULE_UPDATED);
}
@Test
@@ -149,9 +150,9 @@
assertTrue("store should be empty",
Sets.newHashSet(service.getFlowEntries(DID)).isEmpty());
- List<FlowRule> ret = mgr.applyFlowRules(r1, r2, r3);
+ mgr.applyFlowRules(r1, r2, r3);
assertEquals("3 rules should exist", 3, flowCount());
- assertTrue("3 entries should result", fel.containsAll(ret));
+ assertTrue("3 entries should result", fel.containsAll(Lists.newArrayList(r1, r2, r3)));
}
@Test
@@ -167,10 +168,10 @@
mgr.removeFlowRules(rem1, rem2);
//removing from north, so no events generated
validateEvents();
- assertEquals("1 rule should exist", 1, flowCount());
+ assertEquals("3 rule should exist", 3, flowCount());
mgr.removeFlowRules(rem1);
- assertEquals("1 rule should still exist", 1, flowCount());
+ assertEquals("3 rule should still exist", 3, flowCount());
}
@Test