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 | 99d1b15 | 2013-04-09 22:57:33 -0700 | [diff] [blame] | 274 | // Test the Data Path Summary string |
| 275 | String dataPathSummaryStr = flowPathObj.getDataPathSummary(); |
| 276 | if (dataPathSummaryStr == null) |
| 277 | continue; // Could be invalid entry? |
| 278 | if (dataPathSummaryStr.isEmpty()) |
| 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 |
| 295 | Short srcPortShort = flowPathObj.getSrcPort(); |
| 296 | String dstDpidStr = flowPathObj.getDstSwitch(); |
| 297 | Short dstPortShort = flowPathObj.getDstPort(); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 298 | Long flowPathFlagsLong = flowPathObj.getFlowPathFlags(); |
Pavlin Radoslavov | 6db8c6e | 2013-04-08 00:14:07 +0000 | [diff] [blame] | 299 | if ((srcPortShort == null) || |
| 300 | (dstDpidStr == null) || |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 301 | (dstPortShort == null) || |
| 302 | (flowPathFlagsLong == null)) { |
Pavlin Radoslavov | 6db8c6e | 2013-04-08 00:14:07 +0000 | [diff] [blame] | 303 | continue; |
| 304 | } |
| 305 | |
| 306 | Port srcPort = new Port(srcPortShort); |
| 307 | Dpid dstDpid = new Dpid(dstDpidStr); |
| 308 | Port dstPort = new Port(dstPortShort); |
| 309 | SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort); |
| 310 | SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 311 | FlowPathFlags flowPathFlags = new FlowPathFlags(flowPathFlagsLong); |
Pavlin Radoslavov | 6db8c6e | 2013-04-08 00:14:07 +0000 | [diff] [blame] | 312 | |
Pavlin Radoslavov | 2659a0b | 2013-04-03 20:30:40 -0700 | [diff] [blame] | 313 | counterMyFlowPaths++; |
| 314 | |
Pavlin Radoslavov | 832aa65 | 2013-03-29 16:21:59 -0700 | [diff] [blame] | 315 | // |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 316 | // NOTE: Using here the regular getDatabaseShortestPath() |
| 317 | // method won't work here, because that method calls |
| 318 | // internally "conn.endTx(Transaction.COMMIT)", and that |
| 319 | // will invalidate all handlers to the Titan database. |
Pavlin Radoslavov | 832aa65 | 2013-03-29 16:21:59 -0700 | [diff] [blame] | 320 | // If we want to experiment with calling here |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 321 | // getDatabaseShortestPath(), we need to refactor that code |
Pavlin Radoslavov | 832aa65 | 2013-03-29 16:21:59 -0700 | [diff] [blame] | 322 | // to avoid closing the transaction. |
| 323 | // |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 324 | DataPath dataPath = |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 325 | topologyNetService.getTopologyShortestPath( |
| 326 | topology, |
| 327 | srcSwitchPort, |
| 328 | dstSwitchPort); |
Pavlin Radoslavov | 4a32582 | 2013-04-02 22:16:59 +0000 | [diff] [blame] | 329 | if (dataPath == null) { |
| 330 | // We need the DataPath to compare the paths |
| 331 | dataPath = new DataPath(); |
| 332 | dataPath.setSrcPort(srcSwitchPort); |
| 333 | dataPath.setDstPort(dstSwitchPort); |
| 334 | } |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 335 | dataPath.applyFlowPathFlags(flowPathFlags); |
Pavlin Radoslavov | 4a32582 | 2013-04-02 22:16:59 +0000 | [diff] [blame] | 336 | |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 337 | String newDataPathSummaryStr = dataPath.dataPathSummary(); |
| 338 | if (dataPathSummaryStr.equals(newDataPathSummaryStr)) |
| 339 | continue; // Nothing changed |
| 340 | |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 341 | reconcileFlow(flowPathObj, dataPath); |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 342 | } |
Pavlin Radoslavov | 710e2a7 | 2013-04-08 02:31:05 +0000 | [diff] [blame] | 343 | |
| 344 | // |
| 345 | // Delete all leftover Flows marked for deletion from the |
| 346 | // Network MAP. |
| 347 | // |
| 348 | while (! deleteFlows.isEmpty()) { |
| 349 | IFlowPath flowPathObj = deleteFlows.poll(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 350 | dbHandler.removeFlowPath(flowPathObj); |
Pavlin Radoslavov | 710e2a7 | 2013-04-08 02:31:05 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 353 | topologyNetService.dropTopology(topology); |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 354 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 355 | dbHandler.commit(); |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 356 | |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 357 | long estimatedTime = System.nanoTime() - startTime; |
Pavlin Radoslavov | 1552f95 | 2013-04-04 17:51:22 -0700 | [diff] [blame] | 358 | double rate = 0.0; |
| 359 | if (estimatedTime > 0) |
| 360 | rate = ((double)counterAllFlowPaths * 1000000000) / estimatedTime; |
Pavlin Radoslavov | 6fb76d1 | 2013-04-09 22:52:25 -0700 | [diff] [blame] | 361 | String logMsg = "MEASUREMENT: Processed AllFlowPaths: " + |
Pavlin Radoslavov | 1552f95 | 2013-04-04 17:51:22 -0700 | [diff] [blame] | 362 | counterAllFlowPaths + " MyFlowPaths: " + |
| 363 | counterMyFlowPaths + " in " + |
| 364 | (double)estimatedTime / 1000000000 + " sec: " + |
| 365 | rate + " paths/s"; |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 366 | log.debug(logMsg); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 367 | } |
| 368 | }; |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 369 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 370 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 371 | /** |
| 372 | * Initialize the Flow Manager. |
| 373 | * |
| 374 | * @param conf the Graph Database configuration string. |
| 375 | */ |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 376 | @Override |
| 377 | public void init(String conf) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 378 | dbHandler = new GraphDBOperation(conf); |
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 | public void finalize() { |
Toshio Koide | 9fe1cb2 | 2013-06-13 13:51:11 -0700 | [diff] [blame] | 385 | close(); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 386 | } |
| 387 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 388 | /** |
| 389 | * Shutdown the Flow Manager operation. |
| 390 | */ |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 391 | @Override |
| 392 | public void close() { |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 393 | datagridService.deregisterFlowService(this); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 394 | dbHandler.close(); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 395 | } |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 396 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 397 | /** |
| 398 | * Get the collection of offered module services. |
| 399 | * |
| 400 | * @return the collection of offered module services. |
| 401 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 402 | @Override |
| 403 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 404 | Collection<Class<? extends IFloodlightService>> l = |
| 405 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 406 | l.add(IFlowService.class); |
| 407 | return l; |
| 408 | } |
| 409 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 410 | /** |
| 411 | * Get the collection of implemented services. |
| 412 | * |
| 413 | * @return the collection of implemented services. |
| 414 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 415 | @Override |
| 416 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
| 417 | getServiceImpls() { |
| 418 | Map<Class<? extends IFloodlightService>, |
Pavlin Radoslavov | e9a3ef9 | 2013-10-18 18:46:45 -0700 | [diff] [blame] | 419 | IFloodlightService> m = |
| 420 | new HashMap<Class<? extends IFloodlightService>, |
| 421 | IFloodlightService>(); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 422 | m.put(IFlowService.class, this); |
| 423 | return m; |
| 424 | } |
| 425 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 426 | /** |
| 427 | * Get the collection of modules this module depends on. |
| 428 | * |
| 429 | * @return the collection of modules this module depends on. |
| 430 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 431 | @Override |
| 432 | public Collection<Class<? extends IFloodlightService>> |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 433 | getModuleDependencies() { |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 434 | Collection<Class<? extends IFloodlightService>> l = |
| 435 | new ArrayList<Class<? extends IFloodlightService>>(); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 436 | l.add(IFloodlightProviderService.class); |
Pavlin Radoslavov | e9a3ef9 | 2013-10-18 18:46:45 -0700 | [diff] [blame] | 437 | l.add(INetworkGraphService.class); |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 438 | l.add(IDatagridService.class); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 439 | l.add(IRestApiService.class); |
| 440 | return l; |
| 441 | } |
| 442 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 443 | /** |
| 444 | * Initialize the module. |
| 445 | * |
| 446 | * @param context the module context to use for the initialization. |
| 447 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 448 | @Override |
| 449 | public void init(FloodlightModuleContext context) |
| 450 | throws FloodlightModuleException { |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 451 | this.context = context; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 452 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 453 | topologyNetService = context.getServiceImpl(ITopologyNetService.class); |
| 454 | datagridService = context.getServiceImpl(IDatagridService.class); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 455 | restApi = context.getServiceImpl(IRestApiService.class); |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 456 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 457 | messageDamper = new OFMessageDamper(OFMESSAGE_DAMPER_CAPACITY, |
| 458 | EnumSet.of(OFType.FLOW_MOD), |
| 459 | OFMESSAGE_DAMPER_TIMEOUT); |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 460 | |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 461 | this.init(""); |
| 462 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 463 | mapReaderScheduler = Executors.newScheduledThreadPool(1); |
| 464 | shortestPathReconcileScheduler = Executors.newScheduledThreadPool(1); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 465 | } |
| 466 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 467 | /** |
| 468 | * Get the next Flow Entry ID to use. |
| 469 | * |
| 470 | * @return the next Flow Entry ID to use. |
| 471 | */ |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 472 | public synchronized long getNextFlowEntryId() { |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 473 | // |
| 474 | // Generate the next Flow Entry ID. |
| 475 | // NOTE: For now, the higher 32 bits are random, and |
| 476 | // the lower 32 bits are sequential. |
| 477 | // In the future, we need a better allocation mechanism. |
| 478 | // |
| 479 | if ((nextFlowEntryIdSuffix & 0xffffffffL) == 0xffffffffL) { |
| 480 | nextFlowEntryIdPrefix = randomGenerator.nextInt(); |
| 481 | nextFlowEntryIdSuffix = 0; |
| 482 | } else { |
| 483 | nextFlowEntryIdSuffix++; |
| 484 | } |
| 485 | long result = (long)nextFlowEntryIdPrefix << 32; |
| 486 | result = result | (0xffffffffL & nextFlowEntryIdSuffix); |
| 487 | return result; |
| 488 | } |
| 489 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 490 | /** |
| 491 | * Startup module operation. |
| 492 | * |
| 493 | * @param context the module context to use for the startup. |
| 494 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 495 | @Override |
| 496 | public void startUp(FloodlightModuleContext context) { |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 497 | restApi.addRestletRoutable(new FlowWebRoutable()); |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 498 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 499 | // Initialize the Flow Entry ID generator |
| 500 | nextFlowEntryIdPrefix = randomGenerator.nextInt(); |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 501 | |
Pavlin Radoslavov | aaace7f | 2013-10-25 19:42:00 -0700 | [diff] [blame] | 502 | // Register with the Datagrid Service |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 503 | datagridService.registerFlowService(this); |
Pavlin Radoslavov | aaace7f | 2013-10-25 19:42:00 -0700 | [diff] [blame] | 504 | |
| 505 | // Obtain the initial Topology state |
| 506 | Collection<TopologyElement> topologyElements = |
| 507 | datagridService.getAllTopologyElements(); |
| 508 | for (TopologyElement topologyElement : topologyElements) { |
| 509 | EventEntry<TopologyElement> eventEntry = |
| 510 | new EventEntry<TopologyElement>(EventEntry.Type.ENTRY_ADD, topologyElement); |
| 511 | topologyEvents.add(eventEntry); |
| 512 | } |
| 513 | |
| 514 | // Obtain the initial Flow state |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 515 | Collection<FlowPath> flowPaths = datagridService.getAllFlows(); |
Pavlin Radoslavov | 3f9ba65 | 2013-10-25 17:19:01 -0700 | [diff] [blame] | 516 | for (FlowPath flowPath : flowPaths) { |
| 517 | EventEntry<FlowPath> eventEntry = |
| 518 | new EventEntry<FlowPath>(EventEntry.Type.ENTRY_ADD, flowPath); |
| 519 | flowPathEvents.add(eventEntry); |
| 520 | } |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 521 | |
Pavlin Radoslavov | 3f9ba65 | 2013-10-25 17:19:01 -0700 | [diff] [blame] | 522 | // Schedule the periodic tasks |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 523 | mapReaderScheduler.scheduleAtFixedRate( |
| 524 | mapReader, 3, 3, TimeUnit.SECONDS); |
| 525 | shortestPathReconcileScheduler.scheduleAtFixedRate( |
| 526 | shortestPathReconcile, 3, 3, TimeUnit.SECONDS); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | /** |
| 530 | * Add a flow. |
| 531 | * |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 532 | * @param flowPath the Flow Path to install. |
| 533 | * @param flowId the return-by-reference Flow ID as assigned internally. |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 534 | * @param dataPathSummaryStr the data path summary string if the added |
| 535 | * flow will be maintained internally, otherwise null. |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 536 | * @return true on success, otherwise false. |
| 537 | */ |
| 538 | @Override |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 539 | public boolean addFlow(FlowPath flowPath, FlowId flowId, |
| 540 | String dataPathSummaryStr) { |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 541 | if (FlowDatabaseOperation.addFlow(this, dbHandler, flowPath, flowId, |
| 542 | dataPathSummaryStr)) { |
| 543 | datagridService.notificationSendFlowAdded(flowPath); |
| 544 | return true; |
| 545 | } |
| 546 | return false; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | /** |
Pavlin Radoslavov | 9425f70 | 2013-04-04 19:55:07 -0700 | [diff] [blame] | 550 | * Add a flow entry to the Network MAP. |
| 551 | * |
| 552 | * @param flowObj the corresponding Flow Path object for the Flow Entry. |
| 553 | * @param flowEntry the Flow Entry to install. |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 554 | * @return the added Flow Entry object on success, otherwise null. |
Pavlin Radoslavov | 9425f70 | 2013-04-04 19:55:07 -0700 | [diff] [blame] | 555 | */ |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 556 | private IFlowEntry addFlowEntry(IFlowPath flowObj, FlowEntry flowEntry) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 557 | return FlowDatabaseOperation.addFlowEntry(this, dbHandler, flowObj, |
| 558 | flowEntry); |
Pavlin Radoslavov | 9425f70 | 2013-04-04 19:55:07 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | /** |
Pavlin Radoslavov | baea924 | 2013-05-08 00:20:09 +0000 | [diff] [blame] | 562 | * Delete all previously added flows. |
| 563 | * |
| 564 | * @return true on success, otherwise false. |
| 565 | */ |
| 566 | @Override |
| 567 | public boolean deleteAllFlows() { |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 568 | if (FlowDatabaseOperation.deleteAllFlows(dbHandler)) { |
| 569 | datagridService.notificationSendAllFlowsRemoved(); |
| 570 | return true; |
| 571 | } |
| 572 | return false; |
Pavlin Radoslavov | baea924 | 2013-05-08 00:20:09 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /** |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 576 | * Delete a previously added flow. |
| 577 | * |
| 578 | * @param flowId the Flow ID of the flow to delete. |
| 579 | * @return true on success, otherwise false. |
| 580 | */ |
| 581 | @Override |
| 582 | public boolean deleteFlow(FlowId flowId) { |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 583 | if (FlowDatabaseOperation.deleteFlow(dbHandler, flowId)) { |
| 584 | datagridService.notificationSendFlowRemoved(flowId); |
| 585 | return true; |
| 586 | } |
| 587 | return false; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | /** |
Pavlin Radoslavov | baea924 | 2013-05-08 00:20:09 +0000 | [diff] [blame] | 591 | * Clear the state for all previously added flows. |
| 592 | * |
| 593 | * @return true on success, otherwise false. |
| 594 | */ |
| 595 | @Override |
| 596 | public boolean clearAllFlows() { |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 597 | if (FlowDatabaseOperation.clearAllFlows(dbHandler)) { |
| 598 | datagridService.notificationSendAllFlowsRemoved(); |
| 599 | return true; |
| 600 | } |
| 601 | return false; |
Pavlin Radoslavov | baea924 | 2013-05-08 00:20:09 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /** |
Pavlin Radoslavov | 916832f | 2013-03-14 17:48:41 -0700 | [diff] [blame] | 605 | * Clear the state for a previously added flow. |
| 606 | * |
| 607 | * @param flowId the Flow ID of the flow to clear. |
| 608 | * @return true on success, otherwise false. |
| 609 | */ |
| 610 | @Override |
| 611 | public boolean clearFlow(FlowId flowId) { |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 612 | if (FlowDatabaseOperation.clearFlow(dbHandler, flowId)) { |
| 613 | datagridService.notificationSendFlowRemoved(flowId); |
| 614 | return true; |
| 615 | } |
| 616 | return false; |
Pavlin Radoslavov | 916832f | 2013-03-14 17:48:41 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | /** |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 620 | * Get a previously added flow. |
| 621 | * |
| 622 | * @param flowId the Flow ID of the flow to get. |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 623 | * @return the Flow Path if found, otherwise null. |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 624 | */ |
| 625 | @Override |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 626 | public FlowPath getFlow(FlowId flowId) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 627 | return FlowDatabaseOperation.getFlow(dbHandler, flowId); |
| 628 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 629 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 630 | /** |
| 631 | * Get all installed flows by all installers. |
| 632 | * |
| 633 | * @return the Flow Paths if found, otherwise null. |
| 634 | */ |
| 635 | @Override |
| 636 | public ArrayList<FlowPath> getAllFlows() { |
| 637 | return FlowDatabaseOperation.getAllFlows(dbHandler); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /** |
| 641 | * Get all previously added flows by a specific installer for a given |
| 642 | * data path endpoints. |
| 643 | * |
| 644 | * @param installerId the Caller ID of the installer of the flow to get. |
| 645 | * @param dataPathEndpoints the data path endpoints of the flow to get. |
| 646 | * @return the Flow Paths if found, otherwise null. |
| 647 | */ |
| 648 | @Override |
| 649 | public ArrayList<FlowPath> getAllFlows(CallerId installerId, |
| 650 | DataPathEndpoints dataPathEndpoints) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 651 | return FlowDatabaseOperation.getAllFlows(dbHandler, installerId, |
| 652 | dataPathEndpoints); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | /** |
| 656 | * Get all installed flows by all installers for given data path endpoints. |
| 657 | * |
| 658 | * @param dataPathEndpoints the data path endpoints of the flows to get. |
| 659 | * @return the Flow Paths if found, otherwise null. |
| 660 | */ |
| 661 | @Override |
| 662 | public ArrayList<FlowPath> getAllFlows(DataPathEndpoints dataPathEndpoints) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 663 | return FlowDatabaseOperation.getAllFlows(dbHandler, dataPathEndpoints); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | /** |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 667 | * 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] | 668 | * |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 669 | * @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] | 670 | * @param maxFlows the maximum number of flows to be returned. |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 671 | * @return the Flow Paths if found, otherwise null. |
| 672 | */ |
| 673 | @Override |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 674 | public ArrayList<IFlowPath> getAllFlowsSummary(FlowId flowId, |
| 675 | int maxFlows) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 676 | return FlowDatabaseOperation.getAllFlowsSummary(dbHandler, flowId, |
| 677 | maxFlows); |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | /** |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 681 | * Get all Flows information, without the associated Flow Entries. |
| 682 | * |
| 683 | * @return all Flows information, without the associated Flow Entries. |
| 684 | */ |
| 685 | public ArrayList<IFlowPath> getAllFlowsWithoutFlowEntries() { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 686 | return FlowDatabaseOperation.getAllFlowsWithoutFlowEntries(dbHandler); |
Pavlin Radoslavov | 99b1275 | 2013-04-04 17:28:06 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /** |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 690 | * Add and maintain a shortest-path flow. |
| 691 | * |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 692 | * NOTE: The Flow Path argument does NOT contain flow entries. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 693 | * |
| 694 | * @param flowPath the Flow Path with the endpoints and the match |
| 695 | * conditions to install. |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 696 | * @return the added shortest-path flow on success, otherwise null. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 697 | */ |
| 698 | @Override |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 699 | public FlowPath addAndMaintainShortestPathFlow(FlowPath flowPath) { |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 700 | // |
Pavlin Radoslavov | 8b4b059 | 2013-04-10 04:33:33 +0000 | [diff] [blame] | 701 | // Don't do the shortest path computation here. |
| 702 | // Instead, let the Flow reconciliation thread take care of it. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 703 | // |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 704 | |
Pavlin Radoslavov | 8b4b059 | 2013-04-10 04:33:33 +0000 | [diff] [blame] | 705 | // We need the DataPath to populate the Network MAP |
| 706 | DataPath dataPath = new DataPath(); |
| 707 | dataPath.setSrcPort(flowPath.dataPath().srcPort()); |
| 708 | dataPath.setDstPort(flowPath.dataPath().dstPort()); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 709 | |
| 710 | // |
| 711 | // Prepare the computed Flow Path |
| 712 | // |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 713 | FlowPath computedFlowPath = new FlowPath(); |
| 714 | computedFlowPath.setFlowId(new FlowId(flowPath.flowId().value())); |
| 715 | computedFlowPath.setInstallerId(new CallerId(flowPath.installerId().value())); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 716 | computedFlowPath.setFlowPathFlags(new FlowPathFlags(flowPath.flowPathFlags().flags())); |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 717 | computedFlowPath.setDataPath(dataPath); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 718 | computedFlowPath.setFlowEntryMatch(new FlowEntryMatch(flowPath.flowEntryMatch())); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 719 | computedFlowPath.setFlowEntryActions(new FlowEntryActions(flowPath.flowEntryActions())); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 720 | |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 721 | FlowId flowId = new FlowId(); |
Pavlin Radoslavov | 8b4b059 | 2013-04-10 04:33:33 +0000 | [diff] [blame] | 722 | String dataPathSummaryStr = dataPath.dataPathSummary(); |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 723 | if (! addFlow(computedFlowPath, flowId, dataPathSummaryStr)) |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 724 | return null; |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 725 | |
| 726 | // TODO: Mark the flow for maintenance purpose |
| 727 | |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 728 | return (computedFlowPath); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | /** |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 732 | * Reconcile a flow. |
| 733 | * |
| 734 | * @param flowObj the flow that needs to be reconciliated. |
| 735 | * @param newDataPath the new data path to use. |
| 736 | * @return true on success, otherwise false. |
| 737 | */ |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 738 | private boolean reconcileFlow(IFlowPath flowObj, DataPath newDataPath) { |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 739 | |
| 740 | // |
| 741 | // Set the incoming port matching and the outgoing port output |
| 742 | // actions for each flow entry. |
| 743 | // |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 744 | int idx = 0; |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 745 | for (FlowEntry flowEntry : newDataPath.flowEntries()) { |
| 746 | // Set the incoming port matching |
| 747 | FlowEntryMatch flowEntryMatch = new FlowEntryMatch(); |
| 748 | flowEntry.setFlowEntryMatch(flowEntryMatch); |
| 749 | flowEntryMatch.enableInPort(flowEntry.inPort()); |
| 750 | |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 751 | // |
| 752 | // Set the actions |
| 753 | // |
| 754 | FlowEntryActions flowEntryActions = flowEntry.flowEntryActions(); |
| 755 | // |
| 756 | // If the first Flow Entry, copy the Flow Path actions to it |
| 757 | // |
| 758 | if (idx == 0) { |
| 759 | String actionsStr = flowObj.getActions(); |
| 760 | if (actionsStr != null) { |
| 761 | FlowEntryActions flowActions = new FlowEntryActions(actionsStr); |
| 762 | for (FlowEntryAction action : flowActions.actions()) |
| 763 | flowEntryActions.addAction(action); |
| 764 | } |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 765 | } |
Pavlin Radoslavov | 282f4ff | 2013-07-18 11:21:37 -0700 | [diff] [blame] | 766 | idx++; |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 767 | // |
| 768 | // Add the outgoing port output action |
| 769 | // |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 770 | FlowEntryAction flowEntryAction = new FlowEntryAction(); |
| 771 | flowEntryAction.setActionOutput(flowEntry.outPort()); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 772 | flowEntryActions.addAction(flowEntryAction); |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | // |
| 776 | // Remove the old Flow Entries, and add the new Flow Entries |
| 777 | // |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 778 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 779 | for (IFlowEntry flowEntryObj : flowEntries) { |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 780 | flowEntryObj.setUserState("FE_USER_DELETE"); |
Pavlin Radoslavov | 6fb76d1 | 2013-04-09 22:52:25 -0700 | [diff] [blame] | 781 | flowEntryObj.setSwitchState("FE_SWITCH_NOT_UPDATED"); |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 782 | } |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 783 | for (FlowEntry flowEntry : newDataPath.flowEntries()) { |
Pavlin Radoslavov | 6fb76d1 | 2013-04-09 22:52:25 -0700 | [diff] [blame] | 784 | addFlowEntry(flowObj, flowEntry); |
Pavlin Radoslavov | 20d35a2 | 2013-04-05 10:16:15 -0700 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | // |
| 788 | // Set the Data Path Summary |
| 789 | // |
| 790 | String dataPathSummaryStr = newDataPath.dataPathSummary(); |
| 791 | flowObj.setDataPathSummary(dataPathSummaryStr); |
| 792 | |
| 793 | return true; |
| 794 | } |
| 795 | |
| 796 | /** |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 797 | * Reconcile all flows in a set. |
| 798 | * |
| 799 | * @param flowObjSet the set of flows that need to be reconciliated. |
| 800 | */ |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 801 | private void reconcileFlows(Iterable<IFlowPath> flowObjSet) { |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 802 | if (! flowObjSet.iterator().hasNext()) |
| 803 | return; |
Pavlin Radoslavov | 0eeb15d | 2013-04-05 10:23:51 -0700 | [diff] [blame] | 804 | // TODO: Not implemented/used yet. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | /** |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 808 | * Install a Flow Entry on a switch. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 809 | * |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 810 | * @param mySwitch the switch to install the Flow Entry into. |
Pavlin Radoslavov | ec8e2e6 | 2013-04-04 18:18:29 -0700 | [diff] [blame] | 811 | * @param flowObj the flow path object for the flow entry to install. |
| 812 | * @param flowEntryObj the flow entry object to install. |
| 813 | * @return true on success, otherwise false. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 814 | */ |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 815 | private boolean installFlowEntry(IOFSwitch mySwitch, IFlowPath flowObj, |
Pavlin Radoslavov | ec8e2e6 | 2013-04-04 18:18:29 -0700 | [diff] [blame] | 816 | IFlowEntry flowEntryObj) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 817 | return FlowSwitchOperation.installFlowEntry( |
| 818 | floodlightProvider.getOFMessageFactory(), |
| 819 | messageDamper, mySwitch, flowObj, flowEntryObj); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | /** |
| 823 | * Install a Flow Entry on a switch. |
| 824 | * |
| 825 | * @param mySwitch the switch to install the Flow Entry into. |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 826 | * @param flowPath the flow path for the flow entry to install. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 827 | * @param flowEntry the flow entry to install. |
| 828 | * @return true on success, otherwise false. |
| 829 | */ |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 830 | private boolean installFlowEntry(IOFSwitch mySwitch, FlowPath flowPath, |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 831 | FlowEntry flowEntry) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 832 | return FlowSwitchOperation.installFlowEntry( |
| 833 | floodlightProvider.getOFMessageFactory(), |
| 834 | messageDamper, mySwitch, flowPath, flowEntry); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /** |
| 838 | * Remove a Flow Entry from a switch. |
| 839 | * |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 840 | * @param mySwitch the switch to remove the Flow Entry from. |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 841 | * @param flowPath the flow path for the flow entry to remove. |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 842 | * @param flowEntry the flow entry to remove. |
| 843 | * @return true on success, otherwise false. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 844 | */ |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 845 | private boolean removeFlowEntry(IOFSwitch mySwitch, FlowPath flowPath, |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 846 | FlowEntry flowEntry) { |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 847 | // |
| 848 | // The installFlowEntry() method implements both installation |
| 849 | // and removal of flow entries. |
| 850 | // |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 851 | return (installFlowEntry(mySwitch, flowPath, flowEntry)); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 852 | } |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 853 | |
| 854 | /** |
| 855 | * Receive a notification that a Flow is added. |
| 856 | * |
| 857 | * @param flowPath the flow that is added. |
| 858 | */ |
| 859 | @Override |
| 860 | public void notificationRecvFlowAdded(FlowPath flowPath) { |
| 861 | // TODO |
| 862 | } |
| 863 | |
| 864 | /** |
| 865 | * Receive a notification that a Flow is removed. |
| 866 | * |
| 867 | * @param flowPath the flow that is removed. |
| 868 | */ |
| 869 | @Override |
| 870 | public void notificationRecvFlowRemoved(FlowPath flowPath) { |
| 871 | // TODO |
| 872 | } |
| 873 | |
| 874 | /** |
| 875 | * Receive a notification that a Flow is updated. |
| 876 | * |
| 877 | * @param flowPath the flow that is updated. |
| 878 | */ |
| 879 | @Override |
| 880 | public void notificationRecvFlowUpdated(FlowPath flowPath) { |
| 881 | // TODO |
| 882 | } |
Pavlin Radoslavov | aaace7f | 2013-10-25 19:42:00 -0700 | [diff] [blame] | 883 | |
| 884 | /** |
| 885 | * Receive a notification that a Topology Element is added. |
| 886 | * |
| 887 | * @param topologyElement the Topology Element that is added. |
| 888 | */ |
| 889 | @Override |
| 890 | public void notificationRecvTopologyElementAdded(TopologyElement topologyElement) { |
| 891 | // TODO |
| 892 | } |
| 893 | |
| 894 | /** |
| 895 | * Receive a notification that a Topology Element is removed. |
| 896 | * |
| 897 | * @param topologyElement the Topology Element that is removed. |
| 898 | */ |
| 899 | @Override |
| 900 | public void notificationRecvTopologyElementRemoved(TopologyElement topologyElement) { |
| 901 | // TODO |
| 902 | } |
| 903 | |
| 904 | /** |
| 905 | * Receive a notification that a Topology Element is updated. |
| 906 | * |
| 907 | * @param topologyElement the Topology Element that is updated. |
| 908 | */ |
| 909 | @Override |
| 910 | public void notificationRecvTopologyElementUpdated(TopologyElement topologyElement) { |
| 911 | // TODO |
| 912 | } |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 913 | } |