blob: f972d9e25bb97e371887c15243650067c5864aa0 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow.criteria;
tom8bb16062014-09-12 14:47:46 -070017
alshabib99b8fdc2014-09-25 14:30:22 -070018import static com.google.common.base.MoreObjects.toStringHelper;
19
alshabibba5ac482014-10-02 17:15:20 -070020import java.util.Objects;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.PortNumber;
22import org.onosproject.net.flow.criteria.Criterion.Type;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070023import org.onlab.packet.IpPrefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080024import org.onlab.packet.Ip6Address;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070025import org.onlab.packet.MacAddress;
26import org.onlab.packet.VlanId;
alshabib7b795492014-09-16 14:38:39 -070027
tom8bb16062014-09-12 14:47:46 -070028/**
29 * Factory class to create various traffic selection criteria.
30 */
31public final class Criteria {
32
alshabib7b795492014-09-16 14:38:39 -070033 //TODO: incomplete type implementation. Need to implement complete list from Criterion
34
tom8bb16062014-09-12 14:47:46 -070035 // Ban construction
36 private Criteria() {
37 }
38
39 /**
alshabib7b795492014-09-16 14:38:39 -070040 * Creates a match on IN_PORT field using the specified value.
41 *
42 * @param port inport value
43 * @return match criterion
44 */
45 public static Criterion matchInPort(PortNumber port) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080046 return new PortCriterion(port, Type.IN_PORT);
47 }
48
49 /**
50 * Creates a match on IN_PHY_PORT field using the specified value.
51 *
52 * @param port inport value
53 * @return match criterion
54 */
55 public static Criterion matchInPhyPort(PortNumber port) {
56 return new PortCriterion(port, Type.IN_PHY_PORT);
57 }
58
59 /**
60 * Creates a match on METADATA field using the specified value.
61 *
62 * @param metadata metadata value
63 * @return match criterion
64 */
65 public static Criterion matchMetadata(Long metadata) {
66 return new MetadataCriterion(metadata);
alshabib7b795492014-09-16 14:38:39 -070067 }
68
69 /**
alshabib369d2942014-09-12 17:59:35 -070070 * Creates a match on ETH_DST field using the specified value. This value
71 * may be a wildcard mask.
72 *
tomc104d282014-09-19 10:57:55 -070073 * @param mac MAC address value or wildcard mask
alshabib369d2942014-09-12 17:59:35 -070074 * @return match criterion
75 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070076 public static Criterion matchEthDst(MacAddress mac) {
alshabib7b795492014-09-16 14:38:39 -070077 return new EthCriterion(mac, Type.ETH_DST);
78 }
79
80 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080081 * Creates a match on ETH_SRC field using the specified value. This value
82 * may be a wildcard mask.
83 *
84 * @param mac MAC address value or wildcard mask
85 * @return match criterion
86 */
87 public static Criterion matchEthSrc(MacAddress mac) {
88 return new EthCriterion(mac, Type.ETH_SRC);
89 }
90
91 /**
alshabib7b795492014-09-16 14:38:39 -070092 * Creates a match on ETH_TYPE field using the specified value.
93 *
94 * @param ethType eth type value
95 * @return match criterion
96 */
97 public static Criterion matchEthType(Short ethType) {
98 return new EthTypeCriterion(ethType);
99 }
100
101 /**
102 * Creates a match on VLAN ID field using the specified value.
103 *
104 * @param vlanId vlan id value
105 * @return match criterion
106 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700107 public static Criterion matchVlanId(VlanId vlanId) {
alshabib7b795492014-09-16 14:38:39 -0700108 return new VlanIdCriterion(vlanId);
109 }
110
111 /**
112 * Creates a match on VLAN PCP field using the specified value.
113 *
114 * @param vlanPcp vlan pcp value
115 * @return match criterion
116 */
alshabibb45d1962014-09-18 14:25:45 -0700117 public static Criterion matchVlanPcp(Byte vlanPcp) {
alshabib7b795492014-09-16 14:38:39 -0700118 return new VlanPcpCriterion(vlanPcp);
119 }
120
121 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800122 * Creates a match on IP DSCP field using the specified value.
123 *
124 * @param ipDscp ip dscp value
125 * @return match criterion
126 */
127 public static Criterion matchIPDscp(Byte ipDscp) {
128 return new IPDscpCriterion(ipDscp);
129 }
130
131 /**
132 * Creates a match on IP ECN field using the specified value.
133 *
134 * @param ipEcn ip ecn value
135 * @return match criterion
136 */
137 public static Criterion matchIPEcn(Byte ipEcn) {
138 return new IPEcnCriterion(ipEcn);
139 }
140
141 /**
alshabib7b795492014-09-16 14:38:39 -0700142 * Creates a match on IP proto field using the specified value.
143 *
144 * @param proto ip protocol value
145 * @return match criterion
146 */
147 public static Criterion matchIPProtocol(Byte proto) {
148 return new IPProtocolCriterion(proto);
149 }
150
151 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800152 * Creates a match on IPv4 source field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700153 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800154 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700155 * @return match criterion
156 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700157 public static Criterion matchIPSrc(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700158 return new IPCriterion(ip, Type.IPV4_SRC);
159 }
160
161 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800162 * Creates a match on IPv4 destination field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700163 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800164 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700165 * @return match criterion
166 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700167 public static Criterion matchIPDst(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700168 return new IPCriterion(ip, Type.IPV4_DST);
alshabib369d2942014-09-12 17:59:35 -0700169 }
170
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700171 /**
172 * Creates a match on TCP source port field using the specified value.
173 *
Yuta HIGUCHI5c947272014-11-03 21:39:21 -0800174 * @param tcpPort TCP source port
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700175 * @return match criterion
176 */
177 public static Criterion matchTcpSrc(Short tcpPort) {
178 return new TcpPortCriterion(tcpPort, Type.TCP_SRC);
179 }
180
181 /**
182 * Creates a match on TCP destination port field using the specified value.
183 *
Yuta HIGUCHI5c947272014-11-03 21:39:21 -0800184 * @param tcpPort TCP destination port
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700185 * @return match criterion
186 */
187 public static Criterion matchTcpDst(Short tcpPort) {
188 return new TcpPortCriterion(tcpPort, Type.TCP_DST);
189 }
alshabib369d2942014-09-12 17:59:35 -0700190
Marc De Leenheer49087752014-10-23 13:54:09 -0700191 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800192 * Creates a match on UDP source port field using the specified value.
193 *
194 * @param udpPort UDP source port
195 * @return match criterion
196 */
197 public static Criterion matchUdpSrc(Short udpPort) {
198 return new UdpPortCriterion(udpPort, Type.UDP_SRC);
199 }
200
201 /**
202 * Creates a match on UDP destination port field using the specified value.
203 *
204 * @param udpPort UDP destination port
205 * @return match criterion
206 */
207 public static Criterion matchUdpDst(Short udpPort) {
208 return new UdpPortCriterion(udpPort, Type.UDP_DST);
209 }
210
211 /**
212 * Creates a match on SCTP source port field using the specified value.
213 *
214 * @param sctpPort SCTP source port
215 * @return match criterion
216 */
217 public static Criterion matchSctpSrc(Short sctpPort) {
218 return new SctpPortCriterion(sctpPort, Type.SCTP_SRC);
219 }
220
221 /**
222 * Creates a match on SCTP destination port field using the specified
223 * value.
224 *
225 * @param sctpPort SCTP destination port
226 * @return match criterion
227 */
228 public static Criterion matchSctpDst(Short sctpPort) {
229 return new SctpPortCriterion(sctpPort, Type.SCTP_DST);
230 }
231
232 /**
233 * Creates a match on ICMP type field using the specified value.
234 *
235 * @param icmpType ICMP type
236 * @return match criterion
237 */
238 public static Criterion matchIcmpType(Byte icmpType) {
239 return new IcmpTypeCriterion(icmpType);
240 }
241
242 /**
243 * Creates a match on ICMP code field using the specified value.
244 *
245 * @param icmpCode ICMP code
246 * @return match criterion
247 */
248 public static Criterion matchIcmpCode(Byte icmpCode) {
249 return new IcmpCodeCriterion(icmpCode);
250 }
251
252 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800253 * Creates a match on IPv6 source field using the specified value.
254 *
255 * @param ip ipv6 source value
256 * @return match criterion
257 */
258 public static Criterion matchIPv6Src(IpPrefix ip) {
259 return new IPCriterion(ip, Type.IPV6_SRC);
260 }
261
262 /**
263 * Creates a match on IPv6 destination field using the specified value.
264 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800265 * @param ip ipv6 destination value
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800266 * @return match criterion
267 */
268 public static Criterion matchIPv6Dst(IpPrefix ip) {
269 return new IPCriterion(ip, Type.IPV6_DST);
270 }
271
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800272 /**
273 * Creates a match on IPv6 flow label field using the specified value.
274 *
275 * @param flowLabel IPv6 flow label
276 * @return match criterion
277 */
278 public static Criterion matchIPv6FlowLabel(Integer flowLabel) {
279 return new IPv6FlowLabelCriterion(flowLabel);
280 }
281
282 /**
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800283 * Creates a match on ICMPv6 type field using the specified value.
284 *
285 * @param icmpv6Type ICMPv6 type
286 * @return match criterion
287 */
288 public static Criterion matchIcmpv6Type(Byte icmpv6Type) {
289 return new Icmpv6TypeCriterion(icmpv6Type);
290 }
291
292 /**
293 * Creates a match on ICMPv6 code field using the specified value.
294 *
295 * @param icmpv6Code ICMPv6 code
296 * @return match criterion
297 */
298 public static Criterion matchIcmpv6Code(Byte icmpv6Code) {
299 return new Icmpv6CodeCriterion(icmpv6Code);
300 }
301
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800302 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800303 * Creates a match on IPv6 Neighbor Discovery target address using the
304 * specified value.
305 *
306 * @param targetAddress IPv6 Neighbor Discovery target address
307 * @return match criterion
308 */
309 public static Criterion matchIPv6NDTargetAddress(Ip6Address targetAddress) {
310 return new IPv6NDTargetAddressCriterion(targetAddress);
311 }
312
313 /**
314 * Creates a match on IPv6 Neighbor Discovery source link-layer address
315 * using the specified value.
316 *
317 * @param mac IPv6 Neighbor Discovery source link-layer address
318 * @return match criterion
319 */
320 public static Criterion matchIPv6NDSourceLinkLayerAddress(MacAddress mac) {
321 return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_SLL);
322 }
323
324 /**
325 * Creates a match on IPv6 Neighbor Discovery target link-layer address
326 * using the specified value.
327 *
328 * @param mac IPv6 Neighbor Discovery target link-layer address
329 * @return match criterion
330 */
331 public static Criterion matchIPv6NDTargetLinkLayerAddress(MacAddress mac) {
332 return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_TLL);
333 }
334
335 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800336 * Creates a match on MPLS label.
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800337 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800338 * @param mplsLabel MPLS label
339 * @return match criterion
340 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800341 public static Criterion matchMplsLabel(Integer mplsLabel) {
342 return new MplsCriterion(mplsLabel);
343 }
344
345 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700346 * Creates a match on lambda field using the specified value.
347 *
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800348 * @param lambda lambda to match on
Marc De Leenheer49087752014-10-23 13:54:09 -0700349 * @return match criterion
350 */
351 public static Criterion matchLambda(Short lambda) {
352 return new LambdaCriterion(lambda, Type.OCH_SIGID);
353 }
354
355 /**
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800356 * Creates a match on optical signal type using the specified value.
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700357 *
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800358 * @param sigType optical signal type
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700359 * @return match criterion
360 */
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800361 public static Criterion matchOpticalSignalType(Short sigType) {
362 return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700363 }
364
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700365 /**
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800366 * Implementation of input port criterion.
alshabib7b795492014-09-16 14:38:39 -0700367 */
alshabib7b795492014-09-16 14:38:39 -0700368 public static final class PortCriterion implements Criterion {
369 private final PortNumber port;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800370 private final Type type;
alshabib7b795492014-09-16 14:38:39 -0700371
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800372 /**
373 * Constructor.
374 *
375 * @param port the input port number to match
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800376 * @param type the match type. Should be either Type.IN_PORT or
377 * Type.IN_PHY_PORT
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800378 */
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800379 public PortCriterion(PortNumber port, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700380 this.port = port;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800381 this.type = type;
alshabib7b795492014-09-16 14:38:39 -0700382 }
383
384 @Override
385 public Type type() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800386 return this.type;
alshabib7b795492014-09-16 14:38:39 -0700387 }
388
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800389 /**
390 * Gets the input port number to match.
391 *
392 * @return the input port number to match
393 */
alshabib7b795492014-09-16 14:38:39 -0700394 public PortNumber port() {
395 return this.port;
396 }
alshabib99b8fdc2014-09-25 14:30:22 -0700397
398 @Override
399 public String toString() {
400 return toStringHelper(type().toString())
401 .add("port", port).toString();
402 }
alshabibba5ac482014-10-02 17:15:20 -0700403
404 @Override
405 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800406 return Objects.hash(type(), port);
alshabibba5ac482014-10-02 17:15:20 -0700407 }
408
409 @Override
410 public boolean equals(Object obj) {
411 if (this == obj) {
412 return true;
413 }
414 if (obj instanceof PortCriterion) {
415 PortCriterion that = (PortCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700416 return Objects.equals(port, that.port) &&
417 Objects.equals(this.type(), that.type());
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800418 }
419 return false;
420 }
421 }
alshabibba5ac482014-10-02 17:15:20 -0700422
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800423 /**
424 * Implementation of Metadata criterion.
425 */
426 public static final class MetadataCriterion implements Criterion {
427 private final Long metadata;
428
429 /**
430 * Constructor.
431 *
432 * @param metadata the metadata to match
433 */
434 public MetadataCriterion(Long metadata) {
435 this.metadata = metadata;
436 }
437
438 @Override
439 public Type type() {
440 return Type.METADATA;
441 }
442
443 /**
444 * Gets the metadata to match.
445 *
446 * @return the metadata to match
447 */
448 public Long metadata() {
449 return metadata;
450 }
451
452 @Override
453 public String toString() {
454 return toStringHelper(type().toString())
455 .add("metadata", Long.toHexString(metadata))
456 .toString();
457 }
458
459 @Override
460 public int hashCode() {
461 return Objects.hash(type(), metadata);
462 }
463
464 @Override
465 public boolean equals(Object obj) {
466 if (this == obj) {
467 return true;
468 }
469 if (obj instanceof MetadataCriterion) {
470 MetadataCriterion that = (MetadataCriterion) obj;
471 return Objects.equals(metadata, that.metadata) &&
472 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700473 }
474 return false;
475 }
alshabib7b795492014-09-16 14:38:39 -0700476 }
477
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800478 /**
479 * Implementation of MAC address criterion.
480 */
alshabib7b795492014-09-16 14:38:39 -0700481 public static final class EthCriterion implements Criterion {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700482 private final MacAddress mac;
alshabib7b795492014-09-16 14:38:39 -0700483 private final Type type;
484
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800485 /**
486 * Constructor.
487 *
488 * @param mac the source or destination MAC address to match
489 * @param type the match type. Should be either Type.ETH_DST or
490 * Type.ETH_SRC
491 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700492 public EthCriterion(MacAddress mac, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700493 this.mac = mac;
494 this.type = type;
495 }
496
497 @Override
498 public Type type() {
499 return this.type;
500 }
501
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800502 /**
503 * Gets the MAC address to match.
504 *
505 * @return the MAC address to match
506 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700507 public MacAddress mac() {
alshabib7b795492014-09-16 14:38:39 -0700508 return this.mac;
509 }
alshabib99b8fdc2014-09-25 14:30:22 -0700510
511 @Override
512 public String toString() {
513 return toStringHelper(type().toString())
514 .add("mac", mac).toString();
515 }
516
alshabibba5ac482014-10-02 17:15:20 -0700517 @Override
518 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800519 return Objects.hash(type, mac);
alshabibba5ac482014-10-02 17:15:20 -0700520 }
521
522 @Override
523 public boolean equals(Object obj) {
524 if (this == obj) {
525 return true;
526 }
527 if (obj instanceof EthCriterion) {
528 EthCriterion that = (EthCriterion) obj;
529 return Objects.equals(mac, that.mac) &&
530 Objects.equals(type, that.type);
alshabibba5ac482014-10-02 17:15:20 -0700531 }
532 return false;
533 }
alshabib7b795492014-09-16 14:38:39 -0700534 }
535
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800536 /**
537 * Implementation of Ethernet type criterion.
538 */
alshabib7b795492014-09-16 14:38:39 -0700539 public static final class EthTypeCriterion implements Criterion {
alshabib7b795492014-09-16 14:38:39 -0700540 private final Short ethType;
541
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800542 /**
543 * Constructor.
544 *
545 * @param ethType the Ethernet frame type to match
546 */
alshabib7b795492014-09-16 14:38:39 -0700547 public EthTypeCriterion(Short ethType) {
548 this.ethType = ethType;
549 }
550
551 @Override
552 public Type type() {
553 return Type.ETH_TYPE;
554 }
555
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800556 /**
557 * Gets the Ethernet frame type to match.
558 *
559 * @return the Ethernet frame type to match
560 */
alshabib7b795492014-09-16 14:38:39 -0700561 public Short ethType() {
562 return ethType;
563 }
564
alshabib99b8fdc2014-09-25 14:30:22 -0700565 @Override
566 public String toString() {
567 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800568 .add("ethType", Long.toHexString(ethType & 0xffff))
569 .toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700570 }
571
alshabibba5ac482014-10-02 17:15:20 -0700572 @Override
573 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800574 return Objects.hash(type(), ethType);
alshabibba5ac482014-10-02 17:15:20 -0700575 }
576
577 @Override
578 public boolean equals(Object obj) {
579 if (this == obj) {
580 return true;
581 }
582 if (obj instanceof EthTypeCriterion) {
583 EthTypeCriterion that = (EthTypeCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700584 return Objects.equals(ethType, that.ethType) &&
585 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700586
587
588 }
589 return false;
590 }
alshabib7b795492014-09-16 14:38:39 -0700591 }
592
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800593 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800594 * Implementation of VLAN ID criterion.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800595 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800596 public static final class VlanIdCriterion implements Criterion {
597 private final VlanId vlanId;
alshabib7b795492014-09-16 14:38:39 -0700598
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800599 /**
600 * Constructor.
601 *
602 * @param vlanId the VLAN ID to match
603 */
604 public VlanIdCriterion(VlanId vlanId) {
605 this.vlanId = vlanId;
alshabib7b795492014-09-16 14:38:39 -0700606 }
607
608 @Override
609 public Type type() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800610 return Type.VLAN_VID;
alshabib7b795492014-09-16 14:38:39 -0700611 }
612
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800613 /**
614 * Gets the VLAN ID to match.
615 *
616 * @return the VLAN ID to match
617 */
618 public VlanId vlanId() {
619 return vlanId;
alshabib7b795492014-09-16 14:38:39 -0700620 }
621
alshabib99b8fdc2014-09-25 14:30:22 -0700622 @Override
623 public String toString() {
624 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800625 .add("vlanId", vlanId).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700626 }
alshabib7b795492014-09-16 14:38:39 -0700627
alshabibba5ac482014-10-02 17:15:20 -0700628 @Override
629 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800630 return Objects.hash(type(), vlanId);
alshabibba5ac482014-10-02 17:15:20 -0700631 }
632
633 @Override
634 public boolean equals(Object obj) {
635 if (this == obj) {
636 return true;
637 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800638 if (obj instanceof VlanIdCriterion) {
639 VlanIdCriterion that = (VlanIdCriterion) obj;
640 return Objects.equals(vlanId, that.vlanId) &&
641 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700642 }
643 return false;
644 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800645 }
alshabibba5ac482014-10-02 17:15:20 -0700646
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800647 /**
648 * Implementation of VLAN priority criterion.
649 */
650 public static final class VlanPcpCriterion implements Criterion {
651 private final Byte vlanPcp;
652
653 /**
654 * Constructor.
655 *
656 * @param vlanPcp the VLAN priority to match
657 */
658 public VlanPcpCriterion(Byte vlanPcp) {
659 this.vlanPcp = vlanPcp;
660 }
661
662 @Override
663 public Type type() {
664 return Type.VLAN_PCP;
665 }
666
667 /**
668 * Gets the VLAN priority to match.
669 *
670 * @return the VLAN priority to match
671 */
672 public Byte priority() {
673 return vlanPcp;
674 }
675
676 @Override
677 public String toString() {
678 return toStringHelper(type().toString())
679 .add("priority", Long.toHexString(vlanPcp)).toString();
680 }
681
682 @Override
683 public int hashCode() {
684 return Objects.hash(type(), vlanPcp);
685 }
686
687 @Override
688 public boolean equals(Object obj) {
689 if (this == obj) {
690 return true;
691 }
692 if (obj instanceof VlanPcpCriterion) {
693 VlanPcpCriterion that = (VlanPcpCriterion) obj;
694 return Objects.equals(vlanPcp, that.vlanPcp) &&
695 Objects.equals(this.type(), that.type());
696 }
697 return false;
698 }
alshabib7b795492014-09-16 14:38:39 -0700699 }
700
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800701 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800702 * Implementation of IP DSCP criterion (6-bit Differentiated Services
703 * Code Point).
704 */
705 public static final class IPDscpCriterion implements Criterion {
706 private static final byte DSCP_MASK = 0x3f;
707 private final Byte ipDscp; // IP DSCP value: 6 bits
708
709 /**
710 * Constructor.
711 *
712 * @param ipDscp the IP DSCP value to match
713 */
714 public IPDscpCriterion(Byte ipDscp) {
715 this.ipDscp = (byte) (ipDscp & DSCP_MASK);
716 }
717
718 @Override
719 public Type type() {
720 return Type.IP_DSCP;
721 }
722
723 /**
724 * Gets the IP DSCP value to match.
725 *
726 * @return the IP DSCP value to match
727 */
728 public Byte ipDscp() {
729 return ipDscp;
730 }
731
732 @Override
733 public String toString() {
734 return toStringHelper(type().toString())
735 .add("ipDscp", ipDscp).toString();
736 }
737
738 @Override
739 public int hashCode() {
740 return Objects.hash(type(), ipDscp);
741 }
742
743 @Override
744 public boolean equals(Object obj) {
745 if (this == obj) {
746 return true;
747 }
748 if (obj instanceof IPDscpCriterion) {
749 IPDscpCriterion that = (IPDscpCriterion) obj;
750 return Objects.equals(ipDscp, that.ipDscp) &&
751 Objects.equals(this.type(), that.type());
752 }
753 return false;
754 }
755 }
756
757 /**
758 * Implementation of IP ECN criterion (3-bit Explicit Congestion
759 * Notification).
760 */
761 public static final class IPEcnCriterion implements Criterion {
762 private static final byte ECN_MASK = 0x3;
763 private final Byte ipEcn; // IP ECN value: 3 bits
764
765 /**
766 * Constructor.
767 *
768 * @param ipEcn the IP ECN value to match
769 */
770 public IPEcnCriterion(Byte ipEcn) {
771 this.ipEcn = (byte) (ipEcn & ECN_MASK);
772 }
773
774 @Override
775 public Type type() {
776 return Type.IP_ECN;
777 }
778
779 /**
780 * Gets the IP ECN value to match.
781 *
782 * @return the IP ECN value to match
783 */
784 public Byte ipEcn() {
785 return ipEcn;
786 }
787
788 @Override
789 public String toString() {
790 return toStringHelper(type().toString())
791 .add("ipEcn", ipEcn).toString();
792 }
793
794 @Override
795 public int hashCode() {
796 return Objects.hash(type(), ipEcn);
797 }
798
799 @Override
800 public boolean equals(Object obj) {
801 if (this == obj) {
802 return true;
803 }
804 if (obj instanceof IPEcnCriterion) {
805 IPEcnCriterion that = (IPEcnCriterion) obj;
806 return Objects.equals(ipEcn, that.ipEcn) &&
807 Objects.equals(this.type(), that.type());
808 }
809 return false;
810 }
811 }
812
813 /**
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800814 * Implementation of Internet Protocol Number criterion.
815 */
alshabib7b795492014-09-16 14:38:39 -0700816 public static final class IPProtocolCriterion implements Criterion {
alshabib7b795492014-09-16 14:38:39 -0700817 private final Byte proto;
818
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800819 /**
820 * Constructor.
821 *
822 * @param protocol the IP protocol to match (e.g., TCP=6, UDP=17).
823 */
alshabib7b795492014-09-16 14:38:39 -0700824 public IPProtocolCriterion(Byte protocol) {
825 this.proto = protocol;
826 }
827
828 @Override
829 public Type type() {
830 return Type.IP_PROTO;
831 }
832
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800833 /**
834 * Gets the IP protocol to match.
835 *
836 * @return the IP protocol to match
837 */
alshabib7b795492014-09-16 14:38:39 -0700838 public Byte protocol() {
839 return proto;
840 }
841
alshabib99b8fdc2014-09-25 14:30:22 -0700842 @Override
843 public String toString() {
844 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800845 .add("protocol", Long.toHexString(proto & 0xff))
846 .toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700847 }
848
alshabibba5ac482014-10-02 17:15:20 -0700849 @Override
850 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800851 return Objects.hash(type(), proto);
alshabibba5ac482014-10-02 17:15:20 -0700852 }
853
854 @Override
855 public boolean equals(Object obj) {
856 if (this == obj) {
857 return true;
858 }
859 if (obj instanceof IPProtocolCriterion) {
860 IPProtocolCriterion that = (IPProtocolCriterion) obj;
861 return Objects.equals(proto, that.proto);
alshabibba5ac482014-10-02 17:15:20 -0700862 }
863 return false;
864 }
alshabib7b795492014-09-16 14:38:39 -0700865 }
866
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800867 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800868 * Implementation of IP address criterion.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800869 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800870 public static final class IPCriterion implements Criterion {
871 private final IpPrefix ip;
872 private final Type type;
alshabib7b795492014-09-16 14:38:39 -0700873
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800874 /**
875 * Constructor.
876 *
877 * @param ip the IP prefix to match. Could be either IPv4 or IPv6
878 * @param type the match type. Should be one of the following:
879 * Type.IPV4_SRC, Type.IPV4_DST, Type.IPV6_SRC, Type.IPV6_DST
880 */
881 public IPCriterion(IpPrefix ip, Type type) {
882 this.ip = ip;
883 this.type = type;
alshabib7b795492014-09-16 14:38:39 -0700884 }
885
886 @Override
887 public Type type() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800888 return this.type;
alshabib7b795492014-09-16 14:38:39 -0700889 }
890
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800891 /**
892 * Gets the IP prefix to match.
893 *
894 * @return the IP prefix to match
895 */
896 public IpPrefix ip() {
897 return this.ip;
alshabib7b795492014-09-16 14:38:39 -0700898 }
899
alshabib99b8fdc2014-09-25 14:30:22 -0700900 @Override
901 public String toString() {
902 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800903 .add("ip", ip).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700904 }
905
alshabibba5ac482014-10-02 17:15:20 -0700906 @Override
907 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800908 return Objects.hash(type, ip);
alshabibba5ac482014-10-02 17:15:20 -0700909 }
910
911 @Override
912 public boolean equals(Object obj) {
913 if (this == obj) {
914 return true;
915 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800916 if (obj instanceof IPCriterion) {
917 IPCriterion that = (IPCriterion) obj;
918 return Objects.equals(ip, that.ip) &&
919 Objects.equals(type, that.type);
alshabibba5ac482014-10-02 17:15:20 -0700920 }
921 return false;
922 }
alshabib7b795492014-09-16 14:38:39 -0700923 }
924
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800925 /**
926 * Implementation of TCP port criterion.
927 */
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700928 public static final class TcpPortCriterion implements Criterion {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700929 private final Short tcpPort;
930 private final Type type;
931
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800932 /**
933 * Constructor.
934 *
935 * @param tcpPort the TCP port to match
936 * @param type the match type. Should be either Type.TCP_SRC or
937 * Type.TCP_DST
938 */
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700939 public TcpPortCriterion(Short tcpPort, Type type) {
940 this.tcpPort = tcpPort;
941 this.type = type;
942 }
943
944 @Override
945 public Type type() {
946 return this.type;
947 }
948
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800949 /**
950 * Gets the TCP port to match.
951 *
952 * @return the TCP port to match
953 */
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700954 public Short tcpPort() {
955 return this.tcpPort;
956 }
957
958 @Override
959 public String toString() {
960 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800961 .add("tcpPort", tcpPort & 0xffff).toString();
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700962 }
963
964 @Override
965 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800966 return Objects.hash(type, tcpPort);
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700967 }
968
969 @Override
970 public boolean equals(Object obj) {
971 if (this == obj) {
972 return true;
973 }
974 if (obj instanceof TcpPortCriterion) {
975 TcpPortCriterion that = (TcpPortCriterion) obj;
976 return Objects.equals(tcpPort, that.tcpPort) &&
977 Objects.equals(type, that.type);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800978 }
979 return false;
980 }
981 }
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700982
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800983 /**
984 * Implementation of UDP port criterion.
985 */
986 public static final class UdpPortCriterion implements Criterion {
987 private final Short udpPort;
988 private final Type type;
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700989
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800990 /**
991 * Constructor.
992 *
993 * @param udpPort the UDP port to match
994 * @param type the match type. Should be either Type.UDP_SRC or
995 * Type.UDP_DST
996 */
997 public UdpPortCriterion(Short udpPort, Type type) {
998 this.udpPort = udpPort;
999 this.type = type;
1000 }
1001
1002 @Override
1003 public Type type() {
1004 return this.type;
1005 }
1006
1007 /**
1008 * Gets the UDP port to match.
1009 *
1010 * @return the UDP port to match
1011 */
1012 public Short udpPort() {
1013 return this.udpPort;
1014 }
1015
1016 @Override
1017 public String toString() {
1018 return toStringHelper(type().toString())
1019 .add("udpPort", udpPort & 0xffff).toString();
1020 }
1021
1022 @Override
1023 public int hashCode() {
1024 return Objects.hash(type, udpPort);
1025 }
1026
1027 @Override
1028 public boolean equals(Object obj) {
1029 if (this == obj) {
1030 return true;
1031 }
1032 if (obj instanceof UdpPortCriterion) {
1033 UdpPortCriterion that = (UdpPortCriterion) obj;
1034 return Objects.equals(udpPort, that.udpPort) &&
1035 Objects.equals(type, that.type);
1036 }
1037 return false;
1038 }
1039 }
1040
1041 /**
1042 * Implementation of SCTP port criterion.
1043 */
1044 public static final class SctpPortCriterion implements Criterion {
1045 private final Short sctpPort;
1046 private final Type type;
1047
1048 /**
1049 * Constructor.
1050 *
1051 * @param sctpPort the SCTP port to match
1052 * @param type the match type. Should be either Type.SCTP_SRC or
1053 * Type.SCTP_DST
1054 */
1055 public SctpPortCriterion(Short sctpPort, Type type) {
1056 this.sctpPort = sctpPort;
1057 this.type = type;
1058 }
1059
1060 @Override
1061 public Type type() {
1062 return this.type;
1063 }
1064
1065 /**
1066 * Gets the SCTP port to match.
1067 *
1068 * @return the SCTP port to match
1069 */
1070 public Short sctpPort() {
1071 return this.sctpPort;
1072 }
1073
1074 @Override
1075 public String toString() {
1076 return toStringHelper(type().toString())
1077 .add("sctpPort", sctpPort & 0xffff).toString();
1078 }
1079
1080 @Override
1081 public int hashCode() {
1082 return Objects.hash(type, sctpPort);
1083 }
1084
1085 @Override
1086 public boolean equals(Object obj) {
1087 if (this == obj) {
1088 return true;
1089 }
1090 if (obj instanceof SctpPortCriterion) {
1091 SctpPortCriterion that = (SctpPortCriterion) obj;
1092 return Objects.equals(sctpPort, that.sctpPort) &&
1093 Objects.equals(type, that.type);
1094 }
1095 return false;
1096 }
1097 }
1098
1099 /**
1100 * Implementation of ICMP type criterion.
1101 */
1102 public static final class IcmpTypeCriterion implements Criterion {
1103 private final Byte icmpType;
1104
1105 /**
1106 * Constructor.
1107 *
1108 * @param icmpType the ICMP type to match
1109 */
1110 public IcmpTypeCriterion(Byte icmpType) {
1111 this.icmpType = icmpType;
1112 }
1113
1114 @Override
1115 public Type type() {
1116 return Type.ICMPV4_TYPE;
1117 }
1118
1119 /**
1120 * Gets the ICMP type to match.
1121 *
1122 * @return the ICMP type to match
1123 */
1124 public Byte icmpType() {
1125 return icmpType;
1126 }
1127
1128 @Override
1129 public String toString() {
1130 return toStringHelper(type().toString())
1131 .add("icmpType", icmpType & 0xff).toString();
1132 }
1133
1134 @Override
1135 public int hashCode() {
1136 return Objects.hash(type(), icmpType);
1137 }
1138
1139 @Override
1140 public boolean equals(Object obj) {
1141 if (this == obj) {
1142 return true;
1143 }
1144 if (obj instanceof IcmpTypeCriterion) {
1145 IcmpTypeCriterion that = (IcmpTypeCriterion) obj;
1146 return Objects.equals(icmpType, that.icmpType) &&
1147 Objects.equals(this.type(), that.type());
1148 }
1149 return false;
1150 }
1151 }
1152
1153 /**
1154 * Implementation of ICMP code criterion.
1155 */
1156 public static final class IcmpCodeCriterion implements Criterion {
1157 private final Byte icmpCode;
1158
1159 /**
1160 * Constructor.
1161 *
1162 * @param icmpCode the ICMP code to match
1163 */
1164 public IcmpCodeCriterion(Byte icmpCode) {
1165 this.icmpCode = icmpCode;
1166 }
1167
1168 @Override
1169 public Type type() {
1170 return Type.ICMPV4_CODE;
1171 }
1172
1173 /**
1174 * Gets the ICMP code to match.
1175 *
1176 * @return the ICMP code to match
1177 */
1178 public Byte icmpCode() {
1179 return icmpCode;
1180 }
1181
1182 @Override
1183 public String toString() {
1184 return toStringHelper(type().toString())
1185 .add("icmpCode", icmpCode & 0xff).toString();
1186 }
1187
1188 @Override
1189 public int hashCode() {
1190 return Objects.hash(type(), icmpCode);
1191 }
1192
1193 @Override
1194 public boolean equals(Object obj) {
1195 if (this == obj) {
1196 return true;
1197 }
1198 if (obj instanceof IcmpCodeCriterion) {
1199 IcmpCodeCriterion that = (IcmpCodeCriterion) obj;
1200 return Objects.equals(icmpCode, that.icmpCode) &&
1201 Objects.equals(this.type(), that.type());
1202 }
1203 return false;
1204 }
1205 }
1206
1207 /**
1208 * Implementation of IPv6 Flow Label criterion (RFC 6437).
1209 */
1210 public static final class IPv6FlowLabelCriterion implements Criterion {
1211 private static final int FLOW_LABEL_MASK = 0xfffff;
1212 private final Integer flowLabel; // IPv6 flow label: 20 bits
1213
1214 /**
1215 * Constructor.
1216 *
1217 * @param flowLabel the IPv6 flow label to match
1218 */
1219 public IPv6FlowLabelCriterion(Integer flowLabel) {
1220 this.flowLabel = flowLabel & FLOW_LABEL_MASK;
1221 }
1222
1223 @Override
1224 public Type type() {
1225 return Type.IPV6_FLABEL;
1226 }
1227
1228 /**
1229 * Gets the IPv6 flow label to match.
1230 *
1231 * @return the IPv6 flow label to match
1232 */
1233 public Integer flowLabel() {
1234 return flowLabel;
1235 }
1236
1237 @Override
1238 public String toString() {
1239 return toStringHelper(type().toString())
1240 .add("flowLabel", flowLabel).toString();
1241 }
1242
1243 @Override
1244 public int hashCode() {
1245 return Objects.hash(type(), flowLabel);
1246 }
1247
1248 @Override
1249 public boolean equals(Object obj) {
1250 if (this == obj) {
1251 return true;
1252 }
1253 if (obj instanceof IPv6FlowLabelCriterion) {
1254 IPv6FlowLabelCriterion that = (IPv6FlowLabelCriterion) obj;
1255 return Objects.equals(flowLabel, that.flowLabel) &&
1256 Objects.equals(this.type(), that.type());
Toshio Koide9c44c9a2014-10-09 11:44:36 -07001257 }
1258 return false;
1259 }
1260 }
Marc De Leenheer49087752014-10-23 13:54:09 -07001261
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001262 /**
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001263 * Implementation of ICMPv6 type criterion.
1264 */
1265 public static final class Icmpv6TypeCriterion implements Criterion {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001266 private final Byte icmpv6Type;
1267
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001268 /**
1269 * Constructor.
1270 *
1271 * @param icmpv6Type the ICMPv6 type to match
1272 */
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001273 public Icmpv6TypeCriterion(Byte icmpv6Type) {
1274 this.icmpv6Type = icmpv6Type;
1275 }
1276
1277 @Override
1278 public Type type() {
1279 return Type.ICMPV6_TYPE;
1280 }
1281
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001282 /**
1283 * Gets the ICMPv6 type to match.
1284 *
1285 * @return the ICMPv6 type to match
1286 */
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001287 public Byte icmpv6Type() {
1288 return icmpv6Type;
1289 }
1290
1291 @Override
1292 public String toString() {
1293 return toStringHelper(type().toString())
1294 .add("icmpv6Type", icmpv6Type & 0xff).toString();
1295 }
1296
1297 @Override
1298 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001299 return Objects.hash(type(), icmpv6Type);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001300 }
1301
1302 @Override
1303 public boolean equals(Object obj) {
1304 if (this == obj) {
1305 return true;
1306 }
1307 if (obj instanceof Icmpv6TypeCriterion) {
1308 Icmpv6TypeCriterion that = (Icmpv6TypeCriterion) obj;
1309 return Objects.equals(icmpv6Type, that.icmpv6Type) &&
1310 Objects.equals(this.type(), that.type());
1311 }
1312 return false;
1313 }
1314 }
1315
1316 /**
1317 * Implementation of ICMPv6 code criterion.
1318 */
1319 public static final class Icmpv6CodeCriterion implements Criterion {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001320 private final Byte icmpv6Code;
1321
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001322 /**
1323 * Constructor.
1324 *
1325 * @param icmpv6Code the ICMPv6 code to match
1326 */
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001327 public Icmpv6CodeCriterion(Byte icmpv6Code) {
1328 this.icmpv6Code = icmpv6Code;
1329 }
1330
1331 @Override
1332 public Type type() {
1333 return Type.ICMPV6_CODE;
1334 }
1335
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001336 /**
1337 * Gets the ICMPv6 code to match.
1338 *
1339 * @return the ICMPv6 code to match
1340 */
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001341 public Byte icmpv6Code() {
1342 return icmpv6Code;
1343 }
1344
1345 @Override
1346 public String toString() {
1347 return toStringHelper(type().toString())
1348 .add("icmpv6Code", icmpv6Code & 0xff).toString();
1349 }
1350
1351 @Override
1352 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001353 return Objects.hash(type(), icmpv6Code);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001354 }
1355
1356 @Override
1357 public boolean equals(Object obj) {
1358 if (this == obj) {
1359 return true;
1360 }
1361 if (obj instanceof Icmpv6CodeCriterion) {
1362 Icmpv6CodeCriterion that = (Icmpv6CodeCriterion) obj;
1363 return Objects.equals(icmpv6Code, that.icmpv6Code) &&
1364 Objects.equals(this.type(), that.type());
1365 }
1366 return false;
1367 }
1368 }
1369
1370 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001371 * Implementation of IPv6 Neighbor Discovery target address criterion.
1372 */
1373 public static final class IPv6NDTargetAddressCriterion
1374 implements Criterion {
1375 private final Ip6Address targetAddress;
1376
1377 /**
1378 * Constructor.
1379 *
1380 * @param targetAddress the IPv6 target address to match
1381 */
1382 public IPv6NDTargetAddressCriterion(Ip6Address targetAddress) {
1383 this.targetAddress = targetAddress;
1384 }
1385
1386 @Override
1387 public Type type() {
1388 return Type.IPV6_ND_TARGET;
1389 }
1390
1391 /**
1392 * Gets the IPv6 target address to match.
1393 *
1394 * @return the IPv6 target address to match
1395 */
1396 public Ip6Address targetAddress() {
1397 return this.targetAddress;
1398 }
1399
1400 @Override
1401 public String toString() {
1402 return toStringHelper(type().toString())
1403 .add("targetAddress", targetAddress).toString();
1404 }
1405
1406 @Override
1407 public int hashCode() {
1408 return Objects.hash(type(), targetAddress);
1409 }
1410
1411 @Override
1412 public boolean equals(Object obj) {
1413 if (this == obj) {
1414 return true;
1415 }
1416 if (obj instanceof IPv6NDTargetAddressCriterion) {
1417 IPv6NDTargetAddressCriterion that =
1418 (IPv6NDTargetAddressCriterion) obj;
1419 return Objects.equals(targetAddress, that.targetAddress) &&
1420 Objects.equals(type(), that.type());
1421 }
1422 return false;
1423 }
1424 }
1425
1426 /**
1427 * Implementation of IPv6 Neighbor Discovery link-layer address criterion.
1428 */
1429 public static final class IPv6NDLinkLayerAddressCriterion
1430 implements Criterion {
1431 private final MacAddress mac;
1432 private final Type type;
1433
1434 /**
1435 * Constructor.
1436 *
1437 * @param mac the source or destination link-layer address to match
1438 * @param type the match type. Should be either Type.IPV6_ND_SLL or
1439 * Type.IPV6_ND_TLL
1440 */
1441 public IPv6NDLinkLayerAddressCriterion(MacAddress mac, Type type) {
1442 this.mac = mac;
1443 this.type = type;
1444 }
1445
1446 @Override
1447 public Type type() {
1448 return this.type;
1449 }
1450
1451 /**
1452 * Gets the MAC link-layer address to match.
1453 *
1454 * @return the MAC link-layer address to match
1455 */
1456 public MacAddress mac() {
1457 return this.mac;
1458 }
1459
1460 @Override
1461 public String toString() {
1462 return toStringHelper(type().toString())
1463 .add("mac", mac).toString();
1464 }
1465
1466 @Override
1467 public int hashCode() {
1468 return Objects.hash(type, mac);
1469 }
1470
1471 @Override
1472 public boolean equals(Object obj) {
1473 if (this == obj) {
1474 return true;
1475 }
1476 if (obj instanceof IPv6NDLinkLayerAddressCriterion) {
1477 IPv6NDLinkLayerAddressCriterion that =
1478 (IPv6NDLinkLayerAddressCriterion) obj;
1479 return Objects.equals(mac, that.mac) &&
1480 Objects.equals(type, that.type);
1481 }
1482 return false;
1483 }
1484 }
1485
1486 /**
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001487 * Implementation of MPLS tag criterion.
1488 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001489 public static final class MplsCriterion implements Criterion {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001490 private final Integer mplsLabel;
1491
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001492 /**
1493 * Constructor.
1494 *
1495 * @param mplsLabel the MPLS label to match
1496 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001497 public MplsCriterion(Integer mplsLabel) {
1498 this.mplsLabel = mplsLabel;
1499 }
1500
1501 @Override
1502 public Type type() {
1503 return Type.MPLS_LABEL;
1504 }
1505
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001506 /**
1507 * Gets the MPLS label to match.
1508 *
1509 * @return the MPLS label to match
1510 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001511 public Integer label() {
1512 return mplsLabel;
1513 }
1514
1515 @Override
1516 public String toString() {
1517 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001518 .add("label", mplsLabel & 0xffffffffL).toString();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001519 }
1520
1521 @Override
1522 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001523 return Objects.hash(type(), mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001524 }
1525
1526 @Override
1527 public boolean equals(Object obj) {
1528 if (this == obj) {
1529 return true;
1530 }
1531 if (obj instanceof MplsCriterion) {
1532 MplsCriterion that = (MplsCriterion) obj;
1533 return Objects.equals(mplsLabel, that.mplsLabel) &&
1534 Objects.equals(this.type(), that.type());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001535 }
1536 return false;
1537 }
1538
1539 }
1540
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001541 /**
1542 * Implementation of lambda (wavelength) criterion.
1543 */
Marc De Leenheer49087752014-10-23 13:54:09 -07001544 public static final class LambdaCriterion implements Criterion {
Marc De Leenheer49087752014-10-23 13:54:09 -07001545 private final short lambda;
1546 private final Type type;
1547
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001548 /**
1549 * Constructor.
1550 *
1551 * @param lambda the lambda (wavelength) to match
1552 * @param type the match type. Should be Type.OCH_SIGID
1553 */
Marc De Leenheer49087752014-10-23 13:54:09 -07001554 public LambdaCriterion(short lambda, Type type) {
1555 this.lambda = lambda;
1556 this.type = type;
1557 }
1558
1559 @Override
1560 public Type type() {
1561 return this.type;
1562 }
1563
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001564 /**
1565 * Gets the lambda (wavelength) to match.
1566 *
1567 * @return the lambda (wavelength) to match.
1568 */
Marc De Leenheer49087752014-10-23 13:54:09 -07001569 public Short lambda() {
1570 return this.lambda;
1571 }
1572
1573 @Override
1574 public String toString() {
1575 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +08001576 .add("lambda", lambda & 0xffff).toString();
Marc De Leenheer49087752014-10-23 13:54:09 -07001577 }
1578
1579 @Override
1580 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -08001581 return Objects.hash(type, lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -07001582 }
1583
1584 @Override
1585 public boolean equals(Object obj) {
1586 if (this == obj) {
1587 return true;
1588 }
1589 if (obj instanceof LambdaCriterion) {
1590 LambdaCriterion that = (LambdaCriterion) obj;
1591 return Objects.equals(lambda, that.lambda) &&
1592 Objects.equals(type, that.type);
1593 }
1594 return false;
1595 }
1596 }
1597
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001598 /**
1599 * Implementation of optical signal type criterion.
1600 */
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001601 public static final class OpticalSignalTypeCriterion implements Criterion {
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001602 private final Short signalType;
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001603 private final Type type;
1604
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001605 /**
1606 * Constructor.
1607 *
1608 * @param signalType the optical signal type to match
1609 * @param type the match type. Should be Type.OCH_SIGTYPE
1610 */
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001611 public OpticalSignalTypeCriterion(Short signalType, Type type) {
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001612 this.signalType = signalType;
1613 this.type = type;
1614 }
1615
1616 @Override
1617 public Type type() {
1618 return this.type;
1619 }
1620
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001621 /**
1622 * Gets the optical signal type to match.
1623 *
1624 * @return the optical signal type to match
1625 */
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001626 public Short signalType() {
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001627 return this.signalType;
1628 }
1629
1630 @Override
1631 public String toString() {
1632 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +08001633 .add("signalType", signalType & 0xffff).toString();
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001634 }
1635
1636 @Override
1637 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -08001638 return Objects.hash(type, signalType);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001639 }
1640
1641 @Override
1642 public boolean equals(Object obj) {
1643 if (this == obj) {
1644 return true;
1645 }
1646 if (obj instanceof OpticalSignalTypeCriterion) {
1647 OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj;
1648 return Objects.equals(signalType, that.signalType) &&
1649 Objects.equals(type, that.type);
1650 }
1651 return false;
1652 }
1653 }
tom8bb16062014-09-12 14:47:46 -07001654}