use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.
the class LinkCollectionIntentCompilerP2PTest method testVlanEncapsulationForP2P.
/**
* We test the proper compilation of p2p with the VLAN
* encapsulation and trivial filtered points.
*/
@Test
public void testVlanEncapsulationForP2P() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).constraints(constraintsForVlan).links(linksForMp2Sp).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls200Selector))).build();
sut.activate();
/*
* We use the FIRST_FIT to simplify tests.
*/
LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(3));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(1));
FlowRule ruleS1 = rulesS1.iterator().next();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(vlan100Selector).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d1p0.port()).build()));
Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS2, hasSize(1));
FlowRule ruleS2 = rulesS2.iterator().next();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p1.port()).build()));
Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS3, hasSize(1));
FlowRule ruleS3 = rulesS3.iterator().next();
assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder().matchInPort(d3p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d3p10.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.
the class LinkCollectionIntentCompilerTest method singleHopNonTrivialForMp.
/**
* We test the proper compilation of mp2sp with
* selector, treatment, filtered
* points and 1 hop.
*/
@Test
public void singleHopNonTrivialForMp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment).links(ImmutableSet.of()).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector), new FilteredConnectPoint(d1p11, mpls100Selector))).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(ipPrefixSelector).matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).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(ipPrefixSelector).matchMplsLabel(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()).matchInPort(d1p11.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).popMpls(IPV4.ethType()).pushVlan().setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p0.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.
the class LinkCollectionIntentCompilerTest method singleHopTestFilteredForSp.
/**
* We test the proper compilation of sp2mp with
* trivial selector, trivial treatment and 1 hop.
*/
@Test
public void singleHopTestFilteredForSp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).applyTreatmentOnEgress(true).links(ImmutableSet.of()).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector), new FilteredConnectPoint(d1p11, mpls80Selector))).filteredIngressPoints(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(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(vlan200Selector).matchInPort(d1p0.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p10.port()).popVlan().pushMpls().setMpls(((MplsCriterion) mpls80Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d1p11.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.FilteredConnectPoint 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.FilteredConnectPoint 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();
}
Aggregations