blob: d4ec1246376a144efd65ed71354856b2de9ff88e [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) {
46 return new PortCriterion(port);
47 }
48
49 /**
alshabib369d2942014-09-12 17:59:35 -070050 * Creates a match on ETH_DST field using the specified value. This value
51 * may be a wildcard mask.
52 *
tomc104d282014-09-19 10:57:55 -070053 * @param mac MAC address value or wildcard mask
alshabib369d2942014-09-12 17:59:35 -070054 * @return match criterion
55 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070056 public static Criterion matchEthDst(MacAddress mac) {
alshabib7b795492014-09-16 14:38:39 -070057 return new EthCriterion(mac, Type.ETH_DST);
58 }
59
60 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080061 * Creates a match on ETH_SRC field using the specified value. This value
62 * may be a wildcard mask.
63 *
64 * @param mac MAC address value or wildcard mask
65 * @return match criterion
66 */
67 public static Criterion matchEthSrc(MacAddress mac) {
68 return new EthCriterion(mac, Type.ETH_SRC);
69 }
70
71 /**
alshabib7b795492014-09-16 14:38:39 -070072 * Creates a match on ETH_TYPE field using the specified value.
73 *
74 * @param ethType eth type value
75 * @return match criterion
76 */
77 public static Criterion matchEthType(Short ethType) {
78 return new EthTypeCriterion(ethType);
79 }
80
81 /**
82 * Creates a match on VLAN ID field using the specified value.
83 *
84 * @param vlanId vlan id value
85 * @return match criterion
86 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070087 public static Criterion matchVlanId(VlanId vlanId) {
alshabib7b795492014-09-16 14:38:39 -070088 return new VlanIdCriterion(vlanId);
89 }
90
91 /**
92 * Creates a match on VLAN PCP field using the specified value.
93 *
94 * @param vlanPcp vlan pcp value
95 * @return match criterion
96 */
alshabibb45d1962014-09-18 14:25:45 -070097 public static Criterion matchVlanPcp(Byte vlanPcp) {
alshabib7b795492014-09-16 14:38:39 -070098 return new VlanPcpCriterion(vlanPcp);
99 }
100
101 /**
102 * Creates a match on IP proto field using the specified value.
103 *
104 * @param proto ip protocol value
105 * @return match criterion
106 */
107 public static Criterion matchIPProtocol(Byte proto) {
108 return new IPProtocolCriterion(proto);
109 }
110
111 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800112 * Creates a match on IPv4 source field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700113 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800114 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700115 * @return match criterion
116 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700117 public static Criterion matchIPSrc(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700118 return new IPCriterion(ip, Type.IPV4_SRC);
119 }
120
121 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800122 * Creates a match on IPv4 destination field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700123 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800124 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700125 * @return match criterion
126 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700127 public static Criterion matchIPDst(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700128 return new IPCriterion(ip, Type.IPV4_DST);
alshabib369d2942014-09-12 17:59:35 -0700129 }
130
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700131 /**
132 * Creates a match on TCP source port field using the specified value.
133 *
Yuta HIGUCHI5c947272014-11-03 21:39:21 -0800134 * @param tcpPort TCP source port
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700135 * @return match criterion
136 */
137 public static Criterion matchTcpSrc(Short tcpPort) {
138 return new TcpPortCriterion(tcpPort, Type.TCP_SRC);
139 }
140
141 /**
142 * Creates a match on TCP destination port field using the specified value.
143 *
Yuta HIGUCHI5c947272014-11-03 21:39:21 -0800144 * @param tcpPort TCP destination port
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700145 * @return match criterion
146 */
147 public static Criterion matchTcpDst(Short tcpPort) {
148 return new TcpPortCriterion(tcpPort, Type.TCP_DST);
149 }
alshabib369d2942014-09-12 17:59:35 -0700150
Marc De Leenheer49087752014-10-23 13:54:09 -0700151 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800152 * Creates a match on UDP source port field using the specified value.
153 *
154 * @param udpPort UDP source port
155 * @return match criterion
156 */
157 public static Criterion matchUdpSrc(Short udpPort) {
158 return new UdpPortCriterion(udpPort, Type.UDP_SRC);
159 }
160
161 /**
162 * Creates a match on UDP destination port field using the specified value.
163 *
164 * @param udpPort UDP destination port
165 * @return match criterion
166 */
167 public static Criterion matchUdpDst(Short udpPort) {
168 return new UdpPortCriterion(udpPort, Type.UDP_DST);
169 }
170
171 /**
172 * Creates a match on SCTP source port field using the specified value.
173 *
174 * @param sctpPort SCTP source port
175 * @return match criterion
176 */
177 public static Criterion matchSctpSrc(Short sctpPort) {
178 return new SctpPortCriterion(sctpPort, Type.SCTP_SRC);
179 }
180
181 /**
182 * Creates a match on SCTP destination port field using the specified
183 * value.
184 *
185 * @param sctpPort SCTP destination port
186 * @return match criterion
187 */
188 public static Criterion matchSctpDst(Short sctpPort) {
189 return new SctpPortCriterion(sctpPort, Type.SCTP_DST);
190 }
191
192 /**
193 * Creates a match on ICMP type field using the specified value.
194 *
195 * @param icmpType ICMP type
196 * @return match criterion
197 */
198 public static Criterion matchIcmpType(Byte icmpType) {
199 return new IcmpTypeCriterion(icmpType);
200 }
201
202 /**
203 * Creates a match on ICMP code field using the specified value.
204 *
205 * @param icmpCode ICMP code
206 * @return match criterion
207 */
208 public static Criterion matchIcmpCode(Byte icmpCode) {
209 return new IcmpCodeCriterion(icmpCode);
210 }
211
212 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800213 * Creates a match on IPv6 source field using the specified value.
214 *
215 * @param ip ipv6 source value
216 * @return match criterion
217 */
218 public static Criterion matchIPv6Src(IpPrefix ip) {
219 return new IPCriterion(ip, Type.IPV6_SRC);
220 }
221
222 /**
223 * Creates a match on IPv6 destination field using the specified value.
224 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800225 * @param ip ipv6 destination value
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800226 * @return match criterion
227 */
228 public static Criterion matchIPv6Dst(IpPrefix ip) {
229 return new IPCriterion(ip, Type.IPV6_DST);
230 }
231
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800232 /**
233 * Creates a match on IPv6 flow label field using the specified value.
234 *
235 * @param flowLabel IPv6 flow label
236 * @return match criterion
237 */
238 public static Criterion matchIPv6FlowLabel(Integer flowLabel) {
239 return new IPv6FlowLabelCriterion(flowLabel);
240 }
241
242 /**
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800243 * Creates a match on ICMPv6 type field using the specified value.
244 *
245 * @param icmpv6Type ICMPv6 type
246 * @return match criterion
247 */
248 public static Criterion matchIcmpv6Type(Byte icmpv6Type) {
249 return new Icmpv6TypeCriterion(icmpv6Type);
250 }
251
252 /**
253 * Creates a match on ICMPv6 code field using the specified value.
254 *
255 * @param icmpv6Code ICMPv6 code
256 * @return match criterion
257 */
258 public static Criterion matchIcmpv6Code(Byte icmpv6Code) {
259 return new Icmpv6CodeCriterion(icmpv6Code);
260 }
261
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800262 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800263 * Creates a match on IPv6 Neighbor Discovery target address using the
264 * specified value.
265 *
266 * @param targetAddress IPv6 Neighbor Discovery target address
267 * @return match criterion
268 */
269 public static Criterion matchIPv6NDTargetAddress(Ip6Address targetAddress) {
270 return new IPv6NDTargetAddressCriterion(targetAddress);
271 }
272
273 /**
274 * Creates a match on IPv6 Neighbor Discovery source link-layer address
275 * using the specified value.
276 *
277 * @param mac IPv6 Neighbor Discovery source link-layer address
278 * @return match criterion
279 */
280 public static Criterion matchIPv6NDSourceLinkLayerAddress(MacAddress mac) {
281 return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_SLL);
282 }
283
284 /**
285 * Creates a match on IPv6 Neighbor Discovery target link-layer address
286 * using the specified value.
287 *
288 * @param mac IPv6 Neighbor Discovery target link-layer address
289 * @return match criterion
290 */
291 public static Criterion matchIPv6NDTargetLinkLayerAddress(MacAddress mac) {
292 return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_TLL);
293 }
294
295 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800296 * Creates a match on MPLS label.
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800297 *
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800298 * @param mplsLabel MPLS label
299 * @return match criterion
300 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800301 public static Criterion matchMplsLabel(Integer mplsLabel) {
302 return new MplsCriterion(mplsLabel);
303 }
304
305 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700306 * Creates a match on lambda field using the specified value.
307 *
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800308 * @param lambda lambda to match on
Marc De Leenheer49087752014-10-23 13:54:09 -0700309 * @return match criterion
310 */
311 public static Criterion matchLambda(Short lambda) {
312 return new LambdaCriterion(lambda, Type.OCH_SIGID);
313 }
314
315 /**
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800316 * Creates a match on optical signal type using the specified value.
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700317 *
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800318 * @param sigType optical signal type
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700319 * @return match criterion
320 */
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800321 public static Criterion matchOpticalSignalType(Short sigType) {
322 return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700323 }
324
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700325 /**
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800326 * Implementation of input port criterion.
alshabib7b795492014-09-16 14:38:39 -0700327 */
alshabib7b795492014-09-16 14:38:39 -0700328 public static final class PortCriterion implements Criterion {
329 private final PortNumber port;
330
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800331 /**
332 * Constructor.
333 *
334 * @param port the input port number to match
335 */
alshabib7b795492014-09-16 14:38:39 -0700336 public PortCriterion(PortNumber port) {
337 this.port = port;
338 }
339
340 @Override
341 public Type type() {
342 return Type.IN_PORT;
343 }
344
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800345 /**
346 * Gets the input port number to match.
347 *
348 * @return the input port number to match
349 */
alshabib7b795492014-09-16 14:38:39 -0700350 public PortNumber port() {
351 return this.port;
352 }
alshabib99b8fdc2014-09-25 14:30:22 -0700353
354 @Override
355 public String toString() {
356 return toStringHelper(type().toString())
357 .add("port", port).toString();
358 }
alshabibba5ac482014-10-02 17:15:20 -0700359
360 @Override
361 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800362 return Objects.hash(type(), port);
alshabibba5ac482014-10-02 17:15:20 -0700363 }
364
365 @Override
366 public boolean equals(Object obj) {
367 if (this == obj) {
368 return true;
369 }
370 if (obj instanceof PortCriterion) {
371 PortCriterion that = (PortCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700372 return Objects.equals(port, that.port) &&
373 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700374
375 }
376 return false;
377 }
alshabib7b795492014-09-16 14:38:39 -0700378 }
379
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800380 /**
381 * Implementation of MAC address criterion.
382 */
alshabib7b795492014-09-16 14:38:39 -0700383 public static final class EthCriterion implements Criterion {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700384 private final MacAddress mac;
alshabib7b795492014-09-16 14:38:39 -0700385 private final Type type;
386
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800387 /**
388 * Constructor.
389 *
390 * @param mac the source or destination MAC address to match
391 * @param type the match type. Should be either Type.ETH_DST or
392 * Type.ETH_SRC
393 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700394 public EthCriterion(MacAddress mac, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700395 this.mac = mac;
396 this.type = type;
397 }
398
399 @Override
400 public Type type() {
401 return this.type;
402 }
403
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800404 /**
405 * Gets the MAC address to match.
406 *
407 * @return the MAC address to match
408 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700409 public MacAddress mac() {
alshabib7b795492014-09-16 14:38:39 -0700410 return this.mac;
411 }
alshabib99b8fdc2014-09-25 14:30:22 -0700412
413 @Override
414 public String toString() {
415 return toStringHelper(type().toString())
416 .add("mac", mac).toString();
417 }
418
alshabibba5ac482014-10-02 17:15:20 -0700419 @Override
420 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800421 return Objects.hash(type, mac);
alshabibba5ac482014-10-02 17:15:20 -0700422 }
423
424 @Override
425 public boolean equals(Object obj) {
426 if (this == obj) {
427 return true;
428 }
429 if (obj instanceof EthCriterion) {
430 EthCriterion that = (EthCriterion) obj;
431 return Objects.equals(mac, that.mac) &&
432 Objects.equals(type, that.type);
alshabibba5ac482014-10-02 17:15:20 -0700433 }
434 return false;
435 }
alshabib7b795492014-09-16 14:38:39 -0700436 }
437
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800438 /**
439 * Implementation of Ethernet type criterion.
440 */
alshabib7b795492014-09-16 14:38:39 -0700441 public static final class EthTypeCriterion implements Criterion {
alshabib7b795492014-09-16 14:38:39 -0700442 private final Short ethType;
443
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800444 /**
445 * Constructor.
446 *
447 * @param ethType the Ethernet frame type to match
448 */
alshabib7b795492014-09-16 14:38:39 -0700449 public EthTypeCriterion(Short ethType) {
450 this.ethType = ethType;
451 }
452
453 @Override
454 public Type type() {
455 return Type.ETH_TYPE;
456 }
457
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800458 /**
459 * Gets the Ethernet frame type to match.
460 *
461 * @return the Ethernet frame type to match
462 */
alshabib7b795492014-09-16 14:38:39 -0700463 public Short ethType() {
464 return ethType;
465 }
466
alshabib99b8fdc2014-09-25 14:30:22 -0700467 @Override
468 public String toString() {
469 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800470 .add("ethType", Long.toHexString(ethType & 0xffff))
471 .toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700472 }
473
alshabibba5ac482014-10-02 17:15:20 -0700474 @Override
475 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800476 return Objects.hash(type(), ethType);
alshabibba5ac482014-10-02 17:15:20 -0700477 }
478
479 @Override
480 public boolean equals(Object obj) {
481 if (this == obj) {
482 return true;
483 }
484 if (obj instanceof EthTypeCriterion) {
485 EthTypeCriterion that = (EthTypeCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700486 return Objects.equals(ethType, that.ethType) &&
487 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700488
489
490 }
491 return false;
492 }
alshabib7b795492014-09-16 14:38:39 -0700493 }
494
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800495 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800496 * Implementation of VLAN ID criterion.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800497 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800498 public static final class VlanIdCriterion implements Criterion {
499 private final VlanId vlanId;
alshabib7b795492014-09-16 14:38:39 -0700500
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800501 /**
502 * Constructor.
503 *
504 * @param vlanId the VLAN ID to match
505 */
506 public VlanIdCriterion(VlanId vlanId) {
507 this.vlanId = vlanId;
alshabib7b795492014-09-16 14:38:39 -0700508 }
509
510 @Override
511 public Type type() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800512 return Type.VLAN_VID;
alshabib7b795492014-09-16 14:38:39 -0700513 }
514
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800515 /**
516 * Gets the VLAN ID to match.
517 *
518 * @return the VLAN ID to match
519 */
520 public VlanId vlanId() {
521 return vlanId;
alshabib7b795492014-09-16 14:38:39 -0700522 }
523
alshabib99b8fdc2014-09-25 14:30:22 -0700524 @Override
525 public String toString() {
526 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800527 .add("vlanId", vlanId).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700528 }
alshabib7b795492014-09-16 14:38:39 -0700529
alshabibba5ac482014-10-02 17:15:20 -0700530 @Override
531 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800532 return Objects.hash(type(), vlanId);
alshabibba5ac482014-10-02 17:15:20 -0700533 }
534
535 @Override
536 public boolean equals(Object obj) {
537 if (this == obj) {
538 return true;
539 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800540 if (obj instanceof VlanIdCriterion) {
541 VlanIdCriterion that = (VlanIdCriterion) obj;
542 return Objects.equals(vlanId, that.vlanId) &&
543 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700544 }
545 return false;
546 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800547 }
alshabibba5ac482014-10-02 17:15:20 -0700548
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800549 /**
550 * Implementation of VLAN priority criterion.
551 */
552 public static final class VlanPcpCriterion implements Criterion {
553 private final Byte vlanPcp;
554
555 /**
556 * Constructor.
557 *
558 * @param vlanPcp the VLAN priority to match
559 */
560 public VlanPcpCriterion(Byte vlanPcp) {
561 this.vlanPcp = vlanPcp;
562 }
563
564 @Override
565 public Type type() {
566 return Type.VLAN_PCP;
567 }
568
569 /**
570 * Gets the VLAN priority to match.
571 *
572 * @return the VLAN priority to match
573 */
574 public Byte priority() {
575 return vlanPcp;
576 }
577
578 @Override
579 public String toString() {
580 return toStringHelper(type().toString())
581 .add("priority", Long.toHexString(vlanPcp)).toString();
582 }
583
584 @Override
585 public int hashCode() {
586 return Objects.hash(type(), vlanPcp);
587 }
588
589 @Override
590 public boolean equals(Object obj) {
591 if (this == obj) {
592 return true;
593 }
594 if (obj instanceof VlanPcpCriterion) {
595 VlanPcpCriterion that = (VlanPcpCriterion) obj;
596 return Objects.equals(vlanPcp, that.vlanPcp) &&
597 Objects.equals(this.type(), that.type());
598 }
599 return false;
600 }
alshabib7b795492014-09-16 14:38:39 -0700601 }
602
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800603 /**
604 * Implementation of Internet Protocol Number criterion.
605 */
alshabib7b795492014-09-16 14:38:39 -0700606 public static final class IPProtocolCriterion implements Criterion {
alshabib7b795492014-09-16 14:38:39 -0700607 private final Byte proto;
608
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800609 /**
610 * Constructor.
611 *
612 * @param protocol the IP protocol to match (e.g., TCP=6, UDP=17).
613 */
alshabib7b795492014-09-16 14:38:39 -0700614 public IPProtocolCriterion(Byte protocol) {
615 this.proto = protocol;
616 }
617
618 @Override
619 public Type type() {
620 return Type.IP_PROTO;
621 }
622
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800623 /**
624 * Gets the IP protocol to match.
625 *
626 * @return the IP protocol to match
627 */
alshabib7b795492014-09-16 14:38:39 -0700628 public Byte protocol() {
629 return proto;
630 }
631
alshabib99b8fdc2014-09-25 14:30:22 -0700632 @Override
633 public String toString() {
634 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800635 .add("protocol", Long.toHexString(proto & 0xff))
636 .toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700637 }
638
alshabibba5ac482014-10-02 17:15:20 -0700639 @Override
640 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800641 return Objects.hash(type(), proto);
alshabibba5ac482014-10-02 17:15:20 -0700642 }
643
644 @Override
645 public boolean equals(Object obj) {
646 if (this == obj) {
647 return true;
648 }
649 if (obj instanceof IPProtocolCriterion) {
650 IPProtocolCriterion that = (IPProtocolCriterion) obj;
651 return Objects.equals(proto, that.proto);
alshabibba5ac482014-10-02 17:15:20 -0700652 }
653 return false;
654 }
alshabib7b795492014-09-16 14:38:39 -0700655 }
656
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800657 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800658 * Implementation of IP address criterion.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800659 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800660 public static final class IPCriterion implements Criterion {
661 private final IpPrefix ip;
662 private final Type type;
alshabib7b795492014-09-16 14:38:39 -0700663
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800664 /**
665 * Constructor.
666 *
667 * @param ip the IP prefix to match. Could be either IPv4 or IPv6
668 * @param type the match type. Should be one of the following:
669 * Type.IPV4_SRC, Type.IPV4_DST, Type.IPV6_SRC, Type.IPV6_DST
670 */
671 public IPCriterion(IpPrefix ip, Type type) {
672 this.ip = ip;
673 this.type = type;
alshabib7b795492014-09-16 14:38:39 -0700674 }
675
676 @Override
677 public Type type() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800678 return this.type;
alshabib7b795492014-09-16 14:38:39 -0700679 }
680
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800681 /**
682 * Gets the IP prefix to match.
683 *
684 * @return the IP prefix to match
685 */
686 public IpPrefix ip() {
687 return this.ip;
alshabib7b795492014-09-16 14:38:39 -0700688 }
689
alshabib99b8fdc2014-09-25 14:30:22 -0700690 @Override
691 public String toString() {
692 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800693 .add("ip", ip).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700694 }
695
alshabibba5ac482014-10-02 17:15:20 -0700696 @Override
697 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800698 return Objects.hash(type, ip);
alshabibba5ac482014-10-02 17:15:20 -0700699 }
700
701 @Override
702 public boolean equals(Object obj) {
703 if (this == obj) {
704 return true;
705 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800706 if (obj instanceof IPCriterion) {
707 IPCriterion that = (IPCriterion) obj;
708 return Objects.equals(ip, that.ip) &&
709 Objects.equals(type, that.type);
alshabibba5ac482014-10-02 17:15:20 -0700710 }
711 return false;
712 }
alshabib7b795492014-09-16 14:38:39 -0700713 }
714
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800715 /**
716 * Implementation of TCP port criterion.
717 */
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700718 public static final class TcpPortCriterion implements Criterion {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700719 private final Short tcpPort;
720 private final Type type;
721
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800722 /**
723 * Constructor.
724 *
725 * @param tcpPort the TCP port to match
726 * @param type the match type. Should be either Type.TCP_SRC or
727 * Type.TCP_DST
728 */
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700729 public TcpPortCriterion(Short tcpPort, Type type) {
730 this.tcpPort = tcpPort;
731 this.type = type;
732 }
733
734 @Override
735 public Type type() {
736 return this.type;
737 }
738
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800739 /**
740 * Gets the TCP port to match.
741 *
742 * @return the TCP port to match
743 */
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700744 public Short tcpPort() {
745 return this.tcpPort;
746 }
747
748 @Override
749 public String toString() {
750 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800751 .add("tcpPort", tcpPort & 0xffff).toString();
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700752 }
753
754 @Override
755 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800756 return Objects.hash(type, tcpPort);
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700757 }
758
759 @Override
760 public boolean equals(Object obj) {
761 if (this == obj) {
762 return true;
763 }
764 if (obj instanceof TcpPortCriterion) {
765 TcpPortCriterion that = (TcpPortCriterion) obj;
766 return Objects.equals(tcpPort, that.tcpPort) &&
767 Objects.equals(type, that.type);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800768 }
769 return false;
770 }
771 }
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700772
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800773 /**
774 * Implementation of UDP port criterion.
775 */
776 public static final class UdpPortCriterion implements Criterion {
777 private final Short udpPort;
778 private final Type type;
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700779
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800780 /**
781 * Constructor.
782 *
783 * @param udpPort the UDP port to match
784 * @param type the match type. Should be either Type.UDP_SRC or
785 * Type.UDP_DST
786 */
787 public UdpPortCriterion(Short udpPort, Type type) {
788 this.udpPort = udpPort;
789 this.type = type;
790 }
791
792 @Override
793 public Type type() {
794 return this.type;
795 }
796
797 /**
798 * Gets the UDP port to match.
799 *
800 * @return the UDP port to match
801 */
802 public Short udpPort() {
803 return this.udpPort;
804 }
805
806 @Override
807 public String toString() {
808 return toStringHelper(type().toString())
809 .add("udpPort", udpPort & 0xffff).toString();
810 }
811
812 @Override
813 public int hashCode() {
814 return Objects.hash(type, udpPort);
815 }
816
817 @Override
818 public boolean equals(Object obj) {
819 if (this == obj) {
820 return true;
821 }
822 if (obj instanceof UdpPortCriterion) {
823 UdpPortCriterion that = (UdpPortCriterion) obj;
824 return Objects.equals(udpPort, that.udpPort) &&
825 Objects.equals(type, that.type);
826 }
827 return false;
828 }
829 }
830
831 /**
832 * Implementation of SCTP port criterion.
833 */
834 public static final class SctpPortCriterion implements Criterion {
835 private final Short sctpPort;
836 private final Type type;
837
838 /**
839 * Constructor.
840 *
841 * @param sctpPort the SCTP port to match
842 * @param type the match type. Should be either Type.SCTP_SRC or
843 * Type.SCTP_DST
844 */
845 public SctpPortCriterion(Short sctpPort, Type type) {
846 this.sctpPort = sctpPort;
847 this.type = type;
848 }
849
850 @Override
851 public Type type() {
852 return this.type;
853 }
854
855 /**
856 * Gets the SCTP port to match.
857 *
858 * @return the SCTP port to match
859 */
860 public Short sctpPort() {
861 return this.sctpPort;
862 }
863
864 @Override
865 public String toString() {
866 return toStringHelper(type().toString())
867 .add("sctpPort", sctpPort & 0xffff).toString();
868 }
869
870 @Override
871 public int hashCode() {
872 return Objects.hash(type, sctpPort);
873 }
874
875 @Override
876 public boolean equals(Object obj) {
877 if (this == obj) {
878 return true;
879 }
880 if (obj instanceof SctpPortCriterion) {
881 SctpPortCriterion that = (SctpPortCriterion) obj;
882 return Objects.equals(sctpPort, that.sctpPort) &&
883 Objects.equals(type, that.type);
884 }
885 return false;
886 }
887 }
888
889 /**
890 * Implementation of ICMP type criterion.
891 */
892 public static final class IcmpTypeCriterion implements Criterion {
893 private final Byte icmpType;
894
895 /**
896 * Constructor.
897 *
898 * @param icmpType the ICMP type to match
899 */
900 public IcmpTypeCriterion(Byte icmpType) {
901 this.icmpType = icmpType;
902 }
903
904 @Override
905 public Type type() {
906 return Type.ICMPV4_TYPE;
907 }
908
909 /**
910 * Gets the ICMP type to match.
911 *
912 * @return the ICMP type to match
913 */
914 public Byte icmpType() {
915 return icmpType;
916 }
917
918 @Override
919 public String toString() {
920 return toStringHelper(type().toString())
921 .add("icmpType", icmpType & 0xff).toString();
922 }
923
924 @Override
925 public int hashCode() {
926 return Objects.hash(type(), icmpType);
927 }
928
929 @Override
930 public boolean equals(Object obj) {
931 if (this == obj) {
932 return true;
933 }
934 if (obj instanceof IcmpTypeCriterion) {
935 IcmpTypeCriterion that = (IcmpTypeCriterion) obj;
936 return Objects.equals(icmpType, that.icmpType) &&
937 Objects.equals(this.type(), that.type());
938 }
939 return false;
940 }
941 }
942
943 /**
944 * Implementation of ICMP code criterion.
945 */
946 public static final class IcmpCodeCriterion implements Criterion {
947 private final Byte icmpCode;
948
949 /**
950 * Constructor.
951 *
952 * @param icmpCode the ICMP code to match
953 */
954 public IcmpCodeCriterion(Byte icmpCode) {
955 this.icmpCode = icmpCode;
956 }
957
958 @Override
959 public Type type() {
960 return Type.ICMPV4_CODE;
961 }
962
963 /**
964 * Gets the ICMP code to match.
965 *
966 * @return the ICMP code to match
967 */
968 public Byte icmpCode() {
969 return icmpCode;
970 }
971
972 @Override
973 public String toString() {
974 return toStringHelper(type().toString())
975 .add("icmpCode", icmpCode & 0xff).toString();
976 }
977
978 @Override
979 public int hashCode() {
980 return Objects.hash(type(), icmpCode);
981 }
982
983 @Override
984 public boolean equals(Object obj) {
985 if (this == obj) {
986 return true;
987 }
988 if (obj instanceof IcmpCodeCriterion) {
989 IcmpCodeCriterion that = (IcmpCodeCriterion) obj;
990 return Objects.equals(icmpCode, that.icmpCode) &&
991 Objects.equals(this.type(), that.type());
992 }
993 return false;
994 }
995 }
996
997 /**
998 * Implementation of IPv6 Flow Label criterion (RFC 6437).
999 */
1000 public static final class IPv6FlowLabelCriterion implements Criterion {
1001 private static final int FLOW_LABEL_MASK = 0xfffff;
1002 private final Integer flowLabel; // IPv6 flow label: 20 bits
1003
1004 /**
1005 * Constructor.
1006 *
1007 * @param flowLabel the IPv6 flow label to match
1008 */
1009 public IPv6FlowLabelCriterion(Integer flowLabel) {
1010 this.flowLabel = flowLabel & FLOW_LABEL_MASK;
1011 }
1012
1013 @Override
1014 public Type type() {
1015 return Type.IPV6_FLABEL;
1016 }
1017
1018 /**
1019 * Gets the IPv6 flow label to match.
1020 *
1021 * @return the IPv6 flow label to match
1022 */
1023 public Integer flowLabel() {
1024 return flowLabel;
1025 }
1026
1027 @Override
1028 public String toString() {
1029 return toStringHelper(type().toString())
1030 .add("flowLabel", flowLabel).toString();
1031 }
1032
1033 @Override
1034 public int hashCode() {
1035 return Objects.hash(type(), flowLabel);
1036 }
1037
1038 @Override
1039 public boolean equals(Object obj) {
1040 if (this == obj) {
1041 return true;
1042 }
1043 if (obj instanceof IPv6FlowLabelCriterion) {
1044 IPv6FlowLabelCriterion that = (IPv6FlowLabelCriterion) obj;
1045 return Objects.equals(flowLabel, that.flowLabel) &&
1046 Objects.equals(this.type(), that.type());
Toshio Koide9c44c9a2014-10-09 11:44:36 -07001047 }
1048 return false;
1049 }
1050 }
Marc De Leenheer49087752014-10-23 13:54:09 -07001051
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001052 /**
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001053 * Implementation of ICMPv6 type criterion.
1054 */
1055 public static final class Icmpv6TypeCriterion implements Criterion {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001056 private final Byte icmpv6Type;
1057
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001058 /**
1059 * Constructor.
1060 *
1061 * @param icmpv6Type the ICMPv6 type to match
1062 */
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001063 public Icmpv6TypeCriterion(Byte icmpv6Type) {
1064 this.icmpv6Type = icmpv6Type;
1065 }
1066
1067 @Override
1068 public Type type() {
1069 return Type.ICMPV6_TYPE;
1070 }
1071
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001072 /**
1073 * Gets the ICMPv6 type to match.
1074 *
1075 * @return the ICMPv6 type to match
1076 */
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001077 public Byte icmpv6Type() {
1078 return icmpv6Type;
1079 }
1080
1081 @Override
1082 public String toString() {
1083 return toStringHelper(type().toString())
1084 .add("icmpv6Type", icmpv6Type & 0xff).toString();
1085 }
1086
1087 @Override
1088 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001089 return Objects.hash(type(), icmpv6Type);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001090 }
1091
1092 @Override
1093 public boolean equals(Object obj) {
1094 if (this == obj) {
1095 return true;
1096 }
1097 if (obj instanceof Icmpv6TypeCriterion) {
1098 Icmpv6TypeCriterion that = (Icmpv6TypeCriterion) obj;
1099 return Objects.equals(icmpv6Type, that.icmpv6Type) &&
1100 Objects.equals(this.type(), that.type());
1101 }
1102 return false;
1103 }
1104 }
1105
1106 /**
1107 * Implementation of ICMPv6 code criterion.
1108 */
1109 public static final class Icmpv6CodeCriterion implements Criterion {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001110 private final Byte icmpv6Code;
1111
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001112 /**
1113 * Constructor.
1114 *
1115 * @param icmpv6Code the ICMPv6 code to match
1116 */
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001117 public Icmpv6CodeCriterion(Byte icmpv6Code) {
1118 this.icmpv6Code = icmpv6Code;
1119 }
1120
1121 @Override
1122 public Type type() {
1123 return Type.ICMPV6_CODE;
1124 }
1125
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001126 /**
1127 * Gets the ICMPv6 code to match.
1128 *
1129 * @return the ICMPv6 code to match
1130 */
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001131 public Byte icmpv6Code() {
1132 return icmpv6Code;
1133 }
1134
1135 @Override
1136 public String toString() {
1137 return toStringHelper(type().toString())
1138 .add("icmpv6Code", icmpv6Code & 0xff).toString();
1139 }
1140
1141 @Override
1142 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001143 return Objects.hash(type(), icmpv6Code);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001144 }
1145
1146 @Override
1147 public boolean equals(Object obj) {
1148 if (this == obj) {
1149 return true;
1150 }
1151 if (obj instanceof Icmpv6CodeCriterion) {
1152 Icmpv6CodeCriterion that = (Icmpv6CodeCriterion) obj;
1153 return Objects.equals(icmpv6Code, that.icmpv6Code) &&
1154 Objects.equals(this.type(), that.type());
1155 }
1156 return false;
1157 }
1158 }
1159
1160 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001161 * Implementation of IPv6 Neighbor Discovery target address criterion.
1162 */
1163 public static final class IPv6NDTargetAddressCriterion
1164 implements Criterion {
1165 private final Ip6Address targetAddress;
1166
1167 /**
1168 * Constructor.
1169 *
1170 * @param targetAddress the IPv6 target address to match
1171 */
1172 public IPv6NDTargetAddressCriterion(Ip6Address targetAddress) {
1173 this.targetAddress = targetAddress;
1174 }
1175
1176 @Override
1177 public Type type() {
1178 return Type.IPV6_ND_TARGET;
1179 }
1180
1181 /**
1182 * Gets the IPv6 target address to match.
1183 *
1184 * @return the IPv6 target address to match
1185 */
1186 public Ip6Address targetAddress() {
1187 return this.targetAddress;
1188 }
1189
1190 @Override
1191 public String toString() {
1192 return toStringHelper(type().toString())
1193 .add("targetAddress", targetAddress).toString();
1194 }
1195
1196 @Override
1197 public int hashCode() {
1198 return Objects.hash(type(), targetAddress);
1199 }
1200
1201 @Override
1202 public boolean equals(Object obj) {
1203 if (this == obj) {
1204 return true;
1205 }
1206 if (obj instanceof IPv6NDTargetAddressCriterion) {
1207 IPv6NDTargetAddressCriterion that =
1208 (IPv6NDTargetAddressCriterion) obj;
1209 return Objects.equals(targetAddress, that.targetAddress) &&
1210 Objects.equals(type(), that.type());
1211 }
1212 return false;
1213 }
1214 }
1215
1216 /**
1217 * Implementation of IPv6 Neighbor Discovery link-layer address criterion.
1218 */
1219 public static final class IPv6NDLinkLayerAddressCriterion
1220 implements Criterion {
1221 private final MacAddress mac;
1222 private final Type type;
1223
1224 /**
1225 * Constructor.
1226 *
1227 * @param mac the source or destination link-layer address to match
1228 * @param type the match type. Should be either Type.IPV6_ND_SLL or
1229 * Type.IPV6_ND_TLL
1230 */
1231 public IPv6NDLinkLayerAddressCriterion(MacAddress mac, Type type) {
1232 this.mac = mac;
1233 this.type = type;
1234 }
1235
1236 @Override
1237 public Type type() {
1238 return this.type;
1239 }
1240
1241 /**
1242 * Gets the MAC link-layer address to match.
1243 *
1244 * @return the MAC link-layer address to match
1245 */
1246 public MacAddress mac() {
1247 return this.mac;
1248 }
1249
1250 @Override
1251 public String toString() {
1252 return toStringHelper(type().toString())
1253 .add("mac", mac).toString();
1254 }
1255
1256 @Override
1257 public int hashCode() {
1258 return Objects.hash(type, mac);
1259 }
1260
1261 @Override
1262 public boolean equals(Object obj) {
1263 if (this == obj) {
1264 return true;
1265 }
1266 if (obj instanceof IPv6NDLinkLayerAddressCriterion) {
1267 IPv6NDLinkLayerAddressCriterion that =
1268 (IPv6NDLinkLayerAddressCriterion) obj;
1269 return Objects.equals(mac, that.mac) &&
1270 Objects.equals(type, that.type);
1271 }
1272 return false;
1273 }
1274 }
1275
1276 /**
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001277 * Implementation of MPLS tag criterion.
1278 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001279 public static final class MplsCriterion implements Criterion {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001280 private final Integer mplsLabel;
1281
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001282 /**
1283 * Constructor.
1284 *
1285 * @param mplsLabel the MPLS label to match
1286 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001287 public MplsCriterion(Integer mplsLabel) {
1288 this.mplsLabel = mplsLabel;
1289 }
1290
1291 @Override
1292 public Type type() {
1293 return Type.MPLS_LABEL;
1294 }
1295
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001296 /**
1297 * Gets the MPLS label to match.
1298 *
1299 * @return the MPLS label to match
1300 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001301 public Integer label() {
1302 return mplsLabel;
1303 }
1304
1305 @Override
1306 public String toString() {
1307 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001308 .add("label", mplsLabel & 0xffffffffL).toString();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001309 }
1310
1311 @Override
1312 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001313 return Objects.hash(type(), mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001314 }
1315
1316 @Override
1317 public boolean equals(Object obj) {
1318 if (this == obj) {
1319 return true;
1320 }
1321 if (obj instanceof MplsCriterion) {
1322 MplsCriterion that = (MplsCriterion) obj;
1323 return Objects.equals(mplsLabel, that.mplsLabel) &&
1324 Objects.equals(this.type(), that.type());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001325 }
1326 return false;
1327 }
1328
1329 }
1330
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001331 /**
1332 * Implementation of lambda (wavelength) criterion.
1333 */
Marc De Leenheer49087752014-10-23 13:54:09 -07001334 public static final class LambdaCriterion implements Criterion {
Marc De Leenheer49087752014-10-23 13:54:09 -07001335 private final short lambda;
1336 private final Type type;
1337
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001338 /**
1339 * Constructor.
1340 *
1341 * @param lambda the lambda (wavelength) to match
1342 * @param type the match type. Should be Type.OCH_SIGID
1343 */
Marc De Leenheer49087752014-10-23 13:54:09 -07001344 public LambdaCriterion(short lambda, Type type) {
1345 this.lambda = lambda;
1346 this.type = type;
1347 }
1348
1349 @Override
1350 public Type type() {
1351 return this.type;
1352 }
1353
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001354 /**
1355 * Gets the lambda (wavelength) to match.
1356 *
1357 * @return the lambda (wavelength) to match.
1358 */
Marc De Leenheer49087752014-10-23 13:54:09 -07001359 public Short lambda() {
1360 return this.lambda;
1361 }
1362
1363 @Override
1364 public String toString() {
1365 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +08001366 .add("lambda", lambda & 0xffff).toString();
Marc De Leenheer49087752014-10-23 13:54:09 -07001367 }
1368
1369 @Override
1370 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -08001371 return Objects.hash(type, lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -07001372 }
1373
1374 @Override
1375 public boolean equals(Object obj) {
1376 if (this == obj) {
1377 return true;
1378 }
1379 if (obj instanceof LambdaCriterion) {
1380 LambdaCriterion that = (LambdaCriterion) obj;
1381 return Objects.equals(lambda, that.lambda) &&
1382 Objects.equals(type, that.type);
1383 }
1384 return false;
1385 }
1386 }
1387
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001388 /**
1389 * Implementation of optical signal type criterion.
1390 */
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001391 public static final class OpticalSignalTypeCriterion implements Criterion {
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001392 private final Short signalType;
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001393 private final Type type;
1394
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001395 /**
1396 * Constructor.
1397 *
1398 * @param signalType the optical signal type to match
1399 * @param type the match type. Should be Type.OCH_SIGTYPE
1400 */
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001401 public OpticalSignalTypeCriterion(Short signalType, Type type) {
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001402 this.signalType = signalType;
1403 this.type = type;
1404 }
1405
1406 @Override
1407 public Type type() {
1408 return this.type;
1409 }
1410
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001411 /**
1412 * Gets the optical signal type to match.
1413 *
1414 * @return the optical signal type to match
1415 */
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -08001416 public Short signalType() {
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001417 return this.signalType;
1418 }
1419
1420 @Override
1421 public String toString() {
1422 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +08001423 .add("signalType", signalType & 0xffff).toString();
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001424 }
1425
1426 @Override
1427 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -08001428 return Objects.hash(type, signalType);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001429 }
1430
1431 @Override
1432 public boolean equals(Object obj) {
1433 if (this == obj) {
1434 return true;
1435 }
1436 if (obj instanceof OpticalSignalTypeCriterion) {
1437 OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj;
1438 return Objects.equals(signalType, that.signalType) &&
1439 Objects.equals(type, that.type);
1440 }
1441 return false;
1442 }
1443 }
tom8bb16062014-09-12 14:47:46 -07001444}