2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.impl.services.singlelayer;
11 import static org.junit.Assert.assertEquals;
13 import java.math.BigInteger;
14 import java.util.Collections;
15 import java.util.concurrent.Future;
16 import org.junit.Test;
17 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowAggregateStatsBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowAggregateStats;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
29 public class SingleLayerAggregateFlowMultipartServiceTest extends ServiceMocking {
30 private static final short TABLE_ID = 42;
31 private static final BigInteger BYTE_COUNT = BigInteger.TEN;
32 private SingleLayerAggregateFlowMultipartService service;
35 protected void setup() throws Exception {
36 service = new SingleLayerAggregateFlowMultipartService(mockedRequestContextStack, mockedDeviceContext);
40 public void buildRequest() throws Exception {
41 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input = new
42 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder()
46 final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
47 assertEquals(MultipartRequest.class, ofHeader.getImplementedInterface());
49 final MultipartRequestFlowAggregateStats result = MultipartRequestFlowAggregateStats.class.cast(
50 MultipartRequest.class.cast(ofHeader)
51 .getMultipartRequestBody());
53 assertEquals(TABLE_ID, result.getFlowAggregateStats().getTableId().shortValue());
57 public void handleAndReply() throws Exception {
58 mockSuccessfulFuture(Collections.singletonList(new MultipartReplyBuilder()
59 .setMultipartReplyBody(new MultipartReplyFlowAggregateStatsBuilder()
60 .setByteCount(new Counter64(BYTE_COUNT))
64 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input = new
65 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder()
69 final Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> rpcResultFuture = service
70 .handleAndReply(input);
72 final RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>
73 sendAggregateFlowMpRequestOutputRpcResult = rpcResultFuture.get();
75 assertEquals(BYTE_COUNT, sendAggregateFlowMpRequestOutputRpcResult
77 .getAggregatedFlowStatistics()
79 .getByteCount().getValue());