Search in sources :

Example 16 with EncapsulationConstraint

use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.

the class LinkCollectionIntentFlowObjectiveCompilerTest method testFilteredConnectPointForMpWithEncap.

/**
 * 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 constraint of mp2sp
 * with encapsulation, trivial selector, empty treatment and points.
 */
@Test
public void testFilteredConnectPointForMpWithEncap() throws Exception {
    LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
    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(of3p1, vlan100Selector), new FilteredConnectPoint(of1p1, vlan100Selector));
    Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(of4p2, vlan100Selector));
    EncapsulationConstraint constraint = new EncapsulationConstraint(EncapsulationType.VLAN);
    LinkCollectionIntent intent = LinkCollectionIntent.builder().appId(appId).selector(ethDstSelector).treatment(treatment).links(testLinks).filteredIngressPoints(ingress).filteredEgressPoints(egress).constraints(ImmutableList.of(constraint)).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(15));
    TrafficSelector expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_100).build();
    TrafficSelector filteringSelector = vlan100Selector;
    TrafficTreatment expectTreatment = DefaultTrafficTreatment.builder().setVlanId(VLAN_1).setOutput(PortNumber.portNumber(2)).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, filteringSelector.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().matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_1).build();
    filteringSelector = vlan1Selector;
    expectTreatment = DefaultTrafficTreatment.builder().setVlanId(VLAN_100).setOutput(PortNumber.portNumber(2)).build();
    // test case for second filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, filteringSelector.criteria());
    // test case for second next objective
    checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
    // test case for second forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
    /*
         * 3rd set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(6);
    forwardingObjective = (ForwardingObjective) objectives.get(7);
    nextObjective = (NextObjective) objectives.get(8);
    filteringSelector = vlan100Selector;
    expectTreatment = DefaultTrafficTreatment.builder().setVlanId(VLAN_1).setOutput(PortNumber.portNumber(2)).build();
    expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_100).build();
    // test case for 3rd filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, filteringSelector.criteria());
    // test case for 3rd next objective
    checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
    // test case for 3rd forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
    /*
         * 4th set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(9);
    forwardingObjective = (ForwardingObjective) objectives.get(10);
    nextObjective = (NextObjective) objectives.get(11);
    filteringSelector = vlan1Selector;
    expectSelector = DefaultTrafficSelector.builder().matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_1).build();
    // test case for 4th filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, filteringSelector.criteria());
    // test case for 4th next objective
    checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
    // test case for 4th forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
    /*
         * 5th set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(12);
    forwardingObjective = (ForwardingObjective) objectives.get(13);
    nextObjective = (NextObjective) objectives.get(14);
    expectSelector = DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("1")).matchInPort(PortNumber.portNumber(3)).build();
    inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
    // test case for 5th filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, filteringSelector.criteria());
    // test case for 5th next objective
    checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
    // test case for 5th forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
}
Also used : EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Objective(org.onosproject.net.flowobjective.Objective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test)

Example 17 with EncapsulationConstraint

use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.

the class PathIntentCompilerTest method testVlanEncapCompileEdgeEgressVlan.

/**
 * Tests the compilation behavior of the path intent compiler in case of
 * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
 * and edge communication. No ingress VLAN. Egress VLAN.
 */
@Test
public void testVlanEncapCompileEdgeEgressVlan() {
    sut.activate();
    List<Intent> compiled = sut.compile(edgeIntentEgressVlan, 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()).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();
}
Also used : DIRECT(org.onosproject.net.Link.Type.DIRECT) Arrays(java.util.Arrays) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) TestApplicationId(org.onosproject.TestApplicationId) CoreService(org.onosproject.core.CoreService) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ApplicationId(org.onosproject.core.ApplicationId) DefaultPath(org.onosproject.net.DefaultPath) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Intent(org.onosproject.net.intent.Intent) OrderingComparison.greaterThan(org.hamcrest.number.OrderingComparison.greaterThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MockResourceService(org.onosproject.net.resource.MockResourceService) Before(org.junit.Before) DefaultLink(org.onosproject.net.DefaultLink) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Instructions(org.onosproject.net.flow.instructions.Instructions) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) EasyMock(org.easymock.EasyMock) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest) Collectors(java.util.stream.Collectors) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) NetTestTools(org.onosproject.net.NetTestTools) FlowRule(org.onosproject.net.flow.FlowRule) ScalarWeight(org.onlab.graph.ScalarWeight) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 18 with EncapsulationConstraint

