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