Search in sources :

Example 16 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class Ofdpa2GroupHandler method removeBucket.

/**
 * Removes top-level buckets from a group that represents the given next objective.
 *
 * @param chainsToRemove a list of group bucket chains to remove
 * @param nextObjective the next objective that contains information for the
 *                  buckets to be removed from the group
 */
protected void removeBucket(List<Deque<GroupKey>> chainsToRemove, NextObjective nextObjective) {
    List<GroupBucket> bucketsToRemove = Lists.newArrayList();
    // first group key is the one we want to modify
    GroupKey modGroupKey = chainsToRemove.get(0).peekFirst();
    Group modGroup = groupService.getGroup(deviceId, modGroupKey);
    if (modGroup == null) {
        log.warn("removeBucket(): Attempt to modify non-existent group {} for device {}", modGroupKey, deviceId);
        return;
    }
    for (Deque<GroupKey> foundChain : chainsToRemove) {
        // second group key is the one we wish to remove the reference to
        if (foundChain.size() < 2) {
            // additional check to make sure second group key exists in
            // the chain.
            log.warn("Can't find second group key from chain {}", foundChain);
            continue;
        }
        GroupKey pointedGroupKey = foundChain.stream().collect(Collectors.toList()).get(1);
        Group pointedGroup = groupService.getGroup(deviceId, pointedGroupKey);
        if (pointedGroup == null) {
            continue;
        }
        GroupBucket bucket;
        if (nextObjective.type() == NextObjective.Type.HASHED) {
            bucket = DefaultGroupBucket.createSelectGroupBucket(DefaultTrafficTreatment.builder().group(pointedGroup.id()).build());
        } else {
            bucket = DefaultGroupBucket.createAllGroupBucket(DefaultTrafficTreatment.builder().group(pointedGroup.id()).build());
        }
        bucketsToRemove.add(bucket);
    }
    GroupBuckets removeBuckets = new GroupBuckets(bucketsToRemove);
    // for debug log
    List<String> pointedGroupIds;
    pointedGroupIds = bucketsToRemove.stream().map(GroupBucket::treatment).map(TrafficTreatment::allInstructions).flatMap(List::stream).filter(inst -> inst instanceof Instructions.GroupInstruction).map(inst -> (Instructions.GroupInstruction) inst).map(Instructions.GroupInstruction::groupId).map(GroupId::id).map(Integer::toHexString).map(id -> HEX_PREFIX + id).collect(Collectors.toList());
    log.debug("Removing buckets from group id 0x{} pointing to group id(s) {} " + "for next id {} in device {}", Integer.toHexString(modGroup.id().id()), pointedGroupIds, nextObjective.id(), deviceId);
    addPendingUpdateNextObjective(modGroupKey, nextObjective);
    groupService.removeBucketsFromGroup(deviceId, modGroupKey, removeBuckets, modGroupKey, nextObjective.appId());
    // potentially stale copy of allActiveKeys
    synchronized (flowObjectiveStore) {
        // get a fresh copy of what the store holds
        NextGroup next = flowObjectiveStore.getNextGroup(nextObjective.id());
        List<Deque<GroupKey>> allActiveKeys = appKryo.deserialize(next.data());
        allActiveKeys = Lists.newArrayList(allActiveKeys);
        // Note that since we got a new object, and ArrayDeque does not implement
        // Object.equals(), we have to check the deque elems one by one
        allActiveKeys.removeIf(active -> chainsToRemove.stream().anyMatch(remove -> Arrays.equals(remove.toArray(new GroupKey[0]), active.toArray(new GroupKey[0]))));
        // top level group which still exists.
        if (allActiveKeys.isEmpty()) {
            ArrayDeque<GroupKey> top = new ArrayDeque<>();
            top.add(modGroupKey);
            allActiveKeys.add(top);
        }
        flowObjectiveStore.putNextGroup(nextObjective.id(), new OfdpaNextGroup(allActiveKeys, nextObjective));
    }
}
Also used : Arrays(java.util.Arrays) TUNNEL_ID(org.onosproject.net.flow.criteria.Criterion.Type.TUNNEL_ID) AtomicCounter(org.onosproject.store.service.AtomicCounter) OfdpaPipelineUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility) PortNumber(org.onosproject.net.PortNumber) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Operation(org.onosproject.net.flowobjective.Objective.Operation) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) ServiceDirectory(org.onlab.osgi.ServiceDirectory) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) INDIRECT(org.onosproject.net.group.GroupDescription.Type.INDIRECT) StorageService(org.onosproject.store.service.StorageService) GroupListener(org.onosproject.net.group.GroupListener) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) IN_PORT(org.onosproject.net.flow.criteria.Criterion.Type.IN_PORT) SELECT(org.onosproject.net.group.GroupDescription.Type.SELECT) ALL(org.onosproject.net.group.GroupDescription.Type.ALL) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) VLAN_VID(org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) FlowObjectiveStore(org.onosproject.net.flowobjective.FlowObjectiveStore) GroupEvent(org.onosproject.net.group.GroupEvent) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) L2_MULTICAST_TYPE(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.L2_MULTICAST_TYPE) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) GroupBuckets(org.onosproject.net.group.GroupBuckets) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) DeviceId(org.onosproject.net.DeviceId) Ofdpa2Pipeline(org.onosproject.driver.pipeline.ofdpa.Ofdpa2Pipeline) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) IpPrefix(org.onlab.packet.IpPrefix) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) OfdpaSetAllowVlanTranslation(org.onosproject.driver.extensions.OfdpaSetAllowVlanTranslation) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) OfdpaSetVlanVid(org.onosproject.driver.extensions.OfdpaSetVlanVid) DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) GroupBucket(org.onosproject.net.group.GroupBucket) NextGroup(org.onosproject.net.behaviour.NextGroup) GroupKey(org.onosproject.net.group.GroupKey) Deque(java.util.Deque) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) OfdpaGroupHandlerUtility.l2MulticastGroupKey(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OfdpaGroupHandlerUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) RemovalNotification(com.google.common.cache.RemovalNotification) Ofdpa3AllowVlanTranslationType(org.onosproject.driver.extensions.Ofdpa3AllowVlanTranslationType) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) MplsLabel(org.onlab.packet.MplsLabel) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) GroupService(org.onosproject.net.group.GroupService) GroupInstruction(org.onosproject.net.flow.instructions.Instructions.GroupInstruction) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment) TimeUnit(java.util.concurrent.TimeUnit) RemovalCause(com.google.common.cache.RemovalCause) GroupId(org.onosproject.core.GroupId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) Cache(com.google.common.cache.Cache) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) 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) OfdpaGroupHandlerUtility.l2MulticastGroupKey(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey) Instructions(org.onosproject.net.flow.instructions.Instructions) GroupBuckets(org.onosproject.net.group.GroupBuckets) Deque(java.util.Deque) ArrayDeque(java.util.ArrayDeque) ArrayDeque(java.util.ArrayDeque) GroupId(org.onosproject.core.GroupId) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) GroupInstruction(org.onosproject.net.flow.instructions.Instructions.GroupInstruction)