use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.

the class PathIntentCompilerTest method testVlanEncapCompileSingleHopIndirectEgressVlan.

/**
 * Tests the compilation behavior of the path intent compiler in case of
 * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
 * and single-hop-indirect-link scenario. No ingress VLAN. Egress VLAN.
 */
@Test
public void testVlanEncapCompileSingleHopIndirectEgressVlan() {
    sut.activate();
    List<Intent> compiled = sut.compile(singleHopIndirectIntentEgressVlan, 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(d2p2.deviceId())).findFirst().get();
    verifyIdAndPriority(rule, d2p2.deviceId());
    assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p2.port()).build()));
    assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan).setOutput(d2p3.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();
}
Also used : DIRECT(org.onosproject.net.Link.Type.DIRECT) Arrays(java.util.Arrays) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) TestApplicationId(org.onosproject.TestApplicationId) CoreService(org.onosproject.core.CoreService) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ApplicationId(org.onosproject.core.ApplicationId) DefaultPath(org.onosproject.net.DefaultPath) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Intent(org.onosproject.net.intent.Intent) OrderingComparison.greaterThan(org.hamcrest.number.OrderingComparison.greaterThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MockResourceService(org.onosproject.net.resource.MockResourceService) Before(org.junit.Before) DefaultLink(org.onosproject.net.DefaultLink) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Instructions(org.onosproject.net.flow.instructions.Instructions) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) EasyMock(org.easymock.EasyMock) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest) Collectors(java.util.stream.Collectors) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) NetTestTools(org.onosproject.net.NetTestTools) FlowRule(org.onosproject.net.flow.FlowRule) ScalarWeight(org.onlab.graph.ScalarWeight) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 19 with EncapsulationConstraint

use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.

the class PathIntentCompilerTest method testVlanEncapCompileSingleHopIndirectVlan.

/**
 * Tests the compilation behavior of the path intent compiler in case of
 * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
 * and single-hop-indirect-link scenario. Ingress VLAN. Egress VLAN.
 */
@Test
public void testVlanEncapCompileSingleHopIndirectVlan() {
    sut.activate();
    List<Intent> compiled = sut.compile(singleHopIndirectIntentVlan, 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(d2p2.deviceId())).findFirst().get();
    verifyIdAndPriority(rule, d2p2.deviceId());
    assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p2.port()).matchVlanId(ingressVlan).build()));
    assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan).setOutput(d2p3.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();
}
Also used : DIRECT(org.onosproject.net.Link.Type.DIRECT) Arrays(java.util.Arrays) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) TestApplicationId(org.onosproject.TestApplicationId) CoreService(org.onosproject.core.CoreService) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ApplicationId(org.onosproject.core.ApplicationId) DefaultPath(org.onosproject.net.DefaultPath) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Intent(org.onosproject.net.intent.Intent) OrderingComparison.greaterThan(org.hamcrest.number.OrderingComparison.greaterThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MockResourceService(org.onosproject.net.resource.MockResourceService) Before(org.junit.Before) DefaultLink(org.onosproject.net.DefaultLink) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Instructions(org.onosproject.net.flow.instructions.Instructions) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) EasyMock(org.easymock.EasyMock) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest) Collectors(java.util.stream.Collectors) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) NetTestTools(org.onosproject.net.NetTestTools) FlowRule(org.onosproject.net.flow.FlowRule) ScalarWeight(org.onlab.graph.ScalarWeight) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 20 with EncapsulationConstraint

