Class IpamEngine


  • public class IpamEngine
    extends Object
    Make all the validations an calculate the possible subnets for IPv4 and IPv6 Addresses
    Author:
    Adrian Martinez Molina <adrian.martinez@kuwaiba.org>
    • Constructor Detail

      • IpamEngine

        public IpamEngine()
    • Method Detail

      • ipv4ParseToBinary

        public static List<List<String>> ipv4ParseToBinary​(String ipAddress)
        Parse to binary a given ip v4 address
        Parameters:
        ipAddress - the given ip v4 address
        Returns:
      • ipv4CreateBinaryMask

        public static List<List<String>> ipv4CreateBinaryMask​(int maskBits)
        Creates an IPv4 binary mask with the number of bits for the mask
        Parameters:
        maskBits - number of bits
        Returns:
        a list fo list with the IP mask
      • ipv4CreateMask

        public static List<String> ipv4CreateMask​(List<List<String>> binaryMask)
        Creates an IPv4 binary mask with the number of bits for the mask
        Parameters:
        maskBits - number of bits
        Returns:
        a list fo list with the IP mask
      • createIpv6Mask

        public static List<List<String>> createIpv6Mask​(int maskBits)
        Creates a IPv6 mask with a given mask bits
        Parameters:
        maskBits - number of bit for the mask
        Returns:
        the mask
      • completeIPv6

        public static String[] completeIPv6​(String ip)
        Uncompress an IPv6
        Parameters:
        ip - a compressed IP v6 Address
        Returns:
        a complete IPv6
      • ipv6SubnetCalculation

        public static void ipv6SubnetCalculation​(SubnetDetail subnetDetail)
      • itContains

        public static boolean itContains​(String netwrokIp,
                                         String broadcastIp,
                                         String ipAddr)
        calculate if a given networkIp for a subnet is inside of another subnet taking as parameters the broadcastIp an de networkIp
        Parameters:
        netwrokIp - the network IP
        broadcastIp - the broadcast IP
        ipAddr - the possible Ip
        Returns:
        true if it contained, false if not
      • isIpAddress

        public static boolean isIpAddress​(String ipAddress)
        Checks if a given string is an ipv4 or an ipv6 valid ip address
        Parameters:
        ipAddress - a String with the possible ip address
        Returns:
        true if the string is an ip address
      • isIpv4Address

        public static boolean isIpv4Address​(String ipAddress)
        Checks if a given string is an ip address
        Parameters:
        ipAddress - a possible ip address
        Returns:
        true if the string is an ip address
      • isIpv6Address

        public static boolean isIpv6Address​(String ipAddress)
        Checks if a given string is an ip address
        Parameters:
        ipAddress - a possible ip address
        Returns:
        true if the string is an ip address
      • isCIDRFormat

        public static boolean isCIDRFormat​(String ipAddress)
        Checks if a given string complies with CIDR format
        Parameters:
        ipAddress - a possible string with CIDR format: ipAddres / mask bits
        Returns:
        true if the string has de CIDR format
      • isHostname

        public static boolean isHostname​(String hostname)
      • compressIpv6

        public static String compressIpv6​(String ipAddr)
        Compress a complete IPv6 Address e.g. compress 2abf:aaaa:00ff:0000:0000:0000:0:0 into 2abf:aaaa:ff::
        Parameters:
        ipAddr - the IP v6 Address
        Returns:
        a compressed IPv6 address
      • ipv4nextAddr

        public static String ipv4nextAddr​(String networkIp,
                                          String broadCastIp,
                                          String ipAddr,
                                          int maskBits)
        Calculate the next available IP Address
        Parameters:
        ipAddr - the IP Address
        broadCastIp - the subnet's broadcast IP Address
        Returns:
        the next available IP Address
      • ipv6NextAddr

        public static String ipv6NextAddr​(String networkIp,
                                          String broadCastIp,
                                          String ipAddr,
                                          int maskBit)
        Calculate the next available IP Address
        Parameters:
        ipAddr - the IP Address
        broadCastIp - the subnet's broadcast IP Address
        Returns:
        the next available IP Address
      • ipv4addrBelongsToSubnet

        public static boolean ipv4addrBelongsToSubnet​(String networkIp,
                                                      String ipAddr,
                                                      int maskBits)
        calculate if a given networkIp for a subnet is inside of another subnet taking as parameters the networkIp
        Parameters:
        networkIp - the subnet's network ip address
        maskBits - the subnet's numbers of bits
        ipAddr - the possible ip address
        Returns:
        true if it contained, false if not
      • ipv6AddrBelongsToSubnet

        public static boolean ipv6AddrBelongsToSubnet​(String networkIp,
                                                      String ipAddr,
                                                      int maskBits)
        Calculate if a given IP for a subnet is inside of another subnet taking as parameters the broadcastIp an de networkIp
        Parameters:
        networkIp - the network IP
        ipAddr - the possible Ip
        maskBits -
        Returns:
        true if it contained, false if not
      • getIpv4Segment

        public static String getIpv4Segment​(String ipAddr,
                                            int segment)
        Splits a given ip address
        Parameters:
        ipAddr - the given ip address
        segment - the wished segment 0 or 1 or 2 or 3
        Returns:
        the segment of the ip address
      • getSubnetIpAddr

        public static String getSubnetIpAddr​(String cidrSubnet)
        Splits the subnet from its CDIR format into the single ip address
        Parameters:
        cidrSubnet - an String that contains the subnet in CDIR format networkAddress/Mask bits
        Returns:
        the subnet without mask
      • getPartialIpAddr

        public static String getPartialIpAddr​(String cidrSubnet)
        Returns a part of the ip address to search if ther is any match with this part
        Parameters:
        cidrSubnet - the subnet address in cidr format
        Returns:
        a part of the subnet address