Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.flowmanager; |
| 2 | |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 3 | import java.util.ArrayList; |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 4 | import java.util.Collection; |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 5 | import java.util.HashMap; |
| 6 | import java.util.Iterator; |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 7 | import java.util.LinkedList; |
| 8 | import java.util.List; |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 9 | import java.util.Map; |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 10 | |
| 11 | import java.util.concurrent.BlockingQueue; |
| 12 | import java.util.concurrent.LinkedBlockingQueue; |
| 13 | |
| 14 | import net.onrc.onos.datagrid.IDatagridService; |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 15 | import net.onrc.onos.ofcontroller.topology.ShortestPath; |
Pavlin Radoslavov | a23e541 | 2013-10-27 19:56:40 -0700 | [diff] [blame] | 16 | import net.onrc.onos.ofcontroller.topology.Topology; |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 17 | import net.onrc.onos.ofcontroller.topology.TopologyElement; |
Pavlin Radoslavov | 3ecd41e | 2013-10-29 14:29:30 -0700 | [diff] [blame] | 18 | import net.onrc.onos.ofcontroller.topology.TopologyManager; |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 19 | import net.onrc.onos.ofcontroller.util.DataPath; |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 20 | import net.onrc.onos.ofcontroller.util.EventEntry; |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 21 | import net.onrc.onos.ofcontroller.util.FlowEntry; |
| 22 | import net.onrc.onos.ofcontroller.util.FlowEntryAction; |
| 23 | import net.onrc.onos.ofcontroller.util.FlowEntryActions; |
| 24 | import net.onrc.onos.ofcontroller.util.FlowEntryMatch; |
| 25 | import net.onrc.onos.ofcontroller.util.FlowEntrySwitchState; |
| 26 | import net.onrc.onos.ofcontroller.util.FlowEntryUserState; |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 27 | import net.onrc.onos.ofcontroller.util.FlowPath; |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 28 | import net.onrc.onos.ofcontroller.util.FlowPathUserState; |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 29 | |
| 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
| 33 | /** |
| 34 | * Class for implementing the Path Computation and Path Maintenance. |
| 35 | */ |
| 36 | class PathComputation extends Thread implements IPathComputationService { |
| 37 | /** The logger. */ |
| 38 | private final static Logger log = LoggerFactory.getLogger(PathComputation.class); |
| 39 | |
| 40 | private FlowManager flowManager; // The Flow Manager to use |
| 41 | private IDatagridService datagridService; // The Datagrid Service to use |
Pavlin Radoslavov | a23e541 | 2013-10-27 19:56:40 -0700 | [diff] [blame] | 42 | private Topology topology; // The network topology |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 43 | private Map<Long, FlowPath> allFlowPaths = new HashMap<Long, FlowPath>(); |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 44 | |
| 45 | // The queue with Flow Path and Topology Element updates |
| 46 | private BlockingQueue<EventEntry<?>> networkEvents = |
| 47 | new LinkedBlockingQueue<EventEntry<?>>(); |
| 48 | |
| 49 | // The pending Topology and Flow Path events |
| 50 | private List<EventEntry<TopologyElement>> topologyEvents = |
| 51 | new LinkedList<EventEntry<TopologyElement>>(); |
| 52 | private List<EventEntry<FlowPath>> flowPathEvents = |
| 53 | new LinkedList<EventEntry<FlowPath>>(); |
| 54 | |
| 55 | /** |
| 56 | * Constructor for a given Flow Manager and Datagrid Service. |
| 57 | * |
| 58 | * @param flowManager the Flow Manager to use. |
| 59 | * @param datagridService the Datagrid Service to use. |
| 60 | */ |
| 61 | PathComputation(FlowManager flowManager, |
| 62 | IDatagridService datagridService) { |
| 63 | this.flowManager = flowManager; |
| 64 | this.datagridService = datagridService; |
Pavlin Radoslavov | a23e541 | 2013-10-27 19:56:40 -0700 | [diff] [blame] | 65 | this.topology = new Topology(); |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Run the thread. |
| 70 | */ |
| 71 | @Override |
| 72 | public void run() { |
| 73 | // |
| 74 | // Obtain the initial Topology state |
| 75 | // |
| 76 | Collection<TopologyElement> topologyElements = |
| 77 | datagridService.getAllTopologyElements(); |
| 78 | for (TopologyElement topologyElement : topologyElements) { |
| 79 | EventEntry<TopologyElement> eventEntry = |
| 80 | new EventEntry<TopologyElement>(EventEntry.Type.ENTRY_ADD, topologyElement); |
| 81 | topologyEvents.add(eventEntry); |
| 82 | } |
| 83 | // |
| 84 | // Obtain the initial Flow Path state |
| 85 | // |
| 86 | Collection<FlowPath> flowPaths = datagridService.getAllFlows(); |
| 87 | for (FlowPath flowPath : flowPaths) { |
| 88 | EventEntry<FlowPath> eventEntry = |
| 89 | new EventEntry<FlowPath>(EventEntry.Type.ENTRY_ADD, flowPath); |
| 90 | flowPathEvents.add(eventEntry); |
| 91 | } |
| 92 | // Process the events (if any) |
| 93 | processEvents(); |
| 94 | |
| 95 | // |
| 96 | // The main loop |
| 97 | // |
| 98 | Collection<EventEntry<?>> collection = new LinkedList<EventEntry<?>>(); |
| 99 | try { |
| 100 | while (true) { |
| 101 | EventEntry<?> eventEntry = networkEvents.take(); |
| 102 | collection.add(eventEntry); |
| 103 | networkEvents.drainTo(collection); |
| 104 | |
Pavlin Radoslavov | ed4c7a9 | 2013-10-26 21:36:21 -0700 | [diff] [blame] | 105 | // |
| 106 | // Demultiplex all events: |
| 107 | // - EventEntry<TopologyElement> |
| 108 | // - EventEntry<FlowPath> |
| 109 | // |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 110 | for (EventEntry<?> event : collection) { |
| 111 | if (event.eventData() instanceof TopologyElement) { |
| 112 | EventEntry<TopologyElement> topologyEventEntry = |
| 113 | (EventEntry<TopologyElement>)event; |
| 114 | topologyEvents.add(topologyEventEntry); |
| 115 | } else if (event.eventData() instanceof FlowPath) { |
| 116 | EventEntry<FlowPath> flowPathEventEntry = |
| 117 | (EventEntry<FlowPath>)event; |
| 118 | flowPathEvents.add(flowPathEventEntry); |
| 119 | } |
| 120 | } |
| 121 | collection.clear(); |
Pavlin Radoslavov | ed4c7a9 | 2013-10-26 21:36:21 -0700 | [diff] [blame] | 122 | |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 123 | // Process the events (if any) |
| 124 | processEvents(); |
| 125 | } |
| 126 | } catch (Exception exception) { |
| 127 | log.debug("Exception processing Network Events: ", exception); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Process the events (if any) |
| 133 | */ |
| 134 | private void processEvents() { |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 135 | List<FlowPath> newFlowPaths = new LinkedList<FlowPath>(); |
| 136 | List<FlowPath> recomputeFlowPaths = new LinkedList<FlowPath>(); |
| 137 | List<FlowPath> modifiedFlowPaths = new LinkedList<FlowPath>(); |
| 138 | |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 139 | if (topologyEvents.isEmpty() && flowPathEvents.isEmpty()) |
| 140 | return; // Nothing to do |
| 141 | |
Pavlin Radoslavov | a23e541 | 2013-10-27 19:56:40 -0700 | [diff] [blame] | 142 | // |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 143 | // Process the Flow Path events |
| 144 | // |
| 145 | for (EventEntry<FlowPath> eventEntry : flowPathEvents) { |
| 146 | FlowPath flowPath = eventEntry.eventData(); |
| 147 | |
| 148 | switch (eventEntry.eventType()) { |
| 149 | case ENTRY_ADD: { |
| 150 | // |
| 151 | // Add a new Flow Path |
| 152 | // |
| 153 | if (allFlowPaths.get(flowPath.flowId().value()) != null) { |
| 154 | // |
| 155 | // TODO: What to do if the Flow Path already exists? |
| 156 | // Remove and then re-add it, or merge the info? |
| 157 | // For now, we don't have to do anything. |
| 158 | // |
| 159 | break; |
| 160 | } |
| 161 | |
| 162 | switch (flowPath.flowPathType()) { |
| 163 | case FP_TYPE_SHORTEST_PATH: |
| 164 | // |
| 165 | // Reset the Data Path, in case it was set already, because |
| 166 | // we are going to recompute it anyway. |
| 167 | // |
| 168 | flowPath.flowEntries().clear(); |
| 169 | recomputeFlowPaths.add(flowPath); |
| 170 | break; |
| 171 | case FP_TYPE_EXPLICIT_PATH: |
| 172 | // |
| 173 | // Mark all Flow Entries for installation in the switches. |
| 174 | // |
| 175 | for (FlowEntry flowEntry : flowPath.flowEntries()) { |
| 176 | flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.FE_SWITCH_NOT_UPDATED); |
| 177 | } |
| 178 | modifiedFlowPaths.add(flowPath); |
| 179 | break; |
| 180 | } |
| 181 | newFlowPaths.add(flowPath); |
| 182 | |
| 183 | break; |
| 184 | } |
| 185 | |
| 186 | case ENTRY_REMOVE: { |
| 187 | // |
| 188 | // Remove an existing Flow Path. |
| 189 | // |
| 190 | // Find the Flow Path, and mark the Flow and its Flow Entries |
| 191 | // for deletion. |
| 192 | // |
| 193 | FlowPath existingFlowPath = |
| 194 | allFlowPaths.get(flowPath.flowId().value()); |
| 195 | if (existingFlowPath == null) |
| 196 | continue; // Nothing to do |
| 197 | |
| 198 | existingFlowPath.setFlowPathUserState(FlowPathUserState.FP_USER_DELETE); |
| 199 | for (FlowEntry flowEntry : existingFlowPath.flowEntries()) { |
| 200 | flowEntry.setFlowEntryUserState(FlowEntryUserState.FE_USER_DELETE); |
| 201 | flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.FE_SWITCH_NOT_UPDATED); |
| 202 | } |
| 203 | |
| 204 | allFlowPaths.remove(existingFlowPath.flowId()); |
| 205 | modifiedFlowPaths.add(existingFlowPath); |
| 206 | |
| 207 | break; |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // |
| 213 | // Process the topology events |
Pavlin Radoslavov | a23e541 | 2013-10-27 19:56:40 -0700 | [diff] [blame] | 214 | // |
| 215 | boolean isTopologyModified = false; |
| 216 | for (EventEntry<TopologyElement> eventEntry : topologyEvents) { |
| 217 | TopologyElement topologyElement = eventEntry.eventData(); |
| 218 | switch (eventEntry.eventType()) { |
| 219 | case ENTRY_ADD: |
| 220 | isTopologyModified = topology.addTopologyElement(topologyElement); |
| 221 | break; |
| 222 | case ENTRY_REMOVE: |
| 223 | isTopologyModified = topology.removeTopologyElement(topologyElement); |
| 224 | break; |
| 225 | } |
| 226 | } |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 227 | if (isTopologyModified) { |
| 228 | // TODO: For now, if the topology changes, we recompute all Flows |
| 229 | recomputeFlowPaths.addAll(allFlowPaths.values()); |
| 230 | } |
Pavlin Radoslavov | a23e541 | 2013-10-27 19:56:40 -0700 | [diff] [blame] | 231 | |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 232 | // Add all new Flows |
| 233 | for (FlowPath flowPath : newFlowPaths) { |
| 234 | allFlowPaths.put(flowPath.flowId().value(), flowPath); |
| 235 | } |
| 236 | |
| 237 | // Recompute all affected Flow Paths and keep only the modified |
| 238 | for (FlowPath flowPath : recomputeFlowPaths) { |
| 239 | if (recomputeFlowPath(flowPath)) |
| 240 | modifiedFlowPaths.add(flowPath); |
| 241 | } |
| 242 | |
Pavlin Radoslavov | 3ecd41e | 2013-10-29 14:29:30 -0700 | [diff] [blame] | 243 | // |
| 244 | // Push the Flow Entries that have been modified |
| 245 | // |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 246 | flowManager.pushModifiedFlowEntries(modifiedFlowPaths); |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 247 | |
Pavlin Radoslavov | ed4c7a9 | 2013-10-26 21:36:21 -0700 | [diff] [blame] | 248 | // Cleanup |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 249 | topologyEvents.clear(); |
| 250 | flowPathEvents.clear(); |
| 251 | } |
| 252 | |
| 253 | /** |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 254 | * Recompute a Flow Path. |
| 255 | * |
| 256 | * @param flowPath the Flow Path to recompute. |
| 257 | * @return true if the recomputed Flow Path has changed, otherwise false. |
| 258 | */ |
| 259 | private boolean recomputeFlowPath(FlowPath flowPath) { |
| 260 | boolean hasChanged = false; |
| 261 | |
| 262 | // |
| 263 | // Test whether the Flow Path needs to be recomputed |
| 264 | // |
| 265 | switch (flowPath.flowPathType()) { |
| 266 | case FP_TYPE_SHORTEST_PATH: |
| 267 | break; |
| 268 | case FP_TYPE_EXPLICIT_PATH: |
| 269 | return false; // An explicit path never changes |
| 270 | } |
| 271 | |
| 272 | DataPath oldDataPath = flowPath.dataPath(); |
| 273 | |
Pavlin Radoslavov | 3ecd41e | 2013-10-29 14:29:30 -0700 | [diff] [blame] | 274 | // Compute the new path |
| 275 | DataPath newDataPath = TopologyManager.computeNetworkPath(topology, |
| 276 | flowPath); |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 277 | if (newDataPath == null) { |
| 278 | // We need the DataPath to compare the paths |
| 279 | newDataPath = new DataPath(); |
| 280 | } |
| 281 | newDataPath.applyFlowPathFlags(flowPath.flowPathFlags()); |
| 282 | |
| 283 | // |
Pavlin Radoslavov | 3ecd41e | 2013-10-29 14:29:30 -0700 | [diff] [blame] | 284 | // Test whether the new path is same |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 285 | // |
| 286 | if (oldDataPath.flowEntries().size() != |
| 287 | newDataPath.flowEntries().size()) { |
| 288 | hasChanged = true; |
| 289 | } else { |
| 290 | Iterator<FlowEntry> oldIter = oldDataPath.flowEntries().iterator(); |
| 291 | Iterator<FlowEntry> newIter = newDataPath.flowEntries().iterator(); |
| 292 | while (oldIter.hasNext() && newIter.hasNext()) { |
| 293 | FlowEntry oldFlowEntry = oldIter.next(); |
| 294 | FlowEntry newFlowEntry = newIter.next(); |
Pavlin Radoslavov | 3ecd41e | 2013-10-29 14:29:30 -0700 | [diff] [blame] | 295 | if (! TopologyManager.isSameFlowEntryDataPath(oldFlowEntry, |
| 296 | newFlowEntry)) { |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 297 | hasChanged = true; |
| 298 | break; |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | if (! hasChanged) |
| 303 | return hasChanged; |
| 304 | |
| 305 | // |
Pavlin Radoslavov | 3ecd41e | 2013-10-29 14:29:30 -0700 | [diff] [blame] | 306 | // Merge the changes in the path: |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 307 | // - If a Flow Entry for a switch is in the old data path, but not |
| 308 | // in the new data path, then mark it for deletion. |
| 309 | // - If a Flow Entry for a switch is in the new data path, but not |
| 310 | // in the old data path, then mark it for addition. |
| 311 | // - If a Flow Entry for a switch is in both the old and the new |
| 312 | // data path, but it has changed, e.g., the incoming and/or outgoing |
| 313 | // port(s), then mark the old Flow Entry for deletion, and mark |
| 314 | // the new Flow Entry for addition. |
| 315 | // - If a Flow Entry for a switch is in both the old and the new |
| 316 | // data path, and it hasn't changed, then just keep it. |
| 317 | // |
| 318 | // NOTE: We use the Switch DPID of each entry to match the entries |
| 319 | // |
| 320 | Map<Long, FlowEntry> oldFlowEntriesMap = new HashMap<Long, FlowEntry>(); |
| 321 | Map<Long, FlowEntry> newFlowEntriesMap = new HashMap<Long, FlowEntry>(); |
| 322 | ArrayList<FlowEntry> finalFlowEntries = new ArrayList<FlowEntry>(); |
| 323 | List<FlowEntry> deletedFlowEntries = new LinkedList<FlowEntry>(); |
| 324 | |
| 325 | // Prepare maps with the Flow Entries, so they are fast to lookup |
| 326 | for (FlowEntry flowEntry : oldDataPath.flowEntries()) |
| 327 | oldFlowEntriesMap.put(flowEntry.dpid().value(), flowEntry); |
| 328 | for (FlowEntry flowEntry : newDataPath.flowEntries()) |
| 329 | newFlowEntriesMap.put(flowEntry.dpid().value(), flowEntry); |
| 330 | |
| 331 | // |
| 332 | // Find the old Flow Entries that should be deleted |
| 333 | // |
| 334 | for (FlowEntry oldFlowEntry : oldDataPath.flowEntries()) { |
| 335 | FlowEntry newFlowEntry = |
| 336 | newFlowEntriesMap.get(oldFlowEntry.dpid().value()); |
| 337 | if (newFlowEntry == null) { |
| 338 | // The old Flow Entry should be deleted |
| 339 | oldFlowEntry.setFlowEntryUserState(FlowEntryUserState.FE_USER_DELETE); |
| 340 | oldFlowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.FE_SWITCH_NOT_UPDATED); |
| 341 | deletedFlowEntries.add(oldFlowEntry); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | // |
| 346 | // Find the new Flow Entries that should be added or updated |
| 347 | // |
| 348 | int idx = 0; |
| 349 | for (FlowEntry newFlowEntry : newDataPath.flowEntries()) { |
| 350 | FlowEntry oldFlowEntry = |
| 351 | oldFlowEntriesMap.get(newFlowEntry.dpid().value()); |
| 352 | |
| 353 | if ((oldFlowEntry != null) && |
Pavlin Radoslavov | 3ecd41e | 2013-10-29 14:29:30 -0700 | [diff] [blame] | 354 | TopologyManager.isSameFlowEntryDataPath(oldFlowEntry, |
| 355 | newFlowEntry)) { |
Pavlin Radoslavov | fb06a9e | 2013-10-28 23:56:15 -0700 | [diff] [blame] | 356 | // |
| 357 | // Both Flow Entries are same |
| 358 | // |
| 359 | finalFlowEntries.add(oldFlowEntry); |
| 360 | idx++; |
| 361 | continue; |
| 362 | } |
| 363 | |
| 364 | if (oldFlowEntry != null) { |
| 365 | // |
| 366 | // The old Flow Entry should be deleted |
| 367 | // |
| 368 | oldFlowEntry.setFlowEntryUserState(FlowEntryUserState.FE_USER_DELETE); |
| 369 | oldFlowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.FE_SWITCH_NOT_UPDATED); |
| 370 | deletedFlowEntries.add(oldFlowEntry); |
| 371 | } |
| 372 | |
| 373 | // |
| 374 | // Add the new Flow Entry |
| 375 | // |
| 376 | |
| 377 | // Set the incoming port matching |
| 378 | FlowEntryMatch flowEntryMatch = new FlowEntryMatch(); |
| 379 | newFlowEntry.setFlowEntryMatch(flowEntryMatch); |
| 380 | flowEntryMatch.enableInPort(newFlowEntry.inPort()); |
| 381 | |
| 382 | // |
| 383 | // Set the actions: |
| 384 | // If the first Flow Entry, copy the Flow Path actions to it. |
| 385 | // |
| 386 | FlowEntryActions flowEntryActions = newFlowEntry.flowEntryActions(); |
| 387 | if ((idx == 0) && (flowPath.flowEntryActions() != null)) { |
| 388 | FlowEntryActions flowActions = |
| 389 | new FlowEntryActions(flowPath.flowEntryActions()); |
| 390 | for (FlowEntryAction action : flowActions.actions()) |
| 391 | flowEntryActions.addAction(action); |
| 392 | } |
| 393 | idx++; |
| 394 | |
| 395 | // |
| 396 | // Add the outgoing port output action |
| 397 | // |
| 398 | FlowEntryAction flowEntryAction = new FlowEntryAction(); |
| 399 | flowEntryAction.setActionOutput(newFlowEntry.outPort()); |
| 400 | flowEntryActions.addAction(flowEntryAction); |
| 401 | |
| 402 | // |
| 403 | // Set the state of the new Flow Entry |
| 404 | // |
| 405 | newFlowEntry.setFlowEntryUserState(FlowEntryUserState.FE_USER_ADD); |
| 406 | newFlowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.FE_SWITCH_NOT_UPDATED); |
| 407 | finalFlowEntries.add(newFlowEntry); |
| 408 | } |
| 409 | |
| 410 | // |
| 411 | // Replace the old Flow Entries with the new Flow Entries. |
| 412 | // Note that the Flow Entries that will be deleted are added at |
| 413 | // the end. |
| 414 | // |
| 415 | for (FlowEntry flowEntry : deletedFlowEntries) |
| 416 | finalFlowEntries.add(flowEntry); |
| 417 | flowPath.dataPath().setFlowEntries(finalFlowEntries); |
| 418 | |
| 419 | return hasChanged; |
| 420 | } |
| 421 | |
| 422 | /** |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 423 | * Receive a notification that a Flow is added. |
| 424 | * |
| 425 | * @param flowPath the flow that is added. |
| 426 | */ |
| 427 | @Override |
| 428 | public void notificationRecvFlowAdded(FlowPath flowPath) { |
| 429 | EventEntry<FlowPath> eventEntry = |
| 430 | new EventEntry<FlowPath>(EventEntry.Type.ENTRY_ADD, flowPath); |
| 431 | networkEvents.add(eventEntry); |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Receive a notification that a Flow is removed. |
| 436 | * |
| 437 | * @param flowPath the flow that is removed. |
| 438 | */ |
| 439 | @Override |
| 440 | public void notificationRecvFlowRemoved(FlowPath flowPath) { |
| 441 | EventEntry<FlowPath> eventEntry = |
| 442 | new EventEntry<FlowPath>(EventEntry.Type.ENTRY_REMOVE, flowPath); |
| 443 | networkEvents.add(eventEntry); |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Receive a notification that a Flow is updated. |
| 448 | * |
| 449 | * @param flowPath the flow that is updated. |
| 450 | */ |
| 451 | @Override |
| 452 | public void notificationRecvFlowUpdated(FlowPath flowPath) { |
| 453 | // NOTE: The ADD and UPDATE events are processed in same way |
| 454 | EventEntry<FlowPath> eventEntry = |
| 455 | new EventEntry<FlowPath>(EventEntry.Type.ENTRY_ADD, flowPath); |
| 456 | networkEvents.add(eventEntry); |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * Receive a notification that a Topology Element is added. |
| 461 | * |
| 462 | * @param topologyElement the Topology Element that is added. |
| 463 | */ |
| 464 | @Override |
| 465 | public void notificationRecvTopologyElementAdded(TopologyElement topologyElement) { |
| 466 | EventEntry<TopologyElement> eventEntry = |
| 467 | new EventEntry<TopologyElement>(EventEntry.Type.ENTRY_ADD, topologyElement); |
| 468 | networkEvents.add(eventEntry); |
| 469 | } |
| 470 | |
| 471 | /** |
| 472 | * Receive a notification that a Topology Element is removed. |
| 473 | * |
| 474 | * @param topologyElement the Topology Element that is removed. |
| 475 | */ |
| 476 | @Override |
| 477 | public void notificationRecvTopologyElementRemoved(TopologyElement topologyElement) { |
| 478 | EventEntry<TopologyElement> eventEntry = |
| 479 | new EventEntry<TopologyElement>(EventEntry.Type.ENTRY_REMOVE, topologyElement); |
| 480 | networkEvents.add(eventEntry); |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Receive a notification that a Topology Element is updated. |
| 485 | * |
| 486 | * @param topologyElement the Topology Element that is updated. |
| 487 | */ |
| 488 | @Override |
| 489 | public void notificationRecvTopologyElementUpdated(TopologyElement topologyElement) { |
| 490 | // NOTE: The ADD and UPDATE events are processed in same way |
| 491 | EventEntry<TopologyElement> eventEntry = |
| 492 | new EventEntry<TopologyElement>(EventEntry.Type.ENTRY_ADD, topologyElement); |
| 493 | networkEvents.add(eventEntry); |
| 494 | } |
| 495 | } |