| Class | NetAddr::Tree |
| In: |
lib/tree.rb
|
| Parent: | Object |
A class & series of methods for creating and manipulating IP-based heirarchical trees. Both IPv4 and IPv6 are supported.
A sample tree would look like:
192.168.1.0/24
192.168.1.0/26
192.168.1.0/27
192.168.1.0/28
192.168.1.16/29
192.168.1.16/30
192.168.1.24/30
192.168.1.25/32
192.168.1.28/30
192.168.1.32/27
192.168.1.64/26
192.168.1.64/27
192.168.1.128/26
192.168.1.192/26
Add a CIDR address or NetAddr::CIDR object to the tree.
Example:
tree.add!('192.168.1.0/24')
cidr = NetAddr::CIDR.create('192.168.1.0/24', :Tag => {:title => 'test net'}
tree.add!(cidr)
Returns all the ancestors of the provided CIDR addresses.
Example:
tree.ancestors('192.168.1.0/27')
Returns all the immediate children of the provided CIDR addresses.
Example:
tree.children('192.168.1.0/24')
Remove the provided CIDR address from the tree.
Example:
tree.remove!('192.168.1.0/24')
Return all descendants of the provided CIDR address.
Example:
tree.descendants('192.168.1.0/24')
Dump the contents of this tree. Example: tree.dump()
:CIDR => NetAddr::CIDR object :Depth => (depth level in tree)
Has a CIDR address already been added to the tree?
Example:
tree.exists?('192.168.1.0/24')
Fill in the missing subnets of a particular CIDR.
Example:
tree.fill_in!('192.168.1.0/24')
Find and return a CIDR from within the tree.
Example:
tree.find('192.168.1.0/24')
Find subnets that are of at least size X. Only subnets that are not themselves subnetted will be returned. :Subnet takes precedence over :IPCount Example: tree.find_space(:IPCount => 16)
:Subnet - minimum subnet size in bits for returned subnets :IPCount - minimum IP count per subnet required for returned subnets :Version - restrict results to IPvX
Find the longest matching branch of our tree to which a CIDR address belongs. Useful for performing ‘routing table’ style lookups.
Example:
tree.longest_match('192.168.1.1')
Remove all subnets of the provided CIDR address.
Example:
tree.prune!('192.168.1.0/24')
Remove the provided CIDR address, and all of its subnets from the tree.
Example:
tree.remove!('192.168.1.0/24')
Resize the provided CIDR address.
Example:
tree.resize!('192.168.1.0/24', 23)
Returns the root of the provided CIDR address.
Example:
tree.root('192.168.1.32/27')
Return list of the sibling CIDRs of the provided CIDR address.
Example:
tree.siblings('192.168.1.0/27')
Summarize all subnets of the provided CIDR address. The subnets will be
placed under the new summary address within the tree.
Example:
tree.summarize_subnets!('192.168.1.0/24')
Return list of the top-level supernets of this tree. Example: tree.supernets()