blob: 56758cb87be6a9e8db4447cd223e0094d1d935be [file] [log] [blame]
Toshio Koide4f308732014-02-18 15:19:48 -08001package net.onrc.onos.intent.runtime;
2
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.HashMap;
6import java.util.Map;
7
8import net.floodlightcontroller.core.module.FloodlightModuleContext;
9import net.floodlightcontroller.core.module.FloodlightModuleException;
10import net.floodlightcontroller.core.module.IFloodlightModule;
11import net.floodlightcontroller.core.module.IFloodlightService;
12import net.onrc.onos.datagrid.IDatagridService;
13import net.onrc.onos.datagrid.IEventChannel;
14import net.onrc.onos.intent.IntentMap;
15import net.onrc.onos.intent.IntentOperationList;
16import net.onrc.onos.intent.PathIntentMap;
Toshio Koide27ffd412014-02-18 19:15:27 -080017import net.onrc.onos.ofcontroller.networkgraph.INetworkGraphService;
Toshio Koide4f308732014-02-18 15:19:48 -080018import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
19
Toshio Koide27ffd412014-02-18 19:15:27 -080020public class PathCalcRuntimeModule implements IFloodlightModule, IPathCalcRuntimeService {
Toshio Koide4f308732014-02-18 15:19:48 -080021 private PathCalcRuntime runtime;
22 private IDatagridService datagridService;
Toshio Koide27ffd412014-02-18 19:15:27 -080023 private INetworkGraphService networkGraphService;
Toshio Koide4f308732014-02-18 15:19:48 -080024 private IntentMap highLevelIntents;
Toshio Koide27ffd412014-02-18 19:15:27 -080025 private PathIntentMap pathIntents;
26
Toshio Koide4f308732014-02-18 15:19:48 -080027 private IEventChannel<byte[], IntentOperationList> eventChannel;
28 private static final String EVENT_CHANNEL_NAME = "onos.pathintent";
29
Toshio Koide27ffd412014-02-18 19:15:27 -080030
Toshio Koide4f308732014-02-18 15:19:48 -080031 @Override
32 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
33 Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(1);
34 l.add(PathCalcRuntime.class);
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 Koide27ffd412014-02-18 19:15:27 -080041 m.put(IPathCalcRuntimeService.class, this);
Toshio Koide4f308732014-02-18 15:19:48 -080042 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 Koide27ffd412014-02-18 19:15:27 -080049 l.add(INetworkGraphService.class);
Toshio Koide4f308732014-02-18 15:19:48 -080050 return l;
51 }
52
53 @Override
54 public void init(FloodlightModuleContext context) throws FloodlightModuleException {
55 datagridService = context.getServiceImpl(IDatagridService.class);
Toshio Koide27ffd412014-02-18 19:15:27 -080056 networkGraphService = context.getServiceImpl(INetworkGraphService.class);
57 runtime = new PathCalcRuntime(networkGraphService.getNetworkGraph());
Toshio Koide4f308732014-02-18 15:19:48 -080058 highLevelIntents = new IntentMap();
Toshio Koide27ffd412014-02-18 19:15:27 -080059 pathIntents = new PathIntentMap(networkGraphService.getNetworkGraph());
Toshio Koide4f308732014-02-18 15:19:48 -080060 }
61
62 @Override
63 public void startUp(FloodlightModuleContext context) {
64 eventChannel = datagridService.createChannel(
65 EVENT_CHANNEL_NAME,
66 byte[].class,
67 IntentOperationList.class);
68 }
Toshio Koide27ffd412014-02-18 19:15:27 -080069
Toshio Koide4f308732014-02-18 15:19:48 -080070 protected void publishPathIntentOperationList(IntentOperationList list) {
71 eventChannel.addEntry(new byte[1], list); // TODO make key bytes
72 }
Toshio Koide27ffd412014-02-18 19:15:27 -080073
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 Koide4f308732014-02-18 15:19:48 -080085 return highLevelIntents;
86 }
Toshio Koide27ffd412014-02-18 19:15:27 -080087
88 @Override
89 public IntentMap getPathIntents() {
90 return pathIntents;
91 }
92
93 @Override
Toshio Koide4f308732014-02-18 15:19:48 -080094 public void purgeIntents() {
95 highLevelIntents.purge();
Toshio Koide27ffd412014-02-18 19:15:27 -080096 pathIntents.purge();
Toshio Koide4f308732014-02-18 15:19:48 -080097 }
98}