#bgp #networking #protocols #network-protocol #message-parser #attributes #path

zettabgp

This is a BGP (parsing and composing) and BMP (only parsing) protocols driver library for Rust

12 releases

0.3.4 Oct 26, 2023
0.3.3 Jan 17, 2023
0.3.0 Oct 8, 2022
0.2.1 Aug 1, 2021
0.1.2 May 23, 2021

#388 in Network programming

Download history 102/week @ 2024-08-10 132/week @ 2024-08-17 105/week @ 2024-08-24 145/week @ 2024-08-31 118/week @ 2024-09-07 120/week @ 2024-09-14 186/week @ 2024-09-21 89/week @ 2024-09-28 105/week @ 2024-10-05 113/week @ 2024-10-12 107/week @ 2024-10-19 68/week @ 2024-10-26 183/week @ 2024-11-02 164/week @ 2024-11-09 115/week @ 2024-11-16 47/week @ 2024-11-23

523 downloads per month
Used in 3 crates

MIT/Apache

340KB
8K SLoC

zettabgp - BGP&BMP Rust library

This is a BGP and BMP protocols driver library for Rust.

BGP - Border Gateway Protocol version 4. BMP - BGP Monitoring Protocol version 3.

Supported BGP message types

  • Open
  • Notification
  • Keepalive
  • Update

Supported BMP message types

  • Initiation
  • Termination
  • PeerUpNotification
  • RouteMonitoring

Supported address families NLRI (network layer reachability information)

  • ipv4 unicast
  • ipv4 labeled-unicast
  • ipv4 multicast
  • ipv4 mvpn
  • ipv4 mdt
  • vpnv4 unicast
  • vpnv4 multicast
  • ipv6 unicast
  • ipv6 labeled-unicast
  • ipv6 multicast
  • ipv6 mdt
  • vpnv6 unicast
  • vpnv6 multicast
  • vpls
  • evpn
  • flowspec ipv4
  • flowspec ipv6

Supported path attributes

  • MED
  • Origin
  • Local preference
  • AS path
  • Communities
  • Extended communities
  • Aggregator AS
  • Atomic aggregate
  • Cluster list
  • Originator ID
  • Attribute set
  • Connector
  • some PMSI tunnels

Usage

Library allow you to parse protocol messages (as binary buffers) into Rust data structures to frther processing. Or generate valid protocol messages from Rust data structure. So it can be use in any environment (synrchronous or asynchronous) to make a BGP RR, monitoring system or BGP analytics.

use zettabgp::prelude::*;
use std::io::{Read,Write};
let mut socket = match std::net::TcpStream::connect("127.0.0.1:179") {
  Ok(sck) => sck,
  Err(e) => {eprintln!("Unable to connect to BGP neighbor: {}",e);return;}
};
let params=BgpSessionParams::new(64512,180,BgpTransportMode::IPv4,std::net::Ipv4Addr::new(1,1,1,1),vec![BgpCapability::SafiIPv4u].into_iter().collect());
let mut buf = [0 as u8; 32768];
let mut open_my = params.open_message();
let open_sz = open_my.encode_to(&params, &mut buf[19..]).unwrap();
let tosend = params.prepare_message_buf(&mut buf, BgpMessageType::Open, open_sz).unwrap();
socket.write_all(&buf[0..tosend]).unwrap();//send my open message
socket.read_exact(&mut buf[0..19]).unwrap();//read response message head
let messagehead=params.decode_message_head(&buf).unwrap();//decode message head
if messagehead.0 == BgpMessageType::Open {
   socket.read_exact(&mut buf[0..messagehead.1]).unwrap();//read message body
   let mut bom = BgpOpenMessage::new();
   bom.decode_from(&params, &buf[0..messagehead.1]).unwrap();//decode received message body
   eprintln!("BGP Open message received: {:?}", bom);
}

Crates.io

https://crates.io/crates/zettabgp

Documentation

https://docs.rs/zettabgp

License

MIT OR Apache-2.0

Dependencies

~250KB