Example 17 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class LinkCollectionIntentFlowObjectiveCompiler method createBroadcastObjective.

private List<Objective> createBroadcastObjective(ForwardingInstructions instructions, Set<TrafficTreatment> treatmentsWithDifferentPort, LinkCollectionIntent intent) {
    List<Objective> objectives = Lists.newArrayList();
    ForwardingObjective forwardingObjective;
    NextObjective nextObjective;
    Integer nextId = flowObjectiveService.allocateNextId();
    forwardingObjective = buildForwardingObjective(instructions.selector(), nextId, intent.priority());
    DefaultNextObjective.Builder nxBuilder = DefaultNextObjective.builder();
    nxBuilder.withId(nextId).withMeta(instructions.selector()).withType(NextObjective.Type.BROADCAST).fromApp(appId).withPriority(intent.priority()).makePermanent();
    treatmentsWithDifferentPort.forEach(nxBuilder::addTreatment);
    nextObjective = nxBuilder.add();
    objectives.add(forwardingObjective);
    objectives.add(nextObjective);
    return objectives;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective)

Example 18 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class InOrderFlowObjectiveManager method execute.

/**
 * Submit the flow objective. Starting from this point on, the execution order is not guaranteed.
 * Therefore we must be certain that this method is called in-order.
 *
 * @param deviceId Device ID
 * @param obj Flow objective
 */
private void execute(DeviceId deviceId, Objective obj) {
    LogLevel logLevel = (obj.op() == Objective.Operation.VERIFY) ? LogLevel.TRACE : LogLevel.DEBUG;
    Tools.log(log, logLevel, "Submit objective installer, deviceId {}, obj {}", deviceId, obj);
    int priority = obj.priority();
    if (obj instanceof FilteringObjective) {
        FilteringObjQueueKey k = new FilteringObjQueueKey(deviceId, priority, ((FilteringObjective) obj).key());
        filtObjQueueHead.put(k, obj);
        super.filter(deviceId, (FilteringObjective) obj);
    } else if (obj instanceof ForwardingObjective) {
        ForwardingObjQueueKey k = new ForwardingObjQueueKey(deviceId, priority, ((ForwardingObjective) obj).selector());
        fwdObjQueueHead.put(k, obj);
        super.forward(deviceId, (ForwardingObjective) obj);
    } else if (obj instanceof NextObjective) {
        NextObjQueueKey k = new NextObjQueueKey(deviceId, obj.id());
        nextObjQueueHead.put(k, obj);
        super.next(deviceId, (NextObjective) obj);
    } else {
        log.error("Unknown flow objective instance: {}", obj.getClass().getName());
    }
}
Also used : NextObjective(org.onosproject.net.flowobjective.NextObjective) ForwardingObjQueueKey(org.onosproject.net.flowobjective.ForwardingObjQueueKey) FilteringObjQueueKey(org.onosproject.net.flowobjective.FilteringObjQueueKey) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) LogLevel(org.onlab.util.Tools.LogLevel) NextObjQueueKey(org.onosproject.net.flowobjective.NextObjQueueKey)

