Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl From<PaMap> for OwnedPathAttributes #63

Open
density215 opened this issue Feb 10, 2025 · 1 comment
Open

impl From<PaMap> for OwnedPathAttributes #63

density215 opened this issue Feb 10, 2025 · 1 comment

Comments

@density215
Copy link
Member

While trying to write tests best path selection in rotonda-store - which requires From<Vec<u8>> and Into<Vec<u8>> for types to be stored - I need a way to create OwnedPathAttributes from scratch (so not from an existing PDUs). One way could be to create an empty PaMap and try to convert that into a PathAttributes.

I though a (convoluted) way could be:

OwnedPathAttributes::from((
    PduParseInfo::modern(),
    UpdateBuilder::<Vec<u8>>, Ipv4UnicastNlri>::from_attributes_builder(pa_map)
        .into_pdu_iter(&SessionConfig::modern())
        .next()
        .unwrap()
        .unwrap()
        .octets()
        .to_vec(),
));

This is incorrect, however.

Having an From<..> impl for this, would allow OrdRoute to take &OwnedPathAttributes as argument, instead of &PaMap. This would be handy, since Rotonda itself stores OwnedPathAttributes as its meta type in the store.

@DRiKE
Copy link
Collaborator

DRiKE commented Feb 11, 2025

This raises some nice points for the ongoing refactor of the path attributes, which we'll need to discuss a bit more, but for now maybe this can get things going:

let mut pamap = PaMap::empty();
pamap.set(crate::bgp::types::Origin(OriginType::Igp));
let mut buf = Vec::new();
for pa in pamap.attributes.values() {
    pa.compose(&mut buf).unwrap();
}
let owned = OwnedPathAttributes::from((PduParseInfo::modern(), buf));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants