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