- }
-
- @Override
- public boolean deviceConnected(@CheckForNull final ConnectionContext connectionContext) throws Exception {
- Preconditions.checkArgument(connectionContext != null);
-
- 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}
- * If context already exist we are in state closing process (connection flapping) and we should not propagate connection close
- */
- if (deviceContexts.containsKey(deviceInfo)) {
- LOG.warn("Rejecting connection from node which is already connected and there exist deviceContext for it: {}", connectionContext.getNodeId());
- return false;
- }
-
- LOG.info("ConnectionEvent: Device connected to controller, Device:{}, NodeId:{}",
- connectionContext.getConnectionAdapter().getRemoteAddress(), deviceInfo.getNodeId());
-
- // Add Disconnect handler
- connectionContext.setDeviceDisconnectedHandler(DeviceManagerImpl.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
- connectionAdapter.setPacketInFiltering(true);
-
- final OutboundQueueProvider outboundQueueProvider = new OutboundQueueProviderImpl(deviceInfo.getVersion());
-
- connectionContext.setOutboundQueueProvider(outboundQueueProvider);
- final OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration =
- connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, barrierCountLimit, barrierIntervalNanos);
- connectionContext.setOutboundQueueHandleRegistration(outboundQueueHandlerRegistration);
-
- final DeviceState deviceState = new DeviceStateImpl(deviceInfo);
- this.addDeviceSynchronizeListener(deviceState);
- this.addDeviceValidListener(deviceState);
-
- final DeviceContext deviceContext = new DeviceContextImpl(connectionContext,
- deviceState,
- dataBroker,
- conductor,
- outboundQueueProvider,
- translatorLibrary,
- this);
-
- Verify.verify(deviceContexts.putIfAbsent(deviceInfo, deviceContext) == null, "DeviceCtx still not closed.");
-
- ((ExtensionConverterProviderKeeper) deviceContext).setExtensionConverterProvider(extensionConverterProvider);
- deviceContext.setNotificationPublishService(conductor.getNotificationPublishService());
-
- updatePacketInRateLimiters();
-
- final OpenflowProtocolListenerFullImpl messageListener = new OpenflowProtocolListenerFullImpl(
- connectionAdapter, deviceContext);
- connectionAdapter.setMessageListener(messageListener);
- notifyDeviceValidListeners(deviceInfo, true);
-
- deviceInitPhaseHandler.onDeviceContextLevelUp(connectionContext.getDeviceInfo());
-
- notifyDeviceSynchronizeListeners(deviceInfo, true);
-
- return true;
- }
-
- private void updatePacketInRateLimiters() {
- synchronized (deviceContexts) {
- final int deviceContextsSize = deviceContexts.size();
- if (deviceContextsSize > 0) {
- long freshNotificationLimit = globalNotificationQuota / deviceContextsSize;
- if (freshNotificationLimit < 100) {
- freshNotificationLimit = 100;
- }
- LOG.debug("fresh notification limit = {}", freshNotificationLimit);
- for (final DeviceContext deviceContext : deviceContexts.values()) {
- deviceContext.updatePacketInRateLimit(freshNotificationLimit);
- }
- }
- }