Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow.criteria; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 17 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 20 | import java.util.Objects; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.PortNumber; |
| 22 | import org.onosproject.net.flow.criteria.Criterion.Type; |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 23 | import org.onlab.packet.IpPrefix; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 24 | import org.onlab.packet.MacAddress; |
| 25 | import org.onlab.packet.VlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 26 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Factory class to create various traffic selection criteria. |
| 29 | */ |
| 30 | public final class Criteria { |
| 31 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 32 | //TODO: incomplete type implementation. Need to implement complete list from Criterion |
| 33 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 34 | // Ban construction |
| 35 | private Criteria() { |
| 36 | } |
| 37 | |
| 38 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 39 | * Creates a match on IN_PORT field using the specified value. |
| 40 | * |
| 41 | * @param port inport value |
| 42 | * @return match criterion |
| 43 | */ |
| 44 | public static Criterion matchInPort(PortNumber port) { |
| 45 | return new PortCriterion(port); |
| 46 | } |
| 47 | |
| 48 | /** |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 49 | * Creates a match on ETH_SRC field using the specified value. This value |
| 50 | * may be a wildcard mask. |
| 51 | * |
tom | c104d28 | 2014-09-19 10:57:55 -0700 | [diff] [blame] | 52 | * @param mac MAC address value or wildcard mask |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 53 | * @return match criterion |
| 54 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 55 | public static Criterion matchEthSrc(MacAddress mac) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 56 | return new EthCriterion(mac, Type.ETH_SRC); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 57 | } |
| 58 | |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 59 | /** |
| 60 | * Creates a match on ETH_DST field using the specified value. This value |
| 61 | * may be a wildcard mask. |
| 62 | * |
tom | c104d28 | 2014-09-19 10:57:55 -0700 | [diff] [blame] | 63 | * @param mac MAC address value or wildcard mask |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 64 | * @return match criterion |
| 65 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 66 | public static Criterion matchEthDst(MacAddress mac) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 67 | return new EthCriterion(mac, Type.ETH_DST); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Creates a match on ETH_TYPE field using the specified value. |
| 72 | * |
| 73 | * @param ethType eth type value |
| 74 | * @return match criterion |
| 75 | */ |
| 76 | public static Criterion matchEthType(Short ethType) { |
| 77 | return new EthTypeCriterion(ethType); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Creates a match on VLAN ID field using the specified value. |
| 82 | * |
| 83 | * @param vlanId vlan id value |
| 84 | * @return match criterion |
| 85 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 86 | public static Criterion matchVlanId(VlanId vlanId) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 87 | return new VlanIdCriterion(vlanId); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Creates a match on VLAN PCP field using the specified value. |
| 92 | * |
| 93 | * @param vlanPcp vlan pcp value |
| 94 | * @return match criterion |
| 95 | */ |
alshabib | b45d196 | 2014-09-18 14:25:45 -0700 | [diff] [blame] | 96 | public static Criterion matchVlanPcp(Byte vlanPcp) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 97 | return new VlanPcpCriterion(vlanPcp); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Creates a match on IP proto field using the specified value. |
| 102 | * |
| 103 | * @param proto ip protocol value |
| 104 | * @return match criterion |
| 105 | */ |
| 106 | public static Criterion matchIPProtocol(Byte proto) { |
| 107 | return new IPProtocolCriterion(proto); |
| 108 | } |
| 109 | |
| 110 | /** |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame^] | 111 | * Creates a match on IPv4 source field using the specified value. |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 112 | * |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame^] | 113 | * @param ip ipv4 source value |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 114 | * @return match criterion |
| 115 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 116 | public static Criterion matchIPSrc(IpPrefix ip) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 117 | return new IPCriterion(ip, Type.IPV4_SRC); |
| 118 | } |
| 119 | |
| 120 | /** |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame^] | 121 | * Creates a match on IPv4 destination field using the specified value. |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 122 | * |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame^] | 123 | * @param ip ipv4 source value |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 124 | * @return match criterion |
| 125 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 126 | public static Criterion matchIPDst(IpPrefix ip) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 127 | return new IPCriterion(ip, Type.IPV4_DST); |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 130 | /** |
| 131 | * Creates a match on TCP source port field using the specified value. |
| 132 | * |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 133 | * @param tcpPort TCP source port |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 134 | * @return match criterion |
| 135 | */ |
| 136 | public static Criterion matchTcpSrc(Short tcpPort) { |
| 137 | return new TcpPortCriterion(tcpPort, Type.TCP_SRC); |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Creates a match on TCP destination port field using the specified value. |
| 142 | * |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 143 | * @param tcpPort TCP destination port |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 144 | * @return match criterion |
| 145 | */ |
| 146 | public static Criterion matchTcpDst(Short tcpPort) { |
| 147 | return new TcpPortCriterion(tcpPort, Type.TCP_DST); |
| 148 | } |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 149 | |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 150 | /** |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame^] | 151 | * Creates a match on IPv6 source field using the specified value. |
| 152 | * |
| 153 | * @param ip ipv6 source value |
| 154 | * @return match criterion |
| 155 | */ |
| 156 | public static Criterion matchIPv6Src(IpPrefix ip) { |
| 157 | return new IPCriterion(ip, Type.IPV6_SRC); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Creates a match on IPv6 destination field using the specified value. |
| 162 | * |
| 163 | * @param ip ipv6 source value |
| 164 | * @return match criterion |
| 165 | */ |
| 166 | public static Criterion matchIPv6Dst(IpPrefix ip) { |
| 167 | return new IPCriterion(ip, Type.IPV6_DST); |
| 168 | } |
| 169 | |
| 170 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 171 | * Creates a match on MPLS label. |
| 172 | * @param mplsLabel MPLS label |
| 173 | * @return match criterion |
| 174 | */ |
| 175 | |
| 176 | public static Criterion matchMplsLabel(Integer mplsLabel) { |
| 177 | return new MplsCriterion(mplsLabel); |
| 178 | } |
| 179 | |
| 180 | /** |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 181 | * Creates a match on lambda field using the specified value. |
| 182 | * |
Sho SHIMIZU | a66cb12 | 2014-12-02 18:11:15 -0800 | [diff] [blame] | 183 | * @param lambda lambda to match on |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 184 | * @return match criterion |
| 185 | */ |
| 186 | public static Criterion matchLambda(Short lambda) { |
| 187 | return new LambdaCriterion(lambda, Type.OCH_SIGID); |
| 188 | } |
| 189 | |
| 190 | /** |
Sho SHIMIZU | a66cb12 | 2014-12-02 18:11:15 -0800 | [diff] [blame] | 191 | * Creates a match on optical signal type using the specified value. |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 192 | * |
Sho SHIMIZU | a66cb12 | 2014-12-02 18:11:15 -0800 | [diff] [blame] | 193 | * @param sigType optical signal type |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 194 | * @return match criterion |
| 195 | */ |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 196 | public static Criterion matchOpticalSignalType(Short sigType) { |
| 197 | return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE); |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 200 | /** |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 201 | * Implementation of input port criterion. |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 202 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 203 | public static final class PortCriterion implements Criterion { |
| 204 | private final PortNumber port; |
| 205 | |
| 206 | public PortCriterion(PortNumber port) { |
| 207 | this.port = port; |
| 208 | } |
| 209 | |
| 210 | @Override |
| 211 | public Type type() { |
| 212 | return Type.IN_PORT; |
| 213 | } |
| 214 | |
| 215 | public PortNumber port() { |
| 216 | return this.port; |
| 217 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 218 | |
| 219 | @Override |
| 220 | public String toString() { |
| 221 | return toStringHelper(type().toString()) |
| 222 | .add("port", port).toString(); |
| 223 | } |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 224 | |
| 225 | @Override |
| 226 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 227 | return Objects.hash(type(), port); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | @Override |
| 231 | public boolean equals(Object obj) { |
| 232 | if (this == obj) { |
| 233 | return true; |
| 234 | } |
| 235 | if (obj instanceof PortCriterion) { |
| 236 | PortCriterion that = (PortCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 237 | return Objects.equals(port, that.port) && |
| 238 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 239 | |
| 240 | } |
| 241 | return false; |
| 242 | } |
| 243 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 247 | /** |
| 248 | * Implementation of MAC address criterion. |
| 249 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 250 | public static final class EthCriterion implements Criterion { |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 251 | private final MacAddress mac; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 252 | private final Type type; |
| 253 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 254 | public EthCriterion(MacAddress mac, Type type) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 255 | this.mac = mac; |
| 256 | this.type = type; |
| 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public Type type() { |
| 261 | return this.type; |
| 262 | } |
| 263 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 264 | public MacAddress mac() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 265 | return this.mac; |
| 266 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 267 | |
| 268 | @Override |
| 269 | public String toString() { |
| 270 | return toStringHelper(type().toString()) |
| 271 | .add("mac", mac).toString(); |
| 272 | } |
| 273 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 274 | @Override |
| 275 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 276 | return Objects.hash(type, mac); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public boolean equals(Object obj) { |
| 281 | if (this == obj) { |
| 282 | return true; |
| 283 | } |
| 284 | if (obj instanceof EthCriterion) { |
| 285 | EthCriterion that = (EthCriterion) obj; |
| 286 | return Objects.equals(mac, that.mac) && |
| 287 | Objects.equals(type, that.type); |
| 288 | |
| 289 | |
| 290 | } |
| 291 | return false; |
| 292 | } |
| 293 | |
| 294 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 297 | /** |
| 298 | * Implementation of Ethernet type criterion. |
| 299 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 300 | public static final class EthTypeCriterion implements Criterion { |
| 301 | |
| 302 | private final Short ethType; |
| 303 | |
| 304 | public EthTypeCriterion(Short ethType) { |
| 305 | this.ethType = ethType; |
| 306 | } |
| 307 | |
| 308 | @Override |
| 309 | public Type type() { |
| 310 | return Type.ETH_TYPE; |
| 311 | } |
| 312 | |
| 313 | public Short ethType() { |
| 314 | return ethType; |
| 315 | } |
| 316 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 317 | @Override |
| 318 | public String toString() { |
| 319 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 320 | .add("ethType", Long.toHexString(ethType & 0xffff)) |
| 321 | .toString(); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 322 | } |
| 323 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 324 | @Override |
| 325 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 326 | return Objects.hash(type(), ethType); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public boolean equals(Object obj) { |
| 331 | if (this == obj) { |
| 332 | return true; |
| 333 | } |
| 334 | if (obj instanceof EthTypeCriterion) { |
| 335 | EthTypeCriterion that = (EthTypeCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 336 | return Objects.equals(ethType, that.ethType) && |
| 337 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 338 | |
| 339 | |
| 340 | } |
| 341 | return false; |
| 342 | } |
| 343 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 346 | /** |
| 347 | * Implementation of IP address criterion. |
| 348 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 349 | public static final class IPCriterion implements Criterion { |
| 350 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 351 | private final IpPrefix ip; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 352 | private final Type type; |
| 353 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 354 | public IPCriterion(IpPrefix ip, Type type) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 355 | this.ip = ip; |
| 356 | this.type = type; |
| 357 | } |
| 358 | |
| 359 | @Override |
| 360 | public Type type() { |
| 361 | return this.type; |
| 362 | } |
| 363 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 364 | public IpPrefix ip() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 365 | return this.ip; |
| 366 | } |
| 367 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 368 | @Override |
| 369 | public String toString() { |
| 370 | return toStringHelper(type().toString()) |
| 371 | .add("ip", ip).toString(); |
| 372 | } |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 373 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 374 | @Override |
| 375 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 376 | return Objects.hash(type, ip); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public boolean equals(Object obj) { |
| 381 | if (this == obj) { |
| 382 | return true; |
| 383 | } |
| 384 | if (obj instanceof IPCriterion) { |
| 385 | IPCriterion that = (IPCriterion) obj; |
| 386 | return Objects.equals(ip, that.ip) && |
| 387 | Objects.equals(type, that.type); |
| 388 | |
| 389 | |
| 390 | } |
| 391 | return false; |
| 392 | } |
| 393 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 396 | /** |
| 397 | * Implementation of Internet Protocol Number criterion. |
| 398 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 399 | public static final class IPProtocolCriterion implements Criterion { |
| 400 | |
| 401 | private final Byte proto; |
| 402 | |
| 403 | public IPProtocolCriterion(Byte protocol) { |
| 404 | this.proto = protocol; |
| 405 | } |
| 406 | |
| 407 | @Override |
| 408 | public Type type() { |
| 409 | return Type.IP_PROTO; |
| 410 | } |
| 411 | |
| 412 | public Byte protocol() { |
| 413 | return proto; |
| 414 | } |
| 415 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 416 | @Override |
| 417 | public String toString() { |
| 418 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 419 | .add("protocol", Long.toHexString(proto & 0xff)) |
| 420 | .toString(); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 421 | } |
| 422 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 423 | @Override |
| 424 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 425 | return Objects.hash(type(), proto); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public boolean equals(Object obj) { |
| 430 | if (this == obj) { |
| 431 | return true; |
| 432 | } |
| 433 | if (obj instanceof IPProtocolCriterion) { |
| 434 | IPProtocolCriterion that = (IPProtocolCriterion) obj; |
| 435 | return Objects.equals(proto, that.proto); |
| 436 | |
| 437 | |
| 438 | } |
| 439 | return false; |
| 440 | } |
| 441 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 444 | /** |
| 445 | * Implementation of VLAN priority criterion. |
| 446 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 447 | public static final class VlanPcpCriterion implements Criterion { |
| 448 | |
| 449 | private final Byte vlanPcp; |
| 450 | |
| 451 | public VlanPcpCriterion(Byte vlanPcp) { |
| 452 | this.vlanPcp = vlanPcp; |
| 453 | } |
| 454 | |
| 455 | @Override |
| 456 | public Type type() { |
| 457 | return Type.VLAN_PCP; |
| 458 | } |
| 459 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 460 | public Byte priority() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 461 | return vlanPcp; |
| 462 | } |
| 463 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 464 | @Override |
| 465 | public String toString() { |
| 466 | return toStringHelper(type().toString()) |
| 467 | .add("pcp", Long.toHexString(vlanPcp)).toString(); |
| 468 | } |
| 469 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 470 | @Override |
| 471 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 472 | return Objects.hash(type(), vlanPcp); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | @Override |
| 476 | public boolean equals(Object obj) { |
| 477 | if (this == obj) { |
| 478 | return true; |
| 479 | } |
| 480 | if (obj instanceof VlanPcpCriterion) { |
| 481 | VlanPcpCriterion that = (VlanPcpCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 482 | return Objects.equals(vlanPcp, that.vlanPcp) && |
| 483 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 484 | |
| 485 | |
| 486 | } |
| 487 | return false; |
| 488 | } |
| 489 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 492 | /** |
| 493 | * Implementation of VLAN ID criterion. |
| 494 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 495 | public static final class VlanIdCriterion implements Criterion { |
| 496 | |
| 497 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 498 | private final VlanId vlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 499 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 500 | public VlanIdCriterion(VlanId vlanId) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 501 | this.vlanId = vlanId; |
| 502 | } |
| 503 | |
| 504 | @Override |
| 505 | public Type type() { |
| 506 | return Type.VLAN_VID; |
| 507 | } |
| 508 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 509 | public VlanId vlanId() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 510 | return vlanId; |
| 511 | } |
| 512 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 513 | @Override |
| 514 | public String toString() { |
| 515 | return toStringHelper(type().toString()) |
| 516 | .add("id", vlanId).toString(); |
| 517 | } |
| 518 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 519 | @Override |
| 520 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 521 | return Objects.hash(type(), vlanId); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | @Override |
| 525 | public boolean equals(Object obj) { |
| 526 | if (this == obj) { |
| 527 | return true; |
| 528 | } |
| 529 | if (obj instanceof VlanIdCriterion) { |
| 530 | VlanIdCriterion that = (VlanIdCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 531 | return Objects.equals(vlanId, that.vlanId) && |
| 532 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 533 | |
| 534 | |
| 535 | } |
| 536 | return false; |
| 537 | } |
| 538 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 541 | /** |
| 542 | * Implementation of TCP port criterion. |
| 543 | */ |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 544 | public static final class TcpPortCriterion implements Criterion { |
| 545 | |
| 546 | private final Short tcpPort; |
| 547 | private final Type type; |
| 548 | |
| 549 | public TcpPortCriterion(Short tcpPort, Type type) { |
| 550 | this.tcpPort = tcpPort; |
| 551 | this.type = type; |
| 552 | } |
| 553 | |
| 554 | @Override |
| 555 | public Type type() { |
| 556 | return this.type; |
| 557 | } |
| 558 | |
| 559 | public Short tcpPort() { |
| 560 | return this.tcpPort; |
| 561 | } |
| 562 | |
| 563 | @Override |
| 564 | public String toString() { |
| 565 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 566 | .add("tcpPort", tcpPort & 0xffff).toString(); |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | @Override |
| 570 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 571 | return Objects.hash(type, tcpPort); |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | @Override |
| 575 | public boolean equals(Object obj) { |
| 576 | if (this == obj) { |
| 577 | return true; |
| 578 | } |
| 579 | if (obj instanceof TcpPortCriterion) { |
| 580 | TcpPortCriterion that = (TcpPortCriterion) obj; |
| 581 | return Objects.equals(tcpPort, that.tcpPort) && |
| 582 | Objects.equals(type, that.type); |
| 583 | |
| 584 | |
| 585 | } |
| 586 | return false; |
| 587 | } |
| 588 | } |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 589 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 590 | /** |
| 591 | * Implementation of MPLS tag criterion. |
| 592 | */ |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 593 | public static final class MplsCriterion implements Criterion { |
| 594 | |
| 595 | private final Integer mplsLabel; |
| 596 | |
| 597 | public MplsCriterion(Integer mplsLabel) { |
| 598 | this.mplsLabel = mplsLabel; |
| 599 | } |
| 600 | |
| 601 | @Override |
| 602 | public Type type() { |
| 603 | return Type.MPLS_LABEL; |
| 604 | } |
| 605 | |
| 606 | public Integer label() { |
| 607 | return mplsLabel; |
| 608 | } |
| 609 | |
| 610 | @Override |
| 611 | public String toString() { |
| 612 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 613 | .add("mpls", mplsLabel & 0xffffffffL).toString(); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | @Override |
| 617 | public int hashCode() { |
| 618 | return Objects.hash(mplsLabel, type()); |
| 619 | } |
| 620 | |
| 621 | @Override |
| 622 | public boolean equals(Object obj) { |
| 623 | if (this == obj) { |
| 624 | return true; |
| 625 | } |
| 626 | if (obj instanceof MplsCriterion) { |
| 627 | MplsCriterion that = (MplsCriterion) obj; |
| 628 | return Objects.equals(mplsLabel, that.mplsLabel) && |
| 629 | Objects.equals(this.type(), that.type()); |
| 630 | |
| 631 | |
| 632 | } |
| 633 | return false; |
| 634 | } |
| 635 | |
| 636 | } |
| 637 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 638 | /** |
| 639 | * Implementation of lambda (wavelength) criterion. |
| 640 | */ |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 641 | public static final class LambdaCriterion implements Criterion { |
| 642 | |
| 643 | private final short lambda; |
| 644 | private final Type type; |
| 645 | |
| 646 | public LambdaCriterion(short lambda, Type type) { |
| 647 | this.lambda = lambda; |
| 648 | this.type = type; |
| 649 | } |
| 650 | |
| 651 | @Override |
| 652 | public Type type() { |
| 653 | return this.type; |
| 654 | } |
| 655 | |
| 656 | public Short lambda() { |
| 657 | return this.lambda; |
| 658 | } |
| 659 | |
| 660 | @Override |
| 661 | public String toString() { |
| 662 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 663 | .add("lambda", lambda & 0xffff).toString(); |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | @Override |
| 667 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 668 | return Objects.hash(type, lambda); |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | @Override |
| 672 | public boolean equals(Object obj) { |
| 673 | if (this == obj) { |
| 674 | return true; |
| 675 | } |
| 676 | if (obj instanceof LambdaCriterion) { |
| 677 | LambdaCriterion that = (LambdaCriterion) obj; |
| 678 | return Objects.equals(lambda, that.lambda) && |
| 679 | Objects.equals(type, that.type); |
| 680 | } |
| 681 | return false; |
| 682 | } |
| 683 | } |
| 684 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 685 | /** |
| 686 | * Implementation of optical signal type criterion. |
| 687 | */ |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 688 | public static final class OpticalSignalTypeCriterion implements Criterion { |
| 689 | |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 690 | private final Short signalType; |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 691 | private final Type type; |
| 692 | |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 693 | public OpticalSignalTypeCriterion(Short signalType, Type type) { |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 694 | this.signalType = signalType; |
| 695 | this.type = type; |
| 696 | } |
| 697 | |
| 698 | @Override |
| 699 | public Type type() { |
| 700 | return this.type; |
| 701 | } |
| 702 | |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 703 | public Short signalType() { |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 704 | return this.signalType; |
| 705 | } |
| 706 | |
| 707 | @Override |
| 708 | public String toString() { |
| 709 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 710 | .add("signalType", signalType & 0xffff).toString(); |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | @Override |
| 714 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 715 | return Objects.hash(type, signalType); |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | @Override |
| 719 | public boolean equals(Object obj) { |
| 720 | if (this == obj) { |
| 721 | return true; |
| 722 | } |
| 723 | if (obj instanceof OpticalSignalTypeCriterion) { |
| 724 | OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj; |
| 725 | return Objects.equals(signalType, that.signalType) && |
| 726 | Objects.equals(type, that.type); |
| 727 | } |
| 728 | return false; |
| 729 | } |
| 730 | } |
| 731 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 732 | } |