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