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;
}
}
}
}
}
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);
}
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();
}
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);
}
Aggregations