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