Skip to content

ool-mddo/batfish-wrapper

Repository files navigation

batfish-wrapper

Batfish wrapper for MDDO Project

Setup

Install required packages

pip3 install -r requirements_prod.txt

Run batfish-wrapper

python3 src/app.py

It will up at http://localhost:5000/

Environment variables

  • BATFISH_HOST: specify batfish service (hostname)
  • MDDO_CONFIGS_DIR: batfish snapshot directory (default: ./configs)
  • MDDO_QUERIES_DIR: query result directory (default: ./queries)

REST API (/batfish space)

APIs to control batfish.

Parameters in examples:

  • network name : pushed_configs
  • snapshot name: mddo_network

Get network and snapshots in batfish

Get all networks and snapshots

  • GET /batfish/snapshots
curl -X GET http://localhost:5000/batfish/snapshots

Get networks

  • GET /batfish/networks
curl -X GET http://localhost:5000/batfish/networks

Get snapshots in a network

  • GET /batfish/<network>/snapshots
    • simulated: [optional] returns all logical (simulated) snapshots defined in the network even if these snapshots are not registered in batfish. (default: false)
curl -X GET http://localhost:5000/batfish/pushed_configs/snapshots
curl -X GET http://localhost:5000/batfish/pushed_configs/snapshots?simulated=true

Get nodes in a snapshot

  • GET /batfish/<network>/<snapshot>/nodes
curl -X GET http://localhost:5000/batfish/pushed_configs/mddo_network/nodes

Get interfaces in a node

  • GET /batfish/<network>/<snapshot>/<node>/interfaces
curl -X GET http://localhost:5000/batfish/pushed_configs/mddo_network/regiona-svr01/interfaces

Get interfaces in a snapshots

  • GET /batfish/<network>/<snapshot>/interfaces
curl -X GET http://localhost:5000/batfish/pushed_configs/mddo_network/interfaces

Query traceroute for all snapshots in a network

L3 Reachability (traceroute) simulation

  • GET /batfish/<network>/<snapshot>/<source-node>/traceroute
    • interface: source interface
    • destination: destination IP address
curl -X GET "http://localhost:5000/batfish/pushed_configs/mddo_network/regiona-svr01/traceroute?interface=enp1s4&destination=172.31.10.1"

Register snapshot into batfish (for testing/debugging)

Register snapshot

  • POST /batfish/<network>/<snapshot>/register
    • overwrite: [optional] Overwrite (reload) snapshot
curl -X POST -H "Content-Type: application/json" -d {} \
  http://localhost:5000/batfish/pushed_configs/mddo_network/register
# if overwrite (reload)
curl -X POST -H "Content-Type: application/json" -d '{"overwrite": true}'\
  http://localhost:5000/batfish/pushed_configs/mddo_network/register

REST API (/configs space)

APIs to operate configs/snapshots.

Operate logical (linkdown) snapshot pattern

Make snapshot patterns

  • POST /configs/<network>/<snapshot>/snapshot_patterns
    • node: [optional] draw-off (deactivate) target node
    • interface_regexp: [optional] draw-off (deactivate) interface name (regexp match)
# without draw-off
curl -X POST -H "Content-Type: application/json" -d '{}'\
  http://localhost:5000/configs/pushed_configs/mddo_network/snapshot_patterns
# draw-off regiona-pe01[ge-0/0/0]
curl -X POST -H "Content-Type: application/json" \
  -d '{"node": "regiona-pe01", "interface_regexp": "ge-0/0/0"}' \
  http://localhost:5000/configs/pushed_configs/mddo_network/snapshot_patterns

CLI

python3 src/cli_make_snapshot_patterns.py -n pushed_configs -s mddo_network -d regiona-pe01 -l "ge-0/0/0"

Fetch snapshot patterns

  • GET /configs/<network>/<snapshot>/snapshot_patterns
curl http://localhost:5000/configs/pushed_configs/mddo_network/snapshot_patterns

Remove snapshot patterns

  • DELETE /configs/<network>/<snapshot>/snapshot_patterns
curl -X DELETE http://localhost:5000/configs/pushed_configs/mddo_network/snapshot_patterns

Operate configs git repository

Change current branch

  • POST /configs/<network>/branch
    • name : [optional] branch name (default "main")
curl -X POST -H "Content-Type: application/json" -d '{"name": "202202demo"}' \
  http://localhost:5000/configs/pushed_configs/branch

Fetch current branch

  • GET /configs/<network>/branch
curl http://localhost:5000/configs/pushed_configs/branch

Config file operation

Save (upload) config file

  • POST /configs/<network>/<snapshot>
    • filename: file name
    • text: file body

Fetch (download) config file

  • GET /configs/<network>/<snapshot>/<filename>

Fetch all config files

  • GET /configs/<network>/<snapshot>

REST API (/queries space)

APIs to operate batfish query (query results)

Exec batfish queries and save these result as csv files (local files)

Make query data

  • POST /queries/<network> (for all snapshots in the network)
  • POST /queries/<network>/<snapshot> (for a snapshot)
# all snapshots
curl -X POST -H "Content-Type: application/json" -d '{}'\
  http://localhost:5000/queries/pushed_configs
# single snapshot
curl -X POST -H "Content-Type: application/json" -d '{}'\
  http://localhost:5000/queries/pushed_configs/mddo_network

CLI

  • -n/--network: target network (query for all snapshots in the network without -s)
  • -s/--snapshot: [optional] target snapshot (query for single snapshot)
# all snapshots
python3 src/cli_exec_queries.py -n pushed_configs
# single snapshot
python3 src/cli_exec_queries.py -n pushed_configs -s mddo_network

Delete query data

  • DELETE /queries/<network> (for all snapshots in the network)
curl -XX DELETE http://localhost:5000/queries/pushed_configs

Other REST API

Calculate asis/tobe model diff and generate configurations using it.

  • POST /model-merge
    • asis: asis topology
    • tobe: tobe topology

Development

Setup

pip3 install -r requirements_dev.txt

Format code

black src/*.py src/**/*.py

Lint

flake8 --statistics --config .config/flake8 src/
pylint --rcfile .config/pylintrc src/*.py src/**/*.py

Documents

mkdocs serve

and access http://localhost:8000