fn test_flow_aggregation_one_flow()

in nfm-controller/src/events/event_provider_ebpf.rs [581:631]


    fn test_flow_aggregation_one_flow() {
        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 one flow.
        let now_us: u64 = 2025;
        for i in 0..AGG_FLOWS_MAX_ENTRIES {
            let sock_key = i as SockKey;
            let sock_context = SockContext {
                address_family: AF_INET,
                remote_ipv4: Ipv4Addr::from_str("44.33.22.11").unwrap().to_bits(),
                ..Default::default()
            };
            sock_cache.add_context(sock_key, sock_context, now_us);
            sock_stream.insert(
                sock_key,
                AggSockStats {
                    stats: SockStats {
                        bytes_received: 1,
                        ..Default::default()
                    },
                    cpus: vec![],
                },
            );
        }
        let agg_result =
            SocketQueries::aggregate_into_flows(&sock_stream, &sock_cache, &mut flow_cache);

        let expected_bytes: u64 = AGG_FLOWS_MAX_ENTRIES as u64;
        let actual_bytes: u64 = flow_cache
            .values()
            .map(|agg_flow| agg_flow.stats.bytes_received)
            .sum();
        assert_eq!(flow_cache.len(), 1);
        assert_eq!(actual_bytes, expected_bytes);
        assert_eq!(
            agg_result,
            SockOperationResult {
                completed: AGG_FLOWS_MAX_ENTRIES as u64,
                partial: 0,
                failed: 0,
            }
        );
        for flow in flow_cache.keys() {
            assert_eq!(
                flow.remote_address,
                IpAddr::from_str("44.33.22.11").unwrap()
            );
        }
    }