Search in sources :

Example 1 with OfdpaPipelineUtility

use of org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility in project onos by opennetworkinglab.

the class Ofdpa2Pipeline method sendForwards.

// Builds the batch using the accumulated flow rules
private void sendForwards(List<Pair<ForwardingObjective, Collection<FlowRule>>> pairs) {
    FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder();
    log.debug("Sending {} fwd-objs", pairs.size());
    List<Objective> fwdObjs = Lists.newArrayList();
    // Iterates over all accumulated flow rules and then build an unique batch
    pairs.forEach(pair -> {
        ForwardingObjective fwd = pair.getLeft();
        Collection<FlowRule> rules = pair.getRight();
        switch(fwd.op()) {
            case ADD:
                rules.stream().filter(Objects::nonNull).forEach(flowOpsBuilder::add);
                log.debug("Applying a add fwd-obj {} to sw:{}", fwd.id(), deviceId);
                fwdObjs.add(fwd);
                break;
            case REMOVE:
                rules.stream().filter(Objects::nonNull).forEach(flowOpsBuilder::remove);
                log.debug("Deleting a flow rule to sw:{}", deviceId);
                fwdObjs.add(fwd);
                break;
            default:
                fail(fwd, ObjectiveError.UNKNOWN);
                log.warn("Unknown forwarding type {}", fwd.op());
        }
    });
    // Finally applies the operations
    flowRuleService.apply(flowOpsBuilder.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            log.trace("Flow rule operations onSuccess {}", ops);
            fwdObjs.forEach(OfdpaPipelineUtility::pass);
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            ObjectiveError error = ObjectiveError.FLOWINSTALLATIONFAILED;
            log.warn("Flow rule operations onError {}. Reason = {}", ops, error);
            fwdObjs.forEach(fwdObj -> fail(fwdObj, error));
        }
    }));
}
Also used : NextObjective(org.onosproject.net.flowobjective.NextObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Objective(org.onosproject.net.flowobjective.Objective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) OfdpaPipelineUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError)

Aggregations

OfdpaPipelineUtility (org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility)1 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)1 FlowRule (org.onosproject.net.flow.FlowRule)1 FlowRuleOperations (org.onosproject.net.flow.FlowRuleOperations)1 FlowRuleOperationsContext (org.onosproject.net.flow.FlowRuleOperationsContext)1 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)1 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)1 NextObjective (org.onosproject.net.flowobjective.NextObjective)1 Objective (org.onosproject.net.flowobjective.Objective)1 ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)1