blob: b171b8851399a3284bfc73b9fe0990010a921fb7 [file] [log] [blame]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08001package net.floodlightcontroller.util;
2
Pankaj Berde6a97eb82013-03-28 12:12:43 -07003import java.util.ArrayList;
4
5import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry;
6import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08007import net.floodlightcontroller.util.CallerId;
8import net.floodlightcontroller.util.DataPath;
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -07009import net.floodlightcontroller.util.FlowEntryMatch;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080010import net.floodlightcontroller.util.FlowId;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080011
12import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080013
14/**
15 * The class representing the Flow Path.
16 */
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -070017public class FlowPath implements Comparable<FlowPath> {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080018 private FlowId flowId; // The Flow ID
19 private CallerId installerId; // The Caller ID of the path installer
20 private DataPath dataPath; // The data path
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070021 private FlowEntryMatch flowEntryMatch; // Common Flow Entry Match for all
22 // Flow Entries
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080023
24 /**
25 * Default constructor.
26 */
27 public FlowPath() {
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()));
38 this.dataPath().srcPort().setDpid(new Dpid(flowObj.getSrcSwitch()));
39 this.dataPath().srcPort().setPort(new Port(flowObj.getSrcPort()));
40 this.dataPath().dstPort().setDpid(new Dpid(flowObj.getDstSwitch()));
41 this.dataPath().dstPort().setPort(new Port(flowObj.getDstPort()));
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -070042 //
43 // Extract the match conditions that are common for all Flow Entries
44 //
45 {
46 FlowEntryMatch match = new FlowEntryMatch();
47 Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType();
48 if (matchEthernetFrameType != null)
49 match.enableEthernetFrameType(matchEthernetFrameType);
50 String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net();
51 if (matchSrcIPv4Net != null)
52 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
53 String matchDstIPv4Net = flowObj.getMatchDstIPv4Net();
54 if (matchDstIPv4Net != null)
55 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
56 String matchSrcMac = flowObj.getMatchSrcMac();
57 if (matchSrcMac != null)
58 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
59 String matchDstMac = flowObj.getMatchDstMac();
60 if (matchDstMac != null)
61 match.enableDstMac(MACAddress.valueOf(matchDstMac));
62 this.setFlowEntryMatch(match);
63 }
Pankaj Berde6a97eb82013-03-28 12:12:43 -070064
65 //
66 // Extract all Flow Entries
67 //
68 Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries();
69 for (IFlowEntry flowEntryObj : flowEntries) {
70 FlowEntry flowEntry = new FlowEntry();
71 flowEntry.setFlowEntryId(new FlowEntryId(flowEntryObj.getFlowEntryId()));
72 flowEntry.setDpid(new Dpid(flowEntryObj.getSwitchDpid()));
73
74 //
75 // Extract the match conditions
76 //
77 FlowEntryMatch match = new FlowEntryMatch();
78 Short matchInPort = flowEntryObj.getMatchInPort();
79 if (matchInPort != null)
80 match.enableInPort(new Port(matchInPort));
81 Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType();
82 if (matchEthernetFrameType != null)
83 match.enableEthernetFrameType(matchEthernetFrameType);
84 String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net();
85 if (matchSrcIPv4Net != null)
86 match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net));
87 String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net();
88 if (matchDstIPv4Net != null)
89 match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net));
90 String matchSrcMac = flowEntryObj.getMatchSrcMac();
91 if (matchSrcMac != null)
92 match.enableSrcMac(MACAddress.valueOf(matchSrcMac));
93 String matchDstMac = flowEntryObj.getMatchDstMac();
94 if (matchDstMac != null)
95 match.enableDstMac(MACAddress.valueOf(matchDstMac));
96 flowEntry.setFlowEntryMatch(match);
97
98 //
99 // Extract the actions
100 //
101 ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>();
102 Short actionOutputPort = flowEntryObj.getActionOutput();
103 if (actionOutputPort != null) {
104 FlowEntryAction action = new FlowEntryAction();
105 action.setActionOutput(new Port(actionOutputPort));
106 actions.add(action);
107 }
108 flowEntry.setFlowEntryActions(actions);
109
110 String userState = flowEntryObj.getUserState();
111 flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState));
112 String switchState = flowEntryObj.getSwitchState();
113 flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState));
114 //
115 // TODO: Take care of the FlowEntryMatch, FlowEntryAction set,
116 // and FlowEntryErrorState.
117 //
118 this.dataPath().flowEntries().add(flowEntry);
119 }
120 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800121
122 /**
123 * Get the flow path Flow ID.
124 *
125 * @return the flow path Flow ID.
126 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800127 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800128 public FlowId flowId() { return flowId; }
129
130 /**
131 * Set the flow path Flow ID.
132 *
133 * @param flowId the flow path Flow ID to set.
134 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800135 @JsonProperty("flowId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800136 public void setFlowId(FlowId flowId) {
137 this.flowId = flowId;
138 }
139
140 /**
141 * Get the Caller ID of the flow path installer.
142 *
143 * @return the Caller ID of the flow path installer.
144 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800145 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800146 public CallerId installerId() { return installerId; }
147
148 /**
149 * Set the Caller ID of the flow path installer.
150 *
151 * @param installerId the Caller ID of the flow path installer.
152 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800153 @JsonProperty("installerId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800154 public void setInstallerId(CallerId installerId) {
155 this.installerId = installerId;
156 }
157
158 /**
159 * Get the flow path's data path.
160 *
161 * @return the flow path's data path.
162 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800163 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800164 public DataPath dataPath() { return dataPath; }
165
166 /**
167 * Set the flow path's data path.
168 *
169 * @param dataPath the flow path's data path to set.
170 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800171 @JsonProperty("dataPath")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800172 public void setDataPath(DataPath dataPath) {
173 this.dataPath = dataPath;
174 }
175
176 /**
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700177 * Get the flow path's match conditions common for all Flow Entries.
178 *
179 * @return the flow path's match conditions common for all Flow Entries.
180 */
181 @JsonProperty("flowEntryMatch")
182 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
183
184 /**
185 * Set the flow path's match conditions common for all Flow Entries.
186 *
187 * @param flowEntryMatch the flow path's match conditions common for all
188 * Flow Entries.
189 */
190 @JsonProperty("flowEntryMatch")
191 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
192 this.flowEntryMatch = flowEntryMatch;
193 }
194
195 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800196 * Convert the flow path to a string.
197 *
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800198 * The string has the following form:
199 * [flowId=XXX installerId=XXX dataPath=XXX]
200 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800201 * @return the flow path as a string.
202 */
203 @Override
204 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800205 String ret = "[flowId=" + this.flowId.toString();
206 ret += " installerId=" + this.installerId.toString();
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700207 if (dataPath != null)
208 ret += " dataPath=" + this.dataPath.toString();
209 if (flowEntryMatch != null)
210 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800211 ret += "]";
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800212 return ret;
213 }
Umesh Krishnaswamy57a32a92013-03-21 14:21:15 -0700214
215 /**
216 * CompareTo method to order flowPath by Id
217 */
218 @Override
219 public int compareTo(FlowPath f) {
220 return (int) (this.flowId.value() - f.flowId.value());
221 }
222
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800223}