in nfm-controller/src/events/event_provider_ebpf.rs [682:727]
fn test_flow_aggregation_too_many_flows() {
let mut sock_stream: HashMap<SockKey, AggSockStats> = HashMap::new();
let mut sock_cache = SockCache::with_max_entries(AGG_FLOWS_MAX_ENTRIES as usize);
let mut flow_cache: HashMap<FlowProperties, AggregateResults> = HashMap::new();
// Test the aggregation of many sockets into *too many* flows.
let now_us = 2342;
for i in 0..AGG_FLOWS_MAX_ENTRIES * 2 {
let sock_key = i as SockKey;
let sock_context = SockContext {
address_family: AF_INET,
remote_ipv4: i,
..Default::default()
};
sock_cache.add_context(sock_key, sock_context, now_us);
sock_stream.insert(
sock_key,
AggSockStats {
stats: SockStats {
bytes_received: i as u64,
..Default::default()
},
cpus: vec![],
},
);
}
let agg_result =
SocketQueries::aggregate_into_flows(&sock_stream, &sock_cache, &mut flow_cache);
let expected_bytes_min: u64 =
((AGG_FLOWS_MAX_ENTRIES - 1) * (AGG_FLOWS_MAX_ENTRIES / 2)).into();
let actual_bytes: u64 = flow_cache
.values()
.map(|agg_flow| agg_flow.stats.bytes_received)
.sum();
assert_eq!(flow_cache.len(), AGG_FLOWS_MAX_ENTRIES as usize);
assert!(actual_bytes >= expected_bytes_min);
assert_eq!(
agg_result,
SockOperationResult {
completed: AGG_FLOWS_MAX_ENTRIES as u64,
partial: 0,
failed: AGG_FLOWS_MAX_ENTRIES as u64,
}
);
}