Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -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 | 24c849c | 2014-10-27 09:53:05 -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 | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 16 | package org.onlab.packet; |
| 17 | |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 18 | import java.util.Objects; |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 19 | |
| 20 | /** |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 21 | * A class representing an IP prefix. A prefix consists of an IP address and |
| 22 | * a subnet mask. |
Pavlin Radoslavov | f182f01 | 2014-11-04 15:03:18 -0800 | [diff] [blame] | 23 | * This class is immutable. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 24 | * <p> |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 25 | * NOTE: The stored IP address in the result IP prefix is masked to |
| 26 | * contain zeroes in all bits after the prefix length. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 27 | * </p> |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 28 | */ |
Pavlin Radoslavov | f182f01 | 2014-11-04 15:03:18 -0800 | [diff] [blame] | 29 | public class IpPrefix { |
Charles Chan | 4ca8e60 | 2016-02-25 18:05:59 -0800 | [diff] [blame] | 30 | /** |
| 31 | * Longest IPv4 network prefix. |
| 32 | */ |
Pavlin Radoslavov | 52307e6 | 2014-10-29 15:07:37 -0700 | [diff] [blame] | 33 | public static final int MAX_INET_MASK_LENGTH = IpAddress.INET_BIT_LENGTH; |
Charles Chan | 4ca8e60 | 2016-02-25 18:05:59 -0800 | [diff] [blame] | 34 | /** |
| 35 | * Longest IPv6 network prefix. |
| 36 | */ |
Pavlin Radoslavov | 52307e6 | 2014-10-29 15:07:37 -0700 | [diff] [blame] | 37 | public static final int MAX_INET6_MASK_LENGTH = IpAddress.INET6_BIT_LENGTH; |
Charles Chan | 4ca8e60 | 2016-02-25 18:05:59 -0800 | [diff] [blame] | 38 | /** |
| 39 | * An IpPrefix that contains all IPv4 multicast addresses. |
| 40 | */ |
| 41 | @Deprecated |
Jonathan Hart | 7f4bc52 | 2016-02-20 11:32:43 -0800 | [diff] [blame] | 42 | public static final IpPrefix MULTICAST_RANGE = IpPrefix.valueOf("224.0.0.0/4"); |
Charles Chan | 4ca8e60 | 2016-02-25 18:05:59 -0800 | [diff] [blame] | 43 | /** |
| 44 | * An IpPrefix that contains all IPv4 multicast addresses. |
| 45 | */ |
Charles Chan | aedabfd | 2016-02-26 09:31:48 -0800 | [diff] [blame] | 46 | public static final IpPrefix IPV4_MULTICAST_PREFIX = IpPrefix.valueOf("224.0.0.0/4"); |
Charles Chan | 4ca8e60 | 2016-02-25 18:05:59 -0800 | [diff] [blame] | 47 | /** |
| 48 | * An IpPrefix that contains all IPv6 multicast addresses. |
| 49 | */ |
Charles Chan | aedabfd | 2016-02-26 09:31:48 -0800 | [diff] [blame] | 50 | public static final IpPrefix IPV6_MULTICAST_PREFIX = IpPrefix.valueOf("ff00::/8"); |
Jonathan Hart | 7f4bc52 | 2016-02-20 11:32:43 -0800 | [diff] [blame] | 51 | |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 52 | private final IpAddress address; |
| 53 | private final short prefixLength; |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 54 | |
Ayaka Koshibe | 40e7fec | 2014-09-16 22:32:19 -0700 | [diff] [blame] | 55 | /** |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 56 | * Constructor for given IP address, and a prefix length. |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 57 | * |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 58 | * @param address the IP address |
| 59 | * @param prefixLength the prefix length |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 60 | * @throws IllegalArgumentException if the prefix length value is invalid |
Ayaka Koshibe | 40e7fec | 2014-09-16 22:32:19 -0700 | [diff] [blame] | 61 | */ |
Pavlin Radoslavov | f182f01 | 2014-11-04 15:03:18 -0800 | [diff] [blame] | 62 | protected IpPrefix(IpAddress address, int prefixLength) { |
Pavlin Radoslavov | 34c921a | 2014-11-03 15:41:22 -0800 | [diff] [blame] | 63 | checkPrefixLength(address.version(), prefixLength); |
| 64 | this.address = IpAddress.makeMaskedAddress(address, prefixLength); |
| 65 | this.prefixLength = (short) prefixLength; |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 69 | * Returns the IP version of the prefix. |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 70 | * |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 71 | * @return the IP version of the prefix |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 72 | */ |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 73 | public IpAddress.Version version() { |
| 74 | return address.version(); |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
Pavlin Radoslavov | 34ffe72 | 2015-03-10 12:48:55 -0700 | [diff] [blame] | 78 | * Tests whether the IP version of this prefix is IPv4. |
| 79 | * |
| 80 | * @return true if the IP version of this prefix is IPv4, otherwise false. |
| 81 | */ |
| 82 | public boolean isIp4() { |
| 83 | return address.isIp4(); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Tests whether the IP version of this prefix is IPv6. |
| 88 | * |
| 89 | * @return true if the IP version of this prefix is IPv6, otherwise false. |
| 90 | */ |
| 91 | public boolean isIp6() { |
| 92 | return address.isIp6(); |
| 93 | } |
| 94 | |
| 95 | /** |
Charles Chan | aedabfd | 2016-02-26 09:31:48 -0800 | [diff] [blame] | 96 | * Check if this IP prefix is a multicast prefix. |
| 97 | * |
| 98 | * @return true if this prefix a multicast prefix |
| 99 | */ |
| 100 | public boolean isMulticast() { |
| 101 | return isIp4() ? |
| 102 | IPV4_MULTICAST_PREFIX.contains(this.getIp4Prefix()) : |
| 103 | IPV6_MULTICAST_PREFIX.contains(this.getIp6Prefix()); |
| 104 | } |
| 105 | |
| 106 | /** |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 107 | * Returns the IP address value of the prefix. |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 108 | * |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 109 | * @return the IP address value of the prefix |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 110 | */ |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 111 | public IpAddress address() { |
| 112 | return address; |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 115 | /** |
Yuta HIGUCHI | 10681f6 | 2014-09-21 17:49:46 -0700 | [diff] [blame] | 116 | * Returns the IP address prefix length. |
| 117 | * |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 118 | * @return the IP address prefix length |
Yuta HIGUCHI | 10681f6 | 2014-09-21 17:49:46 -0700 | [diff] [blame] | 119 | */ |
| 120 | public int prefixLength() { |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 121 | return prefixLength; |
Yuta HIGUCHI | 10681f6 | 2014-09-21 17:49:46 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /** |
Pavlin Radoslavov | 34c8164 | 2014-11-04 16:21:38 -0800 | [diff] [blame] | 125 | * Gets the {@link Ip4Prefix} view of the IP prefix. |
| 126 | * |
| 127 | * @return the {@link Ip4Prefix} view of the IP prefix if it is IPv4, |
| 128 | * otherwise null |
| 129 | */ |
| 130 | public Ip4Prefix getIp4Prefix() { |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 131 | if (!isIp4()) { |
Pavlin Radoslavov | 34c8164 | 2014-11-04 16:21:38 -0800 | [diff] [blame] | 132 | return null; |
| 133 | } |
| 134 | |
| 135 | // Return this object itself if it is already instance of Ip4Prefix |
| 136 | if (this instanceof Ip4Prefix) { |
| 137 | return (Ip4Prefix) this; |
| 138 | } |
| 139 | return Ip4Prefix.valueOf(address.getIp4Address(), prefixLength); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Gets the {@link Ip6Prefix} view of the IP prefix. |
| 144 | * |
| 145 | * @return the {@link Ip6Prefix} view of the IP prefix if it is IPv6, |
| 146 | * otherwise null |
| 147 | */ |
| 148 | public Ip6Prefix getIp6Prefix() { |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 149 | if (!isIp6()) { |
Pavlin Radoslavov | 34c8164 | 2014-11-04 16:21:38 -0800 | [diff] [blame] | 150 | return null; |
| 151 | } |
| 152 | |
| 153 | // Return this object itself if it is already instance of Ip6Prefix |
| 154 | if (this instanceof Ip6Prefix) { |
| 155 | return (Ip6Prefix) this; |
| 156 | } |
| 157 | return Ip6Prefix.valueOf(address.getIp6Address(), prefixLength); |
| 158 | } |
| 159 | |
| 160 | /** |
Pavlin Radoslavov | 34c921a | 2014-11-03 15:41:22 -0800 | [diff] [blame] | 161 | * Converts an integer and a prefix length into an IPv4 prefix. |
| 162 | * |
| 163 | * @param address an integer representing the IPv4 address |
| 164 | * @param prefixLength the prefix length |
| 165 | * @return an IP prefix |
| 166 | * @throws IllegalArgumentException if the prefix length value is invalid |
| 167 | */ |
| 168 | public static IpPrefix valueOf(int address, int prefixLength) { |
| 169 | return new IpPrefix(IpAddress.valueOf(address), prefixLength); |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Converts a byte array and a prefix length into an IP prefix. |
| 174 | * |
| 175 | * @param version the IP address version |
| 176 | * @param address the IP address value stored in network byte order |
| 177 | * @param prefixLength the prefix length |
| 178 | * @return an IP prefix |
| 179 | * @throws IllegalArgumentException if the prefix length value is invalid |
| 180 | */ |
| 181 | public static IpPrefix valueOf(IpAddress.Version version, byte[] address, |
| 182 | int prefixLength) { |
| 183 | return new IpPrefix(IpAddress.valueOf(version, address), prefixLength); |
| 184 | } |
| 185 | |
| 186 | /** |
Pavlin Radoslavov | f182f01 | 2014-11-04 15:03:18 -0800 | [diff] [blame] | 187 | * Converts an IP address and a prefix length into an IP prefix. |
Pavlin Radoslavov | 34c921a | 2014-11-03 15:41:22 -0800 | [diff] [blame] | 188 | * |
| 189 | * @param address the IP address |
| 190 | * @param prefixLength the prefix length |
| 191 | * @return an IP prefix |
| 192 | * @throws IllegalArgumentException if the prefix length value is invalid |
| 193 | */ |
| 194 | public static IpPrefix valueOf(IpAddress address, int prefixLength) { |
| 195 | return new IpPrefix(address, prefixLength); |
| 196 | } |
| 197 | |
| 198 | /** |
Pavlin Radoslavov | f182f01 | 2014-11-04 15:03:18 -0800 | [diff] [blame] | 199 | * Converts a CIDR (slash) notation string (e.g., "10.1.0.0/16" or |
| 200 | * "1111:2222::/64") into an IP prefix. |
Pavlin Radoslavov | 34c921a | 2014-11-03 15:41:22 -0800 | [diff] [blame] | 201 | * |
Pavlin Radoslavov | f182f01 | 2014-11-04 15:03:18 -0800 | [diff] [blame] | 202 | * @param address an IP prefix in string form (e.g. "10.1.0.0/16" or |
| 203 | * "1111:2222::/64") |
Pavlin Radoslavov | 34c921a | 2014-11-03 15:41:22 -0800 | [diff] [blame] | 204 | * @return an IP prefix |
| 205 | * @throws IllegalArgumentException if the arguments are invalid |
| 206 | */ |
| 207 | public static IpPrefix valueOf(String address) { |
| 208 | final String[] parts = address.split("/"); |
| 209 | if (parts.length != 2) { |
Pavlin Radoslavov | d7b4584 | 2015-03-20 15:40:59 -0700 | [diff] [blame] | 210 | String msg = "Malformed IP prefix string: " + address + ". " + |
Pavlin Radoslavov | f182f01 | 2014-11-04 15:03:18 -0800 | [diff] [blame] | 211 | "Address must take form \"x.x.x.x/y\" or " + |
| 212 | "\"xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/y\""; |
Pavlin Radoslavov | 34c921a | 2014-11-03 15:41:22 -0800 | [diff] [blame] | 213 | throw new IllegalArgumentException(msg); |
| 214 | } |
| 215 | IpAddress ipAddress = IpAddress.valueOf(parts[0]); |
| 216 | int prefixLength = Integer.parseInt(parts[1]); |
| 217 | |
| 218 | return new IpPrefix(ipAddress, prefixLength); |
| 219 | } |
| 220 | |
| 221 | /** |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 222 | * Determines whether a given IP prefix is contained within this prefix. |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 223 | * |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 224 | * @param other the IP prefix to test |
| 225 | * @return true if the other IP prefix is contained in this prefix, |
| 226 | * otherwise false |
Jonathan Hart | b7a2ac3 | 2014-09-19 10:42:27 -0700 | [diff] [blame] | 227 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 228 | public boolean contains(IpPrefix other) { |
Pavlin Radoslavov | dbeab4c | 2015-02-23 09:37:49 -0800 | [diff] [blame] | 229 | if (version() != other.version()) { |
| 230 | return false; |
| 231 | } |
| 232 | |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 233 | if (this.prefixLength > other.prefixLength) { |
| 234 | return false; // This prefix has smaller prefix size |
Jonathan Hart | b7a2ac3 | 2014-09-19 10:42:27 -0700 | [diff] [blame] | 235 | } |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 236 | |
| 237 | // |
| 238 | // Mask the other address with my prefix length. |
| 239 | // If the other prefix is within this prefix, the masked address must |
| 240 | // be same as the address of this prefix. |
| 241 | // |
| 242 | IpAddress maskedAddr = |
| 243 | IpAddress.makeMaskedAddress(other.address, this.prefixLength); |
| 244 | return this.address.equals(maskedAddr); |
Jonathan Hart | b7a2ac3 | 2014-09-19 10:42:27 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 247 | /** |
| 248 | * Determines whether a given IP address is contained within this prefix. |
| 249 | * |
| 250 | * @param other the IP address to test |
| 251 | * @return true if the IP address is contained in this prefix, otherwise |
| 252 | * false |
| 253 | */ |
| 254 | public boolean contains(IpAddress other) { |
Pavlin Radoslavov | dbeab4c | 2015-02-23 09:37:49 -0800 | [diff] [blame] | 255 | if (version() != other.version()) { |
| 256 | return false; |
| 257 | } |
| 258 | |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 259 | // |
| 260 | // Mask the other address with my prefix length. |
| 261 | // If the other prefix is within this prefix, the masked address must |
| 262 | // be same as the address of this prefix. |
| 263 | // |
| 264 | IpAddress maskedAddr = |
| 265 | IpAddress.makeMaskedAddress(other, this.prefixLength); |
| 266 | return this.address.equals(maskedAddr); |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 269 | @Override |
Ayaka Koshibe | 40e7fec | 2014-09-16 22:32:19 -0700 | [diff] [blame] | 270 | public int hashCode() { |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 271 | return Objects.hash(address, prefixLength); |
Ayaka Koshibe | 40e7fec | 2014-09-16 22:32:19 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | @Override |
| 275 | public boolean equals(Object obj) { |
| 276 | if (this == obj) { |
| 277 | return true; |
| 278 | } |
Pavlin Radoslavov | 50b7067 | 2014-11-05 11:22:25 -0800 | [diff] [blame] | 279 | if ((obj == null) || (!(obj instanceof IpPrefix))) { |
Ayaka Koshibe | 40e7fec | 2014-09-16 22:32:19 -0700 | [diff] [blame] | 280 | return false; |
| 281 | } |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 282 | IpPrefix other = (IpPrefix) obj; |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 283 | return ((prefixLength == other.prefixLength) && |
| 284 | address.equals(other.address)); |
Ayaka Koshibe | 40e7fec | 2014-09-16 22:32:19 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | @Override |
| 288 | /* |
| 289 | * (non-Javadoc) |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 290 | * The format is "x.x.x.x/y" for IPv4 prefixes. |
Ayaka Koshibe | 40e7fec | 2014-09-16 22:32:19 -0700 | [diff] [blame] | 291 | * |
| 292 | * @see java.lang.Object#toString() |
| 293 | */ |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 294 | public String toString() { |
| 295 | final StringBuilder builder = new StringBuilder(); |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 296 | builder.append(address.toString()); |
| 297 | builder.append("/"); |
| 298 | builder.append(String.format("%d", prefixLength)); |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 299 | return builder.toString(); |
| 300 | } |
Pavlin Radoslavov | 34c921a | 2014-11-03 15:41:22 -0800 | [diff] [blame] | 301 | |
| 302 | /** |
| 303 | * Checks whether the prefix length is valid. |
| 304 | * |
| 305 | * @param version the IP address version |
| 306 | * @param prefixLength the prefix length value to check |
| 307 | * @throws IllegalArgumentException if the prefix length value is invalid |
| 308 | */ |
| 309 | private static void checkPrefixLength(IpAddress.Version version, |
| 310 | int prefixLength) { |
| 311 | int maxPrefixLen = 0; |
| 312 | |
| 313 | switch (version) { |
| 314 | case INET: |
| 315 | maxPrefixLen = MAX_INET_MASK_LENGTH; |
| 316 | break; |
| 317 | case INET6: |
| 318 | maxPrefixLen = MAX_INET6_MASK_LENGTH; |
| 319 | break; |
| 320 | default: |
| 321 | String msg = "Invalid IP version " + version; |
| 322 | throw new IllegalArgumentException(msg); |
| 323 | } |
| 324 | |
| 325 | if ((prefixLength < 0) || (prefixLength > maxPrefixLen)) { |
| 326 | String msg = "Invalid prefix length " + prefixLength + ". " + |
| 327 | "The value must be in the interval [0, " + |
| 328 | maxPrefixLen + "]"; |
| 329 | throw new IllegalArgumentException(msg); |
| 330 | } |
| 331 | } |
Ayaka Koshibe | 1c7b38e | 2014-09-11 13:09:51 -0700 | [diff] [blame] | 332 | } |