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 | |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame^] | 170 | /* |
| 171 | * Creates a match on ICMPv6 type field using the specified value. |
| 172 | * |
| 173 | * @param icmpv6Type ICMPv6 type |
| 174 | * @return match criterion |
| 175 | */ |
| 176 | public static Criterion matchIcmpv6Type(Byte icmpv6Type) { |
| 177 | return new Icmpv6TypeCriterion(icmpv6Type); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Creates a match on ICMPv6 code field using the specified value. |
| 182 | * |
| 183 | * @param icmpv6Code ICMPv6 code |
| 184 | * @return match criterion |
| 185 | */ |
| 186 | public static Criterion matchIcmpv6Code(Byte icmpv6Code) { |
| 187 | return new Icmpv6CodeCriterion(icmpv6Code); |
| 188 | } |
| 189 | |
Charles M.C. Chan | 52fae7d | 2015-01-17 00:35:53 +0800 | [diff] [blame] | 190 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 191 | * Creates a match on MPLS label. |
| 192 | * @param mplsLabel MPLS label |
| 193 | * @return match criterion |
| 194 | */ |
| 195 | |
| 196 | public static Criterion matchMplsLabel(Integer mplsLabel) { |
| 197 | return new MplsCriterion(mplsLabel); |
| 198 | } |
| 199 | |
| 200 | /** |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 201 | * Creates a match on lambda field using the specified value. |
| 202 | * |
Sho SHIMIZU | a66cb12 | 2014-12-02 18:11:15 -0800 | [diff] [blame] | 203 | * @param lambda lambda to match on |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 204 | * @return match criterion |
| 205 | */ |
| 206 | public static Criterion matchLambda(Short lambda) { |
| 207 | return new LambdaCriterion(lambda, Type.OCH_SIGID); |
| 208 | } |
| 209 | |
| 210 | /** |
Sho SHIMIZU | a66cb12 | 2014-12-02 18:11:15 -0800 | [diff] [blame] | 211 | * Creates a match on optical signal type using the specified value. |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 212 | * |
Sho SHIMIZU | a66cb12 | 2014-12-02 18:11:15 -0800 | [diff] [blame] | 213 | * @param sigType optical signal type |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 214 | * @return match criterion |
| 215 | */ |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 216 | public static Criterion matchOpticalSignalType(Short sigType) { |
| 217 | return new OpticalSignalTypeCriterion(sigType, Type.OCH_SIGTYPE); |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 220 | /** |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 221 | * Implementation of input port criterion. |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 222 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 223 | public static final class PortCriterion implements Criterion { |
| 224 | private final PortNumber port; |
| 225 | |
| 226 | public PortCriterion(PortNumber port) { |
| 227 | this.port = port; |
| 228 | } |
| 229 | |
| 230 | @Override |
| 231 | public Type type() { |
| 232 | return Type.IN_PORT; |
| 233 | } |
| 234 | |
| 235 | public PortNumber port() { |
| 236 | return this.port; |
| 237 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 238 | |
| 239 | @Override |
| 240 | public String toString() { |
| 241 | return toStringHelper(type().toString()) |
| 242 | .add("port", port).toString(); |
| 243 | } |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 244 | |
| 245 | @Override |
| 246 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 247 | return Objects.hash(type(), port); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public boolean equals(Object obj) { |
| 252 | if (this == obj) { |
| 253 | return true; |
| 254 | } |
| 255 | if (obj instanceof PortCriterion) { |
| 256 | PortCriterion that = (PortCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 257 | return Objects.equals(port, that.port) && |
| 258 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 259 | |
| 260 | } |
| 261 | return false; |
| 262 | } |
| 263 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 267 | /** |
| 268 | * Implementation of MAC address criterion. |
| 269 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 270 | public static final class EthCriterion implements Criterion { |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 271 | private final MacAddress mac; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 272 | private final Type type; |
| 273 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 274 | public EthCriterion(MacAddress mac, Type type) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 275 | this.mac = mac; |
| 276 | this.type = type; |
| 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public Type type() { |
| 281 | return this.type; |
| 282 | } |
| 283 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 284 | public MacAddress mac() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 285 | return this.mac; |
| 286 | } |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 287 | |
| 288 | @Override |
| 289 | public String toString() { |
| 290 | return toStringHelper(type().toString()) |
| 291 | .add("mac", mac).toString(); |
| 292 | } |
| 293 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 294 | @Override |
| 295 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 296 | return Objects.hash(type, mac); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | @Override |
| 300 | public boolean equals(Object obj) { |
| 301 | if (this == obj) { |
| 302 | return true; |
| 303 | } |
| 304 | if (obj instanceof EthCriterion) { |
| 305 | EthCriterion that = (EthCriterion) obj; |
| 306 | return Objects.equals(mac, that.mac) && |
| 307 | Objects.equals(type, that.type); |
| 308 | |
| 309 | |
| 310 | } |
| 311 | return false; |
| 312 | } |
| 313 | |
| 314 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 317 | /** |
| 318 | * Implementation of Ethernet type criterion. |
| 319 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 320 | public static final class EthTypeCriterion implements Criterion { |
| 321 | |
| 322 | private final Short ethType; |
| 323 | |
| 324 | public EthTypeCriterion(Short ethType) { |
| 325 | this.ethType = ethType; |
| 326 | } |
| 327 | |
| 328 | @Override |
| 329 | public Type type() { |
| 330 | return Type.ETH_TYPE; |
| 331 | } |
| 332 | |
| 333 | public Short ethType() { |
| 334 | return ethType; |
| 335 | } |
| 336 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 337 | @Override |
| 338 | public String toString() { |
| 339 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 340 | .add("ethType", Long.toHexString(ethType & 0xffff)) |
| 341 | .toString(); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 342 | } |
| 343 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 344 | @Override |
| 345 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 346 | return Objects.hash(type(), ethType); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | @Override |
| 350 | public boolean equals(Object obj) { |
| 351 | if (this == obj) { |
| 352 | return true; |
| 353 | } |
| 354 | if (obj instanceof EthTypeCriterion) { |
| 355 | EthTypeCriterion that = (EthTypeCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 356 | return Objects.equals(ethType, that.ethType) && |
| 357 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 358 | |
| 359 | |
| 360 | } |
| 361 | return false; |
| 362 | } |
| 363 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 366 | /** |
| 367 | * Implementation of IP address criterion. |
| 368 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 369 | public static final class IPCriterion implements Criterion { |
| 370 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 371 | private final IpPrefix ip; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 372 | private final Type type; |
| 373 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 374 | public IPCriterion(IpPrefix ip, Type type) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 375 | this.ip = ip; |
| 376 | this.type = type; |
| 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public Type type() { |
| 381 | return this.type; |
| 382 | } |
| 383 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 384 | public IpPrefix ip() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 385 | return this.ip; |
| 386 | } |
| 387 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 388 | @Override |
| 389 | public String toString() { |
| 390 | return toStringHelper(type().toString()) |
| 391 | .add("ip", ip).toString(); |
| 392 | } |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 393 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 394 | @Override |
| 395 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 396 | return Objects.hash(type, ip); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | @Override |
| 400 | public boolean equals(Object obj) { |
| 401 | if (this == obj) { |
| 402 | return true; |
| 403 | } |
| 404 | if (obj instanceof IPCriterion) { |
| 405 | IPCriterion that = (IPCriterion) obj; |
| 406 | return Objects.equals(ip, that.ip) && |
| 407 | Objects.equals(type, that.type); |
| 408 | |
| 409 | |
| 410 | } |
| 411 | return false; |
| 412 | } |
| 413 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 416 | /** |
| 417 | * Implementation of Internet Protocol Number criterion. |
| 418 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 419 | public static final class IPProtocolCriterion implements Criterion { |
| 420 | |
| 421 | private final Byte proto; |
| 422 | |
| 423 | public IPProtocolCriterion(Byte protocol) { |
| 424 | this.proto = protocol; |
| 425 | } |
| 426 | |
| 427 | @Override |
| 428 | public Type type() { |
| 429 | return Type.IP_PROTO; |
| 430 | } |
| 431 | |
| 432 | public Byte protocol() { |
| 433 | return proto; |
| 434 | } |
| 435 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 436 | @Override |
| 437 | public String toString() { |
| 438 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 439 | .add("protocol", Long.toHexString(proto & 0xff)) |
| 440 | .toString(); |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 441 | } |
| 442 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 443 | @Override |
| 444 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 445 | return Objects.hash(type(), proto); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | @Override |
| 449 | public boolean equals(Object obj) { |
| 450 | if (this == obj) { |
| 451 | return true; |
| 452 | } |
| 453 | if (obj instanceof IPProtocolCriterion) { |
| 454 | IPProtocolCriterion that = (IPProtocolCriterion) obj; |
| 455 | return Objects.equals(proto, that.proto); |
| 456 | |
| 457 | |
| 458 | } |
| 459 | return false; |
| 460 | } |
| 461 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 464 | /** |
| 465 | * Implementation of VLAN priority criterion. |
| 466 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 467 | public static final class VlanPcpCriterion implements Criterion { |
| 468 | |
| 469 | private final Byte vlanPcp; |
| 470 | |
| 471 | public VlanPcpCriterion(Byte vlanPcp) { |
| 472 | this.vlanPcp = vlanPcp; |
| 473 | } |
| 474 | |
| 475 | @Override |
| 476 | public Type type() { |
| 477 | return Type.VLAN_PCP; |
| 478 | } |
| 479 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 480 | public Byte priority() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 481 | return vlanPcp; |
| 482 | } |
| 483 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 484 | @Override |
| 485 | public String toString() { |
| 486 | return toStringHelper(type().toString()) |
| 487 | .add("pcp", Long.toHexString(vlanPcp)).toString(); |
| 488 | } |
| 489 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 490 | @Override |
| 491 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 492 | return Objects.hash(type(), vlanPcp); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | @Override |
| 496 | public boolean equals(Object obj) { |
| 497 | if (this == obj) { |
| 498 | return true; |
| 499 | } |
| 500 | if (obj instanceof VlanPcpCriterion) { |
| 501 | VlanPcpCriterion that = (VlanPcpCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 502 | return Objects.equals(vlanPcp, that.vlanPcp) && |
| 503 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 504 | |
| 505 | |
| 506 | } |
| 507 | return false; |
| 508 | } |
| 509 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 512 | /** |
| 513 | * Implementation of VLAN ID criterion. |
| 514 | */ |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 515 | public static final class VlanIdCriterion implements Criterion { |
| 516 | |
| 517 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 518 | private final VlanId vlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 519 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 520 | public VlanIdCriterion(VlanId vlanId) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 521 | this.vlanId = vlanId; |
| 522 | } |
| 523 | |
| 524 | @Override |
| 525 | public Type type() { |
| 526 | return Type.VLAN_VID; |
| 527 | } |
| 528 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 529 | public VlanId vlanId() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 530 | return vlanId; |
| 531 | } |
| 532 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 533 | @Override |
| 534 | public String toString() { |
| 535 | return toStringHelper(type().toString()) |
| 536 | .add("id", vlanId).toString(); |
| 537 | } |
| 538 | |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 539 | @Override |
| 540 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 541 | return Objects.hash(type(), vlanId); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | @Override |
| 545 | public boolean equals(Object obj) { |
| 546 | if (this == obj) { |
| 547 | return true; |
| 548 | } |
| 549 | if (obj instanceof VlanIdCriterion) { |
| 550 | VlanIdCriterion that = (VlanIdCriterion) obj; |
alshabib | 2020b89 | 2014-10-20 15:47:08 -0700 | [diff] [blame] | 551 | return Objects.equals(vlanId, that.vlanId) && |
| 552 | Objects.equals(this.type(), that.type()); |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 553 | |
| 554 | |
| 555 | } |
| 556 | return false; |
| 557 | } |
| 558 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 561 | /** |
| 562 | * Implementation of TCP port criterion. |
| 563 | */ |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 564 | public static final class TcpPortCriterion implements Criterion { |
| 565 | |
| 566 | private final Short tcpPort; |
| 567 | private final Type type; |
| 568 | |
| 569 | public TcpPortCriterion(Short tcpPort, Type type) { |
| 570 | this.tcpPort = tcpPort; |
| 571 | this.type = type; |
| 572 | } |
| 573 | |
| 574 | @Override |
| 575 | public Type type() { |
| 576 | return this.type; |
| 577 | } |
| 578 | |
| 579 | public Short tcpPort() { |
| 580 | return this.tcpPort; |
| 581 | } |
| 582 | |
| 583 | @Override |
| 584 | public String toString() { |
| 585 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 586 | .add("tcpPort", tcpPort & 0xffff).toString(); |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | @Override |
| 590 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 591 | return Objects.hash(type, tcpPort); |
Toshio Koide | 9c44c9a | 2014-10-09 11:44:36 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | @Override |
| 595 | public boolean equals(Object obj) { |
| 596 | if (this == obj) { |
| 597 | return true; |
| 598 | } |
| 599 | if (obj instanceof TcpPortCriterion) { |
| 600 | TcpPortCriterion that = (TcpPortCriterion) obj; |
| 601 | return Objects.equals(tcpPort, that.tcpPort) && |
| 602 | Objects.equals(type, that.type); |
| 603 | |
| 604 | |
| 605 | } |
| 606 | return false; |
| 607 | } |
| 608 | } |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 609 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 610 | /** |
Kunihiro Ishiguro | 0f9aba8 | 2015-01-15 17:14:17 -0800 | [diff] [blame^] | 611 | * Implementation of ICMPv6 type criterion. |
| 612 | */ |
| 613 | public static final class Icmpv6TypeCriterion implements Criterion { |
| 614 | |
| 615 | private final Byte icmpv6Type; |
| 616 | |
| 617 | public Icmpv6TypeCriterion(Byte icmpv6Type) { |
| 618 | this.icmpv6Type = icmpv6Type; |
| 619 | } |
| 620 | |
| 621 | @Override |
| 622 | public Type type() { |
| 623 | return Type.ICMPV6_TYPE; |
| 624 | } |
| 625 | |
| 626 | public Byte icmpv6Type() { |
| 627 | return icmpv6Type; |
| 628 | } |
| 629 | |
| 630 | @Override |
| 631 | public String toString() { |
| 632 | return toStringHelper(type().toString()) |
| 633 | .add("icmpv6Type", icmpv6Type & 0xff).toString(); |
| 634 | } |
| 635 | |
| 636 | @Override |
| 637 | public int hashCode() { |
| 638 | return Objects.hash(icmpv6Type, type()); |
| 639 | } |
| 640 | |
| 641 | @Override |
| 642 | public boolean equals(Object obj) { |
| 643 | if (this == obj) { |
| 644 | return true; |
| 645 | } |
| 646 | if (obj instanceof Icmpv6TypeCriterion) { |
| 647 | Icmpv6TypeCriterion that = (Icmpv6TypeCriterion) obj; |
| 648 | return Objects.equals(icmpv6Type, that.icmpv6Type) && |
| 649 | Objects.equals(this.type(), that.type()); |
| 650 | } |
| 651 | return false; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * Implementation of ICMPv6 code criterion. |
| 657 | */ |
| 658 | public static final class Icmpv6CodeCriterion implements Criterion { |
| 659 | |
| 660 | private final Byte icmpv6Code; |
| 661 | |
| 662 | public Icmpv6CodeCriterion(Byte icmpv6Code) { |
| 663 | this.icmpv6Code = icmpv6Code; |
| 664 | } |
| 665 | |
| 666 | @Override |
| 667 | public Type type() { |
| 668 | return Type.ICMPV6_CODE; |
| 669 | } |
| 670 | |
| 671 | public Byte icmpv6Code() { |
| 672 | return icmpv6Code; |
| 673 | } |
| 674 | |
| 675 | @Override |
| 676 | public String toString() { |
| 677 | return toStringHelper(type().toString()) |
| 678 | .add("icmpv6Code", icmpv6Code & 0xff).toString(); |
| 679 | } |
| 680 | |
| 681 | @Override |
| 682 | public int hashCode() { |
| 683 | return Objects.hash(icmpv6Code, type()); |
| 684 | } |
| 685 | |
| 686 | @Override |
| 687 | public boolean equals(Object obj) { |
| 688 | if (this == obj) { |
| 689 | return true; |
| 690 | } |
| 691 | if (obj instanceof Icmpv6CodeCriterion) { |
| 692 | Icmpv6CodeCriterion that = (Icmpv6CodeCriterion) obj; |
| 693 | return Objects.equals(icmpv6Code, that.icmpv6Code) && |
| 694 | Objects.equals(this.type(), that.type()); |
| 695 | } |
| 696 | return false; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | /** |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 701 | * Implementation of MPLS tag criterion. |
| 702 | */ |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 703 | public static final class MplsCriterion implements Criterion { |
| 704 | |
| 705 | private final Integer mplsLabel; |
| 706 | |
| 707 | public MplsCriterion(Integer mplsLabel) { |
| 708 | this.mplsLabel = mplsLabel; |
| 709 | } |
| 710 | |
| 711 | @Override |
| 712 | public Type type() { |
| 713 | return Type.MPLS_LABEL; |
| 714 | } |
| 715 | |
| 716 | public Integer label() { |
| 717 | return mplsLabel; |
| 718 | } |
| 719 | |
| 720 | @Override |
| 721 | public String toString() { |
| 722 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 723 | .add("mpls", mplsLabel & 0xffffffffL).toString(); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | @Override |
| 727 | public int hashCode() { |
| 728 | return Objects.hash(mplsLabel, type()); |
| 729 | } |
| 730 | |
| 731 | @Override |
| 732 | public boolean equals(Object obj) { |
| 733 | if (this == obj) { |
| 734 | return true; |
| 735 | } |
| 736 | if (obj instanceof MplsCriterion) { |
| 737 | MplsCriterion that = (MplsCriterion) obj; |
| 738 | return Objects.equals(mplsLabel, that.mplsLabel) && |
| 739 | Objects.equals(this.type(), that.type()); |
| 740 | |
| 741 | |
| 742 | } |
| 743 | return false; |
| 744 | } |
| 745 | |
| 746 | } |
| 747 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 748 | /** |
| 749 | * Implementation of lambda (wavelength) criterion. |
| 750 | */ |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 751 | public static final class LambdaCriterion implements Criterion { |
| 752 | |
| 753 | private final short lambda; |
| 754 | private final Type type; |
| 755 | |
| 756 | public LambdaCriterion(short lambda, Type type) { |
| 757 | this.lambda = lambda; |
| 758 | this.type = type; |
| 759 | } |
| 760 | |
| 761 | @Override |
| 762 | public Type type() { |
| 763 | return this.type; |
| 764 | } |
| 765 | |
| 766 | public Short lambda() { |
| 767 | return this.lambda; |
| 768 | } |
| 769 | |
| 770 | @Override |
| 771 | public String toString() { |
| 772 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 773 | .add("lambda", lambda & 0xffff).toString(); |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | @Override |
| 777 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 778 | return Objects.hash(type, lambda); |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | @Override |
| 782 | public boolean equals(Object obj) { |
| 783 | if (this == obj) { |
| 784 | return true; |
| 785 | } |
| 786 | if (obj instanceof LambdaCriterion) { |
| 787 | LambdaCriterion that = (LambdaCriterion) obj; |
| 788 | return Objects.equals(lambda, that.lambda) && |
| 789 | Objects.equals(type, that.type); |
| 790 | } |
| 791 | return false; |
| 792 | } |
| 793 | } |
| 794 | |
Sho SHIMIZU | 06596e3 | 2014-12-02 18:07:50 -0800 | [diff] [blame] | 795 | /** |
| 796 | * Implementation of optical signal type criterion. |
| 797 | */ |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 798 | public static final class OpticalSignalTypeCriterion implements Criterion { |
| 799 | |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 800 | private final Short signalType; |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 801 | private final Type type; |
| 802 | |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 803 | public OpticalSignalTypeCriterion(Short signalType, Type type) { |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 804 | this.signalType = signalType; |
| 805 | this.type = type; |
| 806 | } |
| 807 | |
| 808 | @Override |
| 809 | public Type type() { |
| 810 | return this.type; |
| 811 | } |
| 812 | |
Praseed Balakrishnan | 2dd5abd | 2014-11-03 14:56:28 -0800 | [diff] [blame] | 813 | public Short signalType() { |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 814 | return this.signalType; |
| 815 | } |
| 816 | |
| 817 | @Override |
| 818 | public String toString() { |
| 819 | return toStringHelper(type().toString()) |
Charles M.C. Chan | 36eb6e1 | 2015-01-06 17:12:27 +0800 | [diff] [blame] | 820 | .add("signalType", signalType & 0xffff).toString(); |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | @Override |
| 824 | public int hashCode() { |
Thomas Vachuska | 9b2da21 | 2014-11-10 19:30:25 -0800 | [diff] [blame] | 825 | return Objects.hash(type, signalType); |
Praseed Balakrishnan | 64369da | 2014-10-23 15:55:20 -0700 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | @Override |
| 829 | public boolean equals(Object obj) { |
| 830 | if (this == obj) { |
| 831 | return true; |
| 832 | } |
| 833 | if (obj instanceof OpticalSignalTypeCriterion) { |
| 834 | OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj; |
| 835 | return Objects.equals(signalType, that.signalType) && |
| 836 | Objects.equals(type, that.type); |
| 837 | } |
| 838 | return false; |
| 839 | } |
| 840 | } |
| 841 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 842 | } |