Search in sources :

Example 1 with VlanIdCriterion

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

the class TsLoopPacket method copyPacketMatch.

/**
 * Creates and returns a new packet instance with the copied match fields.
 *
 * With hard-copied match fields, references to path flows and path links.
 *
 * @return new loop packet instance with the copied match fields
 */
public TsLoopPacket copyPacketMatch() {
    TsLoopPacket newOne = new TsLoopPacket();
    newOne.pathFlow = this.pathFlow;
    newOne.pathLink = this.pathLink;
    Map<Criterion.Type, Criterion> m = newOne.match;
    for (Map.Entry<Criterion.Type, Criterion> entry : this.match.entrySet()) {
        Criterion.Type k = entry.getKey();
        Criterion v = entry.getValue();
        switch(k) {
            case IN_PORT:
                m.put(k, matchInPort(((PortCriterion) v).port()));
                break;
            case // At present, not support Ethernet mask (ONOS?)
            ETH_SRC:
                m.put(k, matchEthSrc(((EthCriterion) v).mac()));
                break;
            case // At present, not support Ethernet mask (ONOS?)
            ETH_DST:
                m.put(k, matchEthDst(((EthCriterion) v).mac()));
                break;
            case ETH_TYPE:
                m.put(k, matchEthType(((EthTypeCriterion) v).ethType()));
                break;
            case // At present, not support VLAN mask (ONOS?)
            VLAN_VID:
                m.put(k, matchVlanId(((VlanIdCriterion) v).vlanId()));
                break;
            case VLAN_PCP:
                m.put(k, matchVlanPcp(((VlanPcpCriterion) v).priority()));
                break;
            case IPV4_SRC:
                m.put(k, matchIPSrc(((IPCriterion) v).ip()));
                break;
            case IPV4_DST:
                m.put(k, matchIPDst(((IPCriterion) v).ip()));
                break;
            case IP_PROTO:
                m.put(k, matchIPProtocol(((IPProtocolCriterion) v).protocol()));
                break;
            case // can't be supported by now
            IP_DSCP:
                m.put(k, matchIPDscp(((IPDscpCriterion) v).ipDscp()));
                break;
            case // can't be supported by now
            IP_ECN:
                m.put(k, matchIPEcn(((IPEcnCriterion) v).ipEcn()));
                break;
            case TCP_SRC:
                m.put(k, matchTcpSrc(((TcpPortCriterion) v).tcpPort()));
                break;
            case TCP_DST:
                m.put(k, matchTcpDst(((TcpPortCriterion) v).tcpPort()));
                break;
            case UDP_SRC:
                m.put(k, matchUdpSrc(((UdpPortCriterion) v).udpPort()));
                break;
            case UDP_DST:
                m.put(k, matchUdpDst(((UdpPortCriterion) v).udpPort()));
                break;
            default:
                // can't be supported by OF1.0
                log.debug("{} can't be supported by OF1.0", k);
                break;
        }
    }
    return newOne;
}
Also used : EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) IPDscpCriterion(org.onosproject.net.flow.criteria.IPDscpCriterion) VlanPcpCriterion(org.onosproject.net.flow.criteria.VlanPcpCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPEcnCriterion(org.onosproject.net.flow.criteria.IPEcnCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) VlanPcpCriterion(org.onosproject.net.flow.criteria.VlanPcpCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) IPDscpCriterion(org.onosproject.net.flow.criteria.IPDscpCriterion) HashMap(java.util.HashMap) Map(java.util.Map) IPEcnCriterion(org.onosproject.net.flow.criteria.IPEcnCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 2 with VlanIdCriterion

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

the class LinkCollectionEncapIntentCompilerTest method testMplsEncapsulationNonTrivialForSp.

/**
 * We test the proper compilation of sp2mp with the MPLS
 * encapsulation, filtered selector, intent selector, and
 * intent treatment.
 */
@Test
public void testMplsEncapsulationNonTrivialForSp() {
    intent = LinkCollectionIntent.builder().appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment).constraints(constraintsForMPLS).links(linksForSp2Mp).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan69Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector), new FilteredConnectPoint(d1p11, vlan200Selector), new FilteredConnectPoint(d2p10, vlan300Selector))).build();
    sut.activate();
    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> 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(ipPrefixSelector).matchInPort(d3p10.port()).matchVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId()).build()));
    assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d3p0.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(d2p1.port()).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).matchEthType(Ethernet.MPLS_UNICAST).build()));
    assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d2p0.port()).setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).popMpls(IPV4.ethType()).pushVlan().setVlanId(((VlanIdCriterion) vlan300Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d2p10.port()).build()));
    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().matchInPort(d1p0.port()).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).matchEthType(Ethernet.MPLS_UNICAST).build()));
    assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).popMpls(IPV4.ethType()).pushVlan().setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p10.port()).setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p11.port()).build()));
    sut.deactivate();
}
Also used : MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) APP_ID(org.onosproject.net.NetTestTools.APP_ID) CoreService(org.onosproject.core.CoreService) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Ethernet(org.onlab.packet.Ethernet) Type(org.onosproject.net.flow.criteria.Criterion.Type) DomainService(org.onosproject.net.domain.DomainService) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) Is.is(org.hamcrest.core.Is.is) Intent(org.onosproject.net.intent.Intent) Matchers.hasSize(org.hamcrest.Matchers.hasSize) 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) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) IPV4(org.onlab.packet.EthType.EtherType.IPV4) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) 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) 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) 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 3 with VlanIdCriterion

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

the class LinkCollectionEncapIntentCompilerTest method testVlanEncapsulationDifferentFilterForSp.

