Merge branch 'master' of https://github.com/OPENNETWORKINGLAB/ONOS
diff --git a/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java b/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java
index c6d89a9..c821339 100644
--- a/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java
+++ b/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java
@@ -15,7 +15,6 @@
 import net.floodlightcontroller.restserver.IRestApiService;
 import net.floodlightcontroller.storage.IStorageSourceService;
 import net.floodlightcontroller.threadpool.IThreadPoolService;
-import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService;
 import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
 import net.onrc.onos.registry.controller.IControllerRegistryService;
 
@@ -54,7 +53,6 @@
         dependencies.add(IThreadPoolService.class);
         // Following added by ONOS
         dependencies.add(IFlowService.class);
-        dependencies.add(ITopoRouteService.class);
         dependencies.add(IControllerRegistryService.class);
 
         return dependencies;
@@ -74,7 +72,6 @@
            context.getServiceImpl(IThreadPoolService.class));
        // Following added by ONOS
        controller.setFlowService(context.getServiceImpl(IFlowService.class));
-       controller.setTopoRouteService(context.getServiceImpl(ITopoRouteService.class));
        controller.setMastershipService(
     		   context.getServiceImpl(IControllerRegistryService.class));
 
diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
index e40f24a..ac29983 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
@@ -74,7 +74,6 @@
 import net.floodlightcontroller.storage.StorageException;
 import net.floodlightcontroller.threadpool.IThreadPoolService;
 import net.onrc.onos.ofcontroller.core.IOFSwitchPortListener;
-import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService;
 import net.onrc.onos.ofcontroller.flowmanager.IFlowService;
 import net.onrc.onos.registry.controller.IControllerRegistryService;
 import net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback;
@@ -146,7 +145,7 @@
  * - Detailed Port event: PORTCHANGED -> {PORTCHANGED, PORTADDED, PORTREMOVED} 
  *    Available as net.onrc.onos.ofcontroller.core.IOFSwitchPortListener
  * - Distributed ownership control of switch through RegistryService(IControllerRegistryService)
- * - Register ONOS services. (IFlowService, ITopoRouteService, IControllerRegistryService)
+ * - Register ONOS services. (IFlowService, IControllerRegistryService)
  * - Additional DEBUG logs
  * - Try using hostname as controller ID, when ID was not explicitly given.
  */
@@ -189,7 +188,6 @@
     protected IPktInProcessingTimeService pktinProcTime;
     protected IThreadPoolService threadPool;
     protected IFlowService flowService;
-    protected ITopoRouteService topoRouteService;
     protected IControllerRegistryService registryService;
     
     // Configuration options
@@ -418,10 +416,6 @@
 	this.flowService = serviceImpl;		
     }
 
-    public void setTopoRouteService(ITopoRouteService serviceImpl) {
-	this.topoRouteService = serviceImpl;		
-    }
-
 	public void setMastershipService(IControllerRegistryService serviceImpl) {
 		this.registryService = serviceImpl;		
 	}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java b/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
index f0b7abe..2034118 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/bgproute/BgpRoute.java
@@ -35,6 +35,7 @@
 import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery;
 import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery.LDUpdate;
 import net.onrc.onos.ofcontroller.proxyarp.ProxyArpManager;
+import net.onrc.onos.ofcontroller.routing.TopoRouteService;
 import net.onrc.onos.ofcontroller.util.DataPath;
 import net.onrc.onos.ofcontroller.util.Dpid;
 import net.onrc.onos.ofcontroller.util.FlowEntry;
@@ -204,7 +205,6 @@
 			= new ArrayList<Class<? extends IFloodlightService>>();
 		l.add(IFloodlightProviderService.class);
 		l.add(ITopologyService.class);
-		l.add(ITopoRouteService.class);
 		l.add(IDeviceService.class);
 		l.add(IRestApiService.class);
 		return l;
@@ -219,7 +219,6 @@
 		// Register floodlight provider and REST handler.
 		floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
 		topology = context.getServiceImpl(ITopologyService.class);
-		topoRouteService = context.getServiceImpl(ITopoRouteService.class);
 		devices = context.getServiceImpl(IDeviceService.class);
 		restApi = context.getServiceImpl(IRestApiService.class);
 		
@@ -230,6 +229,8 @@
 		linkUpdates = new ArrayList<LDUpdate>();
 		ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
 		topologyChangeDetectorTask = new SingletonTask(executor, new TopologyChangeDetector());
