Brian O'Connor

Fixing FlowRule priority in intent compilers

Change-Id: I13998e88d2a116017e87c019f4829101db6c6b6b
......@@ -24,7 +24,6 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.EdgeLink;
......@@ -134,9 +133,14 @@ public class LinkCollectionIntentCompiler implements IntentCompiler<LinkCollecti
treatment = defaultTreatment;
}
DefaultFlowRule rule = new DefaultFlowRule(deviceId, selector, treatment, 123, appId,
new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), 0, true);
FlowRule rule = DefaultFlowRule.builder()
.forDevice(deviceId)
.withSelector(selector)
.withTreatment(treatment)
.withPriority(intent.priority())
.fromApp(appId)
.makePermanent()
.build();
rules.add(rule);
}
......
......@@ -188,13 +188,13 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
// Create optical circuit intent
List<FlowRule> rules = new LinkedList<>();
rules.add(connectPorts(src, connIntent.getSrc()));
rules.add(connectPorts(connIntent.getDst(), dst));
rules.add(connectPorts(src, connIntent.getSrc(), intent.priority()));
rules.add(connectPorts(connIntent.getDst(), dst, intent.priority()));
// Create flow rules for reverse path
if (intent.isBidirectional()) {
rules.add(connectPorts(connIntent.getSrc(), src));
rules.add(connectPorts(dst, connIntent.getDst()));
rules.add(connectPorts(connIntent.getSrc(), src, intent.priority()));
rules.add(connectPorts(dst, connIntent.getDst(), intent.priority()));
}
circuitIntent = new FlowRuleIntent(appId, rules, intent.resources());
......@@ -348,7 +348,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
* @param dst destination port
* @return flow rules
*/
private FlowRule connectPorts(ConnectPoint src, ConnectPoint dst) {
private FlowRule connectPorts(ConnectPoint src, ConnectPoint dst, int priority) {
checkArgument(src.deviceId().equals(dst.deviceId()));
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
......@@ -363,7 +363,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
.forDevice(src.deviceId())
.withSelector(selectorBuilder.build())
.withTreatment(treatmentBuilder.build())
.withPriority(100)
.withPriority(priority)
.fromApp(appId)
.makePermanent()
.build();
......
......@@ -111,7 +111,7 @@ public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathInte
.forDevice(current.deviceId())
.withSelector(selectorBuilder.build())
.withTreatment(treatmentBuilder.build())
.withPriority(100)
.withPriority(intent.priority())
.fromApp(appId)
.makePermanent()
.build();
......@@ -132,7 +132,7 @@ public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathInte
.forDevice(intent.dst().deviceId())
.withSelector(selectorBuilder.build())
.withTreatment(treatmentLast.build())
.withPriority(100)
.withPriority(intent.priority())
.fromApp(appId)
.makePermanent()
.build();
......@@ -163,7 +163,7 @@ public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathInte
.forDevice(current.deviceId())
.withSelector(selectorBuilder.build())
.withTreatment(treatmentBuilder.build())
.withPriority(100)
.withPriority(intent.priority())
.fromApp(appId)
.makePermanent()
.build();
......@@ -184,7 +184,7 @@ public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathInte
.forDevice(intent.src().deviceId())
.withSelector(selectorBuilder.build())
.withTreatment(treatmentLast.build())
.withPriority(100)
.withPriority(intent.priority())
.fromApp(appId)
.makePermanent()
.build();
......
......@@ -76,7 +76,9 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> {
for (int i = 0; i < links.size() - 1; i++) {
ConnectPoint ingress = links.get(i).dst();
ConnectPoint egress = links.get(i + 1).src();
FlowRule rule = createFlowRule(intent.selector(), intent.treatment(), ingress, egress, isLast(links, i));
FlowRule rule = createFlowRule(intent.selector(), intent.treatment(),
ingress, egress, intent.priority(),
isLast(links, i));
rules.add(rule);
}
......@@ -84,7 +86,8 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> {
}
private FlowRule createFlowRule(TrafficSelector originalSelector, TrafficTreatment originalTreatment,
ConnectPoint ingress, ConnectPoint egress, boolean last) {
ConnectPoint ingress, ConnectPoint egress,
int priority, boolean last) {
TrafficSelector selector = DefaultTrafficSelector.builder(originalSelector)
.matchInPort(ingress.port())
.build();
......@@ -97,7 +100,14 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> {
}
TrafficTreatment treatment = treatmentBuilder.setOutput(egress.port()).build();
return new DefaultFlowRule(ingress.deviceId(), selector, treatment, 123, appId, 0, true);
return DefaultFlowRule.builder()
.forDevice(ingress.deviceId())
.withSelector(selector)
.withTreatment(treatment)
.withPriority(priority)
.fromApp(appId)
.makePermanent()
.build();
}
private boolean isLast(List<Link> links, int i) {
......
......@@ -81,7 +81,7 @@ public class LinkCollectionIntentCompilerTest {
private LinkCollectionIntentCompiler sut;
@Before
public void setUP() {
public void setUp() {
sut = new LinkCollectionIntentCompiler();
coreService = createMock(CoreService.class);
expect(coreService.registerApplication("org.onosproject.net.intent"))
......@@ -132,6 +132,7 @@ public class LinkCollectionIntentCompilerTest {
assertThat(rule1.treatment(), is(
DefaultTrafficTreatment.builder(intent.treatment()).setOutput(d1p1.port()).build()
));
assertThat(rule1.priority(), is(intent.priority()));
FlowRule rule2 = rules.stream()
.filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
......@@ -143,6 +144,7 @@ public class LinkCollectionIntentCompilerTest {
assertThat(rule2.treatment(), is(
DefaultTrafficTreatment.builder().setOutput(d2p1.port()).build()
));
assertThat(rule2.priority(), is(intent.priority()));
FlowRule rule3 = rules.stream()
.filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
......@@ -154,6 +156,7 @@ public class LinkCollectionIntentCompilerTest {
assertThat(rule3.treatment(), is(
DefaultTrafficTreatment.builder().setOutput(d3p1.port()).build()
));
assertThat(rule3.priority(), is(intent.priority()));
sut.deactivate();
}
......
......@@ -50,6 +50,7 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertEquals;
import static org.onosproject.net.Link.Type.DIRECT;
import static org.onosproject.net.NetTestTools.PID;
import static org.onosproject.net.NetTestTools.connectPoint;
......@@ -135,7 +136,12 @@ public class OpticalPathIntentCompilerTest {
.findFirst()
.get();
rules.forEach(rule -> assertEquals("FlowRule priority is incorrect",
intent.priority(), rule.priority()));
sut.deactivate();
}
//TODO test bidirectional optical paths and verify rules
}
......
......@@ -75,6 +75,7 @@ public class PathIntentCompilerTest {
private final ConnectPoint d3p1 = connectPoint("s3", 1);
private final ConnectPoint d3p0 = connectPoint("s3", 10);
private final ConnectPoint d1p0 = connectPoint("s1", 10);
private static final int PRIORITY = 555;
private final List<Link> links = Arrays.asList(
createEdgeLink(d1p0, true),
......@@ -102,6 +103,7 @@ public class PathIntentCompilerTest {
.appId(APP_ID)
.selector(selector)
.treatment(treatment)
.priority(PRIORITY)
.path(new DefaultPath(pid, links, hops))
.build();
intentExtensionService = createMock(IntentExtensionService.class);
......@@ -141,6 +143,7 @@ public class PathIntentCompilerTest {
is(DefaultTrafficSelector.builder(selector).matchInPort(d1p0.port()).build()));
assertThat(rule1.treatment(),
is(DefaultTrafficTreatment.builder().setOutput(d1p1.port()).build()));
assertThat(rule1.priority(), is(intent.priority()));
FlowRule rule2 = rules.stream()
.filter(x -> x.deviceId().equals(d2p0.deviceId()))
......@@ -151,6 +154,7 @@ public class PathIntentCompilerTest {
is(DefaultTrafficSelector.builder(selector).matchInPort(d2p0.port()).build()));
assertThat(rule2.treatment(),
is(DefaultTrafficTreatment.builder().setOutput(d2p1.port()).build()));
assertThat(rule2.priority(), is(intent.priority()));
FlowRule rule3 = rules.stream()
.filter(x -> x.deviceId().equals(d3p0.deviceId()))
......@@ -161,6 +165,7 @@ public class PathIntentCompilerTest {
is(DefaultTrafficSelector.builder(selector).matchInPort(d3p1.port()).build()));
assertThat(rule3.treatment(),
is(DefaultTrafficTreatment.builder(treatment).setOutput(d3p0.port()).build()));
assertThat(rule3.priority(), is(intent.priority()));
sut.deactivate();
}
......