use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class PathIntentFlowObjectiveCompiler method compile.
@Override
public List<Intent> compile(PathIntent intent, List<Intent> installable) {
List<Objective> objectives = new LinkedList<>();
List<DeviceId> devices = new LinkedList<>();
compile(this, intent, objectives, devices);
return ImmutableList.of(new FlowObjectiveIntent(appId, intent.key(), devices, objectives, intent.resources(), intent.resourceGroup()));
}
use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class InOrderFlowObjectiveManager method process.
/**
* Processes given objective on given device.
* Objectives submitted through this method are guaranteed to be executed in order.
*
* @param deviceId Device ID
* @param originalObjective Flow objective to be executed
*/
private void process(DeviceId deviceId, Objective originalObjective) {
// Inject ObjectiveContext such that we can get notified when it is completed
Objective.Builder objBuilder = originalObjective.copy();
Optional<ObjectiveContext> originalContext = originalObjective.context();
ObjectiveContext context = new InOrderObjectiveContext(deviceId, originalContext.orElse(null));
// Preserve Objective.Operation
Objective objective;
switch(originalObjective.op()) {
case ADD:
objective = objBuilder.add(context);
break;
case ADD_TO_EXISTING:
objective = ((NextObjective.Builder) objBuilder).addToExisting(context);
break;
case REMOVE:
objective = objBuilder.remove(context);
break;
case REMOVE_FROM_EXISTING:
objective = ((NextObjective.Builder) objBuilder).removeFromExisting(context);
break;
case MODIFY:
objective = ((NextObjective.Builder) objBuilder).modify(context);
break;
case VERIFY:
objective = ((NextObjective.Builder) objBuilder).verify(context);
break;
default:
log.error("Unknown flow objecitve operation {}", originalObjective.op());
return;
}
enqueue(deviceId, objective);
}
use of org.onosproject.net.flowobjective.Objective 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));
}
}
use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class FlowObjectiveIntentInstaller method buildObjectiveContexts.
/**
* Builds all objective contexts for a given flow objective Intent with given
* operation.
*
* @param intent the flow objective Intent
* @param direction the operation of this Intent
* @return all objective context of the Intent with given operation
*/
private Set<FlowObjectiveInstallationContext> buildObjectiveContexts(FlowObjectiveIntent intent, Direction direction) {
Objects.requireNonNull(intent);
Objects.requireNonNull(direction);
Set<FlowObjectiveInstallationContext> contexts = Sets.newHashSet();
int size = intent.objectives().size();
List<Objective> objectives = intent.objectives();
List<DeviceId> deviceIds = intent.devices();
if (direction == ADD) {
// The flow objective system will handle the installation order
for (int i = 0; i < size; i++) {
Objective objective = objectives.get(i);
DeviceId deviceId = deviceIds.get(i);
FlowObjectiveInstallationContext ctx = buildObjectiveContext(objective, deviceId, direction);
contexts.add(ctx);
}
return contexts;
} else {
// basic idea is to chain objective contexts
for (int i = 0; i < size; i++) {
Objective objective = intent.objectives().get(i);
DeviceId deviceId = intent.devices().get(i);
if (objective instanceof FilteringObjective) {
// don't need to care ordering of filtering objective
FlowObjectiveInstallationContext ctx = buildObjectiveContext(objective, deviceId, direction);
contexts.add(ctx);
} else if (objective instanceof NextObjective) {
// need to removed after forwarding objective
// nothing to do here
} else if (objective instanceof ForwardingObjective) {
// forwarding objective, also find next objective if
// exist
FlowObjectiveInstallationContext fwdCtx = buildObjectiveContext(objective, deviceId, direction);
ForwardingObjective fwd = (ForwardingObjective) objective;
NextObjective nxt = null;
Integer nextId = fwd.nextId();
if (nextId != null) {
for (int j = 0; j < size; j++) {
if (objectives.get(j).id() == nextId) {
nxt = (NextObjective) objectives.get(j);
break;
}
}
// if a next objective exists in the Intent
if (nxt != null) {
FlowObjectiveInstallationContext nxtCtx = buildObjectiveContext(nxt, deviceId, direction);
fwdCtx.nextContext(nxtCtx);
}
}
contexts.add(fwdCtx);
} else {
// possible here?
log.warn(UNSUPPORT_OBJ, objective);
}
}
}
return contexts;
}
use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class LinkCollectionIntentFlowObjectiveCompilerTest method testFilteredConnectPointForMp.
/**
* Multi point to single point intent with filtered connect point.
* Scenario is the follow:
*
* -1 of1 2-1 of2 2-1 of4 2-
* 3
* -1 of3 2---/
*/
@Test
public void testFilteredConnectPointForMp() {
Set<Link> testLinks = ImmutableSet.of(DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(), DefaultLink.builder().providerId(PID).src(of3p2).dst(of2p3).type(DIRECT).build(), DefaultLink.builder().providerId(PID).src(of2p2).dst(of4p1).type(DIRECT).build());
Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(of3p1, vlan100Selector), new FilteredConnectPoint(of1p1, vlan100Selector));
Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(of4p2, vlan100Selector));
LinkCollectionIntent intent = LinkCollectionIntent.builder().appId(appId).selector(ethDstSelector).treatment(treatment).links(testLinks).filteredIngressPoints(ingress).filteredEgressPoints(egress).build();
List<Intent> result = compiler.compile(intent, Collections.emptyList());
assertThat(result, hasSize(1));
assertThat(result.get(0), instanceOf(FlowObjectiveIntent.class));
FlowObjectiveIntent foIntent = (FlowObjectiveIntent) result.get(0);
List<Objective> objectives = foIntent.objectives();
assertThat(objectives, hasSize(15));
TrafficSelector expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_100).build();
TrafficTreatment expectTreatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(2)).build();
/*
* First set of objective
*/
filteringObjective = (FilteringObjective) objectives.get(0);
forwardingObjective = (ForwardingObjective) objectives.get(1);
nextObjective = (NextObjective) objectives.get(2);
PortCriterion inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
// test case for first filtering objective
checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.criteria());
// test case for first next objective
checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
// test case for first forwarding objective
checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
/*
* Second set of objective
*/
filteringObjective = (FilteringObjective) objectives.get(3);
forwardingObjective = (ForwardingObjective) objectives.get(4);
nextObjective = (NextObjective) objectives.get(5);
// test case for first filtering objective
checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.criteria());
// test case for first next objective
checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
// test case for first forwarding objective
checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
/*
* 3rd set of objective
*/
filteringObjective = (FilteringObjective) objectives.get(6);
forwardingObjective = (ForwardingObjective) objectives.get(7);
nextObjective = (NextObjective) objectives.get(8);
// test case for first filtering objective
checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.criteria());
// test case for first next objective
checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
// test case for first forwarding objective
checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
/*
* 4th set of objective
*/
filteringObjective = (FilteringObjective) objectives.get(9);
forwardingObjective = (ForwardingObjective) objectives.get(10);
nextObjective = (NextObjective) objectives.get(11);
// test case for first filtering objective
checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.criteria());
// test case for first next objective
checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
// test case for first forwarding objective
checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
/*
* 5th set of objective
*/
filteringObjective = (FilteringObjective) objectives.get(12);
forwardingObjective = (ForwardingObjective) objectives.get(13);
nextObjective = (NextObjective) objectives.get(14);
expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchVlanId(VLAN_100).matchInPort(PortNumber.portNumber(3)).build();
inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
// test case for first filtering objective
checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.criteria());
// test case for first next objective
checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
// test case for first forwarding objective
checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
}
Aggregations