blob: a56dbff0994c60ba4ec015bad2208336167506fc [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 Radoslavov204b2862013-07-12 14:15:36 -07006import net.onrc.onos.ofcontroller.util.FlowPathFlags;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08007
8import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08009
10/**
11 * The class representing the Flow Path.
12 */
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -070013public class FlowPath implements Comparable<FlowPath> {
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 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 Radoslavov204b2862013-07-12 14:15:36 -070027 flowPathFlags = new FlowPathFlags();
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080028 dataPath = new DataPath();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070029 flowEntryActions = new FlowEntryActions();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080030 }
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070031
Pankaj Berde6a97eb82013-03-28 12:12:43 -070032 /**
33 * Constructor to instantiate from object in Network Map
34 */
35 public FlowPath(IFlowPath flowObj) {
36 dataPath = new DataPath();
37 this.setFlowId(new FlowId(flowObj.getFlowId()));
38 this.setInstallerId(new CallerId(flowObj.getInstallerId()));
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070039 this.setFlowPathFlags(new FlowPathFlags(flowObj.getFlowPathFlags()));
Pankaj Berde6a97eb82013-03-28 12:12:43 -070040 this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch()));
41 this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort()));
42 this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch()));
43 this.dataPath().dstPort().setPort(new Port(flowObj.getDstPort()));
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070044 //
45 // Extract the match conditions that are common for all Flow Entries
46 //
47 {
48 FlowEntryMatch match = new FlowEntryMatch();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070049 String matchSrcMac = flowObj.getMatchSrcMac();
50 if (matchSrcMac != null)
51 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
52 String matchDstMac = flowObj.getMatchDstMac();
53 if (matchDstMac != null)
54 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -070055 Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType();
56 if (matchEthernetFrameType != null)
57 match.enableEthernetFrameType(matchEthernetFrameType);
58 Short matchVlanId = flowObj.getMatchVlanId();
59 if (matchVlanId != null)
60 match.enableVlanId(matchVlanId);
61 Byte matchVlanPriority = flowObj.getMatchVlanPriority();
62 if (matchVlanPriority != null)
63 match.enableVlanPriority(matchVlanPriority);
64 String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net();
65 if (matchSrcIPv4Net != null)
66 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
67 String matchDstIPv4Net = flowObj.getMatchDstIPv4Net();
68 if (matchDstIPv4Net != null)
69 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
70 Byte matchIpProto = flowObj.getMatchIpProto();
71 if (matchIpProto != null)
72 match.enableIpProto(matchIpProto);
73 Byte matchIpToS = flowObj.getMatchIpToS();
74 if (matchIpToS != null)
75 match.enableIpToS(matchIpToS);
76 Short matchSrcTcpUdpPort = flowObj.getMatchSrcTcpUdpPort();
77 if (matchSrcTcpUdpPort != null)
78 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
79 Short matchDstTcpUdpPort = flowObj.getMatchDstTcpUdpPort();
80 if (matchDstTcpUdpPort != null)
81 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
82
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070083 this.setFlowEntryMatch(match);
84 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -070085
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070086 //
87 // Extract the actions for the first Flow Entry
88 //
89 {
90 FlowEntryActions actions = new FlowEntryActions();
91
92 String actionsStr = flowObj.getActions();
93 if (actions != null)
94 actions = new FlowEntryActions(actionsStr);
95
96 this.setFlowEntryActions(actions);
97 }
98
Pankaj Berde6a97eb82013-03-28 12:12:43 -070099 //
100 // Extract all Flow Entries
101 //
102 Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
103 for (IFlowEntry flowEntryObj : flowEntries) {
104 FlowEntry flowEntry = new FlowEntry();
105 flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId()));
106 flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid()));
107
108 //
109 // Extract the match conditions
110 //
111 FlowEntryMatch match = new FlowEntryMatch();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700112 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700113 Short matchInPort = flowEntryObj.getMatchInPort();
114 if (matchInPort != null)
115 match.enableInPort(new Port(matchInPort));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700116 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700117 String matchSrcMac = flowEntryObj.getMatchSrcMac();
118 if (matchSrcMac != null)
119 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700120 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700121 String matchDstMac = flowEntryObj.getMatchDstMac();
122 if (matchDstMac != null)
123 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700124 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700125 Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType();
126 if (matchEthernetFrameType != null)
127 match.enableEthernetFrameType(matchEthernetFrameType);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700128 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700129 Short matchVlanId = flowEntryObj.getMatchVlanId();
130 if (matchVlanId != null)
131 match.enableVlanId(matchVlanId);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700132 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700133 Byte matchVlanPriority = flowEntryObj.getMatchVlanPriority();
134 if (matchVlanPriority != null)
135 match.enableVlanPriority(matchVlanPriority);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700136 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700137 String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net();
138 if (matchSrcIPv4Net != null)
139 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700140 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700141 String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net();
142 if (matchDstIPv4Net != null)
143 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700144 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700145 Byte matchIpProto = flowEntryObj.getMatchIpProto();
146 if (matchIpProto != null)
147 match.enableIpProto(matchIpProto);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700148 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700149 Byte matchIpToS = flowEntryObj.getMatchIpToS();
150 if (matchIpToS != null)
151 match.enableIpToS(matchIpToS);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700152 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700153 Short matchSrcTcpUdpPort = flowEntryObj.getMatchSrcTcpUdpPort();
154 if (matchSrcTcpUdpPort != null)
155 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700156 //
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700157 Short matchDstTcpUdpPort = flowEntryObj.getMatchDstTcpUdpPort();
158 if (matchDstTcpUdpPort != null)
159 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700160 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700161 flowEntry.setFlowEntryMatch(match);
162
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700163 //
164 // Extract the actions
165 //
166 {
167 FlowEntryActions actions = new FlowEntryActions();
168
HIGUCHI Yuta6fa39512013-08-04 06:00:47 +0900169 String actionsStr = flowEntryObj.getActions();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700170 if (actions != null)
171 actions = new FlowEntryActions(actionsStr);
172
173 flowEntry.setFlowEntryActions(actions);
174 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700175
176 String userState = flowEntryObj.getUserState();
177 flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState));
178 String switchState = flowEntryObj.getSwitchState();
179 flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700180 //
181 // TODO: Take care of the FlowEntryErrorState.
182 //
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700183 this.dataPath().flowEntries().add(flowEntry);
184 }
185 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800186
187 /**
188 * Get the flow path Flow ID.
189 *
190 * @return the flow path Flow ID.
191 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800192 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800193 public FlowId flowId() { return flowId; }
194
195 /**
196 * Set the flow path Flow ID.
197 *
198 * @param flowId the flow path Flow ID to set.
199 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800200 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800201 public void setFlowId(FlowId flowId) {
202 this.flowId = flowId;
203 }
204
205 /**
206 * Get the Caller ID of the flow path installer.
207 *
208 * @return the Caller ID of the flow path installer.
209 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800210 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800211 public CallerId installerId() { return installerId; }
212
213 /**
214 * Set the Caller ID of the flow path installer.
215 *
216 * @param installerId the Caller ID of the flow path installer.
217 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800218 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800219 public void setInstallerId(CallerId installerId) {
220 this.installerId = installerId;
221 }
222
223 /**
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700224 * Get the flow path flags.
225 *
226 * @return the flow path flags.
227 */
228 @JsonProperty("flowPathFlags")
229 public FlowPathFlags flowPathFlags() { return flowPathFlags; }
230
231 /**
232 * Set the flow path flags.
233 *
234 * @param flowPathFlags the flow path flags to set.
235 */
236 @JsonProperty("flowPathFlags")
237 public void setFlowPathFlags(FlowPathFlags flowPathFlags) {
238 this.flowPathFlags = flowPathFlags;
239 }
240
241 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800242 * Get the flow path's data path.
243 *
244 * @return the flow path's data path.
245 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800246 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800247 public DataPath dataPath() { return dataPath; }
248
249 /**
250 * Set the flow path's data path.
251 *
252 * @param dataPath the flow path's data path to set.
253 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800254 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800255 public void setDataPath(DataPath dataPath) {
256 this.dataPath = dataPath;
257 }
258
259 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700260 * Get the flow path's match conditions common for all Flow Entries.
261 *
262 * @return the flow path's match conditions common for all Flow Entries.
263 */
264 @JsonProperty("flowEntryMatch")
265 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
266
267 /**
268 * Set the flow path's match conditions common for all Flow Entries.
269 *
270 * @param flowEntryMatch the flow path's match conditions common for all
271 * Flow Entries.
272 */
273 @JsonProperty("flowEntryMatch")
274 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
275 this.flowEntryMatch = flowEntryMatch;
276 }
277
278 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700279 * Get the flow path's flow entry actions for the first Flow Entry.
280 *
281 * @return the flow path's flow entry actions for the first Flow Entry.
282 */
283 @JsonProperty("flowEntryActions")
284 public FlowEntryActions flowEntryActions() {
285 return flowEntryActions;
286 }
287
288 /**
289 * Set the flow path's flow entry actions for the first Flow Entry.
290 *
291 * @param flowEntryActions the flow path's flow entry actions for the first
292 * Flow Entry.
293 */
294 @JsonProperty("flowEntryActions")
295 public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
296 this.flowEntryActions = flowEntryActions;
297 }
298
299 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800300 * Convert the flow path to a string.
301 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800302 * The string has the following form:
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700303 * [flowId=XXX installerId=XXX flowPathFlags=XXX dataPath=XXX
304 * flowEntryMatch=XXX flowEntryActions=XXX]
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800305 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800306 * @return the flow path as a string.
307 */
308 @Override
309 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800310 String ret = "[flowId=" + this.flowId.toString();
311 ret += " installerId=" + this.installerId.toString();
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700312 ret += " flowPathFlags=" + this.flowPathFlags.toString();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700313 if (dataPath != null)
314 ret += " dataPath=" + this.dataPath.toString();
315 if (flowEntryMatch != null)
316 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700317 if (flowEntryActions != null)
318 ret += " flowEntryActions=" + this.flowEntryActions.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800319 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800320 return ret;
321 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700322
323 /**
324 * CompareTo method to order flowPath by Id
325 */
326 @Override
327 public int compareTo(FlowPath f) {
328 return (int) (this.flowId.value() - f.flowId.value());
329 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800330}