blob: 2e616368493801d72f77428c5e75bec822fdd7c6 [file] [log] [blame]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08001package net.floodlightcontroller.util;
2
Pavlin Radoslavovede97582013-03-08 18:57:28 -08003import java.util.ArrayList;
4
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08005import net.floodlightcontroller.util.Dpid;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08006import net.floodlightcontroller.util.FlowEntryAction;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08007import net.floodlightcontroller.util.FlowEntryId;
8import net.floodlightcontroller.util.FlowEntryMatch;
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -08009import net.floodlightcontroller.util.FlowEntrySwitchState;
10import net.floodlightcontroller.util.FlowEntryUserState;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080011import net.floodlightcontroller.util.Port;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080012
Pavlin Radoslavovede97582013-03-08 18:57:28 -080013import net.floodlightcontroller.util.MACAddress;
14import net.floodlightcontroller.util.IPv4;
15
Pankaj Berded0ae0ff2013-03-26 15:37:12 -070016import org.codehaus.jackson.annotate.JsonIgnore;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080017import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080018
19/**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080020 * The class representing the Flow Entry.
21 *
22 * NOTE: The specification is incomplete. E.g., the entry needs to
23 * support multiple in-ports and multiple out-ports.
24 */
25public class FlowEntry {
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -070026 private FlowId flowId; // FlowID of flowEntry
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080027 private FlowEntryId flowEntryId; // The Flow Entry ID
28 private FlowEntryMatch flowEntryMatch; // The Flow Entry Match
Pavlin Radoslavovede97582013-03-08 18:57:28 -080029 private ArrayList<FlowEntryAction> flowEntryActions; // The Flow Entry Actions
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080030 private Dpid dpid; // The Switch DPID
Pavlin Radoslavovfbcb97c2013-03-21 11:29:58 -070031 private Port inPort; // The Switch incoming port. Used only
32 // when the entry is used to return
33 // Shortest Path computation.
34 private Port outPort; // The Switch outgoing port. Used only
35 // when the entry is used to return
36 // Shortest Path computation.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080037 private FlowEntryUserState flowEntryUserState; // The Flow Entry User state
38 private FlowEntrySwitchState flowEntrySwitchState; // The Flow Entry Switch state
39 // The Flow Entry Error state (if FlowEntrySwitchState is FE_SWITCH_FAILED)
40 private FlowEntryErrorState flowEntryErrorState;
41
42 /**
43 * Default constructor.
44 */
45 public FlowEntry() {
Pavlin Radoslavovede97582013-03-08 18:57:28 -080046 // TODO: Test code
47 /*
48 MACAddress mac = MACAddress.valueOf("01:02:03:04:05:06");
49 IPv4 ipv4 = new IPv4("1.2.3.4");
50 IPv4Net ipv4net = new IPv4Net("5.6.7.0/24");
51
52 flowEntryMatch = new FlowEntryMatch();
53 flowEntryMatch.enableInPort(new Port((short)10));
54 flowEntryMatch.enableSrcMac(mac);
55 flowEntryMatch.enableDstMac(mac);
56 flowEntryMatch.enableVlanId((short)20);
57 flowEntryMatch.enableVlanPriority((byte)30);
58 flowEntryMatch.enableEthernetFrameType((short)40);
59 flowEntryMatch.enableIpToS((byte)50);
60 flowEntryMatch.enableIpProto((byte)60);
61 flowEntryMatch.enableSrcIPv4Net(ipv4net);
62 flowEntryMatch.enableDstIPv4Net(ipv4net);
63 flowEntryMatch.enableSrcTcpUdpPort((short)70);
64 flowEntryMatch.enableDstTcpUdpPort((short)80);
65
66 FlowEntryAction action = null;
67 ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>();
68
69 action = new FlowEntryAction();
70 action.setActionOutput(new Port((short)12));
71 actions.add(action);
72
73 action = new FlowEntryAction();
74 action.setActionOutputToController((short)13);
75 actions.add(action);
76
77 action = new FlowEntryAction();
78 action.setActionSetVlanId((short)14);
79 actions.add(action);
80
81 action = new FlowEntryAction();
82 action.setActionSetVlanPriority((byte)15);
83 actions.add(action);
84
85 action = new FlowEntryAction();
86 action.setActionStripVlan(true);
87 actions.add(action);
88
89 action = new FlowEntryAction();
90 action.setActionSetEthernetSrcAddr(mac);
91 actions.add(action);
92
93 action = new FlowEntryAction();
94 action.setActionSetEthernetDstAddr(mac);
95 actions.add(action);
96
97 action = new FlowEntryAction();
98 action.setActionSetIPv4SrcAddr(ipv4);
99 actions.add(action);
100
101 action = new FlowEntryAction();
102 action.setActionSetIPv4DstAddr(ipv4);
103 actions.add(action);
104
105 action = new FlowEntryAction();
106 action.setActionSetIpToS((byte)16);
107 actions.add(action);
108
109 action = new FlowEntryAction();
110 action.setActionSetTcpUdpSrcPort((short)17);
111 actions.add(action);
112
113 action = new FlowEntryAction();
114 action.setActionSetTcpUdpDstPort((short)18);
115 actions.add(action);
116
117 action = new FlowEntryAction();
118 action.setActionEnqueue(new Port((short)19), 20);
119 actions.add(action);
120
121 setFlowEntryActions(actions);
122 */
123
124
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800125 flowEntryUserState = FlowEntryUserState.FE_USER_UNKNOWN;
126 flowEntrySwitchState = FlowEntrySwitchState.FE_SWITCH_UNKNOWN;
127 }
128
129 /**
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -0700130 * Get the Flow ID.
131 * @return the Flow ID.
132 */
133 @JsonIgnore
134 public FlowId getFlowId() { return flowId; }
135
136 /**
137 * Set the Flow ID.
138 *
139 * @param flowId the Flow ID to set.
140 */
141 public void setFlowId(FlowId flowId) {
142 this.flowId = flowId;
143 }
144
145 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800146 * Get the Flow Entry ID.
147 *
148 * @return the Flow Entry ID.
149 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800150 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800151 public FlowEntryId flowEntryId() { return flowEntryId; }
152
153 /**
154 * Set the Flow Entry ID.
155 *
156 * @param flowEntryId the Flow Entry ID to set.
157 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800158 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800159 public void setFlowEntryId(FlowEntryId flowEntryId) {
160 this.flowEntryId = flowEntryId;
161 }
162
163 /**
164 * Get the Flow Entry Match.
165 *
166 * @return the Flow Entry Match.
167 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800168 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800169 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
170
171 /**
172 * Set the Flow Entry Match.
173 *
174 * @param flowEntryMatch the Flow Entry Match to set.
175 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800176 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800177 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
178 this.flowEntryMatch = flowEntryMatch;
179 }
180
181 /**
182 * Get the Flow Entry Actions.
183 *
184 * @return the Flow Entry Actions.
185 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800186 @JsonProperty("flowEntryActions")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800187 public ArrayList<FlowEntryAction> flowEntryActions() {
188 return flowEntryActions;
189 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800190
191 /**
192 * Set the Flow Entry Actions.
193 *
194 * @param flowEntryActions the Flow Entry Actions to set.
195 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800196 @JsonProperty("flowEntryActions")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800197 public void setFlowEntryActions(ArrayList<FlowEntryAction> flowEntryActions) {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800198 this.flowEntryActions = flowEntryActions;
199 }
200
201 /**
202 * Get the Switch DPID.
203 *
204 * @return the Switch DPID.
205 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800206 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800207 public Dpid dpid() { return dpid; }
208
209 /**
210 * Set the Switch DPID.
211 *
212 * @param dpid the Switch DPID to set.
213 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800214 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800215 public void setDpid(Dpid dpid) {
216 this.dpid = dpid;
217 }
218
219 /**
220 * Get the Switch incoming port.
221 *
222 * @return the Switch incoming port.
223 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800224 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800225 public Port inPort() { return inPort; }
226
227 /**
228 * Set the Switch incoming port.
229 *
230 * @param inPort the Switch incoming port to set.
231 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800232 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800233 public void setInPort(Port inPort) {
234 this.inPort = inPort;
235 }
236
237 /**
238 * Get the Switch outgoing port.
239 *
240 * @return the Switch outgoing port.
241 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800242 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800243 public Port outPort() { return outPort; }
244
245 /**
246 * Set the Switch outgoing port.
247 *
248 * @param outPort the Switch outgoing port to set.
249 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800250 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800251 public void setOutPort(Port outPort) {
252 this.outPort = outPort;
253 }
254
255 /**
256 * Get the Flow Entry User state.
257 *
258 * @return the Flow Entry User state.
259 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800260 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800261 public FlowEntryUserState flowEntryUserState() {
262 return flowEntryUserState;
263 }
264
265 /**
266 * Set the Flow Entry User state.
267 *
268 * @param flowEntryUserState the Flow Entry User state to set.
269 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800270 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800271 public void setFlowEntryUserState(FlowEntryUserState flowEntryUserState) {
272 this.flowEntryUserState = flowEntryUserState;
273 }
274
275 /**
276 * Get the Flow Entry Switch state.
277 *
278 * The Flow Entry Error state is used if FlowEntrySwitchState is
279 * FE_SWITCH_FAILED.
280 *
281 * @return the Flow Entry Switch state.
282 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800283 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800284 public FlowEntrySwitchState flowEntrySwitchState() {
285 return flowEntrySwitchState;
286 }
287
288 /**
289 * Set the Flow Entry Switch state.
290 *
291 * The Flow Entry Error state is used if FlowEntrySwitchState is
292 * FE_SWITCH_FAILED.
293 *
294 * @param flowEntrySwitchState the Flow Entry Switch state to set.
295 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800296 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800297 public void setFlowEntrySwitchState(FlowEntrySwitchState flowEntrySwitchState) {
298 this.flowEntrySwitchState = flowEntrySwitchState;
299 }
300
301 /**
302 * Get the Flow Entry Error state.
303 *
304 * @return the Flow Entry Error state.
305 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800306 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800307 public FlowEntryErrorState flowEntryErrorState() {
308 return flowEntryErrorState;
309 }
310
311 /**
312 * Set the Flow Entry Error state.
313 *
314 * @param flowEntryErrorState the Flow Entry Error state to set.
315 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800316 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800317 public void setFlowEntryErrorState(FlowEntryErrorState flowEntryErrorState) {
318 this.flowEntryErrorState = flowEntryErrorState;
319 }
320
321 /**
322 * Convert the flow entry to a string.
323 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800324 * The string has the following form:
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800325 * [flowEntryId=XXX flowEntryMatch=XXX flowEntryAction=XXX
326 * flowEntryAction=XXX flowEntryAction=XXX dpid=XXX
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800327 * inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX
328 * flowEntryErrorState=XXX]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800329 * @return the flow entry as a string.
330 */
331 @Override
332 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800333 String ret = "[flowEntryId=" + this.flowEntryId.toString();
334 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800335 for (FlowEntryAction fa : flowEntryActions) {
336 ret += " flowEntryAction=" + fa.toString();
337 }
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800338 ret += " dpid=" + this.dpid.toString();
339 ret += " inPort=" + this.inPort.toString();
340 ret += " outPort=" + this.outPort.toString();
341 ret += " flowEntryUserState=" + this.flowEntryUserState;
342 ret += " flowEntrySwitchState=" + this.flowEntrySwitchState;
343 ret += " flowEntryErrorState=" + this.flowEntryErrorState.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800344 ret += "]";
345
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800346 return ret;
347 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800348}