blob: 2f4d421521c3097bb458c92387610e549e42c50a [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 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 Radoslavov5363c2a2013-02-18 09:55:42 -080029 }
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070030
Pankaj Berde6a97eb82013-03-28 12:12:43 -070031 /**
32 * Constructor to instantiate from object in Network Map
33 */
34 public FlowPath(IFlowPath flowObj) {
35 dataPath = new DataPath();
36 this.setFlowId(new FlowId(flowObj.getFlowId()));
37 this.setInstallerId(new CallerId(flowObj.getInstallerId()));
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070038 this.setFlowPathFlags(new FlowPathFlags(flowObj.getFlowPathFlags()));
Pankaj Berde6a97eb82013-03-28 12:12:43 -070039 this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch()));
40 this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort()));
41 this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch()));
42 this.dataPath().dstPort().setPort(new Port(flowObj.getDstPort()));
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070043 //
44 // Extract the match conditions that are common for all Flow Entries
45 //
46 {
47 FlowEntryMatch match = new FlowEntryMatch();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070048 String matchSrcMac = flowObj.getMatchSrcMac();
49 if (matchSrcMac != null)
50 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
51 String matchDstMac = flowObj.getMatchDstMac();
52 if (matchDstMac != null)
53 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -070054 Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType();
55 if (matchEthernetFrameType != null)
56 match.enableEthernetFrameType(matchEthernetFrameType);
57 Short matchVlanId = flowObj.getMatchVlanId();
58 if (matchVlanId != null)
59 match.enableVlanId(matchVlanId);
60 Byte matchVlanPriority = flowObj.getMatchVlanPriority();
61 if (matchVlanPriority != null)
62 match.enableVlanPriority(matchVlanPriority);
63 String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net();
64 if (matchSrcIPv4Net != null)
65 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
66 String matchDstIPv4Net = flowObj.getMatchDstIPv4Net();
67 if (matchDstIPv4Net != null)
68 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
69 Byte matchIpProto = flowObj.getMatchIpProto();
70 if (matchIpProto != null)
71 match.enableIpProto(matchIpProto);
72 Byte matchIpToS = flowObj.getMatchIpToS();
73 if (matchIpToS != null)
74 match.enableIpToS(matchIpToS);
75 Short matchSrcTcpUdpPort = flowObj.getMatchSrcTcpUdpPort();
76 if (matchSrcTcpUdpPort != null)
77 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
78 Short matchDstTcpUdpPort = flowObj.getMatchDstTcpUdpPort();
79 if (matchDstTcpUdpPort != null)
80 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
81
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070082 this.setFlowEntryMatch(match);
83 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -070084
85 //
86 // Extract all Flow Entries
87 //
88 Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
89 for (IFlowEntry flowEntryObj : flowEntries) {
90 FlowEntry flowEntry = new FlowEntry();
91 flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId()));
92 flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid()));
93
94 //
95 // Extract the match conditions
96 //
97 FlowEntryMatch match = new FlowEntryMatch();
98 Short matchInPort = flowEntryObj.getMatchInPort();
99 if (matchInPort != null)
100 match.enableInPort(new Port(matchInPort));
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700101 String matchSrcMac = flowEntryObj.getMatchSrcMac();
102 if (matchSrcMac != null)
103 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
104 String matchDstMac = flowEntryObj.getMatchDstMac();
105 if (matchDstMac != null)
106 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700107 Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType();
108 if (matchEthernetFrameType != null)
109 match.enableEthernetFrameType(matchEthernetFrameType);
110 Short matchVlanId = flowEntryObj.getMatchVlanId();
111 if (matchVlanId != null)
112 match.enableVlanId(matchVlanId);
113 Byte matchVlanPriority = flowEntryObj.getMatchVlanPriority();
114 if (matchVlanPriority != null)
115 match.enableVlanPriority(matchVlanPriority);
116 String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net();
117 if (matchSrcIPv4Net != null)
118 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
119 String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net();
120 if (matchDstIPv4Net != null)
121 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
122 Byte matchIpProto = flowEntryObj.getMatchIpProto();
123 if (matchIpProto != null)
124 match.enableIpProto(matchIpProto);
125 Byte matchIpToS = flowEntryObj.getMatchIpToS();
126 if (matchIpToS != null)
127 match.enableIpToS(matchIpToS);
128 Short matchSrcTcpUdpPort = flowEntryObj.getMatchSrcTcpUdpPort();
129 if (matchSrcTcpUdpPort != null)
130 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
131 Short matchDstTcpUdpPort = flowEntryObj.getMatchDstTcpUdpPort();
132 if (matchDstTcpUdpPort != null)
133 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700134 flowEntry.setFlowEntryMatch(match);
135
136 //
137 // Extract the actions
138 //
139 ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>();
140 Short actionOutputPort = flowEntryObj.getActionOutput();
141 if (actionOutputPort != null) {
142 FlowEntryAction action = new FlowEntryAction();
143 action.setActionOutput(new Port(actionOutputPort));
144 actions.add(action);
145 }
146 flowEntry.setFlowEntryActions(actions);
147
148 String userState = flowEntryObj.getUserState();
149 flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState));
150 String switchState = flowEntryObj.getSwitchState();
151 flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState));
152 //
153 // TODO: Take care of the FlowEntryMatch, FlowEntryAction set,
154 // and FlowEntryErrorState.
155 //
156 this.dataPath().flowEntries().add(flowEntry);
157 }
158 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800159
160 /**
161 * Get the flow path Flow ID.
162 *
163 * @return the flow path Flow ID.
164 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800165 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800166 public FlowId flowId() { return flowId; }
167
168 /**
169 * Set the flow path Flow ID.
170 *
171 * @param flowId the flow path Flow ID to set.
172 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800173 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800174 public void setFlowId(FlowId flowId) {
175 this.flowId = flowId;
176 }
177
178 /**
179 * Get the Caller ID of the flow path installer.
180 *
181 * @return the Caller ID of the flow path installer.
182 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800183 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800184 public CallerId installerId() { return installerId; }
185
186 /**
187 * Set the Caller ID of the flow path installer.
188 *
189 * @param installerId the Caller ID of the flow path installer.
190 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800191 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800192 public void setInstallerId(CallerId installerId) {
193 this.installerId = installerId;
194 }
195
196 /**
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700197 * Get the flow path flags.
198 *
199 * @return the flow path flags.
200 */
201 @JsonProperty("flowPathFlags")
202 public FlowPathFlags flowPathFlags() { return flowPathFlags; }
203
204 /**
205 * Set the flow path flags.
206 *
207 * @param flowPathFlags the flow path flags to set.
208 */
209 @JsonProperty("flowPathFlags")
210 public void setFlowPathFlags(FlowPathFlags flowPathFlags) {
211 this.flowPathFlags = flowPathFlags;
212 }
213
214 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800215 * Get the flow path's data path.
216 *
217 * @return the flow path's data path.
218 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800219 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800220 public DataPath dataPath() { return dataPath; }
221
222 /**
223 * Set the flow path's data path.
224 *
225 * @param dataPath the flow path's data path to set.
226 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800227 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800228 public void setDataPath(DataPath dataPath) {
229 this.dataPath = dataPath;
230 }
231
232 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700233 * Get the flow path's match conditions common for all Flow Entries.
234 *
235 * @return the flow path's match conditions common for all Flow Entries.
236 */
237 @JsonProperty("flowEntryMatch")
238 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
239
240 /**
241 * Set the flow path's match conditions common for all Flow Entries.
242 *
243 * @param flowEntryMatch the flow path's match conditions common for all
244 * Flow Entries.
245 */
246 @JsonProperty("flowEntryMatch")
247 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
248 this.flowEntryMatch = flowEntryMatch;
249 }
250
251 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800252 * Convert the flow path to a string.
253 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800254 * The string has the following form:
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700255 * [flowId=XXX installerId=XXX flowPathFlags=XXX dataPath=XXX]
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800256 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800257 * @return the flow path as a string.
258 */
259 @Override
260 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800261 String ret = "[flowId=" + this.flowId.toString();
262 ret += " installerId=" + this.installerId.toString();
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700263 ret += " flowPathFlags=" + this.flowPathFlags.toString();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700264 if (dataPath != null)
265 ret += " dataPath=" + this.dataPath.toString();
266 if (flowEntryMatch != null)
267 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800268 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800269 return ret;
270 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700271
272 /**
273 * CompareTo method to order flowPath by Id
274 */
275 @Override
276 public int compareTo(FlowPath f) {
277 return (int) (this.flowId.value() - f.flowId.value());
278 }
279
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800280}