From ce4da5bc86d05c8a1cdc747630972f7cb5ac95c2 Mon Sep 17 00:00:00 2001 From: Kalvin Hom Date: Fri, 12 Apr 2013 16:32:32 -0700 Subject: [PATCH] Added protocol_plugins.stub that implements IPluginInReadService Modified statisticsmanager structure so that api and implementation are separate modules. Added Integration test for statisticsmanager Modified pom.xml for sonar integration test inclusion. When going to the Statistics Manager unit test, should also show integration percentage. If Sonar's integration widget is enabled, should also see coverage on dashboard. Change-Id: I3a2901eb41528008e1d2beb6f0f1f1a88392abf3 Signed-off-by: Kalvin Hom --- .../distribution/opendaylight/pom.xml | 5 +- opendaylight/protocol_plugins/stub/pom.xml | 63 ++++ .../stub/internal/Activator.java | 91 ++++++ .../stub/internal/ReadService.java | 170 ++++++++++ .../statisticsmanager/{ => api}/pom.xml | 53 ++-- .../statisticsmanager/IStatisticsManager.java | 0 .../statisticsmanager/implementation/pom.xml | 109 +++++++ .../statisticsmanager/internal/Activator.java | 1 - .../internal}/StatisticsManager.java | 3 +- .../internal}/StatisticsManagerTest.java | 55 ++-- .../src/test/resources/logback.xml | 13 + .../statisticsmanager/integrationtest/pom.xml | 95 ++++++ .../StatisticsManagerIntegrationTest.java | 290 ++++++++++++++++++ .../src/test/resources/logback.xml | 13 + 14 files changed, 901 insertions(+), 60 deletions(-) create mode 100644 opendaylight/protocol_plugins/stub/pom.xml create mode 100644 opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java create mode 100644 opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/ReadService.java rename opendaylight/statisticsmanager/{ => api}/pom.xml (55%) rename opendaylight/statisticsmanager/{ => api}/src/main/java/org/opendaylight/controller/statisticsmanager/IStatisticsManager.java (100%) create mode 100644 opendaylight/statisticsmanager/implementation/pom.xml rename opendaylight/statisticsmanager/{ => implementation}/src/main/java/org/opendaylight/controller/statisticsmanager/internal/Activator.java (97%) rename opendaylight/statisticsmanager/{src/main/java/org/opendaylight/controller/statisticsmanager => implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal}/StatisticsManager.java (96%) rename opendaylight/statisticsmanager/{src/test/java/org/opendaylight/controller/statisticsmanager => implementation/src/test/java/org/opendaylight/controller/statisticsmanager/internal}/StatisticsManagerTest.java (53%) create mode 100644 opendaylight/statisticsmanager/implementation/src/test/resources/logback.xml create mode 100644 opendaylight/statisticsmanager/integrationtest/pom.xml create mode 100644 opendaylight/statisticsmanager/integrationtest/src/test/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManagerIntegrationTest.java create mode 100644 opendaylight/statisticsmanager/integrationtest/src/test/resources/logback.xml diff --git a/opendaylight/distribution/opendaylight/pom.xml b/opendaylight/distribution/opendaylight/pom.xml index f6a7808b23..8a74689398 100644 --- a/opendaylight/distribution/opendaylight/pom.xml +++ b/opendaylight/distribution/opendaylight/pom.xml @@ -45,7 +45,9 @@ ../../containermanager/api ../../containermanager/implementation ../../switchmanager - ../../statisticsmanager + ../../statisticsmanager/api + ../../statisticsmanager/implementation + ../../statisticsmanager/integrationtest ../../topologymanager ../../usermanager ../../security @@ -83,6 +85,7 @@ ../../protocol_plugins/openflow + ../../protocol_plugins/stub ../../samples/simpleforwarding diff --git a/opendaylight/protocol_plugins/stub/pom.xml b/opendaylight/protocol_plugins/stub/pom.xml new file mode 100644 index 0000000000..36085c9e3b --- /dev/null +++ b/opendaylight/protocol_plugins/stub/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + org.opendaylight.controller + commons.opendaylight + 1.4.0-SNAPSHOT + ../../commons/opendaylight + + org.opendaylight.controller + protocol_plugins.stub + 0.4.0-SNAPSHOT + bundle + + + + org.apache.felix + maven-bundle-plugin + 2.3.6 + true + + + org.opendaylight.controller.sal.packet, + org.opendaylight.controller.sal.action, + org.opendaylight.controller.sal.discovery, + org.opendaylight.controller.sal.topology, + org.opendaylight.controller.sal.core, + org.opendaylight.controller.sal.flowprogrammer, + org.opendaylight.controller.sal.reader, + org.opendaylight.controller.sal.inventory, + org.opendaylight.controller.sal.match, + org.opendaylight.controller.sal.utils, + org.apache.commons.lang3.builder, + org.apache.commons.lang3.tuple, org.apache.felix.dm, + org.slf4j, org.eclipse.osgi.framework.console, + org.osgi.framework + + + org.opendaylight.controller.protocol_plugins.stub.internal + + + org.opendaylight.controller.protocol_plugins.stub.internal.Activator + + + + + + + + + org.opendaylight.controller + sal + 0.4.0-SNAPSHOT + + + junit + junit + 4.8.1 + test + + + \ No newline at end of file diff --git a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java new file mode 100644 index 0000000000..ad447b9584 --- /dev/null +++ b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java @@ -0,0 +1,91 @@ +package org.opendaylight.controller.protocol_plugins.stub.internal; + +import java.util.Dictionary; +import java.util.Hashtable; + +import org.apache.felix.dm.Component; + +import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; +import org.opendaylight.controller.sal.core.IContainerListener; +import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.controller.sal.discovery.IDiscoveryService; +import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService; +import org.opendaylight.controller.sal.inventory.IPluginInInventoryService; +import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService; +import org.opendaylight.controller.sal.packet.IPluginInDataPacketService; +import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService; +import org.opendaylight.controller.sal.reader.IPluginInReadService; +import org.opendaylight.controller.sal.reader.IReadService; +import org.opendaylight.controller.sal.topology.IPluginInTopologyService; +import org.opendaylight.controller.sal.topology.IPluginOutTopologyService; +import org.opendaylight.controller.sal.utils.GlobalConstants; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * stub protocol plugin Activator + * + * + */ +public class Activator extends ComponentActivatorAbstractBase { + protected static final Logger logger = LoggerFactory + .getLogger(Activator.class); + + /** + * Function called when the activator starts just after some initializations + * are done by the ComponentActivatorAbstractBase. + * + */ + public void init() { + } + + /** + * Function called when the activator stops just before the cleanup done by + * ComponentActivatorAbstractBase + * + */ + public void destroy() { + } + + /** + * Function that is used to communicate to dependency manager the list of + * known implementations for services inside a container + * + * + * @return An array containing all the CLASS objects that will be + * instantiated in order to get an fully working implementation + * Object + */ + public Object[] getImplementations() { + Object[] res = { ReadService.class }; + return res; + } + + /** + * Function that is called when configuration of the dependencies is + * required. + * + * @param c + * dependency manager Component object, used for configuring the + * dependencies exported and imported + * @param imp + * Implementation class that is being configured, needed as long + * as the same routine can configure multiple implementations + * @param containerName + * The containerName being configured, this allow also optional + * per-container different behavior if needed, usually should not + * be the case though. + */ + public void configureInstance(Component c, Object imp, String containerName) { + if (imp.equals(ReadService.class)) { + // export the service to be used by SAL + Dictionary props = new Hashtable(); + // Set the protocolPluginType property which will be used + // by SAL + props.put("protocolPluginType", Node.NodeIDType.OPENFLOW); + c.setInterface(IPluginInReadService.class.getName(), props); + } + } + +} diff --git a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/ReadService.java b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/ReadService.java new file mode 100644 index 0000000000..cf633a4fe6 --- /dev/null +++ b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/ReadService.java @@ -0,0 +1,170 @@ +package org.opendaylight.controller.protocol_plugins.stub.internal; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Dictionary; +import java.util.List; + +import org.apache.felix.dm.Component; +//import org.opendaylight.controller.protocol_plugin_stubs.IPluginReadServiceFilter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.opendaylight.controller.sal.action.Action; +import org.opendaylight.controller.sal.action.Drop; +import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.controller.sal.core.NodeConnector; +import org.opendaylight.controller.sal.flowprogrammer.Flow; +import org.opendaylight.controller.sal.match.Match; +import org.opendaylight.controller.sal.match.MatchType; +import org.opendaylight.controller.sal.reader.FlowOnNode; +import org.opendaylight.controller.sal.reader.IPluginInReadService; +import org.opendaylight.controller.sal.reader.NodeConnectorStatistics; +import org.opendaylight.controller.sal.reader.NodeDescription; + +/** + * Stub Implementation for IPluginInReadService used by SAL + * + * + */ +public class ReadService implements IPluginInReadService { + private static final Logger logger = LoggerFactory + .getLogger(ReadService.class); + + /** + * Function called by the dependency manager when all the required + * dependencies are satisfied + * + */ + void init() { + } + + /** + * Function called by the dependency manager when at least one dependency + * become unsatisfied or when the component is shutting down because for + * example bundle is being stopped. + * + */ + void destroy() { + } + + /** + * Function called by dependency manager after "init ()" is called and after + * the services provided by the class are registered in the service registry + * + */ + void start() { + } + + /** + * Function called by the dependency manager before the services exported by + * the component are unregistered, this will be followed by a "destroy ()" + * calls + * + */ + void stop() { + } + + @Override + public FlowOnNode readFlow(Node node, Flow flow, boolean cached) { + FlowOnNode fn1 = new FlowOnNode(flow); + fn1.setByteCount(100); + fn1.setDurationNanoseconds(400); + fn1.setDurationSeconds(40); + fn1.setTableId((byte) 0x1); + fn1.setPacketCount(200); + return fn1; + } + + @Override + public List readAllFlow(Node node, boolean cached) { + Flow flow = new Flow(); + + Match match = new Match(); + try { + match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1")); + } catch (UnknownHostException e) { + + } + flow.setMatch(match); + Action action = new Drop(); + + List actions = new ArrayList(); + actions.add(action); + flow.setActions(actions); + + FlowOnNode fn1 = new FlowOnNode(flow); + fn1.setByteCount(100); + fn1.setDurationNanoseconds(400); + fn1.setDurationSeconds(40); + fn1.setTableId((byte) 0x1); + fn1.setPacketCount(200); + + ArrayList list = new ArrayList(); + list.add(fn1); + return list; + } + + @Override + public NodeDescription readDescription(Node node, boolean cached) { + NodeDescription desc = new NodeDescription(); + desc.setDescription("This is a sample node description"); + desc.setHardware("stub hardware"); + desc.setSoftware("stub software"); + desc.setSerialNumber("123"); + desc.setManufacturer("opendaylight"); + return desc; + } + + @Override + public NodeConnectorStatistics readNodeConnector(NodeConnector connector, + boolean cached) { + NodeConnectorStatistics stats = new NodeConnectorStatistics(); + stats.setNodeConnector(connector); + stats.setCollisionCount(4); + stats.setReceiveByteCount(1000); + stats.setReceiveCRCErrorCount(1); + stats.setReceiveDropCount(2); + stats.setReceiveErrorCount(3); + stats.setReceiveFrameErrorCount(5); + stats.setReceiveOverRunErrorCount(6); + stats.setReceivePacketCount(250); + stats.setTransmitByteCount(5000); + stats.setTransmitDropCount(50); + stats.setTransmitErrorCount(10); + stats.setTransmitPacketCount(500); + + return stats; + } + + @Override + public List readAllNodeConnector(Node node, + boolean cached) { + NodeConnector nc = NodeConnector.fromStringNoNode("123", node); + NodeConnectorStatistics stats = new NodeConnectorStatistics(); + stats.setNodeConnector(nc); + stats.setCollisionCount(4); + stats.setReceiveByteCount(1000); + stats.setReceiveCRCErrorCount(1); + stats.setReceiveDropCount(2); + stats.setReceiveErrorCount(3); + stats.setReceiveFrameErrorCount(5); + stats.setReceiveOverRunErrorCount(6); + stats.setReceivePacketCount(250); + stats.setTransmitByteCount(5000); + stats.setTransmitDropCount(50); + stats.setTransmitErrorCount(10); + stats.setTransmitPacketCount(500); + + List result = new ArrayList(); + result.add(stats); + return result; + } + + @Override + public long getTransmitRate(NodeConnector connector) { + return 100; + } + +} diff --git a/opendaylight/statisticsmanager/pom.xml b/opendaylight/statisticsmanager/api/pom.xml similarity index 55% rename from opendaylight/statisticsmanager/pom.xml rename to opendaylight/statisticsmanager/api/pom.xml index 2b0b00e99c..67329ba5e0 100644 --- a/opendaylight/statisticsmanager/pom.xml +++ b/opendaylight/statisticsmanager/api/pom.xml @@ -1,44 +1,39 @@ - + 4.0.0 org.opendaylight.controller commons.opendaylight 1.4.0-SNAPSHOT - ../commons/opendaylight + ../../commons/opendaylight - org.opendaylight.controller statisticsmanager 0.4.0-SNAPSHOT bundle - - org.apache.felix - maven-bundle-plugin - 2.3.6 - true - - - - org.opendaylight.controller.forwardingrulesmanager, - org.opendaylight.controller.containermanager, - org.opendaylight.controller.sal.core, - org.opendaylight.controller.sal.flowprogrammer, - org.slf4j, - org.opendaylight.controller.sal.reader, - org.apache.felix.dm - - - org.opendaylight.controller.statisticsmanager.internal.Activator - - - org.opendaylight.controller.statisticsmanager - - - + org.apache.felix + maven-bundle-plugin + 2.3.6 + true + + + + org.opendaylight.controller.forwardingrulesmanager, + org.opendaylight.controller.containermanager, + org.opendaylight.controller.sal.core, + org.opendaylight.controller.sal.flowprogrammer, org.slf4j, + org.opendaylight.controller.sal.reader, + org.apache.felix.dm + + + org.opendaylight.controller.statisticsmanager + + + @@ -58,10 +53,10 @@ forwardingrulesmanager 0.4.0-SNAPSHOT - + org.opendaylight.controller clustering.services 0.4.0-SNAPSHOT - + \ No newline at end of file diff --git a/opendaylight/statisticsmanager/src/main/java/org/opendaylight/controller/statisticsmanager/IStatisticsManager.java b/opendaylight/statisticsmanager/api/src/main/java/org/opendaylight/controller/statisticsmanager/IStatisticsManager.java similarity index 100% rename from opendaylight/statisticsmanager/src/main/java/org/opendaylight/controller/statisticsmanager/IStatisticsManager.java rename to opendaylight/statisticsmanager/api/src/main/java/org/opendaylight/controller/statisticsmanager/IStatisticsManager.java diff --git a/opendaylight/statisticsmanager/implementation/pom.xml b/opendaylight/statisticsmanager/implementation/pom.xml new file mode 100644 index 0000000000..98bf15d274 --- /dev/null +++ b/opendaylight/statisticsmanager/implementation/pom.xml @@ -0,0 +1,109 @@ + + + 4.0.0 + + org.opendaylight.controller + commons.opendaylight + 1.4.0-SNAPSHOT + ../../commons/opendaylight + + org.opendaylight.controller + statisticsmanager.implementation + 0.4.0-SNAPSHOT + bundle + + + jacoco + reuseReports + target/jacobo.exec + target/jacoco-it.exec + java + + + + + + org.jacoco + jacoco-maven-plugin + 0.5.3.201107060350 + + + + + + org.apache.felix + maven-bundle-plugin + 2.3.6 + true + + + + org.opendaylight.controller.containermanager, + org.opendaylight.controller.sal.core, + org.opendaylight.controller.sal.flowprogrammer, org.slf4j, + org.opendaylight.controller.sal.reader, + org.opendaylight.controller.statisticsmanager, + org.opendaylight.controller.forwardingrulesmanager, + org.apache.felix.dm + + + org.opendaylight.controller.statisticsmanager.internal.Activator + + + + + + + + org.jacoco + jacoco-maven-plugin + + org.opendaylight.controller.* + + + + pre-test + + prepare-agent + + + + post-test + test + + report + + + + + + + + + org.opendaylight.controller + statisticsmanager + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + sal + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + containermanager + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + forwardingrulesmanager + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + clustering.services + 0.4.0-SNAPSHOT + + + \ No newline at end of file diff --git a/opendaylight/statisticsmanager/src/main/java/org/opendaylight/controller/statisticsmanager/internal/Activator.java b/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/Activator.java similarity index 97% rename from opendaylight/statisticsmanager/src/main/java/org/opendaylight/controller/statisticsmanager/internal/Activator.java rename to opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/Activator.java index e26b6b87d8..faba64a749 100644 --- a/opendaylight/statisticsmanager/src/main/java/org/opendaylight/controller/statisticsmanager/internal/Activator.java +++ b/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/Activator.java @@ -13,7 +13,6 @@ import org.apache.felix.dm.Component; import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; import org.opendaylight.controller.sal.reader.IReadService; import org.opendaylight.controller.statisticsmanager.IStatisticsManager; -import org.opendaylight.controller.statisticsmanager.StatisticsManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/opendaylight/statisticsmanager/src/main/java/org/opendaylight/controller/statisticsmanager/StatisticsManager.java b/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java similarity index 96% rename from opendaylight/statisticsmanager/src/main/java/org/opendaylight/controller/statisticsmanager/StatisticsManager.java rename to opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java index 6104c1b75a..f5f56fc70f 100644 --- a/opendaylight/statisticsmanager/src/main/java/org/opendaylight/controller/statisticsmanager/StatisticsManager.java +++ b/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java @@ -7,7 +7,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.statisticsmanager; +package org.opendaylight.controller.statisticsmanager.internal; import java.util.ArrayList; import java.util.HashMap; @@ -22,6 +22,7 @@ import org.opendaylight.controller.sal.reader.FlowOnNode; import org.opendaylight.controller.sal.reader.IReadService; import org.opendaylight.controller.sal.reader.NodeConnectorStatistics; import org.opendaylight.controller.sal.reader.NodeDescription; +import org.opendaylight.controller.statisticsmanager.IStatisticsManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/opendaylight/statisticsmanager/src/test/java/org/opendaylight/controller/statisticsmanager/StatisticsManagerTest.java b/opendaylight/statisticsmanager/implementation/src/test/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManagerTest.java similarity index 53% rename from opendaylight/statisticsmanager/src/test/java/org/opendaylight/controller/statisticsmanager/StatisticsManagerTest.java rename to opendaylight/statisticsmanager/implementation/src/test/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManagerTest.java index 41c5f766d4..45e9544b89 100644 --- a/opendaylight/statisticsmanager/src/test/java/org/opendaylight/controller/statisticsmanager/StatisticsManagerTest.java +++ b/opendaylight/statisticsmanager/implementation/src/test/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManagerTest.java @@ -1,28 +1,27 @@ - -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.statisticsmanager; - -import org.junit.Test; - -public class StatisticsManagerTest { - - @Test - public void test() { - StatisticsManager sm = new StatisticsManager(); - - sm.init(); - sm.start(); - sm.stop(); - sm.destroy(); - - - } - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.statisticsmanager.internal; + +import org.junit.Test; +import org.opendaylight.controller.statisticsmanager.internal.StatisticsManager; + +public class StatisticsManagerTest { + + @Test + public void test() { + StatisticsManager sm = new StatisticsManager(); + + sm.init(); + sm.start(); + sm.stop(); + sm.destroy(); + + } + +} diff --git a/opendaylight/statisticsmanager/implementation/src/test/resources/logback.xml b/opendaylight/statisticsmanager/implementation/src/test/resources/logback.xml new file mode 100644 index 0000000000..2d63ce5744 --- /dev/null +++ b/opendaylight/statisticsmanager/implementation/src/test/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + diff --git a/opendaylight/statisticsmanager/integrationtest/pom.xml b/opendaylight/statisticsmanager/integrationtest/pom.xml new file mode 100644 index 0000000000..592a3dd071 --- /dev/null +++ b/opendaylight/statisticsmanager/integrationtest/pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + + org.opendaylight.controller + commons.opendaylight + 1.4.0-SNAPSHOT + ../../commons/opendaylight + + org.opendaylight.controller + statisticsmanager.integrationtest + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + protocol_plugins.stub + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + sal + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + sal.implementation + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + containermanager + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + forwardingrulesmanager + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + clustering.services + 0.4.0-SNAPSHOT + + + org.opendaylight.controller + statisticsmanager + 0.4.0-SNAPSHOT + + + + + jacoco + ../implementation/target/jacoco.exec + ../implementaiton/target/jacoco-it.exec + java + + + + + + org.jacoco + jacoco-maven-plugin + 0.5.3.201107060350 + + + + + + org.jacoco + jacoco-maven-plugin + 0.5.3.201107060350 + + ../implementation/target/jacoco-it.exec + org.opendaylight.controller.* + + + + pre-test + + prepare-agent + + + + post-test + + true + + + + + + + \ No newline at end of file diff --git a/opendaylight/statisticsmanager/integrationtest/src/test/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManagerIntegrationTest.java b/opendaylight/statisticsmanager/integrationtest/src/test/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManagerIntegrationTest.java new file mode 100644 index 0000000000..24b96128e9 --- /dev/null +++ b/opendaylight/statisticsmanager/integrationtest/src/test/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManagerIntegrationTest.java @@ -0,0 +1,290 @@ +package org.opendaylight.controller.statisticsmanager.internal; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.Bundle; +import javax.inject.Inject; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.opendaylight.controller.forwardingrulesmanager.FlowEntry; +import org.opendaylight.controller.sal.action.Action; +import org.opendaylight.controller.sal.action.Drop; +import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.controller.sal.core.NodeConnector; +import org.opendaylight.controller.sal.flowprogrammer.Flow; +import org.opendaylight.controller.sal.match.Match; +import org.opendaylight.controller.sal.match.MatchType; +import org.opendaylight.controller.sal.reader.FlowOnNode; +import org.opendaylight.controller.sal.reader.NodeConnectorStatistics; +import org.opendaylight.controller.sal.reader.NodeDescription; +import org.opendaylight.controller.sal.utils.NodeCreator; +import org.opendaylight.controller.statisticsmanager.*; +import org.ops4j.pax.exam.junit.PaxExam; +import org.osgi.framework.BundleContext; +import static org.junit.Assert.*; +import org.ops4j.pax.exam.junit.Configuration; +import static org.ops4j.pax.exam.CoreOptions.*; + +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.util.PathUtils; + +@RunWith(PaxExam.class) +public class StatisticsManagerIntegrationTest { + private Logger log = LoggerFactory + .getLogger(StatisticsManagerIntegrationTest.class); + // get the OSGI bundle context + @Inject + private BundleContext bc; + + private IStatisticsManager manager = null; + + // Configure the OSGi container + @Configuration + public Option[] config() { + return options( + // + systemProperty("logback.configurationFile").value( + "file:" + PathUtils.getBaseDir() + + "/src/test/resources/logback.xml"), + // To start OSGi console for inspection remotely + systemProperty("osgi.console").value("2401"), + // Set the systemPackages (used by clustering) + systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"), + // List framework bundles + mavenBundle("equinoxSDK381", "org.eclipse.equinox.console", + "1.0.0.v20120522-1841"), + mavenBundle("equinoxSDK381", "org.eclipse.equinox.util", + "1.0.400.v20120522-2049"), + mavenBundle("equinoxSDK381", "org.eclipse.osgi.services", + "3.3.100.v20120522-1822"), + mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds", + "1.4.0.v20120522-1841"), + mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command", + "0.8.0.v201108120515"), + mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime", + "0.8.0.v201108120515"), + mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell", + "0.8.0.v201110170705"), + // List logger bundles + mavenBundle("org.slf4j", "slf4j-api", "1.7.2"), + mavenBundle("org.slf4j", "log4j-over-slf4j", "1.7.2"), + mavenBundle("ch.qos.logback", "logback-core", "1.0.9"), + mavenBundle("ch.qos.logback", "logback-classic", "1.0.9"), + // List all the bundles on which the test case depends + mavenBundle("org.opendaylight.controller", "sal", + "0.4.0-SNAPSHOT"), + mavenBundle("org.opendaylight.controller", + "sal.implementation", "0.4.0-SNAPSHOT"), + mavenBundle("org.opendaylight.controller", "statisticsmanager", + "0.4.0-SNAPSHOT"), + mavenBundle("org.opendaylight.controller", "statisticsmanager.implementation", + "0.4.0-SNAPSHOT"), + mavenBundle("org.opendaylight.controller", + "protocol_plugins.stub", "0.4.0-SNAPSHOT"), + // needed by statisticsmanager + mavenBundle("org.opendaylight.controller", "containermanager", + "0.4.0-SNAPSHOT"), + mavenBundle("org.opendaylight.controller", + "containermanager.implementation", "0.4.0-SNAPSHOT"), + mavenBundle("org.opendaylight.controller", + "forwardingrulesmanager", "0.4.0-SNAPSHOT"), + + mavenBundle("org.opendaylight.controller", + "clustering.services", "0.4.0-SNAPSHOT"), + mavenBundle("org.opendaylight.controller", + "clustering.services-implementation", "0.4.0-SNAPSHOT"), + + // needed by forwardingrulesmanager + mavenBundle("org.opendaylight.controller", "switchmanager", + "0.4.0-SNAPSHOT"), + mavenBundle("org.opendaylight.controller", "configuration", + "0.4.0-SNAPSHOT"), + + mavenBundle("org.opendaylight.controller", + "configuration.implementation", "0.4.0-SNAPSHOT"), + mavenBundle("org.opendaylight.controller", "hosttracker", + "0.4.0-SNAPSHOT"), + + // needed by hosttracker + mavenBundle("org.opendaylight.controller", "topologymanager", + "0.4.0-SNAPSHOT"), + + mavenBundle("org.jboss.spec.javax.transaction", + "jboss-transaction-api_1.1_spec", "1.0.1.Final"), + mavenBundle("org.apache.commons", "commons-lang3", "3.1"), + mavenBundle("org.apache.felix", + "org.apache.felix.dependencymanager", "3.1.0"), + junitBundles()); + } + + private String stateToString(int state) { + switch (state) { + case Bundle.ACTIVE: + return "ACTIVE"; + case Bundle.INSTALLED: + return "INSTALLED"; + case Bundle.RESOLVED: + return "RESOLVED"; + case Bundle.UNINSTALLED: + return "UNINSTALLED"; + default: + return "Not CONVERTED"; + } + } + + @Before + public void areWeReady() { + assertNotNull(bc); + boolean debugit = false; + Bundle b[] = bc.getBundles(); + for (int i = 0; i < b.length; i++) { + int state = b[i].getState(); + if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) { + log.debug("Bundle:" + b[i].getSymbolicName() + " state:" + + stateToString(state)); + debugit = true; + } + } + if (debugit) { + log.debug("Do some debugging because some bundle is " + + "unresolved"); + } + + // Assert if true, if false we are good to go! + assertFalse(debugit); + + ServiceReference r = bc.getServiceReference(IStatisticsManager.class + .getName()); + if (r != null) { + this.manager = (IStatisticsManager) bc.getService(r); + } + // If StatisticsManager is null, cannot run tests. + assertNotNull(this.manager); + + } + + @Test + public void testGetFlows() { + Node node = NodeCreator.createOFNode(1L); + List flows = this.manager.getFlows(node); + FlowOnNode fn = flows.get(0); + Assert.assertTrue(fn.getByteCount() == 100); + Assert.assertTrue(fn.getDurationNanoseconds() == 400); + Assert.assertTrue(fn.getDurationSeconds() == 40); + Assert.assertTrue(fn.getTableId() == (byte) 0x1); + Assert.assertTrue(fn.getPacketCount() == 200); + + Match match = new Match(); + try { + match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1")); + } catch (UnknownHostException e) { + fail("Couldn't create match"); + } + Assert.assertTrue(match.equals(fn.getFlow().getMatch())); + Assert.assertTrue(fn.getFlow().getActions().get(0).equals(new Drop())); + } + + @Test + public void testGetFlowStatistics() { + Flow flow = new Flow(); + + Match match = new Match(); + try { + match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1")); + } catch (UnknownHostException e) { + } + flow.setMatch(match); + Action action = new Drop(); + + List actions = new ArrayList(); + actions.add(action); + flow.setActions(actions); + + Node node = NodeCreator.createOFNode(1L); + FlowEntry fe = new FlowEntry("g1", "f1", flow, node); + List list = new ArrayList(); + list.add(fe); + FlowEntry fe2 = new FlowEntry("g1", "f2", flow, node); + list.add(fe2); + + Map> result = this.manager + .getFlowStatisticsForFlowList(null); + Assert.assertTrue(result.isEmpty()); + result = this.manager.getFlowStatisticsForFlowList(list); + List results = result.get(node); + FlowOnNode fn = results.get(0); + Assert.assertTrue(fn.getByteCount() == 100); + Assert.assertTrue(fn.getDurationNanoseconds() == 400); + Assert.assertTrue(fn.getDurationSeconds() == 40); + Assert.assertTrue(fn.getTableId() == (byte) 0x1); + Assert.assertTrue(fn.getPacketCount() == 200); + Assert.assertTrue(fn.getFlow().equals(flow)); + + } + + @Test + public void testGetFlowsNumber() { + Node node = NodeCreator.createOFNode(1L); + Assert.assertTrue(this.manager.getFlowsNumber(node) == 1); + } + + @Test + public void testGetNodeDescription() { + Node node = NodeCreator.createOFNode(1L); + NodeDescription desc = this.manager.getNodeDescription(node); + Assert.assertTrue(desc.getDescription().equals( + "This is a sample node description")); + Assert.assertTrue(desc.getHardware().equals("stub hardware")); + Assert.assertTrue(desc.getSoftware().equals("stub software")); + Assert.assertTrue(desc.getSerialNumber().equals("123")); + Assert.assertTrue(desc.getManufacturer().equals("opendaylight")); + + } + + @Test + public void testGetNodeConnectorStatistics() { + Node node = NodeCreator.createOFNode(1L); + List stats = this.manager + .getNodeConnectorStatistics(node); + NodeConnectorStatistics ns = stats.get(0); + Assert.assertTrue(ns.getCollisionCount() == 4); + Assert.assertTrue(ns.getReceiveByteCount() == 1000); + Assert.assertTrue(ns.getReceiveCRCErrorCount() == 1); + Assert.assertTrue(ns.getReceiveDropCount() == 2); + Assert.assertTrue(ns.getReceiveErrorCount() == 3); + Assert.assertTrue(ns.getReceiveFrameErrorCount() == 5); + Assert.assertTrue(ns.getReceiveOverRunErrorCount() == 6); + Assert.assertTrue(ns.getReceivePacketCount() == 250); + Assert.assertTrue(ns.getTransmitByteCount() == 5000); + Assert.assertTrue(ns.getTransmitDropCount() == 50); + Assert.assertTrue(ns.getTransmitErrorCount() == 10); + Assert.assertTrue(ns.getTransmitPacketCount() == 500); + + NodeConnector nc = ns.getNodeConnector(); + NodeConnectorStatistics ns2 = this.manager + .getNodeConnectorStatistics(nc); + Assert.assertTrue(ns2.getCollisionCount() == 4); + Assert.assertTrue(ns2.getReceiveByteCount() == 1000); + Assert.assertTrue(ns2.getReceiveCRCErrorCount() == 1); + Assert.assertTrue(ns2.getReceiveDropCount() == 2); + Assert.assertTrue(ns2.getReceiveErrorCount() == 3); + Assert.assertTrue(ns2.getReceiveFrameErrorCount() == 5); + Assert.assertTrue(ns2.getReceiveOverRunErrorCount() == 6); + Assert.assertTrue(ns2.getReceivePacketCount() == 250); + Assert.assertTrue(ns2.getTransmitByteCount() == 5000); + Assert.assertTrue(ns2.getTransmitDropCount() == 50); + Assert.assertTrue(ns2.getTransmitErrorCount() == 10); + Assert.assertTrue(ns2.getTransmitPacketCount() == 500); + } + +} diff --git a/opendaylight/statisticsmanager/integrationtest/src/test/resources/logback.xml b/opendaylight/statisticsmanager/integrationtest/src/test/resources/logback.xml new file mode 100644 index 0000000000..2d63ce5744 --- /dev/null +++ b/opendaylight/statisticsmanager/integrationtest/src/test/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + -- 2.36.6