mirror of
https://github.com/mii443/miibgpd.git
synced 2025-08-23 00:05:27 +00:00
add new
method to UpdateMessage
This commit is contained in:
@ -7,7 +7,7 @@ use crate::path_attribute::{AsPath, Origin, PathAttribute};
|
|||||||
use crate::routing::Ipv4Network;
|
use crate::routing::Ipv4Network;
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
|
|
||||||
use super::header::Header;
|
use super::header::{Header, MessageType};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
|
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
|
||||||
pub struct UpdateMessage {
|
pub struct UpdateMessage {
|
||||||
@ -25,7 +25,37 @@ impl UpdateMessage {
|
|||||||
network_layer_reachability_information: Vec<Ipv4Network>,
|
network_layer_reachability_information: Vec<Ipv4Network>,
|
||||||
withdrawn_routes: Vec<Ipv4Network>,
|
withdrawn_routes: Vec<Ipv4Network>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
todo!();
|
let path_attributes_length =
|
||||||
|
path_attributes.iter().map(|p| p.bytes_len()).sum::<usize>() as u16;
|
||||||
|
|
||||||
|
let network_layer_reachability_information_length = network_layer_reachability_information
|
||||||
|
.iter()
|
||||||
|
.map(|r| r.bytes_len())
|
||||||
|
.sum::<usize>() as u16;
|
||||||
|
|
||||||
|
let withdrawn_routes_length = withdrawn_routes
|
||||||
|
.iter()
|
||||||
|
.map(|w| w.bytes_len())
|
||||||
|
.sum::<usize>() as u16;
|
||||||
|
|
||||||
|
let header_minimum_length = 19u16;
|
||||||
|
let header = Header::new(
|
||||||
|
header_minimum_length
|
||||||
|
+ path_attributes_length
|
||||||
|
+ network_layer_reachability_information_length
|
||||||
|
+ withdrawn_routes_length
|
||||||
|
+ 4,
|
||||||
|
MessageType::Update,
|
||||||
|
);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
header,
|
||||||
|
withdrawn_routes,
|
||||||
|
withdrawn_routes_length,
|
||||||
|
path_attributes,
|
||||||
|
path_attributes_length,
|
||||||
|
network_layer_reachability_information,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,3 +23,33 @@ pub enum AsPath {
|
|||||||
AsSequence(Vec<AutonomousSystemNumber>),
|
AsSequence(Vec<AutonomousSystemNumber>),
|
||||||
AsSet(BTreeSet<AutonomousSystemNumber>),
|
AsSet(BTreeSet<AutonomousSystemNumber>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PathAttribute {
|
||||||
|
pub fn bytes_len(&self) -> usize {
|
||||||
|
let path_attribute_value_length = match self {
|
||||||
|
PathAttribute::Origin(_) => 1,
|
||||||
|
PathAttribute::AsPath(a) => a.bytes_len(),
|
||||||
|
PathAttribute::NextHop(_) => 4,
|
||||||
|
PathAttribute::DontKnow(v) => v.len(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let length = path_attribute_value_length + 2;
|
||||||
|
|
||||||
|
if path_attribute_value_length > 255 {
|
||||||
|
length + 2
|
||||||
|
} else {
|
||||||
|
length + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsPath {
|
||||||
|
fn bytes_len(&self) -> usize {
|
||||||
|
let as_bytes_length = match self {
|
||||||
|
AsPath::AsSequence(as_sequence) => 2 * as_sequence.len(),
|
||||||
|
AsPath::AsSet(as_set) => 2 * as_set.len(),
|
||||||
|
};
|
||||||
|
|
||||||
|
2 + as_bytes_length
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -49,6 +49,19 @@ impl FromStr for Ipv4Network {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Ipv4Network {
|
||||||
|
pub fn bytes_len(&self) -> usize {
|
||||||
|
match self.prefix() {
|
||||||
|
0 => 1,
|
||||||
|
1..=8 => 2,
|
||||||
|
9..=16 => 3,
|
||||||
|
17..=24 => 4,
|
||||||
|
25..=32 => 5,
|
||||||
|
_ => panic!("Invalid prefix length: {:?}", self.prefix()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl LocRib {
|
impl LocRib {
|
||||||
pub async fn new(config: &Config) -> Result<Self> {
|
pub async fn new(config: &Config) -> Result<Self> {
|
||||||
todo!();
|
todo!();
|
||||||
|
Reference in New Issue
Block a user