blob: ac32d0bc8adcf6a41f06a10d797742d722a5e36a [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
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08005
Pavlin Radoslavovede97582013-03-08 18:57:28 -08006import net.floodlightcontroller.util.MACAddress;
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07007import net.onrc.onos.ofcontroller.util.FlowEntryAction;
8import net.onrc.onos.ofcontroller.util.FlowEntryErrorState;
9import net.onrc.onos.ofcontroller.util.FlowEntryId;
10import net.onrc.onos.ofcontroller.util.FlowEntryMatch;
11import net.onrc.onos.ofcontroller.util.FlowEntrySwitchState;
12import net.onrc.onos.ofcontroller.util.FlowEntryUserState;
Pavlin Radoslavovede97582013-03-08 18:57:28 -080013
Pankaj Berded0ae0ff2013-03-26 15:37:12 -070014import org.codehaus.jackson.annotate.JsonIgnore;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -080015import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080016
17/**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080018 * The class representing the Flow Entry.
19 *
20 * NOTE: The specification is incomplete. E.g., the entry needs to
21 * support multiple in-ports and multiple out-ports.
22 */
23public class FlowEntry {
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -070024 private FlowId flowId; // FlowID of flowEntry
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080025 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 /**
Pavlin Radoslavov5f85c7b2013-03-28 05:33:57 -0700128 * Get the Flow ID.
129 * @return the Flow ID.
130 */
131 @JsonIgnore
132 public FlowId getFlowId() { return flowId; }
133
134 /**
135 * Set the Flow ID.
136 *
137 * @param flowId the Flow ID to set.
138 */
139 public void setFlowId(FlowId flowId) {
140 this.flowId = flowId;
141 }
142
143 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800144 * Get the Flow Entry ID.
145 *
146 * @return the Flow Entry ID.
147 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800148 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800149 public FlowEntryId flowEntryId() { return flowEntryId; }
150
151 /**
152 * Set the Flow Entry ID.
153 *
154 * @param flowEntryId the Flow Entry ID to set.
155 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800156 @JsonProperty("flowEntryId")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800157 public void setFlowEntryId(FlowEntryId flowEntryId) {
158 this.flowEntryId = flowEntryId;
159 }
160
161 /**
162 * Get the Flow Entry Match.
163 *
164 * @return the Flow Entry Match.
165 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800166 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800167 public FlowEntryMatch flowEntryMatch() { return flowEntryMatch; }
168
169 /**
170 * Set the Flow Entry Match.
171 *
172 * @param flowEntryMatch the Flow Entry Match to set.
173 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800174 @JsonProperty("flowEntryMatch")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800175 public void setFlowEntryMatch(FlowEntryMatch flowEntryMatch) {
176 this.flowEntryMatch = flowEntryMatch;
177 }
178
179 /**
180 * Get the Flow Entry Actions.
181 *
182 * @return the Flow Entry Actions.
183 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800184 @JsonProperty("flowEntryActions")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800185 public ArrayList<FlowEntryAction> flowEntryActions() {
186 return flowEntryActions;
187 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800188
189 /**
190 * Set the Flow Entry Actions.
191 *
192 * @param flowEntryActions the Flow Entry Actions to set.
193 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800194 @JsonProperty("flowEntryActions")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800195 public void setFlowEntryActions(ArrayList<FlowEntryAction> flowEntryActions) {
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800196 this.flowEntryActions = flowEntryActions;
197 }
198
199 /**
200 * Get the Switch DPID.
201 *
202 * @return the Switch DPID.
203 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800204 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800205 public Dpid dpid() { return dpid; }
206
207 /**
208 * Set the Switch DPID.
209 *
210 * @param dpid the Switch DPID to set.
211 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800212 @JsonProperty("dpid")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800213 public void setDpid(Dpid dpid) {
214 this.dpid = dpid;
215 }
216
217 /**
218 * Get the Switch incoming port.
219 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700220 * Used only when the entry is used to return Shortest Path computation.
221 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800222 * @return the Switch incoming port.
223 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800224 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800225 public Port inPort() { return inPort; }
226
227 /**
228 * Set the Switch incoming port.
229 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700230 * Used only when the entry is used to return Shortest Path computation.
231 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800232 * @param inPort the Switch incoming port to set.
233 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800234 @JsonProperty("inPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800235 public void setInPort(Port inPort) {
236 this.inPort = inPort;
237 }
238
239 /**
240 * Get the Switch outgoing port.
241 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700242 * Used only when the entry is used to return Shortest Path computation.
243 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800244 * @return the Switch outgoing port.
245 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800246 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800247 public Port outPort() { return outPort; }
248
249 /**
250 * Set the Switch outgoing port.
251 *
Pavlin Radoslavov67b3ef32013-04-03 02:44:48 -0700252 * Used only when the entry is used to return Shortest Path computation.
253 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800254 * @param outPort the Switch outgoing port to set.
255 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800256 @JsonProperty("outPort")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800257 public void setOutPort(Port outPort) {
258 this.outPort = outPort;
259 }
260
261 /**
262 * Get the Flow Entry User state.
263 *
264 * @return the Flow Entry User state.
265 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800266 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800267 public FlowEntryUserState flowEntryUserState() {
268 return flowEntryUserState;
269 }
270
271 /**
272 * Set the Flow Entry User state.
273 *
274 * @param flowEntryUserState the Flow Entry User state to set.
275 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800276 @JsonProperty("flowEntryUserState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800277 public void setFlowEntryUserState(FlowEntryUserState flowEntryUserState) {
278 this.flowEntryUserState = flowEntryUserState;
279 }
280
281 /**
282 * Get the Flow Entry Switch state.
283 *
284 * The Flow Entry Error state is used if FlowEntrySwitchState is
285 * FE_SWITCH_FAILED.
286 *
287 * @return the Flow Entry Switch state.
288 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800289 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800290 public FlowEntrySwitchState flowEntrySwitchState() {
291 return flowEntrySwitchState;
292 }
293
294 /**
295 * Set the Flow Entry Switch state.
296 *
297 * The Flow Entry Error state is used if FlowEntrySwitchState is
298 * FE_SWITCH_FAILED.
299 *
300 * @param flowEntrySwitchState the Flow Entry Switch state to set.
301 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800302 @JsonProperty("flowEntrySwitchState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800303 public void setFlowEntrySwitchState(FlowEntrySwitchState flowEntrySwitchState) {
304 this.flowEntrySwitchState = flowEntrySwitchState;
305 }
306
307 /**
308 * Get the Flow Entry Error state.
309 *
310 * @return the Flow Entry Error state.
311 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800312 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800313 public FlowEntryErrorState flowEntryErrorState() {
314 return flowEntryErrorState;
315 }
316
317 /**
318 * Set the Flow Entry Error state.
319 *
320 * @param flowEntryErrorState the Flow Entry Error state to set.
321 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800322 @JsonProperty("flowEntryErrorState")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800323 public void setFlowEntryErrorState(FlowEntryErrorState flowEntryErrorState) {
324 this.flowEntryErrorState = flowEntryErrorState;
325 }
326
327 /**
328 * Convert the flow entry to a string.
329 *
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800330 * The string has the following form:
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800331 * [flowEntryId=XXX flowEntryMatch=XXX flowEntryAction=XXX
332 * flowEntryAction=XXX flowEntryAction=XXX dpid=XXX
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800333 * inPort=XXX outPort=XXX flowEntryUserState=XXX flowEntrySwitchState=XXX
334 * flowEntryErrorState=XXX]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800335 * @return the flow entry as a string.
336 */
337 @Override
338 public String toString() {
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800339 String ret = "[flowEntryId=" + this.flowEntryId.toString();
340 ret += " flowEntryMatch=" + this.flowEntryMatch.toString();
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800341 for (FlowEntryAction fa : flowEntryActions) {
342 ret += " flowEntryAction=" + fa.toString();
343 }
Pavlin Radoslavova10a9a82013-02-22 11:47:54 -0800344 ret += " dpid=" + this.dpid.toString();
345 ret += " inPort=" + this.inPort.toString();
346 ret += " outPort=" + this.outPort.toString();
347 ret += " flowEntryUserState=" + this.flowEntryUserState;
348 ret += " flowEntrySwitchState=" + this.flowEntrySwitchState;
349 ret += " flowEntryErrorState=" + this.flowEntryErrorState.toString();
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800350 ret += "]";
351
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800352 return ret;
353 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800354}