Search in sources :

Example 1 with MplsBosCriterion

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

the class PiCriterionTranslatorsTest method testMplsBosCriterion.

@Test
public void testMplsBosCriterion() throws Exception {
    boolean mplsBos = random.nextBoolean();
    int bitWidth = 32;
    int bMplsBos = 0;
    MplsBosCriterion criterion = (MplsBosCriterion) Criteria.matchMplsBos(mplsBos);
    PiExactFieldMatch exactMatch = (PiExactFieldMatch) translateCriterion(criterion, fieldId, EXACT, bitWidth);
    bMplsBos = (criterion.mplsBos()) ? 1 : 0;
    assertThat(exactMatch.value().asReadOnlyBuffer().getInt(), is(bMplsBos));
}
Also used : MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) Test(org.junit.Test)

Example 2 with MplsBosCriterion

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

the class OvsOfdpaPipeline method processEthTypeSpecific.

/*
     * Open vSwitch emulation allows MPLS ECMP.
     *
     * (non-Javadoc)
     * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthTypeSpecific
     */
@Override
protected Collection<FlowRule> processEthTypeSpecific(ForwardingObjective fwd) {
    if (isDoubleTagged(fwd)) {
        return processDoubleTaggedFwd(fwd);
    }
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    if ((ethType == null) || (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST) && (ethType.ethType().toShort() != Ethernet.TYPE_IPV6)) {
        log.warn("processSpecific: Unsupported forwarding objective criteria" + "ethType:{} in dev:{}", ethType, deviceId);
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }
    boolean defaultRule = false;
    int forTableId;
    TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder();
    TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder();
    if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
        IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
        if (ipv4Dst.isMulticast()) {
            if (ipv4Dst.prefixLength() != 32) {
                log.warn("Multicast specific forwarding objective can only be /32");
                fail(fwd, ObjectiveError.BADPARAMS);
                return ImmutableSet.of();
            }
            VlanId assignedVlan = readVlanFromSelector(fwd.meta());
            if (assignedVlan == null) {
                log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort.");
                fail(fwd, ObjectiveError.BADPARAMS);
                return ImmutableSet.of();
            }
            filteredSelector.matchVlanId(assignedVlan);
            filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst);
            forTableId = MULTICAST_ROUTING_TABLE;
            log.debug("processing IPv4 multicast specific forwarding objective {} -> next:{}" + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
        } else {
            if (ipv4Dst.prefixLength() == 0) {
                // The entire IPV4_DST field is wildcarded intentionally
                filteredSelector.matchEthType(Ethernet.TYPE_IPV4);
            } else {
                filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst);
            }
            forTableId = UNICAST_ROUTING_TABLE;
            log.debug("processing IPv4 unicast specific forwarding objective {} -> next:{}" + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
        }
    } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV6) {
        IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip();
        if (ipv6Dst.isMulticast()) {
            if (ipv6Dst.prefixLength() != IpAddress.INET6_BIT_LENGTH) {
                log.debug("Multicast specific IPv6 forwarding objective can only be /128");
                fail(fwd, ObjectiveError.BADPARAMS);
                return ImmutableSet.of();
            }
            VlanId assignedVlan = readVlanFromSelector(fwd.meta());
            if (assignedVlan == null) {
                log.debug("VLAN ID required by multicast specific fwd obj is missing. Abort.");
                fail(fwd, ObjectiveError.BADPARAMS);
                return ImmutableSet.of();
            }
            filteredSelector.matchVlanId(assignedVlan);
            filteredSelector.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Dst(ipv6Dst);
            forTableId = MULTICAST_ROUTING_TABLE;
            log.debug("processing IPv6 multicast specific forwarding objective {} -> next:{}" + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
        } else {
            if (buildIpv6Selector(filteredSelector, fwd) < 0) {
                return Collections.emptyList();
            }
            forTableId = UNICAST_ROUTING_TABLE;
        }
    } else {
        filteredSelector.matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(((MplsCriterion) selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
        MplsBosCriterion bos = (MplsBosCriterion) selector.getCriterion(Criterion.Type.MPLS_BOS);
        if (bos != null) {
            filteredSelector.matchMplsBos(bos.mplsBos());
        }
        forTableId = MPLS_TABLE_1;
        log.debug("processing MPLS specific forwarding objective {} -> next:{}" + " in dev {}", fwd.id(), fwd.nextId(), deviceId);
    }
    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
    if (fwd.treatment() != null) {
        for (Instruction i : fwd.treatment().allInstructions()) {
            if (i instanceof L3ModificationInstruction) {
                L3ModificationInstruction l3instr = (L3ModificationInstruction) i;
                if (l3instr.subtype().equals(L3ModificationInstruction.L3SubType.TTL_IN) || l3instr.subtype().equals(L3ModificationInstruction.L3SubType.TTL_OUT)) {
                    continue;
                }
            }
            /*
                 * NOTE: OF-DPA does not support immediate instruction in
                 * L3 unicast and MPLS table.
                 */
            tb.deferred().add(i);
        }
    }
    if (fwd.nextId() != null) {
        NextGroup next = getGroupForNextObjective(fwd.nextId());
        if (next != null) {
            List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
            // we only need the top level group's key to point the flow to it
            Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
            if (group == null) {
                log.warn("Group with key:{} for next-id:{} not found in dev:{}", gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
                fail(fwd, ObjectiveError.GROUPMISSING);
                return Collections.emptySet();
            }
            tb.deferred().group(group.id());
        }
    }
    tb.transition(ACL_TABLE);
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector.build()).withTreatment(tb.build()).forTable(forTableId);
    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }
    Collection<FlowRule> flowRuleCollection = new ArrayList<>();
    flowRuleCollection.add(ruleBuilder.build());
    if (defaultRule) {
        flowRuleCollection.add(defaultRoute(fwd, complementarySelector, forTableId, tb));
        log.debug("Default rule 0.0.0.0/0 is being installed two rules");
    }
    return flowRuleCollection;
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) ArrayList(java.util.ArrayList) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) Deque(java.util.Deque) ConnectPoint(org.onosproject.net.ConnectPoint) IpPrefix(org.onlab.packet.IpPrefix) MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) VlanId(org.onlab.packet.VlanId)

