### Example Search: u32 to bool Source: https://docs.rs/routecore/0.7.2/routecore/bgp/workshop/route/struct.RouteWorkshop.html?search= Example search query for a conversion from `u32` to `bool`. ```text u32 -> bool ``` -------------------------------- ### Example Search Queries Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/workshop/mod.rs.html?search= Illustrates common search query patterns for exploring Rust types and functions. These examples are useful for understanding how to search for specific functionalities. ```rust * std::vec ``` ```rust * u32 -> bool ``` ```rust * Option, (T -> U) -> Option ``` -------------------------------- ### Example Search: Option transformation Source: https://docs.rs/routecore/0.7.2/routecore/bgp/workshop/route/struct.RouteWorkshop.html?search= Example search query for transforming an `Option` where `T` maps to `U`, resulting in an `Option`. ```text Option, (T -> U) -> Option ``` -------------------------------- ### Example Search Queries Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/nlri/mod.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Illustrative search queries for exploring Rust documentation and functionality. ```text std::vec ``` ```text u32 -> bool ``` ```text Option, (T -> U) -> Option ``` -------------------------------- ### Example Search: std::vec Source: https://docs.rs/routecore/0.7.2/routecore/bgp/workshop/route/struct.RouteWorkshop.html?search= Example search query for the `std::vec` type. ```text std::vec ``` -------------------------------- ### LargeCommunity Search Examples Source: https://docs.rs/routecore/0.7.2/routecore/bgp/communities/struct.LargeCommunity.html?search= Examples of how to search for LargeCommunity. These demonstrate different query patterns. ```APIDOC ## Search LargeCommunity ### Description Provides examples of search queries for LargeCommunity. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### BGP Path Selection Example Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/path_selection.rs.html?search=u32+-%3E+bool Demonstrates the usage of `best` and `best_backup` functions for selecting the best and backup BGP routes from a set of candidates. Asserts equality and inequality of selected routes' attributes. ```rust { b_pamap.set(MultiExitDisc(50)); let mut c_pamap = PaMap::empty(); c_pamap.set(Origin(OriginType::Egp)); c_pamap.set(HopPath::from([80, 90, 100, 200, 300])); let candidates = [ OrdRoute::skip_med(&a_pamap, tiebreakers).unwrap(), OrdRoute::skip_med(&b_pamap, tiebreakers).unwrap(), OrdRoute::skip_med(&a_pamap, tiebreakers).unwrap(), //OrdRoute::skip_med(&c_pamap, tiebreakers).unwrap(), ]; let best1 = best(candidates.iter().cloned()).unwrap(); let (best2, backup2) = best_backup(candidates.iter()); let (best2, backup2) = (best2.unwrap(), backup2.unwrap()); assert_eq!(best1.pa_map(), best2.pa_map()); assert_eq!(best1.tiebreakers(), best2.tiebreakers()); dbg!(&best2); dbg!(&backup2); assert_ne!( (best2.pa_map(), best2.tiebreakers()), (backup2.pa_map(), backup2.tiebreakers()) ); } ``` -------------------------------- ### MpReachNlriBuilder::new Source: https://docs.rs/routecore/0.7.2/routecore/bgp/message/update_builder/struct.MpReachNlriBuilder.html Creates a new MpReachNlriBuilder with default settings. ```APIDOC ## MpReachNlriBuilder::new ### Description Creates a new `MpReachNlriBuilder` instance. ### Method `new()` ### Returns A new `MpReachNlriBuilder` instance. ``` -------------------------------- ### Try Get Size Hint for BTreeMap Generation Source: https://docs.rs/routecore/0.7.2/routecore/bgp/path_attributes/type.AttributesMap.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Attempts to get a size hint for BTreeMap construction, returning an error if recursion depth is exceeded. ```rust fn try_size_hint( depth: usize, ) -> Result<(usize, Option), MaxRecursionReached> ``` -------------------------------- ### from Source: https://docs.rs/routecore/0.7.2/routecore/bgp/path_attributes/struct.PaMap.html Creates a new instance by taking ownership of the provided value. This is a direct conversion. ```APIDOC ## fn from(t: T) -> T ### Description Returns the argument unchanged. ### Method `from` ### Parameters - `t` (T): The value to convert. ### Returns - `T`: The converted value, which is the same as the input. ``` -------------------------------- ### AS Path Selection Methods Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/aspath.rs.html?search= Demonstrates the usage of path selection methods like `neighbor_path_selection` and `hop_count_path_selection`, and how prepending segments affects them. ```rust let mut asp = HopPath::from([10, 20, 30].map(Asn::from_u32)); assert_eq!(asp.neighbor_path_selection(), Some(Asn::from_u32(10))); assert_eq!(asp.hop_count_path_selection(), 3); asp.prepend_set([88,99].map(Asn::from_u32)); assert!(asp.neighbor_path_selection().is_none()); assert_eq!(asp.hop_count_path_selection(), 4); asp.prepend_confed_sequence([1000,1001].map(Asn::from_u32)); assert_eq!(asp.hop_count_path_selection(), 4); ``` -------------------------------- ### Iterate over a BTreeMap sub-range Source: https://docs.rs/routecore/0.7.2/routecore/bgp/path_attributes/type.AttributesMap.html?search=u32+-%3E+bool Use `range` to create an iterator over a specified sub-range of elements. Supports various range syntaxes and bound types. Panics if range start > end or if start == end with excluded bounds. ```rust use std::collections::BTreeMap; use std::ops::Bound::Included; let mut map = BTreeMap::new(); map.insert(3, "a"); map.insert(5, "b"); map.insert(8, "c"); for (&key, &value) in map.range((Included(&4), Included(&8))) { println!("{key}: {value}"); } assert_eq!(Some((&5, &"b")), map.range(4..).next()); ``` -------------------------------- ### Mutably iterate over a BTreeMap sub-range Source: https://docs.rs/routecore/0.7.2/routecore/bgp/path_attributes/type.AttributesMap.html?search=u32+-%3E+bool Use `range_mut` to create a mutable iterator over a specified sub-range of elements. Supports various range syntaxes and bound types. Panics if range start > end or if start == end with excluded bounds. ```rust use std::collections::BTreeMap; let mut map: BTreeMap<&str, i32> = [("Alice", 0), ("Bob", 0), ("Carol", 0), ("Cheryl", 0)].into(); for (_, balance) in map.range_mut("B".."Cheryl") { *balance += 100; } for (name, balance) in &map { println!("{name} => {balance}"); } ``` -------------------------------- ### BGP Path Selection with Best and Best-Backup Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/path_selection.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates selecting the best and backup routes from a collection of candidates using `best` and `best_backup` functions. Asserts that the best and backup routes are distinct. ```rust let candidates = [ OrdRoute::skip_med(&a_pamap, tiebreakers).unwrap(), OrdRoute::skip_med(&b_pamap, tiebreakers).unwrap(), OrdRoute::skip_med(&a_pamap, tiebreakers).unwrap(), //OrdRoute::skip_med(&c_pamap, tiebreakers).unwrap(), ]; let best1 = best(candidates.iter().cloned()).unwrap(); let (best2, backup2) = best_backup(candidates.iter()); let (best2, backup2) = (best2.unwrap(), backup2.unwrap()); assert_eq!(best1.pa_map(), best2.pa_map()); assert_eq!(best1.tiebreakers(), best2.tiebreakers()); dbg!(&best2); dbg!(&backup2); assert_ne!( (best2.pa_map(), best2.tiebreakers()), (backup2.pa_map(), backup2.tiebreakers()) ); ``` -------------------------------- ### Compose and Convert AS Path (32-bit to 16-bit) Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/aspath.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates composing a 32-bit AS path from a HopPath and then converting it to a 16-bit AS path. Asserts that the converted path is shorter and that converting back yields the original 32-bit path. ```rust let mut hp = HopPath::new(); hp.prepend_arr([10, 20, 30, 40].map(Asn::from_u32)); let asp: AsPath> = hp.to_as_path().unwrap(); let asp16: AsPath> = hp.try_to_asn16_path().unwrap(); assert_eq!(asp, asp16); assert!(asp.octets.len() > asp16.octets.len()); // back to four octets let hp2 = asp16.to_hop_path(); let asp2: AsPath> = hp2.to_as_path().unwrap(); assert_eq!(asp, asp2); assert!(asp.octets.len() == asp2.octets.len()); ``` -------------------------------- ### Get RouteDistinguisher Type Source: https://docs.rs/routecore/0.7.2/routecore/bgp/nlri/mpls_vpn/struct.RouteDistinguisher.html Returns the type of the RouteDistinguisher. ```rust pub fn typ(&self) -> RouteDistinguisherType ``` -------------------------------- ### Get FourOctetAsns Setting Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update.rs.html?search= Retrieves the current setting for FourOctetAsns. ```rust pub fn four_octet_asns(&self) -> FourOctetAsns { self.four_octet_asns } ``` -------------------------------- ### Initialize MpReachNlriBuilder Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update_builder.rs.html?search= Creates a new MpReachNlriBuilder with an empty list of announcements and a default NextHop based on the AfiSafi. This is useful when only setting the nexthop. ```rust pub fn new() -> Self { Self { announcements: Vec::new(), nexthop: NextHop::new(A::afi_safi()) } } ``` -------------------------------- ### OpenBuilder Initialization Source: https://docs.rs/routecore/0.7.2/routecore/bgp/message/open/struct.OpenBuilder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides methods to initialize an OpenBuilder instance. ```APIDOC ## OpenBuilder Initialization ### `new_vec()` Creates a new `OpenBuilder` instance with a `Vec` as the target. #### Returns - `OpenBuilder>`: A new instance of `OpenBuilder`. ### `from_target(target: Target)` Creates a new `OpenBuilder` instance from a given `Target`. #### Parameters - **target** (`Target`): The target builder to use. #### Returns - `Result`: A `Result` containing the `OpenBuilder` on success, or a `ShortBuf` error on failure. ``` -------------------------------- ### SessionAddpaths Get Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update.rs.html?search= Retrieves the AddpathDirection for a given AfiSafiType, if present. ```rust fn get(&self, afisafi: AfiSafiType) -> Option { self.0.get(&afisafi).copied() } ``` -------------------------------- ### Get NLRI Source: https://docs.rs/routecore/0.7.2/routecore/bgp/workshop/route/struct.Route.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns an immutable reference to the NLRI of the Route. ```rust pub fn nlri(&self) -> &N ``` -------------------------------- ### Initialize MpUnreachNlriBuilder Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update_builder.rs.html?search= Provides methods to create new MpUnreachNlriBuilder instances. `new()` creates an empty builder, while `from()` initializes it with a single withdrawal. ```rust pub fn new() -> Self { Self { withdrawals: Vec::new(), } } ``` ```rust pub fn from(withdrawal: A) -> Self { Self { withdrawals: vec![withdrawal], } } ``` -------------------------------- ### Get TiebreakerInfo Source: https://docs.rs/routecore/0.7.2/routecore/bgp/path_selection/struct.OrdRoute.html?search=std%3A%3Avec Retrieves the TiebreakerInfo associated with an OrdRoute instance. ```rust pub fn tiebreakers(&self) -> TiebreakerInfo ``` -------------------------------- ### Initialize Parameters Parser Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/open.rs.html?search=u32+-%3E+bool Creates a `ParametersParser` to iterate over the Optional Parameters of the BGP OPEN message. It advances the parser past the fixed header fields and the optional parameters length field. ```rust fn parameters_iter(&self) -> ParametersParser<'_, Octs> { let mut p = Parser::from_ref(&self.octets); p.advance(COFF+10).unwrap(); ``` -------------------------------- ### OpenBuilder Initialization Source: https://docs.rs/routecore/0.7.2/routecore/bgp/message/open/struct.OpenBuilder.html?search=std%3A%3Avec Provides methods to create a new OpenBuilder instance, either from a target builder or as a new vector. ```APIDOC ## OpenBuilder Initialization ### `from_target(target: Target) -> Result` Creates an `OpenBuilder` from an existing `OctetsBuilder`. ### `new_vec() -> Self` Creates a new `OpenBuilder` that builds into a `Vec`. ``` -------------------------------- ### Get FourOctetAsns Setting Source: https://docs.rs/routecore/0.7.2/routecore/bgp/message/update/struct.PduParseInfo.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the FourOctetAsns configuration from the PduParseInfo. ```rust pub fn four_octet_asns(&self) -> FourOctetAsns ``` -------------------------------- ### Get the IPv6 address from Ipv6ExtendedCommunity Source: https://docs.rs/routecore/0.7.2/routecore/bgp/communities/struct.Ipv6ExtendedCommunity.html Extracts the Ipv6Addr from the Ipv6ExtendedCommunity. ```rust pub fn ip6(self) -> Ipv6Addr ``` -------------------------------- ### MpReachNlriBuilder for NextHop Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update_builder.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes an MpReachNlriBuilder with an empty announcement list and a specified NextHop. ```rust pub fn for_nexthop(nexthop: NextHop) -> Self { Self { announcements: Vec::new(), nexthop, } } ``` -------------------------------- ### Compare AS Path Length (Step a) Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/path_selection.rs.html?search= Compares routes based on the length of their AS path. Shorter AS paths are preferred. This step assumes AS_SET counts as a single hop. ```rust match ( self.pa_map.get::(), other.pa_map.get::(), ) { (Some(a), Some(b)) => a .hop_count_path_selection() .cmp(&b.hop_count_path_selection()), (_, _) => { panic!("can not compare routes lacking AS_PATH"); //cmp::Ordering::Equal } } ``` -------------------------------- ### Get Attribute from RouteWorkshop Source: https://docs.rs/routecore/0.7.2/routecore/bgp/workshop/route/struct.RouteWorkshop.html?search=std%3A%3Avec Retrieves a specific workshop attribute from the RouteWorkshop. ```rust pub fn get_attr>(&self) -> Option ``` -------------------------------- ### Get NextHop from RouteWorkshop Source: https://docs.rs/routecore/0.7.2/routecore/bgp/workshop/route/struct.RouteWorkshop.html?search=std%3A%3Avec Returns a reference to the NextHop option in the RouteWorkshop. ```rust pub fn nexthop(&self) -> &Option ``` -------------------------------- ### Header Creation and Access Source: https://docs.rs/routecore/0.7.2/routecore/bgp/message/struct.Header.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to create a new Header, create a Header from a slice, and access its length and message type. ```APIDOC ## Header Struct ### Description Represents a BGP Message header. ### Methods #### `new()` - **Description**: Creates a new Header with a default `Vec`. - **Signature**: `pub fn new() -> Header>` #### `for_slice(s: Octs)` - **Description**: Creates a Header from an Octets type. - **Signature**: `pub fn for_slice(s: Octs) -> Self` #### `for_slice_mut(s: &mut [u8])` - **Description**: Creates a mutable Header from a mutable byte slice. - **Signature**: `pub fn for_slice_mut(s: &mut [u8]) -> Header<&mut [u8]>` #### `length()` - **Description**: Returns the value of the length field in this header. - **Returns**: `u16` - The length of the BGP message. - **Signature**: `pub fn length(&self) -> u16` #### `msg_type()` - **Description**: Returns the value of the message type field in this header. - **Returns**: `MsgType` - The type of the BGP message. - **Signature**: `pub fn msg_type(&self) -> MsgType ``` -------------------------------- ### Get Mutable Attributes Source: https://docs.rs/routecore/0.7.2/routecore/bgp/workshop/route/struct.Route.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns a mutable reference to all attributes of the Route. ```rust pub fn attributes_mut(&mut self) -> &mut PaMap ``` -------------------------------- ### Get Nlri Reference Source: https://docs.rs/routecore/0.7.2/routecore/bgp/nlri/afisafi/struct.Ipv4MplsUnicastNlri.html?search=u32+-%3E+bool Returns a reference to the inner Nlri data. ```rust fn nlri(&self) -> &Self::Nlri ``` -------------------------------- ### Create a New BTreeMap Source: https://docs.rs/routecore/0.7.2/routecore/bgp/path_attributes/type.AttributesMap.html?search=u32+-%3E+bool Demonstrates how to create a new, empty BTreeMap. No allocation is performed by default. ```rust use std::collections::BTreeMap; let mut map = BTreeMap::new(); // entries can now be inserted into the empty map map.insert(1, "a"); ``` -------------------------------- ### Get Global Part of LargeCommunity Source: https://docs.rs/routecore/0.7.2/routecore/bgp/communities/struct.LargeCommunity.html?search=std%3A%3Avec Retrieves the global component of the LargeCommunity. ```rust pub fn global(self) -> u32 ``` -------------------------------- ### Creating Standard Communities Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/communities.rs.html Shows how to create StandardCommunity instances from canonical string notations, hexadecimal representations, or raw byte arrays. ```rust use routecore::bgp::communities::{Community, StandardCommunity, Wellknown}; use std::str::FromStr; // Specific community variants can be created by parsing strings of // canonical notations, hexadecimal representations, or raw input: let c1 = StandardCommunity::from_str("AS1234:7890").unwrap(); assert_eq!(c1.to_raw(), [0x04, 0xD2, 0x1E, 0xD2]); let c2 = StandardCommunity::from_str("0x04D21ED2").unwrap(); assert_eq!(c1, c2); let c3 = StandardCommunity::from_raw([0x04, 0xD2, 0x1E, 0xD2]); assert_eq!(c1, c3); ``` -------------------------------- ### Prepend ASNs and Segments to HopPath Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/aspath.rs.html Shows how to build an AS Path by prepending individual ASNs, sequences of ASNs, and AS Sets to a HopPath. This is useful for constructing AS Paths programmatically. ```rust let mut hp = HopPath::new(); hp.prepend(Asn::from_u32(100)); hp.prepend_n(Asn::from_u32(200), 3); hp.prepend(Segment::new_set([Asn::from_u32(98), Asn::from_u32(99)])); hp.prepend_arr([Asn::from_u32(300), Asn::from_u32(400)]); let asp = hp.to_as_path::>().unwrap(); assert_eq!( asp.to_string(), "AS_SEQUENCE(AS300, AS400), AS_SET(AS98, AS99), \ AS_SEQUENCE(AS200, AS200, AS200, AS100)" ); ``` -------------------------------- ### Get Origin Hop Source: https://docs.rs/routecore/0.7.2/routecore/bgp/aspath/struct.AsPath.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the right-most Hop of this AsPath, if it exists. ```rust pub fn origin(&self) -> Option>> ``` -------------------------------- ### type_id Source: https://docs.rs/routecore/0.7.2/routecore/bgp/aspath/enum.Hop.html Gets the TypeId of the Hop instance. This is part of the Any trait implementation. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method GET (conceptual) ### Endpoint N/A (SDK method) ### Parameters None ### Response #### Success Response - **TypeId** (TypeId) - The unique identifier for the type of the Hop instance. ``` -------------------------------- ### MpUnreachNlriBuilder::new Source: https://docs.rs/routecore/0.7.2/routecore/bgp/message/update_builder/struct.MpUnreachNlriBuilder.html Creates a new, empty MpUnreachNlriBuilder. ```APIDOC ## MpUnreachNlriBuilder::new ### Description Creates a new, empty `MpUnreachNlriBuilder`. ### Method ```rust pub fn new() -> Self ``` ### Returns A new instance of `MpUnreachNlriBuilder`. ``` -------------------------------- ### MpUnreachNlriBuilder::new Source: https://docs.rs/routecore/0.7.2/routecore/bgp/message/update_builder/struct.MpUnreachNlriBuilder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new, empty MpUnreachNlriBuilder. ```APIDOC ## MpUnreachNlriBuilder::new ### Description Creates a new, empty MpUnreachNlriBuilder. ### Method `MpUnreachNlriBuilder::new()` ### Returns A new instance of `MpUnreachNlriBuilder`. ``` -------------------------------- ### RouteTargetNlri Parsing Example Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/nlri/routetarget.rs.html?search= Demonstrates how to parse a sequence of RouteTargetNlri from raw bytes. ```APIDOC ## RouteTargetNlri Parsing ### Description This example shows how to parse multiple `RouteTargetNlri` instances from a byte slice. ### Code Example ```rust use octseq::Parser; use routecore::bgp::nlri::RouteTargetNlri; let raw = vec![ 0x60, 0x00, 0x00, 0x00, 0x64, 0x00, 0x02, 0x00, 0x64, 0x00, 0x00, 0x00, 0x01, 0x60, 0x00, 0x00, 0x00, 0x64, 0x01, 0x02, 0x0a, 0x00, 0x00, 0x02, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x64, 0x01, 0x02, 0x0a, 0x00, 0x00, 0x02, 0x00, 0x01 ]; let mut parser = Parser::from_ref(&raw); let mut nlris = vec![]; while parser.remaining() > 0 { nlris.push(RouteTargetNlri::parse(&mut parser).unwrap()); } assert_eq!(nlris.len(), 3); // Further assertions can be made on the parsed nlris ``` ``` -------------------------------- ### Default PduParseInfo Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update.rs.html?search= Initializes PduParseInfo with default settings, including enabling four-octet ASNs and default PduAddpaths. ```rust fn default() -> Self { Self { four_octet_asns: FourOctetAsns(true), pdu_addpaths: PduAddpaths::default(), } } ``` -------------------------------- ### Get EncodedPathAttribute PDU Parse Info Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/path_attributes.rs.html?search=u32+-%3E+bool Returns the PduParseInfo associated with the EncodedPathAttribute. ```rust pub fn pdu_parse_info(&self) -> PduParseInfo { self.pdu_parse_info } ``` -------------------------------- ### BGP Path Selection with Tiebreakers Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/path_selection.rs.html?search= Demonstrates selecting the best and backup BGP routes from a set of candidates using predefined tiebreakers. This is useful for simulating and testing BGP route selection logic. ```rust b_pamap.set(MultiExitDisc(50)); let mut c_pamap = PaMap::empty(); c_pamap.set(Origin(OriginType::Egp)); c_pamap.set(HopPath::from([80, 90, 100, 200, 300])); let candidates = [ OrdRoute::skip_med(&a_pamap, tiebreakers).unwrap(), OrdRoute::skip_med(&b_pamap, tiebreakers).unwrap(), OrdRoute::skip_med(&a_pamap, tiebreakers).unwrap(), //OrdRoute::skip_med(&c_pamap, tiebreakers).unwrap(), ]; let best1 = best(candidates.iter().cloned()).unwrap(); let (best2, backup2) = best_backup(candidates.iter()); let (best2, backup2) = (best2.unwrap(), backup2.unwrap()); assert_eq!(best1.pa_map(), best2.pa_map()); assert_eq!(best1.tiebreakers(), best2.tiebreakers()); dbg!(&best2); dbg!(&backup2); assert_ne!( (best2.pa_map(), best2.tiebreakers()), (backup2.pa_map(), backup2.tiebreakers()) ); ``` -------------------------------- ### Get EncodedPathAttribute Flags Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/path_attributes.rs.html Retrieves the flags from the beginning of the encoded path attribute. ```Rust pub fn flags(&self) -> Flags { self.parser.peek_all()[0].into() } ``` -------------------------------- ### MpReachNlriBuilder::for_nlri_and_nexthop() Source: https://docs.rs/routecore/0.7.2/routecore/bgp/message/update_builder/struct.MpReachNlriBuilder.html?search= Initializes an MpReachNlriBuilder with both an NLRI value and a next-hop address. This is a convenient way to set up the builder with initial data. ```rust pub fn for_nlri_and_nexthop(nlri: A, nexthop: NextHop) -> Self ``` -------------------------------- ### Get Human-Readable Communities Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update.rs.html Retrieves an iterator over Standard Communities formatted as HumanReadableCommunity. ```APIDOC ## Get Human-Readable Communities ### Description Retrieves an iterator over Standard Communities (RFC1997) formatted as `HumanReadableCommunity` if they exist in the Update Message. ### Method ``` pub fn human_readable_communities(&self) -> Result, crate::bgp::communities::HumanReadableCommunity>>, ParseError> ``` ### Returns - `Result>, ParseError>`: An iterator over `HumanReadableCommunity` if found, otherwise `None`. Returns `ParseError` on failure. ``` -------------------------------- ### Creating AS Path Segments Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/aspath.rs.html?search=std%3A%3Avec Demonstrates the creation of different AS Path segment types including new_set, new_confed_set, and new_confed_sequence. Also shows handling of paths exceeding maximum ASN counts. ```rust vec![Segment::new_set([10, 20, 30].map(Asn::from_u32))].into() vec![ Segment::new_confed_set([10, 20, 30].map(Asn::from_u32)), Segment::new_confed_sequence([10, 20, 30].map(Asn::from_u32)), //Segment::new_sequence([10, 20, 30].map(Asn::from_u32)), ].into() [Asn::from_u32(123); 254].to_vec().into() [Asn::from_u32(123); 255].to_vec().into() [Asn::from_u32(123); 256].to_vec().into() [Asn::from_u32(123); 257].to_vec().into() ``` -------------------------------- ### Get All Human-Readable Communities Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves a vector of all communities formatted as HumanReadableCommunity, if any exist. ```APIDOC ## GET /all_human_readable_communities ### Description Returns an optional `Vec` containing all conventional, Extended, and Large communities, formatted as `HumanReadableCommunity`, if any are present in the BGP Update message. Returns `None` if none of these community types are found. ### Method GET ### Endpoint This is a method call on an UpdateMessage object, not a direct HTTP endpoint. ### Parameters None ### Request Example ```rust // Assuming 'update_message' is an instance of UpdateMessage let all_hr_communities_result = update_message.all_human_readable_communities(); ``` ### Response #### Success Response - **Result** (Result>, ParseError>) - An optional vector of all communities in human-readable format or None if none are present. ``` -------------------------------- ### Get Next-Hop Address Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update_builder.rs.html?search= Retrieves a reference to the current next-hop address configuration. ```rust pub(crate) fn get_nexthop(&self) -> &NextHop { &self.nexthop } ``` -------------------------------- ### Create BTreeMap with Allocator Source: https://docs.rs/routecore/0.7.2/routecore/bgp/path_attributes/type.AttributesMap.html?search=u32+-%3E+bool Shows how to create a new BTreeMap with a specific allocator. Requires the `btreemap_alloc` feature. ```rust use std::collections::BTreeMap; use std::alloc::Global; let map: BTreeMap = BTreeMap::new_in(Global); ``` -------------------------------- ### MpReachNlriBuilder::for_nexthop Source: https://docs.rs/routecore/0.7.2/routecore/bgp/message/update_builder/struct.MpReachNlriBuilder.html Creates a new MpReachNlriBuilder pre-configured with a specific next-hop. ```APIDOC ## MpReachNlriBuilder::for_nexthop ### Description Creates a new `MpReachNlriBuilder` initialized with the provided next-hop address. ### Method `for_nexthop(nexthop: NextHop)` ### Parameters * `nexthop` (NextHop): The next-hop address to initialize the builder with. ### Returns A new `MpReachNlriBuilder` instance. ``` -------------------------------- ### Get Attributes from RouteWorkshop Source: https://docs.rs/routecore/0.7.2/routecore/bgp/workshop/route/struct.RouteWorkshop.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns a reference to the PaMap containing all attributes of the RouteWorkshop. ```rust pub fn attributes(&self) -> &PaMap ``` -------------------------------- ### Get PathAttributes Iterator Source: https://docs.rs/routecore/0.7.2/routecore/bgp/path_attributes/struct.OwnedPathAttributes.html?search= Returns a PathAttributes iterator over the owned path attributes. ```rust pub fn iter(&self) -> PathAttributes<'_, Vec> ``` -------------------------------- ### MplsNlri::new Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/nlri/mpls.rs.html?search=u32+-%3E+bool Constructor for creating a new MplsNlri instance. ```APIDOC ## MplsNlri::new ### Description Creates a new `MplsNlri` instance with the provided prefix and labels. ### Signature `pub fn new(prefix: Prefix, labels: Labels) -> Self` ### Parameters - **prefix**: `Prefix` - The network prefix. - **labels**: `Labels` - The MPLS labels. ``` -------------------------------- ### Initialize Parameters Parser Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/open.rs.html?search=std%3A%3Avec Initializes a `ParametersParser` to iterate over the Optional Parameters of a BGP OPEN message. It advances the parser past the fixed header fields. ```rust impl OpenMessage { /// Returns an iterator over the Optional Parameters. pub fn parameters(&self) -> ParametersParser<'_, Octs> { self.parameters_iter() } fn parameters_iter(&self) -> ParametersParser<'_, Octs> { let mut p = Parser::from_ref(&self.octets); p.advance(COFF+10).unwrap(); ``` -------------------------------- ### Get Parameter Value Source: https://docs.rs/routecore/0.7.2/routecore/bgp/message/open/struct.Parameter.html Returns the raw value of the parameter as an Octets Range. ```rust pub fn value(&self) -> Octs::Range<'_> ``` -------------------------------- ### StandardCommunity Byte Representation Source: https://docs.rs/routecore/0.7.2/routecore/bgp/communities/struct.StandardCommunity.html?search=std%3A%3Avec Explains how to get a byte slice representation of a StandardCommunity. ```APIDOC ## StandardCommunity Byte Representation This section covers obtaining a byte slice representation of a `StandardCommunity`. ### `impl AsRef<[u8]> for StandardCommunity` #### `fn as_ref(&self) -> &[u8]` Returns a reference to the underlying byte slice representation of the `StandardCommunity`. ``` -------------------------------- ### Creating AS Path Segments Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/aspath.rs.html?search= Demonstrates the creation of different AS Path segment types: new_set, new_confed_set, and new_confed_sequence. Also shows handling of ASNs that exceed the u16 limit. ```rust vec![Segment::new_set([10, 20, 30].map(Asn::from_u32))].into(), vec![ Segment::new_confed_set([10, 20, 30].map(Asn::from_u32)), Segment::new_confed_sequence([10, 20, 30].map(Asn::from_u32)), ].into(), ``` -------------------------------- ### Get minimum of two Ipv6ExtendedCommunity Source: https://docs.rs/routecore/0.7.2/routecore/bgp/communities/struct.Ipv6ExtendedCommunity.html Implements the min method from the Ord trait. ```rust fn min(self, other: Self) -> Self where Self: Sized, ``` -------------------------------- ### Create and Inspect Extended Communities Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/communities.rs.html?search=std%3A%3Avec Demonstrates creating various types of Extended Communities (route targets, route origins) using builder methods and raw byte arrays. Includes string parsing and conversion. ```rust use ExtendedCommunity as EC; let ec1 = EC::transitive_as2_route_target(1234_u16.into(), 6789); println!("{}", ec1); let ec2 = EC::transitive_as4_route_target(1234_u32.into(), 6789); println!("{}", ec2); let ec3 = EC::transitive_ip4_route_target( Ipv4Addr::from_str("127.0.0.1").unwrap(), 6789 ); println!("{}", ec3); let ec4 = EC::from_raw([10, 10, 1, 2, 3, 4, 5, 6]); println!("{}", ec4); assert_eq!( ec4, EC::from_str("0x0A0A010203040506").unwrap() ); ``` -------------------------------- ### MpUnreachNlriBuilder Initialization and Composition Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update_builder.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides methods for creating, initializing, and composing MpUnreachNlriBuilder. Includes constructors, splitting functionality, length calculation, and value composition. ```rust pub fn new() -> Self { Self { withdrawals: Vec::new(), } } ``` ```rust pub fn from(withdrawal: A) -> Self { Self { withdrawals: vec![withdrawal], } } ``` ```rust pub(crate) fn split(&mut self, n: usize) -> Self { let this_batch = self.withdrawals.drain(..n).collect(); MpUnreachNlriBuilder { withdrawals: this_batch, } } ``` ```rust pub(crate) fn value_len(&self) -> usize { 3 + self.withdrawals.iter().fold(0, |sum, w| sum + w.compose_len()) } ``` ```rust pub(crate) fn is_empty(&self) -> bool { self.withdrawals.is_empty() } ``` ```rust pub fn add_withdrawal(&mut self, nlri: A) { self.withdrawals.push(nlri); } ``` ```rust pub(crate) fn compose_value(&self, target: &mut Target) -> Result<(), Target::AppendError> { target.append_slice(&A::afi_safi().as_bytes())?; for w in &self.withdrawals { w.compose(target)?; } Ok(()) } ``` -------------------------------- ### Get maximum of two Ipv6ExtendedCommunity Source: https://docs.rs/routecore/0.7.2/routecore/bgp/communities/struct.Ipv6ExtendedCommunity.html Implements the max method from the Ord trait. ```rust fn max(self, other: Self) -> Self where Self: Sized, ``` -------------------------------- ### Get ExtendedCommunity Types Source: https://docs.rs/routecore/0.7.2/routecore/bgp/communities/struct.ExtendedCommunity.html Retrieves the specific ExtendedCommunityType and ExtendedCommunitySubType from an ExtendedCommunity instance. ```rust pub fn types(self) -> (ExtendedCommunityType, ExtendedCommunitySubType) ``` -------------------------------- ### Parameter Creation from Slice Source: https://docs.rs/routecore/0.7.2/routecore/bgp/message/open/struct.Parameter.html?search= Demonstrates how to create a Parameter instance directly from a slice of octets. ```APIDOC ## `for_slice(slice: Octs) -> Self` ### Description Creates a `Parameter` instance from a given slice of octets. ### Parameters * `slice` (Octs) - The slice of octets representing the parameter value. ``` -------------------------------- ### Build Basic IPv4 Withdrawals with Add-Path Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update_builder.rs.html Demonstrates building a BGP UPDATE message with IPv4 withdrawals and Add-Path capabilities, then verifying its integrity. ```rust #[test] fn build_withdrawals_basic_v4_addpath() { let mut builder = UpdateBuilder::new_vec(); let withdrawals = [ "0.0.0.0/0", "10.2.1.0/24", "10.2.2.0/24", "10.2.0.0/23", "10.2.4.0/25", "10.0.0.0/7", "10.0.0.0/8", "10.0.0.0/9", ].iter().enumerate().map(|(idx, s)| Ipv4UnicastNlri::from_str(s).unwrap() .into_addpath(PathId(idx.try_into().unwrap())) ).collect::>(); let _ = builder.append_withdrawals(withdrawals); let msg = builder.finish(&SessionConfig::modern()).unwrap(); let mut sc = SessionConfig::modern(); sc.add_addpath_rxtx(AfiSafiType::Ipv4Unicast); assert!( UpdateMessage::from_octets(&msg, &sc) .is_ok() ); print_pcap(&msg); } ``` -------------------------------- ### Get a specific hop by index Source: https://docs.rs/routecore/0.7.2/routecore/bgp/aspath/struct.HopPath.html Retrieves a hop at a given index from the HopPath. ```rust pub fn get_hop(&self, index: usize) -> Option<&OwnedHop> ``` -------------------------------- ### MpReachNlriBuilder::new Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update_builder.rs.html?search=u32+-%3E+bool Creates a new MpReachNlriBuilder with an empty list of announcements and a NextHop initialized for the builder's AfiSafi. ```rust impl MpReachNlriBuilder { pub fn new() -> Self { Self { announcements: Vec::new(), nexthop: NextHop::new(A::afi_safi()) } } // ... other methods ``` -------------------------------- ### Converting Slices and Vecs to HopPath Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/aspath.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shows various ways to initialize a HopPath from slices of ASNs, vectors of ASNs, and arrays of ASNs. Also demonstrates `try_into` for Hop to Asn conversion. ```rust fn froms_and_intos() { let asns = vec![Asn::from_u32(100), Asn::from_u32(200)]; let hp: HopPath = (&asns[..]).into(); assert_eq!( hp.to_as_path::>().unwrap().to_string(), "AS_SEQUENCE(AS100, AS200)" ); let hp: HopPath = asns.into(); assert_eq!( hp.to_as_path::>().unwrap().to_string(), "AS_SEQUENCE(AS100, AS200)" ); let hp: HopPath = [Asn::from_u32(100), Asn::from_u32(200)].into(); assert_eq!( hp.to_as_path::>().unwrap().to_string(), "AS_SEQUENCE(AS100, AS200)" ); assert_eq!( Hop::>::Asn(Asn::from_u32(1234)).try_into(), Ok(Asn::from_u32(1234)) ); assert_eq!( Hop::>::Asn(Asn::from_u32(1234)).try_into(), Hop::>::Asn(Asn::from_u32(1234)).try_into_asn() ); let hop: OwnedHop = Segment::new_set([Asn::from_u32(10)]).into(); assert!(TryInto::::try_into(hop.clone()).is_err()); assert!(hop.try_into_asn().is_err()); } ``` -------------------------------- ### Get EncodedPathAttribute Flags Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/path_attributes.rs.html?search=u32+-%3E+bool Parses and returns the flags from the beginning of the EncodedPathAttribute's data. ```rust pub fn flags(&self) -> Flags { self.parser.peek_all()[0].into() } ``` -------------------------------- ### Get EncodedPathAttribute Type Code Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/path_attributes.rs.html Retrieves the type code from the encoded path attribute. ```Rust pub fn type_code(&self) -> u8 { self.parser.peek_all()[1] } ``` -------------------------------- ### Header Creation and Access Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/mod.rs.html?search=std%3A%3Avec Demonstrates how to create a new BGP message header with default values and how to access its length and message type. ```APIDOC ## Header Creation and Access ### Description This section shows how to instantiate a new BGP message header and retrieve its length and message type. ### Methods - **`Header::new()`**: Creates a new `Header` with default values (marker set to `0xff`, length to 19, and type to 0). - **`Header::length()`**: Returns the length of the BGP message as a `u16`. - **`Header::msg_type()`**: Returns the type of the BGP message as a `MsgType` enum. ### Example ```rust // Assuming `Header` is in scope and `Octs` is a suitable type like Vec let mut header = Header::>::new(); // Set message type to Open header.set_type(MsgType::Open); // Get the message type let msg_type = header.msg_type(); // Should be MsgType::Open // Get the message length let length = header.length(); // Will be the initial default length ``` ### Response - **`Header::new()`**: Returns a `Header>`. - **`Header::length()`**: Returns a `u16` representing the message length. - **`Header::msg_type()`**: Returns a `MsgType` enum variant. ``` -------------------------------- ### PduParseInfo Constructors Source: https://docs.rs/routecore/0.7.2/routecore/bgp/message/update/struct.PduParseInfo.html?search= Provides methods to create PduParseInfo instances with different configurations for ASN sizes and AddPath settings. ```APIDOC ## PduParseInfo Constructors ### `modern()` Creates a `PduParseInfo` for 32bit ASNs, no AddPath set. ### `legacy()` Creates a `PduParseInfo` for 16bit ASNs, no AddPath set. ### `from_session_config(sc: &SessionConfig, mp_reach_afisafi: Option, mp_unreach_afisafi: Option) -> Self` Creates a `PduParseInfo` from a `SessionConfig` and address families. This constructor takes two optional address families, describing the `AfiSafi` for the MP_REACH and MP_UNREACH path attributes in the BGP UPDATE message. These can be used to match upon to get a typed NLRI iterator (e.g. [`typed_announcements`]) from the message. ``` -------------------------------- ### Get MP_UNREACH AddPath Status Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update.rs.html?search=std%3A%3Avec Retrieves the AddPath status for the MP_UNREACH NLRI section. ```rust pub(crate) fn mp_unreach(self) -> bool { self.mp_unreach } ``` -------------------------------- ### Get MP_REACH AddPath Status Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update.rs.html?search=std%3A%3Avec Retrieves the AddPath status for the MP_REACH NLRI section. ```rust pub(crate) fn mp_reach(self) -> bool { self.mp_reach } ``` -------------------------------- ### Creating Standard BGP Communities Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/communities.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shows how to create Standard BGP communities using canonical string notation, hexadecimal representations, or raw byte arrays. Useful for constructing specific community values. ```rust use routecore::bgp::communities::{Community, StandardCommunity, Wellknown}; use std::str::FromStr; // Specific community variants can be created by parsing strings of // canonical notations, hexadecimal representations, or raw input: let c1 = StandardCommunity::from_str("AS1234:7890").unwrap(); assert_eq!(c1.to_raw(), [0x04, 0xD2, 0x1E, 0xD2]); let c2 = StandardCommunity::from_str("0x04D21ED2").unwrap(); assert_eq!(c1, c2); let c3 = StandardCommunity::from_raw([0x04, 0xD2, 0x1E, 0xD2]); assert_eq!(c1, c3); ``` -------------------------------- ### MpReachNlriBuilder New Constructor Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update_builder.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new MpReachNlriBuilder with an empty list of announcements and a default NextHop based on the AfiSafi type. ```rust impl MpReachNlriBuilder { pub fn new() -> Self { Self { announcements: Vec::new(), nexthop: NextHop::new(A::afi_safi()) } } // ... other methods ... ``` -------------------------------- ### Get Conventional AddPath Status Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update.rs.html?search=std%3A%3Avec Retrieves the AddPath status for the conventional NLRI section. ```rust pub(crate) fn conventional(self) -> bool { self.conventional } ``` -------------------------------- ### Get All Communities Source: https://docs.rs/routecore/0.7.2/src/routecore/bgp/message/update.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves a vector containing all conventional, Extended, and Large communities, if any exist. ```APIDOC ## GET /all_communities ### Description Returns an optional `Vec` containing all conventional, Extended, and Large communities, if any are present in the BGP Update message. Returns `None` if none of these community types are found. ### Method GET ### Endpoint This is a method call on an UpdateMessage object, not a direct HTTP endpoint. ### Parameters None ### Request Example ```rust // Assuming 'update_message' is an instance of UpdateMessage let all_communities_result = update_message.all_communities(); ``` ### Response #### Success Response - **Result** (Result>, ParseError>) - An optional vector of all communities or None if none are present. ```