Search in sources :

Example 46 with VlanIdCriterion

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

the class FlowObjectiveCompositionUtil method revertTreatmentSelector.

public static TrafficSelector revertTreatmentSelector(TrafficTreatment trafficTreatment, TrafficSelector trafficSelector) {
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    Map<Criterion.Type, Criterion> criterionMap = new HashMap<>();
    for (Criterion criterion : trafficSelector.criteria()) {
        criterionMap.put(criterion.type(), criterion);
    }
    for (Instruction instruction : trafficTreatment.allInstructions()) {
        switch(instruction.type()) {
            case OUTPUT:
                break;
            case GROUP:
                break;
            case L0MODIFICATION:
                {
                    L0ModificationInstruction l0 = (L0ModificationInstruction) instruction;
                    switch(l0.subtype()) {
                        case OCH:
                            if (criterionMap.containsKey(Criterion.Type.OCH_SIGID)) {
                                if (((OchSignalCriterion) criterionMap.get((Criterion.Type.OCH_SIGID))).lambda().equals(((L0ModificationInstruction.ModOchSignalInstruction) l0).lambda())) {
                                    criterionMap.remove(Criterion.Type.OCH_SIGID);
                                } else {
                                    return null;
                                }
                            }
                        default:
                            break;
                    }
                    break;
                }
            case L1MODIFICATION:
                {
                    L1ModificationInstruction l1 = (L1ModificationInstruction) instruction;
                    switch(l1.subtype()) {
                        case ODU_SIGID:
                            if (criterionMap.containsKey(Criterion.Type.ODU_SIGID)) {
                                if (((OduSignalIdCriterion) criterionMap.get((Criterion.Type.ODU_SIGID))).oduSignalId().equals(((L1ModificationInstruction.ModOduSignalIdInstruction) l1).oduSignalId())) {
                                    criterionMap.remove(Criterion.Type.ODU_SIGID);
                                } else {
                                    return null;
                                }
                            }
                        default:
                            break;
                    }
                    break;
                }
            case L2MODIFICATION:
                {
                    L2ModificationInstruction l2 = (L2ModificationInstruction) instruction;
                    switch(l2.subtype()) {
                        case ETH_SRC:
                            if (criterionMap.containsKey(Criterion.Type.ETH_SRC)) {
                                if (((EthCriterion) criterionMap.get((Criterion.Type.ETH_SRC))).mac().equals(((L2ModificationInstruction.ModEtherInstruction) l2).mac())) {
                                    criterionMap.remove(Criterion.Type.ETH_SRC);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case ETH_DST:
                            if (criterionMap.containsKey(Criterion.Type.ETH_DST)) {
                                if (((EthCriterion) criterionMap.get((Criterion.Type.ETH_DST))).mac().equals(((L2ModificationInstruction.ModEtherInstruction) l2).mac())) {
                                    criterionMap.remove(Criterion.Type.ETH_DST);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case VLAN_ID:
                            if (criterionMap.containsKey(Criterion.Type.VLAN_VID)) {
                                if (((VlanIdCriterion) criterionMap.get((Criterion.Type.VLAN_VID))).vlanId().equals(((L2ModificationInstruction.ModVlanIdInstruction) l2).vlanId())) {
                                    criterionMap.remove(Criterion.Type.VLAN_VID);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case VLAN_PCP:
                            if (criterionMap.containsKey(Criterion.Type.VLAN_PCP)) {
                                if (((VlanPcpCriterion) criterionMap.get((Criterion.Type.VLAN_PCP))).priority() == ((L2ModificationInstruction.ModVlanPcpInstruction) l2).vlanPcp()) {
                                    criterionMap.remove(Criterion.Type.VLAN_PCP);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case MPLS_LABEL:
                            if (criterionMap.containsKey(Criterion.Type.MPLS_LABEL)) {
                                if (((MplsCriterion) criterionMap.get((Criterion.Type.MPLS_LABEL))).label().equals(((L2ModificationInstruction.ModMplsLabelInstruction) l2).label())) {
                                    criterionMap.remove(Criterion.Type.ETH_DST);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        default:
                            break;
                    }
                    break;
                }
            case TABLE:
                break;
            case L3MODIFICATION:
                {
                    L3ModificationInstruction l3 = (L3ModificationInstruction) instruction;
                    switch(l3.subtype()) {
                        case IPV4_SRC:
                            if (criterionMap.containsKey(Criterion.Type.IPV4_SRC)) {
                                if (((IPCriterion) criterionMap.get(Criterion.Type.IPV4_SRC)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
                                    criterionMap.remove(Criterion.Type.IPV4_SRC);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case IPV4_DST:
                            if (criterionMap.containsKey(Criterion.Type.IPV4_DST)) {
                                if (((IPCriterion) criterionMap.get(Criterion.Type.IPV4_DST)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
                                    criterionMap.remove(Criterion.Type.IPV4_DST);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case IPV6_SRC:
                            if (criterionMap.containsKey(Criterion.Type.IPV6_SRC)) {
                                if (((IPCriterion) criterionMap.get(Criterion.Type.IPV6_SRC)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
                                    criterionMap.remove(Criterion.Type.IPV6_SRC);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case IPV6_DST:
                            if (criterionMap.containsKey(Criterion.Type.IPV6_DST)) {
                                if (((IPCriterion) criterionMap.get(Criterion.Type.IPV6_DST)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
                                    criterionMap.remove(Criterion.Type.IPV6_DST);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        case IPV6_FLABEL:
                            if (criterionMap.containsKey(Criterion.Type.IPV6_FLABEL)) {
                                if (((IPv6FlowLabelCriterion) criterionMap.get(Criterion.Type.IPV6_FLABEL)).flowLabel() == (((L3ModificationInstruction.ModIPv6FlowLabelInstruction) l3).flowLabel())) {
                                    criterionMap.remove(Criterion.Type.IPV4_SRC);
                                } else {
                                    return null;
                                }
                            } else {
                                break;
                            }
                        default:
                            break;
                    }
                    break;
                }
            case METADATA:
                break;
            default:
                break;
        }
    }
    for (Criterion criterion : criterionMap.values()) {
        selectorBuilder.add(criterion);
    }
    return selectorBuilder.build();
}
Also used : EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) HashMap(java.util.HashMap) OduSignalIdCriterion(org.onosproject.net.flow.criteria.OduSignalIdCriterion) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L1ModificationInstruction(org.onosproject.net.flow.instructions.L1ModificationInstruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) VlanPcpCriterion(org.onosproject.net.flow.criteria.VlanPcpCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) OduSignalIdCriterion(org.onosproject.net.flow.criteria.OduSignalIdCriterion) IPv6FlowLabelCriterion(org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) L1ModificationInstruction(org.onosproject.net.flow.instructions.L1ModificationInstruction) IPv6FlowLabelCriterion(org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion) VlanPcpCriterion(org.onosproject.net.flow.criteria.VlanPcpCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 47 with VlanIdCriterion

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

the class LinkCollectionIntentCompilerP2PTest method testCompilationNonTrivialForP2P.

/**
 * We test the proper compilation of p2p with
 * selector, treatment and filtered points.
 */
@Test
public void testCompilationNonTrivialForP2P() {
    intent = LinkCollectionIntent.builder().appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment).applyTreatmentOnEgress(true).links(p2pLinks).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p0, mpls200Selector))).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(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.is(DefaultTrafficSelector.builder(ipPrefixSelector).matchInPort(d1p10.port()).matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).build()));
    assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setOutput(d1p0.port()).build()));
    Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS2, hasSize(1));
    FlowRule ruleS2 = rulesS2.iterator().next();
    assertThat(ruleS2.selector(), Is.is(DefaultTrafficSelector.builder(ipPrefixSelector).matchInPort(d2p0.port()).matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).build()));
    assertThat(ruleS2.treatment(), Is.is(DefaultTrafficTreatment.builder().setOutput(d2p1.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.is(DefaultTrafficSelector.builder(ipPrefixSelector).matchInPort(d3p1.port()).matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).build()));
    assertThat(ruleS3.treatment(), Is.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(d3p0.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) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Is(org.hamcrest.core.Is) Ethernet(org.onlab.packet.Ethernet) 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) VLAN_VID(org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID) 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) MPLS_LABEL(org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL) 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 48 with VlanIdCriterion

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

the class LinkCollectionIntentCompilerP2PTest method testMplsEncapsulationNonTrivialForP2P.

/**
 * We test the proper compilation of p2p with the MPLS
 * encapsulation, filtered points, selector and treatment.
 */
@Test
public void testMplsEncapsulationNonTrivialForP2P() {
    intent = LinkCollectionIntent.builder().appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment).constraints(constraintsForMPLS).links(linksForMp2Sp).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls69Selector))).build();
    sut.activate();
    /*
         * We use the FIRST_FIT to simplify tests.
         */
    LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
    List<Intent> compiled = sut.compile(intent, Collections.emptyList());
    assertThat(compiled, hasSize(1));
    Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
    assertThat(rules, hasSize(3));
    Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS1, hasSize(1));
    FlowRule ruleS1 = rulesS1.iterator().next();
    assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(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()).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()).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).matchEthType(Ethernet.MPLS_UNICAST).build()));
    assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d2p1.port()).build()));
    Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS3, hasSize(1));
    FlowRule ruleS3 = rulesS3.iterator().next();
    assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder().matchInPort(d3p0.port()).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).matchEthType(Ethernet.MPLS_UNICAST).build()));
    assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).setMpls(((MplsCriterion) mpls69Selector.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) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Is(org.hamcrest.core.Is) Ethernet(org.onlab.packet.Ethernet) 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) VLAN_VID(org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID) 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) MPLS_LABEL(org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL) 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 49 with VlanIdCriterion

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

