Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.util; |
| 2 | |
| 3 | import net.floodlightcontroller.util.Dpid; |
| 4 | import net.floodlightcontroller.util.FlowEntryActions; |
| 5 | import net.floodlightcontroller.util.FlowEntryId; |
| 6 | import net.floodlightcontroller.util.FlowEntryMatch; |
| 7 | import net.floodlightcontroller.util.Port; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 8 | |
| 9 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 10 | |
| 11 | /** |
| 12 | * The Flow Entry state as set by the user (via the ONOS API). |
| 13 | */ |
| 14 | enum FlowEntryUserState { |
| 15 | FE_USER_UNKNOWN, // Initialization value: state unknown |
| 16 | FE_USER_ADD, // Flow entry that is added |
| 17 | FE_USER_MODIFY, // Flow entry that is modified |
| 18 | FE_USER_DELETE // Flow entry that is deleted |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * The Flow Entry state as set by the controller. |
| 23 | */ |
| 24 | enum FlowEntrySwitchState { |
| 25 | FE_SWITCH_UNKNOWN, // Initialization value: state unknown |
| 26 | FE_SWITCH_NOT_UPDATED, // Switch not updated with this entry |
| 27 | FE_SWITCH_UPDATE_IN_PROGRESS, // Switch update in progress |
| 28 | FE_SWITCH_UPDATED, // Switch updated with this entry |
| 29 | FE_SWITCH_UPDATE_FAILED // Error updating the switch with this entry |
| 30 | } |
| 31 | |
| 32 | |
| 33 | /** |
| 34 | * The class representing the Flow Entry. |
| 35 | * |
| 36 | * NOTE: The specification is incomplete. E.g., the entry needs to |
| 37 | * support multiple in-ports and multiple out-ports. |
| 38 | */ |
| 39 | public class FlowEntry { |
| 40 | private FlowEntryId flowEntryId; // The Flow Entry ID |
| 41 | private FlowEntryMatch flowEntryMatch; // The Flow Entry Match |
| 42 | private FlowEntryActions flowEntryActions; // The Flow Entry Actions |
| 43 | private Dpid dpid; // The Switch DPID |
| 44 | private Port inPort; // The Switch incoming port |
| 45 | private Port outPort; // The Switch outgoing port |
| 46 | private FlowEntryUserState flowEntryUserState; // The Flow Entry User state |
| 47 | private FlowEntrySwitchState flowEntrySwitchState; // The Flow Entry Switch state |
| 48 | // The Flow Entry Error state (if FlowEntrySwitchState is FE_SWITCH_FAILED) |
| 49 | private FlowEntryErrorState flowEntryErrorState; |
| 50 | |
| 51 | /** |
| 52 | * Default constructor. |
| 53 | */ |
| 54 | public FlowEntry() { |
| 55 | flowEntryUserState = FlowEntryUserState.FE_USER_UNKNOWN; |
| 56 | flowEntrySwitchState = FlowEntrySwitchState.FE_SWITCH_UNKNOWN; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Get the Flow Entry ID. |
| 61 | * |
| 62 | * @return the Flow Entry ID. |
| 63 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 64 | @JsonProperty("flowEntryId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 65 | public FlowEntryId flowEntryId() { return flowEntryId; } |
| 66 | |
| 67 | /** |
| 68 | * Set the Flow Entry ID. |
| 69 | * |
| 70 | * @param flowEntryId the Flow Entry ID to set. |
| 71 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 72 | @JsonProperty("flowEntryId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 73 | public void setFlowEntryId(FlowEntryId flowEntryId) { |
| 74 | this.flowEntryId = flowEntryId; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get the Flow Entry Match. |
| 79 | * |
| 80 | * @return the Flow Entry Match. |
| 81 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 82 | @JsonProperty("flowEntryMatch") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 83 | public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; } |
| 84 | |
| 85 | /** |
| 86 | * Set the Flow Entry Match. |
| 87 | * |
| 88 | * @param flowEntryMatch the Flow Entry Match to set. |
| 89 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 90 | @JsonProperty("flowEntryMatch") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 91 | public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) { |
| 92 | this.flowEntryMatch = flowEntryMatch; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Get the Flow Entry Actions. |
| 97 | * |
| 98 | * @return the Flow Entry Actions. |
| 99 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 100 | @JsonProperty("flowEntryActions") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 101 | public FlowEntryActions flowEntryActions() { return flowEntryActions; } |
| 102 | |
| 103 | /** |
| 104 | * Set the Flow Entry Actions. |
| 105 | * |
| 106 | * @param flowEntryActions the Flow Entry Actions to set. |
| 107 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 108 | @JsonProperty("flowEntryActions") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 109 | public void setFlowEntryActions(FlowEntryActions flowEntryActions) { |
| 110 | this.flowEntryActions = flowEntryActions; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Get the Switch DPID. |
| 115 | * |
| 116 | * @return the Switch DPID. |
| 117 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 118 | @JsonProperty("dpid") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 119 | public Dpid dpid() { return dpid; } |
| 120 | |
| 121 | /** |
| 122 | * Set the Switch DPID. |
| 123 | * |
| 124 | * @param dpid the Switch DPID to set. |
| 125 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 126 | @JsonProperty("dpid") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 127 | public void setDpid(Dpid dpid) { |
| 128 | this.dpid = dpid; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Get the Switch incoming port. |
| 133 | * |
| 134 | * @return the Switch incoming port. |
| 135 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 136 | @JsonProperty("inPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 137 | public Port inPort() { return inPort; } |
| 138 | |
| 139 | /** |
| 140 | * Set the Switch incoming port. |
| 141 | * |
| 142 | * @param inPort the Switch incoming port to set. |
| 143 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 144 | @JsonProperty("inPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 145 | public void setInPort(Port inPort) { |
| 146 | this.inPort = inPort; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Get the Switch outgoing port. |
| 151 | * |
| 152 | * @return the Switch outgoing port. |
| 153 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 154 | @JsonProperty("outPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 155 | public Port outPort() { return outPort; } |
| 156 | |
| 157 | /** |
| 158 | * Set the Switch outgoing port. |
| 159 | * |
| 160 | * @param outPort the Switch outgoing port to set. |
| 161 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 162 | @JsonProperty("outPort") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 163 | public void setOutPort(Port outPort) { |
| 164 | this.outPort = outPort; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Get the Flow Entry User state. |
| 169 | * |
| 170 | * @return the Flow Entry User state. |
| 171 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 172 | @JsonProperty("flowEntryUserState") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 173 | public FlowEntryUserState flowEntryUserState() { |
| 174 | return flowEntryUserState; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Set the Flow Entry User state. |
| 179 | * |
| 180 | * @param flowEntryUserState the Flow Entry User state to set. |
| 181 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 182 | @JsonProperty("flowEntryUserState") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 183 | public void setFlowEntryUserState(FlowEntryUserState flowEntryUserState) { |
| 184 | this.flowEntryUserState = flowEntryUserState; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Get the Flow Entry Switch state. |
| 189 | * |
| 190 | * The Flow Entry Error state is used if FlowEntrySwitchState is |
| 191 | * FE_SWITCH_FAILED. |
| 192 | * |
| 193 | * @return the Flow Entry Switch state. |
| 194 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 195 | @JsonProperty("flowEntrySwitchState") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 196 | public FlowEntrySwitchState flowEntrySwitchState() { |
| 197 | return flowEntrySwitchState; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Set the Flow Entry Switch state. |
| 202 | * |
| 203 | * The Flow Entry Error state is used if FlowEntrySwitchState is |
| 204 | * FE_SWITCH_FAILED. |
| 205 | * |
| 206 | * @param flowEntrySwitchState the Flow Entry Switch state to set. |
| 207 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 208 | @JsonProperty("flowEntrySwitchState") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 209 | public void setFlowEntrySwitchState(FlowEntrySwitchState flowEntrySwitchState) { |
| 210 | this.flowEntrySwitchState = flowEntrySwitchState; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Get the Flow Entry Error state. |
| 215 | * |
| 216 | * @return the Flow Entry Error state. |
| 217 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 218 | @JsonProperty("flowEntryErrorState") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 219 | public FlowEntryErrorState flowEntryErrorState() { |
| 220 | return flowEntryErrorState; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Set the Flow Entry Error state. |
| 225 | * |
| 226 | * @param flowEntryErrorState the Flow Entry Error state to set. |
| 227 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 228 | @JsonProperty("flowEntryErrorState") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 229 | public void setFlowEntryErrorState(FlowEntryErrorState flowEntryErrorState) { |
| 230 | this.flowEntryErrorState = flowEntryErrorState; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Convert the flow entry to a string. |
| 235 | * |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 236 | * The string has the following form: |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 237 | * [flowEntryId=XXX flowEntryMatch=XXX flowEntryActions=XXX dpid=XXX |
| 238 | * inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX |
| 239 | * flowEntryErrorState=XXX] |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 240 | * @return the flow entry as a string. |
| 241 | */ |
| 242 | @Override |
| 243 | public String toString() { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 244 | String ret = "[flowEntryId=" + this.flowEntryId.toString(); |
| 245 | ret += " flowEntryMatch=" + this.flowEntryMatch.toString(); |
| 246 | ret += " flowEntryActions=" + this.flowEntryActions.toString(); |
| 247 | ret += " dpid=" + this.dpid.toString(); |
| 248 | ret += " inPort=" + this.inPort.toString(); |
| 249 | ret += " outPort=" + this.outPort.toString(); |
| 250 | ret += " flowEntryUserState=" + this.flowEntryUserState; |
| 251 | ret += " flowEntrySwitchState=" + this.flowEntrySwitchState; |
| 252 | ret += " flowEntryErrorState=" + this.flowEntryErrorState.toString(); |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 253 | ret += "]"; |
| 254 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 255 | return ret; |
| 256 | } |
| 257 | } |