illegalArgument exception for priority
Change-Id: I9bce0b677b937ee691ac24c13c88a632cfb2339e
diff --git a/apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java b/apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java
index 564a2da..5857438 100644
--- a/apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java
+++ b/apps/fwd/src/main/java/org/onlab/onos/fwd/ReactiveForwarding.java
@@ -39,6 +39,7 @@
public class ReactiveForwarding {
private static final int TIMEOUT = 10;
+ private static final int PRIORITY = 10;
private final Logger log = getLogger(getClass());
@@ -194,7 +195,7 @@
treat.setOutput(portNumber);
FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(),
- builder.build(), treat.build(), 0, appId, TIMEOUT);
+ builder.build(), treat.build(), PRIORITY, appId, TIMEOUT);
flowRuleService.applyFlowRules(f);
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
index 41f30a7..d49ae6e 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
@@ -96,7 +96,7 @@
}
for (FlowRule f : flows) {
print(FMT, Long.toHexString(f.id().value()), f.state(), f.bytes(),
- f.packets(), f.lifeMillis(), f.priority());
+ f.packets(), f.life(), f.priority());
print(SFMT, f.selector().criteria());
print(TFMT, f.treatment().instructions());
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
index d489870..9b44fc2 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
@@ -29,9 +29,23 @@
private final int timeout;
+ /**
+ * Creates a flow rule given the following paremeters.
+ * @param deviceId the device where the rule should be installed
+ * @param selector the traffic selection
+ * @param treatment how the seleted traffic should be handled
+ * @param priority the rule priority cannot be less than FlowRule.MIN_PRIORITY
+ * @param state the state in which the rule is
+ * @param life how long it has existed for (ms)
+ * @param packets number of packets it has seen
+ * @param bytes number of bytes it has seen
+ * @param flowId the identifier
+ * @param timeout the rule's timeout (idle) not to exceed
+ * FlowRule.MAX_TIMEOUT of idle time
+ */
public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
TrafficTreatment treatment, int priority, FlowRuleState state,
- long life, long packets, long bytes, long flowId, boolean expired,
+ long life, long packets, long bytes, long flowId,
int timeout) {
this.deviceId = deviceId;
this.priority = priority;
@@ -50,8 +64,7 @@
public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
TrafficTreatment treatement, int priority, ApplicationId appId,
int timeout) {
-
- this(deviceId, selector, treatement, priority == 0 ? 1 : priority,
+ this(deviceId, selector, treatement, priority,
FlowRuleState.CREATED, appId, timeout);
}
@@ -65,6 +78,9 @@
TrafficSelector selector, TrafficTreatment treatment,
int priority, FlowRuleState state, ApplicationId appId,
int timeout) {
+ if (priority < MIN_PRIORITY) {
+ throw new IllegalArgumentException("Priority cannot be less than " + MIN_PRIORITY);
+ }
this.deviceId = deviceId;
this.priority = priority;
this.selector = selector;
@@ -131,7 +147,7 @@
}
@Override
- public long lifeMillis() {
+ public long life() {
return life;
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java
index 4d1b3cf..9b76f32 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java
@@ -10,6 +10,7 @@
public interface FlowRule {
static final int MAX_TIMEOUT = 60;
+ static final int MIN_PRIORITY = 0;
public enum FlowRuleState {
/**
@@ -96,7 +97,7 @@
*
* @return number of millis
*/
- long lifeMillis();
+ long life();
/**
* Returns the number of packets this flow rule has matched.
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/PathIntentInstaller.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/PathIntentInstaller.java
index 6aa9f66..84e8c79 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/PathIntentInstaller.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/PathIntentInstaller.java
@@ -1,5 +1,7 @@
package org.onlab.onos.net.intent.impl;
+import java.util.Iterator;
+
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -19,8 +21,6 @@
import org.onlab.onos.net.intent.IntentInstaller;
import org.onlab.onos.net.intent.PathIntent;
-import java.util.Iterator;
-
/**
* Installer for {@link PathIntent path connectivity intents}.
*/
@@ -60,7 +60,7 @@
FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
builder.build(), treat.build(),
- 0, appId, 30);
+ 10, appId, 30);
flowRuleService.applyFlowRules(rule);
prev = link.dst();
diff --git a/core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java b/core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
index 0b451c0..8922fd9 100644
--- a/core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
+++ b/core/net/src/test/java/org/onlab/onos/net/flow/impl/FlowRuleManagerTest.java
@@ -100,7 +100,7 @@
private FlowRule flowRule(int tsval, int trval) {
TestSelector ts = new TestSelector(tsval);
TestTreatment tr = new TestTreatment(trval);
- return new DefaultFlowRule(DID, ts, tr, 0, appId, TIMEOUT);
+ return new DefaultFlowRule(DID, ts, tr, 10, appId, TIMEOUT);
}
private FlowRule flowRule(FlowRule rule, FlowRuleState state) {
diff --git a/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowRuleBuilder.java b/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowRuleBuilder.java
index 876bc27..70727d3 100644
--- a/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowRuleBuilder.java
+++ b/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowRuleBuilder.java
@@ -18,7 +18,6 @@
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
-import org.projectfloodlight.openflow.protocol.OFFlowRemovedReason;
import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
import org.projectfloodlight.openflow.protocol.OFInstructionType;
import org.projectfloodlight.openflow.protocol.action.OFAction;
@@ -76,17 +75,16 @@
if (addedRule) {
return new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
buildSelector(), buildTreatment(), stat.getPriority(),
- FlowRuleState.ADDED, stat.getDurationNsec() / 1000000,
+ FlowRuleState.ADDED, stat.getDurationSec(),
stat.getPacketCount().getValue(), stat.getByteCount().getValue(),
- stat.getCookie().getValue(), false, stat.getIdleTimeout());
+ stat.getCookie().getValue(), stat.getIdleTimeout());
} else {
// TODO: revisit potentially.
return new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
buildSelector(), null, removed.getPriority(),
- FlowRuleState.REMOVED, removed.getDurationNsec() / 1000000,
+ FlowRuleState.REMOVED, stat.getDurationSec(),
removed.getPacketCount().getValue(), removed.getByteCount().getValue(),
removed.getCookie().getValue(),
- removed.getReason() == OFFlowRemovedReason.IDLE_TIMEOUT.ordinal(),
stat.getIdleTimeout());
}
}