blob: f9385e739a6cc35d65f4c9957e2502ffdc8bb535 [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();
44 Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType();
45 if (matchEthernetFrameType != null)
46 match.enableEthernetFrameType(matchEthernetFrameType);
47 String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net();
48 if (matchSrcIPv4Net != null)
49 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
50 String matchDstIPv4Net = flowObj.getMatchDstIPv4Net();
51 if (matchDstIPv4Net != null)
52 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
53 String matchSrcMac = flowObj.getMatchSrcMac();
54 if (matchSrcMac != null)
55 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
56 String matchDstMac = flowObj.getMatchDstMac();
57 if (matchDstMac != null)
58 match.enableDstMac(MACAddress.valueOf(matchDstMac));
59 this.setFlowEntryMatch(match);
60 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -070061
62 //
63 // Extract all Flow Entries
64 //
65 Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
66 for (IFlowEntry flowEntryObj : flowEntries) {
67 FlowEntry flowEntry = new FlowEntry();
68 flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId()));
69 flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid()));
70
71 //
72 // Extract the match conditions
73 //
74 FlowEntryMatch match = new FlowEntryMatch();
75 Short matchInPort = flowEntryObj.getMatchInPort();
76 if (matchInPort != null)
77 match.enableInPort(new Port(matchInPort));
78 Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType();
79 if (matchEthernetFrameType != null)
80 match.enableEthernetFrameType(matchEthernetFrameType);
81 String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net();
82 if (matchSrcIPv4Net != null)
83 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
84 String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net();
85 if (matchDstIPv4Net != null)
86 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
87 String matchSrcMac = flowEntryObj.getMatchSrcMac();
88 if (matchSrcMac != null)
89 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
90 String matchDstMac = flowEntryObj.getMatchDstMac();
91 if (matchDstMac != null)
92 match.enableDstMac(MACAddress.valueOf(matchDstMac));
93 flowEntry.setFlowEntryMatch(match);
94
95 //
96 // Extract the actions
97 //
98 ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>();
99 Short actionOutputPort = flowEntryObj.getActionOutput();
100 if (actionOutputPort != null) {
101 FlowEntryAction action = new FlowEntryAction();
102 action.setActionOutput(new Port(actionOutputPort));
103 actions.add(action);
104 }
105 flowEntry.setFlowEntryActions(actions);
106
107 String userState = flowEntryObj.getUserState();
108 flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState));
109 String switchState = flowEntryObj.getSwitchState();
110 flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState));
111 //
112 // TODO: Take care of the FlowEntryMatch, FlowEntryAction set,
113 // and FlowEntryErrorState.
114 //
115 this.dataPath().flowEntries().add(flowEntry);
116 }
117 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800118
119 /**
120 * Get the flow path Flow ID.
121 *
122 * @return the flow path Flow ID.
123 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800124 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800125 public FlowId flowId() { return flowId; }
126
127 /**
128 * Set the flow path Flow ID.
129 *
130 * @param flowId the flow path Flow ID to set.
131 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800132 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800133 public void setFlowId(FlowId flowId) {
134 this.flowId = flowId;
135 }
136
137 /**
138 * Get the Caller ID of the flow path installer.
139 *
140 * @return the Caller ID of the flow path installer.
141 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800142 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800143 public CallerId installerId() { return installerId; }
144
145 /**
146 * Set the Caller ID of the flow path installer.
147 *
148 * @param installerId the Caller ID of the flow path installer.
149 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800150 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800151 public void setInstallerId(CallerId installerId) {
152 this.installerId = installerId;
153 }
154
155 /**
156 * Get the flow path's data path.
157 *
158 * @return the flow path's data path.
159 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800160 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800161 public DataPath dataPath() { return dataPath; }
162
163 /**
164 * Set the flow path's data path.
165 *
166 * @param dataPath the flow path's data path to set.
167 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800168 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800169 public void setDataPath(DataPath dataPath) {
170 this.dataPath = dataPath;
171 }
172
173 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700174 * Get the flow path's match conditions common for all Flow Entries.
175 *
176 * @return the flow path's match conditions common for all Flow Entries.
177 */
178 @JsonProperty("flowEntryMatch")
179 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
180
181 /**
182 * Set the flow path's match conditions common for all Flow Entries.
183 *
184 * @param flowEntryMatch the flow path's match conditions common for all
185 * Flow Entries.
186 */
187 @JsonProperty("flowEntryMatch")
188 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
189 this.flowEntryMatch = flowEntryMatch;
190 }
191
192 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800193 * Convert the flow path to a string.
194 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800195 * The string has the following form:
196 * [flowId=XXX installerId=XXX dataPath=XXX]
197 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800198 * @return the flow path as a string.
199 */
200 @Override
201 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800202 String ret = "[flowId=" + this.flowId.toString();
203 ret += " installerId=" + this.installerId.toString();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700204 if (dataPath != null)
205 ret += " dataPath=" + this.dataPath.toString();
206 if (flowEntryMatch != null)
207 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800208 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800209 return ret;
210 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700211
212 /**
213 * CompareTo method to order flowPath by Id
214 */
215 @Override
216 public int compareTo(FlowPath f) {
217 return (int) (this.flowId.value() - f.flowId.value());
218 }
219
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800220}