+
+		topoRouteService = new TopoRouteService("");
 		
 		//Read in config values
 		bgpdRestIp = context.getConfigParams(this).get("BgpdRestIp");
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
index 2e0d837..25a214a 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/FlowManager.java
@@ -35,6 +35,7 @@
 import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
 import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService;
 import net.onrc.onos.ofcontroller.flowmanager.web.FlowWebRoutable;
+import net.onrc.onos.ofcontroller.routing.TopoRouteService;
 import net.onrc.onos.ofcontroller.util.CallerId;
 import net.onrc.onos.ofcontroller.util.DataPath;
 import net.onrc.onos.ofcontroller.util.DataPathEndpoints;
@@ -413,6 +414,7 @@
     @Override
     public void init(String conf) {
     	op = new GraphDBOperation(conf);
+	topoRouteService = new TopoRouteService(conf);
     }
 
     public void finalize() {
@@ -449,7 +451,6 @@
 	Collection<Class<? extends IFloodlightService>> l =
 	    new ArrayList<Class<? extends IFloodlightService>>();
 	l.add(IFloodlightProviderService.class);
-	l.add(ITopoRouteService.class);
 	l.add(IRestApiService.class);
         return l;
     }
@@ -459,11 +460,11 @@
 	throws FloodlightModuleException {
 	this.context = context;
 	floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
-	topoRouteService = context.getServiceImpl(ITopoRouteService.class);
 	restApi = context.getServiceImpl(IRestApiService.class);
 	messageDamper = new OFMessageDamper(OFMESSAGE_DAMPER_CAPACITY,
 					    EnumSet.of(OFType.FLOW_MOD),
 					    OFMESSAGE_DAMPER_TIMEOUT);
+
 	// TODO: An ugly hack!
 	String conf = "/tmp/cassandra.titan";
 	this.init(conf);
diff --git a/src/main/java/net/onrc/onos/ofcontroller/routing/TopoRouteService.java b/src/main/java/net/onrc/onos/ofcontroller/routing/TopoRouteService.java
index 5328eae..59e76ca 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/routing/TopoRouteService.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/routing/TopoRouteService.java
@@ -11,10 +11,6 @@
 import java.util.Queue;
 import java.util.Set;
 
-import net.floodlightcontroller.core.module.FloodlightModuleContext;
-import net.floodlightcontroller.core.module.FloodlightModuleException;
-import net.floodlightcontroller.core.module.IFloodlightModule;
-import net.floodlightcontroller.core.module.IFloodlightService;
 import net.onrc.onos.graph.GraphDBOperation;
 import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
 import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService;
@@ -97,7 +93,7 @@
 /**
  * A class for implementing Topology Route Service.
  */
-public class TopoRouteService implements IFloodlightModule, ITopoRouteService {
+public class TopoRouteService implements ITopoRouteService {
 
     /** The logger. */
     private static Logger log =
@@ -105,69 +101,42 @@
     
     protected GraphDBOperation op;
 
+
     /**
-     * Get the collection of module services.
-     *
-     * @return the collection of services provided by this module.
+     * Default constructor.
      */
-    @Override
-    public Collection<Class<? extends IFloodlightService>> getModuleServices() {
-        Collection<Class<? extends IFloodlightService>> l = 
-            new ArrayList<Class<? extends IFloodlightService>>();
-        l.add(ITopoRouteService.class);
-        return l;
+    public TopoRouteService() {
     }
 
     /**
-     * Get a map with the services provided by this module.
+     * Constructor for given database configuration file.
      *
-     * @return a map with the services provided by this module.
+     * @param config the database configuration file to use for
+     * the initialization.
      */
-    @Override
-    public Map<Class<? extends IFloodlightService>, IFloodlightService> 
-			       getServiceImpls() {
-        Map<Class<? extends IFloodlightService>,
-        IFloodlightService> m = 
-            new HashMap<Class<? extends IFloodlightService>,
-                IFloodlightService>();
-        m.put(ITopoRouteService.class, this);
-        return m;
-    }
-
-    /**
-     * Get the collection with the services this module depends on.
-     *
-     * @return the collection with the services this module depends on.
-     */
-    @Override
-    public Collection<Class<? extends IFloodlightService>> 
-                                                    getModuleDependencies() {
-	Collection<Class<? extends IFloodlightService>> l =
-	    new ArrayList<Class<? extends IFloodlightService>>();
-	// TODO: Add the appropriate dependencies
-	// l.add(IRestApiService.class);
-        return l;
+    public TopoRouteService(String config) {
+	this.init(config);
     }
 
     /**
      * Init the module.
      *
-     * @param context the module context to use for the initialization.
-     * @see FloodlightModuleContext.
+     * @param config the database configuration file to use for
+     * the initialization.
      */
-    @Override
-    public void init(FloodlightModuleContext context)
-	throws FloodlightModuleException {
-	// TODO: Add the appropriate initialization
-    	op = new GraphDBOperation("");
+    public void init(String config) {
+	try {
+	    op = new GraphDBOperation(config);
+	} catch (Exception e) {
+	    log.error(e.getMessage());
+	}
     }
 
     /**
-     * Startup initialization.
+     * Close the service. It will close the corresponding database connection.
      */
-    @Override
-    public void startUp(FloodlightModuleContext context) {
-	// TODO: Add the approprate setup
+    public void close() {
+	op.close();
     }
 
     /**
diff --git a/src/main/java/net/onrc/onos/ofcontroller/topology/web/RouteResource.java b/src/main/java/net/onrc/onos/ofcontroller/topology/web/RouteResource.java
index 5ad892b..659609d 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/topology/web/RouteResource.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/topology/web/RouteResource.java
@@ -1,6 +1,7 @@
 package net.onrc.onos.ofcontroller.topology.web;
 
 import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService;
+import net.onrc.onos.ofcontroller.routing.TopoRouteService;
 import net.onrc.onos.ofcontroller.util.DataPath;
 import net.onrc.onos.ofcontroller.util.Dpid;
 import net.onrc.onos.ofcontroller.util.Port;
@@ -17,9 +18,7 @@
 
     @Get("json")
     public DataPath retrieve() {
-        ITopoRouteService topoRouteService = 
-                (ITopoRouteService)getContext().getAttributes().
-                    get(ITopoRouteService.class.getCanonicalName());
+        ITopoRouteService topoRouteService = new TopoRouteService("");
 	if (topoRouteService == null) {
 	    log.debug("Topology Route Service not found");
 	    return null;
diff --git a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
index 06e828d..fb1d708 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/flowmanager/FlowManagerTest.java
@@ -18,8 +18,8 @@
 import net.onrc.onos.graph.GraphDBOperation;
 import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
 import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
-import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService;
 import net.onrc.onos.ofcontroller.flowmanager.web.FlowWebRoutable;
+import net.onrc.onos.ofcontroller.routing.TopoRouteService;
 import net.onrc.onos.ofcontroller.util.*;
 
 import org.easymock.EasyMock;
@@ -43,7 +43,7 @@
 public class FlowManagerTest {
 	private static FloodlightModuleContext context;
 	private static IFloodlightProviderService floodlightProvider;
-	private static ITopoRouteService topoRouteService;
+	private static TopoRouteService topoRouteService;
 	private static IRestApiService restApi;
 	private static GraphDBOperation op;
 	
@@ -68,15 +68,15 @@
 		// create mock objects
 		context = createMock(FloodlightModuleContext.class);
 		floodlightProvider = createMock(IFloodlightProviderService.class);
-		topoRouteService = createMock(ITopoRouteService.class);
+		topoRouteService = createMock(TopoRouteService.class);
 		restApi = createMock(IRestApiService.class);
 		op = createMock(GraphDBOperation.class);
 
 		// setup expectations
 		expect(context.getServiceImpl(IFloodlightProviderService.class)).andReturn(floodlightProvider);
-		expect(context.getServiceImpl(ITopoRouteService.class)).andReturn(topoRouteService);
 		expect(context.getServiceImpl(IRestApiService.class)).andReturn(restApi);
 		expectNew(GraphDBOperation.class, new Class<?>[] {String.class}, EasyMock.isA(String.class)).andReturn(op);
+		expectNew(TopoRouteService.class, new Class<?>[] {String.class}, EasyMock.isA(String.class)).andReturn(topoRouteService);
 	}
 	
 	private IFlowPath createIFlowPathMock(long flowId, String installerID,
@@ -909,9 +909,8 @@
 
 		// verify the test
 		verifyAll();
-		assertEquals(3, md.size());
+		assertEquals(2, md.size());
 		assertTrue(md.contains(IFloodlightProviderService.class));
-		assertTrue(md.contains(ITopoRouteService.class));
 		assertTrue(md.contains(IRestApiService.class));
 	}
 
@@ -1198,4 +1197,4 @@
 	public final void testRemoveRemoteFlowEntrySuccessNormally() {
 		fail("not yet implemented");
 	}
-}
\ No newline at end of file
+}