blob: a720fc645646c99c0c4d8892fd2ac7cf865a7a77 [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
9import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080010
11/**
12 * The class representing the Flow Path.
13 */
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -070014public class FlowPath implements Comparable<FlowPath> {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080015 private FlowId flowId; // The Flow ID
16 private CallerId installerId; // The Caller ID of the path installer
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070017 private FlowPathType flowPathType; // The Flow Path type
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070018 private FlowPathUserState flowPathUserState; // The Flow Path User state
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070019 private FlowPathFlags flowPathFlags; // The Flow Path flags
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080020 private DataPath dataPath; // The data path
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070021 private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all
22 // Flow Entries
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070023 private FlowEntryActions flowEntryActions; // The Flow Entry Actions for
24 // the first Flow Entry
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080025
26 /**
27 * Default constructor.
28 */
29 public FlowPath() {
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070030 flowPathType = FlowPathType.FP_TYPE_UNKNOWN;
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070031 flowPathUserState = FlowPathUserState.FP_USER_UNKNOWN;
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070032 flowPathFlags = new FlowPathFlags();
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080033 dataPath = new DataPath();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070034 flowEntryActions = new FlowEntryActions();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080035 }
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070036
Pankaj Berde6a97eb82013-03-28 12:12:43 -070037 /**
38 * Constructor to instantiate from object in Network Map
39 */
40 public FlowPath(IFlowPath flowObj) {
41 dataPath = new DataPath();
42 this.setFlowId(new FlowId(flowObj.getFlowId()));
43 this.setInstallerId(new CallerId(flowObj.getInstallerId()));
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070044 this.setFlowPathType(FlowPathType.valueOf(flowObj.getFlowPathType()));
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070045 this.setFlowPathUserState(FlowPathUserState.valueOf(flowObj.getFlowPathUserState()));
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070046 this.setFlowPathFlags(new FlowPathFlags(flowObj.getFlowPathFlags()));
Pankaj Berde6a97eb82013-03-28 12:12:43 -070047 this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch()));
48 this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort()));
49 this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch()));
50 this.dataPath().dstPort().setPort(new Port(flowObj.getDstPort()));
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070051 //
52 // Extract the match conditions that are common for all Flow Entries
53 //
54 {
55 FlowEntryMatch match = new FlowEntryMatch();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070056 String matchSrcMac = flowObj.getMatchSrcMac();
57 if (matchSrcMac != null)
58 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
59 String matchDstMac = flowObj.getMatchDstMac();
60 if (matchDstMac != null)
61 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -070062 Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType();
63 if (matchEthernetFrameType != null)
64 match.enableEthernetFrameType(matchEthernetFrameType);
65 Short matchVlanId = flowObj.getMatchVlanId();
66 if (matchVlanId != null)
67 match.enableVlanId(matchVlanId);
68 Byte matchVlanPriority = flowObj.getMatchVlanPriority();
69 if (matchVlanPriority != null)
70 match.enableVlanPriority(matchVlanPriority);
71 String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net();
72 if (matchSrcIPv4Net != null)
73 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
74 String matchDstIPv4Net = flowObj.getMatchDstIPv4Net();
75 if (matchDstIPv4Net != null)
76 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
77 Byte matchIpProto = flowObj.getMatchIpProto();
78 if (matchIpProto != null)
79 match.enableIpProto(matchIpProto);
80 Byte matchIpToS = flowObj.getMatchIpToS();
81 if (matchIpToS != null)
82 match.enableIpToS(matchIpToS);
83 Short matchSrcTcpUdpPort = flowObj.getMatchSrcTcpUdpPort();
84 if (matchSrcTcpUdpPort != null)
85 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
86 Short matchDstTcpUdpPort = flowObj.getMatchDstTcpUdpPort();
87 if (matchDstTcpUdpPort != null)
88 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
89
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070090 this.setFlowEntryMatch(match);
91 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -070092
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070093 //
94 // Extract the actions for the first Flow Entry
95 //
96 {
97 FlowEntryActions actions = new FlowEntryActions();
98
99 String actionsStr = flowObj.getActions();
100 if (actions != null)
101 actions = new FlowEntryActions(actionsStr);
102
103 this.setFlowEntryActions(actions);
104 }
105
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700106 //
107 // Extract all Flow Entries
108 //
109 Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
110 for (IFlowEntry flowEntryObj : flowEntries) {
111 FlowEntry flowEntry = new FlowEntry();
112 flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId()));
113 flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid()));
114
115 //
116 // Extract the match conditions
117 //
118 FlowEntryMatch match = new FlowEntryMatch();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700119 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700120 Short matchInPort = flowEntryObj.getMatchInPort();
121 if (matchInPort != null)
122 match.enableInPort(new Port(matchInPort));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700123 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700124 String matchSrcMac = flowEntryObj.getMatchSrcMac();
125 if (matchSrcMac != null)
126 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700127 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700128 String matchDstMac = flowEntryObj.getMatchDstMac();
129 if (matchDstMac != null)
130 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700131 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700132 Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType();
133 if (matchEthernetFrameType != null)
134 match.enableEthernetFrameType(matchEthernetFrameType);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700135 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700136 Short matchVlanId = flowEntryObj.getMatchVlanId();
137 if (matchVlanId != null)
138 match.enableVlanId(matchVlanId);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700139 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700140 Byte matchVlanPriority = flowEntryObj.getMatchVlanPriority();
141 if (matchVlanPriority != null)
142 match.enableVlanPriority(matchVlanPriority);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700143 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700144 String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net();
145 if (matchSrcIPv4Net != null)
146 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700147 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700148 String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net();
149 if (matchDstIPv4Net != null)
150 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700151 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700152 Byte matchIpProto = flowEntryObj.getMatchIpProto();
153 if (matchIpProto != null)
154 match.enableIpProto(matchIpProto);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700155 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700156 Byte matchIpToS = flowEntryObj.getMatchIpToS();
157 if (matchIpToS != null)
158 match.enableIpToS(matchIpToS);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700159 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700160 Short matchSrcTcpUdpPort = flowEntryObj.getMatchSrcTcpUdpPort();
161 if (matchSrcTcpUdpPort != null)
162 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700163 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700164 Short matchDstTcpUdpPort = flowEntryObj.getMatchDstTcpUdpPort();
165 if (matchDstTcpUdpPort != null)
166 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700167 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700168 flowEntry.setFlowEntryMatch(match);
169
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700170 //
171 // Extract the actions
172 //
173 {
174 FlowEntryActions actions = new FlowEntryActions();
175
HIGUCHI Yuta6fa39512013-08-04 06:00:47 +0900176 String actionsStr = flowEntryObj.getActions();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700177 if (actions != null)
178 actions = new FlowEntryActions(actionsStr);
179
180 flowEntry.setFlowEntryActions(actions);
181 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700182
183 String userState = flowEntryObj.getUserState();
184 flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState));
185 String switchState = flowEntryObj.getSwitchState();
186 flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700187 //
188 // TODO: Take care of the FlowEntryErrorState.
189 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700190 this.dataPath().flowEntries().add(flowEntry);
191 }
192 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800193
194 /**
195 * Get the flow path Flow ID.
196 *
197 * @return the flow path Flow ID.
198 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800199 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800200 public FlowId flowId() { return flowId; }
201
202 /**
203 * Set the flow path Flow ID.
204 *
205 * @param flowId the flow path Flow ID to set.
206 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800207 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800208 public void setFlowId(FlowId flowId) {
209 this.flowId = flowId;
210 }
211
212 /**
213 * Get the Caller ID of the flow path installer.
214 *
215 * @return the Caller ID of the flow path installer.
216 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800217 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800218 public CallerId installerId() { return installerId; }
219
220 /**
221 * Set the Caller ID of the flow path installer.
222 *
223 * @param installerId the Caller ID of the flow path installer.
224 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800225 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800226 public void setInstallerId(CallerId installerId) {
227 this.installerId = installerId;
228 }
229
230 /**
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700231 * Get the flow path type.
232 *
233 * @return the flow path type.
234 */
235 @JsonProperty("flowPathType")
236 public FlowPathType flowPathType() { return flowPathType; }
237
238 /**
239 * Set the flow path type.
240 *
241 * @param flowPathType the flow path type to set.
242 */
243 @JsonProperty("flowPathType")
244 public void setFlowPathType(FlowPathType flowPathType) {
245 this.flowPathType = flowPathType;
246 }
247
248 /**
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700249 * Get the flow path user state.
250 *
251 * @return the flow path user state.
252 */
253 @JsonProperty("flowPathUserState")
254 public FlowPathUserState flowPathUserState() { return flowPathUserState; }
255
256 /**
257 * Set the flow path user state.
258 *
259 * @param flowPathUserState the flow path user state to set.
260 */
261 @JsonProperty("flowPathUserState")
262 public void setFlowPathUserState(FlowPathUserState flowPathUserState) {
263 this.flowPathUserState = flowPathUserState;
264 }
265
266 /**
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700267 * Get the flow path flags.
268 *
269 * @return the flow path flags.
270 */
271 @JsonProperty("flowPathFlags")
272 public FlowPathFlags flowPathFlags() { return flowPathFlags; }
273
274 /**
275 * Set the flow path flags.
276 *
277 * @param flowPathFlags the flow path flags to set.
278 */
279 @JsonProperty("flowPathFlags")
280 public void setFlowPathFlags(FlowPathFlags flowPathFlags) {
281 this.flowPathFlags = flowPathFlags;
282 }
283
284 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800285 * Get the flow path's data path.
286 *
287 * @return the flow path's data path.
288 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800289 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800290 public DataPath dataPath() { return dataPath; }
291
292 /**
293 * Set the flow path's data path.
294 *
295 * @param dataPath the flow path's data path to set.
296 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800297 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800298 public void setDataPath(DataPath dataPath) {
299 this.dataPath = dataPath;
300 }
301
302 /**
Pavlin Radoslavov27831be2013-10-28 23:40:29 -0700303 * Get the data path flow entries.
304 *
305 * @return the data path flow entries.
306 */
307 public ArrayList<FlowEntry> flowEntries() {
308 return this.dataPath.flowEntries();
309 }
310
311 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700312 * Get the flow path's match conditions common for all Flow Entries.
313 *
314 * @return the flow path's match conditions common for all Flow Entries.
315 */
316 @JsonProperty("flowEntryMatch")
317 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
318
319 /**
320 * Set the flow path's match conditions common for all Flow Entries.
321 *
322 * @param flowEntryMatch the flow path's match conditions common for all
323 * Flow Entries.
324 */
325 @JsonProperty("flowEntryMatch")
326 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
327 this.flowEntryMatch = flowEntryMatch;
328 }
329
330 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700331 * Get the flow path's flow entry actions for the first Flow Entry.
332 *
333 * @return the flow path's flow entry actions for the first Flow Entry.
334 */
335 @JsonProperty("flowEntryActions")
336 public FlowEntryActions flowEntryActions() {
337 return flowEntryActions;
338 }
339
340 /**
341 * Set the flow path's flow entry actions for the first Flow Entry.
342 *
343 * @param flowEntryActions the flow path's flow entry actions for the first
344 * Flow Entry.
345 */
346 @JsonProperty("flowEntryActions")
347 public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
348 this.flowEntryActions = flowEntryActions;
349 }
350
351 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800352 * Convert the flow path to a string.
353 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800354 * The string has the following form:
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700355 * [flowId=XXX installerId=XXX flowPathType = XXX flowPathUserState = XXX
356 * flowPathFlags=XXX dataPath=XXX flowEntryMatch=XXX
357 * flowEntryActions=XXX]
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800358 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800359 * @return the flow path as a string.
360 */
361 @Override
362 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800363 String ret = "[flowId=" + this.flowId.toString();
364 ret += " installerId=" + this.installerId.toString();
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700365 ret += " flowPathType=" + this.flowPathType;
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700366 ret += " flowPathUserState=" + this.flowPathUserState;
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700367 ret += " flowPathFlags=" + this.flowPathFlags.toString();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700368 if (dataPath != null)
369 ret += " dataPath=" + this.dataPath.toString();
370 if (flowEntryMatch != null)
371 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700372 if (flowEntryActions != null)
373 ret += " flowEntryActions=" + this.flowEntryActions.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800374 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800375 return ret;
376 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700377
378 /**
379 * CompareTo method to order flowPath by Id
380 */
381 @Override
382 public int compareTo(FlowPath f) {
383 return (int) (this.flowId.value() - f.flowId.value());
384 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800385}