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