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