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);
}
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;
}
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());
}
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));
}
}
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));
}
}
Aggregations