Search in sources :

Example 86 with TrafficTreatment

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

the class SoftRouterPipeline method processSimpleNextObjective.

/**
 * Next Objectives are stored as dummy groups for retrieval later
 * when Forwarding Objectives reference the next objective id. At that point
 * the dummy group is fetched from the distributed store and the enclosed
 * treatment is applied as a flow rule action.
 *
 * @param nextObj the next objective of type simple
 */
private void processSimpleNextObjective(NextObjective nextObj) {
    // Simple next objective has a single treatment (not a collection)
    log.debug("Received nextObj {}", nextObj.id());
    // delay processing to emulate group creation
    delay(50);
    TrafficTreatment treatment = nextObj.next().iterator().next();
    flowObjectiveStore.putNextGroup(nextObj.id(), new DummyGroup(treatment));
}
Also used : DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 87 with TrafficTreatment

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

the class SoftRouterPipeline method processVersatile.

/**
 * SoftRouter has a single versatile table - the filter table.
 * This table can be used to filter entries that reach the next table (FIB table).
 * It can also be used to punt packets to the controller and/or bypass
 * the FIB table to forward out of a port.
 *
 * @param fwd The forwarding objective of type versatile
 * @return  A collection of flow rules meant to be delivered to the flowrule
 *          subsystem. May return empty collection in case of failures.
 */
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
    log.debug("Received versatile fwd: to next:{}", fwd.nextId());
    Collection<FlowRule> flowrules = new ArrayList<>();
    if (fwd.nextId() == null && fwd.treatment() == null) {
        log.error("Forwarding objective {} from {} must contain " + "nextId or Treatment", fwd.selector(), fwd.appId());
        return Collections.emptySet();
    }
    int tableId = FILTER_TABLE;
    // so that it only takes effect if the packet misses the FIB rules
    if (fwd.treatment() != null && containsPunt(fwd.treatment()) && fwd.selector() != null && matchesIp(fwd.selector()) && !matchesControlTraffic(fwd.selector())) {
        tableId = FIB_TABLE;
    }
    TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
    if (fwd.treatment() != null) {
        fwd.treatment().immediate().forEach(ins -> ttBuilder.add(ins));
    }
    // convert nextId to flow actions
    if (fwd.nextId() != null) {
        // only acceptable value is output to port
        NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
        if (next == null) {
            log.error("next-id {} does not exist in store", fwd.nextId());
            return Collections.emptySet();
        }
        TrafficTreatment nt = appKryo.deserialize(next.data());
        if (nt == null) {
            log.error("Error in deserializing next-id {}", fwd.nextId());
            return Collections.emptySet();
        }
        for (Instruction ins : nt.allInstructions()) {
            if (ins instanceof OutputInstruction) {
                ttBuilder.add(ins);
            }
        }
    }
    FlowRule rule = DefaultFlowRule.builder().withSelector(fwd.selector()).withTreatment(ttBuilder.build()).forTable(tableId).makePermanent().forDevice(deviceId).fromApp(fwd.appId()).withPriority(fwd.priority()).build();
    flowrules.add(rule);
    return flowrules;
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ArrayList(java.util.ArrayList) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction)

Example 88 with TrafficTreatment

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

the class SpringOpenTTP method addBucketToGroup.

private void addBucketToGroup(NextObjective nextObjective) {
    log.debug("addBucketToGroup in {}: for next objective id {}", deviceId, nextObjective.id());
    Collection<TrafficTreatment> treatments = nextObjective.next();
    TrafficTreatment treatment = treatments.iterator().next();
    final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
    Group group = groupService.getGroup(deviceId, key);
    if (group == null) {
        log.warn("Group is not found in {} for {}", deviceId, key);
        return;
    }
    GroupBucket bucket;
    if (group.type() == GroupDescription.Type.INDIRECT) {
        bucket = DefaultGroupBucket.createIndirectGroupBucket(treatment);
    } else if (group.type() == GroupDescription.Type.SELECT) {
        bucket = DefaultGroupBucket.createSelectGroupBucket(treatment);
    } else if (group.type() == GroupDescription.Type.ALL) {
        bucket = DefaultGroupBucket.createAllGroupBucket(treatment);
    } else {
        log.warn("Unsupported Group type {}", group.type());
        return;
    }
    GroupBuckets bucketsToAdd = new GroupBuckets(Collections.singletonList(bucket));
    log.debug("Adding buckets to group id {} of next objective id {} in device {}", group.id(), nextObjective.id(), deviceId);
    groupService.addBucketsToGroup(deviceId, key, bucketsToAdd, key, appId);
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets)

Example 89 with TrafficTreatment

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

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

the class SpringOpenTTP method addGroup.

private void addGroup(NextObjective nextObjective) {
    log.debug("addGroup with type{} for nextObjective id {}", nextObjective.type(), nextObjective.id());
    List<GroupBucket> buckets;
    switch(nextObjective.type()) {
        case SIMPLE:
            Collection<TrafficTreatment> treatments = nextObjective.next();
            if (treatments.size() == 1) {
                // Spring Open TTP converts simple nextObjective to flow-actions
                // in a dummy group
                TrafficTreatment treatment = nextObjective.next().iterator().next();
                log.debug("Converting SIMPLE group for next objective id {} " + "to {} flow-actions in device:{}", nextObjective.id(), treatment.allInstructions().size(), deviceId);
                flowObjectiveStore.putNextGroup(nextObjective.id(), new SpringOpenGroup(null, treatment));
            }
            break;
        case HASHED:
            // we convert MPLS ECMP groups to flow-actions for a single
            // bucket(output port).
            boolean mplsEcmp = false;
            if (nextObjective.meta() != null) {
                for (Criterion c : nextObjective.meta().criteria()) {
                    if (c.type() == Type.MPLS_LABEL) {
                        mplsEcmp = true;
                    }
                }
            }
            if (mplsEcmp) {
                // covert to flow-actions in a dummy group by choosing the first bucket
                log.debug("Converting HASHED group for next objective id {} " + "to flow-actions in device:{}", nextObjective.id(), deviceId);
                TrafficTreatment treatment = nextObjective.next().iterator().next();
                flowObjectiveStore.putNextGroup(nextObjective.id(), new SpringOpenGroup(null, treatment));
            } else {
                // process as ECMP group
                buckets = nextObjective.next().stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
                if (!buckets.isEmpty()) {
                    final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
                    GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.SELECT, new GroupBuckets(buckets), key, null, nextObjective.appId());
                    log.debug("Creating HASHED group for next objective id {}" + " in dev:{}", nextObjective.id(), deviceId);
                    pendingGroups.put(key, nextObjective);
                    groupService.addGroup(groupDescription);
                    verifyPendingGroupLater();
                }
            }
            break;
        case BROADCAST:
            buckets = nextObjective.next().stream().map(DefaultGroupBucket::createAllGroupBucket).collect(Collectors.toList());
            if (!buckets.isEmpty()) {
                final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
                GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.ALL, new GroupBuckets(buckets), key, null, nextObjective.appId());
                log.debug("Creating BROADCAST group for next objective id {} " + "in device {}", nextObjective.id(), deviceId);
                pendingGroups.put(key, nextObjective);
                groupService.addGroup(groupDescription);
                verifyPendingGroupLater();
            }
            break;
        case FAILOVER:
            log.debug("FAILOVER next objectives not supported");
            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 : GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) 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) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

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