blob: 56a1631a5f141c45aad76ff62ac63b9b5a53a72d [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 {
Pankaj Berded0ae0ff2013-03-26 15:37:12 -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 /**
130 * Get the Flow Entry ID.
131 *
132 * @return the Flow Entry ID.
133 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800134 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800135 public FlowEntryId flowEntryId() { return flowEntryId; }
136
137 /**
138 * Set the Flow Entry ID.
139 *
140 * @param flowEntryId the Flow Entry ID to set.
141 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800142 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800143 public void setFlowEntryId(FlowEntryId flowEntryId) {
144 this.flowEntryId = flowEntryId;
145 }
146
147 /**
148 * Get the Flow Entry Match.
149 *
150 * @return the Flow Entry Match.
151 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800152 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800153 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
154
155 /**
156 * Set the Flow Entry Match.
157 *
158 * @param flowEntryMatch the Flow Entry Match to set.
159 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800160 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800161 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
162 this.flowEntryMatch = flowEntryMatch;
163 }
164
165 /**
166 * Get the Flow Entry Actions.
167 *
168 * @return the Flow Entry Actions.
169 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800170 @JsonProperty("flowEntryActions")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800171 public ArrayList<FlowEntryAction> flowEntryActions() {
172 return flowEntryActions;
173 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800174
175 /**
176 * Set the Flow Entry Actions.
177 *
178 * @param flowEntryActions the Flow Entry Actions to set.
179 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800180 @JsonProperty("flowEntryActions")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800181 public void setFlowEntryActions(ArrayList<FlowEntryAction> flowEntryActions) {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800182 this.flowEntryActions = flowEntryActions;
183 }
184
185 /**
186 * Get the Switch DPID.
187 *
188 * @return the Switch DPID.
189 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800190 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800191 public Dpid dpid() { return dpid; }
192
193 /**
194 * Set the Switch DPID.
195 *
196 * @param dpid the Switch DPID to set.
197 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800198 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800199 public void setDpid(Dpid dpid) {
200 this.dpid = dpid;
201 }
202
203 /**
204 * Get the Switch incoming port.
205 *
206 * @return the Switch incoming port.
207 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800208 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800209 public Port inPort() { return inPort; }
210
211 /**
212 * Set the Switch incoming port.
213 *
214 * @param inPort the Switch incoming port to set.
215 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800216 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800217 public void setInPort(Port inPort) {
218 this.inPort = inPort;
219 }
220
221 /**
222 * Get the Switch outgoing port.
223 *
224 * @return the Switch outgoing port.
225 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800226 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800227 public Port outPort() { return outPort; }
228
229 /**
230 * Set the Switch outgoing port.
231 *
232 * @param outPort the Switch outgoing port to set.
233 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800234 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800235 public void setOutPort(Port outPort) {
236 this.outPort = outPort;
237 }
238
239 /**
240 * Get the Flow Entry User state.
241 *
242 * @return the Flow Entry User state.
243 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800244 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800245 public FlowEntryUserState flowEntryUserState() {
246 return flowEntryUserState;
247 }
248
249 /**
250 * Set the Flow Entry User state.
251 *
252 * @param flowEntryUserState the Flow Entry User state to set.
253 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800254 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800255 public void setFlowEntryUserState(FlowEntryUserState flowEntryUserState) {
256 this.flowEntryUserState = flowEntryUserState;
257 }
258
259 /**
260 * Get the Flow Entry Switch state.
261 *
262 * The Flow Entry Error state is used if FlowEntrySwitchState is
263 * FE_SWITCH_FAILED.
264 *
265 * @return the Flow Entry Switch state.
266 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800267 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800268 public FlowEntrySwitchState flowEntrySwitchState() {
269 return flowEntrySwitchState;
270 }
271
272 /**
273 * Set the Flow Entry Switch state.
274 *
275 * The Flow Entry Error state is used if FlowEntrySwitchState is
276 * FE_SWITCH_FAILED.
277 *
278 * @param flowEntrySwitchState the Flow Entry Switch state to set.
279 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800280 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800281 public void setFlowEntrySwitchState(FlowEntrySwitchState flowEntrySwitchState) {
282 this.flowEntrySwitchState = flowEntrySwitchState;
283 }
284
285 /**
286 * Get the Flow Entry Error state.
287 *
288 * @return the Flow Entry Error state.
289 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800290 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800291 public FlowEntryErrorState flowEntryErrorState() {
292 return flowEntryErrorState;
293 }
294
295 /**
296 * Set the Flow Entry Error state.
297 *
298 * @param flowEntryErrorState the Flow Entry Error state to set.
299 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800300 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800301 public void setFlowEntryErrorState(FlowEntryErrorState flowEntryErrorState) {
302 this.flowEntryErrorState = flowEntryErrorState;
303 }
304
305 /**
306 * Convert the flow entry to a string.
307 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800308 * The string has the following form:
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800309 * [flowEntryId=XXX flowEntryMatch=XXX flowEntryAction=XXX
310 * flowEntryAction=XXX flowEntryAction=XXX dpid=XXX
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800311 * inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX
312 * flowEntryErrorState=XXX]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800313 * @return the flow entry as a string.
314 */
315 @Override
316 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800317 String ret = "[flowEntryId=" + this.flowEntryId.toString();
318 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800319 for (FlowEntryAction fa : flowEntryActions) {
320 ret += " flowEntryAction=" + fa.toString();
321 }
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800322 ret += " dpid=" + this.dpid.toString();
323 ret += " inPort=" + this.inPort.toString();
324 ret += " outPort=" + this.outPort.toString();
325 ret += " flowEntryUserState=" + this.flowEntryUserState;
326 ret += " flowEntrySwitchState=" + this.flowEntrySwitchState;
327 ret += " flowEntryErrorState=" + this.flowEntryErrorState.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800328 ret += "]";
329
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800330 return ret;
331 }
Pankaj Berded0ae0ff2013-03-26 15:37:12 -0700332
333 /**
334 * @return the flowId
335 */
336 @JsonIgnore
337 public FlowId getFlowId() {
338 return flowId;
339 }
340
341 /**
342 * @param flowId the flowId to set
343 */
344 public void setFlowId(FlowId flowId) {
345 this.flowId = flowId;
346 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800347}