Documentation
¶
Index ¶
- Constants
- func CalculateBroadcastAddr(ipNet *net.IPNet) (string, error)
- func CalculateHostCapacity(ipNet *net.IPNet) (int, error)
- func CalculateNetworkAddr(ipNet *net.IPNet) (string, error)
- func CalculateSupernet(cidrs []string) (string, error)
- func DeriveVNetAndSubnets(baseIP net.IP, subnetSize, subnetCount int) (string, []string, net.IP, error)
- func GetBroadcastAddr(cidrBlock string) (string, error)
- func GetNetmask(cidrBlock string) (string, error)
- func GetNetworkAddr(cidrBlock string) (string, error)
- func GetPrefix(cidrBlock string) (int, error)
- func GetSizeOfHosts(cidrBlock string) (int, error)
- func IpToUint32(ip net.IP) uint32
- func NextSubnet(currentSubnetCIDR string, baseNetworkCIDR string) (string, error)
- func PreviousSubnet(currentSubnet string, baseNetworkCIDR string) (string, error)
- func SubnettingByMinimumHosts(cidrBlock string, hostsPerSubnet int) ([]string, error)
- func SubnettingByMinimumSubnetCount(cidrBlock string, minSubnets int) ([]string, error)
- func Uint32ToIP(n uint32) net.IP
- func ValidateNetwork(network Network) error
- func WhichPrivateNetworkByCidr(cidr string) (string, error)
- func WhichPrivateNetworkByIp(ip string) (string, error)
- type Network
- type NetworkConfig
- type NetworkDetails
- type NetworkInterface
- type SubnettingRequest
- type SubnettingRule
- type SubnettingRuleType
Constants ¶
const ( PrivateNetwork10Dot string = "10.0.0.0/8" PrivateNetwork172Dot string = "172.16.0.0/12" PrivateNetwork192Dot string = "192.168.0.0/16" )
Variables ¶
This section is empty.
Functions ¶
func CalculateBroadcastAddr ¶
CalculateBroadcastAddr calculates the broadcast address for a given IPNet.
func CalculateHostCapacity ¶
CalculateHostCapacity calculates the number of hosts that can be accommodated in a given IPNet.
func CalculateNetworkAddr ¶
CalculateNetworkAddr calculates the network address for a given IPNet.
func CalculateSupernet ¶ added in v0.9.10
CalculateSupernet calculates the supernet of the given CIDRs.
func DeriveVNetAndSubnets ¶ added in v0.9.10
func DeriveVNetAndSubnets(baseIP net.IP, subnetSize, subnetCount int) (string, []string, net.IP, error)
DeriveVNetAndSubnets calculates the CIDR blocks for a VNet and its subnets based on the given parameters.
func GetBroadcastAddr ¶
GetBroadcastAddr calculates the broadcast address for a given CIDR block.
func GetNetmask ¶
GetNetmask calculates the netmask for a given CIDR block.
func GetNetworkAddr ¶
GetNetworkAddr calculates the network address for a given CIDR block.
func GetSizeOfHosts ¶
GetSizeOfHosts calculates the number of hosts that can be accommodated in a given CIDR block.
func NextSubnet ¶
/////////////////////////////////////////////////////////////////////////////////// NextSubnet find and check the next subnet based on the base/parent network.
func PreviousSubnet ¶
PreviousSubnet find and check the previous subnet based on the base/parent network.
func SubnettingByMinimumHosts ¶
SubnettingByMinimumHosts divides a CIDR block into subnets based on the number of hosts required for one subnet.
func SubnettingByMinimumSubnetCount ¶
SubnettingByMinimumSubnetCount divides the CIDR block into subnets to accommodate the minimum number of subnets entered.
func ValidateNetwork ¶
/////////////////////////////////////////////////////////////////// ValidateNetwork recursively validates the network and its subnets.
func WhichPrivateNetworkByCidr ¶ added in v0.10.7
WhichPrivateNetworkByCidr identifies the private network of the given CIDR block. The private network includes 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16.
func WhichPrivateNetworkByIp ¶ added in v0.10.7
WhichPrivateNetworkByIp identifies the private network of the given IP address. The private network includes 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16.
Types ¶
type Network ¶
type Network struct {
CidrBlock string `json:"cidrBlock"`
Name string `json:"name,omitempty"`
Subnets []Network `json:"subnets,omitempty"`
}
func NewNetwork ¶
New creates a new NetworkDetails object.
func SubnettingBy ¶
func SubnettingBy(request SubnettingRequest) (Network, error)
Functions for subnetting SubnettingBy divides a CIDR block into subnets based on the given rules.
func (*Network) GetCIDRBlock ¶
func (*Network) GetSubnets ¶
type NetworkConfig ¶
type NetworkConfig struct {
NetworkConfiguration Network `json:"networkConfiguration"`
}
Models
type NetworkDetails ¶
type NetworkDetails struct {
Network
NetworkAddress string `json:"networkAddress,omitempty"`
BroadcastAddress string `json:"broadcastAddress,omitempty"`
Prefix int `json:"prefix,omitempty"`
Netmask string `json:"netmask,omitempty"`
HostCapacity int `json:"hostCapacity,omitempty"`
}
func NewNetworkDetails ¶
func NewNetworkDetails(cidrBlock string) (*NetworkDetails, error)
New creates a new NetworkDetails object.
func (*NetworkDetails) GetBroadcastAddress ¶
func (n *NetworkDetails) GetBroadcastAddress() string
func (*NetworkDetails) GetHostCapacity ¶
func (n *NetworkDetails) GetHostCapacity() int
func (*NetworkDetails) GetNetmask ¶
func (n *NetworkDetails) GetNetmask() string
func (*NetworkDetails) GetNetworkAddress ¶
func (n *NetworkDetails) GetNetworkAddress() string
Getters
func (*NetworkDetails) GetPrefix ¶
func (n *NetworkDetails) GetPrefix() int
type NetworkInterface ¶
NetworkInterface defines the methods that both Network and NetworkDetails should implement.
type SubnettingRequest ¶
type SubnettingRequest struct {
CIDRBlock string `json:"cidrBlock" example:"192.168.0.0/16"`
SubnettingRules []SubnettingRule `json:"subnettingRules"`
}
Models for subnetting
type SubnettingRule ¶
type SubnettingRule struct {
Type SubnettingRuleType `json:"type" example:"minSubnets" enum:"minSubnets,minHosts"`
Value int `json:"value" example:"2"`
}
type SubnettingRuleType ¶
type SubnettingRuleType string
/////////////////////////////////////////////////////////////////// SubnettingRuleType defines the type for subnetting rules.
const ( SubnettingRuleTypeMinSubnets SubnettingRuleType = "minSubnets" SubnettingRuleTypeMinHosts SubnettingRuleType = "minHosts" )
SubnettingRuleType constants.