Search in sources :

Example 11 with EthType

use of org.onlab.packet.EthType in project onos by opennetworkinglab.

the class FlowRuleCodecTest method codecCriteriaFlowTest.

/**
 * Checks that a rule with one of each kind of criterion decodes properly.
 *
 * @throws IOException if the resource cannot be processed
 */
@Test
public void codecCriteriaFlowTest() throws Exception {
    FlowRule rule = getRule("criteria-flow.json");
    checkCommonData(rule);
    assertThat(rule.selector().criteria().size(), is(35));
    rule.selector().criteria().forEach(criterion -> criteria.put(criterion.type().name(), criterion));
    Criterion criterion;
    criterion = getCriterion(Criterion.Type.ETH_TYPE);
    assertThat(((EthTypeCriterion) criterion).ethType(), is(new EthType(2054)));
    criterion = getCriterion(Criterion.Type.ETH_DST);
    assertThat(((EthCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:55")));
    criterion = getCriterion(Criterion.Type.ETH_SRC);
    assertThat(((EthCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:55")));
    criterion = getCriterion(Criterion.Type.IN_PORT);
    assertThat(((PortCriterion) criterion).port(), is(PortNumber.portNumber(23)));
    criterion = getCriterion(Criterion.Type.IN_PHY_PORT);
    assertThat(((PortCriterion) criterion).port(), is(PortNumber.portNumber(44)));
    criterion = getCriterion(Criterion.Type.VLAN_VID);
    assertThat(((VlanIdCriterion) criterion).vlanId(), is(VlanId.vlanId((short) 777)));
    criterion = getCriterion(Criterion.Type.VLAN_PCP);
    assertThat(((VlanPcpCriterion) criterion).priority(), is(((byte) 3)));
    criterion = getCriterion(Criterion.Type.IP_DSCP);
    assertThat(((IPDscpCriterion) criterion).ipDscp(), is(((byte) 2)));
    criterion = getCriterion(Criterion.Type.IP_ECN);
    assertThat(((IPEcnCriterion) criterion).ipEcn(), is(((byte) 1)));
    criterion = getCriterion(Criterion.Type.IP_PROTO);
    assertThat(((IPProtocolCriterion) criterion).protocol(), is(((short) 4)));
    criterion = getCriterion(Criterion.Type.IPV4_SRC);
    assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("1.2.0.0/32"))));
    criterion = getCriterion(Criterion.Type.IPV4_DST);
    assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("2.2.0.0/32"))));
    criterion = getCriterion(Criterion.Type.IPV6_SRC);
    assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("3.2.0.0/32"))));
    criterion = getCriterion(Criterion.Type.IPV6_DST);
    assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("4.2.0.0/32"))));
    criterion = getCriterion(Criterion.Type.TCP_SRC);
    assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(), is(80));
    criterion = getCriterion(Criterion.Type.TCP_DST);
    assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(), is(443));
    criterion = getCriterion(Criterion.Type.UDP_SRC);
    assertThat(((UdpPortCriterion) criterion).udpPort().toInt(), is(180));
    criterion = getCriterion(Criterion.Type.UDP_DST);
    assertThat(((UdpPortCriterion) criterion).udpPort().toInt(), is(1443));
    criterion = getCriterion(Criterion.Type.SCTP_SRC);
    assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(), is(280));
    criterion = getCriterion(Criterion.Type.SCTP_DST);
    assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(), is(2443));
    criterion = getCriterion(Criterion.Type.ICMPV4_TYPE);
    assertThat(((IcmpTypeCriterion) criterion).icmpType(), is((short) 24));
    criterion = getCriterion(Criterion.Type.ICMPV4_CODE);
    assertThat(((IcmpCodeCriterion) criterion).icmpCode(), is((short) 16));
    criterion = getCriterion(Criterion.Type.ICMPV6_TYPE);
    assertThat(((Icmpv6TypeCriterion) criterion).icmpv6Type(), is((short) 14));
    criterion = getCriterion(Criterion.Type.ICMPV6_CODE);
    assertThat(((Icmpv6CodeCriterion) criterion).icmpv6Code(), is((short) 6));
    criterion = getCriterion(Criterion.Type.IPV6_FLABEL);
    assertThat(((IPv6FlowLabelCriterion) criterion).flowLabel(), is(8));
    criterion = getCriterion(Criterion.Type.IPV6_ND_TARGET);
    assertThat(((IPv6NDTargetAddressCriterion) criterion).targetAddress().toString(), is("1111:2222:3333:4444:5555:6666:7777:8888"));
    criterion = getCriterion(Criterion.Type.IPV6_ND_SLL);
    assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:56")));
    criterion = getCriterion(Criterion.Type.IPV6_ND_TLL);
    assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:57")));
    criterion = getCriterion(Criterion.Type.MPLS_LABEL);
    assertThat(((MplsCriterion) criterion).label(), is(MplsLabel.mplsLabel(123)));
    criterion = getCriterion(Criterion.Type.IPV6_EXTHDR);
    assertThat(((IPv6ExthdrFlagsCriterion) criterion).exthdrFlags(), is(99));
    criterion = getCriterion(Criterion.Type.TUNNEL_ID);
    assertThat(((TunnelIdCriterion) criterion).tunnelId(), is(100L));
    criterion = getCriterion(Criterion.Type.OCH_SIGTYPE);
    assertThat(((OchSignalTypeCriterion) criterion).signalType(), is(OchSignalType.FIXED_GRID));
    criterion = getCriterion(Criterion.Type.ODU_SIGTYPE);
    assertThat(((OduSignalTypeCriterion) criterion).signalType(), is(OduSignalType.ODU4));
    criterion = getCriterion(Criterion.Type.ODU_SIGID);
    assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributaryPortNumber(), is(1));
    assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotLength(), is(80));
    assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotBitmap(), is(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }));
}
Also used : EthType(org.onlab.packet.EthType) 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) IcmpTypeCriterion(org.onosproject.net.flow.criteria.IcmpTypeCriterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) IcmpCodeCriterion(org.onosproject.net.flow.criteria.IcmpCodeCriterion) IPv6NDTargetAddressCriterion(org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion) Icmpv6TypeCriterion(org.onosproject.net.flow.criteria.Icmpv6TypeCriterion) SctpPortCriterion(org.onosproject.net.flow.criteria.SctpPortCriterion) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) IPv6NDLinkLayerAddressCriterion(org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPEcnCriterion(org.onosproject.net.flow.criteria.IPEcnCriterion) OduSignalTypeCriterion(org.onosproject.net.flow.criteria.OduSignalTypeCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) OduSignalIdCriterion(org.onosproject.net.flow.criteria.OduSignalIdCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) Icmpv6CodeCriterion(org.onosproject.net.flow.criteria.Icmpv6CodeCriterion) OchSignalTypeCriterion(org.onosproject.net.flow.criteria.OchSignalTypeCriterion) IPv6FlowLabelCriterion(org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion) IPv6ExthdrFlagsCriterion(org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPv6NDTargetAddressCriterion(org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) OduSignalIdCriterion(org.onosproject.net.flow.criteria.OduSignalIdCriterion) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) SctpPortCriterion(org.onosproject.net.flow.criteria.SctpPortCriterion) Test(org.junit.Test)

Example 12 with EthType

use of org.onlab.packet.EthType in project onos by opennetworkinglab.

the class HostCodec method decode.

@Override
public Host decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(MAC), MAC + MISSING_MEMBER_MESSAGE).asText());
    VlanId vlanId = VlanId.vlanId(nullIsIllegal(json.get(VLAN), VLAN + MISSING_MEMBER_MESSAGE).asText());
    HostId id = HostId.hostId(mac, vlanId);
    ArrayNode locationNodes = nullIsIllegal((ArrayNode) json.get(HOST_LOCATIONS), HOST_LOCATIONS + MISSING_MEMBER_MESSAGE);
    Set<HostLocation> hostLocations = context.codec(HostLocation.class).decode(locationNodes, context).stream().collect(Collectors.toSet());
    ArrayNode ipNodes = nullIsIllegal((ArrayNode) json.get(IP_ADDRESSES), IP_ADDRESSES + MISSING_MEMBER_MESSAGE);
    Set<IpAddress> ips = new HashSet<>();
    ipNodes.forEach(ipNode -> {
        ips.add(IpAddress.valueOf(ipNode.asText()));
    });
    // check optional fields
    JsonNode innerVlanIdNode = json.get(INNER_VLAN);
    VlanId innerVlanId = (null == innerVlanIdNode) ? VlanId.NONE : VlanId.vlanId(innerVlanIdNode.asText());
    JsonNode outerTpidNode = json.get(OUTER_TPID);
    EthType outerTpid = (null == outerTpidNode) ? EthType.EtherType.UNKNOWN.ethType() : EthType.EtherType.lookup((short) (Integer.decode(outerTpidNode.asText()) & 0xFFFF)).ethType();
    JsonNode configuredNode = json.get(IS_CONFIGURED);
    boolean configured = (null == configuredNode) ? false : configuredNode.asBoolean();
    JsonNode suspendedNode = json.get(IS_SUSPENDED);
    boolean suspended = (null == suspendedNode) ? false : suspendedNode.asBoolean();
    ArrayNode auxLocationNodes = (ArrayNode) json.get(AUX_LOCATIONS);
    Set<HostLocation> auxHostLocations = (null == auxLocationNodes) ? null : context.codec(HostLocation.class).decode(auxLocationNodes, context).stream().collect(Collectors.toSet());
    Annotations annotations = extractAnnotations(json, context);
    return new DefaultHost(ProviderId.NONE, id, mac, vlanId, hostLocations, auxHostLocations, ips, innerVlanId, outerTpid, configured, suspended, annotations);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) DefaultHost(org.onosproject.net.DefaultHost) EthType(org.onlab.packet.EthType) Annotations(org.onosproject.net.Annotations) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) VlanId(org.onlab.packet.VlanId) HashSet(java.util.HashSet)

