blob: 31a6bf42c1e5d2af83732d2a862672e953bd9ba0 [file] [log] [blame]
HIGUCHI Yuta60a10142013-06-14 15:50:10 -07001package net.onrc.onos.ofcontroller.flowmanager;
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -08002
3import java.util.ArrayList;
4import java.util.Collection;
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -08005import java.util.EnumSet;
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -08006import java.util.HashMap;
Masayoshi Kobayashic9da09e2013-03-26 20:52:02 +00007import java.util.LinkedList;
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -08008import java.util.Map;
Pavlin Radoslavov0b22d0e2013-04-02 01:12:46 +00009import java.util.Random;
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080010import java.util.concurrent.Executors;
11import java.util.concurrent.ScheduledExecutorService;
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080012import java.util.concurrent.TimeUnit;
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -080013
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080014import net.floodlightcontroller.core.IFloodlightProviderService;
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080015import net.floodlightcontroller.core.IOFSwitch;
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -080016import net.floodlightcontroller.core.module.FloodlightModuleContext;
17import net.floodlightcontroller.core.module.FloodlightModuleException;
18import net.floodlightcontroller.core.module.IFloodlightModule;
19import net.floodlightcontroller.core.module.IFloodlightService;
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -080020import net.floodlightcontroller.restserver.IRestApiService;
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080021import net.floodlightcontroller.util.OFMessageDamper;
Pavlin Radoslavov05378272013-10-19 23:23:05 -070022
23import net.onrc.onos.datagrid.IDatagridService;
Pankaj Berde38646d62013-06-21 11:34:04 -070024import net.onrc.onos.graph.GraphDBOperation;
HIGUCHI Yuta20514902013-06-12 11:24:16 -070025import net.onrc.onos.ofcontroller.core.INetMapStorage;
26import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
27import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
Pavlin Radoslavove9a3ef92013-10-18 18:46:45 -070028import net.onrc.onos.ofcontroller.floodlightlistener.INetworkGraphService;
HIGUCHI Yuta60a10142013-06-14 15:50:10 -070029import net.onrc.onos.ofcontroller.flowmanager.web.FlowWebRoutable;
Pavlin Radoslavov1278ac72013-10-16 04:43:49 -070030import net.onrc.onos.ofcontroller.topology.ITopologyNetService;
Pavlin Radoslavov15954d42013-10-19 15:29:04 -070031import net.onrc.onos.ofcontroller.topology.Topology;
Pavlin Radoslavovaaace7f2013-10-25 19:42:00 -070032import net.onrc.onos.ofcontroller.topology.TopologyElement;
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -070033import net.onrc.onos.ofcontroller.util.*;
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080034
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080035import org.openflow.protocol.OFType;
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -080036import org.slf4j.Logger;
37import org.slf4j.LoggerFactory;
38
admin944ef4f2013-10-08 17:48:37 -070039/**
HIGUCHI Yutaeb567aa2013-10-08 19:27:35 -070040 * Flow Manager class for handling the network flows.
admin944ef4f2013-10-08 17:48:37 -070041 */
Pavlin Radoslavov5adf1522013-04-04 17:43:41 -070042public class FlowManager implements IFloodlightModule, IFlowService, INetMapStorage {
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080043
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -070044 protected GraphDBOperation dbHandler;
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -080045
Jonathan Hart50a94982013-04-10 14:49:51 -070046 protected volatile IFloodlightProviderService floodlightProvider;
Pavlin Radoslavov1278ac72013-10-16 04:43:49 -070047 protected volatile ITopologyNetService topologyNetService;
Pavlin Radoslavov05378272013-10-19 23:23:05 -070048 protected volatile IDatagridService datagridService;
49 protected IRestApiService restApi;
Pavlin Radoslavov571cff92013-03-20 02:01:32 -070050 protected FloodlightModuleContext context;
Pavlin Radoslavov6b79f2b2013-10-26 21:31:10 -070051 protected PathComputation pathComputation;
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080052
53 protected OFMessageDamper messageDamper;
54
Pavlin Radoslavov78c4e492013-03-12 17:17:48 -070055 //
56 // TODO: Values copied from elsewhere (class LearningSwitch).
57 // The local copy should go away!
58 //
59 protected static final int OFMESSAGE_DAMPER_CAPACITY = 50000; // TODO: find sweet spot
60 protected static final int OFMESSAGE_DAMPER_TIMEOUT = 250; // ms
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -080061
Pavlin Radoslavov0b22d0e2013-04-02 01:12:46 +000062 // Flow Entry ID generation state
63 private static Random randomGenerator = new Random();
64 private static int nextFlowEntryIdPrefix = 0;
65 private static int nextFlowEntryIdSuffix = 0;
66 private static long nextFlowEntryId = 0;
67
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -080068 /** The logger. */
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070069 private final static Logger log = LoggerFactory.getLogger(FlowManager.class);
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080070
71 // The periodic task(s)
Jonathan Hart50a94982013-04-10 14:49:51 -070072 private ScheduledExecutorService mapReaderScheduler;
73 private ScheduledExecutorService shortestPathReconcileScheduler;
Pavlin Radoslavov6fb76d12013-04-09 22:52:25 -070074
admin944ef4f2013-10-08 17:48:37 -070075 /**
76 * Periodic task for reading the Flow Entries and pushing changes
77 * into the switches.
78 */
Pavlin Radoslavov571cff92013-03-20 02:01:32 -070079 final Runnable mapReader = new Runnable() {
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080080 public void run() {
Pavlin Radoslavova75caea2013-04-10 19:11:26 -070081 try {
82 runImpl();
83 } catch (Exception e) {
84 log.debug("Exception processing All Flow Entries from the Network MAP: ", e);
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -070085 dbHandler.rollback();
Pavlin Radoslavova75caea2013-04-10 19:11:26 -070086 return;
87 }
88 }
89
90 private void runImpl() {
Pavlin Radoslavov42f02ba2013-04-03 20:07:30 -070091 long startTime = System.nanoTime();
92 int counterAllFlowEntries = 0;
93 int counterMyNotUpdatedFlowEntries = 0;
Pavlin Radoslavov42f02ba2013-04-03 20:07:30 -070094
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080095 if (floodlightProvider == null) {
96 log.debug("FloodlightProvider service not found!");
97 return;
98 }
Masayoshi Kobayashic9da09e2013-03-26 20:52:02 +000099 Map<Long, IOFSwitch> mySwitches =
100 floodlightProvider.getSwitches();
Pankaj Berdebf51e4f2013-10-03 17:49:23 -0700101 if (mySwitches.isEmpty()) {
Pankaj Berde85a877b2013-10-03 18:26:35 -0700102 log.trace("No switches controlled");
Pankaj Berdebf51e4f2013-10-03 17:49:23 -0700103 return;
104 }
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700105 LinkedList<IFlowEntry> addFlowEntries =
106 new LinkedList<IFlowEntry>();
Masayoshi Kobayashic9da09e2013-03-26 20:52:02 +0000107 LinkedList<IFlowEntry> deleteFlowEntries =
108 new LinkedList<IFlowEntry>();
Pavlin Radoslavovdbaaf2e2013-03-29 04:25:55 -0700109
110 //
Pavlin Radoslavov50e532e2013-10-20 02:07:51 -0700111 // Fetch all Flow Entries which need to be updated and select
112 // only my Flow Entries that need to be updated into the
113 // switches.
Pavlin Radoslavov01391c92013-03-14 17:13:21 -0700114 //
Masayoshi Kobayashic9da09e2013-03-26 20:52:02 +0000115 Iterable<IFlowEntry> allFlowEntries =
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700116 dbHandler.getAllSwitchNotUpdatedFlowEntries();
Pavlin Radoslavov01391c92013-03-14 17:13:21 -0700117 for (IFlowEntry flowEntryObj : allFlowEntries) {
Pavlin Radoslavov42f02ba2013-04-03 20:07:30 -0700118 counterAllFlowEntries++;
Masayoshi Kobayashic9da09e2013-03-26 20:52:02 +0000119
Pavlin Radoslavov6db8c6e2013-04-08 00:14:07 +0000120 String dpidStr = flowEntryObj.getSwitchDpid();
121 if (dpidStr == null)
122 continue;
123 Dpid dpid = new Dpid(dpidStr);
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800124 IOFSwitch mySwitch = mySwitches.get(dpid.value());
Masayoshi Kobayashic9da09e2013-03-26 20:52:02 +0000125 if (mySwitch == null)
126 continue; // Ignore the entry: not my switch
127
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700128 IFlowPath flowObj =
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700129 dbHandler.getFlowPathByFlowEntry(flowEntryObj);
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700130 if (flowObj == null)
131 continue; // Should NOT happen
132 if (flowObj.getFlowId() == null)
133 continue; // Invalid entry
134
135 //
136 // NOTE: For now we process the DELETE before the ADD
137 // to cover the more common scenario.
138 // TODO: This is error prone and needs to be fixed!
139 //
Pavlin Radoslavov6db8c6e2013-04-08 00:14:07 +0000140 String userState = flowEntryObj.getUserState();
141 if (userState == null)
142 continue;
Pavlin Radoslavovec8e2e62013-04-04 18:18:29 -0700143 if (userState.equals("FE_USER_DELETE")) {
144 // An entry that needs to be deleted.
145 deleteFlowEntries.add(flowEntryObj);
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700146 installFlowEntry(mySwitch, flowObj, flowEntryObj);
147 } else {
148 addFlowEntries.add(flowEntryObj);
Pavlin Radoslavovec8e2e62013-04-04 18:18:29 -0700149 }
Pavlin Radoslavov42f02ba2013-04-03 20:07:30 -0700150 counterMyNotUpdatedFlowEntries++;
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700151 }
152
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700153 //
154 // Process the Flow Entries that need to be added
155 //
156 for (IFlowEntry flowEntryObj : addFlowEntries) {
157 IFlowPath flowObj =
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700158 dbHandler.getFlowPathByFlowEntry(flowEntryObj);
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700159 if (flowObj == null)
160 continue; // Should NOT happen
161 if (flowObj.getFlowId() == null)
162 continue; // Invalid entry
Pavlin Radoslavov01391c92013-03-14 17:13:21 -0700163
Pavlin Radoslavov01391c92013-03-14 17:13:21 -0700164 Dpid dpid = new Dpid(flowEntryObj.getSwitchDpid());
Pavlin Radoslavov01391c92013-03-14 17:13:21 -0700165 IOFSwitch mySwitch = mySwitches.get(dpid.value());
Masayoshi Kobayashic9da09e2013-03-26 20:52:02 +0000166 if (mySwitch == null)
167 continue; // Shouldn't happen
Pavlin Radoslavovec8e2e62013-04-04 18:18:29 -0700168 installFlowEntry(mySwitch, flowObj, flowEntryObj);
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800169 }
Masayoshi Kobayashic9da09e2013-03-26 20:52:02 +0000170
171 //
Pavlin Radoslavov710e2a72013-04-08 02:31:05 +0000172 // Delete all Flow Entries marked for deletion from the
Pavlin Radoslavov44a3dcd2013-04-04 18:42:56 -0700173 // Network MAP.
Masayoshi Kobayashic9da09e2013-03-26 20:52:02 +0000174 //
175 // TODO: We should use the OpenFlow Barrier mechanism
176 // to check for errors, and delete the Flow Entries after the
177 // Barrier message is received.
178 //
179 while (! deleteFlowEntries.isEmpty()) {
180 IFlowEntry flowEntryObj = deleteFlowEntries.poll();
181 IFlowPath flowObj =
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700182 dbHandler.getFlowPathByFlowEntry(flowEntryObj);
Masayoshi Kobayashic9da09e2013-03-26 20:52:02 +0000183 if (flowObj == null) {
184 log.debug("Did not find FlowPath to be deleted");
185 continue;
186 }
187 flowObj.removeFlowEntry(flowEntryObj);
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700188 dbHandler.removeFlowEntry(flowEntryObj);
Masayoshi Kobayashic9da09e2013-03-26 20:52:02 +0000189 }
Pavlin Radoslavov0391b9d2013-03-29 11:54:25 -0700190
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700191 dbHandler.commit();
Pavlin Radoslavov6fb76d12013-04-09 22:52:25 -0700192
Pavlin Radoslavov6fb76d12013-04-09 22:52:25 -0700193 long estimatedTime = System.nanoTime() - startTime;
194 double rate = 0.0;
195 if (estimatedTime > 0)
196 rate = ((double)counterAllFlowEntries * 1000000000) / estimatedTime;
197 String logMsg = "MEASUREMENT: Processed AllFlowEntries: " +
198 counterAllFlowEntries + " MyNotUpdatedFlowEntries: " +
199 counterMyNotUpdatedFlowEntries + " in " +
200 (double)estimatedTime / 1000000000 + " sec: " +
201 rate + " paths/s";
202 log.debug(logMsg);
203 }
204 };
205
admin944ef4f2013-10-08 17:48:37 -0700206 /**
207 * Periodic task for reading the Flow Paths and recomputing the
208 * shortest paths.
209 */
Pavlin Radoslavov6fb76d12013-04-09 22:52:25 -0700210 final Runnable shortestPathReconcile = new Runnable() {
211 public void run() {
Pavlin Radoslavova75caea2013-04-10 19:11:26 -0700212 try {
213 runImpl();
214 } catch (Exception e) {
215 log.debug("Exception processing All Flows from the Network MAP: ", e);
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700216 dbHandler.rollback();
Pavlin Radoslavova75caea2013-04-10 19:11:26 -0700217 return;
218 }
219 }
220
221 private void runImpl() {
Pavlin Radoslavov6fb76d12013-04-09 22:52:25 -0700222 long startTime = System.nanoTime();
223 int counterAllFlowPaths = 0;
224 int counterMyFlowPaths = 0;
225
226 if (floodlightProvider == null) {
227 log.debug("FloodlightProvider service not found!");
228 return;
229 }
230 Map<Long, IOFSwitch> mySwitches =
231 floodlightProvider.getSwitches();
Pankaj Berdebf51e4f2013-10-03 17:49:23 -0700232 if (mySwitches.isEmpty()) {
Pankaj Berde85a877b2013-10-03 18:26:35 -0700233 log.trace("No switches controlled");
Pankaj Berdebf51e4f2013-10-03 17:49:23 -0700234 return;
235 }
Pavlin Radoslavov6fb76d12013-04-09 22:52:25 -0700236 LinkedList<IFlowPath> deleteFlows = new LinkedList<IFlowPath>();
237
Pavlin Radoslavov0391b9d2013-03-29 11:54:25 -0700238 //
239 // Fetch and recompute the Shortest Path for those
240 // Flow Paths this controller is responsible for.
241 //
Pavlin Radoslavov15954d42013-10-19 15:29:04 -0700242 Topology topology = topologyNetService.newDatabaseTopology();
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700243 Iterable<IFlowPath> allFlowPaths = dbHandler.getAllFlowPaths();
Pavlin Radoslavov0391b9d2013-03-29 11:54:25 -0700244 for (IFlowPath flowPathObj : allFlowPaths) {
Pavlin Radoslavov42f02ba2013-04-03 20:07:30 -0700245 counterAllFlowPaths++;
Pavlin Radoslavov0391b9d2013-03-29 11:54:25 -0700246 if (flowPathObj == null)
247 continue;
Pavlin Radoslavov0391b9d2013-03-29 11:54:25 -0700248
Pavlin Radoslavov0391b9d2013-03-29 11:54:25 -0700249 String srcDpidStr = flowPathObj.getSrcSwitch();
Pavlin Radoslavov6db8c6e2013-04-08 00:14:07 +0000250 if (srcDpidStr == null)
Pavlin Radoslavov0391b9d2013-03-29 11:54:25 -0700251 continue;
Pavlin Radoslavov0391b9d2013-03-29 11:54:25 -0700252 Dpid srcDpid = new Dpid(srcDpidStr);
Pavlin Radoslavov2659a0b2013-04-03 20:30:40 -0700253 //
254 // Use the source DPID as a heuristic to decide
255 // which controller is responsible for maintaining the
256 // shortest path.
257 // NOTE: This heuristic is error-prone: if the switch
258 // goes away and no controller is responsible for that
259 // switch, then the original Flow Path is not cleaned-up
260 //
261 IOFSwitch mySwitch = mySwitches.get(srcDpid.value());
262 if (mySwitch == null)
263 continue; // Ignore: not my responsibility
264
Pavlin Radoslavovbcc86ef2013-10-26 12:06:25 -0700265 // Test whether we need to maintain this flow
266 String flowPathTypeStr = flowPathObj.getFlowPathType();
267 if (flowPathTypeStr == null)
Pavlin Radoslavov99d1b152013-04-09 22:57:33 -0700268 continue; // Could be invalid entry?
Pavlin Radoslavovbcc86ef2013-10-26 12:06:25 -0700269 if (! flowPathTypeStr.equals("FP_TYPE_SHORTEST_PATH"))
Pavlin Radoslavov99d1b152013-04-09 22:57:33 -0700270 continue; // No need to maintain this flow
271
Pavlin Radoslavov710e2a72013-04-08 02:31:05 +0000272 //
273 // Test whether we need to complete the Flow cleanup,
274 // if the Flow has been deleted by the user.
275 //
276 String flowUserState = flowPathObj.getUserState();
277 if ((flowUserState != null)
278 && flowUserState.equals("FE_USER_DELETE")) {
279 Iterable<IFlowEntry> flowEntries = flowPathObj.getFlowEntries();
Yuta HIGUCHI2ded2dd2013-10-09 18:06:41 -0700280 final boolean empty = !flowEntries.iterator().hasNext();
Pavlin Radoslavov710e2a72013-04-08 02:31:05 +0000281 if (empty)
282 deleteFlows.add(flowPathObj);
283 }
284
Pavlin Radoslavov6db8c6e2013-04-08 00:14:07 +0000285 // Fetch the fields needed to recompute the shortest path
Pavlin Radoslavovbcc86ef2013-10-26 12:06:25 -0700286 String dataPathSummaryStr = flowPathObj.getDataPathSummary();
Pavlin Radoslavov6db8c6e2013-04-08 00:14:07 +0000287 Short srcPortShort = flowPathObj.getSrcPort();
288 String dstDpidStr = flowPathObj.getDstSwitch();
289 Short dstPortShort = flowPathObj.getDstPort();
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700290 Long flowPathFlagsLong = flowPathObj.getFlowPathFlags();
Pavlin Radoslavovbcc86ef2013-10-26 12:06:25 -0700291 if ((dataPathSummaryStr == null) ||
292 (srcPortShort == null) ||
Pavlin Radoslavov6db8c6e2013-04-08 00:14:07 +0000293 (dstDpidStr == null) ||
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700294 (dstPortShort == null) ||
295 (flowPathFlagsLong == null)) {
Pavlin Radoslavov6db8c6e2013-04-08 00:14:07 +0000296 continue;
297 }
298
299 Port srcPort = new Port(srcPortShort);
300 Dpid dstDpid = new Dpid(dstDpidStr);
301 Port dstPort = new Port(dstPortShort);
302 SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort);
303 SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort);
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700304 FlowPathType flowPathType = FlowPathType.valueOf(flowPathTypeStr);
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700305 FlowPathFlags flowPathFlags = new FlowPathFlags(flowPathFlagsLong);
Pavlin Radoslavov6db8c6e2013-04-08 00:14:07 +0000306
Pavlin Radoslavov2659a0b2013-04-03 20:30:40 -0700307 counterMyFlowPaths++;
308
Pavlin Radoslavov832aa652013-03-29 16:21:59 -0700309 //
Pavlin Radoslavov15954d42013-10-19 15:29:04 -0700310 // NOTE: Using here the regular getDatabaseShortestPath()
311 // method won't work here, because that method calls
312 // internally "conn.endTx(Transaction.COMMIT)", and that
313 // will invalidate all handlers to the Titan database.
Pavlin Radoslavov832aa652013-03-29 16:21:59 -0700314 // If we want to experiment with calling here
Pavlin Radoslavov15954d42013-10-19 15:29:04 -0700315 // getDatabaseShortestPath(), we need to refactor that code
Pavlin Radoslavov832aa652013-03-29 16:21:59 -0700316 // to avoid closing the transaction.
317 //
Pavlin Radoslavov0391b9d2013-03-29 11:54:25 -0700318 DataPath dataPath =
Pavlin Radoslavov15954d42013-10-19 15:29:04 -0700319 topologyNetService.getTopologyShortestPath(
320 topology,
321 srcSwitchPort,
322 dstSwitchPort);
Pavlin Radoslavov4a325822013-04-02 22:16:59 +0000323 if (dataPath == null) {
324 // We need the DataPath to compare the paths
325 dataPath = new DataPath();
326 dataPath.setSrcPort(srcSwitchPort);
327 dataPath.setDstPort(dstSwitchPort);
328 }
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700329 dataPath.applyFlowPathFlags(flowPathFlags);
Pavlin Radoslavov4a325822013-04-02 22:16:59 +0000330
Pavlin Radoslavov0391b9d2013-03-29 11:54:25 -0700331 String newDataPathSummaryStr = dataPath.dataPathSummary();
332 if (dataPathSummaryStr.equals(newDataPathSummaryStr))
333 continue; // Nothing changed
334
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700335 reconcileFlow(flowPathObj, dataPath);
Pavlin Radoslavov0391b9d2013-03-29 11:54:25 -0700336 }
Pavlin Radoslavov710e2a72013-04-08 02:31:05 +0000337
338 //
339 // Delete all leftover Flows marked for deletion from the
340 // Network MAP.
341 //
342 while (! deleteFlows.isEmpty()) {
343 IFlowPath flowPathObj = deleteFlows.poll();
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700344 dbHandler.removeFlowPath(flowPathObj);
Pavlin Radoslavov710e2a72013-04-08 02:31:05 +0000345 }
346
Pavlin Radoslavov15954d42013-10-19 15:29:04 -0700347 topologyNetService.dropTopology(topology);
Pavlin Radoslavov0391b9d2013-03-29 11:54:25 -0700348
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700349 dbHandler.commit();
Pavlin Radoslavov571cff92013-03-20 02:01:32 -0700350
Pavlin Radoslavov42f02ba2013-04-03 20:07:30 -0700351 long estimatedTime = System.nanoTime() - startTime;
Pavlin Radoslavov1552f952013-04-04 17:51:22 -0700352 double rate = 0.0;
353 if (estimatedTime > 0)
354 rate = ((double)counterAllFlowPaths * 1000000000) / estimatedTime;
Pavlin Radoslavov6fb76d12013-04-09 22:52:25 -0700355 String logMsg = "MEASUREMENT: Processed AllFlowPaths: " +
Pavlin Radoslavov1552f952013-04-04 17:51:22 -0700356 counterAllFlowPaths + " MyFlowPaths: " +
357 counterMyFlowPaths + " in " +
358 (double)estimatedTime / 1000000000 + " sec: " +
359 rate + " paths/s";
Pavlin Radoslavov42f02ba2013-04-03 20:07:30 -0700360 log.debug(logMsg);
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800361 }
362 };
Pavlin Radoslavov571cff92013-03-20 02:01:32 -0700363
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800364
admin944ef4f2013-10-08 17:48:37 -0700365 /**
366 * Initialize the Flow Manager.
367 *
368 * @param conf the Graph Database configuration string.
369 */
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800370 @Override
371 public void init(String conf) {
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700372 dbHandler = new GraphDBOperation(conf);
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800373 }
374
admin944ef4f2013-10-08 17:48:37 -0700375 /**
376 * Shutdown the Flow Manager operation.
377 */
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800378 public void finalize() {
Toshio Koide9fe1cb22013-06-13 13:51:11 -0700379 close();
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800380 }
381
admin944ef4f2013-10-08 17:48:37 -0700382 /**
383 * Shutdown the Flow Manager operation.
384 */
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800385 @Override
386 public void close() {
Pavlin Radoslavov6b79f2b2013-10-26 21:31:10 -0700387 datagridService.deregisterPathComputationService(pathComputation);
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700388 dbHandler.close();
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800389 }
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800390
admin944ef4f2013-10-08 17:48:37 -0700391 /**
392 * Get the collection of offered module services.
393 *
394 * @return the collection of offered module services.
395 */
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800396 @Override
397 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
398 Collection<Class<? extends IFloodlightService>> l =
399 new ArrayList<Class<? extends IFloodlightService>>();
400 l.add(IFlowService.class);
401 return l;
402 }
403
admin944ef4f2013-10-08 17:48:37 -0700404 /**
405 * Get the collection of implemented services.
406 *
407 * @return the collection of implemented services.
408 */
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800409 @Override
410 public Map<Class<? extends IFloodlightService>, IFloodlightService>
411 getServiceImpls() {
412 Map<Class<? extends IFloodlightService>,
Pavlin Radoslavove9a3ef92013-10-18 18:46:45 -0700413 IFloodlightService> m =
414 new HashMap<Class<? extends IFloodlightService>,
415 IFloodlightService>();
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800416 m.put(IFlowService.class, this);
417 return m;
418 }
419
admin944ef4f2013-10-08 17:48:37 -0700420 /**
421 * Get the collection of modules this module depends on.
422 *
423 * @return the collection of modules this module depends on.
424 */
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800425 @Override
426 public Collection<Class<? extends IFloodlightService>>
Pavlin Radoslavov50e532e2013-10-20 02:07:51 -0700427 getModuleDependencies() {
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800428 Collection<Class<? extends IFloodlightService>> l =
429 new ArrayList<Class<? extends IFloodlightService>>();
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800430 l.add(IFloodlightProviderService.class);
Pavlin Radoslavove9a3ef92013-10-18 18:46:45 -0700431 l.add(INetworkGraphService.class);
Pavlin Radoslavov05378272013-10-19 23:23:05 -0700432 l.add(IDatagridService.class);
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800433 l.add(IRestApiService.class);
434 return l;
435 }
436
admin944ef4f2013-10-08 17:48:37 -0700437 /**
438 * Initialize the module.
439 *
440 * @param context the module context to use for the initialization.
441 */
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800442 @Override
443 public void init(FloodlightModuleContext context)
444 throws FloodlightModuleException {
Pavlin Radoslavov571cff92013-03-20 02:01:32 -0700445 this.context = context;
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800446 floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
Pavlin Radoslavov05378272013-10-19 23:23:05 -0700447 topologyNetService = context.getServiceImpl(ITopologyNetService.class);
448 datagridService = context.getServiceImpl(IDatagridService.class);
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800449 restApi = context.getServiceImpl(IRestApiService.class);
Pavlin Radoslavov05378272013-10-19 23:23:05 -0700450
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800451 messageDamper = new OFMessageDamper(OFMESSAGE_DAMPER_CAPACITY,
452 EnumSet.of(OFType.FLOW_MOD),
453 OFMESSAGE_DAMPER_TIMEOUT);
Pavlin Radoslavovddd01ba2013-07-03 15:40:44 -0700454
Pavlin Radoslavov50e532e2013-10-20 02:07:51 -0700455 this.init("");
456
admin944ef4f2013-10-08 17:48:37 -0700457 mapReaderScheduler = Executors.newScheduledThreadPool(1);
458 shortestPathReconcileScheduler = Executors.newScheduledThreadPool(1);
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800459 }
460
admin944ef4f2013-10-08 17:48:37 -0700461 /**
462 * Get the next Flow Entry ID to use.
463 *
464 * @return the next Flow Entry ID to use.
465 */
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700466 public synchronized long getNextFlowEntryId() {
Pavlin Radoslavov0b22d0e2013-04-02 01:12:46 +0000467 //
468 // Generate the next Flow Entry ID.
469 // NOTE: For now, the higher 32 bits are random, and
470 // the lower 32 bits are sequential.
471 // In the future, we need a better allocation mechanism.
472 //
473 if ((nextFlowEntryIdSuffix & 0xffffffffL) == 0xffffffffL) {
474 nextFlowEntryIdPrefix = randomGenerator.nextInt();
475 nextFlowEntryIdSuffix = 0;
476 } else {
477 nextFlowEntryIdSuffix++;
478 }
479 long result = (long)nextFlowEntryIdPrefix << 32;
480 result = result | (0xffffffffL & nextFlowEntryIdSuffix);
481 return result;
482 }
483
admin944ef4f2013-10-08 17:48:37 -0700484 /**
485 * Startup module operation.
486 *
487 * @param context the module context to use for the startup.
488 */
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800489 @Override
490 public void startUp(FloodlightModuleContext context) {
admin944ef4f2013-10-08 17:48:37 -0700491 restApi.addRestletRoutable(new FlowWebRoutable());
Pavlin Radoslavov50e532e2013-10-20 02:07:51 -0700492
admin944ef4f2013-10-08 17:48:37 -0700493 // Initialize the Flow Entry ID generator
494 nextFlowEntryIdPrefix = randomGenerator.nextInt();
Pavlin Radoslavov50e532e2013-10-20 02:07:51 -0700495
Pavlin Radoslavov6b79f2b2013-10-26 21:31:10 -0700496 //
497 // Create the Path Computation thread and register it with the
498 // Datagrid Service
499 //
500 pathComputation = new PathComputation(this, datagridService);
501 datagridService.registerPathComputationService(pathComputation);
Pavlin Radoslavovaaace7f2013-10-25 19:42:00 -0700502
Pavlin Radoslavov6b79f2b2013-10-26 21:31:10 -0700503 // Schedule the threads and periodic tasks
504 pathComputation.start();
admin944ef4f2013-10-08 17:48:37 -0700505 mapReaderScheduler.scheduleAtFixedRate(
506 mapReader, 3, 3, TimeUnit.SECONDS);
507 shortestPathReconcileScheduler.scheduleAtFixedRate(
508 shortestPathReconcile, 3, 3, TimeUnit.SECONDS);
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800509 }
510
511 /**
512 * Add a flow.
513 *
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800514 * @param flowPath the Flow Path to install.
515 * @param flowId the return-by-reference Flow ID as assigned internally.
516 * @return true on success, otherwise false.
517 */
518 @Override
Pavlin Radoslavovbcc86ef2013-10-26 12:06:25 -0700519 public boolean addFlow(FlowPath flowPath, FlowId flowId) {
520 if (FlowDatabaseOperation.addFlow(this, dbHandler, flowPath, flowId)) {
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -0700521 datagridService.notificationSendFlowAdded(flowPath);
522 return true;
523 }
524 return false;
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800525 }
526
527 /**
Pavlin Radoslavov9425f702013-04-04 19:55:07 -0700528 * Add a flow entry to the Network MAP.
529 *
530 * @param flowObj the corresponding Flow Path object for the Flow Entry.
531 * @param flowEntry the Flow Entry to install.
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700532 * @return the added Flow Entry object on success, otherwise null.
Pavlin Radoslavov9425f702013-04-04 19:55:07 -0700533 */
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700534 private IFlowEntry addFlowEntry(IFlowPath flowObj, FlowEntry flowEntry) {
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700535 return FlowDatabaseOperation.addFlowEntry(this, dbHandler, flowObj,
536 flowEntry);
Pavlin Radoslavov9425f702013-04-04 19:55:07 -0700537 }
538
539 /**
Pavlin Radoslavovbaea9242013-05-08 00:20:09 +0000540 * Delete all previously added flows.
541 *
542 * @return true on success, otherwise false.
543 */
544 @Override
545 public boolean deleteAllFlows() {
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -0700546 if (FlowDatabaseOperation.deleteAllFlows(dbHandler)) {
547 datagridService.notificationSendAllFlowsRemoved();
548 return true;
549 }
550 return false;
Pavlin Radoslavovbaea9242013-05-08 00:20:09 +0000551 }
552
553 /**
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800554 * Delete a previously added flow.
555 *
556 * @param flowId the Flow ID of the flow to delete.
557 * @return true on success, otherwise false.
558 */
559 @Override
560 public boolean deleteFlow(FlowId flowId) {
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -0700561 if (FlowDatabaseOperation.deleteFlow(dbHandler, flowId)) {
562 datagridService.notificationSendFlowRemoved(flowId);
563 return true;
564 }
565 return false;
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800566 }
567
568 /**
Pavlin Radoslavovbaea9242013-05-08 00:20:09 +0000569 * Clear the state for all previously added flows.
570 *
571 * @return true on success, otherwise false.
572 */
573 @Override
574 public boolean clearAllFlows() {
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -0700575 if (FlowDatabaseOperation.clearAllFlows(dbHandler)) {
576 datagridService.notificationSendAllFlowsRemoved();
577 return true;
578 }
579 return false;
Pavlin Radoslavovbaea9242013-05-08 00:20:09 +0000580 }
581
582 /**
Pavlin Radoslavov916832f2013-03-14 17:48:41 -0700583 * Clear the state for a previously added flow.
584 *
585 * @param flowId the Flow ID of the flow to clear.
586 * @return true on success, otherwise false.
587 */
588 @Override
589 public boolean clearFlow(FlowId flowId) {
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -0700590 if (FlowDatabaseOperation.clearFlow(dbHandler, flowId)) {
591 datagridService.notificationSendFlowRemoved(flowId);
592 return true;
593 }
594 return false;
Pavlin Radoslavov916832f2013-03-14 17:48:41 -0700595 }
596
597 /**
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800598 * Get a previously added flow.
599 *
600 * @param flowId the Flow ID of the flow to get.
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800601 * @return the Flow Path if found, otherwise null.
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800602 */
603 @Override
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800604 public FlowPath getFlow(FlowId flowId) {
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700605 return FlowDatabaseOperation.getFlow(dbHandler, flowId);
606 }
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -0800607
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700608 /**
609 * Get all installed flows by all installers.
610 *
611 * @return the Flow Paths if found, otherwise null.
612 */
613 @Override
614 public ArrayList<FlowPath> getAllFlows() {
615 return FlowDatabaseOperation.getAllFlows(dbHandler);
Pavlin Radoslavov706df052013-03-06 10:49:07 -0800616 }
617
618 /**
619 * Get all previously added flows by a specific installer for a given
620 * data path endpoints.
621 *
622 * @param installerId the Caller ID of the installer of the flow to get.
623 * @param dataPathEndpoints the data path endpoints of the flow to get.
624 * @return the Flow Paths if found, otherwise null.
625 */
626 @Override
627 public ArrayList<FlowPath> getAllFlows(CallerId installerId,
628 DataPathEndpoints dataPathEndpoints) {
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700629 return FlowDatabaseOperation.getAllFlows(dbHandler, installerId,
630 dataPathEndpoints);
Pavlin Radoslavov706df052013-03-06 10:49:07 -0800631 }
632
633 /**
634 * Get all installed flows by all installers for given data path endpoints.
635 *
636 * @param dataPathEndpoints the data path endpoints of the flows to get.
637 * @return the Flow Paths if found, otherwise null.
638 */
639 @Override
640 public ArrayList<FlowPath> getAllFlows(DataPathEndpoints dataPathEndpoints) {
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700641 return FlowDatabaseOperation.getAllFlows(dbHandler, dataPathEndpoints);
Pavlin Radoslavov706df052013-03-06 10:49:07 -0800642 }
643
644 /**
admin944ef4f2013-10-08 17:48:37 -0700645 * Get summary of all installed flows by all installers in a given range.
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700646 *
admin944ef4f2013-10-08 17:48:37 -0700647 * @param flowId the Flow ID of the first flow in the flow range to get.
HIGUCHI Yutaeb567aa2013-10-08 19:27:35 -0700648 * @param maxFlows the maximum number of flows to be returned.
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700649 * @return the Flow Paths if found, otherwise null.
650 */
651 @Override
Pavlin Radoslavov50e532e2013-10-20 02:07:51 -0700652 public ArrayList<IFlowPath> getAllFlowsSummary(FlowId flowId,
653 int maxFlows) {
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700654 return FlowDatabaseOperation.getAllFlowsSummary(dbHandler, flowId,
655 maxFlows);
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700656 }
657
658 /**
admin944ef4f2013-10-08 17:48:37 -0700659 * Get all Flows information, without the associated Flow Entries.
660 *
661 * @return all Flows information, without the associated Flow Entries.
662 */
663 public ArrayList<IFlowPath> getAllFlowsWithoutFlowEntries() {
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700664 return FlowDatabaseOperation.getAllFlowsWithoutFlowEntries(dbHandler);
Pavlin Radoslavov99b12752013-04-04 17:28:06 -0700665 }
666
667 /**
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700668 * Add and maintain a shortest-path flow.
669 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700670 * NOTE: The Flow Path argument does NOT contain flow entries.
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700671 *
672 * @param flowPath the Flow Path with the endpoints and the match
673 * conditions to install.
Pavlin Radoslavove0575292013-03-28 05:35:25 -0700674 * @return the added shortest-path flow on success, otherwise null.
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700675 */
676 @Override
Pavlin Radoslavove0575292013-03-28 05:35:25 -0700677 public FlowPath addAndMaintainShortestPathFlow(FlowPath flowPath) {
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700678 //
Pavlin Radoslavov8b4b0592013-04-10 04:33:33 +0000679 // Don't do the shortest path computation here.
680 // Instead, let the Flow reconciliation thread take care of it.
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700681 //
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700682
Pavlin Radoslavove0575292013-03-28 05:35:25 -0700683 FlowId flowId = new FlowId();
Pavlin Radoslavovbcc86ef2013-10-26 12:06:25 -0700684 if (! addFlow(flowPath, flowId))
Pavlin Radoslavove0575292013-03-28 05:35:25 -0700685 return null;
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700686
Pavlin Radoslavovbcc86ef2013-10-26 12:06:25 -0700687 return (flowPath);
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700688 }
689
690 /**
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700691 * Reconcile a flow.
692 *
693 * @param flowObj the flow that needs to be reconciliated.
694 * @param newDataPath the new data path to use.
695 * @return true on success, otherwise false.
696 */
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -0700697 private boolean reconcileFlow(IFlowPath flowObj, DataPath newDataPath) {
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700698
699 //
700 // Set the incoming port matching and the outgoing port output
701 // actions for each flow entry.
702 //
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700703 int idx = 0;
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700704 for (FlowEntry flowEntry : newDataPath.flowEntries()) {
705 // Set the incoming port matching
706 FlowEntryMatch flowEntryMatch = new FlowEntryMatch();
707 flowEntry.setFlowEntryMatch(flowEntryMatch);
708 flowEntryMatch.enableInPort(flowEntry.inPort());
709
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700710 //
711 // Set the actions
712 //
713 FlowEntryActions flowEntryActions = flowEntry.flowEntryActions();
714 //
715 // If the first Flow Entry, copy the Flow Path actions to it
716 //
717 if (idx == 0) {
718 String actionsStr = flowObj.getActions();
719 if (actionsStr != null) {
720 FlowEntryActions flowActions = new FlowEntryActions(actionsStr);
721 for (FlowEntryAction action : flowActions.actions())
722 flowEntryActions.addAction(action);
723 }
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700724 }
Pavlin Radoslavov282f4ff2013-07-18 11:21:37 -0700725 idx++;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700726 //
727 // Add the outgoing port output action
728 //
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700729 FlowEntryAction flowEntryAction = new FlowEntryAction();
730 flowEntryAction.setActionOutput(flowEntry.outPort());
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700731 flowEntryActions.addAction(flowEntryAction);
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700732 }
733
734 //
735 // Remove the old Flow Entries, and add the new Flow Entries
736 //
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700737 Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700738 for (IFlowEntry flowEntryObj : flowEntries) {
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700739 flowEntryObj.setUserState("FE_USER_DELETE");
Pavlin Radoslavov6fb76d12013-04-09 22:52:25 -0700740 flowEntryObj.setSwitchState("FE_SWITCH_NOT_UPDATED");
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700741 }
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700742 for (FlowEntry flowEntry : newDataPath.flowEntries()) {
Pavlin Radoslavov6fb76d12013-04-09 22:52:25 -0700743 addFlowEntry(flowObj, flowEntry);
Pavlin Radoslavov20d35a22013-04-05 10:16:15 -0700744 }
745
746 //
747 // Set the Data Path Summary
748 //
749 String dataPathSummaryStr = newDataPath.dataPathSummary();
750 flowObj.setDataPathSummary(dataPathSummaryStr);
751
752 return true;
753 }
754
755 /**
Pavlin Radoslavovdbaaf2e2013-03-29 04:25:55 -0700756 * Reconcile all flows in a set.
757 *
758 * @param flowObjSet the set of flows that need to be reconciliated.
759 */
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -0700760 private void reconcileFlows(Iterable<IFlowPath> flowObjSet) {
Pavlin Radoslavovdbaaf2e2013-03-29 04:25:55 -0700761 if (! flowObjSet.iterator().hasNext())
762 return;
Pavlin Radoslavov0eeb15d2013-04-05 10:23:51 -0700763 // TODO: Not implemented/used yet.
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700764 }
765
766 /**
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700767 * Install a Flow Entry on a switch.
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700768 *
Pavlin Radoslavov2b858f82013-03-28 11:37:37 -0700769 * @param mySwitch the switch to install the Flow Entry into.
Pavlin Radoslavovec8e2e62013-04-04 18:18:29 -0700770 * @param flowObj the flow path object for the flow entry to install.
771 * @param flowEntryObj the flow entry object to install.
772 * @return true on success, otherwise false.
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700773 */
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -0700774 private boolean installFlowEntry(IOFSwitch mySwitch, IFlowPath flowObj,
Pavlin Radoslavovec8e2e62013-04-04 18:18:29 -0700775 IFlowEntry flowEntryObj) {
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700776 return FlowSwitchOperation.installFlowEntry(
777 floodlightProvider.getOFMessageFactory(),
778 messageDamper, mySwitch, flowObj, flowEntryObj);
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700779 }
780
781 /**
782 * Install a Flow Entry on a switch.
783 *
784 * @param mySwitch the switch to install the Flow Entry into.
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700785 * @param flowPath the flow path for the flow entry to install.
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700786 * @param flowEntry the flow entry to install.
787 * @return true on success, otherwise false.
788 */
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -0700789 private boolean installFlowEntry(IOFSwitch mySwitch, FlowPath flowPath,
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700790 FlowEntry flowEntry) {
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -0700791 return FlowSwitchOperation.installFlowEntry(
792 floodlightProvider.getOFMessageFactory(),
793 messageDamper, mySwitch, flowPath, flowEntry);
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700794 }
795
796 /**
797 * Remove a Flow Entry from a switch.
798 *
Pavlin Radoslavov2b858f82013-03-28 11:37:37 -0700799 * @param mySwitch the switch to remove the Flow Entry from.
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700800 * @param flowPath the flow path for the flow entry to remove.
Pavlin Radoslavov6b6f4a82013-03-28 03:30:00 -0700801 * @param flowEntry the flow entry to remove.
802 * @return true on success, otherwise false.
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700803 */
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -0700804 private boolean removeFlowEntry(IOFSwitch mySwitch, FlowPath flowPath,
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700805 FlowEntry flowEntry) {
Pavlin Radoslavov6b6f4a82013-03-28 03:30:00 -0700806 //
807 // The installFlowEntry() method implements both installation
808 // and removal of flow entries.
809 //
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700810 return (installFlowEntry(mySwitch, flowPath, flowEntry));
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700811 }
Pavlin Radoslavov9e5344c2013-02-18 09:58:30 -0800812}