the class LinkCollectionIntentCompilerP2PTest method testVlanEncapsulationNonTrivialForP2P.

/**
 * We test the proper compilation of p2p with the VLAN
 * encapsulation, filtered points, selector and treatment.
 */
@Test
public void testVlanEncapsulationNonTrivialForP2P() {
    intent = LinkCollectionIntent.builder().appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment).constraints(constraintsForVlan).links(linksForMp2Sp).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls69Selector))).build();
    sut.activate();
    /*
         * We use the FIRST_FIT to simplify tests.
         */
    LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
    List<Intent> compiled = sut.compile(intent, Collections.emptyList());
    assertThat(compiled, hasSize(1));
    Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
    assertThat(rules, hasSize(3));
    Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS1, hasSize(1));
    FlowRule ruleS1 = rulesS1.iterator().next();
    assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(ipPrefixSelector).matchInPort(d1p10.port()).matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).build()));
    assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d1p0.port()).build()));
    Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS2, hasSize(1));
    FlowRule ruleS2 = rulesS2.iterator().next();
    assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
    assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p1.port()).build()));
    Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p0.deviceId())).collect(Collectors.toSet());
    assertThat(rulesS3, hasSize(1));
    FlowRule ruleS3 = rulesS3.iterator().next();
    assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder().matchInPort(d3p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
    assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).popVlan().pushMpls().setMpls(((MplsCriterion) mpls69Selector.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) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Is(org.hamcrest.core.Is) Ethernet(org.onlab.packet.Ethernet) 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) VLAN_VID(org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID) 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) MPLS_LABEL(org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL) 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 50 with VlanIdCriterion

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

Aggregations

VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)65 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)48 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)45 FlowRule (org.onosproject.net.flow.FlowRule)41 VlanId (org.onlab.packet.VlanId)37 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)35 List (java.util.List)32 DeviceId (org.onosproject.net.DeviceId)30 TrafficSelector (org.onosproject.net.flow.TrafficSelector)30 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)30 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)28 Collection (java.util.Collection)27 Collections (java.util.Collections)27 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)27 Collectors (java.util.stream.Collectors)26 Criterion (org.onosproject.net.flow.criteria.Criterion)26 Test (org.junit.Test)25 ImmutableSet (com.google.common.collect.ImmutableSet)24 CoreService (org.onosproject.core.CoreService)24 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)24