Java Code Examples for org.onlab.packet.IpAddress#INET_BYTE_LENGTH

The following examples show how to use org.onlab.packet.IpAddress#INET_BYTE_LENGTH . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IpPrefixSerializer.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public IpPrefix read(Kryo kryo, Input input,
        Class<IpPrefix> type) {
    int octLen = input.readInt();
    checkArgument(octLen <= IpAddress.INET6_BYTE_LENGTH);
    byte[] octs = new byte[octLen];
    input.readBytes(octs);
    int prefLen = input.readInt();
    // Use the address size to decide whether it is IPv4 or IPv6 address
    if (octLen == IpAddress.INET_BYTE_LENGTH) {
        return IpPrefix.valueOf(IpAddress.Version.INET, octs, prefLen);
    }
    if (octLen == IpAddress.INET6_BYTE_LENGTH) {
        return IpPrefix.valueOf(IpAddress.Version.INET6, octs, prefLen);
    }
    return null;    // Shouldn't be reached
}
 
Example 2
Source File: IpAddressSerializer.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public IpAddress read(Kryo kryo, Input input, Class<IpAddress> type) {
    final int octLen = input.readInt();
    checkArgument(octLen <= IpAddress.INET6_BYTE_LENGTH);
    byte[] octs = new byte[octLen];
    input.readBytes(octs);
    // Use the address size to decide whether it is IPv4 or IPv6 address
    if (octLen == IpAddress.INET_BYTE_LENGTH) {
        return IpAddress.valueOf(IpAddress.Version.INET, octs);
    }
    if (octLen == IpAddress.INET6_BYTE_LENGTH) {
        return IpAddress.valueOf(IpAddress.Version.INET6, octs);
    }
    return null;    // Shouldn't be reached
}