Search in sources :

Example 11 with IPCriterion

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

Example 12 with IPCriterion

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

the class PicaPipeline method processSpecific.

private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }
    List<FlowRule> ipflows = new ArrayList<FlowRule>();
    for (Filter f : filters) {
        TrafficSelector filteredSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip()).matchEthDst(f.mac()).matchVlanId(f.vlanId()).build();
        TrafficTreatment tt = null;
        if (fwd.nextId() != null) {
            NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
            if (next == null) {
                log.error("next-id {} does not exist in store", fwd.nextId());
                return Collections.emptySet();
            }
            tt = appKryo.deserialize(next.data());
            if (tt == null) {
                log.error("Error in deserializing next-id {}", fwd.nextId());
                return Collections.emptySet();
            }
        }
        FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector).withTreatment(tt);
        if (fwd.permanent()) {
            ruleBuilder.makePermanent();
        } else {
            ruleBuilder.makeTemporary(fwd.timeout());
        }
        ruleBuilder.forTable(IP_UNICAST_TABLE);
        ipflows.add(ruleBuilder.build());
    }
    return ipflows;
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 13 with IPCriterion

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

the class SpringOpenTTP method processEthTypeSpecificObjective.

protected Collection<FlowRule> processEthTypeSpecificObjective(ForwardingObjective fwd) {
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    TrafficSelector.Builder filteredSelectorBuilder = DefaultTrafficSelector.builder();
    int forTableId = -1;
    if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
        filteredSelectorBuilder = filteredSelectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip());
        forTableId = ipv4UnicastTableId;
        log.debug("processing IPv4 specific forwarding objective:{} in dev:{}", fwd.id(), deviceId);
    } else {
        filteredSelectorBuilder = filteredSelectorBuilder.matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(((MplsCriterion) selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
        if (selector.getCriterion(Criterion.Type.MPLS_BOS) != null) {
            filteredSelectorBuilder.matchMplsBos(((MplsBosCriterion) selector.getCriterion(Type.MPLS_BOS)).mplsBos());
        }
        forTableId = mplsTableId;
        log.debug("processing MPLS specific forwarding objective:{} in dev:{}", fwd.id(), deviceId);
    }
    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    if (fwd.treatment() != null) {
        for (Instruction i : fwd.treatment().allInstructions()) {
            treatmentBuilder.add(i);
        }
    }
    if (fwd.nextId() != null) {
        NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
        if (next != null) {
            SpringOpenGroup soGroup = appKryo.deserialize(next.data());
            if (soGroup.dummy) {
                log.debug("Adding {} flow-actions for fwd. obj. {} -> next:{} " + "in dev: {}", soGroup.treatment.allInstructions().size(), fwd.id(), fwd.nextId(), deviceId);
                for (Instruction ins : soGroup.treatment.allInstructions()) {
                    treatmentBuilder.add(ins);
                }
            } else {
                GroupKey key = soGroup.key;
                Group group = groupService.getGroup(deviceId, key);
                if (group == null) {
                    log.warn("The group left!");
                    fail(fwd, ObjectiveError.GROUPMISSING);
                    return Collections.emptySet();
                }
                treatmentBuilder.deferred().group(group.id());
                log.debug("Adding OUTGROUP action to group:{} for fwd. obj. {} " + "for next:{} in dev: {}", group.id(), fwd.id(), fwd.nextId(), deviceId);
            }
        } else {
            log.warn("processSpecific: No associated next objective object");
            fail(fwd, ObjectiveError.GROUPMISSING);
            return Collections.emptySet();
        }
    }
    TrafficSelector filteredSelector = filteredSelectorBuilder.build();
    TrafficTreatment treatment = treatmentBuilder.transition(aclTableId).build();
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector).withTreatment(treatment);
    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }
    ruleBuilder.forTable(forTableId);
    return Collections.singletonList(ruleBuilder.build());
}
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) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) 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) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) 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)

Example 14 with IPCriterion

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

the class SpringOpenTTPDell method processSpecific.

