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

Compatibility with latest routecore changes #46

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
errors: Vec<RotoError>,
}

impl RotoReport {
pub fn errors(&self) -> &[RotoError] {

Check failure on line 33 in src/pipeline.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0)

private type `RotoError` in public interface

Check failure on line 33 in src/pipeline.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --no-default-features)

private type `RotoError` in public interface

Check failure on line 33 in src/pipeline.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --all-features)

private type `RotoError` in public interface
&self.errors
}
}

impl std::fmt::Display for RotoReport {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use ariadne::{Color, Label, Report, ReportKind};
Expand Down
234 changes: 204 additions & 30 deletions src/types/builtin/basic_route.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::hash::Hash;
use std::hash::Hasher;
use std::net::IpAddr;
use std::net::Ipv4Addr;

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0)

unused import: `std::net::Ipv4Addr`

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --no-default-features)

unused import: `std::net::Ipv4Addr`

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --all-features)

unused import: `std::net::Ipv4Addr`

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --all-features)

unused import: `std::net::Ipv4Addr`

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --no-default-features)

unused import: `std::net::Ipv4Addr`

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly)

unused import: `std::net::Ipv4Addr`

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --all-features)

unused import: `std::net::Ipv4Addr`

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta)

unused import: `std::net::Ipv4Addr`

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --no-default-features)

unused import: `std::net::Ipv4Addr`

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --no-default-features)

unused import: `std::net::Ipv4Addr`

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --all-features)

unused import: `std::net::Ipv4Addr`

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --all-features)

unused import: `std::net::Ipv4Addr`

Check warning on line 4 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

unused import: `std::net::Ipv4Addr`
use std::net::SocketAddr;

use chrono::Utc;
use routecore::bgp::communities::Community;
use routecore::bgp::communities::HumanReadableCommunity;
use routecore::bgp::message::update_builder::ComposeError;
use routecore::bgp::nlri::afisafi::Ipv4FlowSpecNlri;
use routecore::bgp::nlri::afisafi::Ipv6FlowSpecNlri;
use routecore::bgp::nlri::afisafi::Ipv4UnicastNlri;
use routecore::bgp::nlri::afisafi::Ipv4UnicastAddpathNlri;
use routecore::bgp::nlri::afisafi::Ipv6UnicastNlri;
Expand All @@ -17,7 +19,7 @@
use routecore::bgp::nlri::afisafi::Ipv6MulticastNlri;
use routecore::bgp::nlri::afisafi::Ipv6MulticastAddpathNlri;
use routecore::bgp::workshop::route::WorkshopAttribute;
use crate::types::builtin::FlowSpecNlri::Ipv4FlowSpec;
use crate::types::builtin::FlowSpecNlri::{Ipv4FlowSpec, Ipv6FlowSpec};
use routecore::bgp::nlri::afisafi::IsPrefix;
use routecore::bgp::path_attributes::PaMap;
use routecore::bgp::path_attributes::PathAttribute;
Expand Down Expand Up @@ -403,8 +405,10 @@
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
pub struct RouteContext {
pub(crate) bgp_msg: Option<BytesRecord<BgpUpdateMessage>>,
pub(crate) provenance: Provenance,
pub(crate) nlri_status: NlriStatus,
pub(crate) provenance: Provenance,
// reprocessing: bool // true if this RouteContext is attached to values
// facilitating a query (and thus the bgp_msg itself likely is None).
}

impl RouteContext {
Expand All @@ -419,19 +423,33 @@
provenance,
}
}
pub fn for_reprocessing(
nlri_status: NlriStatus,
provenance: Provenance,
) -> Self {
Self {
bgp_msg: None,
nlri_status,
provenance,
}
}

pub fn message(&self) -> &Option<BytesRecord<BgpUpdateMessage>> {
&self.bgp_msg
}

pub fn provenance(&self) -> &Provenance {
&self.provenance
pub fn provenance(&self) -> Provenance {
self.provenance
}

pub fn nlri_status(&self) -> NlriStatus {
self.nlri_status
}

pub fn update_nlri_status(&mut self, status: NlriStatus) {
self.nlri_status = status;
}

pub fn get_attrs_builder(&self) -> Result<PaMap, VmError> {
if let Some(msg) = &self.bgp_msg {
PaMap::from_update_pdu(&msg.clone().into_inner())
Expand Down Expand Up @@ -1179,44 +1197,194 @@
// TypeValue::Builtin(BuiltinTypeValue::Nlri(Ipv6FlowSpec(value.nlri().clone())))
// }
// }
impl From<RouteWorkshop<Ipv6FlowSpecNlri<bytes::Bytes>>> for TypeValue {
fn from(value: RouteWorkshop<Ipv6FlowSpecNlri<bytes::Bytes>>) -> Self {
TypeValue::Builtin(BuiltinTypeValue::FlowSpecRoute(
FlowSpecRoute {
attributes: value.attributes().clone(),
nlri: Ipv6FlowSpec(value.nlri().clone()),
},
))
}
}

impl RotoType for RouteWorkshop<Ipv6FlowSpecNlri<bytes::Bytes>> {
fn get_props_for_method(
ty: TypeDef,

Check warning on line 1213 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0)

unused variable: `ty`

Check warning on line 1213 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --no-default-features)

unused variable: `ty`

Check warning on line 1213 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --all-features)

unused variable: `ty`

Check warning on line 1213 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --all-features)

unused variable: `ty`

Check warning on line 1213 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --no-default-features)

unused variable: `ty`

Check warning on line 1213 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly)

unused variable: `ty`

Check warning on line 1213 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --all-features)

unused variable: `ty`

Check warning on line 1213 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta)

unused variable: `ty`

Check warning on line 1213 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --no-default-features)

unused variable: `ty`

Check warning on line 1213 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --no-default-features)

unused variable: `ty`

Check warning on line 1213 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --all-features)

unused variable: `ty`

Check warning on line 1213 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

unused variable: `ty`
method_name: &crate::ast::Identifier,

Check warning on line 1214 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0)

unused variable: `method_name`

Check warning on line 1214 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --no-default-features)

unused variable: `method_name`

Check warning on line 1214 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --all-features)

unused variable: `method_name`

Check warning on line 1214 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --all-features)

unused variable: `method_name`

Check warning on line 1214 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --no-default-features)

unused variable: `method_name`

Check warning on line 1214 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly)

unused variable: `method_name`

Check warning on line 1214 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --all-features)

unused variable: `method_name`

Check warning on line 1214 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta)

unused variable: `method_name`

Check warning on line 1214 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --no-default-features)

unused variable: `method_name`

Check warning on line 1214 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --no-default-features)

unused variable: `method_name`

Check warning on line 1214 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --all-features)

unused variable: `method_name`

Check warning on line 1214 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

unused variable: `method_name`
) -> Result<MethodProps, CompileError>
where
Self: std::marker::Sized {
todo!()
}

fn into_type(
self,
type_value: &TypeDef,

Check warning on line 1223 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0)

unused variable: `type_value`

Check warning on line 1223 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --no-default-features)

unused variable: `type_value`

Check warning on line 1223 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --all-features)

unused variable: `type_value`

Check warning on line 1223 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --all-features)

unused variable: `type_value`

Check warning on line 1223 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --no-default-features)

unused variable: `type_value`

Check warning on line 1223 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly)

unused variable: `type_value`

Check warning on line 1223 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --all-features)

unused variable: `type_value`

Check warning on line 1223 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta)

unused variable: `type_value`

Check warning on line 1223 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --no-default-features)

unused variable: `type_value`

Check warning on line 1223 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --no-default-features)

unused variable: `type_value`

Check warning on line 1223 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --all-features)

unused variable: `type_value`

Check warning on line 1223 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

unused variable: `type_value`
) -> Result<TypeValue, CompileError>
where
Self: std::marker::Sized {
todo!()
}

fn exec_value_method<'a>(
&'a self,
method_token: usize,

Check warning on line 1232 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0)

unused variable: `method_token`

Check warning on line 1232 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --no-default-features)

unused variable: `method_token`

Check warning on line 1232 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --all-features)

unused variable: `method_token`

Check warning on line 1232 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --all-features)

unused variable: `method_token`

Check warning on line 1232 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --no-default-features)

unused variable: `method_token`

Check warning on line 1232 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly)

unused variable: `method_token`

Check warning on line 1232 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --all-features)

unused variable: `method_token`

Check warning on line 1232 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta)

unused variable: `method_token`

Check warning on line 1232 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --no-default-features)

unused variable: `method_token`

Check warning on line 1232 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --no-default-features)

unused variable: `method_token`

Check warning on line 1232 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --all-features)

unused variable: `method_token`

Check warning on line 1232 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

unused variable: `method_token`
args: &'a [StackValue],

Check warning on line 1233 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0)

unused variable: `args`

Check warning on line 1233 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --no-default-features)

unused variable: `args`

Check warning on line 1233 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --all-features)

unused variable: `args`

