Search in sources :

Example 1 with DataContainer

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();
}
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 2 with DataContainer

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());
}
Also used : DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) AggregateFlowStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.AggregateFlowStatistics) Test(org.junit.Test)

Example 3 with DataContainer

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());
}
Also used : MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) GroupStatisticsReply(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupStatisticsReply) Test(org.junit.Test)

Example 4 with DataContainer

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());
}
Also used : DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) GroupDescStatsReply(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupDescStatsReply) GroupDescStats(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats) Test(org.junit.Test)

Example 5 with DataContainer

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);
}
Also used : DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMapList) Test(org.junit.Test)

Aggregations

DataContainer (org.opendaylight.yangtools.yang.binding.DataContainer)6 Test (org.junit.Test)5 DeviceContext (org.opendaylight.openflowplugin.api.openflow.device.DeviceContext)5 MultipartReplyMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage)5 OutboundQueue (org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue)1 Xid (org.opendaylight.openflowplugin.api.openflow.device.Xid)1 ServiceException (org.opendaylight.openflowplugin.impl.services.util.ServiceException)1 FlowAndStatisticsMapList (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMapList)1 GroupDescStatsReply (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupDescStatsReply)1 GroupStatisticsReply (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupStatisticsReply)1 GroupDescStats (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats)1 AggregateFlowStatistics (org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.AggregateFlowStatistics)1 OfHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)1 NodeConnectorStatisticsAndPortNumberMap (org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap)1