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.topologymanager;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 import org.opendaylight.controller.protocol_plugins.stub.internal.TopologyServices;
15 import org.opendaylight.controller.sal.core.*;
16 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
17 import org.ops4j.pax.exam.Option;
18 import org.ops4j.pax.exam.junit.Configuration;
19 import org.ops4j.pax.exam.junit.PaxExam;
20 import org.ops4j.pax.exam.util.PathUtils;
21 import org.osgi.framework.Bundle;
22 import org.osgi.framework.BundleContext;
23 import org.osgi.framework.ServiceReference;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import javax.inject.Inject;
28 import java.util.HashSet;
31 import static org.junit.Assert.assertFalse;
32 import static org.junit.Assert.assertNotNull;
33 import static org.ops4j.pax.exam.CoreOptions.*;
35 @RunWith(PaxExam.class)
36 public class TopologyManagerIT {
37 private Logger log = LoggerFactory
38 .getLogger(TopologyManagerIT.class);
39 // get the OSGI bundle context
41 private BundleContext bc;
43 private ITopologyManager manager = null;
45 // Configure the OSGi container
47 public Option[] config() {
50 systemProperty("logback.configurationFile").value(
51 "file:" + PathUtils.getBaseDir()
52 + "/src/test/resources/logback.xml"),
53 // To start OSGi console for inspection remotely
54 systemProperty("osgi.console").value("2401"),
55 // Set the systemPackages (used by clustering)
56 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
57 // List framework bundles
58 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console").versionAsInProject(),
59 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util").versionAsInProject(),
60 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services").versionAsInProject(),
61 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds").versionAsInProject(),
62 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command").versionAsInProject(),
63 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime").versionAsInProject(),
64 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell").versionAsInProject(),
65 // List logger bundles
66 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
67 mavenBundle("org.slf4j", "log4j-over-slf4j")
68 .versionAsInProject(),
69 mavenBundle("ch.qos.logback", "logback-core")
70 .versionAsInProject(),
71 mavenBundle("ch.qos.logback", "logback-classic")
72 .versionAsInProject(),
73 // needed by statisticsmanager
74 mavenBundle("org.opendaylight.controller", "containermanager")
75 .versionAsInProject(),
76 mavenBundle("org.opendaylight.controller", "containermanager.it.implementation")
77 .versionAsInProject(),
78 mavenBundle("org.opendaylight.controller", "clustering.services")
79 .versionAsInProject(),
80 mavenBundle("org.opendaylight.controller", "clustering.stub")
81 .versionAsInProject(),
82 // needed by forwardingrulesmanager
83 mavenBundle("org.opendaylight.controller", "configuration")
84 .versionAsInProject(),
85 mavenBundle("org.opendaylight.controller", "configuration.implementation")
86 .versionAsInProject(),
87 mavenBundle("org.opendaylight.controller", "hosttracker")
88 .versionAsInProject(),
90 // List all the bundles on which the test case depends
91 mavenBundle("org.opendaylight.controller", "sal")
92 .versionAsInProject(),
93 mavenBundle("org.opendaylight.controller", "sal.implementation")
94 .versionAsInProject(),
95 mavenBundle("org.opendaylight.controller", "protocol_plugins.stub")
96 .versionAsInProject(),
97 mavenBundle("org.opendaylight.controller", "switchmanager")
98 .versionAsInProject(),
99 mavenBundle("org.opendaylight.controller", "switchmanager.implementation")
100 .versionAsInProject(),
101 mavenBundle("org.opendaylight.controller", "statisticsmanager")
102 .versionAsInProject(),
103 mavenBundle("org.opendaylight.controller", "statisticsmanager.implementation")
104 .versionAsInProject(),
105 mavenBundle("org.opendaylight.controller", "forwardingrulesmanager")
106 .versionAsInProject(),
108 // needed by hosttracker
109 mavenBundle("org.opendaylight.controller", "topologymanager")
110 .versionAsInProject(),
111 mavenBundle("org.jboss.spec.javax.transaction",
112 "jboss-transaction-api_1.1_spec").versionAsInProject(),
113 mavenBundle("org.apache.commons", "commons-lang3")
114 .versionAsInProject(),
115 mavenBundle("org.apache.felix",
116 "org.apache.felix.dependencymanager")
117 .versionAsInProject(), junitBundles());
120 private String stateToString(int state) {
124 case Bundle.INSTALLED:
126 case Bundle.RESOLVED:
128 case Bundle.UNINSTALLED:
129 return "UNINSTALLED";
131 return "Not CONVERTED";
136 * This test verifies that the isInternal method of the TopologyManager returns true when a node is internal and
139 * To make a node interval we add a node using the plugin interface (TopologyServices.addEdge) this is to ensure
140 * that when TopologyManager sees the edge is via it's dependency on the SAL ITopologyService.
145 public void testIsInternal() throws Exception{
146 Node node1 = new Node("STUB", 0xCAFE);
147 Node node2 = new Node("STUB", 0XFACE);
149 NodeConnector head = new NodeConnector("STUB", node1.getID(), node1);
150 NodeConnector tail = new NodeConnector("STUB", node2.getID(), node2);
152 assert(this.manager.isInternal(head));
154 Set<Property> properties = new HashSet<Property>();
156 ServiceReference r = bc.getServiceReference(IPluginInTopologyService.class
158 TopologyServices topologyServices = null;
160 if(bc.getService(r) instanceof TopologyServices) {
161 topologyServices = (TopologyServices) bc.getService(r);
163 throw new RuntimeException("topology service registered is not from the stub plugin implementation");
167 topologyServices.addEdge(new Edge(tail, head), properties, UpdateType.ADDED);
169 assert(this.manager.isInternal(head));