Search in sources :

Example 1 with MetadataCriterion

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

the class FlowModBuilder method buildMatch.

/**
 * Builds the match for the flow mod.
 *
 * @return the match
 */
// CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES
protected Match buildMatch() {
    Match.Builder mBuilder = factory.buildMatch();
    Ip6Address ip6Address;
    Ip4Prefix ip4Prefix;
    Ip6Prefix ip6Prefix;
    EthCriterion ethCriterion;
    IPCriterion ipCriterion;
    TcpPortCriterion tcpPortCriterion;
    UdpPortCriterion udpPortCriterion;
    SctpPortCriterion sctpPortCriterion;
    IPv6NDLinkLayerAddressCriterion llAddressCriterion;
    ArpHaCriterion arpHaCriterion;
    ArpPaCriterion arpPaCriterion;
    for (Criterion c : selector.criteria()) {
        switch(c.type()) {
            case IN_PORT:
                PortCriterion inPort = (PortCriterion) c;
                mBuilder.setExact(MatchField.IN_PORT, OFPort.of((int) inPort.port().toLong()));
                break;
            case IN_PHY_PORT:
                PortCriterion inPhyPort = (PortCriterion) c;
                mBuilder.setExact(MatchField.IN_PORT, OFPort.of((int) inPhyPort.port().toLong()));
                break;
            case METADATA:
                MetadataCriterion metadata = (MetadataCriterion) c;
                mBuilder.setExact(MatchField.METADATA, OFMetadata.ofRaw(metadata.metadata()));
                break;
            case ETH_DST:
                ethCriterion = (EthCriterion) c;
                mBuilder.setExact(MatchField.ETH_DST, MacAddress.of(ethCriterion.mac().toLong()));
                break;
            case ETH_DST_MASKED:
                ethCriterion = (EthCriterion) c;
                mBuilder.setMasked(MatchField.ETH_DST, MacAddress.of(ethCriterion.mac().toLong()), MacAddress.of(ethCriterion.mask().toLong()));
                break;
            case ETH_SRC:
                ethCriterion = (EthCriterion) c;
                mBuilder.setExact(MatchField.ETH_SRC, MacAddress.of(ethCriterion.mac().toLong()));
                break;
            case ETH_SRC_MASKED:
                ethCriterion = (EthCriterion) c;
                mBuilder.setMasked(MatchField.ETH_SRC, MacAddress.of(ethCriterion.mac().toLong()), MacAddress.of(ethCriterion.mask().toLong()));
                break;
            case ETH_TYPE:
                EthTypeCriterion ethType = (EthTypeCriterion) c;
                mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType().toShort()));
                break;
            case VLAN_VID:
                VlanIdCriterion vid = (VlanIdCriterion) c;
                if (vid.vlanId().equals(VlanId.ANY)) {
                    mBuilder.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.PRESENT, OFVlanVidMatch.PRESENT);
                } else if (vid.vlanId().equals(VlanId.NONE)) {
                    mBuilder.setExact(MatchField.VLAN_VID, OFVlanVidMatch.NONE);
                } else {
                    mBuilder.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort())));
                }
                break;
            case VLAN_PCP:
                VlanPcpCriterion vpcp = (VlanPcpCriterion) c;
                mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority()));
                break;
            case IP_DSCP:
                IPDscpCriterion ipDscpCriterion = (IPDscpCriterion) c;
                mBuilder.setExact(MatchField.IP_DSCP, IpDscp.of(ipDscpCriterion.ipDscp()));
                break;
            case IP_ECN:
                IPEcnCriterion ipEcnCriterion = (IPEcnCriterion) c;
                mBuilder.setExact(MatchField.IP_ECN, IpEcn.of(ipEcnCriterion.ipEcn()));
                break;
            case IP_PROTO:
                IPProtocolCriterion p = (IPProtocolCriterion) c;
                mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol()));
                break;
            case IPV4_SRC:
                ipCriterion = (IPCriterion) c;
                ip4Prefix = ipCriterion.ip().getIp4Prefix();
                if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
                    Ip4Address maskAddr = Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
                    Masked<IPv4Address> maskedIp = Masked.of(IPv4Address.of(ip4Prefix.address().toInt()), IPv4Address.of(maskAddr.toInt()));
                    mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp);
                } else {
                    mBuilder.setExact(MatchField.IPV4_SRC, IPv4Address.of(ip4Prefix.address().toInt()));
                }
                break;
            case IPV4_DST:
                ipCriterion = (IPCriterion) c;
                ip4Prefix = ipCriterion.ip().getIp4Prefix();
                if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
                    Ip4Address maskAddr = Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
                    Masked<IPv4Address> maskedIp = Masked.of(IPv4Address.of(ip4Prefix.address().toInt()), IPv4Address.of(maskAddr.toInt()));
                    mBuilder.setMasked(MatchField.IPV4_DST, maskedIp);
                } else {
                    mBuilder.setExact(MatchField.IPV4_DST, IPv4Address.of(ip4Prefix.address().toInt()));
                }
                break;
            case TCP_SRC:
                tcpPortCriterion = (TcpPortCriterion) c;
                mBuilder.setExact(MatchField.TCP_SRC, TransportPort.of(tcpPortCriterion.tcpPort().toInt()));
                break;
            case TCP_SRC_MASKED:
                tcpPortCriterion = (TcpPortCriterion) c;
                mBuilder.setMasked(MatchField.TCP_SRC, TransportPort.of(tcpPortCriterion.tcpPort().toInt()), TransportPort.of(tcpPortCriterion.mask().toInt()));
                break;
            case TCP_DST:
                tcpPortCriterion = (TcpPortCriterion) c;
                mBuilder.setExact(MatchField.TCP_DST, TransportPort.of(tcpPortCriterion.tcpPort().toInt()));
                break;
            case TCP_DST_MASKED:
                tcpPortCriterion = (TcpPortCriterion) c;
                mBuilder.setMasked(MatchField.TCP_DST, TransportPort.of(tcpPortCriterion.tcpPort().toInt()), TransportPort.of(tcpPortCriterion.mask().toInt()));
                break;
            case UDP_SRC:
                udpPortCriterion = (UdpPortCriterion) c;
                mBuilder.setExact(MatchField.UDP_SRC, TransportPort.of(udpPortCriterion.udpPort().toInt()));
                break;
            case UDP_SRC_MASKED:
                udpPortCriterion = (UdpPortCriterion) c;
                mBuilder.setMasked(MatchField.UDP_SRC, TransportPort.of(udpPortCriterion.udpPort().toInt()), TransportPort.of(udpPortCriterion.mask().toInt()));
                break;
            case UDP_DST:
                udpPortCriterion = (UdpPortCriterion) c;
                mBuilder.setExact(MatchField.UDP_DST, TransportPort.of(udpPortCriterion.udpPort().toInt()));
                break;
            case UDP_DST_MASKED:
                udpPortCriterion = (UdpPortCriterion) c;
                mBuilder.setMasked(MatchField.UDP_DST, TransportPort.of(udpPortCriterion.udpPort().toInt()), TransportPort.of(udpPortCriterion.mask().toInt()));
                break;
            case SCTP_SRC:
                sctpPortCriterion = (SctpPortCriterion) c;
                mBuilder.setExact(MatchField.SCTP_SRC, TransportPort.of(sctpPortCriterion.sctpPort().toInt()));
                break;
            case SCTP_SRC_MASKED:
                sctpPortCriterion = (SctpPortCriterion) c;
                mBuilder.setMasked(MatchField.SCTP_SRC, TransportPort.of(sctpPortCriterion.sctpPort().toInt()), TransportPort.of(sctpPortCriterion.mask().toInt()));
                break;
            case SCTP_DST:
                sctpPortCriterion = (SctpPortCriterion) c;
                mBuilder.setExact(MatchField.SCTP_DST, TransportPort.of(sctpPortCriterion.sctpPort().toInt()));
                break;
            case SCTP_DST_MASKED:
                sctpPortCriterion = (SctpPortCriterion) c;
                mBuilder.setMasked(MatchField.SCTP_DST, TransportPort.of(sctpPortCriterion.sctpPort().toInt()), TransportPort.of(sctpPortCriterion.mask().toInt()));
                break;
            case ICMPV4_TYPE:
                IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c;
                mBuilder.setExact(MatchField.ICMPV4_TYPE, ICMPv4Type.of(icmpType.icmpType()));
                break;
            case ICMPV4_CODE:
                IcmpCodeCriterion icmpCode = (IcmpCodeCriterion) c;
                mBuilder.setExact(MatchField.ICMPV4_CODE, ICMPv4Code.of(icmpCode.icmpCode()));
                break;
            case IPV6_SRC:
                ipCriterion = (IPCriterion) c;
                ip6Prefix = ipCriterion.ip().getIp6Prefix();
                if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
                    Ip6Address maskAddr = Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
                    Masked<IPv6Address> maskedIp = Masked.of(IPv6Address.of(ip6Prefix.address().toString()), IPv6Address.of(maskAddr.toString()));
                    mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp);
                } else {
                    mBuilder.setExact(MatchField.IPV6_SRC, IPv6Address.of(ip6Prefix.address().toString()));
                }
                break;
            case IPV6_DST:
                ipCriterion = (IPCriterion) c;
                ip6Prefix = ipCriterion.ip().getIp6Prefix();
                if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
                    Ip6Address maskAddr = Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
                    Masked<IPv6Address> maskedIp = Masked.of(IPv6Address.of(ip6Prefix.address().toString()), IPv6Address.of(maskAddr.toString()));
                    mBuilder.setMasked(MatchField.IPV6_DST, maskedIp);
                } else {
                    mBuilder.setExact(MatchField.IPV6_DST, IPv6Address.of(ip6Prefix.address().toString()));
                }
                break;
            case IPV6_FLABEL:
                IPv6FlowLabelCriterion flowLabelCriterion = (IPv6FlowLabelCriterion) c;
                mBuilder.setExact(MatchField.IPV6_FLABEL, IPv6FlowLabel.of(flowLabelCriterion.flowLabel()));
                break;
            case ICMPV6_TYPE:
                Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c;
                mBuilder.setExact(MatchField.ICMPV6_TYPE, U8.of(icmpv6Type.icmpv6Type()));
                break;
            case ICMPV6_CODE:
                Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c;
                mBuilder.setExact(MatchField.ICMPV6_CODE, U8.of(icmpv6Code.icmpv6Code()));
                break;
            case IPV6_ND_TARGET:
                IPv6NDTargetAddressCriterion targetAddressCriterion = (IPv6NDTargetAddressCriterion) c;
                ip6Address = targetAddressCriterion.targetAddress();
                mBuilder.setExact(MatchField.IPV6_ND_TARGET, IPv6Address.of(ip6Address.toOctets()));
                break;
            case IPV6_ND_SLL:
                llAddressCriterion = (IPv6NDLinkLayerAddressCriterion) c;
                mBuilder.setExact(MatchField.IPV6_ND_SLL, MacAddress.of(llAddressCriterion.mac().toLong()));
                break;
            case IPV6_ND_TLL:
                llAddressCriterion = (IPv6NDLinkLayerAddressCriterion) c;
                mBuilder.setExact(MatchField.IPV6_ND_TLL, MacAddress.of(llAddressCriterion.mac().toLong()));
                break;
            case MPLS_LABEL:
                MplsCriterion mp = (MplsCriterion) c;
                mBuilder.setExact(MatchField.MPLS_LABEL, U32.of(mp.label().toInt()));
                break;
            case IPV6_EXTHDR:
                IPv6ExthdrFlagsCriterion exthdrFlagsCriterion = (IPv6ExthdrFlagsCriterion) c;
                mBuilder.setExact(MatchField.IPV6_EXTHDR, U16.of(exthdrFlagsCriterion.exthdrFlags()));
                break;
            case OCH_SIGID:
                try {
                    OchSignalCriterion ochSignalCriterion = (OchSignalCriterion) c;
                    OchSignal signal = ochSignalCriterion.lambda();
                    byte gridType = OpenFlowValueMapper.lookupGridType(signal.gridType());
                    byte channelSpacing = OpenFlowValueMapper.lookupChannelSpacing(signal.channelSpacing());
                    mBuilder.setExact(MatchField.EXP_OCH_SIG_ID, new CircuitSignalID(gridType, channelSpacing, (short) signal.spacingMultiplier(), (short) signal.slotGranularity()));
                } catch (NoMappingFoundException e) {
                    log.warn(e.getMessage());
                }
                break;
            case OCH_SIGTYPE:
                try {
                    OchSignalTypeCriterion sc = (OchSignalTypeCriterion) c;
                    byte signalType = OpenFlowValueMapper.lookupOchSignalType(sc.signalType());
                    mBuilder.setExact(MatchField.EXP_OCH_SIGTYPE, U8.of(signalType));
                } catch (NoMappingFoundException e) {
                    log.warn(e.getMessage());
                }
                break;
            case ODU_SIGID:
                OduSignalIdCriterion oduSignalIdCriterion = (OduSignalIdCriterion) c;
                OduSignalId oduSignalId = oduSignalIdCriterion.oduSignalId();
                mBuilder.setExact(MatchField.EXP_ODU_SIG_ID, new OduSignalID((short) oduSignalId.tributaryPortNumber(), (short) oduSignalId.tributarySlotLength(), oduSignalId.tributarySlotBitmap()));
                break;
            case ODU_SIGTYPE:
                try {
                    OduSignalTypeCriterion oduSignalTypeCriterion = (OduSignalTypeCriterion) c;
                    byte oduSigType = OpenFlowValueMapper.lookupOduSignalType(oduSignalTypeCriterion.signalType());
                    mBuilder.setExact(MatchField.EXP_ODU_SIGTYPE, U8.of(oduSigType));
                } catch (NoMappingFoundException e) {
                    log.warn(e.getMessage());
                }
                break;
            case TUNNEL_ID:
                TunnelIdCriterion tunnelId = (TunnelIdCriterion) c;
                mBuilder.setExact(MatchField.TUNNEL_ID, U64.of(tunnelId.tunnelId()));
                break;
            case MPLS_BOS:
                MplsBosCriterion mplsBos = (MplsBosCriterion) c;
                mBuilder.setExact(MatchField.MPLS_BOS, mplsBos.mplsBos() ? OFBooleanValue.TRUE : OFBooleanValue.FALSE);
                break;
            case ARP_OP:
                ArpOpCriterion arpOp = (ArpOpCriterion) c;
                mBuilder.setExact(MatchField.ARP_OP, ArpOpcode.of(arpOp.arpOp()));
                break;
            case ARP_SHA:
                arpHaCriterion = (ArpHaCriterion) c;
                mBuilder.setExact(MatchField.ARP_SHA, MacAddress.of(arpHaCriterion.mac().toLong()));
                break;
            case ARP_SPA:
                arpPaCriterion = (ArpPaCriterion) c;
                mBuilder.setExact(MatchField.ARP_SPA, IPv4Address.of(arpPaCriterion.ip().toInt()));
                break;
            case ARP_THA:
                arpHaCriterion = (ArpHaCriterion) c;
                mBuilder.setExact(MatchField.ARP_THA, MacAddress.of(arpHaCriterion.mac().toLong()));
                break;
            case ARP_TPA:
                arpPaCriterion = (ArpPaCriterion) c;
                mBuilder.setExact(MatchField.ARP_TPA, IPv4Address.of(arpPaCriterion.ip().toInt()));
                break;
            case EXTENSION:
                ExtensionCriterion extensionCriterion = (ExtensionCriterion) c;
                OFOxm oxm = buildExtensionOxm(extensionCriterion.extensionSelector());
                if (oxm == null) {
                    log.warn("Unable to build extension selector");
                    break;
                }
                if (oxm.isMasked()) {
                    mBuilder.setMasked(oxm.getMatchField(), oxm.getValue(), oxm.getMask());
                } else {
                    mBuilder.setExact(oxm.getMatchField(), oxm.getValue());
                }
                break;
            case MPLS_TC:
            case PBB_ISID:
            // TODO: need to implement PBB-ISID case when OpenFlowJ is ready
            default:
                log.warn("Match type {} not yet implemented.", c.type());
        }
    }
    return mBuilder.build();
}
Also used : EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Ip4Address(org.onlab.packet.Ip4Address) IPv6Address(org.projectfloodlight.openflow.types.IPv6Address) Icmpv6TypeCriterion(org.onosproject.net.flow.criteria.Icmpv6TypeCriterion) IPv4Address(org.projectfloodlight.openflow.types.IPv4Address) Icmpv6CodeCriterion(org.onosproject.net.flow.criteria.Icmpv6CodeCriterion) Ip6Address(org.onlab.packet.Ip6Address) IcmpCodeCriterion(org.onosproject.net.flow.criteria.IcmpCodeCriterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) CircuitSignalID(org.projectfloodlight.openflow.types.CircuitSignalID) ArpHaCriterion(org.onosproject.net.flow.criteria.ArpHaCriterion) IcmpTypeCriterion(org.onosproject.net.flow.criteria.IcmpTypeCriterion) VlanPcpCriterion(org.onosproject.net.flow.criteria.VlanPcpCriterion) IPv6NDTargetAddressCriterion(org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion) MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) OFOxm(org.projectfloodlight.openflow.protocol.oxm.OFOxm) IPDscpCriterion(org.onosproject.net.flow.criteria.IPDscpCriterion) NoMappingFoundException(org.onosproject.provider.of.flow.util.NoMappingFoundException) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) IPv6ExthdrFlagsCriterion(org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) OduSignalIdCriterion(org.onosproject.net.flow.criteria.OduSignalIdCriterion) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch) SctpPortCriterion(org.onosproject.net.flow.criteria.SctpPortCriterion) Ip6Prefix(org.onlab.packet.Ip6Prefix) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) IPDscpCriterion(org.onosproject.net.flow.criteria.IPDscpCriterion) ArpHaCriterion(org.onosproject.net.flow.criteria.ArpHaCriterion) MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) 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) ExtensionCriterion(org.onosproject.net.flow.criteria.ExtensionCriterion) 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) MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) ArpOpCriterion(org.onosproject.net.flow.criteria.ArpOpCriterion) ArpPaCriterion(org.onosproject.net.flow.criteria.ArpPaCriterion) 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) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) OduSignalId(org.onosproject.net.OduSignalId) IPEcnCriterion(org.onosproject.net.flow.criteria.IPEcnCriterion) OchSignalTypeCriterion(org.onosproject.net.flow.criteria.OchSignalTypeCriterion) OduSignalTypeCriterion(org.onosproject.net.flow.criteria.OduSignalTypeCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) OchSignal(org.onosproject.net.OchSignal) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) SctpPortCriterion(org.onosproject.net.flow.criteria.SctpPortCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) ArpOpCriterion(org.onosproject.net.flow.criteria.ArpOpCriterion) IPv6FlowLabelCriterion(org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion) ExtensionCriterion(org.onosproject.net.flow.criteria.ExtensionCriterion) ArpPaCriterion(org.onosproject.net.flow.criteria.ArpPaCriterion) MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) IPv6NDLinkLayerAddressCriterion(org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) Ip4Prefix(org.onlab.packet.Ip4Prefix) OduSignalID(org.projectfloodlight.openflow.types.OduSignalID)