@Override
protected // ETH_DST match condition while pushing IP table flow rules
Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific");
    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)) {
        log.debug("processSpecific: Unsupported " + "forwarding objective criteraia");
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }
    TrafficSelector.Builder filteredSelectorBuilder = DefaultTrafficSelector.builder();
    int forTableId = -1;
    if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
        if (deviceTMac == null) {
            log.debug("processSpecific: ETH_DST filtering " + "objective is not set which is required " + "before sending a IPv4 forwarding objective");
            // TODO: Map the error to more appropriate error code.
            fail(fwd, ObjectiveError.DEVICEMISSING);
            return Collections.emptySet();
        }
        filteredSelectorBuilder = filteredSelectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchEthDst(deviceTMac).matchIPDst(((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip());
        forTableId = ipv4UnicastTableId;
        log.debug("processing IPv4 specific forwarding objective");
    } else {
        filteredSelectorBuilder = filteredSelectorBuilder.matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(((MplsCriterion) selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
        if (selector.getCriterion(Criterion.Type.MPLS_BOS) != null) {
            filteredSelectorBuilder.matchMplsBos(((MplsBosCriterion) selector.getCriterion(Criterion.Type.MPLS_BOS)).mplsBos());
        }
        forTableId = mplsTableId;
        log.debug("processing MPLS specific forwarding objective");
    }
    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    if (fwd.treatment() != null) {
        for (Instruction i : fwd.treatment().allInstructions()) {
            treatmentBuilder.add(i);
        }
    }
    if (fwd.nextId() != null) {
        NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
        if (next != null) {
            SpringOpenGroup soGroup = appKryo.deserialize(next.data());
            if (soGroup.dummy()) {
                log.debug("Adding {} flow-actions for fwd. obj. {} -> next:{} " + "in dev: {}", soGroup.treatment().allInstructions().size(), fwd.id(), fwd.nextId(), deviceId);
                for (Instruction ins : soGroup.treatment().allInstructions()) {
                    treatmentBuilder.add(ins);
                }
            } else {
                Group group = groupService.getGroup(deviceId, soGroup.key());
                if (group == null) {
                    log.warn("The group left!");
                    fail(fwd, ObjectiveError.GROUPMISSING);
                    return Collections.emptySet();
                }
                treatmentBuilder.group(group.id());
                log.debug("Adding OUTGROUP action to group:{} for fwd. obj. {} " + "for next:{} in dev: {}", group.id(), fwd.id(), fwd.nextId(), deviceId);
            }
        } else {
            log.warn("processSpecific: No associated next objective object");
            fail(fwd, ObjectiveError.GROUPMISSING);
            return Collections.emptySet();
        }
    }
    TrafficSelector filteredSelector = filteredSelectorBuilder.build();
    TrafficTreatment treatment = treatmentBuilder.transition(aclTableId).build();
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector).withTreatment(treatment);
    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }
    ruleBuilder.forTable(forTableId);
    return Collections.singletonList(ruleBuilder.build());
}
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) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instruction(org.onosproject.net.flow.instructions.Instruction) 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)

Example 15 with IPCriterion

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

the class CentecV350Pipeline method processSpecific.

private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }
    // Must have metadata as key.
    TrafficSelector filteredSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchMetadata(DEFAULT_METADATA).matchIPDst(((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip()).build();
    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
    if (fwd.nextId() != null) {
        NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
        GroupKey key = appKryo.deserialize(next.data());
        Group group = groupService.getGroup(deviceId, key);
        if (group == null) {
            log.warn("The group left!");
            fail(fwd, ObjectiveError.GROUPMISSING);
            return Collections.emptySet();
        }
        tb.group(group.id());
    }
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(ROUTE_TABLE_PRIORITY).forDevice(deviceId).withSelector(filteredSelector).withTreatment(tb.build());
    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }
    ruleBuilder.forTable(ROUTE_TABLE);
    return Collections.singletonList(ruleBuilder.build());
}
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) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)39 TrafficSelector (org.onosproject.net.flow.TrafficSelector)25 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)22 FlowRule (org.onosproject.net.flow.FlowRule)15 Criterion (org.onosproject.net.flow.criteria.Criterion)14 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)13 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)13 IpPrefix (org.onlab.packet.IpPrefix)11 IPProtocolCriterion (org.onosproject.net.flow.criteria.IPProtocolCriterion)9 TcpPortCriterion (org.onosproject.net.flow.criteria.TcpPortCriterion)9 UdpPortCriterion (org.onosproject.net.flow.criteria.UdpPortCriterion)9 NextGroup (org.onosproject.net.behaviour.NextGroup)8 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)8 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)8 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)8 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)7 Group (org.onosproject.net.group.Group)7 FlowEntry (org.onosproject.net.flow.FlowEntry)6