public abstract class NetUtils extends Object
Modifier and Type | Field and Description |
---|---|
protected static org.slf4j.Logger |
LOG |
static int |
MAC_ADDR_LENGTH_IN_BYTES
Constant holding the number of bytes in MAC Address.
|
static int |
MAC_ADDR_LENGTH_IN_WORDS
Constant holding the number of words in MAC Address.
|
static int |
NUM_BITS_IN_A_BYTE
Constant holding the number of bits in a byte.
|
Constructor and Description |
---|
NetUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
byteArray4ToInt(byte[] ba)
Converts a 4 bytes array into an integer number.
|
static long |
byteArray6ToLong(byte[] ba)
Converts a 6 bytes array into a long number MAC addresses.
|
static boolean |
fieldsConflict(int field1,
int field2) |
static byte[] |
getBroadcastMACAddr()
Returns Broadcast MAC Address.
|
static InetAddress |
gethighestIP(boolean v6)
Returns the highest v4 or v6 InetAddress.
|
static InetAddress |
getInetAddress(int address)
Converts an IP address passed as integer value into the respective InetAddress object.
|
static InetAddress |
getInetNetworkMask(int prefixMaskLength,
boolean isV6)
Return the InetAddress Network Mask given the length of the prefix bit
mask.
|
static int |
getSubnetMaskLength(byte[] subnetMask)
Returns the prefix size in bits of the specified subnet mask.
|
static int |
getSubnetMaskLength(InetAddress subnetMask)
Returns the prefix size in bits of the specified subnet mask.
|
static InetAddress |
getSubnetPrefix(InetAddress ip,
int maskLen)
Given an IP address and a prefix network mask length, it returns the
equivalent subnet prefix IP address Example: for ip = "172.28.30.254" and
maskLen = 25 it will return "172.28.30.128".
|
static int |
getUnsignedByte(byte value)
Returns the unsigned value of the passed byte variable.
|
static int |
getUnsignedShort(short value)
Return the unsigned value of the passed short variable.
|
static boolean |
inetAddressConflict(InetAddress testAddress,
InetAddress filterAddress,
InetAddress testMask,
InetAddress filterMask)
Checks if the test address and mask conflicts with the filter address and mask.
|
static byte[] |
intToByteArray4(int number)
Converts an integer number into a 4 bytes array.
|
static boolean |
isAny(InetAddress ip)
Returns true if the passed InetAddress contains all zero.
|
static boolean |
isBroadcastMACAddr(byte[] macAddress)
Returns true if the MAC address is the broadcast MAC address and false otherwise.
|
static boolean |
isIPAddressValid(String cidr)
Checks if the passed IP address in string form is a valid v4 or v6
address.
|
static boolean |
isIPv4AddressValid(String cidr)
Checks if the passed IP v4 address in string form is valid The address
may specify a mask at the end as "/MM".
|
static boolean |
isIPv6AddressValid(String cidr)
Checks if the passed IP v6 address in string form is valid The address
may specify a mask at the end as "/MMM".
|
static boolean |
isMulticastMACAddr(byte[] macAddress)
Returns true if the MAC address is a multicast MAC address and false
otherwise.
|
static boolean |
isUnicastMACAddr(byte[] macAddress)
Returns true if the MAC address is a unicast MAC address and false otherwise.
|
static boolean |
isZeroMAC(byte[] mac)
Returns true if the passed MAC address is all zero.
|
static byte[] |
longToByteArray6(long addr)
Converts a long number to a 6 bytes array for MAC addresses.
|
static InetAddress |
parseInetAddress(String addressString) |
protected static final org.slf4j.Logger LOG
public static final int NUM_BITS_IN_A_BYTE
public static final int MAC_ADDR_LENGTH_IN_BYTES
public static final int MAC_ADDR_LENGTH_IN_WORDS
public static int byteArray4ToInt(byte[] ba)
ba
- the 4 bytes long byte arraypublic static long byteArray6ToLong(byte[] ba)
ba
- The 6 bytes long byte array.ba
is null
or
the length of it is not six.public static byte[] longToByteArray6(long addr)
addr
- The long number.public static byte[] intToByteArray4(int number)
number
- the integer numberpublic static InetAddress getInetAddress(int address)
address
- the IP address in integer formpublic static InetAddress getInetNetworkMask(int prefixMaskLength, boolean isV6)
prefixMaskLength
- integer representing the length of the prefix network maskisV6
- boolean representing the IP version of the returned addresspublic static int getSubnetMaskLength(byte[] subnetMask)
subnetMask
- the subnet mask as byte arraypublic static int getSubnetMaskLength(InetAddress subnetMask)
subnetMask
- the subnet mask as InetAddresspublic static InetAddress getSubnetPrefix(InetAddress ip, int maskLen)
ip
- the IP address in InetAddress formmaskLen
- the length of the prefix network maskpublic static boolean inetAddressConflict(InetAddress testAddress, InetAddress filterAddress, InetAddress testMask, InetAddress filterMask)
For example: testAddress: 172.28.2.23 testMask: 255.255.255.0 filterAddress: 172.28.1.10 testMask: 255.255.255.0 do conflict
testAddress: 172.28.2.23 testMask: 255.255.255.0 filterAddress: 172.28.1.10 testMask: 255.255.0.0 do not conflict
Null parameters are permitted.
public static boolean isZeroMAC(byte[] mac)
mac
- the byte array representing the MAC addresspublic static boolean isBroadcastMACAddr(byte[] macAddress)
public static boolean isUnicastMACAddr(byte[] macAddress)
public static boolean isMulticastMACAddr(byte[] macAddress)
public static boolean isAny(InetAddress ip)
ip
- the IP address to testpublic static boolean fieldsConflict(int field1, int field2)
public static InetAddress parseInetAddress(String addressString)
public static boolean isIPv4AddressValid(String cidr)
cidr
- the v4 address as A.B.C.D/MMpublic static boolean isIPv6AddressValid(String cidr)
cidr
- the v6 address as A::1/MMMpublic static boolean isIPAddressValid(String cidr)
cidr
- the v4 or v6 address as IP/MMMpublic static int getUnsignedByte(byte value)
value
- the byte valuepublic static int getUnsignedShort(short value)
value
- the short valuepublic static InetAddress gethighestIP(boolean v6)
v6
- true for IPv6, false for Ipv4public static byte[] getBroadcastMACAddr()
Copyright © 2019 OpenDaylight. All rights reserved.