Search in sources :

Example 6 with EthCriterion

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

the class OfdpaPipelineTraceable method matchMac.

// Checks if the packet has a dst or src MAC and if that Mac matches the mask of the mac criterion
// TODO Candidate for an AbstractBehavior implementation
private boolean matchMac(TrafficSelector packet, EthCriterion hitCriterion, boolean dst) {
    // Packet can have only one EthCriterion
    EthCriterion matchCriterion;
    if (dst) {
        matchCriterion = (EthCriterion) packet.criteria().stream().filter(criterion1 -> criterion1.type().equals(Criterion.Type.ETH_DST_MASKED) || criterion1.type().equals(Criterion.Type.ETH_DST)).findFirst().orElse(null);
    } else {
        matchCriterion = (EthCriterion) packet.criteria().stream().filter(criterion1 -> criterion1.type().equals(Criterion.Type.ETH_SRC_MASKED) || criterion1.type().equals(Criterion.Type.ETH_SRC)).findFirst().orElse(null);
    }
    // if the packet does not have an ETH criterion we return true
    if (matchCriterion == null) {
        return true;
    }
    log.debug("Checking if {} is under {}/{}", matchCriterion.mac(), hitCriterion.mac(), hitCriterion.mask());
    return matchCriterion.mac().inRange(hitCriterion.mac(), hitCriterion.mask());
}
Also used : EthCriterion(org.onosproject.net.flow.criteria.EthCriterion)

Example 7 with EthCriterion

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

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

the class PiCriterionTranslatorsTest method testTernaryToLpmTranslation.

@Test
public void testTernaryToLpmTranslation() throws Exception {
    EthCriterion criterion = (EthCriterion) Criteria.matchEthDstMasked(MacAddress.ONOS, MacAddress.IPV4_MULTICAST_MASK);
    PiLpmFieldMatch lpmMatch = (PiLpmFieldMatch) translateCriterion(criterion, fieldId, LPM, MacAddress.MAC_ADDRESS_LENGTH * Byte.SIZE);
    ImmutableByteSequence expectedValue = ImmutableByteSequence.copyFrom(MacAddress.ONOS.toBytes());
    assertThat(lpmMatch.prefixLength(), is(25));
    assertThat(lpmMatch.value(), is(expectedValue));
}
Also used : EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) PiLpmFieldMatch(org.onosproject.net.pi.runtime.PiLpmFieldMatch) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) Test(org.junit.Test)

Example 9 with EthCriterion

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

the class AbstractHPPipeline method processFilter.

/**
 * Filter processing and installation.
 * Processes and installs filtering rules.
 *
 * @param filt
 * @param install
 * @param applicationId
 */
private void processFilter(FilteringObjective filt, boolean install, ApplicationId applicationId) {
    // This driver only processes filtering criteria defined with switch
    // ports as the key
    PortCriterion port;
    if (!filt.key().equals(Criteria.dummy()) && filt.key().type() == Criterion.Type.IN_PORT) {
        port = (PortCriterion) filt.key();
    } else {
        log.warn("No key defined in filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
        fail(filt, ObjectiveError.UNKNOWN);
        return;
    }
    // convert filtering conditions for switch-intfs into flowrules
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    for (Criterion c : filt.conditions()) {
        if (c.type() == Criterion.Type.ETH_DST) {
            EthCriterion eth = (EthCriterion) c;
            FlowRule.Builder rule = processEthFilter(filt, eth, port);
            rule.forDevice(deviceId).fromApp(applicationId);
            ops = install ? ops.add(rule.build()) : ops.remove(rule.build());
        } else if (c.type() == Criterion.Type.VLAN_VID) {
            VlanIdCriterion vlan = (VlanIdCriterion) c;
            FlowRule.Builder rule = processVlanFilter(filt, vlan, port);
            rule.forDevice(deviceId).fromApp(applicationId);
            ops = install ? ops.add(rule.build()) : ops.remove(rule.build());
        } else if (c.type() == Criterion.Type.IPV4_DST) {
            IPCriterion ip = (IPCriterion) c;
            FlowRule.Builder rule = processIpFilter(filt, ip, port);
            rule.forDevice(deviceId).fromApp(applicationId);
            ops = install ? ops.add(rule.build()) : ops.remove(rule.build());
        } else {
            log.warn("Driver does not currently process filtering condition" + " of type: {}", c.type());
            fail(filt, ObjectiveError.UNSUPPORTED);
        }
    }
    // apply filtering flow rules
    flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            pass(filt);
            log.trace("HP Driver - Applied filtering rules");
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
            log.trace("HP Driver - Failed to apply filtering rules");
        }
    }));
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) Builder(org.onosproject.net.flow.FlowRule.Builder) Builder(org.onosproject.net.flow.FlowRule.Builder) CacheBuilder(com.google.common.cache.CacheBuilder) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 10 with EthCriterion

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

