Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.util; |
| 2 | |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 3 | import java.util.ArrayList; |
| 4 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 5 | import net.floodlightcontroller.util.Dpid; |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 6 | import net.floodlightcontroller.util.FlowEntryAction; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 7 | import net.floodlightcontroller.util.FlowEntryId; |
| 8 | import net.floodlightcontroller.util.FlowEntryMatch; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 9 | import net.floodlightcontroller.util.FlowEntrySwitchState; |
| 10 | import net.floodlightcontroller.util.FlowEntryUserState; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 11 | import net.floodlightcontroller.util.Port; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 12 | |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 13 | import net.floodlightcontroller.util.MACAddress; |
| 14 | import net.floodlightcontroller.util.IPv4; |
| 15 | |
Pankaj Berde | d0ae0ff | 2013-03-26 15:37:12 -0700 | [diff] [blame] | 16 | import org.codehaus.jackson.annotate.JsonIgnore; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 17 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 18 | |
| 19 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 20 | * The class representing the Flow Entry. |
| 21 | * |
| 22 | * NOTE: The specification is incomplete. E.g., the entry needs to |
| 23 | * support multiple in-ports and multiple out-ports. |
| 24 | */ |
| 25 | public class FlowEntry { |
Pavlin Radoslavov | 5f85c7b | 2013-03-28 05:33:57 -0700 | [diff] [blame] | 26 | private FlowId flowId; // FlowID of flowEntry |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 27 | private FlowEntryId flowEntryId; // The Flow Entry ID |
| 28 | private FlowEntryMatch flowEntryMatch; // The Flow Entry Match |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 29 | private ArrayList<FlowEntryAction> flowEntryActions; // The Flow Entry Actions |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 30 | private Dpid dpid; // The Switch DPID |
Pavlin Radoslavov | fbcb97c | 2013-03-21 11:29:58 -0700 | [diff] [blame] | 31 | private Port inPort; // The Switch incoming port. Used only |
| 32 | // when the entry is used to return |
| 33 | // Shortest Path computation. |
| 34 | private Port outPort; // The Switch outgoing port. Used only |
| 35 | // when the entry is used to return |
| 36 | // Shortest Path computation. |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 37 | private FlowEntryUserState flowEntryUserState; // The Flow Entry User state |
| 38 | private FlowEntrySwitchState flowEntrySwitchState; // The Flow Entry Switch state |
| 39 | // The Flow Entry Error state (if FlowEntrySwitchState is FE_SWITCH_FAILED) |
| 40 | private FlowEntryErrorState flowEntryErrorState; |
| 41 | |
| 42 | /** |
| 43 | * Default constructor. |
| 44 | */ |
| 45 | public FlowEntry() { |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 46 | // TODO: Test code |
| 47 | /* |
| 48 | MACAddress mac = MACAddress.valueOf("01:02:03:04:05:06"); |
| 49 | IPv4 ipv4 = new IPv4("1.2.3.4"); |
| 50 | IPv4Net ipv4net = new IPv4Net("5.6.7.0/24"); |
| 51 | |
| 52 | flowEntryMatch = new FlowEntryMatch(); |
| 53 | flowEntryMatch.enableInPort(new Port((short)10)); |
| 54 | flowEntryMatch.enableSrcMac(mac); |
| 55 | flowEntryMatch.enableDstMac(mac); |
| 56 | flowEntryMatch.enableVlanId((short)20); |
| 57 | flowEntryMatch.enableVlanPriority((byte)30); |
| 58 | flowEntryMatch.enableEthernetFrameType((short)40); |
| 59 | flowEntryMatch.enableIpToS((byte)50); |
| 60 | flowEntryMatch.enableIpProto((byte)60); |
| 61 | flowEntryMatch.enableSrcIPv4Net(ipv4net); |
| 62 | flowEntryMatch.enableDstIPv4Net(ipv4net); |
| 63 | flowEntryMatch.enableSrcTcpUdpPort((short)70); |
| 64 | flowEntryMatch.enableDstTcpUdpPort((short)80); |
| 65 | |
| 66 | FlowEntryAction action = null; |
| 67 | ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>(); |
| 68 | |
| 69 | action = new FlowEntryAction(); |
| 70 | action.setActionOutput(new Port((short)12)); |
| 71 | actions.add(action); |
| 72 | |
| 73 | action = new FlowEntryAction(); |
| 74 | action.setActionOutputToController((short)13); |
| 75 | actions.add(action); |
| 76 | |
| 77 | action = new FlowEntryAction(); |
| 78 | action.setActionSetVlanId((short)14); |
| 79 | actions.add(action); |
| 80 | |
| 81 | action = new FlowEntryAction(); |
| 82 | action.setActionSetVlanPriority((byte)15); |
| 83 | actions.add(action); |
| 84 | |
| 85 | action = new FlowEntryAction(); |
| 86 | action.setActionStripVlan(true); |
| 87 | actions.add(action); |
| 88 | |
| 89 | action = new FlowEntryAction(); |
| 90 | action.setActionSetEthernetSrcAddr(mac); |
| 91 | actions.add(action); |
| 92 | |
| 93 | action = new FlowEntryAction(); |
| 94 | action.setActionSetEthernetDstAddr(mac); |
| 95 | actions.add(action); |
| 96 | |
| 97 | action = new FlowEntryAction(); |
| 98 | action.setActionSetIPv4SrcAddr(ipv4); |
| 99 | actions.add(action); |
| 100 | |
| 101 | action = new FlowEntryAction(); |
| 102 | action.setActionSetIPv4DstAddr(ipv4); |
| 103 | actions.add(action); |
| 104 | |
| 105 | action = new FlowEntryAction(); |
| 106 | action.setActionSetIpToS((byte)16); |
| 107 | actions.add(action); |
| 108 | |
| 109 | action = new FlowEntryAction(); |
| 110 | action.setActionSetTcpUdpSrcPort((short)17); |
| 111 | actions.add(action); |
| 112 | |
| 113 | action = new FlowEntryAction(); |
| 114 | action.setActionSetTcpUdpDstPort((short)18); |
| 115 | actions.add(action); |
| 116 | |
| 117 | action = new FlowEntryAction(); |
| 118 | action.setActionEnqueue(new Port((short)19), 20); |
| 119 | actions.add(action); |
| 120 | |
| 121 | setFlowEntryActions(actions); |
| 122 | */ |
| 123 | |
| 124 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 125 | flowEntryUserState = FlowEntryUserState.FE_USER_UNKNOWN; |
| 126 | flowEntrySwitchState = FlowEntrySwitchState.FE_SWITCH_UNKNOWN; |
| 127 | } |
| 128 | |
| 129 | /** |
Pavlin Radoslavov | 5f85c7b | 2013-03-28 05:33:57 -0700 | [diff] [blame] | 130 | * Get the Flow ID. |
| 131 | * @return the Flow ID. |
| 132 | */ |
| 133 | @JsonIgnore |
| 134 | public FlowId getFlowId() { return flowId; } |
| 135 | |
| 136 | /** |
| 137 | * Set the Flow ID. |
| 138 | * |
| 139 | * @param flowId the Flow ID to set. |
| 140 | */ |
| 141 | public void setFlowId(FlowId flowId) { |
| 142 | this.flowId = flowId; |
| 143 | } |
| 144 | |
| 145 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 146 | * Get the Flow Entry ID. |
| 147 | * |
| 148 | * @return the Flow Entry ID. |
| 149 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 150 | @JsonProperty("flowEntryId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 151 | public FlowEntryId flowEntryId() { return flowEntryId; } |
| 152 | |
| 153 | /** |
| 154 | * Set the Flow Entry ID. |
| 155 | * |
| 156 | * @param flowEntryId the Flow Entry ID to set. |
| 157 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 158 | @JsonProperty("flowEntryId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 159 | public void setFlowEntryId(FlowEntryId flowEntryId) { |
| 160 | this.flowEntryId = flowEntryId; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Get the Flow Entry Match. |
| 165 | * |
| 166 | * @return the Flow Entry Match. |
| 167 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 168 | @JsonProperty("flowEntryMatch") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 169 | public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; } |
| 170 | |
| 171 | /** |
| 172 | * Set the Flow Entry Match. |
| 173 | * |
| 174 | * @param flowEntryMatch the Flow Entry Match to set. |
| 175 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 176 | @JsonProperty("flowEntryMatch") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 177 | public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) { |
| 178 | this.flowEntryMatch = flowEntryMatch; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Get the Flow Entry Actions. |
| 183 | * |
| 184 | * @return the Flow Entry Actions. |
| 185 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 186 | @JsonProperty("flowEntryActions") |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 187 | public ArrayList<FlowEntryAction> flowEntryActions() { |
| 188 | return flowEntryActions; |
| 189 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * Set the Flow Entry Actions. |
| 193 | * |
| 194 | * @param flowEntryActions the Flow Entry Actions to set. |
| 195 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 196 | @JsonProperty("flowEntryActions") |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 197 | public void setFlowEntryActions(ArrayList<FlowEntryAction> flowEntryActions) { |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 198 | this.flowEntryActions = flowEntryActions; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Get the Switch DPID. |
| 203 | * |
| 204 | * @return the Switch DPID. |
| 205 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 206 | @JsonProperty("dpid") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 207 | public Dpid dpid() { return dpid; } |
| 208 | |
| 209 | /** |
| 210 | * Set the Switch DPID. |
| 211 | * |
| 212 | * @param dpid the Switch DPID to set. |
| 213 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 214 | @JsonProperty("dpid") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 215 | public void setDpid(Dpid dpid) { |
| 216 | this.dpid = dpid; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Get the Switch incoming port. |
| 221 | * |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 222 | * Used only when the entry is used to return Shortest Path computation. |
| 223 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 224 | * @return the Switch incoming port. |
| 225 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 226 | @JsonProperty("inPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 227 | public Port inPort() { return inPort; } |
| 228 | |
| 229 | /** |
| 230 | * Set the Switch incoming port. |
| 231 | * |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 232 | * Used only when the entry is used to return Shortest Path computation. |
| 233 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 234 | * @param inPort the Switch incoming port to set. |
| 235 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 236 | @JsonProperty("inPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 237 | public void setInPort(Port inPort) { |
| 238 | this.inPort = inPort; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Get the Switch outgoing port. |
| 243 | * |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 244 | * Used only when the entry is used to return Shortest Path computation. |
| 245 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 246 | * @return the Switch outgoing port. |
| 247 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 248 | @JsonProperty("outPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 249 | public Port outPort() { return outPort; } |
| 250 | |
| 251 | /** |
| 252 | * Set the Switch outgoing port. |
| 253 | * |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 254 | * Used only when the entry is used to return Shortest Path computation. |
| 255 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 256 | * @param outPort the Switch outgoing port to set. |
| 257 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 258 | @JsonProperty("outPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 259 | public void setOutPort(Port outPort) { |
| 260 | this.outPort = outPort; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Get the Flow Entry User state. |
| 265 | * |
| 266 | * @return the Flow Entry User state. |
| 267 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 268 | @JsonProperty("flowEntryUserState") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 269 | public FlowEntryUserState flowEntryUserState() { |
| 270 | return flowEntryUserState; |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Set the Flow Entry User state. |
| 275 | * |
| 276 | * @param flowEntryUserState the Flow Entry User state to set. |
| 277 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 278 | @JsonProperty("flowEntryUserState") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 279 | public void setFlowEntryUserState(FlowEntryUserState flowEntryUserState) { |
| 280 | this.flowEntryUserState = flowEntryUserState; |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Get the Flow Entry Switch state. |
| 285 | * |
| 286 | * The Flow Entry Error state is used if FlowEntrySwitchState is |
| 287 | * FE_SWITCH_FAILED. |
| 288 | * |
| 289 | * @return the Flow Entry Switch state. |
| 290 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 291 | @JsonProperty("flowEntrySwitchState") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 292 | public FlowEntrySwitchState flowEntrySwitchState() { |
| 293 | return flowEntrySwitchState; |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Set the Flow Entry Switch state. |
| 298 | * |
| 299 | * The Flow Entry Error state is used if FlowEntrySwitchState is |
| 300 | * FE_SWITCH_FAILED. |
| 301 | * |
| 302 | * @param flowEntrySwitchState the Flow Entry Switch state to set. |
| 303 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 304 | @JsonProperty("flowEntrySwitchState") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 305 | public void setFlowEntrySwitchState(FlowEntrySwitchState flowEntrySwitchState) { |
| 306 | this.flowEntrySwitchState = flowEntrySwitchState; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Get the Flow Entry Error state. |
| 311 | * |
| 312 | * @return the Flow Entry Error state. |
| 313 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 314 | @JsonProperty("flowEntryErrorState") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 315 | public FlowEntryErrorState flowEntryErrorState() { |
| 316 | return flowEntryErrorState; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Set the Flow Entry Error state. |
| 321 | * |
| 322 | * @param flowEntryErrorState the Flow Entry Error state to set. |
| 323 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 324 | @JsonProperty("flowEntryErrorState") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 325 | public void setFlowEntryErrorState(FlowEntryErrorState flowEntryErrorState) { |
| 326 | this.flowEntryErrorState = flowEntryErrorState; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Convert the flow entry to a string. |
| 331 | * |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 332 | * The string has the following form: |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 333 | * [flowEntryId=XXX flowEntryMatch=XXX flowEntryAction=XXX |
| 334 | * flowEntryAction=XXX flowEntryAction=XXX dpid=XXX |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 335 | * inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX |
| 336 | * flowEntryErrorState=XXX] |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 337 | * @return the flow entry as a string. |
| 338 | */ |
| 339 | @Override |
| 340 | public String toString() { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 341 | String ret = "[flowEntryId=" + this.flowEntryId.toString(); |
| 342 | ret += " flowEntryMatch=" + this.flowEntryMatch.toString(); |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 343 | for (FlowEntryAction fa : flowEntryActions) { |
| 344 | ret += " flowEntryAction=" + fa.toString(); |
| 345 | } |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 346 | ret += " dpid=" + this.dpid.toString(); |
| 347 | ret += " inPort=" + this.inPort.toString(); |
| 348 | ret += " outPort=" + this.outPort.toString(); |
| 349 | ret += " flowEntryUserState=" + this.flowEntryUserState; |
| 350 | ret += " flowEntrySwitchState=" + this.flowEntrySwitchState; |
| 351 | ret += " flowEntryErrorState=" + this.flowEntryErrorState.toString(); |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 352 | ret += "]"; |
| 353 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 354 | return ret; |
| 355 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 356 | } |