Skip to content

Commit 893a441

Browse files
committed
to AS4 Path
1 parent c584efb commit 893a441

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/bgp/aspath.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ impl HopPath {
9696
self.hops.iter().any(|h| h == hop)
9797
}
9898

99+
pub fn contains_segments(&self) -> bool {
100+
self.hops.iter().any(|h| if let Hop::Segment(_) = h { true } else { false })
101+
}
102+
103+
pub fn contains_sets(&self) -> bool {
104+
self.hops.iter().any(|h| if let Hop::Segment(s) = h {
105+
if s.stype == SegmentType::Set || s.stype == SegmentType::ConfedSet {
106+
true
107+
} else {
108+
false }
109+
} else {
110+
false }
111+
)
112+
}
113+
99114
pub fn get_hop(&self, index: usize) -> Option<&OwnedHop> {
100115
self.hops.get(index)
101116
}
@@ -261,9 +276,25 @@ impl HopPath {
261276
})
262277
}
263278

279+
pub fn try_to_asn32_path<Octs>(
280+
&self
281+
) -> Result<AsPath<Octs>,
282+
<<Octs as FromBuilder>::Builder as OctetsBuilder>::AppendError
283+
>
284+
where
285+
Octs: FromBuilder,
286+
<Octs as FromBuilder>::Builder: EmptyBuilder
287+
{
288+
let mut target = EmptyBuilder::empty();
289+
Self::compose_as_path(&self.hops, &mut target)?;
290+
Ok(unsafe {
291+
AsPath::new_unchecked(Octs::from_builder(target), false)
292+
})
293+
}
294+
264295

265296
// Turn this HopPath into the four-octet based AS_PATH wireformat.
266-
fn compose_as_path<Octs: Octets, Target: OctetsBuilder>(
297+
pub fn compose_as_path<Octs: Octets, Target: OctetsBuilder>(
267298
mut hops: &[Hop<Octs>], target: &mut Target
268299
) -> Result<(), Target::AppendError> {
269300
while !hops.is_empty() {
@@ -762,6 +793,7 @@ impl<'a, Octs: Octets> Iterator for PathHops<'a, Octs> {
762793
//----------- PathSegments ---------------------------------------------------
763794

764795
/// Iterates over [`Segment`]s in an [`AsPath`].
796+
#[derive(Debug)]
765797
pub struct PathSegments<'a, Octs> {
766798
parser: Parser<'a, Octs>,
767799
four_byte_asns: bool,

src/bgp/workshop/route.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt::Debug;
22
use std::hash::Hash;
33
//use std::marker::PhantomData;
44

5-
use octseq::{Octets, OctetsFrom};
5+
use octseq::Octets;
66

77
use crate::bgp::communities::Community;
88
use crate::bgp::message::update_builder::{ComposeError, /*MpReachNlriBuilder*/};

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod flowspec;
1111

1212
pub use octseq::Octets;
1313
pub use octseq::Parser;
14+
pub use octseq::OctetsFrom;
1415

1516
//--- Private modules
1617

0 commit comments

Comments
 (0)