3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.switchmanager.internal;
13 import java.net.InetAddress;
14 import java.net.UnknownHostException;
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.HashSet;
18 import java.util.Iterator;
19 import java.util.List;
22 import java.util.Map.Entry;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.osgi.framework.ServiceReference;
27 import org.osgi.framework.Bundle;
28 import javax.inject.Inject;
30 import org.eclipse.osgi.framework.console.CommandProvider;
31 import org.junit.Assert;
32 import org.junit.Test;
33 import org.junit.Before;
34 import org.junit.After;
35 import org.junit.runner.RunWith;
36 import org.opendaylight.controller.sal.core.Actions;
37 import org.opendaylight.controller.sal.core.Bandwidth;
38 import org.opendaylight.controller.sal.core.Buffers;
39 import org.opendaylight.controller.sal.core.Capabilities;
40 import org.opendaylight.controller.sal.core.Node;
41 import org.opendaylight.controller.sal.core.NodeConnector;
42 import org.opendaylight.controller.sal.core.State;
43 import org.opendaylight.controller.sal.core.TimeStamp;
44 import org.opendaylight.controller.sal.core.UpdateType;
45 import org.opendaylight.controller.sal.core.Property;
46 import org.opendaylight.controller.sal.core.Capabilities.CapabilitiesType;
47 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
48 import org.opendaylight.controller.sal.utils.NodeCreator;
49 import org.opendaylight.controller.sal.utils.Status;
50 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
51 import org.opendaylight.controller.switchmanager.*;
52 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
53 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
54 import org.opendaylight.controller.switchmanager.ISwitchManager;
56 import org.ops4j.pax.exam.junit.PaxExam;
57 import org.ops4j.pax.exam.util.Filter;
58 import org.osgi.framework.BundleContext;
59 import static org.junit.Assert.*;
60 import org.ops4j.pax.exam.junit.Configuration;
61 import static org.ops4j.pax.exam.CoreOptions.*;
63 import org.ops4j.pax.exam.Option;
64 import org.ops4j.pax.exam.util.PathUtils;
65 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
66 import org.ops4j.pax.exam.spi.reactors.PerClass;
68 @RunWith(PaxExam.class)
69 public class SwitchmanagerIntegrationTest {
70 private Logger log = LoggerFactory
71 .getLogger(SwitchmanagerIntegrationTest.class);
72 // get the OSGI bundle context
74 private BundleContext bc;
76 private ISwitchManager switchManager = null;
78 // Configure the OSGi container
80 public Option[] config() {
82 systemProperty("logback.configurationFile").value(
83 "file:" + PathUtils.getBaseDir()
84 + "/src/test/resources/logback.xml"),
85 // To start OSGi console for inspection remotely
86 systemProperty("osgi.console").value("2401"),
87 // Set the systemPackages (used by clustering)
88 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
89 // List framework bundles
90 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
91 "1.0.0.v20120522-1841"),
92 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
93 "1.0.400.v20120522-2049"),
94 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
95 "3.3.100.v20120522-1822"),
96 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
97 "1.4.0.v20120522-1841"),
98 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
99 "0.8.0.v201108120515"),
100 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
101 "0.8.0.v201108120515"),
102 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
103 "0.8.0.v201110170705"),
104 // List logger bundles
105 mavenBundle("org.slf4j", "slf4j-api", "1.7.2"),
106 mavenBundle("org.slf4j", "log4j-over-slf4j", "1.7.2"),
107 mavenBundle("ch.qos.logback", "logback-core", "1.0.9"),
108 mavenBundle("ch.qos.logback", "logback-classic", "1.0.9"),
110 mavenBundle("org.opendaylight.controller", "switchmanager",
112 mavenBundle("org.opendaylight.controller", "switchmanager.implementation",
114 mavenBundle("org.opendaylight.controller", "sal",
116 mavenBundle("org.opendaylight.controller", "sal.implementation",
118 mavenBundle("org.opendaylight.controller", "containermanager",
120 mavenBundle("org.opendaylight.controller", "containermanager.implementation",
122 mavenBundle("org.opendaylight.controller", "clustering.services",
124 mavenBundle("org.opendaylight.controller", "clustering.stub",
126 mavenBundle("org.opendaylight.controller", "configuration",
128 mavenBundle("org.opendaylight.controller", "configuration.implementation",
130 mavenBundle("org.opendaylight.controller",
131 "protocol_plugins.stub", "0.4.0-SNAPSHOT"),
132 mavenBundle("org.jboss.spec.javax.transaction",
133 "jboss-transaction-api_1.1_spec", "1.0.1.Final"),
134 mavenBundle("org.apache.commons", "commons-lang3", "3.1"),
135 mavenBundle("org.apache.felix",
136 "org.apache.felix.dependencymanager", "3.1.0"),
140 private String stateToString(int state) {
144 case Bundle.INSTALLED:
146 case Bundle.RESOLVED:
148 case Bundle.UNINSTALLED:
149 return "UNINSTALLED";
151 return "Not CONVERTED";
156 public void areWeReady() {
158 boolean debugit = false;
159 Bundle b[] = bc.getBundles();
160 for (int i = 0; i < b.length; i++) {
161 int state = b[i].getState();
162 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
163 log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
164 + stateToString(state));
169 log.debug("Do some debugging because some bundle is "
173 // Assert if true, if false we are good to go!
174 assertFalse(debugit);
176 // Now lets create a hosttracker for testing purpose
177 ServiceReference s = bc
178 .getServiceReference(ISwitchManager.class.getName());
180 this.switchManager = (ISwitchManager)bc.getService(s);
183 // If StatisticsManager is null, cannot run tests.
184 assertNotNull(this.switchManager);
189 public void testNodeProp() throws UnknownHostException {
190 assertNotNull(this.switchManager);
192 Node node = NodeCreator.createOFNode((long)2);
193 Map<String, Property> propMap = this.switchManager.getNodeProps(node);
194 Assert.assertFalse(propMap.isEmpty());
196 Assert.assertTrue(this.switchManager.getNodeProp
197 (node, Capabilities.CapabilitiesPropName)
198 .equals(new Capabilities((int)3)));
199 Assert.assertTrue(this.switchManager.getNodeProp
200 (node, Actions.ActionsPropName)
201 .equals(new Actions((int)2)));
202 Assert.assertTrue(this.switchManager.getNodeProp
203 (node, Buffers.BuffersPropName)
204 .equals(new Buffers((int)1)));
205 Assert.assertTrue(this.switchManager.getNodeProp
206 (node, TimeStamp.TimeStampPropName)
207 .equals(new TimeStamp(100000L, "connectedSince")));
211 public void testNodeConnectorProp() throws UnknownHostException {
212 assertNotNull(this.switchManager);
214 NodeConnector nc = NodeConnectorCreator.createOFNodeConnector
215 ((short)2, NodeCreator.createOFNode((long)3));
216 Map<String, Property> propMap = this.switchManager.getNodeConnectorProps(nc);
217 Assert.assertFalse(propMap.isEmpty());
219 Assert.assertTrue(this.switchManager.getNodeConnectorProp
220 (nc, Capabilities.CapabilitiesPropName)
221 .equals(new Capabilities
222 (CapabilitiesType.FLOW_STATS_CAPABILITY.getValue())));
223 Assert.assertTrue(this.switchManager.getNodeConnectorProp
224 (nc, Bandwidth.BandwidthPropName)
225 .equals(new Bandwidth (Bandwidth.BW1Gbps)));
226 Assert.assertTrue(this.switchManager.getNodeConnectorProp
227 (nc, State.StatePropName)
228 .equals(new State (State.EDGE_UP)));