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