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.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").versionAsInProject(),
72 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util").versionAsInProject(),
73 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services").versionAsInProject(),
74 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds").versionAsInProject(),
75 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command").versionAsInProject(),
76 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime").versionAsInProject(),
77 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell").versionAsInProject(),
78 // List logger bundles
79 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
80 mavenBundle("org.slf4j", "log4j-over-slf4j")
81 .versionAsInProject(),
82 mavenBundle("ch.qos.logback", "logback-core")
83 .versionAsInProject(),
84 mavenBundle("ch.qos.logback", "logback-classic")
85 .versionAsInProject(),
86 mavenBundle("org.opendaylight.controller", "clustering.stub")
87 .versionAsInProject(),
88 mavenBundle("org.opendaylight.controller", "configuration")
89 .versionAsInProject(),
90 mavenBundle("org.opendaylight.controller",
91 "configuration.implementation").versionAsInProject(),
92 mavenBundle("org.opendaylight.controller", "containermanager")
93 .versionAsInProject(),
94 mavenBundle("org.opendaylight.controller",
95 "containermanager.it.implementation").versionAsInProject(),
96 mavenBundle("org.opendaylight.controller",
97 "clustering.services").versionAsInProject(),
98 mavenBundle("org.opendaylight.controller", "sal")
99 .versionAsInProject(),
100 mavenBundle("org.opendaylight.controller", "sal.implementation")
101 .versionAsInProject(),
102 mavenBundle("org.opendaylight.controller",
103 "protocol_plugins.stub").versionAsInProject(),
104 mavenBundle("org.opendaylight.controller", "switchmanager")
105 .versionAsInProject(),
106 mavenBundle("org.opendaylight.controller", "topologymanager").versionAsInProject(),
107 mavenBundle("org.opendaylight.controller", "hosttracker").versionAsInProject(),
108 mavenBundle("org.opendaylight.controller", "forwardingrulesmanager").versionAsInProject(),
109 mavenBundle("org.opendaylight.controller", "statisticsmanager").versionAsInProject(),
110 mavenBundle("org.opendaylight.controller",
111 "switchmanager.implementation").versionAsInProject(),
112 mavenBundle("org.jboss.spec.javax.transaction",
113 "jboss-transaction-api_1.1_spec").versionAsInProject(),
114 mavenBundle("org.apache.commons", "commons-lang3")
115 .versionAsInProject(),
116 mavenBundle("org.apache.felix",
117 "org.apache.felix.dependencymanager")
118 .versionAsInProject(), junitBundles());
121 private String stateToString(int state) {
125 case Bundle.INSTALLED:
127 case Bundle.RESOLVED:
129 case Bundle.UNINSTALLED:
130 return "UNINSTALLED";
132 return "Not CONVERTED";
137 public void areWeReady() {
139 boolean debugit = false;
140 Bundle b[] = bc.getBundles();
141 for (int i = 0; i < b.length; i++) {
142 int state = b[i].getState();
143 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
144 log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
145 + stateToString(state));
150 log.debug("Do some debugging because some bundle is "
154 // Assert if true, if false we are good to go!
155 assertFalse(debugit);
157 // Now lets create a hosttracker for testing purpose
158 ServiceReference<?> s = bc.getServiceReference(ISwitchManager.class
161 this.switchManager = (ISwitchManager) bc.getService(s);
164 // If StatisticsManager is null, cannot run tests.
165 assertNotNull(this.switchManager);
169 public void testNodeProp() throws UnknownHostException {
170 assertNotNull(this.switchManager);
174 node = new Node("STUB", new Integer(0xCAFE));
175 } catch (ConstructionException e) {
176 // test failed if node cannot be created.
178 Assert.assertTrue(false);
180 Map<String, Property> propMap = this.switchManager.getNodeProps(node);
181 Assert.assertFalse(propMap.isEmpty());
183 Assert.assertTrue(this.switchManager.getNodeProp(node,
184 Capabilities.CapabilitiesPropName).equals(
185 new Capabilities(3)));
186 Assert.assertTrue(this.switchManager.getNodeProp(node,
187 Actions.ActionsPropName).equals(new Actions(2)));
188 Assert.assertTrue(this.switchManager.getNodeProp(node,
189 Buffers.BuffersPropName).equals(new Buffers(1)));
190 Assert.assertTrue(this.switchManager.getNodeProp(node,
191 TimeStamp.TimeStampPropName).equals(
192 new TimeStamp(100000L, "connectedSince")));
196 public void testNodeConnectorProp() throws UnknownHostException {
197 assertNotNull(this.switchManager);
201 node = new Node("STUB", 0xCAFE);
202 nc = new NodeConnector("STUB", 0xCAFE, node);
203 } catch (ConstructionException e) {
206 Assert.assertTrue(false);
208 Map<String, Property> propMap = this.switchManager
209 .getNodeConnectorProps(nc);
210 Assert.assertFalse(propMap.isEmpty());
212 Assert.assertTrue(this.switchManager.getNodeConnectorProp(nc,
213 Capabilities.CapabilitiesPropName).equals(
214 new Capabilities(CapabilitiesType.FLOW_STATS_CAPABILITY
216 Assert.assertTrue(this.switchManager.getNodeConnectorProp(nc,
217 Bandwidth.BandwidthPropName).equals(
218 new Bandwidth(Bandwidth.BW1Gbps)));
219 Assert.assertTrue(this.switchManager.getNodeConnectorProp(nc,
220 State.StatePropName).equals(new State(State.EDGE_UP)));