Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.flowcache; |
| 2 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 3 | import java.io.IOException; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 4 | import java.util.ArrayList; |
| 5 | import java.util.Collection; |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 6 | import java.util.Collections; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 7 | import java.util.EnumSet; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 8 | import java.util.HashMap; |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 9 | import java.util.HashSet; |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 10 | import java.util.LinkedList; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 11 | import java.util.List; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 12 | import java.util.Map; |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 13 | import java.util.Random; |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 14 | import java.util.TreeMap; |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 15 | import java.util.concurrent.BlockingQueue; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 16 | import java.util.concurrent.Executors; |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 17 | import java.util.concurrent.LinkedBlockingQueue; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 18 | import java.util.concurrent.ScheduledExecutorService; |
| 19 | import java.util.concurrent.ScheduledFuture; |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 20 | import java.util.concurrent.ThreadPoolExecutor; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 21 | import java.util.concurrent.TimeUnit; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 22 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 23 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 24 | import net.floodlightcontroller.core.INetMapStorage; |
| 25 | import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 26 | import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath; |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 27 | import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject; |
Pankaj Berde | d007974 | 2013-03-27 17:53:25 -0700 | [diff] [blame] | 28 | import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject; |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 29 | import net.floodlightcontroller.core.INetMapTopologyService.ITopoRouteService; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 30 | import net.floodlightcontroller.core.IOFSwitch; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 31 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 32 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 33 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 34 | import net.floodlightcontroller.core.module.IFloodlightService; |
| 35 | import net.floodlightcontroller.flowcache.IFlowService; |
| 36 | import net.floodlightcontroller.flowcache.web.FlowWebRoutable; |
| 37 | import net.floodlightcontroller.restserver.IRestApiService; |
| 38 | import net.floodlightcontroller.util.CallerId; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 39 | import net.floodlightcontroller.util.DataPath; |
| 40 | import net.floodlightcontroller.util.Dpid; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 41 | import net.floodlightcontroller.util.DataPathEndpoints; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 42 | import net.floodlightcontroller.util.FlowEntry; |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 43 | import net.floodlightcontroller.util.FlowEntryAction; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 44 | import net.floodlightcontroller.util.FlowEntryId; |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 45 | import net.floodlightcontroller.util.FlowEntryMatch; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 46 | import net.floodlightcontroller.util.FlowEntrySwitchState; |
| 47 | import net.floodlightcontroller.util.FlowEntryUserState; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 48 | import net.floodlightcontroller.util.FlowId; |
| 49 | import net.floodlightcontroller.util.FlowPath; |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 50 | import net.floodlightcontroller.util.IPv4Net; |
| 51 | import net.floodlightcontroller.util.MACAddress; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 52 | import net.floodlightcontroller.util.OFMessageDamper; |
| 53 | import net.floodlightcontroller.util.Port; |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 54 | import net.floodlightcontroller.util.SwitchPort; |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 55 | import net.onrc.onos.flow.IFlowManager; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 56 | import net.onrc.onos.util.GraphDBConnection; |
| 57 | import net.onrc.onos.util.GraphDBConnection.Transaction; |
| 58 | |
| 59 | import org.openflow.protocol.OFFlowMod; |
| 60 | import org.openflow.protocol.OFMatch; |
| 61 | import org.openflow.protocol.OFPacketOut; |
Pavlin Radoslavov | 78c4e49 | 2013-03-12 17:17:48 -0700 | [diff] [blame] | 62 | import org.openflow.protocol.OFPort; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 63 | import org.openflow.protocol.OFType; |
| 64 | import org.openflow.protocol.action.OFAction; |
| 65 | import org.openflow.protocol.action.OFActionOutput; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 66 | |
| 67 | import org.slf4j.Logger; |
| 68 | import org.slf4j.LoggerFactory; |
| 69 | |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 70 | public class FlowManager implements IFloodlightModule, IFlowService, IFlowManager, INetMapStorage { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 71 | |
| 72 | public GraphDBConnection conn; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 73 | |
| 74 | protected IRestApiService restApi; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 75 | protected IFloodlightProviderService floodlightProvider; |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 76 | protected ITopoRouteService topoRouteService; |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 77 | protected FloodlightModuleContext context; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 78 | |
| 79 | protected OFMessageDamper messageDamper; |
| 80 | |
Pavlin Radoslavov | 78c4e49 | 2013-03-12 17:17:48 -0700 | [diff] [blame] | 81 | // |
| 82 | // TODO: Values copied from elsewhere (class LearningSwitch). |
| 83 | // The local copy should go away! |
| 84 | // |
| 85 | protected static final int OFMESSAGE_DAMPER_CAPACITY = 50000; // TODO: find sweet spot |
| 86 | protected static final int OFMESSAGE_DAMPER_TIMEOUT = 250; // ms |
| 87 | public static final short FLOWMOD_DEFAULT_IDLE_TIMEOUT = 0; // infinity |
| 88 | public static final short FLOWMOD_DEFAULT_HARD_TIMEOUT = 0; // infinite |
| 89 | public static final short PRIORITY_DEFAULT = 100; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 90 | |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 91 | // Flow Entry ID generation state |
| 92 | private static Random randomGenerator = new Random(); |
| 93 | private static int nextFlowEntryIdPrefix = 0; |
| 94 | private static int nextFlowEntryIdSuffix = 0; |
| 95 | private static long nextFlowEntryId = 0; |
| 96 | |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 97 | private static long measurementFlowId = 100000; |
| 98 | private static String measurementFlowIdStr = "0x186a0"; // 100000 |
| 99 | private long modifiedMeasurementFlowTime = 0; |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 100 | |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 101 | /** The logger. */ |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 102 | private static Logger log = LoggerFactory.getLogger(FlowManager.class); |
| 103 | |
| 104 | // The periodic task(s) |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 105 | private final ScheduledExecutorService measureShortestPathScheduler = |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 106 | Executors.newScheduledThreadPool(1); |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 107 | private final ScheduledExecutorService measureMapReaderScheduler = |
| 108 | Executors.newScheduledThreadPool(1); |
| 109 | private final ScheduledExecutorService mapReaderScheduler = |
| 110 | Executors.newScheduledThreadPool(1); |
| 111 | |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 112 | private BlockingQueue<Runnable> shortestPathQueue = new LinkedBlockingQueue<Runnable>(); |
| 113 | private ThreadPoolExecutor shortestPathExecutor = |
| 114 | new ThreadPoolExecutor(10, 10, 5, TimeUnit.SECONDS, shortestPathQueue); |
| 115 | |
| 116 | class ShortestPathTask implements Runnable { |
| 117 | private int hint; |
| 118 | private ITopoRouteService topoRouteService; |
| 119 | private ArrayList<DataPath> dpList; |
| 120 | |
| 121 | public ShortestPathTask(int hint, |
| 122 | ITopoRouteService topoRouteService, |
| 123 | ArrayList<DataPath> dpList) { |
| 124 | this.hint = hint; |
| 125 | this.topoRouteService = topoRouteService; |
| 126 | this.dpList = dpList; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void run() { |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 131 | /* |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 132 | String logMsg = "MEASUREMENT: Running Thread hint " + this.hint; |
| 133 | log.debug(logMsg); |
| 134 | long startTime = System.nanoTime(); |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 135 | */ |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 136 | for (DataPath dp : this.dpList) { |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 137 | topoRouteService.getTopoShortestPath(dp.srcPort(), dp.dstPort()); |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 138 | } |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 139 | /* |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 140 | long estimatedTime = System.nanoTime() - startTime; |
| 141 | double rate = (estimatedTime > 0)? ((double)dpList.size() * 1000000000) / estimatedTime: 0.0; |
| 142 | logMsg = "MEASUREMENT: Computed Thread hint " + hint + ": " + dpList.size() + " shortest paths in " + (double)estimatedTime / 1000000000 + " sec: " + rate + " flows/s"; |
| 143 | log.debug(logMsg); |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 144 | */ |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 148 | final Runnable measureShortestPath = new Runnable() { |
| 149 | public void run() { |
| 150 | log.debug("Recomputing Shortest Paths from the Network Map Flows..."); |
| 151 | if (floodlightProvider == null) { |
| 152 | log.debug("FloodlightProvider service not found!"); |
| 153 | return; |
| 154 | } |
| 155 | |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 156 | if (topoRouteService == null) { |
| 157 | log.debug("Topology Route Service not found"); |
| 158 | return; |
| 159 | } |
| 160 | |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 161 | int leftoverQueueSize = shortestPathExecutor.getQueue().size(); |
| 162 | if (leftoverQueueSize > 0) { |
| 163 | String logMsg = "MEASUREMENT: Leftover Shortest Path Queue Size: " + leftoverQueueSize; |
| 164 | log.debug(logMsg); |
| 165 | return; |
| 166 | } |
| 167 | log.debug("MEASUREMENT: Beginning Shortest Path Computation"); |
| 168 | |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 169 | // |
| 170 | // Recompute the Shortest Paths for all Flows |
| 171 | // |
| 172 | int counter = 0; |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 173 | int hint = 0; |
| 174 | ArrayList<DataPath> dpList = new ArrayList<DataPath>(); |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 175 | long startTime = System.nanoTime(); |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 176 | |
| 177 | topoRouteService.prepareShortestPathTopo(); |
| 178 | |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 179 | Iterable<IFlowPath> allFlowPaths = conn.utils().getAllFlowPaths(conn); |
| 180 | for (IFlowPath flowPathObj : allFlowPaths) { |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 181 | FlowId flowId = new FlowId(flowPathObj.getFlowId()); |
| 182 | |
| 183 | // log.debug("Found Path {}", flowId.toString()); |
| 184 | Dpid srcDpid = new Dpid(flowPathObj.getSrcSwitch()); |
| 185 | Port srcPort = new Port(flowPathObj.getSrcPort()); |
| 186 | Dpid dstDpid = new Dpid(flowPathObj.getDstSwitch()); |
| 187 | Port dstPort = new Port(flowPathObj.getDstPort()); |
| 188 | SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort); |
| 189 | SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort); |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 190 | |
| 191 | /* |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 192 | DataPath dp = new DataPath(); |
| 193 | dp.setSrcPort(srcSwitchPort); |
| 194 | dp.setDstPort(dstSwitchPort); |
| 195 | dpList.add(dp); |
| 196 | if ((dpList.size() % 10) == 0) { |
| 197 | shortestPathExecutor.execute( |
| 198 | new ShortestPathTask(hint, topoRouteService, |
| 199 | dpList)); |
| 200 | dpList = new ArrayList<DataPath>(); |
| 201 | hint++; |
| 202 | } |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 203 | */ |
| 204 | |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 205 | DataPath dataPath = |
| 206 | topoRouteService.getTopoShortestPath(srcSwitchPort, |
| 207 | dstSwitchPort); |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 208 | counter++; |
| 209 | } |
| 210 | if (dpList.size() > 0) { |
| 211 | shortestPathExecutor.execute( |
| 212 | new ShortestPathTask(hint, topoRouteService, |
| 213 | dpList)); |
| 214 | } |
| 215 | |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 216 | /* |
Pavlin Radoslavov | 4da6128 | 2013-03-20 20:31:36 -0700 | [diff] [blame] | 217 | // Wait for all tasks to finish |
| 218 | try { |
| 219 | while (shortestPathExecutor.getQueue().size() > 0) { |
| 220 | Thread.sleep(100); |
| 221 | } |
| 222 | } catch (InterruptedException ex) { |
| 223 | log.debug("MEASUREMENT: Shortest Path Computation interrupted"); |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 224 | } |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 225 | */ |
| 226 | |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 227 | conn.endTx(Transaction.COMMIT); |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 228 | topoRouteService.dropShortestPathTopo(); |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 229 | |
| 230 | long estimatedTime = System.nanoTime() - startTime; |
| 231 | double rate = (estimatedTime > 0)? ((double)counter * 1000000000) / estimatedTime: 0.0; |
| 232 | String logMsg = "MEASUREMENT: Computed " + counter + " shortest paths in " + (double)estimatedTime / 1000000000 + " sec: " + rate + " flows/s"; |
| 233 | log.debug(logMsg); |
| 234 | } |
| 235 | }; |
| 236 | |
| 237 | final Runnable measureMapReader = new Runnable() { |
| 238 | public void run() { |
| 239 | if (floodlightProvider == null) { |
| 240 | log.debug("FloodlightProvider service not found!"); |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | // |
| 245 | // Fetch all Flow Entries |
| 246 | // |
| 247 | int counter = 0; |
| 248 | long startTime = System.nanoTime(); |
| 249 | Iterable<IFlowEntry> allFlowEntries = conn.utils().getAllFlowEntries(conn); |
| 250 | for (IFlowEntry flowEntryObj : allFlowEntries) { |
| 251 | counter++; |
| 252 | FlowEntryId flowEntryId = |
| 253 | new FlowEntryId(flowEntryObj.getFlowEntryId()); |
| 254 | String userState = flowEntryObj.getUserState(); |
| 255 | String switchState = flowEntryObj.getSwitchState(); |
| 256 | } |
| 257 | conn.endTx(Transaction.COMMIT); |
| 258 | |
| 259 | long estimatedTime = System.nanoTime() - startTime; |
| 260 | double rate = (estimatedTime > 0)? ((double)counter * 1000000000) / estimatedTime: 0.0; |
| 261 | String logMsg = "MEASUREMENT: Fetched " + counter + " flow entries in " + (double)estimatedTime / 1000000000 + " sec: " + rate + " entries/s"; |
| 262 | log.debug(logMsg); |
| 263 | } |
| 264 | }; |
| 265 | |
| 266 | final Runnable mapReader = new Runnable() { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 267 | public void run() { |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 268 | long startTime = System.nanoTime(); |
| 269 | int counterAllFlowEntries = 0; |
| 270 | int counterMyNotUpdatedFlowEntries = 0; |
| 271 | int counterAllFlowPaths = 0; |
| 272 | int counterMyFlowPaths = 0; |
| 273 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 274 | if (floodlightProvider == null) { |
| 275 | log.debug("FloodlightProvider service not found!"); |
| 276 | return; |
| 277 | } |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 278 | Map<Long, IOFSwitch> mySwitches = |
| 279 | floodlightProvider.getSwitches(); |
| 280 | Map<Long, IFlowEntry> myFlowEntries = |
| 281 | new TreeMap<Long, IFlowEntry>(); |
| 282 | LinkedList<IFlowEntry> deleteFlowEntries = |
| 283 | new LinkedList<IFlowEntry>(); |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 284 | |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 285 | |
| 286 | // |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 287 | // Fetch all Flow Entries and select only my Flow Entries |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 288 | // that need to be updated into the switches. |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 289 | // |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 290 | Iterable<IFlowEntry> allFlowEntries = |
| 291 | conn.utils().getAllFlowEntries(conn); |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 292 | for (IFlowEntry flowEntryObj : allFlowEntries) { |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 293 | counterAllFlowEntries++; |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 294 | String flowEntryIdStr = flowEntryObj.getFlowEntryId(); |
Pavlin Radoslavov | 2f9d633 | 2013-03-18 23:05:48 -0700 | [diff] [blame] | 295 | String userState = flowEntryObj.getUserState(); |
| 296 | String switchState = flowEntryObj.getSwitchState(); |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 297 | String dpidStr = flowEntryObj.getSwitchDpid(); |
| 298 | if ((flowEntryIdStr == null) || |
| 299 | (userState == null) || |
| 300 | (switchState == null) || |
| 301 | (dpidStr == null)) { |
| 302 | log.debug("IGNORING Flow Entry entry with null fields"); |
| 303 | continue; |
| 304 | } |
| 305 | FlowEntryId flowEntryId = new FlowEntryId(flowEntryIdStr); |
| 306 | Dpid dpid = new Dpid(dpidStr); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 307 | |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 308 | /* |
| 309 | log.debug("Found Flow Entry Id = {} {}", |
Pavlin Radoslavov | 79a67c1 | 2013-03-15 21:05:53 -0700 | [diff] [blame] | 310 | flowEntryId.toString(), |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 311 | "DPID = " + dpid.toString() + |
| 312 | " User State: " + userState + |
Pavlin Radoslavov | 2f9d633 | 2013-03-18 23:05:48 -0700 | [diff] [blame] | 313 | " Switch State: " + switchState); |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 314 | */ |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 315 | |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 316 | if (! switchState.equals("FE_SWITCH_NOT_UPDATED")) |
| 317 | continue; // Ignore the entry: nothing to do |
| 318 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 319 | IOFSwitch mySwitch = mySwitches.get(dpid.value()); |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 320 | if (mySwitch == null) |
| 321 | continue; // Ignore the entry: not my switch |
| 322 | |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 323 | myFlowEntries.put(flowEntryId.value(), flowEntryObj); |
| 324 | } |
| 325 | |
| 326 | // |
| 327 | // Process my Flow Entries |
| 328 | // |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 329 | boolean processed_measurement_flow = false; |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 330 | for (Map.Entry<Long, IFlowEntry> entry : myFlowEntries.entrySet()) { |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 331 | counterMyNotUpdatedFlowEntries++; |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 332 | IFlowEntry flowEntryObj = entry.getValue(); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 333 | IFlowPath flowObj = |
| 334 | conn.utils().getFlowPathByFlowEntry(conn, |
| 335 | flowEntryObj); |
| 336 | if (flowObj == null) |
| 337 | continue; // Should NOT happen |
| 338 | |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 339 | // Code for measurement purpose |
| 340 | { |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 341 | if (flowObj.getFlowId().equals(measurementFlowIdStr)) { |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 342 | processed_measurement_flow = true; |
| 343 | } |
| 344 | } |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 345 | |
| 346 | // |
| 347 | // TODO: Eliminate the re-fetching of flowEntryId, |
| 348 | // userState, switchState, and dpid from the flowEntryObj. |
| 349 | // |
| 350 | FlowEntryId flowEntryId = |
| 351 | new FlowEntryId(flowEntryObj.getFlowEntryId()); |
| 352 | Dpid dpid = new Dpid(flowEntryObj.getSwitchDpid()); |
| 353 | String userState = flowEntryObj.getUserState(); |
| 354 | String switchState = flowEntryObj.getSwitchState(); |
| 355 | IOFSwitch mySwitch = mySwitches.get(dpid.value()); |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 356 | if (mySwitch == null) |
| 357 | continue; // Shouldn't happen |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 358 | |
| 359 | // |
| 360 | // Create the Open Flow Flow Modification Entry to push |
| 361 | // |
| 362 | OFFlowMod fm = |
| 363 | (OFFlowMod) floodlightProvider.getOFMessageFactory() |
| 364 | .getMessage(OFType.FLOW_MOD); |
| 365 | long cookie = flowEntryId.value(); |
| 366 | |
| 367 | short flowModCommand = OFFlowMod.OFPFC_ADD; |
| 368 | if (userState.equals("FE_USER_ADD")) { |
| 369 | flowModCommand = OFFlowMod.OFPFC_ADD; |
| 370 | } else if (userState.equals("FE_USER_MODIFY")) { |
| 371 | flowModCommand = OFFlowMod.OFPFC_MODIFY_STRICT; |
| 372 | } else if (userState.equals("FE_USER_DELETE")) { |
| 373 | flowModCommand = OFFlowMod.OFPFC_DELETE_STRICT; |
| 374 | } else { |
| 375 | // Unknown user state. Ignore the entry |
Pavlin Radoslavov | 2f9d633 | 2013-03-18 23:05:48 -0700 | [diff] [blame] | 376 | log.debug("Flow Entry ignored (FlowEntryId = {}): unknown user state {}", |
| 377 | flowEntryId.toString(), userState); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 378 | continue; |
| 379 | } |
| 380 | |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 381 | // |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 382 | // Fetch the match conditions. |
| 383 | // |
| 384 | // NOTE: The Flow matching conditions common for all |
| 385 | // Flow Entries are used ONLY if a Flow Entry does NOT |
| 386 | // have the corresponding matching condition set. |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 387 | // |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 388 | OFMatch match = new OFMatch(); |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 389 | match.setWildcards(OFMatch.OFPFW_ALL); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 390 | // |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 391 | Short matchInPort = flowEntryObj.getMatchInPort(); |
| 392 | if (matchInPort != null) { |
| 393 | match.setInputPort(matchInPort); |
| 394 | match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_IN_PORT); |
| 395 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 396 | // |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 397 | Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType(); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 398 | if (matchEthernetFrameType == null) |
| 399 | matchEthernetFrameType = flowObj.getMatchEthernetFrameType(); |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 400 | if (matchEthernetFrameType != null) { |
| 401 | match.setDataLayerType(matchEthernetFrameType); |
| 402 | match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_TYPE); |
| 403 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 404 | // |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 405 | String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net(); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 406 | if (matchSrcIPv4Net == null) |
| 407 | matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net(); |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 408 | if (matchSrcIPv4Net != null) { |
| 409 | match.setFromCIDR(matchSrcIPv4Net, OFMatch.STR_NW_SRC); |
| 410 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 411 | // |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 412 | String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net(); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 413 | if (matchDstIPv4Net == null) |
| 414 | matchDstIPv4Net = flowObj.getMatchDstIPv4Net(); |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 415 | if (matchDstIPv4Net != null) { |
| 416 | match.setFromCIDR(matchDstIPv4Net, OFMatch.STR_NW_DST); |
| 417 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 418 | // |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 419 | String matchSrcMac = flowEntryObj.getMatchSrcMac(); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 420 | if (matchSrcMac == null) |
| 421 | matchSrcMac = flowObj.getMatchSrcMac(); |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 422 | if (matchSrcMac != null) { |
| 423 | match.setDataLayerSource(matchSrcMac); |
| 424 | match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_SRC); |
| 425 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 426 | // |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 427 | String matchDstMac = flowEntryObj.getMatchDstMac(); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 428 | if (matchDstMac == null) |
| 429 | matchDstMac = flowObj.getMatchDstMac(); |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 430 | if (matchDstMac != null) { |
| 431 | match.setDataLayerDestination(matchDstMac); |
| 432 | match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_DST); |
| 433 | } |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 434 | |
| 435 | // |
| 436 | // Fetch the actions |
| 437 | // |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 438 | List<OFAction> actions = new ArrayList<OFAction>(); |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 439 | Short actionOutputPort = flowEntryObj.getActionOutput(); |
| 440 | if (actionOutputPort != null) { |
| 441 | OFActionOutput action = new OFActionOutput(); |
| 442 | // XXX: The max length is hard-coded for now |
| 443 | action.setMaxLength((short)0xffff); |
| 444 | action.setPort(actionOutputPort); |
| 445 | actions.add(action); |
| 446 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 447 | |
| 448 | fm.setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT) |
| 449 | .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT) |
Pavlin Radoslavov | 78c4e49 | 2013-03-12 17:17:48 -0700 | [diff] [blame] | 450 | .setPriority(PRIORITY_DEFAULT) |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 451 | .setBufferId(OFPacketOut.BUFFER_ID_NONE) |
| 452 | .setCookie(cookie) |
| 453 | .setCommand(flowModCommand) |
| 454 | .setMatch(match) |
| 455 | .setActions(actions) |
| 456 | .setLengthU(OFFlowMod.MINIMUM_LENGTH+OFActionOutput.MINIMUM_LENGTH); |
Pavlin Radoslavov | 78c4e49 | 2013-03-12 17:17:48 -0700 | [diff] [blame] | 457 | fm.setOutPort(OFPort.OFPP_NONE.getValue()); |
| 458 | if ((flowModCommand == OFFlowMod.OFPFC_DELETE) || |
| 459 | (flowModCommand == OFFlowMod.OFPFC_DELETE_STRICT)) { |
| 460 | if (actionOutputPort != null) |
| 461 | fm.setOutPort(actionOutputPort); |
| 462 | } |
| 463 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 464 | // |
| 465 | // TODO: Set the following flag |
| 466 | // fm.setFlags(OFFlowMod.OFPFF_SEND_FLOW_REM); |
| 467 | // See method ForwardingBase::pushRoute() |
| 468 | // |
| 469 | try { |
| 470 | messageDamper.write(mySwitch, fm, null); |
| 471 | mySwitch.flush(); |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 472 | // |
| 473 | // TODO: We should use the OpenFlow Barrier mechanism |
| 474 | // to check for errors, and update the SwitchState |
| 475 | // for a flow entry after the Barrier message is |
| 476 | // is received. |
| 477 | // |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 478 | flowEntryObj.setSwitchState("FE_SWITCH_UPDATED"); |
| 479 | if (userState.equals("FE_USER_DELETE")) { |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 480 | // An entry that needs to be deleted. |
| 481 | deleteFlowEntries.add(flowEntryObj); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 482 | } |
| 483 | } catch (IOException e) { |
| 484 | log.error("Failure writing flow mod from network map", e); |
| 485 | } |
| 486 | } |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 487 | |
| 488 | // |
| 489 | // Delete all entries marked for deletion |
| 490 | // |
| 491 | // TODO: We should use the OpenFlow Barrier mechanism |
| 492 | // to check for errors, and delete the Flow Entries after the |
| 493 | // Barrier message is received. |
| 494 | // |
| 495 | while (! deleteFlowEntries.isEmpty()) { |
| 496 | IFlowEntry flowEntryObj = deleteFlowEntries.poll(); |
| 497 | IFlowPath flowObj = |
| 498 | conn.utils().getFlowPathByFlowEntry(conn, flowEntryObj); |
| 499 | if (flowObj == null) { |
| 500 | log.debug("Did not find FlowPath to be deleted"); |
| 501 | continue; |
| 502 | } |
| 503 | flowObj.removeFlowEntry(flowEntryObj); |
| 504 | conn.utils().removeFlowEntry(conn, flowEntryObj); |
| 505 | |
| 506 | // Test whether the last flow entry |
| 507 | Iterable<IFlowEntry> tmpflowEntries = |
| 508 | flowObj.getFlowEntries(); |
| 509 | boolean found = false; |
| 510 | for (IFlowEntry tmpflowEntryObj : tmpflowEntries) { |
| 511 | found = true; |
| 512 | break; |
| 513 | } |
| 514 | if (! found) { |
| 515 | // Remove the Flow Path as well |
| 516 | conn.utils().removeFlowPath(conn, flowObj); |
| 517 | } |
| 518 | } |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 519 | |
| 520 | |
| 521 | // |
| 522 | // Fetch and recompute the Shortest Path for those |
| 523 | // Flow Paths this controller is responsible for. |
| 524 | // |
| 525 | |
| 526 | /* |
| 527 | * TODO: For now, the computation of the reconciliation is |
| 528 | * commented-out. |
| 529 | */ |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 530 | topoRouteService.prepareShortestPathTopo(); |
| 531 | Iterable<IFlowPath> allFlowPaths = conn.utils().getAllFlowPaths(conn); |
| 532 | HashSet<IFlowPath> flowObjSet = new HashSet<IFlowPath>(); |
| 533 | for (IFlowPath flowPathObj : allFlowPaths) { |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 534 | counterAllFlowPaths++; |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 535 | if (flowPathObj == null) |
| 536 | continue; |
| 537 | String dataPathSummaryStr = flowPathObj.getDataPathSummary(); |
| 538 | if (dataPathSummaryStr == null) |
| 539 | continue; // Could be invalid entry? |
| 540 | if (dataPathSummaryStr.isEmpty()) |
| 541 | continue; // No need to maintain this flow |
| 542 | |
| 543 | // Fetch the fields needed to recompute the shortest path |
| 544 | String flowIdStr = flowPathObj.getFlowId(); |
| 545 | String srcDpidStr = flowPathObj.getSrcSwitch(); |
| 546 | Short srcPortShort = flowPathObj.getSrcPort(); |
| 547 | String dstDpidStr = flowPathObj.getDstSwitch(); |
| 548 | Short dstPortShort = flowPathObj.getDstPort(); |
| 549 | if ((flowIdStr == null) || |
| 550 | (srcDpidStr == null) || |
| 551 | (srcPortShort == null) || |
| 552 | (dstDpidStr == null) || |
| 553 | (dstPortShort == null)) { |
| 554 | log.debug("IGNORING Flow Path entry with null fields"); |
| 555 | continue; |
| 556 | } |
| 557 | |
| 558 | FlowId flowId = new FlowId(flowIdStr); |
| 559 | Dpid srcDpid = new Dpid(srcDpidStr); |
| 560 | Port srcPort = new Port(srcPortShort); |
| 561 | Dpid dstDpid = new Dpid(dstDpidStr); |
| 562 | Port dstPort = new Port(dstPortShort); |
| 563 | SwitchPort srcSwitchPort = new SwitchPort(srcDpid, srcPort); |
| 564 | SwitchPort dstSwitchPort = new SwitchPort(dstDpid, dstPort); |
Pavlin Radoslavov | 2659a0b | 2013-04-03 20:30:40 -0700 | [diff] [blame] | 565 | |
| 566 | // |
| 567 | // Use the source DPID as a heuristic to decide |
| 568 | // which controller is responsible for maintaining the |
| 569 | // shortest path. |
| 570 | // NOTE: This heuristic is error-prone: if the switch |
| 571 | // goes away and no controller is responsible for that |
| 572 | // switch, then the original Flow Path is not cleaned-up |
| 573 | // |
| 574 | IOFSwitch mySwitch = mySwitches.get(srcDpid.value()); |
| 575 | if (mySwitch == null) |
| 576 | continue; // Ignore: not my responsibility |
| 577 | |
| 578 | counterMyFlowPaths++; |
| 579 | |
Pavlin Radoslavov | 832aa65 | 2013-03-29 16:21:59 -0700 | [diff] [blame] | 580 | // |
| 581 | // NOTE: Using here the regular getShortestPath() method |
| 582 | // won't work here, because that method calls internally |
| 583 | // "conn.endTx(Transaction.COMMIT)", and that will |
| 584 | // invalidate all handlers to the Titan database. |
| 585 | // If we want to experiment with calling here |
| 586 | // getShortestPath(), we need to refactor that code |
| 587 | // to avoid closing the transaction. |
| 588 | // |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 589 | DataPath dataPath = |
| 590 | topoRouteService.getTopoShortestPath(srcSwitchPort, |
| 591 | dstSwitchPort); |
Pavlin Radoslavov | 4a32582 | 2013-04-02 22:16:59 +0000 | [diff] [blame] | 592 | if (dataPath == null) { |
| 593 | // We need the DataPath to compare the paths |
| 594 | dataPath = new DataPath(); |
| 595 | dataPath.setSrcPort(srcSwitchPort); |
| 596 | dataPath.setDstPort(dstSwitchPort); |
| 597 | } |
| 598 | |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 599 | String newDataPathSummaryStr = dataPath.dataPathSummary(); |
| 600 | if (dataPathSummaryStr.equals(newDataPathSummaryStr)) |
| 601 | continue; // Nothing changed |
| 602 | |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 603 | log.debug("RECONCILE: Need to Reconcile Shortest Path for FlowID {}", |
| 604 | flowId.toString()); |
| 605 | flowObjSet.add(flowPathObj); |
| 606 | } |
| 607 | reconcileFlows(flowObjSet); |
| 608 | topoRouteService.dropShortestPathTopo(); |
Pavlin Radoslavov | 0391b9d | 2013-03-29 11:54:25 -0700 | [diff] [blame] | 609 | |
| 610 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 611 | conn.endTx(Transaction.COMMIT); |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 612 | |
| 613 | if (processed_measurement_flow) { |
| 614 | long estimatedTime = System.nanoTime() - modifiedMeasurementFlowTime; |
| 615 | String logMsg = "MEASUREMENT: Pushed Flow delay: " + |
| 616 | (double)estimatedTime / 1000000000 + " sec"; |
| 617 | log.debug(logMsg); |
| 618 | } |
Pavlin Radoslavov | 42f02ba | 2013-04-03 20:07:30 -0700 | [diff] [blame] | 619 | |
| 620 | long estimatedTime = System.nanoTime() - startTime; |
| 621 | double rate = (estimatedTime > 0)? ((double)counterAllFlowPaths * 1000000000) / estimatedTime: 0.0; |
| 622 | String logMsg = "MEASUREMENT: Processed AllFlowEntries: " + counterAllFlowEntries + " MyNotUpdatedFlowEntries: " + counterMyNotUpdatedFlowEntries + " AllFlowPaths: " + counterAllFlowPaths + " MyFlowPaths: " + counterMyFlowPaths + " in " + (double)estimatedTime / 1000000000 + " sec: " + rate + " paths/s"; |
| 623 | log.debug(logMsg); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 624 | } |
| 625 | }; |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 626 | |
| 627 | /* |
| 628 | final ScheduledFuture<?> measureShortestPathHandle = |
| 629 | measureShortestPathScheduler.scheduleAtFixedRate(measureShortestPath, 10, 10, TimeUnit.SECONDS); |
| 630 | */ |
| 631 | |
Pavlin Radoslavov | e38319c | 2013-03-21 16:20:00 -0700 | [diff] [blame] | 632 | /* |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 633 | final ScheduledFuture<?> measureMapReaderHandle = |
| 634 | measureMapReaderScheduler.scheduleAtFixedRate(measureMapReader, 10, 10, TimeUnit.SECONDS); |
Pavlin Radoslavov | e38319c | 2013-03-21 16:20:00 -0700 | [diff] [blame] | 635 | */ |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 636 | |
| 637 | final ScheduledFuture<?> mapReaderHandle = |
| 638 | mapReaderScheduler.scheduleAtFixedRate(mapReader, 3, 3, TimeUnit.SECONDS); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 639 | |
| 640 | @Override |
| 641 | public void init(String conf) { |
| 642 | conn = GraphDBConnection.getInstance(conf); |
| 643 | } |
| 644 | |
| 645 | public void finalize() { |
| 646 | close(); |
| 647 | } |
| 648 | |
| 649 | @Override |
| 650 | public void close() { |
| 651 | conn.close(); |
| 652 | } |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 653 | |
| 654 | @Override |
| 655 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 656 | Collection<Class<? extends IFloodlightService>> l = |
| 657 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 658 | l.add(IFlowService.class); |
| 659 | return l; |
| 660 | } |
| 661 | |
| 662 | @Override |
| 663 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
| 664 | getServiceImpls() { |
| 665 | Map<Class<? extends IFloodlightService>, |
| 666 | IFloodlightService> m = |
| 667 | new HashMap<Class<? extends IFloodlightService>, |
| 668 | IFloodlightService>(); |
| 669 | m.put(IFlowService.class, this); |
| 670 | return m; |
| 671 | } |
| 672 | |
| 673 | @Override |
| 674 | public Collection<Class<? extends IFloodlightService>> |
| 675 | getModuleDependencies() { |
| 676 | Collection<Class<? extends IFloodlightService>> l = |
| 677 | new ArrayList<Class<? extends IFloodlightService>>(); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 678 | l.add(IFloodlightProviderService.class); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 679 | l.add(ITopoRouteService.class); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 680 | l.add(IRestApiService.class); |
| 681 | return l; |
| 682 | } |
| 683 | |
| 684 | @Override |
| 685 | public void init(FloodlightModuleContext context) |
| 686 | throws FloodlightModuleException { |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 687 | this.context = context; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 688 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 689 | topoRouteService = context.getServiceImpl(ITopoRouteService.class); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 690 | restApi = context.getServiceImpl(IRestApiService.class); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 691 | messageDamper = new OFMessageDamper(OFMESSAGE_DAMPER_CAPACITY, |
| 692 | EnumSet.of(OFType.FLOW_MOD), |
| 693 | OFMESSAGE_DAMPER_TIMEOUT); |
| 694 | // TODO: An ugly hack! |
| 695 | String conf = "/tmp/cassandra.titan"; |
| 696 | this.init(conf); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 697 | } |
| 698 | |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 699 | private long getNextFlowEntryId() { |
| 700 | // |
| 701 | // Generate the next Flow Entry ID. |
| 702 | // NOTE: For now, the higher 32 bits are random, and |
| 703 | // the lower 32 bits are sequential. |
| 704 | // In the future, we need a better allocation mechanism. |
| 705 | // |
| 706 | if ((nextFlowEntryIdSuffix & 0xffffffffL) == 0xffffffffL) { |
| 707 | nextFlowEntryIdPrefix = randomGenerator.nextInt(); |
| 708 | nextFlowEntryIdSuffix = 0; |
| 709 | } else { |
| 710 | nextFlowEntryIdSuffix++; |
| 711 | } |
| 712 | long result = (long)nextFlowEntryIdPrefix << 32; |
| 713 | result = result | (0xffffffffL & nextFlowEntryIdSuffix); |
| 714 | return result; |
| 715 | } |
| 716 | |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 717 | @Override |
| 718 | public void startUp(FloodlightModuleContext context) { |
| 719 | restApi.addRestletRoutable(new FlowWebRoutable()); |
Pavlin Radoslavov | 80ca630 | 2013-03-20 02:08:09 -0700 | [diff] [blame] | 720 | |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 721 | // Initialize the Flow Entry ID generator |
| 722 | nextFlowEntryIdPrefix = randomGenerator.nextInt(); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | /** |
| 726 | * Add a flow. |
| 727 | * |
| 728 | * Internally, ONOS will automatically register the installer for |
| 729 | * receiving Flow Path Notifications for that path. |
| 730 | * |
| 731 | * @param flowPath the Flow Path to install. |
| 732 | * @param flowId the return-by-reference Flow ID as assigned internally. |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 733 | * @param dataPathSummaryStr the data path summary string if the added |
| 734 | * flow will be maintained internally, otherwise null. |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 735 | * @return true on success, otherwise false. |
| 736 | */ |
| 737 | @Override |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 738 | public boolean addFlow(FlowPath flowPath, FlowId flowId, |
| 739 | String dataPathSummaryStr) { |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 740 | if (flowPath.flowId().value() == measurementFlowId) { |
| 741 | modifiedMeasurementFlowTime = System.nanoTime(); |
| 742 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 743 | |
| 744 | // |
| 745 | // Assign the FlowEntry IDs |
Pavlin Radoslavov | 01391c9 | 2013-03-14 17:13:21 -0700 | [diff] [blame] | 746 | // Right now every new flow entry gets a new flow entry ID |
| 747 | // TODO: This needs to be redesigned! |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 748 | // |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 749 | for (FlowEntry flowEntry : flowPath.dataPath().flowEntries()) { |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 750 | long id = getNextFlowEntryId(); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 751 | flowEntry.setFlowEntryId(new FlowEntryId(id)); |
| 752 | } |
| 753 | |
| 754 | IFlowPath flowObj = null; |
| 755 | try { |
| 756 | if ((flowObj = conn.utils().searchFlowPath(conn, flowPath.flowId())) |
| 757 | != null) { |
| 758 | log.debug("Adding FlowPath with FlowId {}: found existing FlowPath", |
| 759 | flowPath.flowId().toString()); |
| 760 | } else { |
| 761 | flowObj = conn.utils().newFlowPath(conn); |
| 762 | log.debug("Adding FlowPath with FlowId {}: creating new FlowPath", |
| 763 | flowPath.flowId().toString()); |
| 764 | } |
| 765 | } catch (Exception e) { |
| 766 | // TODO: handle exceptions |
| 767 | conn.endTx(Transaction.ROLLBACK); |
| 768 | log.error(":addFlow FlowId:{} failed", |
| 769 | flowPath.flowId().toString()); |
| 770 | } |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 771 | if (flowObj == null) { |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 772 | log.error(":addFlow FlowId:{} failed: Flow object not created", |
| 773 | flowPath.flowId().toString()); |
| 774 | conn.endTx(Transaction.ROLLBACK); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 775 | return false; |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 776 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 777 | |
| 778 | // |
| 779 | // Set the Flow key: |
| 780 | // - flowId |
| 781 | // |
| 782 | flowObj.setFlowId(flowPath.flowId().toString()); |
| 783 | flowObj.setType("flow"); |
| 784 | |
| 785 | // |
| 786 | // Set the Flow attributes: |
| 787 | // - flowPath.installerId() |
| 788 | // - flowPath.dataPath().srcPort() |
| 789 | // - flowPath.dataPath().dstPort() |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 790 | // - flowPath.matchEthernetFrameType() |
| 791 | // - flowPath.matchSrcIPv4Net() |
| 792 | // - flowPath.matchDstIPv4Net() |
| 793 | // - flowPath.matchSrcMac() |
| 794 | // - flowPath.matchDstMac() |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 795 | // |
| 796 | flowObj.setInstallerId(flowPath.installerId().toString()); |
| 797 | flowObj.setSrcSwitch(flowPath.dataPath().srcPort().dpid().toString()); |
| 798 | flowObj.setSrcPort(flowPath.dataPath().srcPort().port().value()); |
| 799 | flowObj.setDstSwitch(flowPath.dataPath().dstPort().dpid().toString()); |
| 800 | flowObj.setDstPort(flowPath.dataPath().dstPort().port().value()); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 801 | if (flowPath.flowEntryMatch().matchEthernetFrameType()) { |
| 802 | flowObj.setMatchEthernetFrameType(flowPath.flowEntryMatch().ethernetFrameType()); |
| 803 | } |
| 804 | if (flowPath.flowEntryMatch().matchSrcIPv4Net()) { |
| 805 | flowObj.setMatchSrcIPv4Net(flowPath.flowEntryMatch().srcIPv4Net().toString()); |
| 806 | } |
| 807 | if (flowPath.flowEntryMatch().matchDstIPv4Net()) { |
| 808 | flowObj.setMatchDstIPv4Net(flowPath.flowEntryMatch().dstIPv4Net().toString()); |
| 809 | } |
| 810 | if (flowPath.flowEntryMatch().matchSrcMac()) { |
| 811 | flowObj.setMatchSrcMac(flowPath.flowEntryMatch().srcMac().toString()); |
| 812 | } |
| 813 | if (flowPath.flowEntryMatch().matchDstMac()) { |
| 814 | flowObj.setMatchDstMac(flowPath.flowEntryMatch().dstMac().toString()); |
| 815 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 816 | |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 817 | if (dataPathSummaryStr != null) { |
| 818 | flowObj.setDataPathSummary(dataPathSummaryStr); |
| 819 | } else { |
| 820 | flowObj.setDataPathSummary(""); |
| 821 | } |
| 822 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 823 | // Flow edges: |
| 824 | // HeadFE |
| 825 | |
| 826 | |
| 827 | // |
| 828 | // Flow Entries: |
| 829 | // flowPath.dataPath().flowEntries() |
| 830 | // |
| 831 | for (FlowEntry flowEntry : flowPath.dataPath().flowEntries()) { |
| 832 | IFlowEntry flowEntryObj = null; |
| 833 | boolean found = false; |
| 834 | try { |
| 835 | if ((flowEntryObj = conn.utils().searchFlowEntry(conn, flowEntry.flowEntryId())) != null) { |
| 836 | log.debug("Adding FlowEntry with FlowEntryId {}: found existing FlowEntry", |
| 837 | flowEntry.flowEntryId().toString()); |
| 838 | found = true; |
| 839 | } else { |
| 840 | flowEntryObj = conn.utils().newFlowEntry(conn); |
| 841 | log.debug("Adding FlowEntry with FlowEntryId {}: creating new FlowEntry", |
| 842 | flowEntry.flowEntryId().toString()); |
| 843 | } |
| 844 | } catch (Exception e) { |
| 845 | // TODO: handle exceptions |
| 846 | conn.endTx(Transaction.ROLLBACK); |
| 847 | log.error(":addFlow FlowEntryId:{} failed", |
| 848 | flowEntry.flowEntryId().toString()); |
| 849 | } |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 850 | if (flowEntryObj == null) { |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 851 | log.error(":addFlow FlowEntryId:{} failed: FlowEntry object not created", |
| 852 | flowEntry.flowEntryId().toString()); |
| 853 | conn.endTx(Transaction.ROLLBACK); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 854 | return false; |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 855 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 856 | |
| 857 | // |
| 858 | // Set the Flow Entry key: |
| 859 | // - flowEntry.flowEntryId() |
| 860 | // |
| 861 | flowEntryObj.setFlowEntryId(flowEntry.flowEntryId().toString()); |
| 862 | flowEntryObj.setType("flow_entry"); |
| 863 | |
| 864 | // |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 865 | // Set the Flow Entry Edges and attributes: |
| 866 | // - Switch edge |
| 867 | // - InPort edge |
| 868 | // - OutPort edge |
| 869 | // |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 870 | // - flowEntry.flowEntryMatch() |
| 871 | // - flowEntry.flowEntryActions() |
| 872 | // - flowEntry.dpid() |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 873 | // - flowEntry.flowEntryUserState() |
| 874 | // - flowEntry.flowEntrySwitchState() |
| 875 | // - flowEntry.flowEntryErrorState() |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 876 | // - flowEntry.matchInPort() |
| 877 | // - flowEntry.matchEthernetFrameType() |
| 878 | // - flowEntry.matchSrcIPv4Net() |
| 879 | // - flowEntry.matchDstIPv4Net() |
| 880 | // - flowEntry.matchSrcMac() |
| 881 | // - flowEntry.matchDstMac() |
| 882 | // - flowEntry.actionOutput() |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 883 | // |
Pavlin Radoslavov | b6d1e36 | 2013-03-28 03:15:41 -0700 | [diff] [blame] | 884 | ISwitchObject sw = |
| 885 | conn.utils().searchSwitch(conn, flowEntry.dpid().toString()); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 886 | flowEntryObj.setSwitchDpid(flowEntry.dpid().toString()); |
Pankaj Berde | d007974 | 2013-03-27 17:53:25 -0700 | [diff] [blame] | 887 | flowEntryObj.setSwitch(sw); |
| 888 | if (flowEntry.flowEntryMatch().matchInPort()) { |
Pavlin Radoslavov | b6d1e36 | 2013-03-28 03:15:41 -0700 | [diff] [blame] | 889 | IPortObject inport = |
| 890 | conn.utils().searchPort(conn, flowEntry.dpid().toString(), |
| 891 | flowEntry.flowEntryMatch().inPort().value()); |
Pankaj Berde | d007974 | 2013-03-27 17:53:25 -0700 | [diff] [blame] | 892 | flowEntryObj.setMatchInPort(flowEntry.flowEntryMatch().inPort().value()); |
| 893 | flowEntryObj.setInPort(inport); |
| 894 | } |
| 895 | if (flowEntry.flowEntryMatch().matchEthernetFrameType()) { |
| 896 | flowEntryObj.setMatchEthernetFrameType(flowEntry.flowEntryMatch().ethernetFrameType()); |
| 897 | } |
| 898 | if (flowEntry.flowEntryMatch().matchSrcIPv4Net()) { |
| 899 | flowEntryObj.setMatchSrcIPv4Net(flowEntry.flowEntryMatch().srcIPv4Net().toString()); |
| 900 | } |
| 901 | if (flowEntry.flowEntryMatch().matchDstIPv4Net()) { |
| 902 | flowEntryObj.setMatchDstIPv4Net(flowEntry.flowEntryMatch().dstIPv4Net().toString()); |
| 903 | } |
| 904 | if (flowEntry.flowEntryMatch().matchSrcMac()) { |
| 905 | flowEntryObj.setMatchSrcMac(flowEntry.flowEntryMatch().srcMac().toString()); |
| 906 | } |
| 907 | if (flowEntry.flowEntryMatch().matchDstMac()) { |
| 908 | flowEntryObj.setMatchDstMac(flowEntry.flowEntryMatch().dstMac().toString()); |
| 909 | } |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 910 | |
| 911 | for (FlowEntryAction fa : flowEntry.flowEntryActions()) { |
Pankaj Berde | d007974 | 2013-03-27 17:53:25 -0700 | [diff] [blame] | 912 | if (fa.actionOutput() != null) { |
Pavlin Radoslavov | b6d1e36 | 2013-03-28 03:15:41 -0700 | [diff] [blame] | 913 | IPortObject outport = |
| 914 | conn.utils().searchPort(conn, |
| 915 | flowEntry.dpid().toString(), |
| 916 | fa.actionOutput().port().value()); |
| 917 | flowEntryObj.setActionOutput(fa.actionOutput().port().value()); |
| 918 | flowEntryObj.setOutPort(outport); |
Pankaj Berde | d007974 | 2013-03-27 17:53:25 -0700 | [diff] [blame] | 919 | } |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 920 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 921 | // TODO: Hacks with hard-coded state names! |
| 922 | if (found) |
| 923 | flowEntryObj.setUserState("FE_USER_MODIFY"); |
| 924 | else |
| 925 | flowEntryObj.setUserState("FE_USER_ADD"); |
| 926 | flowEntryObj.setSwitchState("FE_SWITCH_NOT_UPDATED"); |
| 927 | // |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 928 | // TODO: Take care of the FlowEntryErrorState. |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 929 | // |
| 930 | |
| 931 | // Flow Entries edges: |
| 932 | // Flow |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 933 | // NextFE (TODO) |
| 934 | if (! found) { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 935 | flowObj.addFlowEntry(flowEntryObj); |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 936 | flowEntryObj.setFlow(flowObj); |
| 937 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 938 | } |
| 939 | conn.endTx(Transaction.COMMIT); |
| 940 | |
| 941 | // |
| 942 | // TODO: We need a proper Flow ID allocation mechanism. |
| 943 | // |
| 944 | flowId.setValue(flowPath.flowId().value()); |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 945 | |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 946 | return true; |
| 947 | } |
| 948 | |
| 949 | /** |
| 950 | * Delete a previously added flow. |
| 951 | * |
| 952 | * @param flowId the Flow ID of the flow to delete. |
| 953 | * @return true on success, otherwise false. |
| 954 | */ |
| 955 | @Override |
| 956 | public boolean deleteFlow(FlowId flowId) { |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 957 | if (flowId.value() == measurementFlowId) { |
| 958 | modifiedMeasurementFlowTime = System.nanoTime(); |
| 959 | } |
| 960 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 961 | IFlowPath flowObj = null; |
| 962 | // |
| 963 | // We just mark the entries for deletion, |
| 964 | // and let the switches remove each individual entry after |
| 965 | // it has been removed from the switches. |
| 966 | // |
| 967 | try { |
| 968 | if ((flowObj = conn.utils().searchFlowPath(conn, flowId)) |
| 969 | != null) { |
| 970 | log.debug("Deleting FlowPath with FlowId {}: found existing FlowPath", |
| 971 | flowId.toString()); |
| 972 | } else { |
| 973 | log.debug("Deleting FlowPath with FlowId {}: FlowPath not found", |
| 974 | flowId.toString()); |
| 975 | } |
| 976 | } catch (Exception e) { |
| 977 | // TODO: handle exceptions |
| 978 | conn.endTx(Transaction.ROLLBACK); |
| 979 | log.error(":deleteFlow FlowId:{} failed", flowId.toString()); |
| 980 | } |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 981 | if (flowObj == null) { |
| 982 | conn.endTx(Transaction.COMMIT); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 983 | return true; // OK: No such flow |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 984 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 985 | |
| 986 | // |
| 987 | // Find and mark for deletion all Flow Entries |
| 988 | // |
| 989 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
| 990 | boolean empty = true; // TODO: an ugly hack |
| 991 | for (IFlowEntry flowEntryObj : flowEntries) { |
| 992 | empty = false; |
| 993 | // flowObj.removeFlowEntry(flowEntryObj); |
| 994 | // conn.utils().removeFlowEntry(conn, flowEntryObj); |
| 995 | flowEntryObj.setUserState("FE_USER_DELETE"); |
| 996 | flowEntryObj.setSwitchState("FE_SWITCH_NOT_UPDATED"); |
| 997 | } |
| 998 | // Remove from the database empty flows |
| 999 | if (empty) |
| 1000 | conn.utils().removeFlowPath(conn, flowObj); |
| 1001 | conn.endTx(Transaction.COMMIT); |
| 1002 | |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 1003 | return true; |
| 1004 | } |
| 1005 | |
| 1006 | /** |
Pavlin Radoslavov | 916832f | 2013-03-14 17:48:41 -0700 | [diff] [blame] | 1007 | * Clear the state for a previously added flow. |
| 1008 | * |
| 1009 | * @param flowId the Flow ID of the flow to clear. |
| 1010 | * @return true on success, otherwise false. |
| 1011 | */ |
| 1012 | @Override |
| 1013 | public boolean clearFlow(FlowId flowId) { |
| 1014 | IFlowPath flowObj = null; |
| 1015 | try { |
| 1016 | if ((flowObj = conn.utils().searchFlowPath(conn, flowId)) |
| 1017 | != null) { |
| 1018 | log.debug("Clearing FlowPath with FlowId {}: found existing FlowPath", |
| 1019 | flowId.toString()); |
| 1020 | } else { |
| 1021 | log.debug("Clearing FlowPath with FlowId {}: FlowPath not found", |
| 1022 | flowId.toString()); |
| 1023 | } |
| 1024 | } catch (Exception e) { |
| 1025 | // TODO: handle exceptions |
| 1026 | conn.endTx(Transaction.ROLLBACK); |
| 1027 | log.error(":clearFlow FlowId:{} failed", flowId.toString()); |
| 1028 | } |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 1029 | if (flowObj == null) { |
| 1030 | conn.endTx(Transaction.COMMIT); |
Pavlin Radoslavov | 916832f | 2013-03-14 17:48:41 -0700 | [diff] [blame] | 1031 | return true; // OK: No such flow |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 1032 | } |
Pavlin Radoslavov | 916832f | 2013-03-14 17:48:41 -0700 | [diff] [blame] | 1033 | |
| 1034 | // |
| 1035 | // Remove all Flow Entries |
| 1036 | // |
| 1037 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
| 1038 | for (IFlowEntry flowEntryObj : flowEntries) { |
| 1039 | flowObj.removeFlowEntry(flowEntryObj); |
| 1040 | conn.utils().removeFlowEntry(conn, flowEntryObj); |
| 1041 | } |
| 1042 | // Remove the Flow itself |
| 1043 | conn.utils().removeFlowPath(conn, flowObj); |
| 1044 | conn.endTx(Transaction.COMMIT); |
| 1045 | |
| 1046 | return true; |
| 1047 | } |
| 1048 | |
| 1049 | /** |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 1050 | * Get a previously added flow. |
| 1051 | * |
| 1052 | * @param flowId the Flow ID of the flow to get. |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 1053 | * @return the Flow Path if found, otherwise null. |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 1054 | */ |
| 1055 | @Override |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 1056 | public FlowPath getFlow(FlowId flowId) { |
| 1057 | IFlowPath flowObj = null; |
| 1058 | try { |
| 1059 | if ((flowObj = conn.utils().searchFlowPath(conn, flowId)) |
| 1060 | != null) { |
| 1061 | log.debug("Get FlowPath with FlowId {}: found existing FlowPath", |
| 1062 | flowId.toString()); |
| 1063 | } else { |
| 1064 | log.debug("Get FlowPath with FlowId {}: FlowPath not found", |
| 1065 | flowId.toString()); |
| 1066 | } |
| 1067 | } catch (Exception e) { |
| 1068 | // TODO: handle exceptions |
| 1069 | conn.endTx(Transaction.ROLLBACK); |
| 1070 | log.error(":getFlow FlowId:{} failed", flowId.toString()); |
| 1071 | } |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 1072 | if (flowObj == null) { |
| 1073 | conn.endTx(Transaction.COMMIT); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 1074 | return null; // Flow not found |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 1075 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 1076 | |
| 1077 | // |
| 1078 | // Extract the Flow state |
| 1079 | // |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1080 | FlowPath flowPath = extractFlowPath(flowObj); |
| 1081 | conn.endTx(Transaction.COMMIT); |
| 1082 | |
| 1083 | return flowPath; |
| 1084 | } |
| 1085 | |
| 1086 | /** |
| 1087 | * Get all previously added flows by a specific installer for a given |
| 1088 | * data path endpoints. |
| 1089 | * |
| 1090 | * @param installerId the Caller ID of the installer of the flow to get. |
| 1091 | * @param dataPathEndpoints the data path endpoints of the flow to get. |
| 1092 | * @return the Flow Paths if found, otherwise null. |
| 1093 | */ |
| 1094 | @Override |
| 1095 | public ArrayList<FlowPath> getAllFlows(CallerId installerId, |
| 1096 | DataPathEndpoints dataPathEndpoints) { |
| 1097 | // |
| 1098 | // TODO: The implementation below is not optimal: |
| 1099 | // We fetch all flows, and then return only the subset that match |
| 1100 | // the query conditions. |
| 1101 | // We should use the appropriate Titan/Gremlin query to filter-out |
| 1102 | // the flows as appropriate. |
| 1103 | // |
| 1104 | ArrayList<FlowPath> allFlows = getAllFlows(); |
Umesh Krishnaswamy | ea0f4ab | 2013-03-26 18:49:35 -0700 | [diff] [blame] | 1105 | ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>(); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1106 | |
| 1107 | if (allFlows == null) { |
| 1108 | log.debug("Get FlowPaths for installerId{} and dataPathEndpoints{}: no FlowPaths found", installerId, dataPathEndpoints); |
Umesh Krishnaswamy | ea0f4ab | 2013-03-26 18:49:35 -0700 | [diff] [blame] | 1109 | return flowPaths; |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1110 | } |
| 1111 | |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1112 | for (FlowPath flow : allFlows) { |
| 1113 | // |
| 1114 | // TODO: String-based comparison is sub-optimal. |
| 1115 | // We are using it for now to save us the extra work of |
Pavlin Radoslavov | c4e76a6 | 2013-03-06 10:52:41 -0800 | [diff] [blame] | 1116 | // implementing the "equals()" and "hashCode()" methods. |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1117 | // |
| 1118 | if (! flow.installerId().toString().equals(installerId.toString())) |
| 1119 | continue; |
| 1120 | if (! flow.dataPath().srcPort().toString().equals(dataPathEndpoints.srcPort().toString())) { |
| 1121 | continue; |
| 1122 | } |
| 1123 | if (! flow.dataPath().dstPort().toString().equals(dataPathEndpoints.dstPort().toString())) { |
| 1124 | continue; |
| 1125 | } |
| 1126 | flowPaths.add(flow); |
| 1127 | } |
| 1128 | |
| 1129 | if (flowPaths.isEmpty()) { |
| 1130 | log.debug("Get FlowPaths for installerId{} and dataPathEndpoints{}: no FlowPaths found", installerId, dataPathEndpoints); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1131 | } else { |
| 1132 | log.debug("Get FlowPaths for installerId{} and dataPathEndpoints{}: FlowPaths are found", installerId, dataPathEndpoints); |
| 1133 | } |
| 1134 | |
| 1135 | return flowPaths; |
| 1136 | } |
| 1137 | |
| 1138 | /** |
| 1139 | * Get all installed flows by all installers for given data path endpoints. |
| 1140 | * |
| 1141 | * @param dataPathEndpoints the data path endpoints of the flows to get. |
| 1142 | * @return the Flow Paths if found, otherwise null. |
| 1143 | */ |
| 1144 | @Override |
| 1145 | public ArrayList<FlowPath> getAllFlows(DataPathEndpoints dataPathEndpoints) { |
| 1146 | // |
| 1147 | // TODO: The implementation below is not optimal: |
| 1148 | // We fetch all flows, and then return only the subset that match |
| 1149 | // the query conditions. |
| 1150 | // We should use the appropriate Titan/Gremlin query to filter-out |
| 1151 | // the flows as appropriate. |
| 1152 | // |
Umesh Krishnaswamy | ea0f4ab | 2013-03-26 18:49:35 -0700 | [diff] [blame] | 1153 | ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>(); |
| 1154 | ArrayList<FlowPath> allFlows = getAllFlows(); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1155 | |
| 1156 | if (allFlows == null) { |
| 1157 | log.debug("Get FlowPaths for dataPathEndpoints{}: no FlowPaths found", dataPathEndpoints); |
Umesh Krishnaswamy | ea0f4ab | 2013-03-26 18:49:35 -0700 | [diff] [blame] | 1158 | return flowPaths; |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1159 | } |
| 1160 | |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1161 | for (FlowPath flow : allFlows) { |
| 1162 | // |
| 1163 | // TODO: String-based comparison is sub-optimal. |
| 1164 | // We are using it for now to save us the extra work of |
Pavlin Radoslavov | c4e76a6 | 2013-03-06 10:52:41 -0800 | [diff] [blame] | 1165 | // implementing the "equals()" and "hashCode()" methods. |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1166 | // |
| 1167 | if (! flow.dataPath().srcPort().toString().equals(dataPathEndpoints.srcPort().toString())) { |
| 1168 | continue; |
| 1169 | } |
| 1170 | if (! flow.dataPath().dstPort().toString().equals(dataPathEndpoints.dstPort().toString())) { |
| 1171 | continue; |
| 1172 | } |
| 1173 | flowPaths.add(flow); |
| 1174 | } |
| 1175 | |
| 1176 | if (flowPaths.isEmpty()) { |
| 1177 | log.debug("Get FlowPaths for dataPathEndpoints{}: no FlowPaths found", dataPathEndpoints); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1178 | } else { |
| 1179 | log.debug("Get FlowPaths for dataPathEndpoints{}: FlowPaths are found", dataPathEndpoints); |
| 1180 | } |
| 1181 | |
| 1182 | return flowPaths; |
| 1183 | } |
| 1184 | |
| 1185 | /** |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 1186 | * Get summary of all installed flows by all installers in a given range |
| 1187 | * |
| 1188 | * @param flowId the data path endpoints of the flows to get. |
| 1189 | * @param maxFlows: the maximum number of flows to be returned |
| 1190 | * @return the Flow Paths if found, otherwise null. |
| 1191 | */ |
| 1192 | @Override |
| 1193 | public ArrayList<FlowPath> getAllFlowsSummary(FlowId flowId, int maxFlows) { |
| 1194 | // |
| 1195 | // TODO: The implementation below is not optimal: |
| 1196 | // We fetch all flows, and then return only the subset that match |
| 1197 | // the query conditions. |
| 1198 | // We should use the appropriate Titan/Gremlin query to filter-out |
| 1199 | // the flows as appropriate. |
| 1200 | // |
Umesh Krishnaswamy | ea0f4ab | 2013-03-26 18:49:35 -0700 | [diff] [blame] | 1201 | ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>(); |
| 1202 | |
| 1203 | ArrayList<FlowPath> allFlows = getAllFlows(); |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 1204 | |
| 1205 | if (allFlows == null) { |
| 1206 | log.debug("Get FlowPathsSummary for {} {}: no FlowPaths found", flowId, maxFlows); |
Umesh Krishnaswamy | ea0f4ab | 2013-03-26 18:49:35 -0700 | [diff] [blame] | 1207 | return flowPaths; |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
Umesh Krishnaswamy | 244b4ae | 2013-03-29 12:05:15 -0700 | [diff] [blame] | 1210 | Collections.sort(allFlows); |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 1211 | |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 1212 | for (FlowPath flow : allFlows) { |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1213 | flow.setFlowEntryMatch(null); |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 1214 | |
| 1215 | // start from desired flowId |
Umesh Krishnaswamy | 2a82c64 | 2013-03-29 08:27:17 -0700 | [diff] [blame] | 1216 | //if (flow.flowId().value() < flowId.value()) { |
| 1217 | // continue; |
| 1218 | //} |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 1219 | |
| 1220 | // Summarize by making null flow entry fields that are not relevant to report |
| 1221 | for (FlowEntry flowEntry : flow.dataPath().flowEntries()) { |
| 1222 | flowEntry.setFlowEntryActions(null); |
| 1223 | flowEntry.setFlowEntryMatch(null); |
| 1224 | } |
| 1225 | |
| 1226 | flowPaths.add(flow); |
| 1227 | if (maxFlows != 0 && flowPaths.size() >= maxFlows) { |
| 1228 | break; |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | if (flowPaths.isEmpty()) { |
| 1233 | log.debug("Get FlowPathsSummary {} {}: no FlowPaths found", flowId, maxFlows); |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 1234 | } else { |
| 1235 | log.debug("Get FlowPathsSummary for {} {}: FlowPaths were found", flowId, maxFlows); |
| 1236 | } |
| 1237 | |
| 1238 | return flowPaths; |
| 1239 | } |
| 1240 | |
| 1241 | /** |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1242 | * Get all installed flows by all installers. |
| 1243 | * |
| 1244 | * @return the Flow Paths if found, otherwise null. |
| 1245 | */ |
| 1246 | @Override |
| 1247 | public ArrayList<FlowPath> getAllFlows() { |
| 1248 | Iterable<IFlowPath> flowPathsObj = null; |
Umesh Krishnaswamy | ea0f4ab | 2013-03-26 18:49:35 -0700 | [diff] [blame] | 1249 | ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>(); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1250 | |
| 1251 | try { |
| 1252 | if ((flowPathsObj = conn.utils().getAllFlowPaths(conn)) != null) { |
| 1253 | log.debug("Get all FlowPaths: found FlowPaths"); |
| 1254 | } else { |
| 1255 | log.debug("Get all FlowPaths: no FlowPaths found"); |
| 1256 | } |
| 1257 | } catch (Exception e) { |
| 1258 | // TODO: handle exceptions |
| 1259 | conn.endTx(Transaction.ROLLBACK); |
| 1260 | log.error(":getAllFlowPaths failed"); |
| 1261 | } |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 1262 | if ((flowPathsObj == null) || (flowPathsObj.iterator().hasNext() == false)) { |
| 1263 | conn.endTx(Transaction.COMMIT); |
Umesh Krishnaswamy | ea0f4ab | 2013-03-26 18:49:35 -0700 | [diff] [blame] | 1264 | return flowPaths; // No Flows found |
Pavlin Radoslavov | 89c8f43 | 2013-03-15 18:50:46 -0700 | [diff] [blame] | 1265 | } |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1266 | |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1267 | for (IFlowPath flowObj : flowPathsObj) { |
| 1268 | // |
| 1269 | // Extract the Flow state |
| 1270 | // |
| 1271 | FlowPath flowPath = extractFlowPath(flowObj); |
Pavlin Radoslavov | 3f2af73 | 2013-03-29 15:29:35 -0700 | [diff] [blame] | 1272 | if (flowPath != null) |
| 1273 | flowPaths.add(flowPath); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | conn.endTx(Transaction.COMMIT); |
| 1277 | |
| 1278 | return flowPaths; |
| 1279 | } |
| 1280 | |
| 1281 | /** |
| 1282 | * Extract Flow Path State from a Titan Database Object @ref IFlowPath. |
| 1283 | * |
| 1284 | * @param flowObj the object to extract the Flow Path State from. |
| 1285 | * @return the extracted Flow Path State. |
| 1286 | */ |
| 1287 | private FlowPath extractFlowPath(IFlowPath flowObj) { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 1288 | FlowPath flowPath = new FlowPath(); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 1289 | |
| 1290 | // |
| 1291 | // Extract the Flow state |
| 1292 | // |
Pavlin Radoslavov | c287768 | 2013-03-27 16:40:07 -0700 | [diff] [blame] | 1293 | String flowIdStr = flowObj.getFlowId(); |
| 1294 | String installerIdStr = flowObj.getInstallerId(); |
| 1295 | String srcSwitchStr = flowObj.getSrcSwitch(); |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1296 | Short srcPortShort = flowObj.getSrcPort(); |
Pavlin Radoslavov | c287768 | 2013-03-27 16:40:07 -0700 | [diff] [blame] | 1297 | String dstSwitchStr = flowObj.getDstSwitch(); |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1298 | Short dstPortShort = flowObj.getDstPort(); |
Pavlin Radoslavov | c287768 | 2013-03-27 16:40:07 -0700 | [diff] [blame] | 1299 | |
| 1300 | if ((flowIdStr == null) || |
| 1301 | (installerIdStr == null) || |
| 1302 | (srcSwitchStr == null) || |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1303 | (srcPortShort == null) || |
Pavlin Radoslavov | c287768 | 2013-03-27 16:40:07 -0700 | [diff] [blame] | 1304 | (dstSwitchStr == null) || |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1305 | (dstPortShort == null)) { |
Pavlin Radoslavov | c287768 | 2013-03-27 16:40:07 -0700 | [diff] [blame] | 1306 | // TODO: A work-around, becauuse of some bogus database objects |
| 1307 | return null; |
| 1308 | } |
| 1309 | |
| 1310 | flowPath.setFlowId(new FlowId(flowIdStr)); |
| 1311 | flowPath.setInstallerId(new CallerId(installerIdStr)); |
| 1312 | flowPath.dataPath().srcPort().setDpid(new Dpid(srcSwitchStr)); |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1313 | flowPath.dataPath().srcPort().setPort(new Port(srcPortShort)); |
Pavlin Radoslavov | c287768 | 2013-03-27 16:40:07 -0700 | [diff] [blame] | 1314 | flowPath.dataPath().dstPort().setDpid(new Dpid(dstSwitchStr)); |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1315 | flowPath.dataPath().dstPort().setPort(new Port(dstPortShort)); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1316 | // |
| 1317 | // Extract the match conditions common for all Flow Entries |
| 1318 | // |
| 1319 | { |
| 1320 | FlowEntryMatch match = new FlowEntryMatch(); |
| 1321 | Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType(); |
| 1322 | if (matchEthernetFrameType != null) |
| 1323 | match.enableEthernetFrameType(matchEthernetFrameType); |
| 1324 | String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net(); |
| 1325 | if (matchSrcIPv4Net != null) |
| 1326 | match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net)); |
| 1327 | String matchDstIPv4Net = flowObj.getMatchDstIPv4Net(); |
| 1328 | if (matchDstIPv4Net != null) |
| 1329 | match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net)); |
| 1330 | String matchSrcMac = flowObj.getMatchSrcMac(); |
| 1331 | if (matchSrcMac != null) |
| 1332 | match.enableSrcMac(MACAddress.valueOf(matchSrcMac)); |
| 1333 | String matchDstMac = flowObj.getMatchDstMac(); |
| 1334 | if (matchDstMac != null) |
| 1335 | match.enableDstMac(MACAddress.valueOf(matchDstMac)); |
| 1336 | flowPath.setFlowEntryMatch(match); |
| 1337 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 1338 | |
| 1339 | // |
| 1340 | // Extract all Flow Entries |
| 1341 | // |
| 1342 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
| 1343 | for (IFlowEntry flowEntryObj : flowEntries) { |
| 1344 | FlowEntry flowEntry = new FlowEntry(); |
Pavlin Radoslavov | c287768 | 2013-03-27 16:40:07 -0700 | [diff] [blame] | 1345 | String flowEntryIdStr = flowEntryObj.getFlowEntryId(); |
| 1346 | String switchDpidStr = flowEntryObj.getSwitchDpid(); |
| 1347 | String userState = flowEntryObj.getUserState(); |
| 1348 | String switchState = flowEntryObj.getSwitchState(); |
| 1349 | |
| 1350 | if ((flowEntryIdStr == null) || |
| 1351 | (switchDpidStr == null) || |
| 1352 | (userState == null) || |
| 1353 | (switchState == null)) { |
| 1354 | // TODO: A work-around, becauuse of some bogus database objects |
| 1355 | continue; |
| 1356 | } |
| 1357 | flowEntry.setFlowEntryId(new FlowEntryId(flowEntryIdStr)); |
| 1358 | flowEntry.setDpid(new Dpid(switchDpidStr)); |
Pavlin Radoslavov | e2f0de8 | 2013-03-12 01:39:30 -0700 | [diff] [blame] | 1359 | |
| 1360 | // |
| 1361 | // Extract the match conditions |
| 1362 | // |
| 1363 | FlowEntryMatch match = new FlowEntryMatch(); |
| 1364 | Short matchInPort = flowEntryObj.getMatchInPort(); |
| 1365 | if (matchInPort != null) |
| 1366 | match.enableInPort(new Port(matchInPort)); |
| 1367 | Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType(); |
| 1368 | if (matchEthernetFrameType != null) |
| 1369 | match.enableEthernetFrameType(matchEthernetFrameType); |
| 1370 | String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net(); |
| 1371 | if (matchSrcIPv4Net != null) |
| 1372 | match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net)); |
| 1373 | String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net(); |
| 1374 | if (matchDstIPv4Net != null) |
| 1375 | match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net)); |
| 1376 | String matchSrcMac = flowEntryObj.getMatchSrcMac(); |
| 1377 | if (matchSrcMac != null) |
| 1378 | match.enableSrcMac(MACAddress.valueOf(matchSrcMac)); |
| 1379 | String matchDstMac = flowEntryObj.getMatchDstMac(); |
| 1380 | if (matchDstMac != null) |
| 1381 | match.enableDstMac(MACAddress.valueOf(matchDstMac)); |
| 1382 | flowEntry.setFlowEntryMatch(match); |
| 1383 | |
| 1384 | // |
| 1385 | // Extract the actions |
| 1386 | // |
| 1387 | ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>(); |
| 1388 | Short actionOutputPort = flowEntryObj.getActionOutput(); |
| 1389 | if (actionOutputPort != null) { |
| 1390 | FlowEntryAction action = new FlowEntryAction(); |
| 1391 | action.setActionOutput(new Port(actionOutputPort)); |
| 1392 | actions.add(action); |
| 1393 | } |
| 1394 | flowEntry.setFlowEntryActions(actions); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 1395 | flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState)); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 1396 | flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState)); |
| 1397 | // |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 1398 | // TODO: Take care of the FlowEntryMatch, FlowEntryAction set, |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 1399 | // and FlowEntryErrorState. |
| 1400 | // |
| 1401 | flowPath.dataPath().flowEntries().add(flowEntry); |
| 1402 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 1403 | |
| 1404 | return flowPath; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 1405 | } |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1406 | |
| 1407 | /** |
| 1408 | * Add and maintain a shortest-path flow. |
| 1409 | * |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1410 | * NOTE: The Flow Path argument does NOT contain flow entries. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1411 | * |
| 1412 | * @param flowPath the Flow Path with the endpoints and the match |
| 1413 | * conditions to install. |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1414 | * @return the added shortest-path flow on success, otherwise null. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1415 | */ |
| 1416 | @Override |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1417 | public FlowPath addAndMaintainShortestPathFlow(FlowPath flowPath) { |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1418 | String dataPathSummaryStr = null; |
| 1419 | |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1420 | // |
| 1421 | // Do the shortest path computation |
| 1422 | // |
| 1423 | DataPath dataPath = |
| 1424 | topoRouteService.getShortestPath(flowPath.dataPath().srcPort(), |
| 1425 | flowPath.dataPath().dstPort()); |
Pavlin Radoslavov | b2b6d4f | 2013-04-01 21:27:31 +0000 | [diff] [blame] | 1426 | if (dataPath == null) { |
| 1427 | // We need the DataPath to populate the Network MAP |
| 1428 | dataPath = new DataPath(); |
| 1429 | dataPath.setSrcPort(flowPath.dataPath().srcPort()); |
| 1430 | dataPath.setDstPort(flowPath.dataPath().dstPort()); |
| 1431 | } |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1432 | |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1433 | // Compute the Data Path summary |
| 1434 | dataPathSummaryStr = dataPath.dataPathSummary(); |
| 1435 | |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1436 | // |
| 1437 | // Set the incoming port matching and the outgoing port output |
| 1438 | // actions for each flow entry. |
| 1439 | // |
| 1440 | for (FlowEntry flowEntry : dataPath.flowEntries()) { |
| 1441 | // Set the incoming port matching |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1442 | FlowEntryMatch flowEntryMatch = new FlowEntryMatch(); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1443 | flowEntry.setFlowEntryMatch(flowEntryMatch); |
| 1444 | flowEntryMatch.enableInPort(flowEntry.inPort()); |
| 1445 | |
| 1446 | // Set the outgoing port output action |
| 1447 | ArrayList<FlowEntryAction> flowEntryActions = flowEntry.flowEntryActions(); |
| 1448 | if (flowEntryActions == null) { |
| 1449 | flowEntryActions = new ArrayList<FlowEntryAction>(); |
| 1450 | flowEntry.setFlowEntryActions(flowEntryActions); |
| 1451 | } |
| 1452 | FlowEntryAction flowEntryAction = new FlowEntryAction(); |
| 1453 | flowEntryAction.setActionOutput(flowEntry.outPort()); |
| 1454 | flowEntryActions.add(flowEntryAction); |
| 1455 | } |
| 1456 | |
| 1457 | // |
| 1458 | // Prepare the computed Flow Path |
| 1459 | // |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1460 | FlowPath computedFlowPath = new FlowPath(); |
| 1461 | computedFlowPath.setFlowId(new FlowId(flowPath.flowId().value())); |
| 1462 | computedFlowPath.setInstallerId(new CallerId(flowPath.installerId().value())); |
| 1463 | computedFlowPath.setDataPath(dataPath); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1464 | computedFlowPath.setFlowEntryMatch(new FlowEntryMatch(flowPath.flowEntryMatch())); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1465 | |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1466 | FlowId flowId = new FlowId(); |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1467 | if (! addFlow(computedFlowPath, flowId, dataPathSummaryStr)) |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1468 | return null; |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1469 | |
| 1470 | // TODO: Mark the flow for maintenance purpose |
| 1471 | |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1472 | return (computedFlowPath); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | /** |
| 1476 | * Create a Flow from port to port. |
| 1477 | * |
| 1478 | * TODO: We don't need it for now. |
| 1479 | * |
| 1480 | * @param src_port the source port. |
| 1481 | * @param dest_port the destination port. |
| 1482 | */ |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1483 | @Override |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1484 | public void createFlow(IPortObject src_port, IPortObject dest_port) { |
| 1485 | // TODO: We don't need it for now. |
| 1486 | } |
| 1487 | |
| 1488 | /** |
| 1489 | * Get all Flows matching a source and a destination port. |
| 1490 | * |
| 1491 | * TODO: Pankaj might be implementing it later. |
| 1492 | * |
| 1493 | * @param src_port the source port to match. |
| 1494 | * @param dest_port the destination port to match. |
| 1495 | * @return all flows matching the source and the destination port. |
| 1496 | */ |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1497 | @Override |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1498 | public Iterable<FlowPath> getFlows(IPortObject src_port, |
| 1499 | IPortObject dest_port) { |
| 1500 | // TODO: Pankaj might be implementing it later. |
| 1501 | return null; |
| 1502 | } |
| 1503 | |
| 1504 | /** |
| 1505 | * Get all Flows going out from a port. |
| 1506 | * |
| 1507 | * TODO: We need it now: Pankaj |
| 1508 | * |
| 1509 | * @param port the port to match. |
| 1510 | * @return the list of flows that are going out from the port. |
| 1511 | */ |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1512 | @Override |
Pankaj Berde | 83d8338 | 2013-03-28 13:55:34 -0700 | [diff] [blame] | 1513 | public Iterable<FlowPath> getOutFlows(IPortObject port) { |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1514 | // TODO: We need it now: Pankaj |
| 1515 | return null; |
| 1516 | } |
| 1517 | |
| 1518 | /** |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1519 | * Reconcile all flows on inactive switch port. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1520 | * |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1521 | * @param portObject the port that has become inactive. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1522 | */ |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1523 | @Override |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1524 | public void reconcileFlows(IPortObject portObject) { |
| 1525 | Iterable<IFlowEntry> inFlowEntries = portObject.getInFlowEntries(); |
| 1526 | Iterable<IFlowEntry> outFlowEntries = portObject.getOutFlowEntries(); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1527 | |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1528 | // |
| 1529 | // Collect all affected Flow IDs from the affected flow entries |
| 1530 | // |
| 1531 | HashSet<IFlowPath> flowObjSet = new HashSet<IFlowPath>(); |
| 1532 | for (IFlowEntry flowEntryObj: inFlowEntries) { |
| 1533 | IFlowPath flowObj = flowEntryObj.getFlow(); |
| 1534 | if (flowObj != null) |
| 1535 | flowObjSet.add(flowObj); |
| 1536 | } |
| 1537 | for (IFlowEntry flowEntryObj: outFlowEntries) { |
| 1538 | IFlowPath flowObj = flowEntryObj.getFlow(); |
| 1539 | if (flowObj != null) |
| 1540 | flowObjSet.add(flowObj); |
| 1541 | } |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1542 | |
| 1543 | // Reconcile the affected flows |
| 1544 | reconcileFlows(flowObjSet); |
| 1545 | } |
| 1546 | |
| 1547 | /** |
| 1548 | * Reconcile all flows in a set. |
| 1549 | * |
| 1550 | * @param flowObjSet the set of flows that need to be reconciliated. |
| 1551 | */ |
| 1552 | public void reconcileFlows(Iterable<IFlowPath> flowObjSet) { |
| 1553 | if (! flowObjSet.iterator().hasNext()) |
| 1554 | return; |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1555 | |
| 1556 | // |
| 1557 | // Remove the old Flow Entries, and add the new Flow Entries |
| 1558 | // |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1559 | |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1560 | Map<Long, IOFSwitch> mySwitches = floodlightProvider.getSwitches(); |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1561 | LinkedList<FlowPath> flowPaths = new LinkedList<FlowPath>(); |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1562 | for (IFlowPath flowObj : flowObjSet) { |
| 1563 | FlowPath flowPath = extractFlowPath(flowObj); |
| 1564 | if (flowPath == null) |
| 1565 | continue; |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1566 | flowPaths.add(flowPath); |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1567 | |
| 1568 | // |
Pavlin Radoslavov | b2b6d4f | 2013-04-01 21:27:31 +0000 | [diff] [blame] | 1569 | // Remove the Flow Entries from the Network MAP |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1570 | // |
| 1571 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1572 | LinkedList<IFlowEntry> deleteFlowEntries = new LinkedList<IFlowEntry>(); |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1573 | for (IFlowEntry flowEntryObj : flowEntries) { |
| 1574 | String dpidStr = flowEntryObj.getSwitchDpid(); |
| 1575 | if (dpidStr == null) |
| 1576 | continue; |
| 1577 | Dpid dpid = new Dpid(dpidStr); |
Pavlin Radoslavov | b2b6d4f | 2013-04-01 21:27:31 +0000 | [diff] [blame] | 1578 | /* |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1579 | IOFSwitch mySwitch = mySwitches.get(dpid.value()); |
| 1580 | if (mySwitch == null) |
| 1581 | continue; // Ignore the entry: not my switch |
Pavlin Radoslavov | b2b6d4f | 2013-04-01 21:27:31 +0000 | [diff] [blame] | 1582 | */ |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1583 | deleteFlowEntries.add(flowEntryObj); |
| 1584 | } |
| 1585 | for (IFlowEntry flowEntryObj : deleteFlowEntries) { |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1586 | flowObj.removeFlowEntry(flowEntryObj); |
| 1587 | conn.utils().removeFlowEntry(conn, flowEntryObj); |
| 1588 | } |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1589 | } |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1590 | |
Pavlin Radoslavov | dbaaf2e | 2013-03-29 04:25:55 -0700 | [diff] [blame] | 1591 | for (FlowPath flowPath : flowPaths) { |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1592 | // |
| 1593 | // Delete the flow entries from the switches |
| 1594 | // |
| 1595 | for (FlowEntry flowEntry : flowPath.dataPath().flowEntries()) { |
| 1596 | flowEntry.setFlowEntryUserState(FlowEntryUserState.FE_USER_DELETE); |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 1597 | IOFSwitch mySwitch = mySwitches.get(flowEntry.dpid().value()); |
| 1598 | if (mySwitch == null) { |
| 1599 | // Not my switch |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1600 | installRemoteFlowEntry(flowPath, flowEntry); |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 1601 | } else { |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1602 | installFlowEntry(mySwitch, flowPath, flowEntry); |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 1603 | } |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | // |
| 1607 | // Calculate the new shortest path and install it in the |
| 1608 | // Network MAP. |
| 1609 | // |
| 1610 | FlowPath addedFlowPath = addAndMaintainShortestPathFlow(flowPath); |
| 1611 | if (addedFlowPath == null) { |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 1612 | log.error("Cannot add Shortest Path Flow from {} to {}: path not found?", |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1613 | flowPath.dataPath().srcPort().toString(), |
| 1614 | flowPath.dataPath().dstPort().toString()); |
| 1615 | continue; |
| 1616 | } |
| 1617 | |
| 1618 | // |
| 1619 | // Add the flow entries to the switches |
| 1620 | // |
| 1621 | for (FlowEntry flowEntry : addedFlowPath.dataPath().flowEntries()) { |
| 1622 | flowEntry.setFlowEntryUserState(FlowEntryUserState.FE_USER_ADD); |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 1623 | IOFSwitch mySwitch = mySwitches.get(flowEntry.dpid().value()); |
| 1624 | if (mySwitch == null) { |
| 1625 | // Not my switch |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1626 | installRemoteFlowEntry(addedFlowPath, flowEntry); |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 1627 | continue; |
| 1628 | } |
| 1629 | |
| 1630 | IFlowEntry flowEntryObj = |
| 1631 | conn.utils().searchFlowEntry(conn, flowEntry.flowEntryId()); |
| 1632 | if (flowEntryObj == null) { |
| 1633 | // |
| 1634 | // TODO: Remove the "new Object[] wrapper in the statement |
| 1635 | // below after the SLF4J logger is upgraded to |
| 1636 | // Version 1.7.5 |
| 1637 | // |
| 1638 | log.error("Cannot add Flow Entry to switch {} for Path Flow from {} to {} : Flow Entry not in the Network MAP", |
| 1639 | new Object[] { |
| 1640 | flowEntry.dpid(), |
| 1641 | flowPath.dataPath().srcPort(), |
| 1642 | flowPath.dataPath().dstPort() |
| 1643 | }); |
| 1644 | continue; |
| 1645 | } |
| 1646 | // Update the Flow Entry Switch State in the Network MAP |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1647 | if (installFlowEntry(mySwitch, addedFlowPath, flowEntry)) { |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 1648 | flowEntryObj.setSwitchState("FE_SWITCH_UPDATED"); |
| 1649 | } |
Pavlin Radoslavov | e057529 | 2013-03-28 05:35:25 -0700 | [diff] [blame] | 1650 | } |
| 1651 | } |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | /** |
| 1655 | * Reconcile all flows between a source and a destination port. |
| 1656 | * |
| 1657 | * TODO: We don't need it for now. |
| 1658 | * |
| 1659 | * @param src_port the source port. |
| 1660 | * @param dest_port the destination port. |
| 1661 | */ |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1662 | @Override |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1663 | public void reconcileFlow(IPortObject src_port, IPortObject dest_port) { |
| 1664 | // TODO: We don't need it for now. |
| 1665 | } |
| 1666 | |
| 1667 | /** |
| 1668 | * Compute the shortest path between a source and a destination ports. |
| 1669 | * |
| 1670 | * @param src_port the source port. |
| 1671 | * @param dest_port the destination port. |
| 1672 | * @return the computed shortest path between the source and the |
| 1673 | * destination ports. The flow entries in the path itself would |
| 1674 | * contain the incoming port matching and the outgoing port output |
| 1675 | * actions set. However, the path itself will NOT have the Flow ID, |
| 1676 | * Installer ID, and any additional matching conditions for the |
| 1677 | * flow entries (e.g., source or destination MAC address, etc). |
| 1678 | */ |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1679 | @Override |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1680 | public FlowPath computeFlowPath(IPortObject src_port, |
| 1681 | IPortObject dest_port) { |
| 1682 | // |
| 1683 | // Prepare the arguments |
| 1684 | // |
| 1685 | String dpidStr = src_port.getSwitch().getDPID(); |
| 1686 | Dpid srcDpid = new Dpid(dpidStr); |
| 1687 | Port srcPort = new Port(src_port.getNumber()); |
| 1688 | |
| 1689 | dpidStr = dest_port.getSwitch().getDPID(); |
| 1690 | Dpid dstDpid = new Dpid(dpidStr); |
| 1691 | Port dstPort = new Port(dest_port.getNumber()); |
| 1692 | |
| 1693 | SwitchPort src = new SwitchPort(srcDpid, srcPort); |
| 1694 | SwitchPort dst = new SwitchPort(dstDpid, dstPort); |
| 1695 | |
| 1696 | // |
| 1697 | // Do the shortest path computation |
| 1698 | // |
| 1699 | DataPath dataPath = topoRouteService.getShortestPath(src, dst); |
| 1700 | if (dataPath == null) |
| 1701 | return null; |
| 1702 | |
| 1703 | // |
| 1704 | // Set the incoming port matching and the outgoing port output |
| 1705 | // actions for each flow entry. |
| 1706 | // |
| 1707 | for (FlowEntry flowEntry : dataPath.flowEntries()) { |
| 1708 | // Set the incoming port matching |
| 1709 | FlowEntryMatch flowEntryMatch = flowEntry.flowEntryMatch(); |
| 1710 | if (flowEntryMatch == null) { |
| 1711 | flowEntryMatch = new FlowEntryMatch(); |
| 1712 | flowEntry.setFlowEntryMatch(flowEntryMatch); |
| 1713 | } |
| 1714 | flowEntryMatch.enableInPort(flowEntry.inPort()); |
| 1715 | |
| 1716 | // Set the outgoing port output action |
| 1717 | ArrayList<FlowEntryAction> flowEntryActions = flowEntry.flowEntryActions(); |
| 1718 | if (flowEntryActions == null) { |
| 1719 | flowEntryActions = new ArrayList<FlowEntryAction>(); |
| 1720 | flowEntry.setFlowEntryActions(flowEntryActions); |
| 1721 | } |
| 1722 | FlowEntryAction flowEntryAction = new FlowEntryAction(); |
| 1723 | flowEntryAction.setActionOutput(flowEntry.outPort()); |
| 1724 | flowEntryActions.add(flowEntryAction); |
| 1725 | } |
| 1726 | |
| 1727 | // |
| 1728 | // Prepare the return result |
| 1729 | // |
| 1730 | FlowPath flowPath = new FlowPath(); |
| 1731 | flowPath.setDataPath(dataPath); |
| 1732 | |
| 1733 | return flowPath; |
| 1734 | } |
| 1735 | |
| 1736 | /** |
| 1737 | * Get all Flow Entries of a Flow. |
| 1738 | * |
| 1739 | * @param flow the flow whose flow entries should be returned. |
| 1740 | * @return the flow entries of the flow. |
| 1741 | */ |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1742 | @Override |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1743 | public Iterable<FlowEntry> getFlowEntries(FlowPath flow) { |
| 1744 | return flow.dataPath().flowEntries(); |
| 1745 | } |
| 1746 | |
| 1747 | /** |
| 1748 | * Install a Flow Entry on a switch. |
| 1749 | * |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 1750 | * @param mySwitch the switch to install the Flow Entry into. |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1751 | * @param flowPath the flow path for the flow entry to install. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1752 | * @param flowEntry the flow entry to install. |
| 1753 | * @return true on success, otherwise false. |
| 1754 | */ |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1755 | @Override |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1756 | public boolean installFlowEntry(IOFSwitch mySwitch, FlowPath flowPath, |
| 1757 | FlowEntry flowEntry) { |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1758 | // |
| 1759 | // Create the OpenFlow Flow Modification Entry to push |
| 1760 | // |
| 1761 | OFFlowMod fm = (OFFlowMod) floodlightProvider.getOFMessageFactory() |
| 1762 | .getMessage(OFType.FLOW_MOD); |
| 1763 | long cookie = flowEntry.flowEntryId().value(); |
| 1764 | |
| 1765 | short flowModCommand = OFFlowMod.OFPFC_ADD; |
| 1766 | if (flowEntry.flowEntryUserState() == FlowEntryUserState.FE_USER_ADD) { |
| 1767 | flowModCommand = OFFlowMod.OFPFC_ADD; |
| 1768 | } else if (flowEntry.flowEntryUserState() == FlowEntryUserState.FE_USER_MODIFY) { |
| 1769 | flowModCommand = OFFlowMod.OFPFC_MODIFY_STRICT; |
| 1770 | } else if (flowEntry.flowEntryUserState() == FlowEntryUserState.FE_USER_DELETE) { |
| 1771 | flowModCommand = OFFlowMod.OFPFC_DELETE_STRICT; |
| 1772 | } else { |
| 1773 | // Unknown user state. Ignore the entry |
| 1774 | log.debug("Flow Entry ignored (FlowEntryId = {}): unknown user state {}", |
| 1775 | flowEntry.flowEntryId().toString(), |
| 1776 | flowEntry.flowEntryUserState()); |
| 1777 | return false; |
| 1778 | } |
| 1779 | |
| 1780 | // |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1781 | // Fetch the match conditions. |
| 1782 | // |
| 1783 | // NOTE: The Flow matching conditions common for all Flow Entries are |
| 1784 | // used ONLY if a Flow Entry does NOT have the corresponding matching |
| 1785 | // condition set. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1786 | // |
| 1787 | OFMatch match = new OFMatch(); |
| 1788 | match.setWildcards(OFMatch.OFPFW_ALL); |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1789 | FlowEntryMatch flowPathMatch = flowPath.flowEntryMatch(); |
| 1790 | FlowEntryMatch flowEntryMatch = flowEntry.flowEntryMatch(); |
| 1791 | |
| 1792 | // Match the Incoming Port |
| 1793 | Port matchInPort = flowEntryMatch.inPort(); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1794 | if (matchInPort != null) { |
| 1795 | match.setInputPort(matchInPort.value()); |
| 1796 | match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_IN_PORT); |
| 1797 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1798 | |
| 1799 | // Match the Ethernet Frame Type |
| 1800 | Short matchEthernetFrameType = flowEntryMatch.ethernetFrameType(); |
| 1801 | if ((matchEthernetFrameType == null) && (flowPathMatch != null)) { |
| 1802 | matchEthernetFrameType = flowPathMatch.ethernetFrameType(); |
| 1803 | } |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1804 | if (matchEthernetFrameType != null) { |
| 1805 | match.setDataLayerType(matchEthernetFrameType); |
| 1806 | match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_TYPE); |
| 1807 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1808 | |
| 1809 | // Match the Source IPv4 Network prefix |
| 1810 | IPv4Net matchSrcIPv4Net = flowEntryMatch.srcIPv4Net(); |
| 1811 | if ((matchSrcIPv4Net == null) && (flowPathMatch != null)) { |
| 1812 | matchSrcIPv4Net = flowPathMatch.srcIPv4Net(); |
| 1813 | } |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1814 | if (matchSrcIPv4Net != null) { |
| 1815 | match.setFromCIDR(matchSrcIPv4Net.toString(), OFMatch.STR_NW_SRC); |
| 1816 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1817 | |
| 1818 | // Natch the Destination IPv4 Network prefix |
| 1819 | IPv4Net matchDstIPv4Net = flowEntryMatch.dstIPv4Net(); |
| 1820 | if ((matchDstIPv4Net == null) && (flowPathMatch != null)) { |
| 1821 | matchDstIPv4Net = flowPathMatch.dstIPv4Net(); |
| 1822 | } |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1823 | if (matchDstIPv4Net != null) { |
| 1824 | match.setFromCIDR(matchDstIPv4Net.toString(), OFMatch.STR_NW_DST); |
| 1825 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1826 | |
| 1827 | // Match the Source MAC address |
| 1828 | MACAddress matchSrcMac = flowEntryMatch.srcMac(); |
| 1829 | if ((matchSrcMac == null) && (flowPathMatch != null)) { |
| 1830 | matchSrcMac = flowPathMatch.srcMac(); |
| 1831 | } |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1832 | if (matchSrcMac != null) { |
| 1833 | match.setDataLayerSource(matchSrcMac.toString()); |
| 1834 | match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_SRC); |
| 1835 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1836 | |
| 1837 | // Match the Destination MAC address |
| 1838 | MACAddress matchDstMac = flowEntryMatch.dstMac(); |
| 1839 | if ((matchDstMac == null) && (flowPathMatch != null)) { |
| 1840 | matchDstMac = flowPathMatch.dstMac(); |
| 1841 | } |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1842 | if (matchDstMac != null) { |
| 1843 | match.setDataLayerDestination(matchDstMac.toString()); |
| 1844 | match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_DST); |
| 1845 | } |
| 1846 | |
| 1847 | // |
| 1848 | // Fetch the actions |
| 1849 | // |
| 1850 | // TODO: For now we support only the "OUTPUT" actions. |
| 1851 | // |
| 1852 | fm.setOutPort(OFPort.OFPP_NONE.getValue()); |
| 1853 | List<OFAction> actions = new ArrayList<OFAction>(); |
| 1854 | ArrayList<FlowEntryAction> flowEntryActions = |
| 1855 | flowEntry.flowEntryActions(); |
| 1856 | for (FlowEntryAction flowEntryAction : flowEntryActions) { |
| 1857 | FlowEntryAction.ActionOutput actionOutput = |
| 1858 | flowEntryAction.actionOutput(); |
| 1859 | if (actionOutput != null) { |
| 1860 | short actionOutputPort = actionOutput.port().value(); |
| 1861 | OFActionOutput action = new OFActionOutput(); |
| 1862 | // XXX: The max length is hard-coded for now |
| 1863 | action.setMaxLength((short)0xffff); |
| 1864 | action.setPort(actionOutputPort); |
| 1865 | actions.add(action); |
| 1866 | if ((flowModCommand == OFFlowMod.OFPFC_DELETE) || |
| 1867 | (flowModCommand == OFFlowMod.OFPFC_DELETE_STRICT)) { |
| 1868 | fm.setOutPort(actionOutputPort); |
| 1869 | } |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | fm.setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT) |
| 1874 | .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT) |
| 1875 | .setPriority(PRIORITY_DEFAULT) |
| 1876 | .setBufferId(OFPacketOut.BUFFER_ID_NONE) |
| 1877 | .setCookie(cookie) |
| 1878 | .setCommand(flowModCommand) |
| 1879 | .setMatch(match) |
| 1880 | .setActions(actions) |
| 1881 | .setLengthU(OFFlowMod.MINIMUM_LENGTH+OFActionOutput.MINIMUM_LENGTH); |
| 1882 | |
| 1883 | // |
| 1884 | // TODO: Set the following flag |
| 1885 | // fm.setFlags(OFFlowMod.OFPFF_SEND_FLOW_REM); |
| 1886 | // See method ForwardingBase::pushRoute() |
| 1887 | // |
| 1888 | |
| 1889 | // |
| 1890 | // Write the message to the switch |
| 1891 | // |
| 1892 | try { |
| 1893 | messageDamper.write(mySwitch, fm, null); |
| 1894 | mySwitch.flush(); |
| 1895 | } catch (IOException e) { |
| 1896 | log.error("Failure writing flow mod from network map", e); |
| 1897 | return false; |
| 1898 | } |
| 1899 | return true; |
| 1900 | } |
| 1901 | |
| 1902 | /** |
| 1903 | * Remove a Flow Entry from a switch. |
| 1904 | * |
Pavlin Radoslavov | 2b858f8 | 2013-03-28 11:37:37 -0700 | [diff] [blame] | 1905 | * @param mySwitch the switch to remove the Flow Entry from. |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1906 | * @param flowPath the flow path for the flow entry to remove. |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1907 | * @param flowEntry the flow entry to remove. |
| 1908 | * @return true on success, otherwise false. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1909 | */ |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1910 | @Override |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1911 | public boolean removeFlowEntry(IOFSwitch mySwitch, FlowPath flowPath, |
| 1912 | FlowEntry flowEntry) { |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1913 | // |
| 1914 | // The installFlowEntry() method implements both installation |
| 1915 | // and removal of flow entries. |
| 1916 | // |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1917 | return (installFlowEntry(mySwitch, flowPath, flowEntry)); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | /** |
| 1921 | * Install a Flow Entry on a remote controller. |
| 1922 | * |
| 1923 | * TODO: We need it now: Jono |
| 1924 | * - For now it will make a REST call to the remote controller. |
| 1925 | * - Internally, it needs to know the name of the remote controller. |
| 1926 | * |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1927 | * @param flowPath the flow path for the flow entry to install. |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1928 | * @param flowEntry the flow entry to install. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1929 | * @return true on success, otherwise false. |
| 1930 | */ |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1931 | @Override |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1932 | public boolean installRemoteFlowEntry(FlowPath flowPath, |
| 1933 | FlowEntry flowEntry) { |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1934 | // TODO: We need it now: Jono |
| 1935 | // - For now it will make a REST call to the remote controller. |
| 1936 | // - Internally, it needs to know the name of the remote controller. |
| 1937 | return true; |
| 1938 | } |
| 1939 | |
| 1940 | /** |
| 1941 | * Remove a flow entry on a remote controller. |
| 1942 | * |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1943 | * @param flowPath the flow path for the flow entry to remove. |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1944 | * @param flowEntry the flow entry to remove. |
| 1945 | * @return true on success, otherwise false. |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1946 | */ |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1947 | @Override |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1948 | public boolean removeRemoteFlowEntry(FlowPath flowPath, |
| 1949 | FlowEntry flowEntry) { |
Pavlin Radoslavov | 6b6f4a8 | 2013-03-28 03:30:00 -0700 | [diff] [blame] | 1950 | // |
| 1951 | // The installRemoteFlowEntry() method implements both installation |
| 1952 | // and removal of flow entries. |
| 1953 | // |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 1954 | return (installRemoteFlowEntry(flowPath, flowEntry)); |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 1955 | } |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 1956 | } |