Search in sources :

Example 81 with TrafficTreatment

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

the class DefaultSingleTablePipeline method next.

@Override
public void next(NextObjective nextObjective) {
    switch(nextObjective.op()) {
        case ADD:
            // Check next objective
            TrafficTreatment treatment = getTreatment(nextObjective);
            if (treatment == null) {
                // unsupported next objective
                nextObjective.context().ifPresent(context -> context.onError(nextObjective, ObjectiveError.UNSUPPORTED));
                return;
            }
            // We insert the value in the cache
            pendingAddNext.put(nextObjective.id(), nextObjective);
            // Then in the store, this will unblock the queued fwd obj
            flowObjectiveStore.putNextGroup(nextObjective.id(), new SingleGroup(treatment));
            break;
        case REMOVE:
            NextGroup next = flowObjectiveStore.removeNextGroup(nextObjective.id());
            if (next == null) {
                nextObjective.context().ifPresent(context -> context.onError(nextObjective, ObjectiveError.GROUPMISSING));
                return;
            }
            break;
        default:
            log.warn("Unsupported operation {}", nextObjective.op());
    }
    nextObjective.context().ifPresent(context -> context.onSuccess(nextObjective));
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 82 with TrafficTreatment

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

the class OpenVSwitchPipeline method processSpecific.

private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    TrafficTreatment tb = fwd.treatment();
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(selector).withTreatment(tb).makeTemporary(TIME_OUT);
    ruleBuilder.withPriority(fwd.priority());
    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    }
    Integer transition = null;
    Integer forTable = null;
    // MAC table flow rules
    if (selector.getCriterion(Type.TUNNEL_ID) != null && (selector.getCriterion(Type.ETH_DST) != null || selector.getCriterion(Type.ETH_SRC) != null)) {
        forTable = MAC_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // CLASSIFIER table flow rules
    if (selector.getCriterion(Type.IN_PORT) != null) {
        forTable = CLASSIFIER_TABLE;
        if (selector.getCriterion(Type.ETH_SRC) != null && selector.getCriterion(Type.ETH_DST) != null) {
            transition = L3FWD_TABLE;
        } else if (selector.getCriterion(Type.ETH_SRC) != null || selector.getCriterion(Type.TUNNEL_ID) != null) {
            transition = MAC_TABLE;
        } else if (selector.getCriterion(Type.IPV4_DST) != null) {
            transition = DNAT_TABLE;
        } else if (selector.getCriterion(Type.ETH_TYPE) != null && selector.getCriterion(Type.ETH_TYPE).equals(Criteria.matchEthType(EtherType.ARP.ethType().toShort()))) {
            transition = ARP_TABLE;
        }
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // ARP table flow rules
    if (selector.getCriterion(Type.ETH_TYPE) != null && selector.getCriterion(Type.ETH_TYPE).equals(Criteria.matchEthType(EtherType.ARP.ethType().toShort()))) {
        // CLASSIFIER table arp flow rules
        if (selector.getCriterion(Type.TUNNEL_ID) == null) {
            if (selector.getCriterion(Type.ARP_OP) != null) {
                forTable = CLASSIFIER_TABLE;
                return reassemblyFlowRule(ruleBuilder, tb, null, forTable);
            }
            transition = ARP_TABLE;
            forTable = CLASSIFIER_TABLE;
            return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
        }
        forTable = ARP_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // SNAT table flow rules
    if (selector.getCriterion(Type.TUNNEL_ID) != null && selector.getCriterion(Type.IPV4_SRC) != null) {
        transition = MAC_TABLE;
        forTable = SNAT_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // L3FWD table flow rules
    if (selector.getCriterion(Type.TUNNEL_ID) != null && selector.getCriterion(Type.IPV4_DST) != null) {
        transition = MAC_TABLE;
        forTable = L3FWD_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    // DNAT table flow rules
    if (selector.getCriterion(Type.IPV4_DST) != null) {
        IPCriterion ipCriterion = (IPCriterion) selector.getCriterion(Type.IPV4_DST);
        IpPrefix ipPrefix = ipCriterion.ip();
        // specific CLASSIFIER table flow rules for userdata
        if (ipPrefix.address().equals(IpAddress.valueOf(USERDATA_IP))) {
            forTable = CLASSIFIER_TABLE;
            transition = MAC_TABLE;
            return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
        }
        transition = L3FWD_TABLE;
        forTable = DNAT_TABLE;
        return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
    }
    return Collections.singletonList(ruleBuilder.build());
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) 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 83 with TrafficTreatment

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

the class OpenVSwitchPipeline method processVersatile.

private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
    log.debug("Processing versatile forwarding objective");
    TrafficSelector selector = fwd.selector();
    TrafficTreatment tb = fwd.treatment();
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(selector).withTreatment(tb).makeTemporary(TIME_OUT);
    ruleBuilder.withPriority(fwd.priority());
    if (fwd.priority() == 100) {
        ruleBuilder.forTable(ENCAP_OUTPUT_TABLE);
    } else if (fwd.priority() == 200) {
        ruleBuilder.forTable(TUN_SEND_TABLE);
    } else {
        ruleBuilder.forTable(CLASSIFIER_TABLE);
    }
    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    }
    return Collections.singletonList(ruleBuilder.build());
}
Also used : 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 84 with TrafficTreatment

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

the class PicaPipeline method next.

@Override
public void next(NextObjective nextObjective) {
    switch(nextObjective.type()) {
        case SIMPLE:
            Collection<TrafficTreatment> treatments = nextObjective.next();
            if (treatments.size() != 1) {
                log.error("Next Objectives of type Simple should only have a " + "single Traffic Treatment. Next Objective Id:{}", nextObjective.id());
                fail(nextObjective, ObjectiveError.BADPARAMS);
                return;
            }
            TrafficTreatment treatment = treatments.iterator().next();
            TrafficTreatment.Builder filteredTreatment = DefaultTrafficTreatment.builder();
            VlanId modVlanId;
            for (Instruction ins : treatment.allInstructions()) {
                if (ins.type() == Instruction.Type.L2MODIFICATION) {
                    L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
                    switch(l2ins.subtype()) {
                        case ETH_DST:
                            filteredTreatment.setEthDst(((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
                            break;
                        case ETH_SRC:
                            filteredTreatment.setEthSrc(((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
                            break;
                        case VLAN_ID:
                            modVlanId = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
                            filteredTreatment.setVlanId(modVlanId);
                            break;
                        default:
                            break;
                    }
                } else if (ins.type() == Instruction.Type.OUTPUT) {
                    // long portNum = ((Instructions.OutputInstruction) ins).port().toLong();
                    filteredTreatment.add(ins);
                } else {
                    // Ignore the vlan_pcp action since it's does matter much.
                    log.warn("Driver does not handle this type of TrafficTreatment" + " instruction in nextObjectives:  {}", ins.type());
                }
            }
            // store for future use
            flowObjectiveStore.putNextGroup(nextObjective.id(), new PicaGroup(filteredTreatment.build()));
            break;
        case HASHED:
        case BROADCAST:
        case FAILOVER:
            fail(nextObjective, ObjectiveError.UNSUPPORTED);
            log.warn("Unsupported next objective type {}", nextObjective.type());
            break;
        default:
            fail(nextObjective, ObjectiveError.UNKNOWN);
            log.warn("Unknown next objective type {}", nextObjective.type());
    }
}
Also used : L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId)

Example 85 with TrafficTreatment

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

Aggregations

TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)395 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)369 TrafficSelector (org.onosproject.net.flow.TrafficSelector)257 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)236 FlowRule (org.onosproject.net.flow.FlowRule)93 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)86 PiAction (org.onosproject.net.pi.runtime.PiAction)79 Test (org.junit.Test)78 PortNumber (org.onosproject.net.PortNumber)70 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)56 Instruction (org.onosproject.net.flow.instructions.Instruction)52 DeviceId (org.onosproject.net.DeviceId)46 NextObjective (org.onosproject.net.flowobjective.NextObjective)45 ConnectPoint (org.onosproject.net.ConnectPoint)44 List (java.util.List)43 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)43 Ethernet (org.onlab.packet.Ethernet)40 Criterion (org.onosproject.net.flow.criteria.Criterion)39 GroupBucket (org.onosproject.net.group.GroupBucket)39 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)37