Skip to content

Commit

Permalink
Update docs & add verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
job committed Dec 4, 2017
1 parent 349c4db commit ffa79cf
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
all:
cp README.md aggregate6.7.ronn
ronn24 -r --pipe aggregate6.7.ronn > aggregate6.7
ronn -r --pipe aggregate6.7.ronn > aggregate6.7
rm aggregate6.7.ronn

clean:
Expand Down
43 changes: 29 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ aggregate6

aggregate6 will compress an unsorted list of IP prefixes (both IPv4 and IPv6).

DESCRIPTION
Description
-----------

Takes a list of IPv6 prefixes in conventional format on stdin, and performs two
Expand All @@ -25,18 +25,34 @@ a single, shorter-length prefix. For example, `2001:67c:208c::/48` and
The above optimalisation steps are often useful in context of compressing firewall
rules or BGP prefix-list filters.

INSTALLATION
------------
The following command line options are available:

```
$ pip install aggregate6
-4 Only output IPv4 prefixes
-6 Only output IPv6 prefixes
-h, --help show help message and exit
-m N Sets the maximum prefix length for entries read, longer prefixes will be discarded prior to processing
-t truncate IP/mask to network/mask
-v Display verbose information about the optimisations
-V Display aggregate6 version
```

CLI USAGE
Installation
------------

OpenBSD 6.3:

`$ doas pkg_add aggregate6`

Other platforms:

`$ pip3 install aggregate6`

CLI Usage
---------

Either provide the list of IPv4 and IPv6 prefixes on STDIN, or give filenames
containing lists of IPv6 prefixes as arguments.
containing lists of IPv4 and IPv6 prefixes as arguments.

```
$ # via STDIN
Expand All @@ -55,29 +71,28 @@ $ # You can combine IPv4 and IPv6
$ echo 10.0.0.0/16 10.0.0.0/24 2000::/3 | aggregate6
10.0.0.0/16
2000::/3
$ # Or display only a specific AFI
$ echo 10.0.0.0/16 10.0.0.0/24 2000::/3 | aggregate6 -4
10.0.0.0/16
```
See `aggregate6 -h` for a full list of options.

LIBRARY USAGE
Library Usage
-------------

Aggregate6 can be used in your own pyp/python2/python3 project as python module.
Currently there is just one simple public function: `aggregate()` which takes a
list as parameter.

```
>>> import from aggregate6 import aggregate
>>> aggregate(["10.0.0.0/8", "10.0.0.0/24"])
['10.0.0.0/8']
>>>
```

BUGS
Bugs
----

Please report bugs at https://github.com/job/aggregate6/issues

AUTHOR
Author
------

Job Snijders <job@instituut.net>
49 changes: 35 additions & 14 deletions aggregate6.7
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.TH "AGGREGATE6" "7" "December 2017" "" ""
aggregate6 will compress an unsorted list of IP prefixes (both IPv4 and IPv6)\.
.
.SH "DESCRIPTION"
.SH "Description"
Takes a list of IPv6 prefixes in conventional format on stdin, and performs two optimisations to attempt to reduce the length of the prefix list\. The first optimisation is to remove any supplied prefixes which are superfluous because they are already included in another supplied prefix\. For example, \fB2001:67c:208c:10::/64\fR would be removed if \fB2001:67c:208c::/48\fR was also supplied\.
.
.P
Expand All @@ -13,16 +13,39 @@ The second optimisation identifies adjacent prefixes that can be combined under
.P
The above optimalisation steps are often useful in context of compressing firewall rules or BGP prefix\-list filters\.
.
.SH "INSTALLATION"
.P
The following command line options are available:
.
.IP "" 4
.
.nf

$ pip install aggregate6
\-4 Only output IPv4 prefixes
\-6 Only output IPv6 prefixes
\-h, \-\-help show help message and exit
\-m N Sets the maximum prefix length for entries read, longer prefixes will be discarded prior to processing
\-t truncate IP/mask to network/mask
\-v Display verbose information about the optimisations
\-V Display aggregate6 version
.
.fi
.
.SH "CLI USAGE"
Either provide the list of IPv4 and IPv6 prefixes on STDIN, or give filenames containing lists of IPv6 prefixes as arguments\.
.IP "" 0
.
.SH "Installation"
OpenBSD 6\.3:
.
.P
\fB$ doas pkg_add aggregate6\fR
.
.P
Other platforms:
.
.P
\fB$ pip3 install aggregate6\fR
.
.SH "CLI Usage"
Either provide the list of IPv4 and IPv6 prefixes on STDIN, or give filenames containing lists of IPv4 and IPv6 prefixes as arguments\.
.
.IP "" 4
.
Expand All @@ -44,19 +67,15 @@ $ # You can combine IPv4 and IPv6
$ echo 10\.0\.0\.0/16 10\.0\.0\.0/24 2000::/3 | aggregate6
10\.0\.0\.0/16
2000::/3

$ # Or display only a specific AFI
$ echo 10\.0\.0\.0/16 10\.0\.0\.0/24 2000::/3 | aggregate6 \-4
10\.0\.0\.0/16
.
.fi
.
.IP "" 0
.
.P
See \fBaggregate6 \-h\fR for a full list of options\.
.SH "Library Usage"
Aggregate6 can be used in your own pyp/python2/python3 project as python module\. Currently there is just one simple public function: \fBaggregate()\fR which takes a list as parameter\.
.
.SH "LIBRARY USAGE"
.IP "" 4
.
.nf

Expand All @@ -67,8 +86,10 @@ See \fBaggregate6 \-h\fR for a full list of options\.
.
.fi
.
.SH "BUGS"
.IP "" 0
.
.SH "Bugs"
Please report bugs at https://github\.com/job/aggregate6/issues
.
.SH "AUTHOR"
.SH "Author"
Job Snijders \fIjob@instituut\.net\fR
18 changes: 15 additions & 3 deletions aggregate6/aggregate6.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def parse_args(args):
Project website: https://github.com/job/aggregate6
""", formatter_class=argparse.RawTextHelpFormatter)
p.add_argument('-v', dest='verbose', action='store_true',
help="Display verbose information about the optimisations")
help="Display verbose information about the optimisations.")
p.add_argument('-t', dest='truncate', action='store_true',
help="truncate IP/mask to network/mask")
p.add_argument('-m', dest='max_length', metavar='N', type=int,
Expand Down Expand Up @@ -173,5 +173,17 @@ def main():
elif not args.ipv4_only and not args.ipv6_only:
p_tree.add(prefix)

for prefix in aggregate_tree(p_tree).prefixes():
print(prefix)
if args.verbose:
input_list = p_tree.prefixes()
output_list = aggregate_tree(p_tree).prefixes()
for p in sorted(set(input_list + output_list)):
if p in input_list and p not in output_list:
print("- ", end='')
elif p in output_list and p not in input_list:
print("+ ", end='')
else:
print(" ", end='')
print(p)
else:
for prefix in aggregate_tree(p_tree).prefixes():
print(prefix)

0 comments on commit ffa79cf

Please sign in to comment.