blob: 64c32b4e2a4fcc9597b3c441560eca8d574b34b2 [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
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080016import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080017
18/**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080019 * The class representing the Flow Entry.
20 *
21 * NOTE: The specification is incomplete. E.g., the entry needs to
22 * support multiple in-ports and multiple out-ports.
23 */
24public class FlowEntry {
25 private FlowEntryId flowEntryId; // The Flow Entry ID
26 private FlowEntryMatch flowEntryMatch; // The Flow Entry Match
Pavlin Radoslavovede97582013-03-08 18:57:28 -080027 private ArrayList<FlowEntryAction> flowEntryActions; // The Flow Entry Actions
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080028 private Dpid dpid; // The Switch DPID
29 private Port inPort; // The Switch incoming port
30 private Port outPort; // The Switch outgoing port
31 private FlowEntryUserState flowEntryUserState; // The Flow Entry User state
32 private FlowEntrySwitchState flowEntrySwitchState; // The Flow Entry Switch state
33 // The Flow Entry Error state (if FlowEntrySwitchState is FE_SWITCH_FAILED)
34 private FlowEntryErrorState flowEntryErrorState;
35
36 /**
37 * Default constructor.
38 */
39 public FlowEntry() {
Pavlin Radoslavovede97582013-03-08 18:57:28 -080040 // TODO: Test code
41 /*
42 MACAddress mac = MACAddress.valueOf("01:02:03:04:05:06");
43 IPv4 ipv4 = new IPv4("1.2.3.4");
44 IPv4Net ipv4net = new IPv4Net("5.6.7.0/24");
45
46 flowEntryMatch = new FlowEntryMatch();
47 flowEntryMatch.enableInPort(new Port((short)10));
48 flowEntryMatch.enableSrcMac(mac);
49 flowEntryMatch.enableDstMac(mac);
50 flowEntryMatch.enableVlanId((short)20);
51 flowEntryMatch.enableVlanPriority((byte)30);
52 flowEntryMatch.enableEthernetFrameType((short)40);
53 flowEntryMatch.enableIpToS((byte)50);
54 flowEntryMatch.enableIpProto((byte)60);
55 flowEntryMatch.enableSrcIPv4Net(ipv4net);
56 flowEntryMatch.enableDstIPv4Net(ipv4net);
57 flowEntryMatch.enableSrcTcpUdpPort((short)70);
58 flowEntryMatch.enableDstTcpUdpPort((short)80);
59
60 FlowEntryAction action = null;
61 ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>();
62
63 action = new FlowEntryAction();
64 action.setActionOutput(new Port((short)12));
65 actions.add(action);
66
67 action = new FlowEntryAction();
68 action.setActionOutputToController((short)13);
69 actions.add(action);
70
71 action = new FlowEntryAction();
72 action.setActionSetVlanId((short)14);
73 actions.add(action);
74
75 action = new FlowEntryAction();
76 action.setActionSetVlanPriority((byte)15);
77 actions.add(action);
78
79 action = new FlowEntryAction();
80 action.setActionStripVlan(true);
81 actions.add(action);
82
83 action = new FlowEntryAction();
84 action.setActionSetEthernetSrcAddr(mac);
85 actions.add(action);
86
87 action = new FlowEntryAction();
88 action.setActionSetEthernetDstAddr(mac);
89 actions.add(action);
90
91 action = new FlowEntryAction();
92 action.setActionSetIPv4SrcAddr(ipv4);
93 actions.add(action);
94
95 action = new FlowEntryAction();
96 action.setActionSetIPv4DstAddr(ipv4);
97 actions.add(action);
98
99 action = new FlowEntryAction();
100 action.setActionSetIpToS((byte)16);
101 actions.add(action);
102
103 action = new FlowEntryAction();
104 action.setActionSetTcpUdpSrcPort((short)17);
105 actions.add(action);
106
107 action = new FlowEntryAction();
108 action.setActionSetTcpUdpDstPort((short)18);
109 actions.add(action);
110
111 action = new FlowEntryAction();
112 action.setActionEnqueue(new Port((short)19), 20);
113 actions.add(action);
114
115 setFlowEntryActions(actions);
116 */
117
118
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800119 flowEntryUserState = FlowEntryUserState.FE_USER_UNKNOWN;
120 flowEntrySwitchState = FlowEntrySwitchState.FE_SWITCH_UNKNOWN;
121 }
122
123 /**
124 * Get the Flow Entry ID.
125 *
126 * @return the Flow Entry ID.
127 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800128 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800129 public FlowEntryId flowEntryId() { return flowEntryId; }
130
131 /**
132 * Set the Flow Entry ID.
133 *
134 * @param flowEntryId the Flow Entry ID to set.
135 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800136 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800137 public void setFlowEntryId(FlowEntryId flowEntryId) {
138 this.flowEntryId = flowEntryId;
139 }
140
141 /**
142 * Get the Flow Entry Match.
143 *
144 * @return the Flow Entry Match.
145 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800146 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800147 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
148
149 /**
150 * Set the Flow Entry Match.
151 *
152 * @param flowEntryMatch the Flow Entry Match to set.
153 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800154 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800155 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
156 this.flowEntryMatch = flowEntryMatch;
157 }
158
159 /**
160 * Get the Flow Entry Actions.
161 *
162 * @return the Flow Entry Actions.
163 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800164 @JsonProperty("flowEntryActions")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800165 public ArrayList<FlowEntryAction> flowEntryActions() {
166 return flowEntryActions;
167 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800168
169 /**
170 * Set the Flow Entry Actions.
171 *
172 * @param flowEntryActions the Flow Entry Actions to set.
173 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800174 @JsonProperty("flowEntryActions")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800175 public void setFlowEntryActions(ArrayList<FlowEntryAction> flowEntryActions) {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800176 this.flowEntryActions = flowEntryActions;
177 }
178
179 /**
180 * Get the Switch DPID.
181 *
182 * @return the Switch DPID.
183 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800184 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800185 public Dpid dpid() { return dpid; }
186
187 /**
188 * Set the Switch DPID.
189 *
190 * @param dpid the Switch DPID to set.
191 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800192 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800193 public void setDpid(Dpid dpid) {
194 this.dpid = dpid;
195 }
196
197 /**
198 * Get the Switch incoming port.
199 *
200 * @return the Switch incoming port.
201 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800202 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800203 public Port inPort() { return inPort; }
204
205 /**
206 * Set the Switch incoming port.
207 *
208 * @param inPort the Switch incoming port to set.
209 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800210 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800211 public void setInPort(Port inPort) {
212 this.inPort = inPort;
213 }
214
215 /**
216 * Get the Switch outgoing port.
217 *
218 * @return the Switch outgoing port.
219 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800220 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800221 public Port outPort() { return outPort; }
222
223 /**
224 * Set the Switch outgoing port.
225 *
226 * @param outPort the Switch outgoing port to set.
227 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800228 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800229 public void setOutPort(Port outPort) {
230 this.outPort = outPort;
231 }
232
233 /**
234 * Get the Flow Entry User state.
235 *
236 * @return the Flow Entry User state.
237 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800238 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800239 public FlowEntryUserState flowEntryUserState() {
240 return flowEntryUserState;
241 }
242
243 /**
244 * Set the Flow Entry User state.
245 *
246 * @param flowEntryUserState the Flow Entry User state to set.
247 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800248 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800249 public void setFlowEntryUserState(FlowEntryUserState flowEntryUserState) {
250 this.flowEntryUserState = flowEntryUserState;
251 }
252
253 /**
254 * Get the Flow Entry Switch state.
255 *
256 * The Flow Entry Error state is used if FlowEntrySwitchState is
257 * FE_SWITCH_FAILED.
258 *
259 * @return the Flow Entry Switch state.
260 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800261 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800262 public FlowEntrySwitchState flowEntrySwitchState() {
263 return flowEntrySwitchState;
264 }
265
266 /**
267 * Set the Flow Entry Switch state.
268 *
269 * The Flow Entry Error state is used if FlowEntrySwitchState is
270 * FE_SWITCH_FAILED.
271 *
272 * @param flowEntrySwitchState the Flow Entry Switch state to set.
273 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800274 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800275 public void setFlowEntrySwitchState(FlowEntrySwitchState flowEntrySwitchState) {
276 this.flowEntrySwitchState = flowEntrySwitchState;
277 }
278
279 /**
280 * Get the Flow Entry Error state.
281 *
282 * @return the Flow Entry Error state.
283 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800284 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800285 public FlowEntryErrorState flowEntryErrorState() {
286 return flowEntryErrorState;
287 }
288
289 /**
290 * Set the Flow Entry Error state.
291 *
292 * @param flowEntryErrorState the Flow Entry Error state to set.
293 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800294 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800295 public void setFlowEntryErrorState(FlowEntryErrorState flowEntryErrorState) {
296 this.flowEntryErrorState = flowEntryErrorState;
297 }
298
299 /**
300 * Convert the flow entry to a string.
301 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800302 * The string has the following form:
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800303 * [flowEntryId=XXX flowEntryMatch=XXX flowEntryAction=XXX
304 * flowEntryAction=XXX flowEntryAction=XXX dpid=XXX
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800305 * inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX
306 * flowEntryErrorState=XXX]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800307 * @return the flow entry as a string.
308 */
309 @Override
310 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800311 String ret = "[flowEntryId=" + this.flowEntryId.toString();
312 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800313 for (FlowEntryAction fa : flowEntryActions) {
314 ret += " flowEntryAction=" + fa.toString();
315 }
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800316 ret += " dpid=" + this.dpid.toString();
317 ret += " inPort=" + this.inPort.toString();
318 ret += " outPort=" + this.outPort.toString();
319 ret += " flowEntryUserState=" + this.flowEntryUserState;
320 ret += " flowEntrySwitchState=" + this.flowEntrySwitchState;
321 ret += " flowEntryErrorState=" + this.flowEntryErrorState.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800322 ret += "]";
323
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800324 return ret;
325 }
326}