Search in sources :

Example 16 with ModEtherInstruction

use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction in project onos by opennetworkinglab.

the class LinkCollectionOptimizationTest method testCoLocatedDifferentFilteredPointsNonTrivialForSp.

/**
 * We test the proper optimization 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();
    /*
         * 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().copyTtlOut().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()).copyTtlIn().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) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) 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) IPV4(org.onlab.packet.EthType.EtherType.IPV4) 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 17 with ModEtherInstruction

use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction in project onos by opennetworkinglab.

the class FabricTreatmentInterpreter method mapNextHashedOrSimpleTreatment.

private static PiAction mapNextHashedOrSimpleTreatment(TrafficTreatment treatment, PiTableId tableId, boolean simple) throws PiInterpreterException {
    // Provide mapping for output_hashed and routing_hashed; multicast_hashed
    // can only be invoked with PiAction, hence no mapping. outPort required for
    // all actions. Presence of other instructions will determine which action to map to.
    final PortNumber outPort = ((OutputInstruction) instructionOrFail(treatment, OUTPUT, tableId)).port();
    final ModEtherInstruction ethDst = (ModEtherInstruction) l2Instruction(treatment, ETH_DST);
    final ModEtherInstruction ethSrc = (ModEtherInstruction) l2Instruction(treatment, ETH_SRC);
    final PiAction.Builder actionBuilder = PiAction.builder().withParameter(new PiActionParam(FabricConstants.PORT_NUM, outPort.toLong()));
    if (ethDst != null && ethSrc != null) {
        actionBuilder.withParameter(new PiActionParam(FabricConstants.SMAC, ethSrc.mac().toBytes()));
        actionBuilder.withParameter(new PiActionParam(FabricConstants.DMAC, ethDst.mac().toBytes()));
        // routing_hashed
        return actionBuilder.withId(simple ? FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_SIMPLE : FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).build();
    } else {
        // output_hashed
        return actionBuilder.withId(simple ? FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_SIMPLE : FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_HASHED).build();
    }
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 18 with ModEtherInstruction

use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction in project onos by opennetworkinglab.

the class LinkCollectionCompiler method updateBuilder.

/**
 * Update the selector builder using a L2 instruction.
 *
 * @param builder the builder to update
 * @param l2instruction the l2 instruction to use
 */
private void updateBuilder(TrafficSelector.Builder builder, L2ModificationInstruction l2instruction) {
    switch(l2instruction.subtype()) {
        case ETH_SRC:
        case ETH_DST:
            ModEtherInstruction ethInstr = (ModEtherInstruction) l2instruction;
            switch(ethInstr.subtype()) {
                case ETH_SRC:
                    builder.matchEthSrc(ethInstr.mac());
                    break;
                case ETH_DST:
                    builder.matchEthDst(ethInstr.mac());
                    break;
                default:
                    throw new IntentCompilationException(UNSUPPORTED_ETH_SUBTYPE);
            }
            break;
        case VLAN_ID:
            ModVlanIdInstruction vlanIdInstr = (ModVlanIdInstruction) l2instruction;
            builder.matchVlanId(vlanIdInstr.vlanId());
            break;
        case VLAN_PUSH:
            // FIXME
            break;
        case VLAN_POP:
            // TODO how do we handle dropped label? remove the selector?
            throw new IntentCompilationException(UNSUPPORTED_POP_ACTION);
        case VLAN_PCP:
            ModVlanPcpInstruction vlanPcpInstruction = (ModVlanPcpInstruction) l2instruction;
            builder.matchVlanPcp(vlanPcpInstruction.vlanPcp());
            break;
        case MPLS_LABEL:
        case MPLS_PUSH:
            // FIXME
            ModMplsLabelInstruction mplsInstr = (ModMplsLabelInstruction) l2instruction;
            builder.matchMplsLabel(mplsInstr.label());
            break;
        case MPLS_POP:
            // TODO how do we handle dropped label? remove the selector?
            throw new IntentCompilationException(UNSUPPORTED_POP_ACTION);
        case DEC_MPLS_TTL:
            // no-op
            break;
        case MPLS_BOS:
            ModMplsBosInstruction mplsBosInstr = (ModMplsBosInstruction) l2instruction;
            builder.matchMplsBos(mplsBosInstr.mplsBos());
            break;
        case TUNNEL_ID:
            ModTunnelIdInstruction tunInstr = (ModTunnelIdInstruction) l2instruction;
            builder.matchTunnelId(tunInstr.tunnelId());
            break;
        default:
            throw new IntentCompilationException(UNSUPPORTED_L2);
    }
}
Also used : ModMplsLabelInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction) ModTunnelIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction) ModMplsBosInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsBosInstruction) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) ModVlanPcpInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction)

Aggregations

ModEtherInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction)18 Test (org.junit.Test)12 Intent (org.onosproject.net.intent.Intent)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 Collection (java.util.Collection)11 Collections (java.util.Collections)11 List (java.util.List)11 Collectors (java.util.stream.Collectors)11 EasyMock (org.easymock.EasyMock)11 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)11 Before (org.junit.Before)11 VlanId (org.onlab.packet.VlanId)11 ComponentConfigAdapter (org.onosproject.cfg.ComponentConfigAdapter)11 CoreService (org.onosproject.core.CoreService)11 DeviceId (org.onosproject.net.DeviceId)11 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)11 APP_ID (org.onosproject.net.NetTestTools.APP_ID)11 LOCAL (org.onosproject.net.domain.DomainId.LOCAL)11 DomainService (org.onosproject.net.domain.DomainService)11 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)11