Example 3 with MplsBosCriterion

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

the class Ofdpa2Pipeline method processEthTypeSpecificInternal.

/**
 * Internal implementation of processEthTypeSpecific.
 * <p>
 * Wildcarded IPv4_DST is not supported in OFDPA i12. Therefore, we break
 * the rule into 0.0.0.0/1 and 128.0.0.0/1.
 * The allowDefaultRoute must be set to false for OFDPA i12.
 * </p>
 *
 * @param fwd the forwarding objective
 * @param allowDefaultRoute allow wildcarded IPv4_DST or not
 * @param mplsNextTable next MPLS table
 * @return A collection of flow rules, or an empty set
 */
protected Collection<FlowRule> processEthTypeSpecificInternal(ForwardingObjective fwd, boolean allowDefaultRoute, int mplsNextTable) {
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    boolean emptyGroup = false;
    int forTableId;
    TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
    TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder();
    if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
        if (buildIpv4Selector(filteredSelector, complementarySelector, fwd, allowDefaultRoute) < 0) {
            return Collections.emptyList();
        }
        // We need to set properly the next table
        IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
        if (ipv4Dst.isMulticast()) {
            forTableId = MULTICAST_ROUTING_TABLE;
        } else {
            forTableId = UNICAST_ROUTING_TABLE;
        }
    // TODO decrementing IP ttl is done automatically for routing, this
    // action is ignored or rejected in ofdpa as it is not fully implemented
    // if (fwd.treatment() != null) {
    // for (Instruction instr : fwd.treatment().allInstructions()) {
    // if (instr instanceof L3ModificationInstruction &&
    // ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) {
    // tb.deferred().add(instr);
    // }
    // }
    // }
    } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV6) {
        if (buildIpv6Selector(filteredSelector, fwd) < 0) {
            return Collections.emptyList();
        }
        // We need to set the proper next table
        IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip();
        if (ipv6Dst.isMulticast()) {
            forTableId = MULTICAST_ROUTING_TABLE;
        } else {
            forTableId = UNICAST_ROUTING_TABLE;
        }
    // TODO decrementing IP ttl is done automatically for routing, this
    // action is ignored or rejected in ofdpa as it is not fully implemented
    // if (fwd.treatment() != null) {
    // for (Instruction instr : fwd.treatment().allInstructions()) {
    // if (instr instanceof L3ModificationInstruction &&
    // ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) {
    // tb.deferred().add(instr);
    // }
    // }
    // }
    } else {
        filteredSelector.matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(((MplsCriterion) selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
        MplsBosCriterion bos = (MplsBosCriterion) selector.getCriterion(MPLS_BOS);
        if (bos != null && requireMplsBosMatch()) {
            filteredSelector.matchMplsBos(bos.mplsBos());
        }
        forTableId = MPLS_TABLE_1;
        log.debug("processing MPLS specific forwarding objective {} -> next:{}" + " in dev {}", fwd.id(), fwd.nextId(), deviceId);
        if (fwd.treatment() != null) {
            for (Instruction instr : fwd.treatment().allInstructions()) {
                if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2SubType.MPLS_POP) {
                    // setting the MPLS_TYPE so pop can happen down the pipeline
                    if (requireMplsPop()) {
                        if (mplsNextTable == MPLS_TYPE_TABLE && isNotMplsBos(selector)) {
                            tb.immediate().popMpls();
                        }
                    } else {
                        // Skip mpls pop action for mpls_unicast label
                        if (instr instanceof ModMplsHeaderInstruction && !((ModMplsHeaderInstruction) instr).ethernetType().equals(EtherType.MPLS_UNICAST.ethType())) {
                            tb.immediate().add(instr);
                        }
                    }
                }
                if (requireMplsTtlModification()) {
                    if (instr instanceof L3ModificationInstruction && ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) {
                        // FIXME Should modify the app to send the correct DEC_MPLS_TTL instruction
                        tb.immediate().decMplsTtl();
                    }
                    if (instr instanceof L3ModificationInstruction && ((L3ModificationInstruction) instr).subtype() == L3SubType.TTL_IN) {
                        tb.immediate().add(instr);
                    }
                }
            }
        }
    }
    if (fwd.nextId() != null) {
        NextGroup next = getGroupForNextObjective(fwd.nextId());
        if (next != null) {
            List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
            // we only need the top level group's key to point the flow to it
            Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
            if (group == null) {
                log.warn("Group with key:{} for next-id:{} not found in dev:{}", gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
                fail(fwd, ObjectiveError.GROUPMISSING);
                return Collections.emptySet();
            }
            if (isNotMplsBos(selector) && group.type().equals(SELECT)) {
                log.warn("SR CONTINUE case cannot be handled as MPLS ECMP " + "is not implemented in OF-DPA yet. Aborting flow {} -> next:{} " + "in this device {}", fwd.id(), fwd.nextId(), deviceId);
                fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
                return Collections.emptySet();
            }
            tb.deferred().group(group.id());
            // retrying flows may be necessary due to bug CORD-554
            if (gkeys.size() == 1 && gkeys.get(0).size() == 1) {
                if (shouldRetry()) {
                    log.warn("Found empty group 0x{} in dev:{} .. will retry fwd:{}", Integer.toHexString(group.id().id()), deviceId, fwd.id());
                    emptyGroup = true;
                }
            }
        } else {
            log.warn("Cannot find group for nextId:{} in dev:{}. Aborting fwd:{}", fwd.nextId(), deviceId, fwd.id());
            fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
            return Collections.emptySet();
        }
    }
    if (forTableId == MPLS_TABLE_1) {
        if (mplsNextTable == MPLS_L3_TYPE_TABLE) {
            Ofdpa3SetMplsType setMplsType = new Ofdpa3SetMplsType(Ofdpa3MplsType.L3_PHP);
            // set mpls type as apply_action
            tb.immediate().extension(setMplsType, deviceId);
        }
        tb.transition(mplsNextTable);
    } else {
        tb.transition(ACL_TABLE);
    }
    if (fwd.treatment() != null && fwd.treatment().clearedDeferred()) {
        if (supportsUnicastBlackHole()) {
            tb.wipeDeferred();
        } else {
            log.warn("Clear Deferred is not supported Unicast Routing Table on device {}", deviceId);
            return Collections.emptySet();
        }
    }
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector.build()).withTreatment(tb.build()).forTable(forTableId);
    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }
    Collection<FlowRule> flowRuleCollection = new ArrayList<>();
    flowRuleCollection.add(ruleBuilder.build());
    if (!allowDefaultRoute) {
        flowRuleCollection.add(defaultRoute(fwd, complementarySelector, forTableId, tb));
        log.debug("Default rule 0.0.0.0/0 is being installed two rules");
    }
    if (emptyGroup) {
        retryExecutorService.schedule(new RetryFlows(fwd, flowRuleCollection), RETRY_MS, TimeUnit.MILLISECONDS);
    }
    return flowRuleCollection;
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) 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) ModMplsHeaderInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction) IpPrefix(org.onlab.packet.IpPrefix) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ArrayDeque(java.util.ArrayDeque) Deque(java.util.Deque) MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Ofdpa3SetMplsType(org.onosproject.driver.extensions.Ofdpa3SetMplsType)

Example 4 with MplsBosCriterion

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

MplsBosCriterion (org.onosproject.net.flow.criteria.MplsBosCriterion)4 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)3 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)3 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)3 ArrayList (java.util.ArrayList)2 Deque (java.util.Deque)2 IpPrefix (org.onlab.packet.IpPrefix)2 NextGroup (org.onosproject.net.behaviour.NextGroup)2 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)2 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)2 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)2 FlowRule (org.onosproject.net.flow.FlowRule)2 TrafficSelector (org.onosproject.net.flow.TrafficSelector)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2 Instruction (org.onosproject.net.flow.instructions.Instruction)2 NoActionInstruction (org.onosproject.net.flow.instructions.Instructions.NoActionInstruction)2 OutputInstruction (org.onosproject.net.flow.instructions.Instructions.OutputInstruction)2 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)2 L3ModificationInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction)2 Group (org.onosproject.net.group.Group)2