1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
//! BGP messages and relevant structs.
pub mod attributes;
use std::net::Ipv4Addr;
use crate::network::*;
use crate::bgp::attributes::AttributeMap;
#[derive(Debug, Primitive)]
pub enum BgpMessageType {
OPEN = 1,
UPDATE = 2,
NOTIFICATION = 3,
KEEPALIVE = 4,
}
// https://tools.ietf.org/html/rfc4271#section-4
#[derive(Debug)]
pub enum BgpMessage{
Open(BgpOpenMessage),
Update(BgpUpdateMessage),
Notification(BgpNotificationMessage),
KeepAlive(BgpKeepAliveMessage),
}
/// BGP Open Message
///
/// ```text
/// 0 1 2 3
/// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
/// +-+-+-+-+-+-+-+-+
/// | Version |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | My Autonomous System |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | Hold Time |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | BGP Identifier |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | Opt Parm Len |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | |
/// | Optional Parameters (variable) |
/// | |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// ```
#[derive(Debug)]
pub struct BgpOpenMessage {
pub version: u8,
pub asn: Asn,
pub hold_time: u16,
pub sender_ip: Ipv4Addr,
pub opt_params: Vec<OptParam>
}
#[derive(Debug)]
pub struct OptParam {
}
#[derive(Debug)]
pub struct BgpUpdateMessage {
pub withdrawn_prefixes: Vec<NetworkPrefix>,
pub attributes: AttributeMap,
pub announced_prefixes: Vec<NetworkPrefix>,
}
#[derive(Debug)]
pub struct BgpNotificationMessage {
pub error_code: u8,
pub error_subcode: u8,
pub data: Vec<u8>,
}
#[derive(Debug)]
pub struct BgpKeepAliveMessage {
}