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; |
| 17 | import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph; |
| 18 | |
| 19 | public class PathCalcRuntimeModule implements IFloodlightModule { |
| 20 | private PathCalcRuntime runtime; |
| 21 | private IDatagridService datagridService; |
| 22 | private NetworkGraph networkGraph; |
| 23 | private IntentMap highLevelIntents; |
| 24 | private PathIntentMap lowLevelIntents; |
| 25 | |
| 26 | private IEventChannel<byte[], IntentOperationList> eventChannel; |
| 27 | private static final String EVENT_CHANNEL_NAME = "onos.pathintent"; |
| 28 | |
| 29 | |
| 30 | @Override |
| 31 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 32 | Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(1); |
| 33 | l.add(PathCalcRuntime.class); |
| 34 | return l; |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
| 39 | Map<Class<? extends IFloodlightService>, IFloodlightService> m = new HashMap<>(1); |
| 40 | m.put(PathCalcRuntime.class, runtime); |
| 41 | return m; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 46 | Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(); |
| 47 | l.add(IDatagridService.class); |
| 48 | return l; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void init(FloodlightModuleContext context) throws FloodlightModuleException { |
| 53 | datagridService = context.getServiceImpl(IDatagridService.class); |
| 54 | //networkGraph = new MockNetworkGraph(); // TODO give pointer to the correct NetworkGraph |
| 55 | runtime = new PathCalcRuntime(networkGraph); |
| 56 | highLevelIntents = new IntentMap(); |
| 57 | lowLevelIntents = new PathIntentMap(networkGraph); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public void startUp(FloodlightModuleContext context) { |
| 62 | eventChannel = datagridService.createChannel( |
| 63 | EVENT_CHANNEL_NAME, |
| 64 | byte[].class, |
| 65 | IntentOperationList.class); |
| 66 | } |
| 67 | |
| 68 | public void executeIntentOperations(IntentOperationList list) { |
| 69 | highLevelIntents.executeOperations(list); |
| 70 | lowLevelIntents = runtime.calcPathIntents( |
| 71 | highLevelIntents.getAllIntents(), |
| 72 | new PathIntentMap(networkGraph)); |
| 73 | // TODO publishPathIntentOperationList(IntentOperationList list) |
| 74 | } |
| 75 | |
| 76 | protected void publishPathIntentOperationList(IntentOperationList list) { |
| 77 | eventChannel.addEntry(new byte[1], list); // TODO make key bytes |
| 78 | } |
| 79 | |
| 80 | public IntentMap getIntents() { |
| 81 | return highLevelIntents; |
| 82 | } |
| 83 | |
| 84 | public void purgeIntents() { |
| 85 | highLevelIntents.purge(); |
| 86 | lowLevelIntents.purge(); |
| 87 | } |
| 88 | } |