blob: 789248314c2ef98e0c8667edb45d6777b5755836 [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 Radoslavov204b2862013-07-12 14:15:36 -070016 private FlowPathFlags flowPathFlags; // The Flow Path flags
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080017 private DataPath dataPath; // The data path
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070018 private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all
19 // Flow Entries
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070020 private FlowEntryActions flowEntryActions; // The Flow Entry Actions for
21 // the first Flow Entry
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080022
23 /**
24 * Default constructor.
25 */
26 public FlowPath() {
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070027 flowPathType = FlowPathType.FP_TYPE_UNKNOWN;
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070028 flowPathFlags = new FlowPathFlags();
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080029 dataPath = new DataPath();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070030 flowEntryActions = new FlowEntryActions();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080031 }
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070032
Pankaj Berde6a97eb82013-03-28 12:12:43 -070033 /**
34 * Constructor to instantiate from object in Network Map
35 */
36 public FlowPath(IFlowPath flowObj) {
37 dataPath = new DataPath();
38 this.setFlowId(new FlowId(flowObj.getFlowId()));
39 this.setInstallerId(new CallerId(flowObj.getInstallerId()));
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070040 this.setFlowPathType(FlowPathType.valueOf(flowObj.getFlowPathType()));
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070041 this.setFlowPathFlags(new FlowPathFlags(flowObj.getFlowPathFlags()));
Pankaj Berde6a97eb82013-03-28 12:12:43 -070042 this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch()));
43 this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort()));
44 this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch()));
45 this.dataPath().dstPort().setPort(new Port(flowObj.getDstPort()));
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070046 //
47 // Extract the match conditions that are common for all Flow Entries
48 //
49 {
50 FlowEntryMatch match = new FlowEntryMatch();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070051 String matchSrcMac = flowObj.getMatchSrcMac();
52 if (matchSrcMac != null)
53 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
54 String matchDstMac = flowObj.getMatchDstMac();
55 if (matchDstMac != null)
56 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -070057 Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType();
58 if (matchEthernetFrameType != null)
59 match.enableEthernetFrameType(matchEthernetFrameType);
60 Short matchVlanId = flowObj.getMatchVlanId();
61 if (matchVlanId != null)
62 match.enableVlanId(matchVlanId);
63 Byte matchVlanPriority = flowObj.getMatchVlanPriority();
64 if (matchVlanPriority != null)
65 match.enableVlanPriority(matchVlanPriority);
66 String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net();
67 if (matchSrcIPv4Net != null)
68 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
69 String matchDstIPv4Net = flowObj.getMatchDstIPv4Net();
70 if (matchDstIPv4Net != null)
71 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
72 Byte matchIpProto = flowObj.getMatchIpProto();
73 if (matchIpProto != null)
74 match.enableIpProto(matchIpProto);
75 Byte matchIpToS = flowObj.getMatchIpToS();
76 if (matchIpToS != null)
77 match.enableIpToS(matchIpToS);
78 Short matchSrcTcpUdpPort = flowObj.getMatchSrcTcpUdpPort();
79 if (matchSrcTcpUdpPort != null)
80 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
81 Short matchDstTcpUdpPort = flowObj.getMatchDstTcpUdpPort();
82 if (matchDstTcpUdpPort != null)
83 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
84
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070085 this.setFlowEntryMatch(match);
86 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -070087
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070088 //
89 // Extract the actions for the first Flow Entry
90 //
91 {
92 FlowEntryActions actions = new FlowEntryActions();
93
94 String actionsStr = flowObj.getActions();
95 if (actions != null)
96 actions = new FlowEntryActions(actionsStr);
97
98 this.setFlowEntryActions(actions);
99 }
100
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700101 //
102 // Extract all Flow Entries
103 //
104 Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
105 for (IFlowEntry flowEntryObj : flowEntries) {
106 FlowEntry flowEntry = new FlowEntry();
107 flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId()));
108 flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid()));
109
110 //
111 // Extract the match conditions
112 //
113 FlowEntryMatch match = new FlowEntryMatch();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700114 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700115 Short matchInPort = flowEntryObj.getMatchInPort();
116 if (matchInPort != null)
117 match.enableInPort(new Port(matchInPort));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700118 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700119 String matchSrcMac = flowEntryObj.getMatchSrcMac();
120 if (matchSrcMac != null)
121 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700122 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700123 String matchDstMac = flowEntryObj.getMatchDstMac();
124 if (matchDstMac != null)
125 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700126 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700127 Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType();
128 if (matchEthernetFrameType != null)
129 match.enableEthernetFrameType(matchEthernetFrameType);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700130 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700131 Short matchVlanId = flowEntryObj.getMatchVlanId();
132 if (matchVlanId != null)
133 match.enableVlanId(matchVlanId);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700134 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700135 Byte matchVlanPriority = flowEntryObj.getMatchVlanPriority();
136 if (matchVlanPriority != null)
137 match.enableVlanPriority(matchVlanPriority);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700138 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700139 String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net();
140 if (matchSrcIPv4Net != null)
141 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700142 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700143 String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net();
144 if (matchDstIPv4Net != null)
145 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700146 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700147 Byte matchIpProto = flowEntryObj.getMatchIpProto();
148 if (matchIpProto != null)
149 match.enableIpProto(matchIpProto);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700150 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700151 Byte matchIpToS = flowEntryObj.getMatchIpToS();
152 if (matchIpToS != null)
153 match.enableIpToS(matchIpToS);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700154 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700155 Short matchSrcTcpUdpPort = flowEntryObj.getMatchSrcTcpUdpPort();
156 if (matchSrcTcpUdpPort != null)
157 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700158 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700159 Short matchDstTcpUdpPort = flowEntryObj.getMatchDstTcpUdpPort();
160 if (matchDstTcpUdpPort != null)
161 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700162 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700163 flowEntry.setFlowEntryMatch(match);
164
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700165 //
166 // Extract the actions
167 //
168 {
169 FlowEntryActions actions = new FlowEntryActions();
170
HIGUCHI Yuta6fa39512013-08-04 06:00:47 +0900171 String actionsStr = flowEntryObj.getActions();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700172 if (actions != null)
173 actions = new FlowEntryActions(actionsStr);
174
175 flowEntry.setFlowEntryActions(actions);
176 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700177
178 String userState = flowEntryObj.getUserState();
179 flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState));
180 String switchState = flowEntryObj.getSwitchState();
181 flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700182 //
183 // TODO: Take care of the FlowEntryErrorState.
184 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700185 this.dataPath().flowEntries().add(flowEntry);
186 }
187 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800188
189 /**
190 * Get the flow path Flow ID.
191 *
192 * @return the flow path Flow ID.
193 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800194 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800195 public FlowId flowId() { return flowId; }
196
197 /**
198 * Set the flow path Flow ID.
199 *
200 * @param flowId the flow path Flow ID to set.
201 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800202 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800203 public void setFlowId(FlowId flowId) {
204 this.flowId = flowId;
205 }
206
207 /**
208 * Get the Caller ID of the flow path installer.
209 *
210 * @return the Caller ID of the flow path installer.
211 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800212 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800213 public CallerId installerId() { return installerId; }
214
215 /**
216 * Set the Caller ID of the flow path installer.
217 *
218 * @param installerId the Caller ID of the flow path installer.
219 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800220 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800221 public void setInstallerId(CallerId installerId) {
222 this.installerId = installerId;
223 }
224
225 /**
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700226 * Get the flow path type.
227 *
228 * @return the flow path type.
229 */
230 @JsonProperty("flowPathType")
231 public FlowPathType flowPathType() { return flowPathType; }
232
233 /**
234 * Set the flow path type.
235 *
236 * @param flowPathType the flow path type to set.
237 */
238 @JsonProperty("flowPathType")
239 public void setFlowPathType(FlowPathType flowPathType) {
240 this.flowPathType = flowPathType;
241 }
242
243 /**
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700244 * Get the flow path flags.
245 *
246 * @return the flow path flags.
247 */
248 @JsonProperty("flowPathFlags")
249 public FlowPathFlags flowPathFlags() { return flowPathFlags; }
250
251 /**
252 * Set the flow path flags.
253 *
254 * @param flowPathFlags the flow path flags to set.
255 */
256 @JsonProperty("flowPathFlags")
257 public void setFlowPathFlags(FlowPathFlags flowPathFlags) {
258 this.flowPathFlags = flowPathFlags;
259 }
260
261 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800262 * Get the flow path's data path.
263 *
264 * @return the flow path's data path.
265 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800266 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800267 public DataPath dataPath() { return dataPath; }
268
269 /**
270 * Set the flow path's data path.
271 *
272 * @param dataPath the flow path's data path to set.
273 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800274 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800275 public void setDataPath(DataPath dataPath) {
276 this.dataPath = dataPath;
277 }
278
279 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700280 * Get the flow path's match conditions common for all Flow Entries.
281 *
282 * @return the flow path's match conditions common for all Flow Entries.
283 */
284 @JsonProperty("flowEntryMatch")
285 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
286
287 /**
288 * Set the flow path's match conditions common for all Flow Entries.
289 *
290 * @param flowEntryMatch the flow path's match conditions common for all
291 * Flow Entries.
292 */
293 @JsonProperty("flowEntryMatch")
294 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
295 this.flowEntryMatch = flowEntryMatch;
296 }
297
298 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700299 * Get the flow path's flow entry actions for the first Flow Entry.
300 *
301 * @return the flow path's flow entry actions for the first Flow Entry.
302 */
303 @JsonProperty("flowEntryActions")
304 public FlowEntryActions flowEntryActions() {
305 return flowEntryActions;
306 }
307
308 /**
309 * Set the flow path's flow entry actions for the first Flow Entry.
310 *
311 * @param flowEntryActions the flow path's flow entry actions for the first
312 * Flow Entry.
313 */
314 @JsonProperty("flowEntryActions")
315 public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
316 this.flowEntryActions = flowEntryActions;
317 }
318
319 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800320 * Convert the flow path to a string.
321 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800322 * The string has the following form:
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700323 * [flowId=XXX installerId=XXX flowPathType = XXX flowPathFlags=XXX
324 * dataPath=XXX flowEntryMatch=XXX flowEntryActions=XXX]
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800325 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800326 * @return the flow path as a string.
327 */
328 @Override
329 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800330 String ret = "[flowId=" + this.flowId.toString();
331 ret += " installerId=" + this.installerId.toString();
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700332 ret += " flowPathType=" + this.flowPathType;
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700333 ret += " flowPathFlags=" + this.flowPathFlags.toString();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700334 if (dataPath != null)
335 ret += " dataPath=" + this.dataPath.toString();
336 if (flowEntryMatch != null)
337 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700338 if (flowEntryActions != null)
339 ret += " flowEntryActions=" + this.flowEntryActions.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800340 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800341 return ret;
342 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700343
344 /**
345 * CompareTo method to order flowPath by Id
346 */
347 @Override
348 public int compareTo(FlowPath f) {
349 return (int) (this.flowId.value() - f.flowId.value());
350 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800351}