Skip to main content

Take BGP AS PATHs and generate an interactive javascript graph using NetJSON

Project description

aspath_graph converts raw ASPATHs to NetJSON Graph

Do what the fuck you want

Stylized example

NetJSON is a series of JSON schema for defining networks, NetJSON Graph being specific to defining how nodes interconnect. “aspath_graph” uses this to represent BGP autonomous systems as ‘nodes’ and how they connect from the perspective of INPUT

This project aims to make it easy to go from BGP AS PATHs in their raw form to something NetJSON Graph understands. This makes it easy to add properties to nodes based on their label or ASN and display/handle them differently on the frontend in CSS/JS/HTML.

Quickstart

For a really quick start, clone the repo and check out the examples folder. It has a paths text-file for how I saw PATHs to 1.0.0.0/12+ at the time.

For your own data, there are two input methods currently:

  1. netconf to Junos devices

  2. Plain text file of ASPATHs

Good news is that the second one is very flexible. Here are a few ways you can create it:

birdc 'show route table <name> all'|grep BGP\.as_path|egrep -o '[0-9]+ [0-9 ]+' > aspaths.txt
ssh junosrtr "show route protocol bgp | match \"AS path\"" | sed -e 's/.*AS path: //g' > aspaths.txt

Embedding In Existing Webpages

NetJSON Graph is pretty simple to embed into existing pages and theme, thus so is getting your AS nodes there. I’ll refer you to the README and docs for the main project, but below is a small example.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link href="https://rawgit.com/interop-dev/netjsongraph.js/master/src/netjsongraph.css" rel="stylesheet">
    <link href="https://rawgit.com/interop-dev/netjsongraph.js/master/src/netjsongraph-theme.css" rel="stylesheet">
</head>
<body>
<div id="wrap">
    <div class="nav">
        <!-- Nav stuff... -->
    </div>
    <div class="main-container"> <!-- Imagine this your usual main container -->

        <!-- You probably have several things down here... -->
        <div id="legend">
            <!-- You can even add a legend, there's an example on the main project site -->
        </div>
        <div class="bgp-ases"></div>

    </div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.12/d3.min.js"></script>
<script src="https://rawgit.com/interop-dev/netjsongraph.js/master/src/netjsongraph.js"></script>
<script>
    d3.netJsonGraph(
        "example.json", {
            el: '.bgp-ases',
            metadata: false,
            charge: -250,
            labelDy: '-1.18em',
        }
    );
</script>
</body>
</html>

Usage

$ aspath_graph --help    Usage: aspath_graph [OPTIONS] INPUT

Options:
  -v, --version                   Show the version and exit.
  -m, --mode [junos-netconf|txt]  Mode to use
  -o, --output FILENAME           Output file
  --asdot                         Whether to add ASDOT notation
  --ownas TEXT                    Apply perspective of own AS at the beginning
                                  of PATHS
  --runserver                     Run local server on 8000
  --user TEXT                     Only used for relevant modes
  --nopassword                    If using a login mode, this will enable
                                  public key auth
  --yaml FILENAME                 YAML for mapping and ignoring ASes
  --pprint                        Pretty print JSON
  -h, --help                      Show this message and exit.

INPUT can either be a device or file depending on value of MODE. This defaults to a file. (txt)

OUTPUT can be ‘-’ to send results to STDOUT.

If not passing ‘–nopassword’, you will be prompted for a password for the relevant modes.

When using “–asdot” to provide ASDOT notation, the raw ASPLAIN will also be provided on the node - just under the “raw” attribute.

YAML can be formatted as such: (Note that “ignore” must ONLY be ASPLAIN)

label_map:
    65001: SFO
    65002: ORD
    65003: NYC
    65003.1: NYC-R1
    65003.2: NYC-R2

ignore:
    - 7224
    - 9059

By default, ASDOT will be labeled according to the firsthalf. Eg, if 65001 is configured to be labeled as DFW, 65001.211 will appear as DFW-R21. This assumes your ToR ASN is your spine ASN + (racknumber*10+1) - to disable this simply set APG_ASDOT_RAW to true/yes/anything.

Any of the supported options can be passed via ENV by upping the case, replacing ‘-’ with ‘_’, and prefixing with ‘APG’. Eg, ‘APG_MODE’

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

aspath_graph-1.3.tar.gz (66.8 kB view details)

Uploaded Source

File details

Details for the file aspath_graph-1.3.tar.gz.

File metadata

  • Download URL: aspath_graph-1.3.tar.gz
  • Upload date:
  • Size: 66.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aspath_graph-1.3.tar.gz
Algorithm Hash digest
SHA256 1b5c492a3633f1d2809a06345de27a77a3f9decb00b52a514d284b47198ef0bb
MD5 84e13c6b8a5be7f07b1d317f15c4d252
BLAKE2b-256 3ec6c37ab2a18174e3faa9d47f0ebe6eca8c1265e5385fcee4f3a0dec97e2e2f

See more details on using hashes here.

Supported by

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