use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.

the class PathIntentCompilerTest method testEncapIngressEgressVlansCompile.

/**
 * Tests the compilation behavior of the path intent compiler in case of
 * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}.
 * This test includes a selector to match a VLAN at the ingress and a treatment to set VLAN at the egress.
 */
@Test
public void testEncapIngressEgressVlansCompile() {
    sut.activate();
    List<Intent> compiled = sut.compile(constrainIngressEgressVlanIntent, 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());
    verifyVlanEncapSelector(rule1.selector(), d1p0, ingressVlan);
    VlanId vlanToEncap = verifyVlanEncapTreatment(rule1.treatment(), d1p1, true, false);
    FlowRule rule2 = rules.stream().filter(x -> x.deviceId().equals(d2p0.deviceId())).findFirst().get();
    verifyIdAndPriority(rule2, d2p0.deviceId());
    verifyVlanEncapSelector(rule2.selector(), d2p0, vlanToEncap);
    vlanToEncap = verifyVlanEncapTreatment(rule2.treatment(), d2p1, false, false);
    FlowRule rule3 = rules.stream().filter(x -> x.deviceId().equals(d3p0.deviceId())).findFirst().get();
    verifyIdAndPriority(rule3, d3p1.deviceId());
    verifyVlanEncapSelector(rule3.selector(), d3p1, vlanToEncap);
    Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule3.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).collect(Collectors.toSet());
    assertThat(rule3.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).collect(Collectors.toSet()), hasSize(1));
    assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
    assertThat(rule3.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction).collect(Collectors.toSet()), hasSize(0));
    sut.deactivate();
}
Also used : DIRECT(org.onosproject.net.Link.Type.DIRECT) Arrays(java.util.Arrays) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) TestApplicationId(org.onosproject.TestApplicationId) CoreService(org.onosproject.core.CoreService) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ApplicationId(org.onosproject.core.ApplicationId) DefaultPath(org.onosproject.net.DefaultPath) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Intent(org.onosproject.net.intent.Intent) OrderingComparison.greaterThan(org.hamcrest.number.OrderingComparison.greaterThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MockResourceService(org.onosproject.net.resource.MockResourceService) Before(org.junit.Before) DefaultLink(org.onosproject.net.DefaultLink) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Instructions(org.onosproject.net.flow.instructions.Instructions) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) EasyMock(org.easymock.EasyMock) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest) Collectors(java.util.stream.Collectors) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) NetTestTools(org.onosproject.net.NetTestTools) FlowRule(org.onosproject.net.flow.FlowRule) ScalarWeight(org.onlab.graph.ScalarWeight) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) FlowRule(org.onosproject.net.flow.FlowRule) VlanId(org.onlab.packet.VlanId) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Aggregations

EncapsulationConstraint (org.onosproject.net.intent.constraint.EncapsulationConstraint)24 ConnectPoint (org.onosproject.net.ConnectPoint)16 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)16 TrafficSelector (org.onosproject.net.flow.TrafficSelector)16 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)16 ImmutableList (com.google.common.collect.ImmutableList)15 EncapsulationType (org.onosproject.net.EncapsulationType)15 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)15 Intent (org.onosproject.net.intent.Intent)15 List (java.util.List)14 Set (java.util.Set)14 VlanId (org.onlab.packet.VlanId)13 ApplicationId (org.onosproject.core.ApplicationId)13 CoreService (org.onosproject.core.CoreService)13 ArrayList (java.util.ArrayList)12 DeviceId (org.onosproject.net.DeviceId)12 Test (org.junit.Test)11 Ethernet (org.onlab.packet.Ethernet)11 Collectors (java.util.stream.Collectors)9 Collection (java.util.Collection)8