Skip to content

Commit 431050a

Browse files
committed
From one Oct type to another
1 parent 7fa2c49 commit 431050a

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/bgp/nlri/afisafi.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -1003,11 +1003,11 @@ impl<Octs: AsRef<[u8]>> Ord for Ipv4RouteTargetNlri<Octs> {
10031003

10041004
//--- Ipv4FlowSpec
10051005

1006-
#[derive(Clone, Debug, Hash)]
1006+
#[derive(Clone, Hash)]
10071007
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
10081008
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10091009
#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))]
1010-
pub struct Ipv4FlowSpecNlri<Octs>(FlowSpecNlri<Octs>);
1010+
pub struct Ipv4FlowSpecNlri<Octs>(pub FlowSpecNlri<Octs>);
10111011

10121012
impl<Octs> AfiSafiNlri for Ipv4FlowSpecNlri<Octs> {
10131013
type Nlri = FlowSpecNlri<Octs>;
@@ -1048,10 +1048,12 @@ impl<Octs: AsRef<[u8]>> NlriCompose for Ipv4FlowSpecNlri<Octs> {
10481048
}
10491049
}
10501050

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

10571059
impl<Octs, Other> PartialEq<Ipv4FlowSpecNlri<Other>> for Ipv4FlowSpecNlri<Octs>
@@ -1086,6 +1088,12 @@ impl<Octs: AsRef<[u8]>> Ord for Ipv4FlowSpecNlri<Octs> {
10861088
}
10871089
}
10881090

1091+
impl<T> Debug for Ipv4FlowSpecNlri<T> {
1092+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1093+
write!(f, "{}", self.nlri())
1094+
}
1095+
}
1096+
10891097
//------------ Ipv6 ----------------------------------------------------------
10901098

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

13791387
//--- Ipv6FlowSpec
13801388

1381-
#[derive(Clone, Debug, Hash)]
1389+
#[derive(Clone, Hash)]
13821390
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
13831391
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
13841392
#[cfg_attr(feature = "bincode", derive(bincode::Decode, bincode::Encode))]
1385-
pub struct Ipv6FlowSpecNlri<Octs>(FlowSpecNlri<Octs>);
1393+
pub struct Ipv6FlowSpecNlri<Octs>(pub FlowSpecNlri<Octs>);
13861394

13871395
impl<Octs> AfiSafiNlri for Ipv6FlowSpecNlri<Octs> {
13881396
type Nlri = FlowSpecNlri<Octs>;
@@ -1461,6 +1469,12 @@ impl<Octs: AsRef<[u8]>> Ord for Ipv6FlowSpecNlri<Octs> {
14611469
}
14621470
}
14631471

1472+
impl<T> Debug for Ipv6FlowSpecNlri<T> {
1473+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1474+
write!(f, "{}", self.nlri())
1475+
}
1476+
}
1477+
14641478
/*
14651479
impl Ipv6UnicastAddpathNlri {
14661480
pub fn iter<'a, O, P>(parser: Parser<'a, P>) -> NlriIter<'a, O, P, Self>

src/bgp/workshop/route.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ impl<N: AfiSafiNlri> RouteWorkshop<N> {
105105
/// MP_REACH_NLRI attribute is set in the resulting RouteWorkshop.
106106
/// In both cases, the NEXT_HOP path attribute is omitted from the
107107
/// attached [`PaMap`].
108-
pub fn from_update_pdu<Octs: Octets>(
108+
pub fn from_update_pdu<'a, Octs: Octets>(
109109
nlri: N,
110-
pdu: &UpdateMessage<Octs>,
110+
pdu: &'a UpdateMessage<Octs>,
111111
) -> Result<Self, ComposeError>
112112
where
113-
for<'a> Vec<u8>: OctetsFrom<Octs::Range<'a>>,
113+
Vec<u8>: From<<Octs as Octets>::Range<'a>>
114114
{
115115
let mut res = Self::new(nlri);
116116

@@ -440,7 +440,7 @@ mod tests {
440440

441441
let conv_nlri = pdu.typed_announcements::<_, Ipv4UnicastNlri>()
442442
.unwrap().unwrap().next().unwrap().unwrap();
443-
let conv_rws =RouteWorkshop::from_update_pdu(conv_nlri, &pdu).unwrap();
443+
let conv_rws = RouteWorkshop::from_update_pdu(conv_nlri, &pdu).unwrap();
444444

445445
assert_eq!(
446446
conv_rws.1,

0 commit comments

Comments
 (0)