Giter VIP home page Giter VIP logo

hyperglass-frr's Introduction

This repository is no longer maintained

hyperglass-frr was originally created for hyperglass v0, which is being migrated to hyperglass v1.0. If you're using FRR with hyperglass v1.0, please use hyperglass-agent.

hyperglass-frr

hyperglass-frr is a restful API for the Free Range Routing stack, for use by hyperglass. hyperglass-frr ingests a HTTP POST request with JSON data and constructs 1 of 5 shell commands to run based on the passed parameters. For example:

{
  "query_type": "ping",
  "afi": "ipv4",
  "source": "192.0.2.1",
  "target": "1.1.1.1"
}

Would construct (by default) ping -4 -c 5 -I 192.0.2.1 1.1.1.1, execute the command, and return the output as a string. For BGP commands, FRRouting's vtysh is used to get the output. For example:

{
  "query_type": "bgp_route",
  "afi": "ipv6",
  "target": "2606:4700:4700::/48"
}

Would construct (by default) vtysh -u -c "show bgp ipv6 unicast 2606:4700:4700::/48", execute the command, and return the output as a string.

Installation

Currently, hyperglass-frr has only been tested on Ubuntu Server 18.04. A sample systemd service file is included to run hyperglass-frr as a service.

Clone the repository

$ cd /opt/
$ git clone https://github.com/checktheroads/hyperglass-frr

Install requirements

$ cd /opt/hyperglass-frr/
$ pip3 install -r requirements.txt

Create service account

# useradd hyperglass-frr
# usermod -a -G frrvty hyperglass-frr

Install systemd service

# cp /opt/hyperglass-frr/hyperglass-frr.service.example /etc/systemd/system/hyperglass-frr.service
# systemctl daemon-reload
# systemctl enable hyperglass-frr

Generate API Key

$ cd /opt/hyperglass-frr
$ python3 manage.py generate-key
Your API Key is: B3K1ckWUpwNyFU1F
Your Key Hash is: $pbkdf2-sha256$29000$9T5njNFaS6lVag1B6H2vFQ$mLEbQD5kOAgjfZZ1zEVlrke6wE8vBEHzK.zI.7MOAVo

Copy the API Key, in this example B3K1ckWUpwNyFU1F and add it to configuration.toml:

[api]
# listen_addr = "*"
# port = 8080
key = "B3K1ckWUpwNyFU1F"

If needed, you can uncomment the listen_addr or port varibales if you need to define a specific listen address or TCP port for hyperglass-frr to run on. For exmaple:

[api]
listen_addr = "10.0.1.1"
port = 8001
key = "B3K1ckWUpwNyFU1F"

In hyperglass, configure devices.toml to use the Key Hash (in this example $pbkdf2-sha256$29000$9T5njNFaS6lVag1B6H2vFQ$mLEbQD5kOAgjfZZ1zEVlrke6wE8vBEHzK.zI.7MOAVo) as your FRRouting device's password:

[router.'router1']
address = "10.0.0.1"
asn = "65000"
src_addr_ipv4 = "192.0.2.1"
src_addr_ipv6 = "2001:db8::1"
credential = "frr_api_router1"
location = "pop1"
display_name = "POP 1"
port = "8080"
type = "frr"
proxy = ""

[credential.'frr_api_router1']
username = "frr"
password = "$pbkdf2-sha256$29000$9T5njNFaS6lVag1B6H2vFQ$mLEbQD5kOAgjfZZ1zEVlrke6wE8vBEHzK.zI.7MOAVo"

Start hyperglass-frr

# systemctl restart hyperglass-frr
# systemctl status hyperglass-frr

Test

hyperglass-frr should now be active, and you can run a simple test to verify that it is working apart from your main hyperglass implementation:

import json
import requests
query = '{"query_type": "bgp_route", "afi": "ipv4", "target": "1.1.1.0/24"}'
query_json = json.dumps(query)
headers = {'Content-Type': 'application/json', 'X-API-Key': '$pbkdf2-sha256$29000$m9M6R.j9HwMgJGRs7f0/Jw$5HERwfOIn3P0U/M9t5t04SmgRmTzk3435Lr0duqz07w'}
url = "http://192.168.15.130:8080/frr"
output = requests.post(url, headers=headers, data=query_json)
print(output.text)

hyperglass-frr's People

Contributors

thatmattlove avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

hyperglass-frr's Issues

[FR] Update the parser to use FRRouting JSON as data-source instead of screen-scraping

FRRouting support for getting a Command Line Interface command output in JSON format is getting better and better over time.

E.g. for hyperglass-frr is show bgp [ ipv4 | ipv6 ] unicast [ prefix | route ] json

Will avoid screen-scraping and well-known data-format is used as data-source when quering FRRouting for information.


frrouting-A# show bgp ipv4 unicast 172.20.230.0/25
BGP routing table entry for 172.20.230.0/25
Paths: (1 available, best #1, table default)
  Local
    0.0.0.0 from 0.0.0.0 (192.0.2.10)
      Origin IGP, metric 0, localpref 0, weight 32768, valid, sourced, local, bestpath-from-AS Local, best (First path received)
      Community: graceful-shutdown
      AddPath ID: RX 0, TX-All 2 TX-Best-Per-AS 0
      Advertised to: 192.0.2.11
      Last update: Sat Feb 22 03:43:28 2020


frrouting-A# show bgp ipv4 unicast 172.20.230.0/25 json 
{
  "prefix":"172.20.230.0\/25",
  "paths":[
    {
      "aspath":{
        "string":"Local",
        "segments":[
        ],
        "length":0
      },
      "origin":"IGP",
      "med":0,
      "metric":0,
      "localpref":0,
      "weight":32768,
      "valid":true,
      "sourced":true,
      "local":true,
      "bestpath":{
        "bestpathFromAs":0,
        "overall":true,
        "selectionReason":"First path received"
      },
      "community":{
        "string":"graceful-shutdown",
        "list":[
          "gracefulShutdown"
        ]
      },
      "addpathRxId":0,
      "addpathTxId":2,
      "addpathTxIdAll":2,
      "addpathTxIdBestPerAS":0,
      "advertisedTo":{
        "192.0.2.11":{
          "hostname":"frrouting-B"
        }
      },
      "lastUpdate":{
        "epoch":1582343008,
        "string":"Sat Feb 22 03:43:28 2020\n"
      },
      "nexthops":[
        {
          "ip":"0.0.0.0",
          "afi":"ipv4",
          "metric":0,
          "accessible":true,
          "used":true
        }
      ],
      "peer":{
        "peerId":"0.0.0.0",
        "routerId":"192.0.2.10"
      }
    }
  ]
}

frrouting-A# find json 
<snip>
  (view)  show [ip] bgp <view|vrf> all [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast|flowspec>]] [json]
  (view)  show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD> received prefix-filter [json]
  (view)  show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn>]] route-leak  [json]
  (view)  show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast|flowspec>]]          [cidr-only          |dampening <flap-statistics|dampened-paths>          |community [AA:NN|local-AS|no-advertise|no-export          ]
  (view)  show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast|flowspec>]] neighbors <A.B.C.D|X:X::X:X|WORD> <advertised-routes|received-routes|filtered-routes> [route-map WORD] [json]
  (view)  show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast|flowspec>]] neighbors <A.B.C.D|X:X::X:X|WORD> <flap-statistics|dampened-routes|routes> [json]
  (view)  show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast|flowspec>]] large-community [<AA:BB:CC> [exact-match]] [json]
  (view)  show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast|flowspec>]] large-community-list <(1-500)|WORD> [exact-match] [json]
  (view)  show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast|flowspec>]] summary [failed] [json]
  (view)  show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast|flowspec>]]<A.B.C.D|A.B.C.D/M|X:X::X:X|X:X::X:X/M> [<bestpath|multipath>] [json]
  (view)  show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> flowspec] detail [json]
  (view)  show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]
</snip>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.