Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent.runtime; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | import java.util.HashMap; |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 6 | import java.util.HashSet; |
Toshio Koide | df2eab9 | 2014-02-20 11:24:59 -0800 | [diff] [blame] | 7 | import java.util.Iterator; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 8 | import java.util.Map; |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 9 | import java.util.Map.Entry; |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 10 | import java.util.concurrent.locks.ReentrantLock; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 11 | |
Toshio Koide | a94060f | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 12 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; |
| 14 | |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 15 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 16 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 17 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 18 | import net.floodlightcontroller.core.module.IFloodlightService; |
| 19 | import net.onrc.onos.datagrid.IDatagridService; |
| 20 | import net.onrc.onos.datagrid.IEventChannel; |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 21 | import net.onrc.onos.datagrid.IEventChannelListener; |
| 22 | import net.onrc.onos.intent.Intent; |
Toshio Koide | df2eab9 | 2014-02-20 11:24:59 -0800 | [diff] [blame] | 23 | import net.onrc.onos.intent.Intent.IntentState; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 24 | import net.onrc.onos.intent.IntentMap; |
Toshio Koide | df2eab9 | 2014-02-20 11:24:59 -0800 | [diff] [blame] | 25 | import net.onrc.onos.intent.IntentOperation; |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 26 | import net.onrc.onos.intent.IntentOperation.Operator; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 27 | import net.onrc.onos.intent.IntentOperationList; |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 28 | import net.onrc.onos.intent.PathIntent; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 29 | import net.onrc.onos.intent.PathIntentMap; |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 30 | import net.onrc.onos.intent.ShortestPathIntent; |
Toshio Koide | df2eab9 | 2014-02-20 11:24:59 -0800 | [diff] [blame] | 31 | import net.onrc.onos.intent.persist.PersistIntent; |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 32 | import net.onrc.onos.ofcontroller.networkgraph.DeviceEvent; |
| 33 | import net.onrc.onos.ofcontroller.networkgraph.INetworkGraphListener; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 34 | import net.onrc.onos.ofcontroller.networkgraph.INetworkGraphService; |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 35 | import net.onrc.onos.ofcontroller.networkgraph.LinkEvent; |
| 36 | import net.onrc.onos.ofcontroller.networkgraph.PortEvent; |
| 37 | import net.onrc.onos.ofcontroller.networkgraph.SwitchEvent; |
Nick Karanatsios | 8abe717 | 2014-02-19 20:31:48 -0800 | [diff] [blame] | 38 | import net.onrc.onos.registry.controller.IControllerRegistryService; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 39 | |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 40 | /** |
| 41 | * @author Toshio Koide (t-koide@onlab.us) |
| 42 | */ |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 43 | public class PathCalcRuntimeModule implements IFloodlightModule, IPathCalcRuntimeService, INetworkGraphListener, IEventChannelListener<Long, IntentStateList> { |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 44 | private PathCalcRuntime runtime; |
| 45 | private IDatagridService datagridService; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 46 | private INetworkGraphService networkGraphService; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 47 | private IntentMap highLevelIntents; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 48 | private PathIntentMap pathIntents; |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 49 | private IControllerRegistryService controllerRegistry; |
| 50 | private PersistIntent persistIntent; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 51 | |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 52 | private IEventChannel<Long, IntentOperationList> opEventChannel; |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 53 | private final ReentrantLock lock = new ReentrantLock(); |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 54 | private static final String INTENT_OP_EVENT_CHANNEL_NAME = "onos.pathintent"; |
| 55 | private static final String INTENT_STATE_EVENT_CHANNEL_NAME = "onos.pathintent_state"; |
Toshio Koide | a94060f | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 56 | private static final Logger log = LoggerFactory.getLogger(PathCalcRuntimeModule.class); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 57 | |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 58 | // ================================================================================ |
| 59 | // private methods |
| 60 | // ================================================================================ |
| 61 | |
Toshio Koide | a94060f | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 62 | private void reroutePaths(Collection<Intent> oldPaths) { |
Toshio Koide | a9078af | 2014-02-21 16:57:04 -0800 | [diff] [blame] | 63 | if (oldPaths == null || oldPaths.isEmpty()) |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 64 | return; |
Toshio Koide | a10c037 | 2014-02-20 17:28:10 -0800 | [diff] [blame] | 65 | |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 66 | IntentOperationList reroutingOperation = new IntentOperationList(); |
Toshio Koide | 982c81f | 2014-02-23 16:53:10 -0800 | [diff] [blame] | 67 | for (Intent intent : oldPaths) { |
| 68 | PathIntent pathIntent = (PathIntent) intent; |
| 69 | if (pathIntent.getState().equals(IntentState.INST_ACK) && |
| 70 | !reroutingOperation.contains(pathIntent)) { |
| 71 | reroutingOperation.add(Operator.ADD, pathIntent.getParentIntent()); |
| 72 | } |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 73 | } |
Toshio Koide | 8315d7d | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 74 | executeIntentOperations(reroutingOperation); |
Toshio Koide | a94060f | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | private void log(String step) { |
| 78 | log.error("Step:{}, Time:{}", step, System.nanoTime()); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 79 | } |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 80 | |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 81 | // ================================================================================ |
| 82 | // IFloodlightModule implementations |
| 83 | // ================================================================================ |
| 84 | |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 85 | @Override |
| 86 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 87 | Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(1); |
Toshio Koide | eb90d91 | 2014-02-18 21:30:22 -0800 | [diff] [blame] | 88 | l.add(IPathCalcRuntimeService.class); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 89 | return l; |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
Toshio Koide | a9078af | 2014-02-21 16:57:04 -0800 | [diff] [blame] | 94 | Map<Class<? extends IFloodlightService>, IFloodlightService> m = new HashMap<>(); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 95 | m.put(IPathCalcRuntimeService.class, this); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 96 | return m; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
Toshio Koide | a9078af | 2014-02-21 16:57:04 -0800 | [diff] [blame] | 101 | Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(2); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 102 | l.add(IDatagridService.class); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 103 | l.add(INetworkGraphService.class); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 104 | return l; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public void init(FloodlightModuleContext context) throws FloodlightModuleException { |
| 109 | datagridService = context.getServiceImpl(IDatagridService.class); |
Toshio Koide | d9fa2a8 | 2014-02-19 17:35:18 -0800 | [diff] [blame] | 110 | networkGraphService = context.getServiceImpl(INetworkGraphService.class); |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 111 | controllerRegistry = context.getServiceImpl(IControllerRegistryService.class); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public void startUp(FloodlightModuleContext context) { |
Toshio Koide | eb90d91 | 2014-02-18 21:30:22 -0800 | [diff] [blame] | 116 | highLevelIntents = new IntentMap(); |
| 117 | runtime = new PathCalcRuntime(networkGraphService.getNetworkGraph()); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 118 | pathIntents = new PathIntentMap(); |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 119 | opEventChannel = datagridService.createChannel(INTENT_OP_EVENT_CHANNEL_NAME, Long.class, IntentOperationList.class); |
| 120 | datagridService.addListener(INTENT_STATE_EVENT_CHANNEL_NAME, this, Long.class, IntentStateList.class); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 121 | networkGraphService.registerNetworkGraphListener(this); |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 122 | persistIntent = new PersistIntent(controllerRegistry, networkGraphService); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 123 | } |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 124 | |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 125 | // ================================================================================ |
| 126 | // IPathCalcRuntimeService implementations |
| 127 | // ================================================================================ |
| 128 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 129 | @Override |
| 130 | public IntentOperationList executeIntentOperations(IntentOperationList list) { |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 131 | lock.lock(); // TODO optimize locking using smaller steps |
| 132 | try { |
| 133 | // update the map of high-level intents |
| 134 | log("begin_updateInMemoryIntents"); |
| 135 | highLevelIntents.executeOperations(list); |
Toshio Koide | df2eab9 | 2014-02-20 11:24:59 -0800 | [diff] [blame] | 136 | |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 137 | // change states of high-level intents |
| 138 | IntentStateList states = new IntentStateList(); |
| 139 | for (IntentOperation op : list) { |
| 140 | if (op.intent.getState().equals(IntentState.INST_ACK)) |
| 141 | states.put(op.intent.getId(), IntentState.REROUTE_REQ); |
Toshio Koide | df2eab9 | 2014-02-20 11:24:59 -0800 | [diff] [blame] | 142 | } |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 143 | highLevelIntents.changeStates(states); |
| 144 | log("end_updateInMemoryIntents"); |
Toshio Koide | df2eab9 | 2014-02-20 11:24:59 -0800 | [diff] [blame] | 145 | |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 146 | // calculate path-intents (low-level operations) |
| 147 | log("begin_calcPathIntents"); |
| 148 | IntentOperationList pathIntentOperations = runtime.calcPathIntents(list, highLevelIntents, pathIntents); |
| 149 | log("end_calcPathIntents"); |
Toshio Koide | 600ae5f | 2014-02-20 18:42:00 -0800 | [diff] [blame] | 150 | |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 151 | // persist calculated low-level operations into data store |
| 152 | log("begin_persistPathIntents"); |
| 153 | long key = persistIntent.getKey(); |
| 154 | persistIntent.persistIfLeader(key, pathIntentOperations); |
| 155 | log("end_persistPathIntents"); |
| 156 | |
| 157 | // remove error-intents and reflect them to high-level intents |
| 158 | log("begin_removeErrorIntents"); |
| 159 | states.clear(); |
| 160 | Iterator<IntentOperation> i = pathIntentOperations.iterator(); |
| 161 | while (i.hasNext()) { |
| 162 | IntentOperation op = i.next(); |
| 163 | if (op.operator.equals(Operator.ERROR)) { |
| 164 | states.put(op.intent.getId(), IntentState.INST_NACK); |
| 165 | i.remove(); |
| 166 | } |
Toshio Koide | 600ae5f | 2014-02-20 18:42:00 -0800 | [diff] [blame] | 167 | } |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 168 | highLevelIntents.changeStates(states); |
| 169 | log("end_removeErrorIntents"); |
Toshio Koide | a94060f | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 170 | |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 171 | // update the map of path intents and publish the path operations |
| 172 | log("begin_updateInMemoryPathIntents"); |
| 173 | pathIntents.executeOperations(pathIntentOperations); |
| 174 | log("end_updateInMemoryPathIntents"); |
| 175 | |
| 176 | // Demo special: add a complete path to remove operation |
| 177 | log("begin_addPathToRemoveOperation"); |
| 178 | for (IntentOperation op: pathIntentOperations) { |
| 179 | if(op.operator.equals(Operator.REMOVE)) { |
| 180 | op.intent = pathIntents.getIntent(op.intent.getId()); |
| 181 | } |
| 182 | if (op.intent instanceof PathIntent) { |
| 183 | log.debug("operation: {}, intent:{}", op.operator, op.intent); |
| 184 | } |
| 185 | } |
| 186 | log("end_addPathToRemoveOperation"); |
| 187 | |
| 188 | // send notification |
| 189 | log("begin_sendNotification"); |
| 190 | opEventChannel.addEntry(key, pathIntentOperations); |
| 191 | log("end_sendNotification"); |
| 192 | return pathIntentOperations; |
| 193 | } |
| 194 | finally { |
| 195 | lock.unlock(); |
| 196 | } |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public IntentMap getHighLevelIntents() { |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 201 | return highLevelIntents; |
| 202 | } |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 203 | |
| 204 | @Override |
| 205 | public IntentMap getPathIntents() { |
| 206 | return pathIntents; |
| 207 | } |
| 208 | |
| 209 | @Override |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 210 | public void purgeIntents() { |
| 211 | highLevelIntents.purge(); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 212 | pathIntents.purge(); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 213 | } |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 214 | |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 215 | // ================================================================================ |
| 216 | // INetworkGraphListener implementations |
| 217 | // ================================================================================ |
| 218 | |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 219 | @Override |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 220 | public void networkGraphEvents(Collection<SwitchEvent> addedSwitchEvents, |
| 221 | Collection<SwitchEvent> removedSwitchEvents, |
| 222 | Collection<PortEvent> addedPortEvents, |
| 223 | Collection<PortEvent> removedPortEvents, |
| 224 | Collection<LinkEvent> addedLinkEvents, |
| 225 | Collection<LinkEvent> removedLinkEvents, |
| 226 | Collection<DeviceEvent> addedDeviceEvents, |
| 227 | Collection<DeviceEvent> removedDeviceEvents) { |
Toshio Koide | a9078af | 2014-02-21 16:57:04 -0800 | [diff] [blame] | 228 | |
Toshio Koide | a94060f | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 229 | log("called_networkGraphEvents"); |
| 230 | HashSet<Intent> affectedPaths = new HashSet<>(); |
Toshio Koide | a9078af | 2014-02-21 16:57:04 -0800 | [diff] [blame] | 231 | |
Toshio Koide | a94060f | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 232 | if (addedLinkEvents.size() > 0 || |
| 233 | addedPortEvents.size() > 0 || |
| 234 | addedSwitchEvents.size() > 0) { |
| 235 | log("begin_getAllIntents"); |
| 236 | affectedPaths.addAll(getPathIntents().getAllIntents()); |
| 237 | log("end_getAllIntents"); |
| 238 | } |
| 239 | else { |
| 240 | log("begin_getIntentsByLink"); |
| 241 | for (LinkEvent linkEvent: removedLinkEvents) |
| 242 | affectedPaths.addAll(pathIntents.getIntentsByLink(linkEvent)); |
| 243 | log("end_getIntentsByLink"); |
Toshio Koide | a9078af | 2014-02-21 16:57:04 -0800 | [diff] [blame] | 244 | |
Toshio Koide | a94060f | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 245 | log("begin_getIntentsByPort"); |
| 246 | for (PortEvent portEvent: removedPortEvents) |
| 247 | affectedPaths.addAll(pathIntents.getIntentsByPort(portEvent.getDpid(), portEvent.getNumber())); |
| 248 | log("end_getIntentsByPort"); |
Toshio Koide | a9078af | 2014-02-21 16:57:04 -0800 | [diff] [blame] | 249 | |
Toshio Koide | a94060f | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 250 | log("begin_getIntentsByDpid"); |
| 251 | for (SwitchEvent switchEvent: removedSwitchEvents) |
| 252 | affectedPaths.addAll(pathIntents.getIntentsByDpid(switchEvent.getDpid())); |
| 253 | log("end_getIntentsByDpid"); |
| 254 | } |
Toshio Koide | a9078af | 2014-02-21 16:57:04 -0800 | [diff] [blame] | 255 | reroutePaths(affectedPaths); |
Toshio Koide | a94060f | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 256 | log("finished_networkGraphEvents"); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 257 | } |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 258 | |
| 259 | // ================================================================================ |
| 260 | // IEventChannelListener implementations |
| 261 | // ================================================================================ |
| 262 | |
| 263 | @Override |
| 264 | public void entryAdded(IntentStateList value) { |
Toshio Koide | a94060f | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 265 | log("called_EntryAdded"); |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 266 | entryUpdated(value); |
| 267 | } |
| 268 | |
| 269 | @Override |
| 270 | public void entryRemoved(IntentStateList value) { |
| 271 | // do nothing |
| 272 | } |
| 273 | |
| 274 | @Override |
| 275 | public void entryUpdated(IntentStateList value) { |
Toshio Koide | 8315d7d | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 276 | // TODO draw state transition diagram in multiple ONOS instances and update this method |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 277 | lock.lock(); // TODO optimize locking using smaller steps |
| 278 | try { |
| 279 | log("called_EntryUpdated"); |
| 280 | // reflect state changes of path-level intent into application-level intents |
| 281 | log("begin_changeStateByNotification"); |
| 282 | IntentStateList parentStates = new IntentStateList(); |
| 283 | for (Entry<String, IntentState> entry: value.entrySet()) { |
| 284 | PathIntent pathIntent = (PathIntent) pathIntents.getIntent(entry.getKey()); |
| 285 | if (pathIntent == null) continue; |
Toshio Koide | 8315d7d | 2014-02-21 22:58:32 -0800 | [diff] [blame] | 286 | |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 287 | Intent parentIntent = pathIntent.getParentIntent(); |
| 288 | if (parentIntent == null || |
| 289 | !(parentIntent instanceof ShortestPathIntent) || |
| 290 | !((ShortestPathIntent) parentIntent).getPathIntentId().equals(pathIntent.getId())) |
| 291 | continue; |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 292 | |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 293 | IntentState state = entry.getValue(); |
| 294 | switch (state) { |
| 295 | case INST_REQ: |
| 296 | case INST_ACK: |
| 297 | case INST_NACK: |
| 298 | case DEL_REQ: |
| 299 | case DEL_ACK: |
| 300 | case DEL_PENDING: |
| 301 | parentStates.put(parentIntent.getId(), state); |
| 302 | break; |
| 303 | default: |
| 304 | break; |
| 305 | } |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 306 | } |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 307 | highLevelIntents.changeStates(parentStates); |
| 308 | pathIntents.changeStates(value); |
| 309 | log("end_changeStateByNotification"); |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 310 | } |
Toshio Koide | 93be5d6 | 2014-02-23 19:30:57 -0800 | [diff] [blame] | 311 | finally { |
| 312 | lock.unlock(); |
| 313 | } |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 314 | } |
Toshio Koide | a9078af | 2014-02-21 16:57:04 -0800 | [diff] [blame] | 315 | } |