Search in sources :

Example 1 with Criterion

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

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

the class DefaultCheckLoop method matchAndAddFlowEntry.

private boolean matchAndAddFlowEntry(FlowEntry flowEntry, TsLoopPacket pkt, TsReturn<Boolean> isBigger) {
    isBigger.setValue(false);
    List<Criterion> criterionArray = sortCriteria(flowEntry.selector().criteria());
    for (Criterion criterion : criterionArray) {
        // TODO - advance
        switch(criterion.type()) {
            case IN_PORT:
            case ETH_SRC:
            // At present, not support Ethernet mask (ONOS?)
            case ETH_DST:
            // At present, not support Ethernet mask (ONOS?)
            case ETH_TYPE:
                if (!matchAddExactly(pkt, criterion, isBigger)) {
                    return false;
                }
                break;
            case VLAN_VID:
            // At present, not support VLAN mask (ONOS?)
            case VLAN_PCP:
                if (!pkt.headerExists(ETH_TYPE) || !((EthTypeCriterion) pkt.getHeader(ETH_TYPE)).ethType().equals(VLAN.ethType())) {
                    return false;
                }
                if (!matchAddExactly(pkt, criterion, isBigger)) {
                    return false;
                }
                break;
            case IPV4_SRC:
            case IPV4_DST:
                if (!pkt.headerExists(ETH_TYPE) || !((EthTypeCriterion) pkt.getHeader(ETH_TYPE)).ethType().equals(IPV4.ethType())) {
                    return false;
                }
                if (!matchAddIPV4(pkt, criterion, isBigger)) {
                    return false;
                }
                break;
            case IP_PROTO:
                if (!pkt.headerExists(ETH_TYPE) || !((EthTypeCriterion) pkt.getHeader(ETH_TYPE)).ethType().equals(IPV4.ethType())) {
                    return false;
                }
                if (!matchAddExactly(pkt, criterion, isBigger)) {
                    return false;
                }
                break;
            case IP_DSCP:
                // TODO: 10/28/16 support IP_DSCP match field
                break;
            case IP_ECN:
                // TODO: 10/28/16 support IP_DSCP match field
                break;
            case TCP_SRC:
            case TCP_DST:
                if (!pkt.headerExists(IP_PROTO) || IP_PROTO_TCP_TS != ((IPProtocolCriterion) pkt.getHeader(IP_PROTO)).protocol()) {
                    // has TCP match requirement, but can't afford TCP
                    return false;
                }
                // avoid IP_PROTO locates after TCP_*
                if (!matchAddExactly(pkt, criterion, isBigger)) {
                    return false;
                }
                break;
            case UDP_SRC:
            case UDP_DST:
                if (!pkt.headerExists(IP_PROTO) || IP_PROTO_UDP_TS != ((IPProtocolCriterion) pkt.getHeader(IP_PROTO)).protocol()) {
                    // has UDP match requirement, but can't afford UDP
                    return false;
                }
                // avoid IP_PROTO locates after UDP_*
                if (!matchAddExactly(pkt, criterion, isBigger)) {
                    return false;
                }
                break;
            default:
                log.debug("{} can't be supported by OF1.0", criterion.type());
                return false;
        }
    }
    return true;
}
Also used : IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion)

Example 3 with Criterion

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

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

the class FilteringObjectiveCodec method decode.

@Override
public FilteringObjective decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    CoreService coreService = context.getService(CoreService.class);
    final JsonCodec<Criterion> criterionCodec = context.codec(Criterion.class);
    final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class);
    ObjectiveCodecHelper och = new ObjectiveCodecHelper();
    DefaultFilteringObjective.Builder baseBuilder = DefaultFilteringObjective.builder();
    final DefaultFilteringObjective.Builder builder = (DefaultFilteringObjective.Builder) och.decode(json, baseBuilder, context);
    // application id
    JsonNode appIdJson = json.get(APP_ID);
    String appId = appIdJson != null ? appIdJson.asText() : REST_APP_ID;
    builder.fromApp(coreService.registerApplication(appId));
    // decode type
    String typeStr = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
    switch(typeStr) {
        case "PERMIT":
            builder.permit();
            break;
        case "DENY":
            builder.deny();
            break;
        default:
            throw new IllegalArgumentException("The requested type " + typeStr + " is not defined for FilteringObjective.");
    }
    // decode key
    JsonNode keyJson = json.get(KEY);
    if (keyJson != null) {
        Criterion key = criterionCodec.decode((ObjectNode) keyJson, context);
        builder.withKey(key);
    }
    // decode conditions
    JsonNode conditionsJson = json.get(CONDITIONS);
    checkNotNull(conditionsJson);
    if (conditionsJson != null) {
        IntStream.range(0, conditionsJson.size()).forEach(i -> {
            ObjectNode conditionJson = get(conditionsJson, i);
            builder.addCondition(criterionCodec.decode(conditionJson, context));
        });
    }
    // decode meta
    JsonNode metaJson = json.get(META);
    if (metaJson != null) {
        TrafficTreatment trafficTreatment = trafficTreatmentCodec.decode((ObjectNode) metaJson, context);
        builder.withMeta(trafficTreatment);
    }
    // decode operation
    String opStr = nullIsIllegal(json.get(OPERATION), OPERATION + MISSING_MEMBER_MESSAGE).asText();
    FilteringObjective filteringObjective;
    switch(opStr) {
        case "ADD":
            filteringObjective = builder.add();
            break;
        case "REMOVE":
            filteringObjective = builder.remove();
            break;
        default:
            throw new IllegalArgumentException("The requested operation " + opStr + " is not defined for FilteringObjective.");
    }
    return filteringObjective;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CoreService(org.onosproject.core.CoreService) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) JsonNode(com.fasterxml.jackson.databind.JsonNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Example 5 with Criterion

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

the class CriterionCodecTest method matchTcpSrcTest.

/**
 * Tests source TCP port criterion.
 */
@Test
public void matchTcpSrcTest() {
    Criterion criterion = Criteria.matchTcpSrc(tpPort);
    ObjectNode result = criterionCodec.encode(criterion, context);
    assertThat(result, matchesCriterion(criterion));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) CriterionJsonMatcher.matchesCriterion(org.onosproject.codec.impl.CriterionJsonMatcher.matchesCriterion) Test(org.junit.Test)

Aggregations

Criterion (org.onosproject.net.flow.criteria.Criterion)119 Test (org.junit.Test)54 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)51 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)51 CriterionJsonMatcher.matchesCriterion (org.onosproject.codec.impl.CriterionJsonMatcher.matchesCriterion)46 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)42 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)42 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)39 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)38 Instruction (org.onosproject.net.flow.instructions.Instruction)36 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)35 TrafficSelector (org.onosproject.net.flow.TrafficSelector)31 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)28 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)27 FlowRule (org.onosproject.net.flow.FlowRule)25 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)24 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)24 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)22 Instructions (org.onosproject.net.flow.instructions.Instructions)19 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)17