Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/path-attributes-bui…
Browse files Browse the repository at this point in the history
…lder' into path-attributes-builder
  • Loading branch information
DRiKE committed Feb 29, 2024
2 parents 08b459f + 8617b49 commit 580ef94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/bgp/path_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ pub struct ExtendedCommunitiesList {
}

impl ExtendedCommunitiesList {
fn new(communities: Vec<ExtendedCommunity>)
pub fn new(communities: Vec<ExtendedCommunity>)
-> ExtendedCommunitiesList
{
ExtendedCommunitiesList {communities }
Expand Down Expand Up @@ -1876,7 +1876,7 @@ pub struct Ipv6ExtendedCommunitiesList {
}

impl Ipv6ExtendedCommunitiesList {
fn new(communities: Vec<Ipv6ExtendedCommunity>)
pub fn new(communities: Vec<Ipv6ExtendedCommunity>)
-> Ipv6ExtendedCommunitiesList
{
Ipv6ExtendedCommunitiesList {communities }
Expand Down
23 changes: 13 additions & 10 deletions src/bgp/workshop/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<Octs: Octets, N: Clone + Debug + Hash> RouteWorkshop<Octs, N> {
pub fn get_attr<A: FromAttribute + WorkshopAttribute<N>>(
&self,
) -> Option<A> {
self.1.get::<A>()
self.1.get::<A>().or_else(|| A::retrieve(&self.1))
}

pub fn clone_into_route(&self) -> Route<N> {
Expand Down Expand Up @@ -162,6 +162,7 @@ impl_workshop!(
crate::bgp::path_attributes::ClusterIds
crate::bgp::message::update_builder::StandardCommunitiesList
crate::bgp::types::Otc
crate::bgp::message::update_builder::MpReachNlriBuilder
);

//------------ WorkshopAttribute ---------------------------------------------
Expand All @@ -182,25 +183,25 @@ impl<N: Clone + Hash + Debug> WorkshopAttribute<N> for Vec<Community> {
fn retrieve(attrs: &PaMap) -> Option<Self> {
let mut c = attrs
.get::<StandardCommunitiesList>()
.unwrap()
.fmap(|c| Community::Standard(*c));
.map(|c| c.fmap(|c| Community::Standard(*c)))
.unwrap_or_default();
c.append(
&mut attrs
.get::<ExtendedCommunitiesList>()
.unwrap()
.fmap(Community::Extended),
.map(|c| c.fmap(Community::Extended))
.unwrap_or_default()
);
c.append(
&mut attrs
.get::<Ipv6ExtendedCommunitiesList>()
.unwrap()
.fmap(Community::Ipv6Extended),
.map(|c| c.fmap(Community::Ipv6Extended))
.unwrap_or_default()
);
c.append(
&mut attrs
.get::<LargeCommunitiesList>()
.unwrap()
.fmap(Community::Large),
.map(|c| c.fmap(Community::Large))
.unwrap_or_default()
);

Some(c)
Expand Down Expand Up @@ -288,7 +289,9 @@ impl<N: Clone + Hash> WorkshopAttribute<N> for crate::bgp::types::NextHop {
attrs: &mut PaMap,
) -> Result<(), ComposeError> {
if let Some(mut nlri) = attrs.get::<MpReachNlriBuilder>() {
nlri.set_nexthop(local_attr)
nlri.set_nexthop(local_attr)?;
attrs.set(nlri).ok_or(ComposeError::InvalidAttribute)?;
Ok(())
} else {
Err(ComposeError::InvalidAttribute)
}
Expand Down

0 comments on commit 580ef94

Please sign in to comment.