blob: 03794a1678365b4eedf65b8142f3981b59918a97 [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
16 private FlowEntryMatch flowEntryMatch; // The Flow Entry Match
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070017 private FlowEntryActions flowEntryActions; // The Flow Entry Actions
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080018 private Dpid dpid; // The Switch DPID
Pavlin Radoslavovfbcb97c2013-03-21 11:29:58 -070019 private Port inPort; // The Switch incoming port. Used only
20 // when the entry is used to return
21 // Shortest Path computation.
22 private Port outPort; // The Switch outgoing port. Used only
23 // when the entry is used to return
24 // Shortest Path computation.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080025 private FlowEntryUserState flowEntryUserState; // The Flow Entry User state
26 private FlowEntrySwitchState flowEntrySwitchState; // The Flow Entry Switch state
27 // The Flow Entry Error state (if FlowEntrySwitchState is FE_SWITCH_FAILED)
28 private FlowEntryErrorState flowEntryErrorState;
29
30 /**
31 * Default constructor.
32 */
33 public FlowEntry() {
Pavlin Radoslavovede97582013-03-08 18:57:28 -080034 // TODO: Test code
35 /*
36 MACAddress mac = MACAddress.valueOf("01:02:03:04:05:06");
37 IPv4 ipv4 = new IPv4("1.2.3.4");
38 IPv4Net ipv4net = new IPv4Net("5.6.7.0/24");
39
40 flowEntryMatch = new FlowEntryMatch();
41 flowEntryMatch.enableInPort(new Port((short)10));
42 flowEntryMatch.enableSrcMac(mac);
43 flowEntryMatch.enableDstMac(mac);
44 flowEntryMatch.enableVlanId((short)20);
45 flowEntryMatch.enableVlanPriority((byte)30);
46 flowEntryMatch.enableEthernetFrameType((short)40);
47 flowEntryMatch.enableIpToS((byte)50);
48 flowEntryMatch.enableIpProto((byte)60);
49 flowEntryMatch.enableSrcIPv4Net(ipv4net);
50 flowEntryMatch.enableDstIPv4Net(ipv4net);
51 flowEntryMatch.enableSrcTcpUdpPort((short)70);
52 flowEntryMatch.enableDstTcpUdpPort((short)80);
53
54 FlowEntryAction action = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070055 FlowEntryActions actions = new FlowEntryActions();
Pavlin Radoslavovede97582013-03-08 18:57:28 -080056
57 action = new FlowEntryAction();
58 action.setActionOutput(new Port((short)12));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070059 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080060
61 action = new FlowEntryAction();
62 action.setActionOutputToController((short)13);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070063 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080064
65 action = new FlowEntryAction();
66 action.setActionSetVlanId((short)14);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070067 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080068
69 action = new FlowEntryAction();
70 action.setActionSetVlanPriority((byte)15);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070071 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080072
73 action = new FlowEntryAction();
74 action.setActionStripVlan(true);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070075 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080076
77 action = new FlowEntryAction();
78 action.setActionSetEthernetSrcAddr(mac);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070079 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080080
81 action = new FlowEntryAction();
82 action.setActionSetEthernetDstAddr(mac);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070083 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080084
85 action = new FlowEntryAction();
86 action.setActionSetIPv4SrcAddr(ipv4);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070087 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080088
89 action = new FlowEntryAction();
90 action.setActionSetIPv4DstAddr(ipv4);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070091 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080092
93 action = new FlowEntryAction();
94 action.setActionSetIpToS((byte)16);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070095 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080096
97 action = new FlowEntryAction();
98 action.setActionSetTcpUdpSrcPort((short)17);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070099 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800100
101 action = new FlowEntryAction();
102 action.setActionSetTcpUdpDstPort((short)18);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700103 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800104
105 action = new FlowEntryAction();
106 action.setActionEnqueue(new Port((short)19), 20);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700107 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800108
109 setFlowEntryActions(actions);
110 */
111
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700112 flowEntryActions = new FlowEntryActions();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800113 flowEntryUserState = FlowEntryUserState.FE_USER_UNKNOWN;
114 flowEntrySwitchState = FlowEntrySwitchState.FE_SWITCH_UNKNOWN;
115 }
116
117 /**
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -0700118 * Get the Flow ID.
Pavlin Radoslavov062c72d2013-10-30 12:42:15 -0700119 *
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -0700120 * @return the Flow ID.
121 */
122 @JsonIgnore
Pavlin Radoslavovb1309e82013-10-30 12:18:28 -0700123 public FlowId flowId() { return flowId; }
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -0700124
125 /**
126 * Set the Flow ID.
127 *
128 * @param flowId the Flow ID to set.
129 */
130 public void setFlowId(FlowId flowId) {
131 this.flowId = flowId;
132 }
133
134 /**
Pavlin Radoslavov062c72d2013-10-30 12:42:15 -0700135 * Test whether the Flow ID is valid.
136 *
137 * @return true if the Flow ID is valid, otherwise false.
138 */
139 public boolean isValidFlowId() {
140 if (this.flowId == null)
141 return false;
142 return (this.flowId.value() != 0);
143 }
144
145 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800146 * Get the Flow Entry ID.
147 *
148 * @return the Flow Entry ID.
149 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800150 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800151 public FlowEntryId flowEntryId() { return flowEntryId; }
152
153 /**
154 * Set the Flow Entry ID.
155 *
156 * @param flowEntryId the Flow Entry ID to set.
157 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800158 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800159 public void setFlowEntryId(FlowEntryId flowEntryId) {
160 this.flowEntryId = flowEntryId;
161 }
162
163 /**
Pavlin Radoslavovb1309e82013-10-30 12:18:28 -0700164 * Test whether the Flow Entry ID is valid.
165 *
166 * @return true if the Flow Entry ID is valid, otherwise false.
167 */
168 public boolean isValidFlowEntryId() {
169 if (this.flowEntryId == null)
170 return false;
171 return (this.flowEntryId.value() != 0);
172 }
173
174 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800175 * Get the Flow Entry Match.
176 *
177 * @return the Flow Entry Match.
178 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800179 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800180 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
181
182 /**
183 * Set the Flow Entry Match.
184 *
185 * @param flowEntryMatch the Flow Entry Match to set.
186 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800187 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800188 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
189 this.flowEntryMatch = flowEntryMatch;
190 }
191
192 /**
193 * Get the Flow Entry Actions.
194 *
195 * @return the Flow Entry Actions.
196 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800197 @JsonProperty("flowEntryActions")
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700198 public FlowEntryActions flowEntryActions() {
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800199 return flowEntryActions;
200 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800201
202 /**
203 * Set the Flow Entry Actions.
204 *
205 * @param flowEntryActions the Flow Entry Actions to set.
206 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800207 @JsonProperty("flowEntryActions")
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700208 public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800209 this.flowEntryActions = flowEntryActions;
210 }
211
212 /**
213 * Get the Switch DPID.
214 *
215 * @return the Switch DPID.
216 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800217 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800218 public Dpid dpid() { return dpid; }
219
220 /**
221 * Set the Switch DPID.
222 *
223 * @param dpid the Switch DPID to set.
224 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800225 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800226 public void setDpid(Dpid dpid) {
227 this.dpid = dpid;
228 }
229
230 /**
231 * Get 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 * @return the Switch incoming port.
236 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800237 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800238 public Port inPort() { return inPort; }
239
240 /**
241 * Set the Switch incoming port.
242 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700243 * Used only when the entry is used to return Shortest Path computation.
244 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800245 * @param inPort the Switch incoming port to set.
246 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800247 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800248 public void setInPort(Port inPort) {
249 this.inPort = inPort;
250 }
251
252 /**
253 * Get 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 * @return the Switch outgoing port.
258 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800259 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800260 public Port outPort() { return outPort; }
261
262 /**
263 * Set the Switch outgoing port.
264 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700265 * Used only when the entry is used to return Shortest Path computation.
266 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800267 * @param outPort the Switch outgoing port to set.
268 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800269 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800270 public void setOutPort(Port outPort) {
271 this.outPort = outPort;
272 }
273
274 /**
275 * Get the Flow Entry User state.
276 *
277 * @return the Flow Entry User state.
278 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800279 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800280 public FlowEntryUserState flowEntryUserState() {
281 return flowEntryUserState;
282 }
283
284 /**
285 * Set the Flow Entry User state.
286 *
287 * @param flowEntryUserState the Flow Entry User state to set.
288 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800289 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800290 public void setFlowEntryUserState(FlowEntryUserState flowEntryUserState) {
291 this.flowEntryUserState = flowEntryUserState;
292 }
293
294 /**
295 * Get the Flow Entry Switch state.
296 *
297 * The Flow Entry Error state is used if FlowEntrySwitchState is
298 * FE_SWITCH_FAILED.
299 *
300 * @return the Flow Entry Switch state.
301 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800302 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800303 public FlowEntrySwitchState flowEntrySwitchState() {
304 return flowEntrySwitchState;
305 }
306
307 /**
308 * Set the Flow Entry Switch state.
309 *
310 * The Flow Entry Error state is used if FlowEntrySwitchState is
311 * FE_SWITCH_FAILED.
312 *
313 * @param flowEntrySwitchState the Flow Entry Switch state to set.
314 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800315 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800316 public void setFlowEntrySwitchState(FlowEntrySwitchState flowEntrySwitchState) {
317 this.flowEntrySwitchState = flowEntrySwitchState;
318 }
319
320 /**
321 * Get the Flow Entry Error state.
322 *
323 * @return the Flow Entry Error state.
324 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800325 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800326 public FlowEntryErrorState flowEntryErrorState() {
327 return flowEntryErrorState;
328 }
329
330 /**
331 * Set the Flow Entry Error state.
332 *
333 * @param flowEntryErrorState the Flow Entry Error state to set.
334 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800335 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800336 public void setFlowEntryErrorState(FlowEntryErrorState flowEntryErrorState) {
337 this.flowEntryErrorState = flowEntryErrorState;
338 }
339
340 /**
341 * Convert the flow entry to a string.
342 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800343 * The string has the following form:
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700344 * [flowEntryId=XXX flowEntryMatch=XXX flowEntryActions=XXX dpid=XXX
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800345 * inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX
346 * flowEntryErrorState=XXX]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800347 * @return the flow entry as a string.
348 */
349 @Override
350 public String toString() {
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900351 StringBuilder ret = new StringBuilder();
352 if ( flowEntryId != null ) {
353 ret.append("[flowEntryId=" + this.flowEntryId.toString());
354 } else {
HIGUCHI Yuta64163c02013-08-06 07:51:19 +0900355 ret.append("[");
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900356 }
357 if ( flowEntryMatch != null ) {
358 ret.append(" flowEntryMatch=" + this.flowEntryMatch.toString());
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900359 }
360 ret.append( " flowEntryActions=" + this.flowEntryActions.toString() );
361 if ( dpid != null ) {
362 ret.append(" dpid=" + this.dpid.toString());
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900363 }
364 if ( inPort != null ) {
365 ret.append(" inPort=" + this.inPort.toString());
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900366 }
367 if ( outPort != null ) {
368 ret.append(" outPort=" + this.outPort.toString());
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900369 }
370 ret.append(" flowEntryUserState=" + this.flowEntryUserState);
371 ret.append(" flowEntrySwitchState=" + this.flowEntrySwitchState);
372 if ( flowEntryErrorState != null ) {
373 ret.append(" flowEntryErrorState=" + this.flowEntryErrorState.toString());
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900374 }
375 ret.append("]");
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800376
HIGUCHI Yuta01f4d7d2013-08-04 06:02:24 +0900377 return ret.toString();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800378 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800379}