/** * Converts an IPv6 address and a prefix length into an IPv6 prefix. * * @param address the IPv6 address * @param prefixLength the prefix length * @return an IPv6 prefix * @throws IllegalArgumentException if the prefix length value is invalid */ public static Ip6Prefix valueOf(Ip6Address address, int prefixLength) { return new Ip6Prefix(address, prefixLength); }
/** * Gets the {@link Ip6Prefix} view of the IP prefix. * * @return the {@link Ip6Prefix} view of the IP prefix if it is IPv6, * otherwise null */ public Ip6Prefix getIp6Prefix() { if (!isIp6()) { return null; } // Return this object itself if it is already instance of Ip6Prefix if (this instanceof Ip6Prefix) { return (Ip6Prefix) this; } return Ip6Prefix.valueOf(address.getIp6Address(), prefixLength); }
@Override public void write(Kryo kryo, Output output, Ip6Prefix object) { byte[] octs = object.address().toOctets(); // It is always Ip6Address.BYTE_LENGTH output.writeInt(octs.length); output.writeBytes(octs); output.writeInt(object.prefixLength()); }
@Override public Ip6Prefix read(Kryo kryo, Input input, Class<Ip6Prefix> type) { int octLen = input.readInt(); checkArgument(octLen <= Ip6Address.BYTE_LENGTH); byte[] octs = new byte[octLen]; input.readBytes(octs); int prefLen = input.readInt(); return Ip6Prefix.valueOf(octs, prefLen); } }
ipCriterion = (IPCriterion) c; ip6Prefix = ipCriterion.ip().getIp6Prefix(); if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) { Ip6Address maskAddr = Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength()); Masked<IPv6Address> maskedIp = Masked.of(IPv6Address.of(ip6Prefix.address().toString()), IPv6Address.of(maskAddr.toString())); mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp); } else { mBuilder.setExact(MatchField.IPV6_SRC, IPv6Address.of(ip6Prefix.address().toString())); ipCriterion = (IPCriterion) c; ip6Prefix = ipCriterion.ip().getIp6Prefix(); if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) { Ip6Address maskAddr = Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength()); Masked<IPv6Address> maskedIp = Masked.of(IPv6Address.of(ip6Prefix.address().toString()), IPv6Address.of(maskAddr.toString())); mBuilder.setMasked(MatchField.IPV6_DST, maskedIp); } else { mBuilder.setExact(MatchField.IPV6_DST, IPv6Address.of(ip6Prefix.address().toString()));
Ip6Prefix prefix = Ip6Prefix.valueOf(Ip6Address.valueOf(buffer), prefixBitlen); result.add(prefix);
/** * Converts a byte array and a prefix length into an IPv6 prefix. * * @param address the IPv6 address value stored in network byte order * @param prefixLength the prefix length * @return an IPv6 prefix * @throws IllegalArgumentException if the prefix length value is invalid */ public static Ip6Prefix valueOf(byte[] address, int prefixLength) { return new Ip6Prefix(Ip6Address.valueOf(address), prefixLength); }
if (match.isPartiallyMasked(MatchField.IPV6_SRC)) { Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC); ip6Prefix = Ip6Prefix.valueOf( maskedIp.getValue().getBytes(), maskedIp.getMask().asCidrMaskLength()); } else { ip6Prefix = Ip6Prefix.valueOf( match.get(MatchField.IPV6_SRC).getBytes(), Ip6Prefix.MAX_MASK_LENGTH); if (match.isPartiallyMasked(MatchField.IPV6_DST)) { Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST); ip6Prefix = Ip6Prefix.valueOf( maskedIp.getValue().getBytes(), maskedIp.getMask().asCidrMaskLength()); } else { ip6Prefix = Ip6Prefix.valueOf( match.get(MatchField.IPV6_DST).getBytes(), Ip6Prefix.MAX_MASK_LENGTH);
/** * Converts a CIDR (slash) notation string (e.g., "1111:2222::/64") * into an IPv6 prefix. * * @param address an IP prefix in string form (e.g.,"1111:2222::/64") * @return an IPv6 prefix * @throws IllegalArgumentException if the arguments are invalid */ public static Ip6Prefix valueOf(String address) { final String[] parts = address.split("/"); if (parts.length != 2) { String msg = "Malformed IPv6 prefix string: " + address + ". " + "Address must take form " + "\"xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/y\""; throw new IllegalArgumentException(msg); } Ip6Address ipAddress = Ip6Address.valueOf(parts[0]); int prefixLength = Integer.parseInt(parts[1]); return new Ip6Prefix(ipAddress, prefixLength); } }