Search in sources :

Example 6 with FeaturesReply

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

the class StatisticsContextImpMockInitiation method initialize.

@Before
public void initialize() {
    mockedDeviceContext = mock(DeviceContext.class);
    mockedStatisticsGatheringService = mock(StatisticsGatheringService.class);
    mockedStatisticsOnFlyGatheringService = mock(StatisticsGatheringOnTheFlyService.class);
    mockedConnectionContext = mock(ConnectionContext.class);
    mockedDeviceState = mock(DeviceState.class);
    mockedDeviceInfo = mock(DeviceInfo.class);
    mockedStatisticsManager = mock(StatisticsManager.class);
    mockedMastershipWatcher = mock(ContextChainMastershipWatcher.class);
    final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
    final MessageSpy mockedMessageSpy = mock(MessageSpy.class);
    final OutboundQueue mockedOutboundQueue = mock(OutboundQueue.class);
    final DeviceManager mockedDeviceManager = mock(DeviceManager.class);
    when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
    when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
    when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
    when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy);
    when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(isTable);
    when(mockedDeviceState.isFlowStatisticsAvailable()).thenReturn(isFlow);
    when(mockedDeviceState.isGroupAvailable()).thenReturn(isGroup);
    when(mockedDeviceState.isMetersAvailable()).thenReturn(isMeter);
    when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(isPort);
    when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(isQueue);
    when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(DUMMY_NODE_ID);
    when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
    when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
    when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
    when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
    when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy);
    when(mockedDeviceInfo.getNodeId()).thenReturn(DUMMY_NODE_ID.getKey().getId());
    when(mockedConnectionContext.getNodeId()).thenReturn(DUMMY_NODE_ID.getKey().getId());
    when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
    when(mockedConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
    when(mockedConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
}
Also used : OutboundQueue(org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue) DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) StatisticsGatheringOnTheFlyService(org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringOnTheFlyService) DeviceState(org.opendaylight.openflowplugin.api.openflow.device.DeviceState) StatisticsManager(org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager) StatisticsGatheringService(org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService) ContextChainMastershipWatcher(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipWatcher) FeaturesReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) DeviceManager(org.opendaylight.openflowplugin.api.openflow.device.DeviceManager) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) MessageSpy(org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy) Before(org.junit.Before)

Example 7 with FeaturesReply

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

the class OF10DeviceInitializerTest method setUp.

@Before
public void setUp() throws Exception {
    final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = DeviceStateUtil.createNodeInstanceIdentifier(new NodeId("openflow:1"));
    deviceInitializer = new OF10DeviceInitializer();
    when(featuresReply.getCapabilitiesV10()).thenReturn(capabilitiesV10);
    when(featuresReply.getPhyPort()).thenReturn(Collections.singletonList(new PhyPortBuilder().setPortNo(42L).build()));
    when(connectionContext.getFeatures()).thenReturn(featuresReply);
    when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
    when(deviceContext.getDeviceState()).thenReturn(deviceState);
    when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
    when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
    when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
    when(translatorLibrary.lookupTranslator(any())).thenReturn(messageTranslator);
    when(deviceContext.oook()).thenReturn(translatorLibrary);
    when(requestContext.getXid()).thenReturn(new Xid(42L));
    when(requestContext.getFuture()).thenReturn(RpcResultBuilder.success().buildFuture());
    when(deviceContext.createRequestContext()).thenReturn(requestContext);
    when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
}
Also used : Xid(org.opendaylight.openflowplugin.api.openflow.device.Xid) PhyPortBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) Before(org.junit.Before)

Example 8 with FeaturesReply

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

the class SystemNotificationsListenerImpl method executeOnSwitchIdleEvent.

