use of org.onosproject.ngsdn.tutorial.AppConstants.CPU_CLONE_SESSION_ID in project TFG by mattinelorza.
the class PipelinerImpl method forward.
@Override
public void forward(ForwardingObjective obj) {
if (obj.treatment() == null) {
obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED));
}
// Whether this objective specifies an OUTPUT:CONTROLLER instruction.
final boolean hasCloneToCpuAction = obj.treatment().allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (Instructions.OutputInstruction) i).anyMatch(i -> i.port().equals(PortNumber.CONTROLLER));
if (!hasCloneToCpuAction) {
// We support only objectives for clone to CPU behaviours (e.g. for
// host and link discovery)
obj.context().ifPresent(c -> c.onError(obj, ObjectiveError.UNSUPPORTED));
}
// Create an equivalent FlowRule with same selector and clone_to_cpu action.
final PiAction cloneToCpuAction = PiAction.builder().withId(PiActionId.of(CLONE_TO_CPU)).build();
final FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().forTable(PiTableId.of(ACL_TABLE)).forDevice(deviceId).withSelector(obj.selector()).fromApp(obj.appId()).withPriority(obj.priority()).withTreatment(DefaultTrafficTreatment.builder().piTableAction(cloneToCpuAction).build());
if (obj.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(obj.timeout());
}
final GroupDescription cloneGroup = Utils.buildCloneGroup(obj.appId(), deviceId, CPU_CLONE_SESSION_ID, // Just controller in this case.
Collections.singleton(PortNumber.CONTROLLER));
switch(obj.op()) {
case ADD:
flowRuleService.applyFlowRules(ruleBuilder.build());
groupService.addGroup(cloneGroup);
break;
case REMOVE:
flowRuleService.removeFlowRules(ruleBuilder.build());
// pointing to it.
break;
default:
log.warn("Unknown operation {}", obj.op());
}
obj.context().ifPresent(c -> c.onSuccess(obj));
}
Aggregations