Skip to main content

Calculates a diff of a network topology

Project description

https://travis-ci.org/ninuxorg/netdiff.png https://coveralls.io/repos/ninuxorg/netdiff/badge.png Code Health Requirements Status https://badge.fury.io/py/netdiff.png https://img.shields.io/pypi/dm/netdiff.svg

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('telnet://127.0.0.1:9090')
diff(stored, latest)

The output will be a dictionary with the following structure:

{
    "added": []
    "removed": []
}

In alternative, you can use the subtraction operator:

from netdiff import OlsrParser
from netdiff import diff

stored = OlsrParser('./stored-olsr.json')
latest = OlsrParser('telnet://127.0.0.1:9090')
latest - stored

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 also have a json method which returns valid NetJSON output.

The available parsers are:

Parsers must be initialized with a string which can represent one of the following:

  • path to JSON file

  • HTTP url to JSON file

  • telnet url to JSON file

  • JSON formatted string

  • python dictionary representing a JSON structure

Local file example:

from netdiff import BatmanParser
BatmanParser('./my-stored-topology.json')

HTTP example:

from netdiff import NetJsonParser
url = 'https://raw.githubusercontent.com/interop-dev/json-for-networks/master/examples/network-graph.json'
NetJsonParser(url)

NetJSON output

Netdiff parsers can return a valid NetJSON NetworkGraph object:

from netdiff import OlsrParser

olsr = OlsrParser('telnet://127.0.0.1:9090')

# 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": 2.4
        },
        {
            "source": "10.150.0.3",
            "target": "10.150.0.4",
            "weight": 1.0
        }
    ]
}

Running tests

Install your forked repo:

git clone git://github.com/<your_fork>/netdiff
cd netdiff/
python setup.py develop

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
nosetests tests.olsr  # run only olsr related tests
nosetests tests/olsr  # variant form of the previous command
nosetests tests.olsr.tests:TestOlsrParser  # variant form of the previous command
nosetests tests.olsr.tests:TestOlsrParser.test_parse  # run specific test

See test coverage with:

coverage run --source=netdiff runtests.py && coverage report

Contribute

  1. Join the ninux-dev mailing list

  2. Fork this repo and install it

  3. Follow PEP8, Style Guide for Python Code

  4. Write code

  5. Write tests for your code

  6. Ensure all tests pass

  7. Ensure test coverage is not under 90%

  8. Document your changes

  9. Send pull request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netdiff-0.3.1.tar.gz (66.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

netdiff-0.3.1-py2.py3-none-any.whl (13.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file netdiff-0.3.1.tar.gz.

File metadata

  • Download URL: netdiff-0.3.1.tar.gz
  • Upload date:
  • Size: 66.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for netdiff-0.3.1.tar.gz
Algorithm Hash digest
SHA256 1696a3aff4c2848d295f386864f83876e5a6cf478cbbe369d3248c0727c7f73f
MD5 995d13ff741670f1082e6b02ace267df
BLAKE2b-256 01d5721eece6fc6137c62de4b756bf43ebfd0b29fce6e847c230cf100636068a

See more details on using hashes here.

File details

Details for the file netdiff-0.3.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for netdiff-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b4a45e61cb3cbeed5270a0aca2446cb0970c0bddb7d625c8cb5d4abb21dc7645
MD5 3a13ecbbe42ef2be34627cc3621434d5
BLAKE2b-256 a037ad206245e5173bbd7a19b5f5ef93dda7346550f9174b1bce5696377bed99

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page