Search in sources :

Example 46 with NextObjective

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

the class NextObjectiveTranslatorTest method testRouteAndPushNextObjective.

/**
 * Test Route and Push Next Objective (set mac, set double vlan and output port).
 */
@Test
public void testRouteAndPushNextObjective() throws FabricPipelinerException {
    TrafficTreatment routeAndPushTreatment = DefaultTrafficTreatment.builder().setEthSrc(ROUTER_MAC).setEthDst(HOST_MAC).setOutput(PORT_1).setVlanId(VLAN_100).pushVlan().setVlanId(VLAN_200).build();
    NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).addTreatment(routeAndPushTreatment).withType(NextObjective.Type.SIMPLE).makePermanent().fromApp(APP_ID).add();
    ObjectiveTranslation actualTranslation = translatorSimple.translate(nextObjective);
    PiAction piActionRouting = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_SIMPLE).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, HOST_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong())).build();
    PiAction piActionPush = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_DOUBLE_VLAN).withParameter(new PiActionParam(FabricConstants.INNER_VLAN_ID, VLAN_100.toShort())).withParameter(new PiActionParam(FabricConstants.OUTER_VLAN_ID, VLAN_200.toShort())).build();
    TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build()).build();
    FlowRule expectedFlowRuleRouting = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(0).forTable(FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE).withSelector(nextIdSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piActionRouting).build()).build();
    FlowRule expectedFlowRuleDoublePush = DefaultFlowRule.builder().withSelector(nextIdSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piActionPush).build()).forTable(FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN).makePermanent().withPriority(0).forDevice(DEVICE_ID).fromApp(APP_ID).build();
    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedFlowRuleDoublePush).addFlowRule(expectedFlowRuleRouting).build();
    assertEquals(expectedTranslation, actualTranslation);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) 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) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Example 47 with NextObjective

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

the class LinkCollectionIntentFlowObjectiveCompiler method createSimpleNextObjective.

