blob: 4a8fc7b84f9fc827a839651812ee179cbd9c0347 [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 Radoslavovad008e02013-02-21 18:42:42 -08008
9import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080010
11/**
12 * The class representing the Flow Path.
13 */
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -070014public class FlowPath implements Comparable<FlowPath> {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080015 private FlowId flowId; // The Flow ID
16 private CallerId installerId; // The Caller ID of the path installer
17 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 Radoslavov5363c2a2013-02-18 09:55:42 -080020
21 /**
22 * Default constructor.
23 */
24 public FlowPath() {
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080025 dataPath = new DataPath();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080026 }
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070027
Pankaj Berde6a97eb82013-03-28 12:12:43 -070028 /**
29 * Constructor to instantiate from object in Network Map
30 */
31 public FlowPath(IFlowPath flowObj) {
32 dataPath = new DataPath();
33 this.setFlowId(new FlowId(flowObj.getFlowId()));
34 this.setInstallerId(new CallerId(flowObj.getInstallerId()));
35 this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch()));
36 this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort()));
37 this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch()));
38 this.dataPath().dstPort().setPort(new Port(flowObj.getDstPort()));
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070039 //
40 // Extract the match conditions that are common for all Flow Entries
41 //
42 {
43 FlowEntryMatch match = new FlowEntryMatch();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070044 String matchSrcMac = flowObj.getMatchSrcMac();
45 if (matchSrcMac != null)
46 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
47 String matchDstMac = flowObj.getMatchDstMac();
48 if (matchDstMac != null)
49 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -070050 Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType();
51 if (matchEthernetFrameType != null)
52 match.enableEthernetFrameType(matchEthernetFrameType);
53 Short matchVlanId = flowObj.getMatchVlanId();
54 if (matchVlanId != null)
55 match.enableVlanId(matchVlanId);
56 Byte matchVlanPriority = flowObj.getMatchVlanPriority();
57 if (matchVlanPriority != null)
58 match.enableVlanPriority(matchVlanPriority);
59 String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net();
60 if (matchSrcIPv4Net != null)
61 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
62 String matchDstIPv4Net = flowObj.getMatchDstIPv4Net();
63 if (matchDstIPv4Net != null)
64 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
65 Byte matchIpProto = flowObj.getMatchIpProto();
66 if (matchIpProto != null)
67 match.enableIpProto(matchIpProto);
68 Byte matchIpToS = flowObj.getMatchIpToS();
69 if (matchIpToS != null)
70 match.enableIpToS(matchIpToS);
71 Short matchSrcTcpUdpPort = flowObj.getMatchSrcTcpUdpPort();
72 if (matchSrcTcpUdpPort != null)
73 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
74 Short matchDstTcpUdpPort = flowObj.getMatchDstTcpUdpPort();
75 if (matchDstTcpUdpPort != null)
76 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
77
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070078 this.setFlowEntryMatch(match);
79 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -070080
81 //
82 // Extract all Flow Entries
83 //
84 Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
85 for (IFlowEntry flowEntryObj : flowEntries) {
86 FlowEntry flowEntry = new FlowEntry();
87 flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId()));
88 flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid()));
89
90 //
91 // Extract the match conditions
92 //
93 FlowEntryMatch match = new FlowEntryMatch();
94 Short matchInPort = flowEntryObj.getMatchInPort();
95 if (matchInPort != null)
96 match.enableInPort(new Port(matchInPort));
Pankaj Berde6a97eb82013-03-28 12:12:43 -070097 String matchSrcMac = flowEntryObj.getMatchSrcMac();
98 if (matchSrcMac != null)
99 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
100 String matchDstMac = flowEntryObj.getMatchDstMac();
101 if (matchDstMac != null)
102 match.enableDstMac(MACAddress.valueOf(matchDstMac));
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700103 Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType();
104 if (matchEthernetFrameType != null)
105 match.enableEthernetFrameType(matchEthernetFrameType);
106 Short matchVlanId = flowEntryObj.getMatchVlanId();
107 if (matchVlanId != null)
108 match.enableVlanId(matchVlanId);
109 Byte matchVlanPriority = flowEntryObj.getMatchVlanPriority();
110 if (matchVlanPriority != null)
111 match.enableVlanPriority(matchVlanPriority);
112 String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net();
113 if (matchSrcIPv4Net != null)
114 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
115 String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net();
116 if (matchDstIPv4Net != null)
117 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
118 Byte matchIpProto = flowEntryObj.getMatchIpProto();
119 if (matchIpProto != null)
120 match.enableIpProto(matchIpProto);
121 Byte matchIpToS = flowEntryObj.getMatchIpToS();
122 if (matchIpToS != null)
123 match.enableIpToS(matchIpToS);
124 Short matchSrcTcpUdpPort = flowEntryObj.getMatchSrcTcpUdpPort();
125 if (matchSrcTcpUdpPort != null)
126 match.enableSrcTcpUdpPort(matchSrcTcpUdpPort);
127 Short matchDstTcpUdpPort = flowEntryObj.getMatchDstTcpUdpPort();
128 if (matchDstTcpUdpPort != null)
129 match.enableDstTcpUdpPort(matchDstTcpUdpPort);
Pankaj Berde6a97eb82013-03-28 12:12:43 -0700130 flowEntry.setFlowEntryMatch(match);
131
132 //
133 // Extract the actions
134 //
135 ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>();
136 Short actionOutputPort = flowEntryObj.getActionOutput();
137 if (actionOutputPort != null) {
138 FlowEntryAction action = new FlowEntryAction();
139 action.setActionOutput(new Port(actionOutputPort));
140 actions.add(action);
141 }
142 flowEntry.setFlowEntryActions(actions);
143
144 String userState = flowEntryObj.getUserState();
145 flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState));
146 String switchState = flowEntryObj.getSwitchState();
147 flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState));
148 //
149 // TODO: Take care of the FlowEntryMatch, FlowEntryAction set,
150 // and FlowEntryErrorState.
151 //
152 this.dataPath().flowEntries().add(flowEntry);
153 }
154 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800155
156 /**
157 * Get the flow path Flow ID.
158 *
159 * @return the flow path Flow ID.
160 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800161 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800162 public FlowId flowId() { return flowId; }
163
164 /**
165 * Set the flow path Flow ID.
166 *
167 * @param flowId the flow path Flow ID to set.
168 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800169 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800170 public void setFlowId(FlowId flowId) {
171 this.flowId = flowId;
172 }
173
174 /**
175 * Get the Caller ID of the flow path installer.
176 *
177 * @return the Caller ID of the flow path installer.
178 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800179 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800180 public CallerId installerId() { return installerId; }
181
182 /**
183 * Set the Caller ID of the flow path installer.
184 *
185 * @param installerId the Caller ID of the flow path installer.
186 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800187 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800188 public void setInstallerId(CallerId installerId) {
189 this.installerId = installerId;
190 }
191
192 /**
193 * Get the flow path's data path.
194 *
195 * @return the flow path's data path.
196 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800197 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800198 public DataPath dataPath() { return dataPath; }
199
200 /**
201 * Set the flow path's data path.
202 *
203 * @param dataPath the flow path's data path to set.
204 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800205 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800206 public void setDataPath(DataPath dataPath) {
207 this.dataPath = dataPath;
208 }
209
210 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700211 * Get the flow path's match conditions common for all Flow Entries.
212 *
213 * @return the flow path's match conditions common for all Flow Entries.
214 */
215 @JsonProperty("flowEntryMatch")
216 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
217
218 /**
219 * Set the flow path's match conditions common for all Flow Entries.
220 *
221 * @param flowEntryMatch the flow path's match conditions common for all
222 * Flow Entries.
223 */
224 @JsonProperty("flowEntryMatch")
225 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
226 this.flowEntryMatch = flowEntryMatch;
227 }
228
229 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800230 * Convert the flow path to a string.
231 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800232 * The string has the following form:
233 * [flowId=XXX installerId=XXX dataPath=XXX]
234 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800235 * @return the flow path as a string.
236 */
237 @Override
238 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800239 String ret = "[flowId=" + this.flowId.toString();
240 ret += " installerId=" + this.installerId.toString();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700241 if (dataPath != null)
242 ret += " dataPath=" + this.dataPath.toString();
243 if (flowEntryMatch != null)
244 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800245 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800246 return ret;
247 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700248
249 /**
250 * CompareTo method to order flowPath by Id
251 */
252 @Override
253 public int compareTo(FlowPath f) {
254 return (int) (this.flowId.value() - f.flowId.value());
255 }
256
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800257}