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

adapt to multi-mapped store #47

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ paste = "1.0.14"
smallvec = { version = "1.11", features = [ "const_generics", "serde" ] }
serde = { version = "1.0", features = [ "derive", "rc" ] }
inetnum = { version = "0.1.0", features = ["arbitrary", "serde"] }
rotonda-store = { git = "https://github.com/nlnetlabs/rotonda-store", branch = "main" }
rotonda-store = { git = "https://github.com/nlnetlabs/rotonda-store", branch = "indexed-multi-map" }
routecore = { git = "https://github.com/nlnetlabs/routecore", branch = "absorb-fsm", features = ["bgp", "bmp", "serde"] }
clap = { version = "4.4.6", features = ["derive"] }
ariadne = "0.4.0"
Expand Down
1 change: 1 addition & 0 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2938,6 +2938,7 @@ fn add_match_action(

trait BooleanExpr: std::fmt::Debug {
fn get_args(&self) -> &[symbols::Symbol];
#[allow(dead_code)]
fn get_type(&self) -> TypeDef;
fn get_builtin_type(&self) -> Result<TypeDef, CompileError>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn run(
compile(&files, &symbols, None)
}

pub fn run_string<'a>(
pub fn run_string(
script: String,
) -> Result<Vec<Rotolo>, RotoReport> {
let files = vec![SourceFile { name: "script".into(), contents: script }];
Expand Down
2 changes: 1 addition & 1 deletion src/typechecker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl<'methods> TypeChecker<'methods> {
}

fn get_type(&self, type_name: impl AsRef<str>) -> Option<&Type> {
self.types.get(&type_name.as_ref().to_string())
self.types.get(type_name.as_ref())
}

/// Check whether `a` is a subtype of `b`
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
10 changes: 5 additions & 5 deletions src/types/builtin/builtin_type_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::net::IpAddr;

use inetnum::asn::Asn;
use routecore::bgp::types::PathId;
use routecore::bgp::types::{AfiSafi, AtomicAggregate, MultiExitDisc, NextHop, Origin};
use routecore::bgp::types::{AtomicAggregate, MultiExitDisc, NextHop, Origin};
use routecore::bgp::path_attributes::AggregatorInfo;
use inetnum::addr::Prefix;
use routecore::bgp::communities::HumanReadableCommunity as Community;
Expand Down Expand Up @@ -42,7 +42,7 @@ pub enum BuiltinTypeValue {
HexLiteral(HexLiteral), // scalar
IpAddr(IpAddr), // scalar
Prefix(Prefix), // scalar
AfiSafi(AfiSafi), // scalar
// AfiSafi(AfiSafi), // scalar
PathId(PathId), // scalar
PrefixLength(PrefixLength), // scalar
LocalPref(routecore::bgp::types::LocalPref), // scalar
Expand Down Expand Up @@ -94,7 +94,7 @@ impl BuiltinTypeValue {
BuiltinTypeValue::IntegerLiteral(v) => v.into_type(ty),
BuiltinTypeValue::StringLiteral(v) => v.into_type(ty),
BuiltinTypeValue::Prefix(v) => v.into_type(ty),
BuiltinTypeValue::AfiSafi(v) => v.into_type(ty),
// BuiltinTypeValue::AfiSafi(v) => v.into_type(ty),
BuiltinTypeValue::PathId(v) => v.into_type(ty),
BuiltinTypeValue::PrefixLength(v) => v.into_type(ty),
BuiltinTypeValue::Community(v) => v.into_type(ty),
Expand Down Expand Up @@ -194,7 +194,7 @@ impl Display for BuiltinTypeValue {
}
BuiltinTypeValue::Prefix(v) => write!(f, "{}", v),
BuiltinTypeValue::PathId(v) => write!(f, "{}", v),
BuiltinTypeValue::AfiSafi(v) => write!(f, "{}", v),
// BuiltinTypeValue::AfiSafi(v) => write!(f, "{}", v),
BuiltinTypeValue::PrefixLength(v) => {
write!(f, "{}", v)
}
Expand Down Expand Up @@ -286,7 +286,7 @@ impl Display for BuiltinTypeValue {
write!(f, "{} (Const U32 Enum Variant)", v.value)
}
BuiltinTypeValue::Prefix(v) => write!(f, "{} (Prefix)", v),
BuiltinTypeValue::AfiSafi(v) => write!(f, "{} (AFI SAFI)", v),
// BuiltinTypeValue::AfiSafi(v) => write!(f, "{} (AFI SAFI)", v),
BuiltinTypeValue::PathId(v) => write!(f, "{} (Path ID)", v),
BuiltinTypeValue::PrefixLength(v) => {
write!(f, "{} (Prefix Length)", v)
Expand Down
4 changes: 2 additions & 2 deletions src/types/builtin/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use inetnum::addr::Prefix;
use routecore::bgp::types::PathId;
use routecore::bgp::path_attributes::AggregatorInfo;
use routecore::bgp::communities::HumanReadableCommunity as Community;
use routecore::bgp::types::{AfiSafi, AtomicAggregate, LocalPref, MultiExitDisc, NextHop, Origin};
use routecore::bgp::types::{AtomicAggregate, LocalPref, MultiExitDisc, NextHop, Origin};

//------------ U16 Type -----------------------------------------------------

Expand Down Expand Up @@ -1076,7 +1076,7 @@ impl TryFrom<&TypeValue> for PrefixLength {

//------------ AfiSafi Type --------------------------------------------------

minimalscalartype!(AfiSafi);
// minimalscalartype!(AfiSafi);

//------------ PathId Type ---------------------------------------------------

Expand Down
6 changes: 3 additions & 3 deletions src/types/builtin/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use routecore::{
workshop::route::RouteWorkshop,
ParseError,
},
Octets,
// Octets,
};
use serde::Serialize;

Expand Down Expand Up @@ -143,13 +143,13 @@ impl From<&Ipv6MulticastAddpathNlri> for PrefixNlri {
pub struct PrefixRoute(pub PrefixRouteWs);

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
pub enum FlowSpecNlri<O: Octets> {
pub enum FlowSpecNlri<O: AsRef<[u8]>> {
Ipv4FlowSpec(Ipv4FlowSpecNlri<O>),
Ipv6FlowSpec(Ipv6FlowSpecNlri<O>),
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
pub struct FlowSpecRoute<O: routecore::Octets> {
pub struct FlowSpecRoute<O: AsRef<[u8]>> {
pub(crate) nlri: FlowSpecNlri<O>,
pub(crate) attributes: PaMap,
}
Expand Down
3 changes: 2 additions & 1 deletion src/types/datasources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ impl<M: Meta> RotoRib for Rib<M> {
&prefix,
&MatchOptions {
match_type: MatchType::LongestMatch,
include_all_records: false,
include_withdrawn: false,
include_less_specifics: false,
include_more_specifics: false,
mui: None
},
&guard,
)
Expand Down
22 changes: 11 additions & 11 deletions src/types/typedef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use routecore::bgp::path_attributes::AggregatorInfo;
use routecore::bgp::types::{AtomicAggregate, MultiExitDisc, Origin};
use routecore::bgp::{
types::PathId,
types::{AfiSafi, LocalPref},
types::LocalPref,
};
use serde::Serialize;

Expand Down Expand Up @@ -191,7 +191,7 @@ pub enum TypeDef {
Bool,
Prefix,
PrefixLength, // A u8 prefixes by a /
AfiSafi,
// AfiSafi,
PathId,
IpAddr,
Asn,
Expand Down Expand Up @@ -261,7 +261,7 @@ impl TypeDef {
HexLiteral(StringLiteral,U8,U32,Community;),
PrefixLength(StringLiteral,IntegerLiteral,U8,U32;),
Provenance(StringLiteral;),
AfiSafi(StringLiteral;),
// AfiSafi(StringLiteral;),
PeerId(StringLiteral;),
PeerRibType(StringLiteral;),
PathId(StringLiteral,IntegerLiteral,U32;),
Expand Down Expand Up @@ -706,9 +706,9 @@ impl TypeDef {
TypeDef::PrefixLength => {
PrefixLength::get_props_for_method(self.clone(), method_name)
}
TypeDef::AfiSafi => {
AfiSafi::get_props_for_method(self.clone(), method_name)
}
// TypeDef::AfiSafi => {
// AfiSafi::get_props_for_method(self.clone(), method_name)
// }
TypeDef::PathId => {
PathId::get_props_for_method(self.clone(), method_name)
}
Expand Down Expand Up @@ -931,7 +931,7 @@ impl std::fmt::Display for TypeDef {
TypeDef::AsPath => write!(f, "AsPath"),
TypeDef::Hop => write!(f, "Hop"),
TypeDef::Prefix => write!(f, "Prefix"),
TypeDef::AfiSafi => write!(f, "AFI SAFI"),
// TypeDef::AfiSafi => write!(f, "AFI SAFI"),
TypeDef::PathId => write!(f, "Path ID"),
TypeDef::U32 => write!(f, "U32"),
TypeDef::U16 => write!(f, "U16"),
Expand Down Expand Up @@ -1169,7 +1169,7 @@ impl TryFrom<crate::ast::TypeIdentifier> for TypeDef {
"HexLiteral" => Ok(TypeDef::HexLiteral),
"IpAddress" => Ok(TypeDef::IpAddr),
"Prefix" => Ok(TypeDef::Prefix),
"AfiSafi" => Ok(TypeDef::AfiSafi),
// "AfiSafi" => Ok(TypeDef::AfiSafi),
"PathId" => Ok(TypeDef::PathId),
"PrefixLength" => Ok(TypeDef::PrefixLength),
"LocalPref" => Ok(TypeDef::LocalPref),
Expand Down Expand Up @@ -1239,7 +1239,7 @@ impl TryFrom<crate::ast::Identifier> for TypeDef {
"HexLiteral" => Ok(TypeDef::HexLiteral),
"IpAddress" => Ok(TypeDef::IpAddr),
"Prefix" => Ok(TypeDef::Prefix),
"AfiSafi" => Ok(TypeDef::AfiSafi),
// "AfiSafi" => Ok(TypeDef::AfiSafi),
"PathId" => Ok(TypeDef::PathId),
"PrefixLength" => Ok(TypeDef::PrefixLength),
"LocalPref" => Ok(TypeDef::LocalPref),
Expand Down Expand Up @@ -1311,7 +1311,7 @@ impl From<&BuiltinTypeValue> for TypeDef {
BuiltinTypeValue::StringLiteral(_) => TypeDef::StringLiteral,
BuiltinTypeValue::Bool(_) => TypeDef::Bool,
BuiltinTypeValue::Prefix(_) => TypeDef::Prefix,
BuiltinTypeValue::AfiSafi(_) => TypeDef::AfiSafi,
// BuiltinTypeValue::AfiSafi(_) => TypeDef::AfiSafi,
BuiltinTypeValue::PathId(_) => TypeDef::PathId,
BuiltinTypeValue::PrefixLength(_) => TypeDef::PrefixLength,
BuiltinTypeValue::IpAddr(_) => TypeDef::IpAddr,
Expand Down Expand Up @@ -1381,7 +1381,7 @@ impl From<BuiltinTypeValue> for TypeDef {
BuiltinTypeValue::StringLiteral(_) => TypeDef::StringLiteral,
BuiltinTypeValue::Bool(_) => TypeDef::Bool,
BuiltinTypeValue::Prefix(_) => TypeDef::Prefix,
BuiltinTypeValue::AfiSafi(_) => TypeDef::AfiSafi,
// BuiltinTypeValue::AfiSafi(_) => TypeDef::AfiSafi,
BuiltinTypeValue::PathId(_) => TypeDef::PathId,
BuiltinTypeValue::PrefixLength(_) => TypeDef::PrefixLength,
BuiltinTypeValue::IpAddr(_) => TypeDef::IpAddr,
Expand Down
22 changes: 11 additions & 11 deletions src/types/typevalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use routecore::bgp::nlri::afisafi::{
};
use routecore::bgp::types::PathId;
use routecore::bgp::types::{
AfiSafi as AfiSafiType, LocalPref, MultiExitDisc, NextHop, Origin
LocalPref, MultiExitDisc, NextHop, Origin
};
use routecore::bgp::workshop::route::RouteWorkshop;
use serde::Serialize;
Expand Down Expand Up @@ -428,9 +428,9 @@ impl RotoType for TypeValue {
TypeDef::PrefixLength => {
PrefixLength::get_props_for_method(ty, method_name)
}
TypeDef::AfiSafi => {
AfiSafiType::get_props_for_method(ty, method_name)
}
// TypeDef::AfiSafi => {
// AfiSafiType::get_props_for_method(ty, method_name)
// }
TypeDef::PathId => PathId::get_props_for_method(ty, method_name),
TypeDef::Record(_) => {
Record::get_props_for_method(ty, method_name)
Expand Down Expand Up @@ -507,7 +507,7 @@ impl RotoType for TypeValue {
BuiltinTypeValue::Origin(v) => v.into_type(ty),
BuiltinTypeValue::Prefix(v) => v.into_type(ty),
BuiltinTypeValue::PrefixLength(v) => v.into_type(ty),
BuiltinTypeValue::AfiSafi(v) => v.into_type(ty),
// BuiltinTypeValue::AfiSafi(v) => v.into_type(ty),
BuiltinTypeValue::PathId(v) => v.into_type(ty),
BuiltinTypeValue::PrefixRoute(v) => v.into_type(ty),
BuiltinTypeValue::FlowSpecRoute(v) => v.into_type(ty),
Expand Down Expand Up @@ -731,9 +731,9 @@ impl RotoType for TypeValue {
BuiltinTypeValue::Prefix(v) => {
v.exec_value_method(method_token, args, res_type)
}
BuiltinTypeValue::AfiSafi(v) => {
v.exec_value_method(method_token, args, res_type)
}
// BuiltinTypeValue::AfiSafi(v) => {
// v.exec_value_method(method_token, args, res_type)
// }
BuiltinTypeValue::PathId(v) => {
v.exec_value_method(method_token, args, res_type)
}
Expand Down Expand Up @@ -879,9 +879,9 @@ impl RotoType for TypeValue {
BuiltinTypeValue::Prefix(v) => {
v.exec_consume_value_method(method_token, args, res_type)
}
BuiltinTypeValue::AfiSafi(v) => {
v.exec_consume_value_method(method_token, args, res_type)
}
// BuiltinTypeValue::AfiSafi(v) => {
// v.exec_consume_value_method(method_token, args, res_type)
// }
BuiltinTypeValue::PathId(v) => {
v.exec_consume_value_method(method_token, args, res_type)
}
Expand Down
72 changes: 36 additions & 36 deletions tests/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,47 @@ use roto::types::collections::Record;
use roto::types::typedef::TypeDef;
use roto::types::typevalue::TypeValue;
use roto::vm::{self, VmResult};
use rotonda_store::prelude::MergeUpdate;
// use rotonda_store::prelude::MergeUpdate;

use inetnum::asn::Asn;

mod common;

#[derive(Debug, Clone)]
struct RibValue(Vec<TypeValue>);

impl MergeUpdate for RibValue {
type UserDataIn = ();
type UserDataOut = ();

fn merge_update(
&mut self,
update_record: RibValue,
_: Option<&Self::UserDataIn>,
) -> Result<(), Box<dyn std::error::Error>> {
self.0 = update_record.0;
Ok(())
}

fn clone_merge_update(
&self,
update_meta: &Self,
_: Option<&Self::UserDataIn>,
) -> Result<(Self, Self::UserDataOut), Box<dyn std::error::Error>>
where
Self: std::marker::Sized,
{
let mut new_meta = update_meta.0.clone();
new_meta.push(self.0[0].clone());
Ok((RibValue(new_meta), ()))
}
}

impl std::fmt::Display for RibValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.0)
}
}
// #[derive(Debug, Clone)]
// struct RibValue(Vec<TypeValue>);

// impl MergeUpdate for RibValue {
// type UserDataIn = ();
// type UserDataOut = ();

// fn merge_update(
// &mut self,
// update_record: RibValue,
// _: Option<&Self::UserDataIn>,
// ) -> Result<(), Box<dyn std::error::Error>> {
// self.0 = update_record.0;
// Ok(())
// }

// fn clone_merge_update(
// &self,
// update_meta: &Self,
// _: Option<&Self::UserDataIn>,
// ) -> Result<(Self, Self::UserDataOut), Box<dyn std::error::Error>>
// where
// Self: std::marker::Sized,
// {
// let mut new_meta = update_meta.0.clone();
// new_meta.push(self.0[0].clone());
// Ok((RibValue(new_meta), ()))
// }
// }

// impl std::fmt::Display for RibValue {
// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// write!(f, "{:?}", self.0)
// }
// }

fn src_code(code_line: &str, end_accept_reject: &str) -> String {
let pre = format!(
Expand Down
Loading
Loading