use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class MultiPointToSinglePointIntentCompilerTest method testSingleLongPathCompilation.
/**
* Tests a single ingress point with 8 hops to its egress point.
*/
@Test
public void testSingleLongPathCompilation() {
Set<FilteredConnectPoint> ingress = Sets.newHashSet(new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1)));
FilteredConnectPoint egress = new FilteredConnectPoint(new ConnectPoint(DID_8, PORT_1));
MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
assertThat(intent, is(notNullValue()));
String[] hops = { S2, S3, S4, S5, S6, S7 };
MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
assertThat(compiler, is(notNullValue()));
List<Intent> result = compiler.compile(intent, null);
assertThat(result, is(Matchers.notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent instanceof LinkCollectionIntent, is(true));
if (resultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
assertThat(linkIntent.links(), hasSize(7));
assertThat(linkIntent.links(), linksHasPath(S1, S2));
assertThat(linkIntent.links(), linksHasPath(S2, S3));
assertThat(linkIntent.links(), linksHasPath(S3, S4));
assertThat(linkIntent.links(), linksHasPath(S4, S5));
assertThat(linkIntent.links(), linksHasPath(S5, S6));
assertThat(linkIntent.links(), linksHasPath(S6, S7));
assertThat(linkIntent.links(), linksHasPath(S7, S8));
}
assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class MultiPointToSinglePointIntentCompilerTest method testPartialFailureConstraintFailure.
/**
* Tests if compiling an intent without partial failure constraints set and
* with a missing ingress connect point generates an exception and no other
* results.
*/
@Test
public void testPartialFailureConstraintFailure() {
Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1)), new FilteredConnectPoint(new ConnectPoint(DID_5, PORT_1)));
FilteredConnectPoint egress = new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_2));
MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
String[] hops = { S3 };
MultiPointToSinglePointIntentCompiler compiler = makeCompiler(null, new IntentTestsMocks.FixedMP2MPMockPathService(hops), null);
assertThat(compiler, is(notNullValue()));
intentException.expect(IntentException.class);
List<Intent> result = compiler.compile(intent, null);
assertThat(result, null);
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class MultiPointToSinglePointIntentCompilerTest method testNonTrivialSelectorsIntent.
/**
* Tests selector, filtered ingress and egress.
*/
@Test
public void testNonTrivialSelectorsIntent() {
Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1), DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("100")).build()), new FilteredConnectPoint(new ConnectPoint(DID_2, PORT_1), DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("200")).build()));
FilteredConnectPoint egress = new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_2));
TrafficSelector ipPrefixSelector = DefaultTrafficSelector.builder().matchIPDst(IpPrefix.valueOf("192.168.100.0/24")).build();
MultiPointToSinglePointIntent intent = makeIntent(ingress, egress, ipPrefixSelector);
String[] hops = { S3 };
MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
assertThat(compiler, is(notNullValue()));
List<Intent> result = compiler.compile(intent, null);
assertThat(result, is(notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent, instanceOf(LinkCollectionIntent.class));
if (resultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
assertThat(linkIntent.links(), hasSize(3));
assertThat(linkIntent.links(), linksHasPath(S1, S3));
assertThat(linkIntent.links(), linksHasPath(S2, S3));
assertThat(linkIntent.links(), linksHasPath(S3, S4));
assertThat(linkIntent.selector(), is(ipPrefixSelector));
}
assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testCompile.
/**
* Tests the compilation behavior of the path intent compiler.
*/
@Test
public void testCompile() {
sut.activate();
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
assertThat("key is inherited", compiled.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
FlowRule rule1 = rules.stream().filter(x -> x.deviceId().equals(d1p0.deviceId())).findFirst().get();
verifyIdAndPriority(rule1, d1p0.deviceId());
assertThat(rule1.selector(), is(DefaultTrafficSelector.builder(selector).matchInPort(d1p0.port()).build()));
assertThat(rule1.treatment(), is(DefaultTrafficTreatment.builder().setOutput(d1p1.port()).build()));
FlowRule rule2 = rules.stream().filter(x -> x.deviceId().equals(d2p0.deviceId())).findFirst().get();
verifyIdAndPriority(rule2, d2p0.deviceId());
assertThat(rule2.selector(), is(DefaultTrafficSelector.builder(selector).matchInPort(d2p0.port()).build()));
assertThat(rule2.treatment(), is(DefaultTrafficTreatment.builder().setOutput(d2p1.port()).build()));
FlowRule rule3 = rules.stream().filter(x -> x.deviceId().equals(d3p0.deviceId())).findFirst().get();
verifyIdAndPriority(rule3, d3p1.deviceId());
assertThat(rule3.selector(), is(DefaultTrafficSelector.builder(selector).matchInPort(d3p1.port()).build()));
assertThat(rule3.treatment(), is(DefaultTrafficTreatment.builder(treatment).setOutput(d3p0.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testMplsEncapCompile.
/**
* Tests the compilation behavior of the path intent compiler in case of
* encasulation costraint {@link EncapsulationConstraint}.
*/
@Test
public void testMplsEncapCompile() {
sut.activate();
List<Intent> compiled = sut.compile(constraintMplsIntent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(3));
FlowRule rule1 = rules.stream().filter(x -> x.deviceId().equals(d1p0.deviceId())).findFirst().get();
verifyIdAndPriority(rule1, d1p0.deviceId());
assertThat(rule1.selector(), is(DefaultTrafficSelector.builder(selector).matchInPort(d1p0.port()).build()));
MplsLabel mplsLabelToEncap = verifyMplsEncapTreatment(rule1.treatment(), d1p1, true, false);
FlowRule rule2 = rules.stream().filter(x -> x.deviceId().equals(d2p0.deviceId())).findFirst().get();
verifyIdAndPriority(rule2, d2p0.deviceId());
verifyMplsEncapSelector(rule2.selector(), d2p0, mplsLabelToEncap);
mplsLabelToEncap = verifyMplsEncapTreatment(rule2.treatment(), d2p1, false, false);
FlowRule rule3 = rules.stream().filter(x -> x.deviceId().equals(d3p0.deviceId())).findFirst().get();
verifyIdAndPriority(rule3, d3p1.deviceId());
verifyMplsEncapSelector(rule3.selector(), d3p1, mplsLabelToEncap);
verifyMplsEncapTreatment(rule3.treatment(), d3p0, false, true);
sut.deactivate();
}
Aggregations