Check warning on line 1233 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --all-features)

unused variable: `args`

Check warning on line 1233 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --no-default-features)

unused variable: `args`

Check warning on line 1233 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly)

unused variable: `args`

Check warning on line 1233 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --all-features)

unused variable: `args`

Check warning on line 1233 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta)

unused variable: `args`

Check warning on line 1233 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --no-default-features)

unused variable: `args`

Check warning on line 1233 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --no-default-features)

unused variable: `args`

Check warning on line 1233 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --all-features)

unused variable: `args`

Check warning on line 1233 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

unused variable: `args`
res_type: TypeDef,

Check warning on line 1234 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0)

unused variable: `res_type`

Check warning on line 1234 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --no-default-features)

unused variable: `res_type`

Check warning on line 1234 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --all-features)

unused variable: `res_type`

Check warning on line 1234 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --all-features)

unused variable: `res_type`

Check warning on line 1234 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --no-default-features)

unused variable: `res_type`

Check warning on line 1234 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly)

unused variable: `res_type`

Check warning on line 1234 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --all-features)

unused variable: `res_type`

Check warning on line 1234 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta)

unused variable: `res_type`

Check warning on line 1234 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --no-default-features)

unused variable: `res_type`

Check warning on line 1234 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --no-default-features)

unused variable: `res_type`

Check warning on line 1234 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --all-features)

unused variable: `res_type`

Check warning on line 1234 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

unused variable: `res_type`
) -> Result<TypeValue, VmError> {
todo!()
}

fn exec_consume_value_method(
self,
method_token: usize,

Check warning on line 1241 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0)

unused variable: `method_token`

Check warning on line 1241 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --no-default-features)

unused variable: `method_token`

Check warning on line 1241 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.71.0, --all-features)

unused variable: `method_token`

Check warning on line 1241 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --all-features)

unused variable: `method_token`

Check warning on line 1241 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly, --no-default-features)

unused variable: `method_token`

Check warning on line 1241 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly)

unused variable: `method_token`

Check warning on line 1241 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --all-features)

unused variable: `method_token`

Check warning on line 1241 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta)

unused variable: `method_token`

Check warning on line 1241 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, beta, --no-default-features)

unused variable: `method_token`

Check warning on line 1241 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --no-default-features)

unused variable: `method_token`

Check warning on line 1241 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, --all-features)

unused variable: `method_token`

Check warning on line 1241 in src/types/builtin/basic_route.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

unused variable: `method_token`
args: Vec<TypeValue>,
res_type: TypeDef,
) -> Result<TypeValue, VmError> {
todo!()
}

fn exec_type_method(
method_token: usize,
args: &[StackValue],
res_type: TypeDef,
) -> Result<TypeValue, VmError> {
todo!()
}
}

//------------ Provenance ----------------------------------------------------

/// A sized struct containing session/state information for BMP and/or BGP.
///
/// The Provenance struct holds information that pertains to the session. This
/// information comes from configuration, or is exchanged in the first
/// stage of a session prior to the actual routing information is exchanged.
/// Typically, the information in Provenance is not available in the
/// individual routing information messages (e.g. BGP UPDATE PDUs), but is
/// useful or necessary to process such messages.
///
/// For BGP, this means information from the BGP OPEN message.
/// For BMP, that is information from the PerPeerHeader: as we currently split
/// up the encapsulated BGP UPDATE message per NLRI into N `PrefixRoutes`
/// typevalues, we lose the PerPeerHeader after the filter in the connector
/// Unit.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize)]
pub struct Provenance {
#[serde(skip)]
pub timestamp: chrono::DateTime<Utc>,
// The SocketAddr of the monitored router over BMP, or the SocketAddr of
// the BGP peer over BGP.
pub connection_id: SocketAddr,
// The (IP Address, ASN) of a peer of the monitored router over BMP, or
// the (IP Address, ASN) tuple of the connected BGP peer.
pub peer_id: PeerId,
pub peer_bgp_id: routecore::bgp::path_attributes::BgpIdentifier,
pub peer_distuingisher: [u8; 8],


/// The unique ID for the session.
///
/// For the first 'control' messages in a BGP/BMP session, this ingress_id
/// might be a general ID registered by the connector, not a session
/// specific ID.
pub ingress_id: u32, // rotonda::ingress::IngressId

/// The remote address of the BGP session.
///
/// If this is not yet available (e.g. for the first messages of a BMP
/// session), this holds the remote IP of the BMP session itself, i.e. the
/// monitored router.
pub peer_ip: IpAddr,

/// The remote ASN of the BGP session.
///
/// If this is not yet available (e.g. for the first messages of a BMP
/// session), this holds ASN(0).
pub peer_asn: Asn,

/// The remote ip address for the TCP connection.
///
/// For BGP, the connection_ip and peer_ip are the same.
/// For BMP, the connection_ip holds the IP address of the monitored
/// router.
pub connection_ip: IpAddr,

// pub peer_bgp_id: routecore::bgp::path_attributes::BgpIdentifier,

/// The BMP PeerType (1 byte) and PeerDistuingisher (8 bytes).
///
/// These are stored together as the combination of the two is used to
/// disambiguate peers in certain scenarios.
/// PeerType can be 0, 1 or 2, and only for 1 or 2 the RouteDistinguisher
/// is set. So for the majority, the value of peer_distuingisher will be a
/// 0 for PeerType == Global Instance Peer, followed by 8 more zeroes.
pub peer_distuingisher: [u8; 9],

pub peer_rib_type: PeerRibType,
}

