Jonathan Hart

Allowed flows to be permanent

Change-Id: I61952fe4cbad98be53094c7ec4a474868384b616
1 package org.onlab.onos.fwd; 1 package org.onlab.onos.fwd;
2 2
3 +import static org.slf4j.LoggerFactory.getLogger;
4 +
5 +import java.util.Dictionary;
6 +import java.util.Set;
7 +
3 import org.apache.felix.scr.annotations.Activate; 8 import org.apache.felix.scr.annotations.Activate;
4 import org.apache.felix.scr.annotations.Component; 9 import org.apache.felix.scr.annotations.Component;
5 import org.apache.felix.scr.annotations.Deactivate; 10 import org.apache.felix.scr.annotations.Deactivate;
...@@ -30,11 +35,6 @@ import org.onlab.packet.Ethernet; ...@@ -30,11 +35,6 @@ import org.onlab.packet.Ethernet;
30 import org.osgi.service.component.ComponentContext; 35 import org.osgi.service.component.ComponentContext;
31 import org.slf4j.Logger; 36 import org.slf4j.Logger;
32 37
33 -import java.util.Dictionary;
34 -import java.util.Set;
35 -
36 -import static org.slf4j.LoggerFactory.getLogger;
37 -
38 /** 38 /**
39 * Sample reactive forwarding application. 39 * Sample reactive forwarding application.
40 */ 40 */
...@@ -206,7 +206,7 @@ public class ReactiveForwarding { ...@@ -206,7 +206,7 @@ public class ReactiveForwarding {
206 treat.setOutput(portNumber); 206 treat.setOutput(portNumber);
207 207
208 FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(), 208 FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(),
209 - builder.build(), treat.build(), PRIORITY, appId, TIMEOUT); 209 + builder.build(), treat.build(), PRIORITY, appId, TIMEOUT, false);
210 210
211 flowRuleService.applyFlowRules(f); 211 flowRuleService.applyFlowRules(f);
212 } 212 }
......
...@@ -27,7 +27,7 @@ public class DefaultFlowEntry extends DefaultFlowRule ...@@ -27,7 +27,7 @@ public class DefaultFlowEntry extends DefaultFlowRule
27 TrafficTreatment treatment, int priority, FlowEntryState state, 27 TrafficTreatment treatment, int priority, FlowEntryState state,
28 long life, long packets, long bytes, long flowId, 28 long life, long packets, long bytes, long flowId,
29 int timeout) { 29 int timeout) {
30 - super(deviceId, selector, treatment, priority, flowId, timeout); 30 + super(deviceId, selector, treatment, priority, flowId, timeout, false);
31 this.state = state; 31 this.state = state;
32 this.life = life; 32 this.life = life;
33 this.packets = packets; 33 this.packets = packets;
......
...@@ -24,16 +24,18 @@ public class DefaultFlowRule implements FlowRule { ...@@ -24,16 +24,18 @@ public class DefaultFlowRule implements FlowRule {
24 private final short appId; 24 private final short appId;
25 25
26 private final int timeout; 26 private final int timeout;
27 + private final boolean permanent;
27 28
28 29
29 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, 30 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
30 TrafficTreatment treatment, int priority, long flowId, 31 TrafficTreatment treatment, int priority, long flowId,
31 - int timeout) { 32 + int timeout, boolean permanent) {
32 this.deviceId = deviceId; 33 this.deviceId = deviceId;
33 this.priority = priority; 34 this.priority = priority;
34 this.selector = selector; 35 this.selector = selector;
35 this.treatment = treatment; 36 this.treatment = treatment;
36 this.timeout = timeout; 37 this.timeout = timeout;
38 + this.permanent = permanent;
37 this.created = System.currentTimeMillis(); 39 this.created = System.currentTimeMillis();
38 40
39 this.appId = (short) (flowId >>> 48); 41 this.appId = (short) (flowId >>> 48);
...@@ -42,7 +44,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -42,7 +44,7 @@ public class DefaultFlowRule implements FlowRule {
42 44
43 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, 45 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
44 TrafficTreatment treatement, int priority, ApplicationId appId, 46 TrafficTreatment treatement, int priority, ApplicationId appId,
45 - int timeout) { 47 + int timeout, boolean permanent) {
46 48
47 if (priority < FlowRule.MIN_PRIORITY) { 49 if (priority < FlowRule.MIN_PRIORITY) {
48 throw new IllegalArgumentException("Priority cannot be less than " + MIN_PRIORITY); 50 throw new IllegalArgumentException("Priority cannot be less than " + MIN_PRIORITY);
...@@ -54,6 +56,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -54,6 +56,7 @@ public class DefaultFlowRule implements FlowRule {
54 this.treatment = treatement; 56 this.treatment = treatement;
55 this.appId = appId.id(); 57 this.appId = appId.id();
56 this.timeout = timeout; 58 this.timeout = timeout;
59 + this.permanent = permanent;
57 this.created = System.currentTimeMillis(); 60 this.created = System.currentTimeMillis();
58 61
59 this.id = FlowId.valueOf((((long) this.appId) << 48) | (this.hash() & 0x0000ffffffffL)); 62 this.id = FlowId.valueOf((((long) this.appId) << 48) | (this.hash() & 0x0000ffffffffL));
...@@ -67,6 +70,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -67,6 +70,7 @@ public class DefaultFlowRule implements FlowRule {
67 this.appId = rule.appId(); 70 this.appId = rule.appId();
68 this.id = rule.id(); 71 this.id = rule.id();
69 this.timeout = rule.timeout(); 72 this.timeout = rule.timeout();
73 + this.permanent = rule.isPermanent();
70 this.created = System.currentTimeMillis(); 74 this.created = System.currentTimeMillis();
71 75
72 } 76 }
...@@ -157,4 +161,9 @@ public class DefaultFlowRule implements FlowRule { ...@@ -157,4 +161,9 @@ public class DefaultFlowRule implements FlowRule {
157 return timeout; 161 return timeout;
158 } 162 }
159 163
164 + @Override
165 + public boolean isPermanent() {
166 + return permanent;
167 + }
168 +
160 } 169 }
......
...@@ -59,8 +59,16 @@ public interface FlowRule extends BatchOperationTarget { ...@@ -59,8 +59,16 @@ public interface FlowRule extends BatchOperationTarget {
59 59
60 /** 60 /**
61 * Returns the timeout for this flow requested by an application. 61 * Returns the timeout for this flow requested by an application.
62 + *
62 * @return integer value of the timeout 63 * @return integer value of the timeout
63 */ 64 */
64 int timeout(); 65 int timeout();
65 66
67 + /**
68 + * Returns whether the flow is permanent i.e. does not time out.
69 + *
70 + * @return true if the flow is permanent, otherwise false
71 + */
72 + boolean isPermanent();
73 +
66 } 74 }
......
...@@ -327,6 +327,10 @@ public class FlowRuleManager ...@@ -327,6 +327,10 @@ public class FlowRuleManager
327 if (storedRule == null) { 327 if (storedRule == null) {
328 return false; 328 return false;
329 } 329 }
330 + if (storedRule.isPermanent()) {
331 + return true;
332 + }
333 +
330 final long timeout = storedRule.timeout() * 1000; 334 final long timeout = storedRule.timeout() * 1000;
331 final long currentTime = System.currentTimeMillis(); 335 final long currentTime = System.currentTimeMillis();
332 if (storedRule.packets() != swRule.packets()) { 336 if (storedRule.packets() != swRule.packets()) {
......
...@@ -117,7 +117,7 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec ...@@ -117,7 +117,7 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec
117 TrafficTreatment treatment = builder().setOutput(outPort).build(); 117 TrafficTreatment treatment = builder().setOutput(outPort).build();
118 118
119 FlowRule rule = new DefaultFlowRule(deviceId, 119 FlowRule rule = new DefaultFlowRule(deviceId,
120 - selector, treatment, 123, appId, 600); 120 + selector, treatment, 123, appId, 0, true);
121 121
122 return new FlowRuleBatchEntry(operation, rule); 122 return new FlowRuleBatchEntry(operation, rule);
123 } 123 }
......
...@@ -73,7 +73,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -73,7 +73,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
73 73
74 FlowRule rule = new DefaultFlowRule(link.src().deviceId(), 74 FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
75 builder.build(), treatment, 75 builder.build(), treatment,
76 - 123, appId, 15); 76 + 123, appId, 0, true);
77 rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule)); 77 rules.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, rule));
78 prev = link.dst(); 78 prev = link.dst();
79 } 79 }
...@@ -95,7 +95,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -95,7 +95,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
95 .setOutput(link.src().port()).build(); 95 .setOutput(link.src().port()).build();
96 FlowRule rule = new DefaultFlowRule(link.src().deviceId(), 96 FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
97 builder.build(), treatment, 97 builder.build(), treatment,
98 - 123, appId, 600); 98 + 123, appId, 0, true);
99 rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, rule)); 99 rules.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, rule));
100 prev = link.dst(); 100 prev = link.dst();
101 } 101 }
......
1 package org.onlab.onos.net.flow.impl; 1 package org.onlab.onos.net.flow.impl;
2 2
3 import static java.util.Collections.EMPTY_LIST; 3 import static java.util.Collections.EMPTY_LIST;
4 -import static org.junit.Assert.*; 4 +import static org.junit.Assert.assertEquals;
5 +import static org.junit.Assert.assertFalse;
6 +import static org.junit.Assert.assertNotNull;
7 +import static org.junit.Assert.assertTrue;
8 +import static org.junit.Assert.fail;
5 import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED; 9 import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED;
6 import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED; 10 import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
7 import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_UPDATED; 11 import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_UPDATED;
...@@ -115,7 +119,7 @@ public class FlowRuleManagerTest { ...@@ -115,7 +119,7 @@ public class FlowRuleManagerTest {
115 private FlowRule flowRule(int tsval, int trval) { 119 private FlowRule flowRule(int tsval, int trval) {
116 TestSelector ts = new TestSelector(tsval); 120 TestSelector ts = new TestSelector(tsval);
117 TestTreatment tr = new TestTreatment(trval); 121 TestTreatment tr = new TestTreatment(trval);
118 - return new DefaultFlowRule(DID, ts, tr, 10, appId, TIMEOUT); 122 + return new DefaultFlowRule(DID, ts, tr, 10, appId, TIMEOUT, false);
119 } 123 }
120 124
121 125
......
...@@ -78,7 +78,7 @@ public class FlowEntryBuilder { ...@@ -78,7 +78,7 @@ public class FlowEntryBuilder {
78 if (addedRule) { 78 if (addedRule) {
79 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), 79 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
80 buildSelector(), buildTreatment(), stat.getPriority(), 80 buildSelector(), buildTreatment(), stat.getPriority(),
81 - stat.getCookie().getValue(), stat.getIdleTimeout()); 81 + stat.getCookie().getValue(), stat.getIdleTimeout(), false);
82 return new DefaultFlowEntry(rule, FlowEntryState.ADDED, 82 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
83 stat.getDurationSec(), stat.getPacketCount().getValue(), 83 stat.getDurationSec(), stat.getPacketCount().getValue(),
84 stat.getByteCount().getValue()); 84 stat.getByteCount().getValue());
...@@ -86,7 +86,7 @@ public class FlowEntryBuilder { ...@@ -86,7 +86,7 @@ public class FlowEntryBuilder {
86 } else { 86 } else {
87 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), 87 FlowRule rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
88 buildSelector(), null, removed.getPriority(), 88 buildSelector(), null, removed.getPriority(),
89 - removed.getCookie().getValue(), removed.getIdleTimeout()); 89 + removed.getCookie().getValue(), removed.getIdleTimeout(), false);
90 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(), 90 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
91 removed.getPacketCount().getValue(), removed.getByteCount().getValue()); 91 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
92 } 92 }
......