Search in sources :

Example 21 with NextGroup

use of org.onosproject.net.behaviour.NextGroup in project onos by opennetworkinglab.

the class SpringOpenTTP method next.

@Override
public void next(NextObjective nextObjective) {
    NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id());
    switch(nextObjective.op()) {
        case ADD:
            if (nextGroup != null) {
                log.warn("Cannot add next {} that already exists in device {}", nextObjective.id(), deviceId);
                return;
            }
            log.debug("Processing NextObjective id{} in dev{} - add group", nextObjective.id(), deviceId);
            addGroup(nextObjective);
            break;
        case ADD_TO_EXISTING:
            if (nextGroup != null) {
                log.debug("Processing NextObjective id{} in dev{} - add bucket", nextObjective.id(), deviceId);
                addBucketToGroup(nextObjective);
            } else {
                log.warn("Cannot add to group that does not exist");
            }
            break;
        case REMOVE:
            if (nextGroup == null) {
                log.warn("Cannot remove next {} that does not exist in device {}", nextObjective.id(), deviceId);
                return;
            }
            log.debug("Processing NextObjective id{}  in dev{} - remove group", nextObjective.id(), deviceId);
            removeGroup(nextObjective);
            break;
        case REMOVE_FROM_EXISTING:
            if (nextGroup == null) {
                log.warn("Cannot remove from next {} that does not exist in device {}", nextObjective.id(), deviceId);
                return;
            }
            log.debug("Processing NextObjective id{} in dev{} - remove bucket", nextObjective.id(), deviceId);
            removeBucketFromGroup(nextObjective);
            break;
        default:
            log.warn("Unsupported operation {}", nextObjective.op());
    }
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup)

Example 22 with NextGroup

use of org.onosproject.net.behaviour.NextGroup in project onos by opennetworkinglab.

the class SpringOpenTTP method removeBucketFromGroup.

private void removeBucketFromGroup(NextObjective nextObjective) {
    log.debug("removeBucketFromGroup in {}: for next objective id {}", deviceId, nextObjective.id());
    NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id());
    if (nextGroup != null) {
        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 removeBuckets = new GroupBuckets(Collections.singletonList(bucket));
        log.debug("Removing buckets from group id {} of next objective id {} in device {}", group.id(), nextObjective.id(), deviceId);
        groupService.removeBucketsFromGroup(deviceId, key, removeBuckets, key, appId);
    }
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) 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 23 with NextGroup

use of org.onosproject.net.behaviour.NextGroup 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 24 with NextGroup

use of org.onosproject.net.behaviour.NextGroup in project onos by opennetworkinglab.

the class SimpleVirtualFlowObjectiveStore method getAllGroups.

@Override
public Map<Integer, NextGroup> getAllGroups(NetworkId networkId) {
    ConcurrentMap<Integer, byte[]> nextGroups = getNextGroups(networkId);
    Map<Integer, NextGroup> nextGroupMappings = new HashMap<>();
    for (int key : nextGroups.keySet()) {
        NextGroup nextGroup = getNextGroup(networkId, key);
        if (nextGroup != null) {
            nextGroupMappings.put(key, nextGroup);
        }
    }
    return nextGroupMappings;
}
Also used : DefaultNextGroup(org.onosproject.net.behaviour.DefaultNextGroup) NextGroup(org.onosproject.net.behaviour.NextGroup) HashMap(java.util.HashMap)

Example 25 with NextGroup

use of org.onosproject.net.behaviour.NextGroup in project onos by opennetworkinglab.

the class AbstractCorsaPipeline method processSpecificRoute.

private Collection<FlowRule> processSpecificRoute(ForwardingObjective fwd) {
    TrafficSelector filteredSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(((IPCriterion) fwd.selector().getCriterion(Criterion.Type.IPV4_DST)).ip()).build();
    TrafficTreatment.Builder tb = processSpecificRoutingTreatment();
    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 ImmutableSet.of();
        }
        tb.group(group.id());
    } else {
        log.error("Missing NextObjective ID for ForwardingObjective {}", fwd.id());
        fail(fwd, ObjectiveError.BADPARAMS);
        return ImmutableSet.of();
    }
    Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector).withTreatment(tb.build());
    ruleBuilder = processSpecificRoutingRule(ruleBuilder);
    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }
    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) Builder(org.onosproject.net.flow.FlowRule.Builder) CacheBuilder(com.google.common.cache.CacheBuilder) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

NextGroup (org.onosproject.net.behaviour.NextGroup)38 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)25 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)25 Group (org.onosproject.net.group.Group)23 TrafficSelector (org.onosproject.net.flow.TrafficSelector)18 Deque (java.util.Deque)17 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)17 FlowRule (org.onosproject.net.flow.FlowRule)17 ArrayList (java.util.ArrayList)16 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)16 Instruction (org.onosproject.net.flow.instructions.Instruction)12 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)12 GroupKey (org.onosproject.net.group.GroupKey)12 ArrayDeque (java.util.ArrayDeque)10 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)10 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)9 OutputInstruction (org.onosproject.net.flow.instructions.Instructions.OutputInstruction)9 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)8 IpPrefix (org.onlab.packet.IpPrefix)6 DeviceId (org.onosproject.net.DeviceId)6