增加必要的数据记录

This commit is contained in:
xiuting.xu
2026-06-16 14:05:26 +08:00
parent fa19fc8722
commit b70bad4721
24 changed files with 1784 additions and 504 deletions

View File

@@ -71,6 +71,55 @@ fn deltas_all(deltas: VecDeque<Arc<Delta>>) -> [VecDeque<Arc<Delta>>; 3] {
[deltas.clone(), deltas.clone(), deltas]
}
#[test]
fn version_report_stats_separate_snapshot_and_delta_payload_types() {
let vrp = Payload::RouteOrigin(v4_origin(192, 0, 2, 0, 24, 24, 64496));
let router_key = Payload::RouterKey(RouterKey::new(
Ski::default(),
Asn::from(64496u32),
vec![1, 2, 3],
));
let aspa = Payload::Aspa(Aspa::new(
Asn::from(64496u32),
vec![Asn::from(64497u32)],
));
let snapshot = Snapshot::from_payloads(vec![vrp.clone(), router_key.clone(), aspa.clone()]);
let mut deltas = VecDeque::new();
deltas.push_back(Arc::new(Delta::new(
101,
vec![vrp, aspa],
vec![router_key],
)));
let cache = RtrCacheBuilder::new()
.session_ids(SessionIds::from_array([40, 41, 42]))
.serials([99, 100, 101])
.snapshots(snapshots_all(snapshot))
.deltas_by_version(deltas_all(deltas))
.build();
let v2 = cache.version_report_stats()[2];
assert_eq!(v2.version, 2);
assert_eq!(v2.session_id, 42);
assert_eq!(v2.serial, 101);
assert_eq!(v2.snapshot.total, 3);
assert_eq!(v2.snapshot.vrp, 1);
assert_eq!(v2.snapshot.router_key, 1);
assert_eq!(v2.snapshot.aspa, 1);
let latest = v2.latest_delta.unwrap();
assert_eq!(latest.serial, 101);
assert_eq!(latest.announced.total, 2);
assert_eq!(latest.announced.vrp, 1);
assert_eq!(latest.announced.aspa, 1);
assert_eq!(latest.withdrawn.total, 1);
assert_eq!(latest.withdrawn.router_key, 1);
assert_eq!(v2.delta_window.length, 1);
assert_eq!(v2.delta_window.oldest_serial, Some(101));
assert_eq!(v2.delta_window.newest_serial, Some(101));
}
/// Snapshot ?hash ?
/// payload snapshot_hash / origins_hash ?
#[test]

View File

@@ -1,7 +1,10 @@
use std::fs;
use std::path::PathBuf;
use rpki::source::pipeline::{PayloadLoadConfig, load_payloads_from_latest_sources};
use rpki::source::pipeline::{
PayloadLoadConfig, load_payloads_from_latest_sources,
load_payloads_from_latest_sources_with_report,
};
use tempfile::tempdir;
fn data_dir() -> String {
@@ -41,3 +44,56 @@ fn load_payloads_rejects_entire_slurm_set_when_any_file_is_invalid() {
assert!(text.contains("failed to parse SLURM file"));
assert!(text.contains("02-invalid.slurm"));
}
#[test]
fn load_report_contains_source_and_quality_details() {
let config = PayloadLoadConfig {
ccr_dir: data_dir(),
slurm_dir: None,
strict_ccr_validation: false,
};
let result = load_payloads_from_latest_sources_with_report(&config).unwrap();
assert!(result.source.ccr_file.ends_with(".ccr"));
assert!(result.source.ccr_file_size_bytes > 0);
assert!(!result.source.slurm_enabled);
assert_eq!(result.source.slurm_file_count, 0);
assert_eq!(result.quality.before_slurm, result.quality.after_slurm);
assert_eq!(result.quality.after_slurm.total, result.payloads.len());
assert_eq!(
result.quality.ccr_input.total,
result.quality.ccr_input.vrp + result.quality.ccr_input.aspa
);
}
#[test]
fn load_report_contains_slurm_metadata_and_rule_counts() {
let slurm_dir = tempdir().expect("create temp slurm dir");
let slurm = r#"{
"slurmVersion": 1,
"validationOutputFilters": {
"prefixFilters": [],
"bgpsecFilters": []
},
"locallyAddedAssertions": {
"prefixAssertions": [],
"bgpsecAssertions": []
}
}"#;
fs::write(slurm_dir.path().join("policy.slurm"), slurm).unwrap();
let config = PayloadLoadConfig {
ccr_dir: data_dir(),
slurm_dir: Some(slurm_dir.path().to_string_lossy().to_string()),
strict_ccr_validation: false,
};
let result = load_payloads_from_latest_sources_with_report(&config).unwrap();
assert!(result.source.slurm_enabled);
assert_eq!(result.source.slurm_file_count, 1);
assert_eq!(result.source.slurm_version, Some(1));
assert_eq!(result.quality.slurm_filters.prefix, 0);
assert_eq!(result.quality.slurm_assertions.prefix, 0);
assert_eq!(result.quality.before_slurm, result.quality.after_slurm);
}