blob: 5ef50c4992892c2b066c4029f2c7b3473acd3c7e [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;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070024import org.onlab.packet.MacAddress;
25import org.onlab.packet.VlanId;
alshabib7b795492014-09-16 14:38:39 -070026
tom8bb16062014-09-12 14:47:46 -070027/**
28 * Factory class to create various traffic selection criteria.
29 */
30public final class Criteria {
31
alshabib7b795492014-09-16 14:38:39 -070032 //TODO: incomplete type implementation. Need to implement complete list from Criterion
33
tom8bb16062014-09-12 14:47:46 -070034 // Ban construction
35 private Criteria() {
36 }
37
38 /**
alshabib7b795492014-09-16 14:38:39 -070039 * Creates a match on IN_PORT field using the specified value.
40 *
41 * @param port inport value
42 * @return match criterion
43 */
44 public static Criterion matchInPort(PortNumber port) {
45 return new PortCriterion(port);
46 }
47
48 /**
tom8bb16062014-09-12 14:47:46 -070049 * Creates a match on ETH_SRC field using the specified value. This value
50 * may be a wildcard mask.
51 *
tomc104d282014-09-19 10:57:55 -070052 * @param mac MAC address value or wildcard mask
tom8bb16062014-09-12 14:47:46 -070053 * @return match criterion
54 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070055 public static Criterion matchEthSrc(MacAddress mac) {
alshabib7b795492014-09-16 14:38:39 -070056 return new EthCriterion(mac, Type.ETH_SRC);
tom8bb16062014-09-12 14:47:46 -070057 }
58
alshabib369d2942014-09-12 17:59:35 -070059 /**
60 * Creates a match on ETH_DST field using the specified value. This value
61 * may be a wildcard mask.
62 *
tomc104d282014-09-19 10:57:55 -070063 * @param mac MAC address value or wildcard mask
alshabib369d2942014-09-12 17:59:35 -070064 * @return match criterion
65 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070066 public static Criterion matchEthDst(MacAddress mac) {
alshabib7b795492014-09-16 14:38:39 -070067 return new EthCriterion(mac, Type.ETH_DST);
68 }
69
70 /**
71 * Creates a match on ETH_TYPE field using the specified value.
72 *
73 * @param ethType eth type value
74 * @return match criterion
75 */
76 public static Criterion matchEthType(Short ethType) {
77 return new EthTypeCriterion(ethType);
78 }
79
80 /**
81 * Creates a match on VLAN ID field using the specified value.
82 *
83 * @param vlanId vlan id value
84 * @return match criterion
85 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070086 public static Criterion matchVlanId(VlanId vlanId) {
alshabib7b795492014-09-16 14:38:39 -070087 return new VlanIdCriterion(vlanId);
88 }
89
90 /**
91 * Creates a match on VLAN PCP field using the specified value.
92 *
93 * @param vlanPcp vlan pcp value
94 * @return match criterion
95 */
alshabibb45d1962014-09-18 14:25:45 -070096 public static Criterion matchVlanPcp(Byte vlanPcp) {
alshabib7b795492014-09-16 14:38:39 -070097 return new VlanPcpCriterion(vlanPcp);
98 }
99
100 /**
101 * Creates a match on IP proto field using the specified value.
102 *
103 * @param proto ip protocol value
104 * @return match criterion
105 */
106 public static Criterion matchIPProtocol(Byte proto) {
107 return new IPProtocolCriterion(proto);
108 }
109
110 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800111 * Creates a match on IPv4 source field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700112 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800113 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700114 * @return match criterion
115 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700116 public static Criterion matchIPSrc(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700117 return new IPCriterion(ip, Type.IPV4_SRC);
118 }
119
120 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800121 * Creates a match on IPv4 destination field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700122 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800123 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700124 * @return match criterion
125 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700126 public static Criterion matchIPDst(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700127 return new IPCriterion(ip, Type.IPV4_DST);
alshabib369d2942014-09-12 17:59:35 -0700128 }
129
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700130 /**
131 * Creates a match on TCP source port field using the specified value.
132 *
Yuta HIGUCHI5c947272014-11-03 21:39:21 -0800133 * @param tcpPort TCP source port
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700134 * @return match criterion
135 */
136 public static Criterion matchTcpSrc(Short tcpPort) {
137 return new TcpPortCriterion(tcpPort, Type.TCP_SRC);
138 }
139
140 /**
141 * Creates a match on TCP destination port field using the specified value.
142 *
Yuta HIGUCHI5c947272014-11-03 21:39:21 -0800143 * @param tcpPort TCP destination port
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700144 * @return match criterion
145 */
146 public static Criterion matchTcpDst(Short tcpPort) {
147 return new TcpPortCriterion(tcpPort, Type.TCP_DST);
148 }
alshabib369d2942014-09-12 17:59:35 -0700149
Marc De Leenheer49087752014-10-23 13:54:09 -0700150 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800151 * Creates a match on IPv6 source field using the specified value.
152 *
153 * @param ip ipv6 source value
154 * @return match criterion
155 */
156 public static Criterion matchIPv6Src(IpPrefix ip) {
157 return new IPCriterion(ip, Type.IPV6_SRC);
158 }
159
160 /**
161 * Creates a match on IPv6 destination field using the specified value.
162 *
163 * @param ip ipv6 source value
164 * @return match criterion
165 */
166 public static Criterion matchIPv6Dst(IpPrefix ip) {
167 return new IPCriterion(ip, Type.IPV6_DST);
168 }
169
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800170 /*
171 * Creates a match on ICMPv6 type field using the specified value.
172 *
173 * @param icmpv6Type ICMPv6 type
174 * @return match criterion
175 */
176 public static Criterion matchIcmpv6Type(Byte icmpv6Type) {
177 return new Icmpv6TypeCriterion(icmpv6Type);
178 }
179
180 /**
181 * Creates a match on ICMPv6 code field using the specified value.
182 *
183 * @param icmpv6Code ICMPv6 code
184 * @return match criterion
185 */
186 public static Criterion matchIcmpv6Code(Byte icmpv6Code) {
187 return new Icmpv6CodeCriterion(icmpv6Code);
188 }
189
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800190 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800191 * Creates a match on MPLS label.
192 * @param mplsLabel MPLS label
193 * @return match criterion
194 */
195
196 public static Criterion matchMplsLabel(Integer mplsLabel) {
197 return new MplsCriterion(mplsLabel);
198 }
199
200 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700201 * Creates a match on lambda field using the specified value.
202 *
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800203 * @param lambda lambda to match on
Marc De Leenheer49087752014-10-23 13:54:09 -0700204 * @return match criterion
205 */
206 public static Criterion matchLambda(Short lambda) {
207 return new LambdaCriterion(lambda, Type.OCH_SIGID);
208 }
209
210 /**
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800211 * Creates a match on optical signal type using the specified value.
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700212 *
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800213 * @param sigType optical signal type
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700214 * @return match criterion
215 */
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800216 public static Criterion matchOpticalSignalType(Short sigType) {
217 return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700218 }
219
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700220 /**
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800221 * Implementation of input port criterion.
alshabib7b795492014-09-16 14:38:39 -0700222 */
alshabib7b795492014-09-16 14:38:39 -0700223 public static final class PortCriterion implements Criterion {
224 private final PortNumber port;
225
226 public PortCriterion(PortNumber port) {
227 this.port = port;
228 }
229
230 @Override
231 public Type type() {
232 return Type.IN_PORT;
233 }
234
235 public PortNumber port() {
236 return this.port;
237 }
alshabib99b8fdc2014-09-25 14:30:22 -0700238
239 @Override
240 public String toString() {
241 return toStringHelper(type().toString())
242 .add("port", port).toString();
243 }
alshabibba5ac482014-10-02 17:15:20 -0700244
245 @Override
246 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800247 return Objects.hash(type(), port);
alshabibba5ac482014-10-02 17:15:20 -0700248 }
249
250 @Override
251 public boolean equals(Object obj) {
252 if (this == obj) {
253 return true;
254 }
255 if (obj instanceof PortCriterion) {
256 PortCriterion that = (PortCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700257 return Objects.equals(port, that.port) &&
258 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700259
260 }
261 return false;
262 }
263
alshabib7b795492014-09-16 14:38:39 -0700264 }
265
266
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800267 /**
268 * Implementation of MAC address criterion.
269 */
alshabib7b795492014-09-16 14:38:39 -0700270 public static final class EthCriterion implements Criterion {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700271 private final MacAddress mac;
alshabib7b795492014-09-16 14:38:39 -0700272 private final Type type;
273
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700274 public EthCriterion(MacAddress mac, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700275 this.mac = mac;
276 this.type = type;
277 }
278
279 @Override
280 public Type type() {
281 return this.type;
282 }
283
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700284 public MacAddress mac() {
alshabib7b795492014-09-16 14:38:39 -0700285 return this.mac;
286 }
alshabib99b8fdc2014-09-25 14:30:22 -0700287
288 @Override
289 public String toString() {
290 return toStringHelper(type().toString())
291 .add("mac", mac).toString();
292 }
293
alshabibba5ac482014-10-02 17:15:20 -0700294 @Override
295 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800296 return Objects.hash(type, mac);
alshabibba5ac482014-10-02 17:15:20 -0700297 }
298
299 @Override
300 public boolean equals(Object obj) {
301 if (this == obj) {
302 return true;
303 }
304 if (obj instanceof EthCriterion) {
305 EthCriterion that = (EthCriterion) obj;
306 return Objects.equals(mac, that.mac) &&
307 Objects.equals(type, that.type);
308
309
310 }
311 return false;
312 }
313
314
alshabib7b795492014-09-16 14:38:39 -0700315 }
316
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800317 /**
318 * Implementation of Ethernet type criterion.
319 */
alshabib7b795492014-09-16 14:38:39 -0700320 public static final class EthTypeCriterion implements Criterion {
321
322 private final Short ethType;
323
324 public EthTypeCriterion(Short ethType) {
325 this.ethType = ethType;
326 }
327
328 @Override
329 public Type type() {
330 return Type.ETH_TYPE;
331 }
332
333 public Short ethType() {
334 return ethType;
335 }
336
alshabib99b8fdc2014-09-25 14:30:22 -0700337 @Override
338 public String toString() {
339 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800340 .add("ethType", Long.toHexString(ethType & 0xffff))
341 .toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700342 }
343
alshabibba5ac482014-10-02 17:15:20 -0700344 @Override
345 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800346 return Objects.hash(type(), ethType);
alshabibba5ac482014-10-02 17:15:20 -0700347 }
348
349 @Override
350 public boolean equals(Object obj) {
351 if (this == obj) {
352 return true;
353 }
354 if (obj instanceof EthTypeCriterion) {
355 EthTypeCriterion that = (EthTypeCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700356 return Objects.equals(ethType, that.ethType) &&
357 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700358
359
360 }
361 return false;
362 }
363
alshabib7b795492014-09-16 14:38:39 -0700364 }
365
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800366 /**
367 * Implementation of IP address criterion.
368 */
alshabib7b795492014-09-16 14:38:39 -0700369 public static final class IPCriterion implements Criterion {
370
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700371 private final IpPrefix ip;
alshabib7b795492014-09-16 14:38:39 -0700372 private final Type type;
373
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700374 public IPCriterion(IpPrefix ip, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700375 this.ip = ip;
376 this.type = type;
377 }
378
379 @Override
380 public Type type() {
381 return this.type;
382 }
383
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700384 public IpPrefix ip() {
alshabib7b795492014-09-16 14:38:39 -0700385 return this.ip;
386 }
387
alshabib99b8fdc2014-09-25 14:30:22 -0700388 @Override
389 public String toString() {
390 return toStringHelper(type().toString())
391 .add("ip", ip).toString();
392 }
alshabib7b795492014-09-16 14:38:39 -0700393
alshabibba5ac482014-10-02 17:15:20 -0700394 @Override
395 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800396 return Objects.hash(type, ip);
alshabibba5ac482014-10-02 17:15:20 -0700397 }
398
399 @Override
400 public boolean equals(Object obj) {
401 if (this == obj) {
402 return true;
403 }
404 if (obj instanceof IPCriterion) {
405 IPCriterion that = (IPCriterion) obj;
406 return Objects.equals(ip, that.ip) &&
407 Objects.equals(type, that.type);
408
409
410 }
411 return false;
412 }
413
alshabib7b795492014-09-16 14:38:39 -0700414 }
415
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800416 /**
417 * Implementation of Internet Protocol Number criterion.
418 */
alshabib7b795492014-09-16 14:38:39 -0700419 public static final class IPProtocolCriterion implements Criterion {
420
421 private final Byte proto;
422
423 public IPProtocolCriterion(Byte protocol) {
424 this.proto = protocol;
425 }
426
427 @Override
428 public Type type() {
429 return Type.IP_PROTO;
430 }
431
432 public Byte protocol() {
433 return proto;
434 }
435
alshabib99b8fdc2014-09-25 14:30:22 -0700436 @Override
437 public String toString() {
438 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800439 .add("protocol", Long.toHexString(proto & 0xff))
440 .toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700441 }
442
alshabibba5ac482014-10-02 17:15:20 -0700443 @Override
444 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800445 return Objects.hash(type(), proto);
alshabibba5ac482014-10-02 17:15:20 -0700446 }
447
448 @Override
449 public boolean equals(Object obj) {
450 if (this == obj) {
451 return true;
452 }
453 if (obj instanceof IPProtocolCriterion) {
454 IPProtocolCriterion that = (IPProtocolCriterion) obj;
455 return Objects.equals(proto, that.proto);
456
457
458 }
459 return false;
460 }
461
alshabib7b795492014-09-16 14:38:39 -0700462 }
463
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800464 /**
465 * Implementation of VLAN priority criterion.
466 */
alshabib7b795492014-09-16 14:38:39 -0700467 public static final class VlanPcpCriterion implements Criterion {
468
469 private final Byte vlanPcp;
470
471 public VlanPcpCriterion(Byte vlanPcp) {
472 this.vlanPcp = vlanPcp;
473 }
474
475 @Override
476 public Type type() {
477 return Type.VLAN_PCP;
478 }
479
alshabib35edb1a2014-09-16 17:44:44 -0700480 public Byte priority() {
alshabib7b795492014-09-16 14:38:39 -0700481 return vlanPcp;
482 }
483
alshabib99b8fdc2014-09-25 14:30:22 -0700484 @Override
485 public String toString() {
486 return toStringHelper(type().toString())
487 .add("pcp", Long.toHexString(vlanPcp)).toString();
488 }
489
alshabibba5ac482014-10-02 17:15:20 -0700490 @Override
491 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800492 return Objects.hash(type(), vlanPcp);
alshabibba5ac482014-10-02 17:15:20 -0700493 }
494
495 @Override
496 public boolean equals(Object obj) {
497 if (this == obj) {
498 return true;
499 }
500 if (obj instanceof VlanPcpCriterion) {
501 VlanPcpCriterion that = (VlanPcpCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700502 return Objects.equals(vlanPcp, that.vlanPcp) &&
503 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700504
505
506 }
507 return false;
508 }
509
alshabib7b795492014-09-16 14:38:39 -0700510 }
511
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800512 /**
513 * Implementation of VLAN ID criterion.
514 */
alshabib7b795492014-09-16 14:38:39 -0700515 public static final class VlanIdCriterion implements Criterion {
516
517
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700518 private final VlanId vlanId;
alshabib7b795492014-09-16 14:38:39 -0700519
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700520 public VlanIdCriterion(VlanId vlanId) {
alshabib7b795492014-09-16 14:38:39 -0700521 this.vlanId = vlanId;
522 }
523
524 @Override
525 public Type type() {
526 return Type.VLAN_VID;
527 }
528
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700529 public VlanId vlanId() {
alshabib7b795492014-09-16 14:38:39 -0700530 return vlanId;
531 }
532
alshabib99b8fdc2014-09-25 14:30:22 -0700533 @Override
534 public String toString() {
535 return toStringHelper(type().toString())
536 .add("id", vlanId).toString();
537 }
538
alshabibba5ac482014-10-02 17:15:20 -0700539 @Override
540 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800541 return Objects.hash(type(), vlanId);
alshabibba5ac482014-10-02 17:15:20 -0700542 }
543
544 @Override
545 public boolean equals(Object obj) {
546 if (this == obj) {
547 return true;
548 }
549 if (obj instanceof VlanIdCriterion) {
550 VlanIdCriterion that = (VlanIdCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700551 return Objects.equals(vlanId, that.vlanId) &&
552 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700553
554
555 }
556 return false;
557 }
558
alshabib7b795492014-09-16 14:38:39 -0700559 }
560
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800561 /**
562 * Implementation of TCP port criterion.
563 */
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700564 public static final class TcpPortCriterion implements Criterion {
565
566 private final Short tcpPort;
567 private final Type type;
568
569 public TcpPortCriterion(Short tcpPort, Type type) {
570 this.tcpPort = tcpPort;
571 this.type = type;
572 }
573
574 @Override
575 public Type type() {
576 return this.type;
577 }
578
579 public Short tcpPort() {
580 return this.tcpPort;
581 }
582
583 @Override
584 public String toString() {
585 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800586 .add("tcpPort", tcpPort & 0xffff).toString();
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700587 }
588
589 @Override
590 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800591 return Objects.hash(type, tcpPort);
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700592 }
593
594 @Override
595 public boolean equals(Object obj) {
596 if (this == obj) {
597 return true;
598 }
599 if (obj instanceof TcpPortCriterion) {
600 TcpPortCriterion that = (TcpPortCriterion) obj;
601 return Objects.equals(tcpPort, that.tcpPort) &&
602 Objects.equals(type, that.type);
603
604
605 }
606 return false;
607 }
608 }
Marc De Leenheer49087752014-10-23 13:54:09 -0700609
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800610 /**
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800611 * Implementation of ICMPv6 type criterion.
612 */
613 public static final class Icmpv6TypeCriterion implements Criterion {
614
615 private final Byte icmpv6Type;
616
617 public Icmpv6TypeCriterion(Byte icmpv6Type) {
618 this.icmpv6Type = icmpv6Type;
619 }
620
621 @Override
622 public Type type() {
623 return Type.ICMPV6_TYPE;
624 }
625
626 public Byte icmpv6Type() {
627 return icmpv6Type;
628 }
629
630 @Override
631 public String toString() {
632 return toStringHelper(type().toString())
633 .add("icmpv6Type", icmpv6Type & 0xff).toString();
634 }
635
636 @Override
637 public int hashCode() {
638 return Objects.hash(icmpv6Type, type());
639 }
640
641 @Override
642 public boolean equals(Object obj) {
643 if (this == obj) {
644 return true;
645 }
646 if (obj instanceof Icmpv6TypeCriterion) {
647 Icmpv6TypeCriterion that = (Icmpv6TypeCriterion) obj;
648 return Objects.equals(icmpv6Type, that.icmpv6Type) &&
649 Objects.equals(this.type(), that.type());
650 }
651 return false;
652 }
653 }
654
655 /**
656 * Implementation of ICMPv6 code criterion.
657 */
658 public static final class Icmpv6CodeCriterion implements Criterion {
659
660 private final Byte icmpv6Code;
661
662 public Icmpv6CodeCriterion(Byte icmpv6Code) {
663 this.icmpv6Code = icmpv6Code;
664 }
665
666 @Override
667 public Type type() {
668 return Type.ICMPV6_CODE;
669 }
670
671 public Byte icmpv6Code() {
672 return icmpv6Code;
673 }
674
675 @Override
676 public String toString() {
677 return toStringHelper(type().toString())
678 .add("icmpv6Code", icmpv6Code & 0xff).toString();
679 }
680
681 @Override
682 public int hashCode() {
683 return Objects.hash(icmpv6Code, type());
684 }
685
686 @Override
687 public boolean equals(Object obj) {
688 if (this == obj) {
689 return true;
690 }
691 if (obj instanceof Icmpv6CodeCriterion) {
692 Icmpv6CodeCriterion that = (Icmpv6CodeCriterion) obj;
693 return Objects.equals(icmpv6Code, that.icmpv6Code) &&
694 Objects.equals(this.type(), that.type());
695 }
696 return false;
697 }
698 }
699
700 /**
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800701 * Implementation of MPLS tag criterion.
702 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800703 public static final class MplsCriterion implements Criterion {
704
705 private final Integer mplsLabel;
706
707 public MplsCriterion(Integer mplsLabel) {
708 this.mplsLabel = mplsLabel;
709 }
710
711 @Override
712 public Type type() {
713 return Type.MPLS_LABEL;
714 }
715
716 public Integer label() {
717 return mplsLabel;
718 }
719
720 @Override
721 public String toString() {
722 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800723 .add("mpls", mplsLabel & 0xffffffffL).toString();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800724 }
725
726 @Override
727 public int hashCode() {
728 return Objects.hash(mplsLabel, type());
729 }
730
731 @Override
732 public boolean equals(Object obj) {
733 if (this == obj) {
734 return true;
735 }
736 if (obj instanceof MplsCriterion) {
737 MplsCriterion that = (MplsCriterion) obj;
738 return Objects.equals(mplsLabel, that.mplsLabel) &&
739 Objects.equals(this.type(), that.type());
740
741
742 }
743 return false;
744 }
745
746 }
747
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800748 /**
749 * Implementation of lambda (wavelength) criterion.
750 */
Marc De Leenheer49087752014-10-23 13:54:09 -0700751 public static final class LambdaCriterion implements Criterion {
752
753 private final short lambda;
754 private final Type type;
755
756 public LambdaCriterion(short lambda, Type type) {
757 this.lambda = lambda;
758 this.type = type;
759 }
760
761 @Override
762 public Type type() {
763 return this.type;
764 }
765
766 public Short lambda() {
767 return this.lambda;
768 }
769
770 @Override
771 public String toString() {
772 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800773 .add("lambda", lambda & 0xffff).toString();
Marc De Leenheer49087752014-10-23 13:54:09 -0700774 }
775
776 @Override
777 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800778 return Objects.hash(type, lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -0700779 }
780
781 @Override
782 public boolean equals(Object obj) {
783 if (this == obj) {
784 return true;
785 }
786 if (obj instanceof LambdaCriterion) {
787 LambdaCriterion that = (LambdaCriterion) obj;
788 return Objects.equals(lambda, that.lambda) &&
789 Objects.equals(type, that.type);
790 }
791 return false;
792 }
793 }
794
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800795 /**
796 * Implementation of optical signal type criterion.
797 */
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700798 public static final class OpticalSignalTypeCriterion implements Criterion {
799
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800800 private final Short signalType;
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700801 private final Type type;
802
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800803 public OpticalSignalTypeCriterion(Short signalType, Type type) {
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700804 this.signalType = signalType;
805 this.type = type;
806 }
807
808 @Override
809 public Type type() {
810 return this.type;
811 }
812
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800813 public Short signalType() {
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700814 return this.signalType;
815 }
816
817 @Override
818 public String toString() {
819 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800820 .add("signalType", signalType & 0xffff).toString();
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700821 }
822
823 @Override
824 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800825 return Objects.hash(type, signalType);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700826 }
827
828 @Override
829 public boolean equals(Object obj) {
830 if (this == obj) {
831 return true;
832 }
833 if (obj instanceof OpticalSignalTypeCriterion) {
834 OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj;
835 return Objects.equals(signalType, that.signalType) &&
836 Objects.equals(type, that.type);
837 }
838 return false;
839 }
840 }
841
tom8bb16062014-09-12 14:47:46 -0700842}