Search in sources :

Example 1 with FlowRuleListener

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);
}
Also used : Iterables(com.google.common.collect.Iterables) Tools(org.onlab.util.Tools) TOTAL_FLOWS_DEFAULT(org.onosproject.flowperf.OsgiPropertyConstants.TOTAL_FLOWS_DEFAULT) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent) ComponentContext(org.osgi.service.component.ComponentContext) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ApplicationId(org.onosproject.core.ApplicationId) MANDATORY(org.osgi.service.component.annotations.ReferenceCardinality.MANDATORY) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowRuleListener(org.onosproject.net.flow.FlowRuleListener) ExecutorService(java.util.concurrent.ExecutorService) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) Tools.get(org.onlab.util.Tools.get) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) TOTAL_FLOWS(org.onosproject.flowperf.OsgiPropertyConstants.TOTAL_FLOWS) TOTAL_THREADS(org.onosproject.flowperf.OsgiPropertyConstants.TOTAL_THREADS) Executors(java.util.concurrent.Executors) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) BATCH_SIZE_DEFAULT(org.onosproject.flowperf.OsgiPropertyConstants.BATCH_SIZE_DEFAULT) FlowRule(org.onosproject.net.flow.FlowRule) BATCH_SIZE(org.onosproject.flowperf.OsgiPropertyConstants.BATCH_SIZE) TOTAL_THREADS_DEFAULT(org.onosproject.flowperf.OsgiPropertyConstants.TOTAL_THREADS_DEFAULT) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) Dictionary(java.util.Dictionary) Device(org.onosproject.net.Device) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FlowRuleListener(org.onosproject.net.flow.FlowRuleListener) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule)

Aggregations

Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Dictionary (java.util.Dictionary)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 MacAddress (org.onlab.packet.MacAddress)1 Tools (org.onlab.util.Tools)1 Tools.get (org.onlab.util.Tools.get)1 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)1 ApplicationId (org.onosproject.core.ApplicationId)1 CoreService (org.onosproject.core.CoreService)1 BATCH_SIZE (org.onosproject.flowperf.OsgiPropertyConstants.BATCH_SIZE)1 BATCH_SIZE_DEFAULT (org.onosproject.flowperf.OsgiPropertyConstants.BATCH_SIZE_DEFAULT)1 TOTAL_FLOWS (org.onosproject.flowperf.OsgiPropertyConstants.TOTAL_FLOWS)1