impl Provenance {
// pub fn from_rotonda() -> Self {
// Self {
// timestamp: Utc::now(),
// // router_id: 0,
// connection_id: 0,
// peer_id: PeerId {
// addr: "127.0.0.1".parse().unwrap(),
// asn: 0.into(),
// },
// peer_bgp_id: BgpIdentifier::from([0, 0, 0, 0]),
// peer_distuingisher: [0, 0, 0, 0, 0, 0, 0, 0],
// peer_rib_type: PeerRibType::Loc,
// }
// }

pub fn peer_ip(&self) -> std::net::IpAddr {
self.peer_id.addr

pub fn for_bgp(
ingress_id: u32,
peer_ip: IpAddr,
peer_asn: Asn,
) -> Self {
Self::new(
ingress_id,
peer_ip,
peer_asn,
peer_ip, // connection ==~ peer_ip
[0u8; 9],
PeerRibType::OutPost,
)
}

pub fn for_bmp(
ingress_id: u32,
peer_ip: IpAddr,
peer_asn: Asn,
connection_ip: IpAddr,
peer_distuingisher: [u8; 9],
peer_rib_type: PeerRibType,
) -> Self {
Self::new(
ingress_id,
peer_ip,
peer_asn,
connection_ip,
peer_distuingisher,
peer_rib_type,
)
}

pub fn new(
ingress_id: u32,
peer_ip: IpAddr,
peer_asn: Asn,
connection_ip: IpAddr,
peer_distuingisher: [u8; 9],
peer_rib_type: PeerRibType,
) -> Self {
Self {
timestamp: Utc::now(),
ingress_id,
peer_ip,
peer_asn,
connection_ip,
peer_distuingisher,
peer_rib_type,
}
}



pub fn mock() -> Self {
todo!()
}

//pub fn peer_ip(&self) -> std::net::IpAddr {
// self.peer_id.addr
//}

//pub fn peer_asn(&self) -> Asn {
// self.peer_id.asn
//}

pub(crate) fn get_props_for_field(
field_name: &ast::Identifier,
) -> Result<(TypeDef, traits::Token), CompileError>
Expand Down Expand Up @@ -1269,11 +1437,13 @@
field_index: &[usize],
) -> Result<TypeValue, VmError> {
trace!("get_field_by_index {:?} for Provenance", field_index);
todo!()
/*
match field_index.first().map(|i| (*i).try_into()) {
Some(Ok(ProvenanceToken::Timestamp)) => todo!(),
// Some(Ok(ProvenanceToken::RouterId)) => Ok(self.router_id.into()),
Some(Ok(ProvenanceToken::ConnectionId)) => {
Ok(self.connection_id.into())
todo!() //Ok(self.connection_id.into())
}
Some(Ok(ProvenanceToken::PeerId)) => {
match field_index.len() {
Expand All @@ -1296,11 +1466,14 @@
}
_ => Err(VmError::InvalidFieldAccess),
}
*/
}
}

impl Display for Provenance {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
todo!()
/*
write!(
f,
"timestamp: {}, connection_id: {}, peer_id: \
Expand All @@ -1313,6 +1486,7 @@
self.peer_distuingisher,
self.peer_rib_type
)
*/
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/types/builtin/bmp_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ bytes_record_impl!(
record_field(
"session_config"; 13,
field(
"has_four_octet_asn"; 14,
"four_octet_enabled"; 14,
Bool,
session_config.has_four_octet_asn
session_config.four_octet_enabled
),
),
)],
Expand Down
Loading
Loading