blob: 34893a4f264cace03af8af2bfa2d792544777e78 [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 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -080065 public static Criterion matchMetadata(long metadata) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080066 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 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800341 public static Criterion matchMplsLabel(int mplsLabel) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800342 return new MplsCriterion(mplsLabel);
343 }
344
345 /**
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800346 * Creates a match on IPv6 Extension Header pseudo-field fiags.
347 * Those are defined in Criterion.IPv6ExthdrFlags.
348 *
349 * @param exthdrFlags IPv6 Extension Header pseudo-field flags (16 bits)
350 * @return match criterion
351 */
352 public static Criterion matchIPv6ExthdrFlags(int exthdrFlags) {
353 return new IPv6ExthdrFlagsCriterion(exthdrFlags);
354 }
355
356 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700357 * Creates a match on lambda field using the specified value.
358 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800359 * @param lambda lambda to match on (16 bits unsigned integer)
Marc De Leenheer49087752014-10-23 13:54:09 -0700360 * @return match criterion
361 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800362 public static Criterion matchLambda(int lambda) {
Marc De Leenheer49087752014-10-23 13:54:09 -0700363 return new LambdaCriterion(lambda, Type.OCH_SIGID);
364 }
365
366 /**
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800367 * Creates a match on optical signal type using the specified value.
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700368 *
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800369 * @param sigType optical signal type (8 bits unsigned integer)
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700370 * @return match criterion
371 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800372 public static Criterion matchOpticalSignalType(short sigType) {
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800373 return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700374 }
375
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700376 /**
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800377 * Implementation of input port criterion.
alshabib7b795492014-09-16 14:38:39 -0700378 */
alshabib7b795492014-09-16 14:38:39 -0700379 public static final class PortCriterion implements Criterion {
380 private final PortNumber port;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800381 private final Type type;
alshabib7b795492014-09-16 14:38:39 -0700382
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800383 /**
384 * Constructor.
385 *
386 * @param port the input port number to match
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800387 * @param type the match type. Should be either Type.IN_PORT or
388 * Type.IN_PHY_PORT
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800389 */
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800390 public PortCriterion(PortNumber port, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700391 this.port = port;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800392 this.type = type;
alshabib7b795492014-09-16 14:38:39 -0700393 }
394
395 @Override
396 public Type type() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800397 return this.type;
alshabib7b795492014-09-16 14:38:39 -0700398 }
399
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800400 /**
401 * Gets the input port number to match.
402 *
403 * @return the input port number to match
404 */
alshabib7b795492014-09-16 14:38:39 -0700405 public PortNumber port() {
406 return this.port;
407 }
alshabib99b8fdc2014-09-25 14:30:22 -0700408
409 @Override
410 public String toString() {
411 return toStringHelper(type().toString())
412 .add("port", port).toString();
413 }
alshabibba5ac482014-10-02 17:15:20 -0700414
415 @Override
416 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800417 return Objects.hash(type(), port);
alshabibba5ac482014-10-02 17:15:20 -0700418 }
419
420 @Override
421 public boolean equals(Object obj) {
422 if (this == obj) {
423 return true;
424 }
425 if (obj instanceof PortCriterion) {
426 PortCriterion that = (PortCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700427 return Objects.equals(port, that.port) &&
428 Objects.equals(this.type(), that.type());
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800429 }
430 return false;
431 }
432 }
alshabibba5ac482014-10-02 17:15:20 -0700433
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800434 /**
435 * Implementation of Metadata criterion.
436 */
437 public static final class MetadataCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800438 private final long metadata;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800439
440 /**
441 * Constructor.
442 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800443 * @param metadata the metadata to match (64 bits data)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800444 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800445 public MetadataCriterion(long metadata) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800446 this.metadata = metadata;
447 }
448
449 @Override
450 public Type type() {
451 return Type.METADATA;
452 }
453
454 /**
455 * Gets the metadata to match.
456 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800457 * @return the metadata to match (64 bits data)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800458 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800459 public long metadata() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800460 return metadata;
461 }
462
463 @Override
464 public String toString() {
465 return toStringHelper(type().toString())
466 .add("metadata", Long.toHexString(metadata))
467 .toString();
468 }
469
470 @Override
471 public int hashCode() {
472 return Objects.hash(type(), metadata);
473 }
474
475 @Override
476 public boolean equals(Object obj) {
477 if (this == obj) {
478 return true;
479 }
480 if (obj instanceof MetadataCriterion) {
481 MetadataCriterion that = (MetadataCriterion) obj;
482 return Objects.equals(metadata, that.metadata) &&
483 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700484 }
485 return false;
486 }
alshabib7b795492014-09-16 14:38:39 -0700487 }
488
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800489 /**
490 * Implementation of MAC address criterion.
491 */
alshabib7b795492014-09-16 14:38:39 -0700492 public static final class EthCriterion implements Criterion {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700493 private final MacAddress mac;
alshabib7b795492014-09-16 14:38:39 -0700494 private final Type type;
495
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800496 /**
497 * Constructor.
498 *
499 * @param mac the source or destination MAC address to match
500 * @param type the match type. Should be either Type.ETH_DST or
501 * Type.ETH_SRC
502 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700503 public EthCriterion(MacAddress mac, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700504 this.mac = mac;
505 this.type = type;
506 }
507
508 @Override
509 public Type type() {
510 return this.type;
511 }
512
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800513 /**
514 * Gets the MAC address to match.
515 *
516 * @return the MAC address to match
517 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700518 public MacAddress mac() {
alshabib7b795492014-09-16 14:38:39 -0700519 return this.mac;
520 }
alshabib99b8fdc2014-09-25 14:30:22 -0700521
522 @Override
523 public String toString() {
524 return toStringHelper(type().toString())
525 .add("mac", mac).toString();
526 }
527
alshabibba5ac482014-10-02 17:15:20 -0700528 @Override
529 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800530 return Objects.hash(type, mac);
alshabibba5ac482014-10-02 17:15:20 -0700531 }
532
533 @Override
534 public boolean equals(Object obj) {
535 if (this == obj) {
536 return true;
537 }
538 if (obj instanceof EthCriterion) {
539 EthCriterion that = (EthCriterion) obj;
540 return Objects.equals(mac, that.mac) &&
541 Objects.equals(type, that.type);
alshabibba5ac482014-10-02 17:15:20 -0700542 }
543 return false;
544 }
alshabib7b795492014-09-16 14:38:39 -0700545 }
546
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800547 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800548 * Implementation of Ethernet type criterion (16 bits unsigned integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800549 */
alshabib7b795492014-09-16 14:38:39 -0700550 public static final class EthTypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800551 private static final int MASK = 0xffff;
552 private final int ethType; // Ethernet type value: 16 bits
alshabib7b795492014-09-16 14:38:39 -0700553
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800554 /**
555 * Constructor.
556 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800557 * @param ethType the Ethernet frame type to match (16 bits unsigned
558 * integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800559 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800560 public EthTypeCriterion(int ethType) {
561 this.ethType = ethType & MASK;
alshabib7b795492014-09-16 14:38:39 -0700562 }
563
564 @Override
565 public Type type() {
566 return Type.ETH_TYPE;
567 }
568
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800569 /**
570 * Gets the Ethernet frame type to match.
571 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800572 * @return the Ethernet frame type to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800573 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800574 public int ethType() {
alshabib7b795492014-09-16 14:38:39 -0700575 return ethType;
576 }
577
alshabib99b8fdc2014-09-25 14:30:22 -0700578 @Override
579 public String toString() {
580 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800581 .add("ethType", Long.toHexString(ethType))
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800582 .toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700583 }
584
alshabibba5ac482014-10-02 17:15:20 -0700585 @Override
586 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800587 return Objects.hash(type(), ethType);
alshabibba5ac482014-10-02 17:15:20 -0700588 }
589
590 @Override
591 public boolean equals(Object obj) {
592 if (this == obj) {
593 return true;
594 }
595 if (obj instanceof EthTypeCriterion) {
596 EthTypeCriterion that = (EthTypeCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700597 return Objects.equals(ethType, that.ethType) &&
598 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700599 }
600 return false;
601 }
alshabib7b795492014-09-16 14:38:39 -0700602 }
603
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800604 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800605 * Implementation of VLAN ID criterion.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800606 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800607 public static final class VlanIdCriterion implements Criterion {
608 private final VlanId vlanId;
alshabib7b795492014-09-16 14:38:39 -0700609
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800610 /**
611 * Constructor.
612 *
613 * @param vlanId the VLAN ID to match
614 */
615 public VlanIdCriterion(VlanId vlanId) {
616 this.vlanId = vlanId;
alshabib7b795492014-09-16 14:38:39 -0700617 }
618
619 @Override
620 public Type type() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800621 return Type.VLAN_VID;
alshabib7b795492014-09-16 14:38:39 -0700622 }
623
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800624 /**
625 * Gets the VLAN ID to match.
626 *
627 * @return the VLAN ID to match
628 */
629 public VlanId vlanId() {
630 return vlanId;
alshabib7b795492014-09-16 14:38:39 -0700631 }
632
alshabib99b8fdc2014-09-25 14:30:22 -0700633 @Override
634 public String toString() {
635 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800636 .add("vlanId", vlanId).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700637 }
alshabib7b795492014-09-16 14:38:39 -0700638
alshabibba5ac482014-10-02 17:15:20 -0700639 @Override
640 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800641 return Objects.hash(type(), vlanId);
alshabibba5ac482014-10-02 17:15:20 -0700642 }
643
644 @Override
645 public boolean equals(Object obj) {
646 if (this == obj) {
647 return true;
648 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800649 if (obj instanceof VlanIdCriterion) {
650 VlanIdCriterion that = (VlanIdCriterion) obj;
651 return Objects.equals(vlanId, that.vlanId) &&
652 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700653 }
654 return false;
655 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800656 }
alshabibba5ac482014-10-02 17:15:20 -0700657
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800658 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800659 * Implementation of VLAN priority criterion (3 bits).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800660 */
661 public static final class VlanPcpCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800662 private static final byte MASK = 0x7;
663 private final byte vlanPcp; // VLAN pcp value: 3 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800664
665 /**
666 * Constructor.
667 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800668 * @param vlanPcp the VLAN priority to match (3 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800669 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800670 public VlanPcpCriterion(byte vlanPcp) {
671 this.vlanPcp = (byte) (vlanPcp & MASK);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800672 }
673
674 @Override
675 public Type type() {
676 return Type.VLAN_PCP;
677 }
678
679 /**
680 * Gets the VLAN priority to match.
681 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800682 * @return the VLAN priority to match (3 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800683 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800684 public byte priority() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800685 return vlanPcp;
686 }
687
688 @Override
689 public String toString() {
690 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800691 .add("priority", Long.toHexString(vlanPcp)).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800692 }
693
694 @Override
695 public int hashCode() {
696 return Objects.hash(type(), vlanPcp);
697 }
698
699 @Override
700 public boolean equals(Object obj) {
701 if (this == obj) {
702 return true;
703 }
704 if (obj instanceof VlanPcpCriterion) {
705 VlanPcpCriterion that = (VlanPcpCriterion) obj;
706 return Objects.equals(vlanPcp, that.vlanPcp) &&
707 Objects.equals(this.type(), that.type());
708 }
709 return false;
710 }
alshabib7b795492014-09-16 14:38:39 -0700711 }
712
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800713 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800714 * Implementation of IP DSCP (Differentiated Services Code Point)
715 * criterion (6 bits).
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800716 */
717 public static final class IPDscpCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800718 private static final byte MASK = 0x3f;
719 private final byte ipDscp; // IP DSCP value: 6 bits
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800720
721 /**
722 * Constructor.
723 *
724 * @param ipDscp the IP DSCP value to match
725 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800726 public IPDscpCriterion(byte ipDscp) {
727 this.ipDscp = (byte) (ipDscp & MASK);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800728 }
729
730 @Override
731 public Type type() {
732 return Type.IP_DSCP;
733 }
734
735 /**
736 * Gets the IP DSCP value to match.
737 *
738 * @return the IP DSCP value to match
739 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800740 public byte ipDscp() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800741 return ipDscp;
742 }
743
744 @Override
745 public String toString() {
746 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800747 .add("ipDscp", Long.toHexString(ipDscp)).toString();
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800748 }
749
750 @Override
751 public int hashCode() {
752 return Objects.hash(type(), ipDscp);
753 }
754
755 @Override
756 public boolean equals(Object obj) {
757 if (this == obj) {
758 return true;
759 }
760 if (obj instanceof IPDscpCriterion) {
761 IPDscpCriterion that = (IPDscpCriterion) obj;
762 return Objects.equals(ipDscp, that.ipDscp) &&
763 Objects.equals(this.type(), that.type());
764 }
765 return false;
766 }
767 }
768
769 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800770 * Implementation of IP ECN (Explicit Congestion Notification) criterion
771 * (3 bits).
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800772 */
773 public static final class IPEcnCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800774 private static final byte MASK = 0x7;
775 private final byte ipEcn; // IP ECN value: 3 bits
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800776
777 /**
778 * Constructor.
779 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800780 * @param ipEcn the IP ECN value to match (3 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800781 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800782 public IPEcnCriterion(byte ipEcn) {
783 this.ipEcn = (byte) (ipEcn & MASK);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800784 }
785
786 @Override
787 public Type type() {
788 return Type.IP_ECN;
789 }
790
791 /**
792 * Gets the IP ECN value to match.
793 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800794 * @return the IP ECN value to match (3 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800795 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800796 public byte ipEcn() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800797 return ipEcn;
798 }
799
800 @Override
801 public String toString() {
802 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800803 .add("ipEcn", Long.toHexString(ipEcn)).toString();
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800804 }
805
806 @Override
807 public int hashCode() {
808 return Objects.hash(type(), ipEcn);
809 }
810
811 @Override
812 public boolean equals(Object obj) {
813 if (this == obj) {
814 return true;
815 }
816 if (obj instanceof IPEcnCriterion) {
817 IPEcnCriterion that = (IPEcnCriterion) obj;
818 return Objects.equals(ipEcn, that.ipEcn) &&
819 Objects.equals(this.type(), that.type());
820 }
821 return false;
822 }
823 }
824
825 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800826 * Implementation of Internet Protocol Number criterion (8 bits unsigned)
827 * integer.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800828 */
alshabib7b795492014-09-16 14:38:39 -0700829 public static final class IPProtocolCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800830 private static final short MASK = 0xff;
831 private final short proto; // IP protocol number: 8 bits
alshabib7b795492014-09-16 14:38:39 -0700832
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800833 /**
834 * Constructor.
835 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800836 * @param protocol the IP protocol (e.g., TCP=6, UDP=17) to match
837 * (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800838 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800839 public IPProtocolCriterion(short protocol) {
840 this.proto = (short) (protocol & MASK);
alshabib7b795492014-09-16 14:38:39 -0700841 }
842
843 @Override
844 public Type type() {
845 return Type.IP_PROTO;
846 }
847
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800848 /**
849 * Gets the IP protocol to match.
850 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800851 * @return the IP protocol to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800852 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800853 public short protocol() {
alshabib7b795492014-09-16 14:38:39 -0700854 return proto;
855 }
856
alshabib99b8fdc2014-09-25 14:30:22 -0700857 @Override
858 public String toString() {
859 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800860 .add("protocol", proto).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700861 }
862
alshabibba5ac482014-10-02 17:15:20 -0700863 @Override
864 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800865 return Objects.hash(type(), proto);
alshabibba5ac482014-10-02 17:15:20 -0700866 }
867
868 @Override
869 public boolean equals(Object obj) {
870 if (this == obj) {
871 return true;
872 }
873 if (obj instanceof IPProtocolCriterion) {
874 IPProtocolCriterion that = (IPProtocolCriterion) obj;
875 return Objects.equals(proto, that.proto);
alshabibba5ac482014-10-02 17:15:20 -0700876 }
877 return false;
878 }
alshabib7b795492014-09-16 14:38:39 -0700879 }
880
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800881 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800882 * Implementation of IP address criterion.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800883 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800884 public static final class IPCriterion implements Criterion {
885 private final IpPrefix ip;
886 private final Type type;
alshabib7b795492014-09-16 14:38:39 -0700887
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800888 /**
889 * Constructor.
890 *
891 * @param ip the IP prefix to match. Could be either IPv4 or IPv6
892 * @param type the match type. Should be one of the following:
893 * Type.IPV4_SRC, Type.IPV4_DST, Type.IPV6_SRC, Type.IPV6_DST
894 */
895 public IPCriterion(IpPrefix ip, Type type) {
896 this.ip = ip;
897 this.type = type;
alshabib7b795492014-09-16 14:38:39 -0700898 }
899
900 @Override
901 public Type type() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800902 return this.type;
alshabib7b795492014-09-16 14:38:39 -0700903 }
904
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800905 /**
906 * Gets the IP prefix to match.
907 *
908 * @return the IP prefix to match
909 */
910 public IpPrefix ip() {
911 return this.ip;
alshabib7b795492014-09-16 14:38:39 -0700912 }
913
alshabib99b8fdc2014-09-25 14:30:22 -0700914 @Override
915 public String toString() {
916 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800917 .add("ip", ip).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700918 }
919
alshabibba5ac482014-10-02 17:15:20 -0700920 @Override
921 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800922 return Objects.hash(type, ip);
alshabibba5ac482014-10-02 17:15:20 -0700923 }
924
925 @Override
926 public boolean equals(Object obj) {
927 if (this == obj) {
928 return true;
929 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800930 if (obj instanceof IPCriterion) {
931 IPCriterion that = (IPCriterion) obj;
932 return Objects.equals(ip, that.ip) &&
933 Objects.equals(type, that.type);
alshabibba5ac482014-10-02 17:15:20 -0700934 }
935 return false;
936 }
alshabib7b795492014-09-16 14:38:39 -0700937 }
938
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800939 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800940 * Implementation of TCP port criterion (16 bits unsigned integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800941 */
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700942 public static final class TcpPortCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800943 private static final int MASK = 0xffff;
944 private final int tcpPort; // Port value: 16 bits
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700945 private final Type type;
946
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800947 /**
948 * Constructor.
949 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800950 * @param tcpPort the TCP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800951 * @param type the match type. Should be either Type.TCP_SRC or
952 * Type.TCP_DST
953 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800954 public TcpPortCriterion(int tcpPort, Type type) {
955 this.tcpPort = tcpPort & MASK;
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700956 this.type = type;
957 }
958
959 @Override
960 public Type type() {
961 return this.type;
962 }
963
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800964 /**
965 * Gets the TCP port to match.
966 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800967 * @return the TCP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800968 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800969 public int tcpPort() {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700970 return this.tcpPort;
971 }
972
973 @Override
974 public String toString() {
975 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800976 .add("tcpPort", tcpPort).toString();
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700977 }
978
979 @Override
980 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800981 return Objects.hash(type, tcpPort);
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700982 }
983
984 @Override
985 public boolean equals(Object obj) {
986 if (this == obj) {
987 return true;
988 }
989 if (obj instanceof TcpPortCriterion) {
990 TcpPortCriterion that = (TcpPortCriterion) obj;
991 return Objects.equals(tcpPort, that.tcpPort) &&
992 Objects.equals(type, that.type);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800993 }
994 return false;
995 }
996 }
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700997
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800998 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800999 * Implementation of UDP port criterion (16 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001000 */
1001 public static final class UdpPortCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001002 private static final int MASK = 0xffff;
1003 private final int udpPort; // Port value: 16 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001004 private final Type type;
Toshio Koide9c44c9a2014-10-09 11:44:36 -07001005
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001006 /**
1007 * Constructor.
1008 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001009 * @param udpPort the UDP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001010 * @param type the match type. Should be either Type.UDP_SRC or
1011 * Type.UDP_DST
1012 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001013 public UdpPortCriterion(int udpPort, Type type) {
1014 this.udpPort = udpPort & MASK;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001015 this.type = type;
1016 }
1017
1018 @Override
1019 public Type type() {
1020 return this.type;
1021 }
1022
1023 /**
1024 * Gets the UDP port to match.
1025 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001026 * @return the UDP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001027 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001028 public int udpPort() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001029 return this.udpPort;
1030 }
1031
1032 @Override
1033 public String toString() {
1034 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001035 .add("udpPort", udpPort).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001036 }
1037
1038 @Override
1039 public int hashCode() {
1040 return Objects.hash(type, udpPort);
1041 }
1042
1043 @Override
1044 public boolean equals(Object obj) {
1045 if (this == obj) {
1046 return true;
1047 }
1048 if (obj instanceof UdpPortCriterion) {
1049 UdpPortCriterion that = (UdpPortCriterion) obj;
1050 return Objects.equals(udpPort, that.udpPort) &&
1051 Objects.equals(type, that.type);
1052 }
1053 return false;
1054 }
1055 }
1056
1057 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001058 * Implementation of SCTP port criterion (16 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001059 */
1060 public static final class SctpPortCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001061 private static final int MASK = 0xffff;
1062 private final int sctpPort; // Port value: 16 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001063 private final Type type;
1064
1065 /**
1066 * Constructor.
1067 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001068 * @param sctpPort the SCTP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001069 * @param type the match type. Should be either Type.SCTP_SRC or
1070 * Type.SCTP_DST
1071 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001072 public SctpPortCriterion(int sctpPort, Type type) {
1073 this.sctpPort = sctpPort & MASK;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001074 this.type = type;
1075 }
1076
1077 @Override
1078 public Type type() {
1079 return this.type;
1080 }
1081
1082 /**
1083 * Gets the SCTP port to match.
1084 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001085 * @return the SCTP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001086 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001087 public int sctpPort() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001088 return this.sctpPort;
1089 }
1090
1091 @Override
1092 public String toString() {
1093 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001094 .add("sctpPort", sctpPort).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001095 }
1096
1097 @Override
1098 public int hashCode() {
1099 return Objects.hash(type, sctpPort);
1100 }
1101
1102 @Override
1103 public boolean equals(Object obj) {
1104 if (this == obj) {
1105 return true;
1106 }
1107 if (obj instanceof SctpPortCriterion) {
1108 SctpPortCriterion that = (SctpPortCriterion) obj;
1109 return Objects.equals(sctpPort, that.sctpPort) &&
1110 Objects.equals(type, that.type);
1111 }
1112 return false;
1113 }
1114 }
1115
1116 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001117 * Implementation of ICMP type criterion (8 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001118 */
1119 public static final class IcmpTypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001120 private static final short MASK = 0xff;
1121 private final short icmpType; // The ICMP type: 8 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001122
1123 /**
1124 * Constructor.
1125 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001126 * @param icmpType the ICMP type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001127 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001128 public IcmpTypeCriterion(short icmpType) {
1129 this.icmpType = (short) (icmpType & MASK);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001130 }
1131
1132 @Override
1133 public Type type() {
1134 return Type.ICMPV4_TYPE;
1135 }
1136
1137 /**
1138 * Gets the ICMP type to match.
1139 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001140 * @return the ICMP type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001141 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001142 public short icmpType() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001143 return icmpType;
1144 }
1145
1146 @Override
1147 public String toString() {
1148 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001149 .add("icmpType", icmpType).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001150 }
1151
1152 @Override
1153 public int hashCode() {
1154 return Objects.hash(type(), icmpType);
1155 }
1156
1157 @Override
1158 public boolean equals(Object obj) {
1159 if (this == obj) {
1160 return true;
1161 }
1162 if (obj instanceof IcmpTypeCriterion) {
1163 IcmpTypeCriterion that = (IcmpTypeCriterion) obj;
1164 return Objects.equals(icmpType, that.icmpType) &&
1165 Objects.equals(this.type(), that.type());
1166 }
1167 return false;
1168 }
1169 }
1170
1171 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001172 * Implementation of ICMP code criterion (8 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001173 */
1174 public static final class IcmpCodeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001175 private static final short MASK = 0xff;
1176 private final short icmpCode; // The ICMP code: 8 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001177
1178 /**
1179 * Constructor.
1180 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001181 * @param icmpCode the ICMP code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001182 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001183 public IcmpCodeCriterion(short icmpCode) {
1184 this.icmpCode = (short) (icmpCode & MASK);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001185 }
1186
1187 @Override
1188 public Type type() {
1189 return Type.ICMPV4_CODE;
1190 }
1191
1192 /**
1193 * Gets the ICMP code to match.
1194 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001195 * @return the ICMP code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001196 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001197 public short icmpCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001198 return icmpCode;
1199 }
1200
1201 @Override
1202 public String toString() {
1203 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001204 .add("icmpCode", icmpCode).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001205 }
1206
1207 @Override
1208 public int hashCode() {
1209 return Objects.hash(type(), icmpCode);
1210 }
1211
1212 @Override
1213 public boolean equals(Object obj) {
1214 if (this == obj) {
1215 return true;
1216 }
1217 if (obj instanceof IcmpCodeCriterion) {
1218 IcmpCodeCriterion that = (IcmpCodeCriterion) obj;
1219 return Objects.equals(icmpCode, that.icmpCode) &&
1220 Objects.equals(this.type(), that.type());
1221 }
1222 return false;
1223 }
1224 }
1225
1226 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001227 * Implementation of IPv6 Flow Label (RFC 6437) criterion (20 bits unsigned
1228 * integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001229 */
1230 public static final class IPv6FlowLabelCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001231 private static final int MASK = 0xfffff;
1232 private final int flowLabel; // IPv6 flow label: 20 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001233
1234 /**
1235 * Constructor.
1236 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001237 * @param flowLabel the IPv6 flow label to match (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001238 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001239 public IPv6FlowLabelCriterion(int flowLabel) {
1240 this.flowLabel = flowLabel & MASK;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001241 }
1242
1243 @Override
1244 public Type type() {
1245 return Type.IPV6_FLABEL;
1246 }
1247
1248 /**
1249 * Gets the IPv6 flow label to match.
1250 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001251 * @return the IPv6 flow label to match (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001252 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001253 public int flowLabel() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001254 return flowLabel;
1255 }
1256
1257 @Override
1258 public String toString() {
1259 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001260 .add("flowLabel", Long.toHexString(flowLabel)).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001261 }
1262
1263 @Override
1264 public int hashCode() {
1265 return Objects.hash(type(), flowLabel);
1266 }
1267
1268 @Override
1269 public boolean equals(Object obj) {
1270 if (this == obj) {
1271 return true;
1272 }
1273 if (obj instanceof IPv6FlowLabelCriterion) {
1274 IPv6FlowLabelCriterion that = (IPv6FlowLabelCriterion) obj;
1275 return Objects.equals(flowLabel, that.flowLabel) &&
1276 Objects.equals(this.type(), that.type());
Toshio Koide9c44c9a2014-10-09 11:44:36 -07001277 }
1278 return false;
1279 }
1280 }
Marc De Leenheer49087752014-10-23 13:54:09 -07001281
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001282 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001283 * Implementation of ICMPv6 type criterion (8 bits unsigned integer).
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001284 */
1285 public static final class Icmpv6TypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001286 private static final short MASK = 0xff;
1287 private final short icmpv6Type; // ICMPv6 type: 8 bits
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001288
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001289 /**
1290 * Constructor.
1291 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001292 * @param icmpv6Type the ICMPv6 type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001293 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001294 public Icmpv6TypeCriterion(short icmpv6Type) {
1295 this.icmpv6Type = (short) (icmpv6Type & MASK);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001296 }
1297
1298 @Override
1299 public Type type() {
1300 return Type.ICMPV6_TYPE;
1301 }
1302
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001303 /**
1304 * Gets the ICMPv6 type to match.
1305 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001306 * @return the ICMPv6 type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001307 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001308 public short icmpv6Type() {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001309 return icmpv6Type;
1310 }
1311
1312 @Override
1313 public String toString() {
1314 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001315 .add("icmpv6Type", icmpv6Type).toString();
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001316 }
1317
1318 @Override
1319 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001320 return Objects.hash(type(), icmpv6Type);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001321 }
1322
1323 @Override
1324 public boolean equals(Object obj) {
1325 if (this == obj) {
1326 return true;
1327 }
1328 if (obj instanceof Icmpv6TypeCriterion) {
1329 Icmpv6TypeCriterion that = (Icmpv6TypeCriterion) obj;
1330 return Objects.equals(icmpv6Type, that.icmpv6Type) &&
1331 Objects.equals(this.type(), that.type());
1332 }
1333 return false;
1334 }
1335 }
1336
1337 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001338 * Implementation of ICMPv6 code criterion (8 bits unsigned integer).
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001339 */
1340 public static final class Icmpv6CodeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001341 private static final short MASK = 0xff;
1342 private final short icmpv6Code; // ICMPv6 code: 8 bits
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001343
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001344 /**
1345 * Constructor.
1346 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001347 * @param icmpv6Code the ICMPv6 code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001348 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001349 public Icmpv6CodeCriterion(short icmpv6Code) {
1350 this.icmpv6Code = (short) (icmpv6Code & MASK);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001351 }
1352
1353 @Override
1354 public Type type() {
1355 return Type.ICMPV6_CODE;
1356 }
1357
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001358 /**
1359 * Gets the ICMPv6 code to match.
1360 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001361 * @return the ICMPv6 code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001362 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001363 public short icmpv6Code() {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001364 return icmpv6Code;
1365 }
1366
1367 @Override
1368 public String toString() {
1369 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001370 .add("icmpv6Code", icmpv6Code).toString();
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001371 }
1372
1373 @Override
1374 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001375 return Objects.hash(type(), icmpv6Code);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001376 }
1377
1378 @Override
1379 public boolean equals(Object obj) {
1380 if (this == obj) {
1381 return true;
1382 }
1383 if (obj instanceof Icmpv6CodeCriterion) {
1384 Icmpv6CodeCriterion that = (Icmpv6CodeCriterion) obj;
1385 return Objects.equals(icmpv6Code, that.icmpv6Code) &&
1386 Objects.equals(this.type(), that.type());
1387 }
1388 return false;
1389 }
1390 }
1391
1392 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001393 * Implementation of IPv6 Neighbor Discovery target address criterion.
1394 */
1395 public static final class IPv6NDTargetAddressCriterion
1396 implements Criterion {
1397 private final Ip6Address targetAddress;
1398
1399 /**
1400 * Constructor.
1401 *
1402 * @param targetAddress the IPv6 target address to match
1403 */
1404 public IPv6NDTargetAddressCriterion(Ip6Address targetAddress) {
1405 this.targetAddress = targetAddress;
1406 }
1407
1408 @Override
1409 public Type type() {
1410 return Type.IPV6_ND_TARGET;
1411 }
1412
1413 /**
1414 * Gets the IPv6 target address to match.
1415 *
1416 * @return the IPv6 target address to match
1417 */
1418 public Ip6Address targetAddress() {
1419 return this.targetAddress;
1420 }
1421
1422 @Override
1423 public String toString() {
1424 return toStringHelper(type().toString())
1425 .add("targetAddress", targetAddress).toString();
1426 }
1427
1428 @Override
1429 public int hashCode() {
1430 return Objects.hash(type(), targetAddress);
1431 }
1432
1433 @Override
1434 public boolean equals(Object obj) {
1435 if (this == obj) {
1436 return true;
1437 }
1438 if (obj instanceof IPv6NDTargetAddressCriterion) {
1439 IPv6NDTargetAddressCriterion that =
1440 (IPv6NDTargetAddressCriterion) obj;
1441 return Objects.equals(targetAddress, that.targetAddress) &&
1442 Objects.equals(type(), that.type());
1443 }
1444 return false;
1445 }
1446 }
1447
1448 /**
1449 * Implementation of IPv6 Neighbor Discovery link-layer address criterion.
1450 */
1451 public static final class IPv6NDLinkLayerAddressCriterion
1452 implements Criterion {
1453 private final MacAddress mac;
1454 private final Type type;
1455
1456 /**
1457 * Constructor.
1458 *
1459 * @param mac the source or destination link-layer address to match
1460 * @param type the match type. Should be either Type.IPV6_ND_SLL or
1461 * Type.IPV6_ND_TLL
1462 */
1463 public IPv6NDLinkLayerAddressCriterion(MacAddress mac, Type type) {
1464 this.mac = mac;
1465 this.type = type;
1466 }
1467
1468 @Override
1469 public Type type() {
1470 return this.type;
1471 }
1472
1473 /**
1474 * Gets the MAC link-layer address to match.
1475 *
1476 * @return the MAC link-layer address to match
1477 */
1478 public MacAddress mac() {
1479 return this.mac;
1480 }
1481
1482 @Override
1483 public String toString() {
1484 return toStringHelper(type().toString())
1485 .add("mac", mac).toString();
1486 }
1487
1488 @Override
1489 public int hashCode() {
1490 return Objects.hash(type, mac);
1491 }
1492
1493 @Override
1494 public boolean equals(Object obj) {
1495 if (this == obj) {
1496 return true;
1497 }
1498 if (obj instanceof IPv6NDLinkLayerAddressCriterion) {
1499 IPv6NDLinkLayerAddressCriterion that =
1500 (IPv6NDLinkLayerAddressCriterion) obj;
1501 return Objects.equals(mac, that.mac) &&
1502 Objects.equals(type, that.type);
1503 }
1504 return false;
1505 }
1506 }
1507
1508 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001509 * Implementation of MPLS tag criterion (20 bits).
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001510 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001511 public static final class MplsCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001512 private static final int MASK = 0xfffff;
1513 private final int mplsLabel; // MPLS label: 20 bits
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001514
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001515 /**
1516 * Constructor.
1517 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001518 * @param mplsLabel the MPLS label to match (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001519 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001520 public MplsCriterion(int mplsLabel) {
1521 this.mplsLabel = mplsLabel & MASK;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001522 }
1523
1524 @Override
1525 public Type type() {
1526 return Type.MPLS_LABEL;
1527 }
1528
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001529 /**
1530 * Gets the MPLS label to match.
1531 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001532 * @return the MPLS label to match (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001533 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001534 public int label() {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001535 return mplsLabel;
1536 }
1537
1538 @Override
1539 public String toString() {
1540 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001541 .add("label", Long.toHexString(mplsLabel)).toString();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001542 }
1543
1544 @Override
1545 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001546 return Objects.hash(type(), mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001547 }
1548
1549 @Override
1550 public boolean equals(Object obj) {
1551 if (this == obj) {
1552 return true;
1553 }
1554 if (obj instanceof MplsCriterion) {
1555 MplsCriterion that = (MplsCriterion) obj;
1556 return Objects.equals(mplsLabel, that.mplsLabel) &&
1557 Objects.equals(this.type(), that.type());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001558 }
1559 return false;
1560 }
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001561 }
1562
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001563 /**
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001564 * Implementation of IPv6 Extension Header pseudo-field criterion
1565 * (16 bits). Those are defined in Criterion.IPv6ExthdrFlags.
1566 */
1567 public static final class IPv6ExthdrFlagsCriterion implements Criterion {
1568 private static final int MASK = 0xffff;
1569 private final int exthdrFlags; // IPv6 Exthdr flags: 16 bits
1570
1571 /**
1572 * Constructor.
1573 *
1574 * @param exthdrFlags the IPv6 Extension Header pseudo-field flags
1575 * to match (16 bits). Those are defined in Criterion.IPv6ExthdrFlags
1576 */
1577 public IPv6ExthdrFlagsCriterion(int exthdrFlags) {
1578 this.exthdrFlags = exthdrFlags & MASK;
1579 }
1580
1581 @Override
1582 public Type type() {
1583 return Type.IPV6_EXTHDR;
1584 }
1585
1586 /**
1587 * Gets the IPv6 Extension Header pseudo-field flags to match.
1588 *
1589 * @return the IPv6 Extension Header pseudo-field flags to match
1590 * (16 bits). Those are defined in Criterion.IPv6ExthdrFlags
1591 */
1592 public int exthdrFlags() {
1593 return exthdrFlags;
1594 }
1595
1596 @Override
1597 public String toString() {
1598 return toStringHelper(type().toString())
1599 .add("exthdrFlags", Long.toHexString(exthdrFlags)).toString();
1600 }
1601
1602 @Override
1603 public int hashCode() {
1604 return Objects.hash(type(), exthdrFlags);
1605 }
1606
1607 @Override
1608 public boolean equals(Object obj) {
1609 if (this == obj) {
1610 return true;
1611 }
1612 if (obj instanceof IPv6ExthdrFlagsCriterion) {
1613 IPv6ExthdrFlagsCriterion that = (IPv6ExthdrFlagsCriterion) obj;
1614 return Objects.equals(exthdrFlags, that.exthdrFlags) &&
1615 Objects.equals(this.type(), that.type());
1616 }
1617 return false;
1618 }
1619 }
1620
1621 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001622 * Implementation of lambda (wavelength) criterion (16 bits unsigned
1623 * integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001624 */
Marc De Leenheer49087752014-10-23 13:54:09 -07001625 public static final class LambdaCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001626 private static final int MASK = 0xffff;
1627 private final int lambda; // Lambda value: 16 bits
Marc De Leenheer49087752014-10-23 13:54:09 -07001628 private final Type type;
1629
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001630 /**
1631 * Constructor.
1632 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001633 * @param lambda the lambda (wavelength) to match (16 bits unsigned
1634 * integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001635 * @param type the match type. Should be Type.OCH_SIGID
1636 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001637 public LambdaCriterion(int lambda, Type type) {
1638 this.lambda = lambda & MASK;
Marc De Leenheer49087752014-10-23 13:54:09 -07001639 this.type = type;
1640 }
1641
1642 @Override
1643 public Type type() {
1644 return this.type;
1645 }
1646
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001647 /**
1648 * Gets the lambda (wavelength) to match.
1649 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001650 * @return the lambda (wavelength) to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001651 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001652 public int lambda() {
1653 return lambda;
Marc De Leenheer49087752014-10-23 13:54:09 -07001654 }
1655
1656 @Override
1657 public String toString() {
1658 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001659 .add("lambda", lambda).toString();
Marc De Leenheer49087752014-10-23 13:54:09 -07001660 }
1661
1662 @Override
1663 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -08001664 return Objects.hash(type, lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -07001665 }
1666
1667 @Override
1668 public boolean equals(Object obj) {
1669 if (this == obj) {
1670 return true;
1671 }
1672 if (obj instanceof LambdaCriterion) {
1673 LambdaCriterion that = (LambdaCriterion) obj;
1674 return Objects.equals(lambda, that.lambda) &&
1675 Objects.equals(type, that.type);
1676 }
1677 return false;
1678 }
1679 }
1680
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001681 /**
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001682 * Implementation of optical signal type criterion (8 bits unsigned
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001683 * integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001684 */
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001685 public static final class OpticalSignalTypeCriterion implements Criterion {
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001686 private static final short MASK = 0xff;
1687 private final short signalType; // Signal type value: 8 bits
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001688 private final Type type;
1689
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001690 /**
1691 * Constructor.
1692 *
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001693 * @param signalType the optical signal type to match (8 bits unsigned
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001694 * integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001695 * @param type the match type. Should be Type.OCH_SIGTYPE
1696 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001697 public OpticalSignalTypeCriterion(short signalType, Type type) {
1698 this.signalType = (short) (signalType & MASK);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001699 this.type = type;
1700 }
1701
1702 @Override
1703 public Type type() {
1704 return this.type;
1705 }
1706
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001707 /**
1708 * Gets the optical signal type to match.
1709 *
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001710 * @return the optical signal type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001711 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001712 public short signalType() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001713 return signalType;
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001714 }
1715
1716 @Override
1717 public String toString() {
1718 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001719 .add("signalType", signalType).toString();
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001720 }
1721
1722 @Override
1723 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -08001724 return Objects.hash(type, signalType);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001725 }
1726
1727 @Override
1728 public boolean equals(Object obj) {
1729 if (this == obj) {
1730 return true;
1731 }
1732 if (obj instanceof OpticalSignalTypeCriterion) {
1733 OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj;
1734 return Objects.equals(signalType, that.signalType) &&
1735 Objects.equals(type, that.type);
1736 }
1737 return false;
1738 }
1739 }
tom8bb16062014-09-12 14:47:46 -07001740}