|
1 | | -# zettabgp |
2 | | -BGP & BMP Rust library |
| 1 | +zettabgp - BGP&BMP Rust library |
| 2 | +==================== |
| 3 | + |
| 4 | +This is a BGP and BMP protocols driver library for Rust. |
| 5 | + |
| 6 | +BGP - Border Gateway Protocol version 4. |
| 7 | +BMP - BGP Monitoring Protocol version 3. |
| 8 | + |
| 9 | +## Supported BGP message types |
| 10 | + Open |
| 11 | + Notification |
| 12 | + Keepalive |
| 13 | + Update |
| 14 | + |
| 15 | +## Supported BMP message types |
| 16 | + Initiation |
| 17 | + Termination |
| 18 | + PeerUpNotification |
| 19 | + RouteMonitoring |
| 20 | + |
| 21 | +## Supported address families NLRI (network layer reachability information) |
| 22 | +ipv4 unicast |
| 23 | +ipv4 labeled-unicast |
| 24 | +ipv4 multicast |
| 25 | +ipv4 mvpn |
| 26 | +vpnv4 unicast |
| 27 | +vpnv4 multicast |
| 28 | +ipv6 unicast |
| 29 | +ipv6 labeled-unicast |
| 30 | +ipv6 multicast |
| 31 | +vpnv6 unicast |
| 32 | +vpnv6 multicast |
| 33 | +vpls |
| 34 | +evpn |
| 35 | +flowspec ipv4 |
| 36 | +flowspec ipv6 |
| 37 | + |
| 38 | +## Supported path attributes |
| 39 | +MED |
| 40 | +Origin |
| 41 | +Local preference |
| 42 | +AS path |
| 43 | +Communities |
| 44 | +Extended communities |
| 45 | +Aggregator AS |
| 46 | +Atomic aggregate |
| 47 | +Cluster list |
| 48 | +Originator ID |
| 49 | +Attribute set |
| 50 | +some PMSI tunnels |
| 51 | + |
| 52 | +## Usage |
| 53 | + |
| 54 | +Library allow you to parse protocol messages (as binary buffers) into Rust data structures to frther processing. |
| 55 | +Or generate valid protocol messages from Rust data structure. |
| 56 | +So it can be use in any environment (synrchronous or asynchronous) to make a BGP RR, monitoring system or BGP analytics. |
| 57 | + |
| 58 | +```rust |
| 59 | +use zettabgp::prelude::*; |
| 60 | +use std::io::{Read,Write}; |
| 61 | +let mut socket = match std::net::TcpStream::connect("127.0.0.1:179") { |
| 62 | + Ok(sck) => sck, |
| 63 | + Err(e) => {eprintln!("Unable to connect to BGP neighbor: {}",e);return;} |
| 64 | +}; |
| 65 | +let params=BgpSessionParams::new(64512,180,BgpTransportMode::IPv4,std::net::Ipv4Addr::new(1,1,1,1),vec![BgpCapability::SafiIPv4u].into_iter().collect()); |
| 66 | +let mut buf = [0 as u8; 32768]; |
| 67 | +let mut open_my = params.open_message(); |
| 68 | +let open_sz = open_my.encode_to(¶ms, &mut buf[19..]).unwrap(); |
| 69 | +let tosend = params.prepare_message_buf(&mut buf, BgpMessageType::Open, open_sz).unwrap(); |
| 70 | +socket.write_all(&buf[0..tosend]).unwrap();//send my open message |
| 71 | +socket.read_exact(&mut buf[0..19]).unwrap();//read response message head |
| 72 | +let messagehead=params.decode_message_head(&buf).unwrap();//decode message head |
| 73 | +if messagehead.0 == BgpMessageType::Open { |
| 74 | + socket.read_exact(&mut buf[0..messagehead.1]).unwrap();//read message body |
| 75 | + let mut bom = BgpOpenMessage::new(); |
| 76 | + bom.decode_from(¶ms, &buf[0..messagehead.1]).unwrap();//decode received message body |
| 77 | + eprintln!("BGP Open message received: {:?}", bom); |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | + |
| 82 | +## Crates.io |
| 83 | + |
| 84 | +https://crates.io/crates/zettabgp |
| 85 | + |
| 86 | +## Documentation |
| 87 | + |
| 88 | +https://docs.rs/zettabgp |
| 89 | + |
| 90 | +## License |
| 91 | + |
| 92 | +[MIT OR Apache-2.0](LICENSE) |
0 commit comments