/**
 * We test the proper compilation of sp2mp with the VLAN
 * encapsulation and filtered selectors of different type.
 */
@Test
public void testVlanEncapsulationDifferentFilterForSp() {
    intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).constraints(constraintsForVlan).links(linksForSp2Mp).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan200Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, mpls100Selector), new FilteredConnectPoint(d1p11, vlan100Selector), new FilteredConnectPoint(d2p10, mpls200Selector))).build();
    sut.activate();
    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> 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(vlan200Selector).matchInPort(d3p10.port()).build()));
    assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d3p0.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(d2p1.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
    assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p0.port()).popVlan().pushMpls().setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d2p10.port()).build()));
    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().matchInPort(d1p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
    assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p11.port()).popVlan().pushMpls().setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d1p10.port()).build()));
    sut.deactivate();
}
Also used : MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) APP_ID(org.onosproject.net.NetTestTools.APP_ID) CoreService(org.onosproject.core.CoreService) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Ethernet(org.onlab.packet.Ethernet) Type(org.onosproject.net.flow.criteria.Criterion.Type) DomainService(org.onosproject.net.domain.DomainService) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) Is.is(org.hamcrest.core.Is.is) Intent(org.onosproject.net.intent.Intent) Matchers.hasSize(org.hamcrest.Matchers.hasSize) 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) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) IPV4(org.onlab.packet.EthType.EtherType.IPV4) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) 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) 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) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Example 4 with VlanIdCriterion

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

the class LinkCollectionEncapIntentCompilerTest method testCoLocatedDifferentFilteredPointsNonTrivialForSp.

/**
 * We test the proper compilation of sp2mp with selector,
 * treatment, mpls encapsulation and co-located
 * different filtered ingress/egress points.
 */
@Test
public void testCoLocatedDifferentFilteredPointsNonTrivialForSp() {
    intent = LinkCollectionIntent.builder().appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment).applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc).constraints(constraintsForMPLS).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls100Selector), new FilteredConnectPoint(d2p10, vlan200Selector), new FilteredConnectPoint(d3p10, mpls200Selector))).build();
    sut.activate();
    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(ipPrefixSelector).matchInPort(d1p10.port()).matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).build()));
    assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d1p0.port()).setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d1p11.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()).matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).build()));
    assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d2p1.port()).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(d2p10.port()).build()));
    Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p1.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS3, hasSize(1));
    FlowRule ruleS3 = rulesS3.iterator().next();
    assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder().matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).matchInPort(d3p0.port()).build()));
    assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d3p10.port()).build()));
    sut.deactivate();
}
Also used : MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) APP_ID(org.onosproject.net.NetTestTools.APP_ID) CoreService(org.onosproject.core.CoreService) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Ethernet(org.onlab.packet.Ethernet) Type(org.onosproject.net.flow.criteria.Criterion.Type) DomainService(org.onosproject.net.domain.DomainService) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) Is.is(org.hamcrest.core.Is.is) Intent(org.onosproject.net.intent.Intent) Matchers.hasSize(org.hamcrest.Matchers.hasSize) 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) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) IPV4(org.onlab.packet.EthType.EtherType.IPV4) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) 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) 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) 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 5 with VlanIdCriterion

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

the class LinkCollectionEncapIntentCompilerTest method testCoLocatedDifferentFilteredPointsNonTrivialForMp.

/**
 * We test the proper compilation of mp2sp with selector,
 * treatment, vlan encapsulation and co-located
 * filtered ingress/egress points.
 */
@Test
public void testCoLocatedDifferentFilteredPointsNonTrivialForMp() {
    intent = LinkCollectionIntent.builder().appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment).links(linksForMp2SpCoLoc).constraints(constraintsForVlan).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, mpls100Selector), new FilteredConnectPoint(d2p10, vlan100Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls200Selector))).build();
    sut.activate();
    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(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(DefaultTrafficSelector.builder(ipPrefixSelector).matchInPort(d1p10.port()).matchMplsLabel(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()).build()));
    assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d1p11.port()).build()));
    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(DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId(LABEL)).matchInPort(d1p0.port()).build()));
    assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().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()));
    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(ipPrefixSelector).matchInPort(d2p10.port()).matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).build()));
    assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p0.port()).build()));
    sut.deactivate();
}
Also used : MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) APP_ID(org.onosproject.net.NetTestTools.APP_ID) CoreService(org.onosproject.core.CoreService) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Ethernet(org.onlab.packet.Ethernet) Type(org.onosproject.net.flow.criteria.Criterion.Type) DomainService(org.onosproject.net.domain.DomainService) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) Is.is(org.hamcrest.core.Is.is) Intent(org.onosproject.net.intent.Intent) Matchers.hasSize(org.hamcrest.Matchers.hasSize) 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) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) IPV4(org.onlab.packet.EthType.EtherType.IPV4) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) 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) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) 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)

Aggregations

VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)60 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)45 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)43 FlowRule (org.onosproject.net.flow.FlowRule)41 VlanId (org.onlab.packet.VlanId)35 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)35 List (java.util.List)31 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)29 DeviceId (org.onosproject.net.DeviceId)28 Collection (java.util.Collection)26 Collections (java.util.Collections)26 TrafficSelector (org.onosproject.net.flow.TrafficSelector)26 Collectors (java.util.stream.Collectors)25 Test (org.junit.Test)25 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)25 ImmutableSet (com.google.common.collect.ImmutableSet)24 CoreService (org.onosproject.core.CoreService)24 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)24 LOCAL (org.onosproject.net.domain.DomainId.LOCAL)24 DomainService (org.onosproject.net.domain.DomainService)24