the return of the flowentry
Change-Id: I7dbeb6af2014a4df5b0beb7fe0157eaaac63bd0f
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleFlowRuleStore.java b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleFlowRuleStore.java
index d12d00e..5fa92f3 100644
--- a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleFlowRuleStore.java
+++ b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleFlowRuleStore.java
@@ -12,9 +12,10 @@
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.DeviceId;
-import org.onlab.onos.net.flow.DefaultFlowRule;
+import org.onlab.onos.net.flow.DefaultFlowEntry;
+import org.onlab.onos.net.flow.FlowEntry;
+import org.onlab.onos.net.flow.FlowEntry.FlowEntryState;
import org.onlab.onos.net.flow.FlowRule;
-import org.onlab.onos.net.flow.FlowRule.FlowRuleState;
import org.onlab.onos.net.flow.FlowRuleEvent;
import org.onlab.onos.net.flow.FlowRuleEvent.Type;
import org.onlab.onos.net.flow.FlowRuleStore;
@@ -38,8 +39,8 @@
private final Logger log = getLogger(getClass());
// store entries as a pile of rules, no info about device tables
- private final Multimap<DeviceId, FlowRule> flowEntries =
- ArrayListMultimap.<DeviceId, FlowRule>create();
+ private final Multimap<DeviceId, FlowEntry> flowEntries =
+ ArrayListMultimap.<DeviceId, FlowEntry>create();
private final Multimap<ApplicationId, FlowRule> flowEntriesById =
ArrayListMultimap.<ApplicationId, FlowRule>create();
@@ -56,8 +57,8 @@
@Override
- public synchronized FlowRule getFlowRule(FlowRule rule) {
- for (FlowRule f : flowEntries.get(rule.deviceId())) {
+ public synchronized FlowEntry getFlowEntry(FlowRule rule) {
+ for (FlowEntry f : flowEntries.get(rule.deviceId())) {
if (f.equals(rule)) {
return f;
}
@@ -66,8 +67,8 @@
}
@Override
- public synchronized Iterable<FlowRule> getFlowEntries(DeviceId deviceId) {
- Collection<FlowRule> rules = flowEntries.get(deviceId);
+ public synchronized Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
+ Collection<FlowEntry> rules = flowEntries.get(deviceId);
if (rules == null) {
return Collections.emptyList();
}
@@ -75,7 +76,7 @@
}
@Override
- public synchronized Iterable<FlowRule> getFlowEntriesByAppId(ApplicationId appId) {
+ public synchronized Iterable<FlowRule> getFlowRulesByAppId(ApplicationId appId) {
Collection<FlowRule> rules = flowEntriesById.get(appId);
if (rules == null) {
return Collections.emptyList();
@@ -85,7 +86,7 @@
@Override
public synchronized void storeFlowRule(FlowRule rule) {
- FlowRule f = new DefaultFlowRule(rule, FlowRuleState.PENDING_ADD);
+ FlowEntry f = new DefaultFlowEntry(rule);
DeviceId did = f.deviceId();
if (!flowEntries.containsEntry(did, f)) {
flowEntries.put(did, f);
@@ -95,34 +96,25 @@
@Override
public synchronized void deleteFlowRule(FlowRule rule) {
- FlowRule f = new DefaultFlowRule(rule, FlowRuleState.PENDING_REMOVE);
- DeviceId did = f.deviceId();
-
- /*
- * find the rule and mark it for deletion.
- * Ultimately a flow removed will come remove it.
- */
-
- if (flowEntries.containsEntry(did, f)) {
- flowEntries.remove(did, f);
- flowEntries.put(did, f);
- flowEntriesById.remove(rule.appId(), rule);
+ FlowEntry entry = getFlowEntry(rule);
+ if (entry == null) {
+ return;
}
+ entry.setState(FlowEntryState.PENDING_REMOVE);
}
@Override
- public synchronized FlowRuleEvent addOrUpdateFlowRule(FlowRule rule) {
+ public synchronized FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule) {
DeviceId did = rule.deviceId();
// check if this new rule is an update to an existing entry
- FlowRule stored = getFlowRule(rule);
+ FlowEntry stored = getFlowEntry(rule);
if (stored != null) {
- // Multimaps support duplicates so we have to remove our rule
- // and replace it with the current version.
- flowEntries.remove(did, rule);
- flowEntries.put(did, rule);
-
- if (stored.state() == FlowRuleState.PENDING_ADD) {
+ stored.setBytes(rule.bytes());
+ stored.setLife(rule.life());
+ stored.setPackets(rule.packets());
+ if (stored.state() == FlowEntryState.PENDING_ADD) {
+ stored.setState(FlowEntryState.ADDED);
return new FlowRuleEvent(Type.RULE_ADDED, rule);
}
return new FlowRuleEvent(Type.RULE_UPDATED, rule);
@@ -133,13 +125,12 @@
}
@Override
- public synchronized FlowRuleEvent removeFlowRule(FlowRule rule) {
- //synchronized (this) {
+ public synchronized FlowRuleEvent removeFlowRule(FlowEntry rule) {
+ // This is where one could mark a rule as removed and still keep it in the store.
if (flowEntries.remove(rule.deviceId(), rule)) {
return new FlowRuleEvent(RULE_REMOVED, rule);
} else {
return null;
}
- //}
}
}