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