Example 19 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class InOrderFlowObjectiveManager method enqueue.

/**
 * Enqueue flow objective. Execute the flow objective if there is no pending objective ahead.
 *
 * @param deviceId Device ID
 * @param obj Flow objective
 */
private synchronized void enqueue(DeviceId deviceId, Objective obj) {
    int queueSize;
    int priority = obj.priority();
    LogLevel logLevel = (obj.op() == Objective.Operation.VERIFY) ? LogLevel.TRACE : LogLevel.DEBUG;
    Tools.log(log, logLevel, "Enqueue {}", obj);
    if (obj instanceof FilteringObjective) {
        FilteringObjQueueKey k = new FilteringObjQueueKey(deviceId, priority, ((FilteringObjective) obj).key());
        filtObjQueue.put(k, obj);
        queueSize = filtObjQueue.get(k).size();
    } else if (obj instanceof ForwardingObjective) {
        ForwardingObjQueueKey k = new ForwardingObjQueueKey(deviceId, priority, ((ForwardingObjective) obj).selector());
        fwdObjQueue.put(k, obj);
        queueSize = fwdObjQueue.get(k).size();
    } else if (obj instanceof NextObjective) {
        NextObjQueueKey k = new NextObjQueueKey(deviceId, obj.id());
        nextObjQueue.put(k, obj);
        queueSize = nextObjQueue.get(k).size();
    } else {
        log.error("Unknown flow objective instance: {}", obj.getClass().getName());
        return;
    }
    log.trace("{} queue size {}", obj.getClass().getSimpleName(), queueSize);
    // Execute immediately if there is no pending obj ahead
    if (queueSize == 1) {
        execute(deviceId, obj);
    }
}
Also used : NextObjective(org.onosproject.net.flowobjective.NextObjective) ForwardingObjQueueKey(org.onosproject.net.flowobjective.ForwardingObjQueueKey) FilteringObjQueueKey(org.onosproject.net.flowobjective.FilteringObjQueueKey) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) LogLevel(org.onlab.util.Tools.LogLevel) NextObjQueueKey(org.onosproject.net.flowobjective.NextObjQueueKey)

Example 20 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class FibInstallerTest method testRouteUpdate.

/**
 * Tests updating a route.
 *
 * We verify that the flowObjectiveService records the correct state and that the
 * correct flow is submitted to the flowObjectiveService.
 */
@Test
public void testRouteUpdate() {
    // Firstly add a route
    testRouteAdd();
    reset(flowObjectiveService);
    ResolvedRoute oldRoute = createRoute(PREFIX1, NEXT_HOP1, MAC1);
    ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP2, MAC2);
    // Create the next objective
    NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
    flowObjectiveService.next(DEVICE_ID, nextObjective);
    // Create the flow objective
    ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
    flowObjectiveService.forward(DEVICE_ID, fwd);
    EasyMock.expectLastCall().once();
    setUpFlowObjectiveService();
    // Send in the update event
    routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route, oldRoute));
    verify(flowObjectiveService);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) RouteEvent(org.onosproject.routeservice.RouteEvent) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Aggregations

NextObjective (org.onosproject.net.flowobjective.NextObjective)83 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)57 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)56 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)55 TrafficSelector (org.onosproject.net.flow.TrafficSelector)51 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)47 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)36 Objective (org.onosproject.net.flowobjective.Objective)31 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)30 DeviceId (org.onosproject.net.DeviceId)29 PortNumber (org.onosproject.net.PortNumber)24 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)24 DefaultObjectiveContext (org.onosproject.net.flowobjective.DefaultObjectiveContext)23 Set (java.util.Set)22 Test (org.junit.Test)22 List (java.util.List)21 Collectors (java.util.stream.Collectors)20 GroupBucket (org.onosproject.net.group.GroupBucket)19 GroupBuckets (org.onosproject.net.group.GroupBuckets)19 Lists (com.google.common.collect.Lists)18