# Cisco Traffic Gen

> 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.

- Skill: `bradmccloskey/cisco-traffic-gen` (Agent Skill)
- Install (CLI): `npx skillmds@latest add bradmccloskey/cisco-traffic-gen`
- Raw SKILL.md: https://api.skillmd.com/api/skills/bradmccloskey/cisco-traffic-gen/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: bradmccloskey (https://skillmd.com/u/bradmccloskey)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/bradmccloskey/cisco-traffic-gen

---


## 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
```yaml
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
```yaml
# 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

```python
# 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

