Skip to content

Commit

Permalink
From one Oct type to another
Browse files Browse the repository at this point in the history
  • Loading branch information
density215 committed Jun 24, 2024
1 parent 7fa2c49 commit 431050a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
30 changes: 22 additions & 8 deletions src/bgp/nlri/afisafi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,11 +1003,11 @@ impl<Octs: AsRef<[u8]>> Ord for Ipv4RouteTargetNlri<Octs> {

//--- Ipv4FlowSpec

#[derive(Clone, Debug, Hash)]
#[derive(Clone, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))]
pub struct Ipv4FlowSpecNlri<Octs>(FlowSpecNlri<Octs>);
pub struct Ipv4FlowSpecNlri<Octs>(pub FlowSpecNlri<Octs>);

impl<Octs> AfiSafiNlri for Ipv4FlowSpecNlri<Octs> {
type Nlri = FlowSpecNlri<Octs>;
Expand Down Expand Up @@ -1048,10 +1048,12 @@ impl<Octs: AsRef<[u8]>> NlriCompose for Ipv4FlowSpecNlri<Octs> {
}
}

impl<T> From<Ipv4FlowSpecNlri<T>> for FlowSpecNlri<T> {
fn from(value: Ipv4FlowSpecNlri<T>) -> Self {
value.0
}
impl<'a, O: Octets + 'a> From<&'a Ipv4FlowSpecNlri<O>> for FlowSpecNlri<bytes::Bytes> {
fn from(value: &Ipv4FlowSpecNlri<O>) -> Self {
let raw = bytes::Bytes::copy_from_slice(value.0.raw().as_ref());
let p = &mut Parser::from_ref(&raw);
FlowSpecNlri::parse(p, Afi::Ipv4).unwrap()
}
}

impl<Octs, Other> PartialEq<Ipv4FlowSpecNlri<Other>> for Ipv4FlowSpecNlri<Octs>
Expand Down Expand Up @@ -1086,6 +1088,12 @@ impl<Octs: AsRef<[u8]>> Ord for Ipv4FlowSpecNlri<Octs> {
}
}

impl<T> Debug for Ipv4FlowSpecNlri<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.nlri())
}
}

//------------ Ipv6 ----------------------------------------------------------

//--- Ipv6Unicast
Expand Down Expand Up @@ -1378,11 +1386,11 @@ impl<Octs: AsRef<[u8]>> Ord for Ipv6MplsVpnUnicastNlri<Octs> {

//--- Ipv6FlowSpec

#[derive(Clone, Debug, Hash)]
#[derive(Clone, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))]
pub struct Ipv6FlowSpecNlri<Octs>(FlowSpecNlri<Octs>);
pub struct Ipv6FlowSpecNlri<Octs>(pub FlowSpecNlri<Octs>);

impl<Octs> AfiSafiNlri for Ipv6FlowSpecNlri<Octs> {
type Nlri = FlowSpecNlri<Octs>;
Expand Down Expand Up @@ -1461,6 +1469,12 @@ impl<Octs: AsRef<[u8]>> Ord for Ipv6FlowSpecNlri<Octs> {
}
}

impl<T> Debug for Ipv6FlowSpecNlri<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.nlri())
}
}

/*
impl Ipv6UnicastAddpathNlri {
pub fn iter<'a, O, P>(parser: Parser<'a, P>) -> NlriIter<'a, O, P, Self>
Expand Down
8 changes: 4 additions & 4 deletions src/bgp/workshop/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ impl<N: AfiSafiNlri> RouteWorkshop<N> {
/// MP_REACH_NLRI attribute is set in the resulting RouteWorkshop.
/// In both cases, the NEXT_HOP path attribute is omitted from the
/// attached [`PaMap`].
pub fn from_update_pdu<Octs: Octets>(
pub fn from_update_pdu<'a, Octs: Octets>(
nlri: N,
pdu: &UpdateMessage<Octs>,
pdu: &'a UpdateMessage<Octs>,
) -> Result<Self, ComposeError>
where
for<'a> Vec<u8>: OctetsFrom<Octs::Range<'a>>,
Vec<u8>: From<<Octs as Octets>::Range<'a>>
{
let mut res = Self::new(nlri);

Expand Down Expand Up @@ -440,7 +440,7 @@ mod tests {

let conv_nlri = pdu.typed_announcements::<_, Ipv4UnicastNlri>()
.unwrap().unwrap().next().unwrap().unwrap();
let conv_rws =RouteWorkshop::from_update_pdu(conv_nlri, &pdu).unwrap();
let conv_rws = RouteWorkshop::from_update_pdu(conv_nlri, &pdu).unwrap();

assert_eq!(
conv_rws.1,
Expand Down

0 comments on commit 431050a

Please # to comment.