Search in sources :

Example 36 with PortCriterion

use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.

the class LinkCollectionIntentCompilerTest method singleHopNonTrivialForSp.

/**
 * We test the proper compilation of sp2mp with
 * selector, treatment and 1 hop.
 */
@Test
public void singleHopNonTrivialForSp() {
    intent = LinkCollectionIntent.builder().appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment).applyTreatmentOnEgress(true).links(ImmutableSet.of()).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector), new FilteredConnectPoint(d1p11, mpls200Selector))).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(ipPrefixSelector).matchVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).matchInPort(d1p0.port()).build()));
    assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p10.port()).setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).popVlan().pushMpls().setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d1p11.port()).build()));
    sut.deactivate();
}
Also used : MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) DIRECT(org.onosproject.net.Link.Type.DIRECT) APP_ID(org.onosproject.net.NetTestTools.APP_ID) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Is(org.hamcrest.core.Is) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Type(org.onosproject.net.flow.criteria.Criterion.Type) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DomainService(org.onosproject.net.domain.DomainService) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) Intent(org.onosproject.net.intent.Intent) LOCAL(org.onosproject.net.domain.DomainId.LOCAL) 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) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) IPV4(org.onlab.packet.EthType.EtherType.IPV4) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) PID(org.onosproject.net.NetTestTools.PID) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Intent(org.onosproject.net.intent.Intent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FlowRule(org.onosproject.net.flow.FlowRule) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) Test(org.junit.Test)

Example 37 with PortCriterion

use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.

the class LinkCollectionIntentFlowObjectiveCompilerTest 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---/
 */
@Test
public void testFilteredConnectPointForMp() {
    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));
    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(15));
    TrafficSelector expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_100).build();
    TrafficTreatment expectTreatment = DefaultTrafficTreatment.builder().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, 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);
    // 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);
    /*
         * 3rd set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(6);
    forwardingObjective = (ForwardingObjective) objectives.get(7);
    nextObjective = (NextObjective) objectives.get(8);
    // 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);
    /*
         * 4th set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(9);
    forwardingObjective = (ForwardingObjective) objectives.get(10);
    nextObjective = (NextObjective) objectives.get(11);
    // 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);
    /*
         * 5th set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(12);
    forwardingObjective = (ForwardingObjective) objectives.get(13);
    nextObjective = (NextObjective) objectives.get(14);
    expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchVlanId(VLAN_100).matchInPort(PortNumber.portNumber(3)).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);
}
Also used : 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 38 with PortCriterion

use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.

the class LinkCollectionIntentFlowObjectiveCompilerTest method testFilteredConnectPointForSp.

/**
 * Single point to multi point case. Scenario is the follow:
 *
 * -1 of1 2-1 of2 2--1 of3 2-
 *             3
 *             `-1 of4 2-
 *
 * We test the proper compilation of sp2mp with trivial selector,
 * empty treatment and points.
 */
@Test
public void testFilteredConnectPointForSp() {
    Set<Link> testLinks = ImmutableSet.of(DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(), DefaultLink.builder().providerId(PID).src(of2p2).dst(of3p1).type(DIRECT).build(), DefaultLink.builder().providerId(PID).src(of2p3).dst(of4p1).type(DIRECT).build());
    Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(of1p1, vlan100Selector));
    Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(of3p2, vlan100Selector), new FilteredConnectPoint(of4p2, vlan100Selector));
    TrafficSelector broadcastSelector = DefaultTrafficSelector.builder().matchEthDst(MacAddress.BROADCAST).build();
    LinkCollectionIntent intent = LinkCollectionIntent.builder().appId(appId).selector(broadcastSelector).treatment(treatment).links(testLinks).filteredIngressPoints(ingress).filteredEgressPoints(egress).applyTreatmentOnEgress(true).resourceGroup(resourceGroup1).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(12));
    /*
         * First set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(0);
    forwardingObjective = (ForwardingObjective) objectives.get(1);
    nextObjective = (NextObjective) objectives.get(2);
    // expect selector and treatment
    TrafficSelector expectSelector = DefaultTrafficSelector.builder().matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_100).matchEthDst(MacAddress.BROADCAST).build();
    List<TrafficTreatment> expectTreatments = ImmutableList.of(DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(2)).build());
    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, BROADCAST, expectTreatments, 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);
    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 second next objective
    checkNext(nextObjective, BROADCAST, expectTreatments, 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);
    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 3rd next objective
    checkNext(nextObjective, BROADCAST, expectTreatments, 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);
    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 3rd next objective
    expectTreatments = ImmutableList.of(DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(2)).build(), DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(3)).build());
    checkNext(nextObjective, BROADCAST, expectTreatments, expectSelector, ADD);
    // test case for 3rd forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
}
Also used : 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 39 with PortCriterion

use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.

the class LinkCollectionIntentFlowObjectiveCompilerTest method testFilteredConnectPointForSpWithEncap.

/**
 * Single point to multi point case. Scenario is the follow:
 *
 * -1 of1 2-1 of2 2--1 of3 2-
 *             3
 *             `-1 of4 2-
 *
 * We test the proper compilation constraint of sp2mp
 * with encapsulation, trivial selector, empty treatment and points.
 */
@Test
public void testFilteredConnectPointForSpWithEncap() 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(of2p2).dst(of3p1).type(DIRECT).build(), DefaultLink.builder().providerId(PID).src(of2p3).dst(of4p1).type(DIRECT).build());
    Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(of1p1, vlan100Selector));
    Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(of3p2, vlan100Selector), new FilteredConnectPoint(of4p2, vlan100Selector));
    TrafficSelector broadcastSelector = DefaultTrafficSelector.builder().matchEthDst(MacAddress.BROADCAST).build();
    EncapsulationConstraint constraint = new EncapsulationConstraint(EncapsulationType.VLAN);
    LinkCollectionIntent intent = LinkCollectionIntent.builder().appId(appId).selector(broadcastSelector).treatment(treatment).links(testLinks).filteredIngressPoints(ingress).filteredEgressPoints(egress).applyTreatmentOnEgress(true).resourceGroup(resourceGroup1).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(12));
    /*
         * First set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(0);
    forwardingObjective = (ForwardingObjective) objectives.get(1);
    nextObjective = (NextObjective) objectives.get(2);
    // expect selector and treatment
    TrafficSelector expectSelector = DefaultTrafficSelector.builder().matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_100).matchEthDst(MacAddress.BROADCAST).build();
    List<TrafficTreatment> expectTreatments = ImmutableList.of(DefaultTrafficTreatment.builder().setVlanId(VLAN_1).setOutput(PortNumber.portNumber(2)).build());
    TrafficSelector filteringSelector = vlan100Selector;
    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, BROADCAST, expectTreatments, 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();
    expectTreatments = ImmutableList.of(DefaultTrafficTreatment.builder().setVlanId(VLAN_100).setOutput(PortNumber.portNumber(2)).build());
    filteringSelector = vlan1Selector;
    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 second next objective
    checkNext(nextObjective, BROADCAST, expectTreatments, 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);
    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 3rd next objective
    checkNext(nextObjective, BROADCAST, expectTreatments, 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);
    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 3rd next objective
    expectTreatments = ImmutableList.of(DefaultTrafficTreatment.builder().setVlanId(VLAN_1).setOutput(PortNumber.portNumber(2)).build(), DefaultTrafficTreatment.builder().setVlanId(VLAN_1).setOutput(PortNumber.portNumber(3)).build());
    checkNext(nextObjective, BROADCAST, expectTreatments, expectSelector, ADD);
    // test case for 3rd 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 40 with PortCriterion

use of org.onosproject.net.flow.criteria.PortCriterion 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)

Aggregations

PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)55 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)34 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)32 FlowRule (org.onosproject.net.flow.FlowRule)32 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)28 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)26 TrafficSelector (org.onosproject.net.flow.TrafficSelector)25 List (java.util.List)24 Criterion (org.onosproject.net.flow.criteria.Criterion)24 Test (org.junit.Test)22 Intent (org.onosproject.net.intent.Intent)21 CoreService (org.onosproject.core.CoreService)20 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)20 PortNumber (org.onosproject.net.PortNumber)20 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)20 DeviceId (org.onosproject.net.DeviceId)18 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)18 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)18 Collection (java.util.Collection)16 Collectors (java.util.stream.Collectors)16