Improves openflow fr provider reducing the number of i/o ops
Change-Id: Ie5386c3b5f7475b4a4f821d1481b6d4a0db94f6d
diff --git a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/OpenFlowRuleProvider.java b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/OpenFlowRuleProvider.java
index f2419e0..07be6c9 100644
--- a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/OpenFlowRuleProvider.java
+++ b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/OpenFlowRuleProvider.java
@@ -396,10 +396,11 @@
return;
}
pendingBatches.put(batch.id(), new InternalCacheEntry(batch));
+ // Build a batch of flow mods - to reduce the number i/o asked to the SO
+ Set<OFFlowMod> mods = Sets.newHashSet();
OFFlowMod mod;
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
// flow is the third party privacy flow
-
FlowRuleExtPayLoad flowRuleExtPayLoad = fbe.target().payLoad();
if (hasPayload(flowRuleExtPayLoad)) {
OFMessage msg = new ThirdPartyMessage(flowRuleExtPayLoad.payLoad());
@@ -424,13 +425,17 @@
fbe.operator(), fbe);
continue;
}
- sw.sendMsg(mod);
+ mods.add(mod);
}
+ // Build a list to mantain the order
+ List<OFMessage> modsTosend = Lists.newArrayList(mods);
OFBarrierRequest.Builder builder = sw.factory().buildBarrierRequest()
.setXid(batch.id());
- sw.sendMsg(builder.build());
-
- recordEvents(dpid, batch.getOperations().size());
+ // Adds finally the barrier request
+ modsTosend.add(builder.build());
+ sw.sendMsg(modsTosend);
+ // Take into account also the barrier request
+ recordEvents(dpid, (batch.getOperations().size() + 1));
}
private boolean hasPayload(FlowRuleExtPayLoad flowRuleExtPayLoad) {