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.ConstructionException;
41 import org.opendaylight.controller.sal.core.Node;
42 import org.opendaylight.controller.sal.core.NodeConnector;
43 import org.opendaylight.controller.sal.core.State;
44 import org.opendaylight.controller.sal.core.TimeStamp;
45 import org.opendaylight.controller.sal.core.UpdateType;
46 import org.opendaylight.controller.sal.core.Property;
47 import org.opendaylight.controller.sal.core.Capabilities.CapabilitiesType;
48 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
49 import org.opendaylight.controller.sal.utils.NodeCreator;
50 import org.opendaylight.controller.sal.utils.Status;
51 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
52 import org.opendaylight.controller.switchmanager.*;
53 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
54 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
55 import org.opendaylight.controller.switchmanager.ISwitchManager;
57 import org.ops4j.pax.exam.junit.PaxExam;
58 import org.ops4j.pax.exam.util.Filter;
59 import org.osgi.framework.BundleContext;
60 import static org.junit.Assert.*;
61 import org.ops4j.pax.exam.junit.Configuration;
62 import static org.ops4j.pax.exam.CoreOptions.*;
64 import org.ops4j.pax.exam.Option;
65 import org.ops4j.pax.exam.util.PathUtils;
66 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
67 import org.ops4j.pax.exam.spi.reactors.PerClass;
69 @RunWith(PaxExam.class)
70 public class SwitchmanagerIntegrationTest {
71 private Logger log = LoggerFactory
72 .getLogger(SwitchmanagerIntegrationTest.class);
73 // get the OSGI bundle context
75 private BundleContext bc;
77 private ISwitchManager switchManager = null;
79 // Configure the OSGi container
81 public Option[] config() {
83 systemProperty("logback.configurationFile").value(
84 "file:" + PathUtils.getBaseDir()
85 + "/src/test/resources/logback.xml"),
86 // To start OSGi console for inspection remotely
87 systemProperty("osgi.console").value("2401"),
88 // Set the systemPackages (used by clustering)
89 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
90 // List framework bundles
91 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
92 "1.0.0.v20120522-1841"),
93 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
94 "1.0.400.v20120522-2049"),
95 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
96 "3.3.100.v20120522-1822"),
97 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
98 "1.4.0.v20120522-1841"),
99 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
100 "0.8.0.v201108120515"),
101 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
102 "0.8.0.v201108120515"),
103 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
104 "0.8.0.v201110170705"),
105 // List logger bundles
106 mavenBundle("org.slf4j", "slf4j-api", "1.7.2"),
107 mavenBundle("org.slf4j", "log4j-over-slf4j", "1.7.2"),
108 mavenBundle("ch.qos.logback", "logback-core", "1.0.9"),
109 mavenBundle("ch.qos.logback", "logback-classic", "1.0.9"),
111 mavenBundle("org.opendaylight.controller", "switchmanager",
113 mavenBundle("org.opendaylight.controller", "switchmanager.implementation",
115 mavenBundle("org.opendaylight.controller", "sal",
117 mavenBundle("org.opendaylight.controller", "sal.implementation",
119 mavenBundle("org.opendaylight.controller", "containermanager",
121 mavenBundle("org.opendaylight.controller", "containermanager.implementation",
123 mavenBundle("org.opendaylight.controller", "clustering.services",
125 mavenBundle("org.opendaylight.controller", "clustering.stub",
127 mavenBundle("org.opendaylight.controller", "configuration",
129 mavenBundle("org.opendaylight.controller", "configuration.implementation",
131 mavenBundle("org.opendaylight.controller",
132 "protocol_plugins.stub", "0.4.0-SNAPSHOT"),
133 mavenBundle("org.jboss.spec.javax.transaction",
134 "jboss-transaction-api_1.1_spec", "1.0.1.Final"),
135 mavenBundle("org.apache.commons", "commons-lang3", "3.1"),
136 mavenBundle("org.apache.felix",
137 "org.apache.felix.dependencymanager", "3.1.0"),
141 private String stateToString(int state) {
145 case Bundle.INSTALLED:
147 case Bundle.RESOLVED:
149 case Bundle.UNINSTALLED:
150 return "UNINSTALLED";
152 return "Not CONVERTED";
157 public void areWeReady() {
159 boolean debugit = false;
160 Bundle b[] = bc.getBundles();
161 for (int i = 0; i < b.length; i++) {
162 int state = b[i].getState();
163 if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
164 log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
165 + stateToString(state));
170 log.debug("Do some debugging because some bundle is "
174 // Assert if true, if false we are good to go!
175 assertFalse(debugit);
177 // Now lets create a hosttracker for testing purpose
178 ServiceReference s = bc
179 .getServiceReference(ISwitchManager.class.getName());
181 this.switchManager = (ISwitchManager)bc.getService(s);
184 // If StatisticsManager is null, cannot run tests.
185 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
205 (node, Capabilities.CapabilitiesPropName)
206 .equals(new Capabilities((int)3)));
207 Assert.assertTrue(this.switchManager.getNodeProp
208 (node, Actions.ActionsPropName)
209 .equals(new Actions((int)2)));
210 Assert.assertTrue(this.switchManager.getNodeProp
211 (node, Buffers.BuffersPropName)
212 .equals(new Buffers((int)1)));
213 Assert.assertTrue(this.switchManager.getNodeProp
214 (node, TimeStamp.TimeStampPropName)
215 .equals(new TimeStamp(100000L, "connectedSince")));
219 public void testNodeConnectorProp() throws UnknownHostException {
220 assertNotNull(this.switchManager);
224 node = new Node("STUB", 0xCAFE);
225 nc = new NodeConnector("STUB", 0xCAFE, node);
227 catch(ConstructionException e){
230 Assert.assertTrue(false);
232 Map<String, Property> propMap = this.switchManager.getNodeConnectorProps(nc);
233 Assert.assertFalse(propMap.isEmpty());
235 Assert.assertTrue(this.switchManager.getNodeConnectorProp
236 (nc, Capabilities.CapabilitiesPropName)
237 .equals(new Capabilities
238 (CapabilitiesType.FLOW_STATS_CAPABILITY.getValue())));
239 Assert.assertTrue(this.switchManager.getNodeConnectorProp
240 (nc, Bandwidth.BandwidthPropName)
241 .equals(new Bandwidth (Bandwidth.BW1Gbps)));
242 Assert.assertTrue(this.switchManager.getNodeConnectorProp
243 (nc, State.StatePropName)
244 .equals(new State (State.EDGE_UP)));