blob: c8b206f8e3f3011f2a9540d3c0cf1d71cd921a0a [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Pavlin Radoslavovede97582013-03-08 18:57:28 -08003
Pankaj Berded0ae0ff2013-03-26 15:37:12 -07004import org.codehaus.jackson.annotate.JsonIgnore;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08005import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08006
7/**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08008 * The class representing the Flow Entry.
9 *
10 * NOTE: The specification is incomplete. E.g., the entry needs to
11 * support multiple in-ports and multiple out-ports.
12 */
13public class FlowEntry {
Pavlin Radoslavovd5b21db2013-07-29 17:09:53 -070014 private FlowId flowId; // FlowID of the Flow Entry
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080015 private FlowEntryId flowEntryId; // The Flow Entry ID
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -080016 private int idleTimeout; // The Flow idle timeout
17 private int hardTimeout; // The Flow hard timeout
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080018 private FlowEntryMatch flowEntryMatch; // The Flow Entry Match
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070019 private FlowEntryActions flowEntryActions; // The Flow Entry Actions
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080020 private Dpid dpid; // The Switch DPID
Pavlin Radoslavovfbcb97c2013-03-21 11:29:58 -070021 private Port inPort; // The Switch incoming port. Used only
22 // when the entry is used to return
23 // Shortest Path computation.
24 private Port outPort; // The Switch outgoing port. Used only
25 // when the entry is used to return
26 // Shortest Path computation.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080027 private FlowEntryUserState flowEntryUserState; // The Flow Entry User state
28 private FlowEntrySwitchState flowEntrySwitchState; // The Flow Entry Switch state
29 // The Flow Entry Error state (if FlowEntrySwitchState is FE_SWITCH_FAILED)
30 private FlowEntryErrorState flowEntryErrorState;
31
32 /**
33 * Default constructor.
34 */
35 public FlowEntry() {
Pavlin Radoslavovede97582013-03-08 18:57:28 -080036 // TODO: Test code
37 /*
38 MACAddress mac = MACAddress.valueOf("01:02:03:04:05:06");
39 IPv4 ipv4 = new IPv4("1.2.3.4");
40 IPv4Net ipv4net = new IPv4Net("5.6.7.0/24");
41
42 flowEntryMatch = new FlowEntryMatch();
43 flowEntryMatch.enableInPort(new Port((short)10));
44 flowEntryMatch.enableSrcMac(mac);
45 flowEntryMatch.enableDstMac(mac);
46 flowEntryMatch.enableVlanId((short)20);
47 flowEntryMatch.enableVlanPriority((byte)30);
48 flowEntryMatch.enableEthernetFrameType((short)40);
49 flowEntryMatch.enableIpToS((byte)50);
50 flowEntryMatch.enableIpProto((byte)60);
51 flowEntryMatch.enableSrcIPv4Net(ipv4net);
52 flowEntryMatch.enableDstIPv4Net(ipv4net);
53 flowEntryMatch.enableSrcTcpUdpPort((short)70);
54 flowEntryMatch.enableDstTcpUdpPort((short)80);
55
56 FlowEntryAction action = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070057 FlowEntryActions actions = new FlowEntryActions();
Pavlin Radoslavovede97582013-03-08 18:57:28 -080058
59 action = new FlowEntryAction();
60 action.setActionOutput(new Port((short)12));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070061 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080062
63 action = new FlowEntryAction();
64 action.setActionOutputToController((short)13);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070065 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080066
67 action = new FlowEntryAction();
68 action.setActionSetVlanId((short)14);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070069 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080070
71 action = new FlowEntryAction();
72 action.setActionSetVlanPriority((byte)15);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070073 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080074
75 action = new FlowEntryAction();
76 action.setActionStripVlan(true);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070077 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080078
79 action = new FlowEntryAction();
80 action.setActionSetEthernetSrcAddr(mac);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070081 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080082
83 action = new FlowEntryAction();
84 action.setActionSetEthernetDstAddr(mac);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070085 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080086
87 action = new FlowEntryAction();
88 action.setActionSetIPv4SrcAddr(ipv4);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070089 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080090
91 action = new FlowEntryAction();
92 action.setActionSetIPv4DstAddr(ipv4);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070093 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080094
95 action = new FlowEntryAction();
96 action.setActionSetIpToS((byte)16);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070097 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080098
99 action = new FlowEntryAction();
100 action.setActionSetTcpUdpSrcPort((short)17);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700101 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800102
103 action = new FlowEntryAction();
104 action.setActionSetTcpUdpDstPort((short)18);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700105 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800106
107 action = new FlowEntryAction();
108 action.setActionEnqueue(new Port((short)19), 20);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700109 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800110
111 setFlowEntryActions(actions);
112 */
113
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700114 flowEntryActions = new FlowEntryActions();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800115 flowEntryUserState = FlowEntryUserState.FE_USER_UNKNOWN;
116 flowEntrySwitchState = FlowEntrySwitchState.FE_SWITCH_UNKNOWN;
117 }
118
119 /**
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -0700120 * Get the Flow ID.
Pavlin Radoslavov062c72d2013-10-30 12:42:15 -0700121 *
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -0700122 * @return the Flow ID.
123 */
124 @JsonIgnore
Pavlin Radoslavovb1309e82013-10-30 12:18:28 -0700125 public FlowId flowId() { return flowId; }
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -0700126
127 /**
128 * Set the Flow ID.
129 *
130 * @param flowId the Flow ID to set.
131 */
132 public void setFlowId(FlowId flowId) {
133 this.flowId = flowId;
134 }
135
136 /**
Pavlin Radoslavov062c72d2013-10-30 12:42:15 -0700137 * Test whether the Flow ID is valid.
138 *
139 * @return true if the Flow ID is valid, otherwise false.
140 */
Pavlin Radoslavovda26a9a2013-11-22 19:31:36 -0800141 @JsonIgnore
Pavlin Radoslavov062c72d2013-10-30 12:42:15 -0700142 public boolean isValidFlowId() {
143 if (this.flowId == null)
144 return false;
Pavlin Radoslavovf74271f2013-11-25 18:22:47 -0800145 return (this.flowId.isValid());
Pavlin Radoslavov062c72d2013-10-30 12:42:15 -0700146 }
147
148 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800149 * Get the Flow Entry ID.
150 *
151 * @return the Flow Entry ID.
152 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800153 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800154 public FlowEntryId flowEntryId() { return flowEntryId; }
155
156 /**
157 * Set the Flow Entry ID.
158 *
159 * @param flowEntryId the Flow Entry ID to set.
160 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800161 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800162 public void setFlowEntryId(FlowEntryId flowEntryId) {
163 this.flowEntryId = flowEntryId;
164 }
165
166 /**
Pavlin Radoslavovb1309e82013-10-30 12:18:28 -0700167 * Test whether the Flow Entry ID is valid.
168 *
169 * @return true if the Flow Entry ID is valid, otherwise false.
170 */
Pavlin Radoslavovda26a9a2013-11-22 19:31:36 -0800171 @JsonIgnore
Pavlin Radoslavovb1309e82013-10-30 12:18:28 -0700172 public boolean isValidFlowEntryId() {
173 if (this.flowEntryId == null)
174 return false;
Pavlin Radoslavovf74271f2013-11-25 18:22:47 -0800175 return (this.flowEntryId.isValid());
Pavlin Radoslavovb1309e82013-10-30 12:18:28 -0700176 }
177
178 /**
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800179 * Get the flow idle timeout in seconds.
180 *
181 * It should be an unsigned integer in the interval [0, 65535].
182 * If zero, the timeout is not set.
183 *
184 * @return the flow idle timeout.
185 */
186 @JsonProperty("idleTimeout")
187 public int idleTimeout() { return idleTimeout; }
188
189 /**
190 * Set the flow idle timeout in seconds.
191 *
192 * It should be an unsigned integer in the interval [0, 65535].
193 * If zero, the timeout is not set.
194 *
195 * @param idleTimeout the flow idle timeout to set.
196 */
197 @JsonProperty("idleTimeout")
198 public void setIdleTimeout(int idleTimeout) {
199 this.idleTimeout = 0xffff & idleTimeout;
200 }
201
202 /**
203 * Get the flow hard timeout in seconds.
204 *
205 * It should be an unsigned integer in the interval [0, 65535].
206 * If zero, the timeout is not set.
207 *
208 * @return the flow hard timeout.
209 */
210 @JsonProperty("hardTimeout")
211 public int hardTimeout() { return hardTimeout; }
212
213 /**
214 * Set the flow hard timeout in seconds.
215 *
216 * It should be an unsigned integer in the interval [0, 65535].
217 * If zero, the timeout is not set.
218 *
219 * @param hardTimeout the flow hard timeout to set.
220 */
221 @JsonProperty("hardTimeout")
222 public void setHardTimeout(int hardTimeout) {
223 this.hardTimeout = 0xffff & hardTimeout;
224 }
225
226 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800227 * Get the Flow Entry Match.
228 *
229 * @return the Flow Entry Match.
230 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800231 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800232 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
233
234 /**
235 * Set the Flow Entry Match.
236 *
237 * @param flowEntryMatch the Flow Entry Match to set.
238 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800239 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800240 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
241 this.flowEntryMatch = flowEntryMatch;
242 }
243
244 /**
245 * Get the Flow Entry Actions.
246 *
247 * @return the Flow Entry Actions.
248 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800249 @JsonProperty("flowEntryActions")
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700250 public FlowEntryActions flowEntryActions() {
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800251 return flowEntryActions;
252 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800253
254 /**
255 * Set the Flow Entry Actions.
256 *
257 * @param flowEntryActions the Flow Entry Actions to set.
258 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800259 @JsonProperty("flowEntryActions")
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700260 public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800261 this.flowEntryActions = flowEntryActions;
262 }
263
264 /**
265 * Get the Switch DPID.
266 *
267 * @return the Switch DPID.
268 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800269 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800270 public Dpid dpid() { return dpid; }
271
272 /**
273 * Set the Switch DPID.
274 *
275 * @param dpid the Switch DPID to set.
276 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800277 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800278 public void setDpid(Dpid dpid) {
279 this.dpid = dpid;
280 }
281
282 /**
283 * Get the Switch incoming port.
284 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700285 * Used only when the entry is used to return Shortest Path computation.
286 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800287 * @return the Switch incoming port.
288 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800289 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800290 public Port inPort() { return inPort; }
291
292 /**
293 * Set the Switch incoming port.
294 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700295 * Used only when the entry is used to return Shortest Path computation.
296 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800297 * @param inPort the Switch incoming port to set.
298 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800299 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800300 public void setInPort(Port inPort) {
301 this.inPort = inPort;
302 }
303
304 /**
305 * Get the Switch outgoing port.
306 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700307 * Used only when the entry is used to return Shortest Path computation.
308 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800309 * @return the Switch outgoing port.
310 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800311 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800312 public Port outPort() { return outPort; }
313
314 /**
315 * Set the Switch outgoing port.
316 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700317 * Used only when the entry is used to return Shortest Path computation.
318 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800319 * @param outPort the Switch outgoing port to set.
320 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800321 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800322 public void setOutPort(Port outPort) {
323 this.outPort = outPort;
324 }
325
326 /**
327 * Get the Flow Entry User state.
328 *
329 * @return the Flow Entry User state.
330 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800331 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800332 public FlowEntryUserState flowEntryUserState() {
333 return flowEntryUserState;
334 }
335
336 /**
337 * Set the Flow Entry User state.
338 *
339 * @param flowEntryUserState the Flow Entry User state to set.
340 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800341 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800342 public void setFlowEntryUserState(FlowEntryUserState flowEntryUserState) {
343 this.flowEntryUserState = flowEntryUserState;
344 }
345
346 /**
347 * Get the Flow Entry Switch state.
348 *
349 * The Flow Entry Error state is used if FlowEntrySwitchState is
350 * FE_SWITCH_FAILED.
351 *
352 * @return the Flow Entry Switch state.
353 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800354 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800355 public FlowEntrySwitchState flowEntrySwitchState() {
356 return flowEntrySwitchState;
357 }
358
359 /**
360 * Set the Flow Entry Switch state.
361 *
362 * The Flow Entry Error state is used if FlowEntrySwitchState is
363 * FE_SWITCH_FAILED.
364 *
365 * @param flowEntrySwitchState the Flow Entry Switch state to set.
366 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800367 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800368 public void setFlowEntrySwitchState(FlowEntrySwitchState flowEntrySwitchState) {
369 this.flowEntrySwitchState = flowEntrySwitchState;
370 }
371
372 /**
373 * Get the Flow Entry Error state.
374 *
375 * @return the Flow Entry Error state.
376 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800377 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800378 public FlowEntryErrorState flowEntryErrorState() {
379 return flowEntryErrorState;
380 }
381
382 /**
383 * Set the Flow Entry Error state.
384 *
385 * @param flowEntryErrorState the Flow Entry Error state to set.
386 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800387 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800388 public void setFlowEntryErrorState(FlowEntryErrorState flowEntryErrorState) {
389 this.flowEntryErrorState = flowEntryErrorState;
390 }
391
392 /**
393 * Convert the flow entry to a string.
394 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800395 * The string has the following form:
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800396 * [flowEntryId=XXX idleTimeout=XXX hardTimeout=XXX
397 * flowEntryMatch=XXX flowEntryActions=XXX dpid=XXX
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800398 * inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX
399 * flowEntryErrorState=XXX]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800400 * @return the flow entry as a string.
401 */
402 @Override
403 public String toString() {
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900404 StringBuilder ret = new StringBuilder();
405 if ( flowEntryId != null ) {
406 ret.append("[flowEntryId=" + this.flowEntryId.toString());
407 } else {
HIGUCHI Yuta64163c02013-08-06 07:51:19 +0900408 ret.append("[");
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900409 }
Pavlin Radoslavov919d0a22013-10-30 12:50:37 -0700410 if ( flowId != null ) {
411 ret.append(" flowId=" + this.flowId.toString());
412 }
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800413 ret.append(" idleTimeout=" + this.idleTimeout);
414 ret.append(" hardTimeout=" + this.hardTimeout);
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900415 if ( flowEntryMatch != null ) {
416 ret.append(" flowEntryMatch=" + this.flowEntryMatch.toString());
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900417 }
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800418 ret.append(" flowEntryActions=" + this.flowEntryActions.toString() );
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900419 if ( dpid != null ) {
420 ret.append(" dpid=" + this.dpid.toString());
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900421 }
422 if ( inPort != null ) {
423 ret.append(" inPort=" + this.inPort.toString());
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900424 }
425 if ( outPort != null ) {
426 ret.append(" outPort=" + this.outPort.toString());
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900427 }
428 ret.append(" flowEntryUserState=" + this.flowEntryUserState);
429 ret.append(" flowEntrySwitchState=" + this.flowEntrySwitchState);
430 if ( flowEntryErrorState != null ) {
431 ret.append(" flowEntryErrorState=" + this.flowEntryErrorState.toString());
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900432 }
433 ret.append("]");
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800434
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900435 return ret.toString();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800436 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800437}