blob: 2314dfc972fc89031c7e3858b281e610396cc580 [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Pavlin Radoslavov27831be2013-10-28 23:40:29 -07003import java.util.ArrayList;
4
Pavlin Radoslavov892dd182013-12-05 23:33:15 -08005import org.codehaus.jackson.annotate.JsonIgnore;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08006import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08007
8/**
9 * The class representing the Flow Path.
10 */
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -070011public class FlowPath implements Comparable<FlowPath> {
Ray Milkey269ffb92014-04-03 14:43:30 -070012 public static final int PRIORITY_DEFAULT = 32768; // Default Flow Priority
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -080013
Ray Milkey269ffb92014-04-03 14:43:30 -070014 private FlowId flowId; // The Flow ID
15 private CallerId installerId; // The Caller ID of the path installer
16 private FlowPathType flowPathType; // The Flow Path type
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070017 private FlowPathUserState flowPathUserState; // The Flow Path User state
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070018 private FlowPathFlags flowPathFlags; // The Flow Path flags
Ray Milkey269ffb92014-04-03 14:43:30 -070019 private int idleTimeout; // The Flow idle timeout
20 private int hardTimeout; // The Flow hard timeout
21 private int priority; // The Flow priority
22 private DataPath dataPath; // The data path
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070023 private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all
Ray Milkey269ffb92014-04-03 14:43:30 -070024 // Flow Entries
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070025 private FlowEntryActions flowEntryActions; // The Flow Entry Actions for
Ray Milkey269ffb92014-04-03 14:43:30 -070026 // the first Flow Entry
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080027
28 /**
29 * Default constructor.
30 */
31 public FlowPath() {
Ray Milkey269ffb92014-04-03 14:43:30 -070032 flowPathType = FlowPathType.FP_TYPE_UNKNOWN;
33 flowPathUserState = FlowPathUserState.FP_USER_UNKNOWN;
34 flowPathFlags = new FlowPathFlags();
35 priority = FlowPath.PRIORITY_DEFAULT;
36 dataPath = new DataPath();
37 flowEntryActions = new FlowEntryActions();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080038 }
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070039
Pankaj Berde6a97eb82013-03-28 12:12:43 -070040 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080041 * Get the flow path Flow ID.
42 *
43 * @return the flow path Flow ID.
44 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080045 @JsonProperty("flowId")
Ray Milkey269ffb92014-04-03 14:43:30 -070046 public FlowId flowId() {
47 return flowId;
48 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080049
50 /**
51 * Set the flow path Flow ID.
52 *
53 * @param flowId the flow path Flow ID to set.
54 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080055 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080056 public void setFlowId(FlowId flowId) {
Ray Milkey269ffb92014-04-03 14:43:30 -070057 this.flowId = flowId;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080058 }
59
60 /**
Pavlin Radoslavov892dd182013-12-05 23:33:15 -080061 * Test whether the Flow ID is valid.
62 *
63 * @return true if the Flow ID is valid, otherwise false.
64 */
65 @JsonIgnore
66 public boolean isValidFlowId() {
Ray Milkeyb29e6262014-04-09 16:02:14 -070067 if (this.flowId == null) {
Ray Milkey269ffb92014-04-03 14:43:30 -070068 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -070069 }
Ray Milkey269ffb92014-04-03 14:43:30 -070070 return (this.flowId.isValid());
Pavlin Radoslavov892dd182013-12-05 23:33:15 -080071 }
72
73 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080074 * Get the Caller ID of the flow path installer.
75 *
76 * @return the Caller ID of the flow path installer.
77 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080078 @JsonProperty("installerId")
Ray Milkey269ffb92014-04-03 14:43:30 -070079 public CallerId installerId() {
80 return installerId;
81 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080082
83 /**
84 * Set the Caller ID of the flow path installer.
85 *
86 * @param installerId the Caller ID of the flow path installer.
87 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080088 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080089 public void setInstallerId(CallerId installerId) {
Ray Milkey269ffb92014-04-03 14:43:30 -070090 this.installerId = installerId;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080091 }
92
93 /**
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070094 * Get the flow path type.
95 *
96 * @return the flow path type.
97 */
98 @JsonProperty("flowPathType")
Ray Milkey269ffb92014-04-03 14:43:30 -070099 public FlowPathType flowPathType() {
100 return flowPathType;
101 }
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700102
103 /**
104 * Set the flow path type.
105 *
106 * @param flowPathType the flow path type to set.
107 */
108 @JsonProperty("flowPathType")
109 public void setFlowPathType(FlowPathType flowPathType) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700110 this.flowPathType = flowPathType;
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700111 }
112
113 /**
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700114 * Get the flow path user state.
115 *
116 * @return the flow path user state.
117 */
118 @JsonProperty("flowPathUserState")
Ray Milkey269ffb92014-04-03 14:43:30 -0700119 public FlowPathUserState flowPathUserState() {
120 return flowPathUserState;
121 }
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700122
123 /**
124 * Set the flow path user state.
125 *
126 * @param flowPathUserState the flow path user state to set.
127 */
128 @JsonProperty("flowPathUserState")
129 public void setFlowPathUserState(FlowPathUserState flowPathUserState) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700130 this.flowPathUserState = flowPathUserState;
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700131 }
132
133 /**
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700134 * Get the flow path flags.
135 *
136 * @return the flow path flags.
137 */
138 @JsonProperty("flowPathFlags")
Ray Milkey269ffb92014-04-03 14:43:30 -0700139 public FlowPathFlags flowPathFlags() {
140 return flowPathFlags;
141 }
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700142
143 /**
144 * Set the flow path flags.
145 *
146 * @param flowPathFlags the flow path flags to set.
147 */
148 @JsonProperty("flowPathFlags")
149 public void setFlowPathFlags(FlowPathFlags flowPathFlags) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700150 this.flowPathFlags = flowPathFlags;
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700151 }
152
153 /**
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800154 * Get the flow idle timeout in seconds.
Ray Milkey269ffb92014-04-03 14:43:30 -0700155 * <p/>
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800156 * It should be an unsigned integer in the interval [0, 65535].
157 * If zero, the timeout is not set.
158 *
159 * @return the flow idle timeout.
160 */
161 @JsonProperty("idleTimeout")
Ray Milkey269ffb92014-04-03 14:43:30 -0700162 public int idleTimeout() {
163 return idleTimeout;
164 }
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800165
166 /**
167 * Set the flow idle timeout in seconds.
Ray Milkey269ffb92014-04-03 14:43:30 -0700168 * <p/>
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800169 * It should be an unsigned integer in the interval [0, 65535].
170 * If zero, the timeout is not set.
171 *
172 * @param idleTimeout the flow idle timeout to set.
173 */
174 @JsonProperty("idleTimeout")
175 public void setIdleTimeout(int idleTimeout) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700176 this.idleTimeout = 0xffff & idleTimeout;
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800177 }
178
179 /**
180 * Get the flow hard timeout in seconds.
Ray Milkey269ffb92014-04-03 14:43:30 -0700181 * <p/>
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800182 * It should be an unsigned integer in the interval [0, 65535].
183 * If zero, the timeout is not set.
184 *
185 * @return the flow hard timeout.
186 */
187 @JsonProperty("hardTimeout")
Ray Milkey269ffb92014-04-03 14:43:30 -0700188 public int hardTimeout() {
189 return hardTimeout;
190 }
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800191
192 /**
193 * Set the flow hard timeout.
Ray Milkey269ffb92014-04-03 14:43:30 -0700194 * <p/>
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800195 * It should be an unsigned integer in the interval [0, 65535].
196 * If zero, the timeout is not set.
197 *
198 * @param hardTimeout the flow hard timeout to set.
199 */
200 @JsonProperty("hardTimeout")
201 public void setHardTimeout(int hardTimeout) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700202 this.hardTimeout = 0xffff & hardTimeout;
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800203 }
204
205 /**
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -0800206 * Get the flow priority.
Ray Milkey269ffb92014-04-03 14:43:30 -0700207 * <p/>
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -0800208 * It should be an unsigned integer in the interval [0, 65535].
209 *
210 * @return the flow priority.
211 */
212 @JsonProperty("priority")
Ray Milkey269ffb92014-04-03 14:43:30 -0700213 public int priority() {
214 return priority;
215 }
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -0800216
217 /**
218 * Set the flow priority.
Ray Milkey269ffb92014-04-03 14:43:30 -0700219 * <p/>
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -0800220 * It should be an unsigned integer in the interval [0, 65535].
221 *
222 * @param priority the flow priority to set.
223 */
224 @JsonProperty("priority")
225 public void setPriority(int priority) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700226 this.priority = 0xffff & priority;
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -0800227 }
228
229 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800230 * Get the flow path's data path.
231 *
232 * @return the flow path's data path.
233 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800234 @JsonProperty("dataPath")
Ray Milkey269ffb92014-04-03 14:43:30 -0700235 public DataPath dataPath() {
236 return dataPath;
237 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800238
239 /**
240 * Set the flow path's data path.
241 *
242 * @param dataPath the flow path's data path to set.
243 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800244 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800245 public void setDataPath(DataPath dataPath) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700246 this.dataPath = dataPath;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800247 }
248
249 /**
Pavlin Radoslavov27831be2013-10-28 23:40:29 -0700250 * Get the data path flow entries.
251 *
252 * @return the data path flow entries.
253 */
254 public ArrayList<FlowEntry> flowEntries() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700255 return this.dataPath.flowEntries();
Pavlin Radoslavov27831be2013-10-28 23:40:29 -0700256 }
257
258 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700259 * Get the flow path's match conditions common for all Flow Entries.
260 *
261 * @return the flow path's match conditions common for all Flow Entries.
262 */
263 @JsonProperty("flowEntryMatch")
Ray Milkey269ffb92014-04-03 14:43:30 -0700264 public FlowEntryMatch flowEntryMatch() {
265 return flowEntryMatch;
266 }
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700267
268 /**
269 * Set the flow path's match conditions common for all Flow Entries.
270 *
271 * @param flowEntryMatch the flow path's match conditions common for all
Ray Milkey269ffb92014-04-03 14:43:30 -0700272 * Flow Entries.
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700273 */
274 @JsonProperty("flowEntryMatch")
275 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700276 this.flowEntryMatch = flowEntryMatch;
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700277 }
278
279 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700280 * Get the flow path's flow entry actions for the first Flow Entry.
281 *
282 * @return the flow path's flow entry actions for the first Flow Entry.
283 */
284 @JsonProperty("flowEntryActions")
285 public FlowEntryActions flowEntryActions() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700286 return flowEntryActions;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700287 }
288
289 /**
290 * Set the flow path's flow entry actions for the first Flow Entry.
291 *
292 * @param flowEntryActions the flow path's flow entry actions for the first
Ray Milkey269ffb92014-04-03 14:43:30 -0700293 * Flow Entry.
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700294 */
295 @JsonProperty("flowEntryActions")
296 public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700297 this.flowEntryActions = flowEntryActions;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700298 }
299
300 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800301 * Convert the flow path to a string.
Ray Milkey269ffb92014-04-03 14:43:30 -0700302 * <p/>
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800303 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -0700304 * [flowId=XXX installerId=XXX flowPathType = XXX flowPathUserState = XXX
305 * flowPathFlags=XXX idleTimeout=XXX hardTimeout=XXX priority=XXX
306 * dataPath=XXX flowEntryMatch=XXX flowEntryActions=XXX]
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800307 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800308 * @return the flow path as a string.
309 */
310 @Override
311 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700312 String ret = "[flowId=" + this.flowId.toString();
313 ret += " installerId=" + this.installerId.toString();
314 ret += " flowPathType=" + this.flowPathType;
315 ret += " flowPathUserState=" + this.flowPathUserState;
316 ret += " flowPathFlags=" + this.flowPathFlags.toString();
317 ret += " idleTimeout=" + this.idleTimeout;
318 ret += " hardTimeout=" + this.hardTimeout;
319 ret += " priority=" + this.priority;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700320 if (dataPath != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700321 ret += " dataPath=" + this.dataPath.toString();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700322 }
323 if (flowEntryMatch != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700324 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700325 }
326 if (flowEntryActions != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700327 ret += " flowEntryActions=" + this.flowEntryActions.toString();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700328 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700329 ret += "]";
330 return ret;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800331 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700332
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700333 /**
Pavlin Radoslavov60c9b8f2014-04-09 16:25:01 -0700334 * Compares this object with the specified object for order.
335 * NOTE: The test is based on the Flow ID.
336 *
337 * @param o the object to be compared.
338 * @return a negative integer, zero, or a positive integer as this object
339 * is less than, equal to, or greater than the specified object.
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700340 */
341 @Override
342 public int compareTo(FlowPath f) {
Pavlin Radoslavov60c9b8f2014-04-09 16:25:01 -0700343 return (this.flowId.compareTo(f.flowId()));
344 }
345
346 /**
347 * Test whether some other object is "equal to" this one.
348 * NOTE: The test is based on the Flow ID.
349 *
350 * @param obj the reference object with which to compare.
351 * @return true if this object is the same as the obj argument; false
352 * otherwise.
353 */
354 @Override
355 public boolean equals(Object obj) {
356 if (obj instanceof FlowPath) {
357 FlowPath other = (FlowPath) obj;
358 return (this.flowId.equals(other.flowId()));
359 }
360 return false;
361 }
362
363 /**
364 * Get the hash code for the object.
365 * NOTE: The computation is based on the Flow ID.
366 *
367 * @return a hash code value for this object.
368 */
369 @Override
370 public int hashCode() {
371 return this.flowId.hashCode();
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700372 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800373}