blob: 2bb5ad3169cadec9d7e99d151660eae1c579e1ef [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> {
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -080012 public static final int PRIORITY_DEFAULT = 32768; // Default Flow Priority
13
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080014 private FlowId flowId; // The Flow ID
15 private CallerId installerId; // The Caller ID of the path installer
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070016 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
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -080019 private int idleTimeout; // The Flow idle timeout
20 private int hardTimeout; // The Flow hard timeout
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -080021 private int priority; // The Flow priority
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -080022 private DataPath dataPath; // The data path
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070023 private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all
24 // Flow Entries
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070025 private FlowEntryActions flowEntryActions; // The Flow Entry Actions for
26 // the first Flow Entry
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080027
28 /**
29 * Default constructor.
30 */
31 public FlowPath() {
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070032 flowPathType = FlowPathType.FP_TYPE_UNKNOWN;
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070033 flowPathUserState = FlowPathUserState.FP_USER_UNKNOWN;
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070034 flowPathFlags = new FlowPathFlags();
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -080035 priority = FlowPath.PRIORITY_DEFAULT;
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080036 dataPath = new DataPath();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070037 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")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080046 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 Radoslavov2013cbb2013-02-26 10:15:18 -080053 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080054 public void setFlowId(FlowId flowId) {
55 this.flowId = flowId;
56 }
57
58 /**
Pavlin Radoslavov892dd182013-12-05 23:33:15 -080059 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -080071 * Get the Caller ID of the flow path installer.
72 *
73 * @return the Caller ID of the flow path installer.
74 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080075 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080076 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 Radoslavov2013cbb2013-02-26 10:15:18 -080083 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080084 public void setInstallerId(CallerId installerId) {
85 this.installerId = installerId;
86 }
87
88 /**
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070089 * 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 Radoslavov7d4a40e2013-10-27 23:39:40 -0700107 * 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 Radoslavov204b2862013-07-12 14:15:36 -0700125 * 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 Radoslavov5139c0b2013-12-09 18:04:53 -0800143 * 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 Radoslavovafbf1032014-02-04 10:37:52 -0800191 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -0800213 * Get the flow path's data path.
214 *
215 * @return the flow path's data path.
216 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800217 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800218 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 Radoslavov2013cbb2013-02-26 10:15:18 -0800225 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800226 public void setDataPath(DataPath dataPath) {
227 this.dataPath = dataPath;
228 }
229
230 /**
Pavlin Radoslavov27831be2013-10-28 23:40:29 -0700231 * 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 Radoslavov67b3ef32013-04-03 02:44:48 -0700240 * 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 Radoslavov1bc2c472013-07-17 18:11:37 -0700259 * 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 Radoslavov5363c2a2013-02-18 09:55:42 -0800280 * Convert the flow path to a string.
281 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800282 * The string has the following form:
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700283 * [flowId=XXX installerId=XXX flowPathType = XXX flowPathUserState = XXX
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -0800284 * flowPathFlags=XXX idleTimeout=XXX hardTimeout=XXX priority=XXX
285 * dataPath=XXX flowEntryMatch=XXX flowEntryActions=XXX]
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800286 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800287 * @return the flow path as a string.
288 */
289 @Override
290 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800291 String ret = "[flowId=" + this.flowId.toString();
292 ret += " installerId=" + this.installerId.toString();
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700293 ret += " flowPathType=" + this.flowPathType;
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700294 ret += " flowPathUserState=" + this.flowPathUserState;
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700295 ret += " flowPathFlags=" + this.flowPathFlags.toString();
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800296 ret += " idleTimeout=" + this.idleTimeout;
297 ret += " hardTimeout=" + this.hardTimeout;
Pavlin Radoslavovafbf1032014-02-04 10:37:52 -0800298 ret += " priority=" + this.priority;
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700299 if (dataPath != null)
300 ret += " dataPath=" + this.dataPath.toString();
301 if (flowEntryMatch != null)
302 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700303 if (flowEntryActions != null)
304 ret += " flowEntryActions=" + this.flowEntryActions.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800305 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800306 return ret;
307 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700308
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 Radoslavov5363c2a2013-02-18 09:55:42 -0800316}