use of org.opendaylight.yangtools.yang.binding.DataContainer 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.yangtools.yang.binding.DataContainer in project openflowplugin by opendaylight.
the class MultipartReplyTranslatorTest method testTranslateAggregate.
@Test
public void testTranslateAggregate() {
DeviceContext mockedDeviceContext = mock(DeviceContext.class);
MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyAggregate(), MultipartType.OFPMPAGGREGATE);
DataContainer result = MultipartReplyTranslatorUtil.translate(multipartReplyMessage, mockedDeviceContext.getDeviceInfo(), CONVERTOR_MANAGER, mockedDeviceContext.oook()).get();
DataContainer dataObject = validateOutput(result);
assertTrue(dataObject instanceof AggregateFlowStatistics);
AggregateFlowStatistics message = (AggregateFlowStatistics) dataObject;
assertEquals(DUMMY_BYTE_COUNT, message.getByteCount().getValue());
assertEquals(DUMMY_PACKET_COUNT, message.getPacketCount().getValue());
assertEquals(DUMMY_FLOW_COUNT, message.getFlowCount().getValue());
}
use of org.opendaylight.yangtools.yang.binding.DataContainer in project openflowplugin by opendaylight.
the class MultipartReplyTranslatorTest method testTranslateGroup.
@Test
public void testTranslateGroup() {
DeviceContext mockedDeviceContext = mock(DeviceContext.class);
MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyGroup(), MultipartType.OFPMPGROUP);
DataContainer result = MultipartReplyTranslatorUtil.translate(multipartReplyMessage, mockedDeviceContext.getDeviceInfo(), CONVERTOR_MANAGER, mockedDeviceContext.oook()).get();
DataContainer dataObject = validateOutput(result);
assertTrue(dataObject instanceof GroupStatisticsReply);
GroupStatisticsReply groupStatisticsUpdate = (GroupStatisticsReply) dataObject;
List<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats> groupStats = groupStatisticsUpdate.getGroupStats();
assertEquals(1, groupStats.size());
org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats groupStat = groupStats.get(0);
assertEquals(DUMMY_BYTE_COUNT, groupStat.getByteCount().getValue());
assertEquals(DUMMY_DURATION_SEC, groupStat.getDuration().getSecond().getValue());
assertEquals(DUMMY_DURATION_NSEC, groupStat.getDuration().getNanosecond().getValue());
assertEquals(DUMMY_GROUP_ID.getValue(), groupStat.getGroupId().getValue());
assertEquals(DUMMY_PACKET_COUNT, groupStat.getPacketCount().getValue());
assertEquals(DUMMY_REF_COUNT, groupStat.getRefCount().getValue());
}
use of org.opendaylight.yangtools.yang.binding.DataContainer in project openflowplugin by opendaylight.
the class MultipartReplyTranslatorTest method testTranslateGroupDesc.
@Test
public void testTranslateGroupDesc() {
DeviceContext mockedDeviceContext = mock(DeviceContext.class);
MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyGroupDesc(), MultipartType.OFPMPGROUPDESC);
DataContainer result = MultipartReplyTranslatorUtil.translate(multipartReplyMessage, mockedDeviceContext.getDeviceInfo(), CONVERTOR_MANAGER, mockedDeviceContext.oook()).get();
DataContainer dataObject = validateOutput(result);
assertTrue(dataObject instanceof GroupDescStatsReply);
GroupDescStatsReply groupStatistics = (GroupDescStatsReply) dataObject;
List<GroupDescStats> groupDescStats = groupStatistics.getGroupDescStats();
assertEquals(1, groupDescStats.size());
GroupDescStats groupDescStat = groupDescStats.get(0);
assertEquals(DUMMY_GROUP_ID.getValue(), groupDescStat.getGroupId().getValue());
assertEquals(DUMMY_GROUPS_TYPE, groupDescStat.getGroupType());
}
use of org.opendaylight.yangtools.yang.binding.DataContainer in project openflowplugin by opendaylight.
the class MultipartReplyTranslatorTest method testTranslateFlow.
@Test
public void testTranslateFlow() {
DeviceContext mockedDeviceContext = mock(DeviceContext.class);
MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyFlow(), MultipartType.OFPMPFLOW);
DataContainer result = MultipartReplyTranslatorUtil.translate(multipartReplyMessage, mockedDeviceContext.getDeviceInfo(), CONVERTOR_MANAGER, mockedDeviceContext.oook()).get();
DataContainer dataObject = validateOutput(result);
assertTrue(dataObject instanceof FlowAndStatisticsMapList);
}
Aggregations