blob: e7251433b739f74a746d5b4c47f34b2cee44c4c1 [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
170 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800171 * Creates a match on MPLS label.
172 * @param mplsLabel MPLS label
173 * @return match criterion
174 */
175
176 public static Criterion matchMplsLabel(Integer mplsLabel) {
177 return new MplsCriterion(mplsLabel);
178 }
179
180 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700181 * Creates a match on lambda field using the specified value.
182 *
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800183 * @param lambda lambda to match on
Marc De Leenheer49087752014-10-23 13:54:09 -0700184 * @return match criterion
185 */
186 public static Criterion matchLambda(Short lambda) {
187 return new LambdaCriterion(lambda, Type.OCH_SIGID);
188 }
189
190 /**
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800191 * Creates a match on optical signal type using the specified value.
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700192 *
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800193 * @param sigType optical signal type
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700194 * @return match criterion
195 */
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800196 public static Criterion matchOpticalSignalType(Short sigType) {
197 return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700198 }
199
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700200 /**
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800201 * Implementation of input port criterion.
alshabib7b795492014-09-16 14:38:39 -0700202 */
alshabib7b795492014-09-16 14:38:39 -0700203 public static final class PortCriterion implements Criterion {
204 private final PortNumber port;
205
206 public PortCriterion(PortNumber port) {
207 this.port = port;
208 }
209
210 @Override
211 public Type type() {
212 return Type.IN_PORT;
213 }
214
215 public PortNumber port() {
216 return this.port;
217 }
alshabib99b8fdc2014-09-25 14:30:22 -0700218
219 @Override
220 public String toString() {
221 return toStringHelper(type().toString())
222 .add("port", port).toString();
223 }
alshabibba5ac482014-10-02 17:15:20 -0700224
225 @Override
226 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800227 return Objects.hash(type(), port);
alshabibba5ac482014-10-02 17:15:20 -0700228 }
229
230 @Override
231 public boolean equals(Object obj) {
232 if (this == obj) {
233 return true;
234 }
235 if (obj instanceof PortCriterion) {
236 PortCriterion that = (PortCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700237 return Objects.equals(port, that.port) &&
238 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700239
240 }
241 return false;
242 }
243
alshabib7b795492014-09-16 14:38:39 -0700244 }
245
246
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800247 /**
248 * Implementation of MAC address criterion.
249 */
alshabib7b795492014-09-16 14:38:39 -0700250 public static final class EthCriterion implements Criterion {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700251 private final MacAddress mac;
alshabib7b795492014-09-16 14:38:39 -0700252 private final Type type;
253
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700254 public EthCriterion(MacAddress mac, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700255 this.mac = mac;
256 this.type = type;
257 }
258
259 @Override
260 public Type type() {
261 return this.type;
262 }
263
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700264 public MacAddress mac() {
alshabib7b795492014-09-16 14:38:39 -0700265 return this.mac;
266 }
alshabib99b8fdc2014-09-25 14:30:22 -0700267
268 @Override
269 public String toString() {
270 return toStringHelper(type().toString())
271 .add("mac", mac).toString();
272 }
273
alshabibba5ac482014-10-02 17:15:20 -0700274 @Override
275 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800276 return Objects.hash(type, mac);
alshabibba5ac482014-10-02 17:15:20 -0700277 }
278
279 @Override
280 public boolean equals(Object obj) {
281 if (this == obj) {
282 return true;
283 }
284 if (obj instanceof EthCriterion) {
285 EthCriterion that = (EthCriterion) obj;
286 return Objects.equals(mac, that.mac) &&
287 Objects.equals(type, that.type);
288
289
290 }
291 return false;
292 }
293
294
alshabib7b795492014-09-16 14:38:39 -0700295 }
296
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800297 /**
298 * Implementation of Ethernet type criterion.
299 */
alshabib7b795492014-09-16 14:38:39 -0700300 public static final class EthTypeCriterion implements Criterion {
301
302 private final Short ethType;
303
304 public EthTypeCriterion(Short ethType) {
305 this.ethType = ethType;
306 }
307
308 @Override
309 public Type type() {
310 return Type.ETH_TYPE;
311 }
312
313 public Short ethType() {
314 return ethType;
315 }
316
alshabib99b8fdc2014-09-25 14:30:22 -0700317 @Override
318 public String toString() {
319 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800320 .add("ethType", Long.toHexString(ethType & 0xffff))
321 .toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700322 }
323
alshabibba5ac482014-10-02 17:15:20 -0700324 @Override
325 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800326 return Objects.hash(type(), ethType);
alshabibba5ac482014-10-02 17:15:20 -0700327 }
328
329 @Override
330 public boolean equals(Object obj) {
331 if (this == obj) {
332 return true;
333 }
334 if (obj instanceof EthTypeCriterion) {
335 EthTypeCriterion that = (EthTypeCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700336 return Objects.equals(ethType, that.ethType) &&
337 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700338
339
340 }
341 return false;
342 }
343
alshabib7b795492014-09-16 14:38:39 -0700344 }
345
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800346 /**
347 * Implementation of IP address criterion.
348 */
alshabib7b795492014-09-16 14:38:39 -0700349 public static final class IPCriterion implements Criterion {
350
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700351 private final IpPrefix ip;
alshabib7b795492014-09-16 14:38:39 -0700352 private final Type type;
353
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700354 public IPCriterion(IpPrefix ip, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700355 this.ip = ip;
356 this.type = type;
357 }
358
359 @Override
360 public Type type() {
361 return this.type;
362 }
363
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700364 public IpPrefix ip() {
alshabib7b795492014-09-16 14:38:39 -0700365 return this.ip;
366 }
367
alshabib99b8fdc2014-09-25 14:30:22 -0700368 @Override
369 public String toString() {
370 return toStringHelper(type().toString())
371 .add("ip", ip).toString();
372 }
alshabib7b795492014-09-16 14:38:39 -0700373
alshabibba5ac482014-10-02 17:15:20 -0700374 @Override
375 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800376 return Objects.hash(type, ip);
alshabibba5ac482014-10-02 17:15:20 -0700377 }
378
379 @Override
380 public boolean equals(Object obj) {
381 if (this == obj) {
382 return true;
383 }
384 if (obj instanceof IPCriterion) {
385 IPCriterion that = (IPCriterion) obj;
386 return Objects.equals(ip, that.ip) &&
387 Objects.equals(type, that.type);
388
389
390 }
391 return false;
392 }
393
alshabib7b795492014-09-16 14:38:39 -0700394 }
395
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800396 /**
397 * Implementation of Internet Protocol Number criterion.
398 */
alshabib7b795492014-09-16 14:38:39 -0700399 public static final class IPProtocolCriterion implements Criterion {
400
401 private final Byte proto;
402
403 public IPProtocolCriterion(Byte protocol) {
404 this.proto = protocol;
405 }
406
407 @Override
408 public Type type() {
409 return Type.IP_PROTO;
410 }
411
412 public Byte protocol() {
413 return proto;
414 }
415
alshabib99b8fdc2014-09-25 14:30:22 -0700416 @Override
417 public String toString() {
418 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800419 .add("protocol", Long.toHexString(proto & 0xff))
420 .toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700421 }
422
alshabibba5ac482014-10-02 17:15:20 -0700423 @Override
424 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800425 return Objects.hash(type(), proto);
alshabibba5ac482014-10-02 17:15:20 -0700426 }
427
428 @Override
429 public boolean equals(Object obj) {
430 if (this == obj) {
431 return true;
432 }
433 if (obj instanceof IPProtocolCriterion) {
434 IPProtocolCriterion that = (IPProtocolCriterion) obj;
435 return Objects.equals(proto, that.proto);
436
437
438 }
439 return false;
440 }
441
alshabib7b795492014-09-16 14:38:39 -0700442 }
443
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800444 /**
445 * Implementation of VLAN priority criterion.
446 */
alshabib7b795492014-09-16 14:38:39 -0700447 public static final class VlanPcpCriterion implements Criterion {
448
449 private final Byte vlanPcp;
450
451 public VlanPcpCriterion(Byte vlanPcp) {
452 this.vlanPcp = vlanPcp;
453 }
454
455 @Override
456 public Type type() {
457 return Type.VLAN_PCP;
458 }
459
alshabib35edb1a2014-09-16 17:44:44 -0700460 public Byte priority() {
alshabib7b795492014-09-16 14:38:39 -0700461 return vlanPcp;
462 }
463
alshabib99b8fdc2014-09-25 14:30:22 -0700464 @Override
465 public String toString() {
466 return toStringHelper(type().toString())
467 .add("pcp", Long.toHexString(vlanPcp)).toString();
468 }
469
alshabibba5ac482014-10-02 17:15:20 -0700470 @Override
471 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800472 return Objects.hash(type(), vlanPcp);
alshabibba5ac482014-10-02 17:15:20 -0700473 }
474
475 @Override
476 public boolean equals(Object obj) {
477 if (this == obj) {
478 return true;
479 }
480 if (obj instanceof VlanPcpCriterion) {
481 VlanPcpCriterion that = (VlanPcpCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700482 return Objects.equals(vlanPcp, that.vlanPcp) &&
483 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700484
485
486 }
487 return false;
488 }
489
alshabib7b795492014-09-16 14:38:39 -0700490 }
491
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800492 /**
493 * Implementation of VLAN ID criterion.
494 */
alshabib7b795492014-09-16 14:38:39 -0700495 public static final class VlanIdCriterion implements Criterion {
496
497
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700498 private final VlanId vlanId;
alshabib7b795492014-09-16 14:38:39 -0700499
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700500 public VlanIdCriterion(VlanId vlanId) {
alshabib7b795492014-09-16 14:38:39 -0700501 this.vlanId = vlanId;
502 }
503
504 @Override
505 public Type type() {
506 return Type.VLAN_VID;
507 }
508
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700509 public VlanId vlanId() {
alshabib7b795492014-09-16 14:38:39 -0700510 return vlanId;
511 }
512
alshabib99b8fdc2014-09-25 14:30:22 -0700513 @Override
514 public String toString() {
515 return toStringHelper(type().toString())
516 .add("id", vlanId).toString();
517 }
518
alshabibba5ac482014-10-02 17:15:20 -0700519 @Override
520 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800521 return Objects.hash(type(), vlanId);
alshabibba5ac482014-10-02 17:15:20 -0700522 }
523
524 @Override
525 public boolean equals(Object obj) {
526 if (this == obj) {
527 return true;
528 }
529 if (obj instanceof VlanIdCriterion) {
530 VlanIdCriterion that = (VlanIdCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700531 return Objects.equals(vlanId, that.vlanId) &&
532 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700533
534
535 }
536 return false;
537 }
538
alshabib7b795492014-09-16 14:38:39 -0700539 }
540
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800541 /**
542 * Implementation of TCP port criterion.
543 */
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700544 public static final class TcpPortCriterion implements Criterion {
545
546 private final Short tcpPort;
547 private final Type type;
548
549 public TcpPortCriterion(Short tcpPort, Type type) {
550 this.tcpPort = tcpPort;
551 this.type = type;
552 }
553
554 @Override
555 public Type type() {
556 return this.type;
557 }
558
559 public Short tcpPort() {
560 return this.tcpPort;
561 }
562
563 @Override
564 public String toString() {
565 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800566 .add("tcpPort", tcpPort & 0xffff).toString();
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700567 }
568
569 @Override
570 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800571 return Objects.hash(type, tcpPort);
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700572 }
573
574 @Override
575 public boolean equals(Object obj) {
576 if (this == obj) {
577 return true;
578 }
579 if (obj instanceof TcpPortCriterion) {
580 TcpPortCriterion that = (TcpPortCriterion) obj;
581 return Objects.equals(tcpPort, that.tcpPort) &&
582 Objects.equals(type, that.type);
583
584
585 }
586 return false;
587 }
588 }
Marc De Leenheer49087752014-10-23 13:54:09 -0700589
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800590 /**
591 * Implementation of MPLS tag criterion.
592 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800593 public static final class MplsCriterion implements Criterion {
594
595 private final Integer mplsLabel;
596
597 public MplsCriterion(Integer mplsLabel) {
598 this.mplsLabel = mplsLabel;
599 }
600
601 @Override
602 public Type type() {
603 return Type.MPLS_LABEL;
604 }
605
606 public Integer label() {
607 return mplsLabel;
608 }
609
610 @Override
611 public String toString() {
612 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800613 .add("mpls", mplsLabel & 0xffffffffL).toString();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800614 }
615
616 @Override
617 public int hashCode() {
618 return Objects.hash(mplsLabel, type());
619 }
620
621 @Override
622 public boolean equals(Object obj) {
623 if (this == obj) {
624 return true;
625 }
626 if (obj instanceof MplsCriterion) {
627 MplsCriterion that = (MplsCriterion) obj;
628 return Objects.equals(mplsLabel, that.mplsLabel) &&
629 Objects.equals(this.type(), that.type());
630
631
632 }
633 return false;
634 }
635
636 }
637
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800638 /**
639 * Implementation of lambda (wavelength) criterion.
640 */
Marc De Leenheer49087752014-10-23 13:54:09 -0700641 public static final class LambdaCriterion implements Criterion {
642
643 private final short lambda;
644 private final Type type;
645
646 public LambdaCriterion(short lambda, Type type) {
647 this.lambda = lambda;
648 this.type = type;
649 }
650
651 @Override
652 public Type type() {
653 return this.type;
654 }
655
656 public Short lambda() {
657 return this.lambda;
658 }
659
660 @Override
661 public String toString() {
662 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800663 .add("lambda", lambda & 0xffff).toString();
Marc De Leenheer49087752014-10-23 13:54:09 -0700664 }
665
666 @Override
667 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800668 return Objects.hash(type, lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -0700669 }
670
671 @Override
672 public boolean equals(Object obj) {
673 if (this == obj) {
674 return true;
675 }
676 if (obj instanceof LambdaCriterion) {
677 LambdaCriterion that = (LambdaCriterion) obj;
678 return Objects.equals(lambda, that.lambda) &&
679 Objects.equals(type, that.type);
680 }
681 return false;
682 }
683 }
684
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800685 /**
686 * Implementation of optical signal type criterion.
687 */
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700688 public static final class OpticalSignalTypeCriterion implements Criterion {
689
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800690 private final Short signalType;
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700691 private final Type type;
692
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800693 public OpticalSignalTypeCriterion(Short signalType, Type type) {
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700694 this.signalType = signalType;
695 this.type = type;
696 }
697
698 @Override
699 public Type type() {
700 return this.type;
701 }
702
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800703 public Short signalType() {
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700704 return this.signalType;
705 }
706
707 @Override
708 public String toString() {
709 return toStringHelper(type().toString())
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800710 .add("signalType", signalType & 0xffff).toString();
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700711 }
712
713 @Override
714 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800715 return Objects.hash(type, signalType);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700716 }
717
718 @Override
719 public boolean equals(Object obj) {
720 if (this == obj) {
721 return true;
722 }
723 if (obj instanceof OpticalSignalTypeCriterion) {
724 OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj;
725 return Objects.equals(signalType, that.signalType) &&
726 Objects.equals(type, that.type);
727 }
728 return false;
729 }
730 }
731
tom8bb16062014-09-12 14:47:46 -0700732}