Search in sources :

Example 11 with FeaturesReply

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply 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)

Example 12 with FeaturesReply

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply in project openflowplugin by opendaylight.

the class OF13DeviceInitializerTest method initializeMultiLayer.

@Test
public void initializeMultiLayer() throws Exception {
    when(deviceContext.canUseSingleLayerSerialization()).thenReturn(false);
    when(requestContext.getFuture()).thenReturn(RpcResultBuilder.success(Collections.singletonList(new MultipartReplyMessageBuilder().setType(MultipartType.OFPMPDESC).setMultipartReplyBody(new MultipartReplyDescCaseBuilder().setMultipartReplyDesc(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDescBuilder().build()).build()).build())).buildFuture());
    final Future<Void> initialize = deviceInitializer.initialize(deviceContext, true, false, multipartWriterProvider, convertorExecutor);
    initialize.get();
    verify(messageSpy, times(5)).spyMessage(eq(MultipartType.class), any());
    verify(requestContext, times(5)).getFuture();
    verify(featuresReply).getCapabilities();
    verify(deviceContext).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
}
Also used : MultipartType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType) MultipartReplyDescCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCaseBuilder) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) Test(org.junit.Test)

Aggregations

FeaturesReply (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply)7 Before (org.junit.Before)6 DeviceInfo (org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo)4 ConnectionContext (org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext)3 Xid (org.opendaylight.openflowplugin.api.openflow.device.Xid)3 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)3 Test (org.junit.Test)2 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)2 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)2 Capabilities (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities)2 MultipartType (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType)2 Optional (com.google.common.base.Optional)1 InetSocketAddress (java.net.InetSocketAddress)1 Date (java.util.Date)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 OutboundQueue (org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue)1 DeviceContext (org.opendaylight.openflowplugin.api.openflow.device.DeviceContext)1 DeviceManager (org.opendaylight.openflowplugin.api.openflow.device.DeviceManager)1 DeviceState (org.opendaylight.openflowplugin.api.openflow.device.DeviceState)1 ContextChain (org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain)1