Example 2 with MetadataCriterion

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

the class PiCriterionTranslatorsTest method testMetadataCriterion.

@Test
public void testMetadataCriterion() throws Exception {
    long metadata = random.nextLong();
    int bitWidth = 64;
    MetadataCriterion criterion = (MetadataCriterion) Criteria.matchMetadata(metadata);
    PiExactFieldMatch exactMatch = (PiExactFieldMatch) translateCriterion(criterion, fieldId, EXACT, bitWidth);
    assertThat(exactMatch.value().asReadOnlyBuffer().getLong(), is(criterion.metadata()));
}
Also used : MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) Test(org.junit.Test)

Example 3 with MetadataCriterion

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

the class FabricUtils method isSrMetadataSet.

/**
 * Verify if a given flag has been set into the metadata.
 *
 * @param obj the objective containing the metadata
 * @param flag the flag to verify
 * @return true if the flag is set, false otherwise
 */
public static boolean isSrMetadataSet(Objective obj, long flag) {
    long meta = 0;
    if (obj instanceof FilteringObjective) {
        FilteringObjective filtObj = (FilteringObjective) obj;
        if (filtObj.meta() == null) {
            return false;
        }
        Instructions.MetadataInstruction metaIns = filtObj.meta().writeMetadata();
        if (metaIns == null) {
            return false;
        }
        meta = metaIns.metadata() & metaIns.metadataMask();
    } else if (obj instanceof ForwardingObjective) {
        ForwardingObjective fwdObj = (ForwardingObjective) obj;
        if (fwdObj.meta() == null) {
            return false;
        }
        MetadataCriterion metaCrit = (MetadataCriterion) fwdObj.meta().getCriterion(Criterion.Type.METADATA);
        if (metaCrit == null) {
            return false;
        }
        meta = metaCrit.metadata();
    }
    return (meta & flag) == flag;
}
Also used : MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Instructions(org.onosproject.net.flow.instructions.Instructions) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective)

