Class NWUtil
- java.lang.Object
-
- org.opendaylight.genius.mdsalutil.NWUtil
-
public final class NWUtil extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
convertInetAddressToLong(java.net.InetAddress address)
static int
getEtherTypeFromIpPrefix(java.lang.String ipPrefix)
Utility API that returns the corresponding etherType based on the ipPrefix address family.static java.util.List<org.opendaylight.yangtools.yang.common.Uint64>
getOperativeDPNs(org.opendaylight.controller.md.sal.binding.api.DataBroker dataBroker)
Returns the ids of the currently operative DPNs.static int
ipAddressToInt(java.lang.String ipAddr)
static boolean
isIpAddressInRange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress ipAddress, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix cidr)
Checks if IP address is within CIDR range.static boolean
isIpAddressInRange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address ipv6Address, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix cidr)
Checks if IPv6 address is within CIDR range.static boolean
isIpInSubnet(int ipAddress, java.lang.String subnetCidr)
Checks if a given ipAddress belongs to a specific subnet.static java.lang.Boolean
isIpv4Address(java.lang.String ipAddress)
Utility API to check if the supplied ipAddress is IPv4 Address.static java.lang.String
longToIpv4(long ipAddress, long mask)
Converts IPv4 Address in long to String.static long
macByteToLong(byte[] macAddress)
Accepts a MAC address and returns the corresponding long, where the MAC bytes are set on the lower order bytes of the long.static long
macToLong(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress macAddress)
Accepts a MAC address of the form 00:aa:11:bb:22:cc, case does not matter, and returns the corresponding long, where the MAC bytes are set on the lower order bytes of the long.static byte[]
parseMacAddress(java.lang.String macAddress)
static java.lang.String
toIpPrefix(java.lang.String ipAddress)
Utility API that returns the corresponding ipPrefix based on the ipAddress.static java.lang.String
toStringIpAddress(byte[] ipAddress)
static java.lang.String
toStringMacAddress(byte[] macAddress)
-
-
-
Method Detail
-
convertInetAddressToLong
public static long convertInetAddressToLong(java.net.InetAddress address)
-
longToIpv4
public static java.lang.String longToIpv4(long ipAddress, long mask)
Converts IPv4 Address in long to String.longToIpv4(long, long)
fixes the issue ofMDSALUtil.longToIp(long, long)
not handling IP address greater than byte.- Parameters:
ipAddress
- IP Address to be converted to Stringmask
- Network mask to be appended- Returns:
- IP Address converted to String
-
ipAddressToInt
public static int ipAddressToInt(java.lang.String ipAddr) throws java.net.UnknownHostException
- Throws:
java.net.UnknownHostException
-
parseMacAddress
public static byte[] parseMacAddress(java.lang.String macAddress)
-
toStringIpAddress
public static java.lang.String toStringIpAddress(byte[] ipAddress)
-
macByteToLong
public static long macByteToLong(byte[] macAddress)
Accepts a MAC address and returns the corresponding long, where the MAC bytes are set on the lower order bytes of the long.- Returns:
- a long containing the mac address bytes
-
macToLong
public static long macToLong(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress macAddress)
Accepts a MAC address of the form 00:aa:11:bb:22:cc, case does not matter, and returns the corresponding long, where the MAC bytes are set on the lower order bytes of the long.- Parameters:
macAddress
- in String format- Returns:
- a long containing the mac address bytes
-
toStringMacAddress
public static java.lang.String toStringMacAddress(byte[] macAddress)
-
getOperativeDPNs
public static java.util.List<org.opendaylight.yangtools.yang.common.Uint64> getOperativeDPNs(org.opendaylight.controller.md.sal.binding.api.DataBroker dataBroker)
Returns the ids of the currently operative DPNs.
-
isIpv4Address
public static java.lang.Boolean isIpv4Address(java.lang.String ipAddress)
Utility API to check if the supplied ipAddress is IPv4 Address.- Parameters:
ipAddress
- string-ified text of a possible IP address- Returns:
- true if ipAddress is an IPv4Address and false otherwise
-
isIpInSubnet
public static boolean isIpInSubnet(int ipAddress, java.lang.String subnetCidr)
Checks if a given ipAddress belongs to a specific subnet.- Parameters:
ipAddress
- The Ip Address to checksubnetCidr
- Subnet represented as string with CIDR- Returns:
- true if the ipAddress belongs to the Subnet, or false if it doesn't belong or the IpAddress string cannot be converted to an InetAddress
-
isIpAddressInRange
public static boolean isIpAddressInRange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress ipAddress, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix cidr)
Checks if IP address is within CIDR range.- Parameters:
ipAddress
- the ip addresscidr
- the cidr- Returns:
- true, if ip address is in range
-
isIpAddressInRange
public static boolean isIpAddressInRange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address ipv6Address, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix cidr)
Checks if IPv6 address is within CIDR range.- Parameters:
ipv6Address
- the IPv6 addresscidr
- the cidr- Returns:
- true, if IPv6 address is in range
-
toIpPrefix
public static java.lang.String toIpPrefix(java.lang.String ipAddress)
Utility API that returns the corresponding ipPrefix based on the ipAddress.- Parameters:
ipAddress
- string text of an IP address- Returns:
- ipAddress appended with a "/32" prefix (if IPv4), else "/128" prefix (for IPv6)
-
getEtherTypeFromIpPrefix
public static int getEtherTypeFromIpPrefix(java.lang.String ipPrefix)
Utility API that returns the corresponding etherType based on the ipPrefix address family.- Parameters:
ipPrefix
- the ipPrefix address string either IPv4 prefix or IPv6 prefix.- Returns:
- etherType of given ipPrefix.
-
-