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