/** * Gets IPv6 peer address. * * @return the IPv6 peer address */ public Ip6Address getIp6PeerAddress() { return peerAddress == null ? null : Ip6Address.valueOf(peerAddress); }
/** * Gets IPv6 link address. * * @return the IPv6 link address */ public Ip6Address getIp6LinkAddress() { return linkAddress == null ? null : Ip6Address.valueOf(linkAddress); }
/** * 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); }
@Override public String toString() { if (RELAY_MSG_TYPES.contains(msgType)) { // relay message return toStringHelper(getClass()) .add("msgType", msgType) .add("hopCount", hopCount) .add("linkAddress", Ip6Address.valueOf(linkAddress)) .add("peerAddress", Ip6Address.valueOf(peerAddress)) .add("options", options) .toString(); } else { return toStringHelper(getClass()) .add("msgType", msgType) .add("transactionId", transactionId) .add("options", options) .toString(); } } }
/** * Gets the {@link Ip6Address} view of the IP address. * * @return the {@link Ip6Address} view of the IP address if it is IPv6, * otherwise null */ public Ip6Address getIp6Address() { if (!isIp6()) { return null; } // Return this object itself if it is already instance of Ip6Address if (this instanceof Ip6Address) { return (Ip6Address) this; } return Ip6Address.valueOf(octets); }
/** * Creates an IPv6 address by masking it with a network mask of given * mask length. * * @param address the address to mask * @param prefixLength the length of the mask prefix. Must be in the * interval [0, 128] * @return a new IPv6 address that is masked with a mask prefix of the * specified length * @throws IllegalArgumentException if the prefix length is invalid */ public static Ip6Address makeMaskedAddress(final Ip6Address address, int prefixLength) { byte[] net = makeMaskedAddressArray(address, prefixLength); return Ip6Address.valueOf(net); } }
/** * Converts a byte array and a given offset from the beginning of the * array into an IPv6 address. * <p> * The IP address is stored in network byte order (i.e., the most * significant byte first). * </p> * @param value the value to use * @param offset the offset in bytes from the beginning of the byte array * @return an IPv6 address * @throws IllegalArgumentException if the arguments are invalid */ public static Ip6Address valueOf(byte[] value, int offset) { IpAddress.checkArguments(VERSION, value, offset); byte[] bc = Arrays.copyOfRange(value, offset, value.length); return Ip6Address.valueOf(bc); }
/** * Converts an IPv6 string literal (e.g., "1111:2222::8888") into an IP * address. * * @param value an IPv6 address value in string form * @return an IPv6 address * @throws IllegalArgumentException if the argument is invalid */ public static Ip6Address valueOf(String value) { InetAddress inetAddress = null; try { inetAddress = InetAddresses.forString(value); } catch (IllegalArgumentException e) { final String msg = "Invalid IP address string: " + value; throw new IllegalArgumentException(msg); } return valueOf(inetAddress); }
@Override public Criterion decodeCriterion(ObjectNode json) { Ip6Address target = Ip6Address.valueOf(nullIsIllegal(json.get(CriterionCodec.TARGET_ADDRESS), CriterionCodec.TARGET_ADDRESS + MISSING_MEMBER_MESSAGE).asText()); return Criteria.matchIPv6NDTargetAddress(target); } }
/** * 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); } }
@Override public Ip6Address read(Kryo kryo, Input input, Class<Ip6Address> type) { final int octLen = input.readInt(); checkArgument(octLen == Ip6Address.BYTE_LENGTH); byte[] octs = new byte[octLen]; input.readBytes(octs); return Ip6Address.valueOf(octs); } }
public PIMAddrUnicast deserialize(ByteBuffer bb) throws DeserializationException { // Assume IPv4 for check length until we read the encoded family. checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_UNICAST_IPV4_BYTE_LENGTH); this.family = bb.get(); // If we have IPv6 we need to ensure we have adequate buffer space. if (this.family != PIM.ADDRESS_FAMILY_IP4 && this.family != PIM.ADDRESS_FAMILY_IP6) { throw new DeserializationException("Invalid address family: " + this.family); } else if (this.family == PIM.ADDRESS_FAMILY_IP6) { // Subtract -1 from ENC_UNICAST_IPv6 BYTE_LENGTH because we read one byte for family previously. checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_UNICAST_IPV6_BYTE_LENGTH - 1); } this.encType = bb.get(); if (this.family == PIM.ADDRESS_FAMILY_IP4) { this.addr = IpAddress.valueOf(bb.getInt()); } else if (this.family == PIM.ADDRESS_FAMILY_IP6) { this.addr = Ip6Address.valueOf(bb.array(), 2); } return this; }
this.addr = IpAddress.valueOf(bb.getInt()); } else if (this.family == PIM.ADDRESS_FAMILY_IP6) { this.addr = Ip6Address.valueOf(bb.array(), 2);
this.addr = IpAddress.valueOf(bb.getInt()); } else if (this.family == PIM.ADDRESS_FAMILY_IP6) { this.addr = Ip6Address.valueOf(bb.array(), 2);
/** * Reads the channel buffer and returns object of IPv6AddressTlv. * * @param cb channelBuffer * @param type address type * @return object of IPv6AddressTlv * @throws BgpParseException while parsing IPv6AddressTlv */ public static IPv6AddressTlv read(ChannelBuffer cb, short type) throws BgpParseException { InetAddress ipAddress = Validation.toInetAddress(LENGTH, cb); if (ipAddress.isMulticastAddress()) { throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null); } Ip6Address address = Ip6Address.valueOf(ipAddress); return IPv6AddressTlv.of(address, type); }
public static Deserializer<Dhcp6Option> deserializer() { return (data, offset, length) -> { Dhcp6IaPrefixOption iaPrefixOption = new Dhcp6IaPrefixOption(); Dhcp6Option dhcp6Option = Dhcp6Option.deserializer().deserialize(data, offset, length); iaPrefixOption.setPayload(dhcp6Option.getPayload()); if (dhcp6Option.getLength() < DEFAULT_LEN) { throw new DeserializationException("Invalid length of IA prefix option"); } ByteBuffer bb = ByteBuffer.wrap(dhcp6Option.getData()); iaPrefixOption.preferredLifetime = bb.getInt(); iaPrefixOption.validLifetime = bb.getInt(); iaPrefixOption.prefixLength = bb.get(); byte[] ipv6Pref = new byte[Ip6Address.BYTE_LENGTH]; bb.get(ipv6Pref); iaPrefixOption.ip6Prefix = Ip6Address.valueOf(ipv6Pref); // options length of IA Address option int optionsLen = dhcp6Option.getLength() - DEFAULT_LEN; if (optionsLen > 0) { byte[] optionsData = new byte[optionsLen]; bb.get(optionsData); iaPrefixOption.options = Data.deserializer().deserialize(optionsData, 0, optionsLen); } return iaPrefixOption; }; }
public static Deserializer<Dhcp6Option> deserializer() { return (data, offset, length) -> { Dhcp6IaAddressOption iaAddressOption = new Dhcp6IaAddressOption(); Dhcp6Option dhcp6Option = Dhcp6Option.deserializer().deserialize(data, offset, length); iaAddressOption.setPayload(dhcp6Option.getPayload()); if (dhcp6Option.getLength() < DEFAULT_LEN) { throw new DeserializationException("Invalid length of IA address option"); } ByteBuffer bb = ByteBuffer.wrap(dhcp6Option.getData()); byte[] ipv6Addr = new byte[16]; bb.get(ipv6Addr); iaAddressOption.ip6Address = Ip6Address.valueOf(ipv6Addr); iaAddressOption.preferredLifetime = bb.getInt(); iaAddressOption.validLifetime = bb.getInt(); // options length of IA Address option int optionsLen = dhcp6Option.getLength() - DEFAULT_LEN; if (optionsLen > 0) { byte[] optionsData = new byte[optionsLen]; bb.get(optionsData); iaAddressOption.options = Data.deserializer().deserialize(optionsData, 0, optionsLen); } return iaAddressOption; }; }
Ip6Prefix prefix = Ip6Prefix.valueOf(Ip6Address.valueOf(buffer), prefixBitlen); result.add(prefix);
/** * Reads the IPv6 Router-ID. * * @param cb ChannelBuffer * @param sType TLV type * @return object of BgpAttrRouterIdV6 * @throws BgpParseException while parsing BgpAttrRouterIdV6 */ public static BgpAttrRouterIdV6 read(ChannelBuffer cb, short sType) throws BgpParseException { byte[] ipBytes; Ip6Address ip6RouterId; short lsAttrLength = cb.readShort(); if ((lsAttrLength != 16) || (cb.readableBytes() < lsAttrLength)) { Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, lsAttrLength); } ipBytes = new byte[lsAttrLength]; cb.readBytes(ipBytes); ip6RouterId = Ip6Address.valueOf(ipBytes); return BgpAttrRouterIdV6.of(ip6RouterId, sType); }
/** * Reads the OSPF Forwarding Address. * * @param cb ChannelBuffer * @return object of BgpPrefixAttrOSPFFwdAddr * @throws BgpParseException while parsing BgpPrefixAttrOspfFwdAddr */ public static BgpPrefixAttrOspfFwdAddr read(ChannelBuffer cb) throws BgpParseException { short lsAttrLength; byte[] ipBytes; Ip4Address ip4RouterId = null; Ip6Address ip6RouterId = null; lsAttrLength = cb.readShort(); ipBytes = new byte[lsAttrLength]; if ((cb.readableBytes() < lsAttrLength)) { Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, lsAttrLength); } cb.readBytes(ipBytes); if (IPV4_LEN == lsAttrLength) { ip4RouterId = Ip4Address.valueOf(ipBytes); } else if (IPV6_LEN == lsAttrLength) { ip6RouterId = Ip6Address.valueOf(ipBytes); } return BgpPrefixAttrOspfFwdAddr.of(lsAttrLength, ip4RouterId, ip6RouterId); }