Example 4 with MetadataCriterion

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

the class FabricUtils method isValidSrMetadata.

/**
 * Check metadata passed from SegmentRouting app.
 *
 * @param obj the objective containing the metadata
 * @return true if the objective contains valid metadata, false otherwise
 */
public static boolean isValidSrMetadata(Objective obj) {
    long meta = 0;
    if (obj instanceof FilteringObjective) {
        FilteringObjective filtObj = (FilteringObjective) obj;
        if (filtObj.meta() == null) {
            return true;
        }
        Instructions.MetadataInstruction metaIns = filtObj.meta().writeMetadata();
        if (metaIns == null) {
            return true;
        }
        meta = metaIns.metadata() & metaIns.metadataMask();
    } else if (obj instanceof ForwardingObjective) {
        ForwardingObjective fwdObj = (ForwardingObjective) obj;
        if (fwdObj.meta() == null) {
            return true;
        }
        MetadataCriterion metaCrit = (MetadataCriterion) fwdObj.meta().getCriterion(Criterion.Type.METADATA);
        if (metaCrit == null) {
            return true;
        }
        meta = metaCrit.metadata();
    }
    return meta != 0 && ((meta ^ METADATA_MASK) <= METADATA_MASK);
}
Also used : MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Instructions(org.onosproject.net.flow.instructions.Instructions) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective)

Example 5 with MetadataCriterion

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

Aggregations

MetadataCriterion (org.onosproject.net.flow.criteria.MetadataCriterion)5 Instructions (org.onosproject.net.flow.instructions.Instructions)3 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)2 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)2 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.Test)1 EthType (org.onlab.packet.EthType)1 Ip4Address (org.onlab.packet.Ip4Address)1 Ip4Prefix (org.onlab.packet.Ip4Prefix)1 Ip6Address (org.onlab.packet.Ip6Address)1 Ip6Prefix (org.onlab.packet.Ip6Prefix)1 IpPrefix (org.onlab.packet.IpPrefix)1