This tool takes a list of networks and attempts to reduce it by removing smaller networks which are already represented by larger networks and joining adjacent networks to form larger networks. The input and output represent exactly the same set of IP addresses.
Networks may be formatted as IPv4/6 CIDR or an IPv4 address and a dot-decimal subnet mask.
The algorithm works as follows:
- Sort the network list in ascending order
- Join the network and mask bytes and compare lexicographically
- Assimilate smaller networks into larger networks
- Iterate the network list from the first network to the second-to-last network
- If the next network falls within the current network, then delete the next network
- Iterate the network list from the first network to the second-to-last network
- Aggregate adjacent networks to form larger networks
- Iterate the network list from the first network to the second-to-last network
- If
- The next network decremented by one falls withint he current network, and
- The masks/prefix lengths are equal, and
- The network prefix decremented by one does not change the network address
- Decrement the prefix length of the current network by one
- Delete the next network
- Decrement the iteration index by one
- If
- Iterate the network list from the first network to the second-to-last network
Usage of ./netaggr:
-aggr
perform network aggregation (default true)
-assim
perform network assimilation (default true)
-in string
input file
-notation string
output notation: "cidr" or "dd" (default "cidr")
If the -in flag is not specified it will read from stdin. To turn off assimilation or
aggregation use the -assim=false and -aggr=false flags.
Copyright (c) 2018-2021 Eric Barkie. All rights reserved.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.