* @author michal.polkorab
*/
@Component(service = SwitchConnectionProvider.class, factory = SwitchConnectionProviderImpl.FACTORY_NAME)
-public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, ConnectionInitializer {
+public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, ConnectionInitializer, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(SwitchConnectionProviderImpl.class);
private static final String THREAD_NAME_PREFIX = "OFP-SwitchConnectionProvider-Udp/TcpHandler";
"org.opendaylight.openflowjava.protocol.impl.core.SwitchConnectionProviderImpl";
public static final String PROP_CONFIG = ".config";
- private SwitchConnectionHandler switchConnectionHandler;
- private ServerFacade serverFacade;
private final ConnectionConfiguration connConfig;
private final SerializationFactory serializationFactory;
private final SerializerRegistry serializerRegistry;
private final String threadName;
private TcpConnectionInitializer connectionInitializer;
+ private ServerFacade serverFacade;
// FIXME: clean this up when no longer needed
private final ServiceRegistration diagReg;
this(diagStatus, new ConnectionConfigurationImpl((SwitchConnectionConfig) props.get(PROP_CONFIG)));
}
+ @Override
@Deactivate
- void deactivate() {
+ public void close() {
+ shutdown();
diagReg.close();
}
return config == null ? "-null-config" : "_" + config.getPort();
}
- @Override
- public void setSwitchConnectionHandler(final SwitchConnectionHandler switchConnectionHandler) {
- LOG.debug("setSwitchConnectionHandler");
- this.switchConnectionHandler = switchConnectionHandler;
- }
-
@Override
public ListenableFuture<Boolean> shutdown() {
LOG.debug("Shutdown summoned");
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
- public ListenableFuture<Void> startup() {
+ public ListenableFuture<Void> startup(final SwitchConnectionHandler connectionHandler) {
LOG.debug("Startup summoned");
+ if (connConfig == null) {
+ return Futures.immediateFailedFuture(new IllegalStateException("Connection not configured"));
+ }
+ if (connectionHandler == null) {
+ return Futures.immediateFailedFuture(new IllegalStateException("SwitchConnectionHandler is not set"));
+ }
+
try {
- serverFacade = createAndConfigureServer();
- if (switchConnectionHandler == null) {
- throw new IllegalStateException("SwitchConnectionHandler is not set");
- }
+ serverFacade = createAndConfigureServer(connectionHandler);
Futures.addCallback(listeningExecutorService.submit(serverFacade), new FutureCallback<Object>() {
@Override
public void onFailure(final Throwable throwable) {
}
}
- private ServerFacade createAndConfigureServer() {
+ private ServerFacade createAndConfigureServer(final SwitchConnectionHandler connectionHandler) {
LOG.debug("Configuring ..");
- if (connConfig == null) {
- throw new IllegalStateException("Connection not configured");
- }
final var transportProtocol = (TransportProtocol) connConfig.getTransferProtocol();
if (transportProtocol == null) {
throw new IllegalStateException("No transport protocol received in " + connConfig);
}
final var factory = new ChannelInitializerFactory();
- factory.setSwitchConnectionHandler(switchConnectionHandler);
+ factory.setSwitchConnectionHandler(connectionHandler);
factory.setSwitchIdleTimeout(connConfig.getSwitchIdleTimeout());
factory.setTlsConfig(connConfig.getTlsConfiguration());
factory.setSerializationFactory(serializationFactory);
return serverFacade;
}
- @Override
- public void close() {
- shutdown();
- }
-
@Override
public boolean unregisterSerializer(final ExperimenterSerializerKey key) {
return serializerRegistry.unregisterSerializer((MessageTypeKey<?>) key);
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.util.List;
-import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
*
* @param protocol communication protocol
*/
- public void startUp(final TransportProtocol protocol) throws UnknownHostException {
+ public void startUp(final TransportProtocol protocol) throws Exception {
config = null;
if (protocol != null) {
createConfig(protocol);
provider = new SwitchConnectionProviderImpl(diagStatusService, config);
}
- private void createConfig(final TransportProtocol protocol) throws UnknownHostException {
+ private void createConfig(final TransportProtocol protocol) throws Exception {
InetAddress startupAddress = InetAddress.getLocalHost();
tlsConfiguration = null;
* Test getServerFacade.
*/
@Test
- public void testServerFacade() throws UnknownHostException {
+ public void testServerFacade() throws Exception {
startUp(TransportProtocol.TCP);
- final var future = provider.startup();
+ final var future = provider.startup(handler);
final var serverFacade = provider.getServerFacade();
assertNotNull("Wrong -- getServerFacade return null", serverFacade);
}
* Test shutdown on unconfigured provider.
*/
@Test(expected = IllegalStateException.class)
- public void testShutdownUnconfigured() throws UnknownHostException {
+ public void testShutdownUnconfigured() throws Exception {
startUp(TransportProtocol.TCP);
provider.shutdown();
}
* Test unregister by wrong key.
*/
@Test
- public void testUnregisterWrongKeys() throws UnknownHostException {
+ public void testUnregisterWrongKeys() throws Exception {
startUp(TransportProtocol.TCP);
final var testSerKey = new ExperimenterInstructionSerializerKey(EncodeConstants.OF_VERSION_1_0, 42L);
assertFalse("Wrong -- unregisterSerializer",provider.unregisterSerializer(testSerKey));
* Test register and unregister method.
*/
@Test
- public void testUnregisterExistingKeys() throws UnknownHostException {
+ public void testUnregisterExistingKeys() throws Exception {
startUp(TransportProtocol.TCP);
// -- registerActionSerializer
final ExperimenterActionSerializerKey key1 =
new ExperimenterActionSerializerKey(EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(42), TestSubType.VALUE);
provider.registerActionSerializer(key1, serializer);
- Assert.assertTrue("Wrong -- unregister ActionSerializer", provider.unregisterSerializer(key1));
- Assert.assertFalse("Wrong -- unregister ActionSerializer by not existing key",
+ assertTrue("Wrong -- unregister ActionSerializer", provider.unregisterSerializer(key1));
+ assertFalse("Wrong -- unregister ActionSerializer by not existing key",
provider.unregisterSerializer(key1));
// -- registerActionDeserializer
final ExperimenterActionDeserializerKey key2
= new ExperimenterActionDeserializerKey(EncodeConstants.OF_VERSION_1_0, 42L);
provider.registerActionDeserializer(key2, deserializer);
- Assert.assertTrue("Wrong -- unregister ActionDeserializer", provider.unregisterDeserializer(key2));
- Assert.assertFalse("Wrong -- unregister ActionDeserializer by not existing key",
+ assertTrue("Wrong -- unregister ActionDeserializer", provider.unregisterDeserializer(key2));
+ assertFalse("Wrong -- unregister ActionDeserializer by not existing key",
provider.unregisterDeserializer(key2));
// -- registerInstructionSerializer
final ExperimenterInstructionSerializerKey key3 =
new ExperimenterInstructionSerializerKey(EncodeConstants.OF_VERSION_1_0, 42L);
provider.registerInstructionSerializer(key3, serializer);
- Assert.assertTrue("Wrong -- unregister InstructionSerializer", provider.unregisterSerializer(key3));
- Assert.assertFalse("Wrong -- unregister InstructionSerializer by not existing key",
+ assertTrue("Wrong -- unregister InstructionSerializer", provider.unregisterSerializer(key3));
+ assertFalse("Wrong -- unregister InstructionSerializer by not existing key",
provider.unregisterSerializer(key3));
// -- registerInstructionDeserializer
final ExperimenterInstructionDeserializerKey key4 =
new ExperimenterInstructionDeserializerKey(EncodeConstants.OF_VERSION_1_0, 42L);
provider.registerInstructionDeserializer(key4, deserializer);
- Assert.assertTrue("Wrong -- unregister InstructionDeserializer", provider.unregisterDeserializer(key4));
- Assert.assertFalse("Wrong -- unregister InstructionDeserializer by not existing key",
+ assertTrue("Wrong -- unregister InstructionDeserializer", provider.unregisterDeserializer(key4));
+ assertFalse("Wrong -- unregister InstructionDeserializer by not existing key",
provider.unregisterDeserializer(key4));
// -- registerMatchEntryDeserializer
final MatchEntryDeserializerKey key5 =
new MatchEntryDeserializerKey(EncodeConstants.OF_VERSION_1_0, 0x8000, 42);
provider.registerMatchEntryDeserializer(key5, deserializer);
- Assert.assertTrue("Wrong -- unregister MatchEntryDeserializer", provider.unregisterDeserializer(key5));
- Assert.assertFalse("Wrong -- unregister MatchEntryDeserializer by not existing key",
+ assertTrue("Wrong -- unregister MatchEntryDeserializer", provider.unregisterDeserializer(key5));
+ assertFalse("Wrong -- unregister MatchEntryDeserializer by not existing key",
provider.unregisterDeserializer(key5));
// -- registerErrorDeserializer
final ExperimenterIdDeserializerKey key6 = new ExperimenterIdDeserializerKey(EncodeConstants.OF_VERSION_1_0,
Uint32.valueOf(42), ErrorMessage.class);
provider.registerErrorDeserializer(key6, deserializerError);
- Assert.assertTrue("Wrong -- unregister ErrorDeserializer", provider.unregisterDeserializer(key6));
- Assert.assertFalse("Wrong -- unregister ErrorDeserializer by not existing key",
+ assertTrue("Wrong -- unregister ErrorDeserializer", provider.unregisterDeserializer(key6));
+ assertFalse("Wrong -- unregister ErrorDeserializer by not existing key",
provider.unregisterDeserializer(key6));
// -- registerExperimenterMessageDeserializer
final ExperimenterIdDeserializerKey key7 = new ExperimenterIdDeserializerKey(EncodeConstants.OF_VERSION_1_0,
Uint32.valueOf(42), ExperimenterMessage.class);
provider.registerExperimenterMessageDeserializer(key7, deserializerExpMsg);
- Assert.assertTrue("Wrong -- unregister ExperimenterMessageDeserializer", provider.unregisterDeserializer(key7));
- Assert.assertFalse("Wrong -- unregister ExperimenterMessageDeserializer by not existing key",
+ assertTrue("Wrong -- unregister ExperimenterMessageDeserializer", provider.unregisterDeserializer(key7));
+ assertFalse("Wrong -- unregister ExperimenterMessageDeserializer by not existing key",
provider.unregisterDeserializer(key7));
// -- registerMultipartReplyMessageDeserializer
final ExperimenterIdDeserializerKey key8 = new ExperimenterIdDeserializerKey(EncodeConstants.OF_VERSION_1_0,
Uint32.valueOf(42), MultipartReplyMessage.class);
provider.registerMultipartReplyMessageDeserializer(key8, deserializerMultipartRplMsg);
- Assert.assertTrue("Wrong -- unregister MultipartReplyMessageDeserializer",
+ assertTrue("Wrong -- unregister MultipartReplyMessageDeserializer",
provider.unregisterDeserializer(key8));
- Assert.assertFalse("Wrong -- unregister MultipartReplyMessageDeserializer by not existing key",
+ assertFalse("Wrong -- unregister MultipartReplyMessageDeserializer by not existing key",
provider.unregisterDeserializer(key8));
// -- registerMultipartReplyTFDeserializer
final ExperimenterIdDeserializerKey key9 = new ExperimenterIdDeserializerKey(EncodeConstants.OF_VERSION_1_0,
Uint32.valueOf(42), MultipartReplyMessage.class);
provider.registerMultipartReplyTFDeserializer(key9, deserializer);
- Assert.assertTrue("Wrong -- unregister MultipartReplyTFDeserializer", provider.unregisterDeserializer(key9));
- Assert.assertFalse("Wrong -- unregister MultipartReplyTFDeserializer by non existing key",
+ assertTrue("Wrong -- unregister MultipartReplyTFDeserializer", provider.unregisterDeserializer(key9));
+ assertFalse("Wrong -- unregister MultipartReplyTFDeserializer by non existing key",
provider.unregisterDeserializer(key9));
// -- registerQueuePropertyDeserializer
final ExperimenterIdDeserializerKey key10 = new ExperimenterIdDeserializerKey(EncodeConstants.OF_VERSION_1_0,
Uint32.valueOf(42), QueueProperty.class);
provider.registerQueuePropertyDeserializer(key10, deserializerQueueProperty);
- Assert.assertTrue("Wrong -- unregister QueuePropertyDeserializer", provider.unregisterDeserializer(key10));
- Assert.assertFalse("Wrong -- unregister QueuePropertyDeserializer by not existing key",
+ assertTrue("Wrong -- unregister QueuePropertyDeserializer", provider.unregisterDeserializer(key10));
+ assertFalse("Wrong -- unregister QueuePropertyDeserializer by not existing key",
provider.unregisterDeserializer(key10));
// -- registerMeterBandDeserializer
final ExperimenterIdDeserializerKey key11 = new ExperimenterIdDeserializerKey(EncodeConstants.OF_VERSION_1_0,
Uint32.valueOf(42), MeterBandExperimenterCase.class);
provider.registerMeterBandDeserializer(key11, deserializerMeterBandExpCase);
- Assert.assertTrue("Wrong -- unregister MeterBandDeserializer", provider.unregisterDeserializer(key11));
- Assert.assertFalse("Wrong -- unregister MeterBandDeserializer by not existing key",
+ assertTrue("Wrong -- unregister MeterBandDeserializer", provider.unregisterDeserializer(key11));
+ assertFalse("Wrong -- unregister MeterBandDeserializer by not existing key",
provider.unregisterDeserializer(key11));
// -- registerExperimenterMessageSerializer
ExperimenterIdSerializerKey<ExperimenterDataOfChoice> key12 =
new ExperimenterIdSerializerKey<>(EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(42),
ExperimenterDataOfChoice.class);
provider.registerExperimenterMessageSerializer(key12, serializerExperimenterInput);
- Assert.assertTrue("Wrong -- unregister ExperimenterMessageSerializer", provider.unregisterSerializer(key12));
- Assert.assertFalse("Wrong -- unregister ExperimenterMessageSerializer by not existing key",
+ assertTrue("Wrong -- unregister ExperimenterMessageSerializer", provider.unregisterSerializer(key12));
+ assertFalse("Wrong -- unregister ExperimenterMessageSerializer by not existing key",
provider.unregisterSerializer(key12));
//registerMultipartRequestSerializer
ExperimenterIdSerializerKey<ExperimenterDataOfChoice> key13 =
new ExperimenterIdSerializerKey<>(EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(42),
ExperimenterDataOfChoice.class);
provider.registerMultipartRequestSerializer(key13, serializerMultipartRequestExpCase);
- Assert.assertTrue("Wrong -- unregister MultipartRequestSerializer", provider.unregisterSerializer(key13));
- Assert.assertFalse("Wrong -- unregister MultipartRequestSerializer by not existing key",
+ assertTrue("Wrong -- unregister MultipartRequestSerializer", provider.unregisterSerializer(key13));
+ assertFalse("Wrong -- unregister MultipartRequestSerializer by not existing key",
provider.unregisterSerializer(key13));
// -- registerMultipartRequestTFSerializer
final ExperimenterIdSerializerKey<TableFeatureProperties> key14 =
new ExperimenterIdSerializerKey<>(EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(42),
TableFeatureProperties.class);
provider.registerMultipartRequestTFSerializer(key14, serializer);
- Assert.assertTrue("Wrong -- unregister MultipartRequestTFSerializer", provider.unregisterSerializer(key14));
- Assert.assertFalse("Wrong -- unregister MultipartRequestTFSerializer by not existing key",
+ assertTrue("Wrong -- unregister MultipartRequestTFSerializer", provider.unregisterSerializer(key14));
+ assertFalse("Wrong -- unregister MultipartRequestTFSerializer by not existing key",
provider.unregisterSerializer(key14));
// -- registerMeterBandSerializer
final ExperimenterIdMeterSubTypeSerializerKey<MeterBandExperimenterCase> key15 =
new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(42),
MeterBandExperimenterCase.class,null);
provider.registerMeterBandSerializer(key15, serializerMeterBandExpCase);
- Assert.assertTrue("Wrong -- unregister MeterBandSerializer", provider.unregisterSerializer(key15));
- Assert.assertFalse("Wrong -- unregister MeterBandSerializer by not existing key",
+ assertTrue("Wrong -- unregister MeterBandSerializer", provider.unregisterSerializer(key15));
+ assertFalse("Wrong -- unregister MeterBandSerializer by not existing key",
provider.unregisterSerializer(key15));
// -- registerMatchEntrySerializer
final MatchEntrySerializerKey<OpenflowBasicClass, InPort> key16 =
new MatchEntrySerializerKey<>(EncodeConstants.OF_VERSION_1_3, OpenflowBasicClass.VALUE, InPort.VALUE);
provider.registerMatchEntrySerializer(key16, serializer);
- Assert.assertTrue("Wrong -- unregister MatchEntrySerializer", provider.unregisterSerializer(key16));
- Assert.assertFalse("Wrong -- unregister MatchEntrySerializer by not existing key",
+ assertTrue("Wrong -- unregister MatchEntrySerializer", provider.unregisterSerializer(key16));
+ assertFalse("Wrong -- unregister MatchEntrySerializer by not existing key",
provider.unregisterSerializer(key15));
// -- registerSerializer
final MessageTypeKey key17 = new MessageTypeKey<>(EncodeConstants.OF_VERSION_1_3, TestSubType.class);