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