the class PicaPipeline method processFilter.

private void processFilter(FilteringObjective filt, boolean install, ApplicationId applicationId) {
    // This driver only processes filtering criteria defined with switch
    // ports as the key
    PortCriterion p;
    if (!filt.key().equals(Criteria.dummy()) && filt.key().type() == Criterion.Type.IN_PORT) {
        p = (PortCriterion) filt.key();
    } else {
        log.warn("No key defined in filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
        fail(filt, ObjectiveError.UNKNOWN);
        return;
    }
    EthCriterion e = null;
    VlanIdCriterion v = null;
    Collection<IPCriterion> ips = new ArrayList<IPCriterion>();
    // convert filtering conditions for switch-intfs into flowrules
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    for (Criterion c : filt.conditions()) {
        if (c.type() == Criterion.Type.ETH_DST) {
            e = (EthCriterion) c;
        } else if (c.type() == Criterion.Type.VLAN_VID) {
            v = (VlanIdCriterion) c;
        } else if (c.type() == Criterion.Type.IPV4_DST) {
            ips.add((IPCriterion) c);
        } else {
            log.error("Unsupported filter {}", c);
            fail(filt, ObjectiveError.UNSUPPORTED);
            return;
        }
    }
    if (v == null || e == null) {
        log.warn("Pica Pipeline ETH_DST and/or VLAN_ID not specified");
        fail(filt, ObjectiveError.BADPARAMS);
        return;
    }
    // cache for later use
    Filter filter = new Filter(p, e, v, ips);
    filters.add(filter);
    // apply any pending versatile forwarding objectives
    for (ForwardingObjective fwd : pendingVersatiles) {
        Collection<FlowRule> ret = processVersatilesWithFilters(filter, fwd);
        for (FlowRule fr : ret) {
            ops.add(fr);
        }
    }
    for (IPCriterion ipaddr : ips) {
        log.debug("adding IP filtering rules in ACL table: {}", ipaddr.ip());
        TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
        TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
        selector.matchInPort(p.port());
        selector.matchVlanId(v.vlanId());
        selector.matchEthDst(e.mac());
        selector.matchEthType(Ethernet.TYPE_IPV4);
        // router IPs to the controller
        selector.matchIPDst(ipaddr.ip());
        treatment.setOutput(PortNumber.CONTROLLER);
        FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(HIGHEST_PRIORITY).fromApp(applicationId).makePermanent().forTable(ACL_TABLE).build();
        ops = ops.add(rule);
    }
    // apply filtering flow rules
    flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            pass(filt);
            log.info("Applied filtering rules");
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
            log.info("Failed to apply filtering rules");
        }
    }));
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) ArrayList(java.util.ArrayList) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Aggregations

EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)33 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)24 Criterion (org.onosproject.net.flow.criteria.Criterion)18 TrafficSelector (org.onosproject.net.flow.TrafficSelector)15 FlowRule (org.onosproject.net.flow.FlowRule)14 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)14 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)13 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)13 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)12 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)11 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)10 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)9 FlowRuleOperations (org.onosproject.net.flow.FlowRuleOperations)9 FlowRuleOperationsContext (org.onosproject.net.flow.FlowRuleOperationsContext)9 ArrayList (java.util.ArrayList)8 MacAddress (org.onlab.packet.MacAddress)8 Instruction (org.onosproject.net.flow.instructions.Instruction)7 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)7 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)6 ImmutableList (com.google.common.collect.ImmutableList)4