Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.flowmanager; |
| 2 | |
| 3 | import java.io.PrintWriter; |
| 4 | import java.io.StringWriter; |
| 5 | import java.util.ArrayList; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 6 | import java.util.LinkedList; |
| 7 | import java.util.List; |
Pavlin Radoslavov | 16b761d | 2014-01-08 09:47:14 -0800 | [diff] [blame] | 8 | import java.util.Map; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 9 | |
Pavlin Radoslavov | 16b761d | 2014-01-08 09:47:14 -0800 | [diff] [blame] | 10 | import net.floodlightcontroller.core.IOFSwitch; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 11 | import net.floodlightcontroller.util.MACAddress; |
| 12 | |
| 13 | import net.onrc.onos.graph.GraphDBOperation; |
| 14 | |
| 15 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 16 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
| 17 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 18 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 19 | import net.onrc.onos.ofcontroller.util.*; |
| 20 | |
| 21 | import org.slf4j.Logger; |
| 22 | import org.slf4j.LoggerFactory; |
| 23 | |
| 24 | /** |
| 25 | * Class for performing Flow-related operations on the Database. |
| 26 | */ |
Pavlin Radoslavov | 6bfaea6 | 2013-12-03 14:55:57 -0800 | [diff] [blame] | 27 | public class FlowDatabaseOperation { |
Pavlin Radoslavov | 909da3c | 2014-01-09 04:04:33 -0800 | [diff] [blame^] | 28 | static private boolean enableOnrc2014MeasurementsFlows = true; |
| 29 | |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 30 | private final static Logger log = LoggerFactory.getLogger(FlowDatabaseOperation.class); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Add a flow. |
| 34 | * |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 35 | * @param dbHandler the Graph Database handler to use. |
| 36 | * @param flowPath the Flow Path to install. |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 37 | * @return true on success, otherwise false. |
| 38 | */ |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 39 | static boolean addFlow(GraphDBOperation dbHandler, FlowPath flowPath) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 40 | IFlowPath flowObj = null; |
| 41 | boolean found = false; |
| 42 | try { |
| 43 | if ((flowObj = dbHandler.searchFlowPath(flowPath.flowId())) != null) { |
| 44 | found = true; |
| 45 | } else { |
| 46 | flowObj = dbHandler.newFlowPath(); |
| 47 | } |
| 48 | } catch (Exception e) { |
| 49 | dbHandler.rollback(); |
| 50 | |
| 51 | StringWriter sw = new StringWriter(); |
| 52 | e.printStackTrace(new PrintWriter(sw)); |
| 53 | String stacktrace = sw.toString(); |
| 54 | |
| 55 | log.error(":addFlow FlowId:{} failed: {}", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 56 | flowPath.flowId(), |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 57 | stacktrace); |
| 58 | return false; |
| 59 | } |
| 60 | if (flowObj == null) { |
| 61 | log.error(":addFlow FlowId:{} failed: Flow object not created", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 62 | flowPath.flowId()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 63 | dbHandler.rollback(); |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | // |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 68 | // Remove the old Flow Entries |
| 69 | // |
| 70 | if (found) { |
| 71 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
| 72 | LinkedList<IFlowEntry> deleteFlowEntries = |
| 73 | new LinkedList<IFlowEntry>(); |
| 74 | for (IFlowEntry flowEntryObj : flowEntries) |
| 75 | deleteFlowEntries.add(flowEntryObj); |
| 76 | for (IFlowEntry flowEntryObj : deleteFlowEntries) { |
| 77 | flowObj.removeFlowEntry(flowEntryObj); |
| 78 | dbHandler.removeFlowEntry(flowEntryObj); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 83 | // Set the Flow key: |
| 84 | // - flowId |
| 85 | // |
| 86 | flowObj.setFlowId(flowPath.flowId().toString()); |
| 87 | flowObj.setType("flow"); |
| 88 | |
| 89 | // |
| 90 | // Set the Flow attributes: |
| 91 | // - flowPath.installerId() |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 92 | // - flowPath.flowPathType() |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 93 | // - flowPath.flowPathUserState() |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 94 | // - flowPath.flowPathFlags() |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 95 | // - flowPath.idleTimeout() |
| 96 | // - flowPath.hardTimeout() |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 97 | // - flowPath.dataPath().srcPort() |
| 98 | // - flowPath.dataPath().dstPort() |
| 99 | // - flowPath.matchSrcMac() |
| 100 | // - flowPath.matchDstMac() |
| 101 | // - flowPath.matchEthernetFrameType() |
| 102 | // - flowPath.matchVlanId() |
| 103 | // - flowPath.matchVlanPriority() |
| 104 | // - flowPath.matchSrcIPv4Net() |
| 105 | // - flowPath.matchDstIPv4Net() |
| 106 | // - flowPath.matchIpProto() |
| 107 | // - flowPath.matchIpToS() |
| 108 | // - flowPath.matchSrcTcpUdpPort() |
| 109 | // - flowPath.matchDstTcpUdpPort() |
| 110 | // - flowPath.flowEntryActions() |
| 111 | // |
| 112 | flowObj.setInstallerId(flowPath.installerId().toString()); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 113 | flowObj.setFlowPathType(flowPath.flowPathType().toString()); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 114 | flowObj.setFlowPathUserState(flowPath.flowPathUserState().toString()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 115 | flowObj.setFlowPathFlags(flowPath.flowPathFlags().flags()); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 116 | flowObj.setIdleTimeout(flowPath.idleTimeout()); |
| 117 | flowObj.setHardTimeout(flowPath.hardTimeout()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 118 | flowObj.setSrcSwitch(flowPath.dataPath().srcPort().dpid().toString()); |
| 119 | flowObj.setSrcPort(flowPath.dataPath().srcPort().port().value()); |
| 120 | flowObj.setDstSwitch(flowPath.dataPath().dstPort().dpid().toString()); |
| 121 | flowObj.setDstPort(flowPath.dataPath().dstPort().port().value()); |
| 122 | if (flowPath.flowEntryMatch().matchSrcMac()) { |
| 123 | flowObj.setMatchSrcMac(flowPath.flowEntryMatch().srcMac().toString()); |
| 124 | } |
| 125 | if (flowPath.flowEntryMatch().matchDstMac()) { |
| 126 | flowObj.setMatchDstMac(flowPath.flowEntryMatch().dstMac().toString()); |
| 127 | } |
| 128 | if (flowPath.flowEntryMatch().matchEthernetFrameType()) { |
| 129 | flowObj.setMatchEthernetFrameType(flowPath.flowEntryMatch().ethernetFrameType()); |
| 130 | } |
| 131 | if (flowPath.flowEntryMatch().matchVlanId()) { |
| 132 | flowObj.setMatchVlanId(flowPath.flowEntryMatch().vlanId()); |
| 133 | } |
| 134 | if (flowPath.flowEntryMatch().matchVlanPriority()) { |
| 135 | flowObj.setMatchVlanPriority(flowPath.flowEntryMatch().vlanPriority()); |
| 136 | } |
| 137 | if (flowPath.flowEntryMatch().matchSrcIPv4Net()) { |
| 138 | flowObj.setMatchSrcIPv4Net(flowPath.flowEntryMatch().srcIPv4Net().toString()); |
| 139 | } |
| 140 | if (flowPath.flowEntryMatch().matchDstIPv4Net()) { |
| 141 | flowObj.setMatchDstIPv4Net(flowPath.flowEntryMatch().dstIPv4Net().toString()); |
| 142 | } |
| 143 | if (flowPath.flowEntryMatch().matchIpProto()) { |
| 144 | flowObj.setMatchIpProto(flowPath.flowEntryMatch().ipProto()); |
| 145 | } |
| 146 | if (flowPath.flowEntryMatch().matchIpToS()) { |
| 147 | flowObj.setMatchIpToS(flowPath.flowEntryMatch().ipToS()); |
| 148 | } |
| 149 | if (flowPath.flowEntryMatch().matchSrcTcpUdpPort()) { |
| 150 | flowObj.setMatchSrcTcpUdpPort(flowPath.flowEntryMatch().srcTcpUdpPort()); |
| 151 | } |
| 152 | if (flowPath.flowEntryMatch().matchDstTcpUdpPort()) { |
| 153 | flowObj.setMatchDstTcpUdpPort(flowPath.flowEntryMatch().dstTcpUdpPort()); |
| 154 | } |
| 155 | if (! flowPath.flowEntryActions().actions().isEmpty()) { |
| 156 | flowObj.setActions(flowPath.flowEntryActions().toString()); |
| 157 | } |
Pavlin Radoslavov | bcc86ef | 2013-10-26 12:06:25 -0700 | [diff] [blame] | 158 | flowObj.setDataPathSummary(flowPath.dataPath().dataPathSummary()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 159 | |
| 160 | if (found) |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 161 | flowObj.setFlowPathUserState("FP_USER_MODIFY"); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 162 | else |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 163 | flowObj.setFlowPathUserState("FP_USER_ADD"); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 164 | |
| 165 | // Flow edges: |
| 166 | // HeadFE |
| 167 | |
| 168 | |
| 169 | // |
| 170 | // Flow Entries: |
| 171 | // flowPath.dataPath().flowEntries() |
| 172 | // |
| 173 | for (FlowEntry flowEntry : flowPath.dataPath().flowEntries()) { |
Pavlin Radoslavov | 909da3c | 2014-01-09 04:04:33 -0800 | [diff] [blame^] | 174 | if (! enableOnrc2014MeasurementsFlows) { |
| 175 | if (flowEntry.flowEntryUserState() == FlowEntryUserState.FE_USER_DELETE) |
| 176 | continue; // Skip: all Flow Entries were deleted earlier |
| 177 | } |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 178 | |
Pavlin Radoslavov | 67bf762 | 2013-12-04 12:28:23 -0800 | [diff] [blame] | 179 | if (addFlowEntry(dbHandler, flowObj, flowEntry) == null) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 180 | dbHandler.rollback(); |
| 181 | return false; |
| 182 | } |
| 183 | } |
| 184 | dbHandler.commit(); |
| 185 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 186 | return true; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Add a flow entry to the Network MAP. |
| 191 | * |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 192 | * @param dbHandler the Graph Database handler to use. |
| 193 | * @param flowObj the corresponding Flow Path object for the Flow Entry. |
| 194 | * @param flowEntry the Flow Entry to install. |
| 195 | * @return the added Flow Entry object on success, otherwise null. |
| 196 | */ |
Pavlin Radoslavov | 67bf762 | 2013-12-04 12:28:23 -0800 | [diff] [blame] | 197 | static IFlowEntry addFlowEntry(GraphDBOperation dbHandler, |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 198 | IFlowPath flowObj, |
| 199 | FlowEntry flowEntry) { |
| 200 | // Flow edges |
| 201 | // HeadFE (TODO) |
| 202 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 203 | IFlowEntry flowEntryObj = null; |
| 204 | boolean found = false; |
| 205 | try { |
| 206 | if ((flowEntryObj = |
| 207 | dbHandler.searchFlowEntry(flowEntry.flowEntryId())) != null) { |
| 208 | found = true; |
| 209 | } else { |
| 210 | flowEntryObj = dbHandler.newFlowEntry(); |
| 211 | } |
| 212 | } catch (Exception e) { |
| 213 | log.error(":addFlow FlowEntryId:{} failed", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 214 | flowEntry.flowEntryId()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 215 | return null; |
| 216 | } |
| 217 | if (flowEntryObj == null) { |
| 218 | log.error(":addFlow FlowEntryId:{} failed: FlowEntry object not created", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 219 | flowEntry.flowEntryId()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 220 | return null; |
| 221 | } |
| 222 | |
| 223 | // |
| 224 | // Set the Flow Entry key: |
| 225 | // - flowEntry.flowEntryId() |
| 226 | // |
| 227 | flowEntryObj.setFlowEntryId(flowEntry.flowEntryId().toString()); |
| 228 | flowEntryObj.setType("flow_entry"); |
| 229 | |
| 230 | // |
| 231 | // Set the Flow Entry Edges and attributes: |
| 232 | // - Switch edge |
| 233 | // - InPort edge |
| 234 | // - OutPort edge |
| 235 | // |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 236 | // - flowEntry.idleTimeout() |
| 237 | // - flowEntry.hardTimeout() |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 238 | // - flowEntry.dpid() |
| 239 | // - flowEntry.flowEntryUserState() |
| 240 | // - flowEntry.flowEntrySwitchState() |
| 241 | // - flowEntry.flowEntryErrorState() |
| 242 | // - flowEntry.matchInPort() |
| 243 | // - flowEntry.matchSrcMac() |
| 244 | // - flowEntry.matchDstMac() |
| 245 | // - flowEntry.matchEthernetFrameType() |
| 246 | // - flowEntry.matchVlanId() |
| 247 | // - flowEntry.matchVlanPriority() |
| 248 | // - flowEntry.matchSrcIPv4Net() |
| 249 | // - flowEntry.matchDstIPv4Net() |
| 250 | // - flowEntry.matchIpProto() |
| 251 | // - flowEntry.matchIpToS() |
| 252 | // - flowEntry.matchSrcTcpUdpPort() |
| 253 | // - flowEntry.matchDstTcpUdpPort() |
| 254 | // - flowEntry.actionOutputPort() |
| 255 | // - flowEntry.actions() |
| 256 | // |
| 257 | ISwitchObject sw = dbHandler.searchSwitch(flowEntry.dpid().toString()); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 258 | flowEntryObj.setIdleTimeout(flowEntry.idleTimeout()); |
| 259 | flowEntryObj.setHardTimeout(flowEntry.hardTimeout()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 260 | flowEntryObj.setSwitchDpid(flowEntry.dpid().toString()); |
| 261 | flowEntryObj.setSwitch(sw); |
| 262 | if (flowEntry.flowEntryMatch().matchInPort()) { |
Jonathan Hart | 5b3ad19 | 2013-12-06 17:34:46 -0800 | [diff] [blame] | 263 | IPortObject inport = |
| 264 | dbHandler.searchPort(flowEntry.dpid().toString(), |
| 265 | flowEntry.flowEntryMatch().inPort().value()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 266 | flowEntryObj.setMatchInPort(flowEntry.flowEntryMatch().inPort().value()); |
Jonathan Hart | 5b3ad19 | 2013-12-06 17:34:46 -0800 | [diff] [blame] | 267 | flowEntryObj.setInPort(inport); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 268 | } |
| 269 | if (flowEntry.flowEntryMatch().matchSrcMac()) { |
| 270 | flowEntryObj.setMatchSrcMac(flowEntry.flowEntryMatch().srcMac().toString()); |
| 271 | } |
| 272 | if (flowEntry.flowEntryMatch().matchDstMac()) { |
| 273 | flowEntryObj.setMatchDstMac(flowEntry.flowEntryMatch().dstMac().toString()); |
| 274 | } |
| 275 | if (flowEntry.flowEntryMatch().matchEthernetFrameType()) { |
| 276 | flowEntryObj.setMatchEthernetFrameType(flowEntry.flowEntryMatch().ethernetFrameType()); |
| 277 | } |
| 278 | if (flowEntry.flowEntryMatch().matchVlanId()) { |
| 279 | flowEntryObj.setMatchVlanId(flowEntry.flowEntryMatch().vlanId()); |
| 280 | } |
| 281 | if (flowEntry.flowEntryMatch().matchVlanPriority()) { |
| 282 | flowEntryObj.setMatchVlanPriority(flowEntry.flowEntryMatch().vlanPriority()); |
| 283 | } |
| 284 | if (flowEntry.flowEntryMatch().matchSrcIPv4Net()) { |
| 285 | flowEntryObj.setMatchSrcIPv4Net(flowEntry.flowEntryMatch().srcIPv4Net().toString()); |
| 286 | } |
| 287 | if (flowEntry.flowEntryMatch().matchDstIPv4Net()) { |
| 288 | flowEntryObj.setMatchDstIPv4Net(flowEntry.flowEntryMatch().dstIPv4Net().toString()); |
| 289 | } |
| 290 | if (flowEntry.flowEntryMatch().matchIpProto()) { |
| 291 | flowEntryObj.setMatchIpProto(flowEntry.flowEntryMatch().ipProto()); |
| 292 | } |
| 293 | if (flowEntry.flowEntryMatch().matchIpToS()) { |
| 294 | flowEntryObj.setMatchIpToS(flowEntry.flowEntryMatch().ipToS()); |
| 295 | } |
| 296 | if (flowEntry.flowEntryMatch().matchSrcTcpUdpPort()) { |
| 297 | flowEntryObj.setMatchSrcTcpUdpPort(flowEntry.flowEntryMatch().srcTcpUdpPort()); |
| 298 | } |
| 299 | if (flowEntry.flowEntryMatch().matchDstTcpUdpPort()) { |
| 300 | flowEntryObj.setMatchDstTcpUdpPort(flowEntry.flowEntryMatch().dstTcpUdpPort()); |
| 301 | } |
| 302 | |
| 303 | for (FlowEntryAction fa : flowEntry.flowEntryActions().actions()) { |
| 304 | if (fa.actionOutput() != null) { |
Jonathan Hart | 5b3ad19 | 2013-12-06 17:34:46 -0800 | [diff] [blame] | 305 | IPortObject outport = |
| 306 | dbHandler.searchPort(flowEntry.dpid().toString(), |
| 307 | fa.actionOutput().port().value()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 308 | flowEntryObj.setActionOutputPort(fa.actionOutput().port().value()); |
Jonathan Hart | 5b3ad19 | 2013-12-06 17:34:46 -0800 | [diff] [blame] | 309 | flowEntryObj.setOutPort(outport); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | if (! flowEntry.flowEntryActions().isEmpty()) { |
| 313 | flowEntryObj.setActions(flowEntry.flowEntryActions().toString()); |
| 314 | } |
| 315 | |
| 316 | // TODO: Hacks with hard-coded state names! |
| 317 | if (found) |
| 318 | flowEntryObj.setUserState("FE_USER_MODIFY"); |
| 319 | else |
| 320 | flowEntryObj.setUserState("FE_USER_ADD"); |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 321 | flowEntryObj.setSwitchState(flowEntry.flowEntrySwitchState().toString()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 322 | // |
| 323 | // TODO: Take care of the FlowEntryErrorState. |
| 324 | // |
| 325 | |
| 326 | // Flow Entries edges: |
| 327 | // Flow |
| 328 | // NextFE (TODO) |
| 329 | if (! found) { |
| 330 | flowObj.addFlowEntry(flowEntryObj); |
| 331 | flowEntryObj.setFlow(flowObj); |
| 332 | } |
| 333 | |
| 334 | return flowEntryObj; |
| 335 | } |
| 336 | |
| 337 | /** |
Pavlin Radoslavov | 7407ab5 | 2013-11-01 22:19:00 -0700 | [diff] [blame] | 338 | * Delete a flow entry from the Network MAP. |
| 339 | * |
| 340 | * @param dbHandler the Graph Database handler to use. |
| 341 | * @param flowObj the corresponding Flow Path object for the Flow Entry. |
| 342 | * @param flowEntry the Flow Entry to delete. |
| 343 | * @return true on success, otherwise false. |
| 344 | */ |
| 345 | static boolean deleteFlowEntry(GraphDBOperation dbHandler, |
| 346 | IFlowPath flowObj, |
| 347 | FlowEntry flowEntry) { |
| 348 | IFlowEntry flowEntryObj = null; |
| 349 | try { |
| 350 | flowEntryObj = dbHandler.searchFlowEntry(flowEntry.flowEntryId()); |
| 351 | } catch (Exception e) { |
| 352 | log.error(":deleteFlowEntry FlowEntryId:{} failed", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 353 | flowEntry.flowEntryId()); |
Pavlin Radoslavov | 7407ab5 | 2013-11-01 22:19:00 -0700 | [diff] [blame] | 354 | return false; |
| 355 | } |
| 356 | // |
| 357 | // TODO: Don't print an error for now, because multiple controller |
| 358 | // instances might be deleting the same flow entry. |
| 359 | // |
| 360 | /* |
| 361 | if (flowEntryObj == null) { |
| 362 | log.error(":deleteFlowEntry FlowEntryId:{} failed: FlowEntry object not found", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 363 | flowEntry.flowEntryId()); |
Pavlin Radoslavov | 7407ab5 | 2013-11-01 22:19:00 -0700 | [diff] [blame] | 364 | return false; |
| 365 | } |
| 366 | */ |
| 367 | if (flowEntryObj == null) |
| 368 | return true; |
| 369 | |
| 370 | flowObj.removeFlowEntry(flowEntryObj); |
| 371 | dbHandler.removeFlowEntry(flowEntryObj); |
| 372 | return true; |
| 373 | } |
| 374 | |
| 375 | /** |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 376 | * Delete all previously added flows. |
| 377 | * |
| 378 | * @param dbHandler the Graph Database handler to use. |
| 379 | * @return true on success, otherwise false. |
| 380 | */ |
| 381 | static boolean deleteAllFlows(GraphDBOperation dbHandler) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 382 | List<FlowId> allFlowIds = new LinkedList<FlowId>(); |
| 383 | |
| 384 | // Get all Flow IDs |
| 385 | Iterable<IFlowPath> allFlowPaths = dbHandler.getAllFlowPaths(); |
| 386 | for (IFlowPath flowPathObj : allFlowPaths) { |
| 387 | if (flowPathObj == null) |
| 388 | continue; |
| 389 | String flowIdStr = flowPathObj.getFlowId(); |
| 390 | if (flowIdStr == null) |
| 391 | continue; |
| 392 | FlowId flowId = new FlowId(flowIdStr); |
| 393 | allFlowIds.add(flowId); |
| 394 | } |
| 395 | |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 396 | // Delete all flows one-by-one |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 397 | for (FlowId flowId : allFlowIds) { |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 398 | deleteFlow(dbHandler, flowId); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | return true; |
| 402 | } |
| 403 | |
| 404 | /** |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 405 | * Delete a previously added flow. |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 406 | * |
| 407 | * @param dbHandler the Graph Database handler to use. |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 408 | * @param flowId the Flow ID of the flow to delete. |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 409 | * @return true on success, otherwise false. |
| 410 | */ |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 411 | static boolean deleteFlow(GraphDBOperation dbHandler, FlowId flowId) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 412 | IFlowPath flowObj = null; |
| 413 | try { |
| 414 | flowObj = dbHandler.searchFlowPath(flowId); |
| 415 | } catch (Exception e) { |
| 416 | // TODO: handle exceptions |
| 417 | dbHandler.rollback(); |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 418 | log.error(":deleteFlow FlowId:{} failed", flowId); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 419 | return false; |
| 420 | } |
| 421 | if (flowObj == null) { |
| 422 | dbHandler.commit(); |
| 423 | return true; // OK: No such flow |
| 424 | } |
| 425 | |
| 426 | // |
| 427 | // Remove all Flow Entries |
| 428 | // |
| 429 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
| 430 | for (IFlowEntry flowEntryObj : flowEntries) { |
| 431 | flowObj.removeFlowEntry(flowEntryObj); |
| 432 | dbHandler.removeFlowEntry(flowEntryObj); |
| 433 | } |
| 434 | // Remove the Flow itself |
| 435 | dbHandler.removeFlowPath(flowObj); |
| 436 | dbHandler.commit(); |
| 437 | |
| 438 | return true; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Get a previously added flow. |
| 443 | * |
| 444 | * @param dbHandler the Graph Database handler to use. |
| 445 | * @param flowId the Flow ID of the flow to get. |
| 446 | * @return the Flow Path if found, otherwise null. |
| 447 | */ |
| 448 | static FlowPath getFlow(GraphDBOperation dbHandler, FlowId flowId) { |
| 449 | IFlowPath flowObj = null; |
| 450 | try { |
| 451 | flowObj = dbHandler.searchFlowPath(flowId); |
| 452 | } catch (Exception e) { |
| 453 | // TODO: handle exceptions |
| 454 | dbHandler.rollback(); |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 455 | log.error(":getFlow FlowId:{} failed", flowId); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 456 | return null; |
| 457 | } |
| 458 | if (flowObj == null) { |
| 459 | dbHandler.commit(); |
| 460 | return null; // Flow not found |
| 461 | } |
| 462 | |
| 463 | // |
| 464 | // Extract the Flow state |
| 465 | // |
| 466 | FlowPath flowPath = extractFlowPath(flowObj); |
| 467 | dbHandler.commit(); |
| 468 | |
| 469 | return flowPath; |
| 470 | } |
| 471 | |
| 472 | /** |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 473 | * Get the source switch DPID of a previously added flow. |
| 474 | * |
| 475 | * @param dbHandler the Graph Database handler to use. |
| 476 | * @param flowId the Flow ID of the flow to get. |
| 477 | * @return the source switch DPID if found, otherwise null. |
| 478 | */ |
| 479 | static Dpid getFlowSourceDpid(GraphDBOperation dbHandler, FlowId flowId) { |
| 480 | IFlowPath flowObj = null; |
| 481 | try { |
| 482 | flowObj = dbHandler.searchFlowPath(flowId); |
| 483 | } catch (Exception e) { |
| 484 | // TODO: handle exceptions |
| 485 | dbHandler.rollback(); |
| 486 | log.error(":getFlowSourceDpid FlowId:{} failed", flowId); |
| 487 | return null; |
| 488 | } |
| 489 | if (flowObj == null) { |
| 490 | dbHandler.commit(); |
| 491 | return null; // Flow not found |
| 492 | } |
| 493 | |
| 494 | // |
| 495 | // Extract the Flow Source DPID |
| 496 | // |
| 497 | String srcSwitchStr = flowObj.getSrcSwitch(); |
| 498 | if (srcSwitchStr == null) { |
| 499 | // TODO: A work-around, becauuse of some bogus database objects |
| 500 | dbHandler.commit(); |
| 501 | return null; |
| 502 | } |
| 503 | |
| 504 | Dpid dpid = new Dpid(srcSwitchStr); |
| 505 | |
| 506 | dbHandler.commit(); |
| 507 | |
| 508 | return dpid; |
| 509 | } |
| 510 | |
| 511 | /** |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 512 | * Get all installed flows by all installers. |
| 513 | * |
| 514 | * @param dbHandler the Graph Database handler to use. |
| 515 | * @return the Flow Paths if found, otherwise null. |
| 516 | */ |
| 517 | static ArrayList<FlowPath> getAllFlows(GraphDBOperation dbHandler) { |
| 518 | Iterable<IFlowPath> flowPathsObj = null; |
| 519 | ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>(); |
| 520 | |
| 521 | try { |
| 522 | flowPathsObj = dbHandler.getAllFlowPaths(); |
| 523 | } catch (Exception e) { |
| 524 | // TODO: handle exceptions |
| 525 | dbHandler.rollback(); |
| 526 | log.error(":getAllFlowPaths failed"); |
| 527 | return flowPaths; |
| 528 | } |
| 529 | if ((flowPathsObj == null) || (flowPathsObj.iterator().hasNext() == false)) { |
| 530 | dbHandler.commit(); |
| 531 | return flowPaths; // No Flows found |
| 532 | } |
| 533 | |
| 534 | for (IFlowPath flowObj : flowPathsObj) { |
| 535 | // |
| 536 | // Extract the Flow state |
| 537 | // |
| 538 | FlowPath flowPath = extractFlowPath(flowObj); |
| 539 | if (flowPath != null) |
| 540 | flowPaths.add(flowPath); |
| 541 | } |
| 542 | |
| 543 | dbHandler.commit(); |
| 544 | |
| 545 | return flowPaths; |
| 546 | } |
| 547 | |
| 548 | /** |
Pavlin Radoslavov | 16b761d | 2014-01-08 09:47:14 -0800 | [diff] [blame] | 549 | * Get all installed flows whose Source Switch is controlled by this |
| 550 | * instance. |
| 551 | * |
| 552 | * @param dbHandler the Graph Database handler to use. |
| 553 | * @param mySwitches the collection of the switches controlled by this |
| 554 | * instance. |
| 555 | * @return the Flow Paths if found, otherwise null. |
| 556 | */ |
| 557 | static ArrayList<FlowPath> getAllMyFlows(GraphDBOperation dbHandler, |
| 558 | Map<Long, IOFSwitch> mySwitches) { |
| 559 | Iterable<IFlowPath> flowPathsObj = null; |
| 560 | ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>(); |
| 561 | |
| 562 | try { |
| 563 | flowPathsObj = dbHandler.getAllFlowPaths(); |
| 564 | } catch (Exception e) { |
| 565 | // TODO: handle exceptions |
| 566 | dbHandler.rollback(); |
| 567 | log.error(":getAllMyFlowPaths failed"); |
| 568 | return flowPaths; |
| 569 | } |
| 570 | if ((flowPathsObj == null) || (flowPathsObj.iterator().hasNext() == false)) { |
| 571 | dbHandler.commit(); |
| 572 | return flowPaths; // No Flows found |
| 573 | } |
| 574 | |
| 575 | for (IFlowPath flowObj : flowPathsObj) { |
| 576 | // |
| 577 | // Extract the Source Switch DPID and ignore if the switch |
| 578 | // is not controlled by this instance. |
| 579 | // |
| 580 | String srcSwitchStr = flowObj.getSrcSwitch(); |
| 581 | if (srcSwitchStr == null) { |
| 582 | // TODO: A work-around, becauuse of some bogus database objects |
| 583 | continue; |
| 584 | } |
| 585 | Dpid dpid = new Dpid(srcSwitchStr); |
| 586 | if (mySwitches.get(dpid.value()) == null) |
| 587 | continue; |
| 588 | |
| 589 | // |
| 590 | // Extract the Flow state |
| 591 | // |
| 592 | FlowPath flowPath = extractFlowPath(flowObj); |
| 593 | if (flowPath != null) |
| 594 | flowPaths.add(flowPath); |
| 595 | } |
| 596 | |
| 597 | dbHandler.commit(); |
| 598 | |
| 599 | return flowPaths; |
| 600 | } |
| 601 | |
| 602 | /** |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 603 | * Extract Flow Path State from a Titan Database Object @ref IFlowPath. |
| 604 | * |
| 605 | * @param flowObj the object to extract the Flow Path State from. |
| 606 | * @return the extracted Flow Path State. |
| 607 | */ |
| 608 | private static FlowPath extractFlowPath(IFlowPath flowObj) { |
| 609 | // |
| 610 | // Extract the Flow state |
| 611 | // |
| 612 | String flowIdStr = flowObj.getFlowId(); |
| 613 | String installerIdStr = flowObj.getInstallerId(); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 614 | String flowPathType = flowObj.getFlowPathType(); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 615 | String flowPathUserState = flowObj.getFlowPathUserState(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 616 | Long flowPathFlags = flowObj.getFlowPathFlags(); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 617 | Integer idleTimeout = flowObj.getIdleTimeout(); |
| 618 | Integer hardTimeout = flowObj.getHardTimeout(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 619 | String srcSwitchStr = flowObj.getSrcSwitch(); |
| 620 | Short srcPortShort = flowObj.getSrcPort(); |
| 621 | String dstSwitchStr = flowObj.getDstSwitch(); |
| 622 | Short dstPortShort = flowObj.getDstPort(); |
| 623 | |
| 624 | if ((flowIdStr == null) || |
| 625 | (installerIdStr == null) || |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 626 | (flowPathType == null) || |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 627 | (flowPathUserState == null) || |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 628 | (flowPathFlags == null) || |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 629 | (idleTimeout == null) || |
| 630 | (hardTimeout == null) || |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 631 | (srcSwitchStr == null) || |
| 632 | (srcPortShort == null) || |
| 633 | (dstSwitchStr == null) || |
| 634 | (dstPortShort == null)) { |
| 635 | // TODO: A work-around, becauuse of some bogus database objects |
| 636 | return null; |
| 637 | } |
| 638 | |
| 639 | FlowPath flowPath = new FlowPath(); |
| 640 | flowPath.setFlowId(new FlowId(flowIdStr)); |
| 641 | flowPath.setInstallerId(new CallerId(installerIdStr)); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 642 | flowPath.setFlowPathType(FlowPathType.valueOf(flowPathType)); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 643 | flowPath.setFlowPathUserState(FlowPathUserState.valueOf(flowPathUserState)); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 644 | flowPath.setFlowPathFlags(new FlowPathFlags(flowPathFlags)); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 645 | flowPath.setIdleTimeout(idleTimeout); |
| 646 | flowPath.setHardTimeout(hardTimeout); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 647 | flowPath.dataPath().srcPort().setDpid(new Dpid(srcSwitchStr)); |
| 648 | flowPath.dataPath().srcPort().setPort(new Port(srcPortShort)); |
| 649 | flowPath.dataPath().dstPort().setDpid(new Dpid(dstSwitchStr)); |
| 650 | flowPath.dataPath().dstPort().setPort(new Port(dstPortShort)); |
| 651 | // |
| 652 | // Extract the match conditions common for all Flow Entries |
| 653 | // |
| 654 | { |
| 655 | FlowEntryMatch match = new FlowEntryMatch(); |
| 656 | String matchSrcMac = flowObj.getMatchSrcMac(); |
| 657 | if (matchSrcMac != null) |
| 658 | match.enableSrcMac(MACAddress.valueOf(matchSrcMac)); |
| 659 | String matchDstMac = flowObj.getMatchDstMac(); |
| 660 | if (matchDstMac != null) |
| 661 | match.enableDstMac(MACAddress.valueOf(matchDstMac)); |
| 662 | Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType(); |
| 663 | if (matchEthernetFrameType != null) |
| 664 | match.enableEthernetFrameType(matchEthernetFrameType); |
| 665 | Short matchVlanId = flowObj.getMatchVlanId(); |
| 666 | if (matchVlanId != null) |
| 667 | match.enableVlanId(matchVlanId); |
| 668 | Byte matchVlanPriority = flowObj.getMatchVlanPriority(); |
| 669 | if (matchVlanPriority != null) |
| 670 | match.enableVlanPriority(matchVlanPriority); |
| 671 | String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net(); |
| 672 | if (matchSrcIPv4Net != null) |
| 673 | match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net)); |
| 674 | String matchDstIPv4Net = flowObj.getMatchDstIPv4Net(); |
| 675 | if (matchDstIPv4Net != null) |
| 676 | match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net)); |
| 677 | Byte matchIpProto = flowObj.getMatchIpProto(); |
| 678 | if (matchIpProto != null) |
| 679 | match.enableIpProto(matchIpProto); |
| 680 | Byte matchIpToS = flowObj.getMatchIpToS(); |
| 681 | if (matchIpToS != null) |
| 682 | match.enableIpToS(matchIpToS); |
| 683 | Short matchSrcTcpUdpPort = flowObj.getMatchSrcTcpUdpPort(); |
| 684 | if (matchSrcTcpUdpPort != null) |
| 685 | match.enableSrcTcpUdpPort(matchSrcTcpUdpPort); |
| 686 | Short matchDstTcpUdpPort = flowObj.getMatchDstTcpUdpPort(); |
| 687 | if (matchDstTcpUdpPort != null) |
| 688 | match.enableDstTcpUdpPort(matchDstTcpUdpPort); |
| 689 | |
| 690 | flowPath.setFlowEntryMatch(match); |
| 691 | } |
| 692 | // |
| 693 | // Extract the actions for the first Flow Entry |
| 694 | // |
| 695 | { |
| 696 | String actionsStr = flowObj.getActions(); |
| 697 | if (actionsStr != null) { |
| 698 | FlowEntryActions flowEntryActions = new FlowEntryActions(actionsStr); |
| 699 | flowPath.setFlowEntryActions(flowEntryActions); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | // |
| 704 | // Extract all Flow Entries |
| 705 | // |
| 706 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
| 707 | for (IFlowEntry flowEntryObj : flowEntries) { |
| 708 | FlowEntry flowEntry = extractFlowEntry(flowEntryObj); |
| 709 | if (flowEntry == null) |
| 710 | continue; |
| 711 | flowPath.dataPath().flowEntries().add(flowEntry); |
| 712 | } |
| 713 | |
| 714 | return flowPath; |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * Extract Flow Entry State from a Titan Database Object @ref IFlowEntry. |
| 719 | * |
| 720 | * @param flowEntryObj the object to extract the Flow Entry State from. |
| 721 | * @return the extracted Flow Entry State. |
| 722 | */ |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 723 | public static FlowEntry extractFlowEntry(IFlowEntry flowEntryObj) { |
Pavlin Radoslavov | cf87e53 | 2013-12-13 18:17:00 -0800 | [diff] [blame] | 724 | IFlowPath flowObj = flowEntryObj.getFlow(); |
| 725 | if (flowObj == null) |
| 726 | return null; |
| 727 | |
| 728 | String flowIdStr = flowObj.getFlowId(); |
| 729 | // |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 730 | String flowEntryIdStr = flowEntryObj.getFlowEntryId(); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 731 | Integer idleTimeout = flowEntryObj.getIdleTimeout(); |
| 732 | Integer hardTimeout = flowEntryObj.getHardTimeout(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 733 | String switchDpidStr = flowEntryObj.getSwitchDpid(); |
| 734 | String userState = flowEntryObj.getUserState(); |
| 735 | String switchState = flowEntryObj.getSwitchState(); |
| 736 | |
Pavlin Radoslavov | cf87e53 | 2013-12-13 18:17:00 -0800 | [diff] [blame] | 737 | if ((flowIdStr == null) || |
| 738 | (flowEntryIdStr == null) || |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 739 | (idleTimeout == null) || |
| 740 | (hardTimeout == null) || |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 741 | (switchDpidStr == null) || |
| 742 | (userState == null) || |
| 743 | (switchState == null)) { |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 744 | // TODO: A work-around, because of some bogus database objects |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 745 | return null; |
| 746 | } |
| 747 | |
| 748 | FlowEntry flowEntry = new FlowEntry(); |
| 749 | flowEntry.setFlowEntryId(new FlowEntryId(flowEntryIdStr)); |
Pavlin Radoslavov | cf87e53 | 2013-12-13 18:17:00 -0800 | [diff] [blame] | 750 | flowEntry.setFlowId(new FlowId(flowIdStr)); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 751 | flowEntry.setDpid(new Dpid(switchDpidStr)); |
Pavlin Radoslavov | ce93a03 | 2013-12-13 11:03:02 -0800 | [diff] [blame] | 752 | flowEntry.setIdleTimeout(idleTimeout); |
| 753 | flowEntry.setHardTimeout(hardTimeout); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 754 | |
| 755 | // |
| 756 | // Extract the match conditions |
| 757 | // |
| 758 | FlowEntryMatch match = new FlowEntryMatch(); |
| 759 | Short matchInPort = flowEntryObj.getMatchInPort(); |
| 760 | if (matchInPort != null) |
| 761 | match.enableInPort(new Port(matchInPort)); |
| 762 | String matchSrcMac = flowEntryObj.getMatchSrcMac(); |
| 763 | if (matchSrcMac != null) |
| 764 | match.enableSrcMac(MACAddress.valueOf(matchSrcMac)); |
| 765 | String matchDstMac = flowEntryObj.getMatchDstMac(); |
| 766 | if (matchDstMac != null) |
| 767 | match.enableDstMac(MACAddress.valueOf(matchDstMac)); |
| 768 | Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType(); |
| 769 | if (matchEthernetFrameType != null) |
| 770 | match.enableEthernetFrameType(matchEthernetFrameType); |
| 771 | Short matchVlanId = flowEntryObj.getMatchVlanId(); |
| 772 | if (matchVlanId != null) |
| 773 | match.enableVlanId(matchVlanId); |
| 774 | Byte matchVlanPriority = flowEntryObj.getMatchVlanPriority(); |
| 775 | if (matchVlanPriority != null) |
| 776 | match.enableVlanPriority(matchVlanPriority); |
| 777 | String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net(); |
| 778 | if (matchSrcIPv4Net != null) |
| 779 | match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net)); |
| 780 | String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net(); |
| 781 | if (matchDstIPv4Net != null) |
| 782 | match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net)); |
| 783 | Byte matchIpProto = flowEntryObj.getMatchIpProto(); |
| 784 | if (matchIpProto != null) |
| 785 | match.enableIpProto(matchIpProto); |
| 786 | Byte matchIpToS = flowEntryObj.getMatchIpToS(); |
| 787 | if (matchIpToS != null) |
| 788 | match.enableIpToS(matchIpToS); |
| 789 | Short matchSrcTcpUdpPort = flowEntryObj.getMatchSrcTcpUdpPort(); |
| 790 | if (matchSrcTcpUdpPort != null) |
| 791 | match.enableSrcTcpUdpPort(matchSrcTcpUdpPort); |
| 792 | Short matchDstTcpUdpPort = flowEntryObj.getMatchDstTcpUdpPort(); |
| 793 | if (matchDstTcpUdpPort != null) |
| 794 | match.enableDstTcpUdpPort(matchDstTcpUdpPort); |
| 795 | flowEntry.setFlowEntryMatch(match); |
| 796 | |
| 797 | // |
| 798 | // Extract the actions |
| 799 | // |
| 800 | FlowEntryActions actions = new FlowEntryActions(); |
| 801 | String actionsStr = flowEntryObj.getActions(); |
| 802 | if (actionsStr != null) |
| 803 | actions = new FlowEntryActions(actionsStr); |
| 804 | flowEntry.setFlowEntryActions(actions); |
| 805 | flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState)); |
| 806 | flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState)); |
| 807 | // |
| 808 | // TODO: Take care of FlowEntryErrorState. |
| 809 | // |
| 810 | return flowEntry; |
| 811 | } |
| 812 | } |