HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.flowmanager; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 5 | import java.util.EnumSet; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 6 | import java.util.HashMap; |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 7 | import java.util.LinkedList; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 8 | import java.util.Map; |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 9 | import java.util.Random; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 10 | import java.util.concurrent.Executors; |
| 11 | import java.util.concurrent.ScheduledExecutorService; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 12 | import java.util.concurrent.TimeUnit; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 13 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 14 | import net.floodlightcontroller.core.IFloodlightProviderService; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 15 | import net.floodlightcontroller.core.IOFSwitch; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 16 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 17 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 18 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 19 | import net.floodlightcontroller.core.module.IFloodlightService; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 20 | import net.floodlightcontroller.restserver.IRestApiService; |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 21 | |
| 22 | import net.onrc.onos.datagrid.IDatagridService; |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 23 | import net.onrc.onos.graph.GraphDBOperation; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 24 | import net.onrc.onos.ofcontroller.core.INetMapStorage; |
| 25 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 26 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
Pavlin Radoslavov | e9a3ef9 | 2013-10-18 18:46:45 -0700 | [diff] [blame] | 27 | import net.onrc.onos.ofcontroller.floodlightlistener.INetworkGraphService; |
HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame] | 28 | import net.onrc.onos.ofcontroller.flowmanager.web.FlowWebRoutable; |
Pavlin Radoslavov | 1278ac7 | 2013-10-16 04:43:49 -0700 | [diff] [blame] | 29 | import net.onrc.onos.ofcontroller.topology.ITopologyNetService; |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 30 | import net.onrc.onos.ofcontroller.topology.Topology; |
Pavlin Radoslavov | aaace7f | 2013-10-25 19:42:00 -0700 | [diff] [blame] | 31 | import net.onrc.onos.ofcontroller.topology.TopologyElement; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 32 | import net.onrc.onos.ofcontroller.util.*; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 33 | |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 34 | import org.slf4j.Logger; |
| 35 | import org.slf4j.LoggerFactory; |
| 36 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 37 | /** |
HIGUCHI Yuta | eb567aa | 2013-10-08 19:27:35 -0700 | [diff] [blame] | 38 | * Flow Manager class for handling the network flows. |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 39 | */ |
Pavlin Radoslavov | 5adf152 | 2013-04-04 17:43:41 -0700 | [diff] [blame] | 40 | public class FlowManager implements IFloodlightModule, IFlowService, INetMapStorage { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 41 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 42 | protected GraphDBOperation dbHandler; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 43 | |
Jonathan Hart | 50a9498 | 2013-04-10 14:49:51 -0700 | [diff] [blame] | 44 | protected volatile IFloodlightProviderService floodlightProvider; |
Pavlin Radoslavov | 1278ac7 | 2013-10-16 04:43:49 -0700 | [diff] [blame] | 45 | protected volatile ITopologyNetService topologyNetService; |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 46 | protected volatile IDatagridService datagridService; |
| 47 | protected IRestApiService restApi; |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 48 | protected FloodlightModuleContext context; |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 49 | protected PathComputation pathComputation; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 50 | |
Naoki Shiota | 5c8d19f | 2013-11-05 15:52:38 -0800 | [diff] [blame^] | 51 | protected FlowPusher pusher; |
| 52 | |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 53 | // Flow Entry ID generation state |
| 54 | private static Random randomGenerator = new Random(); |
| 55 | private static int nextFlowEntryIdPrefix = 0; |
| 56 | private static int nextFlowEntryIdSuffix = 0; |
| 57 | private static long nextFlowEntryId = 0; |
| 58 | |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 59 | /** The logger. */ |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 60 | private final static Logger log = LoggerFactory.getLogger(FlowManager.class); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 61 | |
| 62 | // The periodic task(s) |
Jonathan Hart | 50a9498 | 2013-04-10 14:49:51 -0700 | [diff] [blame] | 63 | private ScheduledExecutorService mapReaderScheduler; |
| 64 | private ScheduledExecutorService shortestPathReconcileScheduler; |
Pavlin Radoslavov | 6fb76d1 | 2013-04-09 22:52:25 -0700 | [diff] [blame] | 65 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 66 | /** |
| 67 | * Periodic task for reading the Flow Entries and pushing changes |
| 68 | * into the switches. |
| 69 | */ |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 70 | final Runnable mapReader = new Runnable() { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 71 | public void run() { |
Pavlin Radoslavov | a75caea | 2013-04-10 19:11:26 -0700 | [diff] [blame] | 72 | try { |
| 73 | runImpl(); |
| 74 | } catch (Exception e) { |
| 75 | log.debug("Exception processing All Flow Entries from the Network MAP: ", e); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 76 | dbHandler.rollback(); |
Pavlin Radoslavov | a75caea | 2013-04-10 19:11:26 -0700 | [diff] [blame] | 77 | return; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | private void runImpl() { |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 82 | long startTime = System.nanoTime(); |
| 83 | int counterAllFlowEntries = 0; |
| 84 | int counterMyNotUpdatedFlowEntries = 0; |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 85 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 86 | if (floodlightProvider == null) { |
| 87 | log.debug("FloodlightProvider service not found!"); |
| 88 | return; |
| 89 | } |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 90 | Map<Long, IOFSwitch> mySwitches = |
| 91 | floodlightProvider.getSwitches(); |
Pankaj Berde | bf51e4f | 2013-10-03 17:49:23 -0700 | [diff] [blame] | 92 | if (mySwitches.isEmpty()) { |
Pankaj Berde | 85a877b | 2013-10-03 18:26:35 -0700 | [diff] [blame] | 93 | log.trace("No switches controlled"); |
Pankaj Berde | bf51e4f | 2013-10-03 17:49:23 -0700 | [diff] [blame] | 94 | return; |
| 95 | } |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 96 | LinkedList<IFlowEntry> addFlowEntries = |
| 97 | new LinkedList<IFlowEntry>(); |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 98 | LinkedList<IFlowEntry> deleteFlowEntries = |
| 99 | new LinkedList<IFlowEntry>(); |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 100 | |
| 101 | // |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 102 | // Fetch all Flow Entries which need to be updated and select |
| 103 | // only my Flow Entries that need to be updated into the |
| 104 | // switches. |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 105 | // |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 106 | Iterable<IFlowEntry> allFlowEntries = |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 107 | dbHandler.getAllSwitchNotUpdatedFlowEntries(); |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 108 | for (IFlowEntry flowEntryObj : allFlowEntries) { |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 109 | counterAllFlowEntries++; |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 110 | |
Pavlin Radoslavov | 6db8c6e | 2013-04-08 00:14:07 +0000 | [diff] [blame] | 111 | String dpidStr = flowEntryObj.getSwitchDpid(); |
| 112 | if (dpidStr == null) |
| 113 | continue; |
| 114 | Dpid dpid = new Dpid(dpidStr); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 115 | IOFSwitch mySwitch = mySwitches.get(dpid.value()); |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 116 | if (mySwitch == null) |
| 117 | continue; // Ignore the entry: not my switch |
| 118 | |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 119 | IFlowPath flowObj = |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 120 | dbHandler.getFlowPathByFlowEntry(flowEntryObj); |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 121 | if (flowObj == null) |
| 122 | continue; // Should NOT happen |
| 123 | if (flowObj.getFlowId() == null) |
| 124 | continue; // Invalid entry |
| 125 | |
| 126 | // |
| 127 | // NOTE: For now we process the DELETE before the ADD |
| 128 | // to cover the more common scenario. |
| 129 | // TODO: This is error prone and needs to be fixed! |
| 130 | // |
Pavlin Radoslavov | 6db8c6e | 2013-04-08 00:14:07 +0000 | [diff] [blame] | 131 | String userState = flowEntryObj.getUserState(); |
| 132 | if (userState == null) |
| 133 | continue; |
Pavlin Radoslavov | ec8e2e6 | 2013-04-04 18:18:29 -0700 | [diff] [blame] | 134 | if (userState.equals("FE_USER_DELETE")) { |
| 135 | // An entry that needs to be deleted. |
| 136 | deleteFlowEntries.add(flowEntryObj); |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 137 | installFlowEntry(mySwitch, flowObj, flowEntryObj); |
| 138 | } else { |
| 139 | addFlowEntries.add(flowEntryObj); |
Pavlin Radoslavov | ec8e2e6 | 2013-04-04 18:18:29 -0700 | [diff] [blame] | 140 | } |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 141 | counterMyNotUpdatedFlowEntries++; |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 144 | // |
| 145 | // Process the Flow Entries that need to be added |
| 146 | // |
| 147 | for (IFlowEntry flowEntryObj : addFlowEntries) { |
| 148 | IFlowPath flowObj = |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 149 | dbHandler.getFlowPathByFlowEntry(flowEntryObj); |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 150 | if (flowObj == null) |
| 151 | continue; // Should NOT happen |
| 152 | if (flowObj.getFlowId() == null) |
| 153 | continue; // Invalid entry |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 154 | |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 155 | Dpid dpid = new Dpid(flowEntryObj.getSwitchDpid()); |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 156 | IOFSwitch mySwitch = mySwitches.get(dpid.value()); |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 157 | if (mySwitch == null) |
| 158 | continue; // Shouldn't happen |
Pavlin Radoslavov | ec8e2e6 | 2013-04-04 18:18:29 -0700 | [diff] [blame] | 159 | installFlowEntry(mySwitch, flowObj, flowEntryObj); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 160 | } |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 161 | |
| 162 | // |
Pavlin Radoslavov | 710e2a7 | 2013-04-08 02:31:05 +0000 | [diff] [blame] | 163 | // Delete all Flow Entries marked for deletion from the |
Pavlin Radoslavov | 44a3dcd | 2013-04-04 18:42:56 -0700 | [diff] [blame] | 164 | // Network MAP. |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 165 | // |
| 166 | // TODO: We should use the OpenFlow Barrier mechanism |
| 167 | // to check for errors, and delete the Flow Entries after the |
| 168 | // Barrier message is received. |
| 169 | // |
| 170 | while (! deleteFlowEntries.isEmpty()) { |
| 171 | IFlowEntry flowEntryObj = deleteFlowEntries.poll(); |
| 172 | IFlowPath flowObj = |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 173 | dbHandler.getFlowPathByFlowEntry(flowEntryObj); |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 174 | if (flowObj == null) { |
| 175 | log.debug("Did not find FlowPath to be deleted"); |
| 176 | continue; |
| 177 | } |
| 178 | flowObj.removeFlowEntry(flowEntryObj); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 179 | dbHandler.removeFlowEntry(flowEntryObj); |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 180 | } |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 181 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 182 | dbHandler.commit(); |
Pavlin Radoslavov | 6fb76d1 | 2013-04-09 22:52:25 -0700 | [diff] [blame] | 183 | |
Pavlin Radoslavov | 6fb76d1 | 2013-04-09 22:52:25 -0700 | [diff] [blame] | 184 | long estimatedTime = System.nanoTime() - startTime; |
| 185 | double rate = 0.0; |
| 186 | if (estimatedTime > 0) |
| 187 | rate = ((double)counterAllFlowEntries * 1000000000) / estimatedTime; |
| 188 | String logMsg = "MEASUREMENT: Processed AllFlowEntries: " + |
| 189 | counterAllFlowEntries + " MyNotUpdatedFlowEntries: " + |
| 190 | counterMyNotUpdatedFlowEntries + " in " + |
| 191 | (double)estimatedTime / 1000000000 + " sec: " + |
| 192 | rate + " paths/s"; |
| 193 | log.debug(logMsg); |
| 194 | } |
| 195 | }; |
| 196 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 197 | /** |
| 198 | * Periodic task for reading the Flow Paths and recomputing the |
| 199 | * shortest paths. |
| 200 | */ |
Pavlin Radoslavov | 6fb76d1 | 2013-04-09 22:52:25 -0700 | [diff] [blame] | 201 | final Runnable shortestPathReconcile = new Runnable() { |
| 202 | public void run() { |
Pavlin Radoslavov | a75caea | 2013-04-10 19:11:26 -0700 | [diff] [blame] | 203 | try { |
| 204 | runImpl(); |
| 205 | } catch (Exception e) { |
| 206 | log.debug("Exception processing All Flows from the Network MAP: ", e); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 207 | dbHandler.rollback(); |
Pavlin Radoslavov | a75caea | 2013-04-10 19:11:26 -0700 | [diff] [blame] | 208 | return; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | private void runImpl() { |
Pavlin Radoslavov | 6fb76d1 | 2013-04-09 22:52:25 -0700 | [diff] [blame] | 213 | long startTime = System.nanoTime(); |
| 214 | int counterAllFlowPaths = 0; |
| 215 | int counterMyFlowPaths = 0; |
| 216 | |
| 217 | if (floodlightProvider == null) { |
| 218 | log.debug("FloodlightProvider service not found!"); |
| 219 | return; |
| 220 | } |
| 221 | Map<Long, IOFSwitch> mySwitches = |
| 222 | floodlightProvider.getSwitches(); |
Pankaj Berde | bf51e4f | 2013-10-03 17:49:23 -0700 | [diff] [blame] | 223 | if (mySwitches.isEmpty()) { |
Pankaj Berde | 85a877b | 2013-10-03 18:26:35 -0700 | [diff] [blame] | 224 | log.trace("No switches controlled"); |
Pankaj Berde | bf51e4f | 2013-10-03 17:49:23 -0700 | [diff] [blame] | 225 | return; |
| 226 | } |
Pavlin Radoslavov | 6fb76d1 | 2013-04-09 22:52:25 -0700 | [diff] [blame] | 227 | LinkedList<IFlowPath> deleteFlows = new LinkedList<IFlowPath>(); |
| 228 | |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 229 | // |
| 230 | // Fetch and recompute the Shortest Path for those |
| 231 | // Flow Paths this controller is responsible for. |
| 232 | // |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 233 | Topology topology = topologyNetService.newDatabaseTopology(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 234 | Iterable<IFlowPath> allFlowPaths = dbHandler.getAllFlowPaths(); |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 235 | for (IFlowPath flowPathObj : allFlowPaths) { |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 236 | counterAllFlowPaths++; |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 237 | if (flowPathObj == null) |
| 238 | continue; |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 239 | |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 240 | String srcDpidStr = flowPathObj.getSrcSwitch(); |
Pavlin Radoslavov | 6db8c6e | 2013-04-08 00:14:07 +0000 | [diff] [blame] | 241 | if (srcDpidStr == null) |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 242 | continue; |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 243 | Dpid srcDpid = new Dpid(srcDpidStr); |
Pavlin Radoslavov | 2659a0b | 2013-04-03 20:30:40 -0700 | [diff] [blame] | 244 | // |
| 245 | // Use the source DPID as a heuristic to decide |
| 246 | // which controller is responsible for maintaining the |
| 247 | // shortest path. |
| 248 | // NOTE: This heuristic is error-prone: if the switch |
| 249 | // goes away and no controller is responsible for that |
| 250 | // switch, then the original Flow Path is not cleaned-up |
| 251 | // |
| 252 | IOFSwitch mySwitch = mySwitches.get(srcDpid.value()); |
| 253 | if (mySwitch == null) |
| 254 | continue; // Ignore: not my responsibility |
| 255 | |
Pavlin Radoslavov | bcc86ef | 2013-10-26 12:06:25 -0700 | [diff] [blame] | 256 | // Test whether we need to maintain this flow |
| 257 | String flowPathTypeStr = flowPathObj.getFlowPathType(); |
| 258 | if (flowPathTypeStr == null) |
Pavlin Radoslavov | 99d1b15 | 2013-04-09 22:57:33 -0700 | [diff] [blame] | 259 | continue; // Could be invalid entry? |
Pavlin Radoslavov | bcc86ef | 2013-10-26 12:06:25 -0700 | [diff] [blame] | 260 | if (! flowPathTypeStr.equals("FP_TYPE_SHORTEST_PATH")) |
Pavlin Radoslavov | 99d1b15 | 2013-04-09 22:57:33 -0700 | [diff] [blame] | 261 | continue; // No need to maintain this flow |
| 262 | |
Pavlin Radoslavov | 710e2a7 | 2013-04-08 02:31:05 +0000 | [diff] [blame] | 263 | // |
| 264 | // Test whether we need to complete the Flow cleanup, |
| 265 | // if the Flow has been deleted by the user. |
| 266 | // |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 267 | String flowPathUserStateStr = flowPathObj.getFlowPathUserState(); |
| 268 | if ((flowPathUserStateStr != null) |
| 269 | && flowPathUserStateStr.equals("FP_USER_DELETE")) { |
Pavlin Radoslavov | 710e2a7 | 2013-04-08 02:31:05 +0000 | [diff] [blame] | 270 | Iterable<IFlowEntry> flowEntries = flowPathObj.getFlowEntries(); |
Yuta HIGUCHI | 2ded2dd | 2013-10-09 18:06:41 -0700 | [diff] [blame] | 271 | final boolean empty = !flowEntries.iterator().hasNext(); |
Pavlin Radoslavov | 710e2a7 | 2013-04-08 02:31:05 +0000 | [diff] [blame] | 272 | if (empty) |
| 273 | deleteFlows.add(flowPathObj); |
| 274 | } |
| 275 | |
Pavlin Radoslavov | 6db8c6e | 2013-04-08 00:14:07 +0000 | [diff] [blame] | 276 | // Fetch the fields needed to recompute the shortest path |
Pavlin Radoslavov | bcc86ef | 2013-10-26 12:06:25 -0700 | [diff] [blame] | 277 | String dataPathSummaryStr = flowPathObj.getDataPathSummary(); |
Pavlin Radoslavov | 6db8c6e | 2013-04-08 00:14:07 +0000 | [diff] [blame] | 278 | Short srcPortShort = flowPathObj.getSrcPort(); |
| 279 | String dstDpidStr = flowPathObj.getDstSwitch(); |
| 280 | Short dstPortShort = flowPathObj.getDstPort(); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 281 | Long flowPathFlagsLong = flowPathObj.getFlowPathFlags(); |
Pavlin Radoslavov | bcc86ef | 2013-10-26 12:06:25 -0700 | [diff] [blame] | 282 | if ((dataPathSummaryStr == null) || |
| 283 | (srcPortShort == null) || |
Pavlin Radoslavov | 6db8c6e | 2013-04-08 00:14:07 +0000 | [diff] [blame] | 284 | (dstDpidStr == null) || |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 285 | (dstPortShort == null) || |
| 286 | (flowPathFlagsLong == null)) { |
Pavlin Radoslavov | 6db8c6e | 2013-04-08 00:14:07 +0000 | [diff] [blame] | 287 | continue; |
| 288 | } |
| 289 | |
| 290 | Port srcPort = new Port(srcPortShort); |
| 291 | Dpid dstDpid = new Dpid(dstDpidStr); |
| 292 | Port dstPort = new Port(dstPortShort); |
| 293 | SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort); |
| 294 | SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 295 | FlowPathType flowPathType = FlowPathType.valueOf(flowPathTypeStr); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 296 | FlowPathUserState flowPathUserState = FlowPathUserState.valueOf(flowPathUserStateStr); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 297 | FlowPathFlags flowPathFlags = new FlowPathFlags(flowPathFlagsLong); |
Pavlin Radoslavov | 6db8c6e | 2013-04-08 00:14:07 +0000 | [diff] [blame] | 298 | |
Pavlin Radoslavov | 2659a0b | 2013-04-03 20:30:40 -0700 | [diff] [blame] | 299 | counterMyFlowPaths++; |
| 300 | |
Pavlin Radoslavov | 832aa65 | 2013-03-29 16:21:59 -0700 | [diff] [blame] | 301 | // |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 302 | // NOTE: Using here the regular getDatabaseShortestPath() |
| 303 | // method won't work here, because that method calls |
| 304 | // internally "conn.endTx(Transaction.COMMIT)", and that |
| 305 | // will invalidate all handlers to the Titan database. |
Pavlin Radoslavov | 832aa65 | 2013-03-29 16:21:59 -0700 | [diff] [blame] | 306 | // If we want to experiment with calling here |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 307 | // getDatabaseShortestPath(), we need to refactor that code |
Pavlin Radoslavov | 832aa65 | 2013-03-29 16:21:59 -0700 | [diff] [blame] | 308 | // to avoid closing the transaction. |
| 309 | // |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 310 | DataPath dataPath = |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 311 | topologyNetService.getTopologyShortestPath( |
| 312 | topology, |
| 313 | srcSwitchPort, |
| 314 | dstSwitchPort); |
Pavlin Radoslavov | 4a32582 | 2013-04-02 22:16:59 +0000 | [diff] [blame] | 315 | if (dataPath == null) { |
| 316 | // We need the DataPath to compare the paths |
| 317 | dataPath = new DataPath(); |
| 318 | dataPath.setSrcPort(srcSwitchPort); |
| 319 | dataPath.setDstPort(dstSwitchPort); |
| 320 | } |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 321 | dataPath.applyFlowPathFlags(flowPathFlags); |
Pavlin Radoslavov | 4a32582 | 2013-04-02 22:16:59 +0000 | [diff] [blame] | 322 | |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 323 | String newDataPathSummaryStr = dataPath.dataPathSummary(); |
| 324 | if (dataPathSummaryStr.equals(newDataPathSummaryStr)) |
| 325 | continue; // Nothing changed |
| 326 | |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 327 | reconcileFlow(flowPathObj, dataPath); |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 328 | } |
Pavlin Radoslavov | 710e2a7 | 2013-04-08 02:31:05 +0000 | [diff] [blame] | 329 | |
| 330 | // |
| 331 | // Delete all leftover Flows marked for deletion from the |
| 332 | // Network MAP. |
| 333 | // |
| 334 | while (! deleteFlows.isEmpty()) { |
| 335 | IFlowPath flowPathObj = deleteFlows.poll(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 336 | dbHandler.removeFlowPath(flowPathObj); |
Pavlin Radoslavov | 710e2a7 | 2013-04-08 02:31:05 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 339 | topologyNetService.dropTopology(topology); |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 340 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 341 | dbHandler.commit(); |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 342 | |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 343 | long estimatedTime = System.nanoTime() - startTime; |
Pavlin Radoslavov | 1552f95 | 2013-04-04 17:51:22 -0700 | [diff] [blame] | 344 | double rate = 0.0; |
| 345 | if (estimatedTime > 0) |
| 346 | rate = ((double)counterAllFlowPaths * 1000000000) / estimatedTime; |
Pavlin Radoslavov | 6fb76d1 | 2013-04-09 22:52:25 -0700 | [diff] [blame] | 347 | String logMsg = "MEASUREMENT: Processed AllFlowPaths: " + |
Pavlin Radoslavov | 1552f95 | 2013-04-04 17:51:22 -0700 | [diff] [blame] | 348 | counterAllFlowPaths + " MyFlowPaths: " + |
| 349 | counterMyFlowPaths + " in " + |
| 350 | (double)estimatedTime / 1000000000 + " sec: " + |
| 351 | rate + " paths/s"; |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 352 | log.debug(logMsg); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 353 | } |
| 354 | }; |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 355 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 356 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 357 | /** |
| 358 | * Initialize the Flow Manager. |
| 359 | * |
| 360 | * @param conf the Graph Database configuration string. |
| 361 | */ |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 362 | @Override |
| 363 | public void init(String conf) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 364 | dbHandler = new GraphDBOperation(conf); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 365 | } |
| 366 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 367 | /** |
| 368 | * Shutdown the Flow Manager operation. |
| 369 | */ |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 370 | public void finalize() { |
Toshio Koide | 9fe1cb2 | 2013-06-13 13:51:11 -0700 | [diff] [blame] | 371 | close(); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 372 | } |
| 373 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 374 | /** |
| 375 | * Shutdown the Flow Manager operation. |
| 376 | */ |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 377 | @Override |
| 378 | public void close() { |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 379 | datagridService.deregisterPathComputationService(pathComputation); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 380 | dbHandler.close(); |
Naoki Shiota | 5c8d19f | 2013-11-05 15:52:38 -0800 | [diff] [blame^] | 381 | pusher.stop(); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 382 | } |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 383 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 384 | /** |
| 385 | * Get the collection of offered module services. |
| 386 | * |
| 387 | * @return the collection of offered module services. |
| 388 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 389 | @Override |
| 390 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 391 | Collection<Class<? extends IFloodlightService>> l = |
| 392 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 393 | l.add(IFlowService.class); |
| 394 | return l; |
| 395 | } |
| 396 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 397 | /** |
| 398 | * Get the collection of implemented services. |
| 399 | * |
| 400 | * @return the collection of implemented services. |
| 401 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 402 | @Override |
| 403 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
| 404 | getServiceImpls() { |
| 405 | Map<Class<? extends IFloodlightService>, |
Pavlin Radoslavov | e9a3ef9 | 2013-10-18 18:46:45 -0700 | [diff] [blame] | 406 | IFloodlightService> m = |
| 407 | new HashMap<Class<? extends IFloodlightService>, |
| 408 | IFloodlightService>(); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 409 | m.put(IFlowService.class, this); |
| 410 | return m; |
| 411 | } |
| 412 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 413 | /** |
| 414 | * Get the collection of modules this module depends on. |
| 415 | * |
| 416 | * @return the collection of modules this module depends on. |
| 417 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 418 | @Override |
| 419 | public Collection<Class<? extends IFloodlightService>> |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 420 | getModuleDependencies() { |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 421 | Collection<Class<? extends IFloodlightService>> l = |
| 422 | new ArrayList<Class<? extends IFloodlightService>>(); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 423 | l.add(IFloodlightProviderService.class); |
Pavlin Radoslavov | e9a3ef9 | 2013-10-18 18:46:45 -0700 | [diff] [blame] | 424 | l.add(INetworkGraphService.class); |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 425 | l.add(IDatagridService.class); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 426 | l.add(IRestApiService.class); |
| 427 | return l; |
| 428 | } |
| 429 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 430 | /** |
| 431 | * Initialize the module. |
| 432 | * |
| 433 | * @param context the module context to use for the initialization. |
| 434 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 435 | @Override |
| 436 | public void init(FloodlightModuleContext context) |
| 437 | throws FloodlightModuleException { |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 438 | this.context = context; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 439 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 440 | topologyNetService = context.getServiceImpl(ITopologyNetService.class); |
| 441 | datagridService = context.getServiceImpl(IDatagridService.class); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 442 | restApi = context.getServiceImpl(IRestApiService.class); |
Naoki Shiota | 5c8d19f | 2013-11-05 15:52:38 -0800 | [diff] [blame^] | 443 | |
| 444 | pusher = new FlowPusher(); |
| 445 | pusher.init(null, floodlightProvider.getOFMessageFactory(), null); |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 446 | this.init(""); |
| 447 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 448 | mapReaderScheduler = Executors.newScheduledThreadPool(1); |
| 449 | shortestPathReconcileScheduler = Executors.newScheduledThreadPool(1); |
Naoki Shiota | 5c8d19f | 2013-11-05 15:52:38 -0800 | [diff] [blame^] | 450 | |
| 451 | pusher.start(); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 452 | } |
| 453 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 454 | /** |
| 455 | * Get the next Flow Entry ID to use. |
| 456 | * |
| 457 | * @return the next Flow Entry ID to use. |
| 458 | */ |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 459 | public synchronized long getNextFlowEntryId() { |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 460 | // |
| 461 | // Generate the next Flow Entry ID. |
| 462 | // NOTE: For now, the higher 32 bits are random, and |
| 463 | // the lower 32 bits are sequential. |
| 464 | // In the future, we need a better allocation mechanism. |
| 465 | // |
| 466 | if ((nextFlowEntryIdSuffix & 0xffffffffL) == 0xffffffffL) { |
| 467 | nextFlowEntryIdPrefix = randomGenerator.nextInt(); |
| 468 | nextFlowEntryIdSuffix = 0; |
| 469 | } else { |
| 470 | nextFlowEntryIdSuffix++; |
| 471 | } |
| 472 | long result = (long)nextFlowEntryIdPrefix << 32; |
| 473 | result = result | (0xffffffffL & nextFlowEntryIdSuffix); |
| 474 | return result; |
| 475 | } |
| 476 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 477 | /** |
| 478 | * Startup module operation. |
| 479 | * |
| 480 | * @param context the module context to use for the startup. |
| 481 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 482 | @Override |
| 483 | public void startUp(FloodlightModuleContext context) { |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 484 | restApi.addRestletRoutable(new FlowWebRoutable()); |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 485 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 486 | // Initialize the Flow Entry ID generator |
| 487 | nextFlowEntryIdPrefix = randomGenerator.nextInt(); |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 488 | |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 489 | // |
| 490 | // Create the Path Computation thread and register it with the |
| 491 | // Datagrid Service |
| 492 | // |
| 493 | pathComputation = new PathComputation(this, datagridService); |
| 494 | datagridService.registerPathComputationService(pathComputation); |
Pavlin Radoslavov | aaace7f | 2013-10-25 19:42:00 -0700 | [diff] [blame] | 495 | |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 496 | // Schedule the threads and periodic tasks |
| 497 | pathComputation.start(); |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 498 | mapReaderScheduler.scheduleAtFixedRate( |
| 499 | mapReader, 3, 3, TimeUnit.SECONDS); |
| 500 | shortestPathReconcileScheduler.scheduleAtFixedRate( |
| 501 | shortestPathReconcile, 3, 3, TimeUnit.SECONDS); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /** |
| 505 | * Add a flow. |
| 506 | * |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 507 | * @param flowPath the Flow Path to install. |
| 508 | * @param flowId the return-by-reference Flow ID as assigned internally. |
| 509 | * @return true on success, otherwise false. |
| 510 | */ |
| 511 | @Override |
Pavlin Radoslavov | bcc86ef | 2013-10-26 12:06:25 -0700 | [diff] [blame] | 512 | public boolean addFlow(FlowPath flowPath, FlowId flowId) { |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 513 | // |
| 514 | // NOTE: We need to explicitly initialize the Flow Entry Switch State, |
| 515 | // in case the application didn't do it. |
| 516 | // |
| 517 | for (FlowEntry flowEntry : flowPath.flowEntries()) { |
| 518 | if (flowEntry.flowEntrySwitchState() == |
| 519 | FlowEntrySwitchState.FE_SWITCH_UNKNOWN) { |
| 520 | flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.FE_SWITCH_NOT_UPDATED); |
| 521 | } |
| 522 | } |
| 523 | |
Pavlin Radoslavov | bcc86ef | 2013-10-26 12:06:25 -0700 | [diff] [blame] | 524 | if (FlowDatabaseOperation.addFlow(this, dbHandler, flowPath, flowId)) { |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 525 | datagridService.notificationSendFlowAdded(flowPath); |
| 526 | return true; |
| 527 | } |
| 528 | return false; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /** |
Pavlin Radoslavov | 9425f70 | 2013-04-04 19:55:07 -0700 | [diff] [blame] | 532 | * Add a flow entry to the Network MAP. |
| 533 | * |
| 534 | * @param flowObj the corresponding Flow Path object for the Flow Entry. |
| 535 | * @param flowEntry the Flow Entry to install. |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 536 | * @return the added Flow Entry object on success, otherwise null. |
Pavlin Radoslavov | 9425f70 | 2013-04-04 19:55:07 -0700 | [diff] [blame] | 537 | */ |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 538 | private IFlowEntry addFlowEntry(IFlowPath flowObj, FlowEntry flowEntry) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 539 | return FlowDatabaseOperation.addFlowEntry(this, dbHandler, flowObj, |
| 540 | flowEntry); |
Pavlin Radoslavov | 9425f70 | 2013-04-04 19:55:07 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /** |
Pavlin Radoslavov | baea924 | 2013-05-08 00:20:09 +0000 | [diff] [blame] | 544 | * Delete all previously added flows. |
| 545 | * |
| 546 | * @return true on success, otherwise false. |
| 547 | */ |
| 548 | @Override |
| 549 | public boolean deleteAllFlows() { |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 550 | if (FlowDatabaseOperation.deleteAllFlows(dbHandler)) { |
| 551 | datagridService.notificationSendAllFlowsRemoved(); |
| 552 | return true; |
| 553 | } |
| 554 | return false; |
Pavlin Radoslavov | baea924 | 2013-05-08 00:20:09 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | /** |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 558 | * Delete a previously added flow. |
| 559 | * |
| 560 | * @param flowId the Flow ID of the flow to delete. |
| 561 | * @return true on success, otherwise false. |
| 562 | */ |
| 563 | @Override |
| 564 | public boolean deleteFlow(FlowId flowId) { |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 565 | if (FlowDatabaseOperation.deleteFlow(dbHandler, flowId)) { |
| 566 | datagridService.notificationSendFlowRemoved(flowId); |
| 567 | return true; |
| 568 | } |
| 569 | return false; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | /** |
Pavlin Radoslavov | baea924 | 2013-05-08 00:20:09 +0000 | [diff] [blame] | 573 | * Clear the state for all previously added flows. |
| 574 | * |
| 575 | * @return true on success, otherwise false. |
| 576 | */ |
| 577 | @Override |
| 578 | public boolean clearAllFlows() { |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 579 | if (FlowDatabaseOperation.clearAllFlows(dbHandler)) { |
| 580 | datagridService.notificationSendAllFlowsRemoved(); |
| 581 | return true; |
| 582 | } |
| 583 | return false; |
Pavlin Radoslavov | baea924 | 2013-05-08 00:20:09 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /** |
Pavlin Radoslavov | 916832f | 2013-03-14 17:48:41 -0700 | [diff] [blame] | 587 | * Clear the state for a previously added flow. |
| 588 | * |
| 589 | * @param flowId the Flow ID of the flow to clear. |
| 590 | * @return true on success, otherwise false. |
| 591 | */ |
| 592 | @Override |
| 593 | public boolean clearFlow(FlowId flowId) { |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 594 | if (FlowDatabaseOperation.clearFlow(dbHandler, flowId)) { |
| 595 | datagridService.notificationSendFlowRemoved(flowId); |
| 596 | return true; |
| 597 | } |
| 598 | return false; |
Pavlin Radoslavov | 916832f | 2013-03-14 17:48:41 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /** |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 602 | * Get a previously added flow. |
| 603 | * |
| 604 | * @param flowId the Flow ID of the flow to get. |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 605 | * @return the Flow Path if found, otherwise null. |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 606 | */ |
| 607 | @Override |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 608 | public FlowPath getFlow(FlowId flowId) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 609 | return FlowDatabaseOperation.getFlow(dbHandler, flowId); |
| 610 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 611 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 612 | /** |
| 613 | * Get all installed flows by all installers. |
| 614 | * |
| 615 | * @return the Flow Paths if found, otherwise null. |
| 616 | */ |
| 617 | @Override |
| 618 | public ArrayList<FlowPath> getAllFlows() { |
| 619 | return FlowDatabaseOperation.getAllFlows(dbHandler); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | /** |
| 623 | * Get all previously added flows by a specific installer for a given |
| 624 | * data path endpoints. |
| 625 | * |
| 626 | * @param installerId the Caller ID of the installer of the flow to get. |
| 627 | * @param dataPathEndpoints the data path endpoints of the flow to get. |
| 628 | * @return the Flow Paths if found, otherwise null. |
| 629 | */ |
| 630 | @Override |
| 631 | public ArrayList<FlowPath> getAllFlows(CallerId installerId, |
| 632 | DataPathEndpoints dataPathEndpoints) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 633 | return FlowDatabaseOperation.getAllFlows(dbHandler, installerId, |
| 634 | dataPathEndpoints); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | /** |
| 638 | * Get all installed flows by all installers for given data path endpoints. |
| 639 | * |
| 640 | * @param dataPathEndpoints the data path endpoints of the flows to get. |
| 641 | * @return the Flow Paths if found, otherwise null. |
| 642 | */ |
| 643 | @Override |
| 644 | public ArrayList<FlowPath> getAllFlows(DataPathEndpoints dataPathEndpoints) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 645 | return FlowDatabaseOperation.getAllFlows(dbHandler, dataPathEndpoints); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | /** |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 649 | * Get summary of all installed flows by all installers in a given range. |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 650 | * |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 651 | * @param flowId the Flow ID of the first flow in the flow range to get. |
HIGUCHI Yuta | eb567aa | 2013-10-08 19:27:35 -0700 | [diff] [blame] | 652 | * @param maxFlows the maximum number of flows to be returned. |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 653 | * @return the Flow Paths if found, otherwise null. |
| 654 | */ |
| 655 | @Override |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 656 | public ArrayList<IFlowPath> getAllFlowsSummary(FlowId flowId, |
| 657 | int maxFlows) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 658 | return FlowDatabaseOperation.getAllFlowsSummary(dbHandler, flowId, |
| 659 | maxFlows); |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | /** |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 663 | * Get all Flows information, without the associated Flow Entries. |
| 664 | * |
| 665 | * @return all Flows information, without the associated Flow Entries. |
| 666 | */ |
| 667 | public ArrayList<IFlowPath> getAllFlowsWithoutFlowEntries() { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 668 | return FlowDatabaseOperation.getAllFlowsWithoutFlowEntries(dbHandler); |
Pavlin Radoslavov | 99b1275 | 2013-04-04 17:28:06 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | /** |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 672 | * Add and maintain a shortest-path flow. |
| 673 | * |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 674 | * NOTE: The Flow Path argument does NOT contain flow entries. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 675 | * |
| 676 | * @param flowPath the Flow Path with the endpoints and the match |
| 677 | * conditions to install. |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 678 | * @return the added shortest-path flow on success, otherwise null. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 679 | */ |
| 680 | @Override |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 681 | public FlowPath addAndMaintainShortestPathFlow(FlowPath flowPath) { |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 682 | // |
Pavlin Radoslavov | 8b4b059 | 2013-04-10 04:33:33 +0000 | [diff] [blame] | 683 | // Don't do the shortest path computation here. |
| 684 | // Instead, let the Flow reconciliation thread take care of it. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 685 | // |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 686 | |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 687 | FlowId flowId = new FlowId(); |
Pavlin Radoslavov | bcc86ef | 2013-10-26 12:06:25 -0700 | [diff] [blame] | 688 | if (! addFlow(flowPath, flowId)) |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 689 | return null; |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 690 | |
Pavlin Radoslavov | bcc86ef | 2013-10-26 12:06:25 -0700 | [diff] [blame] | 691 | return (flowPath); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /** |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 695 | * Reconcile a flow. |
| 696 | * |
| 697 | * @param flowObj the flow that needs to be reconciliated. |
| 698 | * @param newDataPath the new data path to use. |
| 699 | * @return true on success, otherwise false. |
| 700 | */ |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 701 | private boolean reconcileFlow(IFlowPath flowObj, DataPath newDataPath) { |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 702 | |
| 703 | // |
| 704 | // Set the incoming port matching and the outgoing port output |
| 705 | // actions for each flow entry. |
| 706 | // |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 707 | int idx = 0; |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 708 | for (FlowEntry flowEntry : newDataPath.flowEntries()) { |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 709 | // Mark the Flow Entry as not updated in the switch |
| 710 | flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.FE_SWITCH_NOT_UPDATED); |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 711 | // Set the incoming port matching |
| 712 | FlowEntryMatch flowEntryMatch = new FlowEntryMatch(); |
| 713 | flowEntry.setFlowEntryMatch(flowEntryMatch); |
| 714 | flowEntryMatch.enableInPort(flowEntry.inPort()); |
| 715 | |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 716 | // |
| 717 | // Set the actions |
| 718 | // |
| 719 | FlowEntryActions flowEntryActions = flowEntry.flowEntryActions(); |
| 720 | // |
| 721 | // If the first Flow Entry, copy the Flow Path actions to it |
| 722 | // |
| 723 | if (idx == 0) { |
| 724 | String actionsStr = flowObj.getActions(); |
| 725 | if (actionsStr != null) { |
| 726 | FlowEntryActions flowActions = new FlowEntryActions(actionsStr); |
| 727 | for (FlowEntryAction action : flowActions.actions()) |
| 728 | flowEntryActions.addAction(action); |
| 729 | } |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 730 | } |
Pavlin Radoslavov | 282f4ff | 2013-07-18 11:21:37 -0700 | [diff] [blame] | 731 | idx++; |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 732 | // |
| 733 | // Add the outgoing port output action |
| 734 | // |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 735 | FlowEntryAction flowEntryAction = new FlowEntryAction(); |
| 736 | flowEntryAction.setActionOutput(flowEntry.outPort()); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 737 | flowEntryActions.addAction(flowEntryAction); |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | // |
| 741 | // Remove the old Flow Entries, and add the new Flow Entries |
| 742 | // |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 743 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 744 | for (IFlowEntry flowEntryObj : flowEntries) { |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 745 | flowEntryObj.setUserState("FE_USER_DELETE"); |
Pavlin Radoslavov | 6fb76d1 | 2013-04-09 22:52:25 -0700 | [diff] [blame] | 746 | flowEntryObj.setSwitchState("FE_SWITCH_NOT_UPDATED"); |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 747 | } |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 748 | for (FlowEntry flowEntry : newDataPath.flowEntries()) { |
Pavlin Radoslavov | 6fb76d1 | 2013-04-09 22:52:25 -0700 | [diff] [blame] | 749 | addFlowEntry(flowObj, flowEntry); |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | // |
| 753 | // Set the Data Path Summary |
| 754 | // |
| 755 | String dataPathSummaryStr = newDataPath.dataPathSummary(); |
| 756 | flowObj.setDataPathSummary(dataPathSummaryStr); |
| 757 | |
| 758 | return true; |
| 759 | } |
| 760 | |
| 761 | /** |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 762 | * Reconcile all flows in a set. |
| 763 | * |
| 764 | * @param flowObjSet the set of flows that need to be reconciliated. |
| 765 | */ |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 766 | private void reconcileFlows(Iterable<IFlowPath> flowObjSet) { |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 767 | if (! flowObjSet.iterator().hasNext()) |
| 768 | return; |
Pavlin Radoslavov | 0eeb15d | 2013-04-05 10:23:51 -0700 | [diff] [blame] | 769 | // TODO: Not implemented/used yet. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /** |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 773 | * Install a Flow Entry on a switch. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 774 | * |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 775 | * @param mySwitch the switch to install the Flow Entry into. |
Pavlin Radoslavov | ec8e2e6 | 2013-04-04 18:18:29 -0700 | [diff] [blame] | 776 | * @param flowObj the flow path object for the flow entry to install. |
| 777 | * @param flowEntryObj the flow entry object to install. |
| 778 | * @return true on success, otherwise false. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 779 | */ |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 780 | private boolean installFlowEntry(IOFSwitch mySwitch, IFlowPath flowObj, |
Pavlin Radoslavov | ec8e2e6 | 2013-04-04 18:18:29 -0700 | [diff] [blame] | 781 | IFlowEntry flowEntryObj) { |
Naoki Shiota | 5c8d19f | 2013-11-05 15:52:38 -0800 | [diff] [blame^] | 782 | log.debug("Flow is sent to pusher : dpid({}) flow_id({})", mySwitch.getId(), flowEntryObj.getFlowEntryId()); |
| 783 | return pusher.send(mySwitch, flowObj, flowEntryObj); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | /** |
| 787 | * Install a Flow Entry on a switch. |
| 788 | * |
| 789 | * @param mySwitch the switch to install the Flow Entry into. |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 790 | * @param flowPath the flow path for the flow entry to install. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 791 | * @param flowEntry the flow entry to install. |
| 792 | * @return true on success, otherwise false. |
| 793 | */ |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 794 | private boolean installFlowEntry(IOFSwitch mySwitch, FlowPath flowPath, |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 795 | FlowEntry flowEntry) { |
Naoki Shiota | 5c8d19f | 2013-11-05 15:52:38 -0800 | [diff] [blame^] | 796 | log.debug("Flow is sent to pusher : dpid({}) flow_id({})", mySwitch.getId(), flowEntry.getFlowId()); |
| 797 | // TODO handle this installation by FlowPusher |
| 798 | |
| 799 | // return FlowSwitchOperation.installFlowEntry( |
| 800 | // floodlightProvider.getOFMessageFactory(), |
| 801 | // messageDamper, mySwitch, flowPath, flowEntry); |
| 802 | |
| 803 | return true; |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | /** |
| 807 | * Remove a Flow Entry from a switch. |
| 808 | * |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 809 | * @param mySwitch the switch to remove the Flow Entry from. |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 810 | * @param flowPath the flow path for the flow entry to remove. |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 811 | * @param flowEntry the flow entry to remove. |
| 812 | * @return true on success, otherwise false. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 813 | */ |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 814 | private boolean removeFlowEntry(IOFSwitch mySwitch, FlowPath flowPath, |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 815 | FlowEntry flowEntry) { |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 816 | // |
| 817 | // The installFlowEntry() method implements both installation |
| 818 | // and removal of flow entries. |
| 819 | // |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 820 | return (installFlowEntry(mySwitch, flowPath, flowEntry)); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 821 | } |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 822 | |
| 823 | /** |
| 824 | * Push the modified Flow Entries of a collection of Flow Paths. |
| 825 | * Only the Flow Entries to switches controlled by this instance |
| 826 | * are pushed. |
| 827 | * |
| 828 | * NOTE: Currently, we write to both the Network MAP and the switches. |
| 829 | * |
| 830 | * @param modifiedFlowPaths the collection of Flow Paths with the modified |
| 831 | * Flow Entries. |
| 832 | */ |
| 833 | public void pushModifiedFlowEntries(Collection<FlowPath> modifiedFlowPaths) { |
| 834 | |
| 835 | // TODO: For now, the pushing of Flow Entries is disabled |
| 836 | if (true) |
| 837 | return; |
| 838 | |
| 839 | Map<Long, IOFSwitch> mySwitches = floodlightProvider.getSwitches(); |
| 840 | |
| 841 | for (FlowPath flowPath : modifiedFlowPaths) { |
| 842 | IFlowPath flowObj = dbHandler.searchFlowPath(flowPath.flowId()); |
| 843 | if (flowObj == null) { |
| 844 | String logMsg = "Cannot find Network MAP entry for Flow Path " + |
| 845 | flowPath.flowId(); |
| 846 | log.error(logMsg); |
| 847 | continue; |
| 848 | } |
| 849 | |
| 850 | for (FlowEntry flowEntry : flowPath.flowEntries()) { |
| 851 | if (flowEntry.flowEntrySwitchState() != |
| 852 | FlowEntrySwitchState.FE_SWITCH_NOT_UPDATED) { |
| 853 | continue; // No need to update the entry |
| 854 | } |
| 855 | |
| 856 | IOFSwitch mySwitch = mySwitches.get(flowEntry.dpid().value()); |
| 857 | if (mySwitch == null) |
| 858 | continue; // Ignore the entry: not my switch |
| 859 | |
| 860 | // |
| 861 | // Assign the FlowEntry ID if needed |
| 862 | // |
| 863 | if ((flowEntry.flowEntryId() == null) || |
| 864 | (flowEntry.flowEntryId().value() == 0)) { |
| 865 | long id = getNextFlowEntryId(); |
| 866 | flowEntry.setFlowEntryId(new FlowEntryId(id)); |
| 867 | } |
| 868 | |
| 869 | // |
| 870 | // Install the Flow Entry into the switch |
| 871 | // |
| 872 | if (! installFlowEntry(mySwitch, flowPath, flowEntry)) { |
| 873 | String logMsg = "Cannot install Flow Entry " + |
| 874 | flowEntry.flowEntryId() + |
| 875 | " from Flow Path " + flowPath.flowId() + |
| 876 | " on switch " + flowEntry.dpid(); |
| 877 | log.error(logMsg); |
| 878 | continue; |
| 879 | } |
| 880 | |
| 881 | // |
| 882 | // NOTE: Here we assume that the switch has been successfully |
| 883 | // updated. |
| 884 | // |
| 885 | flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.FE_SWITCH_UPDATED); |
| 886 | |
| 887 | // |
| 888 | // Write the Flow Entry to the Network Map |
| 889 | // |
| 890 | try { |
| 891 | if (addFlowEntry(flowObj, flowEntry) == null) { |
| 892 | String logMsg = "Cannot write to Network MAP Flow Entry " + |
| 893 | flowEntry.flowEntryId() + |
| 894 | " from Flow Path " + flowPath.flowId() + |
| 895 | " on switch " + flowEntry.dpid(); |
| 896 | log.error(logMsg); |
| 897 | continue; |
| 898 | } |
| 899 | } catch (Exception e) { |
| 900 | String logMsg = "Exception writing Flow Entry to Network MAP"; |
| 901 | log.debug(logMsg); |
| 902 | dbHandler.rollback(); |
| 903 | continue; |
| 904 | } |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | dbHandler.commit(); |
| 909 | } |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 910 | } |