import org.opendaylight.openflowplugin.extension.api.ExtensionConverterProviderKeeper;
import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
import org.opendaylight.openflowplugin.impl.connection.OutboundQueueProviderImpl;
+import org.opendaylight.openflowplugin.impl.device.initialization.DeviceInitializerProvider;
import org.opendaylight.openflowplugin.impl.device.listener.OpenflowProtocolListenerFullImpl;
import org.opendaylight.openflowplugin.impl.lifecycle.LifecycleServiceImpl;
-import org.opendaylight.openflowplugin.impl.services.SalRoleServiceImpl;
+import org.opendaylight.openflowplugin.impl.services.sal.SalRoleServiceImpl;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
private final long globalNotificationQuota;
private final boolean switchFeaturesMandatory;
- private boolean isNotificationFlowRemovedOff;
+ private boolean isFlowRemovedNotificationOn;
private boolean skipTableFeatures;
private static final int SPY_RATE = 10;
private final DataBroker dataBroker;
+ private final DeviceInitializerProvider deviceInitializerProvider;
private final ConvertorExecutor convertorExecutor;
private TranslatorLibrary translatorLibrary;
private DeviceInitializationPhaseHandler deviceInitPhaseHandler;
private final NotificationPublishService notificationPublishService;
private final MessageSpy messageSpy;
private final HashedWheelTimer hashedWheelTimer;
+ private final boolean useSingleLayerSerialization;
public DeviceManagerImpl(@Nonnull final DataBroker dataBroker,
final long globalNotificationQuota,
final long barrierInterval,
final int barrierCountLimit,
final MessageSpy messageSpy,
- final boolean isNotificationFlowRemovedOff,
+ final boolean isFlowRemovedNotificationOn,
final ClusterSingletonServiceProvider singletonServiceProvider,
final NotificationPublishService notificationPublishService,
final HashedWheelTimer hashedWheelTimer,
final ConvertorExecutor convertorExecutor,
- final boolean skipTableFeatures) {
+ final boolean skipTableFeatures,
+ final boolean useSingleLayerSerialization,
+ final DeviceInitializerProvider deviceInitializerProvider) {
this.dataBroker = dataBroker;
+ this.deviceInitializerProvider = deviceInitializerProvider;
/* merge empty nodes to oper DS to predict any problems with missing parent for Node */
final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
this.switchFeaturesMandatory = switchFeaturesMandatory;
this.globalNotificationQuota = globalNotificationQuota;
- this.isNotificationFlowRemovedOff = isNotificationFlowRemovedOff;
+ this.isFlowRemovedNotificationOn = isFlowRemovedNotificationOn;
this.skipTableFeatures = skipTableFeatures;
this.convertorExecutor = convertorExecutor;
this.hashedWheelTimer = hashedWheelTimer;
this.singletonServiceProvider = singletonServiceProvider;
this.notificationPublishService = notificationPublishService;
this.messageSpy = messageSpy;
+ this.useSingleLayerSerialization = useSingleLayerSerialization;
}
LOG.debug("Final phase of DeviceContextLevelUp for Node: {} ", deviceInfo.getNodeId());
DeviceContext deviceContext = Preconditions.checkNotNull(deviceContexts.get(deviceInfo));
deviceContext.onPublished();
+ lifecycleService.registerDeviceRemovedHandler(this);
lifecycleService.registerService(this.singletonServiceProvider);
}
@Override
public ConnectionStatus deviceConnected(@CheckForNull final ConnectionContext connectionContext) throws Exception {
Preconditions.checkArgument(connectionContext != null);
+ final DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
- DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
/*
* This part prevent destroy another device context. Throwing here an exception result to propagate close connection
* in {@link org.opendaylight.openflowplugin.impl.connection.org.opendaylight.openflowplugin.impl.connection.HandshakeContextImpl}
connectionContext.getConnectionAdapter().getRemoteAddress(), deviceInfo.getNodeId());
// Add Disconnect handler
- connectionContext.setDeviceDisconnectedHandler(DeviceManagerImpl.this);
+ connectionContext.setDeviceDisconnectedHandler(this);
+
// Cache this for clarity
final ConnectionAdapter connectionAdapter = connectionContext.getConnectionAdapter();
- //FIXME: as soon as auxiliary connection are fully supported then this is needed only before device context published
+ // FIXME: as soon as auxiliary connection are fully supported then this is needed only before device context published
connectionAdapter.setPacketInFiltering(true);
final OutboundQueueProvider outboundQueueProvider = new OutboundQueueProviderImpl(deviceInfo.getVersion());
connectionContext.setOutboundQueueHandleRegistration(outboundQueueHandlerRegistration);
final LifecycleService lifecycleService = new LifecycleServiceImpl();
-
final DeviceContext deviceContext = new DeviceContextImpl(
connectionContext,
dataBroker,
convertorExecutor,
skipTableFeatures,
hashedWheelTimer,
- this);
+ this,
+ useSingleLayerSerialization,
+ deviceInitializerProvider);
deviceContext.setSalRoleService(new SalRoleServiceImpl(deviceContext, deviceContext));
deviceContexts.put(deviceInfo, deviceContext);
@Override
public void onDeviceContextLevelDown(final DeviceInfo deviceInfo) {
-
- LifecycleService lifecycleService = lifecycleServices.remove(deviceInfo);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Lifecycle service removed for node {}", deviceInfo.getLOGValue());
- }
-
updatePacketInRateLimiters();
- if (Objects.nonNull(lifecycleService)) {
- try {
- lifecycleService.close();
- LOG.debug("Lifecycle service successfully closed for node {}", deviceInfo.getLOGValue());
- } catch (Exception e) {
- LOG.warn("Closing lifecycle service for node {} was unsuccessful ", deviceInfo.getLOGValue(), e);
- }
- }
-
- deviceContexts.remove(deviceInfo);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Device context removed for node {}", deviceInfo.getLOGValue());
- }
-
+ Optional.ofNullable(lifecycleServices.get(deviceInfo)).ifPresent(OFPContext::close);
}
@Override
final DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
final DeviceContext deviceCtx = this.deviceContexts.get(deviceInfo);
- if (null == deviceCtx) {
+ if (Objects.isNull(deviceCtx)) {
LOG.info("DeviceContext for Node {} was not found. Connection is terminated without OFP context suite.", deviceInfo.getLOGValue());
return;
}
return;
}
- deviceCtx.setState(OFPContext.CONTEXT_STATE.TERMINATION);
+ deviceCtx.close();
if (!connectionContext.equals(deviceCtx.getPrimaryConnectionContext())) {
LOG.debug("Node {} disconnected, but not primary connection.", connectionContext.getDeviceInfo().getLOGValue());
- /* Connection is not PrimaryConnection so try to remove from Auxiliary Connections */
+ // Connection is not PrimaryConnection so try to remove from Auxiliary Connections
deviceCtx.removeAuxiliaryConnectionContext(connectionContext);
}
- //TODO: Auxiliary connections supported ?
- /* Device is disconnected and so we need to close TxManager */
+
+ // TODO: Auxiliary connections supported ?
+ // Device is disconnected and so we need to close TxManager
final ListenableFuture<Void> future = deviceCtx.shuttingDownDataStoreTransactions();
Futures.addCallback(future, new FutureCallback<Void>() {
-
@Override
public void onSuccess(final Void result) {
LOG.debug("TxChainManager for device {} is closed successful.", deviceInfo.getLOGValue());
deviceTerminPhaseHandler.onDeviceContextLevelDown(deviceInfo);
}
});
- /* Add timer for Close TxManager because it could fain ind cluster without notification */
+
+ // Add timer for Close TxManager because it could fail in cluster without notification
final TimerTask timerTask = timeout -> {
if (!future.isDone()) {
LOG.warn("Shutting down TxChain for node {} not completed during 10 sec. Continue anyway.", deviceInfo.getLOGValue());
future.cancel(false);
}
};
+
hashedWheelTimer.newTimeout(timerTask, 10, TimeUnit.SECONDS);
}
}
@Override
- public void setIsNotificationFlowRemovedOff(boolean isNotificationFlowRemovedOff) {
- this.isNotificationFlowRemovedOff = isNotificationFlowRemovedOff;
+ public void setFlowRemovedNotificationOn(boolean isNotificationFlowRemovedOff) {
+ this.isFlowRemovedNotificationOn = isNotificationFlowRemovedOff;
}
@Override
- public boolean getIsNotificationFlowRemovedOff() {
- return this.isNotificationFlowRemovedOff;
+ public boolean isFlowRemovedNotificationOn() {
+ return this.isFlowRemovedNotificationOn;
}
}
}
- @VisibleForTesting
- void setDeviceContext(final DeviceInfo deviceInfo, final DeviceContext deviceContext) {
- this.deviceContexts.putIfAbsent(deviceInfo, deviceContext);
- }
+ public void onDeviceRemoved(DeviceInfo deviceInfo) {
+ deviceContexts.remove(deviceInfo);
+ LOG.debug("Device context removed for node {}", deviceInfo.getLOGValue());
- @VisibleForTesting
- int getDeviceContextCount() {
- return this.deviceContexts.size();
+ lifecycleServices.remove(deviceInfo);
+ LOG.debug("Lifecycle service removed for node {}", deviceInfo.getLOGValue());
}
-
-
}