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
8 package org.opendaylight.openflowplugin.impl.services.singlelayer;
10 import static org.junit.Assert.assertEquals;
12 import java.util.Collections;
13 import java.util.concurrent.Future;
14 import org.junit.Test;
15 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowAggregateStatsBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.multipart.request.multipart.request.body.MultipartRequestFlowAggregateStats;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
26 import org.opendaylight.yangtools.yang.common.Uint64;
27 import org.opendaylight.yangtools.yang.common.Uint8;
29 public class SingleLayerAggregateFlowMultipartServiceTest extends ServiceMocking {
30 private static final Uint8 TABLE_ID = Uint8.valueOf(42);
31 private static final Uint64 BYTE_COUNT = Uint64.valueOf(10);
32 private SingleLayerAggregateFlowMultipartService service;
35 protected void setup() {
36 service = new SingleLayerAggregateFlowMultipartService(mockedRequestContextStack, mockedDeviceContext);
40 public void buildRequest() {
41 final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input = new
42 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder()
46 final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
47 assertEquals(MultipartRequest.class, ofHeader.implementedInterface());
49 final MultipartRequestFlowAggregateStats result =
50 (MultipartRequestFlowAggregateStats) ((MultipartRequest) ofHeader)
51 .getMultipartRequestBody();
53 assertEquals(TABLE_ID, result.getFlowAggregateStats().getTableId());
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());