Class IpamEngine
- java.lang.Object
-
- com.neotropic.kuwaiba.modules.commercial.ipam.engine.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 Summary
Constructors Constructor Description IpamEngine()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String[]
completeIPv6(String ip)
Uncompress an IPv6static String
compressIpv6(String ipAddr)
Compress a complete IPv6 Address e.g.static List<List<String>>
createIpv6Mask(int maskBits)
Creates a IPv6 mask with a given mask bitsstatic String
getIpv4Segment(String ipAddr, int segment)
Splits a given ip addressstatic String
getPartialIpAddr(String cidrSubnet)
Returns a part of the ip address to search if ther is any match with this partstatic String
getSubnetIpAddr(String cidrSubnet)
Splits the subnet from its CDIR format into the single ip addressstatic 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 networkIpstatic List<List<String>>
ipv4CreateBinaryMask(int maskBits)
Creates an IPv4 binary mask with the number of bits for the maskstatic List<String>
ipv4CreateMask(List<List<String>> binaryMask)
Creates an IPv4 binary mask with the number of bits for the maskstatic String
ipv4nextAddr(String networkIp, String broadCastIp, String ipAddr, int maskBits)
Calculate the next available IP Addressstatic List<List<String>>
ipv4ParseToBinary(String ipAddress)
Parse to binary a given ip v4 addressstatic List<SubnetDetail>
ipv4Split(String networkAddress, int currentMaskBits, String broadcastIpAddr, int bitsToSplit)
static void
ipv4SubnetCalculation(SubnetDetail subnetDetail)
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 networkIpstatic String
ipv6NextAddr(String networkIp, String broadCastIp, String ipAddr, int maskBit)
Calculate the next available IP Addressstatic void
ipv6SubnetCalculation(SubnetDetail subnetDetail)
static boolean
isCIDRFormat(String ipAddress)
Checks if a given string complies with CIDR formatstatic boolean
isHostname(String hostname)
static boolean
isIpAddress(String ipAddress)
Checks if a given string is an ipv4 or an ipv6 valid ip addressstatic boolean
isIpv4Address(String ipAddress)
Checks if a given string is an ip addressstatic boolean
isIpv6Address(String ipAddress)
Checks if a given string is an ip addressstatic 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
-
-
-
Method Detail
-
ipv4SubnetCalculation
public static void ipv4SubnetCalculation(SubnetDetail subnetDetail) throws InvalidArgumentException
- Throws:
InvalidArgumentException
-
ipv4Split
public static List<SubnetDetail> ipv4Split(String networkAddress, int currentMaskBits, String broadcastIpAddr, int bitsToSplit) throws InvalidArgumentException
- Throws:
InvalidArgumentException
-
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 IPbroadcastIp
- the broadcast IPipAddr
- 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 AddressbroadCastIp
- 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 AddressbroadCastIp
- 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 addressmaskBits
- the subnet's numbers of bitsipAddr
- 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 IPipAddr
- the possible IpmaskBits
-- 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 addresssegment
- 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
-
-