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 testRandomVlanSelection.
/**
* Tests the random selection of VLAN Ids in the PathCompiler.
* It can fail randomly (it is unlikely)
*/
@Test
public void testRandomVlanSelection() {
sut.activate();
List<Intent> compiled = sut.compile(constraintVlanIntent, 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()));
VlanId vlanToEncap = verifyVlanEncapTreatment(rule1.treatment(), d1p1, true, false);
assertTrue(VlanId.NO_VID < vlanToEncap.toShort() && vlanToEncap.toShort() < VlanId.MAX_VLAN);
/*
* This second part is meant to test if the random selection is working properly.
* We are compiling the same intent in order to verify if the VLAN ID is different
* from the previous one.
*/
List<Intent> compiled2 = sut.compile(constraintVlanIntent, Collections.emptyList());
assertThat(compiled2, hasSize(1));
Collection<FlowRule> rules2 = ((FlowRuleIntent) compiled2.get(0)).flowRules();
assertThat(rules2, hasSize(3));
FlowRule rule2 = rules2.stream().filter(x -> x.deviceId().equals(d1p0.deviceId())).findFirst().get();
verifyIdAndPriority(rule2, d1p0.deviceId());
assertThat(rule2.selector(), is(DefaultTrafficSelector.builder(selector).matchInPort(d1p0.port()).build()));
VlanId vlanToEncap2 = verifyVlanEncapTreatment(rule2.treatment(), d1p1, true, false);
assertTrue(VlanId.NO_VID < vlanToEncap2.toShort() && vlanToEncap2.toShort() < VlanId.MAX_VLAN);
sut.deactivate();
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testVlanEncapCompileEdgeIngressVlan.
/**
* Tests the compilation behavior of the path intent compiler in case of
* VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
* and edge communication. Ingress VLAN. No egress VLAN.
*/
@Test
public void testVlanEncapCompileEdgeIngressVlan() {
sut.activate();
List<Intent> compiled = sut.compile(edgeIntentIngressVlan, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(1));
FlowRule rule = rules.stream().filter(x -> x.deviceId().equals(d1p2.deviceId())).findFirst().get();
verifyIdAndPriority(rule, d1p2.deviceId());
assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d1p2.port()).matchVlanId(ingressVlan).build()));
assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setOutput(d1p3.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testVlanEncapCompileSingleHopDirectEgressVlan.
/**
* Tests the compilation behavior of the path intent compiler in case of
* VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
* and single-hop-direct-link scenario. No ingress VLAN. Egress VLAN.
*/
@Test
public void testVlanEncapCompileSingleHopDirectEgressVlan() {
sut.activate();
List<Intent> compiled = sut.compile(singleHopDirectIntentEgressVlan, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(1));
FlowRule rule = rules.stream().filter(x -> x.deviceId().equals(d2p4.deviceId())).findFirst().get();
verifyIdAndPriority(rule, d2p4.deviceId());
assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p4.port()).build()));
assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan).setOutput(d2p5.port()).build()));
Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).collect(Collectors.toSet());
assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).collect(Collectors.toSet()), hasSize(1));
assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction).collect(Collectors.toSet()), hasSize(0));
sut.deactivate();
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testVlanEncapCompileEdgeVlan.
/**
* Tests the compilation behavior of the path intent compiler in case of
* VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
* and edge communication. Ingress VLAN. Egress VLAN.
*/
@Test
public void testVlanEncapCompileEdgeVlan() {
sut.activate();
List<Intent> compiled = sut.compile(edgeIntentVlan, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(1));
FlowRule rule = rules.stream().filter(x -> x.deviceId().equals(d1p2.deviceId())).findFirst().get();
verifyIdAndPriority(rule, d1p2.deviceId());
assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d1p2.port()).matchVlanId(ingressVlan).build()));
assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan).setOutput(d1p3.port()).build()));
Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).collect(Collectors.toSet());
assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).collect(Collectors.toSet()), hasSize(1));
assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction).collect(Collectors.toSet()), hasSize(0));
sut.deactivate();
}
Aggregations