use of org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain in project openflowplugin by opendaylight.
the class ContextChainHolderImpl method createContextChain.
@VisibleForTesting
void createContextChain(final ConnectionContext connectionContext) {
final DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
final DeviceContext deviceContext = deviceManager.createContext(connectionContext);
deviceContext.registerMastershipWatcher(this);
LOG.debug("Device" + CONTEXT_CREATED_FOR_CONNECTION, deviceInfo);
final RpcContext rpcContext = rpcManager.createContext(deviceContext);
rpcContext.registerMastershipWatcher(this);
LOG.debug("RPC" + CONTEXT_CREATED_FOR_CONNECTION, deviceInfo);
final StatisticsContext statisticsContext = statisticsManager.createContext(deviceContext, ownershipChangeListener.isReconciliationFrameworkRegistered());
statisticsContext.registerMastershipWatcher(this);
LOG.debug("Statistics" + CONTEXT_CREATED_FOR_CONNECTION, deviceInfo);
final RoleContext roleContext = roleManager.createContext(deviceContext);
roleContext.registerMastershipWatcher(this);
LOG.debug("Role" + CONTEXT_CREATED_FOR_CONNECTION, deviceInfo);
final ContextChain contextChain = new ContextChainImpl(this, connectionContext, executorService);
contextChain.registerDeviceRemovedHandler(deviceManager);
contextChain.registerDeviceRemovedHandler(rpcManager);
contextChain.registerDeviceRemovedHandler(statisticsManager);
contextChain.registerDeviceRemovedHandler(roleManager);
contextChain.registerDeviceRemovedHandler(this);
contextChain.addContext(deviceContext);
contextChain.addContext(rpcContext);
contextChain.addContext(statisticsContext);
contextChain.addContext(roleContext);
contextChainMap.put(deviceInfo, contextChain);
connectingDevices.remove(deviceInfo);
LOG.debug("Context chain" + CONTEXT_CREATED_FOR_CONNECTION, deviceInfo);
deviceContext.onPublished();
contextChain.registerServices(singletonServiceProvider);
}
use of org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain in project openflowplugin by opendaylight.
the class DeviceContextImpl method isMasterOfDevice.
private Boolean isMasterOfDevice() {
final ContextChain contextChain = contextChainHolder.getContextChain(deviceInfo);
boolean result = false;
if (contextChain != null) {
result = contextChain.isMastered(ContextChainMastershipState.CHECK, false);
}
return result;
}
use of org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain in project openflowplugin by opendaylight.
the class ContextChainHolderImpl method deviceConnected.
@Override
public ConnectionStatus deviceConnected(final ConnectionContext connectionContext) throws Exception {
final DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
final ContextChain contextChain = contextChainMap.get(deviceInfo);
final FeaturesReply featuresReply = connectionContext.getFeatures();
final Short auxiliaryId = featuresReply != null ? featuresReply.getAuxiliaryId() : null;
if (auxiliaryId != null && auxiliaryId != 0) {
if (contextChain == null) {
LOG.warn("An auxiliary connection for device {}, but no primary connection. Refusing connection.", deviceInfo);
return ConnectionStatus.REFUSING_AUXILIARY_CONNECTION;
} else {
if (contextChain.addAuxiliaryConnection(connectionContext)) {
LOG.info("An auxiliary connection was added to device: {}", deviceInfo);
return ConnectionStatus.MAY_CONTINUE;
} else {
LOG.warn("Not able to add auxiliary connection to the device {}", deviceInfo);
return ConnectionStatus.REFUSING_AUXILIARY_CONNECTION;
}
}
} else {
LOG.info("Device {} connected.", deviceInfo);
final boolean contextExists = contextChain != null;
final boolean isClosing = contextExists && contextChain.isClosing();
if (!isClosing && connectingDevices.putIfAbsent(deviceInfo, connectionContext) != null) {
LOG.warn("Device {} is already trying to connect, wait until succeeded or disconnected.", deviceInfo);
return ConnectionStatus.ALREADY_CONNECTED;
}
if (contextExists) {
if (isClosing) {
LOG.warn("Device {} is already in termination state, closing all incoming connections.", deviceInfo);
return ConnectionStatus.CLOSING;
}
LOG.warn("Device {} already connected. Closing previous connection", deviceInfo);
destroyContextChain(deviceInfo);
LOG.info("Old connection dropped, creating new context chain for device {}", deviceInfo);
createContextChain(connectionContext);
} else {
LOG.info("No context chain found for device: {}, creating new.", deviceInfo);
createContextChain(connectionContext);
}
return ConnectionStatus.MAY_CONTINUE;
}
}
Aggregations