# UCI Configuration Reference

Configuration file: `/etc/config/qos`

## classify — Traffic Classification

Each `classify` section defines a rule that matches packets and applies actions.

```
config classify '<name>'
    # --- Control ---
    option enable '1'              # 0/1 - Enable this rule
    option order '1'               # Priority order (lower = evaluated first)

    # --- Classification Criteria (match conditions) ---
    option ifname 'ae_wan'           # Interface name
    option all_interfaces '0'      # Apply to all interfaces (0/1)
    option proto '6'               # IP protocol (6=TCP, 17=UDP, 1=ICMP, or name)
    option ethertype 'IPv4'        # Ethertype (IPv4, IPv6, or hex e.g. 0x0800)
    option src_ip '192.168.1.0/24' # Source IP with CIDR mask
    option dest_ip '10.0.0.0/8'   # Destination IP with CIDR mask
    option src_port '1024'         # Source port
    option dest_port '80'          # Destination port
    option src_port_range '65535'  # Source port range max (from src_port to this)
    option dst_port_range '65535'  # Destination port range max
    option src_mac 'AA:BB:CC:DD:EE:FF'   # Source MAC address
    option dst_mac 'AA:BB:CC:DD:EE:FF'   # Destination MAC address
    option vid_check '100'         # Match VLAN ID (802.1Q)
    option pcp_check '3'           # Match P-bit / PCP value (0-7)
    option dscp_filter '46'        # Match DSCP value (0-63, -1 = disabled)
    option ip_len_min '64'         # Minimum IP packet length (bytes)
    option ip_len_max '1500'       # Maximum IP packet length (bytes)

    # --- DHCP-based Criteria ---
    option src_vendor_class_id 'vendor1'   # DHCPv4 Option 60
    option dest_vendor_class_id 'vendor2'
    option src_user_class_id 'user1'       # DHCPv4 Option 77 / DHCPv6 Option 15
    option dest_user_class_id 'user2'
    option src_client_id 'client1'         # DHCPv4 Option 61 / DHCPv6 Option 1
    option dest_client_id 'client2'

    # --- Classification Actions ---
    option traffic_class '0'       # Queue assignment (0-7, maps 1:1 to queue ID)
    option dscp_mark '46'          # Rewrite DSCP value (0-63)
    option pcp_mark '7'            # Rewrite 802.1p P-bit (0-7)
    option vid_mark '200'          # Rewrite VLAN ID
    option forwarding_policy '100' # fwmark tag for policy-based routing; Device.Routing.Policy.ForwardingPolicy must reference this value to select the routing table
    option policer 'policer_1'     # Name of policer section to apply
```

## queue — Queue Configuration

Each `queue` section defines a hardware queue bound to a port.

```
config queue 'q_0_ae_wan'
    option enable '1'          # Enable this queue
    option ifname 'ae_wan'       # Interface this queue belongs to
    option precedence '8'      # Priority (1+, lower = higher priority)
    option scheduling 'SP'     # Scheduling: SP, WRR, or WFQ
    option weight '1'          # Weight for WRR scheduling
    option rate '0'            # Per-queue shaping rate in bps (0 = unlimited)
    option burst_size '0'      # Burst size in bytes (0 = default)
```

**Naming convention:** `q_<queue_id>_<interface>` (e.g., `q_0_ae_wan` is queue 0 on ae_wan).

## shaper — Port-Level Traffic Shaping

Each `shaper` section applies egress rate-limiting to an entire port.

```
config shaper 'shaper_ae_wan'
    option enable '1'
    option ifname 'ae_wan'       # Interface to shape
    option rate '100000000'    # Rate in bits per second (100 Mbps)
    option burst_size '12000'  # Burst size in bytes
```

## policer — Ingress Traffic Policing

Each `policer` section defines a metering profile applied to classified traffic.

```
config policer 'policer_1'
    option enable '1'
    option name 'policer_1'              # Name used by classify->policer reference
    option committed_rate '10000000'     # CIR in bits per second
    option committed_burst_size '12000'  # CBS in bytes
    option excess_burst_size '24000'     # EBS in bytes
    option peak_rate '20000000'          # PIR in bits per second
    option peak_burst_size '24000'       # PBS in bytes
    option meter_type '0'                # 0=SimpleTokenBucket, 1=srTCM, 2=trTCM
```

**Meter Types:**

| Value | Type | Description |
|---|---|---|
| 0 | SimpleTokenBucket | Single rate, single burst bucket |
| 1 | SingleRateThreeColor (srTCM) | Single rate with committed and excess burst |
| 2 | TwoRateThreeColor (trTCM) | Dual rate (committed + peak) with burst sizes |
