/** * Gets IPv6 peer address. * * @return the IPv6 peer address */ public Ip6Address getIp6PeerAddress() { return peerAddress == null ? null : Ip6Address.valueOf(peerAddress); }
@Override public byte[] serialize() { int payloadLen = options == null ? DEFAULT_LEN : DEFAULT_LEN + options.serialize().length; ByteBuffer bb = ByteBuffer.allocate(payloadLen + Dhcp6Option.DEFAULT_LEN); bb.putShort(DHCP6.OptionCode.IAADDR.value()); bb.putShort((short) payloadLen); bb.put(ip6Address.toOctets()); bb.putInt(preferredLifetime); bb.putInt(validLifetime); if (options != null) { bb.put(options.serialize()); } return bb.array(); }
@Override public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { final IPv6NDTargetAddressCriterion ipv6NDTargetAddressCriterion = (IPv6NDTargetAddressCriterion) criterion; return root.put(CriterionCodec.TARGET_ADDRESS, ipv6NDTargetAddressCriterion.targetAddress().toString()); } }
/** * 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); } }
@Override public void init(Criterion criterion, int bitWidth) throws ByteSequenceTrimException { IPv6NDTargetAddressCriterion c = (IPv6NDTargetAddressCriterion) criterion; initAsExactMatch(copyFrom(c.targetAddress().getIp6Address().toOctets()), bitWidth); } }
final IPv6 ipv6 = (IPv6) pkt; sb.append("\nipv6_src: "); sb.append(Ip6Address.valueOf(ipv6.getSourceAddress()).toString()); sb.append("\nipv6_dst: "); sb.append(Ip6Address.valueOf(ipv6.getDestinationAddress()).toString()); sb.append("\nipv6_proto: "); sb.append(ipv6.getNextHeader()); final NeighborSolicitation ns = (NeighborSolicitation) payload; sb.append("\nns_target_addr: "); sb.append(Ip6Address.valueOf(ns.getTargetAddress()).toString()); ns.getOptions().forEach(option -> { sb.append("\noption_type: "); final NeighborAdvertisement na = (NeighborAdvertisement) payload; sb.append("\nna_target_addr: "); sb.append(Ip6Address.valueOf(na.getTargetAddress()).toString()); sb.append("\nna_solicited_flag: "); sb.append(na.getSolicitedFlag()); final Redirect rd = (Redirect) payload; sb.append("\nrd_target_addr: "); sb.append(Ip6Address.valueOf(rd.getTargetAddress()).toString()); rd.getOptions().forEach(option -> { sb.append("\noption_type: ");
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())); 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())); ip6Address = targetAddressCriterion.targetAddress(); mBuilder.setExact(MatchField.IPV6_ND_TARGET, IPv6Address.of(ip6Address.toOctets())); break; case IPV6_ND_SLL:
/** * Converts a byte array into an IPv6 address. * * @param value the IPv6 address value stored in network byte order * (i.e., the most significant byte first) * @return an IPv6 address * @throws IllegalArgumentException if the argument is invalid */ public static Ip6Address valueOf(byte[] value) { return new Ip6Address(value); }
@Override public int compareTo(Object o) { if (this.equals(o)) { return 0; } return ((Ip6Address) (this.address)).compareTo((Ip6Address) (((IPv6AddressTlv) o).address)); }
/** * Creates an IPv6 network mask prefix. * * @param prefixLength the length of the mask prefix. Must be in the * interval [0, 128] * @return a new IPv6 address that contains a mask prefix of the * specified length * @throws IllegalArgumentException if the arguments are invalid */ public static Ip6Address makeMaskPrefix(int prefixLength) { byte[] mask = IpAddress.makeMaskPrefixArray(VERSION, prefixLength); return new Ip6Address(mask); }
/** * Gets IPv6 link address. * * @return the IPv6 link address */ public Ip6Address getIp6LinkAddress() { return linkAddress == null ? null : Ip6Address.valueOf(linkAddress); }
@Override public byte[] serialize() { int payloadLen = options == null ? DEFAULT_LEN : DEFAULT_LEN + options.serialize().length; ByteBuffer bb = ByteBuffer.allocate(payloadLen + Dhcp6Option.DEFAULT_LEN); bb.putShort(DHCP6.OptionCode.IAPREFIX.value()); bb.putShort((short) payloadLen); bb.putInt(preferredLifetime); bb.putInt(validLifetime); bb.put(prefixLength); bb.put(ip6Prefix.toOctets()); if (options != null) { bb.put(options.serialize()); } return bb.array(); }
/** * Converts an InetAddress into an IPv6 address. * * @param inetAddress the InetAddress value to use. It must contain an IPv6 * address * @return an IPv6 address * @throws IllegalArgumentException if the argument is invalid */ public static Ip6Address valueOf(InetAddress inetAddress) { byte[] bytes = inetAddress.getAddress(); if (inetAddress instanceof Inet6Address) { return new Ip6Address(bytes); } if ((inetAddress instanceof Inet4Address) || (bytes.length == INET_BYTE_LENGTH)) { final String msg = "Invalid IPv6 version address string: " + inetAddress.toString(); throw new IllegalArgumentException(msg); } // Use the number of bytes as a hint if (bytes.length == INET6_BYTE_LENGTH) { return new Ip6Address(bytes); } final String msg = "Unrecognized IP version address string: " + inetAddress.toString(); throw new IllegalArgumentException(msg); }
/** * 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 void writeTo(ByteBuf byteBuf, LispIpv6Address address) throws LispWriterException { byte[] ipByte = address.getAddress().getIp6Address().toOctets(); byteBuf.writeBytes(ipByte); } }
@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(); } } }
@Override public void write(Kryo kryo, Output output, Ip6Address object) { byte[] octs = object.toOctets(); // It is always Ip6Address.BYTE_LENGTH output.writeInt(octs.length); output.writeBytes(octs); }
/** * 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); }
@Override public int write(ChannelBuffer cb) { int iLenStartIndex = cb.writerIndex(); cb.writeShort(type); cb.writeShort(LENGTH); cb.writeBytes(address.toOctets()); return cb.writerIndex() - iLenStartIndex; }
/** * 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); }