blob: 153e184d9031efed7188fad69fb789775f2db4e8 [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Pankaj Berde6a97eb82013-03-28 12:12:43 -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 Radoslavov204b2862013-07-12 14:15:36 -07008import net.onrc.onos.ofcontroller.util.FlowPathFlags;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08009
10import 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 Radoslavov204b2862013-07-12 14:15:36 -070018 private FlowPathFlags flowPathFlags; // The Flow Path flags
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080019 private DataPath dataPath; // The data path
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070020 private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all
21 // Flow Entries
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070022 private FlowEntryActions flowEntryActions; // The Flow Entry Actions for
23 // the first Flow Entry
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080024
25 /**
26 * Default constructor.
27 */
28 public FlowPath() {
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070029 flowPathFlags = new FlowPathFlags();
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080030 dataPath = new DataPath();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070031 flowEntryActions = new FlowEntryActions();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080032 }
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070033
Pankaj Berde6a97eb82013-03-28 12:12:43 -070034 /**
35 * Constructor to instantiate from object in Network Map
36 */
37 public FlowPath(IFlowPath flowObj) {
38 dataPath = new DataPath();
39 this.setFlowId(new FlowId(flowObj.getFlowId()));
40 this.setInstallerId(new CallerId(flowObj.getInstallerId()));
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
171 String actionsStr = flowObj.getActions();
172 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 Radoslavov204b2862013-07-12 14:15:36 -0700226 * Get the flow path flags.
227 *
228 * @return the flow path flags.
229 */
230 @JsonProperty("flowPathFlags")
231 public FlowPathFlags flowPathFlags() { return flowPathFlags; }
232
233 /**
234 * Set the flow path flags.
235 *
236 * @param flowPathFlags the flow path flags to set.
237 */
238 @JsonProperty("flowPathFlags")
239 public void setFlowPathFlags(FlowPathFlags flowPathFlags) {
240 this.flowPathFlags = flowPathFlags;
241 }
242
243 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800244 * Get the flow path's data path.
245 *
246 * @return the flow path's data path.
247 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800248 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800249 public DataPath dataPath() { return dataPath; }
250
251 /**
252 * Set the flow path's data path.
253 *
254 * @param dataPath the flow path's data path to set.
255 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800256 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800257 public void setDataPath(DataPath dataPath) {
258 this.dataPath = dataPath;
259 }
260
261 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700262 * Get the flow path's match conditions common for all Flow Entries.
263 *
264 * @return the flow path's match conditions common for all Flow Entries.
265 */
266 @JsonProperty("flowEntryMatch")
267 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
268
269 /**
270 * Set the flow path's match conditions common for all Flow Entries.
271 *
272 * @param flowEntryMatch the flow path's match conditions common for all
273 * Flow Entries.
274 */
275 @JsonProperty("flowEntryMatch")
276 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
277 this.flowEntryMatch = flowEntryMatch;
278 }
279
280 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700281 * Get the flow path's flow entry actions for the first Flow Entry.
282 *
283 * @return the flow path's flow entry actions for the first Flow Entry.
284 */
285 @JsonProperty("flowEntryActions")
286 public FlowEntryActions flowEntryActions() {
287 return flowEntryActions;
288 }
289
290 /**
291 * Set the flow path's flow entry actions for the first Flow Entry.
292 *
293 * @param flowEntryActions the flow path's flow entry actions for the first
294 * Flow Entry.
295 */
296 @JsonProperty("flowEntryActions")
297 public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
298 this.flowEntryActions = flowEntryActions;
299 }
300
301 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800302 * Convert the flow path to a string.
303 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800304 * The string has the following form:
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700305 * [flowId=XXX installerId=XXX flowPathFlags=XXX dataPath=XXX
306 * flowEntryMatch=XXX flowEntryActions=XXX]
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800307 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800308 * @return the flow path as a string.
309 */
310 @Override
311 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800312 String ret = "[flowId=" + this.flowId.toString();
313 ret += " installerId=" + this.installerId.toString();
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700314 ret += " flowPathFlags=" + this.flowPathFlags.toString();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700315 if (dataPath != null)
316 ret += " dataPath=" + this.dataPath.toString();
317 if (flowEntryMatch != null)
318 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700319 if (flowEntryActions != null)
320 ret += " flowEntryActions=" + this.flowEntryActions.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800321 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800322 return ret;
323 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700324
325 /**
326 * CompareTo method to order flowPath by Id
327 */
328 @Override
329 public int compareTo(FlowPath f) {
330 return (int) (this.flowId.value() - f.flowId.value());
331 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800332}