Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent.runtime; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | import java.util.HashMap; |
| 6 | import java.util.Map; |
| 7 | |
| 8 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 9 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 10 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 11 | import net.floodlightcontroller.core.module.IFloodlightService; |
| 12 | import net.onrc.onos.datagrid.IDatagridService; |
| 13 | import net.onrc.onos.datagrid.IEventChannel; |
| 14 | import net.onrc.onos.intent.IntentMap; |
| 15 | import net.onrc.onos.intent.IntentOperationList; |
| 16 | import net.onrc.onos.intent.PathIntentMap; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 17 | import net.onrc.onos.ofcontroller.networkgraph.INetworkGraphService; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 18 | import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph; |
| 19 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 20 | public class PathCalcRuntimeModule implements IFloodlightModule, IPathCalcRuntimeService { |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 21 | private PathCalcRuntime runtime; |
| 22 | private IDatagridService datagridService; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 23 | private INetworkGraphService networkGraphService; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 24 | private IntentMap highLevelIntents; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 25 | private PathIntentMap pathIntents; |
| 26 | |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 27 | private IEventChannel<byte[], IntentOperationList> eventChannel; |
| 28 | private static final String EVENT_CHANNEL_NAME = "onos.pathintent"; |
| 29 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 30 | |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 31 | @Override |
| 32 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 33 | Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(1); |
Toshio Koide | eb90d91 | 2014-02-18 21:30:22 -0800 | [diff] [blame] | 34 | l.add(IPathCalcRuntimeService.class); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 35 | return l; |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
| 40 | Map<Class<? extends IFloodlightService>, IFloodlightService> m = new HashMap<>(1); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 41 | m.put(IPathCalcRuntimeService.class, this); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 42 | return m; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 47 | Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(); |
| 48 | l.add(IDatagridService.class); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 49 | l.add(INetworkGraphService.class); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 50 | return l; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public void init(FloodlightModuleContext context) throws FloodlightModuleException { |
| 55 | datagridService = context.getServiceImpl(IDatagridService.class); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 56 | networkGraphService = context.getServiceImpl(INetworkGraphService.class); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public void startUp(FloodlightModuleContext context) { |
Toshio Koide | eb90d91 | 2014-02-18 21:30:22 -0800 | [diff] [blame] | 61 | highLevelIntents = new IntentMap(); |
| 62 | runtime = new PathCalcRuntime(networkGraphService.getNetworkGraph()); |
| 63 | pathIntents = new PathIntentMap(networkGraphService.getNetworkGraph()); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 64 | eventChannel = datagridService.createChannel( |
| 65 | EVENT_CHANNEL_NAME, |
| 66 | byte[].class, |
| 67 | IntentOperationList.class); |
| 68 | } |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 69 | |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 70 | protected void publishPathIntentOperationList(IntentOperationList list) { |
| 71 | eventChannel.addEntry(new byte[1], list); // TODO make key bytes |
| 72 | } |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 73 | |
| 74 | @Override |
| 75 | public IntentOperationList executeIntentOperations(IntentOperationList list) { |
| 76 | highLevelIntents.executeOperations(list); |
| 77 | IntentOperationList pathIntentOperations = runtime.calcPathIntents(list, pathIntents); |
| 78 | pathIntents.executeOperations(pathIntentOperations); |
| 79 | publishPathIntentOperationList(pathIntentOperations); |
| 80 | return pathIntentOperations; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public IntentMap getHighLevelIntents() { |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 85 | return highLevelIntents; |
| 86 | } |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 87 | |
| 88 | @Override |
| 89 | public IntentMap getPathIntents() { |
| 90 | return pathIntents; |
| 91 | } |
| 92 | |
| 93 | @Override |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 94 | public void purgeIntents() { |
| 95 | highLevelIntents.purge(); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 96 | pathIntents.purge(); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 97 | } |
| 98 | } |