2 * Copyright (c) 2013 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.controller.switchmanager.internal;
11 import java.net.InetAddress;
12 import java.net.UnknownHostException;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.Iterator;
17 import java.util.List;
20 import java.util.Map.Entry;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.osgi.framework.ServiceReference;
25 import org.osgi.framework.Bundle;
26 import javax.inject.Inject;
28 import org.eclipse.osgi.framework.console.CommandProvider;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.junit.Before;
32 import org.junit.After;
33 import org.junit.runner.RunWith;
34 import org.opendaylight.controller.sal.core.Actions;
35 import org.opendaylight.controller.sal.core.Bandwidth;
36 import org.opendaylight.controller.sal.core.Buffers;
37 import org.opendaylight.controller.sal.core.Capabilities;
38 import org.opendaylight.controller.sal.core.ConstructionException;
39 import org.opendaylight.controller.sal.core.Node;
40 import org.opendaylight.controller.sal.core.NodeConnector;
41 import org.opendaylight.controller.sal.core.State;
42 import org.opendaylight.controller.sal.core.TimeStamp;
43 import org.opendaylight.controller.sal.core.UpdateType;
44 import org.opendaylight.controller.sal.core.Property;
45 import org.opendaylight.controller.sal.core.Capabilities.CapabilitiesType;
46 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
47 import org.opendaylight.controller.sal.utils.NodeCreator;
48 import org.opendaylight.controller.sal.utils.Status;
49 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
50 import org.opendaylight.controller.switchmanager.*;
51 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
52 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
53 import org.opendaylight.controller.switchmanager.ISwitchManager;
55 import org.ops4j.pax.exam.junit.PaxExam;
56 import org.ops4j.pax.exam.util.Filter;
57 import org.osgi.framework.BundleContext;
58 import static org.junit.Assert.*;
59 import org.ops4j.pax.exam.junit.Configuration;
60 import static org.ops4j.pax.exam.CoreOptions.*;
62 import org.ops4j.pax.exam.Option;
63 import org.ops4j.pax.exam.util.PathUtils;
64 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
65 import org.ops4j.pax.exam.spi.reactors.PerClass;
67 @RunWith(PaxExam.class)
68 public class SwitchManagerIT {
69 private Logger log = LoggerFactory.getLogger(SwitchManagerIT.class);
70 // get the OSGI bundle context
72 private BundleContext bc;
74 private ISwitchManager switchManager = null;
76 // Configure the OSGi container
78 public Option[] config() {
80 systemProperty("logback.configurationFile").value(
81 "file:" + PathUtils.getBaseDir()
82 + "/src/test/resources/logback.xml"),
83 // To start OSGi console for inspection remotely
84 systemProperty("osgi.console").value("2401"),
85 // Set the systemPackages (used by clustering)
86 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
87 // List framework bundles
88 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
89 "1.0.0.v20120522-1841"),
90 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
91 "1.0.400.v20120522-2049"),
92 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
93 "3.3.100.v20120522-1822"),
94 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
95 "1.4.0.v20120522-1841"),
96 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
97 "0.8.0.v201108120515"),
98 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
99 "0.8.0.v201108120515"),
100 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
101 "0.8.0.v201110170705"),
102 // List logger bundles
103 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
104 mavenBundle("org.slf4j", "log4j-over-slf4j")
105 .versionAsInProject(),
106 mavenBundle("ch.qos.logback", "logback-core")
107 .versionAsInProject(),
108 mavenBundle("ch.qos.logback", "logback-classic")
109 .versionAsInProject(),
111 mavenBundle("org.opendaylight.controller", "switchmanager")
112 .versionAsInProject(),
113 mavenBundle("org.opendaylight.controller",
114 "switchmanager.implementation").versionAsInProject(),
115 mavenBundle("org.opendaylight.controller", "sal")
116 .versionAsInProject(),
117 mavenBundle("org.opendaylight.controller", "sal.implementation")
118 .versionAsInProject(),
119 mavenBundle("org.opendaylight.controller", "containermanager")
120 .versionAsInProject(),
121 mavenBundle("org.opendaylight.controller",
122 "containermanager.implementation").versionAsInProject(),
123 mavenBundle("org.opendaylight.controller",
124 "clustering.services").versionAsInProject(),
125 mavenBundle("org.opendaylight.controller", "clustering.stub")
126 .versionAsInProject(),
127 mavenBundle("org.opendaylight.controller", "configuration")
128 .versionAsInProject(),
129 mavenBundle("org.opendaylight.controller",
130 "configuration.implementation").versionAsInProject(),
131 mavenBundle("org.opendaylight.controller",
132 "protocol_plugins.stub").versionAsInProject(),
133 mavenBundle("org.jboss.spec.javax.transaction",
134 "jboss-transaction-api_1.1_spec").versionAsInProject(),
135 mavenBundle("org.apache.commons", "commons-lang3")
136 .versionAsInProject(),
137 mavenBundle("org.apache.felix",
138 "org.apache.felix.dependencymanager")
139 .versionAsInProject(), junitBundles());
142 private String stateToString(int state) {
146 case Bundle.INSTALLED:
148 case Bundle.RESOLVED:
150 case Bundle.UNINSTALLED:
151 return "UNINSTALLED";
153 return "Not CONVERTED";
158 public void areWeReady() {
160 boolean debugit = false;
161 Bundle b[] = bc.getBundles();
162 for (int i = 0; i < b.length; i++) {
163 int state = b[i].getState();
164 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
165 log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
166 + stateToString(state));
171 log.debug("Do some debugging because some bundle is "
175 // Assert if true, if false we are good to go!
176 assertFalse(debugit);
178 // Now lets create a hosttracker for testing purpose
179 ServiceReference s = bc.getServiceReference(ISwitchManager.class
182 this.switchManager = (ISwitchManager) bc.getService(s);
185 // If StatisticsManager is null, cannot run tests.
186 assertNotNull(this.switchManager);
190 public void testNodeProp() throws UnknownHostException {
191 assertNotNull(this.switchManager);
195 node = new Node("STUB", new Integer(0xCAFE));
196 } catch (ConstructionException e) {
197 // test failed if node cannot be created.
199 Assert.assertTrue(false);
201 Map<String, Property> propMap = this.switchManager.getNodeProps(node);
202 Assert.assertFalse(propMap.isEmpty());
204 Assert.assertTrue(this.switchManager.getNodeProp(node,
205 Capabilities.CapabilitiesPropName).equals(
206 new Capabilities((int) 3)));
207 Assert.assertTrue(this.switchManager.getNodeProp(node,
208 Actions.ActionsPropName).equals(new Actions((int) 2)));
209 Assert.assertTrue(this.switchManager.getNodeProp(node,
210 Buffers.BuffersPropName).equals(new Buffers((int) 1)));
211 Assert.assertTrue(this.switchManager.getNodeProp(node,
212 TimeStamp.TimeStampPropName).equals(
213 new TimeStamp(100000L, "connectedSince")));
217 public void testNodeConnectorProp() throws UnknownHostException {
218 assertNotNull(this.switchManager);
222 node = new Node("STUB", 0xCAFE);
223 nc = new NodeConnector("STUB", 0xCAFE, node);
224 } catch (ConstructionException e) {
227 Assert.assertTrue(false);
229 Map<String, Property> propMap = this.switchManager
230 .getNodeConnectorProps(nc);
231 Assert.assertFalse(propMap.isEmpty());
233 Assert.assertTrue(this.switchManager.getNodeConnectorProp(nc,
234 Capabilities.CapabilitiesPropName).equals(
235 new Capabilities(CapabilitiesType.FLOW_STATS_CAPABILITY
237 Assert.assertTrue(this.switchManager.getNodeConnectorProp(nc,
238 Bandwidth.BandwidthPropName).equals(
239 new Bandwidth(Bandwidth.BW1Gbps)));
240 Assert.assertTrue(this.switchManager.getNodeConnectorProp(nc,
241 State.StatePropName).equals(new State(State.EDGE_UP)));