Code Monkey home page Code Monkey logo

aggregate6's Introduction

Requirements Status Coverage Status

aggregate6

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

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, 2001:67c:208c:10::/64 would be removed if 2001:67c:208c::/48 was also supplied.

The second optimisation identifies adjacent prefixes that can be combined under a single, shorter-length prefix. For example, 2001:67c:208c::/48 and 2001:67c:208d::/48 can be combined into the single prefix 2001:67c:208c::/47.

The above optimalisation steps are often useful in context of compressing firewall rules or BGP prefix-list filters.

The following command line options are available:

	-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

Installation

OpenBSD:

$ doas pkg_add aggregate6

CentOS/RHEL/Rocky:

$ yum install epel-release
$ yum install aggregate6

Fedora:

$ dnf install 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 IPv4 and IPv6 prefixes as arguments.

$ # via STDIN
$ cat file_with_list_of_prefixes | aggregate6
   ... output ...

$ # with a filename as argument
$ aggregate6 file_with_list_of_prefixes [ ... optional_other_prefix_lists ]
   ... output ...

$ # Whitespace separated works too
$ echo 2001:67c:208c::/48 2000::/3 | aggregate6
2000::/3

$ # 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

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.

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

Bugs

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

Author

Job Snijders [email protected]

aggregate6's People

Contributors

afpd avatar devicenull avatar habbie avatar job avatar kmosiejczuk avatar movatica avatar oleholmnielsen avatar robert-scheck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aggregate6's Issues

Fails to parse ASCII strings (expects unicode)

$ echo 2620:0:1c00::/40 | aggregate6
Traceback (most recent call last):
File "/usr/local/bin/aggregate6", line 9, in
load_entry_point('aggregate6==0.7', 'console_scripts', 'aggregate6')()
File "/usr/local/lib/python2.7/dist-packages/aggregate6/cli.py", line 107, in main
prefix_obj = ip_network(prefix)
File "/usr/lib/python2.7/dist-packages/ipaddress.py", line 199, in ip_network
' a unicode object?' % address)
ipaddress.AddressValueError: '3236:3230:3a30:3a31:6330:303a:3a2f:3430/128' does not appear to be an IPv4 or IPv6 network. Did you pass in a bytes (str in Python 2) instead of a unicode object?

question regarding -t

Great tool. Very helpful. Can you explain what the -t option does? I have tried using it multiple times with and without it and it returns the same output. Just confused on what you mean by "truncate IP/mask to network/mask"?

thanks,

Suggestion: calculating aggregated prefix list with "holes"/exceptions

In case you're taking feature requests, it would be useful to generate an aggregated prefix list but with some sub-prefixes removed:

Mock-up to explain what I mean:

$ echo 192.0.2.0/25 192.0.2.128/26 192.0.2.192/27 192.0.2.224/27 > prefixes.txt
$ echo 192.0.2.3/32 192.0.2.128/30 > exceptions.txt
$ aggregate6 -e exceptions.txt prefixes.txt
192.0.2.0/31
192.0.2.2/32
192.0.2.4/30
192.0.2.8/29
192.0.2.16/28
192.0.2.32/27
192.0.2.64/26
192.0.2.132/30
192.0.2.136/29
192.0.2.144/28
192.0.2.160/27
192.0.2.192/26

If on the other hand you're not taking feature requests, feel free to close this issue. In any case, thank you for this very useful tool!

pip install failed

> sudo -H pip install aggregate6
Collecting aggregate6
  Downloading aggregate6-0.6.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/tmp/pip-build-JFgKf2/aggregate6/setup.py", line 52, in <module>
        reqs = [str(ir.req) for ir in install_reqs]
      File "/Library/Python/2.7/site-packages/pip/req/req_file.py", line 79, in parse_requirements
        "parse_requirements() missing 1 required keyword argument: "
    TypeError: parse_requirements() missing 1 required keyword argument: 'session'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-JFgKf2/aggregate6/
> pip --version
pip 8.1.1 from /Library/Python/2.7/site-packages (python 2.7)

This is on Mac OS X 10.11.3.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.