Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 1 | @SuppressWarnings("unchecked") |
| 2 | @Override |
| 3 | public <F extends OFValueType<F>> F get(MatchField<F> field) |
| 4 | throws UnsupportedOperationException { |
| 5 | if (isFullyWildcarded(field)) |
| 6 | return null; |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 7 | |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 8 | Object result; |
| 9 | switch (field.id) { |
| 10 | case IN_PORT: |
| 11 | result = inPort; |
| 12 | break; |
| 13 | case ETH_DST: |
| 14 | result = ethDst; |
| 15 | break; |
| 16 | case ETH_SRC: |
| 17 | result = ethSrc; |
| 18 | break; |
| 19 | case ETH_TYPE: |
| 20 | result = ethType; |
| 21 | break; |
| 22 | case VLAN_VID: |
| 23 | result = vlanVid; |
| 24 | break; |
| 25 | case VLAN_PCP: |
| 26 | result = vlanPcp; |
| 27 | break; |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 28 | case ARP_OP: |
| 29 | result = ArpOpcode.of(ipProto.getIpProtocolNumber()); |
| 30 | break; |
| 31 | case ARP_SPA: |
| 32 | result = ipv4Src; |
| 33 | break; |
| 34 | case ARP_TPA: |
| 35 | result = ipv4Dst; |
| 36 | break; |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 37 | case IP_DSCP: |
| 38 | result = ipDscp; |
| 39 | break; |
| 40 | case IP_PROTO: |
| 41 | result = ipProto; |
| 42 | break; |
| 43 | case IPV4_SRC: |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 44 | result = ipv4Src; |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 45 | break; |
| 46 | case IPV4_DST: |
| 47 | result = ipv4Dst; |
| 48 | break; |
| 49 | case TCP_SRC: |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 50 | result = tcpSrc; |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 51 | break; |
| 52 | case TCP_DST: |
| 53 | result = tcpDst; |
| 54 | break; |
| 55 | case UDP_SRC: |
| 56 | result = tcpSrc; |
| 57 | break; |
| 58 | case UDP_DST: |
| 59 | result = tcpDst; |
| 60 | break; |
| 61 | case SCTP_SRC: |
| 62 | result = tcpSrc; |
| 63 | break; |
| 64 | case SCTP_DST: |
| 65 | result = tcpDst; |
| 66 | break; |
| 67 | case ICMPV4_TYPE: |
| 68 | result = tcpSrc; |
| 69 | break; |
| 70 | case ICMPV4_CODE: |
| 71 | result = tcpDst; |
| 72 | break; |
| 73 | // NOT SUPPORTED: |
| 74 | default: |
| 75 | throw new UnsupportedOperationException("OFMatch does not support matching on field " + field.getName()); |
| 76 | } |
| 77 | return (F)result; |
| 78 | } |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 79 | |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 80 | @SuppressWarnings("unchecked") |
| 81 | @Override |
| 82 | public <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field) |
| 83 | throws UnsupportedOperationException { |
| 84 | if (!isPartiallyMasked(field)) |
| 85 | return null; |
| 86 | Object result; |
| 87 | switch (field.id) { |
| 88 | case IPV4_SRC: |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 89 | case ARP_SPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 90 | int srcBitMask = (-1) << (32 - getIpv4SrcCidrMaskLen()); |
| 91 | result = IPv4AddressWithMask.of(ipv4Src, IPv4Address.of(srcBitMask)); |
| 92 | break; |
| 93 | case IPV4_DST: |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 94 | case ARP_TPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 95 | int dstMaskedBits = Math.min(32, (wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT); |
| 96 | int dstBitMask = (-1) << (32 - getIpv4DstCidrMaskLen()); |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 97 | |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 98 | result = IPv4AddressWithMask.of(ipv4Dst, IPv4Address.of(dstBitMask)); |
| 99 | break; |
| 100 | default: |
| 101 | throw new UnsupportedOperationException("OFMatch does not support masked matching on field " + field.getName()); |
| 102 | } |
| 103 | return (Masked<F>)result; |
| 104 | } |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 105 | |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 106 | @Override |
| 107 | public boolean supports(MatchField<?> field) { |
| 108 | switch (field.id) { |
| 109 | case IN_PORT: |
| 110 | case ETH_DST: |
| 111 | case ETH_SRC: |
| 112 | case ETH_TYPE: |
| 113 | case VLAN_VID: |
| 114 | case VLAN_PCP: |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 115 | case ARP_OP: |
| 116 | case ARP_SPA: |
| 117 | case ARP_TPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 118 | case IP_DSCP: |
| 119 | case IP_PROTO: |
| 120 | case IPV4_SRC: |
| 121 | case IPV4_DST: |
| 122 | case TCP_SRC: |
| 123 | case TCP_DST: |
| 124 | case UDP_SRC: |
| 125 | case UDP_DST: |
| 126 | case SCTP_SRC: |
| 127 | case SCTP_DST: |
| 128 | case ICMPV4_TYPE: |
| 129 | case ICMPV4_CODE: |
| 130 | return true; |
| 131 | default: |
| 132 | return false; |
| 133 | } |
| 134 | } |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 135 | |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 136 | @Override |
| 137 | public boolean supportsMasked(MatchField<?> field) { |
| 138 | switch (field.id) { |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 139 | case ARP_SPA: |
| 140 | case ARP_TPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 141 | case IPV4_SRC: |
| 142 | case IPV4_DST: |
| 143 | return true; |
| 144 | default: |
| 145 | return false; |
| 146 | } |
| 147 | } |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 148 | |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 149 | @Override |
| 150 | public boolean isExact(MatchField<?> field) { |
| 151 | switch (field.id) { |
| 152 | case IN_PORT: |
| 153 | return (this.wildcards & OFPFW_IN_PORT) == 0; |
| 154 | case ETH_DST: |
| 155 | return (this.wildcards & OFPFW_DL_DST) == 0; |
| 156 | case ETH_SRC: |
| 157 | return (this.wildcards & OFPFW_DL_SRC) == 0; |
| 158 | case ETH_TYPE: |
| 159 | return (this.wildcards & OFPFW_DL_TYPE) == 0; |
| 160 | case VLAN_VID: |
| 161 | return (this.wildcards & OFPFW_DL_VLAN) == 0; |
| 162 | case VLAN_PCP: |
| 163 | return (this.wildcards & OFPFW_DL_VLAN_PCP) == 0; |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 164 | case ARP_OP: |
| 165 | return (this.wildcards & OFPFW_NW_PROTO) == 0; |
| 166 | case ARP_SPA: |
| 167 | return this.getIpv4SrcCidrMaskLen() >= 32; |
| 168 | case ARP_TPA: |
| 169 | return this.getIpv4DstCidrMaskLen() >= 32; |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 170 | case IP_DSCP: |
| 171 | return (this.wildcards & OFPFW_NW_TOS) == 0; |
| 172 | case IP_PROTO: |
| 173 | return (this.wildcards & OFPFW_NW_PROTO) == 0; |
| 174 | case IPV4_SRC: |
| 175 | return this.getIpv4SrcCidrMaskLen() >= 32; |
| 176 | case IPV4_DST: |
| 177 | return this.getIpv4DstCidrMaskLen() >= 32; |
| 178 | case TCP_SRC: |
| 179 | return (this.wildcards & OFPFW_TP_SRC) == 0; |
| 180 | case TCP_DST: |
| 181 | return (this.wildcards & OFPFW_TP_DST) == 0; |
| 182 | case UDP_SRC: |
| 183 | return (this.wildcards & OFPFW_TP_SRC) == 0; |
| 184 | case UDP_DST: |
| 185 | return (this.wildcards & OFPFW_TP_DST) == 0; |
| 186 | case SCTP_SRC: |
| 187 | return (this.wildcards & OFPFW_TP_SRC) == 0; |
| 188 | case SCTP_DST: |
| 189 | return (this.wildcards & OFPFW_TP_DST) == 0; |
| 190 | case ICMPV4_TYPE: |
| 191 | return (this.wildcards & OFPFW_TP_SRC) == 0; |
| 192 | case ICMPV4_CODE: |
| 193 | return (this.wildcards & OFPFW_TP_DST) == 0; |
| 194 | default: |
| 195 | throw new UnsupportedOperationException("OFMatch does not support matching on field " + field.getName()); |
| 196 | } |
| 197 | } |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 198 | |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 199 | /** |
| 200 | * Parse this match's wildcard fields and return the number of significant |
| 201 | * bits in the IP destination field. NOTE: this returns the number of bits |
| 202 | * that are fixed, i.e., like CIDR, not the number of bits that are free |
| 203 | * like OpenFlow encodes. |
| 204 | * |
| 205 | * @return A number between 0 (matches all IPs) and 32 (exact match) |
| 206 | */ |
| 207 | public int getIpv4DstCidrMaskLen() { |
| 208 | return Math.max(32 - ((wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT), |
| 209 | 0); |
| 210 | } |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 211 | |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 212 | /** |
| 213 | * Parse this match's wildcard fields and return the number of significant |
| 214 | * bits in the IP destination field. NOTE: this returns the number of bits |
| 215 | * that are fixed, i.e., like CIDR, not the number of bits that are free |
| 216 | * like OpenFlow encodes. |
| 217 | * |
| 218 | * @return A number between 0 (matches all IPs) and 32 (exact match) |
| 219 | */ |
| 220 | public int getIpv4SrcCidrMaskLen() { |
| 221 | return Math.max(32 - ((wildcards & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT), |
| 222 | 0); |
| 223 | } |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 224 | |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 225 | |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 226 | @Override |
| 227 | public boolean isFullyWildcarded(MatchField<?> field) { |
| 228 | switch (field.id) { |
| 229 | case IN_PORT: |
| 230 | return (this.wildcards & OFPFW_IN_PORT) != 0; |
| 231 | case ETH_DST: |
| 232 | return (this.wildcards & OFPFW_DL_DST) != 0; |
| 233 | case ETH_SRC: |
| 234 | return (this.wildcards & OFPFW_DL_SRC) != 0; |
| 235 | case ETH_TYPE: |
| 236 | return (this.wildcards & OFPFW_DL_TYPE) != 0; |
| 237 | case VLAN_VID: |
| 238 | return (this.wildcards & OFPFW_DL_VLAN) != 0; |
| 239 | case VLAN_PCP: |
| 240 | return (this.wildcards & OFPFW_DL_VLAN_PCP) != 0; |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 241 | case ARP_OP: |
| 242 | return (this.wildcards & OFPFW_NW_PROTO) != 0; |
| 243 | case ARP_SPA: |
| 244 | return this.getIpv4SrcCidrMaskLen() <= 0; |
| 245 | case ARP_TPA: |
| 246 | return this.getIpv4DstCidrMaskLen() <= 0; |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 247 | case IP_DSCP: |
| 248 | return (this.wildcards & OFPFW_NW_TOS) != 0; |
| 249 | case IP_PROTO: |
| 250 | return (this.wildcards & OFPFW_NW_PROTO) != 0; |
| 251 | case TCP_SRC: |
| 252 | return (this.wildcards & OFPFW_TP_SRC) != 0; |
| 253 | case TCP_DST: |
| 254 | return (this.wildcards & OFPFW_TP_DST) != 0; |
| 255 | case UDP_SRC: |
| 256 | return (this.wildcards & OFPFW_TP_SRC) != 0; |
| 257 | case UDP_DST: |
| 258 | return (this.wildcards & OFPFW_TP_DST) != 0; |
| 259 | case SCTP_SRC: |
| 260 | return (this.wildcards & OFPFW_TP_SRC) != 0; |
| 261 | case SCTP_DST: |
| 262 | return (this.wildcards & OFPFW_TP_DST) != 0; |
| 263 | case ICMPV4_TYPE: |
| 264 | return (this.wildcards & OFPFW_TP_SRC) != 0; |
| 265 | case ICMPV4_CODE: |
| 266 | return (this.wildcards & OFPFW_TP_DST) != 0; |
| 267 | case IPV4_SRC: |
| 268 | return this.getIpv4SrcCidrMaskLen() <= 0; |
| 269 | case IPV4_DST: |
| 270 | return this.getIpv4DstCidrMaskLen() <= 0; |
| 271 | default: |
| 272 | throw new UnsupportedOperationException("OFMatch does not support matching on field " + field.getName()); |
| 273 | } |
| 274 | } |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 275 | |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 276 | @Override |
| 277 | public boolean isPartiallyMasked(MatchField<?> field) { |
| 278 | switch (field.id) { |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 279 | case ARP_SPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 280 | case IPV4_SRC: |
| 281 | int srcCidrLen = getIpv4SrcCidrMaskLen(); |
| 282 | return srcCidrLen > 0 && srcCidrLen < 32; |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 283 | case ARP_TPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 284 | case IPV4_DST: |
| 285 | int dstCidrLen = getIpv4SrcCidrMaskLen(); |
| 286 | return dstCidrLen > 0 && dstCidrLen < 32; |
| 287 | default: |
| 288 | throw new UnsupportedOperationException("OFMatch does not support masked matching on field " + field.getName()); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | private final void initWildcards() { |
| 293 | if(!wildcardsSet) { |
| 294 | //:: if has_parent: |
| 295 | wildcards = parentMessage.wildcards; |
| 296 | //:: else: |
| 297 | wildcards = OFPFW_ALL; |
| 298 | //:: #endif |
| 299 | wildcardsSet = true; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | @Override |
| 304 | public <F extends OFValueType<F>> Match.Builder setExact(MatchField<F> field, |
| 305 | F value) { |
| 306 | initWildcards(); |
| 307 | Object val = value; |
| 308 | switch (field.id) { |
| 309 | case ETH_DST: |
| 310 | setEthDst((MacAddress) value); |
| 311 | wildcards &= ~OFPFW_DL_DST; |
| 312 | break; |
| 313 | case ETH_SRC: |
| 314 | setEthSrc((MacAddress) value); |
| 315 | wildcards &= ~OFPFW_DL_SRC; |
| 316 | break; |
| 317 | case ETH_TYPE: |
| 318 | setEthType((EthType) value); |
| 319 | wildcards &= ~OFPFW_DL_TYPE; |
| 320 | break; |
| 321 | case ICMPV4_CODE: |
| 322 | setTcpDst((TransportPort) value); |
| 323 | wildcards &= ~OFPFW_TP_DST; |
| 324 | break; |
| 325 | case ICMPV4_TYPE: |
| 326 | setTcpSrc((TransportPort) value); |
| 327 | wildcards &= ~OFPFW_TP_SRC; |
| 328 | break; |
| 329 | case IN_PORT: |
| 330 | setInPort((OFPort) value); |
| 331 | wildcards &= ~OFPFW_IN_PORT; |
| 332 | break; |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 333 | case ARP_OP: |
| 334 | setIpProto(IpProtocol.of((short)((ArpOpcode)value).getOpcode())); |
| 335 | wildcards &= ~OFPFW_NW_PROTO; |
| 336 | break; |
| 337 | case ARP_TPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 338 | case IPV4_DST: |
| 339 | setIpv4Dst((IPv4Address) value); |
| 340 | wildcards &= ~OFPFW_NW_DST_MASK; |
| 341 | break; |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 342 | case ARP_SPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 343 | case IPV4_SRC: |
| 344 | setIpv4Src((IPv4Address) value); |
| 345 | wildcards &= ~OFPFW_NW_SRC_MASK; |
| 346 | break; |
| 347 | case IP_DSCP: |
| 348 | setIpDscp((IpDscp) value); |
| 349 | wildcards &= ~OFPFW_NW_TOS; |
| 350 | break; |
| 351 | case IP_PROTO: |
| 352 | setIpProto((IpProtocol) value); |
| 353 | wildcards &= ~OFPFW_NW_PROTO; |
| 354 | break; |
| 355 | case SCTP_DST: |
| 356 | setTcpDst((TransportPort) value); |
| 357 | wildcards &= ~OFPFW_TP_DST; |
| 358 | break; |
| 359 | case SCTP_SRC: |
| 360 | setTcpSrc((TransportPort) value); |
| 361 | wildcards &= ~OFPFW_TP_SRC; |
| 362 | break; |
| 363 | case TCP_DST: |
| 364 | setTcpDst((TransportPort) value); |
| 365 | wildcards &= ~OFPFW_TP_DST; |
| 366 | break; |
| 367 | case TCP_SRC: |
| 368 | setTcpSrc((TransportPort) value); |
| 369 | wildcards &= ~OFPFW_TP_SRC; |
| 370 | break; |
| 371 | case UDP_DST: |
| 372 | setTcpDst((TransportPort) value); |
| 373 | wildcards &= ~OFPFW_TP_DST; |
| 374 | break; |
| 375 | case UDP_SRC: |
| 376 | setTcpSrc((TransportPort) value); |
| 377 | wildcards &= ~OFPFW_TP_SRC; |
| 378 | break; |
| 379 | case VLAN_PCP: |
| 380 | setVlanPcp((VlanPcp) value); |
| 381 | wildcards &= ~OFPFW_DL_VLAN_PCP; |
| 382 | break; |
| 383 | case VLAN_VID: |
| 384 | setVlanVid((VlanVid) value); |
| 385 | wildcards &= ~OFPFW_DL_VLAN; |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 386 | break; |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 387 | default: |
| 388 | throw new UnsupportedOperationException( |
| 389 | "OFMatch does not support matching on field " + field.getName()); |
| 390 | } |
| 391 | return this; |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public <F extends OFValueType<F>> Match.Builder setMasked(MatchField<F> field, |
| 396 | F value, F mask) { |
| 397 | initWildcards(); |
| 398 | switch (field.id) { |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 399 | case ARP_SPA: |
| 400 | case ARP_TPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 401 | case IPV4_DST: |
| 402 | case IPV4_SRC: |
| 403 | Object valObj = value; |
| 404 | Object masObj = mask; |
| 405 | IPv4Address ip = ((IPv4Address)valObj); |
| 406 | int maskval = ((IPv4Address)masObj).getInt(); |
| 407 | if (Integer.bitCount(~maskval + 1) != 1) |
| 408 | throw new UnsupportedOperationException("OFMatch only supports CIDR masks for IPv4"); |
| 409 | int maskLen = 32 - Integer.bitCount(maskval); |
| 410 | switch(field.id) { |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 411 | case ARP_TPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 412 | case IPV4_DST: |
| 413 | setIpv4Dst(ip); |
| 414 | wildcards = (wildcards &~OFPFW_NW_DST_MASK) | (maskLen << OFPFW_NW_DST_SHIFT); |
| 415 | break; |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 416 | case ARP_SPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 417 | case IPV4_SRC: |
| 418 | setIpv4Src(ip); |
| 419 | wildcards = (wildcards &~OFPFW_NW_SRC_MASK) | (maskLen << OFPFW_NW_SRC_SHIFT); |
| 420 | break; |
| 421 | default: |
| 422 | // Cannot really get here |
| 423 | break; |
| 424 | } |
| 425 | break; |
| 426 | default: |
| 427 | throw new UnsupportedOperationException("OFMatch does not support masked matching on field " + field.getName()); |
| 428 | } |
| 429 | return this; |
| 430 | } |
| 431 | |
| 432 | @Override |
| 433 | public <F extends OFValueType<F>> Match.Builder setMasked(MatchField<F> field, Masked<F> valueWithMask) |
| 434 | throws UnsupportedOperationException { |
| 435 | return this.setMasked(field, valueWithMask.getValue(), valueWithMask.getMask()); |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | public <F extends OFValueType<F>> Match.Builder wildcard(MatchField<F> field) { |
| 440 | initWildcards(); |
| 441 | switch (field.id) { |
| 442 | case ETH_DST: |
| 443 | setEthDst(MacAddress.NONE); |
| 444 | wildcards |= OFPFW_DL_DST; |
| 445 | break; |
| 446 | case ETH_SRC: |
| 447 | setEthSrc(MacAddress.NONE); |
| 448 | wildcards |= OFPFW_DL_SRC; |
| 449 | break; |
| 450 | case ETH_TYPE: |
| 451 | setEthType(EthType.NONE); |
| 452 | wildcards |= OFPFW_DL_TYPE; |
| 453 | break; |
| 454 | case ICMPV4_CODE: |
| 455 | case TCP_DST: |
| 456 | case UDP_DST: |
| 457 | case SCTP_DST: |
| 458 | setTcpDst(TransportPort.NONE); |
| 459 | wildcards |= OFPFW_TP_DST; |
| 460 | break; |
| 461 | case ICMPV4_TYPE: |
| 462 | case TCP_SRC: |
| 463 | case UDP_SRC: |
| 464 | case SCTP_SRC: |
| 465 | setTcpSrc(TransportPort.NONE); |
| 466 | wildcards |= OFPFW_TP_SRC; |
| 467 | break; |
| 468 | case IN_PORT: |
Andreas Wundsam | ad499c9 | 2013-09-28 18:56:49 -0700 | [diff] [blame] | 469 | setInPort(OFPort.of(0)); // NOTE: not 'NONE' -- that is 0xFF for ports |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 470 | wildcards |= OFPFW_IN_PORT; |
| 471 | break; |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 472 | case ARP_TPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 473 | case IPV4_DST: |
| 474 | setIpv4Dst(IPv4Address.NONE); |
| 475 | wildcards |= OFPFW_NW_DST_MASK; |
| 476 | break; |
Rob Vaterlaus | f13323d | 2013-10-10 13:30:29 -0700 | [diff] [blame^] | 477 | case ARP_SPA: |
Andreas Wundsam | f89f782 | 2013-09-23 14:49:24 -0700 | [diff] [blame] | 478 | case IPV4_SRC: |
| 479 | setIpv4Src(IPv4Address.NONE); |
| 480 | wildcards |= OFPFW_NW_SRC_MASK; |
| 481 | break; |
| 482 | case IP_DSCP: |
| 483 | setIpDscp(IpDscp.NONE); |
| 484 | wildcards |= OFPFW_NW_TOS; |
| 485 | break; |
| 486 | case IP_PROTO: |
| 487 | setIpProto(IpProtocol.NONE); |
| 488 | wildcards |= OFPFW_NW_PROTO; |
| 489 | break; |
| 490 | case VLAN_PCP: |
| 491 | setVlanPcp(VlanPcp.NONE); |
| 492 | wildcards |= OFPFW_DL_VLAN_PCP; |
| 493 | break; |
| 494 | case VLAN_VID: |
| 495 | setVlanVid(VlanVid.NONE); |
| 496 | wildcards |= OFPFW_DL_VLAN; |
| 497 | break; |
| 498 | default: |
| 499 | throw new UnsupportedOperationException("OFMatch does not support matching on field " + field.getName()); |
| 500 | } |
| 501 | return this; |
| 502 | } |