Search in sources :

Example 26 with FlowRuleOperations

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

the class JuniperQfx5100Pipeliner method forward.

@Override
public void forward(ForwardingObjective forwardObjective) {
    FlowRule rule;
    FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder();
    ForwardingObjective newFwd = forwardObjective;
    Device device = deviceService.getDevice(deviceId);
    if (forwardObjective.treatment() != null && forwardObjective.treatment().clearedDeferred()) {
        log.warn("Using 'clear actions' instruction which is not supported by {}  {} {} Switch", device.id(), device.manufacturer(), device.hwVersion());
        newFwd = forwardingObjectiveWithoutCleardDef(forwardObjective).orElse(forwardObjective);
    }
    rule = processForward(newFwd);
    switch(forwardObjective.op()) {
        case ADD:
            flowOpsBuilder.add(rule);
            break;
        case REMOVE:
            flowOpsBuilder.remove(rule);
            break;
        default:
            fail(forwardObjective, ObjectiveError.UNKNOWN);
            log.warn("Unknown forwarding type {}", forwardObjective.op());
    }
    flowRuleService.apply(flowOpsBuilder.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            pass(forwardObjective);
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            fail(forwardObjective, ObjectiveError.FLOWINSTALLATIONFAILED);
        }
    }));
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Device(org.onosproject.net.Device) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext)

Example 27 with FlowRuleOperations

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

the class SpringOpenTTP method processFilter.

private void processFilter(FilteringObjective filt, boolean install, ApplicationId applicationId) {
    // ports as the key
    if (filt.key().equals(Criteria.dummy()) || filt.key().type() != Criterion.Type.IN_PORT) {
        log.warn("No key defined in filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
        fail(filt, ObjectiveError.UNKNOWN);
        return;
    }
    EthCriterion ethCriterion = null;
    VlanIdCriterion vlanIdCriterion = null;
    // convert filtering conditions for switch-intfs into flowrules
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    for (Criterion criterion : filt.conditions()) {
        if (criterion.type() == Criterion.Type.ETH_DST) {
            ethCriterion = (EthCriterion) criterion;
        } else if (criterion.type() == Criterion.Type.VLAN_VID) {
            vlanIdCriterion = (VlanIdCriterion) criterion;
        } else if (criterion.type() == Criterion.Type.IPV4_DST) {
            log.debug("driver does not process IP filtering rules as it " + "sends all misses in the IP table to the controller");
        } else {
            log.warn("Driver does not currently process filtering condition" + " of type: {}", criterion.type());
            fail(filt, ObjectiveError.UNSUPPORTED);
        }
    }
    VlanId assignedVlan = null;
    VlanId modifiedVlan = null;
    VlanId pushedVlan = null;
    boolean pushVlan = false;
    boolean popVlan = false;
    if (vlanIdCriterion != null) {
        if (filt.meta() != null) {
            for (Instruction i : filt.meta().allInstructions()) {
                if (i instanceof L2ModificationInstruction) {
                    if (((L2ModificationInstruction) i).subtype().equals(L2ModificationInstruction.L2SubType.VLAN_PUSH)) {
                        pushVlan = true;
                    } else if (((L2ModificationInstruction) i).subtype().equals(L2ModificationInstruction.L2SubType.VLAN_POP)) {
                        if (modifiedVlan != null) {
                            log.error("Pop tag is not allowed after modify VLAN operation " + "in filtering objective", deviceId);
                            fail(filt, ObjectiveError.BADPARAMS);
                            return;
                        }
                        popVlan = true;
                    }
                }
                if (i instanceof ModVlanIdInstruction) {
                    if (pushVlan && vlanIdCriterion.vlanId() != VlanId.NONE) {
                        // Modify VLAN should not appear after pushing a new tag
                        if (pushedVlan != null) {
                            log.error("Modify VLAN not allowed after push tag operation " + "in filtering objective", deviceId);
                            fail(filt, ObjectiveError.BADPARAMS);
                            return;
                        }
                        pushedVlan = ((ModVlanIdInstruction) i).vlanId();
                    } else if (vlanIdCriterion.vlanId() == VlanId.NONE) {
                        // For untagged packets the pushed VLAN ID will be saved in assignedVlan
                        // just to ensure the driver works as designed for the fabric use case
                        assignedVlan = ((ModVlanIdInstruction) i).vlanId();
                    } else {
                        // For tagged packets modifiedVlan will contain the modified value of existing tag
                        if (modifiedVlan != null) {
                            log.error("Driver does not allow multiple modify VLAN operations " + "in the same filtering objective", deviceId);
                            fail(filt, ObjectiveError.BADPARAMS);
                            return;
                        }
                        modifiedVlan = ((ModVlanIdInstruction) i).vlanId();
                    }
                }
            }
        }
        // For VLAN cross-connect packets, use the configured VLAN unless there is an explicitly provided VLAN ID
        if (vlanIdCriterion.vlanId() != VlanId.NONE) {
            if (assignedVlan == null) {
                assignedVlan = vlanIdCriterion.vlanId();
            }
        // For untagged packets, assign a VLAN ID
        } else {
            if (filt.meta() == null) {
                log.error("Missing metadata in filtering objective required " + "for vlan assignment in dev {}", deviceId);
                fail(filt, ObjectiveError.BADPARAMS);
                return;
            }
            if (assignedVlan == null) {
                log.error("Driver requires an assigned vlan-id to tag incoming " + "untagged packets. Not processing vlan filters on " + "device {}", deviceId);
                fail(filt, ObjectiveError.BADPARAMS);
                return;
            }
        }
        if (pushVlan && popVlan) {
            log.error("Cannot push and pop vlan in the same filtering objective");
            fail(filt, ObjectiveError.BADPARAMS);
            return;
        }
        if (popVlan && vlanIdCriterion.vlanId() == VlanId.NONE) {
            log.error("Cannot pop vlan for untagged packets");
            fail(filt, ObjectiveError.BADPARAMS);
            return;
        }
        if ((pushVlan && pushedVlan == null) && vlanIdCriterion.vlanId() != VlanId.NONE) {
            log.error("No VLAN ID provided for push tag operation");
            fail(filt, ObjectiveError.BADPARAMS);
            return;
        }
    }
    if (ethCriterion == null) {
        log.debug("filtering objective missing dstMac, cannot program TMAC table");
    } else {
        for (FlowRule tmacRule : processEthDstFilter(ethCriterion, vlanIdCriterion, filt, assignedVlan, applicationId)) {
            log.debug("adding MAC filtering rules in TMAC table: {} for dev: {}", tmacRule, deviceId);
            ops = install ? ops.add(tmacRule) : ops.remove(tmacRule);
        }
    }
    if (vlanIdCriterion == null) {
        log.debug("filtering objective missing VLAN ID criterion, " + "cannot program VLAN Table");
    } else {
        for (FlowRule vlanRule : processVlanIdFilter(vlanIdCriterion, filt, assignedVlan, modifiedVlan, pushedVlan, pushVlan, popVlan, applicationId)) {
            log.debug("adding VLAN filtering rule in VLAN table: {} for dev: {}", vlanRule, deviceId);
            ops = install ? ops.add(vlanRule) : ops.remove(vlanRule);
        }
    }
    // apply filtering flow rules
    flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            pass(filt);
            log.debug("Provisioned tables in {} with fitering " + "rules", deviceId);
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
            log.warn("Failed to provision tables in {} with " + "fitering rules", deviceId);
        }
    }));
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) 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) VlanId(org.onlab.packet.VlanId) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 28 with FlowRuleOperations

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

the class CentecV350Pipeline method processFilter.

private void processFilter(FilteringObjective filt, boolean install, ApplicationId applicationId) {
    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;
    }
    // Convert filtering conditions for switch-intfs into flow rules.
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    for (Criterion c : filt.conditions()) {
        // Here we do a trick to install 2 flow rules to MAC_TABLE and ROUTE_TABLE.
        if (c.type() == Criterion.Type.ETH_DST) {
            EthCriterion e = (EthCriterion) c;
            // Install TMAC flow rule.
            log.debug("adding rule for Termination MAC in Filter Table: {}", e.mac());
            TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
            TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
            selector.matchEthDst(e.mac());
            // Add IPv4 matching explicitly since we will redirect it to ROUTE Table
            // through MAC table.
            selector.matchEthType(Ethernet.TYPE_IPV4);
            treatment.transition(MAC_TABLE);
            FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(FILTER_TABLE_TMAC_PRIORITY).fromApp(applicationId).makePermanent().forTable(FILTER_TABLE).build();
            ops = install ? ops.add(rule) : ops.remove(rule);
            // Must install another rule to direct the IPv4 packets that hit TMAC to
            // Route table.
            log.debug("adding rule for Termination MAC in MAC Table: {}", e.mac());
            selector = DefaultTrafficSelector.builder();
            treatment = DefaultTrafficTreatment.builder();
            selector.matchEthDst(e.mac());
            // MAC_Table must have metadata matching configured, use the default metadata.
            selector.matchMetadata(DEFAULT_METADATA);
            treatment.transition(ROUTE_TABLE);
            rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(MAC_TABLE_PRIORITY).fromApp(applicationId).makePermanent().forTable(MAC_TABLE).build();
            ops = install ? ops.add(rule) : ops.remove(rule);
        } else if (c.type() == Criterion.Type.VLAN_VID) {
            VlanIdCriterion v = (VlanIdCriterion) c;
            log.debug("adding rule for VLAN: {}", v.vlanId());
            TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
            TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
            selector.matchVlanId(v.vlanId());
            selector.matchInPort(p.port());
            // Although the accepted packets will be sent to filter table, we must
            // explicitly set goto_table instruction here.
            treatment.writeMetadata(DEFAULT_METADATA, DEFAULT_METADATA_MASK);
            // set default metadata written by PORT_VLAN Table.
            treatment.transition(FILTER_TABLE);
            // We do not support strip vlan here, treatment.deferred().popVlan();
            // PORT_VLAN table only accept 0xffff priority since it does exact match only.
            FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(PORT_VLAN_TABLE_PRIORITY).fromApp(applicationId).makePermanent().forTable(PORT_VLAN_TABLE).build();
            ops = install ? ops.add(rule) : ops.remove(rule);
        } else if (c.type() == Criterion.Type.IPV4_DST) {
            IPCriterion ipaddr = (IPCriterion) c;
            log.debug("adding IP filtering rules in FILTER table: {}", ipaddr.ip());
            TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
            TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
            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(FILTER_TABLE_CONTROLLER_PRIORITY).fromApp(applicationId).makePermanent().forTable(FILTER_TABLE).build();
            ops = install ? ops.add(rule) : ops.remove(rule);
        } 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.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) CacheBuilder(com.google.common.cache.CacheBuilder) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) 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) 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 29 with FlowRuleOperations

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

the class CentecV350Pipeline method processFilterTable.

private void processFilterTable(boolean install) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    FlowRule rule;
    // Punt ARP packets to controller by default.
    selector.matchEthType(Ethernet.TYPE_ARP);
    treatment.punt();
    rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(FILTER_TABLE_CONTROLLER_PRIORITY).fromApp(appId).makePermanent().forTable(FILTER_TABLE).build();
    ops = install ? ops.add(rule) : ops.remove(rule);
    // Punt BGP packets to controller directly.
    selector = DefaultTrafficSelector.builder();
    treatment = DefaultTrafficTreatment.builder();
    selector.matchEthType(Ethernet.TYPE_IPV4).matchIPProtocol(IPv4.PROTOCOL_TCP).matchTcpSrc(TpPort.tpPort(BGP_PORT));
    treatment.punt();
    rule = DefaultFlowRule.builder().forDevice(deviceId).withPriority(FILTER_TABLE_HIGHEST_PRIORITY).withSelector(selector.build()).withTreatment(treatment.build()).fromApp(appId).makePermanent().forTable(FILTER_TABLE).build();
    ops = install ? ops.add(rule) : ops.remove(rule);
    selector = DefaultTrafficSelector.builder();
    treatment = DefaultTrafficTreatment.builder();
    selector.matchEthType(Ethernet.TYPE_IPV4).matchIPProtocol(IPv4.PROTOCOL_TCP).matchTcpDst(TpPort.tpPort(BGP_PORT));
    treatment.punt();
    rule = DefaultFlowRule.builder().forDevice(deviceId).withPriority(FILTER_TABLE_HIGHEST_PRIORITY).withSelector(selector.build()).withTreatment(treatment.build()).fromApp(appId).makePermanent().forTable(FILTER_TABLE).build();
    ops = install ? ops.add(rule) : ops.remove(rule);
    // Packet will be discard in PORT_VLAN table, no need to install rule in
    // filter table.
    // XXX does not tell me if packets are going to be dropped by default in
    // filter table or not? TTP says it will be dropped by default
    flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            log.info("Provisioned filter table");
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            log.info("Failed to provision filter table");
        }
    }));
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) 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) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext)

Example 30 with FlowRuleOperations

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

the class CorsaPipelineV1 method processVlanMplsTable.

@Override
protected void processVlanMplsTable(boolean install) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    FlowRule rule;
    // corsa uses non-OF-standard way to match on presence of VLAN tags
    selector.matchEthType(Ethernet.TYPE_VLAN);
    treatment.transition(VLAN_TABLE);
    rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(CONTROLLER_PRIORITY).fromApp(appId).makePermanent().forTable(VLAN_MPLS_TABLE).build();
    ops = install ? ops.add(rule) : ops.remove(rule);
    flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            log.info("Provisioned vlan/mpls table");
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            log.info("Failed to provision vlan/mpls table");
        }
    }));
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext)

Aggregations

FlowRuleOperations (org.onosproject.net.flow.FlowRuleOperations)35 FlowRule (org.onosproject.net.flow.FlowRule)30 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)27 FlowRuleOperationsContext (org.onosproject.net.flow.FlowRuleOperationsContext)22 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)11 TrafficSelector (org.onosproject.net.flow.TrafficSelector)11 Criterion (org.onosproject.net.flow.criteria.Criterion)11 Test (org.junit.Test)10 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)10 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)10 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)10 IntReportConfig (org.stratumproject.fabric.tna.inbandtelemetry.IntReportConfig)10 TestUtils.getIntReportConfig (org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig)10 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)8 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)7 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)6 FlowEntry (org.onosproject.net.flow.FlowEntry)6 Set (java.util.Set)5