Search in sources :

Example 1 with UdpPortCriterion

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

the class TsLoopPacket method copyPacketMatch.

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

Example 2 with UdpPortCriterion

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

the class TelemetryVflowListCommand method doExecute.

@Override
protected void doExecute() {
    CoreService coreService = get(CoreService.class);
    FlowRuleService flowService = get(FlowRuleService.class);
    ApplicationId appId = coreService.getAppId(OPENSTACK_TELEMETRY_APP_ID);
    List<FlowEntry> flows = Lists.newArrayList(flowService.getFlowEntriesById(appId));
    print(FORMAT, "SrcIp", "SrcPort", "DstIp", "DstPort", "Protocol");
    for (FlowEntry entry : flows) {
        TrafficSelector selector = entry.selector();
        IpPrefix srcIp = ((IPCriterion) selector.getCriterion(IPV4_SRC)).ip();
        IpPrefix dstIp = ((IPCriterion) selector.getCriterion(IPV4_DST)).ip();
        TpPort srcPort = TpPort.tpPort(0);
        TpPort dstPort = TpPort.tpPort(0);
        String protocolStr = "ANY";
        Criterion ipProtocolCriterion = selector.getCriterion(IP_PROTO);
        if (ipProtocolCriterion != null) {
            short protocol = ((IPProtocolCriterion) selector.getCriterion(IP_PROTO)).protocol();
            if (protocol == PROTOCOL_TCP) {
                srcPort = ((TcpPortCriterion) selector.getCriterion(TCP_SRC)).tcpPort();
                dstPort = ((TcpPortCriterion) selector.getCriterion(TCP_DST)).tcpPort();
                protocolStr = TCP;
            }
            if (protocol == PROTOCOL_UDP) {
                srcPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
                dstPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
                protocolStr = UDP;
            }
        }
        print(FORMAT, srcIp.toString(), srcPort.toString(), dstIp.toString(), dstPort.toString(), protocolStr);
    }
}
Also used : IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) CoreService(org.onosproject.core.CoreService) IpPrefix(org.onlab.packet.IpPrefix) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) TpPort(org.onlab.packet.TpPort) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 3 with UdpPortCriterion

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

the class Ofdpa2Pipeline method processVersatile.

