From f985e53ae49aff53f09a82f69bab70e293593a13 Mon Sep 17 00:00:00 2001 From: Martin Bobak Date: Wed, 20 May 2015 17:56:23 +0200 Subject: [PATCH] device context holds OQHandler registration Handler registration is closed when device context is closed. Change-Id: Ib4a58c943789c5505542858767e5b6311bea3f3b Signed-off-by: Martin Bobak --- .../api/openflow/device/DeviceContext.java | 8 ++++++++ .../openflowplugin/impl/device/DeviceContextImpl.java | 9 +++++++++ .../openflowplugin/impl/device/DeviceManagerImpl.java | 10 +++++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java index 4ef9946a94..de5669500b 100644 --- a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java +++ b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java @@ -14,6 +14,7 @@ import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService import org.opendaylight.controller.md.sal.binding.api.NotificationService; import org.opendaylight.controller.md.sal.binding.api.ReadTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration; import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginTimer; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextClosedHandler; @@ -172,5 +173,12 @@ public interface DeviceContext extends AutoCloseable, */ void onPublished(); + + /** + * Method registers outbound queue handler that should be invalidated when device context is closed.s + * @param outboundQueueHandlerRegistration + */ + void registerOutboundQueueHandler(OutboundQueueHandlerRegistration outboundQueueHandlerRegistration); + } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java index e09a5c6e04..de860f7e18 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java @@ -28,6 +28,7 @@ import org.opendaylight.controller.md.sal.binding.api.ReadTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue; +import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.DeviceState; @@ -107,6 +108,7 @@ public class DeviceContextImpl implements DeviceContext { private volatile boolean filteringPacketIn = false; private final Object throttlingLock = new Object(); private int filteringHighWaterMark = 0; + private OutboundQueueHandlerRegistration outboundQueueHandlerRegistration; @Override public MultiMsgCollector getMultiMsgCollector() { @@ -348,6 +350,8 @@ public class DeviceContextImpl implements DeviceContext { public void close() { deviceState.setValid(false); + outboundQueueHandlerRegistration.close(); + LOG.trace("Removing node {} from operational DS.", getDeviceState().getNodeId()); addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, getDeviceState().getNodeInstanceIdentifier()); @@ -438,4 +442,9 @@ public class DeviceContextImpl implements DeviceContext { switchAuxConnectionContext.getConnectionAdapter().setPacketInFiltering(false); } } + + @Override + public void registerOutboundQueueHandler(final OutboundQueueHandlerRegistration outboundQueueHandlerRegistration) { + this.outboundQueueHandlerRegistration = outboundQueueHandlerRegistration; + } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java index da40934d3d..358473e328 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java @@ -32,6 +32,7 @@ import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue; +import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration; import org.opendaylight.openflowplugin.api.ConnectionException; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; @@ -167,14 +168,13 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable { final Short version = connectionContext.getFeatures().getVersion(); OutboundQueueProvider outboundQueueProvider = new OutboundQueueProviderImpl(version); - // FIXME: we are losing registration, we should be registering in the connection context - connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, maxQueueDepth, barrierNanos); + final OutboundQueueHandlerRegistration outboundQueueHandlerRegistration = connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, maxQueueDepth, barrierNanos); connectionContext.setOutboundQueueProvider(outboundQueueProvider); final DeviceState deviceState = new DeviceStateImpl(connectionContext.getFeatures(), connectionContext.getNodeId()); final DeviceContext deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker, hashedWheelTimer, messageIntelligenceAgency); - + deviceContext.registerOutboundQueueHandler(outboundQueueHandlerRegistration); deviceContext.setNotificationService(notificationService); deviceContext.setNotificationPublishService(notificationPublishService); NodeBuilder nodeBuilder = new NodeBuilder().setId(deviceState.getNodeId()).setNodeConnector(Collections.emptyList()); @@ -264,7 +264,7 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable { private static ListenableFuture>>> createDeviceFeaturesForOF10(final DeviceContext deviceContext, - final DeviceState deviceState) { + final DeviceState deviceState) { final ListenableFuture>> replyDesc = getNodeStaticInfo(MultipartType.OFPMPDESC, deviceContext, deviceState.getNodeInstanceIdentifier(), @@ -274,7 +274,7 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable { } private static ListenableFuture>>> createDeviceFeaturesForOF13(final DeviceContext deviceContext, - final DeviceState deviceState) { + final DeviceState deviceState) { final ListenableFuture>> replyDesc = getNodeStaticInfo(MultipartType.OFPMPDESC, deviceContext, -- 2.36.6