Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.net.flow.criteria; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.Objects; |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableMap; |
| 22 | import org.onosproject.net.pi.runtime.PiExactFieldMatch; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 23 | import org.onosproject.net.pi.runtime.PiFieldMatch; |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 24 | import org.onosproject.net.pi.runtime.PiHeaderFieldId; |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 25 | import org.onosproject.net.pi.runtime.PiLpmFieldMatch; |
| 26 | import org.onosproject.net.pi.runtime.PiRangeFieldMatch; |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 27 | import org.onosproject.net.pi.runtime.PiTernaryFieldMatch; |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 28 | import org.onosproject.net.pi.runtime.PiValidFieldMatch; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 29 | |
| 30 | import java.util.Collection; |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 31 | import java.util.Optional; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 32 | import java.util.StringJoiner; |
| 33 | |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 34 | import static com.google.common.base.Preconditions.checkArgument; |
| 35 | import static org.onlab.util.ImmutableByteSequence.copyFrom; |
| 36 | |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 37 | /** |
Carmelo Cascone | 2261917 | 2017-07-13 16:08:17 -0400 | [diff] [blame] | 38 | * Protocol-independent criterion. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 39 | */ |
| 40 | @Beta |
| 41 | public final class PiCriterion implements Criterion { |
| 42 | |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 43 | private final ImmutableMap<PiHeaderFieldId, PiFieldMatch> fieldMatchMap; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Creates a new protocol-independent criterion for the given match fields. |
| 47 | * |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 48 | * @param fieldMatchMap field match map |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 49 | */ |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 50 | private PiCriterion(ImmutableMap<PiHeaderFieldId, PiFieldMatch> fieldMatchMap) { |
| 51 | this.fieldMatchMap = fieldMatchMap; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 55 | * Returns all protocol-independent field matches defined by this criterion. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 56 | * |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 57 | * @return collection of match parameters |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 58 | */ |
| 59 | public Collection<PiFieldMatch> fieldMatches() { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 60 | return fieldMatchMap.values(); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * If present, returns the field match associated with the given header field identifier. |
| 65 | * |
| 66 | * @param fieldId field identifier |
| 67 | * @return optional field match |
| 68 | */ |
| 69 | public Optional<PiFieldMatch> fieldMatch(PiHeaderFieldId fieldId) { |
| 70 | return Optional.ofNullable(fieldMatchMap.get(fieldId)); |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public Type type() { |
| 75 | return Type.PROTOCOL_INDEPENDENT; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public boolean equals(Object o) { |
| 80 | if (this == o) { |
| 81 | return true; |
| 82 | } |
| 83 | if (o == null || getClass() != o.getClass()) { |
| 84 | return false; |
| 85 | } |
| 86 | PiCriterion that = (PiCriterion) o; |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 87 | return Objects.equal(fieldMatchMap, that.fieldMatchMap); |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public int hashCode() { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 92 | return Objects.hashCode(fieldMatchMap); |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public String toString() { |
| 97 | StringJoiner stringParams = new StringJoiner(", ", "{", "}"); |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 98 | fieldMatchMap.forEach((key, value) -> stringParams.add(value.toString())); |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 99 | return stringParams.toString(); |
| 100 | } |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Returns the PiCriterion builder. |
| 104 | * |
| 105 | * @return PiCriterion builder |
| 106 | */ |
| 107 | public static Builder builder() { |
| 108 | return new Builder(); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * PiCriterion Builder. |
| 113 | */ |
| 114 | @Beta |
| 115 | public static final class Builder { |
| 116 | |
Carmelo Cascone | 2261917 | 2017-07-13 16:08:17 -0400 | [diff] [blame] | 117 | // Use map to guarantee that there's only one field match per field id. |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 118 | private final ImmutableMap.Builder<PiHeaderFieldId, PiFieldMatch> fieldMatchMapBuilder = ImmutableMap.builder(); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 119 | |
| 120 | private Builder() { |
| 121 | // ban constructor. |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Adds an exact field match for the given fieldId and value. |
| 126 | * |
| 127 | * @param fieldId protocol-independent header field Id |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 128 | * @param value exact match value |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 129 | * @return this |
| 130 | */ |
| 131 | public Builder matchExact(PiHeaderFieldId fieldId, short value) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 132 | fieldMatchMapBuilder.put(fieldId, new PiExactFieldMatch(fieldId, copyFrom(value))); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 133 | return this; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Adds an exact field match for the given fieldId and value. |
| 138 | * |
| 139 | * @param fieldId protocol-independent header field Id |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 140 | * @param value exact match value |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 141 | * @return this |
| 142 | */ |
| 143 | public Builder matchExact(PiHeaderFieldId fieldId, int value) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 144 | fieldMatchMapBuilder.put(fieldId, new PiExactFieldMatch(fieldId, copyFrom(value))); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 145 | return this; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Adds an exact field match for the given fieldId and value. |
| 150 | * |
| 151 | * @param fieldId protocol-independent header field Id |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 152 | * @param value exact match value |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 153 | * @return this |
| 154 | */ |
| 155 | public Builder matchExact(PiHeaderFieldId fieldId, long value) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 156 | fieldMatchMapBuilder.put(fieldId, new PiExactFieldMatch(fieldId, copyFrom(value))); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 157 | return this; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Adds an exact field match for the given fieldId and value. |
| 162 | * |
| 163 | * @param fieldId protocol-independent header field Id |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 164 | * @param value exact match value |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 165 | * @return this |
| 166 | */ |
| 167 | public Builder matchExact(PiHeaderFieldId fieldId, byte[] value) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 168 | fieldMatchMapBuilder.put(fieldId, new PiExactFieldMatch(fieldId, copyFrom(value))); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 169 | return this; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Adds a ternary field match for the given fieldId, value and mask. |
| 174 | * |
| 175 | * @param fieldId protocol-independent header field Id |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 176 | * @param value ternary match value |
| 177 | * @param mask ternary match mask |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 178 | * @return this |
| 179 | */ |
| 180 | public Builder matchTernary(PiHeaderFieldId fieldId, short value, short mask) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 181 | fieldMatchMapBuilder.put(fieldId, new PiTernaryFieldMatch(fieldId, copyFrom(value), copyFrom(mask))); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 182 | return this; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Adds a ternary field match for the given fieldId, value and mask. |
| 187 | * |
| 188 | * @param fieldId protocol-independent header field Id |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 189 | * @param value ternary match value |
| 190 | * @param mask ternary match mask |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 191 | * @return this |
| 192 | */ |
| 193 | public Builder matchTernary(PiHeaderFieldId fieldId, int value, int mask) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 194 | fieldMatchMapBuilder.put(fieldId, new PiTernaryFieldMatch(fieldId, copyFrom(value), copyFrom(mask))); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 195 | return this; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Adds a ternary field match for the given fieldId, value and mask. |
| 200 | * |
| 201 | * @param fieldId protocol-independent header field Id |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 202 | * @param value ternary match value |
| 203 | * @param mask ternary match mask |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 204 | * @return this |
| 205 | */ |
| 206 | public Builder matchTernary(PiHeaderFieldId fieldId, long value, long mask) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 207 | fieldMatchMapBuilder.put(fieldId, new PiTernaryFieldMatch(fieldId, copyFrom(value), copyFrom(mask))); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 208 | return this; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Adds a ternary field match for the given fieldId, value and mask. |
| 213 | * |
| 214 | * @param fieldId protocol-independent header field Id |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 215 | * @param value ternary match value |
| 216 | * @param mask ternary match mask |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 217 | * @return this |
| 218 | */ |
| 219 | public Builder matchTernary(PiHeaderFieldId fieldId, byte[] value, byte[] mask) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 220 | fieldMatchMapBuilder.put(fieldId, new PiTernaryFieldMatch(fieldId, copyFrom(value), copyFrom(mask))); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 221 | return this; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Adds a longest-prefix field match for the given fieldId, value and prefix length. |
| 226 | * |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 227 | * @param fieldId protocol-independent header field Id |
| 228 | * @param value lpm match value |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 229 | * @param prefixLength lpm match prefix length |
| 230 | * @return this |
| 231 | */ |
| 232 | public Builder matchLpm(PiHeaderFieldId fieldId, short value, int prefixLength) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 233 | fieldMatchMapBuilder.put(fieldId, new PiLpmFieldMatch(fieldId, copyFrom(value), prefixLength)); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 234 | return this; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Adds a longest-prefix field match for the given fieldId, value and prefix length. |
| 239 | * |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 240 | * @param fieldId protocol-independent header field Id |
| 241 | * @param value lpm match value |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 242 | * @param prefixLength lpm match prefix length |
| 243 | * @return this |
| 244 | */ |
| 245 | public Builder matchLpm(PiHeaderFieldId fieldId, int value, int prefixLength) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 246 | fieldMatchMapBuilder.put(fieldId, new PiLpmFieldMatch(fieldId, copyFrom(value), prefixLength)); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 247 | return this; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Adds a longest-prefix field match for the given fieldId, value and prefix length. |
| 252 | * |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 253 | * @param fieldId protocol-independent header field Id |
| 254 | * @param value lpm match value |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 255 | * @param prefixLength lpm match prefix length |
| 256 | * @return this |
| 257 | */ |
| 258 | public Builder matchLpm(PiHeaderFieldId fieldId, long value, int prefixLength) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 259 | fieldMatchMapBuilder.put(fieldId, new PiLpmFieldMatch(fieldId, copyFrom(value), prefixLength)); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 260 | return this; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Adds a longest-prefix field match for the given fieldId, value and prefix length. |
| 265 | * |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 266 | * @param fieldId protocol-independent header field Id |
| 267 | * @param value lpm match value |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 268 | * @param prefixLength lpm match prefix length |
| 269 | * @return this |
| 270 | */ |
| 271 | public Builder matchLpm(PiHeaderFieldId fieldId, byte[] value, int prefixLength) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 272 | fieldMatchMapBuilder.put(fieldId, new PiLpmFieldMatch(fieldId, copyFrom(value), prefixLength)); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 273 | return this; |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Adds a valid field match for the given fieldId and flag. |
| 278 | * |
| 279 | * @param fieldId protocol-independent header field Id |
| 280 | * @param flag a boolean value |
| 281 | * @return this |
| 282 | */ |
| 283 | public Builder matchValid(PiHeaderFieldId fieldId, boolean flag) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 284 | fieldMatchMapBuilder.put(fieldId, new PiValidFieldMatch(fieldId, flag)); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 285 | return this; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * Adds a range field match for the given fieldId, low and high. |
| 290 | * |
| 291 | * @param fieldId protocol-independent header field Id |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 292 | * @param low range match low value |
| 293 | * @param high range match high value |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 294 | * @return this |
| 295 | */ |
| 296 | public Builder matchRange(PiHeaderFieldId fieldId, short low, short high) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 297 | fieldMatchMapBuilder.put(fieldId, new PiRangeFieldMatch(fieldId, copyFrom(low), copyFrom(high))); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 298 | return this; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Adds a range field match for the given fieldId, low and high. |
| 303 | * |
| 304 | * @param fieldId protocol-independent header field Id |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 305 | * @param low range match low value |
| 306 | * @param high range match high value |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 307 | * @return this |
| 308 | */ |
| 309 | public Builder matchRange(PiHeaderFieldId fieldId, int low, int high) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 310 | fieldMatchMapBuilder.put(fieldId, new PiRangeFieldMatch(fieldId, copyFrom(low), copyFrom(high))); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 311 | return this; |
| 312 | } |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 313 | |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 314 | /** |
| 315 | * Adds a range field match for the given fieldId, low and high. |
| 316 | * |
| 317 | * @param fieldId protocol-independent header field Id |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 318 | * @param low range match low value |
| 319 | * @param high range match high value |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 320 | * @return this |
| 321 | */ |
| 322 | public Builder matchRange(PiHeaderFieldId fieldId, long low, long high) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 323 | fieldMatchMapBuilder.put(fieldId, new PiRangeFieldMatch(fieldId, copyFrom(low), copyFrom(high))); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 324 | return this; |
| 325 | } |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 326 | |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 327 | /** |
| 328 | * Adds a range field match for the given fieldId, low and high. |
| 329 | * |
| 330 | * @param fieldId protocol-independent header field Id |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 331 | * @param low range match low value |
| 332 | * @param high range match high value |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 333 | * @return this |
| 334 | */ |
| 335 | public Builder matchRange(PiHeaderFieldId fieldId, byte[] low, byte[] high) { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 336 | fieldMatchMapBuilder.put(fieldId, new PiRangeFieldMatch(fieldId, copyFrom(low), copyFrom(high))); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 337 | return this; |
| 338 | } |
| 339 | |
| 340 | /** |
| 341 | * Builds a PiCriterion. |
| 342 | * |
| 343 | * @return PiCriterion |
| 344 | */ |
| 345 | public Criterion build() { |
Carmelo Cascone | 32a01b2 | 2017-07-18 10:51:07 -0400 | [diff] [blame] | 346 | ImmutableMap<PiHeaderFieldId, PiFieldMatch> fieldMatchMap = fieldMatchMapBuilder.build(); |
| 347 | checkArgument(fieldMatchMap.size() > 0, "Cannot build PI criterion with 0 field matches"); |
| 348 | return new PiCriterion(fieldMatchMap); |
Frank Wang | df38321 | 2017-06-23 09:17:41 +0800 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | } |