blob: df4c762df2e3467b5b8d96fe6f4c621af59c8380 [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;
21import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
22
23public class PlanInstallModule implements IFloodlightModule {
24 protected volatile IFloodlightProviderService floodlightProvider;
25 protected volatile NetworkGraph networkGraph;
26 protected volatile IDatagridService datagridService;
27 protected volatile IFlowPusherService flowPusher;
28 private PlanCalcRuntime planCalc;
29 private PlanInstallRuntime planInstall;
30 private EventListener eventListener;
31
32 private static final String PATH_INTENT_CHANNEL_NAME = "onos.pathintent";
33
34 @Override
35 public void init(FloodlightModuleContext context)
36 throws FloodlightModuleException {
37 floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
38 //networkGraph = context.getServiceImpl(INetworkGraphService.class);
39 datagridService = context.getServiceImpl(IDatagridService.class);
40 flowPusher = context.getServiceImpl(IFlowPusherService.class);
41 planCalc = new PlanCalcRuntime(networkGraph);
42 planInstall = new PlanInstallRuntime(networkGraph, floodlightProvider, flowPusher);
43 eventListener = new EventListener();
44 }
45
46 class EventListener extends Thread
47 implements IEventChannelListener<Long, IntentOperationList> {
48
49 private BlockingQueue<IntentOperationList> intentQueue = new LinkedBlockingQueue<>();
50
51 @Override
52 public void run() {
53 while(true) {
54 try {
55 IntentOperationList intents = intentQueue.take();
56 //TODO: drain the remaining intent lists
57 processIntents(intents);
58 } catch (InterruptedException e) {
59 //TODO: log the exception
60 }
61 }
62 }
63
64 private void processIntents(IntentOperationList intents) {
65 List<Set<FlowEntry>> plan = planCalc.computePlan(intents);
66 planInstall.installPlan(plan);
67 }
68
69 @Override
70 public void entryAdded(IntentOperationList value) {
71 intentQueue.add(value);
72 }
73
74 @Override
75 public void entryRemoved(IntentOperationList value) {
76 // This channel is a queue, so this method is not needed
77 }
78
79 @Override
80 public void entryUpdated(IntentOperationList value) {
81 // This channel is a queue, so this method is not needed
82 }
83 }
84 @Override
85 public void startUp(FloodlightModuleContext context) {
86 eventListener.start();
87 datagridService.addListener(PATH_INTENT_CHANNEL_NAME,
88 new EventListener(),
89 Long.class,
90 IntentOperationList.class);
91 }
92
93 @Override
94 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
95 Collection<Class<? extends IFloodlightService>> l =
96 new ArrayList<Class<? extends IFloodlightService>>();
97 l.add(IFloodlightProviderService.class);
98// l.add(INetworkGraphService.class);
99 l.add(IDatagridService.class);
100 l.add(IFlowPusherService.class);
101 return l;
102 }
103
104 @Override
105 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
106 // TODO Auto-generated method stub
107 return null;
108 }
109
110 @Override
111 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
112 // TODO Auto-generated method stub
113 return null;
114 }
115
116}