blob: 8c219c208cdc2d2fd023e99e11cc06f7e429efbe [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;
Jonathan Hart6df90172014-04-03 10:13:11 -070017import net.onrc.onos.core.datagrid.IDatagridService;
18import net.onrc.onos.core.datagrid.IEventChannel;
19import net.onrc.onos.core.datagrid.IEventChannelListener;
Jonathan Hartaa380972014-04-03 10:24:46 -070020import net.onrc.onos.core.intent.Intent;
Jonathan Harta99ec672014-04-03 11:30:34 -070021import net.onrc.onos.core.intent.Intent.IntentState;
Jonathan Hartaa380972014-04-03 10:24:46 -070022import net.onrc.onos.core.intent.IntentMap;
23import net.onrc.onos.core.intent.IntentOperation;
Jonathan Harta99ec672014-04-03 11:30:34 -070024import net.onrc.onos.core.intent.IntentOperation.Operator;
Jonathan Hartaa380972014-04-03 10:24:46 -070025import net.onrc.onos.core.intent.IntentOperationList;
26import net.onrc.onos.core.intent.PathIntent;
27import net.onrc.onos.core.intent.PathIntentMap;
28import net.onrc.onos.core.intent.ShortestPathIntent;
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070029import net.onrc.onos.core.registry.IControllerRegistryService;
Jonathan Hart472062d2014-04-03 10:56:48 -070030import net.onrc.onos.core.topology.DeviceEvent;
31import net.onrc.onos.core.topology.INetworkGraphListener;
32import net.onrc.onos.core.topology.INetworkGraphService;
33import net.onrc.onos.core.topology.LinkEvent;
34import net.onrc.onos.core.topology.PortEvent;
35import net.onrc.onos.core.topology.SwitchEvent;
Toshio Koide4f308732014-02-18 15:19:48 -080036
Jonathan Harta99ec672014-04-03 11:30:34 -070037import org.slf4j.Logger;
38import org.slf4j.LoggerFactory;
39
Toshio Koide0c9106d2014-02-19 15:26:38 -080040/**
41 * @author Toshio Koide (t-koide@onlab.us)
42 */
Toshio Koide066506e2014-02-20 19:52:09 -080043public class PathCalcRuntimeModule implements IFloodlightModule, IPathCalcRuntimeService, INetworkGraphListener, IEventChannelListener<Long, IntentStateList> {
Toshio Koidebf875662014-02-24 12:19:15 -080044 class PerfLog {
45 private String step;
46 private long time;
47
48 public PerfLog(String step) {
49 this.step = step;
50 this.time = System.nanoTime();
51 }
52
53 public void logThis() {
54 log.error("Time:{}, Step:{}", time, step);
55 }
56 }
57 class PerfLogger {
58 private LinkedList<PerfLog> logData = new LinkedList<>();
59
60 public PerfLogger(String logPhase) {
61 log("start_" + logPhase);
62 }
63
64 public void log(String step) {
65 logData.add(new PerfLog(step));
66 }
67
68 public void flushLog() {
69 log("finish");
70 for (PerfLog log: logData) {
71 log.logThis();
72 }
73 logData.clear();
74 }
75 }
Toshio Koide4f308732014-02-18 15:19:48 -080076 private PathCalcRuntime runtime;
77 private IDatagridService datagridService;
Toshio Koide27ffd412014-02-18 19:15:27 -080078 private INetworkGraphService networkGraphService;
Toshio Koide4f308732014-02-18 15:19:48 -080079 private IntentMap highLevelIntents;
Toshio Koide27ffd412014-02-18 19:15:27 -080080 private PathIntentMap pathIntents;
Toshio Koide798bc1b2014-02-20 14:02:40 -080081 private IControllerRegistryService controllerRegistry;
82 private PersistIntent persistIntent;
Toshio Koide27ffd412014-02-18 19:15:27 -080083
Toshio Koide066506e2014-02-20 19:52:09 -080084 private IEventChannel<Long, IntentOperationList> opEventChannel;
Toshio Koide93be5d62014-02-23 19:30:57 -080085 private final ReentrantLock lock = new ReentrantLock();
Brian O'Connor5518d282014-02-25 22:25:58 -080086 private HashSet<LinkEvent> unmatchedLinkEvents = new HashSet<>();
Toshio Koide066506e2014-02-20 19:52:09 -080087 private static final String INTENT_OP_EVENT_CHANNEL_NAME = "onos.pathintent";
88 private static final String INTENT_STATE_EVENT_CHANNEL_NAME = "onos.pathintent_state";
Toshio Koidea94060f2014-02-21 22:58:32 -080089 private static final Logger log = LoggerFactory.getLogger(PathCalcRuntimeModule.class);
Toshio Koide4f308732014-02-18 15:19:48 -080090
Toshio Koide798bc1b2014-02-20 14:02:40 -080091 // ================================================================================
92 // private methods
93 // ================================================================================
94
Toshio Koidea94060f2014-02-21 22:58:32 -080095 private void reroutePaths(Collection<Intent> oldPaths) {
Toshio Koidea9078af2014-02-21 16:57:04 -080096 if (oldPaths == null || oldPaths.isEmpty())
Toshio Koide798bc1b2014-02-20 14:02:40 -080097 return;
Toshio Koidea10c0372014-02-20 17:28:10 -080098
Toshio Koide0c9106d2014-02-19 15:26:38 -080099 IntentOperationList reroutingOperation = new IntentOperationList();
Toshio Koide982c81f2014-02-23 16:53:10 -0800100 for (Intent intent : oldPaths) {
101 PathIntent pathIntent = (PathIntent) intent;
Toshio Koide565d6dd2014-03-27 11:22:25 -0700102 if (pathIntent.isPathFrozen())
Toshio Koide93797dc2014-02-27 23:54:26 -0800103 continue;
Brian O'Connor5518d282014-02-25 22:25:58 -0800104 if (pathIntent.getState().equals(IntentState.INST_ACK) && // XXX: path intents in flight
Toshio Koide93797dc2014-02-27 23:54:26 -0800105 !reroutingOperation.contains(pathIntent.getParentIntent())) {
Toshio Koide982c81f2014-02-23 16:53:10 -0800106 reroutingOperation.add(Operator.ADD, pathIntent.getParentIntent());
107 }
Toshio Koide0c9106d2014-02-19 15:26:38 -0800108 }
Toshio Koide8315d7d2014-02-21 22:58:32 -0800109 executeIntentOperations(reroutingOperation);
Toshio Koidea94060f2014-02-21 22:58:32 -0800110 }
111
Toshio Koide27ffd412014-02-18 19:15:27 -0800112
Toshio Koide798bc1b2014-02-20 14:02:40 -0800113 // ================================================================================
114 // IFloodlightModule implementations
115 // ================================================================================
116
Toshio Koide4f308732014-02-18 15:19:48 -0800117 @Override
118 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
119 Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(1);
Toshio Koideeb90d912014-02-18 21:30:22 -0800120 l.add(IPathCalcRuntimeService.class);
Toshio Koide4f308732014-02-18 15:19:48 -0800121 return l;
122 }
123
124 @Override
125 public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
Toshio Koidea9078af2014-02-21 16:57:04 -0800126 Map<Class<? extends IFloodlightService>, IFloodlightService> m = new HashMap<>();
Toshio Koide27ffd412014-02-18 19:15:27 -0800127 m.put(IPathCalcRuntimeService.class, this);
Toshio Koide4f308732014-02-18 15:19:48 -0800128 return m;
129 }
130
131 @Override
132 public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
Toshio Koidea9078af2014-02-21 16:57:04 -0800133 Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(2);
Toshio Koide4f308732014-02-18 15:19:48 -0800134 l.add(IDatagridService.class);
Toshio Koide27ffd412014-02-18 19:15:27 -0800135 l.add(INetworkGraphService.class);
Toshio Koide4f308732014-02-18 15:19:48 -0800136 return l;
137 }
138
139 @Override
140 public void init(FloodlightModuleContext context) throws FloodlightModuleException {
141 datagridService = context.getServiceImpl(IDatagridService.class);
Toshio Koided9fa2a82014-02-19 17:35:18 -0800142 networkGraphService = context.getServiceImpl(INetworkGraphService.class);
Toshio Koide798bc1b2014-02-20 14:02:40 -0800143 controllerRegistry = context.getServiceImpl(IControllerRegistryService.class);
Toshio Koide4f308732014-02-18 15:19:48 -0800144 }
145
146 @Override
147 public void startUp(FloodlightModuleContext context) {
Toshio Koideeb90d912014-02-18 21:30:22 -0800148 highLevelIntents = new IntentMap();
149 runtime = new PathCalcRuntime(networkGraphService.getNetworkGraph());
Toshio Koide0c9106d2014-02-19 15:26:38 -0800150 pathIntents = new PathIntentMap();
Toshio Koide066506e2014-02-20 19:52:09 -0800151 opEventChannel = datagridService.createChannel(INTENT_OP_EVENT_CHANNEL_NAME, Long.class, IntentOperationList.class);
152 datagridService.addListener(INTENT_STATE_EVENT_CHANNEL_NAME, this, Long.class, IntentStateList.class);
Toshio Koide0c9106d2014-02-19 15:26:38 -0800153 networkGraphService.registerNetworkGraphListener(this);
Toshio Koide798bc1b2014-02-20 14:02:40 -0800154 persistIntent = new PersistIntent(controllerRegistry, networkGraphService);
Toshio Koide4f308732014-02-18 15:19:48 -0800155 }
Toshio Koide27ffd412014-02-18 19:15:27 -0800156
Toshio Koide798bc1b2014-02-20 14:02:40 -0800157 // ================================================================================
158 // IPathCalcRuntimeService implementations
159 // ================================================================================
160
Toshio Koide27ffd412014-02-18 19:15:27 -0800161 @Override
162 public IntentOperationList executeIntentOperations(IntentOperationList list) {
Toshio Koidebf875662014-02-24 12:19:15 -0800163 if (list == null || list.size() == 0)
164 return null;
165 PerfLogger p = new PerfLogger("executeIntentOperations_" + list.get(0).operator);
Toshio Koide275d8142014-02-24 16:41:52 -0800166
167 lock.lock(); // TODO optimize locking using smaller steps
Toshio Koide93be5d62014-02-23 19:30:57 -0800168 try {
169 // update the map of high-level intents
Toshio Koidebf875662014-02-24 12:19:15 -0800170 p.log("begin_updateInMemoryIntents");
Toshio Koide93be5d62014-02-23 19:30:57 -0800171 highLevelIntents.executeOperations(list);
Toshio Koidedf2eab92014-02-20 11:24:59 -0800172
Toshio Koide93be5d62014-02-23 19:30:57 -0800173 // change states of high-level intents
174 IntentStateList states = new IntentStateList();
175 for (IntentOperation op : list) {
Toshio Koidefa735a12014-03-28 10:49:07 -0700176 switch (op.operator) {
177 case ADD:
178 switch (op.intent.getState()) {
179 case CREATED:
180 states.put(op.intent.getId(), IntentState.INST_REQ);
181 break;
182 case INST_ACK:
183 states.put(op.intent.getId(), IntentState.REROUTE_REQ);
184 break;
185 default:
186 break;
187 }
188 break;
189 case REMOVE:
190 switch (op.intent.getState()) {
191 case CREATED:
192 states.put(op.intent.getId(), IntentState.DEL_REQ);
193 break;
194 default:
195 break;
196 }
197 break;
198 default:
199 break;
200 }
Toshio Koidedf2eab92014-02-20 11:24:59 -0800201 }
Toshio Koide93be5d62014-02-23 19:30:57 -0800202 highLevelIntents.changeStates(states);
Toshio Koidebf875662014-02-24 12:19:15 -0800203 p.log("end_updateInMemoryIntents");
Toshio Koidedf2eab92014-02-20 11:24:59 -0800204
Toshio Koide93be5d62014-02-23 19:30:57 -0800205 // calculate path-intents (low-level operations)
Toshio Koidebf875662014-02-24 12:19:15 -0800206 p.log("begin_calcPathIntents");
Toshio Koide93be5d62014-02-23 19:30:57 -0800207 IntentOperationList pathIntentOperations = runtime.calcPathIntents(list, highLevelIntents, pathIntents);
Toshio Koidebf875662014-02-24 12:19:15 -0800208 p.log("end_calcPathIntents");
Toshio Koide600ae5f2014-02-20 18:42:00 -0800209
Toshio Koide93be5d62014-02-23 19:30:57 -0800210 // persist calculated low-level operations into data store
Toshio Koidebf875662014-02-24 12:19:15 -0800211 p.log("begin_persistPathIntents");
Toshio Koide93be5d62014-02-23 19:30:57 -0800212 long key = persistIntent.getKey();
213 persistIntent.persistIfLeader(key, pathIntentOperations);
Toshio Koidebf875662014-02-24 12:19:15 -0800214 p.log("end_persistPathIntents");
Toshio Koide93be5d62014-02-23 19:30:57 -0800215
216 // remove error-intents and reflect them to high-level intents
Toshio Koidebf875662014-02-24 12:19:15 -0800217 p.log("begin_removeErrorIntents");
Toshio Koide93be5d62014-02-23 19:30:57 -0800218 states.clear();
219 Iterator<IntentOperation> i = pathIntentOperations.iterator();
220 while (i.hasNext()) {
221 IntentOperation op = i.next();
222 if (op.operator.equals(Operator.ERROR)) {
223 states.put(op.intent.getId(), IntentState.INST_NACK);
224 i.remove();
225 }
Toshio Koide600ae5f2014-02-20 18:42:00 -0800226 }
Toshio Koide93be5d62014-02-23 19:30:57 -0800227 highLevelIntents.changeStates(states);
Toshio Koidebf875662014-02-24 12:19:15 -0800228 p.log("end_removeErrorIntents");
Toshio Koidea94060f2014-02-21 22:58:32 -0800229
Toshio Koide93be5d62014-02-23 19:30:57 -0800230 // update the map of path intents and publish the path operations
Toshio Koidebf875662014-02-24 12:19:15 -0800231 p.log("begin_updateInMemoryPathIntents");
Toshio Koide93be5d62014-02-23 19:30:57 -0800232 pathIntents.executeOperations(pathIntentOperations);
Toshio Koidebf875662014-02-24 12:19:15 -0800233 p.log("end_updateInMemoryPathIntents");
Toshio Koide93be5d62014-02-23 19:30:57 -0800234
Toshio Koide500431f2014-02-28 02:02:25 -0800235 // XXX Demo special: add a complete path to remove operation
Toshio Koidebf875662014-02-24 12:19:15 -0800236 p.log("begin_addPathToRemoveOperation");
Toshio Koide93be5d62014-02-23 19:30:57 -0800237 for (IntentOperation op: pathIntentOperations) {
238 if(op.operator.equals(Operator.REMOVE)) {
239 op.intent = pathIntents.getIntent(op.intent.getId());
240 }
241 if (op.intent instanceof PathIntent) {
242 log.debug("operation: {}, intent:{}", op.operator, op.intent);
243 }
244 }
Toshio Koidebf875662014-02-24 12:19:15 -0800245 p.log("end_addPathToRemoveOperation");
Toshio Koide93be5d62014-02-23 19:30:57 -0800246
247 // send notification
Toshio Koidebf875662014-02-24 12:19:15 -0800248 p.log("begin_sendNotification");
Toshio Koide3a52ef32014-02-28 12:10:26 -0800249 // XXX: Send notifications using the same key every time
250 // and receive them by entryAdded() and entryUpdated()
251 opEventChannel.addEntry(0L, pathIntentOperations);
Toshio Koidebf875662014-02-24 12:19:15 -0800252 p.log("end_sendNotification");
Toshio Koide3a52ef32014-02-28 12:10:26 -0800253 //opEventChannel.removeEntry(key);
Toshio Koide93be5d62014-02-23 19:30:57 -0800254 return pathIntentOperations;
255 }
256 finally {
Toshio Koidebf875662014-02-24 12:19:15 -0800257 p.flushLog();
Toshio Koide93be5d62014-02-23 19:30:57 -0800258 lock.unlock();
259 }
Toshio Koide27ffd412014-02-18 19:15:27 -0800260 }
261
262 @Override
263 public IntentMap getHighLevelIntents() {
Toshio Koide4f308732014-02-18 15:19:48 -0800264 return highLevelIntents;
265 }
Toshio Koide27ffd412014-02-18 19:15:27 -0800266
267 @Override
268 public IntentMap getPathIntents() {
269 return pathIntents;
270 }
271
272 @Override
Toshio Koide4f308732014-02-18 15:19:48 -0800273 public void purgeIntents() {
274 highLevelIntents.purge();
Toshio Koide27ffd412014-02-18 19:15:27 -0800275 pathIntents.purge();
Toshio Koide4f308732014-02-18 15:19:48 -0800276 }
Toshio Koide0c9106d2014-02-19 15:26:38 -0800277
Toshio Koide798bc1b2014-02-20 14:02:40 -0800278 // ================================================================================
279 // INetworkGraphListener implementations
280 // ================================================================================
281
Toshio Koide0c9106d2014-02-19 15:26:38 -0800282 @Override
Toshio Koide798bc1b2014-02-20 14:02:40 -0800283 public void networkGraphEvents(Collection<SwitchEvent> addedSwitchEvents,
284 Collection<SwitchEvent> removedSwitchEvents,
285 Collection<PortEvent> addedPortEvents,
286 Collection<PortEvent> removedPortEvents,
287 Collection<LinkEvent> addedLinkEvents,
288 Collection<LinkEvent> removedLinkEvents,
289 Collection<DeviceEvent> addedDeviceEvents,
290 Collection<DeviceEvent> removedDeviceEvents) {
Toshio Koidea9078af2014-02-21 16:57:04 -0800291
Toshio Koidebf875662014-02-24 12:19:15 -0800292 PerfLogger p = new PerfLogger("networkGraphEvents");
Toshio Koidea94060f2014-02-21 22:58:32 -0800293 HashSet<Intent> affectedPaths = new HashSet<>();
Toshio Koide93797dc2014-02-27 23:54:26 -0800294
Brian O'Connor5518d282014-02-25 22:25:58 -0800295 boolean rerouteAll = false;
296 for(LinkEvent le : addedLinkEvents) {
297 LinkEvent rev = new LinkEvent(le.getDst().getDpid(), le.getDst().getNumber(), le.getSrc().getDpid(), le.getSrc().getNumber());
298 if(unmatchedLinkEvents.contains(rev)) {
299 rerouteAll = true;
300 unmatchedLinkEvents.remove(rev);
301 log.debug("Found matched LinkEvent: {} {}", rev, le);
302 }
303 else {
304 unmatchedLinkEvents.add(le);
305 log.debug("Adding unmatched LinkEvent: {}", le);
306 }
307 }
308 for(LinkEvent le : removedLinkEvents) {
309 if (unmatchedLinkEvents.contains(le)) {
310 unmatchedLinkEvents.remove(le);
311 log.debug("Removing LinkEvent: {}", le);
312 }
313 }
314 if(unmatchedLinkEvents.size() > 0) {
315 log.debug("Unmatched link events: {} events", unmatchedLinkEvents.size());
316 }
Toshio Koidea9078af2014-02-21 16:57:04 -0800317
Brian O'Connor5518d282014-02-25 22:25:58 -0800318 if ( rerouteAll ) {//addedLinkEvents.size() > 0) { // ||
Toshio Koidebf875662014-02-24 12:19:15 -0800319// addedPortEvents.size() > 0 ||
320// addedSwitchEvents.size() > 0) {
321 p.log("begin_getAllIntents");
Toshio Koidea94060f2014-02-21 22:58:32 -0800322 affectedPaths.addAll(getPathIntents().getAllIntents());
Toshio Koidebf875662014-02-24 12:19:15 -0800323 p.log("end_getAllIntents");
Toshio Koidea94060f2014-02-21 22:58:32 -0800324 }
Brian O'Connor5518d282014-02-25 22:25:58 -0800325 else if (removedSwitchEvents.size() > 0 ||
326 removedLinkEvents.size() > 0 ||
327 removedPortEvents.size() > 0) {
Toshio Koidebf875662014-02-24 12:19:15 -0800328 p.log("begin_getIntentsByLink");
Toshio Koidea94060f2014-02-21 22:58:32 -0800329 for (LinkEvent linkEvent: removedLinkEvents)
330 affectedPaths.addAll(pathIntents.getIntentsByLink(linkEvent));
Toshio Koidebf875662014-02-24 12:19:15 -0800331 p.log("end_getIntentsByLink");
Toshio Koidea9078af2014-02-21 16:57:04 -0800332
Toshio Koidebf875662014-02-24 12:19:15 -0800333 p.log("begin_getIntentsByPort");
Toshio Koidea94060f2014-02-21 22:58:32 -0800334 for (PortEvent portEvent: removedPortEvents)
335 affectedPaths.addAll(pathIntents.getIntentsByPort(portEvent.getDpid(), portEvent.getNumber()));
Toshio Koidebf875662014-02-24 12:19:15 -0800336 p.log("end_getIntentsByPort");
Toshio Koidea9078af2014-02-21 16:57:04 -0800337
Toshio Koidebf875662014-02-24 12:19:15 -0800338 p.log("begin_getIntentsByDpid");
Toshio Koidea94060f2014-02-21 22:58:32 -0800339 for (SwitchEvent switchEvent: removedSwitchEvents)
340 affectedPaths.addAll(pathIntents.getIntentsByDpid(switchEvent.getDpid()));
Toshio Koidebf875662014-02-24 12:19:15 -0800341 p.log("end_getIntentsByDpid");
Toshio Koidea94060f2014-02-21 22:58:32 -0800342 }
Toshio Koide240b1302014-02-26 20:08:41 -0800343 p.log("begin_reroutePaths");
Toshio Koidea9078af2014-02-21 16:57:04 -0800344 reroutePaths(affectedPaths);
Toshio Koide240b1302014-02-26 20:08:41 -0800345 p.log("end_reroutePaths");
Toshio Koidebf875662014-02-24 12:19:15 -0800346 p.flushLog();
Toshio Koide0c9106d2014-02-19 15:26:38 -0800347 }
Toshio Koide066506e2014-02-20 19:52:09 -0800348
349 // ================================================================================
350 // IEventChannelListener implementations
351 // ================================================================================
352
353 @Override
354 public void entryAdded(IntentStateList value) {
355 entryUpdated(value);
356 }
357
358 @Override
359 public void entryRemoved(IntentStateList value) {
360 // do nothing
361 }
362
363 @Override
364 public void entryUpdated(IntentStateList value) {
Toshio Koide8315d7d2014-02-21 22:58:32 -0800365 // TODO draw state transition diagram in multiple ONOS instances and update this method
Toshio Koidebf875662014-02-24 12:19:15 -0800366 PerfLogger p = new PerfLogger("entryUpdated");
Toshio Koide93be5d62014-02-23 19:30:57 -0800367 lock.lock(); // TODO optimize locking using smaller steps
368 try {
Toshio Koide93be5d62014-02-23 19:30:57 -0800369 // reflect state changes of path-level intent into application-level intents
Toshio Koidebf875662014-02-24 12:19:15 -0800370 p.log("begin_changeStateByNotification");
Toshio Koide500431f2014-02-28 02:02:25 -0800371 IntentStateList highLevelIntentStates = new IntentStateList();
372 IntentStateList pathIntentStates = new IntentStateList();
Toshio Koide93be5d62014-02-23 19:30:57 -0800373 for (Entry<String, IntentState> entry: value.entrySet()) {
374 PathIntent pathIntent = (PathIntent) pathIntents.getIntent(entry.getKey());
375 if (pathIntent == null) continue;
Toshio Koide8315d7d2014-02-21 22:58:32 -0800376
Toshio Koide93be5d62014-02-23 19:30:57 -0800377 Intent parentIntent = pathIntent.getParentIntent();
378 if (parentIntent == null ||
379 !(parentIntent instanceof ShortestPathIntent) ||
380 !((ShortestPathIntent) parentIntent).getPathIntentId().equals(pathIntent.getId()))
381 continue;
Toshio Koide066506e2014-02-20 19:52:09 -0800382
Toshio Koide93be5d62014-02-23 19:30:57 -0800383 IntentState state = entry.getValue();
384 switch (state) {
Toshio Koide500431f2014-02-28 02:02:25 -0800385 //case INST_REQ:
Toshio Koide93be5d62014-02-23 19:30:57 -0800386 case INST_ACK:
387 case INST_NACK:
Toshio Koide500431f2014-02-28 02:02:25 -0800388 //case DEL_REQ:
Toshio Koide93be5d62014-02-23 19:30:57 -0800389 case DEL_ACK:
390 case DEL_PENDING:
Toshio Koide500431f2014-02-28 02:02:25 -0800391 highLevelIntentStates.put(parentIntent.getId(), state);
392 pathIntentStates.put(entry.getKey(), entry.getValue());
Toshio Koide93be5d62014-02-23 19:30:57 -0800393 break;
394 default:
395 break;
396 }
Toshio Koide066506e2014-02-20 19:52:09 -0800397 }
Toshio Koide500431f2014-02-28 02:02:25 -0800398 highLevelIntents.changeStates(highLevelIntentStates);
399 pathIntents.changeStates(pathIntentStates);
Toshio Koidebf875662014-02-24 12:19:15 -0800400 p.log("end_changeStateByNotification");
Toshio Koide066506e2014-02-20 19:52:09 -0800401 }
Toshio Koide93be5d62014-02-23 19:30:57 -0800402 finally {
Toshio Koidebf875662014-02-24 12:19:15 -0800403 p.flushLog();
Toshio Koide93be5d62014-02-23 19:30:57 -0800404 lock.unlock();
405 }
Toshio Koide066506e2014-02-20 19:52:09 -0800406 }
Toshio Koidea9078af2014-02-21 16:57:04 -0800407}