-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from NLnetLabs/modules
Modules
- Loading branch information
Showing
46 changed files
with
3,648 additions
and
2,046 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,12 @@ categories.workspace = true | |
[dependencies] | ||
ariadne = "0.5.0" | ||
clap = { version = "4.4.6", features = ["derive"] } | ||
env_logger = "0.10" | ||
log = "0.4" | ||
logos = "0.14.0" | ||
env_logger = "0.11" | ||
icu = { version = "1.5.0", features = ["compiled_data"] } | ||
inetnum = "0.1.0" | ||
symbol_table = { version = "0.3.0", features = ["global"] } | ||
string-interner = "0.17.0" | ||
roto-macros = { workspace = true, version = "0.4.0" } | ||
log = "0.4" | ||
roto-macros = { workspace = true } | ||
symbol_table = { version = "0.4.0", features = ["global"] } | ||
|
||
[dependencies.cranelift] | ||
version = "0.113.0" | ||
|
@@ -38,7 +37,7 @@ rev = "1af294ea2d6c18c5a8fa9b4f272398b7c98e0c48" | |
[dev-dependencies] | ||
bytes = "1" | ||
routecore = { version = "0.5", features = ["bgp", "bmp", "serde"] } | ||
tabled = { version = "0.17.0", default-features = false, features = ["std"] } | ||
tabled = { version = "0.18.0", default-features = false, features = ["std"] } | ||
|
||
[profile.profiling] | ||
inherits = "release" | ||
|
@@ -54,7 +53,7 @@ version = "0.4.1-dev" | |
edition = "2021" | ||
authors = ["NLnet Labs <[email protected]>"] | ||
license = "BSD-3-Clause" | ||
rust-version = "1.80" | ||
rust-version = "1.81" | ||
description = "strongly-typed, compiled language for Rotonda" | ||
documentation = "https://docs.rs/roto/" | ||
repository = "https://github.com/NLnetLabs/roto/" | ||
|
@@ -64,7 +63,7 @@ categories = ["network-programming"] | |
readme = "README.md" | ||
|
||
[workspace.dependencies] | ||
roto-macros = { path = "macros", version = "0.4.0" } | ||
roto-macros = { path = "macros", version = "0.4.1-dev" } | ||
proc-macro2 = "1.0.86" | ||
quote = "1.0.37" | ||
syn = { version = "2.0.77", features = ["full"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
filtermap within_range(range: AddrRange, ip: IpAddr) { | ||
if range.contains(ip) && ip.is_ipv4() { | ||
accept ip | ||
} else { | ||
reject | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::{net::IpAddr, path::Path}; | ||
|
||
use roto::{roto_method, FileTree, Runtime, Val, Verdict}; | ||
|
||
#[derive(Clone)] | ||
struct AddrRange { | ||
min: IpAddr, | ||
max: IpAddr, | ||
} | ||
|
||
fn main() { | ||
let path = Path::new("./examples/addr_range.roto"); | ||
|
||
// Create a runtime | ||
let mut runtime = Runtime::new(); | ||
|
||
// Register the AddrRange type into Roto with a docstring | ||
runtime | ||
.register_clone_type::<AddrRange>("A range of IP addresses") | ||
.unwrap(); | ||
|
||
// Register the contains method with a docstring | ||
#[roto_method(runtime, AddrRange)] | ||
fn contains(range: &AddrRange, addr: &IpAddr) -> bool { | ||
range.min <= *addr && *addr <= range.max | ||
} | ||
|
||
// Compile the program with our runtime | ||
let mut program = FileTree::read(path).compile(runtime).unwrap(); | ||
|
||
// Extract the function | ||
let function = program | ||
.get_function::<(), (Val<AddrRange>, IpAddr), Verdict<IpAddr, ()>>( | ||
"within_range", | ||
) | ||
.unwrap(); | ||
|
||
let range = AddrRange { | ||
min: "10.10.10.10".parse().unwrap(), | ||
max: "10.10.10.12".parse().unwrap(), | ||
}; | ||
|
||
// Run the function | ||
let in_range = "10.10.10.11".parse().unwrap(); | ||
println!("{:?}", function.call(&mut (), Val(range.clone()), in_range)); | ||
|
||
let out_of_range = "20.20.20.20".parse().unwrap(); | ||
println!("{:?}", function.call(&mut (), Val(range), out_of_range)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use std::path::Path; | ||
|
||
use roto::{FileTree, Runtime}; | ||
|
||
fn main() -> Result<(), roto::RotoReport> { | ||
env_logger::init(); | ||
|
||
let runtime = Runtime::new(); | ||
let mut compiled = FileTree::directory(Path::new("examples/modules")) | ||
.compile(runtime) | ||
.inspect_err(|e| eprintln!("{e}"))?; | ||
|
||
let f = compiled.get_function::<(), (i32,), i32>("main").unwrap(); | ||
|
||
let x = f.call(&mut (), 4i32); | ||
println!("main(4) = {x}"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function bar(x: i32) -> i32 { | ||
import pkg.double; | ||
let a = super.double(x); | ||
let b = pkg.double(a); | ||
let c = double(b); | ||
c | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function main(x: i32) -> i32 { | ||
import foo.bar; | ||
bar(bar(x)) | ||
} | ||
|
||
function double(x: i32) -> i32 { | ||
2 * x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,13 @@ | ||
filter-map rib-in-pre( | ||
filtermap rib_in_pre( | ||
output: Log, | ||
route: Route, | ||
) { | ||
define { | ||
my_prefix = 100.40.0.0/17; | ||
} | ||
|
||
apply { | ||
if route.prefix_matches(my_prefix) { | ||
output.log_custom(10, 100); | ||
reject | ||
} else { | ||
output.log_prefix(my_prefix); | ||
accept | ||
} | ||
let my_prefix = 100.40.0.0/17; | ||
if route.prefix_matches(my_prefix) { | ||
output.log_custom(10, 100); | ||
reject | ||
} else { | ||
output.log_prefix(my_prefix); | ||
accept | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
filter-map main(bla: Bla) { | ||
apply { | ||
if bla.x() > 10 { | ||
accept 2 * bla.x() | ||
} else { | ||
reject | ||
} | ||
filtermap main(bla: Bla) { | ||
if bla.x() > 10 { | ||
accept 2 * bla.x() | ||
} else { | ||
reject | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.