IsValidIpV6Benchmark Class — netty Architecture
Architecture documentation for the IsValidIpV6Benchmark class in IsValidIpV6Benchmark.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 9b92b46f_30d7_cc3a_cdb1_382da71e0b4b["IsValidIpV6Benchmark"] 56477445_1d6e_d9dc_bae5_e2311e0d8a76["IsValidIpV6Benchmark.java"] 9b92b46f_30d7_cc3a_cdb1_382da71e0b4b -->|defined in| 56477445_1d6e_d9dc_bae5_e2311e0d8a76 4284543e_d63d_4f50_7633_966dfec71ba6["isValidIp4Word()"] 9b92b46f_30d7_cc3a_cdb1_382da71e0b4b -->|method| 4284543e_d63d_4f50_7633_966dfec71ba6 5a662ff3_5643_047b_1135_3570ffd5f146["isValidHexChar()"] 9b92b46f_30d7_cc3a_cdb1_382da71e0b4b -->|method| 5a662ff3_5643_047b_1135_3570ffd5f146 e844f822_84a6_3bea_aedb_3dddd7b02c83["isValidIPv4MappedChar()"] 9b92b46f_30d7_cc3a_cdb1_382da71e0b4b -->|method| e844f822_84a6_3bea_aedb_3dddd7b02c83 57b756cc_5352_fd98_feb3_98288ab9dd2c["isValidIpV6AddressOld()"] 9b92b46f_30d7_cc3a_cdb1_382da71e0b4b -->|method| 57b756cc_5352_fd98_feb3_98288ab9dd2c 2317803d_7e2c_87f4_580c_31db5b0c7c50["isValidIpV6AddressNew()"] 9b92b46f_30d7_cc3a_cdb1_382da71e0b4b -->|method| 2317803d_7e2c_87f4_580c_31db5b0c7c50
Relationship Graph
Source Code
microbench/src/main/java/io/netty/microbenchmark/common/IsValidIpV6Benchmark.java lines 29–219
@Threads(1)
@Warmup(iterations = 3)
@Measurement(iterations = 3)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public class IsValidIpV6Benchmark extends AbstractMicrobenchmark {
@Param({
"127.0.0.1", "fdf8:f53b:82e4::53", "2001::1",
"2001:0000:4136:e378:8000:63bf:3fff:fdd2", "0:0:0:0:0:0:10.0.0.1"
})
private String ip;
private static boolean isValidIp4Word(String word) {
char c;
if (word.length() < 1 || word.length() > 3) {
return false;
}
for (int i = 0; i < word.length(); i++) {
c = word.charAt(i);
if (!(c >= '0' && c <= '9')) {
return false;
}
}
return Integer.parseInt(word) <= 255;
}
private static boolean isValidHexChar(char c) {
return c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f';
}
private static boolean isValidIPv4MappedChar(char c) {
return c == 'f' || c == 'F';
}
public static boolean isValidIpV6AddressOld(String ipAddress) {
boolean doubleColon = false;
int numberOfColons = 0;
int numberOfPeriods = 0;
StringBuilder word = new StringBuilder();
char c = 0;
char prevChar;
int startOffset = 0; // offset for [] ip addresses
int endOffset = ipAddress.length();
if (endOffset < 2) {
return false;
}
// Strip []
if (ipAddress.charAt(0) == '[') {
if (ipAddress.charAt(endOffset - 1) != ']') {
return false; // must have a close ]
}
startOffset = 1;
endOffset--;
}
// Strip the interface name/index after the percent sign.
int percentIdx = ipAddress.indexOf('%', startOffset);
if (percentIdx >= 0) {
endOffset = percentIdx;
}
for (int i = startOffset; i < endOffset; i++) {
prevChar = c;
c = ipAddress.charAt(i);
switch (c) {
// case for the last 32-bits represented as IPv4 x:x:x:x:x:x:d.d.d.d
case '.':
numberOfPeriods++;
if (numberOfPeriods > 3) {
return false;
}
if (numberOfPeriods == 1) {
// Verify this address is of the correct structure to contain an IPv4 address.
// It must be IPv4-Mapped or IPv4-Compatible
// (see https://tools.ietf.org/html/rfc4291#section-2.5.5).
int j = i - word.length() - 2; // index of character before the previous ':'.
final int beginColonIndex = ipAddress.lastIndexOf(':', j);
if (beginColonIndex == -1) {
Source
Frequently Asked Questions
What is the IsValidIpV6Benchmark class?
IsValidIpV6Benchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/microbenchmark/common/IsValidIpV6Benchmark.java.
Where is IsValidIpV6Benchmark defined?
IsValidIpV6Benchmark is defined in microbench/src/main/java/io/netty/microbenchmark/common/IsValidIpV6Benchmark.java at line 29.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free