blob: ab3edb140000a085782a994f73d6f88f2ef4f6dc [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Pavlin Radoslavov27831be2013-10-28 23:40:29 -07003import java.util.ArrayList;
4
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07005import net.floodlightcontroller.util.MACAddress;
HIGUCHI Yuta20514902013-06-12 11:24:16 -07006import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
7import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08008
Pavlin Radoslavov892dd182013-12-05 23:33:15 -08009import org.codehaus.jackson.annotate.JsonIgnore;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080010import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080011
12/**
13 * The class representing the Flow Path.
14 */
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -070015public class FlowPath implements Comparable<FlowPath> {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080016 private FlowId flowId; // The Flow ID
17 private CallerId installerId; // The Caller ID of the path installer
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070018 private FlowPathType flowPathType; // The Flow Path type
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070019 private FlowPathUserState flowPathUserState; // The Flow Path User state
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070020 private FlowPathFlags flowPathFlags; // The Flow Path flags
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080021 private DataPath dataPath; // The data path
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070022 private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all
23 // Flow Entries
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070024 private FlowEntryActions flowEntryActions; // The Flow Entry Actions for
25 // the first Flow Entry
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080026
27 /**
28 * Default constructor.
29 */
30 public FlowPath() {
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070031 flowPathType = FlowPathType.FP_TYPE_UNKNOWN;
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070032 flowPathUserState = FlowPathUserState.FP_USER_UNKNOWN;
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070033 flowPathFlags = new FlowPathFlags();
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080034 dataPath = new DataPath();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070035 flowEntryActions = new FlowEntryActions();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080036 }
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070037
Pankaj Berde6a97eb82013-03-28 12:12:43 -070038 /**
39 * Constructor to instantiate from object in Network Map
40 */
41 public FlowPath(IFlowPath flowObj) {
42 dataPath = new DataPath();
43 this.setFlowId(new FlowId(flowObj.getFlowId()));
44 this.setInstallerId(new CallerId(flowObj.getInstallerId()));
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070045 this.setFlowPathType(FlowPathType.valueOf(flowObj.getFlowPathType()));
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070046 this.setFlowPathUserState(FlowPathUserState.valueOf(flowObj.getFlowPathUserState()));
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070047 this.setFlowPathFlags(new FlowPathFlags(flowObj.getFlowPathFlags()));
Pankaj Berde6a97eb82013-03-28 12:12:43 -070048 this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch()));
49 this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort()));
50 this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch()));
51 this.dataPath().dstPort().setPort(new Port(flowObj.getDstPort()));
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070052 //
53 // Extract the match conditions that are common for all Flow Entries
54 //
55 {
56 FlowEntryMatch match = new FlowEntryMatch();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070057 String matchSrcMac = flowObj.getMatchSrcMac();
58 if (matchSrcMac != null)
59 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
60 String matchDstMac = flowObj.getMatchDstMac();
61 if (matchDstMac != null)
62 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -070063 Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType();
64 if (matchEthernetFrameType != null)
65 match.enableEthernetFrameType(matchEthernetFrameType);
66 Short matchVlanId = flowObj.getMatchVlanId();
67 if (matchVlanId != null)
68 match.enableVlanId(matchVlanId);
69 Byte matchVlanPriority = flowObj.getMatchVlanPriority();
70 if (matchVlanPriority != null)
71 match.enableVlanPriority(matchVlanPriority);
72 String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net();
73 if (matchSrcIPv4Net != null)
74 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
75 String matchDstIPv4Net = flowObj.getMatchDstIPv4Net();
76 if (matchDstIPv4Net != null)
77 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
78 Byte matchIpProto = flowObj.getMatchIpProto();
79 if (matchIpProto != null)
80 match.enableIpProto(matchIpProto);
81 Byte matchIpToS = flowObj.getMatchIpToS();
82 if (matchIpToS != null)
83 match.enableIpToS(matchIpToS);
84 Short matchSrcTcpUdpPort = flowObj.getMatchSrcTcpUdpPort();
85 if (matchSrcTcpUdpPort != null)
86 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
87 Short matchDstTcpUdpPort = flowObj.getMatchDstTcpUdpPort();
88 if (matchDstTcpUdpPort != null)
89 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
90
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070091 this.setFlowEntryMatch(match);
92 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -070093
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070094 //
95 // Extract the actions for the first Flow Entry
96 //
97 {
98 FlowEntryActions actions = new FlowEntryActions();
99
100 String actionsStr = flowObj.getActions();
101 if (actions != null)
102 actions = new FlowEntryActions(actionsStr);
103
104 this.setFlowEntryActions(actions);
105 }
106
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700107 //
108 // Extract all Flow Entries
109 //
110 Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
111 for (IFlowEntry flowEntryObj : flowEntries) {
112 FlowEntry flowEntry = new FlowEntry();
113 flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId()));
114 flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid()));
115
116 //
117 // Extract the match conditions
118 //
119 FlowEntryMatch match = new FlowEntryMatch();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700120 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700121 Short matchInPort = flowEntryObj.getMatchInPort();
122 if (matchInPort != null)
123 match.enableInPort(new Port(matchInPort));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700124 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700125 String matchSrcMac = flowEntryObj.getMatchSrcMac();
126 if (matchSrcMac != null)
127 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700128 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700129 String matchDstMac = flowEntryObj.getMatchDstMac();
130 if (matchDstMac != null)
131 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700132 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700133 Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType();
134 if (matchEthernetFrameType != null)
135 match.enableEthernetFrameType(matchEthernetFrameType);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700136 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700137 Short matchVlanId = flowEntryObj.getMatchVlanId();
138 if (matchVlanId != null)
139 match.enableVlanId(matchVlanId);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700140 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700141 Byte matchVlanPriority = flowEntryObj.getMatchVlanPriority();
142 if (matchVlanPriority != null)
143 match.enableVlanPriority(matchVlanPriority);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700144 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700145 String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net();
146 if (matchSrcIPv4Net != null)
147 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700148 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700149 String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net();
150 if (matchDstIPv4Net != null)
151 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700152 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700153 Byte matchIpProto = flowEntryObj.getMatchIpProto();
154 if (matchIpProto != null)
155 match.enableIpProto(matchIpProto);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700156 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700157 Byte matchIpToS = flowEntryObj.getMatchIpToS();
158 if (matchIpToS != null)
159 match.enableIpToS(matchIpToS);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700160 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700161 Short matchSrcTcpUdpPort = flowEntryObj.getMatchSrcTcpUdpPort();
162 if (matchSrcTcpUdpPort != null)
163 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700164 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700165 Short matchDstTcpUdpPort = flowEntryObj.getMatchDstTcpUdpPort();
166 if (matchDstTcpUdpPort != null)
167 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700168 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700169 flowEntry.setFlowEntryMatch(match);
170
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700171 //
172 // Extract the actions
173 //
174 {
175 FlowEntryActions actions = new FlowEntryActions();
176
HIGUCHI Yuta6fa39512013-08-04 06:00:47 +0900177 String actionsStr = flowEntryObj.getActions();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700178 if (actions != null)
179 actions = new FlowEntryActions(actionsStr);
180
181 flowEntry.setFlowEntryActions(actions);
182 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700183
184 String userState = flowEntryObj.getUserState();
185 flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState));
186 String switchState = flowEntryObj.getSwitchState();
187 flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700188 //
189 // TODO: Take care of the FlowEntryErrorState.
190 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700191 this.dataPath().flowEntries().add(flowEntry);
192 }
193 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800194
195 /**
196 * Get the flow path Flow ID.
197 *
198 * @return the flow path Flow ID.
199 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800200 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800201 public FlowId flowId() { return flowId; }
202
203 /**
204 * Set the flow path Flow ID.
205 *
206 * @param flowId the flow path Flow ID to set.
207 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800208 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800209 public void setFlowId(FlowId flowId) {
210 this.flowId = flowId;
211 }
212
213 /**
Pavlin Radoslavov892dd182013-12-05 23:33:15 -0800214 * Test whether the Flow ID is valid.
215 *
216 * @return true if the Flow ID is valid, otherwise false.
217 */
218 @JsonIgnore
219 public boolean isValidFlowId() {
220 if (this.flowId == null)
221 return false;
222 return (this.flowId.isValid());
223 }
224
225 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800226 * Get the Caller ID of the flow path installer.
227 *
228 * @return the Caller ID of the flow path installer.
229 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800230 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800231 public CallerId installerId() { return installerId; }
232
233 /**
234 * Set the Caller ID of the flow path installer.
235 *
236 * @param installerId the Caller ID of the flow path installer.
237 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800238 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800239 public void setInstallerId(CallerId installerId) {
240 this.installerId = installerId;
241 }
242
243 /**
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700244 * Get the flow path type.
245 *
246 * @return the flow path type.
247 */
248 @JsonProperty("flowPathType")
249 public FlowPathType flowPathType() { return flowPathType; }
250
251 /**
252 * Set the flow path type.
253 *
254 * @param flowPathType the flow path type to set.
255 */
256 @JsonProperty("flowPathType")
257 public void setFlowPathType(FlowPathType flowPathType) {
258 this.flowPathType = flowPathType;
259 }
260
261 /**
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700262 * Get the flow path user state.
263 *
264 * @return the flow path user state.
265 */
266 @JsonProperty("flowPathUserState")
267 public FlowPathUserState flowPathUserState() { return flowPathUserState; }
268
269 /**
270 * Set the flow path user state.
271 *
272 * @param flowPathUserState the flow path user state to set.
273 */
274 @JsonProperty("flowPathUserState")
275 public void setFlowPathUserState(FlowPathUserState flowPathUserState) {
276 this.flowPathUserState = flowPathUserState;
277 }
278
279 /**
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700280 * Get the flow path flags.
281 *
282 * @return the flow path flags.
283 */
284 @JsonProperty("flowPathFlags")
285 public FlowPathFlags flowPathFlags() { return flowPathFlags; }
286
287 /**
288 * Set the flow path flags.
289 *
290 * @param flowPathFlags the flow path flags to set.
291 */
292 @JsonProperty("flowPathFlags")
293 public void setFlowPathFlags(FlowPathFlags flowPathFlags) {
294 this.flowPathFlags = flowPathFlags;
295 }
296
297 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800298 * Get the flow path's data path.
299 *
300 * @return the flow path's data path.
301 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800302 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800303 public DataPath dataPath() { return dataPath; }
304
305 /**
306 * Set the flow path's data path.
307 *
308 * @param dataPath the flow path's data path to set.
309 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800310 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800311 public void setDataPath(DataPath dataPath) {
312 this.dataPath = dataPath;
313 }
314
315 /**
Pavlin Radoslavov27831be2013-10-28 23:40:29 -0700316 * Get the data path flow entries.
317 *
318 * @return the data path flow entries.
319 */
320 public ArrayList<FlowEntry> flowEntries() {
321 return this.dataPath.flowEntries();
322 }
323
324 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700325 * Get the flow path's match conditions common for all Flow Entries.
326 *
327 * @return the flow path's match conditions common for all Flow Entries.
328 */
329 @JsonProperty("flowEntryMatch")
330 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
331
332 /**
333 * Set the flow path's match conditions common for all Flow Entries.
334 *
335 * @param flowEntryMatch the flow path's match conditions common for all
336 * Flow Entries.
337 */
338 @JsonProperty("flowEntryMatch")
339 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
340 this.flowEntryMatch = flowEntryMatch;
341 }
342
343 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700344 * Get the flow path's flow entry actions for the first Flow Entry.
345 *
346 * @return the flow path's flow entry actions for the first Flow Entry.
347 */
348 @JsonProperty("flowEntryActions")
349 public FlowEntryActions flowEntryActions() {
350 return flowEntryActions;
351 }
352
353 /**
354 * Set the flow path's flow entry actions for the first Flow Entry.
355 *
356 * @param flowEntryActions the flow path's flow entry actions for the first
357 * Flow Entry.
358 */
359 @JsonProperty("flowEntryActions")
360 public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
361 this.flowEntryActions = flowEntryActions;
362 }
363
364 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800365 * Convert the flow path to a string.
366 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800367 * The string has the following form:
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700368 * [flowId=XXX installerId=XXX flowPathType = XXX flowPathUserState = XXX
369 * flowPathFlags=XXX dataPath=XXX flowEntryMatch=XXX
370 * flowEntryActions=XXX]
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800371 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800372 * @return the flow path as a string.
373 */
374 @Override
375 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800376 String ret = "[flowId=" + this.flowId.toString();
377 ret += " installerId=" + this.installerId.toString();
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700378 ret += " flowPathType=" + this.flowPathType;
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700379 ret += " flowPathUserState=" + this.flowPathUserState;
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700380 ret += " flowPathFlags=" + this.flowPathFlags.toString();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700381 if (dataPath != null)
382 ret += " dataPath=" + this.dataPath.toString();
383 if (flowEntryMatch != null)
384 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700385 if (flowEntryActions != null)
386 ret += " flowEntryActions=" + this.flowEntryActions.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800387 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800388 return ret;
389 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700390
391 /**
392 * CompareTo method to order flowPath by Id
393 */
394 @Override
395 public int compareTo(FlowPath f) {
396 return (int) (this.flowId.value() - f.flowId.value());
397 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800398}