Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.util; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 2 | |
Pavlin Radoslavov | 27831be | 2013-10-28 23:40:29 -0700 | [diff] [blame] | 3 | import java.util.ArrayList; |
| 4 | |
Pavlin Radoslavov | 892dd18 | 2013-12-05 23:33:15 -0800 | [diff] [blame] | 5 | import org.codehaus.jackson.annotate.JsonIgnore; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 6 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 7 | |
| 8 | /** |
| 9 | * The class representing the Flow Path. |
| 10 | */ |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 11 | public class FlowPath implements Comparable<FlowPath> { |
Pavlin Radoslavov | afbf103 | 2014-02-04 10:37:52 -0800 | [diff] [blame] | 12 | public static final int PRIORITY_DEFAULT = 32768; // Default Flow Priority |
| 13 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 14 | private FlowId flowId; // The Flow ID |
| 15 | private CallerId installerId; // The Caller ID of the path installer |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 16 | private FlowPathType flowPathType; // The Flow Path type |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 17 | private FlowPathUserState flowPathUserState; // The Flow Path User state |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 18 | private FlowPathFlags flowPathFlags; // The Flow Path flags |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 19 | private int idleTimeout; // The Flow idle timeout |
| 20 | private int hardTimeout; // The Flow hard timeout |
Pavlin Radoslavov | afbf103 | 2014-02-04 10:37:52 -0800 | [diff] [blame] | 21 | private int priority; // The Flow priority |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 22 | private DataPath dataPath; // The data path |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 23 | private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all |
| 24 | // Flow Entries |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 25 | private FlowEntryActions flowEntryActions; // The Flow Entry Actions for |
| 26 | // the first Flow Entry |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Default constructor. |
| 30 | */ |
| 31 | public FlowPath() { |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 32 | flowPathType = FlowPathType.FP_TYPE_UNKNOWN; |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 33 | flowPathUserState = FlowPathUserState.FP_USER_UNKNOWN; |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 34 | flowPathFlags = new FlowPathFlags(); |
Pavlin Radoslavov | afbf103 | 2014-02-04 10:37:52 -0800 | [diff] [blame] | 35 | priority = FlowPath.PRIORITY_DEFAULT; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 36 | dataPath = new DataPath(); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 37 | flowEntryActions = new FlowEntryActions(); |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 38 | } |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 39 | |
Pankaj Berde | 6a97eb8 | 2013-03-28 12:12:43 -0700 | [diff] [blame] | 40 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 41 | * Get the flow path Flow ID. |
| 42 | * |
| 43 | * @return the flow path Flow ID. |
| 44 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 45 | @JsonProperty("flowId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 46 | public FlowId flowId() { return flowId; } |
| 47 | |
| 48 | /** |
| 49 | * Set the flow path Flow ID. |
| 50 | * |
| 51 | * @param flowId the flow path Flow ID to set. |
| 52 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 53 | @JsonProperty("flowId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 54 | public void setFlowId(FlowId flowId) { |
| 55 | this.flowId = flowId; |
| 56 | } |
| 57 | |
| 58 | /** |
Pavlin Radoslavov | 892dd18 | 2013-12-05 23:33:15 -0800 | [diff] [blame] | 59 | * Test whether the Flow ID is valid. |
| 60 | * |
| 61 | * @return true if the Flow ID is valid, otherwise false. |
| 62 | */ |
| 63 | @JsonIgnore |
| 64 | public boolean isValidFlowId() { |
| 65 | if (this.flowId == null) |
| 66 | return false; |
| 67 | return (this.flowId.isValid()); |
| 68 | } |
| 69 | |
| 70 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 71 | * Get the Caller ID of the flow path installer. |
| 72 | * |
| 73 | * @return the Caller ID of the flow path installer. |
| 74 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 75 | @JsonProperty("installerId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 76 | public CallerId installerId() { return installerId; } |
| 77 | |
| 78 | /** |
| 79 | * Set the Caller ID of the flow path installer. |
| 80 | * |
| 81 | * @param installerId the Caller ID of the flow path installer. |
| 82 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 83 | @JsonProperty("installerId") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 84 | public void setInstallerId(CallerId installerId) { |
| 85 | this.installerId = installerId; |
| 86 | } |
| 87 | |
| 88 | /** |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 89 | * Get the flow path type. |
| 90 | * |
| 91 | * @return the flow path type. |
| 92 | */ |
| 93 | @JsonProperty("flowPathType") |
| 94 | public FlowPathType flowPathType() { return flowPathType; } |
| 95 | |
| 96 | /** |
| 97 | * Set the flow path type. |
| 98 | * |
| 99 | * @param flowPathType the flow path type to set. |
| 100 | */ |
| 101 | @JsonProperty("flowPathType") |
| 102 | public void setFlowPathType(FlowPathType flowPathType) { |
| 103 | this.flowPathType = flowPathType; |
| 104 | } |
| 105 | |
| 106 | /** |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 107 | * Get the flow path user state. |
| 108 | * |
| 109 | * @return the flow path user state. |
| 110 | */ |
| 111 | @JsonProperty("flowPathUserState") |
| 112 | public FlowPathUserState flowPathUserState() { return flowPathUserState; } |
| 113 | |
| 114 | /** |
| 115 | * Set the flow path user state. |
| 116 | * |
| 117 | * @param flowPathUserState the flow path user state to set. |
| 118 | */ |
| 119 | @JsonProperty("flowPathUserState") |
| 120 | public void setFlowPathUserState(FlowPathUserState flowPathUserState) { |
| 121 | this.flowPathUserState = flowPathUserState; |
| 122 | } |
| 123 | |
| 124 | /** |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 125 | * Get the flow path flags. |
| 126 | * |
| 127 | * @return the flow path flags. |
| 128 | */ |
| 129 | @JsonProperty("flowPathFlags") |
| 130 | public FlowPathFlags flowPathFlags() { return flowPathFlags; } |
| 131 | |
| 132 | /** |
| 133 | * Set the flow path flags. |
| 134 | * |
| 135 | * @param flowPathFlags the flow path flags to set. |
| 136 | */ |
| 137 | @JsonProperty("flowPathFlags") |
| 138 | public void setFlowPathFlags(FlowPathFlags flowPathFlags) { |
| 139 | this.flowPathFlags = flowPathFlags; |
| 140 | } |
| 141 | |
| 142 | /** |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 143 | * Get the flow idle timeout in seconds. |
| 144 | * |
| 145 | * It should be an unsigned integer in the interval [0, 65535]. |
| 146 | * If zero, the timeout is not set. |
| 147 | * |
| 148 | * @return the flow idle timeout. |
| 149 | */ |
| 150 | @JsonProperty("idleTimeout") |
| 151 | public int idleTimeout() { return idleTimeout; } |
| 152 | |
| 153 | /** |
| 154 | * Set the flow idle timeout in seconds. |
| 155 | * |
| 156 | * It should be an unsigned integer in the interval [0, 65535]. |
| 157 | * If zero, the timeout is not set. |
| 158 | * |
| 159 | * @param idleTimeout the flow idle timeout to set. |
| 160 | */ |
| 161 | @JsonProperty("idleTimeout") |
| 162 | public void setIdleTimeout(int idleTimeout) { |
| 163 | this.idleTimeout = 0xffff & idleTimeout; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Get the flow hard timeout in seconds. |
| 168 | * |
| 169 | * It should be an unsigned integer in the interval [0, 65535]. |
| 170 | * If zero, the timeout is not set. |
| 171 | * |
| 172 | * @return the flow hard timeout. |
| 173 | */ |
| 174 | @JsonProperty("hardTimeout") |
| 175 | public int hardTimeout() { return hardTimeout; } |
| 176 | |
| 177 | /** |
| 178 | * Set the flow hard timeout. |
| 179 | * |
| 180 | * It should be an unsigned integer in the interval [0, 65535]. |
| 181 | * If zero, the timeout is not set. |
| 182 | * |
| 183 | * @param hardTimeout the flow hard timeout to set. |
| 184 | */ |
| 185 | @JsonProperty("hardTimeout") |
| 186 | public void setHardTimeout(int hardTimeout) { |
| 187 | this.hardTimeout = 0xffff & hardTimeout; |
| 188 | } |
| 189 | |
| 190 | /** |
Pavlin Radoslavov | afbf103 | 2014-02-04 10:37:52 -0800 | [diff] [blame] | 191 | * Get the flow priority. |
| 192 | * |
| 193 | * It should be an unsigned integer in the interval [0, 65535]. |
| 194 | * |
| 195 | * @return the flow priority. |
| 196 | */ |
| 197 | @JsonProperty("priority") |
| 198 | public int priority() { return priority; } |
| 199 | |
| 200 | /** |
| 201 | * Set the flow priority. |
| 202 | * |
| 203 | * It should be an unsigned integer in the interval [0, 65535]. |
| 204 | * |
| 205 | * @param priority the flow priority to set. |
| 206 | */ |
| 207 | @JsonProperty("priority") |
| 208 | public void setPriority(int priority) { |
| 209 | this.priority = 0xffff & priority; |
| 210 | } |
| 211 | |
| 212 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 213 | * Get the flow path's data path. |
| 214 | * |
| 215 | * @return the flow path's data path. |
| 216 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 217 | @JsonProperty("dataPath") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 218 | public DataPath dataPath() { return dataPath; } |
| 219 | |
| 220 | /** |
| 221 | * Set the flow path's data path. |
| 222 | * |
| 223 | * @param dataPath the flow path's data path to set. |
| 224 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 225 | @JsonProperty("dataPath") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 226 | public void setDataPath(DataPath dataPath) { |
| 227 | this.dataPath = dataPath; |
| 228 | } |
| 229 | |
| 230 | /** |
Pavlin Radoslavov | 27831be | 2013-10-28 23:40:29 -0700 | [diff] [blame] | 231 | * Get the data path flow entries. |
| 232 | * |
| 233 | * @return the data path flow entries. |
| 234 | */ |
| 235 | public ArrayList<FlowEntry> flowEntries() { |
| 236 | return this.dataPath.flowEntries(); |
| 237 | } |
| 238 | |
| 239 | /** |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 240 | * Get the flow path's match conditions common for all Flow Entries. |
| 241 | * |
| 242 | * @return the flow path's match conditions common for all Flow Entries. |
| 243 | */ |
| 244 | @JsonProperty("flowEntryMatch") |
| 245 | public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; } |
| 246 | |
| 247 | /** |
| 248 | * Set the flow path's match conditions common for all Flow Entries. |
| 249 | * |
| 250 | * @param flowEntryMatch the flow path's match conditions common for all |
| 251 | * Flow Entries. |
| 252 | */ |
| 253 | @JsonProperty("flowEntryMatch") |
| 254 | public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) { |
| 255 | this.flowEntryMatch = flowEntryMatch; |
| 256 | } |
| 257 | |
| 258 | /** |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 259 | * Get the flow path's flow entry actions for the first Flow Entry. |
| 260 | * |
| 261 | * @return the flow path's flow entry actions for the first Flow Entry. |
| 262 | */ |
| 263 | @JsonProperty("flowEntryActions") |
| 264 | public FlowEntryActions flowEntryActions() { |
| 265 | return flowEntryActions; |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Set the flow path's flow entry actions for the first Flow Entry. |
| 270 | * |
| 271 | * @param flowEntryActions the flow path's flow entry actions for the first |
| 272 | * Flow Entry. |
| 273 | */ |
| 274 | @JsonProperty("flowEntryActions") |
| 275 | public void setFlowEntryActions(FlowEntryActions flowEntryActions) { |
| 276 | this.flowEntryActions = flowEntryActions; |
| 277 | } |
| 278 | |
| 279 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 280 | * Convert the flow path to a string. |
| 281 | * |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 282 | * The string has the following form: |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 283 | * [flowId=XXX installerId=XXX flowPathType = XXX flowPathUserState = XXX |
Pavlin Radoslavov | afbf103 | 2014-02-04 10:37:52 -0800 | [diff] [blame] | 284 | * flowPathFlags=XXX idleTimeout=XXX hardTimeout=XXX priority=XXX |
| 285 | * dataPath=XXX flowEntryMatch=XXX flowEntryActions=XXX] |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 286 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 287 | * @return the flow path as a string. |
| 288 | */ |
| 289 | @Override |
| 290 | public String toString() { |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 291 | String ret = "[flowId=" + this.flowId.toString(); |
| 292 | ret += " installerId=" + this.installerId.toString(); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 293 | ret += " flowPathType=" + this.flowPathType; |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 294 | ret += " flowPathUserState=" + this.flowPathUserState; |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 295 | ret += " flowPathFlags=" + this.flowPathFlags.toString(); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 296 | ret += " idleTimeout=" + this.idleTimeout; |
| 297 | ret += " hardTimeout=" + this.hardTimeout; |
Pavlin Radoslavov | afbf103 | 2014-02-04 10:37:52 -0800 | [diff] [blame] | 298 | ret += " priority=" + this.priority; |
Pavlin Radoslavov | 67b3ef3 | 2013-04-03 02:44:48 -0700 | [diff] [blame] | 299 | if (dataPath != null) |
| 300 | ret += " dataPath=" + this.dataPath.toString(); |
| 301 | if (flowEntryMatch != null) |
| 302 | ret += " flowEntryMatch=" + this.flowEntryMatch.toString(); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 303 | if (flowEntryActions != null) |
| 304 | ret += " flowEntryActions=" + this.flowEntryActions.toString(); |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 305 | ret += "]"; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 306 | return ret; |
| 307 | } |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 308 | |
| 309 | /** |
| 310 | * CompareTo method to order flowPath by Id |
| 311 | */ |
| 312 | @Override |
| 313 | public int compareTo(FlowPath f) { |
| 314 | return (int) (this.flowId.value() - f.flowId.value()); |
| 315 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 316 | } |