private List<Objective> createSimpleNextObjective(ForwardingInstructions instructions, 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();
    nextObjective = nxBuilder.withId(nextId).withMeta(instructions.selector()).addTreatment(instructions.treatment()).withType(NextObjective.Type.SIMPLE).fromApp(appId).makePermanent().withPriority(intent.priority()).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 48 with NextObjective

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

the class PathIntentFlowObjectiveCompiler method createFlow.

@Override
public void createFlow(TrafficSelector originalSelector, TrafficTreatment originalTreatment, ConnectPoint ingress, ConnectPoint egress, int priority, boolean applyTreatment, List<Objective> objectives, List<DeviceId> devices) {
    TrafficSelector selector = DefaultTrafficSelector.builder(originalSelector).matchInPort(ingress.port()).build();
    TrafficTreatment.Builder treatmentBuilder;
    if (applyTreatment) {
        treatmentBuilder = DefaultTrafficTreatment.builder(originalTreatment);
    } else {
        treatmentBuilder = DefaultTrafficTreatment.builder();
    }
    TrafficTreatment treatment = treatmentBuilder.setOutput(egress.port()).build();
    NextObjective nextObjective = DefaultNextObjective.builder().withId(flowObjectiveService.allocateNextId()).addTreatment(treatment).withType(NextObjective.Type.SIMPLE).fromApp(appId).makePermanent().add();
    objectives.add(nextObjective);
    devices.add(ingress.deviceId());
    objectives.add(DefaultForwardingObjective.builder().withSelector(selector).nextStep(nextObjective.id()).withPriority(priority).fromApp(appId).makePermanent().withFlag(ForwardingObjective.Flag.SPECIFIC).add());
    devices.add(ingress.deviceId());
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 49 with NextObjective

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

the class InOrderFlowObjectiveManager method dequeue.

/**
 * Dequeue flow objective. Execute the next flow objective in the queue, if any.
 *
 * @param deviceId Device ID
 * @param obj Flow objective
 * @param error ObjectiveError that triggers this dequeue. Null if this is not triggered by an error.
 */
private synchronized void dequeue(DeviceId deviceId, Objective obj, ObjectiveError error) {
    List<Objective> remaining;
    int priority = obj.priority();
    LogLevel logLevel = (obj.op() == Objective.Operation.VERIFY) ? LogLevel.TRACE : LogLevel.DEBUG;
    Tools.log(log, logLevel, "Dequeue {}", obj);
    if (obj instanceof FilteringObjective) {
        FilteringObjQueueKey k = new FilteringObjQueueKey(deviceId, priority, ((FilteringObjective) obj).key());
        if (!Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
            filtObjQueueHead.invalidate(k);
        }
        filtObjQueue.remove(k, obj);
        remaining = filtObjQueue.get(k);
    } else if (obj instanceof ForwardingObjective) {
        ForwardingObjQueueKey k = new ForwardingObjQueueKey(deviceId, priority, ((ForwardingObjective) obj).selector());
        if (!Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
            fwdObjQueueHead.invalidate(k);
        }
        fwdObjQueue.remove(k, obj);
        remaining = fwdObjQueue.get(k);
    } else if (obj instanceof NextObjective) {
        if (error != null) {
            // Remove pendingForwards and pendingNexts if next objective failed
            Set<PendingFlowObjective> removedForwards = pendingForwards.remove(obj.id());
            List<PendingFlowObjective> removedNexts = pendingNexts.remove(obj.id());
            if (removedForwards != null) {
                removedForwards.stream().map(PendingFlowObjective::flowObjective).forEach(pendingObj -> pendingObj.context().ifPresent(c -> c.onError(pendingObj, error)));
            }
            if (removedNexts != null) {
                removedNexts.stream().map(PendingFlowObjective::flowObjective).forEach(pendingObj -> pendingObj.context().ifPresent(c -> c.onError(pendingObj, error)));
            }
        }
        NextObjQueueKey k = new NextObjQueueKey(deviceId, obj.id());
        if (!Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
            nextObjQueueHead.invalidate(k);
        }
        nextObjQueue.remove(k, obj);
        remaining = nextObjQueue.get(k);
    } else {
        log.error("Unknown flow objective instance: {}", obj.getClass().getName());
        return;
    }
    log.trace("{} queue size {}", obj.getClass().getSimpleName(), remaining.size());
    // Submit the next one in the queue, if any
    if (remaining.size() > 0) {
        execute(deviceId, remaining.get(0));
    }
}
Also used : NextObjective(org.onosproject.net.flowobjective.NextObjective) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ObjectiveEvent(org.onosproject.net.flowobjective.ObjectiveEvent) ListMultimap(com.google.common.collect.ListMultimap) Tools(org.onlab.util.Tools) IFOM_OBJ_TIMEOUT_MS_DEFAULT(org.onosproject.net.OsgiPropertyConstants.IFOM_OBJ_TIMEOUT_MS_DEFAULT) NextObjQueueKey(org.onosproject.net.flowobjective.NextObjQueueKey) ComponentContext(org.osgi.service.component.ComponentContext) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Multimaps(com.google.common.collect.Multimaps) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Component(org.osgi.service.component.annotations.Component) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) ObjectiveQueueKey(org.onosproject.net.flowobjective.ObjectiveQueueKey) Map(java.util.Map) NextObjective(org.onosproject.net.flowobjective.NextObjective) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) ForwardingObjQueueKey(org.onosproject.net.flowobjective.ForwardingObjQueueKey) LogLevel(org.onlab.util.Tools.LogLevel) ExecutorService(java.util.concurrent.ExecutorService) FlowObjectiveStoreDelegate(org.onosproject.net.flowobjective.FlowObjectiveStoreDelegate) Logger(org.slf4j.Logger) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Deactivate(org.osgi.service.component.annotations.Deactivate) IFOM_OBJ_TIMEOUT_MS(org.onosproject.net.OsgiPropertyConstants.IFOM_OBJ_TIMEOUT_MS) Set(java.util.Set) FilteringObjQueueKey(org.onosproject.net.flowobjective.FilteringObjQueueKey) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) RemovalListeners(com.google.common.cache.RemovalListeners) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Objective(org.onosproject.net.flowobjective.Objective) Optional(java.util.Optional) RemovalListener(com.google.common.cache.RemovalListener) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) DeviceId(org.onosproject.net.DeviceId) ForwardingObjQueueKey(org.onosproject.net.flowobjective.ForwardingObjQueueKey) FilteringObjQueueKey(org.onosproject.net.flowobjective.FilteringObjQueueKey) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) LogLevel(org.onlab.util.Tools.LogLevel) NextObjQueueKey(org.onosproject.net.flowobjective.NextObjQueueKey) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Objective(org.onosproject.net.flowobjective.Objective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Example 50 with NextObjective

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

the class FlowObjectiveCompositionManager method next.

@Override
public void next(DeviceId deviceId, NextObjective nextObjective) {
    checkPermission(FLOWRULE_WRITE);
    List<NextObjective> nextObjectives = this.deviceCompositionTreeMap.get(deviceId).updateNext(nextObjective);
    for (NextObjective tmp : nextObjectives) {
        executorService.execute(new ObjectiveInstaller(deviceId, tmp));
    }
}
Also used : NextObjective(org.onosproject.net.flowobjective.NextObjective)

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