Example 13 with EthType

use of org.onlab.packet.EthType in project onos by opennetworkinglab.

the class OfdpaPipelineTraceable method translateInstruction.

// Applies an instruction to the packet in the form of a selector
private TrafficSelector.Builder translateInstruction(TrafficSelector.Builder newSelector, Instruction instruction) {
    log.debug("Translating instruction {}", instruction);
    log.debug("New Selector {}", newSelector.build());
    // TODO add as required
    Criterion criterion = null;
    if (instruction.type() == Instruction.Type.L2MODIFICATION) {
        L2ModificationInstruction l2Instruction = (L2ModificationInstruction) instruction;
        switch(l2Instruction.subtype()) {
            case VLAN_ID:
                ModVlanIdInstruction vlanIdInstruction = (ModVlanIdInstruction) instruction;
                VlanId id = vlanIdInstruction.vlanId();
                criterion = Criteria.matchVlanId(id);
                break;
            case VLAN_POP:
                criterion = Criteria.matchVlanId(VlanId.NONE);
                break;
            case MPLS_PUSH:
                L2ModificationInstruction.ModMplsHeaderInstruction mplsEthInstruction = (L2ModificationInstruction.ModMplsHeaderInstruction) instruction;
                criterion = Criteria.matchEthType(mplsEthInstruction.ethernetType().toShort());
                // When pushing MPLS adding metadata to remember the original ethtype
                if (isHardwareSwitch()) {
                    TrafficSelector temporaryPacket = newSelector.build();
                    Criterion ethCriterion = temporaryPacket.getCriterion(Criterion.Type.ETH_TYPE);
                    if (ethCriterion != null) {
                        TrafficSelector.Builder tempSelector = DefaultTrafficSelector.builder(temporaryPacket);
                        // Store the old ether type for the
                        tempSelector.matchMetadata(((EthTypeCriterion) ethCriterion).ethType().toShort());
                        newSelector = tempSelector;
                    }
                }
                break;
            case MPLS_POP:
                L2ModificationInstruction.ModMplsHeaderInstruction mplsPopInstruction = (L2ModificationInstruction.ModMplsHeaderInstruction) instruction;
                criterion = Criteria.matchEthType(mplsPopInstruction.ethernetType().toShort());
                // When popping MPLS we remove label and BOS
                TrafficSelector temporaryPacket = newSelector.build();
                if (temporaryPacket.getCriterion(Criterion.Type.MPLS_LABEL) != null) {
                    TrafficSelector.Builder noMplsSelector = DefaultTrafficSelector.builder();
                    temporaryPacket.criteria().stream().filter(c -> !c.type().equals(Criterion.Type.MPLS_LABEL) && !c.type().equals(Criterion.Type.MPLS_BOS)).forEach(noMplsSelector::add);
                    newSelector = noMplsSelector;
                }
                break;
            case MPLS_LABEL:
                L2ModificationInstruction.ModMplsLabelInstruction mplsLabelInstruction = (L2ModificationInstruction.ModMplsLabelInstruction) instruction;
                criterion = Criteria.matchMplsLabel(mplsLabelInstruction.label());
                newSelector.matchMplsBos(true);
                break;
            case ETH_DST:
                L2ModificationInstruction.ModEtherInstruction modEtherDstInstruction = (L2ModificationInstruction.ModEtherInstruction) instruction;
                criterion = Criteria.matchEthDst(modEtherDstInstruction.mac());
                break;
            case ETH_SRC:
                L2ModificationInstruction.ModEtherInstruction modEtherSrcInstruction = (L2ModificationInstruction.ModEtherInstruction) instruction;
                criterion = Criteria.matchEthSrc(modEtherSrcInstruction.mac());
                break;
            default:
                log.debug("Unsupported L2 Instruction");
                break;
        }
    } else {
        log.debug("Unsupported Instruction");
    }
    if (criterion != null) {
        log.debug("Adding criterion {}", criterion);
        newSelector.add(criterion);
    }
    return newSelector;
}
Also used : PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) ConnectPoint(org.onosproject.net.ConnectPoint) DataPlaneEntity(org.onosproject.net.DataPlaneEntity) PipelineTraceable(org.onosproject.net.behaviour.PipelineTraceable) L2_INTERFACE_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_INTERFACE_TYPE) TMAC_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.TMAC_TABLE) Map(java.util.Map) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IndexTableId(org.onosproject.net.flow.IndexTableId) VLAN_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.VLAN_TABLE) Set(java.util.Set) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) Collectors(java.util.stream.Collectors) L3_MULTICAST_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L3_MULTICAST_TYPE) L2_MULTICAST_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_MULTICAST_TYPE) EthType(org.onlab.packet.EthType) PipelineTraceableOutput(org.onosproject.net.PipelineTraceableOutput) List(java.util.List) PipelineTraceableInput(org.onosproject.net.PipelineTraceableInput) FlowRule(org.onosproject.net.flow.FlowRule) MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) Ofdpa2Pipeline(org.onosproject.driver.pipeline.ofdpa.Ofdpa2Pipeline) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) Pipeliner(org.onosproject.net.behaviour.Pipeliner) PipelineTraceableHitChain(org.onosproject.net.PipelineTraceableHitChain) BRIDGING_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.BRIDGING_TABLE) TableId(org.onosproject.net.flow.TableId) ACL_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.ACL_TABLE) GroupBucket(org.onosproject.net.group.GroupBucket) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) OvsOfdpaPipeline(org.onosproject.driver.pipeline.ofdpa.OvsOfdpaPipeline) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) PipelineTraceablePacket(org.onosproject.net.PipelineTraceablePacket) L2_FLOOD_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_FLOOD_TYPE) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) MPLS_L3_TYPE_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.MPLS_L3_TYPE_TABLE) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) GroupId(org.onosproject.core.GroupId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MULTICAST_ROUTING_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.MULTICAST_ROUTING_TABLE) Comparator(java.util.Comparator) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) VlanId(org.onlab.packet.VlanId)

