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 | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 17 | import net.onrc.onos.core.topology.web.TopologyWebRoutable; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 18 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 19 | public class TopologyModule implements IFloodlightModule, ITopologyService { |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 20 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 21 | // This is initialized as a module for now |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 22 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 23 | private TopologyManager topologyManager; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 24 | private IDatagridService datagridService; |
| 25 | private IControllerRegistryService registryService; |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 26 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 27 | private CopyOnWriteArrayList<ITopologyListener> topologyListeners; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 28 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 29 | private IRestApiService restApi; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 30 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 31 | @Override |
| 32 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 33 | List<Class<? extends IFloodlightService>> services = |
| 34 | new ArrayList<Class<? extends IFloodlightService>>(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 35 | services.add(ITopologyService.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 36 | return services; |
| 37 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 38 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 39 | @Override |
| 40 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
| 41 | getServiceImpls() { |
| 42 | Map<Class<? extends IFloodlightService>, IFloodlightService> impls = |
| 43 | new HashMap<Class<? extends IFloodlightService>, IFloodlightService>(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 44 | impls.put(ITopologyService.class, this); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 45 | return impls; |
| 46 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 47 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 48 | @Override |
| 49 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 50 | List<Class<? extends IFloodlightService>> dependencies = |
| 51 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 52 | dependencies.add(IDatagridService.class); |
| 53 | dependencies.add(IRestApiService.class); |
| 54 | dependencies.add(IControllerRegistryService.class); |
| 55 | return dependencies; |
| 56 | } |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 57 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 58 | @Override |
| 59 | public void init(FloodlightModuleContext context) |
| 60 | throws FloodlightModuleException { |
| 61 | restApi = context.getServiceImpl(IRestApiService.class); |
| 62 | datagridService = context.getServiceImpl(IDatagridService.class); |
| 63 | registryService = context.getServiceImpl(IControllerRegistryService.class); |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 64 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 65 | topologyListeners = new CopyOnWriteArrayList<>(); |
| 66 | topologyManager = new TopologyManager(registryService, topologyListeners); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 67 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 68 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 69 | @Override |
| 70 | public void startUp(FloodlightModuleContext context) { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 71 | restApi.addRestletRoutable(new TopologyWebRoutable()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 72 | topologyManager.startup(datagridService); |
| 73 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 74 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 75 | @Override |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 76 | public Topology getTopology() { |
| 77 | return topologyManager.getTopology(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 78 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 79 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 80 | @Override |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 81 | public TopologyDiscoveryInterface getTopologyDiscoveryInterface() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 82 | return topologyManager; |
| 83 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 84 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 85 | @Override |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 86 | public void registerTopologyListener(ITopologyListener listener) { |
| 87 | topologyListeners.addIfAbsent(listener); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 88 | } |
Yuta HIGUCHI | a536e76 | 2014-02-17 21:47:28 -0800 | [diff] [blame] | 89 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 90 | @Override |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 91 | public void deregisterTopologyListener(ITopologyListener listener) { |
| 92 | topologyListeners.remove(listener); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 93 | } |
Yuta HIGUCHI | a536e76 | 2014-02-17 21:47:28 -0800 | [diff] [blame] | 94 | |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 95 | } |