blob: 76fa263cbe6df4dd2b6c9285e2b516b26da9b217 [file] [log] [blame]
Jonathan Hartaa380972014-04-03 10:24:46 -07001package net.onrc.onos.core.intent.runtime;
Toshio Koide4f308732014-02-18 15:19:48 -08002
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.HashMap;
Toshio Koide798bc1b2014-02-20 14:02:40 -08006import java.util.HashSet;
Toshio Koidedf2eab92014-02-20 11:24:59 -08007import java.util.Iterator;
Toshio Koidebf875662014-02-24 12:19:15 -08008import java.util.LinkedList;
Toshio Koide4f308732014-02-18 15:19:48 -08009import java.util.Map;
Toshio Koide066506e2014-02-20 19:52:09 -080010import java.util.Map.Entry;
Toshio Koide93be5d62014-02-23 19:30:57 -080011import java.util.concurrent.locks.ReentrantLock;
Toshio Koide4f308732014-02-18 15:19:48 -080012
13import net.floodlightcontroller.core.module.FloodlightModuleContext;
14import net.floodlightcontroller.core.module.FloodlightModuleException;
15import net.floodlightcontroller.core.module.IFloodlightModule;
16import net.floodlightcontroller.core.module.IFloodlightService;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070017import net.floodlightcontroller.restserver.IRestApiService;
Jonathan Hart6df90172014-04-03 10:13:11 -070018import net.onrc.onos.core.datagrid.IDatagridService;
19import net.onrc.onos.core.datagrid.IEventChannel;
20import net.onrc.onos.core.datagrid.IEventChannelListener;
Jonathan Hartaa380972014-04-03 10:24:46 -070021import net.onrc.onos.core.intent.Intent;
Jonathan Harta99ec672014-04-03 11:30:34 -070022import net.onrc.onos.core.intent.Intent.IntentState;
Jonathan Hartaa380972014-04-03 10:24:46 -070023import net.onrc.onos.core.intent.IntentMap;
24import net.onrc.onos.core.intent.IntentOperation;
Jonathan Harta99ec672014-04-03 11:30:34 -070025import net.onrc.onos.core.intent.IntentOperation.Operator;
Jonathan Hartaa380972014-04-03 10:24:46 -070026import net.onrc.onos.core.intent.IntentOperationList;
27import net.onrc.onos.core.intent.PathIntent;
28import net.onrc.onos.core.intent.PathIntentMap;
29import net.onrc.onos.core.intent.ShortestPathIntent;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070030import net.onrc.onos.core.intent.runtime.web.IntentWebRoutable;
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070031import net.onrc.onos.core.registry.IControllerRegistryService;
Jonathan Hart472062d2014-04-03 10:56:48 -070032import net.onrc.onos.core.topology.DeviceEvent;
Jonathan Harte37e4e22014-05-13 19:12:02 -070033import net.onrc.onos.core.topology.ITopologyListener;
34import net.onrc.onos.core.topology.ITopologyService;
Jonathan Hart472062d2014-04-03 10:56:48 -070035import net.onrc.onos.core.topology.LinkEvent;
36import net.onrc.onos.core.topology.PortEvent;
37import net.onrc.onos.core.topology.SwitchEvent;
Toshio Koide4f308732014-02-18 15:19:48 -080038
Jonathan Harta99ec672014-04-03 11:30:34 -070039import org.slf4j.Logger;
40import org.slf4j.LoggerFactory;
41
Toshio Koide0c9106d2014-02-19 15:26:38 -080042/**
43 * @author Toshio Koide (t-koide@onlab.us)
44 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070045public class PathCalcRuntimeModule implements IFloodlightModule, IPathCalcRuntimeService, ITopologyListener, IEventChannelListener<Long, IntentStateList> {
Pavlin Radoslavovfee80982014-04-10 12:12:04 -070046 static class PerfLog {
Ray Milkey269ffb92014-04-03 14:43:30 -070047 private String step;
48 private long time;
Toshio Koidebf875662014-02-24 12:19:15 -080049
Ray Milkey269ffb92014-04-03 14:43:30 -070050 public PerfLog(String step) {
51 this.step = step;
52 this.time = System.nanoTime();
53 }
Toshio Koidebf875662014-02-24 12:19:15 -080054
Ray Milkey269ffb92014-04-03 14:43:30 -070055 public void logThis() {
Pavlin Radoslavov964f8ae2014-04-18 16:44:14 -070056 log.debug("Time:{}, Step:{}", time, step);
Ray Milkey269ffb92014-04-03 14:43:30 -070057 }
58 }
Toshio Koidebf875662014-02-24 12:19:15 -080059
Pavlin Radoslavov53ad5e32014-04-10 14:24:26 -070060 static class PerfLogger {
Ray Milkey269ffb92014-04-03 14:43:30 -070061 private LinkedList<PerfLog> logData = new LinkedList<>();
Toshio Koidebf875662014-02-24 12:19:15 -080062
Ray Milkey269ffb92014-04-03 14:43:30 -070063 public PerfLogger(String logPhase) {
64 log("start_" + logPhase);
65 }
Toshio Koidebf875662014-02-24 12:19:15 -080066
Ray Milkey269ffb92014-04-03 14:43:30 -070067 public void log(String step) {
68 logData.add(new PerfLog(step));
69 }
Toshio Koide27ffd412014-02-18 19:15:27 -080070
Ray Milkey269ffb92014-04-03 14:43:30 -070071 public void flushLog() {
72 log("finish");
Ray Milkey5df613b2014-04-15 10:50:56 -070073 for (PerfLog perfLog : logData) {
74 perfLog.logThis();
Ray Milkey269ffb92014-04-03 14:43:30 -070075 }
76 logData.clear();
77 }
78 }
Toshio Koide4f308732014-02-18 15:19:48 -080079
Ray Milkey269ffb92014-04-03 14:43:30 -070080 private PathCalcRuntime runtime;
81 private IDatagridService datagridService;
Jonathan Harte37e4e22014-05-13 19:12:02 -070082 private ITopologyService topologyService;
Ray Milkey269ffb92014-04-03 14:43:30 -070083 private IntentMap highLevelIntents;
84 private PathIntentMap pathIntents;
85 private IControllerRegistryService controllerRegistry;
86 private PersistIntent persistIntent;
Pavlin Radoslavov13669052014-05-13 10:33:39 -070087 private IRestApiService restApi;
Toshio Koide798bc1b2014-02-20 14:02:40 -080088
Ray Milkey269ffb92014-04-03 14:43:30 -070089 private IEventChannel<Long, IntentOperationList> opEventChannel;
90 private final ReentrantLock lock = new ReentrantLock();
91 private HashSet<LinkEvent> unmatchedLinkEvents = new HashSet<>();
92 private static final String INTENT_OP_EVENT_CHANNEL_NAME = "onos.pathintent";
93 private static final String INTENT_STATE_EVENT_CHANNEL_NAME = "onos.pathintent_state";
94 private static final Logger log = LoggerFactory.getLogger(PathCalcRuntimeModule.class);
Toshio Koidea10c0372014-02-20 17:28:10 -080095
Ray Milkey269ffb92014-04-03 14:43:30 -070096 // ================================================================================
97 // private methods
98 // ================================================================================
99
100 private void reroutePaths(Collection<Intent> oldPaths) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700101 if (oldPaths == null || oldPaths.isEmpty()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700102 return;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700103 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700104
105 IntentOperationList reroutingOperation = new IntentOperationList();
106 for (Intent intent : oldPaths) {
107 PathIntent pathIntent = (PathIntent) intent;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700108 if (pathIntent.isPathFrozen()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700109 continue;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700110 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700111 if (pathIntent.getState().equals(IntentState.INST_ACK) && // XXX: path intents in flight
112 !reroutingOperation.contains(pathIntent.getParentIntent())) {
113 reroutingOperation.add(Operator.ADD, pathIntent.getParentIntent());
114 }
115 }
116 executeIntentOperations(reroutingOperation);
117 }
Toshio Koidea94060f2014-02-21 22:58:32 -0800118
Toshio Koide27ffd412014-02-18 19:15:27 -0800119
Ray Milkey269ffb92014-04-03 14:43:30 -0700120 // ================================================================================
121 // IFloodlightModule implementations
122 // ================================================================================
Toshio Koide798bc1b2014-02-20 14:02:40 -0800123
Ray Milkey269ffb92014-04-03 14:43:30 -0700124 @Override
125 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
126 Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(1);
127 l.add(IPathCalcRuntimeService.class);
128 return l;
129 }
Toshio Koide4f308732014-02-18 15:19:48 -0800130
Ray Milkey269ffb92014-04-03 14:43:30 -0700131 @Override
132 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
133 Map<Class<? extends IFloodlightService>, IFloodlightService> m = new HashMap<>();
134 m.put(IPathCalcRuntimeService.class, this);
135 return m;
136 }
Toshio Koide4f308732014-02-18 15:19:48 -0800137
Ray Milkey269ffb92014-04-03 14:43:30 -0700138 @Override
139 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
140 Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(2);
141 l.add(IDatagridService.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700142 l.add(IRestApiService.class);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700143 l.add(ITopologyService.class);
Ray Milkey269ffb92014-04-03 14:43:30 -0700144 return l;
145 }
Toshio Koide4f308732014-02-18 15:19:48 -0800146
Ray Milkey269ffb92014-04-03 14:43:30 -0700147 @Override
148 public void init(FloodlightModuleContext context) throws FloodlightModuleException {
149 datagridService = context.getServiceImpl(IDatagridService.class);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700150 topologyService = context.getServiceImpl(ITopologyService.class);
Ray Milkey269ffb92014-04-03 14:43:30 -0700151 controllerRegistry = context.getServiceImpl(IControllerRegistryService.class);
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700152 restApi = context.getServiceImpl(IRestApiService.class);
Ray Milkey269ffb92014-04-03 14:43:30 -0700153 }
Toshio Koide4f308732014-02-18 15:19:48 -0800154
Ray Milkey269ffb92014-04-03 14:43:30 -0700155 @Override
156 public void startUp(FloodlightModuleContext context) {
157 highLevelIntents = new IntentMap();
Jonathan Harte37e4e22014-05-13 19:12:02 -0700158 runtime = new PathCalcRuntime(topologyService.getTopology());
Ray Milkey269ffb92014-04-03 14:43:30 -0700159 pathIntents = new PathIntentMap();
160 opEventChannel = datagridService.createChannel(INTENT_OP_EVENT_CHANNEL_NAME, Long.class, IntentOperationList.class);
161 datagridService.addListener(INTENT_STATE_EVENT_CHANNEL_NAME, this, Long.class, IntentStateList.class);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700162 topologyService.registerTopologyListener(this);
Pavlin Radoslavov0294e052014-04-10 13:36:45 -0700163 persistIntent = new PersistIntent(controllerRegistry);
Pavlin Radoslavov13669052014-05-13 10:33:39 -0700164 restApi.addRestletRoutable(new IntentWebRoutable());
Ray Milkey269ffb92014-04-03 14:43:30 -0700165 }
Toshio Koide27ffd412014-02-18 19:15:27 -0800166
Ray Milkey269ffb92014-04-03 14:43:30 -0700167 // ================================================================================
168 // IPathCalcRuntimeService implementations
169 // ================================================================================
Toshio Koide798bc1b2014-02-20 14:02:40 -0800170
Ray Milkey269ffb92014-04-03 14:43:30 -0700171 @Override
172 public IntentOperationList executeIntentOperations(IntentOperationList list) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700173 if (list == null || list.size() == 0) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700174 return null;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700175 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700176 PerfLogger p = new PerfLogger("executeIntentOperations_" + list.get(0).operator);
Toshio Koide275d8142014-02-24 16:41:52 -0800177
Ray Milkey269ffb92014-04-03 14:43:30 -0700178 lock.lock(); // TODO optimize locking using smaller steps
179 try {
180 // update the map of high-level intents
181 p.log("begin_updateInMemoryIntents");
182 highLevelIntents.executeOperations(list);
Toshio Koidedf2eab92014-02-20 11:24:59 -0800183
Ray Milkey269ffb92014-04-03 14:43:30 -0700184 // change states of high-level intents
185 IntentStateList states = new IntentStateList();
186 for (IntentOperation op : list) {
187 switch (op.operator) {
188 case ADD:
189 switch (op.intent.getState()) {
190 case CREATED:
191 states.put(op.intent.getId(), IntentState.INST_REQ);
192 break;
193 case INST_ACK:
194 states.put(op.intent.getId(), IntentState.REROUTE_REQ);
195 break;
196 default:
197 break;
198 }
199 break;
200 case REMOVE:
201 switch (op.intent.getState()) {
202 case CREATED:
203 states.put(op.intent.getId(), IntentState.DEL_REQ);
204 break;
205 default:
206 break;
207 }
208 break;
209 default:
210 break;
211 }
212 }
213 highLevelIntents.changeStates(states);
214 p.log("end_updateInMemoryIntents");
Toshio Koidedf2eab92014-02-20 11:24:59 -0800215
Ray Milkey269ffb92014-04-03 14:43:30 -0700216 // calculate path-intents (low-level operations)
217 p.log("begin_calcPathIntents");
218 IntentOperationList pathIntentOperations = runtime.calcPathIntents(list, highLevelIntents, pathIntents);
219 p.log("end_calcPathIntents");
Toshio Koide600ae5f2014-02-20 18:42:00 -0800220
Ray Milkey269ffb92014-04-03 14:43:30 -0700221 // persist calculated low-level operations into data store
222 p.log("begin_persistPathIntents");
223 long key = persistIntent.getKey();
224 persistIntent.persistIfLeader(key, pathIntentOperations);
225 p.log("end_persistPathIntents");
Toshio Koide93be5d62014-02-23 19:30:57 -0800226
Ray Milkey269ffb92014-04-03 14:43:30 -0700227 // remove error-intents and reflect them to high-level intents
228 p.log("begin_removeErrorIntents");
229 states.clear();
230 Iterator<IntentOperation> i = pathIntentOperations.iterator();
231 while (i.hasNext()) {
232 IntentOperation op = i.next();
233 if (op.operator.equals(Operator.ERROR)) {
234 states.put(op.intent.getId(), IntentState.INST_NACK);
235 i.remove();
236 }
237 }
238 highLevelIntents.changeStates(states);
239 p.log("end_removeErrorIntents");
Toshio Koidea94060f2014-02-21 22:58:32 -0800240
Ray Milkey269ffb92014-04-03 14:43:30 -0700241 // update the map of path intents and publish the path operations
242 p.log("begin_updateInMemoryPathIntents");
243 pathIntents.executeOperations(pathIntentOperations);
244 p.log("end_updateInMemoryPathIntents");
Toshio Koide93be5d62014-02-23 19:30:57 -0800245
Ray Milkey269ffb92014-04-03 14:43:30 -0700246 // XXX Demo special: add a complete path to remove operation
247 p.log("begin_addPathToRemoveOperation");
248 for (IntentOperation op : pathIntentOperations) {
249 if (op.operator.equals(Operator.REMOVE)) {
250 op.intent = pathIntents.getIntent(op.intent.getId());
251 }
252 if (op.intent instanceof PathIntent) {
253 log.debug("operation: {}, intent:{}", op.operator, op.intent);
254 }
255 }
256 p.log("end_addPathToRemoveOperation");
Toshio Koide93be5d62014-02-23 19:30:57 -0800257
Ray Milkey269ffb92014-04-03 14:43:30 -0700258 // send notification
259 p.log("begin_sendNotification");
260 // XXX: Send notifications using the same key every time
261 // and receive them by entryAdded() and entryUpdated()
262 opEventChannel.addEntry(0L, pathIntentOperations);
263 p.log("end_sendNotification");
264 //opEventChannel.removeEntry(key);
265 return pathIntentOperations;
266 } finally {
Ray Milkey269ffb92014-04-03 14:43:30 -0700267 lock.unlock();
Pavlin Radoslavovc68974f2014-04-09 17:28:38 -0700268 p.flushLog();
Ray Milkey269ffb92014-04-03 14:43:30 -0700269 }
270 }
Toshio Koide27ffd412014-02-18 19:15:27 -0800271
Ray Milkey269ffb92014-04-03 14:43:30 -0700272 @Override
273 public IntentMap getHighLevelIntents() {
274 return highLevelIntents;
275 }
Toshio Koide27ffd412014-02-18 19:15:27 -0800276
Ray Milkey269ffb92014-04-03 14:43:30 -0700277 @Override
278 public IntentMap getPathIntents() {
279 return pathIntents;
280 }
Toshio Koide27ffd412014-02-18 19:15:27 -0800281
Ray Milkey269ffb92014-04-03 14:43:30 -0700282 @Override
283 public void purgeIntents() {
284 highLevelIntents.purge();
285 pathIntents.purge();
286 }
Toshio Koide0c9106d2014-02-19 15:26:38 -0800287
Ray Milkey269ffb92014-04-03 14:43:30 -0700288 // ================================================================================
Jonathan Harte37e4e22014-05-13 19:12:02 -0700289 // ITopologyListener implementations
Ray Milkey269ffb92014-04-03 14:43:30 -0700290 // ================================================================================
Toshio Koide798bc1b2014-02-20 14:02:40 -0800291
Ray Milkeya5450cc2014-04-17 14:31:30 -0700292 // CHECKSTYLE:OFF suppress warning about too many parameters
Ray Milkey269ffb92014-04-03 14:43:30 -0700293 @Override
Jonathan Harte37e4e22014-05-13 19:12:02 -0700294 public void topologyEvents(Collection<SwitchEvent> addedSwitchEvents,
Ray Milkey269ffb92014-04-03 14:43:30 -0700295 Collection<SwitchEvent> removedSwitchEvents,
296 Collection<PortEvent> addedPortEvents,
297 Collection<PortEvent> removedPortEvents,
298 Collection<LinkEvent> addedLinkEvents,
299 Collection<LinkEvent> removedLinkEvents,
300 Collection<DeviceEvent> addedDeviceEvents,
301 Collection<DeviceEvent> removedDeviceEvents) {
Ray Milkeya5450cc2014-04-17 14:31:30 -0700302 // CHECKSTYLE:ON
Toshio Koidea9078af2014-02-21 16:57:04 -0800303
Ray Milkey269ffb92014-04-03 14:43:30 -0700304 PerfLogger p = new PerfLogger("networkGraphEvents");
305 HashSet<Intent> affectedPaths = new HashSet<>();
Toshio Koide93797dc2014-02-27 23:54:26 -0800306
Ray Milkey269ffb92014-04-03 14:43:30 -0700307 boolean rerouteAll = false;
308 for (LinkEvent le : addedLinkEvents) {
309 LinkEvent rev = new LinkEvent(le.getDst().getDpid(), le.getDst().getNumber(), le.getSrc().getDpid(), le.getSrc().getNumber());
310 if (unmatchedLinkEvents.contains(rev)) {
311 rerouteAll = true;
312 unmatchedLinkEvents.remove(rev);
313 log.debug("Found matched LinkEvent: {} {}", rev, le);
314 } else {
315 unmatchedLinkEvents.add(le);
316 log.debug("Adding unmatched LinkEvent: {}", le);
317 }
318 }
319 for (LinkEvent le : removedLinkEvents) {
320 if (unmatchedLinkEvents.contains(le)) {
321 unmatchedLinkEvents.remove(le);
322 log.debug("Removing LinkEvent: {}", le);
323 }
324 }
325 if (unmatchedLinkEvents.size() > 0) {
326 log.debug("Unmatched link events: {} events", unmatchedLinkEvents.size());
327 }
Toshio Koidea9078af2014-02-21 16:57:04 -0800328
Ray Milkey7f1567c2014-04-08 13:53:32 -0700329 if (rerouteAll) { //addedLinkEvents.size() > 0) { // ||
Ray Milkey269ffb92014-04-03 14:43:30 -0700330// addedPortEvents.size() > 0 ||
331// addedSwitchEvents.size() > 0) {
332 p.log("begin_getAllIntents");
333 affectedPaths.addAll(getPathIntents().getAllIntents());
334 p.log("end_getAllIntents");
335 } else if (removedSwitchEvents.size() > 0 ||
336 removedLinkEvents.size() > 0 ||
337 removedPortEvents.size() > 0) {
338 p.log("begin_getIntentsByLink");
Ray Milkeyb29e6262014-04-09 16:02:14 -0700339 for (LinkEvent linkEvent : removedLinkEvents) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700340 affectedPaths.addAll(pathIntents.getIntentsByLink(linkEvent));
Ray Milkeyb29e6262014-04-09 16:02:14 -0700341 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700342 p.log("end_getIntentsByLink");
Toshio Koidea9078af2014-02-21 16:57:04 -0800343
Ray Milkey269ffb92014-04-03 14:43:30 -0700344 p.log("begin_getIntentsByPort");
Ray Milkeyb29e6262014-04-09 16:02:14 -0700345 for (PortEvent portEvent : removedPortEvents) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700346 affectedPaths.addAll(pathIntents.getIntentsByPort(portEvent.getDpid(), portEvent.getNumber()));
Ray Milkeyb29e6262014-04-09 16:02:14 -0700347 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700348 p.log("end_getIntentsByPort");
Toshio Koidea9078af2014-02-21 16:57:04 -0800349
Ray Milkey269ffb92014-04-03 14:43:30 -0700350 p.log("begin_getIntentsByDpid");
Ray Milkeyb29e6262014-04-09 16:02:14 -0700351 for (SwitchEvent switchEvent : removedSwitchEvents) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700352 affectedPaths.addAll(pathIntents.getIntentsByDpid(switchEvent.getDpid()));
Ray Milkeyb29e6262014-04-09 16:02:14 -0700353 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700354 p.log("end_getIntentsByDpid");
355 }
356 p.log("begin_reroutePaths");
357 reroutePaths(affectedPaths);
358 p.log("end_reroutePaths");
359 p.flushLog();
360 }
Toshio Koide066506e2014-02-20 19:52:09 -0800361
Ray Milkey269ffb92014-04-03 14:43:30 -0700362 // ================================================================================
363 // IEventChannelListener implementations
364 // ================================================================================
Toshio Koide066506e2014-02-20 19:52:09 -0800365
Ray Milkey269ffb92014-04-03 14:43:30 -0700366 @Override
367 public void entryAdded(IntentStateList value) {
368 entryUpdated(value);
369 }
Toshio Koide066506e2014-02-20 19:52:09 -0800370
Ray Milkey269ffb92014-04-03 14:43:30 -0700371 @Override
372 public void entryRemoved(IntentStateList value) {
373 // do nothing
374 }
Toshio Koide066506e2014-02-20 19:52:09 -0800375
Ray Milkey269ffb92014-04-03 14:43:30 -0700376 @Override
377 public void entryUpdated(IntentStateList value) {
378 // TODO draw state transition diagram in multiple ONOS instances and update this method
379 PerfLogger p = new PerfLogger("entryUpdated");
380 lock.lock(); // TODO optimize locking using smaller steps
381 try {
382 // reflect state changes of path-level intent into application-level intents
383 p.log("begin_changeStateByNotification");
384 IntentStateList highLevelIntentStates = new IntentStateList();
385 IntentStateList pathIntentStates = new IntentStateList();
386 for (Entry<String, IntentState> entry : value.entrySet()) {
387 PathIntent pathIntent = (PathIntent) pathIntents.getIntent(entry.getKey());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700388 if (pathIntent == null) {
389 continue;
390 }
Toshio Koide8315d7d2014-02-21 22:58:32 -0800391
Ray Milkey269ffb92014-04-03 14:43:30 -0700392 Intent parentIntent = pathIntent.getParentIntent();
393 if (parentIntent == null ||
394 !(parentIntent instanceof ShortestPathIntent) ||
Ray Milkeyb29e6262014-04-09 16:02:14 -0700395 !((ShortestPathIntent) parentIntent).getPathIntentId().equals(pathIntent.getId())) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700396 continue;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700397 }
Toshio Koide066506e2014-02-20 19:52:09 -0800398
Ray Milkey269ffb92014-04-03 14:43:30 -0700399 IntentState state = entry.getValue();
400 switch (state) {
401 //case INST_REQ:
402 case INST_ACK:
403 case INST_NACK:
404 //case DEL_REQ:
405 case DEL_ACK:
406 case DEL_PENDING:
407 highLevelIntentStates.put(parentIntent.getId(), state);
408 pathIntentStates.put(entry.getKey(), entry.getValue());
409 break;
410 default:
411 break;
412 }
413 }
414 highLevelIntents.changeStates(highLevelIntentStates);
415 pathIntents.changeStates(pathIntentStates);
416 p.log("end_changeStateByNotification");
417 } finally {
Ray Milkey269ffb92014-04-03 14:43:30 -0700418 lock.unlock();
Pavlin Radoslavovc68974f2014-04-09 17:28:38 -0700419 p.flushLog();
Ray Milkey269ffb92014-04-03 14:43:30 -0700420 }
421 }
Toshio Koidea9078af2014-02-21 16:57:04 -0800422}