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