Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Showing
16 changed files
with
439 additions
and
376 deletions
| ... | @@ -5,7 +5,7 @@ import java.util.SortedSet; | ... | @@ -5,7 +5,7 @@ import java.util.SortedSet; |
| 5 | 5 | ||
| 6 | import org.apache.karaf.shell.console.Completer; | 6 | import org.apache.karaf.shell.console.Completer; |
| 7 | import org.apache.karaf.shell.console.completer.StringsCompleter; | 7 | import org.apache.karaf.shell.console.completer.StringsCompleter; |
| 8 | -import org.onlab.onos.net.flow.FlowRule.FlowRuleState; | 8 | +import org.onlab.onos.net.flow.FlowEntry.FlowEntryState; |
| 9 | 9 | ||
| 10 | /** | 10 | /** |
| 11 | * Device ID completer. | 11 | * Device ID completer. |
| ... | @@ -16,7 +16,7 @@ public class FlowRuleStatusCompleter implements Completer { | ... | @@ -16,7 +16,7 @@ public class FlowRuleStatusCompleter implements Completer { |
| 16 | // Delegate string completer | 16 | // Delegate string completer |
| 17 | StringsCompleter delegate = new StringsCompleter(); | 17 | StringsCompleter delegate = new StringsCompleter(); |
| 18 | 18 | ||
| 19 | - FlowRuleState[] states = FlowRuleState.values(); | 19 | + FlowEntryState[] states = FlowEntryState.values(); |
| 20 | SortedSet<String> strings = delegate.getStrings(); | 20 | SortedSet<String> strings = delegate.getStrings(); |
| 21 | for (int i = 0; i < states.length; i++) { | 21 | for (int i = 0; i < states.length; i++) { |
| 22 | strings.add(states[i].toString().toLowerCase()); | 22 | strings.add(states[i].toString().toLowerCase()); | ... | ... |
| ... | @@ -13,8 +13,8 @@ import org.onlab.onos.cli.Comparators; | ... | @@ -13,8 +13,8 @@ import org.onlab.onos.cli.Comparators; |
| 13 | import org.onlab.onos.net.Device; | 13 | import org.onlab.onos.net.Device; |
| 14 | import org.onlab.onos.net.DeviceId; | 14 | import org.onlab.onos.net.DeviceId; |
| 15 | import org.onlab.onos.net.device.DeviceService; | 15 | import org.onlab.onos.net.device.DeviceService; |
| 16 | -import org.onlab.onos.net.flow.FlowRule; | 16 | +import org.onlab.onos.net.flow.FlowEntry; |
| 17 | -import org.onlab.onos.net.flow.FlowRule.FlowRuleState; | 17 | +import org.onlab.onos.net.flow.FlowEntry.FlowEntryState; |
| 18 | import org.onlab.onos.net.flow.FlowRuleService; | 18 | import org.onlab.onos.net.flow.FlowRuleService; |
| 19 | 19 | ||
| 20 | import com.google.common.collect.Maps; | 20 | import com.google.common.collect.Maps; |
| ... | @@ -45,7 +45,7 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -45,7 +45,7 @@ public class FlowsListCommand extends AbstractShellCommand { |
| 45 | protected void execute() { | 45 | protected void execute() { |
| 46 | DeviceService deviceService = get(DeviceService.class); | 46 | DeviceService deviceService = get(DeviceService.class); |
| 47 | FlowRuleService service = get(FlowRuleService.class); | 47 | FlowRuleService service = get(FlowRuleService.class); |
| 48 | - Map<Device, List<FlowRule>> flows = getSortedFlows(deviceService, service); | 48 | + Map<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service); |
| 49 | for (Device d : flows.keySet()) { | 49 | for (Device d : flows.keySet()) { |
| 50 | printFlows(d, flows.get(d)); | 50 | printFlows(d, flows.get(d)); |
| 51 | } | 51 | } |
| ... | @@ -57,12 +57,12 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -57,12 +57,12 @@ public class FlowsListCommand extends AbstractShellCommand { |
| 57 | * @param service device service | 57 | * @param service device service |
| 58 | * @return sorted device list | 58 | * @return sorted device list |
| 59 | */ | 59 | */ |
| 60 | - protected Map<Device, List<FlowRule>> getSortedFlows(DeviceService deviceService, FlowRuleService service) { | 60 | + protected Map<Device, List<FlowEntry>> getSortedFlows(DeviceService deviceService, FlowRuleService service) { |
| 61 | - Map<Device, List<FlowRule>> flows = Maps.newHashMap(); | 61 | + Map<Device, List<FlowEntry>> flows = Maps.newHashMap(); |
| 62 | - List<FlowRule> rules; | 62 | + List<FlowEntry> rules; |
| 63 | - FlowRuleState s = null; | 63 | + FlowEntryState s = null; |
| 64 | if (state != null && !state.equals("any")) { | 64 | if (state != null && !state.equals("any")) { |
| 65 | - s = FlowRuleState.valueOf(state.toUpperCase()); | 65 | + s = FlowEntryState.valueOf(state.toUpperCase()); |
| 66 | } | 66 | } |
| 67 | Iterable<Device> devices = uri == null ? deviceService.getDevices() : | 67 | Iterable<Device> devices = uri == null ? deviceService.getDevices() : |
| 68 | Collections.singletonList(deviceService.getDevice(DeviceId.deviceId(uri))); | 68 | Collections.singletonList(deviceService.getDevice(DeviceId.deviceId(uri))); |
| ... | @@ -71,7 +71,7 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -71,7 +71,7 @@ public class FlowsListCommand extends AbstractShellCommand { |
| 71 | rules = newArrayList(service.getFlowEntries(d.id())); | 71 | rules = newArrayList(service.getFlowEntries(d.id())); |
| 72 | } else { | 72 | } else { |
| 73 | rules = newArrayList(); | 73 | rules = newArrayList(); |
| 74 | - for (FlowRule f : service.getFlowEntries(d.id())) { | 74 | + for (FlowEntry f : service.getFlowEntries(d.id())) { |
| 75 | if (f.state().equals(s)) { | 75 | if (f.state().equals(s)) { |
| 76 | rules.add(f); | 76 | rules.add(f); |
| 77 | } | 77 | } |
| ... | @@ -88,13 +88,13 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -88,13 +88,13 @@ public class FlowsListCommand extends AbstractShellCommand { |
| 88 | * @param d the device | 88 | * @param d the device |
| 89 | * @param flows the set of flows for that device. | 89 | * @param flows the set of flows for that device. |
| 90 | */ | 90 | */ |
| 91 | - protected void printFlows(Device d, List<FlowRule> flows) { | 91 | + protected void printFlows(Device d, List<FlowEntry> flows) { |
| 92 | print("Device: " + d.id()); | 92 | print("Device: " + d.id()); |
| 93 | if (flows == null | flows.isEmpty()) { | 93 | if (flows == null | flows.isEmpty()) { |
| 94 | print(" %s", "No flows."); | 94 | print(" %s", "No flows."); |
| 95 | return; | 95 | return; |
| 96 | } | 96 | } |
| 97 | - for (FlowRule f : flows) { | 97 | + for (FlowEntry f : flows) { |
| 98 | print(FMT, Long.toHexString(f.id().value()), f.state(), f.bytes(), | 98 | print(FMT, Long.toHexString(f.id().value()), f.state(), f.bytes(), |
| 99 | f.packets(), f.life(), f.priority()); | 99 | f.packets(), f.life(), f.priority()); |
| 100 | print(SFMT, f.selector().criteria()); | 100 | print(SFMT, f.selector().criteria()); | ... | ... |
| 1 | +package org.onlab.onos.net.flow; | ||
| 2 | + | ||
| 3 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
| 4 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 5 | + | ||
| 6 | +import org.onlab.onos.net.DeviceId; | ||
| 7 | +import org.slf4j.Logger; | ||
| 8 | + | ||
| 9 | +public class DefaultFlowEntry extends DefaultFlowRule implements FlowEntry { | ||
| 10 | + | ||
| 11 | + private final Logger log = getLogger(getClass()); | ||
| 12 | + | ||
| 13 | + private long life; | ||
| 14 | + private long packets; | ||
| 15 | + private long bytes; | ||
| 16 | + private FlowEntryState state; | ||
| 17 | + | ||
| 18 | + private long lastSeen = -1; | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + public DefaultFlowEntry(DeviceId deviceId, TrafficSelector selector, | ||
| 22 | + TrafficTreatment treatment, int priority, FlowEntryState state, | ||
| 23 | + long life, long packets, long bytes, long flowId, | ||
| 24 | + int timeout) { | ||
| 25 | + super(deviceId, selector, treatment, priority, flowId, timeout); | ||
| 26 | + this.state = state; | ||
| 27 | + this.life = life; | ||
| 28 | + this.packets = packets; | ||
| 29 | + this.bytes = bytes; | ||
| 30 | + this.lastSeen = System.currentTimeMillis(); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public DefaultFlowEntry(FlowRule rule, FlowEntryState state, | ||
| 34 | + long life, long packets, long bytes) { | ||
| 35 | + super(rule); | ||
| 36 | + this.state = state; | ||
| 37 | + this.life = life; | ||
| 38 | + this.packets = packets; | ||
| 39 | + this.bytes = bytes; | ||
| 40 | + this.lastSeen = System.currentTimeMillis(); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public DefaultFlowEntry(FlowRule rule) { | ||
| 44 | + super(rule); | ||
| 45 | + this.state = FlowEntryState.PENDING_ADD; | ||
| 46 | + this.life = 0; | ||
| 47 | + this.packets = 0; | ||
| 48 | + this.bytes = 0; | ||
| 49 | + this.lastSeen = System.currentTimeMillis(); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public long life() { | ||
| 54 | + return life; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + @Override | ||
| 58 | + public long packets() { | ||
| 59 | + return packets; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public long bytes() { | ||
| 64 | + return bytes; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + @Override | ||
| 68 | + public FlowEntryState state() { | ||
| 69 | + return this.state; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @Override | ||
| 73 | + public long lastSeen() { | ||
| 74 | + return lastSeen; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public void setLastSeen() { | ||
| 79 | + this.lastSeen = System.currentTimeMillis(); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + @Override | ||
| 83 | + public void setState(FlowEntryState newState) { | ||
| 84 | + this.state = newState; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + @Override | ||
| 88 | + public void setLife(long life) { | ||
| 89 | + this.life = life; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + @Override | ||
| 93 | + public void setPackets(long packets) { | ||
| 94 | + this.packets = packets; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + public void setBytes(long bytes) { | ||
| 99 | + this.bytes = bytes; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + @Override | ||
| 103 | + public String toString() { | ||
| 104 | + return toStringHelper(this) | ||
| 105 | + .add("rule", super.toString()) | ||
| 106 | + .add("state", state) | ||
| 107 | + .toString(); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + | ||
| 111 | +} |
| ... | @@ -18,10 +18,6 @@ public class DefaultFlowRule implements FlowRule { | ... | @@ -18,10 +18,6 @@ public class DefaultFlowRule implements FlowRule { |
| 18 | private final TrafficSelector selector; | 18 | private final TrafficSelector selector; |
| 19 | private final TrafficTreatment treatment; | 19 | private final TrafficTreatment treatment; |
| 20 | private final long created; | 20 | private final long created; |
| 21 | - private final long life; | ||
| 22 | - private final long packets; | ||
| 23 | - private final long bytes; | ||
| 24 | - private final FlowRuleState state; | ||
| 25 | 21 | ||
| 26 | private final FlowId id; | 22 | private final FlowId id; |
| 27 | 23 | ||
| ... | @@ -29,90 +25,50 @@ public class DefaultFlowRule implements FlowRule { | ... | @@ -29,90 +25,50 @@ public class DefaultFlowRule implements FlowRule { |
| 29 | 25 | ||
| 30 | private final int timeout; | 26 | private final int timeout; |
| 31 | 27 | ||
| 32 | - /** | 28 | + |
| 33 | - * Creates a flow rule given the following paremeters. | ||
| 34 | - * @param deviceId the device where the rule should be installed | ||
| 35 | - * @param selector the traffic selection | ||
| 36 | - * @param treatment how the seleted traffic should be handled | ||
| 37 | - * @param priority the rule priority cannot be less than FlowRule.MIN_PRIORITY | ||
| 38 | - * @param state the state in which the rule is | ||
| 39 | - * @param life how long it has existed for (ms) | ||
| 40 | - * @param packets number of packets it has seen | ||
| 41 | - * @param bytes number of bytes it has seen | ||
| 42 | - * @param flowId the identifier | ||
| 43 | - * @param timeout the rule's timeout (idle) not to exceed | ||
| 44 | - * FlowRule.MAX_TIMEOUT of idle time | ||
| 45 | - */ | ||
| 46 | public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, | 29 | public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, |
| 47 | - TrafficTreatment treatment, int priority, FlowRuleState state, | 30 | + TrafficTreatment treatment, int priority, long flowId, |
| 48 | - long life, long packets, long bytes, long flowId, | ||
| 49 | int timeout) { | 31 | int timeout) { |
| 50 | this.deviceId = deviceId; | 32 | this.deviceId = deviceId; |
| 51 | this.priority = priority; | 33 | this.priority = priority; |
| 52 | this.selector = selector; | 34 | this.selector = selector; |
| 53 | this.treatment = treatment; | 35 | this.treatment = treatment; |
| 54 | - this.state = state; | 36 | + this.timeout = timeout; |
| 37 | + this.created = System.currentTimeMillis(); | ||
| 38 | + | ||
| 55 | this.appId = ApplicationId.valueOf((int) (flowId >> 32)); | 39 | this.appId = ApplicationId.valueOf((int) (flowId >> 32)); |
| 56 | this.id = FlowId.valueOf(flowId); | 40 | this.id = FlowId.valueOf(flowId); |
| 57 | - this.life = life; | ||
| 58 | - this.packets = packets; | ||
| 59 | - this.bytes = bytes; | ||
| 60 | - this.created = System.currentTimeMillis(); | ||
| 61 | - this.timeout = timeout; | ||
| 62 | } | 41 | } |
| 63 | 42 | ||
| 64 | public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, | 43 | public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, |
| 65 | TrafficTreatment treatement, int priority, ApplicationId appId, | 44 | TrafficTreatment treatement, int priority, ApplicationId appId, |
| 66 | int timeout) { | 45 | int timeout) { |
| 67 | - this(deviceId, selector, treatement, priority, | ||
| 68 | - FlowRuleState.CREATED, appId, timeout); | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - public DefaultFlowRule(FlowRule rule, FlowRuleState state) { | ||
| 72 | - this(rule.deviceId(), rule.selector(), rule.treatment(), | ||
| 73 | - rule.priority(), state, rule.id(), rule.appId(), | ||
| 74 | - rule.timeout()); | ||
| 75 | - } | ||
| 76 | 46 | ||
| 77 | - private DefaultFlowRule(DeviceId deviceId, | 47 | + if (priority < FlowRule.MIN_PRIORITY) { |
| 78 | - TrafficSelector selector, TrafficTreatment treatment, | ||
| 79 | - int priority, FlowRuleState state, ApplicationId appId, | ||
| 80 | - int timeout) { | ||
| 81 | - if (priority < MIN_PRIORITY) { | ||
| 82 | throw new IllegalArgumentException("Priority cannot be less than " + MIN_PRIORITY); | 48 | throw new IllegalArgumentException("Priority cannot be less than " + MIN_PRIORITY); |
| 83 | } | 49 | } |
| 50 | + | ||
| 84 | this.deviceId = deviceId; | 51 | this.deviceId = deviceId; |
| 85 | this.priority = priority; | 52 | this.priority = priority; |
| 86 | this.selector = selector; | 53 | this.selector = selector; |
| 87 | - this.treatment = treatment; | 54 | + this.treatment = treatement; |
| 88 | - this.state = state; | ||
| 89 | - this.life = 0; | ||
| 90 | - this.packets = 0; | ||
| 91 | - this.bytes = 0; | ||
| 92 | this.appId = appId; | 55 | this.appId = appId; |
| 93 | - | ||
| 94 | this.timeout = timeout; | 56 | this.timeout = timeout; |
| 57 | + this.created = System.currentTimeMillis(); | ||
| 95 | 58 | ||
| 96 | this.id = FlowId.valueOf((((long) appId().id()) << 32) | (this.hash() & 0xffffffffL)); | 59 | this.id = FlowId.valueOf((((long) appId().id()) << 32) | (this.hash() & 0xffffffffL)); |
| 97 | - this.created = System.currentTimeMillis(); | ||
| 98 | } | 60 | } |
| 99 | 61 | ||
| 100 | - private DefaultFlowRule(DeviceId deviceId, | 62 | + public DefaultFlowRule(FlowRule rule) { |
| 101 | - TrafficSelector selector, TrafficTreatment treatment, | 63 | + this.deviceId = rule.deviceId(); |
| 102 | - int priority, FlowRuleState state, FlowId flowId, ApplicationId appId, | 64 | + this.priority = rule.priority(); |
| 103 | - int timeout) { | 65 | + this.selector = rule.selector(); |
| 104 | - this.deviceId = deviceId; | 66 | + this.treatment = rule.treatment(); |
| 105 | - this.priority = priority; | 67 | + this.appId = rule.appId(); |
| 106 | - this.selector = selector; | 68 | + this.id = rule.id(); |
| 107 | - this.treatment = treatment; | 69 | + this.timeout = rule.timeout(); |
| 108 | - this.state = state; | ||
| 109 | - this.life = 0; | ||
| 110 | - this.packets = 0; | ||
| 111 | - this.bytes = 0; | ||
| 112 | - this.appId = appId; | ||
| 113 | - this.id = flowId; | ||
| 114 | - this.timeout = timeout; | ||
| 115 | this.created = System.currentTimeMillis(); | 70 | this.created = System.currentTimeMillis(); |
| 71 | + | ||
| 116 | } | 72 | } |
| 117 | 73 | ||
| 118 | 74 | ||
| ... | @@ -146,26 +102,6 @@ public class DefaultFlowRule implements FlowRule { | ... | @@ -146,26 +102,6 @@ public class DefaultFlowRule implements FlowRule { |
| 146 | return treatment; | 102 | return treatment; |
| 147 | } | 103 | } |
| 148 | 104 | ||
| 149 | - @Override | ||
| 150 | - public long life() { | ||
| 151 | - return life; | ||
| 152 | - } | ||
| 153 | - | ||
| 154 | - @Override | ||
| 155 | - public long packets() { | ||
| 156 | - return packets; | ||
| 157 | - } | ||
| 158 | - | ||
| 159 | - @Override | ||
| 160 | - public long bytes() { | ||
| 161 | - return bytes; | ||
| 162 | - } | ||
| 163 | - | ||
| 164 | - @Override | ||
| 165 | - public FlowRuleState state() { | ||
| 166 | - return this.state; | ||
| 167 | - } | ||
| 168 | - | ||
| 169 | 105 | ||
| 170 | @Override | 106 | @Override |
| 171 | /* | 107 | /* |
| ... | @@ -213,7 +149,6 @@ public class DefaultFlowRule implements FlowRule { | ... | @@ -213,7 +149,6 @@ public class DefaultFlowRule implements FlowRule { |
| 213 | .add("selector", selector.criteria()) | 149 | .add("selector", selector.criteria()) |
| 214 | .add("treatment", treatment == null ? "N/A" : treatment.instructions()) | 150 | .add("treatment", treatment == null ? "N/A" : treatment.instructions()) |
| 215 | .add("created", created) | 151 | .add("created", created) |
| 216 | - .add("state", state) | ||
| 217 | .toString(); | 152 | .toString(); |
| 218 | } | 153 | } |
| 219 | 154 | ... | ... |
| 1 | +package org.onlab.onos.net.flow; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * Represents a generalized match & action pair to be applied to | ||
| 6 | + * an infrastucture device. | ||
| 7 | + */ | ||
| 8 | +public interface FlowEntry extends FlowRule { | ||
| 9 | + | ||
| 10 | + | ||
| 11 | + public enum FlowEntryState { | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * Indicates that this rule has been submitted for addition. | ||
| 15 | + * Not necessarily in the flow table. | ||
| 16 | + */ | ||
| 17 | + PENDING_ADD, | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * Rule has been added which means it is in the flow table. | ||
| 21 | + */ | ||
| 22 | + ADDED, | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * Flow has been marked for removal, might still be in flow table. | ||
| 26 | + */ | ||
| 27 | + PENDING_REMOVE, | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * Flow has been removed from flow table and can be purged. | ||
| 31 | + */ | ||
| 32 | + REMOVED | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * Returns the flow entry state. | ||
| 37 | + * | ||
| 38 | + * @return flow entry state | ||
| 39 | + */ | ||
| 40 | + FlowEntryState state(); | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * Returns the number of milliseconds this flow rule has been applied. | ||
| 44 | + * | ||
| 45 | + * @return number of millis | ||
| 46 | + */ | ||
| 47 | + long life(); | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Returns the number of packets this flow rule has matched. | ||
| 51 | + * | ||
| 52 | + * @return number of packets | ||
| 53 | + */ | ||
| 54 | + long packets(); | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * Returns the number of bytes this flow rule has matched. | ||
| 58 | + * | ||
| 59 | + * @return number of bytes | ||
| 60 | + */ | ||
| 61 | + long bytes(); | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * When this flow entry was last deemed active. | ||
| 65 | + * @return epoch time of last activity | ||
| 66 | + */ | ||
| 67 | + long lastSeen(); | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * Sets the last active epoch time. | ||
| 71 | + */ | ||
| 72 | + void setLastSeen(); | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * Sets the new state for this entry. | ||
| 76 | + * @param newState new flow entry state. | ||
| 77 | + */ | ||
| 78 | + void setState(FlowEntryState newState); | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * Sets how long this entry has been entered in the system. | ||
| 82 | + * @param life epoch time | ||
| 83 | + */ | ||
| 84 | + void setLife(long life); | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Number of packets seen by this entry. | ||
| 88 | + * @param packets a long value | ||
| 89 | + */ | ||
| 90 | + void setPackets(long packets); | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * Number of bytes seen by this rule. | ||
| 94 | + * @param bytes a long value | ||
| 95 | + */ | ||
| 96 | + void setBytes(long bytes); | ||
| 97 | + | ||
| 98 | +} |
| ... | @@ -12,41 +12,6 @@ public interface FlowRule { | ... | @@ -12,41 +12,6 @@ public interface FlowRule { |
| 12 | static final int MAX_TIMEOUT = 60; | 12 | static final int MAX_TIMEOUT = 60; |
| 13 | static final int MIN_PRIORITY = 0; | 13 | static final int MIN_PRIORITY = 0; |
| 14 | 14 | ||
| 15 | - public enum FlowRuleState { | ||
| 16 | - /** | ||
| 17 | - * Indicates that this rule has been created. | ||
| 18 | - */ | ||
| 19 | - CREATED, | ||
| 20 | - | ||
| 21 | - /** | ||
| 22 | - * Indicates that this rule has been submitted for addition. | ||
| 23 | - * Not necessarily in the flow table. | ||
| 24 | - */ | ||
| 25 | - PENDING_ADD, | ||
| 26 | - | ||
| 27 | - /** | ||
| 28 | - * Rule has been added which means it is in the flow table. | ||
| 29 | - */ | ||
| 30 | - ADDED, | ||
| 31 | - | ||
| 32 | - /** | ||
| 33 | - * Flow has been marked for removal, might still be in flow table. | ||
| 34 | - */ | ||
| 35 | - PENDING_REMOVE, | ||
| 36 | - | ||
| 37 | - /** | ||
| 38 | - * Flow has been removed from flow table and can be purged. | ||
| 39 | - */ | ||
| 40 | - REMOVED | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | - /** | ||
| 44 | - * Returns the flow rule state. | ||
| 45 | - * | ||
| 46 | - * @return flow rule state | ||
| 47 | - */ | ||
| 48 | - FlowRuleState state(); | ||
| 49 | - | ||
| 50 | //TODO: build cookie value | 15 | //TODO: build cookie value |
| 51 | /** | 16 | /** |
| 52 | * Returns the ID of this flow. | 17 | * Returns the ID of this flow. |
| ... | @@ -93,27 +58,6 @@ public interface FlowRule { | ... | @@ -93,27 +58,6 @@ public interface FlowRule { |
| 93 | TrafficTreatment treatment(); | 58 | TrafficTreatment treatment(); |
| 94 | 59 | ||
| 95 | /** | 60 | /** |
| 96 | - * Returns the number of milliseconds this flow rule has been applied. | ||
| 97 | - * | ||
| 98 | - * @return number of millis | ||
| 99 | - */ | ||
| 100 | - long life(); | ||
| 101 | - | ||
| 102 | - /** | ||
| 103 | - * Returns the number of packets this flow rule has matched. | ||
| 104 | - * | ||
| 105 | - * @return number of packets | ||
| 106 | - */ | ||
| 107 | - long packets(); | ||
| 108 | - | ||
| 109 | - /** | ||
| 110 | - * Returns the number of bytes this flow rule has matched. | ||
| 111 | - * | ||
| 112 | - * @return number of bytes | ||
| 113 | - */ | ||
| 114 | - long bytes(); | ||
| 115 | - | ||
| 116 | - /** | ||
| 117 | * Returns the timeout for this flow requested by an application. | 61 | * Returns the timeout for this flow requested by an application. |
| 118 | * @return integer value of the timeout | 62 | * @return integer value of the timeout |
| 119 | */ | 63 | */ | ... | ... |
| ... | @@ -14,7 +14,7 @@ public interface FlowRuleProviderService extends ProviderService<FlowRuleProvide | ... | @@ -14,7 +14,7 @@ public interface FlowRuleProviderService extends ProviderService<FlowRuleProvide |
| 14 | * | 14 | * |
| 15 | * @param flowRule information about the removed flow | 15 | * @param flowRule information about the removed flow |
| 16 | */ | 16 | */ |
| 17 | - void flowRemoved(FlowRule flowRule); | 17 | + void flowRemoved(FlowEntry flowEntry); |
| 18 | 18 | ||
| 19 | /** | 19 | /** |
| 20 | * Pushes the collection of flow entries currently applied on the given | 20 | * Pushes the collection of flow entries currently applied on the given |
| ... | @@ -22,7 +22,7 @@ public interface FlowRuleProviderService extends ProviderService<FlowRuleProvide | ... | @@ -22,7 +22,7 @@ public interface FlowRuleProviderService extends ProviderService<FlowRuleProvide |
| 22 | * | 22 | * |
| 23 | * @param flowRules collection of flow rules | 23 | * @param flowRules collection of flow rules |
| 24 | */ | 24 | */ |
| 25 | - void pushFlowMetrics(DeviceId deviceId, Iterable<FlowRule> flowRules); | 25 | + void pushFlowMetrics(DeviceId deviceId, Iterable<FlowEntry> flowEntries); |
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | 28 | ... | ... |
| ... | @@ -20,7 +20,7 @@ public interface FlowRuleService { | ... | @@ -20,7 +20,7 @@ public interface FlowRuleService { |
| 20 | * @param deviceId device identifier | 20 | * @param deviceId device identifier |
| 21 | * @return collection of flow rules | 21 | * @return collection of flow rules |
| 22 | */ | 22 | */ |
| 23 | - Iterable<FlowRule> getFlowEntries(DeviceId deviceId); | 23 | + Iterable<FlowEntry> getFlowEntries(DeviceId deviceId); |
| 24 | 24 | ||
| 25 | // TODO: add createFlowRule factory method and execute operations method | 25 | // TODO: add createFlowRule factory method and execute operations method |
| 26 | 26 | ... | ... |
| ... | @@ -14,7 +14,7 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat | ... | @@ -14,7 +14,7 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat |
| 14 | * @param rule the rule to look for | 14 | * @param rule the rule to look for |
| 15 | * @return a flow rule | 15 | * @return a flow rule |
| 16 | */ | 16 | */ |
| 17 | - FlowRule getFlowRule(FlowRule rule); | 17 | + FlowEntry getFlowEntry(FlowRule rule); |
| 18 | 18 | ||
| 19 | /** | 19 | /** |
| 20 | * Returns the flow entries associated with a device. | 20 | * Returns the flow entries associated with a device. |
| ... | @@ -22,7 +22,7 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat | ... | @@ -22,7 +22,7 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat |
| 22 | * @param deviceId the device ID | 22 | * @param deviceId the device ID |
| 23 | * @return the flow entries | 23 | * @return the flow entries |
| 24 | */ | 24 | */ |
| 25 | - Iterable<FlowRule> getFlowEntries(DeviceId deviceId); | 25 | + Iterable<FlowEntry> getFlowEntries(DeviceId deviceId); |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | * Returns the flow entries associated with an application. | 28 | * Returns the flow entries associated with an application. |
| ... | @@ -30,7 +30,7 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat | ... | @@ -30,7 +30,7 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat |
| 30 | * @param appId the application id | 30 | * @param appId the application id |
| 31 | * @return the flow entries | 31 | * @return the flow entries |
| 32 | */ | 32 | */ |
| 33 | - Iterable<FlowRule> getFlowEntriesByAppId(ApplicationId appId); | 33 | + Iterable<FlowRule> getFlowRulesByAppId(ApplicationId appId); |
| 34 | 34 | ||
| 35 | /** | 35 | /** |
| 36 | * Stores a new flow rule without generating events. | 36 | * Stores a new flow rule without generating events. |
| ... | @@ -40,7 +40,8 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat | ... | @@ -40,7 +40,8 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat |
| 40 | void storeFlowRule(FlowRule rule); | 40 | void storeFlowRule(FlowRule rule); |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| 43 | - * Deletes a flow rule without generating events. | 43 | + * Marks a flow rule for deletion. Actual deletion will occur |
| 44 | + * when the provider indicates that the flow has been removed. | ||
| 44 | * | 45 | * |
| 45 | * @param rule the flow rule to delete | 46 | * @param rule the flow rule to delete |
| 46 | */ | 47 | */ |
| ... | @@ -52,12 +53,12 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat | ... | @@ -52,12 +53,12 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat |
| 52 | * @param rule the flow rule to add or update | 53 | * @param rule the flow rule to add or update |
| 53 | * @return flow_added event, or null if just an update | 54 | * @return flow_added event, or null if just an update |
| 54 | */ | 55 | */ |
| 55 | - FlowRuleEvent addOrUpdateFlowRule(FlowRule rule); | 56 | + FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule); |
| 56 | 57 | ||
| 57 | /** | 58 | /** |
| 58 | - * @param rule the flow rule to remove | 59 | + * @param rule the flow entry to remove |
| 59 | * @return flow_removed event, or null if nothing removed | 60 | * @return flow_removed event, or null if nothing removed |
| 60 | */ | 61 | */ |
| 61 | - FlowRuleEvent removeFlowRule(FlowRule rule); | 62 | + FlowRuleEvent removeFlowRule(FlowEntry rule); |
| 62 | 63 | ||
| 63 | } | 64 | } | ... | ... |
| ... | @@ -5,8 +5,6 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -5,8 +5,6 @@ import static org.slf4j.LoggerFactory.getLogger; |
| 5 | 5 | ||
| 6 | import java.util.Iterator; | 6 | import java.util.Iterator; |
| 7 | import java.util.List; | 7 | import java.util.List; |
| 8 | -import java.util.Map; | ||
| 9 | -import java.util.concurrent.ConcurrentHashMap; | ||
| 10 | 8 | ||
| 11 | import org.apache.felix.scr.annotations.Activate; | 9 | import org.apache.felix.scr.annotations.Activate; |
| 12 | import org.apache.felix.scr.annotations.Component; | 10 | import org.apache.felix.scr.annotations.Component; |
| ... | @@ -20,6 +18,7 @@ import org.onlab.onos.event.EventDeliveryService; | ... | @@ -20,6 +18,7 @@ import org.onlab.onos.event.EventDeliveryService; |
| 20 | import org.onlab.onos.net.Device; | 18 | import org.onlab.onos.net.Device; |
| 21 | import org.onlab.onos.net.DeviceId; | 19 | import org.onlab.onos.net.DeviceId; |
| 22 | import org.onlab.onos.net.device.DeviceService; | 20 | import org.onlab.onos.net.device.DeviceService; |
| 21 | +import org.onlab.onos.net.flow.FlowEntry; | ||
| 23 | import org.onlab.onos.net.flow.FlowRule; | 22 | import org.onlab.onos.net.flow.FlowRule; |
| 24 | import org.onlab.onos.net.flow.FlowRuleEvent; | 23 | import org.onlab.onos.net.flow.FlowRuleEvent; |
| 25 | import org.onlab.onos.net.flow.FlowRuleListener; | 24 | import org.onlab.onos.net.flow.FlowRuleListener; |
| ... | @@ -61,8 +60,6 @@ implements FlowRuleService, FlowRuleProviderRegistry { | ... | @@ -61,8 +60,6 @@ implements FlowRuleService, FlowRuleProviderRegistry { |
| 61 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 60 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 62 | protected DeviceService deviceService; | 61 | protected DeviceService deviceService; |
| 63 | 62 | ||
| 64 | - private final Map<FlowRule, Long> idleTime = new ConcurrentHashMap<>(); | ||
| 65 | - | ||
| 66 | @Activate | 63 | @Activate |
| 67 | public void activate() { | 64 | public void activate() { |
| 68 | store.setDelegate(delegate); | 65 | store.setDelegate(delegate); |
| ... | @@ -78,7 +75,7 @@ implements FlowRuleService, FlowRuleProviderRegistry { | ... | @@ -78,7 +75,7 @@ implements FlowRuleService, FlowRuleProviderRegistry { |
| 78 | } | 75 | } |
| 79 | 76 | ||
| 80 | @Override | 77 | @Override |
| 81 | - public Iterable<FlowRule> getFlowEntries(DeviceId deviceId) { | 78 | + public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { |
| 82 | return store.getFlowEntries(deviceId); | 79 | return store.getFlowEntries(deviceId); |
| 83 | } | 80 | } |
| 84 | 81 | ||
| ... | @@ -88,7 +85,6 @@ implements FlowRuleService, FlowRuleProviderRegistry { | ... | @@ -88,7 +85,6 @@ implements FlowRuleService, FlowRuleProviderRegistry { |
| 88 | FlowRule f = flowRules[i]; | 85 | FlowRule f = flowRules[i]; |
| 89 | final Device device = deviceService.getDevice(f.deviceId()); | 86 | final Device device = deviceService.getDevice(f.deviceId()); |
| 90 | final FlowRuleProvider frp = getProvider(device.providerId()); | 87 | final FlowRuleProvider frp = getProvider(device.providerId()); |
| 91 | - idleTime.put(f, System.currentTimeMillis()); | ||
| 92 | store.storeFlowRule(f); | 88 | store.storeFlowRule(f); |
| 93 | frp.applyFlowRule(f); | 89 | frp.applyFlowRule(f); |
| 94 | } | 90 | } |
| ... | @@ -103,7 +99,6 @@ implements FlowRuleService, FlowRuleProviderRegistry { | ... | @@ -103,7 +99,6 @@ implements FlowRuleService, FlowRuleProviderRegistry { |
| 103 | f = flowRules[i]; | 99 | f = flowRules[i]; |
| 104 | device = deviceService.getDevice(f.deviceId()); | 100 | device = deviceService.getDevice(f.deviceId()); |
| 105 | frp = getProvider(device.providerId()); | 101 | frp = getProvider(device.providerId()); |
| 106 | - idleTime.remove(f); | ||
| 107 | store.deleteFlowRule(f); | 102 | store.deleteFlowRule(f); |
| 108 | frp.removeFlowRule(f); | 103 | frp.removeFlowRule(f); |
| 109 | } | 104 | } |
| ... | @@ -125,7 +120,7 @@ implements FlowRuleService, FlowRuleProviderRegistry { | ... | @@ -125,7 +120,7 @@ implements FlowRuleService, FlowRuleProviderRegistry { |
| 125 | 120 | ||
| 126 | @Override | 121 | @Override |
| 127 | public Iterable<FlowRule> getFlowRulesById(ApplicationId id) { | 122 | public Iterable<FlowRule> getFlowRulesById(ApplicationId id) { |
| 128 | - return store.getFlowEntriesByAppId(id); | 123 | + return store.getFlowRulesByAppId(id); |
| 129 | } | 124 | } |
| 130 | 125 | ||
| 131 | @Override | 126 | @Override |
| ... | @@ -153,15 +148,15 @@ implements FlowRuleService, FlowRuleProviderRegistry { | ... | @@ -153,15 +148,15 @@ implements FlowRuleService, FlowRuleProviderRegistry { |
| 153 | } | 148 | } |
| 154 | 149 | ||
| 155 | @Override | 150 | @Override |
| 156 | - public void flowRemoved(FlowRule flowRule) { | 151 | + public void flowRemoved(FlowEntry flowEntry) { |
| 157 | - checkNotNull(flowRule, FLOW_RULE_NULL); | 152 | + checkNotNull(flowEntry, FLOW_RULE_NULL); |
| 158 | checkValidity(); | 153 | checkValidity(); |
| 159 | - FlowRule stored = store.getFlowRule(flowRule); | 154 | + FlowEntry stored = store.getFlowEntry(flowEntry); |
| 160 | if (stored == null) { | 155 | if (stored == null) { |
| 161 | - log.info("Rule already evicted from store: {}", flowRule); | 156 | + log.info("Rule already evicted from store: {}", flowEntry); |
| 162 | return; | 157 | return; |
| 163 | } | 158 | } |
| 164 | - Device device = deviceService.getDevice(flowRule.deviceId()); | 159 | + Device device = deviceService.getDevice(flowEntry.deviceId()); |
| 165 | FlowRuleProvider frp = getProvider(device.providerId()); | 160 | FlowRuleProvider frp = getProvider(device.providerId()); |
| 166 | FlowRuleEvent event = null; | 161 | FlowRuleEvent event = null; |
| 167 | switch (stored.state()) { | 162 | switch (stored.state()) { |
| ... | @@ -171,20 +166,20 @@ implements FlowRuleService, FlowRuleProviderRegistry { | ... | @@ -171,20 +166,20 @@ implements FlowRuleService, FlowRuleProviderRegistry { |
| 171 | break; | 166 | break; |
| 172 | case PENDING_REMOVE: | 167 | case PENDING_REMOVE: |
| 173 | case REMOVED: | 168 | case REMOVED: |
| 174 | - event = store.removeFlowRule(flowRule); | 169 | + event = store.removeFlowRule(stored); |
| 175 | break; | 170 | break; |
| 176 | default: | 171 | default: |
| 177 | break; | 172 | break; |
| 178 | 173 | ||
| 179 | } | 174 | } |
| 180 | if (event != null) { | 175 | if (event != null) { |
| 181 | - log.debug("Flow {} removed", flowRule); | 176 | + log.debug("Flow {} removed", flowEntry); |
| 182 | post(event); | 177 | post(event); |
| 183 | } | 178 | } |
| 184 | } | 179 | } |
| 185 | 180 | ||
| 186 | 181 | ||
| 187 | - private void flowMissing(FlowRule flowRule) { | 182 | + private void flowMissing(FlowEntry flowRule) { |
| 188 | checkNotNull(flowRule, FLOW_RULE_NULL); | 183 | checkNotNull(flowRule, FLOW_RULE_NULL); |
| 189 | checkValidity(); | 184 | checkValidity(); |
| 190 | Device device = deviceService.getDevice(flowRule.deviceId()); | 185 | Device device = deviceService.getDevice(flowRule.deviceId()); |
| ... | @@ -220,36 +215,37 @@ implements FlowRuleService, FlowRuleProviderRegistry { | ... | @@ -220,36 +215,37 @@ implements FlowRuleService, FlowRuleProviderRegistry { |
| 220 | } | 215 | } |
| 221 | 216 | ||
| 222 | 217 | ||
| 223 | - private void flowAdded(FlowRule flowRule) { | 218 | + private void flowAdded(FlowEntry flowEntry) { |
| 224 | - checkNotNull(flowRule, FLOW_RULE_NULL); | 219 | + checkNotNull(flowEntry, FLOW_RULE_NULL); |
| 225 | checkValidity(); | 220 | checkValidity(); |
| 226 | 221 | ||
| 227 | - if (idleTime.containsKey(flowRule) && | 222 | + if (checkRuleLiveness(flowEntry, store.getFlowEntry(flowEntry))) { |
| 228 | - checkRuleLiveness(flowRule, store.getFlowRule(flowRule))) { | ||
| 229 | 223 | ||
| 230 | - FlowRuleEvent event = store.addOrUpdateFlowRule(flowRule); | 224 | + FlowRuleEvent event = store.addOrUpdateFlowRule(flowEntry); |
| 231 | if (event == null) { | 225 | if (event == null) { |
| 232 | log.debug("No flow store event generated."); | 226 | log.debug("No flow store event generated."); |
| 233 | } else { | 227 | } else { |
| 234 | - log.debug("Flow {} {}", flowRule, event.type()); | 228 | + log.debug("Flow {} {}", flowEntry, event.type()); |
| 235 | post(event); | 229 | post(event); |
| 236 | } | 230 | } |
| 237 | } else { | 231 | } else { |
| 238 | - removeFlowRules(flowRule); | 232 | + removeFlowRules(flowEntry); |
| 239 | } | 233 | } |
| 240 | 234 | ||
| 241 | } | 235 | } |
| 242 | 236 | ||
| 243 | - private boolean checkRuleLiveness(FlowRule swRule, FlowRule storedRule) { | 237 | + private boolean checkRuleLiveness(FlowEntry swRule, FlowEntry storedRule) { |
| 238 | + if (storedRule == null) { | ||
| 239 | + return false; | ||
| 240 | + } | ||
| 244 | long timeout = storedRule.timeout() * 1000; | 241 | long timeout = storedRule.timeout() * 1000; |
| 245 | Long currentTime = System.currentTimeMillis(); | 242 | Long currentTime = System.currentTimeMillis(); |
| 246 | if (storedRule.packets() != swRule.packets()) { | 243 | if (storedRule.packets() != swRule.packets()) { |
| 247 | - idleTime.put(swRule, currentTime); | 244 | + storedRule.setLastSeen(); |
| 248 | return true; | 245 | return true; |
| 249 | } | 246 | } |
| 250 | 247 | ||
| 251 | - if ((currentTime - idleTime.get(swRule)) <= timeout) { | 248 | + if ((currentTime - storedRule.lastSeen()) <= timeout) { |
| 252 | - idleTime.put(swRule, currentTime); | ||
| 253 | return true; | 249 | return true; |
| 254 | } | 250 | } |
| 255 | return false; | 251 | return false; |
| ... | @@ -263,13 +259,13 @@ implements FlowRuleService, FlowRuleProviderRegistry { | ... | @@ -263,13 +259,13 @@ implements FlowRuleService, FlowRuleProviderRegistry { |
| 263 | } | 259 | } |
| 264 | 260 | ||
| 265 | @Override | 261 | @Override |
| 266 | - public void pushFlowMetrics(DeviceId deviceId, Iterable<FlowRule> flowEntries) { | 262 | + public void pushFlowMetrics(DeviceId deviceId, Iterable<FlowEntry> flowEntries) { |
| 267 | - List<FlowRule> storedRules = Lists.newLinkedList(store.getFlowEntries(deviceId)); | 263 | + List<FlowEntry> storedRules = Lists.newLinkedList(store.getFlowEntries(deviceId)); |
| 268 | 264 | ||
| 269 | - Iterator<FlowRule> switchRulesIterator = flowEntries.iterator(); | 265 | + Iterator<FlowEntry> switchRulesIterator = flowEntries.iterator(); |
| 270 | 266 | ||
| 271 | while (switchRulesIterator.hasNext()) { | 267 | while (switchRulesIterator.hasNext()) { |
| 272 | - FlowRule rule = switchRulesIterator.next(); | 268 | + FlowEntry rule = switchRulesIterator.next(); |
| 273 | if (storedRules.remove(rule)) { | 269 | if (storedRules.remove(rule)) { |
| 274 | // we both have the rule, let's update some info then. | 270 | // we both have the rule, let's update some info then. |
| 275 | flowAdded(rule); | 271 | flowAdded(rule); |
| ... | @@ -278,7 +274,7 @@ implements FlowRuleService, FlowRuleProviderRegistry { | ... | @@ -278,7 +274,7 @@ implements FlowRuleService, FlowRuleProviderRegistry { |
| 278 | extraneousFlow(rule); | 274 | extraneousFlow(rule); |
| 279 | } | 275 | } |
| 280 | } | 276 | } |
| 281 | - for (FlowRule rule : storedRules) { | 277 | + for (FlowEntry rule : storedRules) { |
| 282 | // there are rules in the store that aren't on the switch | 278 | // there are rules in the store that aren't on the switch |
| 283 | flowMissing(rule); | 279 | flowMissing(rule); |
| 284 | 280 | ... | ... |
| ... | @@ -27,9 +27,11 @@ import org.onlab.onos.net.Port; | ... | @@ -27,9 +27,11 @@ import org.onlab.onos.net.Port; |
| 27 | import org.onlab.onos.net.PortNumber; | 27 | import org.onlab.onos.net.PortNumber; |
| 28 | import org.onlab.onos.net.device.DeviceListener; | 28 | import org.onlab.onos.net.device.DeviceListener; |
| 29 | import org.onlab.onos.net.device.DeviceService; | 29 | import org.onlab.onos.net.device.DeviceService; |
| 30 | +import org.onlab.onos.net.flow.DefaultFlowEntry; | ||
| 30 | import org.onlab.onos.net.flow.DefaultFlowRule; | 31 | import org.onlab.onos.net.flow.DefaultFlowRule; |
| 32 | +import org.onlab.onos.net.flow.FlowEntry; | ||
| 33 | +import org.onlab.onos.net.flow.FlowEntry.FlowEntryState; | ||
| 31 | import org.onlab.onos.net.flow.FlowRule; | 34 | import org.onlab.onos.net.flow.FlowRule; |
| 32 | -import org.onlab.onos.net.flow.FlowRule.FlowRuleState; | ||
| 33 | import org.onlab.onos.net.flow.FlowRuleEvent; | 35 | import org.onlab.onos.net.flow.FlowRuleEvent; |
| 34 | import org.onlab.onos.net.flow.FlowRuleListener; | 36 | import org.onlab.onos.net.flow.FlowRuleListener; |
| 35 | import org.onlab.onos.net.flow.FlowRuleProvider; | 37 | import org.onlab.onos.net.flow.FlowRuleProvider; |
| ... | @@ -103,9 +105,6 @@ public class FlowRuleManagerTest { | ... | @@ -103,9 +105,6 @@ public class FlowRuleManagerTest { |
| 103 | return new DefaultFlowRule(DID, ts, tr, 10, appId, TIMEOUT); | 105 | return new DefaultFlowRule(DID, ts, tr, 10, appId, TIMEOUT); |
| 104 | } | 106 | } |
| 105 | 107 | ||
| 106 | - private FlowRule flowRule(FlowRule rule, FlowRuleState state) { | ||
| 107 | - return new DefaultFlowRule(rule, state); | ||
| 108 | - } | ||
| 109 | 108 | ||
| 110 | private FlowRule addFlowRule(int hval) { | 109 | private FlowRule addFlowRule(int hval) { |
| 111 | FlowRule rule = flowRule(hval, hval); | 110 | FlowRule rule = flowRule(hval, hval); |
| ... | @@ -143,24 +142,26 @@ public class FlowRuleManagerTest { | ... | @@ -143,24 +142,26 @@ public class FlowRuleManagerTest { |
| 143 | FlowRule f1 = addFlowRule(1); | 142 | FlowRule f1 = addFlowRule(1); |
| 144 | FlowRule f2 = addFlowRule(2); | 143 | FlowRule f2 = addFlowRule(2); |
| 145 | 144 | ||
| 145 | + FlowEntry fe1 = new DefaultFlowEntry(f1); | ||
| 146 | + FlowEntry fe2 = new DefaultFlowEntry(f2); | ||
| 146 | assertEquals("2 rules should exist", 2, flowCount()); | 147 | assertEquals("2 rules should exist", 2, flowCount()); |
| 147 | 148 | ||
| 148 | - providerService.pushFlowMetrics(DID, ImmutableList.of(f1, f2)); | 149 | + providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2)); |
| 149 | validateEvents(RULE_ADDED, RULE_ADDED); | 150 | validateEvents(RULE_ADDED, RULE_ADDED); |
| 150 | 151 | ||
| 151 | addFlowRule(1); | 152 | addFlowRule(1); |
| 152 | assertEquals("should still be 2 rules", 2, flowCount()); | 153 | assertEquals("should still be 2 rules", 2, flowCount()); |
| 153 | 154 | ||
| 154 | - providerService.pushFlowMetrics(DID, ImmutableList.of(f1)); | 155 | + providerService.pushFlowMetrics(DID, ImmutableList.of(fe1)); |
| 155 | validateEvents(RULE_UPDATED); | 156 | validateEvents(RULE_UPDATED); |
| 156 | } | 157 | } |
| 157 | 158 | ||
| 158 | 159 | ||
| 159 | //backing store is sensitive to the order of additions/removals | 160 | //backing store is sensitive to the order of additions/removals |
| 160 | - private boolean validateState(FlowRuleState... state) { | 161 | + private boolean validateState(FlowEntryState... state) { |
| 161 | - Iterable<FlowRule> rules = service.getFlowEntries(DID); | 162 | + Iterable<FlowEntry> rules = service.getFlowEntries(DID); |
| 162 | int i = 0; | 163 | int i = 0; |
| 163 | - for (FlowRule f : rules) { | 164 | + for (FlowEntry f : rules) { |
| 164 | if (f.state() != state[i]) { | 165 | if (f.state() != state[i]) { |
| 165 | return false; | 166 | return false; |
| 166 | } | 167 | } |
| ... | @@ -181,8 +182,8 @@ public class FlowRuleManagerTest { | ... | @@ -181,8 +182,8 @@ public class FlowRuleManagerTest { |
| 181 | mgr.applyFlowRules(r1, r2, r3); | 182 | mgr.applyFlowRules(r1, r2, r3); |
| 182 | assertEquals("3 rules should exist", 3, flowCount()); | 183 | assertEquals("3 rules should exist", 3, flowCount()); |
| 183 | assertTrue("Entries should be pending add.", | 184 | assertTrue("Entries should be pending add.", |
| 184 | - validateState(FlowRuleState.PENDING_ADD, FlowRuleState.PENDING_ADD, | 185 | + validateState(FlowEntryState.PENDING_ADD, FlowEntryState.PENDING_ADD, |
| 185 | - FlowRuleState.PENDING_ADD)); | 186 | + FlowEntryState.PENDING_ADD)); |
| 186 | } | 187 | } |
| 187 | 188 | ||
| 188 | @Test | 189 | @Test |
| ... | @@ -192,20 +193,21 @@ public class FlowRuleManagerTest { | ... | @@ -192,20 +193,21 @@ public class FlowRuleManagerTest { |
| 192 | FlowRule f3 = addFlowRule(3); | 193 | FlowRule f3 = addFlowRule(3); |
| 193 | assertEquals("3 rules should exist", 3, flowCount()); | 194 | assertEquals("3 rules should exist", 3, flowCount()); |
| 194 | 195 | ||
| 195 | - providerService.pushFlowMetrics(DID, ImmutableList.of(f1, f2, f3)); | 196 | + FlowEntry fe1 = new DefaultFlowEntry(f1); |
| 197 | + FlowEntry fe2 = new DefaultFlowEntry(f2); | ||
| 198 | + FlowEntry fe3 = new DefaultFlowEntry(f3); | ||
| 199 | + providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2, fe3)); | ||
| 196 | validateEvents(RULE_ADDED, RULE_ADDED, RULE_ADDED); | 200 | validateEvents(RULE_ADDED, RULE_ADDED, RULE_ADDED); |
| 197 | 201 | ||
| 198 | - FlowRule rem1 = flowRule(f1, FlowRuleState.REMOVED); | 202 | + mgr.removeFlowRules(f1, f2); |
| 199 | - FlowRule rem2 = flowRule(f2, FlowRuleState.REMOVED); | ||
| 200 | - mgr.removeFlowRules(rem1, rem2); | ||
| 201 | //removing from north, so no events generated | 203 | //removing from north, so no events generated |
| 202 | validateEvents(); | 204 | validateEvents(); |
| 203 | assertEquals("3 rule should exist", 3, flowCount()); | 205 | assertEquals("3 rule should exist", 3, flowCount()); |
| 204 | assertTrue("Entries should be pending remove.", | 206 | assertTrue("Entries should be pending remove.", |
| 205 | - validateState(FlowRuleState.CREATED, FlowRuleState.PENDING_REMOVE, | 207 | + validateState(FlowEntryState.PENDING_REMOVE, FlowEntryState.PENDING_REMOVE, |
| 206 | - FlowRuleState.PENDING_REMOVE)); | 208 | + FlowEntryState.ADDED)); |
| 207 | 209 | ||
| 208 | - mgr.removeFlowRules(rem1); | 210 | + mgr.removeFlowRules(f1); |
| 209 | assertEquals("3 rule should still exist", 3, flowCount()); | 211 | assertEquals("3 rule should still exist", 3, flowCount()); |
| 210 | } | 212 | } |
| 211 | 213 | ||
| ... | @@ -213,21 +215,24 @@ public class FlowRuleManagerTest { | ... | @@ -213,21 +215,24 @@ public class FlowRuleManagerTest { |
| 213 | public void flowRemoved() { | 215 | public void flowRemoved() { |
| 214 | FlowRule f1 = addFlowRule(1); | 216 | FlowRule f1 = addFlowRule(1); |
| 215 | FlowRule f2 = addFlowRule(2); | 217 | FlowRule f2 = addFlowRule(2); |
| 216 | - providerService.pushFlowMetrics(f1.deviceId(), ImmutableList.of(f1, f2)); | 218 | + FlowEntry fe1 = new DefaultFlowEntry(f1); |
| 219 | + FlowEntry fe2 = new DefaultFlowEntry(f2); | ||
| 220 | + providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2)); | ||
| 217 | service.removeFlowRules(f1); | 221 | service.removeFlowRules(f1); |
| 218 | - FlowRule rem1 = flowRule(f1, FlowRuleState.REMOVED); | 222 | + fe1.setState(FlowEntryState.REMOVED); |
| 219 | - providerService.flowRemoved(rem1); | 223 | + providerService.flowRemoved(fe1); |
| 220 | validateEvents(RULE_ADDED, RULE_ADDED, RULE_REMOVED); | 224 | validateEvents(RULE_ADDED, RULE_ADDED, RULE_REMOVED); |
| 221 | 225 | ||
| 222 | - providerService.flowRemoved(rem1); | 226 | + providerService.flowRemoved(fe1); |
| 223 | validateEvents(); | 227 | validateEvents(); |
| 224 | 228 | ||
| 225 | FlowRule f3 = flowRule(3, 3); | 229 | FlowRule f3 = flowRule(3, 3); |
| 230 | + FlowEntry fe3 = new DefaultFlowEntry(f3); | ||
| 226 | service.applyFlowRules(f3); | 231 | service.applyFlowRules(f3); |
| 227 | - providerService.pushFlowMetrics(f3.deviceId(), Collections.singletonList(f3)); | 232 | + providerService.pushFlowMetrics(DID, Collections.singletonList(fe3)); |
| 228 | validateEvents(RULE_ADDED); | 233 | validateEvents(RULE_ADDED); |
| 229 | 234 | ||
| 230 | - providerService.flowRemoved(f3); | 235 | + providerService.flowRemoved(fe3); |
| 231 | validateEvents(); | 236 | validateEvents(); |
| 232 | } | 237 | } |
| 233 | 238 | ||
| ... | @@ -237,17 +242,20 @@ public class FlowRuleManagerTest { | ... | @@ -237,17 +242,20 @@ public class FlowRuleManagerTest { |
| 237 | FlowRule f2 = flowRule(2, 2); | 242 | FlowRule f2 = flowRule(2, 2); |
| 238 | FlowRule f3 = flowRule(3, 3); | 243 | FlowRule f3 = flowRule(3, 3); |
| 239 | 244 | ||
| 245 | + mgr.applyFlowRules(f1, f2, f3); | ||
| 240 | 246 | ||
| 247 | + FlowEntry fe1 = new DefaultFlowEntry(f1); | ||
| 248 | + FlowEntry fe2 = new DefaultFlowEntry(f2); | ||
| 241 | 249 | ||
| 242 | - mgr.applyFlowRules(f1, f2, f3); | ||
| 243 | - FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED); | ||
| 244 | - FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED); | ||
| 245 | 250 | ||
| 246 | - providerService.pushFlowMetrics(DID, Lists.newArrayList(updatedF1, updatedF2)); | 251 | + //FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED); |
| 252 | + //FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED); | ||
| 253 | + | ||
| 254 | + providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2)); | ||
| 247 | 255 | ||
| 248 | assertTrue("Entries should be added.", | 256 | assertTrue("Entries should be added.", |
| 249 | - validateState(FlowRuleState.PENDING_ADD, FlowRuleState.ADDED, | 257 | + validateState(FlowEntryState.ADDED, FlowEntryState.ADDED, |
| 250 | - FlowRuleState.ADDED)); | 258 | + FlowEntryState.PENDING_ADD)); |
| 251 | 259 | ||
| 252 | validateEvents(RULE_ADDED, RULE_ADDED); | 260 | validateEvents(RULE_ADDED, RULE_ADDED); |
| 253 | } | 261 | } |
| ... | @@ -259,11 +267,15 @@ public class FlowRuleManagerTest { | ... | @@ -259,11 +267,15 @@ public class FlowRuleManagerTest { |
| 259 | FlowRule f3 = flowRule(3, 3); | 267 | FlowRule f3 = flowRule(3, 3); |
| 260 | mgr.applyFlowRules(f1, f2); | 268 | mgr.applyFlowRules(f1, f2); |
| 261 | 269 | ||
| 262 | - FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED); | 270 | +// FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED); |
| 263 | - FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED); | 271 | +// FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED); |
| 264 | - FlowRule updatedF3 = flowRule(f3, FlowRuleState.ADDED); | 272 | +// FlowRule updatedF3 = flowRule(f3, FlowRuleState.ADDED); |
| 273 | + FlowEntry fe1 = new DefaultFlowEntry(f1); | ||
| 274 | + FlowEntry fe2 = new DefaultFlowEntry(f2); | ||
| 275 | + FlowEntry fe3 = new DefaultFlowEntry(f3); | ||
| 276 | + | ||
| 265 | 277 | ||
| 266 | - providerService.pushFlowMetrics(DID, Lists.newArrayList(updatedF1, updatedF2, updatedF3)); | 278 | + providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2, fe3)); |
| 267 | 279 | ||
| 268 | validateEvents(RULE_ADDED, RULE_ADDED); | 280 | validateEvents(RULE_ADDED, RULE_ADDED); |
| 269 | 281 | ||
| ... | @@ -279,13 +291,16 @@ public class FlowRuleManagerTest { | ... | @@ -279,13 +291,16 @@ public class FlowRuleManagerTest { |
| 279 | FlowRule f2 = flowRule(2, 2); | 291 | FlowRule f2 = flowRule(2, 2); |
| 280 | FlowRule f3 = flowRule(3, 3); | 292 | FlowRule f3 = flowRule(3, 3); |
| 281 | 293 | ||
| 282 | - FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED); | 294 | +// FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED); |
| 283 | - FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED); | 295 | +// FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED); |
| 296 | + | ||
| 297 | + FlowEntry fe1 = new DefaultFlowEntry(f1); | ||
| 298 | + FlowEntry fe2 = new DefaultFlowEntry(f2); | ||
| 284 | mgr.applyFlowRules(f1, f2, f3); | 299 | mgr.applyFlowRules(f1, f2, f3); |
| 285 | 300 | ||
| 286 | mgr.removeFlowRules(f3); | 301 | mgr.removeFlowRules(f3); |
| 287 | 302 | ||
| 288 | - providerService.pushFlowMetrics(DID, Lists.newArrayList(updatedF1, updatedF2)); | 303 | + providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2)); |
| 289 | 304 | ||
| 290 | validateEvents(RULE_ADDED, RULE_ADDED, RULE_REMOVED); | 305 | validateEvents(RULE_ADDED, RULE_ADDED, RULE_REMOVED); |
| 291 | 306 | ||
| ... | @@ -312,7 +327,7 @@ public class FlowRuleManagerTest { | ... | @@ -312,7 +327,7 @@ public class FlowRuleManagerTest { |
| 312 | 327 | ||
| 313 | //only check that we are in pending remove. Events and actual remove state will | 328 | //only check that we are in pending remove. Events and actual remove state will |
| 314 | // be set by flowRemoved call. | 329 | // be set by flowRemoved call. |
| 315 | - validateState(FlowRuleState.PENDING_REMOVE, FlowRuleState.PENDING_REMOVE); | 330 | + validateState(FlowEntryState.PENDING_REMOVE, FlowEntryState.PENDING_REMOVE); |
| 316 | } | 331 | } |
| 317 | 332 | ||
| 318 | private static class TestListener implements FlowRuleListener { | 333 | private static class TestListener implements FlowRuleListener { | ... | ... |
| 1 | package org.onlab.onos.store.flow.impl; | 1 | package org.onlab.onos.store.flow.impl; |
| 2 | 2 | ||
| 3 | -import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED; | ||
| 4 | import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED; | 3 | import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED; |
| 5 | import static org.slf4j.LoggerFactory.getLogger; | 4 | import static org.slf4j.LoggerFactory.getLogger; |
| 6 | 5 | ||
| ... | @@ -13,9 +12,10 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -13,9 +12,10 @@ import org.apache.felix.scr.annotations.Deactivate; |
| 13 | import org.apache.felix.scr.annotations.Service; | 12 | import org.apache.felix.scr.annotations.Service; |
| 14 | import org.onlab.onos.ApplicationId; | 13 | import org.onlab.onos.ApplicationId; |
| 15 | import org.onlab.onos.net.DeviceId; | 14 | import org.onlab.onos.net.DeviceId; |
| 16 | -import org.onlab.onos.net.flow.DefaultFlowRule; | 15 | +import org.onlab.onos.net.flow.DefaultFlowEntry; |
| 16 | +import org.onlab.onos.net.flow.FlowEntry; | ||
| 17 | +import org.onlab.onos.net.flow.FlowEntry.FlowEntryState; | ||
| 17 | import org.onlab.onos.net.flow.FlowRule; | 18 | import org.onlab.onos.net.flow.FlowRule; |
| 18 | -import org.onlab.onos.net.flow.FlowRule.FlowRuleState; | ||
| 19 | import org.onlab.onos.net.flow.FlowRuleEvent; | 19 | import org.onlab.onos.net.flow.FlowRuleEvent; |
| 20 | import org.onlab.onos.net.flow.FlowRuleEvent.Type; | 20 | import org.onlab.onos.net.flow.FlowRuleEvent.Type; |
| 21 | import org.onlab.onos.net.flow.FlowRuleStore; | 21 | import org.onlab.onos.net.flow.FlowRuleStore; |
| ... | @@ -30,18 +30,18 @@ import com.google.common.collect.Multimap; | ... | @@ -30,18 +30,18 @@ import com.google.common.collect.Multimap; |
| 30 | /** | 30 | /** |
| 31 | * Manages inventory of flow rules using trivial in-memory implementation. | 31 | * Manages inventory of flow rules using trivial in-memory implementation. |
| 32 | */ | 32 | */ |
| 33 | -//FIXME: I LIE I AM NOT DISTRIBUTED | 33 | +//FIXME I LIE. I AIN'T DISTRIBUTED |
| 34 | @Component(immediate = true) | 34 | @Component(immediate = true) |
| 35 | @Service | 35 | @Service |
| 36 | public class DistributedFlowRuleStore | 36 | public class DistributedFlowRuleStore |
| 37 | -extends AbstractStore<FlowRuleEvent, FlowRuleStoreDelegate> | 37 | + extends AbstractStore<FlowRuleEvent, FlowRuleStoreDelegate> |
| 38 | -implements FlowRuleStore { | 38 | + implements FlowRuleStore { |
| 39 | 39 | ||
| 40 | private final Logger log = getLogger(getClass()); | 40 | private final Logger log = getLogger(getClass()); |
| 41 | 41 | ||
| 42 | // store entries as a pile of rules, no info about device tables | 42 | // store entries as a pile of rules, no info about device tables |
| 43 | - private final Multimap<DeviceId, FlowRule> flowEntries = | 43 | + private final Multimap<DeviceId, FlowEntry> flowEntries = |
| 44 | - ArrayListMultimap.<DeviceId, FlowRule>create(); | 44 | + ArrayListMultimap.<DeviceId, FlowEntry>create(); |
| 45 | 45 | ||
| 46 | private final Multimap<ApplicationId, FlowRule> flowEntriesById = | 46 | private final Multimap<ApplicationId, FlowRule> flowEntriesById = |
| 47 | ArrayListMultimap.<ApplicationId, FlowRule>create(); | 47 | ArrayListMultimap.<ApplicationId, FlowRule>create(); |
| ... | @@ -58,8 +58,8 @@ implements FlowRuleStore { | ... | @@ -58,8 +58,8 @@ implements FlowRuleStore { |
| 58 | 58 | ||
| 59 | 59 | ||
| 60 | @Override | 60 | @Override |
| 61 | - public synchronized FlowRule getFlowRule(FlowRule rule) { | 61 | + public synchronized FlowEntry getFlowEntry(FlowRule rule) { |
| 62 | - for (FlowRule f : flowEntries.get(rule.deviceId())) { | 62 | + for (FlowEntry f : flowEntries.get(rule.deviceId())) { |
| 63 | if (f.equals(rule)) { | 63 | if (f.equals(rule)) { |
| 64 | return f; | 64 | return f; |
| 65 | } | 65 | } |
| ... | @@ -68,8 +68,8 @@ implements FlowRuleStore { | ... | @@ -68,8 +68,8 @@ implements FlowRuleStore { |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | @Override | 70 | @Override |
| 71 | - public synchronized Iterable<FlowRule> getFlowEntries(DeviceId deviceId) { | 71 | + public synchronized Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { |
| 72 | - Collection<FlowRule> rules = flowEntries.get(deviceId); | 72 | + Collection<FlowEntry> rules = flowEntries.get(deviceId); |
| 73 | if (rules == null) { | 73 | if (rules == null) { |
| 74 | return Collections.emptyList(); | 74 | return Collections.emptyList(); |
| 75 | } | 75 | } |
| ... | @@ -77,7 +77,7 @@ implements FlowRuleStore { | ... | @@ -77,7 +77,7 @@ implements FlowRuleStore { |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | @Override | 79 | @Override |
| 80 | - public synchronized Iterable<FlowRule> getFlowEntriesByAppId(ApplicationId appId) { | 80 | + public synchronized Iterable<FlowRule> getFlowRulesByAppId(ApplicationId appId) { |
| 81 | Collection<FlowRule> rules = flowEntriesById.get(appId); | 81 | Collection<FlowRule> rules = flowEntriesById.get(appId); |
| 82 | if (rules == null) { | 82 | if (rules == null) { |
| 83 | return Collections.emptyList(); | 83 | return Collections.emptyList(); |
| ... | @@ -87,7 +87,7 @@ implements FlowRuleStore { | ... | @@ -87,7 +87,7 @@ implements FlowRuleStore { |
| 87 | 87 | ||
| 88 | @Override | 88 | @Override |
| 89 | public synchronized void storeFlowRule(FlowRule rule) { | 89 | public synchronized void storeFlowRule(FlowRule rule) { |
| 90 | - FlowRule f = new DefaultFlowRule(rule, FlowRuleState.PENDING_ADD); | 90 | + FlowEntry f = new DefaultFlowEntry(rule); |
| 91 | DeviceId did = f.deviceId(); | 91 | DeviceId did = f.deviceId(); |
| 92 | if (!flowEntries.containsEntry(did, f)) { | 92 | if (!flowEntries.containsEntry(did, f)) { |
| 93 | flowEntries.put(did, f); | 93 | flowEntries.put(did, f); |
| ... | @@ -97,57 +97,41 @@ implements FlowRuleStore { | ... | @@ -97,57 +97,41 @@ implements FlowRuleStore { |
| 97 | 97 | ||
| 98 | @Override | 98 | @Override |
| 99 | public synchronized void deleteFlowRule(FlowRule rule) { | 99 | public synchronized void deleteFlowRule(FlowRule rule) { |
| 100 | - FlowRule f = new DefaultFlowRule(rule, FlowRuleState.PENDING_REMOVE); | 100 | + FlowEntry entry = getFlowEntry(rule); |
| 101 | - DeviceId did = f.deviceId(); | 101 | + if (entry == null) { |
| 102 | - | 102 | + return; |
| 103 | - /* | ||
| 104 | - * find the rule and mark it for deletion. | ||
| 105 | - * Ultimately a flow removed will come remove it. | ||
| 106 | - */ | ||
| 107 | - | ||
| 108 | - if (flowEntries.containsEntry(did, f)) { | ||
| 109 | - //synchronized (flowEntries) { | ||
| 110 | - flowEntries.remove(did, f); | ||
| 111 | - flowEntries.put(did, f); | ||
| 112 | - flowEntriesById.remove(rule.appId(), rule); | ||
| 113 | - //} | ||
| 114 | } | 103 | } |
| 104 | + entry.setState(FlowEntryState.PENDING_REMOVE); | ||
| 115 | } | 105 | } |
| 116 | 106 | ||
| 117 | @Override | 107 | @Override |
| 118 | - public synchronized FlowRuleEvent addOrUpdateFlowRule(FlowRule rule) { | 108 | + public synchronized FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule) { |
| 119 | DeviceId did = rule.deviceId(); | 109 | DeviceId did = rule.deviceId(); |
| 120 | 110 | ||
| 121 | // check if this new rule is an update to an existing entry | 111 | // check if this new rule is an update to an existing entry |
| 122 | - if (flowEntries.containsEntry(did, rule)) { | 112 | + FlowEntry stored = getFlowEntry(rule); |
| 123 | - //synchronized (flowEntries) { | 113 | + if (stored != null) { |
| 124 | - // Multimaps support duplicates so we have to remove our rule | 114 | + stored.setBytes(rule.bytes()); |
| 125 | - // and replace it with the current version. | 115 | + stored.setLife(rule.life()); |
| 126 | - flowEntries.remove(did, rule); | 116 | + stored.setPackets(rule.packets()); |
| 127 | - flowEntries.put(did, rule); | 117 | + if (stored.state() == FlowEntryState.PENDING_ADD) { |
| 128 | - //} | 118 | + stored.setState(FlowEntryState.ADDED); |
| 119 | + return new FlowRuleEvent(Type.RULE_ADDED, rule); | ||
| 120 | + } | ||
| 129 | return new FlowRuleEvent(Type.RULE_UPDATED, rule); | 121 | return new FlowRuleEvent(Type.RULE_UPDATED, rule); |
| 130 | } | 122 | } |
| 131 | 123 | ||
| 132 | flowEntries.put(did, rule); | 124 | flowEntries.put(did, rule); |
| 133 | - return new FlowRuleEvent(RULE_ADDED, rule); | 125 | + return null; |
| 134 | } | 126 | } |
| 135 | 127 | ||
| 136 | @Override | 128 | @Override |
| 137 | - public synchronized FlowRuleEvent removeFlowRule(FlowRule rule) { | 129 | + public synchronized FlowRuleEvent removeFlowRule(FlowEntry rule) { |
| 138 | - //synchronized (this) { | 130 | + // This is where one could mark a rule as removed and still keep it in the store. |
| 139 | if (flowEntries.remove(rule.deviceId(), rule)) { | 131 | if (flowEntries.remove(rule.deviceId(), rule)) { |
| 140 | return new FlowRuleEvent(RULE_REMOVED, rule); | 132 | return new FlowRuleEvent(RULE_REMOVED, rule); |
| 141 | } else { | 133 | } else { |
| 142 | return null; | 134 | return null; |
| 143 | } | 135 | } |
| 144 | - //} | ||
| 145 | } | 136 | } |
| 146 | - | ||
| 147 | - | ||
| 148 | - | ||
| 149 | - | ||
| 150 | - | ||
| 151 | - | ||
| 152 | - | ||
| 153 | } | 137 | } | ... | ... |
| 1 | package org.onlab.onos.store.flow.impl; | 1 | package org.onlab.onos.store.flow.impl; |
| 2 | 2 | ||
| 3 | -import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED; | ||
| 4 | import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED; | 3 | import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED; |
| 5 | import static org.slf4j.LoggerFactory.getLogger; | 4 | import static org.slf4j.LoggerFactory.getLogger; |
| 6 | 5 | ||
| ... | @@ -13,9 +12,10 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -13,9 +12,10 @@ import org.apache.felix.scr.annotations.Deactivate; |
| 13 | import org.apache.felix.scr.annotations.Service; | 12 | import org.apache.felix.scr.annotations.Service; |
| 14 | import org.onlab.onos.ApplicationId; | 13 | import org.onlab.onos.ApplicationId; |
| 15 | import org.onlab.onos.net.DeviceId; | 14 | import org.onlab.onos.net.DeviceId; |
| 16 | -import org.onlab.onos.net.flow.DefaultFlowRule; | 15 | +import org.onlab.onos.net.flow.DefaultFlowEntry; |
| 16 | +import org.onlab.onos.net.flow.FlowEntry; | ||
| 17 | +import org.onlab.onos.net.flow.FlowEntry.FlowEntryState; | ||
| 17 | import org.onlab.onos.net.flow.FlowRule; | 18 | import org.onlab.onos.net.flow.FlowRule; |
| 18 | -import org.onlab.onos.net.flow.FlowRule.FlowRuleState; | ||
| 19 | import org.onlab.onos.net.flow.FlowRuleEvent; | 19 | import org.onlab.onos.net.flow.FlowRuleEvent; |
| 20 | import org.onlab.onos.net.flow.FlowRuleEvent.Type; | 20 | import org.onlab.onos.net.flow.FlowRuleEvent.Type; |
| 21 | import org.onlab.onos.net.flow.FlowRuleStore; | 21 | import org.onlab.onos.net.flow.FlowRuleStore; |
| ... | @@ -28,20 +28,20 @@ import com.google.common.collect.ImmutableSet; | ... | @@ -28,20 +28,20 @@ import com.google.common.collect.ImmutableSet; |
| 28 | import com.google.common.collect.Multimap; | 28 | import com.google.common.collect.Multimap; |
| 29 | 29 | ||
| 30 | /** | 30 | /** |
| 31 | - * TEMPORARY: Manages inventory of flow rules using distributed store implementation. | 31 | + * Manages inventory of flow rules using trivial in-memory implementation. |
| 32 | */ | 32 | */ |
| 33 | -//FIXME: I LIE I AM NOT DISTRIBUTED | 33 | +//FIXME I LIE. I AIN'T DISTRIBUTED |
| 34 | @Component(immediate = true) | 34 | @Component(immediate = true) |
| 35 | @Service | 35 | @Service |
| 36 | public class DistributedFlowRuleStore | 36 | public class DistributedFlowRuleStore |
| 37 | -extends AbstractStore<FlowRuleEvent, FlowRuleStoreDelegate> | 37 | + extends AbstractStore<FlowRuleEvent, FlowRuleStoreDelegate> |
| 38 | -implements FlowRuleStore { | 38 | + implements FlowRuleStore { |
| 39 | 39 | ||
| 40 | private final Logger log = getLogger(getClass()); | 40 | private final Logger log = getLogger(getClass()); |
| 41 | 41 | ||
| 42 | // store entries as a pile of rules, no info about device tables | 42 | // store entries as a pile of rules, no info about device tables |
| 43 | - private final Multimap<DeviceId, FlowRule> flowEntries = | 43 | + private final Multimap<DeviceId, FlowEntry> flowEntries = |
| 44 | - ArrayListMultimap.<DeviceId, FlowRule>create(); | 44 | + ArrayListMultimap.<DeviceId, FlowEntry>create(); |
| 45 | 45 | ||
| 46 | private final Multimap<ApplicationId, FlowRule> flowEntriesById = | 46 | private final Multimap<ApplicationId, FlowRule> flowEntriesById = |
| 47 | ArrayListMultimap.<ApplicationId, FlowRule>create(); | 47 | ArrayListMultimap.<ApplicationId, FlowRule>create(); |
| ... | @@ -58,8 +58,8 @@ implements FlowRuleStore { | ... | @@ -58,8 +58,8 @@ implements FlowRuleStore { |
| 58 | 58 | ||
| 59 | 59 | ||
| 60 | @Override | 60 | @Override |
| 61 | - public synchronized FlowRule getFlowRule(FlowRule rule) { | 61 | + public synchronized FlowEntry getFlowEntry(FlowRule rule) { |
| 62 | - for (FlowRule f : flowEntries.get(rule.deviceId())) { | 62 | + for (FlowEntry f : flowEntries.get(rule.deviceId())) { |
| 63 | if (f.equals(rule)) { | 63 | if (f.equals(rule)) { |
| 64 | return f; | 64 | return f; |
| 65 | } | 65 | } |
| ... | @@ -68,8 +68,8 @@ implements FlowRuleStore { | ... | @@ -68,8 +68,8 @@ implements FlowRuleStore { |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | @Override | 70 | @Override |
| 71 | - public synchronized Iterable<FlowRule> getFlowEntries(DeviceId deviceId) { | 71 | + public synchronized Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { |
| 72 | - Collection<FlowRule> rules = flowEntries.get(deviceId); | 72 | + Collection<FlowEntry> rules = flowEntries.get(deviceId); |
| 73 | if (rules == null) { | 73 | if (rules == null) { |
| 74 | return Collections.emptyList(); | 74 | return Collections.emptyList(); |
| 75 | } | 75 | } |
| ... | @@ -77,7 +77,7 @@ implements FlowRuleStore { | ... | @@ -77,7 +77,7 @@ implements FlowRuleStore { |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | @Override | 79 | @Override |
| 80 | - public synchronized Iterable<FlowRule> getFlowEntriesByAppId(ApplicationId appId) { | 80 | + public synchronized Iterable<FlowRule> getFlowRulesByAppId(ApplicationId appId) { |
| 81 | Collection<FlowRule> rules = flowEntriesById.get(appId); | 81 | Collection<FlowRule> rules = flowEntriesById.get(appId); |
| 82 | if (rules == null) { | 82 | if (rules == null) { |
| 83 | return Collections.emptyList(); | 83 | return Collections.emptyList(); |
| ... | @@ -87,7 +87,7 @@ implements FlowRuleStore { | ... | @@ -87,7 +87,7 @@ implements FlowRuleStore { |
| 87 | 87 | ||
| 88 | @Override | 88 | @Override |
| 89 | public synchronized void storeFlowRule(FlowRule rule) { | 89 | public synchronized void storeFlowRule(FlowRule rule) { |
| 90 | - FlowRule f = new DefaultFlowRule(rule, FlowRuleState.PENDING_ADD); | 90 | + FlowEntry f = new DefaultFlowEntry(rule); |
| 91 | DeviceId did = f.deviceId(); | 91 | DeviceId did = f.deviceId(); |
| 92 | if (!flowEntries.containsEntry(did, f)) { | 92 | if (!flowEntries.containsEntry(did, f)) { |
| 93 | flowEntries.put(did, f); | 93 | flowEntries.put(did, f); |
| ... | @@ -97,57 +97,41 @@ implements FlowRuleStore { | ... | @@ -97,57 +97,41 @@ implements FlowRuleStore { |
| 97 | 97 | ||
| 98 | @Override | 98 | @Override |
| 99 | public synchronized void deleteFlowRule(FlowRule rule) { | 99 | public synchronized void deleteFlowRule(FlowRule rule) { |
| 100 | - FlowRule f = new DefaultFlowRule(rule, FlowRuleState.PENDING_REMOVE); | 100 | + FlowEntry entry = getFlowEntry(rule); |
| 101 | - DeviceId did = f.deviceId(); | 101 | + if (entry == null) { |
| 102 | - | 102 | + return; |
| 103 | - /* | ||
| 104 | - * find the rule and mark it for deletion. | ||
| 105 | - * Ultimately a flow removed will come remove it. | ||
| 106 | - */ | ||
| 107 | - | ||
| 108 | - if (flowEntries.containsEntry(did, f)) { | ||
| 109 | - //synchronized (flowEntries) { | ||
| 110 | - flowEntries.remove(did, f); | ||
| 111 | - flowEntries.put(did, f); | ||
| 112 | - flowEntriesById.remove(rule.appId(), rule); | ||
| 113 | - //} | ||
| 114 | } | 103 | } |
| 104 | + entry.setState(FlowEntryState.PENDING_REMOVE); | ||
| 115 | } | 105 | } |
| 116 | 106 | ||
| 117 | @Override | 107 | @Override |
| 118 | - public synchronized FlowRuleEvent addOrUpdateFlowRule(FlowRule rule) { | 108 | + public synchronized FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule) { |
| 119 | DeviceId did = rule.deviceId(); | 109 | DeviceId did = rule.deviceId(); |
| 120 | 110 | ||
| 121 | // check if this new rule is an update to an existing entry | 111 | // check if this new rule is an update to an existing entry |
| 122 | - if (flowEntries.containsEntry(did, rule)) { | 112 | + FlowEntry stored = getFlowEntry(rule); |
| 123 | - //synchronized (flowEntries) { | 113 | + if (stored != null) { |
| 124 | - // Multimaps support duplicates so we have to remove our rule | 114 | + stored.setBytes(rule.bytes()); |
| 125 | - // and replace it with the current version. | 115 | + stored.setLife(rule.life()); |
| 126 | - flowEntries.remove(did, rule); | 116 | + stored.setPackets(rule.packets()); |
| 127 | - flowEntries.put(did, rule); | 117 | + if (stored.state() == FlowEntryState.PENDING_ADD) { |
| 128 | - //} | 118 | + stored.setState(FlowEntryState.ADDED); |
| 119 | + return new FlowRuleEvent(Type.RULE_ADDED, rule); | ||
| 120 | + } | ||
| 129 | return new FlowRuleEvent(Type.RULE_UPDATED, rule); | 121 | return new FlowRuleEvent(Type.RULE_UPDATED, rule); |
| 130 | } | 122 | } |
| 131 | 123 | ||
| 132 | flowEntries.put(did, rule); | 124 | flowEntries.put(did, rule); |
| 133 | - return new FlowRuleEvent(RULE_ADDED, rule); | 125 | + return null; |
| 134 | } | 126 | } |
| 135 | 127 | ||
| 136 | @Override | 128 | @Override |
| 137 | - public synchronized FlowRuleEvent removeFlowRule(FlowRule rule) { | 129 | + public synchronized FlowRuleEvent removeFlowRule(FlowEntry rule) { |
| 138 | - //synchronized (this) { | 130 | + // This is where one could mark a rule as removed and still keep it in the store. |
| 139 | if (flowEntries.remove(rule.deviceId(), rule)) { | 131 | if (flowEntries.remove(rule.deviceId(), rule)) { |
| 140 | return new FlowRuleEvent(RULE_REMOVED, rule); | 132 | return new FlowRuleEvent(RULE_REMOVED, rule); |
| 141 | } else { | 133 | } else { |
| 142 | return null; | 134 | return null; |
| 143 | } | 135 | } |
| 144 | - //} | ||
| 145 | } | 136 | } |
| 146 | - | ||
| 147 | - | ||
| 148 | - | ||
| 149 | - | ||
| 150 | - | ||
| 151 | - | ||
| 152 | - | ||
| 153 | } | 137 | } | ... | ... |
| ... | @@ -12,9 +12,10 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -12,9 +12,10 @@ import org.apache.felix.scr.annotations.Deactivate; |
| 12 | import org.apache.felix.scr.annotations.Service; | 12 | import org.apache.felix.scr.annotations.Service; |
| 13 | import org.onlab.onos.ApplicationId; | 13 | import org.onlab.onos.ApplicationId; |
| 14 | import org.onlab.onos.net.DeviceId; | 14 | import org.onlab.onos.net.DeviceId; |
| 15 | -import org.onlab.onos.net.flow.DefaultFlowRule; | 15 | +import org.onlab.onos.net.flow.DefaultFlowEntry; |
| 16 | +import org.onlab.onos.net.flow.FlowEntry; | ||
| 17 | +import org.onlab.onos.net.flow.FlowEntry.FlowEntryState; | ||
| 16 | import org.onlab.onos.net.flow.FlowRule; | 18 | import org.onlab.onos.net.flow.FlowRule; |
| 17 | -import org.onlab.onos.net.flow.FlowRule.FlowRuleState; | ||
| 18 | import org.onlab.onos.net.flow.FlowRuleEvent; | 19 | import org.onlab.onos.net.flow.FlowRuleEvent; |
| 19 | import org.onlab.onos.net.flow.FlowRuleEvent.Type; | 20 | import org.onlab.onos.net.flow.FlowRuleEvent.Type; |
| 20 | import org.onlab.onos.net.flow.FlowRuleStore; | 21 | import org.onlab.onos.net.flow.FlowRuleStore; |
| ... | @@ -38,8 +39,8 @@ public class SimpleFlowRuleStore | ... | @@ -38,8 +39,8 @@ public class SimpleFlowRuleStore |
| 38 | private final Logger log = getLogger(getClass()); | 39 | private final Logger log = getLogger(getClass()); |
| 39 | 40 | ||
| 40 | // store entries as a pile of rules, no info about device tables | 41 | // store entries as a pile of rules, no info about device tables |
| 41 | - private final Multimap<DeviceId, FlowRule> flowEntries = | 42 | + private final Multimap<DeviceId, FlowEntry> flowEntries = |
| 42 | - ArrayListMultimap.<DeviceId, FlowRule>create(); | 43 | + ArrayListMultimap.<DeviceId, FlowEntry>create(); |
| 43 | 44 | ||
| 44 | private final Multimap<ApplicationId, FlowRule> flowEntriesById = | 45 | private final Multimap<ApplicationId, FlowRule> flowEntriesById = |
| 45 | ArrayListMultimap.<ApplicationId, FlowRule>create(); | 46 | ArrayListMultimap.<ApplicationId, FlowRule>create(); |
| ... | @@ -56,8 +57,8 @@ public class SimpleFlowRuleStore | ... | @@ -56,8 +57,8 @@ public class SimpleFlowRuleStore |
| 56 | 57 | ||
| 57 | 58 | ||
| 58 | @Override | 59 | @Override |
| 59 | - public synchronized FlowRule getFlowRule(FlowRule rule) { | 60 | + public synchronized FlowEntry getFlowEntry(FlowRule rule) { |
| 60 | - for (FlowRule f : flowEntries.get(rule.deviceId())) { | 61 | + for (FlowEntry f : flowEntries.get(rule.deviceId())) { |
| 61 | if (f.equals(rule)) { | 62 | if (f.equals(rule)) { |
| 62 | return f; | 63 | return f; |
| 63 | } | 64 | } |
| ... | @@ -66,8 +67,8 @@ public class SimpleFlowRuleStore | ... | @@ -66,8 +67,8 @@ public class SimpleFlowRuleStore |
| 66 | } | 67 | } |
| 67 | 68 | ||
| 68 | @Override | 69 | @Override |
| 69 | - public synchronized Iterable<FlowRule> getFlowEntries(DeviceId deviceId) { | 70 | + public synchronized Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { |
| 70 | - Collection<FlowRule> rules = flowEntries.get(deviceId); | 71 | + Collection<FlowEntry> rules = flowEntries.get(deviceId); |
| 71 | if (rules == null) { | 72 | if (rules == null) { |
| 72 | return Collections.emptyList(); | 73 | return Collections.emptyList(); |
| 73 | } | 74 | } |
| ... | @@ -75,7 +76,7 @@ public class SimpleFlowRuleStore | ... | @@ -75,7 +76,7 @@ public class SimpleFlowRuleStore |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | @Override | 78 | @Override |
| 78 | - public synchronized Iterable<FlowRule> getFlowEntriesByAppId(ApplicationId appId) { | 79 | + public synchronized Iterable<FlowRule> getFlowRulesByAppId(ApplicationId appId) { |
| 79 | Collection<FlowRule> rules = flowEntriesById.get(appId); | 80 | Collection<FlowRule> rules = flowEntriesById.get(appId); |
| 80 | if (rules == null) { | 81 | if (rules == null) { |
| 81 | return Collections.emptyList(); | 82 | return Collections.emptyList(); |
| ... | @@ -85,7 +86,7 @@ public class SimpleFlowRuleStore | ... | @@ -85,7 +86,7 @@ public class SimpleFlowRuleStore |
| 85 | 86 | ||
| 86 | @Override | 87 | @Override |
| 87 | public synchronized void storeFlowRule(FlowRule rule) { | 88 | public synchronized void storeFlowRule(FlowRule rule) { |
| 88 | - FlowRule f = new DefaultFlowRule(rule, FlowRuleState.PENDING_ADD); | 89 | + FlowEntry f = new DefaultFlowEntry(rule); |
| 89 | DeviceId did = f.deviceId(); | 90 | DeviceId did = f.deviceId(); |
| 90 | if (!flowEntries.containsEntry(did, f)) { | 91 | if (!flowEntries.containsEntry(did, f)) { |
| 91 | flowEntries.put(did, f); | 92 | flowEntries.put(did, f); |
| ... | @@ -95,34 +96,25 @@ public class SimpleFlowRuleStore | ... | @@ -95,34 +96,25 @@ public class SimpleFlowRuleStore |
| 95 | 96 | ||
| 96 | @Override | 97 | @Override |
| 97 | public synchronized void deleteFlowRule(FlowRule rule) { | 98 | public synchronized void deleteFlowRule(FlowRule rule) { |
| 98 | - FlowRule f = new DefaultFlowRule(rule, FlowRuleState.PENDING_REMOVE); | 99 | + FlowEntry entry = getFlowEntry(rule); |
| 99 | - DeviceId did = f.deviceId(); | 100 | + if (entry == null) { |
| 100 | - | 101 | + return; |
| 101 | - /* | ||
| 102 | - * find the rule and mark it for deletion. | ||
| 103 | - * Ultimately a flow removed will come remove it. | ||
| 104 | - */ | ||
| 105 | - | ||
| 106 | - if (flowEntries.containsEntry(did, f)) { | ||
| 107 | - flowEntries.remove(did, f); | ||
| 108 | - flowEntries.put(did, f); | ||
| 109 | - flowEntriesById.remove(rule.appId(), rule); | ||
| 110 | } | 102 | } |
| 103 | + entry.setState(FlowEntryState.PENDING_REMOVE); | ||
| 111 | } | 104 | } |
| 112 | 105 | ||
| 113 | @Override | 106 | @Override |
| 114 | - public synchronized FlowRuleEvent addOrUpdateFlowRule(FlowRule rule) { | 107 | + public synchronized FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule) { |
| 115 | DeviceId did = rule.deviceId(); | 108 | DeviceId did = rule.deviceId(); |
| 116 | 109 | ||
| 117 | // check if this new rule is an update to an existing entry | 110 | // check if this new rule is an update to an existing entry |
| 118 | - FlowRule stored = getFlowRule(rule); | 111 | + FlowEntry stored = getFlowEntry(rule); |
| 119 | if (stored != null) { | 112 | if (stored != null) { |
| 120 | - // Multimaps support duplicates so we have to remove our rule | 113 | + stored.setBytes(rule.bytes()); |
| 121 | - // and replace it with the current version. | 114 | + stored.setLife(rule.life()); |
| 122 | - flowEntries.remove(did, rule); | 115 | + stored.setPackets(rule.packets()); |
| 123 | - flowEntries.put(did, rule); | 116 | + if (stored.state() == FlowEntryState.PENDING_ADD) { |
| 124 | - | 117 | + stored.setState(FlowEntryState.ADDED); |
| 125 | - if (stored.state() == FlowRuleState.PENDING_ADD) { | ||
| 126 | return new FlowRuleEvent(Type.RULE_ADDED, rule); | 118 | return new FlowRuleEvent(Type.RULE_ADDED, rule); |
| 127 | } | 119 | } |
| 128 | return new FlowRuleEvent(Type.RULE_UPDATED, rule); | 120 | return new FlowRuleEvent(Type.RULE_UPDATED, rule); |
| ... | @@ -133,13 +125,12 @@ public class SimpleFlowRuleStore | ... | @@ -133,13 +125,12 @@ public class SimpleFlowRuleStore |
| 133 | } | 125 | } |
| 134 | 126 | ||
| 135 | @Override | 127 | @Override |
| 136 | - public synchronized FlowRuleEvent removeFlowRule(FlowRule rule) { | 128 | + public synchronized FlowRuleEvent removeFlowRule(FlowEntry rule) { |
| 137 | - //synchronized (this) { | 129 | + // This is where one could mark a rule as removed and still keep it in the store. |
| 138 | if (flowEntries.remove(rule.deviceId(), rule)) { | 130 | if (flowEntries.remove(rule.deviceId(), rule)) { |
| 139 | return new FlowRuleEvent(RULE_REMOVED, rule); | 131 | return new FlowRuleEvent(RULE_REMOVED, rule); |
| 140 | } else { | 132 | } else { |
| 141 | return null; | 133 | return null; |
| 142 | } | 134 | } |
| 143 | - //} | ||
| 144 | } | 135 | } |
| 145 | } | 136 | } | ... | ... |
| ... | @@ -6,11 +6,13 @@ import java.util.List; | ... | @@ -6,11 +6,13 @@ import java.util.List; |
| 6 | 6 | ||
| 7 | import org.onlab.onos.net.DeviceId; | 7 | import org.onlab.onos.net.DeviceId; |
| 8 | import org.onlab.onos.net.PortNumber; | 8 | import org.onlab.onos.net.PortNumber; |
| 9 | +import org.onlab.onos.net.flow.DefaultFlowEntry; | ||
| 9 | import org.onlab.onos.net.flow.DefaultFlowRule; | 10 | import org.onlab.onos.net.flow.DefaultFlowRule; |
| 10 | import org.onlab.onos.net.flow.DefaultTrafficSelector; | 11 | import org.onlab.onos.net.flow.DefaultTrafficSelector; |
| 11 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; | 12 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
| 13 | +import org.onlab.onos.net.flow.FlowEntry; | ||
| 14 | +import org.onlab.onos.net.flow.FlowEntry.FlowEntryState; | ||
| 12 | import org.onlab.onos.net.flow.FlowRule; | 15 | import org.onlab.onos.net.flow.FlowRule; |
| 13 | -import org.onlab.onos.net.flow.FlowRule.FlowRuleState; | ||
| 14 | import org.onlab.onos.net.flow.TrafficSelector; | 16 | import org.onlab.onos.net.flow.TrafficSelector; |
| 15 | import org.onlab.onos.net.flow.TrafficTreatment; | 17 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 16 | import org.onlab.onos.openflow.controller.Dpid; | 18 | import org.onlab.onos.openflow.controller.Dpid; |
| ... | @@ -37,7 +39,7 @@ import org.slf4j.Logger; | ... | @@ -37,7 +39,7 @@ import org.slf4j.Logger; |
| 37 | 39 | ||
| 38 | import com.google.common.collect.Lists; | 40 | import com.google.common.collect.Lists; |
| 39 | 41 | ||
| 40 | -public class FlowRuleBuilder { | 42 | +public class FlowEntryBuilder { |
| 41 | private final Logger log = getLogger(getClass()); | 43 | private final Logger log = getLogger(getClass()); |
| 42 | 44 | ||
| 43 | private final OFFlowStatsEntry stat; | 45 | private final OFFlowStatsEntry stat; |
| ... | @@ -51,7 +53,7 @@ public class FlowRuleBuilder { | ... | @@ -51,7 +53,7 @@ public class FlowRuleBuilder { |
| 51 | private final boolean addedRule; | 53 | private final boolean addedRule; |
| 52 | 54 | ||
| 53 | 55 | ||
| 54 | - public FlowRuleBuilder(Dpid dpid, OFFlowStatsEntry entry) { | 56 | + public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) { |
| 55 | this.stat = entry; | 57 | this.stat = entry; |
| 56 | this.match = entry.getMatch(); | 58 | this.match = entry.getMatch(); |
| 57 | this.actions = getActions(entry); | 59 | this.actions = getActions(entry); |
| ... | @@ -60,7 +62,7 @@ public class FlowRuleBuilder { | ... | @@ -60,7 +62,7 @@ public class FlowRuleBuilder { |
| 60 | this.addedRule = true; | 62 | this.addedRule = true; |
| 61 | } | 63 | } |
| 62 | 64 | ||
| 63 | - public FlowRuleBuilder(Dpid dpid, OFFlowRemoved removed) { | 65 | + public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) { |
| 64 | this.match = removed.getMatch(); | 66 | this.match = removed.getMatch(); |
| 65 | this.removed = removed; | 67 | this.removed = removed; |
| 66 | 68 | ||
| ... | @@ -71,20 +73,21 @@ public class FlowRuleBuilder { | ... | @@ -71,20 +73,21 @@ public class FlowRuleBuilder { |
| 71 | 73 | ||
| 72 | } | 74 | } |
| 73 | 75 | ||
| 74 | - public FlowRule build() { | 76 | + public FlowEntry build() { |
| 75 | if (addedRule) { | 77 | if (addedRule) { |
| 76 | - return new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), | 78 | + FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), |
| 77 | buildSelector(), buildTreatment(), stat.getPriority(), | 79 | buildSelector(), buildTreatment(), stat.getPriority(), |
| 78 | - FlowRuleState.ADDED, stat.getDurationSec(), | ||
| 79 | - stat.getPacketCount().getValue(), stat.getByteCount().getValue(), | ||
| 80 | stat.getCookie().getValue(), stat.getIdleTimeout()); | 80 | stat.getCookie().getValue(), stat.getIdleTimeout()); |
| 81 | + return new DefaultFlowEntry(rule, FlowEntryState.ADDED, | ||
| 82 | + stat.getDurationSec(), stat.getPacketCount().getValue(), | ||
| 83 | + stat.getByteCount().getValue()); | ||
| 84 | + | ||
| 81 | } else { | 85 | } else { |
| 82 | - // TODO: revisit potentially. | 86 | + FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), |
| 83 | - return new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), | ||
| 84 | buildSelector(), null, removed.getPriority(), | 87 | buildSelector(), null, removed.getPriority(), |
| 85 | - FlowRuleState.REMOVED, removed.getDurationSec(), | 88 | + removed.getCookie().getValue(), removed.getIdleTimeout()); |
| 86 | - removed.getPacketCount().getValue(), removed.getByteCount().getValue(), | 89 | + return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(), |
| 87 | - removed.getCookie().getValue(), removed.getIdleTimeout()); | 90 | + removed.getPacketCount().getValue(), removed.getByteCount().getValue()); |
| 88 | } | 91 | } |
| 89 | } | 92 | } |
| 90 | 93 | ... | ... |
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/OpenFlowRuleProvider.java
| ... | @@ -12,6 +12,7 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -12,6 +12,7 @@ import org.apache.felix.scr.annotations.Reference; |
| 12 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 12 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 13 | import org.onlab.onos.ApplicationId; | 13 | import org.onlab.onos.ApplicationId; |
| 14 | import org.onlab.onos.net.DeviceId; | 14 | import org.onlab.onos.net.DeviceId; |
| 15 | +import org.onlab.onos.net.flow.FlowEntry; | ||
| 15 | import org.onlab.onos.net.flow.FlowRule; | 16 | import org.onlab.onos.net.flow.FlowRule; |
| 16 | import org.onlab.onos.net.flow.FlowRuleProvider; | 17 | import org.onlab.onos.net.flow.FlowRuleProvider; |
| 17 | import org.onlab.onos.net.flow.FlowRuleProviderRegistry; | 18 | import org.onlab.onos.net.flow.FlowRuleProviderRegistry; |
| ... | @@ -131,7 +132,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -131,7 +132,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
| 131 | implements OpenFlowSwitchListener, OpenFlowEventListener { | 132 | implements OpenFlowSwitchListener, OpenFlowEventListener { |
| 132 | 133 | ||
| 133 | private final Map<Dpid, FlowStatsCollector> collectors = Maps.newHashMap(); | 134 | private final Map<Dpid, FlowStatsCollector> collectors = Maps.newHashMap(); |
| 134 | - private final Multimap<DeviceId, FlowRule> completeEntries = | 135 | + private final Multimap<DeviceId, FlowEntry> completeEntries = |
| 135 | ArrayListMultimap.create(); | 136 | ArrayListMultimap.create(); |
| 136 | 137 | ||
| 137 | @Override | 138 | @Override |
| ... | @@ -158,7 +159,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -158,7 +159,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
| 158 | //TODO: make this better | 159 | //TODO: make this better |
| 159 | OFFlowRemoved removed = (OFFlowRemoved) msg; | 160 | OFFlowRemoved removed = (OFFlowRemoved) msg; |
| 160 | 161 | ||
| 161 | - FlowRule fr = new FlowRuleBuilder(dpid, removed).build(); | 162 | + FlowEntry fr = new FlowEntryBuilder(dpid, removed).build(); |
| 162 | providerService.flowRemoved(fr); | 163 | providerService.flowRemoved(fr); |
| 163 | break; | 164 | break; |
| 164 | case STATS_REPLY: | 165 | case STATS_REPLY: |
| ... | @@ -188,7 +189,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -188,7 +189,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
| 188 | 189 | ||
| 189 | for (OFFlowStatsEntry reply : replies.getEntries()) { | 190 | for (OFFlowStatsEntry reply : replies.getEntries()) { |
| 190 | if (!tableMissRule(dpid, reply)) { | 191 | if (!tableMissRule(dpid, reply)) { |
| 191 | - completeEntries.put(did, new FlowRuleBuilder(dpid, reply).build()); | 192 | + completeEntries.put(did, new FlowEntryBuilder(dpid, reply).build()); |
| 192 | } | 193 | } |
| 193 | } | 194 | } |
| 194 | 195 | ... | ... |
-
Please register or login to post a comment