blob: 5ce9b6b4a954f409f9c73017a1879e52fded119f [file] [log] [blame]
Jonathan Hart472062d2014-04-03 10:56:48 -07001package net.onrc.onos.core.topology;
Jonathan Hart4b5bbb52014-02-06 10:09:31 -08002
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.HashMap;
6import java.util.List;
7import java.util.Map;
8
9import net.floodlightcontroller.core.module.FloodlightModuleContext;
10import net.floodlightcontroller.core.module.FloodlightModuleException;
11import net.floodlightcontroller.core.module.IFloodlightModule;
12import net.floodlightcontroller.core.module.IFloodlightService;
Jonathan Hart47016712014-02-07 12:41:35 -080013import net.floodlightcontroller.restserver.IRestApiService;
Jonathan Hart6df90172014-04-03 10:13:11 -070014import net.onrc.onos.core.datagrid.IDatagridService;
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070015import net.onrc.onos.core.registry.IControllerRegistryService;
Jonathan Harte37e4e22014-05-13 19:12:02 -070016import net.onrc.onos.core.topology.web.TopologyWebRoutable;
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080017
Jonathan Harte37e4e22014-05-13 19:12:02 -070018public class TopologyModule implements IFloodlightModule, ITopologyService {
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080019
Ray Milkey269ffb92014-04-03 14:43:30 -070020 // This is initialized as a module for now
Yuta HIGUCHI170229f2014-02-17 15:47:54 -080021
Ray Milkey269ffb92014-04-03 14:43:30 -070022 private TopologyManager topologyManager;
Ray Milkey269ffb92014-04-03 14:43:30 -070023 private IDatagridService datagridService;
24 private IControllerRegistryService registryService;
Ray Milkey269ffb92014-04-03 14:43:30 -070025 private IRestApiService restApi;
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080026
Ray Milkey269ffb92014-04-03 14:43:30 -070027 @Override
28 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
29 List<Class<? extends IFloodlightService>> services =
30 new ArrayList<Class<? extends IFloodlightService>>();
Jonathan Harte37e4e22014-05-13 19:12:02 -070031 services.add(ITopologyService.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070032 return services;
33 }
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080034
Ray Milkey269ffb92014-04-03 14:43:30 -070035 @Override
36 public Map<Class<? extends IFloodlightService>, IFloodlightService>
37 getServiceImpls() {
38 Map<Class<? extends IFloodlightService>, IFloodlightService> impls =
39 new HashMap<Class<? extends IFloodlightService>, IFloodlightService>();
Jonathan Harte37e4e22014-05-13 19:12:02 -070040 impls.put(ITopologyService.class, this);
Ray Milkey269ffb92014-04-03 14:43:30 -070041 return impls;
42 }
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080043
Ray Milkey269ffb92014-04-03 14:43:30 -070044 @Override
45 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
46 List<Class<? extends IFloodlightService>> dependencies =
47 new ArrayList<Class<? extends IFloodlightService>>();
48 dependencies.add(IDatagridService.class);
49 dependencies.add(IRestApiService.class);
50 dependencies.add(IControllerRegistryService.class);
51 return dependencies;
52 }
Yuta HIGUCHI170229f2014-02-17 15:47:54 -080053
Ray Milkey269ffb92014-04-03 14:43:30 -070054 @Override
55 public void init(FloodlightModuleContext context)
56 throws FloodlightModuleException {
57 restApi = context.getServiceImpl(IRestApiService.class);
58 datagridService = context.getServiceImpl(IDatagridService.class);
59 registryService = context.getServiceImpl(IControllerRegistryService.class);
Pavlin Radoslavov8a44b782014-08-07 12:53:27 -070060 topologyManager = new TopologyManager(registryService);
Ray Milkey269ffb92014-04-03 14:43:30 -070061 }
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080062
Ray Milkey269ffb92014-04-03 14:43:30 -070063 @Override
64 public void startUp(FloodlightModuleContext context) {
Jonathan Harte37e4e22014-05-13 19:12:02 -070065 restApi.addRestletRoutable(new TopologyWebRoutable());
Ray Milkey269ffb92014-04-03 14:43:30 -070066 topologyManager.startup(datagridService);
67 }
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080068
Ray Milkey269ffb92014-04-03 14:43:30 -070069 @Override
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -070070 public MutableTopology getTopology() {
Jonathan Harte37e4e22014-05-13 19:12:02 -070071 return topologyManager.getTopology();
Ray Milkey269ffb92014-04-03 14:43:30 -070072 }
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080073
Ray Milkey269ffb92014-04-03 14:43:30 -070074 @Override
Pavlin Radoslavov054cd592014-08-07 20:57:16 -070075 public void addListener(ITopologyListener listener,
76 boolean startFromSnapshot) {
77 topologyManager.addListener(listener, startFromSnapshot);
Ray Milkey269ffb92014-04-03 14:43:30 -070078 }
Yuta HIGUCHIa536e762014-02-17 21:47:28 -080079
Ray Milkey269ffb92014-04-03 14:43:30 -070080 @Override
Pavlin Radoslavov054cd592014-08-07 20:57:16 -070081 public void removeListener(ITopologyListener listener) {
82 topologyManager.removeListener(listener);
Ray Milkey269ffb92014-04-03 14:43:30 -070083 }
Pavlin Radoslavov24409672014-08-20 16:45:11 -070084
85 @Override
86 public boolean publish(TopologyBatchOperation tbo) {
87 // TODO: Replace with a call to the new (log-based) TopologyReplicator
88 // return topologyReplicator.publish(tbo);
89 return false;
90 }
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080091}