blob: 45facb5e960c82f7bcb188f4833437df024ddacc [file] [log] [blame]
Brian O'Connor12861f72014-02-19 20:40:32 -08001package net.onrc.onos.intent.runtime;
2
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.List;
6import java.util.Map;
7import java.util.Set;
8import java.util.concurrent.BlockingQueue;
9import java.util.concurrent.LinkedBlockingQueue;
10
11import net.floodlightcontroller.core.IFloodlightProviderService;
12import net.floodlightcontroller.core.module.FloodlightModuleContext;
13import net.floodlightcontroller.core.module.FloodlightModuleException;
14import net.floodlightcontroller.core.module.IFloodlightModule;
15import net.floodlightcontroller.core.module.IFloodlightService;
16import net.onrc.onos.datagrid.IDatagridService;
17import net.onrc.onos.datagrid.IEventChannelListener;
18import net.onrc.onos.intent.FlowEntry;
19import net.onrc.onos.intent.IntentOperationList;
20import net.onrc.onos.ofcontroller.flowprogrammer.IFlowPusherService;
Brian O'Connor135a95e2014-02-20 13:48:44 -080021import net.onrc.onos.ofcontroller.networkgraph.INetworkGraphService;
Brian O'Connor12861f72014-02-19 20:40:32 -080022import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
23
24public class PlanInstallModule implements IFloodlightModule {
25 protected volatile IFloodlightProviderService floodlightProvider;
Brian O'Connor135a95e2014-02-20 13:48:44 -080026 protected volatile INetworkGraphService networkGraph;
Brian O'Connor12861f72014-02-19 20:40:32 -080027 protected volatile IDatagridService datagridService;
28 protected volatile IFlowPusherService flowPusher;
29 private PlanCalcRuntime planCalc;
30 private PlanInstallRuntime planInstall;
31 private EventListener eventListener;
32
33 private static final String PATH_INTENT_CHANNEL_NAME = "onos.pathintent";
34
35 @Override
36 public void init(FloodlightModuleContext context)
37 throws FloodlightModuleException {
38 floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
Brian O'Connor135a95e2014-02-20 13:48:44 -080039 networkGraph = context.getServiceImpl(INetworkGraphService.class);
Brian O'Connor12861f72014-02-19 20:40:32 -080040 datagridService = context.getServiceImpl(IDatagridService.class);
41 flowPusher = context.getServiceImpl(IFlowPusherService.class);
Brian O'Connor135a95e2014-02-20 13:48:44 -080042 NetworkGraph graph = networkGraph.getNetworkGraph();
43 planCalc = new PlanCalcRuntime(graph);
44 planInstall = new PlanInstallRuntime(graph, floodlightProvider, flowPusher);
Brian O'Connor12861f72014-02-19 20:40:32 -080045 eventListener = new EventListener();
46 }
47
48 class EventListener extends Thread
49 implements IEventChannelListener<Long, IntentOperationList> {
50
51 private BlockingQueue<IntentOperationList> intentQueue = new LinkedBlockingQueue<>();
52
53 @Override
54 public void run() {
55 while(true) {
56 try {
57 IntentOperationList intents = intentQueue.take();
58 //TODO: drain the remaining intent lists
59 processIntents(intents);
60 } catch (InterruptedException e) {
61 //TODO: log the exception
62 }
63 }
64 }
65
66 private void processIntents(IntentOperationList intents) {
67 List<Set<FlowEntry>> plan = planCalc.computePlan(intents);
68 planInstall.installPlan(plan);
69 }
70
71 @Override
72 public void entryAdded(IntentOperationList value) {
73 intentQueue.add(value);
74 }
75
76 @Override
77 public void entryRemoved(IntentOperationList value) {
78 // This channel is a queue, so this method is not needed
79 }
80
81 @Override
82 public void entryUpdated(IntentOperationList value) {
83 // This channel is a queue, so this method is not needed
84 }
85 }
86 @Override
87 public void startUp(FloodlightModuleContext context) {
88 eventListener.start();
89 datagridService.addListener(PATH_INTENT_CHANNEL_NAME,
90 new EventListener(),
91 Long.class,
92 IntentOperationList.class);
93 }
94
95 @Override
96 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
97 Collection<Class<? extends IFloodlightService>> l =
98 new ArrayList<Class<? extends IFloodlightService>>();
99 l.add(IFloodlightProviderService.class);
Brian O'Connor135a95e2014-02-20 13:48:44 -0800100 l.add(INetworkGraphService.class);
Brian O'Connor12861f72014-02-19 20:40:32 -0800101 l.add(IDatagridService.class);
102 l.add(IFlowPusherService.class);
103 return l;
104 }
105
106 @Override
107 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
108 // TODO Auto-generated method stub
109 return null;
110 }
111
112 @Override
113 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
114 // TODO Auto-generated method stub
115 return null;
116 }
117
118}