Skip to content

Initial creation of netflow v5 payload generation#1372

Closed
scottopell wants to merge 4 commits intomainfrom
sopell/netflow-poc
Closed

Initial creation of netflow v5 payload generation#1372
scottopell wants to merge 4 commits intomainfrom
sopell/netflow-poc

Conversation

@scottopell
Copy link
Copy Markdown
Contributor

What does this PR do?

Implements netflow v5 records as a new payload type that can be sent over UDP

Motivation

Load testing for netflow processors.

Related issues

Additional Notes

@scottopell scottopell requested a review from a team as a code owner May 29, 2025 21:55
blt added a commit that referenced this pull request Jun 2, 2025
We've found the claude CLI tool is pretty helpful in this project, see
#1372 for one example. This file is
introduced to follow the recommendations in https://www.anthropic.com/engineering/claude-code-best-practices.

Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
@blt blt mentioned this pull request Jun 2, 2025
blt added a commit that referenced this pull request Jun 2, 2025
### What does this PR do?

We've found the claude CLI tool is pretty helpful in this project, see
    #1372 for one example. This file is
    introduced to follow the recommendations in https://www.anthropic.com/engineering/claude-code-best-practices.

### Motivation

Tooling improvements.
@scottopell scottopell force-pushed the sopell/netflow-poc branch from 71a1cfe to efa69a0 Compare July 10, 2025 20:35
@scottopell scottopell requested a review from Copilot July 10, 2025 20:35
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements NetFlow v5 payload generation for the lading load testing framework, allowing users to generate realistic NetFlow v5 packets for testing network flow collectors.

  • Adds a new NetFlowV5 payload type with comprehensive configuration options for flow generation
  • Implements proper NetFlow v5 packet structure with 24-byte headers and 48-byte flow records
  • Includes weighted protocol distribution, configurable IP/port ranges, and realistic flow timing

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
lading_payload/src/netflow.rs New module implementing NetFlow v5 packet generation with configurable parameters
lading_payload/src/lib.rs Exports NetFlowV5 type and adds it to the Config enum
lading_payload/src/block.rs Integrates NetFlowV5 into the block cache construction system
lading_payload/src/NETFLOW_README.md Documentation explaining NetFlow v5 implementation and usage
examples/netflow_v5.yaml Example configuration file demonstrating NetFlow v5 usage

time::{SystemTime, UNIX_EPOCH},
};

use rand::{Rng, distr::weighted::WeightedIndex, prelude::Distribution};
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider grouping related imports. The Distribution trait is from rand::distributions::Distribution, not prelude::Distribution.

Suggested change
use rand::{Rng, distr::weighted::WeightedIndex, prelude::Distribution};
use rand::{Rng, distributions::Distribution, distr::weighted::WeightedIndex};

Copilot uses AI. Check for mistakes.
where
R: Rng + ?Sized,
{
config.valid().map_err(|_e| Error::StringGenerate)?;
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message from config validation is being discarded. Consider preserving the validation error message or using a more appropriate error variant than StringGenerate.

Copilot uses AI. Check for mistakes.
config,
protocol_distribution: WeightedIndex::new(protocol_weights)?,
flow_sequence: rng.random(),
sys_uptime_base: rng.random_range(0..86_400_000), // Random base uptime (0-24h)
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number 86_400_000 should be defined as a named constant. Consider defining const MILLISECONDS_PER_DAY: u32 = 86_400_000;

Suggested change
sys_uptime_base: rng.random_range(0..86_400_000), // Random base uptime (0-24h)
sys_uptime_base: rng.random_range(0..MILLISECONDS_PER_DAY), // Random base uptime (0-24h)

Copilot uses AI. Check for mistakes.
.duration_since(UNIX_EPOCH)
.unwrap_or_default();

let current_uptime = self.sys_uptime_base + rng.random_range(0..3_600_000); // Add up to 1h
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number 3_600_000 should be defined as a named constant. Consider defining const MILLISECONDS_PER_HOUR: u32 = 3_600_000;

Suggested change
let current_uptime = self.sys_uptime_base + rng.random_range(0..3_600_000); // Add up to 1h
let current_uptime = self.sys_uptime_base + rng.random_range(0..MILLISECONDS_PER_HOUR); // Add up to 1h

Copilot uses AI. Check for mistakes.
count: flow_count,
sys_uptime: current_uptime,
unix_secs: now.as_secs() as u32,
unix_nsecs: (now.subsec_nanos() / 1000) * 1000, // Round to microseconds
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calculation is incorrect for NetFlow v5. The unix_nsecs field should contain nanoseconds since the Unix epoch second, not rounded microseconds. It should be now.subsec_nanos().

Suggested change
unix_nsecs: (now.subsec_nanos() / 1000) * 1000, // Round to microseconds
unix_nsecs: now.subsec_nanos(), // Use exact nanoseconds

Copilot uses AI. Check for mistakes.
// Calculate maximum flows that fit in the byte budget
let max_flows_by_budget = (max_bytes - HEADER_SIZE) / FLOW_RECORD_SIZE;
let desired_flows = self.config.flows_per_packet.sample(&mut rng) as usize;
let actual_flows = desired_flows.min(max_flows_by_budget).min(30); // NetFlow v5 max is 30
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number 30 should be defined as a named constant. Consider defining const MAX_FLOWS_PER_PACKET: usize = 30;

Suggested change
let actual_flows = desired_flows.min(max_flows_by_budget).min(30); // NetFlow v5 max is 30
let actual_flows = desired_flows.min(max_flows_by_budget).min(MAX_FLOWS_PER_PACKET);

Copilot uses AI. Check for mistakes.
@blt
Copy link
Copy Markdown
Collaborator

blt commented Sep 3, 2025

Closing, still interested in it but I want to keep the backlog focused on active work.

@blt blt closed this Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants