blob: 3c32dea4e53deb56280fc4bd5be725184f4dfae7 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow.criteria;
tom8bb16062014-09-12 14:47:46 -070017
alshabib99b8fdc2014-09-25 14:30:22 -070018import static com.google.common.base.MoreObjects.toStringHelper;
19
alshabibba5ac482014-10-02 17:15:20 -070020import java.util.Objects;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.PortNumber;
22import org.onosproject.net.flow.criteria.Criterion.Type;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070023import org.onlab.packet.IpPrefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080024import org.onlab.packet.Ip6Address;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070025import org.onlab.packet.MacAddress;
26import org.onlab.packet.VlanId;
alshabib7b795492014-09-16 14:38:39 -070027
tom8bb16062014-09-12 14:47:46 -070028/**
29 * Factory class to create various traffic selection criteria.
30 */
31public final class Criteria {
32
alshabib7b795492014-09-16 14:38:39 -070033 //TODO: incomplete type implementation. Need to implement complete list from Criterion
34
tom8bb16062014-09-12 14:47:46 -070035 // Ban construction
36 private Criteria() {
37 }
38
39 /**
alshabib7b795492014-09-16 14:38:39 -070040 * Creates a match on IN_PORT field using the specified value.
41 *
42 * @param port inport value
43 * @return match criterion
44 */
45 public static Criterion matchInPort(PortNumber port) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080046 return new PortCriterion(port, Type.IN_PORT);
47 }
48
49 /**
50 * Creates a match on IN_PHY_PORT field using the specified value.
51 *
52 * @param port inport value
53 * @return match criterion
54 */
55 public static Criterion matchInPhyPort(PortNumber port) {
56 return new PortCriterion(port, Type.IN_PHY_PORT);
57 }
58
59 /**
60 * Creates a match on METADATA field using the specified value.
61 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080062 * @param metadata metadata value (64 bits data)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080063 * @return match criterion
64 */
65 public static Criterion matchMetadata(Long metadata) {
66 return new MetadataCriterion(metadata);
alshabib7b795492014-09-16 14:38:39 -070067 }
68
69 /**
alshabib369d2942014-09-12 17:59:35 -070070 * Creates a match on ETH_DST field using the specified value. This value
71 * may be a wildcard mask.
72 *
tomc104d282014-09-19 10:57:55 -070073 * @param mac MAC address value or wildcard mask
alshabib369d2942014-09-12 17:59:35 -070074 * @return match criterion
75 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070076 public static Criterion matchEthDst(MacAddress mac) {
alshabib7b795492014-09-16 14:38:39 -070077 return new EthCriterion(mac, Type.ETH_DST);
78 }
79
80 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080081 * Creates a match on ETH_SRC field using the specified value. This value
82 * may be a wildcard mask.
83 *
84 * @param mac MAC address value or wildcard mask
85 * @return match criterion
86 */
87 public static Criterion matchEthSrc(MacAddress mac) {
88 return new EthCriterion(mac, Type.ETH_SRC);
89 }
90
91 /**
alshabib7b795492014-09-16 14:38:39 -070092 * Creates a match on ETH_TYPE field using the specified value.
93 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080094 * @param ethType eth type value (16 bits unsigned integer)
alshabib7b795492014-09-16 14:38:39 -070095 * @return match criterion
96 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080097 public static Criterion matchEthType(int ethType) {
alshabib7b795492014-09-16 14:38:39 -070098 return new EthTypeCriterion(ethType);
99 }
100
101 /**
102 * Creates a match on VLAN ID field using the specified value.
103 *
104 * @param vlanId vlan id value
105 * @return match criterion
106 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700107 public static Criterion matchVlanId(VlanId vlanId) {
alshabib7b795492014-09-16 14:38:39 -0700108 return new VlanIdCriterion(vlanId);
109 }
110
111 /**
112 * Creates a match on VLAN PCP field using the specified value.
113 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800114 * @param vlanPcp vlan pcp value (3 bits)
alshabib7b795492014-09-16 14:38:39 -0700115 * @return match criterion
116 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800117 public static Criterion matchVlanPcp(byte vlanPcp) {
alshabib7b795492014-09-16 14:38:39 -0700118 return new VlanPcpCriterion(vlanPcp);
119 }
120
121 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800122 * Creates a match on IP DSCP field using the specified value.
123 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800124 * @param ipDscp ip dscp value (6 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800125 * @return match criterion
126 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800127 public static Criterion matchIPDscp(byte ipDscp) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800128 return new IPDscpCriterion(ipDscp);
129 }
130
131 /**
132 * Creates a match on IP ECN field using the specified value.
133 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800134 * @param ipEcn ip ecn value (3 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800135 * @return match criterion
136 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800137 public static Criterion matchIPEcn(byte ipEcn) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800138 return new IPEcnCriterion(ipEcn);
139 }
140
141 /**
alshabib7b795492014-09-16 14:38:39 -0700142 * Creates a match on IP proto field using the specified value.
143 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800144 * @param proto ip protocol value (8 bits unsigned integer)
alshabib7b795492014-09-16 14:38:39 -0700145 * @return match criterion
146 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800147 public static Criterion matchIPProtocol(short proto) {
alshabib7b795492014-09-16 14:38:39 -0700148 return new IPProtocolCriterion(proto);
149 }
150
151 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800152 * Creates a match on IPv4 source field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700153 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800154 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700155 * @return match criterion
156 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700157 public static Criterion matchIPSrc(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700158 return new IPCriterion(ip, Type.IPV4_SRC);
159 }
160
161 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800162 * Creates a match on IPv4 destination field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700163 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800164 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700165 * @return match criterion
166 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700167 public static Criterion matchIPDst(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700168 return new IPCriterion(ip, Type.IPV4_DST);
alshabib369d2942014-09-12 17:59:35 -0700169 }
170
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700171 /**
172 * Creates a match on TCP source port field using the specified value.
173 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800174 * @param tcpPort TCP source port (16 bits unsigned integer)
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700175 * @return match criterion
176 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800177 public static Criterion matchTcpSrc(int tcpPort) {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700178 return new TcpPortCriterion(tcpPort, Type.TCP_SRC);
179 }
180
181 /**
182 * Creates a match on TCP destination port field using the specified value.
183 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800184 * @param tcpPort TCP destination port (16 bits unsigned integer)
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700185 * @return match criterion
186 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800187 public static Criterion matchTcpDst(int tcpPort) {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700188 return new TcpPortCriterion(tcpPort, Type.TCP_DST);
189 }
alshabib369d2942014-09-12 17:59:35 -0700190
Marc De Leenheer49087752014-10-23 13:54:09 -0700191 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800192 * Creates a match on UDP source port field using the specified value.
193 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800194 * @param udpPort UDP source port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800195 * @return match criterion
196 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800197 public static Criterion matchUdpSrc(int udpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800198 return new UdpPortCriterion(udpPort, Type.UDP_SRC);
199 }
200
201 /**
202 * Creates a match on UDP destination port field using the specified value.
203 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800204 * @param udpPort UDP destination port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800205 * @return match criterion
206 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800207 public static Criterion matchUdpDst(int udpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800208 return new UdpPortCriterion(udpPort, Type.UDP_DST);
209 }
210
211 /**
212 * Creates a match on SCTP source port field using the specified value.
213 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800214 * @param sctpPort SCTP source port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800215 * @return match criterion
216 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800217 public static Criterion matchSctpSrc(int sctpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800218 return new SctpPortCriterion(sctpPort, Type.SCTP_SRC);
219 }
220
221 /**
222 * Creates a match on SCTP destination port field using the specified
223 * value.
224 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800225 * @param sctpPort SCTP destination port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800226 * @return match criterion
227 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800228 public static Criterion matchSctpDst(int sctpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800229 return new SctpPortCriterion(sctpPort, Type.SCTP_DST);
230 }
231
232 /**
233 * Creates a match on ICMP type field using the specified value.
234 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800235 * @param icmpType ICMP type (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800236 * @return match criterion
237 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800238 public static Criterion matchIcmpType(short icmpType) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800239 return new IcmpTypeCriterion(icmpType);
240 }
241
242 /**
243 * Creates a match on ICMP code field using the specified value.
244 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800245 * @param icmpCode ICMP code (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800246 * @return match criterion
247 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800248 public static Criterion matchIcmpCode(short icmpCode) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800249 return new IcmpCodeCriterion(icmpCode);
250 }
251
252 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800253 * Creates a match on IPv6 source field using the specified value.
254 *
255 * @param ip ipv6 source value
256 * @return match criterion
257 */
258 public static Criterion matchIPv6Src(IpPrefix ip) {
259 return new IPCriterion(ip, Type.IPV6_SRC);
260 }
261
262 /**
263 * Creates a match on IPv6 destination field using the specified value.
264 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800265 * @param ip ipv6 destination value
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800266 * @return match criterion
267 */
268 public static Criterion matchIPv6Dst(IpPrefix ip) {
269 return new IPCriterion(ip, Type.IPV6_DST);
270 }
271
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800272 /**
273 * Creates a match on IPv6 flow label field using the specified value.
274 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800275 * @param flowLabel IPv6 flow label (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800276 * @return match criterion
277 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800278 public static Criterion matchIPv6FlowLabel(int flowLabel) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800279 return new IPv6FlowLabelCriterion(flowLabel);
280 }
281
282 /**
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800283 * Creates a match on ICMPv6 type field using the specified value.
284 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800285 * @param icmpv6Type ICMPv6 type (8 bits unsigned integer)
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800286 * @return match criterion
287 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800288 public static Criterion matchIcmpv6Type(short icmpv6Type) {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800289 return new Icmpv6TypeCriterion(icmpv6Type);
290 }
291
292 /**
293 * Creates a match on ICMPv6 code field using the specified value.
294 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800295 * @param icmpv6Code ICMPv6 code (8 bits unsigned integer)
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800296 * @return match criterion
297 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800298 public static Criterion matchIcmpv6Code(short icmpv6Code) {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800299 return new Icmpv6CodeCriterion(icmpv6Code);
300 }
301
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800302 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800303 * Creates a match on IPv6 Neighbor Discovery target address using the
304 * specified value.
305 *
306 * @param targetAddress IPv6 Neighbor Discovery target address
307 * @return match criterion
308 */
309 public static Criterion matchIPv6NDTargetAddress(Ip6Address targetAddress) {
310 return new IPv6NDTargetAddressCriterion(targetAddress);
311 }
312
313 /**
314 * Creates a match on IPv6 Neighbor Discovery source link-layer address
315 * using the specified value.
316 *
317 * @param mac IPv6 Neighbor Discovery source link-layer address
318 * @return match criterion
319 */
320 public static Criterion matchIPv6NDSourceLinkLayerAddress(MacAddress mac) {
321 return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_SLL);
322 }
323
324 /**
325 * Creates a match on IPv6 Neighbor Discovery target link-layer address
326 * using the specified value.
327 *
328 * @param mac IPv6 Neighbor Discovery target link-layer address
329 * @return match criterion
330 */
331 public static Criterion matchIPv6NDTargetLinkLayerAddress(MacAddress mac) {
332 return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_TLL);
333 }
334
335 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800336 * Creates a match on MPLS label.
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800337 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800338 * @param mplsLabel MPLS label (20 bits)
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800339 * @return match criterion
340 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800341 public static Criterion matchMplsLabel(Integer mplsLabel) {
342 return new MplsCriterion(mplsLabel);
343 }
344
345 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700346 * Creates a match on lambda field using the specified value.
347 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800348 * @param lambda lambda to match on (16 bits unsigned integer)
Marc De Leenheer49087752014-10-23 13:54:09 -0700349 * @return match criterion
350 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800351 public static Criterion matchLambda(int lambda) {
Marc De Leenheer49087752014-10-23 13:54:09 -0700352 return new LambdaCriterion(lambda, Type.OCH_SIGID);
353 }
354
355 /**
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800356 * Creates a match on optical signal type using the specified value.
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700357 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800358 * @param sigType optical signal type (16 bits unsigned integer)
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700359 * @return match criterion
360 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800361 public static Criterion matchOpticalSignalType(int sigType) {
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800362 return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700363 }
364
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700365 /**
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800366 * Implementation of input port criterion.
alshabib7b795492014-09-16 14:38:39 -0700367 */
alshabib7b795492014-09-16 14:38:39 -0700368 public static final class PortCriterion implements Criterion {
369 private final PortNumber port;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800370 private final Type type;
alshabib7b795492014-09-16 14:38:39 -0700371
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800372 /**
373 * Constructor.
374 *
375 * @param port the input port number to match
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800376 * @param type the match type. Should be either Type.IN_PORT or
377 * Type.IN_PHY_PORT
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800378 */
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800379 public PortCriterion(PortNumber port, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700380 this.port = port;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800381 this.type = type;
alshabib7b795492014-09-16 14:38:39 -0700382 }
383
384 @Override
385 public Type type() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800386 return this.type;
alshabib7b795492014-09-16 14:38:39 -0700387 }
388
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800389 /**
390 * Gets the input port number to match.
391 *
392 * @return the input port number to match
393 */
alshabib7b795492014-09-16 14:38:39 -0700394 public PortNumber port() {
395 return this.port;
396 }
alshabib99b8fdc2014-09-25 14:30:22 -0700397
398 @Override
399 public String toString() {
400 return toStringHelper(type().toString())
401 .add("port", port).toString();
402 }
alshabibba5ac482014-10-02 17:15:20 -0700403
404 @Override
405 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800406 return Objects.hash(type(), port);
alshabibba5ac482014-10-02 17:15:20 -0700407 }
408
409 @Override
410 public boolean equals(Object obj) {
411 if (this == obj) {
412 return true;
413 }
414 if (obj instanceof PortCriterion) {
415 PortCriterion that = (PortCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700416 return Objects.equals(port, that.port) &&
417 Objects.equals(this.type(), that.type());
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800418 }
419 return false;
420 }
421 }
alshabibba5ac482014-10-02 17:15:20 -0700422
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800423 /**
424 * Implementation of Metadata criterion.
425 */
426 public static final class MetadataCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800427 private final long metadata;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800428
429 /**
430 * Constructor.
431 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800432 * @param metadata the metadata to match (64 bits data)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800433 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800434 public MetadataCriterion(long metadata) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800435 this.metadata = metadata;
436 }
437
438 @Override
439 public Type type() {
440 return Type.METADATA;
441 }
442
443 /**
444 * Gets the metadata to match.
445 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800446 * @return the metadata to match (64 bits data)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800447 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800448 public long metadata() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800449 return metadata;
450 }
451
452 @Override
453 public String toString() {
454 return toStringHelper(type().toString())
455 .add("metadata", Long.toHexString(metadata))
456 .toString();
457 }
458
459 @Override
460 public int hashCode() {
461 return Objects.hash(type(), metadata);
462 }
463
464 @Override
465 public boolean equals(Object obj) {
466 if (this == obj) {
467 return true;
468 }
469 if (obj instanceof MetadataCriterion) {
470 MetadataCriterion that = (MetadataCriterion) obj;
471 return Objects.equals(metadata, that.metadata) &&
472 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700473 }
474 return false;
475 }
alshabib7b795492014-09-16 14:38:39 -0700476 }
477
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800478 /**
479 * Implementation of MAC address criterion.
480 */
alshabib7b795492014-09-16 14:38:39 -0700481 public static final class EthCriterion implements Criterion {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700482 private final MacAddress mac;
alshabib7b795492014-09-16 14:38:39 -0700483 private final Type type;
484
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800485 /**
486 * Constructor.
487 *
488 * @param mac the source or destination MAC address to match
489 * @param type the match type. Should be either Type.ETH_DST or
490 * Type.ETH_SRC
491 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700492 public EthCriterion(MacAddress mac, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700493 this.mac = mac;
494 this.type = type;
495 }
496
497 @Override
498 public Type type() {
499 return this.type;
500 }
501
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800502 /**
503 * Gets the MAC address to match.
504 *
505 * @return the MAC address to match
506 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700507 public MacAddress mac() {
alshabib7b795492014-09-16 14:38:39 -0700508 return this.mac;
509 }
alshabib99b8fdc2014-09-25 14:30:22 -0700510
511 @Override
512 public String toString() {
513 return toStringHelper(type().toString())
514 .add("mac", mac).toString();
515 }
516
alshabibba5ac482014-10-02 17:15:20 -0700517 @Override
518 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800519 return Objects.hash(type, mac);
alshabibba5ac482014-10-02 17:15:20 -0700520 }
521
522 @Override
523 public boolean equals(Object obj) {
524 if (this == obj) {
525 return true;
526 }
527 if (obj instanceof EthCriterion) {
528 EthCriterion that = (EthCriterion) obj;
529 return Objects.equals(mac, that.mac) &&
530 Objects.equals(type, that.type);
alshabibba5ac482014-10-02 17:15:20 -0700531 }
532 return false;
533 }
alshabib7b795492014-09-16 14:38:39 -0700534 }
535
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800536 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800537 * Implementation of Ethernet type criterion (16 bits unsigned integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800538 */
alshabib7b795492014-09-16 14:38:39 -0700539 public static final class EthTypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800540 private static final int MASK = 0xffff;
541 private final int ethType; // Ethernet type value: 16 bits
alshabib7b795492014-09-16 14:38:39 -0700542
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800543 /**
544 * Constructor.
545 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800546 * @param ethType the Ethernet frame type to match (16 bits unsigned
547 * integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800548 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800549 public EthTypeCriterion(int ethType) {
550 this.ethType = ethType & MASK;
alshabib7b795492014-09-16 14:38:39 -0700551 }
552
553 @Override
554 public Type type() {
555 return Type.ETH_TYPE;
556 }
557
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800558 /**
559 * Gets the Ethernet frame type to match.
560 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800561 * @return the Ethernet frame type to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800562 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800563 public int ethType() {
alshabib7b795492014-09-16 14:38:39 -0700564 return ethType;
565 }
566
alshabib99b8fdc2014-09-25 14:30:22 -0700567 @Override
568 public String toString() {
569 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800570 .add("ethType", Long.toHexString(ethType))
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800571 .toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700572 }
573
alshabibba5ac482014-10-02 17:15:20 -0700574 @Override
575 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800576 return Objects.hash(type(), ethType);
alshabibba5ac482014-10-02 17:15:20 -0700577 }
578
579 @Override
580 public boolean equals(Object obj) {
581 if (this == obj) {
582 return true;
583 }
584 if (obj instanceof EthTypeCriterion) {
585 EthTypeCriterion that = (EthTypeCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700586 return Objects.equals(ethType, that.ethType) &&
587 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700588 }
589 return false;
590 }
alshabib7b795492014-09-16 14:38:39 -0700591 }
592
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800593 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800594 * Implementation of VLAN ID criterion.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800595 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800596 public static final class VlanIdCriterion implements Criterion {
597 private final VlanId vlanId;
alshabib7b795492014-09-16 14:38:39 -0700598
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800599 /**
600 * Constructor.
601 *
602 * @param vlanId the VLAN ID to match
603 */
604 public VlanIdCriterion(VlanId vlanId) {
605 this.vlanId = vlanId;
alshabib7b795492014-09-16 14:38:39 -0700606 }
607
608 @Override
609 public Type type() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800610 return Type.VLAN_VID;
alshabib7b795492014-09-16 14:38:39 -0700611 }
612
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800613 /**
614 * Gets the VLAN ID to match.
615 *
616 * @return the VLAN ID to match
617 */
618 public VlanId vlanId() {
619 return vlanId;
alshabib7b795492014-09-16 14:38:39 -0700620 }
621
alshabib99b8fdc2014-09-25 14:30:22 -0700622 @Override
623 public String toString() {
624 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800625 .add("vlanId", vlanId).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700626 }
alshabib7b795492014-09-16 14:38:39 -0700627
alshabibba5ac482014-10-02 17:15:20 -0700628 @Override
629 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800630 return Objects.hash(type(), vlanId);
alshabibba5ac482014-10-02 17:15:20 -0700631 }
632
633 @Override
634 public boolean equals(Object obj) {
635 if (this == obj) {
636 return true;
637 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800638 if (obj instanceof VlanIdCriterion) {
639 VlanIdCriterion that = (VlanIdCriterion) obj;
640 return Objects.equals(vlanId, that.vlanId) &&
641 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700642 }
643 return false;
644 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800645 }
alshabibba5ac482014-10-02 17:15:20 -0700646
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800647 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800648 * Implementation of VLAN priority criterion (3 bits).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800649 */
650 public static final class VlanPcpCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800651 private static final byte MASK = 0x7;
652 private final byte vlanPcp; // VLAN pcp value: 3 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800653
654 /**
655 * Constructor.
656 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800657 * @param vlanPcp the VLAN priority to match (3 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800658 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800659 public VlanPcpCriterion(byte vlanPcp) {
660 this.vlanPcp = (byte) (vlanPcp & MASK);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800661 }
662
663 @Override
664 public Type type() {
665 return Type.VLAN_PCP;
666 }
667
668 /**
669 * Gets the VLAN priority to match.
670 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800671 * @return the VLAN priority to match (3 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800672 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800673 public byte priority() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800674 return vlanPcp;
675 }
676
677 @Override
678 public String toString() {
679 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800680 .add("priority", Long.toHexString(vlanPcp)).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800681 }
682
683 @Override
684 public int hashCode() {
685 return Objects.hash(type(), vlanPcp);
686 }
687
688 @Override
689 public boolean equals(Object obj) {
690 if (this == obj) {
691 return true;
692 }
693 if (obj instanceof VlanPcpCriterion) {
694 VlanPcpCriterion that = (VlanPcpCriterion) obj;
695 return Objects.equals(vlanPcp, that.vlanPcp) &&
696 Objects.equals(this.type(), that.type());
697 }
698 return false;
699 }
alshabib7b795492014-09-16 14:38:39 -0700700 }
701
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800702 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800703 * Implementation of IP DSCP (Differentiated Services Code Point)
704 * criterion (6 bits).
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800705 */
706 public static final class IPDscpCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800707 private static final byte MASK = 0x3f;
708 private final byte ipDscp; // IP DSCP value: 6 bits
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800709
710 /**
711 * Constructor.
712 *
713 * @param ipDscp the IP DSCP value to match
714 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800715 public IPDscpCriterion(byte ipDscp) {
716 this.ipDscp = (byte) (ipDscp & MASK);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800717 }
718
719 @Override
720 public Type type() {
721 return Type.IP_DSCP;
722 }
723
724 /**
725 * Gets the IP DSCP value to match.
726 *
727 * @return the IP DSCP value to match
728 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800729 public byte ipDscp() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800730 return ipDscp;
731 }
732
733 @Override
734 public String toString() {
735 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800736 .add("ipDscp", Long.toHexString(ipDscp)).toString();
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800737 }
738
739 @Override
740 public int hashCode() {
741 return Objects.hash(type(), ipDscp);
742 }
743
744 @Override
745 public boolean equals(Object obj) {
746 if (this == obj) {
747 return true;
748 }
749 if (obj instanceof IPDscpCriterion) {
750 IPDscpCriterion that = (IPDscpCriterion) obj;
751 return Objects.equals(ipDscp, that.ipDscp) &&
752 Objects.equals(this.type(), that.type());
753 }
754 return false;
755 }
756 }
757
758 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800759 * Implementation of IP ECN (Explicit Congestion Notification) criterion
760 * (3 bits).
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800761 */
762 public static final class IPEcnCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800763 private static final byte MASK = 0x7;
764 private final byte ipEcn; // IP ECN value: 3 bits
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800765
766 /**
767 * Constructor.
768 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800769 * @param ipEcn the IP ECN value to match (3 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800770 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800771 public IPEcnCriterion(byte ipEcn) {
772 this.ipEcn = (byte) (ipEcn & MASK);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800773 }
774
775 @Override
776 public Type type() {
777 return Type.IP_ECN;
778 }
779
780 /**
781 * Gets the IP ECN value to match.
782 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800783 * @return the IP ECN value to match (3 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800784 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800785 public byte ipEcn() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800786 return ipEcn;
787 }
788
789 @Override
790 public String toString() {
791 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800792 .add("ipEcn", Long.toHexString(ipEcn)).toString();
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800793 }
794
795 @Override
796 public int hashCode() {
797 return Objects.hash(type(), ipEcn);
798 }
799
800 @Override
801 public boolean equals(Object obj) {
802 if (this == obj) {
803 return true;
804 }
805 if (obj instanceof IPEcnCriterion) {
806 IPEcnCriterion that = (IPEcnCriterion) obj;
807 return Objects.equals(ipEcn, that.ipEcn) &&
808 Objects.equals(this.type(), that.type());
809 }
810 return false;
811 }
812 }
813
814 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800815 * Implementation of Internet Protocol Number criterion (8 bits unsigned)
816 * integer.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800817 */
alshabib7b795492014-09-16 14:38:39 -0700818 public static final class IPProtocolCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800819 private static final short MASK = 0xff;
820 private final short proto; // IP protocol number: 8 bits
alshabib7b795492014-09-16 14:38:39 -0700821
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800822 /**
823 * Constructor.
824 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800825 * @param protocol the IP protocol (e.g., TCP=6, UDP=17) to match
826 * (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800827 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800828 public IPProtocolCriterion(short protocol) {
829 this.proto = (short) (protocol & MASK);
alshabib7b795492014-09-16 14:38:39 -0700830 }
831
832 @Override
833 public Type type() {
834 return Type.IP_PROTO;
835 }
836
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800837 /**
838 * Gets the IP protocol to match.
839 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800840 * @return the IP protocol to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800841 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800842 public short protocol() {
alshabib7b795492014-09-16 14:38:39 -0700843 return proto;
844 }
845
alshabib99b8fdc2014-09-25 14:30:22 -0700846 @Override
847 public String toString() {
848 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800849 .add("protocol", proto).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700850 }
851
alshabibba5ac482014-10-02 17:15:20 -0700852 @Override
853 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800854 return Objects.hash(type(), proto);
alshabibba5ac482014-10-02 17:15:20 -0700855 }
856
857 @Override
858 public boolean equals(Object obj) {
859 if (this == obj) {
860 return true;
861 }
862 if (obj instanceof IPProtocolCriterion) {
863 IPProtocolCriterion that = (IPProtocolCriterion) obj;
864 return Objects.equals(proto, that.proto);
alshabibba5ac482014-10-02 17:15:20 -0700865 }
866 return false;
867 }
alshabib7b795492014-09-16 14:38:39 -0700868 }
869
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800870 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800871 * Implementation of IP address criterion.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800872 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800873 public static final class IPCriterion implements Criterion {
874 private final IpPrefix ip;
875 private final Type type;
alshabib7b795492014-09-16 14:38:39 -0700876
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800877 /**
878 * Constructor.
879 *
880 * @param ip the IP prefix to match. Could be either IPv4 or IPv6
881 * @param type the match type. Should be one of the following:
882 * Type.IPV4_SRC, Type.IPV4_DST, Type.IPV6_SRC, Type.IPV6_DST
883 */
884 public IPCriterion(IpPrefix ip, Type type) {
885 this.ip = ip;
886 this.type = type;
alshabib7b795492014-09-16 14:38:39 -0700887 }
888
889 @Override
890 public Type type() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800891 return this.type;
alshabib7b795492014-09-16 14:38:39 -0700892 }
893
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800894 /**
895 * Gets the IP prefix to match.
896 *
897 * @return the IP prefix to match
898 */
899 public IpPrefix ip() {
900 return this.ip;
alshabib7b795492014-09-16 14:38:39 -0700901 }
902
alshabib99b8fdc2014-09-25 14:30:22 -0700903 @Override
904 public String toString() {
905 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800906 .add("ip", ip).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700907 }
908
alshabibba5ac482014-10-02 17:15:20 -0700909 @Override
910 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800911 return Objects.hash(type, ip);
alshabibba5ac482014-10-02 17:15:20 -0700912 }
913
914 @Override
915 public boolean equals(Object obj) {
916 if (this == obj) {
917 return true;
918 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800919 if (obj instanceof IPCriterion) {
920 IPCriterion that = (IPCriterion) obj;
921 return Objects.equals(ip, that.ip) &&
922 Objects.equals(type, that.type);
alshabibba5ac482014-10-02 17:15:20 -0700923 }
924 return false;
925 }
alshabib7b795492014-09-16 14:38:39 -0700926 }
927
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800928 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800929 * Implementation of TCP port criterion (16 bits unsigned integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800930 */
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700931 public static final class TcpPortCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800932 private static final int MASK = 0xffff;
933 private final int tcpPort; // Port value: 16 bits
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700934 private final Type type;
935
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800936 /**
937 * Constructor.
938 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800939 * @param tcpPort the TCP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800940 * @param type the match type. Should be either Type.TCP_SRC or
941 * Type.TCP_DST
942 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800943 public TcpPortCriterion(int tcpPort, Type type) {
944 this.tcpPort = tcpPort & MASK;
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700945 this.type = type;
946 }
947
948 @Override
949 public Type type() {
950 return this.type;
951 }
952
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800953 /**
954 * Gets the TCP port to match.
955 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800956 * @return the TCP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800957 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800958 public int tcpPort() {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700959 return this.tcpPort;
960 }
961
962 @Override
963 public String toString() {
964 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800965 .add("tcpPort", tcpPort).toString();
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700966 }
967
968 @Override
969 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800970 return Objects.hash(type, tcpPort);
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700971 }
972
973 @Override
974 public boolean equals(Object obj) {
975 if (this == obj) {
976 return true;
977 }
978 if (obj instanceof TcpPortCriterion) {
979 TcpPortCriterion that = (TcpPortCriterion) obj;
980 return Objects.equals(tcpPort, that.tcpPort) &&
981 Objects.equals(type, that.type);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800982 }
983 return false;
984 }
985 }
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700986
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800987 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800988 * Implementation of UDP port criterion (16 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800989 */
990 public static final class UdpPortCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800991 private static final int MASK = 0xffff;
992 private final int udpPort; // Port value: 16 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800993 private final Type type;
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700994
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800995 /**
996 * Constructor.
997 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800998 * @param udpPort the UDP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800999 * @param type the match type. Should be either Type.UDP_SRC or
1000 * Type.UDP_DST
1001 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001002 public UdpPortCriterion(int udpPort, Type type) {
1003 this.udpPort = udpPort & MASK;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001004 this.type = type;
1005 }
1006
1007 @Override
1008 public Type type() {
1009 return this.type;
1010 }
1011
1012 /**
1013 * Gets the UDP port to match.
1014 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001015 * @return the UDP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001016 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001017 public int udpPort() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001018 return this.udpPort;
1019 }
1020
1021 @Override
1022 public String toString() {
1023 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001024 .add("udpPort", udpPort).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001025 }
1026
1027 @Override
1028 public int hashCode() {
1029 return Objects.hash(type, udpPort);
1030 }
1031
1032 @Override
1033 public boolean equals(Object obj) {
1034 if (this == obj) {
1035 return true;
1036 }
1037 if (obj instanceof UdpPortCriterion) {
1038 UdpPortCriterion that = (UdpPortCriterion) obj;
1039 return Objects.equals(udpPort, that.udpPort) &&
1040 Objects.equals(type, that.type);
1041 }
1042 return false;
1043 }
1044 }
1045
1046 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001047 * Implementation of SCTP port criterion (16 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001048 */
1049 public static final class SctpPortCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001050 private static final int MASK = 0xffff;
1051 private final int sctpPort; // Port value: 16 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001052 private final Type type;
1053
1054 /**
1055 * Constructor.
1056 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001057 * @param sctpPort the SCTP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001058 * @param type the match type. Should be either Type.SCTP_SRC or
1059 * Type.SCTP_DST
1060 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001061 public SctpPortCriterion(int sctpPort, Type type) {
1062 this.sctpPort = sctpPort & MASK;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001063 this.type = type;
1064 }
1065
1066 @Override
1067 public Type type() {
1068 return this.type;
1069 }
1070
1071 /**
1072 * Gets the SCTP port to match.
1073 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001074 * @return the SCTP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001075 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001076 public int sctpPort() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001077 return this.sctpPort;
1078 }
1079
1080 @Override
1081 public String toString() {
1082 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001083 .add("sctpPort", sctpPort).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001084 }
1085
1086 @Override
1087 public int hashCode() {
1088 return Objects.hash(type, sctpPort);
1089 }
1090
1091 @Override
1092 public boolean equals(Object obj) {
1093 if (this == obj) {
1094 return true;
1095 }
1096 if (obj instanceof SctpPortCriterion) {
1097 SctpPortCriterion that = (SctpPortCriterion) obj;
1098 return Objects.equals(sctpPort, that.sctpPort) &&
1099 Objects.equals(type, that.type);
1100 }
1101 return false;
1102 }
1103 }
1104
1105 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001106 * Implementation of ICMP type criterion (8 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001107 */
1108 public static final class IcmpTypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001109 private static final short MASK = 0xff;
1110 private final short icmpType; // The ICMP type: 8 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001111
1112 /**
1113 * Constructor.
1114 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001115 * @param icmpType the ICMP type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001116 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001117 public IcmpTypeCriterion(short icmpType) {
1118 this.icmpType = (short) (icmpType & MASK);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001119 }
1120
1121 @Override
1122 public Type type() {
1123 return Type.ICMPV4_TYPE;
1124 }
1125
1126 /**
1127 * Gets the ICMP type to match.
1128 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001129 * @return the ICMP type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001130 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001131 public short icmpType() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001132 return icmpType;
1133 }
1134
1135 @Override
1136 public String toString() {
1137 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001138 .add("icmpType", icmpType).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001139 }
1140
1141 @Override
1142 public int hashCode() {
1143 return Objects.hash(type(), icmpType);
1144 }
1145
1146 @Override
1147 public boolean equals(Object obj) {
1148 if (this == obj) {
1149 return true;
1150 }
1151 if (obj instanceof IcmpTypeCriterion) {
1152 IcmpTypeCriterion that = (IcmpTypeCriterion) obj;
1153 return Objects.equals(icmpType, that.icmpType) &&
1154 Objects.equals(this.type(), that.type());
1155 }
1156 return false;
1157 }
1158 }
1159
1160 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001161 * Implementation of ICMP code criterion (8 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001162 */
1163 public static final class IcmpCodeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001164 private static final short MASK = 0xff;
1165 private final short icmpCode; // The ICMP code: 8 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001166
1167 /**
1168 * Constructor.
1169 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001170 * @param icmpCode the ICMP code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001171 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001172 public IcmpCodeCriterion(short icmpCode) {
1173 this.icmpCode = (short) (icmpCode & MASK);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001174 }
1175
1176 @Override
1177 public Type type() {
1178 return Type.ICMPV4_CODE;
1179 }
1180
1181 /**
1182 * Gets the ICMP code to match.
1183 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001184 * @return the ICMP code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001185 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001186 public short icmpCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001187 return icmpCode;
1188 }
1189
1190 @Override
1191 public String toString() {
1192 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001193 .add("icmpCode", icmpCode).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001194 }
1195
1196 @Override
1197 public int hashCode() {
1198 return Objects.hash(type(), icmpCode);
1199 }
1200
1201 @Override
1202 public boolean equals(Object obj) {
1203 if (this == obj) {
1204 return true;
1205 }
1206 if (obj instanceof IcmpCodeCriterion) {
1207 IcmpCodeCriterion that = (IcmpCodeCriterion) obj;
1208 return Objects.equals(icmpCode, that.icmpCode) &&
1209 Objects.equals(this.type(), that.type());
1210 }
1211 return false;
1212 }
1213 }
1214
1215 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001216 * Implementation of IPv6 Flow Label (RFC 6437) criterion (20 bits unsigned
1217 * integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001218 */
1219 public static final class IPv6FlowLabelCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001220 private static final int MASK = 0xfffff;
1221 private final int flowLabel; // IPv6 flow label: 20 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001222
1223 /**
1224 * Constructor.
1225 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001226 * @param flowLabel the IPv6 flow label to match (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001227 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001228 public IPv6FlowLabelCriterion(int flowLabel) {
1229 this.flowLabel = flowLabel & MASK;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001230 }
1231
1232 @Override
1233 public Type type() {
1234 return Type.IPV6_FLABEL;
1235 }
1236
1237 /**
1238 * Gets the IPv6 flow label to match.
1239 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001240 * @return the IPv6 flow label to match (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001241 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001242 public int flowLabel() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001243 return flowLabel;
1244 }
1245
1246 @Override
1247 public String toString() {
1248 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001249 .add("flowLabel", Long.toHexString(flowLabel)).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001250 }
1251
1252 @Override
1253 public int hashCode() {
1254 return Objects.hash(type(), flowLabel);
1255 }
1256
1257 @Override
1258 public boolean equals(Object obj) {
1259 if (this == obj) {
1260 return true;
1261 }
1262 if (obj instanceof IPv6FlowLabelCriterion) {
1263 IPv6FlowLabelCriterion that = (IPv6FlowLabelCriterion) obj;
1264 return Objects.equals(flowLabel, that.flowLabel) &&
1265 Objects.equals(this.type(), that.type());
Toshio Koide9c44c9a2014-10-09 11:44:36 -07001266 }
1267 return false;
1268 }
1269 }
Marc De Leenheer49087752014-10-23 13:54:09 -07001270
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001271 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001272 * Implementation of ICMPv6 type criterion (8 bits unsigned integer).
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001273 */
1274 public static final class Icmpv6TypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001275 private static final short MASK = 0xff;
1276 private final short icmpv6Type; // ICMPv6 type: 8 bits
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001277
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001278 /**
1279 * Constructor.
1280 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001281 * @param icmpv6Type the ICMPv6 type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001282 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001283 public Icmpv6TypeCriterion(short icmpv6Type) {
1284 this.icmpv6Type = (short) (icmpv6Type & MASK);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001285 }
1286
1287 @Override
1288 public Type type() {
1289 return Type.ICMPV6_TYPE;
1290 }
1291
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001292 /**
1293 * Gets the ICMPv6 type to match.
1294 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001295 * @return the ICMPv6 type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001296 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001297 public short icmpv6Type() {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001298 return icmpv6Type;
1299 }
1300
1301 @Override
1302 public String toString() {
1303 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001304 .add("icmpv6Type", icmpv6Type).toString();
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001305 }
1306
1307 @Override
1308 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001309 return Objects.hash(type(), icmpv6Type);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001310 }
1311
1312 @Override
1313 public boolean equals(Object obj) {
1314 if (this == obj) {
1315 return true;
1316 }
1317 if (obj instanceof Icmpv6TypeCriterion) {
1318 Icmpv6TypeCriterion that = (Icmpv6TypeCriterion) obj;
1319 return Objects.equals(icmpv6Type, that.icmpv6Type) &&
1320 Objects.equals(this.type(), that.type());
1321 }
1322 return false;
1323 }
1324 }
1325
1326 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001327 * Implementation of ICMPv6 code criterion (8 bits unsigned integer).
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001328 */
1329 public static final class Icmpv6CodeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001330 private static final short MASK = 0xff;
1331 private final short icmpv6Code; // ICMPv6 code: 8 bits
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001332
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001333 /**
1334 * Constructor.
1335 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001336 * @param icmpv6Code the ICMPv6 code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001337 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001338 public Icmpv6CodeCriterion(short icmpv6Code) {
1339 this.icmpv6Code = (short) (icmpv6Code & MASK);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001340 }
1341
1342 @Override
1343 public Type type() {
1344 return Type.ICMPV6_CODE;
1345 }
1346
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001347 /**
1348 * Gets the ICMPv6 code to match.
1349 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001350 * @return the ICMPv6 code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001351 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001352 public short icmpv6Code() {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001353 return icmpv6Code;
1354 }
1355
1356 @Override
1357 public String toString() {
1358 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001359 .add("icmpv6Code", icmpv6Code).toString();
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001360 }
1361
1362 @Override
1363 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001364 return Objects.hash(type(), icmpv6Code);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001365 }
1366
1367 @Override
1368 public boolean equals(Object obj) {
1369 if (this == obj) {
1370 return true;
1371 }
1372 if (obj instanceof Icmpv6CodeCriterion) {
1373 Icmpv6CodeCriterion that = (Icmpv6CodeCriterion) obj;
1374 return Objects.equals(icmpv6Code, that.icmpv6Code) &&
1375 Objects.equals(this.type(), that.type());
1376 }
1377 return false;
1378 }
1379 }
1380
1381 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001382 * Implementation of IPv6 Neighbor Discovery target address criterion.
1383 */
1384 public static final class IPv6NDTargetAddressCriterion
1385 implements Criterion {
1386 private final Ip6Address targetAddress;
1387
1388 /**
1389 * Constructor.
1390 *
1391 * @param targetAddress the IPv6 target address to match
1392 */
1393 public IPv6NDTargetAddressCriterion(Ip6Address targetAddress) {
1394 this.targetAddress = targetAddress;
1395 }
1396
1397 @Override
1398 public Type type() {
1399 return Type.IPV6_ND_TARGET;
1400 }
1401
1402 /**
1403 * Gets the IPv6 target address to match.
1404 *
1405 * @return the IPv6 target address to match
1406 */
1407 public Ip6Address targetAddress() {
1408 return this.targetAddress;
1409 }
1410
1411 @Override
1412 public String toString() {
1413 return toStringHelper(type().toString())
1414 .add("targetAddress", targetAddress).toString();
1415 }
1416
1417 @Override
1418 public int hashCode() {
1419 return Objects.hash(type(), targetAddress);
1420 }
1421
1422 @Override
1423 public boolean equals(Object obj) {
1424 if (this == obj) {
1425 return true;
1426 }
1427 if (obj instanceof IPv6NDTargetAddressCriterion) {
1428 IPv6NDTargetAddressCriterion that =
1429 (IPv6NDTargetAddressCriterion) obj;
1430 return Objects.equals(targetAddress, that.targetAddress) &&
1431 Objects.equals(type(), that.type());
1432 }
1433 return false;
1434 }
1435 }
1436
1437 /**
1438 * Implementation of IPv6 Neighbor Discovery link-layer address criterion.
1439 */
1440 public static final class IPv6NDLinkLayerAddressCriterion
1441 implements Criterion {
1442 private final MacAddress mac;
1443 private final Type type;
1444
1445 /**
1446 * Constructor.
1447 *
1448 * @param mac the source or destination link-layer address to match
1449 * @param type the match type. Should be either Type.IPV6_ND_SLL or
1450 * Type.IPV6_ND_TLL
1451 */
1452 public IPv6NDLinkLayerAddressCriterion(MacAddress mac, Type type) {
1453 this.mac = mac;
1454 this.type = type;
1455 }
1456
1457 @Override
1458 public Type type() {
1459 return this.type;
1460 }
1461
1462 /**
1463 * Gets the MAC link-layer address to match.
1464 *
1465 * @return the MAC link-layer address to match
1466 */
1467 public MacAddress mac() {
1468 return this.mac;
1469 }
1470
1471 @Override
1472 public String toString() {
1473 return toStringHelper(type().toString())
1474 .add("mac", mac).toString();
1475 }
1476
1477 @Override
1478 public int hashCode() {
1479 return Objects.hash(type, mac);
1480 }
1481
1482 @Override
1483 public boolean equals(Object obj) {
1484 if (this == obj) {
1485 return true;
1486 }
1487 if (obj instanceof IPv6NDLinkLayerAddressCriterion) {
1488 IPv6NDLinkLayerAddressCriterion that =
1489 (IPv6NDLinkLayerAddressCriterion) obj;
1490 return Objects.equals(mac, that.mac) &&
1491 Objects.equals(type, that.type);
1492 }
1493 return false;
1494 }
1495 }
1496
1497 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001498 * Implementation of MPLS tag criterion (20 bits).
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001499 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001500 public static final class MplsCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001501 private static final int MASK = 0xfffff;
1502 private final int mplsLabel; // MPLS label: 20 bits
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001503
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001504 /**
1505 * Constructor.
1506 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001507 * @param mplsLabel the MPLS label to match (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001508 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001509 public MplsCriterion(int mplsLabel) {
1510 this.mplsLabel = mplsLabel & MASK;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001511 }
1512
1513 @Override
1514 public Type type() {
1515 return Type.MPLS_LABEL;
1516 }
1517
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001518 /**
1519 * Gets the MPLS label to match.
1520 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001521 * @return the MPLS label to match (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001522 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001523 public int label() {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001524 return mplsLabel;
1525 }
1526
1527 @Override
1528 public String toString() {
1529 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001530 .add("label", Long.toHexString(mplsLabel)).toString();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001531 }
1532
1533 @Override
1534 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001535 return Objects.hash(type(), mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001536 }
1537
1538 @Override
1539 public boolean equals(Object obj) {
1540 if (this == obj) {
1541 return true;
1542 }
1543 if (obj instanceof MplsCriterion) {
1544 MplsCriterion that = (MplsCriterion) obj;
1545 return Objects.equals(mplsLabel, that.mplsLabel) &&
1546 Objects.equals(this.type(), that.type());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001547 }
1548 return false;
1549 }
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001550 }
1551
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001552 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001553 * Implementation of lambda (wavelength) criterion (16 bits unsigned
1554 * integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001555 */
Marc De Leenheer49087752014-10-23 13:54:09 -07001556 public static final class LambdaCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001557 private static final int MASK = 0xffff;
1558 private final int lambda; // Lambda value: 16 bits
Marc De Leenheer49087752014-10-23 13:54:09 -07001559 private final Type type;
1560
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001561 /**
1562 * Constructor.
1563 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001564 * @param lambda the lambda (wavelength) to match (16 bits unsigned
1565 * integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001566 * @param type the match type. Should be Type.OCH_SIGID
1567 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001568 public LambdaCriterion(int lambda, Type type) {
1569 this.lambda = lambda & MASK;
Marc De Leenheer49087752014-10-23 13:54:09 -07001570 this.type = type;
1571 }
1572
1573 @Override
1574 public Type type() {
1575 return this.type;
1576 }
1577
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001578 /**
1579 * Gets the lambda (wavelength) to match.
1580 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001581 * @return the lambda (wavelength) to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001582 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001583 public int lambda() {
1584 return lambda;
Marc De Leenheer49087752014-10-23 13:54:09 -07001585 }
1586
1587 @Override
1588 public String toString() {
1589 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001590 .add("lambda", lambda).toString();
Marc De Leenheer49087752014-10-23 13:54:09 -07001591 }
1592
1593 @Override
1594 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -08001595 return Objects.hash(type, lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -07001596 }
1597
1598 @Override
1599 public boolean equals(Object obj) {
1600 if (this == obj) {
1601 return true;
1602 }
1603 if (obj instanceof LambdaCriterion) {
1604 LambdaCriterion that = (LambdaCriterion) obj;
1605 return Objects.equals(lambda, that.lambda) &&
1606 Objects.equals(type, that.type);
1607 }
1608 return false;
1609 }
1610 }
1611
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001612 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001613 * Implementation of optical signal type criterion (16 bits unsigned
1614 * integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001615 */
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001616 public static final class OpticalSignalTypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001617 private static final int MASK = 0xffff;
1618 private final int signalType; // Signal type value: 16 bits
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001619 private final Type type;
1620
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001621 /**
1622 * Constructor.
1623 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001624 * @param signalType the optical signal type to match (16 bits unsigned
1625 * integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001626 * @param type the match type. Should be Type.OCH_SIGTYPE
1627 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001628 public OpticalSignalTypeCriterion(int signalType, Type type) {
1629 this.signalType = signalType & MASK;
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001630 this.type = type;
1631 }
1632
1633 @Override
1634 public Type type() {
1635 return this.type;
1636 }
1637
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001638 /**
1639 * Gets the optical signal type to match.
1640 *
1641 * @return the optical signal type to match
1642 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001643 public int signalType() {
1644 return signalType;
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001645 }
1646
1647 @Override
1648 public String toString() {
1649 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001650 .add("signalType", signalType).toString();
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001651 }
1652
1653 @Override
1654 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -08001655 return Objects.hash(type, signalType);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001656 }
1657
1658 @Override
1659 public boolean equals(Object obj) {
1660 if (this == obj) {
1661 return true;
1662 }
1663 if (obj instanceof OpticalSignalTypeCriterion) {
1664 OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj;
1665 return Objects.equals(signalType, that.signalType) &&
1666 Objects.equals(type, that.type);
1667 }
1668 return false;
1669 }
1670 }
tom8bb16062014-09-12 14:47:46 -07001671}