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 org.junit.Before;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 import org.mockito.Mock;
15 import org.mockito.runners.MockitoJUnitRunner;
16 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
17 import org.opendaylight.openflowplugin.api.OFConstants;
18 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
19 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
20 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
21 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
22 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
23 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
24 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
25 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
26 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
27 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
39 import java.math.BigInteger;
41 import static org.mockito.Matchers.any;
42 import static org.mockito.Mockito.when;
44 @RunWith(MockitoJUnitRunner.class)
45 public abstract class AbstractDirectStatisticsServiceTest {
46 protected static final Long PORT_NO = 1L;
47 protected static final BigInteger DATAPATH_ID = BigInteger.TEN;
48 protected static final short OF_VERSION = OFConstants.OFP_VERSION_1_3;
49 protected static final String NODE_ID = "openflow:1";
52 protected RequestContextStack requestContextStack;
54 protected DeviceContext deviceContext;
56 protected ConnectionContext connectionContext;
58 protected FeaturesReply features;
60 protected MessageSpy messageSpy;
62 protected OutboundQueue outboundQueueProvider;
64 protected MultiMsgCollector multiMsgCollector;
66 protected TranslatorLibrary translatorLibrary;
68 protected DeviceState deviceState;
70 protected GetFeaturesOutput getFeaturesOutput;
72 protected NodeConnectorId nodeConnectorId;
73 protected KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
75 protected static NodeRef createNodeRef(String nodeIdValue) {
76 InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class)
77 .child(Node.class, new NodeKey(new NodeId(nodeIdValue)));
79 return new NodeRef(nodePath);
83 public void init() throws Exception {
84 OpenflowPortsUtil.init();
86 nodeConnectorId = InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(
87 DATAPATH_ID, PORT_NO, OpenflowVersion.get(OF_VERSION));
89 nodeInstanceIdentifier = InstanceIdentifier
91 .child(Node.class, new NodeKey(new NodeId(NODE_ID)));
93 when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
94 when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
95 when(deviceContext.getMultiMsgCollector(any())).thenReturn(multiMsgCollector);
96 when(deviceContext.oook()).thenReturn(translatorLibrary);
97 when(deviceContext.getDeviceState()).thenReturn(deviceState);
98 when(deviceContext.getDeviceState()).thenReturn(deviceState);
99 when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
100 when(deviceState.getNodeId()).thenReturn(new NodeId(NODE_ID));
101 when(deviceState.getVersion()).thenReturn(OF_VERSION);
102 when(deviceState.getFeatures()).thenReturn(getFeaturesOutput);
103 when(getFeaturesOutput.getVersion()).thenReturn(OF_VERSION);
104 when(getFeaturesOutput.getDatapathId()).thenReturn(DATAPATH_ID);
105 when(connectionContext.getFeatures()).thenReturn(features);
106 when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
107 when(features.getVersion()).thenReturn(OF_VERSION);
108 when(features.getDatapathId()).thenReturn(DATAPATH_ID);
112 protected abstract void setUp() throws Exception;
115 public abstract void testBuildRequestBody() throws Exception;
118 public abstract void testBuildReply() throws Exception;
121 public abstract void testStoreStatistics() throws Exception;