use of org.onosproject.net.flow.FlowRuleListener in project onos by opennetworkinglab.
the class FlowPerfApp method runTest.
private void runTest() {
pendingBatchCount = new AtomicInteger(totalFlows / batchSize);
installationLatch = new CountDownLatch(totalFlows);
List<Device> deviceList = Lists.newArrayList();
deviceService.getAvailableDevices().forEach(deviceList::add);
devices = Iterables.cycle(deviceList).iterator();
log.info("Starting installation. Total flows: {}, Total threads: {}, " + "Batch Size: {}", totalFlows, totalThreads, batchSize);
macIndex = new AtomicLong(0);
FlowRuleListener addMonitor = event -> {
if (event.type() == FlowRuleEvent.Type.RULE_ADDED) {
installationLatch.countDown();
}
};
flowRuleService.addListener(addMonitor);
long addStartTime = System.currentTimeMillis();
for (int i = 0; i < totalThreads; ++i) {
installer.submit(() -> {
while (pendingBatchCount.getAndDecrement() > 0) {
List<FlowRule> batch = nextBatch(batchSize);
addedRules.addAll(batch);
flowRuleService.applyFlowRules(batch.toArray(new FlowRule[] {}));
}
});
}
// Wait till all the flows are in ADDED state.
try {
installationLatch.await();
} catch (InterruptedException e) {
Thread.interrupted();
}
log.info("Time to install {} flows: {} ms", totalFlows, System.currentTimeMillis() - addStartTime);
flowRuleService.removeListener(addMonitor);
uninstallationLatch = new CountDownLatch(totalFlows);
FlowRuleListener removeListener = event -> {
if (event.type() == FlowRuleEvent.Type.RULE_REMOVED) {
uninstallationLatch.countDown();
}
};
AtomicInteger currentIndex = new AtomicInteger(0);
long removeStartTime = System.currentTimeMillis();
flowRuleService.addListener(removeListener);
// Uninstallation runs on a single thread.
installer.submit(() -> {
while (currentIndex.get() < addedRules.size()) {
List<FlowRule> removeBatch = addedRules.subList(currentIndex.get(), Math.min(currentIndex.get() + batchSize, addedRules.size()));
currentIndex.addAndGet(removeBatch.size());
flowRuleService.removeFlowRules(removeBatch.toArray(new FlowRule[] {}));
}
});
try {
uninstallationLatch.await();
} catch (InterruptedException e) {
Thread.interrupted();
}
log.info("Time to uninstall {} flows: {} ms", totalFlows, System.currentTimeMillis() - removeStartTime);
flowRuleService.removeListener(removeListener);
}
Aggregations