blob: 717be4ea8162bc08fbeeb258190fdc5fc1cd0f28 [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
Pavlin Radoslavovfbcb97c2013-03-21 11:29:58 -070029 private Port inPort; // The Switch incoming port. Used only
30 // when the entry is used to return
31 // Shortest Path computation.
32 private Port outPort; // The Switch outgoing port. Used only
33 // when the entry is used to return
34 // Shortest Path computation.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080035 private FlowEntryUserState flowEntryUserState; // The Flow Entry User state
36 private FlowEntrySwitchState flowEntrySwitchState; // The Flow Entry Switch state
37 // The Flow Entry Error state (if FlowEntrySwitchState is FE_SWITCH_FAILED)
38 private FlowEntryErrorState flowEntryErrorState;
39
40 /**
41 * Default constructor.
42 */
43 public FlowEntry() {
Pavlin Radoslavovede97582013-03-08 18:57:28 -080044 // TODO: Test code
45 /*
46 MACAddress mac = MACAddress.valueOf("01:02:03:04:05:06");
47 IPv4 ipv4 = new IPv4("1.2.3.4");
48 IPv4Net ipv4net = new IPv4Net("5.6.7.0/24");
49
50 flowEntryMatch = new FlowEntryMatch();
51 flowEntryMatch.enableInPort(new Port((short)10));
52 flowEntryMatch.enableSrcMac(mac);
53 flowEntryMatch.enableDstMac(mac);
54 flowEntryMatch.enableVlanId((short)20);
55 flowEntryMatch.enableVlanPriority((byte)30);
56 flowEntryMatch.enableEthernetFrameType((short)40);
57 flowEntryMatch.enableIpToS((byte)50);
58 flowEntryMatch.enableIpProto((byte)60);
59 flowEntryMatch.enableSrcIPv4Net(ipv4net);
60 flowEntryMatch.enableDstIPv4Net(ipv4net);
61 flowEntryMatch.enableSrcTcpUdpPort((short)70);
62 flowEntryMatch.enableDstTcpUdpPort((short)80);
63
64 FlowEntryAction action = null;
65 ArrayList<FlowEntryAction> actions = new ArrayList<FlowEntryAction>();
66
67 action = new FlowEntryAction();
68 action.setActionOutput(new Port((short)12));
69 actions.add(action);
70
71 action = new FlowEntryAction();
72 action.setActionOutputToController((short)13);
73 actions.add(action);
74
75 action = new FlowEntryAction();
76 action.setActionSetVlanId((short)14);
77 actions.add(action);
78
79 action = new FlowEntryAction();
80 action.setActionSetVlanPriority((byte)15);
81 actions.add(action);
82
83 action = new FlowEntryAction();
84 action.setActionStripVlan(true);
85 actions.add(action);
86
87 action = new FlowEntryAction();
88 action.setActionSetEthernetSrcAddr(mac);
89 actions.add(action);
90
91 action = new FlowEntryAction();
92 action.setActionSetEthernetDstAddr(mac);
93 actions.add(action);
94
95 action = new FlowEntryAction();
96 action.setActionSetIPv4SrcAddr(ipv4);
97 actions.add(action);
98
99 action = new FlowEntryAction();
100 action.setActionSetIPv4DstAddr(ipv4);
101 actions.add(action);
102
103 action = new FlowEntryAction();
104 action.setActionSetIpToS((byte)16);
105 actions.add(action);
106
107 action = new FlowEntryAction();
108 action.setActionSetTcpUdpSrcPort((short)17);
109 actions.add(action);
110
111 action = new FlowEntryAction();
112 action.setActionSetTcpUdpDstPort((short)18);
113 actions.add(action);
114
115 action = new FlowEntryAction();
116 action.setActionEnqueue(new Port((short)19), 20);
117 actions.add(action);
118
119 setFlowEntryActions(actions);
120 */
121
122
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800123 flowEntryUserState = FlowEntryUserState.FE_USER_UNKNOWN;
124 flowEntrySwitchState = FlowEntrySwitchState.FE_SWITCH_UNKNOWN;
125 }
126
127 /**
128 * Get the Flow Entry ID.
129 *
130 * @return the Flow Entry ID.
131 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800132 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800133 public FlowEntryId flowEntryId() { return flowEntryId; }
134
135 /**
136 * Set the Flow Entry ID.
137 *
138 * @param flowEntryId the Flow Entry ID to set.
139 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800140 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800141 public void setFlowEntryId(FlowEntryId flowEntryId) {
142 this.flowEntryId = flowEntryId;
143 }
144
145 /**
146 * Get the Flow Entry Match.
147 *
148 * @return the Flow Entry Match.
149 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800150 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800151 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
152
153 /**
154 * Set the Flow Entry Match.
155 *
156 * @param flowEntryMatch the Flow Entry Match to set.
157 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800158 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800159 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
160 this.flowEntryMatch = flowEntryMatch;
161 }
162
163 /**
164 * Get the Flow Entry Actions.
165 *
166 * @return the Flow Entry Actions.
167 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800168 @JsonProperty("flowEntryActions")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800169 public ArrayList<FlowEntryAction> flowEntryActions() {
170 return flowEntryActions;
171 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800172
173 /**
174 * Set the Flow Entry Actions.
175 *
176 * @param flowEntryActions the Flow Entry Actions to set.
177 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800178 @JsonProperty("flowEntryActions")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800179 public void setFlowEntryActions(ArrayList<FlowEntryAction> flowEntryActions) {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800180 this.flowEntryActions = flowEntryActions;
181 }
182
183 /**
184 * Get the Switch DPID.
185 *
186 * @return the Switch DPID.
187 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800188 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800189 public Dpid dpid() { return dpid; }
190
191 /**
192 * Set the Switch DPID.
193 *
194 * @param dpid the Switch DPID to set.
195 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800196 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800197 public void setDpid(Dpid dpid) {
198 this.dpid = dpid;
199 }
200
201 /**
202 * Get the Switch incoming port.
203 *
204 * @return the Switch incoming port.
205 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800206 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800207 public Port inPort() { return inPort; }
208
209 /**
210 * Set the Switch incoming port.
211 *
212 * @param inPort the Switch incoming port to set.
213 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800214 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800215 public void setInPort(Port inPort) {
216 this.inPort = inPort;
217 }
218
219 /**
220 * Get the Switch outgoing port.
221 *
222 * @return the Switch outgoing port.
223 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800224 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800225 public Port outPort() { return outPort; }
226
227 /**
228 * Set the Switch outgoing port.
229 *
230 * @param outPort the Switch outgoing port to set.
231 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800232 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800233 public void setOutPort(Port outPort) {
234 this.outPort = outPort;
235 }
236
237 /**
238 * Get the Flow Entry User state.
239 *
240 * @return the Flow Entry User state.
241 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800242 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800243 public FlowEntryUserState flowEntryUserState() {
244 return flowEntryUserState;
245 }
246
247 /**
248 * Set the Flow Entry User state.
249 *
250 * @param flowEntryUserState the Flow Entry User state to set.
251 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800252 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800253 public void setFlowEntryUserState(FlowEntryUserState flowEntryUserState) {
254 this.flowEntryUserState = flowEntryUserState;
255 }
256
257 /**
258 * Get the Flow Entry Switch state.
259 *
260 * The Flow Entry Error state is used if FlowEntrySwitchState is
261 * FE_SWITCH_FAILED.
262 *
263 * @return the Flow Entry Switch state.
264 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800265 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800266 public FlowEntrySwitchState flowEntrySwitchState() {
267 return flowEntrySwitchState;
268 }
269
270 /**
271 * Set the Flow Entry Switch state.
272 *
273 * The Flow Entry Error state is used if FlowEntrySwitchState is
274 * FE_SWITCH_FAILED.
275 *
276 * @param flowEntrySwitchState the Flow Entry Switch state to set.
277 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800278 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800279 public void setFlowEntrySwitchState(FlowEntrySwitchState flowEntrySwitchState) {
280 this.flowEntrySwitchState = flowEntrySwitchState;
281 }
282
283 /**
284 * Get the Flow Entry Error state.
285 *
286 * @return the Flow Entry Error state.
287 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800288 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800289 public FlowEntryErrorState flowEntryErrorState() {
290 return flowEntryErrorState;
291 }
292
293 /**
294 * Set the Flow Entry Error state.
295 *
296 * @param flowEntryErrorState the Flow Entry Error state to set.
297 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800298 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800299 public void setFlowEntryErrorState(FlowEntryErrorState flowEntryErrorState) {
300 this.flowEntryErrorState = flowEntryErrorState;
301 }
302
303 /**
304 * Convert the flow entry to a string.
305 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800306 * The string has the following form:
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800307 * [flowEntryId=XXX flowEntryMatch=XXX flowEntryAction=XXX
308 * flowEntryAction=XXX flowEntryAction=XXX dpid=XXX
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800309 * inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX
310 * flowEntryErrorState=XXX]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800311 * @return the flow entry as a string.
312 */
313 @Override
314 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800315 String ret = "[flowEntryId=" + this.flowEntryId.toString();
316 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800317 for (FlowEntryAction fa : flowEntryActions) {
318 ret += " flowEntryAction=" + fa.toString();
319 }
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800320 ret += " dpid=" + this.dpid.toString();
321 ret += " inPort=" + this.inPort.toString();
322 ret += " outPort=" + this.outPort.toString();
323 ret += " flowEntryUserState=" + this.flowEntryUserState;
324 ret += " flowEntrySwitchState=" + this.flowEntrySwitchState;
325 ret += " flowEntryErrorState=" + this.flowEntryErrorState.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800326 ret += "]";
327
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800328 return ret;
329 }
330}