rtr的输入换成ccr文件
This commit is contained in:
@@ -15,7 +15,7 @@ use rpki::rtr::cache::{
|
||||
validate_payload_updates_for_rtr,
|
||||
validate_payloads_for_rtr,
|
||||
};
|
||||
use rpki::rtr::payload::{Aspa, Payload, Timing};
|
||||
use rpki::rtr::payload::{Aspa, Payload, RouterKey, Ski, Timing};
|
||||
use rpki::rtr::store::RtrStore;
|
||||
|
||||
fn delta_to_string(delta: &Delta) -> String {
|
||||
@@ -118,7 +118,7 @@ async fn init_keeps_cache_running_when_file_loader_returns_no_data() {
|
||||
let store = RtrStore::open(dir.path()).unwrap();
|
||||
|
||||
let cache = rpki::rtr::cache::RtrCache::default()
|
||||
.init(&store, 16, Timing::new(600, 600, 7200), || Ok(vec![]))
|
||||
.init(&store, 16, false, Timing::new(600, 600, 7200), || Ok(vec![]))
|
||||
.unwrap();
|
||||
|
||||
assert!(!cache.is_data_available());
|
||||
@@ -188,7 +188,7 @@ async fn init_restores_wraparound_delta_window_from_store() {
|
||||
.unwrap();
|
||||
|
||||
let cache = rpki::rtr::cache::RtrCache::default()
|
||||
.init(&store, 16, Timing::new(600, 600, 7200), || Ok(Vec::new()))
|
||||
.init(&store, 16, false, Timing::new(600, 600, 7200), || Ok(Vec::new()))
|
||||
.unwrap();
|
||||
|
||||
match cache.get_deltas_since(u32::MAX.wrapping_sub(1)) {
|
||||
@@ -200,6 +200,47 @@ async fn init_restores_wraparound_delta_window_from_store() {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn update_prunes_delta_window_when_cumulative_delta_size_reaches_snapshot_size() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let store = RtrStore::open(dir.path()).unwrap();
|
||||
let valid_spki = vec![
|
||||
0x30, 0x13, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
|
||||
0x01, 0x01, 0x05, 0x00, 0x03, 0x02, 0x00, 0x00,
|
||||
];
|
||||
|
||||
let initial_snapshot = Snapshot::from_payloads(vec![Payload::RouterKey(RouterKey::new(
|
||||
Ski::default(),
|
||||
Asn::from(64496u32),
|
||||
valid_spki.clone(),
|
||||
))]);
|
||||
|
||||
let mut cache = RtrCacheBuilder::new()
|
||||
.availability(CacheAvailability::Ready)
|
||||
.session_ids(SessionIds::from_array([42, 43, 44]))
|
||||
.serial(1)
|
||||
.snapshot(initial_snapshot)
|
||||
.max_delta(16)
|
||||
.prune_delta_by_snapshot_size(true)
|
||||
.timing(Timing::new(600, 600, 7200))
|
||||
.build();
|
||||
|
||||
cache
|
||||
.update(vec![Payload::RouterKey(RouterKey::new(
|
||||
Ski::from_bytes([1u8; 20]),
|
||||
Asn::from(64496u32),
|
||||
valid_spki,
|
||||
))], &store)
|
||||
.unwrap();
|
||||
|
||||
match cache.get_deltas_since(1) {
|
||||
SerialResult::ResetRequired => {}
|
||||
_ => panic!(
|
||||
"expected delta window to be pruned when cumulative delta size exceeds snapshot size"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Snapshot::diff() ?
|
||||
/// old_snapshot ?new_snapshot announced?withdrawn?
|
||||
#[test]
|
||||
|
||||
71
tests/test_ccr.rs
Normal file
71
tests/test_ccr.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use rpki::rtr::ccr::{
|
||||
ParsedCcrSnapshot,
|
||||
find_latest_ccr_file,
|
||||
load_ccr_snapshot_from_file,
|
||||
snapshot_to_payloads_with_options,
|
||||
};
|
||||
use rpki::rtr::loader::{ParsedAspa, ParsedVrp};
|
||||
use tempfile::tempdir;
|
||||
|
||||
fn fixture_path(name: &str) -> PathBuf {
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("data").join(name)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "manual CCR loader smoke test for local samples"]
|
||||
fn ccr_loader_smoke() {
|
||||
let snapshot = load_ccr_snapshot_from_file(fixture_path("20260324T000037Z-sng1.ccr"))
|
||||
.expect("load CCR snapshot");
|
||||
|
||||
println!("content_type_oid: {}", snapshot.content_type_oid);
|
||||
println!("produced_at : {:?}", snapshot.produced_at);
|
||||
println!("vrp_count : {}", snapshot.vrps.len());
|
||||
println!("vap_count : {}", snapshot.vaps.len());
|
||||
println!("first_vrp : {:?}", snapshot.vrps.first());
|
||||
println!("first_vap : {:?}", snapshot.vaps.first());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_latest_ccr_file_picks_latest_name() {
|
||||
let dir = tempdir().expect("create temp dir");
|
||||
let older = dir.path().join("20260324T000037Z-sng1.ccr");
|
||||
let newer = dir.path().join("20260324T000138Z-zur1.ccr");
|
||||
let ignored = dir.path().join("notes.txt");
|
||||
|
||||
fs::write(&older, b"older").expect("write older ccr");
|
||||
fs::write(&newer, b"newer").expect("write newer ccr");
|
||||
fs::write(&ignored, b"ignored").expect("write ignored file");
|
||||
|
||||
let latest = find_latest_ccr_file(dir.path()).expect("find latest ccr");
|
||||
|
||||
assert_eq!(latest, newer);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_to_payloads_with_options_skips_invalid_aspa_when_not_strict() {
|
||||
let snapshot = ParsedCcrSnapshot {
|
||||
content_type_oid: "1.2.840.113549.1.9.16.1.54".to_string(),
|
||||
produced_at: Some("20260324000037Z".to_string()),
|
||||
vrps: vec![ParsedVrp {
|
||||
prefix_addr: "192.0.2.0".parse().expect("parse IPv4"),
|
||||
prefix_len: 24,
|
||||
max_len: 24,
|
||||
asn: 64496,
|
||||
}],
|
||||
vaps: vec![ParsedAspa {
|
||||
customer_asn: 174,
|
||||
provider_asns: vec![0],
|
||||
}],
|
||||
};
|
||||
|
||||
let conversion =
|
||||
snapshot_to_payloads_with_options(&snapshot, false).expect("non-strict conversion");
|
||||
|
||||
assert_eq!(conversion.payloads.len(), 1);
|
||||
assert!(conversion.invalid_vrps.is_empty());
|
||||
assert_eq!(conversion.invalid_vaps.len(), 1);
|
||||
assert!(conversion.invalid_vaps[0].contains("provider list must not contain AS0"));
|
||||
}
|
||||
Reference in New Issue
Block a user