Calculates a diff of a network topology
Project description
Netdiff is an experimental Python library that provides utilities for parsing network topologies of open source dynamic routing protocols and calculating changes in these topologies.
It was developed to abstract the differences between the different JSON structures of the open source dynamic routing protocols (like OLSR and batman-advanced).
Install stable version from pypi
Install from pypi:
pip install netdiff
Install development version
Install tarball:
pip install https://github.com/ninuxorg/netdiff/tarball/master
Alternatively you can install via pip using git:
pip install -e git+git://github.com/ninuxorg/netdiff#egg=netdiff
If you want to contribute, install your cloned fork:
git clone git@github.com:<your_fork>/netdiff.git
cd netdiff
python setup.py develop
Basic Usage Example
Calculate diff of an OLSR 0.6.x topology:
from netdiff import OlsrParser
from netdiff import diff
stored = OlsrParser('./stored-olsr.json')
latest = OlsrParser('http://127.0.0.1:2006')
diff(stored, latest)
The output will be a dictionary with the following structure:
{
"added": []
"removed": []
}
NetJSON output
Netdiff parsers can return a valid NetJSON NetworkGraph object:
from netdiff import OlsrParser
olsr = OlsrParser('http://127.0.0.1:2006')
# will return a dict
olsr.json(dict=True)
# will return a JSON formatted string
print(olsr.json(indent=4))
Output:
{
"type": "NetworkGraph",
"protocol": "OLSR",
"version": "0.6.6",
"revision": "5031a799fcbe17f61d57e387bc3806de",
"metric": "ETX",
"nodes": [
{
"id": "10.150.0.3"
},
{
"id": "10.150.0.2"
},
{
"id": "10.150.0.4"
}
],
"links": [
{
"source": "10.150.0.3",
"target": "10.150.0.2",
"weight": 28334
},
{
"source": "10.150.0.3",
"target": "10.150.0.4",
"weight": 1024
}
]
}
Parsers
Parsers are classes that extend netdiff.base.BaseParser and implement a parse method which is in charge of converting a python data structure into networkx.Graph object.
Parsers have a json method which returns NetJSON.
Running tests
Clone / fork repo:
git clone git://github.com/ninuxorg/netdiff
cd diff/
Install test requirements:
pip install -r requirements-test.txt
Run tests with:
./runtests.py
Alternatively, you can use the nose command (which has a ton of available options):
nosetests
See test coverage with:
coverage run --source=netdiff runtests.py && coverage report
Contribute
Join the ninux-dev mailing list
Fork this repo and install it
Write code
Write tests for your code
Ensure all tests pass
Ensure test coverage is not under 90%
Document your changes
Send pull request
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
Built Distribution
Hashes for netdiff-0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 702b90c2a3765fbe8e5894f964f09306bbc275a3b83def58837ab1146f0d19f0 |
|
MD5 | 0b6943c10ed39503f28125fb97f9738e |
|
BLAKE2b-256 | b571aa3c78d8931c3919b152f88e72602bd6a205e93a0a6eae82f67189fa8d1a |