blob: 87d08cedd90fd104810cc167392b73837316f6ce [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 -08003import java.util.ArrayList;
4
Pankaj Berded0ae0ff2013-03-26 15:37:12 -07005import org.codehaus.jackson.annotate.JsonIgnore;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08006import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08007
8/**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08009 * The class representing the Flow Entry.
10 *
11 * NOTE: The specification is incomplete. E.g., the entry needs to
12 * support multiple in-ports and multiple out-ports.
13 */
14public class FlowEntry {
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -070015 private FlowId flowId; // FlowID of flowEntry
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080016 private FlowEntryId flowEntryId; // The Flow Entry ID
17 private FlowEntryMatch flowEntryMatch; // The Flow Entry Match
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070018 private FlowEntryActions flowEntryActions; // The Flow Entry Actions
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080019 private Dpid dpid; // The Switch DPID
Pavlin Radoslavovfbcb97c2013-03-21 11:29:58 -070020 private Port inPort; // The Switch incoming port. Used only
21 // when the entry is used to return
22 // Shortest Path computation.
23 private Port outPort; // The Switch outgoing port. Used only
24 // when the entry is used to return
25 // Shortest Path computation.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080026 private FlowEntryUserState flowEntryUserState; // The Flow Entry User state
27 private FlowEntrySwitchState flowEntrySwitchState; // The Flow Entry Switch state
28 // The Flow Entry Error state (if FlowEntrySwitchState is FE_SWITCH_FAILED)
29 private FlowEntryErrorState flowEntryErrorState;
30
31 /**
32 * Default constructor.
33 */
34 public FlowEntry() {
Pavlin Radoslavovede97582013-03-08 18:57:28 -080035 // TODO: Test code
36 /*
37 MACAddress mac = MACAddress.valueOf("01:02:03:04:05:06");
38 IPv4 ipv4 = new IPv4("1.2.3.4");
39 IPv4Net ipv4net = new IPv4Net("5.6.7.0/24");
40
41 flowEntryMatch = new FlowEntryMatch();
42 flowEntryMatch.enableInPort(new Port((short)10));
43 flowEntryMatch.enableSrcMac(mac);
44 flowEntryMatch.enableDstMac(mac);
45 flowEntryMatch.enableVlanId((short)20);
46 flowEntryMatch.enableVlanPriority((byte)30);
47 flowEntryMatch.enableEthernetFrameType((short)40);
48 flowEntryMatch.enableIpToS((byte)50);
49 flowEntryMatch.enableIpProto((byte)60);
50 flowEntryMatch.enableSrcIPv4Net(ipv4net);
51 flowEntryMatch.enableDstIPv4Net(ipv4net);
52 flowEntryMatch.enableSrcTcpUdpPort((short)70);
53 flowEntryMatch.enableDstTcpUdpPort((short)80);
54
55 FlowEntryAction action = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070056 FlowEntryActions actions = new FlowEntryActions();
Pavlin Radoslavovede97582013-03-08 18:57:28 -080057
58 action = new FlowEntryAction();
59 action.setActionOutput(new Port((short)12));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070060 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080061
62 action = new FlowEntryAction();
63 action.setActionOutputToController((short)13);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070064 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080065
66 action = new FlowEntryAction();
67 action.setActionSetVlanId((short)14);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070068 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080069
70 action = new FlowEntryAction();
71 action.setActionSetVlanPriority((byte)15);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070072 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080073
74 action = new FlowEntryAction();
75 action.setActionStripVlan(true);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070076 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080077
78 action = new FlowEntryAction();
79 action.setActionSetEthernetSrcAddr(mac);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070080 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080081
82 action = new FlowEntryAction();
83 action.setActionSetEthernetDstAddr(mac);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070084 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080085
86 action = new FlowEntryAction();
87 action.setActionSetIPv4SrcAddr(ipv4);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070088 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080089
90 action = new FlowEntryAction();
91 action.setActionSetIPv4DstAddr(ipv4);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070092 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080093
94 action = new FlowEntryAction();
95 action.setActionSetIpToS((byte)16);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070096 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080097
98 action = new FlowEntryAction();
99 action.setActionSetTcpUdpSrcPort((short)17);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700100 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800101
102 action = new FlowEntryAction();
103 action.setActionSetTcpUdpDstPort((short)18);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700104 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800105
106 action = new FlowEntryAction();
107 action.setActionEnqueue(new Port((short)19), 20);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700108 actions.addAction(action);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800109
110 setFlowEntryActions(actions);
111 */
112
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700113 flowEntryActions = new FlowEntryActions();
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800114 flowEntryUserState = FlowEntryUserState.FE_USER_UNKNOWN;
115 flowEntrySwitchState = FlowEntrySwitchState.FE_SWITCH_UNKNOWN;
116 }
117
118 /**
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -0700119 * Get the Flow ID.
120 * @return the Flow ID.
121 */
122 @JsonIgnore
123 public FlowId getFlowId() { return flowId; }
124
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 Radoslavov5363c2a2013-02-18 09:55:42 -0800135 * Get the Flow Entry ID.
136 *
137 * @return the Flow Entry ID.
138 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800139 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800140 public FlowEntryId flowEntryId() { return flowEntryId; }
141
142 /**
143 * Set the Flow Entry ID.
144 *
145 * @param flowEntryId the Flow Entry ID to set.
146 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800147 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800148 public void setFlowEntryId(FlowEntryId flowEntryId) {
149 this.flowEntryId = flowEntryId;
150 }
151
152 /**
153 * Get the Flow Entry Match.
154 *
155 * @return the Flow Entry Match.
156 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800157 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800158 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
159
160 /**
161 * Set the Flow Entry Match.
162 *
163 * @param flowEntryMatch the Flow Entry Match to set.
164 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800165 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800166 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
167 this.flowEntryMatch = flowEntryMatch;
168 }
169
170 /**
171 * Get the Flow Entry Actions.
172 *
173 * @return the Flow Entry Actions.
174 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800175 @JsonProperty("flowEntryActions")
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700176 public FlowEntryActions flowEntryActions() {
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800177 return flowEntryActions;
178 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800179
180 /**
181 * Set the Flow Entry Actions.
182 *
183 * @param flowEntryActions the Flow Entry Actions to set.
184 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800185 @JsonProperty("flowEntryActions")
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700186 public void setFlowEntryActions(FlowEntryActions flowEntryActions) {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800187 this.flowEntryActions = flowEntryActions;
188 }
189
190 /**
191 * Get the Switch DPID.
192 *
193 * @return the Switch DPID.
194 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800195 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800196 public Dpid dpid() { return dpid; }
197
198 /**
199 * Set the Switch DPID.
200 *
201 * @param dpid the Switch DPID to set.
202 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800203 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800204 public void setDpid(Dpid dpid) {
205 this.dpid = dpid;
206 }
207
208 /**
209 * Get the Switch incoming port.
210 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700211 * Used only when the entry is used to return Shortest Path computation.
212 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800213 * @return the Switch incoming port.
214 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800215 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800216 public Port inPort() { return inPort; }
217
218 /**
219 * Set the Switch incoming port.
220 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700221 * Used only when the entry is used to return Shortest Path computation.
222 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800223 * @param inPort the Switch incoming port to set.
224 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800225 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800226 public void setInPort(Port inPort) {
227 this.inPort = inPort;
228 }
229
230 /**
231 * Get the Switch outgoing 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 outgoing port.
236 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800237 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800238 public Port outPort() { return outPort; }
239
240 /**
241 * Set the Switch outgoing 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 outPort the Switch outgoing port to set.
246 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800247 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800248 public void setOutPort(Port outPort) {
249 this.outPort = outPort;
250 }
251
252 /**
253 * Get the Flow Entry User state.
254 *
255 * @return the Flow Entry User state.
256 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800257 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800258 public FlowEntryUserState flowEntryUserState() {
259 return flowEntryUserState;
260 }
261
262 /**
263 * Set the Flow Entry User state.
264 *
265 * @param flowEntryUserState the Flow Entry User state to set.
266 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800267 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800268 public void setFlowEntryUserState(FlowEntryUserState flowEntryUserState) {
269 this.flowEntryUserState = flowEntryUserState;
270 }
271
272 /**
273 * Get the Flow Entry Switch state.
274 *
275 * The Flow Entry Error state is used if FlowEntrySwitchState is
276 * FE_SWITCH_FAILED.
277 *
278 * @return the Flow Entry Switch state.
279 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800280 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800281 public FlowEntrySwitchState flowEntrySwitchState() {
282 return flowEntrySwitchState;
283 }
284
285 /**
286 * Set the Flow Entry Switch state.
287 *
288 * The Flow Entry Error state is used if FlowEntrySwitchState is
289 * FE_SWITCH_FAILED.
290 *
291 * @param flowEntrySwitchState the Flow Entry Switch state to set.
292 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800293 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800294 public void setFlowEntrySwitchState(FlowEntrySwitchState flowEntrySwitchState) {
295 this.flowEntrySwitchState = flowEntrySwitchState;
296 }
297
298 /**
299 * Get the Flow Entry Error state.
300 *
301 * @return the Flow Entry Error state.
302 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800303 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800304 public FlowEntryErrorState flowEntryErrorState() {
305 return flowEntryErrorState;
306 }
307
308 /**
309 * Set the Flow Entry Error state.
310 *
311 * @param flowEntryErrorState the Flow Entry Error state to set.
312 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800313 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800314 public void setFlowEntryErrorState(FlowEntryErrorState flowEntryErrorState) {
315 this.flowEntryErrorState = flowEntryErrorState;
316 }
317
318 /**
319 * Convert the flow entry to a string.
320 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800321 * The string has the following form:
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700322 * [flowEntryId=XXX flowEntryMatch=XXX flowEntryActions=XXX dpid=XXX
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800323 * inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX
324 * flowEntryErrorState=XXX]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800325 * @return the flow entry as a string.
326 */
327 @Override
328 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800329 String ret = "[flowEntryId=" + this.flowEntryId.toString();
330 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700331 ret += " flowEntryActions=" + this.flowEntryActions.toString();
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800332 ret += " dpid=" + this.dpid.toString();
333 ret += " inPort=" + this.inPort.toString();
334 ret += " outPort=" + this.outPort.toString();
335 ret += " flowEntryUserState=" + this.flowEntryUserState;
336 ret += " flowEntrySwitchState=" + this.flowEntrySwitchState;
337 ret += " flowEntryErrorState=" + this.flowEntryErrorState.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800338 ret += "]";
339
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800340 return ret;
341 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800342}