Cisco Network Traffic Generation & QoS Testing Scripts
Write Python scripts that generate controlled network traffic for testing QoS policies and network performance. Follow these standards:
Traffic Types
TCP Traffic
- Bulk data transfers (saturate a link to test bandwidth shaping)
- Multiple parallel TCP streams (simulate many users)
- Configurable payload size and duration
- HTTP/HTTPS traffic simulation
- FTP-like large file transfers
- Configurable TCP window size for throughput control
UDP Traffic
- Constant bitrate (CBR) streams at specified rates (e.g., 1 Mbps, 10 Mbps, 100 Mbps)
- Variable bitrate (VBR) with configurable burst patterns
- Configurable packet size (64 byte small packets to 9000 byte jumbo)
- Adjustable packets-per-second rate
- Multi-stream generation to different destinations
Voice (VoIP) Simulation
- G.711 profile: 64 kbps, 160 byte payload, 20ms interval, UDP
- G.729 profile: 8 kbps, 20 byte payload, 20ms interval, UDP
- RTP-like headers with sequence numbers and timestamps
- Simulate multiple concurrent calls (e.g., 50 calls = ~5 Mbps G.711)
- Jitter injection for realistic voice patterns
- Mark with DSCP EF (46) to test priority queue
Video Simulation
- Constant bitrate video: 2-10 Mbps sustained UDP streams
- Bursty video: I-frame bursts followed by smaller P/B frames
- Configurable resolution profiles (720p ~5 Mbps, 1080p ~10 Mbps, 4K ~25 Mbps)
- Mark with DSCP AF41 (34) to test video queue
Signaling / Control Traffic
- Small periodic packets (SIP, SCCP-like signaling patterns)
- Mark with DSCP CS3 (24) for call signaling class
- Low bandwidth, latency-sensitive patterns
Scavenger / Bulk Data
- Large sustained transfers marked DSCP CS1 (8)
- Test that scavenger class gets deprioritized under congestion
- Peer-to-peer style traffic patterns
Background / Best Effort
- Mixed traffic patterns at DSCP 0 (default)
- Web browsing simulation (short bursts, variable intervals)
- Simulate realistic background network noise
DSCP Marking Reference
| Class |
DSCP Name |
DSCP Value |
Per-Hop Behavior |
Typical Use |
| EF |
EF |
46 |
Expedited Forwarding |
Voice RTP |
| CS5 |
CS5 |
40 |
Signaling |
Call signaling (SIP/SCCP) |
| AF41 |
AF41 |
34 |
Assured Forwarding |
Video conferencing |
| AF31 |
AF31 |
26 |
Assured Forwarding |
Streaming video |
| AF21 |
AF21 |
18 |
Assured Forwarding |
Transactional data (ERP, CRM) |
| AF11 |
AF11 |
10 |
Assured Forwarding |
Bulk data |
| CS3 |
CS3 |
24 |
Call signaling |
Broadcast video |
| CS1 |
CS1 |
8 |
Scavenger |
Backup, P2P |
| DF |
DF |
0 |
Default / Best Effort |
Web, email |
Traffic Profiles (Presets)
Enterprise QoS Test Suite
profiles:
voice:
protocol: udp
codec: g711
dscp: 46
streams: 20 # 20 concurrent calls
duration: 120s
video:
protocol: udp
rate_mbps: 10
dscp: 34
burst_size: 15000 # bytes
duration: 120s
signaling:
protocol: udp
rate_kbps: 50
dscp: 24
packet_size: 200
duration: 120s
data_critical:
protocol: tcp
streams: 5
dscp: 18
duration: 120s
bulk:
protocol: tcp
streams: 20
dscp: 0
duration: 120s
scavenger:
protocol: tcp
streams: 10
dscp: 8
duration: 120s
Link Saturation Profile
# Fill a link to test queuing behavior under congestion
saturate:
protocol: udp
rate_mbps: 100 # adjust to match link speed
dscp: 0
packet_size: 1400
duration: 60s
QoS Validation (Collect from Devices)
After generating traffic, collect QoS stats from Cisco devices to validate policy behavior:
# Interface queuing stats
show policy-map interface {interface}
# Class-map match counters
show policy-map interface {interface} | include Class|packets|bytes|rate|drops
# DSCP marking verification
show ip nbar protocol-discovery
show mls qos interface {interface} statistics
# Queue drops and tail drops
show platform hardware fed switch active qos queue stats interface {interface}
What to Validate
- Priority queue (EF/voice): zero drops, low latency, low jitter
- Video class (AF41): minimal drops, bandwidth guarantee met
- Data classes (AF21/AF11): fair bandwidth allocation
- Best effort (DF): gets remaining bandwidth after guaranteed classes
- Scavenger (CS1): first to be dropped under congestion
- Policing: traffic exceeding rate is remarked or dropped as configured
- Shaping: output rate matches configured shaper
Script Architecture
# Traffic generator scripts should follow this pattern:
# 1. Parse traffic profile (YAML or CLI args)
# 2. Set up sender/receiver pairs
# 3. Open sockets with DSCP marking
# 4. Generate traffic at specified rates
# 5. Measure: throughput, packet loss, latency, jitter
# 6. Optionally collect QoS counters from devices via SSH (before/after)
# 7. Report results: per-class throughput, loss, latency, jitter
# Sender sets DSCP via socket option:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Set DSCP EF (46) - shift left 2 bits for TOS field
sock.setsockopt(socket.IPPROTO_IP, socket.IP_TOS, 46 << 2)
Measurement & Reporting
Per-Stream Metrics
- Throughput (bps) achieved vs target
- Packet loss percentage
- One-way latency (requires clock sync or estimation)
- Jitter (inter-packet delay variation)
- Out-of-order packets
QoS Policy Report
- Per-class bandwidth allocation (expected vs actual)
- Drop counts per class under congestion
- Priority queue behavior (EF should have zero loss)
- Policing/shaping conformance
Output Formats
- Real-time console output with
rich (live updating tables)
- CSV export of per-second measurements
- JSON summary report
- Before/after comparison of device QoS counters
Libraries to Use
socket for raw TCP/UDP traffic with DSCP marking
scapy for crafted packets with full header control
asyncio for concurrent stream management
iperf3 Python wrapper (iperf3 library) as an alternative to raw sockets
netmiko for collecting QoS counters from devices
pyats + genie for parsing show policy-map output
rich for live traffic dashboards
numpy for jitter/latency statistics
yaml for traffic profile definitions
concurrent.futures / threading for multi-stream generation
time / struct for packet timestamps and sequencing
Receiver Script
Always generate a paired receiver script that:
- Listens on the target port(s)
- Tracks sequence numbers for loss detection
- Measures inter-packet arrival time for jitter
- Calculates throughput per second
- Reports summary stats when traffic stops
Safety & Best Practices
- Always require explicit target IP/port (never broadcast/multicast by default)
- Include a
--max-rate safety cap to prevent accidental link flooding
- Default duration should have a sane limit (e.g., 60 seconds)
- Support graceful stop via Ctrl+C with summary output
- Log all traffic parameters used
- Warn if generating traffic to production networks
- Include
--dry-run flag that shows what would be generated without sending
- Require
--confirm flag when rate exceeds 50% of a specified link speed
- NEVER generate traffic intended for denial-of-service; these scripts are for legitimate QoS testing in controlled lab and production environments with authorization
1---2name: cisco-traffic-gen3description: Generate Python scripts that create network traffic and load for testing Cisco QoS policies, bandwidth, and network performance. Use when the user wants to generate test traffic, simulate load, validate QoS markings, or stress test network links.4---56## Cisco Network Traffic Generation & QoS Testing Scripts78Write Python scripts that generate controlled network traffic for testing QoS policies and network performance. Follow these standards:910### Traffic Types1112#### TCP Traffic13- Bulk data transfers (saturate a link to test bandwidth shaping)14- Multiple parallel TCP streams (simulate many users)15- Configurable payload size and duration16- HTTP/HTTPS traffic simulation17- FTP-like large file transfers18- Configurable TCP window size for throughput control1920#### UDP Traffic21- Constant bitrate (CBR) streams at specified rates (e.g., 1 Mbps, 10 Mbps, 100 Mbps)22- Variable bitrate (VBR) with configurable burst patterns23- Configurable packet size (64 byte small packets to 9000 byte jumbo)24- Adjustable packets-per-second rate25- Multi-stream generation to different destinations2627#### Voice (VoIP) Simulation28- G.711 profile: 64 kbps, 160 byte payload, 20ms interval, UDP29- G.729 profile: 8 kbps, 20 byte payload, 20ms interval, UDP30- RTP-like headers with sequence numbers and timestamps31- Simulate multiple concurrent calls (e.g., 50 calls = ~5 Mbps G.711)32- Jitter injection for realistic voice patterns33- Mark with DSCP EF (46) to test priority queue3435#### Video Simulation36- Constant bitrate video: 2-10 Mbps sustained UDP streams37- Bursty video: I-frame bursts followed by smaller P/B frames38- Configurable resolution profiles (720p ~5 Mbps, 1080p ~10 Mbps, 4K ~25 Mbps)39- Mark with DSCP AF41 (34) to test video queue4041#### Signaling / Control Traffic42- Small periodic packets (SIP, SCCP-like signaling patterns)43- Mark with DSCP CS3 (24) for call signaling class44- Low bandwidth, latency-sensitive patterns4546#### Scavenger / Bulk Data47- Large sustained transfers marked DSCP CS1 (8)48- Test that scavenger class gets deprioritized under congestion49- Peer-to-peer style traffic patterns5051#### Background / Best Effort52- Mixed traffic patterns at DSCP 0 (default)53- Web browsing simulation (short bursts, variable intervals)54- Simulate realistic background network noise5556### DSCP Marking Reference5758| Class | DSCP Name | DSCP Value | Per-Hop Behavior | Typical Use |59|-------|-----------|------------|-------------------|-------------|60| EF | EF | 46 | Expedited Forwarding | Voice RTP |61| CS5 | CS5 | 40 | Signaling | Call signaling (SIP/SCCP) |62| AF41 | AF41 | 34 | Assured Forwarding | Video conferencing |63| AF31 | AF31 | 26 | Assured Forwarding | Streaming video |64| AF21 | AF21 | 18 | Assured Forwarding | Transactional data (ERP, CRM) |65| AF11 | AF11 | 10 | Assured Forwarding | Bulk data |66| CS3 | CS3 | 24 | Call signaling | Broadcast video |67| CS1 | CS1 | 8 | Scavenger | Backup, P2P |68| DF | DF | 0 | Default / Best Effort | Web, email |6970### Traffic Profiles (Presets)7172#### Enterprise QoS Test Suite73```yaml74profiles:75 voice:76 protocol: udp77 codec: g71178 dscp: 4679 streams: 20 # 20 concurrent calls80 duration: 120s81 video:82 protocol: udp83 rate_mbps: 1084 dscp: 3485 burst_size: 15000 # bytes86 duration: 120s87 signaling:88 protocol: udp89 rate_kbps: 5090 dscp: 2491 packet_size: 20092 duration: 120s93 data_critical:94 protocol: tcp95 streams: 596 dscp: 1897 duration: 120s98 bulk:99 protocol: tcp100 streams: 20101 dscp: 0102 duration: 120s103 scavenger:104 protocol: tcp105 streams: 10106 dscp: 8107 duration: 120s108```109110#### Link Saturation Profile111```yaml112# Fill a link to test queuing behavior under congestion113saturate:114 protocol: udp115 rate_mbps: 100 # adjust to match link speed116 dscp: 0117 packet_size: 1400118 duration: 60s119```120121### QoS Validation (Collect from Devices)122123After generating traffic, collect QoS stats from Cisco devices to validate policy behavior:124125```126# Interface queuing stats127show policy-map interface {interface}128129# Class-map match counters130show policy-map interface {interface} | include Class|packets|bytes|rate|drops131132# DSCP marking verification133show ip nbar protocol-discovery134show mls qos interface {interface} statistics135136# Queue drops and tail drops137show platform hardware fed switch active qos queue stats interface {interface}138```139140#### What to Validate141- **Priority queue** (EF/voice): zero drops, low latency, low jitter142- **Video class** (AF41): minimal drops, bandwidth guarantee met143- **Data classes** (AF21/AF11): fair bandwidth allocation144- **Best effort** (DF): gets remaining bandwidth after guaranteed classes145- **Scavenger** (CS1): first to be dropped under congestion146- **Policing**: traffic exceeding rate is remarked or dropped as configured147- **Shaping**: output rate matches configured shaper148149### Script Architecture150151```python152# Traffic generator scripts should follow this pattern:153154# 1. Parse traffic profile (YAML or CLI args)155# 2. Set up sender/receiver pairs156# 3. Open sockets with DSCP marking157# 4. Generate traffic at specified rates158# 5. Measure: throughput, packet loss, latency, jitter159# 6. Optionally collect QoS counters from devices via SSH (before/after)160# 7. Report results: per-class throughput, loss, latency, jitter161162# Sender sets DSCP via socket option:163import socket164sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)165# Set DSCP EF (46) - shift left 2 bits for TOS field166sock.setsockopt(socket.IPPROTO_IP, socket.IP_TOS, 46 << 2)167```168169### Measurement & Reporting170171#### Per-Stream Metrics172- Throughput (bps) achieved vs target173- Packet loss percentage174- One-way latency (requires clock sync or estimation)175- Jitter (inter-packet delay variation)176- Out-of-order packets177178#### QoS Policy Report179- Per-class bandwidth allocation (expected vs actual)180- Drop counts per class under congestion181- Priority queue behavior (EF should have zero loss)182- Policing/shaping conformance183184#### Output Formats185- Real-time console output with `rich` (live updating tables)186- CSV export of per-second measurements187- JSON summary report188- Before/after comparison of device QoS counters189190### Libraries to Use191- `socket` for raw TCP/UDP traffic with DSCP marking192- `scapy` for crafted packets with full header control193- `asyncio` for concurrent stream management194- `iperf3` Python wrapper (`iperf3` library) as an alternative to raw sockets195- `netmiko` for collecting QoS counters from devices196- `pyats` + `genie` for parsing `show policy-map` output197- `rich` for live traffic dashboards198- `numpy` for jitter/latency statistics199- `yaml` for traffic profile definitions200- `concurrent.futures` / `threading` for multi-stream generation201- `time` / `struct` for packet timestamps and sequencing202203### Receiver Script204Always generate a paired receiver script that:205- Listens on the target port(s)206- Tracks sequence numbers for loss detection207- Measures inter-packet arrival time for jitter208- Calculates throughput per second209- Reports summary stats when traffic stops210211### Safety & Best Practices212- Always require explicit target IP/port (never broadcast/multicast by default)213- Include a `--max-rate` safety cap to prevent accidental link flooding214- Default duration should have a sane limit (e.g., 60 seconds)215- Support graceful stop via Ctrl+C with summary output216- Log all traffic parameters used217- Warn if generating traffic to production networks218- Include `--dry-run` flag that shows what would be generated without sending219- Require `--confirm` flag when rate exceeds 50% of a specified link speed220- NEVER generate traffic intended for denial-of-service; these scripts are for legitimate QoS testing in controlled lab and production environments with authorization