@SuppressWarnings("checkstyle:IllegalCatch")
private void executeOnSwitchIdleEvent() {
    boolean shouldBeDisconnected = true;
    final InetSocketAddress remoteAddress = connectionContext.getConnectionAdapter().getRemoteAddress();
    if (ConnectionContext.CONNECTION_STATE.WORKING.equals(connectionContext.getConnectionState())) {
        FeaturesReply features = connectionContext.getFeatures();
        LOG.info("Switch Idle state occurred, node={}|auxId={}", remoteAddress, features.getAuxiliaryId());
        connectionContext.changeStateToTimeouting();
        EchoInputBuilder builder = new EchoInputBuilder();
        builder.setVersion(features.getVersion());
        builder.setXid(ECHO_XID.getValue());
        Future<RpcResult<EchoOutput>> echoReplyFuture = connectionContext.getConnectionAdapter().echo(builder.build());
        try {
            RpcResult<EchoOutput> echoReplyValue = echoReplyFuture.get(echoReplyTimeout, TimeUnit.MILLISECONDS);
            if (echoReplyValue.isSuccessful() && Objects.equals(echoReplyValue.getResult().getXid(), ECHO_XID.getValue())) {
                connectionContext.changeStateToWorking();
                shouldBeDisconnected = false;
            } else {
                logErrors(remoteAddress, echoReplyValue);
            }
        } catch (Exception e) {
            if (LOG.isWarnEnabled()) {
                LOG.warn("Exception while  waiting for echoReply from [{}] in TIMEOUTING state: {}", remoteAddress, e.getMessage());
            }
            if (LOG.isTraceEnabled()) {
                LOG.trace("Exception while  waiting for echoReply from [{}] in TIMEOUTING state: {}", remoteAddress, e);
            }
        }
    }
    if (shouldBeDisconnected) {
        if (LOG.isInfoEnabled()) {
            LOG.info("ConnectionEvent:Closing connection as device is idle. Echo sent at {}. Device:{}, NodeId:{}", new Date(System.currentTimeMillis() - echoReplyTimeout), remoteAddress, connectionContext.getSafeNodeIdForLOG());
        }
        connectionContext.closeConnection(true);
    }
}
Also used : EchoOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput) InetSocketAddress(java.net.InetSocketAddress) FeaturesReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply) EchoInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Date(java.util.Date)

Example 9 with FeaturesReply

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

the class MultipartReplyTranslatorTest method prepareMocks.

private MultipartReplyMessage prepareMocks(DeviceContext mockedDeviceContext, MultipartReplyBody multipartReplyBody, final MultipartType multipartType) {
    ConnectionContext mockedConnectionContext = mock(ConnectionContext.class);
    FeaturesReply mockedFeaturesReply = mock(FeaturesReply.class);
    when(mockedFeaturesReply.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
    when(mockedFeaturesReply.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
    DeviceInfo deviceInfo = mock(DeviceInfo.class);
    when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
    when(deviceInfo.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
    when(mockedDeviceContext.getDeviceInfo()).thenReturn(deviceInfo);
    when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeaturesReply);
    when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
    MultipartReplyMessage multipartReplyMessage = mock(MultipartReplyMessage.class);
    when(multipartReplyMessage.getType()).thenReturn(multipartType);
    when(multipartReplyMessage.getFlags()).thenReturn(new MultipartRequestFlags(true));
    when(multipartReplyMessage.getXid()).thenReturn(DUMMY_XID);
    when(multipartReplyMessage.getMultipartReplyBody()).thenReturn(multipartReplyBody);
    return multipartReplyMessage;
}
Also used : MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) FeaturesReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) MultipartRequestFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext)

Example 10 with FeaturesReply

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

the class DeviceInitializationUtilTest method setUp.

@Before
public void setUp() throws Exception {
    when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(NODE_II);
    when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
    when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
    when(connectionAdapter.getRemoteAddress()).thenReturn(INET_SOCKET_ADDRESS);
    when(featuresReply.getTables()).thenReturn(TABLES);
    when(featuresReply.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
    when(featuresReply.getCapabilities()).thenReturn(new Capabilities(false, false, false, false, false, false, false));
    when(connectionContext.getFeatures()).thenReturn(featuresReply);
    when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
}
Also used : Capabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities) Before(org.junit.Before)

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