blob: a63e245a0248357af91095f1bec06708e46c1e9d [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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;
Michele Santuari4b6019e2014-12-19 11:31:45 +010021
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.PortNumber;
23import org.onosproject.net.flow.criteria.Criterion.Type;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070024import org.onlab.packet.IpPrefix;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080025import org.onlab.packet.Ip6Address;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070026import org.onlab.packet.MacAddress;
Michele Santuari4b6019e2014-12-19 11:31:45 +010027import org.onlab.packet.MplsLabel;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070028import org.onlab.packet.VlanId;
alshabib7b795492014-09-16 14:38:39 -070029
tom8bb16062014-09-12 14:47:46 -070030/**
31 * Factory class to create various traffic selection criteria.
32 */
33public final class Criteria {
34
alshabib7b795492014-09-16 14:38:39 -070035 //TODO: incomplete type implementation. Need to implement complete list from Criterion
36
tom8bb16062014-09-12 14:47:46 -070037 // Ban construction
38 private Criteria() {
39 }
40
41 /**
alshabib7b795492014-09-16 14:38:39 -070042 * Creates a match on IN_PORT field using the specified value.
43 *
44 * @param port inport value
45 * @return match criterion
46 */
47 public static Criterion matchInPort(PortNumber port) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080048 return new PortCriterion(port, Type.IN_PORT);
49 }
50
51 /**
52 * Creates a match on IN_PHY_PORT field using the specified value.
53 *
54 * @param port inport value
55 * @return match criterion
56 */
57 public static Criterion matchInPhyPort(PortNumber port) {
58 return new PortCriterion(port, Type.IN_PHY_PORT);
59 }
60
61 /**
62 * Creates a match on METADATA field using the specified value.
63 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080064 * @param metadata metadata value (64 bits data)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080065 * @return match criterion
66 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -080067 public static Criterion matchMetadata(long metadata) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -080068 return new MetadataCriterion(metadata);
alshabib7b795492014-09-16 14:38:39 -070069 }
70
71 /**
alshabib369d2942014-09-12 17:59:35 -070072 * Creates a match on ETH_DST field using the specified value. This value
73 * may be a wildcard mask.
74 *
tomc104d282014-09-19 10:57:55 -070075 * @param mac MAC address value or wildcard mask
alshabib369d2942014-09-12 17:59:35 -070076 * @return match criterion
77 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070078 public static Criterion matchEthDst(MacAddress mac) {
alshabib7b795492014-09-16 14:38:39 -070079 return new EthCriterion(mac, Type.ETH_DST);
80 }
81
82 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -080083 * Creates a match on ETH_SRC field using the specified value. This value
84 * may be a wildcard mask.
85 *
86 * @param mac MAC address value or wildcard mask
87 * @return match criterion
88 */
89 public static Criterion matchEthSrc(MacAddress mac) {
90 return new EthCriterion(mac, Type.ETH_SRC);
91 }
92
93 /**
alshabib7b795492014-09-16 14:38:39 -070094 * Creates a match on ETH_TYPE field using the specified value.
95 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080096 * @param ethType eth type value (16 bits unsigned integer)
alshabib7b795492014-09-16 14:38:39 -070097 * @return match criterion
98 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -080099 public static Criterion matchEthType(int ethType) {
alshabib7b795492014-09-16 14:38:39 -0700100 return new EthTypeCriterion(ethType);
101 }
102
103 /**
104 * Creates a match on VLAN ID field using the specified value.
105 *
106 * @param vlanId vlan id value
107 * @return match criterion
108 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700109 public static Criterion matchVlanId(VlanId vlanId) {
alshabib7b795492014-09-16 14:38:39 -0700110 return new VlanIdCriterion(vlanId);
111 }
112
113 /**
114 * Creates a match on VLAN PCP field using the specified value.
115 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800116 * @param vlanPcp vlan pcp value (3 bits)
alshabib7b795492014-09-16 14:38:39 -0700117 * @return match criterion
118 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800119 public static Criterion matchVlanPcp(byte vlanPcp) {
alshabib7b795492014-09-16 14:38:39 -0700120 return new VlanPcpCriterion(vlanPcp);
121 }
122
123 /**
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800124 * Creates a match on IP DSCP field using the specified value.
125 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800126 * @param ipDscp ip dscp value (6 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800127 * @return match criterion
128 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800129 public static Criterion matchIPDscp(byte ipDscp) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800130 return new IPDscpCriterion(ipDscp);
131 }
132
133 /**
134 * Creates a match on IP ECN field using the specified value.
135 *
Pavlin Radoslavovab8553a2015-02-20 14:13:50 -0800136 * @param ipEcn ip ecn value (2 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800137 * @return match criterion
138 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800139 public static Criterion matchIPEcn(byte ipEcn) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800140 return new IPEcnCriterion(ipEcn);
141 }
142
143 /**
alshabib7b795492014-09-16 14:38:39 -0700144 * Creates a match on IP proto field using the specified value.
145 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800146 * @param proto ip protocol value (8 bits unsigned integer)
alshabib7b795492014-09-16 14:38:39 -0700147 * @return match criterion
148 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800149 public static Criterion matchIPProtocol(short proto) {
alshabib7b795492014-09-16 14:38:39 -0700150 return new IPProtocolCriterion(proto);
151 }
152
153 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800154 * Creates a match on IPv4 source field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700155 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800156 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700157 * @return match criterion
158 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700159 public static Criterion matchIPSrc(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700160 return new IPCriterion(ip, Type.IPV4_SRC);
161 }
162
163 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800164 * Creates a match on IPv4 destination field using the specified value.
alshabib7b795492014-09-16 14:38:39 -0700165 *
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800166 * @param ip ipv4 source value
alshabib7b795492014-09-16 14:38:39 -0700167 * @return match criterion
168 */
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -0700169 public static Criterion matchIPDst(IpPrefix ip) {
alshabib7b795492014-09-16 14:38:39 -0700170 return new IPCriterion(ip, Type.IPV4_DST);
alshabib369d2942014-09-12 17:59:35 -0700171 }
172
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700173 /**
174 * Creates a match on TCP source port field using the specified value.
175 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800176 * @param tcpPort TCP source port (16 bits unsigned integer)
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700177 * @return match criterion
178 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800179 public static Criterion matchTcpSrc(int tcpPort) {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700180 return new TcpPortCriterion(tcpPort, Type.TCP_SRC);
181 }
182
183 /**
184 * Creates a match on TCP destination port field using the specified value.
185 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800186 * @param tcpPort TCP destination port (16 bits unsigned integer)
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700187 * @return match criterion
188 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800189 public static Criterion matchTcpDst(int tcpPort) {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700190 return new TcpPortCriterion(tcpPort, Type.TCP_DST);
191 }
alshabib369d2942014-09-12 17:59:35 -0700192
Marc De Leenheer49087752014-10-23 13:54:09 -0700193 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800194 * Creates a match on UDP source port field using the specified value.
195 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800196 * @param udpPort UDP source port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800197 * @return match criterion
198 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800199 public static Criterion matchUdpSrc(int udpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800200 return new UdpPortCriterion(udpPort, Type.UDP_SRC);
201 }
202
203 /**
204 * Creates a match on UDP destination port field using the specified value.
205 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800206 * @param udpPort UDP destination port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800207 * @return match criterion
208 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800209 public static Criterion matchUdpDst(int udpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800210 return new UdpPortCriterion(udpPort, Type.UDP_DST);
211 }
212
213 /**
214 * Creates a match on SCTP source port field using the specified value.
215 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800216 * @param sctpPort SCTP source port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800217 * @return match criterion
218 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800219 public static Criterion matchSctpSrc(int sctpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800220 return new SctpPortCriterion(sctpPort, Type.SCTP_SRC);
221 }
222
223 /**
224 * Creates a match on SCTP destination port field using the specified
225 * value.
226 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800227 * @param sctpPort SCTP destination port (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800228 * @return match criterion
229 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800230 public static Criterion matchSctpDst(int sctpPort) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800231 return new SctpPortCriterion(sctpPort, Type.SCTP_DST);
232 }
233
234 /**
235 * Creates a match on ICMP type field using the specified value.
236 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800237 * @param icmpType ICMP type (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800238 * @return match criterion
239 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800240 public static Criterion matchIcmpType(short icmpType) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800241 return new IcmpTypeCriterion(icmpType);
242 }
243
244 /**
245 * Creates a match on ICMP code field using the specified value.
246 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800247 * @param icmpCode ICMP code (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800248 * @return match criterion
249 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800250 public static Criterion matchIcmpCode(short icmpCode) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800251 return new IcmpCodeCriterion(icmpCode);
252 }
253
254 /**
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800255 * Creates a match on IPv6 source field using the specified value.
256 *
257 * @param ip ipv6 source value
258 * @return match criterion
259 */
260 public static Criterion matchIPv6Src(IpPrefix ip) {
261 return new IPCriterion(ip, Type.IPV6_SRC);
262 }
263
264 /**
265 * Creates a match on IPv6 destination field using the specified value.
266 *
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800267 * @param ip ipv6 destination value
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800268 * @return match criterion
269 */
270 public static Criterion matchIPv6Dst(IpPrefix ip) {
271 return new IPCriterion(ip, Type.IPV6_DST);
272 }
273
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800274 /**
275 * Creates a match on IPv6 flow label field using the specified value.
276 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800277 * @param flowLabel IPv6 flow label (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800278 * @return match criterion
279 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800280 public static Criterion matchIPv6FlowLabel(int flowLabel) {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800281 return new IPv6FlowLabelCriterion(flowLabel);
282 }
283
284 /**
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800285 * Creates a match on ICMPv6 type field using the specified value.
286 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800287 * @param icmpv6Type ICMPv6 type (8 bits unsigned integer)
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800288 * @return match criterion
289 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800290 public static Criterion matchIcmpv6Type(short icmpv6Type) {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800291 return new Icmpv6TypeCriterion(icmpv6Type);
292 }
293
294 /**
295 * Creates a match on ICMPv6 code field using the specified value.
296 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800297 * @param icmpv6Code ICMPv6 code (8 bits unsigned integer)
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800298 * @return match criterion
299 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800300 public static Criterion matchIcmpv6Code(short icmpv6Code) {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -0800301 return new Icmpv6CodeCriterion(icmpv6Code);
302 }
303
Charles M.C. Chan52fae7d2015-01-17 00:35:53 +0800304 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800305 * Creates a match on IPv6 Neighbor Discovery target address using the
306 * specified value.
307 *
308 * @param targetAddress IPv6 Neighbor Discovery target address
309 * @return match criterion
310 */
311 public static Criterion matchIPv6NDTargetAddress(Ip6Address targetAddress) {
312 return new IPv6NDTargetAddressCriterion(targetAddress);
313 }
314
315 /**
316 * Creates a match on IPv6 Neighbor Discovery source link-layer address
317 * using the specified value.
318 *
319 * @param mac IPv6 Neighbor Discovery source link-layer address
320 * @return match criterion
321 */
322 public static Criterion matchIPv6NDSourceLinkLayerAddress(MacAddress mac) {
323 return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_SLL);
324 }
325
326 /**
327 * Creates a match on IPv6 Neighbor Discovery target link-layer address
328 * using the specified value.
329 *
330 * @param mac IPv6 Neighbor Discovery target link-layer address
331 * @return match criterion
332 */
333 public static Criterion matchIPv6NDTargetLinkLayerAddress(MacAddress mac) {
334 return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_TLL);
335 }
336
337 /**
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800338 * Creates a match on MPLS label.
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800339 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800340 * @param mplsLabel MPLS label (20 bits)
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800341 * @return match criterion
342 */
Michele Santuari4b6019e2014-12-19 11:31:45 +0100343 public static Criterion matchMplsLabel(MplsLabel mplsLabel) {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -0800344 return new MplsCriterion(mplsLabel);
345 }
346
347 /**
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800348 * Creates a match on IPv6 Extension Header pseudo-field fiags.
349 * Those are defined in Criterion.IPv6ExthdrFlags.
350 *
351 * @param exthdrFlags IPv6 Extension Header pseudo-field flags (16 bits)
352 * @return match criterion
353 */
354 public static Criterion matchIPv6ExthdrFlags(int exthdrFlags) {
355 return new IPv6ExthdrFlagsCriterion(exthdrFlags);
356 }
357
358 /**
Marc De Leenheer49087752014-10-23 13:54:09 -0700359 * Creates a match on lambda field using the specified value.
360 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800361 * @param lambda lambda to match on (16 bits unsigned integer)
Marc De Leenheer49087752014-10-23 13:54:09 -0700362 * @return match criterion
363 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800364 public static Criterion matchLambda(int lambda) {
Marc De Leenheer49087752014-10-23 13:54:09 -0700365 return new LambdaCriterion(lambda, Type.OCH_SIGID);
366 }
367
368 /**
Sho SHIMIZUa66cb122014-12-02 18:11:15 -0800369 * Creates a match on optical signal type using the specified value.
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700370 *
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800371 * @param sigType optical signal type (8 bits unsigned integer)
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700372 * @return match criterion
373 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -0800374 public static Criterion matchOpticalSignalType(short sigType) {
Praseed Balakrishnan2dd5abd2014-11-03 14:56:28 -0800375 return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700376 }
377
alshabiba3a476d2015-04-10 14:35:38 -0700378 public static Criterion dummy() {
379 return new DummyCriterion();
380 }
381
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700382 /**
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800383 * Implementation of input port criterion.
alshabib7b795492014-09-16 14:38:39 -0700384 */
alshabib7b795492014-09-16 14:38:39 -0700385 public static final class PortCriterion implements Criterion {
386 private final PortNumber port;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800387 private final Type type;
alshabib7b795492014-09-16 14:38:39 -0700388
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800389 /**
390 * Constructor.
391 *
392 * @param port the input port number to match
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800393 * @param type the match type. Should be either Type.IN_PORT or
394 * Type.IN_PHY_PORT
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800395 */
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800396 public PortCriterion(PortNumber port, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700397 this.port = port;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800398 this.type = type;
alshabib7b795492014-09-16 14:38:39 -0700399 }
400
401 @Override
402 public Type type() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800403 return this.type;
alshabib7b795492014-09-16 14:38:39 -0700404 }
405
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800406 /**
407 * Gets the input port number to match.
408 *
409 * @return the input port number to match
410 */
alshabib7b795492014-09-16 14:38:39 -0700411 public PortNumber port() {
412 return this.port;
413 }
alshabib99b8fdc2014-09-25 14:30:22 -0700414
415 @Override
416 public String toString() {
417 return toStringHelper(type().toString())
418 .add("port", port).toString();
419 }
alshabibba5ac482014-10-02 17:15:20 -0700420
421 @Override
422 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800423 return Objects.hash(type(), port);
alshabibba5ac482014-10-02 17:15:20 -0700424 }
425
426 @Override
427 public boolean equals(Object obj) {
428 if (this == obj) {
429 return true;
430 }
431 if (obj instanceof PortCriterion) {
432 PortCriterion that = (PortCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700433 return Objects.equals(port, that.port) &&
434 Objects.equals(this.type(), that.type());
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800435 }
436 return false;
437 }
438 }
alshabibba5ac482014-10-02 17:15:20 -0700439
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800440 /**
441 * Implementation of Metadata criterion.
442 */
443 public static final class MetadataCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800444 private final long metadata;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800445
446 /**
447 * Constructor.
448 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800449 * @param metadata the metadata to match (64 bits data)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800450 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800451 public MetadataCriterion(long metadata) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800452 this.metadata = metadata;
453 }
454
455 @Override
456 public Type type() {
457 return Type.METADATA;
458 }
459
460 /**
461 * Gets the metadata to match.
462 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800463 * @return the metadata to match (64 bits data)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800464 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800465 public long metadata() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800466 return metadata;
467 }
468
469 @Override
470 public String toString() {
471 return toStringHelper(type().toString())
472 .add("metadata", Long.toHexString(metadata))
473 .toString();
474 }
475
476 @Override
477 public int hashCode() {
478 return Objects.hash(type(), metadata);
479 }
480
481 @Override
482 public boolean equals(Object obj) {
483 if (this == obj) {
484 return true;
485 }
486 if (obj instanceof MetadataCriterion) {
487 MetadataCriterion that = (MetadataCriterion) obj;
488 return Objects.equals(metadata, that.metadata) &&
489 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700490 }
491 return false;
492 }
alshabib7b795492014-09-16 14:38:39 -0700493 }
494
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800495 /**
496 * Implementation of MAC address criterion.
497 */
alshabib7b795492014-09-16 14:38:39 -0700498 public static final class EthCriterion implements Criterion {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700499 private final MacAddress mac;
alshabib7b795492014-09-16 14:38:39 -0700500 private final Type type;
501
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800502 /**
503 * Constructor.
504 *
505 * @param mac the source or destination MAC address to match
506 * @param type the match type. Should be either Type.ETH_DST or
507 * Type.ETH_SRC
508 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700509 public EthCriterion(MacAddress mac, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700510 this.mac = mac;
511 this.type = type;
512 }
513
514 @Override
515 public Type type() {
516 return this.type;
517 }
518
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800519 /**
520 * Gets the MAC address to match.
521 *
522 * @return the MAC address to match
523 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700524 public MacAddress mac() {
alshabib7b795492014-09-16 14:38:39 -0700525 return this.mac;
526 }
alshabib99b8fdc2014-09-25 14:30:22 -0700527
528 @Override
529 public String toString() {
530 return toStringHelper(type().toString())
531 .add("mac", mac).toString();
532 }
533
alshabibba5ac482014-10-02 17:15:20 -0700534 @Override
535 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800536 return Objects.hash(type, mac);
alshabibba5ac482014-10-02 17:15:20 -0700537 }
538
539 @Override
540 public boolean equals(Object obj) {
541 if (this == obj) {
542 return true;
543 }
544 if (obj instanceof EthCriterion) {
545 EthCriterion that = (EthCriterion) obj;
546 return Objects.equals(mac, that.mac) &&
547 Objects.equals(type, that.type);
alshabibba5ac482014-10-02 17:15:20 -0700548 }
549 return false;
550 }
alshabib7b795492014-09-16 14:38:39 -0700551 }
552
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800553 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800554 * Implementation of Ethernet type criterion (16 bits unsigned integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800555 */
alshabib7b795492014-09-16 14:38:39 -0700556 public static final class EthTypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800557 private static final int MASK = 0xffff;
558 private final int ethType; // Ethernet type value: 16 bits
alshabib7b795492014-09-16 14:38:39 -0700559
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800560 /**
561 * Constructor.
562 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800563 * @param ethType the Ethernet frame type to match (16 bits unsigned
564 * integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800565 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800566 public EthTypeCriterion(int ethType) {
567 this.ethType = ethType & MASK;
alshabib7b795492014-09-16 14:38:39 -0700568 }
569
570 @Override
571 public Type type() {
572 return Type.ETH_TYPE;
573 }
574
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800575 /**
576 * Gets the Ethernet frame type to match.
577 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800578 * @return the Ethernet frame type to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800579 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800580 public int ethType() {
alshabib7b795492014-09-16 14:38:39 -0700581 return ethType;
582 }
583
alshabib99b8fdc2014-09-25 14:30:22 -0700584 @Override
585 public String toString() {
586 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800587 .add("ethType", Long.toHexString(ethType))
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800588 .toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700589 }
590
alshabibba5ac482014-10-02 17:15:20 -0700591 @Override
592 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800593 return Objects.hash(type(), ethType);
alshabibba5ac482014-10-02 17:15:20 -0700594 }
595
596 @Override
597 public boolean equals(Object obj) {
598 if (this == obj) {
599 return true;
600 }
601 if (obj instanceof EthTypeCriterion) {
602 EthTypeCriterion that = (EthTypeCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700603 return Objects.equals(ethType, that.ethType) &&
604 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700605 }
606 return false;
607 }
alshabib7b795492014-09-16 14:38:39 -0700608 }
609
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800610 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800611 * Implementation of VLAN ID criterion.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800612 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800613 public static final class VlanIdCriterion implements Criterion {
614 private final VlanId vlanId;
alshabib7b795492014-09-16 14:38:39 -0700615
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800616 /**
617 * Constructor.
618 *
619 * @param vlanId the VLAN ID to match
620 */
621 public VlanIdCriterion(VlanId vlanId) {
622 this.vlanId = vlanId;
alshabib7b795492014-09-16 14:38:39 -0700623 }
624
625 @Override
626 public Type type() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800627 return Type.VLAN_VID;
alshabib7b795492014-09-16 14:38:39 -0700628 }
629
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800630 /**
631 * Gets the VLAN ID to match.
632 *
633 * @return the VLAN ID to match
634 */
635 public VlanId vlanId() {
636 return vlanId;
alshabib7b795492014-09-16 14:38:39 -0700637 }
638
alshabib99b8fdc2014-09-25 14:30:22 -0700639 @Override
640 public String toString() {
641 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800642 .add("vlanId", vlanId).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700643 }
alshabib7b795492014-09-16 14:38:39 -0700644
alshabibba5ac482014-10-02 17:15:20 -0700645 @Override
646 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800647 return Objects.hash(type(), vlanId);
alshabibba5ac482014-10-02 17:15:20 -0700648 }
649
650 @Override
651 public boolean equals(Object obj) {
652 if (this == obj) {
653 return true;
654 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800655 if (obj instanceof VlanIdCriterion) {
656 VlanIdCriterion that = (VlanIdCriterion) obj;
657 return Objects.equals(vlanId, that.vlanId) &&
658 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700659 }
660 return false;
661 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800662 }
alshabibba5ac482014-10-02 17:15:20 -0700663
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800664 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800665 * Implementation of VLAN priority criterion (3 bits).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800666 */
667 public static final class VlanPcpCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800668 private static final byte MASK = 0x7;
669 private final byte vlanPcp; // VLAN pcp value: 3 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800670
671 /**
672 * Constructor.
673 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800674 * @param vlanPcp the VLAN priority to match (3 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800675 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800676 public VlanPcpCriterion(byte vlanPcp) {
677 this.vlanPcp = (byte) (vlanPcp & MASK);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800678 }
679
680 @Override
681 public Type type() {
682 return Type.VLAN_PCP;
683 }
684
685 /**
686 * Gets the VLAN priority to match.
687 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800688 * @return the VLAN priority to match (3 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800689 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800690 public byte priority() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800691 return vlanPcp;
692 }
693
694 @Override
695 public String toString() {
696 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800697 .add("priority", Long.toHexString(vlanPcp)).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800698 }
699
700 @Override
701 public int hashCode() {
702 return Objects.hash(type(), vlanPcp);
703 }
704
705 @Override
706 public boolean equals(Object obj) {
707 if (this == obj) {
708 return true;
709 }
710 if (obj instanceof VlanPcpCriterion) {
711 VlanPcpCriterion that = (VlanPcpCriterion) obj;
712 return Objects.equals(vlanPcp, that.vlanPcp) &&
713 Objects.equals(this.type(), that.type());
714 }
715 return false;
716 }
alshabib7b795492014-09-16 14:38:39 -0700717 }
718
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800719 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800720 * Implementation of IP DSCP (Differentiated Services Code Point)
721 * criterion (6 bits).
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800722 */
723 public static final class IPDscpCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800724 private static final byte MASK = 0x3f;
725 private final byte ipDscp; // IP DSCP value: 6 bits
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800726
727 /**
728 * Constructor.
729 *
730 * @param ipDscp the IP DSCP value to match
731 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800732 public IPDscpCriterion(byte ipDscp) {
733 this.ipDscp = (byte) (ipDscp & MASK);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800734 }
735
736 @Override
737 public Type type() {
738 return Type.IP_DSCP;
739 }
740
741 /**
742 * Gets the IP DSCP value to match.
743 *
744 * @return the IP DSCP value to match
745 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800746 public byte ipDscp() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800747 return ipDscp;
748 }
749
750 @Override
751 public String toString() {
752 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800753 .add("ipDscp", Long.toHexString(ipDscp)).toString();
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800754 }
755
756 @Override
757 public int hashCode() {
758 return Objects.hash(type(), ipDscp);
759 }
760
761 @Override
762 public boolean equals(Object obj) {
763 if (this == obj) {
764 return true;
765 }
766 if (obj instanceof IPDscpCriterion) {
767 IPDscpCriterion that = (IPDscpCriterion) obj;
768 return Objects.equals(ipDscp, that.ipDscp) &&
769 Objects.equals(this.type(), that.type());
770 }
771 return false;
772 }
773 }
774
775 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800776 * Implementation of IP ECN (Explicit Congestion Notification) criterion
Pavlin Radoslavovab8553a2015-02-20 14:13:50 -0800777 * (2 bits).
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800778 */
779 public static final class IPEcnCriterion implements Criterion {
Pavlin Radoslavovab8553a2015-02-20 14:13:50 -0800780 private static final byte MASK = 0x3;
781 private final byte ipEcn; // IP ECN value: 2 bits
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800782
783 /**
784 * Constructor.
785 *
Pavlin Radoslavovab8553a2015-02-20 14:13:50 -0800786 * @param ipEcn the IP ECN value to match (2 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800787 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800788 public IPEcnCriterion(byte ipEcn) {
789 this.ipEcn = (byte) (ipEcn & MASK);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800790 }
791
792 @Override
793 public Type type() {
794 return Type.IP_ECN;
795 }
796
797 /**
798 * Gets the IP ECN value to match.
799 *
Pavlin Radoslavovab8553a2015-02-20 14:13:50 -0800800 * @return the IP ECN value to match (2 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800801 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800802 public byte ipEcn() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800803 return ipEcn;
804 }
805
806 @Override
807 public String toString() {
808 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800809 .add("ipEcn", Long.toHexString(ipEcn)).toString();
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800810 }
811
812 @Override
813 public int hashCode() {
814 return Objects.hash(type(), ipEcn);
815 }
816
817 @Override
818 public boolean equals(Object obj) {
819 if (this == obj) {
820 return true;
821 }
822 if (obj instanceof IPEcnCriterion) {
823 IPEcnCriterion that = (IPEcnCriterion) obj;
824 return Objects.equals(ipEcn, that.ipEcn) &&
825 Objects.equals(this.type(), that.type());
826 }
827 return false;
828 }
829 }
830
831 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800832 * Implementation of Internet Protocol Number criterion (8 bits unsigned)
833 * integer.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800834 */
alshabib7b795492014-09-16 14:38:39 -0700835 public static final class IPProtocolCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800836 private static final short MASK = 0xff;
837 private final short proto; // IP protocol number: 8 bits
alshabib7b795492014-09-16 14:38:39 -0700838
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800839 /**
840 * Constructor.
841 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800842 * @param protocol the IP protocol (e.g., TCP=6, UDP=17) to match
843 * (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800844 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800845 public IPProtocolCriterion(short protocol) {
846 this.proto = (short) (protocol & MASK);
alshabib7b795492014-09-16 14:38:39 -0700847 }
848
849 @Override
850 public Type type() {
851 return Type.IP_PROTO;
852 }
853
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800854 /**
855 * Gets the IP protocol to match.
856 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800857 * @return the IP protocol to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800858 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800859 public short protocol() {
alshabib7b795492014-09-16 14:38:39 -0700860 return proto;
861 }
862
alshabib99b8fdc2014-09-25 14:30:22 -0700863 @Override
864 public String toString() {
865 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800866 .add("protocol", proto).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700867 }
868
alshabibba5ac482014-10-02 17:15:20 -0700869 @Override
870 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800871 return Objects.hash(type(), proto);
alshabibba5ac482014-10-02 17:15:20 -0700872 }
873
874 @Override
875 public boolean equals(Object obj) {
876 if (this == obj) {
877 return true;
878 }
879 if (obj instanceof IPProtocolCriterion) {
880 IPProtocolCriterion that = (IPProtocolCriterion) obj;
881 return Objects.equals(proto, that.proto);
alshabibba5ac482014-10-02 17:15:20 -0700882 }
883 return false;
884 }
alshabib7b795492014-09-16 14:38:39 -0700885 }
886
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800887 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800888 * Implementation of IP address criterion.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800889 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800890 public static final class IPCriterion implements Criterion {
891 private final IpPrefix ip;
892 private final Type type;
alshabib7b795492014-09-16 14:38:39 -0700893
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800894 /**
895 * Constructor.
896 *
897 * @param ip the IP prefix to match. Could be either IPv4 or IPv6
898 * @param type the match type. Should be one of the following:
899 * Type.IPV4_SRC, Type.IPV4_DST, Type.IPV6_SRC, Type.IPV6_DST
900 */
901 public IPCriterion(IpPrefix ip, Type type) {
902 this.ip = ip;
903 this.type = type;
alshabib7b795492014-09-16 14:38:39 -0700904 }
905
906 @Override
907 public Type type() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800908 return this.type;
alshabib7b795492014-09-16 14:38:39 -0700909 }
910
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800911 /**
912 * Gets the IP prefix to match.
913 *
914 * @return the IP prefix to match
915 */
916 public IpPrefix ip() {
917 return this.ip;
alshabib7b795492014-09-16 14:38:39 -0700918 }
919
alshabib99b8fdc2014-09-25 14:30:22 -0700920 @Override
921 public String toString() {
922 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800923 .add("ip", ip).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700924 }
925
alshabibba5ac482014-10-02 17:15:20 -0700926 @Override
927 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800928 return Objects.hash(type, ip);
alshabibba5ac482014-10-02 17:15:20 -0700929 }
930
931 @Override
932 public boolean equals(Object obj) {
933 if (this == obj) {
934 return true;
935 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800936 if (obj instanceof IPCriterion) {
937 IPCriterion that = (IPCriterion) obj;
938 return Objects.equals(ip, that.ip) &&
939 Objects.equals(type, that.type);
alshabibba5ac482014-10-02 17:15:20 -0700940 }
941 return false;
942 }
alshabib7b795492014-09-16 14:38:39 -0700943 }
944
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800945 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800946 * Implementation of TCP port criterion (16 bits unsigned integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800947 */
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700948 public static final class TcpPortCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800949 private static final int MASK = 0xffff;
950 private final int tcpPort; // Port value: 16 bits
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700951 private final Type type;
952
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800953 /**
954 * Constructor.
955 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800956 * @param tcpPort the TCP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800957 * @param type the match type. Should be either Type.TCP_SRC or
958 * Type.TCP_DST
959 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800960 public TcpPortCriterion(int tcpPort, Type type) {
961 this.tcpPort = tcpPort & MASK;
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700962 this.type = type;
963 }
964
965 @Override
966 public Type type() {
967 return this.type;
968 }
969
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800970 /**
971 * Gets the TCP port to match.
972 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800973 * @return the TCP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800974 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800975 public int tcpPort() {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700976 return this.tcpPort;
977 }
978
979 @Override
980 public String toString() {
981 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800982 .add("tcpPort", tcpPort).toString();
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700983 }
984
985 @Override
986 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800987 return Objects.hash(type, tcpPort);
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700988 }
989
990 @Override
991 public boolean equals(Object obj) {
992 if (this == obj) {
993 return true;
994 }
995 if (obj instanceof TcpPortCriterion) {
996 TcpPortCriterion that = (TcpPortCriterion) obj;
997 return Objects.equals(tcpPort, that.tcpPort) &&
998 Objects.equals(type, that.type);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800999 }
1000 return false;
1001 }
1002 }
Toshio Koide9c44c9a2014-10-09 11:44:36 -07001003
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001004 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001005 * Implementation of UDP port criterion (16 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001006 */
1007 public static final class UdpPortCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001008 private static final int MASK = 0xffff;
1009 private final int udpPort; // Port value: 16 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001010 private final Type type;
Toshio Koide9c44c9a2014-10-09 11:44:36 -07001011
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001012 /**
1013 * Constructor.
1014 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001015 * @param udpPort the UDP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001016 * @param type the match type. Should be either Type.UDP_SRC or
1017 * Type.UDP_DST
1018 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001019 public UdpPortCriterion(int udpPort, Type type) {
1020 this.udpPort = udpPort & MASK;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001021 this.type = type;
1022 }
1023
1024 @Override
1025 public Type type() {
1026 return this.type;
1027 }
1028
1029 /**
1030 * Gets the UDP port to match.
1031 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001032 * @return the UDP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001033 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001034 public int udpPort() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001035 return this.udpPort;
1036 }
1037
1038 @Override
1039 public String toString() {
1040 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001041 .add("udpPort", udpPort).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001042 }
1043
1044 @Override
1045 public int hashCode() {
1046 return Objects.hash(type, udpPort);
1047 }
1048
1049 @Override
1050 public boolean equals(Object obj) {
1051 if (this == obj) {
1052 return true;
1053 }
1054 if (obj instanceof UdpPortCriterion) {
1055 UdpPortCriterion that = (UdpPortCriterion) obj;
1056 return Objects.equals(udpPort, that.udpPort) &&
1057 Objects.equals(type, that.type);
1058 }
1059 return false;
1060 }
1061 }
1062
1063 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001064 * Implementation of SCTP port criterion (16 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001065 */
1066 public static final class SctpPortCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001067 private static final int MASK = 0xffff;
1068 private final int sctpPort; // Port value: 16 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001069 private final Type type;
1070
1071 /**
1072 * Constructor.
1073 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001074 * @param sctpPort the SCTP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001075 * @param type the match type. Should be either Type.SCTP_SRC or
1076 * Type.SCTP_DST
1077 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001078 public SctpPortCriterion(int sctpPort, Type type) {
1079 this.sctpPort = sctpPort & MASK;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001080 this.type = type;
1081 }
1082
1083 @Override
1084 public Type type() {
1085 return this.type;
1086 }
1087
1088 /**
1089 * Gets the SCTP port to match.
1090 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001091 * @return the SCTP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001092 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001093 public int sctpPort() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001094 return this.sctpPort;
1095 }
1096
1097 @Override
1098 public String toString() {
1099 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001100 .add("sctpPort", sctpPort).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001101 }
1102
1103 @Override
1104 public int hashCode() {
1105 return Objects.hash(type, sctpPort);
1106 }
1107
1108 @Override
1109 public boolean equals(Object obj) {
1110 if (this == obj) {
1111 return true;
1112 }
1113 if (obj instanceof SctpPortCriterion) {
1114 SctpPortCriterion that = (SctpPortCriterion) obj;
1115 return Objects.equals(sctpPort, that.sctpPort) &&
1116 Objects.equals(type, that.type);
1117 }
1118 return false;
1119 }
1120 }
1121
1122 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001123 * Implementation of ICMP type criterion (8 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001124 */
1125 public static final class IcmpTypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001126 private static final short MASK = 0xff;
1127 private final short icmpType; // The ICMP type: 8 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001128
1129 /**
1130 * Constructor.
1131 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001132 * @param icmpType the ICMP type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001133 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001134 public IcmpTypeCriterion(short icmpType) {
1135 this.icmpType = (short) (icmpType & MASK);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001136 }
1137
1138 @Override
1139 public Type type() {
1140 return Type.ICMPV4_TYPE;
1141 }
1142
1143 /**
1144 * Gets the ICMP type to match.
1145 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001146 * @return the ICMP type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001147 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001148 public short icmpType() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001149 return icmpType;
1150 }
1151
1152 @Override
1153 public String toString() {
1154 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001155 .add("icmpType", icmpType).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001156 }
1157
1158 @Override
1159 public int hashCode() {
1160 return Objects.hash(type(), icmpType);
1161 }
1162
1163 @Override
1164 public boolean equals(Object obj) {
1165 if (this == obj) {
1166 return true;
1167 }
1168 if (obj instanceof IcmpTypeCriterion) {
1169 IcmpTypeCriterion that = (IcmpTypeCriterion) obj;
1170 return Objects.equals(icmpType, that.icmpType) &&
1171 Objects.equals(this.type(), that.type());
1172 }
1173 return false;
1174 }
1175 }
1176
1177 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001178 * Implementation of ICMP code criterion (8 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001179 */
1180 public static final class IcmpCodeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001181 private static final short MASK = 0xff;
1182 private final short icmpCode; // The ICMP code: 8 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001183
1184 /**
1185 * Constructor.
1186 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001187 * @param icmpCode the ICMP code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001188 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001189 public IcmpCodeCriterion(short icmpCode) {
1190 this.icmpCode = (short) (icmpCode & MASK);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001191 }
1192
1193 @Override
1194 public Type type() {
1195 return Type.ICMPV4_CODE;
1196 }
1197
1198 /**
1199 * Gets the ICMP code to match.
1200 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001201 * @return the ICMP code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001202 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001203 public short icmpCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001204 return icmpCode;
1205 }
1206
1207 @Override
1208 public String toString() {
1209 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001210 .add("icmpCode", icmpCode).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001211 }
1212
1213 @Override
1214 public int hashCode() {
1215 return Objects.hash(type(), icmpCode);
1216 }
1217
1218 @Override
1219 public boolean equals(Object obj) {
1220 if (this == obj) {
1221 return true;
1222 }
1223 if (obj instanceof IcmpCodeCriterion) {
1224 IcmpCodeCriterion that = (IcmpCodeCriterion) obj;
1225 return Objects.equals(icmpCode, that.icmpCode) &&
1226 Objects.equals(this.type(), that.type());
1227 }
1228 return false;
1229 }
1230 }
1231
1232 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001233 * Implementation of IPv6 Flow Label (RFC 6437) criterion (20 bits unsigned
1234 * integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001235 */
1236 public static final class IPv6FlowLabelCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001237 private static final int MASK = 0xfffff;
1238 private final int flowLabel; // IPv6 flow label: 20 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001239
1240 /**
1241 * Constructor.
1242 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001243 * @param flowLabel the IPv6 flow label to match (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001244 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001245 public IPv6FlowLabelCriterion(int flowLabel) {
1246 this.flowLabel = flowLabel & MASK;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001247 }
1248
1249 @Override
1250 public Type type() {
1251 return Type.IPV6_FLABEL;
1252 }
1253
1254 /**
1255 * Gets the IPv6 flow label to match.
1256 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001257 * @return the IPv6 flow label to match (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001258 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001259 public int flowLabel() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001260 return flowLabel;
1261 }
1262
1263 @Override
1264 public String toString() {
1265 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001266 .add("flowLabel", Long.toHexString(flowLabel)).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001267 }
1268
1269 @Override
1270 public int hashCode() {
1271 return Objects.hash(type(), flowLabel);
1272 }
1273
1274 @Override
1275 public boolean equals(Object obj) {
1276 if (this == obj) {
1277 return true;
1278 }
1279 if (obj instanceof IPv6FlowLabelCriterion) {
1280 IPv6FlowLabelCriterion that = (IPv6FlowLabelCriterion) obj;
1281 return Objects.equals(flowLabel, that.flowLabel) &&
1282 Objects.equals(this.type(), that.type());
Toshio Koide9c44c9a2014-10-09 11:44:36 -07001283 }
1284 return false;
1285 }
1286 }
Marc De Leenheer49087752014-10-23 13:54:09 -07001287
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001288 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001289 * Implementation of ICMPv6 type criterion (8 bits unsigned integer).
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001290 */
1291 public static final class Icmpv6TypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001292 private static final short MASK = 0xff;
1293 private final short icmpv6Type; // ICMPv6 type: 8 bits
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001294
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001295 /**
1296 * Constructor.
1297 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001298 * @param icmpv6Type the ICMPv6 type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001299 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001300 public Icmpv6TypeCriterion(short icmpv6Type) {
1301 this.icmpv6Type = (short) (icmpv6Type & MASK);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001302 }
1303
1304 @Override
1305 public Type type() {
1306 return Type.ICMPV6_TYPE;
1307 }
1308
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001309 /**
1310 * Gets the ICMPv6 type to match.
1311 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001312 * @return the ICMPv6 type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001313 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001314 public short icmpv6Type() {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001315 return icmpv6Type;
1316 }
1317
1318 @Override
1319 public String toString() {
1320 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001321 .add("icmpv6Type", icmpv6Type).toString();
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001322 }
1323
1324 @Override
1325 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001326 return Objects.hash(type(), icmpv6Type);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001327 }
1328
1329 @Override
1330 public boolean equals(Object obj) {
1331 if (this == obj) {
1332 return true;
1333 }
1334 if (obj instanceof Icmpv6TypeCriterion) {
1335 Icmpv6TypeCriterion that = (Icmpv6TypeCriterion) obj;
1336 return Objects.equals(icmpv6Type, that.icmpv6Type) &&
1337 Objects.equals(this.type(), that.type());
1338 }
1339 return false;
1340 }
1341 }
1342
1343 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001344 * Implementation of ICMPv6 code criterion (8 bits unsigned integer).
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001345 */
1346 public static final class Icmpv6CodeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001347 private static final short MASK = 0xff;
1348 private final short icmpv6Code; // ICMPv6 code: 8 bits
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001349
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001350 /**
1351 * Constructor.
1352 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001353 * @param icmpv6Code the ICMPv6 code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001354 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001355 public Icmpv6CodeCriterion(short icmpv6Code) {
1356 this.icmpv6Code = (short) (icmpv6Code & MASK);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001357 }
1358
1359 @Override
1360 public Type type() {
1361 return Type.ICMPV6_CODE;
1362 }
1363
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001364 /**
1365 * Gets the ICMPv6 code to match.
1366 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001367 * @return the ICMPv6 code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001368 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001369 public short icmpv6Code() {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001370 return icmpv6Code;
1371 }
1372
1373 @Override
1374 public String toString() {
1375 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001376 .add("icmpv6Code", icmpv6Code).toString();
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001377 }
1378
1379 @Override
1380 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001381 return Objects.hash(type(), icmpv6Code);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001382 }
1383
1384 @Override
1385 public boolean equals(Object obj) {
1386 if (this == obj) {
1387 return true;
1388 }
1389 if (obj instanceof Icmpv6CodeCriterion) {
1390 Icmpv6CodeCriterion that = (Icmpv6CodeCriterion) obj;
1391 return Objects.equals(icmpv6Code, that.icmpv6Code) &&
1392 Objects.equals(this.type(), that.type());
1393 }
1394 return false;
1395 }
1396 }
1397
1398 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001399 * Implementation of IPv6 Neighbor Discovery target address criterion.
1400 */
1401 public static final class IPv6NDTargetAddressCriterion
1402 implements Criterion {
1403 private final Ip6Address targetAddress;
1404
1405 /**
1406 * Constructor.
1407 *
1408 * @param targetAddress the IPv6 target address to match
1409 */
1410 public IPv6NDTargetAddressCriterion(Ip6Address targetAddress) {
1411 this.targetAddress = targetAddress;
1412 }
1413
1414 @Override
1415 public Type type() {
1416 return Type.IPV6_ND_TARGET;
1417 }
1418
1419 /**
1420 * Gets the IPv6 target address to match.
1421 *
1422 * @return the IPv6 target address to match
1423 */
1424 public Ip6Address targetAddress() {
1425 return this.targetAddress;
1426 }
1427
1428 @Override
1429 public String toString() {
1430 return toStringHelper(type().toString())
1431 .add("targetAddress", targetAddress).toString();
1432 }
1433
1434 @Override
1435 public int hashCode() {
1436 return Objects.hash(type(), targetAddress);
1437 }
1438
1439 @Override
1440 public boolean equals(Object obj) {
1441 if (this == obj) {
1442 return true;
1443 }
1444 if (obj instanceof IPv6NDTargetAddressCriterion) {
1445 IPv6NDTargetAddressCriterion that =
1446 (IPv6NDTargetAddressCriterion) obj;
1447 return Objects.equals(targetAddress, that.targetAddress) &&
1448 Objects.equals(type(), that.type());
1449 }
1450 return false;
1451 }
1452 }
1453
1454 /**
1455 * Implementation of IPv6 Neighbor Discovery link-layer address criterion.
1456 */
1457 public static final class IPv6NDLinkLayerAddressCriterion
1458 implements Criterion {
1459 private final MacAddress mac;
1460 private final Type type;
1461
1462 /**
1463 * Constructor.
1464 *
1465 * @param mac the source or destination link-layer address to match
1466 * @param type the match type. Should be either Type.IPV6_ND_SLL or
1467 * Type.IPV6_ND_TLL
1468 */
1469 public IPv6NDLinkLayerAddressCriterion(MacAddress mac, Type type) {
1470 this.mac = mac;
1471 this.type = type;
1472 }
1473
1474 @Override
1475 public Type type() {
1476 return this.type;
1477 }
1478
1479 /**
1480 * Gets the MAC link-layer address to match.
1481 *
1482 * @return the MAC link-layer address to match
1483 */
1484 public MacAddress mac() {
1485 return this.mac;
1486 }
1487
1488 @Override
1489 public String toString() {
1490 return toStringHelper(type().toString())
1491 .add("mac", mac).toString();
1492 }
1493
1494 @Override
1495 public int hashCode() {
1496 return Objects.hash(type, mac);
1497 }
1498
1499 @Override
1500 public boolean equals(Object obj) {
1501 if (this == obj) {
1502 return true;
1503 }
1504 if (obj instanceof IPv6NDLinkLayerAddressCriterion) {
1505 IPv6NDLinkLayerAddressCriterion that =
1506 (IPv6NDLinkLayerAddressCriterion) obj;
1507 return Objects.equals(mac, that.mac) &&
1508 Objects.equals(type, that.type);
1509 }
1510 return false;
1511 }
1512 }
1513
1514 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001515 * Implementation of MPLS tag criterion (20 bits).
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001516 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001517 public static final class MplsCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001518 private static final int MASK = 0xfffff;
Michele Santuari4b6019e2014-12-19 11:31:45 +01001519 private final MplsLabel mplsLabel;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001520
Michele Santuari4b6019e2014-12-19 11:31:45 +01001521 public MplsCriterion(MplsLabel mplsLabel) {
1522 this.mplsLabel = mplsLabel;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001523 }
1524
1525 @Override
1526 public Type type() {
1527 return Type.MPLS_LABEL;
1528 }
1529
Michele Santuari4b6019e2014-12-19 11:31:45 +01001530 public MplsLabel label() {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001531 return mplsLabel;
1532 }
1533
1534 @Override
1535 public String toString() {
1536 return toStringHelper(type().toString())
Michele Santuari4b6019e2014-12-19 11:31:45 +01001537 .add("mpls", mplsLabel).toString();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001538 }
1539
1540 @Override
1541 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001542 return Objects.hash(type(), mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001543 }
1544
1545 @Override
1546 public boolean equals(Object obj) {
1547 if (this == obj) {
1548 return true;
1549 }
1550 if (obj instanceof MplsCriterion) {
1551 MplsCriterion that = (MplsCriterion) obj;
1552 return Objects.equals(mplsLabel, that.mplsLabel) &&
1553 Objects.equals(this.type(), that.type());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001554 }
1555 return false;
1556 }
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001557 }
1558
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001559 /**
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001560 * Implementation of IPv6 Extension Header pseudo-field criterion
1561 * (16 bits). Those are defined in Criterion.IPv6ExthdrFlags.
1562 */
1563 public static final class IPv6ExthdrFlagsCriterion implements Criterion {
1564 private static final int MASK = 0xffff;
1565 private final int exthdrFlags; // IPv6 Exthdr flags: 16 bits
1566
1567 /**
1568 * Constructor.
1569 *
1570 * @param exthdrFlags the IPv6 Extension Header pseudo-field flags
1571 * to match (16 bits). Those are defined in Criterion.IPv6ExthdrFlags
1572 */
1573 public IPv6ExthdrFlagsCriterion(int exthdrFlags) {
1574 this.exthdrFlags = exthdrFlags & MASK;
1575 }
1576
1577 @Override
1578 public Type type() {
1579 return Type.IPV6_EXTHDR;
1580 }
1581
1582 /**
1583 * Gets the IPv6 Extension Header pseudo-field flags to match.
1584 *
1585 * @return the IPv6 Extension Header pseudo-field flags to match
1586 * (16 bits). Those are defined in Criterion.IPv6ExthdrFlags
1587 */
1588 public int exthdrFlags() {
1589 return exthdrFlags;
1590 }
1591
1592 @Override
1593 public String toString() {
1594 return toStringHelper(type().toString())
1595 .add("exthdrFlags", Long.toHexString(exthdrFlags)).toString();
1596 }
1597
1598 @Override
1599 public int hashCode() {
1600 return Objects.hash(type(), exthdrFlags);
1601 }
1602
1603 @Override
1604 public boolean equals(Object obj) {
1605 if (this == obj) {
1606 return true;
1607 }
1608 if (obj instanceof IPv6ExthdrFlagsCriterion) {
1609 IPv6ExthdrFlagsCriterion that = (IPv6ExthdrFlagsCriterion) obj;
1610 return Objects.equals(exthdrFlags, that.exthdrFlags) &&
1611 Objects.equals(this.type(), that.type());
1612 }
1613 return false;
1614 }
1615 }
1616
1617 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001618 * Implementation of lambda (wavelength) criterion (16 bits unsigned
1619 * integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001620 */
Marc De Leenheer49087752014-10-23 13:54:09 -07001621 public static final class LambdaCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001622 private static final int MASK = 0xffff;
1623 private final int lambda; // Lambda value: 16 bits
Marc De Leenheer49087752014-10-23 13:54:09 -07001624 private final Type type;
1625
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001626 /**
1627 * Constructor.
1628 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001629 * @param lambda the lambda (wavelength) to match (16 bits unsigned
1630 * integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001631 * @param type the match type. Should be Type.OCH_SIGID
1632 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001633 public LambdaCriterion(int lambda, Type type) {
1634 this.lambda = lambda & MASK;
Marc De Leenheer49087752014-10-23 13:54:09 -07001635 this.type = type;
1636 }
1637
1638 @Override
1639 public Type type() {
1640 return this.type;
1641 }
1642
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001643 /**
1644 * Gets the lambda (wavelength) to match.
1645 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001646 * @return the lambda (wavelength) to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001647 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001648 public int lambda() {
1649 return lambda;
Marc De Leenheer49087752014-10-23 13:54:09 -07001650 }
1651
1652 @Override
1653 public String toString() {
1654 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001655 .add("lambda", lambda).toString();
Marc De Leenheer49087752014-10-23 13:54:09 -07001656 }
1657
1658 @Override
1659 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -08001660 return Objects.hash(type, lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -07001661 }
1662
1663 @Override
1664 public boolean equals(Object obj) {
1665 if (this == obj) {
1666 return true;
1667 }
1668 if (obj instanceof LambdaCriterion) {
1669 LambdaCriterion that = (LambdaCriterion) obj;
1670 return Objects.equals(lambda, that.lambda) &&
1671 Objects.equals(type, that.type);
1672 }
1673 return false;
1674 }
1675 }
1676
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001677 /**
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001678 * Implementation of optical signal type criterion (8 bits unsigned
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001679 * integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001680 */
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001681 public static final class OpticalSignalTypeCriterion implements Criterion {
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001682 private static final short MASK = 0xff;
1683 private final short signalType; // Signal type value: 8 bits
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001684 private final Type type;
1685
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001686 /**
1687 * Constructor.
1688 *
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001689 * @param signalType the optical signal type to match (8 bits unsigned
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001690 * integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001691 * @param type the match type. Should be Type.OCH_SIGTYPE
1692 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001693 public OpticalSignalTypeCriterion(short signalType, Type type) {
1694 this.signalType = (short) (signalType & MASK);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001695 this.type = type;
1696 }
1697
1698 @Override
1699 public Type type() {
1700 return this.type;
1701 }
1702
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001703 /**
1704 * Gets the optical signal type to match.
1705 *
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001706 * @return the optical signal type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001707 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001708 public short signalType() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001709 return signalType;
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001710 }
1711
1712 @Override
1713 public String toString() {
1714 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001715 .add("signalType", signalType).toString();
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001716 }
1717
1718 @Override
1719 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -08001720 return Objects.hash(type, signalType);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001721 }
1722
1723 @Override
1724 public boolean equals(Object obj) {
1725 if (this == obj) {
1726 return true;
1727 }
1728 if (obj instanceof OpticalSignalTypeCriterion) {
1729 OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj;
1730 return Objects.equals(signalType, that.signalType) &&
1731 Objects.equals(type, that.type);
1732 }
1733 return false;
1734 }
1735 }
alshabiba3a476d2015-04-10 14:35:38 -07001736
1737 /**
1738 * Dummy Criterion used with @see{FilteringObjective}.
1739 */
1740 private static class DummyCriterion implements Criterion {
1741
1742 @Override
1743 public Type type() {
1744 return Type.DUMMY;
1745 }
1746 }
tom8bb16062014-09-12 14:47:46 -07001747}