2 * Copyright (c) 2015 Cisco Systems, Inc. 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.statistics.services;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.ArgumentMatchers.eq;
13 import com.google.common.util.concurrent.FutureCallback;
14 import java.util.Collections;
15 import java.util.concurrent.Future;
16 import java.util.concurrent.atomic.AtomicLong;
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.mockito.ArgumentCaptor;
20 import org.mockito.ArgumentMatchers;
21 import org.mockito.Captor;
22 import org.mockito.Mockito;
23 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
24 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStatsBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCase;
35 import org.opendaylight.yangtools.yang.common.RpcResult;
36 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
37 import org.opendaylight.yangtools.yang.common.Uint32;
38 import org.opendaylight.yangtools.yang.common.Uint64;
39 import org.opendaylight.yangtools.yang.common.Uint8;
42 * Test for {@link OpendaylightFlowTableStatisticsServiceImpl}.
44 public class OpendaylightFlowTableStatisticsServiceImplTest extends AbstractSingleStatsServiceTest {
45 private static final Uint8 TABLE_ID = Uint8.valueOf(123);
48 private ArgumentCaptor<MultipartRequestInput> requestInput;
50 private OpendaylightFlowTableStatisticsServiceImpl flowTableStatisticsService;
54 flowTableStatisticsService = new OpendaylightFlowTableStatisticsServiceImpl(rqContextStack, deviceContext,
55 new AtomicLong(), notificationPublishService);
59 public void testGetFlowTablesStatistics() throws Exception {
60 Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider)
61 .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class));
63 GetFlowTablesStatisticsInputBuilder input = new GetFlowTablesStatisticsInputBuilder()
64 .setNode(createNodeRef("unitProt:123"));
66 rpcResult = RpcResultBuilder.<Object>success(Collections.singletonList(
67 new MultipartReplyMessageBuilder()
68 .setVersion(EncodeConstants.OF_VERSION_1_3)
69 .setMultipartReplyBody(new MultipartReplyTableCaseBuilder()
70 .setMultipartReplyTable(new MultipartReplyTableBuilder()
71 .setTableStats(Collections.singletonList(new TableStatsBuilder()
72 .setActiveCount(Uint32.valueOf(31))
73 .setLookupCount(Uint64.valueOf(32))
74 .setMatchedCount(Uint64.valueOf(33))
75 .setMaxEntries(Uint32.valueOf(34))
76 .setName("test-table")
77 .setNwDstMask(Uint8.valueOf(35))
78 .setNwSrcMask(Uint8.valueOf(36))
86 final Future<RpcResult<GetFlowTablesStatisticsOutput>> resultFuture
87 = flowTableStatisticsService.getFlowTablesStatistics(input.build());
89 Assert.assertTrue(resultFuture.isDone());
90 final RpcResult<GetFlowTablesStatisticsOutput> rpcResult = resultFuture.get();
91 Assert.assertTrue(rpcResult.isSuccessful());
92 Assert.assertEquals(MultipartType.OFPMPTABLE, requestInput.getValue().getType());
94 Mockito.verify(notificationPublishService).offerNotification(ArgumentMatchers.any());
98 public void testBuildRequest() {
99 Xid xid = new Xid(Uint32.valueOf(42L));
100 GetFlowTablesStatisticsInputBuilder input = new GetFlowTablesStatisticsInputBuilder()
101 .setNode(createNodeRef("unitProt:123"));
102 final OfHeader request = flowTableStatisticsService.buildRequest(xid, input.build());
103 Assert.assertTrue(request instanceof MultipartRequestInput);
104 final MultipartRequestInput mpRequest = (MultipartRequestInput) request;
105 Assert.assertEquals(MultipartType.OFPMPTABLE, mpRequest.getType());
106 Assert.assertTrue(mpRequest.getMultipartRequestBody() instanceof MultipartRequestTableCase);
107 final MultipartRequestTableCase mpRequestBody =
108 (MultipartRequestTableCase) mpRequest.getMultipartRequestBody();
109 Assert.assertNotNull(mpRequestBody.getMultipartRequestTable().getEmpty());