Skip to content

Commit

Permalink
add support for RD and local peer types
Browse files Browse the repository at this point in the history
  • Loading branch information
yu-re-ka committed Mar 13, 2024
1 parent 2502046 commit 167ee20
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
44 changes: 33 additions & 11 deletions src/bmp_collector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::store::{Client, RouteState, Session, SessionId, Store, TableSelector};
use crate::store::{
Client, PeerDistinguisher, RouteState, Session, SessionId, Store, TableSelector,
};
use bitvec::prelude::Msb0;
use bitvec::view::BitView;
use futures_util::future::join_all;
Expand All @@ -19,16 +21,36 @@ fn table_selector_for_peer(
client_addr: SocketAddr,
peer: &BmpMessagePeerHeader,
) -> Option<TableSelector> {
match (peer.peertype, peer.flags.view_bits::<Msb0>()[1]) {
(0, false) => Some(TableSelector::PrePolicyAdjIn(SessionId {
from_client: client_addr,
peer_address: peer.peeraddress,
})),
(0, true) => Some(TableSelector::PostPolicyAdjIn(SessionId {
from_client: client_addr,
peer_address: peer.peeraddress,
})),
(3, _) => Some(TableSelector::LocRib {
let peer_distinguisher = match peer.peertype {
0 => {
if peer.peerdistinguisher.is_zero() {
Some(PeerDistinguisher::Global)
} else {
warn!("Peer type global but peer distinguisher is not empty");
None
}
}
1 => Some(PeerDistinguisher::RD(
peer.peerdistinguisher.rdh,
peer.peerdistinguisher.rdl,
)),
2 => Some(PeerDistinguisher::Local(
peer.peerdistinguisher.rdh,
peer.peerdistinguisher.rdl,
)),
_ => None,
};

let session_id = peer_distinguisher.map(|peer_distinguisher| SessionId {
from_client: client_addr,
peer_distinguisher,
peer_address: peer.peeraddress,
});

match (peer.peertype, session_id, peer.flags.view_bits::<Msb0>()[1]) {
(0 | 1 | 2, Some(session), false) => Some(TableSelector::PrePolicyAdjIn(session)),
(0 | 1 | 2, Some(session), true) => Some(TableSelector::PostPolicyAdjIn(session)),
(3, _, _) => Some(TableSelector::LocRib {
from_client: client_addr,
route_state: RouteState::Selected,
}),
Expand Down
8 changes: 8 additions & 0 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ pub struct RouteAttrs {
pub nexthop: Option<IpAddr>,
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
pub enum PeerDistinguisher {
Global,
RD(u32, u32),
Local(u32, u32),
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SessionId {
pub from_client: SocketAddr,
pub peer_distinguisher: PeerDistinguisher,
pub peer_address: IpAddr,
}

Expand Down

0 comments on commit 167ee20

Please sign in to comment.