Changed sal version to 0.5.0-SNAPSHOT 83/283/6
authortaochang <taochang@cisco.com>
Thu, 2 May 2013 20:06:29 +0000 (13:06 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 3 May 2013 16:42:55 +0000 (16:42 +0000)
Moved switchmanager.integrationteststub into protoco_plugins.stub
Removed non-source code files.
Added integration test for switchmanager bundle

Change-Id: I2dd2cbffe9e30224dcf2e03b3f11da465baec09f
Signed-off-by: taochang <taochang@cisco.com>
opendaylight/distribution/opendaylight/pom.xml
opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/Activator.java
opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/InventoryService.java [new file with mode: 0644]
opendaylight/switchmanager/integrationtest/pom.xml [new file with mode: 0644]
opendaylight/switchmanager/integrationtest/src/test/java/org/opendaylight/controller/switchmanager/internal/SwitchmanagerIntegrationTest.java [new file with mode: 0644]

index 4eef0a2..986f074 100644 (file)
@@ -51,6 +51,7 @@
     <module>../../containermanager/implementation</module>
     <module>../../switchmanager/api</module>
     <module>../../switchmanager/implementation</module>
+    <module>../../switchmanager/integrationtest</module>
     <module>../../statisticsmanager/api</module>
     <module>../../statisticsmanager/implementation</module>
     <module>../../statisticsmanager/integrationtest</module>
index ad447b9..cf93fb0 100644 (file)
@@ -58,7 +58,7 @@ public class Activator extends ComponentActivatorAbstractBase {
      *         Object
      */
     public Object[] getImplementations() {
-        Object[] res = { ReadService.class };
+        Object[] res = { ReadService.class, InventoryService.class };
         return res;
     }
 
@@ -86,6 +86,14 @@ public class Activator extends ComponentActivatorAbstractBase {
             props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
             c.setInterface(IPluginInReadService.class.getName(), props);
         }
-    }
 
+        if (imp.equals(InventoryService.class)) {
+            // export the service to be used by SAL
+            Dictionary<String, Object> props = new Hashtable<String, Object>();
+            // Set the protocolPluginType property which will be used
+            // by SAL
+            props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
+            c.setInterface(IPluginInInventoryService.class.getName(), props);
+        }
+    }
 }
