blob: 1eff64b72336e0800a270102700c81df57133bc5 [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;
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 Radoslavovf3b69332015-02-06 15:47:05 -0800136 * @param ipEcn ip ecn value (3 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
Praseed Balakrishnan64369da2014-10-23 15:55:20 -0700378 /**
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800379 * Implementation of input port criterion.
alshabib7b795492014-09-16 14:38:39 -0700380 */
alshabib7b795492014-09-16 14:38:39 -0700381 public static final class PortCriterion implements Criterion {
382 private final PortNumber port;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800383 private final Type type;
alshabib7b795492014-09-16 14:38:39 -0700384
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800385 /**
386 * Constructor.
387 *
388 * @param port the input port number to match
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800389 * @param type the match type. Should be either Type.IN_PORT or
390 * Type.IN_PHY_PORT
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800391 */
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800392 public PortCriterion(PortNumber port, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700393 this.port = port;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800394 this.type = type;
alshabib7b795492014-09-16 14:38:39 -0700395 }
396
397 @Override
398 public Type type() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800399 return this.type;
alshabib7b795492014-09-16 14:38:39 -0700400 }
401
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800402 /**
403 * Gets the input port number to match.
404 *
405 * @return the input port number to match
406 */
alshabib7b795492014-09-16 14:38:39 -0700407 public PortNumber port() {
408 return this.port;
409 }
alshabib99b8fdc2014-09-25 14:30:22 -0700410
411 @Override
412 public String toString() {
413 return toStringHelper(type().toString())
414 .add("port", port).toString();
415 }
alshabibba5ac482014-10-02 17:15:20 -0700416
417 @Override
418 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800419 return Objects.hash(type(), port);
alshabibba5ac482014-10-02 17:15:20 -0700420 }
421
422 @Override
423 public boolean equals(Object obj) {
424 if (this == obj) {
425 return true;
426 }
427 if (obj instanceof PortCriterion) {
428 PortCriterion that = (PortCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700429 return Objects.equals(port, that.port) &&
430 Objects.equals(this.type(), that.type());
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800431 }
432 return false;
433 }
434 }
alshabibba5ac482014-10-02 17:15:20 -0700435
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800436 /**
437 * Implementation of Metadata criterion.
438 */
439 public static final class MetadataCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800440 private final long metadata;
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800441
442 /**
443 * Constructor.
444 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800445 * @param metadata the metadata to match (64 bits data)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800446 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800447 public MetadataCriterion(long metadata) {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800448 this.metadata = metadata;
449 }
450
451 @Override
452 public Type type() {
453 return Type.METADATA;
454 }
455
456 /**
457 * Gets the metadata to match.
458 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800459 * @return the metadata to match (64 bits data)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800460 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800461 public long metadata() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800462 return metadata;
463 }
464
465 @Override
466 public String toString() {
467 return toStringHelper(type().toString())
468 .add("metadata", Long.toHexString(metadata))
469 .toString();
470 }
471
472 @Override
473 public int hashCode() {
474 return Objects.hash(type(), metadata);
475 }
476
477 @Override
478 public boolean equals(Object obj) {
479 if (this == obj) {
480 return true;
481 }
482 if (obj instanceof MetadataCriterion) {
483 MetadataCriterion that = (MetadataCriterion) obj;
484 return Objects.equals(metadata, that.metadata) &&
485 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700486 }
487 return false;
488 }
alshabib7b795492014-09-16 14:38:39 -0700489 }
490
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800491 /**
492 * Implementation of MAC address criterion.
493 */
alshabib7b795492014-09-16 14:38:39 -0700494 public static final class EthCriterion implements Criterion {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700495 private final MacAddress mac;
alshabib7b795492014-09-16 14:38:39 -0700496 private final Type type;
497
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800498 /**
499 * Constructor.
500 *
501 * @param mac the source or destination MAC address to match
502 * @param type the match type. Should be either Type.ETH_DST or
503 * Type.ETH_SRC
504 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700505 public EthCriterion(MacAddress mac, Type type) {
alshabib7b795492014-09-16 14:38:39 -0700506 this.mac = mac;
507 this.type = type;
508 }
509
510 @Override
511 public Type type() {
512 return this.type;
513 }
514
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800515 /**
516 * Gets the MAC address to match.
517 *
518 * @return the MAC address to match
519 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -0700520 public MacAddress mac() {
alshabib7b795492014-09-16 14:38:39 -0700521 return this.mac;
522 }
alshabib99b8fdc2014-09-25 14:30:22 -0700523
524 @Override
525 public String toString() {
526 return toStringHelper(type().toString())
527 .add("mac", mac).toString();
528 }
529
alshabibba5ac482014-10-02 17:15:20 -0700530 @Override
531 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800532 return Objects.hash(type, mac);
alshabibba5ac482014-10-02 17:15:20 -0700533 }
534
535 @Override
536 public boolean equals(Object obj) {
537 if (this == obj) {
538 return true;
539 }
540 if (obj instanceof EthCriterion) {
541 EthCriterion that = (EthCriterion) obj;
542 return Objects.equals(mac, that.mac) &&
543 Objects.equals(type, that.type);
alshabibba5ac482014-10-02 17:15:20 -0700544 }
545 return false;
546 }
alshabib7b795492014-09-16 14:38:39 -0700547 }
548
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800549 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800550 * Implementation of Ethernet type criterion (16 bits unsigned integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800551 */
alshabib7b795492014-09-16 14:38:39 -0700552 public static final class EthTypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800553 private static final int MASK = 0xffff;
554 private final int ethType; // Ethernet type value: 16 bits
alshabib7b795492014-09-16 14:38:39 -0700555
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800556 /**
557 * Constructor.
558 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800559 * @param ethType the Ethernet frame type to match (16 bits unsigned
560 * integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800561 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800562 public EthTypeCriterion(int ethType) {
563 this.ethType = ethType & MASK;
alshabib7b795492014-09-16 14:38:39 -0700564 }
565
566 @Override
567 public Type type() {
568 return Type.ETH_TYPE;
569 }
570
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800571 /**
572 * Gets the Ethernet frame type to match.
573 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800574 * @return the Ethernet frame type to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800575 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800576 public int ethType() {
alshabib7b795492014-09-16 14:38:39 -0700577 return ethType;
578 }
579
alshabib99b8fdc2014-09-25 14:30:22 -0700580 @Override
581 public String toString() {
582 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800583 .add("ethType", Long.toHexString(ethType))
Charles M.C. Chan36eb6e12015-01-06 17:12:27 +0800584 .toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700585 }
586
alshabibba5ac482014-10-02 17:15:20 -0700587 @Override
588 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800589 return Objects.hash(type(), ethType);
alshabibba5ac482014-10-02 17:15:20 -0700590 }
591
592 @Override
593 public boolean equals(Object obj) {
594 if (this == obj) {
595 return true;
596 }
597 if (obj instanceof EthTypeCriterion) {
598 EthTypeCriterion that = (EthTypeCriterion) obj;
alshabib2020b892014-10-20 15:47:08 -0700599 return Objects.equals(ethType, that.ethType) &&
600 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700601 }
602 return false;
603 }
alshabib7b795492014-09-16 14:38:39 -0700604 }
605
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800606 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800607 * Implementation of VLAN ID criterion.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800608 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800609 public static final class VlanIdCriterion implements Criterion {
610 private final VlanId vlanId;
alshabib7b795492014-09-16 14:38:39 -0700611
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800612 /**
613 * Constructor.
614 *
615 * @param vlanId the VLAN ID to match
616 */
617 public VlanIdCriterion(VlanId vlanId) {
618 this.vlanId = vlanId;
alshabib7b795492014-09-16 14:38:39 -0700619 }
620
621 @Override
622 public Type type() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800623 return Type.VLAN_VID;
alshabib7b795492014-09-16 14:38:39 -0700624 }
625
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800626 /**
627 * Gets the VLAN ID to match.
628 *
629 * @return the VLAN ID to match
630 */
631 public VlanId vlanId() {
632 return vlanId;
alshabib7b795492014-09-16 14:38:39 -0700633 }
634
alshabib99b8fdc2014-09-25 14:30:22 -0700635 @Override
636 public String toString() {
637 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800638 .add("vlanId", vlanId).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700639 }
alshabib7b795492014-09-16 14:38:39 -0700640
alshabibba5ac482014-10-02 17:15:20 -0700641 @Override
642 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800643 return Objects.hash(type(), vlanId);
alshabibba5ac482014-10-02 17:15:20 -0700644 }
645
646 @Override
647 public boolean equals(Object obj) {
648 if (this == obj) {
649 return true;
650 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800651 if (obj instanceof VlanIdCriterion) {
652 VlanIdCriterion that = (VlanIdCriterion) obj;
653 return Objects.equals(vlanId, that.vlanId) &&
654 Objects.equals(this.type(), that.type());
alshabibba5ac482014-10-02 17:15:20 -0700655 }
656 return false;
657 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800658 }
alshabibba5ac482014-10-02 17:15:20 -0700659
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800660 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800661 * Implementation of VLAN priority criterion (3 bits).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800662 */
663 public static final class VlanPcpCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800664 private static final byte MASK = 0x7;
665 private final byte vlanPcp; // VLAN pcp value: 3 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800666
667 /**
668 * Constructor.
669 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800670 * @param vlanPcp the VLAN priority to match (3 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800671 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800672 public VlanPcpCriterion(byte vlanPcp) {
673 this.vlanPcp = (byte) (vlanPcp & MASK);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800674 }
675
676 @Override
677 public Type type() {
678 return Type.VLAN_PCP;
679 }
680
681 /**
682 * Gets the VLAN priority to match.
683 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800684 * @return the VLAN priority to match (3 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800685 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800686 public byte priority() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800687 return vlanPcp;
688 }
689
690 @Override
691 public String toString() {
692 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800693 .add("priority", Long.toHexString(vlanPcp)).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800694 }
695
696 @Override
697 public int hashCode() {
698 return Objects.hash(type(), vlanPcp);
699 }
700
701 @Override
702 public boolean equals(Object obj) {
703 if (this == obj) {
704 return true;
705 }
706 if (obj instanceof VlanPcpCriterion) {
707 VlanPcpCriterion that = (VlanPcpCriterion) obj;
708 return Objects.equals(vlanPcp, that.vlanPcp) &&
709 Objects.equals(this.type(), that.type());
710 }
711 return false;
712 }
alshabib7b795492014-09-16 14:38:39 -0700713 }
714
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800715 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800716 * Implementation of IP DSCP (Differentiated Services Code Point)
717 * criterion (6 bits).
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800718 */
719 public static final class IPDscpCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800720 private static final byte MASK = 0x3f;
721 private final byte ipDscp; // IP DSCP value: 6 bits
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800722
723 /**
724 * Constructor.
725 *
726 * @param ipDscp the IP DSCP value to match
727 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800728 public IPDscpCriterion(byte ipDscp) {
729 this.ipDscp = (byte) (ipDscp & MASK);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800730 }
731
732 @Override
733 public Type type() {
734 return Type.IP_DSCP;
735 }
736
737 /**
738 * Gets the IP DSCP value to match.
739 *
740 * @return the IP DSCP value to match
741 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800742 public byte ipDscp() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800743 return ipDscp;
744 }
745
746 @Override
747 public String toString() {
748 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800749 .add("ipDscp", Long.toHexString(ipDscp)).toString();
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800750 }
751
752 @Override
753 public int hashCode() {
754 return Objects.hash(type(), ipDscp);
755 }
756
757 @Override
758 public boolean equals(Object obj) {
759 if (this == obj) {
760 return true;
761 }
762 if (obj instanceof IPDscpCriterion) {
763 IPDscpCriterion that = (IPDscpCriterion) obj;
764 return Objects.equals(ipDscp, that.ipDscp) &&
765 Objects.equals(this.type(), that.type());
766 }
767 return false;
768 }
769 }
770
771 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800772 * Implementation of IP ECN (Explicit Congestion Notification) criterion
773 * (3 bits).
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800774 */
775 public static final class IPEcnCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800776 private static final byte MASK = 0x7;
777 private final byte ipEcn; // IP ECN value: 3 bits
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800778
779 /**
780 * Constructor.
781 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800782 * @param ipEcn the IP ECN value to match (3 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800783 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800784 public IPEcnCriterion(byte ipEcn) {
785 this.ipEcn = (byte) (ipEcn & MASK);
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800786 }
787
788 @Override
789 public Type type() {
790 return Type.IP_ECN;
791 }
792
793 /**
794 * Gets the IP ECN value to match.
795 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800796 * @return the IP ECN value to match (3 bits)
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800797 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800798 public byte ipEcn() {
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800799 return ipEcn;
800 }
801
802 @Override
803 public String toString() {
804 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800805 .add("ipEcn", Long.toHexString(ipEcn)).toString();
Pavlin Radoslavovd0fd8412015-02-04 13:57:00 -0800806 }
807
808 @Override
809 public int hashCode() {
810 return Objects.hash(type(), ipEcn);
811 }
812
813 @Override
814 public boolean equals(Object obj) {
815 if (this == obj) {
816 return true;
817 }
818 if (obj instanceof IPEcnCriterion) {
819 IPEcnCriterion that = (IPEcnCriterion) obj;
820 return Objects.equals(ipEcn, that.ipEcn) &&
821 Objects.equals(this.type(), that.type());
822 }
823 return false;
824 }
825 }
826
827 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800828 * Implementation of Internet Protocol Number criterion (8 bits unsigned)
829 * integer.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800830 */
alshabib7b795492014-09-16 14:38:39 -0700831 public static final class IPProtocolCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800832 private static final short MASK = 0xff;
833 private final short proto; // IP protocol number: 8 bits
alshabib7b795492014-09-16 14:38:39 -0700834
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800835 /**
836 * Constructor.
837 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800838 * @param protocol the IP protocol (e.g., TCP=6, UDP=17) to match
839 * (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800840 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800841 public IPProtocolCriterion(short protocol) {
842 this.proto = (short) (protocol & MASK);
alshabib7b795492014-09-16 14:38:39 -0700843 }
844
845 @Override
846 public Type type() {
847 return Type.IP_PROTO;
848 }
849
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800850 /**
851 * Gets the IP protocol to match.
852 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800853 * @return the IP protocol to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800854 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800855 public short protocol() {
alshabib7b795492014-09-16 14:38:39 -0700856 return proto;
857 }
858
alshabib99b8fdc2014-09-25 14:30:22 -0700859 @Override
860 public String toString() {
861 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800862 .add("protocol", proto).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700863 }
864
alshabibba5ac482014-10-02 17:15:20 -0700865 @Override
866 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800867 return Objects.hash(type(), proto);
alshabibba5ac482014-10-02 17:15:20 -0700868 }
869
870 @Override
871 public boolean equals(Object obj) {
872 if (this == obj) {
873 return true;
874 }
875 if (obj instanceof IPProtocolCriterion) {
876 IPProtocolCriterion that = (IPProtocolCriterion) obj;
877 return Objects.equals(proto, that.proto);
alshabibba5ac482014-10-02 17:15:20 -0700878 }
879 return false;
880 }
alshabib7b795492014-09-16 14:38:39 -0700881 }
882
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800883 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800884 * Implementation of IP address criterion.
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800885 */
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800886 public static final class IPCriterion implements Criterion {
887 private final IpPrefix ip;
888 private final Type type;
alshabib7b795492014-09-16 14:38:39 -0700889
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800890 /**
891 * Constructor.
892 *
893 * @param ip the IP prefix to match. Could be either IPv4 or IPv6
894 * @param type the match type. Should be one of the following:
895 * Type.IPV4_SRC, Type.IPV4_DST, Type.IPV6_SRC, Type.IPV6_DST
896 */
897 public IPCriterion(IpPrefix ip, Type type) {
898 this.ip = ip;
899 this.type = type;
alshabib7b795492014-09-16 14:38:39 -0700900 }
901
902 @Override
903 public Type type() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800904 return this.type;
alshabib7b795492014-09-16 14:38:39 -0700905 }
906
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800907 /**
908 * Gets the IP prefix to match.
909 *
910 * @return the IP prefix to match
911 */
912 public IpPrefix ip() {
913 return this.ip;
alshabib7b795492014-09-16 14:38:39 -0700914 }
915
alshabib99b8fdc2014-09-25 14:30:22 -0700916 @Override
917 public String toString() {
918 return toStringHelper(type().toString())
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800919 .add("ip", ip).toString();
alshabib99b8fdc2014-09-25 14:30:22 -0700920 }
921
alshabibba5ac482014-10-02 17:15:20 -0700922 @Override
923 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800924 return Objects.hash(type, ip);
alshabibba5ac482014-10-02 17:15:20 -0700925 }
926
927 @Override
928 public boolean equals(Object obj) {
929 if (this == obj) {
930 return true;
931 }
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800932 if (obj instanceof IPCriterion) {
933 IPCriterion that = (IPCriterion) obj;
934 return Objects.equals(ip, that.ip) &&
935 Objects.equals(type, that.type);
alshabibba5ac482014-10-02 17:15:20 -0700936 }
937 return false;
938 }
alshabib7b795492014-09-16 14:38:39 -0700939 }
940
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800941 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800942 * Implementation of TCP port criterion (16 bits unsigned integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -0800943 */
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700944 public static final class TcpPortCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800945 private static final int MASK = 0xffff;
946 private final int tcpPort; // Port value: 16 bits
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700947 private final Type type;
948
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800949 /**
950 * Constructor.
951 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800952 * @param tcpPort the TCP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800953 * @param type the match type. Should be either Type.TCP_SRC or
954 * Type.TCP_DST
955 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800956 public TcpPortCriterion(int tcpPort, Type type) {
957 this.tcpPort = tcpPort & MASK;
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700958 this.type = type;
959 }
960
961 @Override
962 public Type type() {
963 return this.type;
964 }
965
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800966 /**
967 * Gets the TCP port to match.
968 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800969 * @return the TCP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800970 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800971 public int tcpPort() {
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700972 return this.tcpPort;
973 }
974
975 @Override
976 public String toString() {
977 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -0800978 .add("tcpPort", tcpPort).toString();
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700979 }
980
981 @Override
982 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800983 return Objects.hash(type, tcpPort);
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700984 }
985
986 @Override
987 public boolean equals(Object obj) {
988 if (this == obj) {
989 return true;
990 }
991 if (obj instanceof TcpPortCriterion) {
992 TcpPortCriterion that = (TcpPortCriterion) obj;
993 return Objects.equals(tcpPort, that.tcpPort) &&
994 Objects.equals(type, that.type);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -0800995 }
996 return false;
997 }
998 }
Toshio Koide9c44c9a2014-10-09 11:44:36 -0700999
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001000 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001001 * Implementation of UDP port criterion (16 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001002 */
1003 public static final class UdpPortCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001004 private static final int MASK = 0xffff;
1005 private final int udpPort; // Port value: 16 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001006 private final Type type;
Toshio Koide9c44c9a2014-10-09 11:44:36 -07001007
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001008 /**
1009 * Constructor.
1010 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001011 * @param udpPort the UDP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001012 * @param type the match type. Should be either Type.UDP_SRC or
1013 * Type.UDP_DST
1014 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001015 public UdpPortCriterion(int udpPort, Type type) {
1016 this.udpPort = udpPort & MASK;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001017 this.type = type;
1018 }
1019
1020 @Override
1021 public Type type() {
1022 return this.type;
1023 }
1024
1025 /**
1026 * Gets the UDP port to match.
1027 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001028 * @return the UDP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001029 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001030 public int udpPort() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001031 return this.udpPort;
1032 }
1033
1034 @Override
1035 public String toString() {
1036 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001037 .add("udpPort", udpPort).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001038 }
1039
1040 @Override
1041 public int hashCode() {
1042 return Objects.hash(type, udpPort);
1043 }
1044
1045 @Override
1046 public boolean equals(Object obj) {
1047 if (this == obj) {
1048 return true;
1049 }
1050 if (obj instanceof UdpPortCriterion) {
1051 UdpPortCriterion that = (UdpPortCriterion) obj;
1052 return Objects.equals(udpPort, that.udpPort) &&
1053 Objects.equals(type, that.type);
1054 }
1055 return false;
1056 }
1057 }
1058
1059 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001060 * Implementation of SCTP port criterion (16 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001061 */
1062 public static final class SctpPortCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001063 private static final int MASK = 0xffff;
1064 private final int sctpPort; // Port value: 16 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001065 private final Type type;
1066
1067 /**
1068 * Constructor.
1069 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001070 * @param sctpPort the SCTP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001071 * @param type the match type. Should be either Type.SCTP_SRC or
1072 * Type.SCTP_DST
1073 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001074 public SctpPortCriterion(int sctpPort, Type type) {
1075 this.sctpPort = sctpPort & MASK;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001076 this.type = type;
1077 }
1078
1079 @Override
1080 public Type type() {
1081 return this.type;
1082 }
1083
1084 /**
1085 * Gets the SCTP port to match.
1086 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001087 * @return the SCTP port to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001088 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001089 public int sctpPort() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001090 return this.sctpPort;
1091 }
1092
1093 @Override
1094 public String toString() {
1095 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001096 .add("sctpPort", sctpPort).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001097 }
1098
1099 @Override
1100 public int hashCode() {
1101 return Objects.hash(type, sctpPort);
1102 }
1103
1104 @Override
1105 public boolean equals(Object obj) {
1106 if (this == obj) {
1107 return true;
1108 }
1109 if (obj instanceof SctpPortCriterion) {
1110 SctpPortCriterion that = (SctpPortCriterion) obj;
1111 return Objects.equals(sctpPort, that.sctpPort) &&
1112 Objects.equals(type, that.type);
1113 }
1114 return false;
1115 }
1116 }
1117
1118 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001119 * Implementation of ICMP type criterion (8 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001120 */
1121 public static final class IcmpTypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001122 private static final short MASK = 0xff;
1123 private final short icmpType; // The ICMP type: 8 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001124
1125 /**
1126 * Constructor.
1127 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001128 * @param icmpType the ICMP type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001129 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001130 public IcmpTypeCriterion(short icmpType) {
1131 this.icmpType = (short) (icmpType & MASK);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001132 }
1133
1134 @Override
1135 public Type type() {
1136 return Type.ICMPV4_TYPE;
1137 }
1138
1139 /**
1140 * Gets the ICMP type to match.
1141 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001142 * @return the ICMP type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001143 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001144 public short icmpType() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001145 return icmpType;
1146 }
1147
1148 @Override
1149 public String toString() {
1150 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001151 .add("icmpType", icmpType).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001152 }
1153
1154 @Override
1155 public int hashCode() {
1156 return Objects.hash(type(), icmpType);
1157 }
1158
1159 @Override
1160 public boolean equals(Object obj) {
1161 if (this == obj) {
1162 return true;
1163 }
1164 if (obj instanceof IcmpTypeCriterion) {
1165 IcmpTypeCriterion that = (IcmpTypeCriterion) obj;
1166 return Objects.equals(icmpType, that.icmpType) &&
1167 Objects.equals(this.type(), that.type());
1168 }
1169 return false;
1170 }
1171 }
1172
1173 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001174 * Implementation of ICMP code criterion (8 bits unsigned integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001175 */
1176 public static final class IcmpCodeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001177 private static final short MASK = 0xff;
1178 private final short icmpCode; // The ICMP code: 8 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001179
1180 /**
1181 * Constructor.
1182 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001183 * @param icmpCode the ICMP code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001184 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001185 public IcmpCodeCriterion(short icmpCode) {
1186 this.icmpCode = (short) (icmpCode & MASK);
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001187 }
1188
1189 @Override
1190 public Type type() {
1191 return Type.ICMPV4_CODE;
1192 }
1193
1194 /**
1195 * Gets the ICMP code to match.
1196 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001197 * @return the ICMP code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001198 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001199 public short icmpCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001200 return icmpCode;
1201 }
1202
1203 @Override
1204 public String toString() {
1205 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001206 .add("icmpCode", icmpCode).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001207 }
1208
1209 @Override
1210 public int hashCode() {
1211 return Objects.hash(type(), icmpCode);
1212 }
1213
1214 @Override
1215 public boolean equals(Object obj) {
1216 if (this == obj) {
1217 return true;
1218 }
1219 if (obj instanceof IcmpCodeCriterion) {
1220 IcmpCodeCriterion that = (IcmpCodeCriterion) obj;
1221 return Objects.equals(icmpCode, that.icmpCode) &&
1222 Objects.equals(this.type(), that.type());
1223 }
1224 return false;
1225 }
1226 }
1227
1228 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001229 * Implementation of IPv6 Flow Label (RFC 6437) criterion (20 bits unsigned
1230 * integer).
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001231 */
1232 public static final class IPv6FlowLabelCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001233 private static final int MASK = 0xfffff;
1234 private final int flowLabel; // IPv6 flow label: 20 bits
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001235
1236 /**
1237 * Constructor.
1238 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001239 * @param flowLabel the IPv6 flow label to match (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001240 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001241 public IPv6FlowLabelCriterion(int flowLabel) {
1242 this.flowLabel = flowLabel & MASK;
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001243 }
1244
1245 @Override
1246 public Type type() {
1247 return Type.IPV6_FLABEL;
1248 }
1249
1250 /**
1251 * Gets the IPv6 flow label to match.
1252 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001253 * @return the IPv6 flow label to match (20 bits)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001254 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001255 public int flowLabel() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001256 return flowLabel;
1257 }
1258
1259 @Override
1260 public String toString() {
1261 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001262 .add("flowLabel", Long.toHexString(flowLabel)).toString();
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001263 }
1264
1265 @Override
1266 public int hashCode() {
1267 return Objects.hash(type(), flowLabel);
1268 }
1269
1270 @Override
1271 public boolean equals(Object obj) {
1272 if (this == obj) {
1273 return true;
1274 }
1275 if (obj instanceof IPv6FlowLabelCriterion) {
1276 IPv6FlowLabelCriterion that = (IPv6FlowLabelCriterion) obj;
1277 return Objects.equals(flowLabel, that.flowLabel) &&
1278 Objects.equals(this.type(), that.type());
Toshio Koide9c44c9a2014-10-09 11:44:36 -07001279 }
1280 return false;
1281 }
1282 }
Marc De Leenheer49087752014-10-23 13:54:09 -07001283
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001284 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001285 * Implementation of ICMPv6 type criterion (8 bits unsigned integer).
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001286 */
1287 public static final class Icmpv6TypeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001288 private static final short MASK = 0xff;
1289 private final short icmpv6Type; // ICMPv6 type: 8 bits
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001290
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001291 /**
1292 * Constructor.
1293 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001294 * @param icmpv6Type the ICMPv6 type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001295 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001296 public Icmpv6TypeCriterion(short icmpv6Type) {
1297 this.icmpv6Type = (short) (icmpv6Type & MASK);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001298 }
1299
1300 @Override
1301 public Type type() {
1302 return Type.ICMPV6_TYPE;
1303 }
1304
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001305 /**
1306 * Gets the ICMPv6 type to match.
1307 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001308 * @return the ICMPv6 type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001309 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001310 public short icmpv6Type() {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001311 return icmpv6Type;
1312 }
1313
1314 @Override
1315 public String toString() {
1316 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001317 .add("icmpv6Type", icmpv6Type).toString();
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001318 }
1319
1320 @Override
1321 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001322 return Objects.hash(type(), icmpv6Type);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001323 }
1324
1325 @Override
1326 public boolean equals(Object obj) {
1327 if (this == obj) {
1328 return true;
1329 }
1330 if (obj instanceof Icmpv6TypeCriterion) {
1331 Icmpv6TypeCriterion that = (Icmpv6TypeCriterion) obj;
1332 return Objects.equals(icmpv6Type, that.icmpv6Type) &&
1333 Objects.equals(this.type(), that.type());
1334 }
1335 return false;
1336 }
1337 }
1338
1339 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001340 * Implementation of ICMPv6 code criterion (8 bits unsigned integer).
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001341 */
1342 public static final class Icmpv6CodeCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001343 private static final short MASK = 0xff;
1344 private final short icmpv6Code; // ICMPv6 code: 8 bits
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001345
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001346 /**
1347 * Constructor.
1348 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001349 * @param icmpv6Code the ICMPv6 code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001350 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001351 public Icmpv6CodeCriterion(short icmpv6Code) {
1352 this.icmpv6Code = (short) (icmpv6Code & MASK);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001353 }
1354
1355 @Override
1356 public Type type() {
1357 return Type.ICMPV6_CODE;
1358 }
1359
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001360 /**
1361 * Gets the ICMPv6 code to match.
1362 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001363 * @return the ICMPv6 code to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001364 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001365 public short icmpv6Code() {
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001366 return icmpv6Code;
1367 }
1368
1369 @Override
1370 public String toString() {
1371 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001372 .add("icmpv6Code", icmpv6Code).toString();
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001373 }
1374
1375 @Override
1376 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001377 return Objects.hash(type(), icmpv6Code);
Kunihiro Ishiguro0f9aba82015-01-15 17:14:17 -08001378 }
1379
1380 @Override
1381 public boolean equals(Object obj) {
1382 if (this == obj) {
1383 return true;
1384 }
1385 if (obj instanceof Icmpv6CodeCriterion) {
1386 Icmpv6CodeCriterion that = (Icmpv6CodeCriterion) obj;
1387 return Objects.equals(icmpv6Code, that.icmpv6Code) &&
1388 Objects.equals(this.type(), that.type());
1389 }
1390 return false;
1391 }
1392 }
1393
1394 /**
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001395 * Implementation of IPv6 Neighbor Discovery target address criterion.
1396 */
1397 public static final class IPv6NDTargetAddressCriterion
1398 implements Criterion {
1399 private final Ip6Address targetAddress;
1400
1401 /**
1402 * Constructor.
1403 *
1404 * @param targetAddress the IPv6 target address to match
1405 */
1406 public IPv6NDTargetAddressCriterion(Ip6Address targetAddress) {
1407 this.targetAddress = targetAddress;
1408 }
1409
1410 @Override
1411 public Type type() {
1412 return Type.IPV6_ND_TARGET;
1413 }
1414
1415 /**
1416 * Gets the IPv6 target address to match.
1417 *
1418 * @return the IPv6 target address to match
1419 */
1420 public Ip6Address targetAddress() {
1421 return this.targetAddress;
1422 }
1423
1424 @Override
1425 public String toString() {
1426 return toStringHelper(type().toString())
1427 .add("targetAddress", targetAddress).toString();
1428 }
1429
1430 @Override
1431 public int hashCode() {
1432 return Objects.hash(type(), targetAddress);
1433 }
1434
1435 @Override
1436 public boolean equals(Object obj) {
1437 if (this == obj) {
1438 return true;
1439 }
1440 if (obj instanceof IPv6NDTargetAddressCriterion) {
1441 IPv6NDTargetAddressCriterion that =
1442 (IPv6NDTargetAddressCriterion) obj;
1443 return Objects.equals(targetAddress, that.targetAddress) &&
1444 Objects.equals(type(), that.type());
1445 }
1446 return false;
1447 }
1448 }
1449
1450 /**
1451 * Implementation of IPv6 Neighbor Discovery link-layer address criterion.
1452 */
1453 public static final class IPv6NDLinkLayerAddressCriterion
1454 implements Criterion {
1455 private final MacAddress mac;
1456 private final Type type;
1457
1458 /**
1459 * Constructor.
1460 *
1461 * @param mac the source or destination link-layer address to match
1462 * @param type the match type. Should be either Type.IPV6_ND_SLL or
1463 * Type.IPV6_ND_TLL
1464 */
1465 public IPv6NDLinkLayerAddressCriterion(MacAddress mac, Type type) {
1466 this.mac = mac;
1467 this.type = type;
1468 }
1469
1470 @Override
1471 public Type type() {
1472 return this.type;
1473 }
1474
1475 /**
1476 * Gets the MAC link-layer address to match.
1477 *
1478 * @return the MAC link-layer address to match
1479 */
1480 public MacAddress mac() {
1481 return this.mac;
1482 }
1483
1484 @Override
1485 public String toString() {
1486 return toStringHelper(type().toString())
1487 .add("mac", mac).toString();
1488 }
1489
1490 @Override
1491 public int hashCode() {
1492 return Objects.hash(type, mac);
1493 }
1494
1495 @Override
1496 public boolean equals(Object obj) {
1497 if (this == obj) {
1498 return true;
1499 }
1500 if (obj instanceof IPv6NDLinkLayerAddressCriterion) {
1501 IPv6NDLinkLayerAddressCriterion that =
1502 (IPv6NDLinkLayerAddressCriterion) obj;
1503 return Objects.equals(mac, that.mac) &&
1504 Objects.equals(type, that.type);
1505 }
1506 return false;
1507 }
1508 }
1509
1510 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001511 * Implementation of MPLS tag criterion (20 bits).
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001512 */
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001513 public static final class MplsCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001514 private static final int MASK = 0xfffff;
Michele Santuari4b6019e2014-12-19 11:31:45 +01001515 private final MplsLabel mplsLabel;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001516
Michele Santuari4b6019e2014-12-19 11:31:45 +01001517 public MplsCriterion(MplsLabel mplsLabel) {
1518 this.mplsLabel = mplsLabel;
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001519 }
1520
1521 @Override
1522 public Type type() {
1523 return Type.MPLS_LABEL;
1524 }
1525
Michele Santuari4b6019e2014-12-19 11:31:45 +01001526 public MplsLabel label() {
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001527 return mplsLabel;
1528 }
1529
1530 @Override
1531 public String toString() {
1532 return toStringHelper(type().toString())
Michele Santuari4b6019e2014-12-19 11:31:45 +01001533 .add("mpls", mplsLabel).toString();
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001534 }
1535
1536 @Override
1537 public int hashCode() {
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001538 return Objects.hash(type(), mplsLabel);
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001539 }
1540
1541 @Override
1542 public boolean equals(Object obj) {
1543 if (this == obj) {
1544 return true;
1545 }
1546 if (obj instanceof MplsCriterion) {
1547 MplsCriterion that = (MplsCriterion) obj;
1548 return Objects.equals(mplsLabel, that.mplsLabel) &&
1549 Objects.equals(this.type(), that.type());
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001550 }
1551 return false;
1552 }
Praseed Balakrishnan8c67d172014-11-10 10:15:41 -08001553 }
1554
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001555 /**
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001556 * Implementation of IPv6 Extension Header pseudo-field criterion
1557 * (16 bits). Those are defined in Criterion.IPv6ExthdrFlags.
1558 */
1559 public static final class IPv6ExthdrFlagsCriterion implements Criterion {
1560 private static final int MASK = 0xffff;
1561 private final int exthdrFlags; // IPv6 Exthdr flags: 16 bits
1562
1563 /**
1564 * Constructor.
1565 *
1566 * @param exthdrFlags the IPv6 Extension Header pseudo-field flags
1567 * to match (16 bits). Those are defined in Criterion.IPv6ExthdrFlags
1568 */
1569 public IPv6ExthdrFlagsCriterion(int exthdrFlags) {
1570 this.exthdrFlags = exthdrFlags & MASK;
1571 }
1572
1573 @Override
1574 public Type type() {
1575 return Type.IPV6_EXTHDR;
1576 }
1577
1578 /**
1579 * Gets the IPv6 Extension Header pseudo-field flags to match.
1580 *
1581 * @return the IPv6 Extension Header pseudo-field flags to match
1582 * (16 bits). Those are defined in Criterion.IPv6ExthdrFlags
1583 */
1584 public int exthdrFlags() {
1585 return exthdrFlags;
1586 }
1587
1588 @Override
1589 public String toString() {
1590 return toStringHelper(type().toString())
1591 .add("exthdrFlags", Long.toHexString(exthdrFlags)).toString();
1592 }
1593
1594 @Override
1595 public int hashCode() {
1596 return Objects.hash(type(), exthdrFlags);
1597 }
1598
1599 @Override
1600 public boolean equals(Object obj) {
1601 if (this == obj) {
1602 return true;
1603 }
1604 if (obj instanceof IPv6ExthdrFlagsCriterion) {
1605 IPv6ExthdrFlagsCriterion that = (IPv6ExthdrFlagsCriterion) obj;
1606 return Objects.equals(exthdrFlags, that.exthdrFlags) &&
1607 Objects.equals(this.type(), that.type());
1608 }
1609 return false;
1610 }
1611 }
1612
1613 /**
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001614 * Implementation of lambda (wavelength) criterion (16 bits unsigned
1615 * integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001616 */
Marc De Leenheer49087752014-10-23 13:54:09 -07001617 public static final class LambdaCriterion implements Criterion {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001618 private static final int MASK = 0xffff;
1619 private final int lambda; // Lambda value: 16 bits
Marc De Leenheer49087752014-10-23 13:54:09 -07001620 private final Type type;
1621
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001622 /**
1623 * Constructor.
1624 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001625 * @param lambda the lambda (wavelength) to match (16 bits unsigned
1626 * integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001627 * @param type the match type. Should be Type.OCH_SIGID
1628 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001629 public LambdaCriterion(int lambda, Type type) {
1630 this.lambda = lambda & MASK;
Marc De Leenheer49087752014-10-23 13:54:09 -07001631 this.type = type;
1632 }
1633
1634 @Override
1635 public Type type() {
1636 return this.type;
1637 }
1638
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001639 /**
1640 * Gets the lambda (wavelength) to match.
1641 *
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001642 * @return the lambda (wavelength) to match (16 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001643 */
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001644 public int lambda() {
1645 return lambda;
Marc De Leenheer49087752014-10-23 13:54:09 -07001646 }
1647
1648 @Override
1649 public String toString() {
1650 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001651 .add("lambda", lambda).toString();
Marc De Leenheer49087752014-10-23 13:54:09 -07001652 }
1653
1654 @Override
1655 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -08001656 return Objects.hash(type, lambda);
Marc De Leenheer49087752014-10-23 13:54:09 -07001657 }
1658
1659 @Override
1660 public boolean equals(Object obj) {
1661 if (this == obj) {
1662 return true;
1663 }
1664 if (obj instanceof LambdaCriterion) {
1665 LambdaCriterion that = (LambdaCriterion) obj;
1666 return Objects.equals(lambda, that.lambda) &&
1667 Objects.equals(type, that.type);
1668 }
1669 return false;
1670 }
1671 }
1672
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001673 /**
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001674 * Implementation of optical signal type criterion (8 bits unsigned
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001675 * integer).
Sho SHIMIZU06596e32014-12-02 18:07:50 -08001676 */
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001677 public static final class OpticalSignalTypeCriterion implements Criterion {
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001678 private static final short MASK = 0xff;
1679 private final short signalType; // Signal type value: 8 bits
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001680 private final Type type;
1681
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001682 /**
1683 * Constructor.
1684 *
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001685 * @param signalType the optical signal type to match (8 bits unsigned
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001686 * integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001687 * @param type the match type. Should be Type.OCH_SIGTYPE
1688 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001689 public OpticalSignalTypeCriterion(short signalType, Type type) {
1690 this.signalType = (short) (signalType & MASK);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001691 this.type = type;
1692 }
1693
1694 @Override
1695 public Type type() {
1696 return this.type;
1697 }
1698
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001699 /**
1700 * Gets the optical signal type to match.
1701 *
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001702 * @return the optical signal type to match (8 bits unsigned integer)
Pavlin Radoslavov320e6c92015-02-02 16:51:58 -08001703 */
Pavlin Radoslavov5e4f7542015-02-06 18:18:21 -08001704 public short signalType() {
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001705 return signalType;
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001706 }
1707
1708 @Override
1709 public String toString() {
1710 return toStringHelper(type().toString())
Pavlin Radoslavovf3b69332015-02-06 15:47:05 -08001711 .add("signalType", signalType).toString();
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001712 }
1713
1714 @Override
1715 public int hashCode() {
Thomas Vachuska9b2da212014-11-10 19:30:25 -08001716 return Objects.hash(type, signalType);
Praseed Balakrishnan64369da2014-10-23 15:55:20 -07001717 }
1718
1719 @Override
1720 public boolean equals(Object obj) {
1721 if (this == obj) {
1722 return true;
1723 }
1724 if (obj instanceof OpticalSignalTypeCriterion) {
1725 OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj;
1726 return Objects.equals(signalType, that.signalType) &&
1727 Objects.equals(type, that.type);
1728 }
1729 return false;
1730 }
1731 }
tom8bb16062014-09-12 14:47:46 -07001732}