Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | import java.util.HashMap; |
| 6 | import java.util.List; |
| 7 | import java.util.Map; |
Yuta HIGUCHI | a536e76 | 2014-02-17 21:47:28 -0800 | [diff] [blame] | 8 | import java.util.concurrent.CopyOnWriteArrayList; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 9 | |
| 10 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 11 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 12 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 13 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | 4701671 | 2014-02-07 12:41:35 -0800 | [diff] [blame] | 14 | import net.floodlightcontroller.restserver.IRestApiService; |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 15 | import net.onrc.onos.core.datagrid.IDatagridService; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 16 | import net.onrc.onos.core.registry.IControllerRegistryService; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 17 | import net.onrc.onos.core.topology.web.NetworkGraphWebRoutable; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 18 | |
| 19 | public class NetworkGraphModule implements IFloodlightModule, INetworkGraphService { |
| 20 | |
| 21 | // This is initialized as a module for now |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 22 | |
Pavlin Radoslavov | 6d224ee | 2014-02-18 16:43:15 -0800 | [diff] [blame] | 23 | private TopologyManager topologyManager; |
Jonathan Hart | 22eb988 | 2014-02-11 15:52:59 -0800 | [diff] [blame] | 24 | //private NetworkGraphDatastore southboundNetworkGraph; |
Pavlin Radoslavov | 721a2e0 | 2014-02-14 23:40:14 -0800 | [diff] [blame] | 25 | private IDatagridService datagridService; |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 26 | private IControllerRegistryService registryService; |
| 27 | |
Yuta HIGUCHI | a536e76 | 2014-02-17 21:47:28 -0800 | [diff] [blame] | 28 | private CopyOnWriteArrayList<INetworkGraphListener> networkGraphListeners; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 29 | |
Jonathan Hart | 4701671 | 2014-02-07 12:41:35 -0800 | [diff] [blame] | 30 | private IRestApiService restApi; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 31 | |
| 32 | @Override |
| 33 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 34 | List<Class<? extends IFloodlightService>> services = |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 35 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 36 | services.add(INetworkGraphService.class); |
| 37 | return services; |
| 38 | } |
| 39 | |
| 40 | @Override |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 41 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 42 | getServiceImpls() { |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 43 | Map<Class<? extends IFloodlightService>, IFloodlightService> impls = |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 44 | new HashMap<Class<? extends IFloodlightService>, IFloodlightService>(); |
| 45 | impls.put(INetworkGraphService.class, this); |
| 46 | return impls; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 51 | List<Class<? extends IFloodlightService>> dependencies = |
Jonathan Hart | 4701671 | 2014-02-07 12:41:35 -0800 | [diff] [blame] | 52 | new ArrayList<Class<? extends IFloodlightService>>(); |
Pavlin Radoslavov | 721a2e0 | 2014-02-14 23:40:14 -0800 | [diff] [blame] | 53 | dependencies.add(IDatagridService.class); |
Jonathan Hart | 4701671 | 2014-02-07 12:41:35 -0800 | [diff] [blame] | 54 | dependencies.add(IRestApiService.class); |
Yuta HIGUCHI | bc0ab3b | 2014-02-18 21:24:05 -0800 | [diff] [blame] | 55 | dependencies.add(IControllerRegistryService.class); |
Jonathan Hart | 4701671 | 2014-02-07 12:41:35 -0800 | [diff] [blame] | 56 | return dependencies; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 57 | } |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 58 | |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 59 | @Override |
| 60 | public void init(FloodlightModuleContext context) |
| 61 | throws FloodlightModuleException { |
Jonathan Hart | 4701671 | 2014-02-07 12:41:35 -0800 | [diff] [blame] | 62 | restApi = context.getServiceImpl(IRestApiService.class); |
Pavlin Radoslavov | 721a2e0 | 2014-02-14 23:40:14 -0800 | [diff] [blame] | 63 | datagridService = context.getServiceImpl(IDatagridService.class); |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 64 | registryService = context.getServiceImpl(IControllerRegistryService.class); |
| 65 | |
Yuta HIGUCHI | a536e76 | 2014-02-17 21:47:28 -0800 | [diff] [blame] | 66 | networkGraphListeners = new CopyOnWriteArrayList<>(); |
Pavlin Radoslavov | 6d224ee | 2014-02-18 16:43:15 -0800 | [diff] [blame] | 67 | topologyManager = new TopologyManager(registryService, networkGraphListeners); |
Jonathan Hart | 22eb988 | 2014-02-11 15:52:59 -0800 | [diff] [blame] | 68 | //southboundNetworkGraph = new NetworkGraphDatastore(networkGraph); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void startUp(FloodlightModuleContext context) { |
Jonathan Hart | 4701671 | 2014-02-07 12:41:35 -0800 | [diff] [blame] | 73 | restApi.addRestletRoutable(new NetworkGraphWebRoutable()); |
Pavlin Radoslavov | 6d224ee | 2014-02-18 16:43:15 -0800 | [diff] [blame] | 74 | topologyManager.startup(datagridService); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public NetworkGraph getNetworkGraph() { |
Pavlin Radoslavov | 6d224ee | 2014-02-18 16:43:15 -0800 | [diff] [blame] | 79 | return topologyManager.getNetworkGraph(); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
Jonathan Hart | 22eb988 | 2014-02-11 15:52:59 -0800 | [diff] [blame] | 83 | public NetworkGraphDiscoveryInterface getNetworkGraphDiscoveryInterface() { |
Pavlin Radoslavov | 6d224ee | 2014-02-18 16:43:15 -0800 | [diff] [blame] | 84 | return topologyManager; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Yuta HIGUCHI | a536e76 | 2014-02-17 21:47:28 -0800 | [diff] [blame] | 87 | @Override |
| 88 | public void registerNetworkGraphListener(INetworkGraphListener listener) { |
| 89 | networkGraphListeners.addIfAbsent(listener); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public void deregisterNetworkGraphListener(INetworkGraphListener listener) { |
| 94 | networkGraphListeners.remove(listener); |
| 95 | } |
| 96 | |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 97 | } |