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
9 package org.opendaylight.openflowplugin.impl.statistics.services.direct;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.lenient;
13 import static org.mockito.Mockito.when;
15 import java.math.BigInteger;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.runners.MockitoJUnitRunner;
21 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
22 import org.opendaylight.openflowplugin.api.OFConstants;
23 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
24 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
25 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
26 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
27 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
28 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
29 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
30 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
31 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
32 import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
33 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
34 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
35 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
36 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProviderFactory;
37 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
38 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
39 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
48 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
49 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
51 @RunWith(MockitoJUnitRunner.class)
52 public abstract class AbstractDirectStatisticsServiceTest {
53 protected static final Long PORT_NO = 1L;
54 protected static final BigInteger DATAPATH_ID = BigInteger.TEN;
55 protected static final short OF_VERSION = OFConstants.OFP_VERSION_1_3;
56 protected static final String NODE_ID = "openflow:10";
59 protected RequestContextStack requestContextStack;
61 protected DeviceFlowRegistry deviceFlowRegistry;
63 protected DeviceGroupRegistry deviceGroupRegistry;
65 protected DeviceMeterRegistry deviceMeterRegistry;
67 protected DeviceContext deviceContext;
69 protected ConnectionContext connectionContext;
71 protected FeaturesReply features;
73 protected MessageSpy messageSpy;
75 protected OutboundQueue outboundQueueProvider;
77 protected MultiMsgCollector multiMsgCollector;
79 protected TranslatorLibrary translatorLibrary;
81 protected DeviceState deviceState;
83 protected DeviceInfo deviceInfo;
85 protected GetFeaturesOutput getFeaturesOutput;
87 protected NodeConnectorId nodeConnectorId;
88 protected KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
89 protected ConvertorManager convertorManager;
90 protected MultipartWriterProvider multipartWriterProvider;
92 protected static NodeRef createNodeRef(String nodeIdValue) {
93 InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class)
94 .child(Node.class, new NodeKey(new NodeId(nodeIdValue)));
96 return new NodeRef(nodePath);
100 public void init() throws Exception {
101 nodeConnectorId = InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(
102 DATAPATH_ID, PORT_NO, OpenflowVersion.get(OF_VERSION));
104 nodeInstanceIdentifier = InstanceIdentifier
106 .child(Node.class, new NodeKey(new NodeId(NODE_ID)));
108 convertorManager = ConvertorManagerFactory.createDefaultManager();
109 lenient().when(deviceContext.getDeviceFlowRegistry()).thenReturn(deviceFlowRegistry);
110 lenient().when(deviceContext.getDeviceGroupRegistry()).thenReturn(deviceGroupRegistry);
111 lenient().when(deviceContext.getDeviceMeterRegistry()).thenReturn(deviceMeterRegistry);
112 when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
113 when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
114 lenient().when(deviceContext.getMultiMsgCollector(any())).thenReturn(multiMsgCollector);
115 lenient().when(deviceContext.oook()).thenReturn(translatorLibrary);
116 lenient().when(deviceContext.getDeviceState()).thenReturn(deviceState);
117 when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
118 when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
119 lenient().when(deviceInfo.getNodeId()).thenReturn(new NodeId(NODE_ID));
120 when(deviceInfo.getVersion()).thenReturn(OF_VERSION);
121 when(deviceInfo.getDatapathId()).thenReturn(DATAPATH_ID);
122 lenient().when(getFeaturesOutput.getVersion()).thenReturn(OF_VERSION);
123 lenient().when(getFeaturesOutput.getDatapathId()).thenReturn(DATAPATH_ID);
124 when(connectionContext.getFeatures()).thenReturn(features);
125 lenient().when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
126 lenient().when(features.getVersion()).thenReturn(OF_VERSION);
127 lenient().when(features.getDatapathId()).thenReturn(DATAPATH_ID);
128 multipartWriterProvider = MultipartWriterProviderFactory.createDefaultProvider(deviceContext);
132 protected abstract void setUp() throws Exception;
135 public abstract void testBuildRequestBody() throws Exception;
138 public abstract void testBuildReply() throws Exception;
141 public abstract void testStoreStatistics() throws Exception;