Fast prefix origin pair lookups
Project description
roa_checker
This package contains a trie of ROAs for fast prefix-origin pair lookups
Usage
from ipaddress import ip_network
from roa_checker import ROAChecker, ROARouted, ROAValidity
def test_tree():
# TODO: Break up into unit tests
trie = ROAChecker()
cidrs = [ip_network(x) for x in ["1.2.0.0/16", "1.2.3.0/24", "1.2.3.4"]]
routed_origin = 1
for cidr in cidrs:
trie.insert(cidr, routed_origin, cidr.prefixlen)
for cidr in cidrs:
assert trie.get_roa(cidr, routed_origin).prefix == cidr
validity, routed = trie.get_validity(cidr, routed_origin)
assert validity, routed == (ROAValidity.VALID, ROARouted.ROUTED,)
assert ROAValidity.is_unknown(validity) is False
assert ROAValidity.is_invalid(validity) is False
assert ROAValidity.is_valid(validity) is True
non_routed_cidrs = [ip_network(x) for x in ["2.2.0.0/16", "2.2.3.0/24", "2.2.3.4"]]
non_routed_origin = 0
for cidr in non_routed_cidrs:
trie.insert(cidr, non_routed_origin, cidr.prefixlen)
for cidr in non_routed_cidrs:
assert trie.get_roa(cidr, non_routed_origin).prefix == cidr
assert trie.get_validity(cidr, routed_origin) == (
ROAValidity.INVALID_ORIGIN,
ROARouted.NON_ROUTED,
)
validity, routed = trie.get_validity(ip_network("1.0.0.0/8"), routed_origin)
assert validity == ROAValidity.UNKNOWN
assert routed == ROARouted.UNKNOWN
validity, routed = trie.get_validity(ip_network("255.255.255.255"), routed_origin)
assert validity == ROAValidity.UNKNOWN
assert routed == ROARouted.UNKNOWN
assert ROAValidity.is_unknown(validity) is True
assert ROAValidity.is_invalid(validity) is False
assert ROAValidity.is_valid(validity) is False
validity, routed = trie.get_validity(ip_network("1.2.4.0/24"), routed_origin)
assert validity == ROAValidity.INVALID_LENGTH
assert routed == ROARouted.ROUTED
assert ROAValidity.is_unknown(validity) is False
assert ROAValidity.is_invalid(validity) is True
assert ROAValidity.is_valid(validity) is False
validity, routed = trie.get_validity(ip_network("1.2.3.0/24"), routed_origin + 1)
assert validity == ROAValidity.INVALID_ORIGIN
assert routed == ROARouted.ROUTED
assert ROAValidity.is_unknown(validity) is False
assert ROAValidity.is_invalid(validity) is True
assert ROAValidity.is_valid(validity) is False
validity, routed = trie.get_validity(ip_network("1.2.4.0/24"), routed_origin + 1)
assert validity == ROAValidity.INVALID_LENGTH_AND_ORIGIN
assert routed == ROARouted.ROUTED
assert ROAValidity.is_unknown(validity) is False
assert ROAValidity.is_invalid(validity) is True
assert ROAValidity.is_valid(validity) is False
validity, routed = trie.get_validity(ip_network("1.2.0.255"), routed_origin)
assert validity == ROAValidity.INVALID_LENGTH
assert routed == ROARouted.ROUTED
validity, routed = trie.get_validity(ip_network("1.3.0.0/16"), routed_origin)
assert validity == ROAValidity.UNKNOWN
assert routed == ROARouted.UNKNOWN
validity, routed = trie.get_validity(ip_network("1.2.0.255"), routed_origin)
assert validity == ROAValidity.INVALID_LENGTH
assert routed == ROARouted.ROUTED
Installation
Install python and pip if you have not already. Then run:
pip3 install roa_checker
This will install the package and all of it's python dependencies.
If you want to install the project for development:
git clone https://github.com/jfuruness/roa_checker.git
cd roa_checker
pip3 install -e .[test]
pre-commit install
To test the development package: Testing
Testing
After installation for development:
cd roa_checker
python3 -m pytest roa_checker
To run all tests:
tox
Development/Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
- Email me at jfuruness@gmail.com if I don't see it after a while
History
- roa_checker
- 1.1.4 Bug fix for multiple ROA case where multiple ROAs would result in the least valid ROA being selected, rather than the most valid ROA being selected. Thanks for finding this Cameron Morris!
- 1.1.3 Dependency updates
- 1.1.2 Added ROA to top level import
- 1.1.1 mypy and linter fixes
- 1.1.0 Updated test deps
- 1.0.0 Updated package structure, typing, linters, etc, made ROAValidity contains multiple invalid types
- 0.0.1 First working version
License
BSD License (see license file)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
roa_checker-1.1.4.tar.gz
(10.3 kB
view hashes)
Built Distribution
Close
Hashes for roa_checker-1.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e654908e901f11b01136635fac3a88b8dc88457b8eb6c3d9095c71f01d03006 |
|
MD5 | e5fce3f74c395afe3dd268ce4f38be3e |
|
BLAKE2b-256 | f7663f3397fe4cbe547043af9be4ec17d4154efc586def5813829c94661b421a |