Overview
The router receives UDP packets from clients and servers, then dispatches them to their destinations. During delivery, it can simulate adverse network conditions:Packet Loss
Randomly drop packets based on a configured probability
Network Delay
Introduce variable delays up to a maximum duration
The router changes the peer address value from
toAddr to fromAddr during packet delivery, enabling proper bidirectional communication.Command Syntax
Configuration Parameters
Port number that the router listens on for incoming packets.
Both client and server must communicate through this port. Choose a port that doesn’t conflict with your server port.
Probability (0.0 to 1.0) that any given packet will be dropped during transmission.Common values:
0.0- No packet loss (ideal network)0.05- 5% loss (good network)0.1- 10% loss (typical Wi-Fi)0.2- 20% loss (poor network)0.3+- High loss (stress testing)
Maximum duration that any packet can be delayed. Each packet receives a random delay between 0 and this value.Common values:
Use 0 to route packets immediately without delay. Format:
5s, 100ms, 1m, etc.0- No delay (instant delivery)10ms- Minimal delay (LAN)50ms- Moderate delay (internet)100ms- High delay (poor connection)500ms+- Very high delay (extreme testing)
Seed value for the random number generator. Using the same seed produces repeatable random behaviors.
Basic Configurations
Ideal Network (No Loss, No Delay)
Test basic functionality without network issues:This configuration is useful for verifying that your client and server work correctly before introducing network issues.
Light Packet Loss
Simulate a good network with occasional packet loss:Moderate Network Conditions
Test resilience with noticeable packet loss and delay:Poor Network Conditions
Stress test with high packet loss:Extreme Testing
Test protocol limits with severe network issues:Reproducible Testing
Using Fixed Seeds
For reproducible test scenarios, use the same seed value:With the same seed, the exact same packets will be dropped and delayed in the same way. This is crucial for debugging specific issues.
Variable Testing
For different behavior each time, omit the seed or use different values:Router Logging
The router logs all activity to both console androuter.log file.
Log Format
Understanding Log Entries
Viewing Logs
- Console Output
- Log File
- Analyze Logs
Logs are displayed in real-time on the console:You’ll see packet activity as it happens.
Testing Scenarios
- Protocol Verification
- Loss Tolerance
- Delay Handling
- Combined Stress
- Extreme Stress
Verify basic protocol correctness:Expected:
- All packets delivered in order
- No retransmissions needed
- Fast transfer times
Advanced Configuration
Multi-Client Testing
The router handles multiple clients simultaneously:The router maintains separate packet queues and applies drop/delay rules independently to each packet.
Performance Tuning
Delay Distribution
Delay is uniformly distributed between 0 and max-delay. Each packet gets a random delay value.
Queue Management
The router tracks queue size for delayed packets. High queue sizes indicate network congestion.
Packet Format
Understanding the packet structure helps with debugging:Troubleshooting
Router not starting
Router not starting
Check if the port is already in use:
Too many packets dropped
Too many packets dropped
If transfers are failing, reduce the drop rate:Check router logs to see actual drop statistics:
Packets timing out
Packets timing out
Reduce max-delay or increase client timeout values:
Can't reproduce issue
Can't reproduce issue
Use a fixed seed to reproduce the same packet loss pattern:
Log file growing too large
Log file growing too large
Truncate or rotate the log file:
Complete Testing Example
Here’s a comprehensive test setup:Monitor Router Activity
In another terminal:This shows the last 20 log lines, updating every second.
Next Steps
Client Usage
Test your router configuration with the client
Server Setup
Configure the server to work with the router