blob: 2683e860e0cb64b9e28ae16dde5cdfc506f14f2b [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07003import net.floodlightcontroller.util.MACAddress;
HIGUCHI Yuta20514902013-06-12 11:24:16 -07004import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
5import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08006
7import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08008
9/**
10 * The class representing the Flow Path.
11 */
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -070012public class FlowPath implements Comparable<FlowPath> {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080013 private FlowId flowId; // The Flow ID
14 private CallerId installerId; // The Caller ID of the path installer
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070015 private FlowPathType flowPathType; // The Flow Path type
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070016 private FlowPathUserState flowPathUserState; // The Flow Path User state
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070017 private FlowPathFlags flowPathFlags; // The Flow Path flags
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080018 private DataPath dataPath; // The data path
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070019 private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all
20 // Flow Entries
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070021 private FlowEntryActions flowEntryActions; // The Flow Entry Actions for
22 // the first Flow Entry
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080023
24 /**
25 * Default constructor.
26 */
27 public FlowPath() {
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070028 flowPathType = FlowPathType.FP_TYPE_UNKNOWN;
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070029 flowPathUserState = FlowPathUserState.FP_USER_UNKNOWN;
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070030 flowPathFlags = new FlowPathFlags();
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080031 dataPath = new DataPath();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070032 flowEntryActions = new FlowEntryActions();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080033 }
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070034
Pankaj Berde6a97eb82013-03-28 12:12:43 -070035 /**
36 * Constructor to instantiate from object in Network Map
37 */
38 public FlowPath(IFlowPath flowObj) {
39 dataPath = new DataPath();
40 this.setFlowId(new FlowId(flowObj.getFlowId()));
41 this.setInstallerId(new CallerId(flowObj.getInstallerId()));
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070042 this.setFlowPathType(FlowPathType.valueOf(flowObj.getFlowPathType()));
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070043 this.setFlowPathUserState(FlowPathUserState.valueOf(flowObj.getFlowPathUserState()));
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070044 this.setFlowPathFlags(new FlowPathFlags(flowObj.getFlowPathFlags()));
Pankaj Berde6a97eb82013-03-28 12:12:43 -070045 this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch()));
46 this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort()));
47 this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch()));
48 this.dataPath().dstPort().setPort(new Port(flowObj.getDstPort()));
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070049 //
50 // Extract the match conditions that are common for all Flow Entries
51 //
52 {
53 FlowEntryMatch match = new FlowEntryMatch();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070054 String matchSrcMac = flowObj.getMatchSrcMac();
55 if (matchSrcMac != null)
56 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
57 String matchDstMac = flowObj.getMatchDstMac();
58 if (matchDstMac != null)
59 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -070060 Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType();
61 if (matchEthernetFrameType != null)
62 match.enableEthernetFrameType(matchEthernetFrameType);
63 Short matchVlanId = flowObj.getMatchVlanId();
64 if (matchVlanId != null)
65 match.enableVlanId(matchVlanId);
66 Byte matchVlanPriority = flowObj.getMatchVlanPriority();
67 if (matchVlanPriority != null)
68 match.enableVlanPriority(matchVlanPriority);
69 String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net();
70 if (matchSrcIPv4Net != null)
71 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
72 String matchDstIPv4Net = flowObj.getMatchDstIPv4Net();
73 if (matchDstIPv4Net != null)
74 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
75 Byte matchIpProto = flowObj.getMatchIpProto();
76 if (matchIpProto != null)
77 match.enableIpProto(matchIpProto);
78 Byte matchIpToS = flowObj.getMatchIpToS();
79 if (matchIpToS != null)
80 match.enableIpToS(matchIpToS);
81 Short matchSrcTcpUdpPort = flowObj.getMatchSrcTcpUdpPort();
82 if (matchSrcTcpUdpPort != null)
83 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
84 Short matchDstTcpUdpPort = flowObj.getMatchDstTcpUdpPort();
85 if (matchDstTcpUdpPort != null)
86 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
87
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070088 this.setFlowEntryMatch(match);
89 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -070090
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070091 //
92 // Extract the actions for the first Flow Entry
93 //
94 {
95 FlowEntryActions actions = new FlowEntryActions();
96
97 String actionsStr = flowObj.getActions();
98 if (actions != null)
99 actions = new FlowEntryActions(actionsStr);
100
101 this.setFlowEntryActions(actions);
102 }
103
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700104 //
105 // Extract all Flow Entries
106 //
107 Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
108 for (IFlowEntry flowEntryObj : flowEntries) {
109 FlowEntry flowEntry = new FlowEntry();
110 flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId()));
111 flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid()));
112
113 //
114 // Extract the match conditions
115 //
116 FlowEntryMatch match = new FlowEntryMatch();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700117 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700118 Short matchInPort = flowEntryObj.getMatchInPort();
119 if (matchInPort != null)
120 match.enableInPort(new Port(matchInPort));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700121 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700122 String matchSrcMac = flowEntryObj.getMatchSrcMac();
123 if (matchSrcMac != null)
124 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700125 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700126 String matchDstMac = flowEntryObj.getMatchDstMac();
127 if (matchDstMac != null)
128 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700129 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700130 Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType();
131 if (matchEthernetFrameType != null)
132 match.enableEthernetFrameType(matchEthernetFrameType);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700133 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700134 Short matchVlanId = flowEntryObj.getMatchVlanId();
135 if (matchVlanId != null)
136 match.enableVlanId(matchVlanId);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700137 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700138 Byte matchVlanPriority = flowEntryObj.getMatchVlanPriority();
139 if (matchVlanPriority != null)
140 match.enableVlanPriority(matchVlanPriority);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700141 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700142 String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net();
143 if (matchSrcIPv4Net != null)
144 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700145 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700146 String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net();
147 if (matchDstIPv4Net != null)
148 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700149 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700150 Byte matchIpProto = flowEntryObj.getMatchIpProto();
151 if (matchIpProto != null)
152 match.enableIpProto(matchIpProto);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700153 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700154 Byte matchIpToS = flowEntryObj.getMatchIpToS();
155 if (matchIpToS != null)
156 match.enableIpToS(matchIpToS);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700157 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700158 Short matchSrcTcpUdpPort = flowEntryObj.getMatchSrcTcpUdpPort();
159 if (matchSrcTcpUdpPort != null)
160 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700161 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700162 Short matchDstTcpUdpPort = flowEntryObj.getMatchDstTcpUdpPort();
163 if (matchDstTcpUdpPort != null)
164 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700165 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700166 flowEntry.setFlowEntryMatch(match);
167
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700168 //
169 // Extract the actions
170 //
171 {
172 FlowEntryActions actions = new FlowEntryActions();
173
HIGUCHI Yuta6fa39512013-08-04 06:00:47 +0900174 String actionsStr = flowEntryObj.getActions();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700175 if (actions != null)
176 actions = new FlowEntryActions(actionsStr);
177
178 flowEntry.setFlowEntryActions(actions);
179 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700180
181 String userState = flowEntryObj.getUserState();
182 flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState));
183 String switchState = flowEntryObj.getSwitchState();
184 flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700185 //
186 // TODO: Take care of the FlowEntryErrorState.
187 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700188 this.dataPath().flowEntries().add(flowEntry);
189 }
190 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800191
192 /**
193 * Get the flow path Flow ID.
194 *
195 * @return the flow path Flow ID.
196 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800197 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800198 public FlowId flowId() { return flowId; }
199
200 /**
201 * Set the flow path Flow ID.
202 *
203 * @param flowId the flow path Flow ID to set.
204 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800205 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800206 public void setFlowId(FlowId flowId) {
207 this.flowId = flowId;
208 }
209
210 /**
211 * Get the Caller ID of the flow path installer.
212 *
213 * @return the Caller ID of the flow path installer.
214 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800215 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800216 public CallerId installerId() { return installerId; }
217
218 /**
219 * Set the Caller ID of the flow path installer.
220 *
221 * @param installerId the Caller ID of the flow path installer.
222 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800223 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800224 public void setInstallerId(CallerId installerId) {
225 this.installerId = installerId;
226 }
227
228 /**
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700229 * Get the flow path type.
230 *
231 * @return the flow path type.
232 */
233 @JsonProperty("flowPathType")
234 public FlowPathType flowPathType() { return flowPathType; }
235
236 /**
237 * Set the flow path type.
238 *
239 * @param flowPathType the flow path type to set.
240 */
241 @JsonProperty("flowPathType")
242 public void setFlowPathType(FlowPathType flowPathType) {
243 this.flowPathType = flowPathType;
244 }
245
246 /**
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700247 * Get the flow path user state.
248 *
249 * @return the flow path user state.
250 */
251 @JsonProperty("flowPathUserState")
252 public FlowPathUserState flowPathUserState() { return flowPathUserState; }
253
254 /**
255 * Set the flow path user state.
256 *
257 * @param flowPathUserState the flow path user state to set.
258 */
259 @JsonProperty("flowPathUserState")
260 public void setFlowPathUserState(FlowPathUserState flowPathUserState) {
261 this.flowPathUserState = flowPathUserState;
262 }
263
264 /**
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700265 * Get the flow path flags.
266 *
267 * @return the flow path flags.
268 */
269 @JsonProperty("flowPathFlags")
270 public FlowPathFlags flowPathFlags() { return flowPathFlags; }
271
272 /**
273 * Set the flow path flags.
274 *
275 * @param flowPathFlags the flow path flags to set.
276 */
277 @JsonProperty("flowPathFlags")
278 public void setFlowPathFlags(FlowPathFlags flowPathFlags) {
279 this.flowPathFlags = flowPathFlags;
280 }
281
282 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800283 * Get the flow path's data path.
284 *
285 * @return the flow path's data path.
286 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800287 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800288 public DataPath dataPath() { return dataPath; }
289
290 /**
291 * Set the flow path's data path.
292 *
293 * @param dataPath the flow path's data path to set.
294 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800295 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800296 public void setDataPath(DataPath dataPath) {
297 this.dataPath = dataPath;
298 }
299
300 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700301 * Get the flow path's match conditions common for all Flow Entries.
302 *
303 * @return the flow path's match conditions common for all Flow Entries.
304 */
305 @JsonProperty("flowEntryMatch")
306 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
307
308 /**
309 * Set the flow path's match conditions common for all Flow Entries.
310 *
311 * @param flowEntryMatch the flow path's match conditions common for all
312 * Flow Entries.
313 */
314 @JsonProperty("flowEntryMatch")
315 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
316 this.flowEntryMatch = flowEntryMatch;
317 }
318
319 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700320 * Get the flow path's flow entry actions for the first Flow Entry.
321 *
322 * @return the flow path's flow entry actions for the first Flow Entry.
323 */
324 @JsonProperty("flowEntryActions")
325 public FlowEntryActions flowEntryActions() {
326 return flowEntryActions;
327 }
328
329 /**
330 * Set the flow path's flow entry actions for the first Flow Entry.
331 *
332 * @param flowEntryActions the flow path's flow entry actions for the first
333 * Flow Entry.
334 */
335 @JsonProperty("flowEntryActions")
336 public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
337 this.flowEntryActions = flowEntryActions;
338 }
339
340 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800341 * Convert the flow path to a string.
342 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800343 * The string has the following form:
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700344 * [flowId=XXX installerId=XXX flowPathType = XXX flowPathUserState = XXX
345 * flowPathFlags=XXX dataPath=XXX flowEntryMatch=XXX
346 * flowEntryActions=XXX]
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800347 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800348 * @return the flow path as a string.
349 */
350 @Override
351 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800352 String ret = "[flowId=" + this.flowId.toString();
353 ret += " installerId=" + this.installerId.toString();
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700354 ret += " flowPathType=" + this.flowPathType;
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700355 ret += " flowPathUserState=" + this.flowPathUserState;
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700356 ret += " flowPathFlags=" + this.flowPathFlags.toString();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700357 if (dataPath != null)
358 ret += " dataPath=" + this.dataPath.toString();
359 if (flowEntryMatch != null)
360 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700361 if (flowEntryActions != null)
362 ret += " flowEntryActions=" + this.flowEntryActions.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800363 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800364 return ret;
365 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700366
367 /**
368 * CompareTo method to order flowPath by Id
369 */
370 @Override
371 public int compareTo(FlowPath f) {
372 return (int) (this.flowId.value() - f.flowId.value());
373 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800374}