use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class LinkCollectionIntentCompilerTest method testCompile.
/**
* We test the proper compilation of a simple link collection intent
* with connect points, trivial treatment and trivial selector.
*/
@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();
assertThat(rules, hasSize(links.size()));
// if not found, get() raises an exception
FlowRule rule1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p10.deviceId())).findFirst().get();
assertThat(rule1.selector(), is(DefaultTrafficSelector.builder(intent.selector()).matchInPort(d1p1.port()).build()));
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())).findFirst().get();
assertThat(rule2.selector(), is(DefaultTrafficSelector.builder(intent.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(rule -> rule.deviceId().equals(d3p0.deviceId())).findFirst().get();
assertThat(rule3.selector(), is(DefaultTrafficSelector.builder(intent.selector()).matchInPort(d3p1.port()).build()));
assertThat(rule3.treatment(), is(DefaultTrafficTreatment.builder().setOutput(d3p1.port()).build()));
assertThat(rule3.priority(), is(intent.priority()));
sut.deactivate();
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class LinkCollectionIntentCompilerTest method singleHopTestFilteredForMp.
/**
* We test the proper compilation of mp2sp with
* trivial selector, trivial treatment, filtered
* points and 1 hop.
*/
@Test
public void singleHopTestFilteredForMp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).links(ImmutableSet.of()).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector), new FilteredConnectPoint(d1p11, mpls69Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0, vlan200Selector))).build();
sut.activate();
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(2));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(2));
FlowRule ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p10.port());
}).findFirst().get();
assertThat(ruleS1.selector(), Is.is(DefaultTrafficSelector.builder(vlan100Selector).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p0.port()).build()));
ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p11.port());
}).findFirst().get();
assertThat(ruleS1.selector(), Is.is(DefaultTrafficSelector.builder(mpls69Selector).matchInPort(d1p11.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().popMpls(IPV4.ethType()).pushVlan().setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p0.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class LinkCollectionIntentCompilerTest method testFilteredConnectPointForMp.
/**
* Multi point to single point intent with filtered connect point.
* Scenario is the follow:
*
* -1 of1 2-1 of2 2-1 of4 2-
* 3
* -1 of3 2---/
*
* We test the proper compilation of mp2sp intents with trivial selector,
* trivial treatment and different filtered point.
*/
@Test
public void testFilteredConnectPointForMp() {
sut.activate();
Set<Link> testlinks = ImmutableSet.of(DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(), DefaultLink.builder().providerId(PID).src(of3p2).dst(of2p3).type(DIRECT).build(), DefaultLink.builder().providerId(PID).src(of2p2).dst(of4p1).type(DIRECT).build());
Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(of1p1, vlan100Selector), new FilteredConnectPoint(of3p1, vlan100Selector));
Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(of4p2, vlan200Selector));
TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(vlan100Selector).matchInPort(PortNumber.portNumber(1)).build();
TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId("200")).setOutput(PortNumber.portNumber(2)).build();
TrafficSelector expectOf2Selector1 = DefaultTrafficSelector.builder(vlan200Selector).matchInPort(PortNumber.portNumber(1)).build();
TrafficSelector expectOf2Selector2 = DefaultTrafficSelector.builder(vlan200Selector).matchInPort(PortNumber.portNumber(3)).build();
TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(2)).build();
TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(vlan100Selector).matchInPort(PortNumber.portNumber(1)).build();
TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId("200")).setOutput(PortNumber.portNumber(2)).build();
TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(vlan100Selector).matchInPort(PortNumber.portNumber(1)).matchVlanId(VlanId.vlanId("200")).build();
TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(2)).build();
intent = LinkCollectionIntent.builder().appId(APP_ID).filteredIngressPoints(ingress).filteredEgressPoints(egress).treatment(treatment).links(testlinks).build();
List<Intent> result = sut.compile(intent, Collections.emptyList());
assertThat(result, is(notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent, instanceOf(FlowRuleIntent.class));
if (resultIntent instanceof FlowRuleIntent) {
FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent;
assertThat(frIntent.flowRules(), hasSize(5));
List<FlowRule> deviceFlowRules;
FlowRule flowRule;
// Of1
deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf1Selector));
assertThat(flowRule.treatment(), is(expectOf1Treatment));
// Of2 (has 2 flows)
deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(2));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf2Selector1));
assertThat(flowRule.treatment(), is(expectOf2Treatment));
flowRule = deviceFlowRules.get(1);
assertThat(flowRule.selector(), is(expectOf2Selector2));
assertThat(flowRule.treatment(), is(expectOf2Treatment));
// Of3
deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf3Selector));
assertThat(flowRule.treatment(), is(expectOf3Treatment));
// Of4
deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf4Selector));
assertThat(flowRule.treatment(), is(expectOf4Treatment));
}
sut.deactivate();
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class LinkCollectionIntentCompilerTest method singleHopTestForSp.
/**
* We test the proper compilation of sp2mp with
* trivial selector, trivial treatment and 1 hop.
*/
@Test
public void singleHopTestForSp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).applyTreatmentOnEgress(true).links(ImmutableSet.of()).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10), new FilteredConnectPoint(d1p11))).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0))).build();
sut.activate();
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(1));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(1));
FlowRule ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p0.port());
}).findFirst().get();
assertThat(ruleS1.selector(), Is.is(DefaultTrafficSelector.builder().matchInPort(d1p0.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setOutput(d1p10.port()).setOutput(d1p11.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class LinkCollectionIntentFlowObjectiveCompilerTest method singleHopTestForMp.
/**
* Multiple point to single point intent with only one switch.
* We test the proper compilation of mp2sp with
* trivial selector, trivial treatment and 1 hop.
*/
@Test
public void singleHopTestForMp() {
Set<Link> testLinks = ImmutableSet.of();
Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(of1p1, vlan100Selector), new FilteredConnectPoint(of1p2, vlan100Selector));
Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(of1p3, vlan100Selector));
LinkCollectionIntent intent = LinkCollectionIntent.builder().appId(appId).selector(ethDstSelector).treatment(treatment).links(testLinks).filteredIngressPoints(ingress).filteredEgressPoints(egress).build();
List<Intent> result = compiler.compile(intent, Collections.emptyList());
assertThat(result, hasSize(1));
assertThat(result.get(0), instanceOf(FlowObjectiveIntent.class));
FlowObjectiveIntent foIntent = (FlowObjectiveIntent) result.get(0);
List<Objective> objectives = foIntent.objectives();
assertThat(objectives, hasSize(6));
TrafficSelector expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_100).build();
TrafficTreatment expectTreatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(3)).build();
/*
* First set of objective
*/
filteringObjective = (FilteringObjective) objectives.get(0);
forwardingObjective = (ForwardingObjective) objectives.get(1);
nextObjective = (NextObjective) objectives.get(2);
PortCriterion inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
// test case for first filtering objective
checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.criteria());
// test case for first next objective
checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
// test case for first forwarding objective
checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
/*
* Second set of objective
*/
filteringObjective = (FilteringObjective) objectives.get(3);
forwardingObjective = (ForwardingObjective) objectives.get(4);
nextObjective = (NextObjective) objectives.get(5);
expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchInPort(PortNumber.portNumber(2)).matchVlanId(VLAN_100).build();
inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
// test case for first filtering objective
checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.criteria());
// test case for first next objective
checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
// test case for first forwarding objective
checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
}
Aggregations