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