<version>0.18.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
+
<artifactId>drop-test-karaf</artifactId>
<packaging>bundle</packaging>
- <scm>
- <connection>scm:git:ssh://git.opendaylight.org:29418/openflowplugin.git</connection>
- <developerConnection>scm:git:ssh://git.opendaylight.org:29418/openflowplugin.git</developerConnection>
- </scm>
+
<dependencies>
<dependency>
- <groupId>org.opendaylight.openflowplugin</groupId>
- <artifactId>test-common</artifactId>
+ <groupId>com.guicedee.services</groupId>
+ <artifactId>javax.inject</artifactId>
+ <optional>true</optional>
</dependency>
<dependency>
- <groupId>org.opendaylight.mdsal</groupId>
- <artifactId>mdsal-binding-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.openflowplugin.model</groupId>
- <artifactId>model-flow-service</artifactId>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>test-common</artifactId>
</dependency>
+
+ <!-- FIXME: migrate karaf commands and adjust these two dependencies -->
<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.console</artifactId>
</dependency>
</dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- </plugin>
- </plugins>
- </build>
+ <scm>
+ <connection>scm:git:ssh://git.opendaylight.org:29418/openflowplugin.git</connection>
+ <developerConnection>scm:git:ssh://git.opendaylight.org:29418/openflowplugin.git</developerConnection>
+ </scm>
</project>
*/
package org.opendaylight.openflowplugin.droptestkaraf;
-import java.io.PrintStream;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.opendaylight.openflowplugin.testcommon.DropTestDsProvider;
-import org.opendaylight.openflowplugin.testcommon.DropTestRpcProvider;
+import org.opendaylight.openflowplugin.testcommon.DropTestCommiter;
+import org.opendaylight.openflowplugin.testcommon.DropTestRpcSender;
@Command(scope = "drop-test", name = "clearDropStats", description = "Clear drop statistics.")
public class ClearDropStatsCommandProvider extends OsgiCommandSupport {
+ @Reference
+ DropTestRpcSender rpcProvider;
+ @Reference
+ DropTestCommiter dsProvider;
@Override
protected Object doExecute() {
- PrintStream out = session.getConsole();
- final DropTestRpcProvider rpcProvider = DropTestProviderImpl.getDropRpcProvider();
- final DropTestDsProvider provider = DropTestProviderImpl.getDropDsProvider();
-
+ final var out = session.getConsole();
out.println("Clearing drop statistics... ");
rpcProvider.clearStats();
- provider.clearStats();
+ dsProvider.clearStats();
out.println("Done.");
-
return null;
}
-
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.droptestkaraf;
-import java.io.PrintStream;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.opendaylight.openflowplugin.testcommon.DropTestDsProvider;
+import org.opendaylight.openflowplugin.testcommon.DropTestCommiter;
@Command(scope = "drop-test", name = "dropAllPackets",
description = "drop packet responder involving dataStore and FRM")
public class DropAllPacketsCommandProvider extends OsgiCommandSupport {
+ @Reference
+ DropTestCommiter provider;
@Argument(index = 0, name = "on-off",
description = "target state of drop responder",
required = true, multiValued = false)
String targetStateArg;
-
@Override
protected Object doExecute() {
- PrintStream out = session.getConsole();
- final DropTestDsProvider provider = DropTestProviderImpl.getDropDsProvider();
+ final var out = session.getConsole();
if ("on".equalsIgnoreCase(targetStateArg)) {
- if (! provider.isActive()) {
- provider.start();
+ if (provider.start()) {
out.println("DropAllFlows transitions to on");
} else {
out.println("DropAllFlows is already on");
}
} else if ("off".equalsIgnoreCase(targetStateArg)) {
- if (provider.isActive()) {
- provider.close();
+ if (provider.stop()) {
out.println("DropAllFlows transitions to off");
} else {
out.println("DropAllFlows is already off");
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.droptestkaraf;
import java.io.PrintStream;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.opendaylight.openflowplugin.testcommon.DropTestRpcProvider;
+import org.opendaylight.openflowplugin.testcommon.DropTestRpcSender;
@Command(scope = "drop-test", name = "dropAllPacketsRpc",
description = "drop packet responder involving SalFlowService")
public class DropAllPacketsRpcCommandProvider extends OsgiCommandSupport {
+ @Reference
+ DropTestRpcSender provider;
@Argument(index = 0, name = "on-off",
description = "target state of drop responder",
@Override
protected Object doExecute() {
PrintStream out = session.getConsole();
- final DropTestRpcProvider provider = DropTestProviderImpl.getDropRpcProvider();
-
if ("on".equalsIgnoreCase(targetStateArg)) {
- if (! provider.isActive()) {
- provider.start();
+ if (provider.start()) {
out.println("DropAllFlows transitions to on");
} else {
out.println("DropAllFlows is already on");
}
} else if ("off".equalsIgnoreCase(targetStateArg)) {
- if (provider.isActive()) {
- provider.close();
+ if (provider.stop()) {
out.println("DropAllFlows transitions to off");
} else {
out.println("DropAllFlows is already off");
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.droptestkaraf;
-
-import static java.util.Objects.requireNonNull;
-
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.NotificationService;
-import org.opendaylight.openflowplugin.testcommon.DropTestDsProvider;
-import org.opendaylight.openflowplugin.testcommon.DropTestRpcProvider;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Created by Martin Bobak <mbobak@cisco.com> on 26.4.2015.
- */
-public class DropTestProviderImpl implements AutoCloseable {
-
- private static final Logger LOG = LoggerFactory.getLogger(DropTestProviderImpl.class);
-
- private static DropTestDsProvider dropDsProvider = new DropTestDsProvider();
-
- private static DropTestRpcProvider dropRpcProvider = new DropTestRpcProvider();
-
- public DropTestProviderImpl(final DataBroker dataBroker,
- final NotificationService notificationService,
- final SalFlowService salFlowService) {
- requireNonNull(dataBroker, "Data broker can't be empty");
- requireNonNull(notificationService, "NotificationProviderService can't be empty");
- requireNonNull(salFlowService, "SalFlowService can't be empty");
-
- LOG.debug("Activator DropAllPack INIT");
-
- dropDsProvider.setDataService(dataBroker);
- dropDsProvider.setNotificationService(notificationService);
-
- dropRpcProvider.setNotificationService(notificationService);
- dropRpcProvider.setFlowService(salFlowService);
-
- LOG.debug("Activator DropAllPack END");
- }
-
- public static DropTestDsProvider getDropDsProvider() {
- return dropDsProvider;
- }
-
- public static DropTestRpcProvider getDropRpcProvider() {
- return dropRpcProvider;
- }
-
- @Override
- public void close() {
- dropDsProvider.close();
- dropRpcProvider.close();
- }
-}
*/
package org.opendaylight.openflowplugin.droptestkaraf;
-import java.io.PrintStream;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.opendaylight.openflowplugin.testcommon.DropTestDsProvider;
-import org.opendaylight.openflowplugin.testcommon.DropTestRpcProvider;
+import org.opendaylight.openflowplugin.testcommon.DropTestCommiter;
+import org.opendaylight.openflowplugin.testcommon.DropTestRpcSender;
@Command(scope = "drop-test", name = "showDropStats", description = "Show drop statistics.")
public class ShowDropStatsCommandProvider extends OsgiCommandSupport {
+ @Reference
+ DropTestRpcSender rpcProvider;
+ @Reference
+ DropTestCommiter dsProvider;
@Override
protected Object doExecute() {
- PrintStream out = session.getConsole();
- final DropTestRpcProvider rpcProvider = DropTestProviderImpl.getDropRpcProvider();
- final DropTestDsProvider provider = DropTestProviderImpl.getDropDsProvider();
-
+ var out = session.getConsole();
out.format("RPC Test Statistics: %s%n", rpcProvider.getStats().toString());
- out.format("FRM Test Statistics: %s%n", provider.getStats().toString());
-
+ out.format("FRM Test Statistics: %s%n", dsProvider.getStats().toString());
return null;
}
-
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
- odl:use-default-for-reference-types="true">
-
- <reference id="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
- <reference id="notificationService" interface="org.opendaylight.mdsal.binding.api.NotificationService"/>
-
- <odl:rpc-service id="flowService"
- interface="org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService"/>
-
- <bean id="dropTestProvider" class="org.opendaylight.openflowplugin.droptestkaraf.DropTestProviderImpl">
- <argument ref="dataBroker"/>
- <argument ref="notificationService"/>
- <argument ref="flowService"/>
- </bean>
-</blueprint>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.guicedee.services</groupId>
+ <artifactId>javax.inject</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <optional>true</optional>
+ </dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>mdsal-binding-api</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.openflowplugin.model</groupId>
- <artifactId>model-flow-service</artifactId>
+ <artifactId>model-flow-base</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.openflowplugin.model</groupId>
- <artifactId>model-flow-base</artifactId>
+ <artifactId>model-inventory</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.openflowplugin.model</groupId>
- <artifactId>model-inventory</artifactId>
+ <artifactId>model-flow-service</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.openflowplugin</groupId>
- <artifactId>openflowplugin-common</artifactId>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component.annotations</artifactId>
</dependency>
</dependencies>
*/
package org.opendaylight.openflowplugin.testcommon;
+import static java.util.Objects.requireNonNull;
+
import java.util.concurrent.atomic.AtomicLong;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.NotificationService;
-import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.Uint64;
import org.opendaylight.yangtools.yang.common.Uint8;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Provides cbench responder behavior: upon packetIn arrival addFlow action is sent out to
- * device using dataStore strategy (FRM involved).
+ * Provides cbench responder behavior: upon packetIn arrival addFlow action is sent out to device using dataStore
+ * strategy (FRM involved).
*/
-public class DropTestCommiter extends AbstractDropTest {
+@Singleton
+@Component(service = DropTestCommiter.class, immediate = true)
+public final class DropTestCommiter extends AbstractDropTest {
private static final Logger LOG = LoggerFactory.getLogger(DropTestCommiter.class);
private static final TableKey ZERO_TABLE = new TableKey(Uint8.ZERO);
- private static final AtomicLong ID_COUNTER = new AtomicLong();
private static final ThreadLocal<FlowBuilder> BUILDER = ThreadLocal.withInitial(() -> {
final var cookie = new FlowCookie(Uint64.TEN);
return new FlowBuilder()
.setFlags(new FlowModFlags(false, false, false, false, false));
});
- private NotificationService notificationService = null;
- private Registration notificationRegistration = null;
- private DataBroker dataService = null;
+ private final AtomicLong idCounter = new AtomicLong();
+ private final DataBroker dataBroker;
+ private final NotificationService notificationService;
+
+ private Registration reg = null;
+
+ @Inject
+ @Activate
+ public DropTestCommiter(@Reference final DataBroker dataBroker,
+ @Reference final NotificationService notificationService) {
+ this.dataBroker = requireNonNull(dataBroker);
+ this.notificationService = requireNonNull(notificationService);
+ }
+
+ @PreDestroy
+ @Deactivate
+ @Override
+ public void close() {
+ stop();
+ super.close();
+ LOG.debug("DropTestProvider terminated");
+ }
/**
- * start listening on packetIn.
+ * Start listening on packetIn.
+ *
+ * @return {@code false} if already started
*/
- public void start() {
- notificationRegistration = notificationService.registerListener(PacketReceived.class, this);
+ public synchronized boolean start() {
+ if (reg != null) {
+ return false;
+ }
+ reg = notificationService.registerListener(PacketReceived.class, this);
+ LOG.debug("DropTestProvider started");
+ return true;
}
- public void setDataService(final DataBroker dataService) {
- this.dataService = dataService;
+ /**
+ * Stop listening on packetIn.
+ *
+ * @return {@code false} if already stopped
+ */
+ public synchronized boolean stop() {
+ if (reg == null) {
+ return false;
+ }
+ reg.close();
+ reg = null;
+ LOG.debug("DropTestProvider stopped");
+ return true;
}
@Override
final FlowBuilder fb = BUILDER.get();
fb.setMatch(match);
fb.setInstructions(instructions);
- fb.setId(new FlowId(String.valueOf(fb.hashCode()) + "." + ID_COUNTER.getAndIncrement()));
+ fb.setId(new FlowId(String.valueOf(fb.hashCode()) + "." + idCounter.getAndIncrement()));
// Construct the flow instance id
- final InstanceIdentifier<Flow> flowInstanceId = node.builder()
+ final var flowInstanceId = node.builder()
// That is flow capable, only FlowCapableNodes have tables
.augmentation(FlowCapableNode.class)
// In the table identified by TableKey
.child(Flow.class, new FlowKey(fb.getId()))
.build();
- final Flow flow = fb.build();
- final ReadWriteTransaction transaction = dataService.newReadWriteTransaction();
+ final var flow = fb.build();
+ final var transaction = dataBroker.newReadWriteTransaction();
- if (LOG.isDebugEnabled()) {
- LOG.debug("onPacketReceived - About to write flow {}", flow);
- }
+ LOG.debug("onPacketReceived - About to write flow {}", flow);
transaction.mergeParentStructurePut(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow);
transaction.commit();
LOG.debug("onPacketReceived - About to write flow commited");
}
-
- @Override
- public void close() {
- super.close();
- LOG.debug("DropTestProvider stopped.");
- if (notificationRegistration != null) {
- notificationRegistration.close();
- }
- }
-
- public void setNotificationService(final NotificationService notificationService) {
- this.notificationService = notificationService;
- }
}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.testcommon;
-
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.NotificationService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Provides activation and deactivation of drop responder service - responds on packetIn.
- */
-public class DropTestDsProvider implements AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(DropTestDsProvider.class);
-
- private DataBroker dataService;
- private NotificationService notificationService;
- private final DropTestCommiter commiter = new DropTestCommiter();
- private boolean active = false;
-
- /**
- * Returns the message counts.
- */
- public DropTestStats getStats() {
- return commiter.getStats();
- }
-
- /**
- * Reset message counts.
- */
- public void clearStats() {
- commiter.clearStats();
- }
-
- public void setDataService(final DataBroker dataService) {
- this.dataService = dataService;
- }
-
- public void setNotificationService(final NotificationService notificationService) {
- this.notificationService = notificationService;
- }
-
- /**
- * Activates the drop responder.
- */
- public void start() {
- commiter.setDataService(dataService);
- commiter.setNotificationService(notificationService);
- commiter.start();
- active = true;
- LOG.debug("DropTestProvider Started.");
- }
-
- @Override
- public void close() {
- LOG.debug("DropTestProvider stopped.");
- if (commiter != null) {
- commiter.close();
- active = false;
- }
- }
-
- /**
- * Returns the active state.
- */
- public boolean isActive() {
- return active;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.testcommon;
-
-import org.opendaylight.mdsal.binding.api.NotificationService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Provides activation and deactivation of drop responder service - responds on packetIn.
- */
-public class DropTestRpcProvider implements AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(DropTestRpcProvider.class);
-
- private SalFlowService flowService;
- private NotificationService notificationService;
- private final DropTestRpcSender commiter = new DropTestRpcSender();
- private boolean active = false;
-
- public void setFlowService(final SalFlowService flowService) {
- this.flowService = flowService;
- }
-
- public void setNotificationService(final NotificationService notificationService) {
- this.notificationService = notificationService;
- }
-
- /**
- * Activates drop responder.
- */
- public void start() {
- commiter.setFlowService(flowService);
- commiter.setNotificationService(notificationService);
- commiter.start();
- active = true;
- LOG.debug("DropTestProvider Started.");
- }
-
- /**
- * Returns the message counts.
- */
- public DropTestStats getStats() {
- if (this.commiter != null) {
- return commiter.getStats();
- } else {
- return new DropTestStats("Not initialized yet.");
- }
- }
-
- /**
- * Reset message counts.
- */
- public void clearStats() {
- if (commiter != null) {
- commiter.clearStats();
- }
- }
-
- @Override
- public void close() {
- LOG.debug("DropTestProvider stopped.");
- if (commiter != null) {
- commiter.close();
- active = false;
- }
- }
-
- /**
- * Returns the active state.
- */
- public boolean isActive() {
- return active;
- }
-}
*/
package org.opendaylight.openflowplugin.testcommon;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import org.opendaylight.mdsal.binding.api.NotificationService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
+import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.Uint64;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* Provides cbench responder behavior: upon packetIn arrival addFlow action is sent out to
* device using {@link SalFlowService} strategy.
*/
-public class DropTestRpcSender extends AbstractDropTest {
+@Singleton
+@Component(service = DropTestRpcSender.class, immediate = true)
+public final class DropTestRpcSender extends AbstractDropTest {
private static final Logger LOG = LoggerFactory.getLogger(DropTestRpcSender.class);
private static final ThreadLocal<AddFlowInputBuilder> BUILDER = ThreadLocal.withInitial(() -> {
final var cookie = new FlowCookie(Uint64.TEN);
.setFlags(new FlowModFlags(false, false, false, false, false));
});
- private NotificationService notificationService = null;
- private Registration notificationRegistration = null;
- private SalFlowService flowService = null;
+ private final NotificationService notificationService;
+ private final AddFlow addFlow;
+
+ private Registration reg = null;
- public void setFlowService(final SalFlowService flowService) {
- this.flowService = flowService;
+ @Inject
+ @Activate
+ public DropTestRpcSender(@Reference final NotificationService notificationService,
+ @Reference final RpcConsumerRegistry rpcService) {
+ this.notificationService = requireNonNull(notificationService);
+ addFlow = rpcService.getRpc(AddFlow.class);
+ }
+
+ @PreDestroy
+ @Deactivate
+ @Override
+ public void close() {
+ stop();
+ super.close();
+ LOG.debug("DropTestProvider terminated");
}
- /**
- * Start listening on packetIn.
- */
- public void start() {
- notificationRegistration = notificationService.registerListener(PacketReceived.class, this);
+ public synchronized boolean start() {
+ if (reg != null) {
+ return false;
+ }
+ reg = notificationService.registerListener(PacketReceived.class, this);
+ LOG.debug("DropTestProvider started");
+ return true;
+ }
+
+ public synchronized boolean stop() {
+ if (reg == null) {
+ return false;
+ }
+ reg.close();
+ reg = null;
+ LOG.debug("DropTestProvider stopped");
+ return true;
}
@Override
fb.setNode(new NodeRef(node));
// Add flow
- final AddFlowInput flow = fb.build();
+ final var flow = fb.build();
LOG.debug("onPacketReceived - About to write flow (via SalFlowService) {}", flow);
- ListenableFuture<RpcResult<AddFlowOutput>> result = flowService.addFlow(flow);
- Futures.addCallback(result, new FutureCallback<RpcResult<AddFlowOutput>>() {
+ Futures.addCallback(addFlow.invoke(flow), new FutureCallback<RpcResult<AddFlowOutput>>() {
@Override
public void onSuccess(final RpcResult<AddFlowOutput> result) {
countFutureSuccess();
}
}, MoreExecutors.directExecutor());
}
-
- public void setNotificationService(final NotificationService notificationService) {
- this.notificationService = notificationService;
- }
-
- @Override
- public void close() {
- super.close();
- LOG.debug("DropTestProvider stopped.");
- if (notificationRegistration != null) {
- notificationRegistration.close();
- }
- }
}