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 static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
14 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
15 import static org.ops4j.pax.exam.CoreOptions.options;
16 import static org.ops4j.pax.exam.CoreOptions.systemPackages;
17 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
19 import java.net.UnknownHostException;
22 import javax.inject.Inject;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.opendaylight.controller.sal.core.Actions;
29 import org.opendaylight.controller.sal.core.Bandwidth;
30 import org.opendaylight.controller.sal.core.Buffers;
31 import org.opendaylight.controller.sal.core.Capabilities;
32 import org.opendaylight.controller.sal.core.Capabilities.CapabilitiesType;
33 import org.opendaylight.controller.sal.core.ConstructionException;
34 import org.opendaylight.controller.sal.core.Node;
35 import org.opendaylight.controller.sal.core.NodeConnector;
36 import org.opendaylight.controller.sal.core.Property;
37 import org.opendaylight.controller.sal.core.State;
38 import org.opendaylight.controller.sal.core.TimeStamp;
39 import org.opendaylight.controller.switchmanager.ISwitchManager;
40 import org.ops4j.pax.exam.Option;
41 import org.ops4j.pax.exam.junit.Configuration;
42 import org.ops4j.pax.exam.junit.PaxExam;
43 import org.ops4j.pax.exam.util.PathUtils;
44 import org.osgi.framework.Bundle;
45 import org.osgi.framework.BundleContext;
46 import org.osgi.framework.ServiceReference;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
50 @RunWith(PaxExam.class)
51 public class SwitchManagerIT {
52 private final Logger log = LoggerFactory.getLogger(SwitchManagerIT.class);
53 // get the OSGI bundle context
55 private BundleContext bc;
57 private ISwitchManager switchManager = null;
59 // Configure the OSGi container
61 public Option[] config() {
63 systemProperty("logback.configurationFile").value(
64 "file:" + PathUtils.getBaseDir()
65 + "/src/test/resources/logback.xml"),
66 // To start OSGi console for inspection remotely
67 systemProperty("osgi.console").value("2401"),
68 // Set the systemPackages (used by clustering)
69 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
70 // List framework bundles
71 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
72 "1.0.0.v20120522-1841"),
73 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
74 "1.0.400.v20120522-2049"),
75 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
76 "3.3.100.v20120522-1822"),
77 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
78 "1.4.0.v20120522-1841"),
79 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
80 "0.8.0.v201108120515"),
81 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
82 "0.8.0.v201108120515"),
83 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
84 "0.8.0.v201110170705"),
85 // List logger bundles
86 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
87 mavenBundle("org.slf4j", "log4j-over-slf4j")
88 .versionAsInProject(),
89 mavenBundle("ch.qos.logback", "logback-core")
90 .versionAsInProject(),
91 mavenBundle("ch.qos.logback", "logback-classic")
92 .versionAsInProject(),
93 mavenBundle("org.opendaylight.controller", "clustering.stub")
94 .versionAsInProject(),
95 mavenBundle("org.opendaylight.controller", "configuration")
96 .versionAsInProject(),
97 mavenBundle("org.opendaylight.controller",
98 "configuration.implementation").versionAsInProject(),
99 mavenBundle("org.opendaylight.controller", "containermanager")
100 .versionAsInProject(),
101 mavenBundle("org.opendaylight.controller",
102 "containermanager.implementation").versionAsInProject(),
103 mavenBundle("org.opendaylight.controller",
104 "clustering.services").versionAsInProject(),
105 mavenBundle("org.opendaylight.controller", "sal")
106 .versionAsInProject(),
107 mavenBundle("org.opendaylight.controller", "sal.implementation")
108 .versionAsInProject(),
109 mavenBundle("org.opendaylight.controller",
110 "protocol_plugins.stub").versionAsInProject(),
111 mavenBundle("org.opendaylight.controller", "switchmanager")
112 .versionAsInProject(),
113 mavenBundle("org.opendaylight.controller", "topologymanager").versionAsInProject(),
114 mavenBundle("org.opendaylight.controller", "hosttracker").versionAsInProject(),
115 mavenBundle("org.opendaylight.controller", "forwardingrulesmanager").versionAsInProject(),
116 mavenBundle("org.opendaylight.controller", "statisticsmanager").versionAsInProject(),
117 mavenBundle("org.opendaylight.controller",
118 "switchmanager.implementation").versionAsInProject(),
119 mavenBundle("org.jboss.spec.javax.transaction",
120 "jboss-transaction-api_1.1_spec").versionAsInProject(),
121 mavenBundle("org.apache.commons", "commons-lang3")
122 .versionAsInProject(),
123 mavenBundle("org.apache.felix",
124 "org.apache.felix.dependencymanager")
125 .versionAsInProject(), junitBundles());
128 private String stateToString(int state) {
132 case Bundle.INSTALLED:
134 case Bundle.RESOLVED:
136 case Bundle.UNINSTALLED:
137 return "UNINSTALLED";
139 return "Not CONVERTED";
144 public void areWeReady() {
146 boolean debugit = false;
147 Bundle b[] = bc.getBundles();
148 for (int i = 0; i < b.length; i++) {
149 int state = b[i].getState();
150 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
151 log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
152 + stateToString(state));
157 log.debug("Do some debugging because some bundle is "
161 // Assert if true, if false we are good to go!
162 assertFalse(debugit);
164 // Now lets create a hosttracker for testing purpose
165 ServiceReference s = bc.getServiceReference(ISwitchManager.class
168 this.switchManager = (ISwitchManager) bc.getService(s);
171 // If StatisticsManager is null, cannot run tests.
172 assertNotNull(this.switchManager);
176 public void testNodeProp() throws UnknownHostException {
177 assertNotNull(this.switchManager);
181 node = new Node("STUB", new Integer(0xCAFE));
182 } catch (ConstructionException e) {
183 // test failed if node cannot be created.
185 Assert.assertTrue(false);
187 Map<String, Property> propMap = this.switchManager.getNodeProps(node);
188 Assert.assertFalse(propMap.isEmpty());
190 Assert.assertTrue(this.switchManager.getNodeProp(node,
191 Capabilities.CapabilitiesPropName).equals(
192 new Capabilities(3)));
193 Assert.assertTrue(this.switchManager.getNodeProp(node,
194 Actions.ActionsPropName).equals(new Actions(2)));
195 Assert.assertTrue(this.switchManager.getNodeProp(node,
196 Buffers.BuffersPropName).equals(new Buffers(1)));
197 Assert.assertTrue(this.switchManager.getNodeProp(node,
198 TimeStamp.TimeStampPropName).equals(
199 new TimeStamp(100000L, "connectedSince")));
203 public void testNodeConnectorProp() throws UnknownHostException {
204 assertNotNull(this.switchManager);
208 node = new Node("STUB", 0xCAFE);
209 nc = new NodeConnector("STUB", 0xCAFE, node);
210 } catch (ConstructionException e) {
213 Assert.assertTrue(false);
215 Map<String, Property> propMap = this.switchManager
216 .getNodeConnectorProps(nc);
217 Assert.assertFalse(propMap.isEmpty());
219 Assert.assertTrue(this.switchManager.getNodeConnectorProp(nc,
220 Capabilities.CapabilitiesPropName).equals(
221 new Capabilities(CapabilitiesType.FLOW_STATS_CAPABILITY
223 Assert.assertTrue(this.switchManager.getNodeConnectorProp(nc,
224 Bandwidth.BandwidthPropName).equals(
225 new Bandwidth(Bandwidth.BW1Gbps)));
226 Assert.assertTrue(this.switchManager.getNodeConnectorProp(nc,
227 State.StatePropName).equals(new State(State.EDGE_UP)));