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 Instance Methods Concrete Methods Modifier and Type Method Description static String[]completeIPv6(String ip)Uncompress an IPv6static StringcompressIpv6(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 StringgetIpv4Completed(String ipAddr)Splits a given ip addressstatic StringgetIpv4Segment(String ipAddr, int segment)Splits a given ip addressstatic StringgetPartialSubnetIpAddr(String cidrSubnet, int version)Returns a part of the ip address to search if ther is any match with this partstatic StringgetSubnetIpAddr(String cidrSubnet)Splits the subnet from its CDIR format into the single ip addressstatic booleanipv4addrBelongsToSubnet(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 Stringipv4nextAddr(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 voidipv4SubnetCalculation(SubnetDetail subnetDetail)booleanipv4SubnetOverlaps(String newNetworkIpAddr, String newBoradcstIpAddr, SubnetDetail subnetContainer)Checks if the broadcast ip and the network ip of a given new subnet is inside of other subnetstatic booleanipv6AddrBelongsToSubnet(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 Stringipv6NextAddr(String networkIp, String broadCastIp, String ipAddr, int maskBit)Calculate the next available IP Addressstatic List<SubnetDetail>ipv6Split(String networkAddress, int currentMaskBits, String broadcastIpAddr, int bitsToSplit)static voidipv6SubnetCalculation(SubnetDetail subnetDetail)static booleanipv6SubnetsOvelaps(String possibleSubnetContainerCidr, String possibleContainedSubnetNetworkAddress, String possibleContainedSubnetBroadcastAddress)Checks if the broadcast ip and the network ip of a given new subnet is inside of other subnetstatic booleanisCIDRFormat(String ipAddress)Checks if a given string complies with CIDR formatstatic booleanisHostname(String hostname)static booleanisIpAddress(String ipAddress)Checks if a given string is an ipv4 or an ipv6 valid ip addressstatic booleanisIpv4Address(String ipAddress)Checks if a given string is an ip addressstatic booleanisIpv6Address(String ipAddress)Checks if a given string is an ip addressstatic booleanitContains(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
-
ipv6Split
public static List<SubnetDetail> ipv6Split(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:
binaryMask-- 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:
networkIp- the subnet's network IP AddressipAddr- the IP AddressbroadCastIp- the subnet's broadcast IP AddressmaskBits- the subnet mask bits- 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:
networkIp- the subnet's network IP AddressipAddr- the IP AddressbroadCastIp- the subnet's broadcast IP AddressmaskBit- the subnet mask bits- 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
-
getIpv4Completed
public static String getIpv4Completed(String ipAddr)
Splits a given ip address- Parameters:
ipAddr- the given ip address- Returns:
- the segment of the ip address
-
ipv4SubnetOverlaps
public boolean ipv4SubnetOverlaps(String newNetworkIpAddr, String newBoradcstIpAddr, SubnetDetail subnetContainer) throws InvalidArgumentException
Checks if the broadcast ip and the network ip of a given new subnet is inside of other subnet- Parameters:
newNetworkIpAddr-newBoradcstIpAddr-subnetContainer- the alleged subnet that could contains the new subnet- Returns:
- true if contains completely the new subnet
- Throws:
InvalidArgumentException
-
ipv6SubnetsOvelaps
public static boolean ipv6SubnetsOvelaps(String possibleSubnetContainerCidr, String possibleContainedSubnetNetworkAddress, String possibleContainedSubnetBroadcastAddress)
Checks if the broadcast ip and the network ip of a given new subnet is inside of other subnet- Parameters:
newSubnet- a given new subnet in CIDR formatallegedSubnetContainer- the alleged subnet that could contains the new subnet- Returns:
- true if contains completely the new subnet
-
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
-
-