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