Skip to content

Repository files navigation

node-bird-router-api

TypeScript library that connects to BIRD’s Unix control socket, sends the same commands you would type in birdc, and parses show protocols output into structured objects (including BGP channels and passive BGP details).

Requirements

  • BIRD running locally with its control socket available (default path: /run/bird/bird.ctl).
  • Node.js 20+ (matches dev tooling in this repo).

Install & build

This package is marked private in package.json; clone the repo and build from source:

yarn install
yarn build && yarn build:types

The project is ESM ("type": "module"). After a build, import from dist/ (or from the package name if you publish this library yourself).

Usage

import { Bird } from "./dist/index.js";

const bird = new Bird();
// Optional: custom socket path
// const bird = new Bird({ socketPath: "/run/bird/bird.ctl" });

await bird.connect();

try {
  const raw = await bird.sendCommand("show route");
  console.log(raw);

  const protocols = await bird.showProtocols();
  console.log(protocols);

  const ok = await bird.configureCheck();
  if (ok) {
    await bird.configure();
  }
} finally {
  await bird.destroy();
}

sendCommand queues requests so only one command runs on the socket at a time.

showProtocols

  • Default: list of Protocol rows (summary view).
  • { all: true }: full detail; BGP entries include parsed channels and bgp data.
  • { name: "my_proto" }: filter to a single protocol (or undefined if missing).
  • { raw: true }: return unparsed text for the matching protocol when combined with name and all (see overloads in src/index.ts).

API (summary)

Method Purpose
connect() Connect to the socket and wait for BIRD’s ready banner.
destroy() Close the socket.
sendCommand(command) Send a line to BIRD; returns the textual response (status codes stripped).
showProtocols(options?) Parsed or raw protocol listing (overloads for all, name, raw).
configureCheck() Run configure check; resolves true if output contains “Configuration OK”.
configure() Runs configure check then configure if the check passes.

Exported types live in src/types.ts.

Development

yarn dev          # run src with ts-node + nodemon
yarn build        # compile to dist with SWC
yarn build:types  # emit .d.ts to dist
yarn test:unit    # unit tests
yarn test:types   # tsc --noEmit
yarn lint         # eslint on src

License

GPL-3.0 — see LICENSE.

About

Node/TS library for BIRD Internet Routing Daemon: Unix socket control, CLI commands, and structured show protocols parsing.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages