blob: f0b115201ea31879bf1c4ea0604cb5f3d5e870d5 [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
3import net.floodlightcontroller.util.MACAddress;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08004
5import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08006
7/**
8 * The class representing the Flow Entry Matching filter.
Ray Milkey269ffb92014-04-03 14:43:30 -07009 * <p/>
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080010 * The Flow Entry matching filter that is used to specify
11 * the network data that would be forwarded on the data path from
Pavlin Radoslavovede97582013-03-08 18:57:28 -080012 * the source to the destination. Examples: source or destination MAC address,
13 * IP prefix that includes the destination's IP address, etc.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080014 */
15public class FlowEntryMatch {
Pavlin Radoslavovede97582013-03-08 18:57:28 -080016 /**
17 * A class for storing a value to match.
18 */
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070019 public static class Field<T> {
Ray Milkey269ffb92014-04-03 14:43:30 -070020 /**
21 * Default constructor.
22 */
23 public Field() {
24 this.enabled = false;
25 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -080026
Ray Milkey269ffb92014-04-03 14:43:30 -070027 /**
28 * Constructor for a given value to match.
29 *
30 * @param value the value to match.
31 */
32 public Field(T value) {
33 this.value = value;
34 this.enabled = true;
35 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -080036
Ray Milkey269ffb92014-04-03 14:43:30 -070037 /**
38 * Get the value.
39 *
40 * @return the value.
41 */
42 public T value() {
43 return this.value;
44 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -080045
Ray Milkey269ffb92014-04-03 14:43:30 -070046 /**
47 * Enable the matching for a given value.
48 *
49 * @param value the value to set.
50 */
51 public void enableMatch(T value) {
52 this.value = value;
53 this.enabled = true;
54 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -080055
Ray Milkey269ffb92014-04-03 14:43:30 -070056 /**
57 * Disable the matching.
58 */
59 public void disableMatch() {
60 this.enabled = false;
61 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -080062
Ray Milkey269ffb92014-04-03 14:43:30 -070063 /**
64 * Test whether matching is enabled.
65 *
66 * @return true if matching is enabled, otherwise false.
67 */
68 public boolean enabled() {
69 return this.enabled;
70 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -080071
Ray Milkey269ffb92014-04-03 14:43:30 -070072 private T value; // The value to match
73 private boolean enabled; // Set to true, if matching is enabled
Pavlin Radoslavovede97582013-03-08 18:57:28 -080074 }
75
Ray Milkey269ffb92014-04-03 14:43:30 -070076 private Field<Port> inPort; // Matching input switch port
77 private Field<MACAddress> srcMac; // Matching source MAC address
78 private Field<MACAddress> dstMac; // Matching destination MAC address
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -070079 private Field<Short> ethernetFrameType; // Matching Ethernet frame type
Ray Milkey269ffb92014-04-03 14:43:30 -070080 private Field<Short> vlanId; // Matching VLAN ID
81 private Field<Byte> vlanPriority; // Matching VLAN priority
82 private Field<IPv4Net> srcIPv4Net; // Matching source IPv4 prefix
83 private Field<IPv4Net> dstIPv4Net; // Matching destination IPv4 prefix
84 private Field<Byte> ipProto; // Matching IP protocol
85 private Field<Byte> ipToS; // Matching IP ToS (DSCP field, 6 bits)
86 private Field<Short> srcTcpUdpPort; // Matching source TCP/UDP port
87 private Field<Short> dstTcpUdpPort; // Matching destination TCP/UDP port
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080088
89 /**
90 * Default constructor.
91 */
92 public FlowEntryMatch() {
93 }
94
95 /**
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -070096 * Copy constructor.
97 *
98 * @param other the object to copy from.
99 */
100 public FlowEntryMatch(FlowEntryMatch other) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700101 if ((other.inPort != null) && other.inPort.enabled()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700102 this.enableInPort(other.inPort.value());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700103 }
104 if ((other.srcMac != null) && other.srcMac.enabled()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700105 this.enableSrcMac(other.srcMac.value());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700106 }
107 if ((other.dstMac != null) && other.dstMac.enabled()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700108 this.enableDstMac(other.dstMac.value());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700109 }
110 if ((other.ethernetFrameType != null) && other.ethernetFrameType.enabled()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700111 this.enableEthernetFrameType(other.ethernetFrameType.value());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700112 }
113 if ((other.vlanId != null) && other.vlanId.enabled()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700114 this.enableVlanId(other.vlanId.value());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700115 }
116 if ((other.vlanPriority != null) && other.vlanPriority.enabled()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700117 this.enableVlanPriority(other.vlanPriority.value());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700118 }
119 if ((other.srcIPv4Net != null) && other.srcIPv4Net.enabled()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700120 this.enableSrcIPv4Net(other.srcIPv4Net.value());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700121 }
122 if ((other.dstIPv4Net != null) && other.dstIPv4Net.enabled()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700123 this.enableDstIPv4Net(other.dstIPv4Net.value());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700124 }
125 if ((other.ipProto != null) && other.ipProto.enabled()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700126 this.enableIpProto(other.ipProto.value());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700127 }
128 if ((other.ipToS != null) && other.ipToS.enabled()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700129 this.enableIpToS(other.ipToS.value());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700130 }
131 if ((other.srcTcpUdpPort != null) && other.srcTcpUdpPort.enabled()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700132 this.enableSrcTcpUdpPort(other.srcTcpUdpPort.value());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700133 }
134 if ((other.dstTcpUdpPort != null) && other.dstTcpUdpPort.enabled()) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700135 this.enableDstTcpUdpPort(other.dstTcpUdpPort.value());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700136 }
Pavlin Radoslavovb9fe6b42013-03-27 16:25:05 -0700137 }
138
139 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800140 * Get the matching input switch port.
141 *
142 * @return the matching input switch port.
143 */
144 @JsonProperty("inPort")
145 public Port inPort() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700146 if (inPort != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700147 return inPort.value();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700148 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700149 return null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800150 }
151
152 /**
153 * Enable the matching on input switch port.
154 *
155 * @param inPort the input switch port value to enable for matching.
156 */
157 @JsonProperty("inPort")
158 public void enableInPort(Port inPort) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700159 this.inPort = new Field<Port>(inPort);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800160 }
161
162 /**
163 * Disable the matching on input switch port.
164 */
165 public void disableInPort() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700166 this.inPort = null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800167 }
168
169 /**
170 * Test if matching on input switch port is enabled.
171 *
172 * @return true if matching on input switch port is enabled.
173 */
174 @JsonProperty("matchInPort")
175 public boolean matchInPort() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700176 if (inPort != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700177 return inPort.enabled();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700178 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700179 return false;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800180 }
181
182 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800183 * Get the matching source MAC address.
184 *
185 * @return the matching source MAC address.
186 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800187 @JsonProperty("srcMac")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800188 public MACAddress srcMac() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700189 if (srcMac != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700190 return srcMac.value();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700191 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700192 return null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800193 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800194
195 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800196 * Enable the matching on source MAC address.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800197 *
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800198 * @param srcMac the source MAC address value to enable for matching.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800199 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800200 @JsonProperty("srcMac")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800201 public void enableSrcMac(MACAddress srcMac) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700202 this.srcMac = new Field<MACAddress>(srcMac);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800203 }
204
205 /**
206 * Disable the matching on source MAC address.
207 */
208 public void disableSrcMac() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700209 this.srcMac = null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800210 }
211
212 /**
213 * Test if matching on source MAC address is enabled.
214 *
215 * @return true if matching on source MAC address is enabled.
216 */
217 @JsonProperty("matchSrcMac")
218 public boolean matchSrcMac() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700219 if (srcMac != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700220 return srcMac.enabled();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700221 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700222 return false;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800223 }
224
225 /**
226 * Get the matching destination MAC address.
227 *
228 * @return the matching destination MAC address.
229 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800230 @JsonProperty("dstMac")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800231 public MACAddress dstMac() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700232 if (dstMac != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700233 return dstMac.value();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700234 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700235 return null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800236 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800237
238 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800239 * Enable the matching on destination MAC address.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800240 *
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800241 * @param dstMac the destination MAC address value to enable for matching.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800242 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800243 @JsonProperty("dstMac")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800244 public void enableDstMac(MACAddress dstMac) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700245 this.dstMac = new Field<MACAddress>(dstMac);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800246 }
247
248 /**
249 * Disable the matching on destination MAC address.
250 */
251 public void disableDstMac() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700252 this.dstMac = null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800253 }
254
255 /**
256 * Test if matching on destination MAC address is enabled.
257 *
258 * @return true if matching on destination MAC address is enabled.
259 */
260 @JsonProperty("matchDstMac")
261 public boolean matchDstMac() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700262 if (dstMac != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700263 return dstMac.enabled();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700264 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700265 return false;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800266 }
267
268 /**
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700269 * Get the matching Ethernet frame type.
270 *
271 * @return the matching Ethernet frame type.
272 */
273 @JsonProperty("ethernetFrameType")
274 public Short ethernetFrameType() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700275 if (ethernetFrameType != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700276 return ethernetFrameType.value();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700277 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700278 return null;
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700279 }
280
281 /**
282 * Enable the matching on Ethernet frame type.
283 *
284 * @param ethernetFrameType the Ethernet frame type value to enable for
Ray Milkey269ffb92014-04-03 14:43:30 -0700285 * matching.
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700286 */
287 @JsonProperty("ethernetFrameType")
288 public void enableEthernetFrameType(Short ethernetFrameType) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700289 this.ethernetFrameType = new Field<Short>(ethernetFrameType);
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700290 }
291
292 /**
293 * Disable the matching on Ethernet frame type.
294 */
295 public void disableEthernetFrameType() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700296 this.ethernetFrameType = null;
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700297 }
298
299 /**
300 * Test if matching on Ethernet frame type is enabled.
301 *
302 * @return true if matching on Ethernet frame type is enabled.
303 */
304 @JsonProperty("matchEthernetFrameType")
305 public boolean matchEthernetFrameType() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700306 if (ethernetFrameType != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700307 return ethernetFrameType.enabled();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700308 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700309 return false;
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700310 }
311
312 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800313 * Get the matching VLAN ID.
314 *
315 * @return the matching VLAN ID.
316 */
317 @JsonProperty("vlanId")
318 public Short vlanId() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700319 if (vlanId != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700320 return vlanId.value();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700321 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700322 return null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800323 }
324
325 /**
326 * Enable the matching on VLAN ID.
327 *
328 * @param vlanId the VLAN ID value to enable for matching.
329 */
330 @JsonProperty("vlanId")
331 public void enableVlanId(Short vlanId) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700332 this.vlanId = new Field<Short>(vlanId);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800333 }
334
335 /**
336 * Disable the matching on VLAN ID.
337 */
338 public void disableVlanId() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700339 this.vlanId = null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800340 }
341
342 /**
343 * Test if matching on VLAN ID is enabled.
344 *
345 * @return true if matching on VLAN ID is enabled.
346 */
347 @JsonProperty("matchVlanId")
348 public boolean matchVlanId() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700349 if (vlanId != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700350 return vlanId.enabled();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700351 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700352 return false;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800353 }
354
355 /**
356 * Get the matching VLAN priority.
357 *
358 * @return the matching VLAN priority.
359 */
360 @JsonProperty("vlanPriority")
361 public Byte vlanPriority() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700362 if (vlanPriority != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700363 return vlanPriority.value();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700364 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700365 return null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800366 }
367
368 /**
369 * Enable the matching on VLAN priority.
370 *
371 * @param vlanPriority the VLAN priority value to enable for matching.
372 */
373 @JsonProperty("vlanPriority")
374 public void enableVlanPriority(Byte vlanPriority) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700375 this.vlanPriority = new Field<Byte>(vlanPriority);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800376 }
377
378 /**
379 * Disable the matching on VLAN priority.
380 */
381 public void disableVlanPriority() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700382 this.vlanPriority = null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800383 }
384
385 /**
386 * Test if matching on VLAN priority is enabled.
387 *
388 * @return true if matching on VLAN priority is enabled.
389 */
390 @JsonProperty("matchVlanPriority")
391 public boolean matchVlanPriority() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700392 if (vlanPriority != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700393 return vlanPriority.enabled();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700394 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700395 return false;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800396 }
397
398 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800399 * Get the matching source IPv4 prefix.
400 *
401 * @return the matching source IPv4 prefix.
402 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800403 @JsonProperty("srcIPv4Net")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800404 public IPv4Net srcIPv4Net() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700405 if (srcIPv4Net != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700406 return srcIPv4Net.value();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700407 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700408 return null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800409 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800410
411 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800412 * Enable the matching on source IPv4 prefix.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800413 *
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800414 * @param srcIPv4Net the source IPv4 prefix value to enable for matching.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800415 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800416 @JsonProperty("srcIPv4Net")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800417 public void enableSrcIPv4Net(IPv4Net srcIPv4Net) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700418 this.srcIPv4Net = new Field<IPv4Net>(srcIPv4Net);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800419 }
420
421 /**
422 * Disable the matching on source IPv4 prefix.
423 */
424 public void disableSrcIPv4Net() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700425 this.srcIPv4Net = null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800426 }
427
428 /**
429 * Test if matching on source IPv4 prefix is enabled.
430 *
431 * @return true if matching on source IPv4 prefix is enabled.
432 */
433 @JsonProperty("matchSrcIPv4Net")
434 public boolean matchSrcIPv4Net() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700435 if (srcIPv4Net != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700436 return srcIPv4Net.enabled();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700437 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700438 return false;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800439 }
440
441 /**
442 * Get the matching destination IPv4 prefix.
443 *
444 * @return the matching destination IPv4 prefix.
445 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800446 @JsonProperty("dstIPv4Net")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800447 public IPv4Net dstIPv4Net() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700448 if (dstIPv4Net != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700449 return dstIPv4Net.value();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700450 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700451 return null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800452 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800453
454 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800455 * Enable the matching on destination IPv4 prefix.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800456 *
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800457 * @param dstIPv4Net the destination IPv4 prefix value to enable for
Ray Milkey269ffb92014-04-03 14:43:30 -0700458 * matching.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800459 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800460 @JsonProperty("dstIPv4Net")
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800461 public void enableDstIPv4Net(IPv4Net dstIPv4Net) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700462 this.dstIPv4Net = new Field<IPv4Net>(dstIPv4Net);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800463 }
464
465 /**
466 * Disable the matching on destination IPv4 prefix.
467 */
468 public void disableDstIPv4Net() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700469 this.dstIPv4Net = null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800470 }
471
472 /**
473 * Test if matching on destination IPv4 prefix is enabled.
474 *
475 * @return true if matching on destination IPv4 prefix is enabled.
476 */
477 @JsonProperty("matchDstIPv4Net")
478 public boolean matchDstIPv4Net() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700479 if (dstIPv4Net != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700480 return dstIPv4Net.enabled();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700481 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700482 return false;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800483 }
484
485 /**
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700486 * Get the matching IP protocol.
487 *
488 * @return the matching IP protocol.
489 */
490 @JsonProperty("ipProto")
491 public Byte ipProto() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700492 if (ipProto != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700493 return ipProto.value();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700494 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700495 return null;
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700496 }
497
498 /**
499 * Enable the matching on IP protocol.
500 *
501 * @param ipProto the IP protocol value to enable for matching.
502 */
503 @JsonProperty("ipProto")
504 public void enableIpProto(Byte ipProto) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700505 this.ipProto = new Field<Byte>(ipProto);
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700506 }
507
508 /**
509 * Disable the matching on IP protocol.
510 */
511 public void disableIpProto() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700512 this.ipProto = null;
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700513 }
514
515 /**
516 * Test if matching on IP protocol is enabled.
517 *
518 * @return true if matching on IP protocol is enabled.
519 */
520 @JsonProperty("matchIpProto")
521 public boolean matchIpProto() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700522 if (ipProto != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700523 return ipProto.enabled();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700524 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700525 return false;
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700526 }
527
528 /**
529 * Get the matching IP ToS (DSCP field, 6 bits)
530 *
531 * @return the matching IP ToS.
532 */
533 @JsonProperty("ipToS")
534 public Byte ipToS() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700535 if (ipToS != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700536 return ipToS.value();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700537 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700538 return null;
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700539 }
540
541 /**
542 * Enable the matching on IP ToS (DSCP field, 6 bits).
543 *
544 * @param ipToS the IP ToS value to enable for matching.
545 */
546 @JsonProperty("ipToS")
547 public void enableIpToS(Byte ipToS) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700548 this.ipToS = new Field<Byte>(ipToS);
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700549 }
550
551 /**
552 * Disable the matching on IP ToS (DSCP field, 6 bits).
553 */
554 public void disableIpToS() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700555 this.ipToS = null;
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700556 }
557
558 /**
559 * Test if matching on IP ToS (DSCP field, 6 bits) is enabled.
560 *
561 * @return true if matching on IP ToS is enabled.
562 */
563 @JsonProperty("matchIpToS")
564 public boolean matchIpToS() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700565 if (ipToS != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700566 return ipToS.enabled();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700567 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700568 return false;
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700569 }
570
571 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800572 * Get the matching source TCP/UDP port.
573 *
574 * @return the matching source TCP/UDP port.
575 */
576 @JsonProperty("srcTcpUdpPort")
577 public Short srcTcpUdpPort() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700578 if (srcTcpUdpPort != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700579 return srcTcpUdpPort.value();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700580 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700581 return null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800582 }
583
584 /**
585 * Enable the matching on source TCP/UDP port.
586 *
587 * @param srcTcpUdpPort the source TCP/UDP port to enable for matching.
588 */
589 @JsonProperty("srcTcpUdpPort")
590 public void enableSrcTcpUdpPort(Short srcTcpUdpPort) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700591 this.srcTcpUdpPort = new Field<Short>(srcTcpUdpPort);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800592 }
593
594 /**
595 * Disable the matching on source TCP/UDP port.
596 */
597 public void disableSrcTcpUdpPort() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700598 this.srcTcpUdpPort = null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800599 }
600
601 /**
602 * Test if matching on source TCP/UDP port is enabled.
603 *
604 * @return true if matching on source TCP/UDP port is enabled.
605 */
606 @JsonProperty("matchSrcTcpUdpPort")
607 public boolean matchSrcTcpUdpPort() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700608 if (srcTcpUdpPort != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700609 return srcTcpUdpPort.enabled();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700610 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700611 return false;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800612 }
613
614 /**
615 * Get the matching destination TCP/UDP port.
616 *
617 * @return the matching destination TCP/UDP port.
618 */
619 @JsonProperty("dstTcpUdpPort")
620 public Short dstTcpUdpPort() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700621 if (dstTcpUdpPort != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700622 return dstTcpUdpPort.value();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700623 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700624 return null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800625 }
626
627 /**
628 * Enable the matching on destination TCP/UDP port.
629 *
630 * @param dstTcpUdpPort the destination TCP/UDP port to enable for
Ray Milkey269ffb92014-04-03 14:43:30 -0700631 * matching.
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800632 */
633 @JsonProperty("dstTcpUdpPort")
634 public void enableDstTcpUdpPort(Short dstTcpUdpPort) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700635 this.dstTcpUdpPort = new Field<Short>(dstTcpUdpPort);
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800636 }
637
638 /**
639 * Disable the matching on destination TCP/UDP port.
640 */
641 public void disableDstTcpUdpPort() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700642 this.dstTcpUdpPort = null;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800643 }
644
645 /**
646 * Test if matching on destination TCP/UDP port is enabled.
647 *
648 * @return true if matching on destination TCP/UDP port is enabled.
649 */
650 @JsonProperty("matchDstTcpUdpPort")
651 public boolean matchDstTcpUdpPort() {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700652 if (dstTcpUdpPort != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700653 return dstTcpUdpPort.enabled();
Ray Milkeyb29e6262014-04-09 16:02:14 -0700654 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700655 return false;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800656 }
657
658 /**
659 * Convert the matching filter to a string.
Ray Milkey269ffb92014-04-03 14:43:30 -0700660 * <p/>
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800661 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -0700662 * [srcMac=XXX dstMac=XXX srcIPv4Net=XXX dstIPv4Net=XXX]
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800663 *
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800664 * @return the matching filter as a string.
665 */
666 @Override
667 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700668 String ret = "[";
669 boolean addSpace = false;
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800670
Ray Milkey269ffb92014-04-03 14:43:30 -0700671 //
672 // Conditionally add only those matching fields that are enabled
673 //
674 if (matchInPort()) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700675 if (addSpace) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700676 ret += " ";
Ray Milkeyb29e6262014-04-09 16:02:14 -0700677 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700678 addSpace = true;
679 ret += "inPort=" + this.inPort().toString();
680 }
681 if (matchSrcMac()) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700682 if (addSpace) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700683 ret += " ";
Ray Milkeyb29e6262014-04-09 16:02:14 -0700684 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700685 addSpace = true;
686 ret += "srcMac=" + this.srcMac().toString();
687 }
688 if (matchDstMac()) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700689 if (addSpace) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700690 ret += " ";
Ray Milkeyb29e6262014-04-09 16:02:14 -0700691 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700692 addSpace = true;
693 ret += "dstMac=" + this.dstMac().toString();
694 }
695 if (matchEthernetFrameType()) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700696 if (addSpace) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700697 ret += " ";
Ray Milkeyb29e6262014-04-09 16:02:14 -0700698 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700699 addSpace = true;
700 ret += "ethernetFrameType=" + this.ethernetFrameType().toString();
701 }
702 if (matchVlanId()) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700703 if (addSpace) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700704 ret += " ";
Ray Milkeyb29e6262014-04-09 16:02:14 -0700705 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700706 addSpace = true;
707 ret += "vlanId=" + this.vlanId().toString();
708 }
709 if (matchVlanPriority()) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700710 if (addSpace) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700711 ret += " ";
Ray Milkeyb29e6262014-04-09 16:02:14 -0700712 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700713 addSpace = true;
714 ret += "vlanPriority=" + this.vlanPriority().toString();
715 }
716 if (matchSrcIPv4Net()) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700717 if (addSpace) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700718 ret += " ";
Ray Milkeyb29e6262014-04-09 16:02:14 -0700719 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700720 addSpace = true;
721 ret += "srcIPv4Net=" + this.srcIPv4Net().toString();
722 }
723 if (matchDstIPv4Net()) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700724 if (addSpace) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700725 ret += " ";
Ray Milkeyb29e6262014-04-09 16:02:14 -0700726 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700727 addSpace = true;
728 ret += "dstIPv4Net=" + this.dstIPv4Net().toString();
729 }
730 if (matchIpProto()) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700731 if (addSpace) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700732 ret += " ";
Ray Milkeyb29e6262014-04-09 16:02:14 -0700733 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700734 addSpace = true;
735 ret += "ipProto=" + this.ipProto().toString();
736 }
737 if (matchIpToS()) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700738 if (addSpace) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700739 ret += " ";
Ray Milkeyb29e6262014-04-09 16:02:14 -0700740 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700741 addSpace = true;
742 ret += "ipToS=" + this.ipToS().toString();
743 }
744 if (matchSrcTcpUdpPort()) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700745 if (addSpace) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700746 ret += " ";
Ray Milkeyb29e6262014-04-09 16:02:14 -0700747 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700748 addSpace = true;
749 ret += "srcTcpUdpPort=" + this.srcTcpUdpPort().toString();
750 }
751 if (matchDstTcpUdpPort()) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700752 if (addSpace) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700753 ret += " ";
Ray Milkeyb29e6262014-04-09 16:02:14 -0700754 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700755 addSpace = true;
756 ret += "dstTcpUdpPort=" + this.dstTcpUdpPort().toString();
757 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800758
Ray Milkey269ffb92014-04-03 14:43:30 -0700759 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800760
Ray Milkey269ffb92014-04-03 14:43:30 -0700761 return ret;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800762 }
763}