Unique Smallest Routable Entries Monitor (USREsMonitor)
This library is inspired by an issue opened by Thomas Mangin on the repository of [InvalidRoutesReporter](https://github.com/pierky/invalidroutesreporter): https://github.com/pierky/invalidroutesreporter/issues/1
Given a set (or stream) of IP prefixes, this library calculates the unique smallest routable entries (SREs) covered by them.
De-duplication of overlapping prefixes is performed. SREs are calculated on the basis of a target prefix length that can be set on input.
Prefixes can be added and removed as they come (for example from a BGP session) and the resultant set of unique SREs is computed accordingly.
Example:
` >>> from pierky.usres_monitor import UniqueSmallestRoutableEntriesMonitor >>> monitor = UniqueSmallestRoutableEntriesMonitor(target_prefix_len4=24) >>> monitor.add_net("192.168.0.0/16") >>> ["first: {first_ip}, last: {last_ip}, cnt: {cnt}".format(**prefix) for prefix in monitor.get_prefixes(4)] ['first: 192.168.0.0, last: 192.168.255.0, cnt: 256'] >>> monitor.get_count(4) 256 `
So, 192.168.0.0/16 contains 256 /24 subnets.
Now, add a prefix that is already covered by the previous one:
` >>> monitor.add_net("192.168.0.0/21") >>> ["first: {first_ip}, last: {last_ip}, cnt: {cnt}".format(**prefix) for prefix in monitor.get_prefixes(4)] ['first: 192.168.0.0, last: 192.168.255.0, cnt: 256'] `
Nothing changed. Add a prefix that covers the 2 already added before:
` >>> monitor.add_net("192.0.0.0/8") >>> ["first: {first_ip}, last: {last_ip}, cnt: {cnt}".format(**prefix) for prefix in monitor.get_prefixes(4)] ['first: 192.0.0.0, last: 192.255.255.0, cnt: 65536'] `
Here it is, 192.0.0.0/8 covers both 192.168.0.0/16 and 192.168.0.0/21 and contains 65536 /24 subnets.
Now remove the two larger prefixes:
` >>> monitor.del_net("192.0.0.0/8") >>> monitor.del_net("192.168.0.0/16") >>> ["first: {first_ip}, last: {last_ip}, cnt: {cnt}".format(**prefix) for prefix in monitor.get_prefixes(4)] ['first: 192.168.0.0, last: 192.168.7.0, cnt: 8'] `
Only 192.168.0.0/21 remains, with its 8 /24 subnets.
Add now a second prefix:
` >>> monitor.add_net("192.168.8.0/21") >>> ["first: {first_ip}, last: {last_ip}, cnt: {cnt}".format(**prefix) for prefix in monitor.get_prefixes(4)] ['first: 192.168.0.0, last: 192.168.7.0, cnt: 8', 'first: 192.168.8.0, last: 192.168.15.0, cnt: 8'] >>> monitor.get_count(4) 16 `
Two prefixes are printed, each one covering 8 SREs, for a total of 16 SREs.
Both IPv4 and IPv6 can be used, also simultaneously with the same monitor object:
` >>> from pierky.usres_monitor import UniqueSmallestRoutableEntriesMonitor >>> monitor = UniqueSmallestRoutableEntriesMonitor(target_prefix_len4=24, target_prefix_len6=56) >>> monitor.add_net("192.168.0.0/16") >>> monitor.add_net("10.0.0.0/8") >>> monitor.add_net("2001:db8:aaaa::/48") >>> ["first: {first_ip}, last: {last_ip}, cnt: {cnt}".format(**prefix) for prefix in monitor.get_prefixes(4)] ['first: 192.168.0.0, last: 192.168.255.0, cnt: 256', 'first: 10.0.0.0, last: 10.255.255.0, cnt: 65536'] >>> ["first: {first_ip}, last: {last_ip}, cnt: {cnt}".format(**prefix) for prefix in monitor.get_prefixes(6)] ['first: 2001:db8:aaaa::, last: 2001:db8:aaaa:ff00::, cnt: 256'] >>> monitor.get_count(4) 65792 >>> monitor.get_count(6) 256 `
Installation
` pip install usresmonitor `
Optionally, the [apsw](https://github.com/rogerbinns/apsw) SQLite library can be installed; in that case, it will be preferred during the setup of the backend database used by USREsMonitor.
Future work
Add some examples of how this library can be used (ExaBGP integration).
Status
First-release, looking for testers and reviewers.
Bug? Issues?
But also suggestions? New ideas?
Please create an issue on GitHub or drop me a message.
Change log
v0.1.1
Fix: better exception handling of duplicate prefixes
v0.1.0
First release.
Metadata
Release files for usresmonitor 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| usresmonitor-0.1.1.tar.gz | 21.0 kB | Without provenance | Details for usresmonitor-0.1.1.tar.gz |
Release files / usresmonitor-0.1.1.tar.gz
| Download URL | usresmonitor-0.1.1.tar.gz |
|---|---|
| Size | 21.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6159380c687b9cd69fc31b9552ea36f0c0207370f07601ebafd25adcb75461f
|
|
BLAKE2b-256 checksum How to use checksums |
c31dcefd3bf3b974aecb7de076a754db8e5241c2d48b7bbb21a536a2865034d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for usresmonitor 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.