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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.ArgumentMatchers.any;
14 import static org.mockito.ArgumentMatchers.eq;
15 import static org.mockito.Mockito.doAnswer;
16 import static org.mockito.Mockito.verify;
18 import com.google.common.util.concurrent.FutureCallback;
19 import java.util.List;
20 import java.util.concurrent.atomic.AtomicLong;
21 import org.junit.Test;
22 import org.mockito.ArgumentCaptor;
23 import org.mockito.Captor;
24 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
25 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder;
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.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStatsBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCase;
34 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
35 import org.opendaylight.yangtools.yang.common.Uint32;
36 import org.opendaylight.yangtools.yang.common.Uint64;
37 import org.opendaylight.yangtools.yang.common.Uint8;
40 * Test for {@link GetFlowTablesStatisticsImpl}.
43 public class GetFlowTablesStatisticsImplTest extends AbstractSingleStatsServiceTest {
44 private static final Uint8 TABLE_ID = Uint8.valueOf(123);
47 private ArgumentCaptor<MultipartRequestInput> requestInput;
49 private GetFlowTablesStatisticsImpl getFlowTablesStatistics;
53 getFlowTablesStatistics = new GetFlowTablesStatisticsImpl(rqContextStack, deviceContext, new AtomicLong(),
54 notificationPublishService);
58 public void testGetFlowTablesStatistics() throws Exception {
59 doAnswer(answerVoidToCallback).when(outboundQueueProvider)
60 .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class));
62 var input = new GetFlowTablesStatisticsInputBuilder()
63 .setNode(createNodeRef("unitProt:123"));
65 rpcResult = RpcResultBuilder.<Object>success(List.of(
66 new MultipartReplyMessageBuilder()
67 .setVersion(EncodeConstants.OF_VERSION_1_3)
68 .setMultipartReplyBody(new MultipartReplyTableCaseBuilder()
69 .setMultipartReplyTable(new MultipartReplyTableBuilder()
70 .setTableStats(List.of(new TableStatsBuilder()
71 .setActiveCount(Uint32.valueOf(31))
72 .setLookupCount(Uint64.valueOf(32))
73 .setMatchedCount(Uint64.valueOf(33))
74 .setMaxEntries(Uint32.valueOf(34))
75 .setName("test-table")
76 .setNwDstMask(Uint8.valueOf(35))
77 .setNwSrcMask(Uint8.valueOf(36))
85 final var resultFuture = getFlowTablesStatistics.invoke(input.build());
87 assertTrue(resultFuture.isDone());
88 final var rpcResult = resultFuture.get();
89 assertTrue(rpcResult.isSuccessful());
90 assertEquals(MultipartType.OFPMPTABLE, requestInput.getValue().getType());
92 verify(notificationPublishService).offerNotification(any());
96 public void testBuildRequest() {
97 final var xid = new Xid(Uint32.valueOf(42L));
98 final var input = new GetFlowTablesStatisticsInputBuilder()
99 .setNode(createNodeRef("unitProt:123"));
100 final var request = getFlowTablesStatistics.buildRequest(xid, input.build());
101 assertTrue(request instanceof MultipartRequestInput);
102 final var mpRequest = (MultipartRequestInput) request;
103 assertEquals(MultipartType.OFPMPTABLE, mpRequest.getType());
104 assertTrue(mpRequest.getMultipartRequestBody() instanceof MultipartRequestTableCase);
105 final var mpRequestBody = (MultipartRequestTableCase) mpRequest.getMultipartRequestBody();
106 assertNotNull(mpRequestBody.getMultipartRequestTable().getEmpty());