Search in sources :

Example 1 with ContextChain

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);
}
Also used : RpcContext(org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext) DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) RoleContext(org.opendaylight.openflowplugin.api.openflow.role.RoleContext) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) StatisticsContext(org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext) ContextChain(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ContextChain

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;
}
Also used : ContextChain(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain)

Example 3 with ContextChain

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;
    }
}
Also used : FeaturesReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) ContextChain(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain)

Aggregations

ContextChain (org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain)3 DeviceInfo (org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 DeviceContext (org.opendaylight.openflowplugin.api.openflow.device.DeviceContext)1 RoleContext (org.opendaylight.openflowplugin.api.openflow.role.RoleContext)1 RpcContext (org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext)1 StatisticsContext (org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext)1 FeaturesReply (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply)1