blob: fe51f080b83871933d52a23a69893a992c4ae832 [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 Milkey269ffb92014-04-03 14:43:30 -070067 if (this.flowId == null)
68 return false;
69 return (this.flowId.isValid());
Pavlin Radoslavov892dd182013-12-05 23:33:15 -080070 }
71
72 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080073 * Get the Caller ID of the flow path installer.
74 *
75 * @return the Caller ID of the flow path installer.
76 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080077 @JsonProperty("installerId")
Ray Milkey269ffb92014-04-03 14:43:30 -070078 public CallerId installerId() {
79 return installerId;
80 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080081
82 /**
83 * Set the Caller ID of the flow path installer.
84 *
85 * @param installerId the Caller ID of the flow path installer.
86 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080087 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080088 public void setInstallerId(CallerId installerId) {
Ray Milkey269ffb92014-04-03 14:43:30 -070089 this.installerId = installerId;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080090 }
91
92 /**
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070093 * Get the flow path type.
94 *
95 * @return the flow path type.
96 */
97 @JsonProperty("flowPathType")
Ray Milkey269ffb92014-04-03 14:43:30 -070098 public FlowPathType flowPathType() {
99 return flowPathType;
100 }
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700101
102 /**
103 * Set the flow path type.
104 *
105 * @param flowPathType the flow path type to set.
106 */
107 @JsonProperty("flowPathType")
108 public void setFlowPathType(FlowPathType flowPathType) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700109 this.flowPathType = flowPathType;
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700110 }
111
112 /**
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700113 * Get the flow path user state.
114 *
115 * @return the flow path user state.
116 */
117 @JsonProperty("flowPathUserState")
Ray Milkey269ffb92014-04-03 14:43:30 -0700118 public FlowPathUserState flowPathUserState() {
119 return flowPathUserState;
120 }
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700121
122 /**
123 * Set the flow path user state.
124 *
125 * @param flowPathUserState the flow path user state to set.
126 */
127 @JsonProperty("flowPathUserState")
128 public void setFlowPathUserState(FlowPathUserState flowPathUserState) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700129 this.flowPathUserState = flowPathUserState;
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700130 }
131
132 /**
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700133 * Get the flow path flags.
134 *
135 * @return the flow path flags.
136 */
137 @JsonProperty("flowPathFlags")
Ray Milkey269ffb92014-04-03 14:43:30 -0700138 public FlowPathFlags flowPathFlags() {
139 return flowPathFlags;
140 }
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700141
142 /**
143 * Set the flow path flags.
144 *
145 * @param flowPathFlags the flow path flags to set.
146 */
147 @JsonProperty("flowPathFlags")
148 public void setFlowPathFlags(FlowPathFlags flowPathFlags) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700149 this.flowPathFlags = flowPathFlags;
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700150 }
151
152 /**
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800153 * Get the flow idle timeout in seconds.
Ray Milkey269ffb92014-04-03 14:43:30 -0700154 * <p/>
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800155 * It should be an unsigned integer in the interval [0, 65535].
156 * If zero, the timeout is not set.
157 *
158 * @return the flow idle timeout.
159 */
160 @JsonProperty("idleTimeout")
Ray Milkey269ffb92014-04-03 14:43:30 -0700161 public int idleTimeout() {
162 return idleTimeout;
163 }
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800164
165 /**
166 * Set the flow idle timeout in seconds.
Ray Milkey269ffb92014-04-03 14:43:30 -0700167 * <p/>
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800168 * It should be an unsigned integer in the interval [0, 65535].
169 * If zero, the timeout is not set.
170 *
171 * @param idleTimeout the flow idle timeout to set.
172 */
173 @JsonProperty("idleTimeout")
174 public void setIdleTimeout(int idleTimeout) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700175 this.idleTimeout = 0xffff & idleTimeout;
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800176 }
177
178 /**
179 * Get the flow hard timeout in seconds.
Ray Milkey269ffb92014-04-03 14:43:30 -0700180 * <p/>
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800181 * It should be an unsigned integer in the interval [0, 65535].
182 * If zero, the timeout is not set.
183 *
184 * @return the flow hard timeout.
185 */
186 @JsonProperty("hardTimeout")
Ray Milkey269ffb92014-04-03 14:43:30 -0700187 public int hardTimeout() {
188 return hardTimeout;
189 }
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800190
191 /**
192 * Set the flow hard timeout.
Ray Milkey269ffb92014-04-03 14:43:30 -0700193 * <p/>
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800194 * It should be an unsigned integer in the interval [0, 65535].
195 * If zero, the timeout is not set.
196 *
197 * @param hardTimeout the flow hard timeout to set.
198 */
199 @JsonProperty("hardTimeout")
200 public void setHardTimeout(int hardTimeout) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700201 this.hardTimeout = 0xffff & hardTimeout;
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800202 }
203
204 /**
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -0800205 * Get the flow priority.
Ray Milkey269ffb92014-04-03 14:43:30 -0700206 * <p/>
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -0800207 * It should be an unsigned integer in the interval [0, 65535].
208 *
209 * @return the flow priority.
210 */
211 @JsonProperty("priority")
Ray Milkey269ffb92014-04-03 14:43:30 -0700212 public int priority() {
213 return priority;
214 }
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -0800215
216 /**
217 * Set the flow priority.
Ray Milkey269ffb92014-04-03 14:43:30 -0700218 * <p/>
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -0800219 * It should be an unsigned integer in the interval [0, 65535].
220 *
221 * @param priority the flow priority to set.
222 */
223 @JsonProperty("priority")
224 public void setPriority(int priority) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700225 this.priority = 0xffff & priority;
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -0800226 }
227
228 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800229 * Get the flow path's data path.
230 *
231 * @return the flow path's data path.
232 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800233 @JsonProperty("dataPath")
Ray Milkey269ffb92014-04-03 14:43:30 -0700234 public DataPath dataPath() {
235 return dataPath;
236 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800237
238 /**
239 * Set the flow path's data path.
240 *
241 * @param dataPath the flow path's data path to set.
242 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800243 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800244 public void setDataPath(DataPath dataPath) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700245 this.dataPath = dataPath;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800246 }
247
248 /**
Pavlin Radoslavov27831be2013-10-28 23:40:29 -0700249 * Get the data path flow entries.
250 *
251 * @return the data path flow entries.
252 */
253 public ArrayList<FlowEntry> flowEntries() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700254 return this.dataPath.flowEntries();
Pavlin Radoslavov27831be2013-10-28 23:40:29 -0700255 }
256
257 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700258 * Get the flow path's match conditions common for all Flow Entries.
259 *
260 * @return the flow path's match conditions common for all Flow Entries.
261 */
262 @JsonProperty("flowEntryMatch")
Ray Milkey269ffb92014-04-03 14:43:30 -0700263 public FlowEntryMatch flowEntryMatch() {
264 return flowEntryMatch;
265 }
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700266
267 /**
268 * Set the flow path's match conditions common for all Flow Entries.
269 *
270 * @param flowEntryMatch the flow path's match conditions common for all
Ray Milkey269ffb92014-04-03 14:43:30 -0700271 * Flow Entries.
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700272 */
273 @JsonProperty("flowEntryMatch")
274 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700275 this.flowEntryMatch = flowEntryMatch;
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700276 }
277
278 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700279 * Get the flow path's flow entry actions for the first Flow Entry.
280 *
281 * @return the flow path's flow entry actions for the first Flow Entry.
282 */
283 @JsonProperty("flowEntryActions")
284 public FlowEntryActions flowEntryActions() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700285 return flowEntryActions;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700286 }
287
288 /**
289 * Set the flow path's flow entry actions for the first Flow Entry.
290 *
291 * @param flowEntryActions the flow path's flow entry actions for the first
Ray Milkey269ffb92014-04-03 14:43:30 -0700292 * Flow Entry.
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700293 */
294 @JsonProperty("flowEntryActions")
295 public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700296 this.flowEntryActions = flowEntryActions;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700297 }
298
299 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800300 * Convert the flow path to a string.
Ray Milkey269ffb92014-04-03 14:43:30 -0700301 * <p/>
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800302 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -0700303 * [flowId=XXX installerId=XXX flowPathType = XXX flowPathUserState = XXX
304 * flowPathFlags=XXX idleTimeout=XXX hardTimeout=XXX priority=XXX
305 * dataPath=XXX flowEntryMatch=XXX flowEntryActions=XXX]
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800306 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800307 * @return the flow path as a string.
308 */
309 @Override
310 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700311 String ret = "[flowId=" + this.flowId.toString();
312 ret += " installerId=" + this.installerId.toString();
313 ret += " flowPathType=" + this.flowPathType;
314 ret += " flowPathUserState=" + this.flowPathUserState;
315 ret += " flowPathFlags=" + this.flowPathFlags.toString();
316 ret += " idleTimeout=" + this.idleTimeout;
317 ret += " hardTimeout=" + this.hardTimeout;
318 ret += " priority=" + this.priority;
319 if (dataPath != null)
320 ret += " dataPath=" + this.dataPath.toString();
321 if (flowEntryMatch != null)
322 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
323 if (flowEntryActions != null)
324 ret += " flowEntryActions=" + this.flowEntryActions.toString();
325 ret += "]";
326 return ret;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800327 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700328
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700329 /**
330 * CompareTo method to order flowPath by Id
331 */
332 @Override
333 public int compareTo(FlowPath f) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700334 return (int) (this.flowId.value() - f.flowId.value());
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700335 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800336}