Example 14 with EthType

use of org.onlab.packet.EthType in project onos by opennetworkinglab.

the class OfdpaPipelineTraceable method handleOfdpa27FixedTable.

// Handles table 27 in Ofpda which is a fixed table not visible to any controller that handles Mpls Labels.
private TrafficSelector handleOfdpa27FixedTable(TrafficSelector initialPacket, TrafficSelector packet) {
    log.debug("Handling table 27 on OFDPA, removing mpls ETH Type and change mpls label");
    Criterion mplsCriterion = packet.getCriterion(Criterion.Type.ETH_TYPE);
    // T3 was using the initial packet of the trace - using the metadata in the packet to carry this info
    Criterion metadataCriterion = initialPacket.getCriterion(Criterion.Type.METADATA);
    ImmutableList.Builder<Instruction> builder = ImmutableList.builder();
    // If the packet comes in with the expected elements we update it as per OFDPA spec.
    if (mplsCriterion != null && ((EthTypeCriterion) mplsCriterion).ethType().equals(EthType.EtherType.MPLS_UNICAST.ethType()) && metadataCriterion != null) {
        // Get the metadata to restore the original ethertype
        long ethType = ((MetadataCriterion) metadataCriterion).metadata();
        // TODO update with parsing with eth MPLS pop Instruction for treating label an bos
        Instruction ethInstruction = Instructions.popMpls(EthType.EtherType.lookup((short) ethType).ethType());
        // FIXME what do we use as L3_Unicast mpls Label ?
        // translateInstruction(builder, ethInstruction);
        builder.add(ethInstruction);
        // Filtering out metadata
        TrafficSelector.Builder currentPacketBuilder = DefaultTrafficSelector.builder();
        packet.criteria().stream().filter(criterion -> criterion.type() != Criterion.Type.METADATA).forEach(currentPacketBuilder::add);
        packet = currentPacketBuilder.build();
    }
    packet = updatePacket(packet, builder.build()).build();
    return packet;
}
Also used : PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) ConnectPoint(org.onosproject.net.ConnectPoint) DataPlaneEntity(org.onosproject.net.DataPlaneEntity) PipelineTraceable(org.onosproject.net.behaviour.PipelineTraceable) L2_INTERFACE_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_INTERFACE_TYPE) TMAC_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.TMAC_TABLE) Map(java.util.Map) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IndexTableId(org.onosproject.net.flow.IndexTableId) VLAN_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.VLAN_TABLE) Set(java.util.Set) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) Collectors(java.util.stream.Collectors) L3_MULTICAST_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L3_MULTICAST_TYPE) L2_MULTICAST_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_MULTICAST_TYPE) EthType(org.onlab.packet.EthType) PipelineTraceableOutput(org.onosproject.net.PipelineTraceableOutput) List(java.util.List) PipelineTraceableInput(org.onosproject.net.PipelineTraceableInput) FlowRule(org.onosproject.net.flow.FlowRule) MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) Ofdpa2Pipeline(org.onosproject.driver.pipeline.ofdpa.Ofdpa2Pipeline) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) Pipeliner(org.onosproject.net.behaviour.Pipeliner) PipelineTraceableHitChain(org.onosproject.net.PipelineTraceableHitChain) BRIDGING_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.BRIDGING_TABLE) TableId(org.onosproject.net.flow.TableId) ACL_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.ACL_TABLE) GroupBucket(org.onosproject.net.group.GroupBucket) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) OvsOfdpaPipeline(org.onosproject.driver.pipeline.ofdpa.OvsOfdpaPipeline) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) PipelineTraceablePacket(org.onosproject.net.PipelineTraceablePacket) L2_FLOOD_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_FLOOD_TYPE) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) MPLS_L3_TYPE_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.MPLS_L3_TYPE_TABLE) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) GroupId(org.onosproject.core.GroupId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MULTICAST_ROUTING_TABLE(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.MULTICAST_ROUTING_TABLE) Comparator(java.util.Comparator) MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) ImmutableList(com.google.common.collect.ImmutableList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction)