/**
 * In the OF-DPA 2.0 pipeline, versatile forwarding objectives go to the
 * ACL table.
 * @param fwd  the forwarding objective of type 'versatile'
 * @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> processVersatile(ForwardingObjective fwd) {
    log.debug("Processing versatile forwarding objective:{} in dev:{}", fwd.id(), deviceId);
    List<FlowRule> flowRules = new ArrayList<>();
    final AtomicBoolean ethTypeUsed = new AtomicBoolean(false);
    if (fwd.nextId() == null && fwd.treatment() == null) {
        log.error("Forwarding objective {} from {} must contain " + "nextId or Treatment", fwd.selector(), fwd.appId());
        fail(fwd, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
    fwd.selector().criteria().forEach(criterion -> {
        if (criterion instanceof VlanIdCriterion) {
            VlanId vlanId = ((VlanIdCriterion) criterion).vlanId();
            // match untagged packets this way in the ACL table.
            if (vlanId.equals(VlanId.NONE)) {
                return;
            }
            if (requireVlanExtensions()) {
                OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanId);
                sbuilder.extension(ofdpaMatchVlanVid, deviceId);
            } else {
                sbuilder.matchVlanId(vlanId);
            }
        } else if (criterion instanceof Icmpv6TypeCriterion) {
            byte icmpv6Type = (byte) ((Icmpv6TypeCriterion) criterion).icmpv6Type();
            sbuilder.matchIcmpv6Type(icmpv6Type);
        } else if (criterion instanceof Icmpv6CodeCriterion) {
            byte icmpv6Code = (byte) ((Icmpv6CodeCriterion) criterion).icmpv6Code();
            sbuilder.matchIcmpv6Type(icmpv6Code);
        } else if (criterion instanceof TcpPortCriterion || criterion instanceof UdpPortCriterion) {
            // We need to revisit this if L4 dst port is used for other purpose in the future.
            if (!supportIpv6L4Dst() && isIpv6(fwd.selector())) {
                switch(criterion.type()) {
                    case UDP_DST:
                    case UDP_DST_MASKED:
                    case TCP_DST:
                    case TCP_DST_MASKED:
                        break;
                    default:
                        sbuilder.add(criterion);
                }
            } else {
                sbuilder.add(criterion);
            }
        } else if (criterion instanceof EthTypeCriterion) {
            sbuilder.add(criterion);
            ethTypeUsed.set(true);
        } else {
            sbuilder.add(criterion);
        }
    });
    TrafficTreatment.Builder ttBuilder = versatileTreatmentBuilder(fwd);
    if (ttBuilder == null) {
        return Collections.emptySet();
    }
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sbuilder.build()).withTreatment(ttBuilder.build()).makePermanent().forTable(ACL_TABLE);
    flowRules.add(ruleBuilder.build());
    if (!ethTypeUsed.get() && requireEthType()) {
        log.debug("{} doesn't match on ethType but requireEthType is true, adding complementary ACL flow.", sbuilder.toString());
        sbuilder.matchEthType(Ethernet.TYPE_IPV6);
        FlowRule.Builder ethTypeRuleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sbuilder.build()).withTreatment(ttBuilder.build()).makePermanent().forTable(ACL_TABLE);
        flowRules.add(ethTypeRuleBuilder.build());
    }
    return flowRules;
}
Also used : EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) ArrayList(java.util.ArrayList) Icmpv6TypeCriterion(org.onosproject.net.flow.criteria.Icmpv6TypeCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OfdpaMatchVlanVid(org.onosproject.driver.extensions.OfdpaMatchVlanVid) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Icmpv6CodeCriterion(org.onosproject.net.flow.criteria.Icmpv6CodeCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) VlanId(org.onlab.packet.VlanId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 4 with UdpPortCriterion

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

the class IntProgrammableImpl method buildWatchlistEntry.

private FlowRule buildWatchlistEntry(IntObjective obj) {
    int instructionBitmap = buildInstructionBitmap(obj.metadataTypes());
    PiActionParam hopMetaLenParam = new PiActionParam(IntConstants.HOP_METADATA_LEN, ImmutableByteSequence.copyFrom(Integer.bitCount(instructionBitmap)));
    PiActionParam hopCntParam = new PiActionParam(IntConstants.REMAINING_HOP_CNT, ImmutableByteSequence.copyFrom(MAXHOP));
    PiActionParam inst0003Param = new PiActionParam(IntConstants.INS_MASK0003, ImmutableByteSequence.copyFrom((instructionBitmap >> 12) & 0xF));
    PiActionParam inst0407Param = new PiActionParam(IntConstants.INS_MASK0407, ImmutableByteSequence.copyFrom((instructionBitmap >> 8) & 0xF));
    PiAction intSourceAction = PiAction.builder().withId(IntConstants.INGRESS_PROCESS_INT_SOURCE_INT_SOURCE_DSCP).withParameter(hopMetaLenParam).withParameter(hopCntParam).withParameter(inst0003Param).withParameter(inst0407Param).build();
    TrafficTreatment instTreatment = DefaultTrafficTreatment.builder().piTableAction(intSourceAction).build();
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
    for (Criterion criterion : obj.selector().criteria()) {
        switch(criterion.type()) {
            case IPV4_SRC:
                sBuilder.matchIPSrc(((IPCriterion) criterion).ip());
                break;
            case IPV4_DST:
                sBuilder.matchIPDst(((IPCriterion) criterion).ip());
                break;
            case TCP_SRC:
                sBuilder.matchPi(PiCriterion.builder().matchTernary(IntConstants.HDR_LOCAL_METADATA_L4_SRC_PORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK).build());
                break;
            case UDP_SRC:
                sBuilder.matchPi(PiCriterion.builder().matchTernary(IntConstants.HDR_LOCAL_METADATA_L4_SRC_PORT, ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK).build());
                break;
            case TCP_DST:
                sBuilder.matchPi(PiCriterion.builder().matchTernary(IntConstants.HDR_LOCAL_METADATA_L4_DST_PORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK).build());
                break;
            case UDP_DST:
                sBuilder.matchPi(PiCriterion.builder().matchTernary(IntConstants.HDR_LOCAL_METADATA_L4_DST_PORT, ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK).build());
                break;
            default:
                log.warn("Unsupported criterion type: {}", criterion.type());
        }
    }
    return DefaultFlowRule.builder().forDevice(this.data().deviceId()).withSelector(sBuilder.build()).withTreatment(instTreatment).withPriority(DEFAULT_PRIORITY).forTable(IntConstants.INGRESS_PROCESS_INT_SOURCE_TB_INT_SOURCE).fromApp(appId).withIdleTimeout(IDLE_TIMEOUT).build();
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 5 with UdpPortCriterion

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

Aggregations

UdpPortCriterion (org.onosproject.net.flow.criteria.UdpPortCriterion)9 TcpPortCriterion (org.onosproject.net.flow.criteria.TcpPortCriterion)8 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)7 Criterion (org.onosproject.net.flow.criteria.Criterion)6 TrafficSelector (org.onosproject.net.flow.TrafficSelector)5 IPProtocolCriterion (org.onosproject.net.flow.criteria.IPProtocolCriterion)5 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)4 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)4 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)4 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)3 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)3 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)3 IPDscpCriterion (org.onosproject.net.flow.criteria.IPDscpCriterion)3 IPEcnCriterion (org.onosproject.net.flow.criteria.IPEcnCriterion)3 Icmpv6CodeCriterion (org.onosproject.net.flow.criteria.Icmpv6CodeCriterion)3 Icmpv6TypeCriterion (org.onosproject.net.flow.criteria.Icmpv6TypeCriterion)3 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)3 VlanPcpCriterion (org.onosproject.net.flow.criteria.VlanPcpCriterion)3 Test (org.junit.Test)2 TpPort (org.onlab.packet.TpPort)2