fn test_flow_aggregation_many_flows()

in nfm-controller/src/events/event_provider_ebpf.rs [634:679]


    fn test_flow_aggregation_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 different flows.
        let now_us = 1997;
        for i in 0..AGG_FLOWS_MAX_ENTRIES {
            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);
        assert_eq!(
            agg_result,
            SockOperationResult {
                completed: AGG_FLOWS_MAX_ENTRIES as u64,
                partial: 0,
                failed: 0,
            }
        );

        let expected_bytes: 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_eq!(actual_bytes, expected_bytes);
    }