blob: 21f3a9e0cba877c47ba97a4cbf2c21842411534d [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 Radoslavov84540c12013-06-10 18:33:34 -07007import net.floodlightcontroller.util.FlowEntryErrorState;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08008import net.floodlightcontroller.util.FlowEntryId;
9import net.floodlightcontroller.util.FlowEntryMatch;
Pavlin Radoslavovb6f53542013-03-01 16:02:14 -080010import net.floodlightcontroller.util.FlowEntrySwitchState;
11import net.floodlightcontroller.util.FlowEntryUserState;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080012import net.floodlightcontroller.util.Port;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080013
Pavlin Radoslavovede97582013-03-08 18:57:28 -080014import net.floodlightcontroller.util.MACAddress;
15import net.floodlightcontroller.util.IPv4;
16
Pankaj Berded0ae0ff2013-03-26 15:37:12 -070017import org.codehaus.jackson.annotate.JsonIgnore;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080018import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080019
20/**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080021 * The class representing the Flow Entry.
22 *
23 * NOTE: The specification is incomplete. E.g., the entry needs to
24 * support multiple in-ports and multiple out-ports.
25 */
26public class FlowEntry {
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -070027 private FlowId flowId; // FlowID of flowEntry
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080028 private FlowEntryId flowEntryId; // The Flow Entry ID
29 private FlowEntryMatch flowEntryMatch; // The Flow Entry Match
Pavlin Radoslavovede97582013-03-08 18:57:28 -080030 private ArrayList<FlowEntryAction> flowEntryActions; // The Flow Entry Actions
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080031 private Dpid dpid; // The Switch DPID
Pavlin Radoslavovfbcb97c2013-03-21 11:29:58 -070032 private Port inPort; // The Switch incoming port. Used only
33 // when the entry is used to return
34 // Shortest Path computation.
35 private Port outPort; // The Switch outgoing port. Used only
36 // when the entry is used to return
37 // Shortest Path computation.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080038 private FlowEntryUserState flowEntryUserState; // The Flow Entry User state
39 private FlowEntrySwitchState flowEntrySwitchState; // The Flow Entry Switch state
40 // The Flow Entry Error state (if FlowEntrySwitchState is FE_SWITCH_FAILED)
41 private FlowEntryErrorState flowEntryErrorState;
42
43 /**
44 * Default constructor.
45 */
46 public FlowEntry() {
Pavlin Radoslavovede97582013-03-08 18:57:28 -080047 // TODO: Test code
48 /*
49 MACAddress mac = MACAddress.valueOf("01:02:03:04:05:06");
50 IPv4 ipv4 = new IPv4("1.2.3.4");
51 IPv4Net ipv4net = new IPv4Net("5.6.7.0/24");
52
53 flowEntryMatch = new FlowEntryMatch();
54 flowEntryMatch.enableInPort(new Port((short)10));
55 flowEntryMatch.enableSrcMac(mac);
56 flowEntryMatch.enableDstMac(mac);
57 flowEntryMatch.enableVlanId((short)20);
58 flowEntryMatch.enableVlanPriority((byte)30);
59 flowEntryMatch.enableEthernetFrameType((short)40);
60 flowEntryMatch.enableIpToS((byte)50);
61 flowEntryMatch.enableIpProto((byte)60);
62 flowEntryMatch.enableSrcIPv4Net(ipv4net);
63 flowEntryMatch.enableDstIPv4Net(ipv4net);
64 flowEntryMatch.enableSrcTcpUdpPort((short)70);
65 flowEntryMatch.enableDstTcpUdpPort((short)80);
66
67 FlowEntryAction action = null;
68 ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>();
69
70 action = new FlowEntryAction();
71 action.setActionOutput(new Port((short)12));
72 actions.add(action);
73
74 action = new FlowEntryAction();
75 action.setActionOutputToController((short)13);
76 actions.add(action);
77
78 action = new FlowEntryAction();
79 action.setActionSetVlanId((short)14);
80 actions.add(action);
81
82 action = new FlowEntryAction();
83 action.setActionSetVlanPriority((byte)15);
84 actions.add(action);
85
86 action = new FlowEntryAction();
87 action.setActionStripVlan(true);
88 actions.add(action);
89
90 action = new FlowEntryAction();
91 action.setActionSetEthernetSrcAddr(mac);
92 actions.add(action);
93
94 action = new FlowEntryAction();
95 action.setActionSetEthernetDstAddr(mac);
96 actions.add(action);
97
98 action = new FlowEntryAction();
99 action.setActionSetIPv4SrcAddr(ipv4);
100 actions.add(action);
101
102 action = new FlowEntryAction();
103 action.setActionSetIPv4DstAddr(ipv4);
104 actions.add(action);
105
106 action = new FlowEntryAction();
107 action.setActionSetIpToS((byte)16);
108 actions.add(action);
109
110 action = new FlowEntryAction();
111 action.setActionSetTcpUdpSrcPort((short)17);
112 actions.add(action);
113
114 action = new FlowEntryAction();
115 action.setActionSetTcpUdpDstPort((short)18);
116 actions.add(action);
117
118 action = new FlowEntryAction();
119 action.setActionEnqueue(new Port((short)19), 20);
120 actions.add(action);
121
122 setFlowEntryActions(actions);
123 */
124
125
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800126 flowEntryUserState = FlowEntryUserState.FE_USER_UNKNOWN;
127 flowEntrySwitchState = FlowEntrySwitchState.FE_SWITCH_UNKNOWN;
128 }
129
130 /**
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -0700131 * Get the Flow ID.
132 * @return the Flow ID.
133 */
134 @JsonIgnore
135 public FlowId getFlowId() { return flowId; }
136
137 /**
138 * Set the Flow ID.
139 *
140 * @param flowId the Flow ID to set.
141 */
142 public void setFlowId(FlowId flowId) {
143 this.flowId = flowId;
144 }
145
146 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800147 * Get the Flow Entry ID.
148 *
149 * @return the Flow Entry ID.
150 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800151 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800152 public FlowEntryId flowEntryId() { return flowEntryId; }
153
154 /**
155 * Set the Flow Entry ID.
156 *
157 * @param flowEntryId the Flow Entry ID to set.
158 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800159 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800160 public void setFlowEntryId(FlowEntryId flowEntryId) {
161 this.flowEntryId = flowEntryId;
162 }
163
164 /**
165 * Get the Flow Entry Match.
166 *
167 * @return the Flow Entry Match.
168 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800169 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800170 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
171
172 /**
173 * Set the Flow Entry Match.
174 *
175 * @param flowEntryMatch the Flow Entry Match to set.
176 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800177 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800178 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
179 this.flowEntryMatch = flowEntryMatch;
180 }
181
182 /**
183 * Get the Flow Entry Actions.
184 *
185 * @return the Flow Entry Actions.
186 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800187 @JsonProperty("flowEntryActions")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800188 public ArrayList<FlowEntryAction> flowEntryActions() {
189 return flowEntryActions;
190 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800191
192 /**
193 * Set the Flow Entry Actions.
194 *
195 * @param flowEntryActions the Flow Entry Actions to set.
196 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800197 @JsonProperty("flowEntryActions")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800198 public void setFlowEntryActions(ArrayList<FlowEntryAction> flowEntryActions) {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800199 this.flowEntryActions = flowEntryActions;
200 }
201
202 /**
203 * Get the Switch DPID.
204 *
205 * @return the Switch DPID.
206 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800207 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800208 public Dpid dpid() { return dpid; }
209
210 /**
211 * Set the Switch DPID.
212 *
213 * @param dpid the Switch DPID to set.
214 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800215 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800216 public void setDpid(Dpid dpid) {
217 this.dpid = dpid;
218 }
219
220 /**
221 * Get the Switch incoming port.
222 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700223 * Used only when the entry is used to return Shortest Path computation.
224 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800225 * @return the Switch incoming port.
226 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800227 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800228 public Port inPort() { return inPort; }
229
230 /**
231 * Set the Switch incoming port.
232 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700233 * Used only when the entry is used to return Shortest Path computation.
234 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800235 * @param inPort the Switch incoming port to set.
236 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800237 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800238 public void setInPort(Port inPort) {
239 this.inPort = inPort;
240 }
241
242 /**
243 * Get the Switch outgoing port.
244 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700245 * Used only when the entry is used to return Shortest Path computation.
246 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800247 * @return the Switch outgoing port.
248 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800249 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800250 public Port outPort() { return outPort; }
251
252 /**
253 * Set the Switch outgoing port.
254 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700255 * Used only when the entry is used to return Shortest Path computation.
256 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800257 * @param outPort the Switch outgoing port to set.
258 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800259 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800260 public void setOutPort(Port outPort) {
261 this.outPort = outPort;
262 }
263
264 /**
265 * Get the Flow Entry User state.
266 *
267 * @return the Flow Entry User state.
268 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800269 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800270 public FlowEntryUserState flowEntryUserState() {
271 return flowEntryUserState;
272 }
273
274 /**
275 * Set the Flow Entry User state.
276 *
277 * @param flowEntryUserState the Flow Entry User state to set.
278 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800279 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800280 public void setFlowEntryUserState(FlowEntryUserState flowEntryUserState) {
281 this.flowEntryUserState = flowEntryUserState;
282 }
283
284 /**
285 * Get the Flow Entry Switch state.
286 *
287 * The Flow Entry Error state is used if FlowEntrySwitchState is
288 * FE_SWITCH_FAILED.
289 *
290 * @return the Flow Entry Switch state.
291 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800292 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800293 public FlowEntrySwitchState flowEntrySwitchState() {
294 return flowEntrySwitchState;
295 }
296
297 /**
298 * Set the Flow Entry Switch state.
299 *
300 * The Flow Entry Error state is used if FlowEntrySwitchState is
301 * FE_SWITCH_FAILED.
302 *
303 * @param flowEntrySwitchState the Flow Entry Switch state to set.
304 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800305 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800306 public void setFlowEntrySwitchState(FlowEntrySwitchState flowEntrySwitchState) {
307 this.flowEntrySwitchState = flowEntrySwitchState;
308 }
309
310 /**
311 * Get the Flow Entry Error state.
312 *
313 * @return the Flow Entry Error state.
314 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800315 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800316 public FlowEntryErrorState flowEntryErrorState() {
317 return flowEntryErrorState;
318 }
319
320 /**
321 * Set the Flow Entry Error state.
322 *
323 * @param flowEntryErrorState the Flow Entry Error state to set.
324 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800325 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800326 public void setFlowEntryErrorState(FlowEntryErrorState flowEntryErrorState) {
327 this.flowEntryErrorState = flowEntryErrorState;
328 }
329
330 /**
331 * Convert the flow entry to a string.
332 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800333 * The string has the following form:
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800334 * [flowEntryId=XXX flowEntryMatch=XXX flowEntryAction=XXX
335 * flowEntryAction=XXX flowEntryAction=XXX dpid=XXX
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800336 * inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX
337 * flowEntryErrorState=XXX]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800338 * @return the flow entry as a string.
339 */
340 @Override
341 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800342 String ret = "[flowEntryId=" + this.flowEntryId.toString();
343 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800344 for (FlowEntryAction fa : flowEntryActions) {
345 ret += " flowEntryAction=" + fa.toString();
346 }
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800347 ret += " dpid=" + this.dpid.toString();
348 ret += " inPort=" + this.inPort.toString();
349 ret += " outPort=" + this.outPort.toString();
350 ret += " flowEntryUserState=" + this.flowEntryUserState;
351 ret += " flowEntrySwitchState=" + this.flowEntrySwitchState;
352 ret += " flowEntryErrorState=" + this.flowEntryErrorState.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800353 ret += "]";
354
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800355 return ret;
356 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800357}