Search in sources :

Example 1 with CPU_CLONE_SESSION_ID

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));
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) Pipeliner(org.onosproject.net.behaviour.Pipeliner) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) NextGroup(org.onosproject.net.behaviour.NextGroup) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) FlowRuleService(org.onosproject.net.flow.FlowRuleService) NextObjective(org.onosproject.net.flowobjective.NextObjective) Utils(org.onosproject.ngsdn.tutorial.common.Utils) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) GroupService(org.onosproject.net.group.GroupService) PiAction(org.onosproject.net.pi.runtime.PiAction) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) DeviceId(org.onosproject.net.DeviceId) CPU_CLONE_SESSION_ID(org.onosproject.ngsdn.tutorial.AppConstants.CPU_CLONE_SESSION_ID) GroupDescription(org.onosproject.net.group.GroupDescription) Collections(java.util.Collections) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) PiActionId(org.onosproject.net.pi.model.PiActionId) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiAction(org.onosproject.net.pi.runtime.PiAction)

Aggregations

Collections (java.util.Collections)1 List (java.util.List)1 DeviceId (org.onosproject.net.DeviceId)1 PortNumber (org.onosproject.net.PortNumber)1 NextGroup (org.onosproject.net.behaviour.NextGroup)1 Pipeliner (org.onosproject.net.behaviour.Pipeliner)1 PipelinerContext (org.onosproject.net.behaviour.PipelinerContext)1 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)1 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)1 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)1 FlowRule (org.onosproject.net.flow.FlowRule)1 FlowRuleService (org.onosproject.net.flow.FlowRuleService)1 OUTPUT (org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT)1 Instructions (org.onosproject.net.flow.instructions.Instructions)1 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)1 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)1 NextObjective (org.onosproject.net.flowobjective.NextObjective)1 ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)1 GroupDescription (org.onosproject.net.group.GroupDescription)1 GroupService (org.onosproject.net.group.GroupService)1