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; |
| 8 | |
| 9 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 10 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 11 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 12 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | 4701671 | 2014-02-07 12:41:35 -0800 | [diff] [blame] | 13 | import net.floodlightcontroller.restserver.IRestApiService; |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 14 | import net.onrc.onos.core.datagrid.IDatagridService; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 15 | import net.onrc.onos.core.registry.IControllerRegistryService; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 16 | import net.onrc.onos.core.topology.web.TopologyWebRoutable; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 17 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 18 | public class TopologyModule implements IFloodlightModule, ITopologyService { |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 19 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 20 | // This is initialized as a module for now |
Yuta HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 21 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 22 | private TopologyManager topologyManager; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 23 | private IDatagridService datagridService; |
| 24 | private IControllerRegistryService registryService; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 25 | private IRestApiService restApi; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 26 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 27 | @Override |
| 28 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 29 | List<Class<? extends IFloodlightService>> services = |
| 30 | new ArrayList<Class<? extends IFloodlightService>>(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 31 | services.add(ITopologyService.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 32 | return services; |
| 33 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 34 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 35 | @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 Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 40 | impls.put(ITopologyService.class, this); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 41 | return impls; |
| 42 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 43 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 44 | @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 HIGUCHI | 170229f | 2014-02-17 15:47:54 -0800 | [diff] [blame] | 53 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 54 | @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 Radoslavov | 8a44b78 | 2014-08-07 12:53:27 -0700 | [diff] [blame] | 60 | topologyManager = new TopologyManager(registryService); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 61 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 62 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 63 | @Override |
| 64 | public void startUp(FloodlightModuleContext context) { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 65 | restApi.addRestletRoutable(new TopologyWebRoutable()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 66 | topologyManager.startup(datagridService); |
| 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 |
Yuta HIGUCHI | d92b10c | 2014-08-25 09:30:28 -0700 | [diff] [blame] | 70 | public MutableTopology getTopology() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 71 | return topologyManager.getTopology(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 72 | } |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 73 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 74 | @Override |
Pavlin Radoslavov | 054cd59 | 2014-08-07 20:57:16 -0700 | [diff] [blame] | 75 | public void addListener(ITopologyListener listener, |
| 76 | boolean startFromSnapshot) { |
| 77 | topologyManager.addListener(listener, startFromSnapshot); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 78 | } |
Yuta HIGUCHI | a536e76 | 2014-02-17 21:47:28 -0800 | [diff] [blame] | 79 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 80 | @Override |
Pavlin Radoslavov | 054cd59 | 2014-08-07 20:57:16 -0700 | [diff] [blame] | 81 | public void removeListener(ITopologyListener listener) { |
| 82 | topologyManager.removeListener(listener); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 83 | } |
Pavlin Radoslavov | 2440967 | 2014-08-20 16:45:11 -0700 | [diff] [blame] | 84 | |
| 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 Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 91 | } |