alshabib

illegalArgument exception for priority

Change-Id: I9bce0b677b937ee691ac24c13c88a632cfb2339e
......@@ -39,6 +39,7 @@ import org.slf4j.Logger;
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 @@ public class ReactiveForwarding {
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);
}
......
......@@ -96,7 +96,7 @@ public class FlowsListCommand extends AbstractShellCommand {
}
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());
}
......
......@@ -29,9 +29,23 @@ public class DefaultFlowRule implements FlowRule {
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 class DefaultFlowRule implements FlowRule {
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 @@ public class DefaultFlowRule implements FlowRule {
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 @@ public class DefaultFlowRule implements FlowRule {
}
@Override
public long lifeMillis() {
public long life() {
return life;
}
......
......@@ -10,6 +10,7 @@ import org.onlab.onos.net.DeviceId;
public interface FlowRule {
static final int MAX_TIMEOUT = 60;
static final int MIN_PRIORITY = 0;
public enum FlowRuleState {
/**
......@@ -96,7 +97,7 @@ public interface FlowRule {
*
* @return number of millis
*/
long lifeMillis();
long life();
/**
* Returns the number of packets this flow rule has matched.
......
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.IntentExtensionService;
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 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
builder.build(), treat.build(),
0, appId, 30);
10, appId, 30);
flowRuleService.applyFlowRules(rule);
prev = link.dst();
......
......@@ -100,7 +100,7 @@ public class FlowRuleManagerTest {
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) {
......
......@@ -18,7 +18,6 @@ import org.onlab.packet.IpPrefix;
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 @@ public class FlowRuleBuilder {
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());
}
}
......