blob: 12f31b55e79cded6dc51ec1e42d2a26b31a1c62e [file] [log] [blame]
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * 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
7 *
8 * 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.
15 */
16package org.onosproject.net.flow.criteria;
17
18import java.util.Objects;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
21
22/**
23 * Implementation of UDP port criterion (16 bits unsigned integer).
24 */
25public final class UdpPortCriterion implements Criterion {
26 private static final int MASK = 0xffff;
27 private final int udpPort; // Port value: 16 bits
28 private final Type type;
29
30 /**
31 * Constructor.
32 *
33 * @param udpPort the UDP port to match (16 bits unsigned integer)
34 * @param type the match type. Should be either Type.UDP_SRC or
35 * Type.UDP_DST
36 */
37 UdpPortCriterion(int udpPort, Type type) {
38 this.udpPort = udpPort & MASK;
39 this.type = type;
40 }
41
42 @Override
43 public Type type() {
44 return this.type;
45 }
46
47 /**
48 * Gets the UDP port to match.
49 *
50 * @return the UDP port to match (16 bits unsigned integer)
51 */
52 public int udpPort() {
53 return this.udpPort;
54 }
55
56 @Override
57 public String toString() {
58 return toStringHelper(type().toString())
59 .add("udpPort", udpPort).toString();
60 }
61
62 @Override
63 public int hashCode() {
64 return Objects.hash(type, udpPort);
65 }
66
67 @Override
68 public boolean equals(Object obj) {
69 if (this == obj) {
70 return true;
71 }
72 if (obj instanceof UdpPortCriterion) {
73 UdpPortCriterion that = (UdpPortCriterion) obj;
74 return Objects.equals(udpPort, that.udpPort) &&
75 Objects.equals(type, that.type);
76 }
77 return false;
78 }
79}