Class 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.mdsal.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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 of MDSALUtil.longToIp(long, long) not handling IP address greater than byte.
        Parameters:
        ipAddress - IP Address to be converted to String
        mask - 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.
        Parameters:
        macAddress - The MAC
        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.mdsal.binding.api.DataBroker dataBroker)
                                                                                              throws java.util.concurrent.ExecutionException,
                                                                                                     java.lang.InterruptedException
        Returns the ids of the currently operative DPNs.
        Parameters:
        dataBroker - instance of databroker
        Returns:
        List of DPNs
        Throws:
        java.util.concurrent.ExecutionException - in case of a technical (!) error while reading
        java.lang.InterruptedException - if the transaction is interrupted
      • 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 check
        subnetCidr - 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 address
        cidr - 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 address
        cidr - 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.