diff --git a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/InventoryService.java b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/InventoryService.java
new file mode 100644 (file)
index 0000000..54b4ea1
--- /dev/null
@@ -0,0 +1,141 @@
+package org.opendaylight.controller.protocol_plugins.stub.internal;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.felix.dm.Component;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.opendaylight.controller.sal.core.Actions;
+import org.opendaylight.controller.sal.core.Bandwidth;
+import org.opendaylight.controller.sal.core.Buffers;
+import org.opendaylight.controller.sal.core.Capabilities;
+import org.opendaylight.controller.sal.core.Capabilities.CapabilitiesType;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.controller.sal.core.State;
+import org.opendaylight.controller.sal.core.Tables;
+import org.opendaylight.controller.sal.core.TimeStamp;
+import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
+import org.opendaylight.controller.sal.utils.NodeCreator;
+import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
+
+/**
+ * Stub Implementation for IPluginInReadService used by SAL
+ *
+ *
+ */
+public class InventoryService implements IPluginInInventoryService {
+    private static final Logger logger = LoggerFactory
+            .getLogger(InventoryService.class);
+
+    private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties are maintained in global container only
+    private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties are maintained in global container only
+
+
+    /**
+     * Function called by the dependency manager when all the required
+     * dependencies are satisfied
+     *
+     */
+    void init() {
+        nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
+        nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
+
+    }
+
+    /**
+     * 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() {
+    }
+
+    /**
+     * Retrieve nodes from openflow
+     */
+    @Override
+    public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
+
+        //  setup nodeProps
+        Map<String, Property> propMap = new HashMap<String, Property>();
+
+        Tables t = new Tables((byte)1);
+        propMap.put(Tables.TablesPropName, t);
+        Capabilities c = new Capabilities((int)3);
+        propMap.put(Capabilities.CapabilitiesPropName, c);
+        Actions a = new Actions((int)2);
+        propMap.put(Actions.ActionsPropName, a);
+        Buffers b = new Buffers((int)1);
+        propMap.put(Buffers.BuffersPropName, b);
+        Long connectedSinceTime = 100000L;
+        TimeStamp timeStamp = new TimeStamp(connectedSinceTime,
+                "connectedSince");
+        propMap.put(TimeStamp.TimeStampPropName, timeStamp);
+
+        // setup property map for all nodes
+        Node node;
+        node = NodeCreator.createOFNode(2L);
+        nodeProps.put(node, propMap);
+
+        return nodeProps;
+    }
+
+    /**
+     * Retrieve nodeConnectors from openflow
+     */
+    @Override
+    public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
+            Boolean refresh) {
+
+        //  setup nodeConnectorProps
+        Map<String, Property> ncPropMap = new HashMap<String, Property>();
+        Capabilities cap = new Capabilities
+                (CapabilitiesType.FLOW_STATS_CAPABILITY.getValue());
+        ncPropMap.put(Capabilities.CapabilitiesPropName, cap);
+        Bandwidth bw = new Bandwidth (Bandwidth.BW1Gbps);
+        ncPropMap.put(Bandwidth.BandwidthPropName, bw);
+        State st = new State (State.EDGE_UP);
+        ncPropMap.put(State.StatePropName, st);
+
+        // setup property map for all node connectors
+        NodeConnector nc = NodeConnectorCreator.createOFNodeConnector
+                ((short)2, NodeCreator.createOFNode(3L));
+        nodeConnectorProps.put(nc, ncPropMap);
+
+        return nodeConnectorProps;
+    }
+
+
+}
diff --git a/opendaylight/switchmanager/integrationtest/pom.xml b/opendaylight/switchmanager/integrationtest/pom.xml
new file mode 100644 (file)
index 0000000..bdf00f4
--- /dev/null
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.controller</groupId>
+    <artifactId>commons.opendaylight</artifactId>
+    <version>1.4.0-SNAPSHOT</version>
+    <relativePath>../../../opendaylight/commons/opendaylight</relativePath>
+  </parent>
+
+  <groupId>org.opendaylight.controller</groupId>
+  <artifactId>switchmanager.integrationtest</artifactId>
+  <version>0.4.0-SNAPSHOT</version>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>switchmanager</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+      <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>switchmanager.implementation</artifactId>
+         <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+     <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal</artifactId>
+      <version>0.5.0-SNAPSHOT</version>
+    </dependency>
+     <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal.implementation</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>containermanager</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>containermanager.implementation</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>clustering.services</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>clustering.stub</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>configuration</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>configuration.implementation</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>protocol_plugins.stub</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+  <properties>
+    <!-- Sonar jacoco plugin to get integration test coverage info -->
+    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
+    <sonar.jacoco.reportPath>../implementation/target/jacoco.exec</sonar.jacoco.reportPath>
+    <sonar.jacoco.itReportPath>../implementaiton/target/jacoco-it.exec</sonar.jacoco.itReportPath>
+    <sonar.language>java</sonar.language>
+  </properties>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.jacoco</groupId>
+          <artifactId>jacoco-maven-plugin</artifactId>
+          <version>0.5.3.201107060350</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>org.jacoco</groupId>
+        <artifactId>jacoco-maven-plugin</artifactId>
+        <version>0.5.3.201107060350</version>
+        <configuration>
+          <destFile>../implementation/target/jacoco-it.exec</destFile>
+          <includes>org.opendaylight.controller.*</includes>
+        </configuration>
+        <executions>
+          <execution>
+            <id>pre-test</id>
+            <goals>
+              <goal>prepare-agent</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>post-test</id>
+            <configuration>
+              <skip>true</skip>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/opendaylight/switchmanager/integrationtest/src/test/java/org/opendaylight/controller/switchmanager/internal/SwitchmanagerIntegrationTest.java b/opendaylight/switchmanager/integrationtest/src/test/java/org/opendaylight/controller/switchmanager/internal/SwitchmanagerIntegrationTest.java
new file mode 100644 (file)
index 0000000..450a717
--- /dev/null
@@ -0,0 +1,230 @@
+
+/*
+ * 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.switchmanager.internal;
+
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Bundle;
+import javax.inject.Inject;
+
+import org.eclipse.osgi.framework.console.CommandProvider;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.runner.RunWith;
+import org.opendaylight.controller.sal.core.Actions;
+import org.opendaylight.controller.sal.core.Bandwidth;
+import org.opendaylight.controller.sal.core.Buffers;
+import org.opendaylight.controller.sal.core.Capabilities;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.State;
+import org.opendaylight.controller.sal.core.TimeStamp;
+import org.opendaylight.controller.sal.core.UpdateType;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.controller.sal.core.Capabilities.CapabilitiesType;
+import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
+import org.opendaylight.controller.sal.utils.NodeCreator;
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
+import org.opendaylight.controller.switchmanager.*;
+import org.opendaylight.controller.configuration.IConfigurationContainerAware;
+import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
+import org.opendaylight.controller.switchmanager.ISwitchManager;
+
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.util.Filter;
+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;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+@RunWith(PaxExam.class)
+public class SwitchmanagerIntegrationTest {
+    private Logger log = LoggerFactory
+            .getLogger(SwitchmanagerIntegrationTest.class);
+    // get the OSGI bundle context
+    @Inject
+    private BundleContext bc;
+
+    private ISwitchManager switchManager = 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"),
+
+                mavenBundle("org.opendaylight.controller", "switchmanager",
+                        "0.4.0-SNAPSHOT"),
+                mavenBundle("org.opendaylight.controller", "switchmanager.implementation",
+                        "0.4.0-SNAPSHOT"),
+                mavenBundle("org.opendaylight.controller", "sal",
+                        "0.5.0-SNAPSHOT"),
+                mavenBundle("org.opendaylight.controller", "sal.implementation",
+                        "0.4.0-SNAPSHOT"),
+               mavenBundle("org.opendaylight.controller", "containermanager",
+                        "0.4.0-SNAPSHOT"),
+               mavenBundle("org.opendaylight.controller", "containermanager.implementation",
+                       "0.4.0-SNAPSHOT"),
+               mavenBundle("org.opendaylight.controller", "clustering.services",
+                       "0.4.0-SNAPSHOT"),
+               mavenBundle("org.opendaylight.controller", "clustering.stub",
+                       "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",
+                        "protocol_plugins.stub", "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);
+
+         // Now lets create a hosttracker for testing purpose
+         ServiceReference s = bc
+             .getServiceReference(ISwitchManager.class.getName());
+         if (s != null) {
+                 this.switchManager = (ISwitchManager)bc.getService(s);
+         }
+
+         // If StatisticsManager is null, cannot run tests.
+         assertNotNull(this.switchManager);
+    }
+
+
+    @Test
+    public void testNodeProp() throws UnknownHostException {
+        assertNotNull(this.switchManager);
+
+        Node node = NodeCreator.createOFNode((long)2);
+        Map<String, Property> propMap = this.switchManager.getNodeProps(node);
+        Assert.assertFalse(propMap.isEmpty());
+
+        Assert.assertTrue(this.switchManager.getNodeProp
+                (node, Capabilities.CapabilitiesPropName)
+                .equals(new Capabilities((int)3)));
+        Assert.assertTrue(this.switchManager.getNodeProp
+                (node, Actions.ActionsPropName)
+                .equals(new Actions((int)2)));
+        Assert.assertTrue(this.switchManager.getNodeProp
+                (node, Buffers.BuffersPropName)
+                .equals(new Buffers((int)1)));
+        Assert.assertTrue(this.switchManager.getNodeProp
+                (node, TimeStamp.TimeStampPropName)
+                .equals(new TimeStamp(100000L, "connectedSince")));
+    }
+
+    @Test
+    public void testNodeConnectorProp() throws UnknownHostException {
+        assertNotNull(this.switchManager);
+
+        NodeConnector nc = NodeConnectorCreator.createOFNodeConnector
+                ((short)2, NodeCreator.createOFNode((long)3));
+        Map<String, Property> propMap = this.switchManager.getNodeConnectorProps(nc);
+        Assert.assertFalse(propMap.isEmpty());
+
+        Assert.assertTrue(this.switchManager.getNodeConnectorProp
+                (nc, Capabilities.CapabilitiesPropName)
+                .equals(new Capabilities
+                        (CapabilitiesType.FLOW_STATS_CAPABILITY.getValue())));
+        Assert.assertTrue(this.switchManager.getNodeConnectorProp
+                (nc, Bandwidth.BandwidthPropName)
+                .equals(new Bandwidth (Bandwidth.BW1Gbps)));
+        Assert.assertTrue(this.switchManager.getNodeConnectorProp
+                (nc, State.StatePropName)
+                .equals(new State (State.EDGE_UP)));
+    }
+}