Example 15 with EthType

use of org.onlab.packet.EthType in project onos by opennetworkinglab.

the class Ofdpa2Pipeline method processEgress.

/**
 * In the OF-DPA 2.0 pipeline, egress forwarding objectives go to the
 * egress tables.
 * @param fwd  the forwarding objective of type 'egress'
 * @return     a collection of flow rules to be sent to the switch. An empty
 *             collection may be returned if there is a problem in processing
 *             the flow rule
 */
protected Collection<FlowRule> processEgress(ForwardingObjective fwd) {
    log.debug("Processing egress forwarding objective:{} in dev:{}", fwd, deviceId);
    List<FlowRule> rules = new ArrayList<>();
    // Build selector
    TrafficSelector.Builder sb = DefaultTrafficSelector.builder();
    VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) fwd.selector().getCriterion(Criterion.Type.VLAN_VID);
    if (vlanIdCriterion == null) {
        log.error("Egress forwarding objective:{} must include vlanId", fwd.id());
        fail(fwd, ObjectiveError.BADPARAMS);
        return rules;
    }
    Optional<Instruction> outInstr = fwd.treatment().allInstructions().stream().filter(instruction -> instruction instanceof OutputInstruction).findFirst();
    if (!outInstr.isPresent()) {
        log.error("Egress forwarding objective:{} must include output port", fwd.id());
        fail(fwd, ObjectiveError.BADPARAMS);
        return rules;
    }
    PortNumber portNumber = ((OutputInstruction) outInstr.get()).port();
    sb.matchVlanId(vlanIdCriterion.vlanId());
    OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber);
    sb.extension(actsetOutput, deviceId);
    sb.extension(new OfdpaMatchAllowVlanTranslation(ALLOW_VLAN_TRANSLATION), deviceId);
    // Build a flow rule for Egress VLAN Flow table
    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
    tb.transition(EGRESS_DSCP_PCP_REMARK_FLOW_TABLE);
    if (fwd.treatment() != null) {
        for (Instruction instr : fwd.treatment().allInstructions()) {
            if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2SubType.VLAN_ID) {
                tb.immediate().add(instr);
            }
            if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2SubType.VLAN_PUSH) {
                tb.immediate().pushVlan();
                EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType();
                if (ethType.equals(EtherType.QINQ.ethType())) {
                    // Build a flow rule for Egress TPID Flow table
                    TrafficSelector tpidSelector = DefaultTrafficSelector.builder().extension(actsetOutput, deviceId).matchVlanId(VlanId.ANY).build();
                    TrafficTreatment tpidTreatment = DefaultTrafficTreatment.builder().extension(new Ofdpa3CopyField(COPY_FIELD_NBITS, COPY_FIELD_OFFSET, COPY_FIELD_OFFSET, OXM_ID_VLAN_VID, OXM_ID_PACKET_REG_1), deviceId).popVlan().pushVlan(EtherType.QINQ.ethType()).extension(new Ofdpa3CopyField(COPY_FIELD_NBITS, COPY_FIELD_OFFSET, COPY_FIELD_OFFSET, OXM_ID_PACKET_REG_1, OXM_ID_VLAN_VID), deviceId).build();
                    FlowRule.Builder tpidRuleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(tpidSelector).withTreatment(tpidTreatment).makePermanent().forTable(EGRESS_TPID_FLOW_TABLE);
                    rules.add(tpidRuleBuilder.build());
                }
            }
        }
    }
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sb.build()).withTreatment(tb.build()).makePermanent().forTable(EGRESS_VLAN_FLOW_TABLE);
    rules.add(ruleBuilder.build());
    return rules;
}
Also used : OfdpaPipelineUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) OfdpaMatchActsetOutput(org.onosproject.driver.extensions.OfdpaMatchActsetOutput) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) FlowRuleService(org.onosproject.net.flow.FlowRuleService) Pair(org.apache.commons.lang3.tuple.Pair) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) SELECT(org.onosproject.net.group.GroupDescription.Type.SELECT) MPLS_BOS(org.onosproject.net.flow.criteria.Criterion.Type.MPLS_BOS) Ofdpa3MplsType(org.onosproject.driver.extensions.Ofdpa3MplsType) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) AbstractAccumulator(org.onlab.util.AbstractAccumulator) OfdpaMatchVlanVid(org.onosproject.driver.extensions.OfdpaMatchVlanVid) OfdpaMatchAllowVlanTranslation(org.onosproject.driver.extensions.OfdpaMatchAllowVlanTranslation) DeviceId(org.onosproject.net.DeviceId) L3SubType(org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType) L2SubType(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType) Pipeliner(org.onosproject.net.behaviour.Pipeliner) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) OfdpaSetVlanVid(org.onosproject.driver.extensions.OfdpaSetVlanVid) KryoNamespace(org.onlab.util.KryoNamespace) NextGroup(org.onosproject.net.behaviour.NextGroup) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) Ofdpa3CopyField(org.onosproject.driver.extensions.Ofdpa3CopyField) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) GroupService(org.onosproject.net.group.GroupService) Icmpv6CodeCriterion(org.onosproject.net.flow.criteria.Icmpv6CodeCriterion) OXM_ID_VLAN_VID(org.onosproject.driver.extensions.Ofdpa3CopyField.OXM_ID_VLAN_VID) EtherType(org.onlab.packet.EthType.EtherType) Accumulator(org.onlab.util.Accumulator) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) ArrayDeque(java.util.ArrayDeque) MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) CoreService(org.onosproject.core.CoreService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Timer(java.util.Timer) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) ServiceDirectory(org.onlab.osgi.ServiceDirectory) Ethernet(org.onlab.packet.Ethernet) OXM_ID_PACKET_REG_1(org.onosproject.driver.extensions.Ofdpa3CopyField.OXM_ID_PACKET_REG_1) SPECIFIC(org.onosproject.net.flowobjective.ForwardingObjective.Flag.SPECIFIC) Ofdpa3SetMplsType(org.onosproject.driver.extensions.Ofdpa3SetMplsType) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Collection(java.util.Collection) FlowObjectiveStore(org.onosproject.net.flowobjective.FlowObjectiveStore) Sets(com.google.common.collect.Sets) Icmpv6TypeCriterion(org.onosproject.net.flow.criteria.Icmpv6TypeCriterion) Objects(java.util.Objects) EthType(org.onlab.packet.EthType) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) Optional(java.util.Optional) IpPrefix(org.onlab.packet.IpPrefix) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GroupKey(org.onosproject.net.group.GroupKey) Deque(java.util.Deque) Group(org.onosproject.net.group.Group) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) OfdpaGroupHandlerUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) ModMplsHeaderInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction) TimeUnit(java.util.concurrent.TimeUnit) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Collections(java.util.Collections) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OfdpaMatchActsetOutput(org.onosproject.driver.extensions.OfdpaMatchActsetOutput) ArrayList(java.util.ArrayList) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ModMplsHeaderInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) EthType(org.onlab.packet.EthType) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OfdpaMatchAllowVlanTranslation(org.onosproject.driver.extensions.OfdpaMatchAllowVlanTranslation) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) Ofdpa3CopyField(org.onosproject.driver.extensions.Ofdpa3CopyField)

Aggregations

EthType (org.onlab.packet.EthType)17 VlanId (org.onlab.packet.VlanId)10 IpAddress (org.onlab.packet.IpAddress)7 PortNumber (org.onosproject.net.PortNumber)7 FlowRule (org.onosproject.net.flow.FlowRule)7 Logger (org.slf4j.Logger)7 HashSet (java.util.HashSet)6 List (java.util.List)6 Set (java.util.Set)6 MacAddress (org.onlab.packet.MacAddress)6 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)6 Lists (com.google.common.collect.Lists)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 IpPrefix (org.onlab.packet.IpPrefix)5 DeviceId (org.onosproject.net.DeviceId)5 HostLocation (org.onosproject.net.HostLocation)5 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)5 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)5 TrafficSelector (org.onosproject.net.flow.TrafficSelector)5