Search in sources :

Example 1 with OutboundQueue

use of org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue in project openflowplugin by opendaylight.

the class OutboundQueueProviderImpl method reserveEntry.

@Override
public Long reserveEntry() {
    for (; ; ) {
        OutboundQueue queue = outboundQueue;
        if (queue == null) {
            LOG.error("No queue present, failing request");
            return null;
        }
        final Long ret = queue.reserveEntry();
        if (ret != null) {
            return ret;
        }
        LOG.debug("Reservation failed, trying to recover");
        synchronized (this) {
            while (queue.equals(outboundQueue)) {
                LOG.debug("Queue {} is not replaced yet, going to sleep", queue);
                try {
                    wait();
                } catch (InterruptedException e) {
                    LOG.error("Interrupted while waiting for entry", e);
                    return null;
                }
            }
        }
    }
}
Also used : OutboundQueue(org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue)

Example 2 with OutboundQueue

use of org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue 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 3 with OutboundQueue

use of org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue in project openflowplugin by opendaylight.

the class AbstractService method handleServiceCall.

public ListenableFuture<RpcResult<O>> handleServiceCall(@Nonnull final I input, @Nullable final Function<OfHeader, Boolean> isComplete) {
    Preconditions.checkNotNull(input);
    final Class<?> requestType = input instanceof DataContainer ? DataContainer.class.cast(input).getImplementedInterface() : input.getClass();
    getMessageSpy().spyMessage(requestType, MessageSpy.StatisticsGroup.TO_SWITCH_ENTERED);
    LOG.trace("Handling general service call");
    final RequestContext<O> requestContext = requestContextStack.createRequestContext();
    if (Objects.isNull(requestContext)) {
        LOG.trace("Request context refused.");
        getMessageSpy().spyMessage(AbstractService.class, MessageSpy.StatisticsGroup.TO_SWITCH_DISREGARDED);
        return Futures.immediateFuture(RpcResultBuilder.<O>failed().withError(RpcError.ErrorType.APPLICATION, "", "Request quota exceeded").build());
    }
    if (Objects.isNull(requestContext.getXid())) {
        getMessageSpy().spyMessage(requestContext.getClass(), MessageSpy.StatisticsGroup.TO_SWITCH_RESERVATION_REJECTED);
        return RequestContextUtil.closeRequestContextWithRpcError(requestContext, "Outbound queue wasn't able to reserve XID.");
    }
    getMessageSpy().spyMessage(requestContext.getClass(), MessageSpy.StatisticsGroup.TO_SWITCH_READY_FOR_SUBMIT);
    final Xid xid = requestContext.getXid();
    OfHeader request = null;
    try {
        request = buildRequest(xid, input);
        Verify.verify(xid.getValue().equals(request.getXid()), "Expected XID %s got %s", xid.getValue(), request.getXid());
    } catch (ServiceException ex) {
        LOG.error("Failed to build request for {}, forfeiting request {}", input, xid.getValue(), ex);
        RequestContextUtil.closeRequestContextWithRpcError(requestContext, "failed to build request input: " + ex.getMessage());
    } finally {
        final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
        if (Objects.nonNull(isComplete)) {
            outboundQueue.commitEntry(xid.getValue(), request, createCallback(requestContext, requestType), isComplete);
        } else {
            outboundQueue.commitEntry(xid.getValue(), request, createCallback(requestContext, requestType));
        }
    }
    return requestContext.getFuture();
}
Also used : OutboundQueue(org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) Xid(org.opendaylight.openflowplugin.api.openflow.device.Xid) ServiceException(org.opendaylight.openflowplugin.impl.services.util.ServiceException) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)

Example 4 with OutboundQueue

use of org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue in project openflowplugin by opendaylight.

the class OutboundQueueProviderImplTest method testReserveEntry.

@Test
public void testReserveEntry() throws Exception {
    outboundQueueProvider.onConnectionQueueChanged(null);
    Long returnValue = outboundQueueProvider.reserveEntry();
    assertEquals(null, returnValue);
    OutboundQueue mockedQueue = mock(OutboundQueue.class);
    when(mockedQueue.reserveEntry()).thenReturn(DUMMY_ENTRY_NUMBER);
    outboundQueueProvider.onConnectionQueueChanged(mockedQueue);
    returnValue = outboundQueueProvider.reserveEntry();
    assertEquals(DUMMY_ENTRY_NUMBER, returnValue);
}
Also used : OutboundQueue(org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue) Test(org.junit.Test)

Aggregations

OutboundQueue (org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue)4 Before (org.junit.Before)1 Test (org.junit.Test)1 ConnectionContext (org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext)1 DeviceContext (org.opendaylight.openflowplugin.api.openflow.device.DeviceContext)1 DeviceInfo (org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo)1 DeviceManager (org.opendaylight.openflowplugin.api.openflow.device.DeviceManager)1 DeviceState (org.opendaylight.openflowplugin.api.openflow.device.DeviceState)1 Xid (org.opendaylight.openflowplugin.api.openflow.device.Xid)1 ContextChainMastershipWatcher (org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipWatcher)1 StatisticsManager (org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager)1 MessageSpy (org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy)1 ServiceException (org.opendaylight.openflowplugin.impl.services.util.ServiceException)1 StatisticsGatheringOnTheFlyService (org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringOnTheFlyService)1 StatisticsGatheringService (org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService)1 FeaturesReply (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply)1 OfHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)1 DataContainer (org.opendaylight.yangtools.yang.binding.DataContainer)1