# QoS Deployment Scenarios

- [Scenario 1: VoIP Traffic Prioritization](#scenario-1-voip-traffic-prioritization)
- [Scenario 2: IPTV/Multicast Prioritization](#scenario-2-iptvmulticast-prioritization)
- [Scenario 3: WAN Egress Traffic Shaping](#scenario-3-wan-egress-traffic-shaping)
- [Scenario 4: Per-Queue Rate Limiting](#scenario-4-per-queue-rate-limiting)
- [Scenario 5: DSCP-to-P-bit Mapping](#scenario-5-dscp-to-p-bit-mapping)
- [Scenario 6: VLAN Translation](#scenario-6-vlan-translation)
- [Scenario 7: P-bit/802.1p Translation](#scenario-7-pbit8021p-translation)
- [Scenario 8: Ingress Policing (Rate Limiting)](#scenario-8-ingress-policing-rate-limiting)
- [Scenario 9: Policy-Based Routing (Source-Based Routing)](#scenario-9-policy-based-routing-source-based-routing)
- [Scenario 10: WRR Scheduling with Weighted Queues](#scenario-10-wrr-scheduling-with-weighted-queues)
- [Scenario 11: Multi-Criteria Classification (Gaming + Streaming)](#scenario-11-multi-criteria-classification-gaming--streaming)
- [Scenario 12: Classify by Ingress Port](#scenario-12-classify-by-ingress-port)
- [Scenario 13: Classify by 802.1p P-bit](#scenario-13-classify-by-8021p-p-bit)
- [Scenario 14: Classify by VLAN ID](#scenario-14-classify-by-vlan-id)
- [Scenario 15: Classify by Source/Destination MAC](#scenario-15-classify-by-sourcedestination-mac)
- [Scenario 16: Classify by Ethernet Type](#scenario-16-classify-by-ethernet-type)
- [Scenario 17: Set DSCP Based on Ingress Port](#scenario-17-set-dscp-based-on-ingress-port)
- [Scenario 18: Set DSCP Based on Source IP](#scenario-18-set-dscp-based-on-source-ip)
- [Scenario 19: Classify by Destination IP](#scenario-19-classify-by-destination-ip)
- [Scenario 20: Classify by DSCP Value](#scenario-20-classify-by-dscp-value)
- [Scenario 21: Classify by L4 Protocol](#scenario-21-classify-by-l4-protocol)
- [Scenario 22: Set DSCP Based on L4 Protocol](#scenario-22-set-dscp-based-on-l4-protocol)
- [Scenario 23: Classify by Source/Destination Port](#scenario-23-classify-by-sourcedestination-port)
- [Scenario 24: Classify by Port Range](#scenario-24-classify-by-port-range)
- [Scenario 25: Classify by L3 Packet Length](#scenario-25-classify-by-l3-packet-length)
- [Scenario 26: Strict Priority Scheduling](#scenario-26-strict-priority-scheduling)
- [Scenario 27: Percentage-Based Traffic Shaping](#scenario-27-percentage-based-traffic-shaping)
- [Statistics and Monitoring](QoS_Troubleshooting.md#statistics-and-monitoring)

---

### Scenario 1: VoIP Traffic Prioritization

**Goal:** Ensure VoIP (SIP + RTP) traffic gets highest priority queue with EF DSCP marking.

#### UCI Configuration

```
# Prioritize SIP signaling (UDP port 5060)
config classify 'voip_sip'
    option enable '1'
    option order '1'
    option proto '17'
    option dest_port '5060'
    option traffic_class '7'
    option dscp_mark '46'
    option pcp_mark '7'

# Prioritize RTP media (UDP port range 10000-20000)
config classify 'voip_rtp'
    option enable '1'
    option order '2'
    option proto '17'
    option dest_port '10000'
    option dst_port_range '20000'
    option traffic_class '7'
    option dscp_mark '46'
    option pcp_mark '7'
```

#### TR-181 Configuration

```bash
# Create SIP classification
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Order 1
obuspa -c set Device.QoS.Classification.1.AllInterfaces true
obuspa -c set Device.QoS.Classification.1.Protocol 17
obuspa -c set Device.QoS.Classification.1.DestPort 5060
obuspa -c set Device.QoS.Classification.1.TrafficClass 7
obuspa -c set Device.QoS.Classification.1.DSCPMark 46
obuspa -c set Device.QoS.Classification.1.EthernetPriorityMark 7
obuspa -c set Device.QoS.Classification.1.Enable true

# Create RTP classification
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.2.Order 2
obuspa -c set Device.QoS.Classification.2.AllInterfaces true
obuspa -c set Device.QoS.Classification.2.Protocol 17
obuspa -c set Device.QoS.Classification.2.DestPort 10000
obuspa -c set Device.QoS.Classification.2.DestPortRangeMax 20000
obuspa -c set Device.QoS.Classification.2.TrafficClass 7
obuspa -c set Device.QoS.Classification.2.DSCPMark 46
obuspa -c set Device.QoS.Classification.2.EthernetPriorityMark 7
obuspa -c set Device.QoS.Classification.2.Enable true
```

#### Apply and Verify

```bash
/etc/init.d/qos reload

# Check that VoIP traffic goes to queue 7
ubus call qos queue_stats '{"ifname":"ae_wan", "qid":7}'
```

---

### Scenario 2: IPTV/Multicast Prioritization

**Goal:** Prioritize IGMP and multicast video traffic to a dedicated high-priority queue.

#### UCI Configuration

```
# Prioritize IGMP (protocol 2)
config classify 'igmp_priority'
    option enable '1'
    option order '1'
    option proto '2'
    option traffic_class '6'
    option dscp_mark '40'
    option pcp_mark '6'

# Prioritize multicast to specific group range (239.0.0.0/8)
config classify 'mcast_video'
    option enable '1'
    option order '2'
    option proto '17'
    option dest_ip '239.0.0.0/8'
    option traffic_class '6'
    option dscp_mark '40'
    option pcp_mark '6'
```

#### TR-181 Configuration

```bash
# IGMP
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Order 1
obuspa -c set Device.QoS.Classification.1.AllInterfaces true
obuspa -c set Device.QoS.Classification.1.Protocol 2
obuspa -c set Device.QoS.Classification.1.TrafficClass 6
obuspa -c set Device.QoS.Classification.1.DSCPMark 40
obuspa -c set Device.QoS.Classification.1.EthernetPriorityMark 6
obuspa -c set Device.QoS.Classification.1.Enable true

# Multicast video
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.2.Order 2
obuspa -c set Device.QoS.Classification.2.AllInterfaces true
obuspa -c set Device.QoS.Classification.2.Protocol 17
obuspa -c set Device.QoS.Classification.2.DestIP 239.0.0.0
obuspa -c set Device.QoS.Classification.2.DestMask /8
obuspa -c set Device.QoS.Classification.2.TrafficClass 6
obuspa -c set Device.QoS.Classification.2.DSCPMark 40
obuspa -c set Device.QoS.Classification.2.EthernetPriorityMark 6
obuspa -c set Device.QoS.Classification.2.Enable true
```

---

### Scenario 3: WAN Egress Traffic Shaping

**Goal:** Limit the WAN uplink to 50 Mbps to prevent upstream congestion (e.g., on a 100 Mbps link).

#### UCI Configuration

```
config shaper 'shaper_wan'
    option enable '1'
    option ifname 'ae_wan'
    option rate '50000000'
    option burst_size '15000'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Shaper.
obuspa -c set Device.QoS.Shaper.1.Interface Device.Ethernet.Interface.6.
obuspa -c set Device.QoS.Shaper.1.ShapingRate 50000000
obuspa -c set Device.QoS.Shaper.1.ShapingBurstSize 15000
obuspa -c set Device.QoS.Shaper.1.Enable true
```

#### Apply and Verify

```bash
/etc/init.d/qos reload

# Monitor traffic on WAN to confirm shaping
ubus call qos queue_stats '{"ifname":"ae_wan"}'
```

---

### Scenario 4: Per-Queue Rate Limiting

**Goal:** On the WAN interface, limit best-effort queue (queue 0) to 10 Mbps while leaving high-priority queues uncapped.

#### UCI Configuration

```
config queue 'q_0_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '8'
    option scheduling 'SP'
    option rate '10000000'
    option burst_size '15000'
    option weight '1'

config queue 'q_7_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '1'
    option scheduling 'SP'
    option rate '0'
    option burst_size '0'
    option weight '1'
```

#### TR-181 Configuration

```bash
# Assuming queue instances already exist (auto-generated)
# Set rate limit on queue 1 (maps to q_0_ae_wan)
obuspa -c set Device.QoS.Queue.1.ShapingRate 10000000
obuspa -c set Device.QoS.Queue.1.ShapingBurstSize 15000

# Verify queue 8 (maps to q_7_ae_wan) is unlimited
obuspa -c get Device.QoS.Queue.8.ShapingRate
# Should return -1 (unlimited)
```

---

### Scenario 5: DSCP-to-P-bit Mapping

**Goal:** Map incoming DSCP values to 802.1p P-bit values on a specific LAN port for proper upstream QoS signaling.

This is useful when the WAN service requires specific P-bit values based on the traffic type indicated by DSCP.

#### Common DSCP-to-P-bit Mapping Table

| DSCP | PHB | P-bit | Traffic Type |
|---|---|---|---|
| 0 | BE (Best Effort) | 0 | Best Effort |
| 8 | CS1 | 1 | Background |
| 10,12,14 | AF11-AF13 | 1 | Background |
| 18,20,22 | AF21-AF23 | 2 | Spare |
| 24 | CS3 | 3 | Excellent Effort |
| 26,28,30 | AF31-AF33 | 3 | Excellent Effort |
| 32 | CS4 | 4 | Controlled Load |
| 34,36,38 | AF41-AF43 | 4 | Controlled Load |
| 40 | CS5 | 5 | Video |
| 46 | EF | 6 | Voice |
| 48 | CS6 | 7 | Network Control |

#### UCI Configuration (per-port, per-DSCP)

```
# Map DSCP 0 (BE) -> P-bit 0
config classify 'dscp_be'
    option enable '1'
    option order '1'
    option ifname 'eth0.2'
    option dscp_filter '0'
    option pcp_mark '0'

# Map DSCP 46 (EF/Voice) -> P-bit 6
config classify 'dscp_ef'
    option enable '1'
    option order '2'
    option ifname 'eth0.2'
    option dscp_filter '46'
    option pcp_mark '6'

# Map DSCP 34 (AF41/Video) -> P-bit 4
config classify 'dscp_af41'
    option enable '1'
    option order '3'
    option ifname 'eth0.2'
    option dscp_filter '34'
    option pcp_mark '4'

# Map DSCP 26 (AF31) -> P-bit 3
config classify 'dscp_af31'
    option enable '1'
    option order '4'
    option ifname 'eth0.2'
    option dscp_filter '26'
    option pcp_mark '3'
```

#### TR-181 Configuration

```bash
# Map DSCP 46 -> P-bit 6 on Ethernet Interface 2 (LAN2 / eth0.2)
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.2.
obuspa -c set Device.QoS.Classification.1.DSCPCheck 46
obuspa -c set Device.QoS.Classification.1.EthernetPriorityMark 6
obuspa -c set Device.QoS.Classification.1.Enable true

# Map DSCP 34 -> P-bit 4
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.2.Interface Device.Ethernet.Interface.2.
obuspa -c set Device.QoS.Classification.2.DSCPCheck 34
obuspa -c set Device.QoS.Classification.2.EthernetPriorityMark 4
obuspa -c set Device.QoS.Classification.2.Enable true
```

**Note:** The mapping rules are visible in the ebtables `broute` table's `dscp2pbit` chain.

---

### Scenario 6: VLAN Translation

**Goal:** Translate customer VLAN 100 to service provider VLAN 200 (and back). This is used at the edge between customer and provider networks.

#### UCI Configuration

```
# Egress: C-VLAN 100 -> S-VLAN 200 (on LAN port)
config classify 'vlan_c_to_s'
    option enable '1'
    option order '1'
    option ifname 'eth0.3'
    option vid_check '100'
    option vid_mark '200'

# Ingress: S-VLAN 200 -> C-VLAN 100 (on WAN port)
config classify 'vlan_s_to_c'
    option enable '1'
    option order '2'
    option ifname 'ae_wan'
    option vid_check '200'
    option vid_mark '100'
```

#### TR-181 Configuration

```bash
# C-VLAN 100 -> S-VLAN 200 on LAN3 (eth0.3)
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.3.
obuspa -c set Device.QoS.Classification.1.VLANIDCheck 100
obuspa -c set Device.QoS.Classification.1.X_IOWRT_EU_VLANIDMark 200
obuspa -c set Device.QoS.Classification.1.Enable true

# S-VLAN 200 -> C-VLAN 100 on WAN (ae_wan)
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.2.Interface Device.Ethernet.Interface.6.
obuspa -c set Device.QoS.Classification.2.VLANIDCheck 200
obuspa -c set Device.QoS.Classification.2.X_IOWRT_EU_VLANIDMark 100
obuspa -c set Device.QoS.Classification.2.Enable true
```

**Important:** VLAN translation must be configured in both directions for bidirectional communication.

---

### Scenario 7: P-bit/802.1p Translation

**Goal:** Remark P-bit values on traffic entering from a LAN port (e.g., remap P-bit 3 to P-bit 7).

#### UCI Configuration

```
config classify 'pbit_remap'
    option enable '1'
    option order '1'
    option ifname 'eth0.3'
    option pcp_check '3'
    option pcp_mark '7'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.3.
obuspa -c set Device.QoS.Classification.1.EthernetPriorityCheck 3
obuspa -c set Device.QoS.Classification.1.EthernetPriorityMark 7
obuspa -c set Device.QoS.Classification.1.Enable true
```

---

### Scenario 8: Ingress Policing (Rate Limiting)

**Goal:** Rate-limit HTTP traffic from a specific subnet to 5 Mbps using a Two-Rate Three-Color Meter.

#### UCI Configuration

```
config policer 'http_limit'
    option enable '1'
    option name 'http_limit'
    option committed_rate '5000000'
    option committed_burst_size '15000'
    option excess_burst_size '30000'
    option peak_rate '7000000'
    option peak_burst_size '15000'
    option meter_type '2'

config classify 'http_traffic'
    option enable '1'
    option order '10'
    option src_ip '192.168.1.0/24'
    option proto '6'
    option dest_port '80'
    option traffic_class '2'
    option policer 'http_limit'
```

#### TR-181 Configuration

```bash
# Create policer
obuspa -c add Device.QoS.Policer.
obuspa -c set Device.QoS.Policer.1.CommittedRate 5000000
obuspa -c set Device.QoS.Policer.1.CommittedBurstSize 15000
obuspa -c set Device.QoS.Policer.1.ExcessBurstSize 30000
obuspa -c set Device.QoS.Policer.1.PeakRate 7000000
obuspa -c set Device.QoS.Policer.1.PeakBurstSize 15000
obuspa -c set Device.QoS.Policer.1.MeterType TwoRateThreeColor
obuspa -c set Device.QoS.Policer.1.Enable true

# Create classification with policer reference
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Order 10
obuspa -c set Device.QoS.Classification.1.SourceIP 192.168.1.0
obuspa -c set Device.QoS.Classification.1.SourceMask /24
obuspa -c set Device.QoS.Classification.1.Protocol 6
obuspa -c set Device.QoS.Classification.1.DestPort 80
obuspa -c set Device.QoS.Classification.1.TrafficClass 2
obuspa -c set Device.QoS.Classification.1.Policer Device.QoS.Policer.1.
obuspa -c set Device.QoS.Classification.1.Enable true
```

**Note:** Ingress policing support depends on the SoC platform. Not all hardware supports it.

---

### Scenario 9: Policy-Based Routing (Source-Based Routing)

**Goal:** Route traffic from subnet 172.16.11.0/24 destined for 1.1.1.0/24 via a specific routing table (table 100) associated with a secondary WAN.

This requires coordinating both `Device.QoS.Classification` and `Device.Routing.Policy`. `ForwardingPolicy` in the QoS classifier is an **fwmark tag** — qosmngr marks matching packets via `iptables MARK --set-mark` in the `qos_prerouting` chain. `Device.Routing.Policy` (managed by netmngr) then matches that fwmark value to select the routing table.

For a complete dual-WAN example including firewall configuration, UCI details, and troubleshooting, see the [netmngr PBR guide](../../netmngr/docs/guide/pbr_wan_example.md).

#### Step 1: Set Up Alternate Routing Table

```bash
# Create a new Router object; the system auto-assigns a table ID
obuspa -c add Device.Routing.Router.
# Returns e.g. Device.Routing.Router.2.
# Note the assigned ID: obuspa -c get Device.Routing.Router.2.ID  (assume it returns 100)

# Associate the secondary WAN interface with the new routing table
obuspa -c set Device.IP.Interface.2.Router Device.Routing.Router.2.
```

This adds `option ip4table '100'` to the WAN interface in `/etc/config/network`. The DHCP client places all learned routes for that interface into table 100 automatically.

#### Step 2: Add Routing Policy (link fwmark 5 to table 100)

`Device.Routing.Policy.ForwardingPolicy` creates the `ip rule fwmark ... lookup <table>` kernel rule. The fwmark value here must match what the QoS classifier sets (step 3).

##### UCI Configuration

```
# /etc/config/network
config rule 'rule_1'
    option priority  '100'
    option mark      '5'
    option lookup    '100'
    option src       '0.0.0.0/0'
    option disabled  '0'
```

##### TR-181 Configuration

```bash
obuspa -c add Device.Routing.Policy.
obuspa -c set Device.Routing.Policy.1.Priority 100
obuspa -c set Device.Routing.Policy.1.ForwardingPolicy 5
obuspa -c set Device.Routing.Policy.1.RouterRef Device.Routing.Router.2.
# Clear the default 'option in loopback' added by netmngr (see netmngr PBR guide):
obuspa -c set Device.Routing.Policy.1.SourceIPPrefix 0.0.0.0/0
obuspa -c set Device.Routing.Policy.1.Enable true
```

#### Step 3: Add QoS Classification (mark matching packets with fwmark 5)

The `forwarding_policy` value must match the `ForwardingPolicy` set in step 2.

##### UCI Configuration

```
# /etc/config/qos
config classify 'pbr_rule_1'
    option enable            '1'
    option src_ip            '172.16.11.0/24'
    option dest_ip           '1.1.1.0/24'
    option forwarding_policy '5'
```

##### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.SourceIP 172.16.11.0
obuspa -c set Device.QoS.Classification.1.SourceMask /24
obuspa -c set Device.QoS.Classification.1.DestIP 1.1.1.0
obuspa -c set Device.QoS.Classification.1.DestMask /24
obuspa -c set Device.QoS.Classification.1.ForwardingPolicy 5
obuspa -c set Device.QoS.Classification.1.Enable true
```

#### Verify

```bash
# Check that matched packets are marked in qos_prerouting
iptables -t mangle -L qos_prerouting -n -v
# Should show:
# MARK  all  --  *  *  172.16.11.0/24  1.1.1.0/24  MARK set 0x5

# Check that the routing policy rule routes fwmark 0x5 to table 100
ip rule show
# Should show:
# 0:      from all lookup local
# 100:    from all fwmark 0x5 lookup 100
# 32766:  from all lookup main
# 32767:  from all lookup default
```

---

### Scenario 10: WRR Scheduling with Weighted Queues

**Goal:** Configure WAN port queues to use Weighted Round Robin scheduling where video traffic gets 4x the bandwidth of best-effort traffic.

#### UCI Configuration

```
# High priority - Video (queue 6, weight 4)
config queue 'q_6_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '2'
    option scheduling 'WRR'
    option weight '4'
    option rate '0'
    option burst_size '0'

# Medium priority - Interactive (queue 4, weight 2)
config queue 'q_4_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '4'
    option scheduling 'WRR'
    option weight '2'
    option rate '0'
    option burst_size '0'

# Low priority - Best Effort (queue 0, weight 1)
config queue 'q_0_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '8'
    option scheduling 'WRR'
    option weight '1'
    option rate '0'
    option burst_size '0'
```

Then classify traffic into these queues:

```
# Video -> queue 6
config classify 'video'
    option enable '1'
    option order '1'
    option dscp_filter '34'
    option traffic_class '6'

# Interactive -> queue 4
config classify 'interactive'
    option enable '1'
    option order '2'
    option proto '6'
    option dest_port '22'
    option traffic_class '4'
```

#### TR-181 Configuration

```bash
# Set scheduling algorithm on queues
obuspa -c set Device.QoS.Queue.7.SchedulerAlgorithm WRR
obuspa -c set Device.QoS.Queue.7.Weight 4

obuspa -c set Device.QoS.Queue.5.SchedulerAlgorithm WRR
obuspa -c set Device.QoS.Queue.5.Weight 2

obuspa -c set Device.QoS.Queue.1.SchedulerAlgorithm WRR
obuspa -c set Device.QoS.Queue.1.Weight 1
```

---

### Scenario 11: Multi-Criteria Classification (Gaming + Streaming)

**Goal:** Comprehensive QoS policy for a home gateway:
- Gaming traffic (specific ports) -> highest priority, DSCP EF
- Streaming video (specific IPs) -> high priority, DSCP AF41
- Web browsing -> medium priority
- Everything else -> best effort

#### UCI Configuration

```
# Gaming: common game server ports (UDP)
config classify 'gaming'
    option enable '1'
    option order '1'
    option proto '17'
    option dest_port '27015'
    option dst_port_range '27030'
    option traffic_class '7'
    option dscp_mark '46'
    option pcp_mark '7'

# Streaming: Netflix/YouTube approximate ranges (TCP 443 from known subnets)
config classify 'streaming'
    option enable '1'
    option order '2'
    option proto '6'
    option dest_port '443'
    option dest_ip '23.246.0.0/18'
    option traffic_class '5'
    option dscp_mark '34'
    option pcp_mark '5'

# DNS: always high priority
config classify 'dns_priority'
    option enable '1'
    option order '3'
    option proto '17'
    option dest_port '53'
    option traffic_class '7'
    option dscp_mark '48'

# Web browsing: HTTP/HTTPS to medium queue
config classify 'web'
    option enable '1'
    option order '10'
    option proto '6'
    option dest_port '443'
    option traffic_class '3'
    option dscp_mark '0'

# SSH: interactive, high priority
config classify 'ssh'
    option enable '1'
    option order '5'
    option proto '6'
    option dest_port '22'
    option traffic_class '6'
    option dscp_mark '46'

# Shape the WAN to avoid ISP bufferbloat
config shaper 'wan_shape'
    option enable '1'
    option ifname 'ae_wan'
    option rate '95000000'
    option burst_size '15000'
```

---

### Scenario 12: Classify by Ingress Port

**Goal:** Map all traffic ingressing on LAN4 (eth3) to Queue 2.

#### UCI Configuration

```
config classify 'lan4_to_q2'
    option enable '1'
    option ifname 'eth3'
    option traffic_class '1'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.4.
obuspa -c set Device.QoS.Classification.1.TrafficClass 1
obuspa -c set Device.QoS.Classification.1.Enable true
```

> **Note:** `traffic_class` is 0-indexed (0-7), so `1` maps to Queue 2.

---

### Scenario 13: Classify by 802.1p P-bit

**Goal:** All traffic ingressing on LAN4 with 802.1p P-bit value 5 will be mapped to Queue 2.

> **Note:** This requires that the ingress traffic has a VLAN header. This rule only maps traffic to a queue — it does not rewrite the P-bit value.

#### UCI Configuration

```
config classify 'lan4_pbit5'
    option enable '1'
    option ifname 'eth3'
    option pcp_check '5'
    option traffic_class '1'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.4.
obuspa -c set Device.QoS.Classification.1.EthernetPriorityCheck 5
obuspa -c set Device.QoS.Classification.1.TrafficClass 1
obuspa -c set Device.QoS.Classification.1.Enable true
```

---

### Scenario 14: Classify by VLAN ID

**Goal:** All traffic ingressing on LAN4 with VLAN ID 101 will be mapped to Queue 6.

#### UCI Configuration

```
config classify 'lan4_vlan101'
    option enable '1'
    option ifname 'eth3'
    option vid_check '101'
    option traffic_class '5'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.4.
obuspa -c set Device.QoS.Classification.1.VLANIDCheck 101
obuspa -c set Device.QoS.Classification.1.TrafficClass 5
obuspa -c set Device.QoS.Classification.1.Enable true
```

---

### Scenario 15: Classify by Source/Destination MAC

**Goal:** Traffic with source MAC `50:3e:aa:70:f6:72` and destination MAC `08:00:27:1b:bd:b0` on LAN4 will be mapped to Queue 5.

#### UCI Configuration

```
config classify 'mac_filter'
    option enable '1'
    option ifname 'eth3'
    option src_mac '50:3e:aa:70:f6:72'
    option dst_mac '08:00:27:1b:bd:b0'
    option traffic_class '4'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.4.
obuspa -c set Device.QoS.Classification.1.SourceMACAddress 50:3e:aa:70:f6:72
obuspa -c set Device.QoS.Classification.1.DestMACAddress 08:00:27:1b:bd:b0
obuspa -c set Device.QoS.Classification.1.TrafficClass 4
obuspa -c set Device.QoS.Classification.1.Enable true
```

> **Note:** Source and destination MAC can also be used independently.

---

### Scenario 16: Classify by Ethernet Type

**Goal:** All ARP frames (EtherType 0x0806) ingressing on LAN4 will be mapped to Queue 7.

#### UCI Configuration

```
config classify 'lan4_arp'
    option enable '1'
    option ifname 'eth3'
    option ethertype '0x0806'
    option traffic_class '6'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.4.
obuspa -c set Device.QoS.Classification.1.Ethertype 2054
obuspa -c set Device.QoS.Classification.1.TrafficClass 6
obuspa -c set Device.QoS.Classification.1.Enable true
```

> **Note:** In UCI, EtherType is specified in hex (`0x0806`). In TR-181, it is specified in decimal (`2054`).

---

### Scenario 17: Set DSCP Based on Ingress Port

**Goal:** Set DSCP value to 53 for all traffic ingressing on LAN4.

> **Note:** This marks the DSCP field but does not assign traffic to a specific queue. To do both, create two separate classification rules.

#### UCI Configuration

```
config classify 'dscp_53_lan1'
    option enable '1'
    option ifname 'eth3'
    option dscp_mark '53'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.4.
obuspa -c set Device.QoS.Classification.1.DSCPMark 53
obuspa -c set Device.QoS.Classification.1.Enable true
```

---

### Scenario 18: Set DSCP Based on Source IP

**Goal:** Mark DSCP for traffic based on source IP address.

#### IPv4 Example

Set DSCP to 23 for all traffic from source IP `192.168.1.100`:

```
config classify 'dscp_src_ipv4'
    option enable '1'
    option src_ip '192.168.1.100'
    option dscp_mark '23'
```

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.SourceIP 192.168.1.100
obuspa -c set Device.QoS.Classification.1.DSCPMark 23
obuspa -c set Device.QoS.Classification.1.Enable true
```

#### IPv6 Example

Set DSCP to 43 for all traffic from source IPv6 `2001:db8::2:1`:

```
config classify 'dscp_src_ipv6'
    option enable '1'
    option src_ip '2001:db8::2:1'
    option dscp_mark '43'
```

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.SourceIP 2001:db8::2:1
obuspa -c set Device.QoS.Classification.1.DSCPMark 43
obuspa -c set Device.QoS.Classification.1.Enable true
```

---

### Scenario 19: Classify by Destination IP

**Goal:** Map traffic to a queue based on destination IP address.

#### IPv4 Example

All traffic to `192.168.2.1` will be mapped to Queue 6:

```
config classify 'dest_ipv4'
    option enable '1'
    option dest_ip '192.168.2.1'
    option traffic_class '5'
```

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.DestIP 192.168.2.1
obuspa -c set Device.QoS.Classification.1.TrafficClass 5
obuspa -c set Device.QoS.Classification.1.Enable true
```

#### IPv6 Example

All traffic to `2001:db8::3:1` will be mapped to Queue 7:

```
config classify 'dest_ipv6'
    option enable '1'
    option dest_ip '2001:db8::3:1'
    option traffic_class '6'
```

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.DestIP 2001:db8::3:1
obuspa -c set Device.QoS.Classification.1.TrafficClass 6
obuspa -c set Device.QoS.Classification.1.Enable true
```

---

### Scenario 20: Classify by DSCP Value

**Goal:** All traffic with DSCP value 26 (AF31) will be mapped to Queue 2.

#### UCI Configuration

```
config classify 'dscp_26_to_q2'
    option enable '1'
    option dscp_filter '26'
    option traffic_class '1'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.DSCPCheck 26
obuspa -c set Device.QoS.Classification.1.TrafficClass 1
obuspa -c set Device.QoS.Classification.1.Enable true
```

---

### Scenario 21: Classify by L4 Protocol

**Goal:** All UDP traffic (protocol 17) ingressing on LAN4 will be mapped to Queue 7.

#### UCI Configuration

```
config classify 'lan4_udp_q7'
    option enable '1'
    option ifname 'eth3'
    option proto '17'
    option traffic_class '6'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.4.
obuspa -c set Device.QoS.Classification.1.Protocol 17
obuspa -c set Device.QoS.Classification.1.TrafficClass 6
obuspa -c set Device.QoS.Classification.1.Enable true
```

> **Note:** Common protocol numbers: 1=ICMP, 6=TCP, 17=UDP, 132=SCTP.

---

### Scenario 22: Set DSCP Based on L4 Protocol

**Goal:** Set DSCP to 37 for all UDP traffic ingressing on LAN4.

#### UCI Configuration

```
config classify 'lan4_udp_dscp37'
    option enable '1'
    option ifname 'eth3'
    option proto '17'
    option dscp_mark '37'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.4.
obuspa -c set Device.QoS.Classification.1.Protocol 17
obuspa -c set Device.QoS.Classification.1.DSCPMark 37
obuspa -c set Device.QoS.Classification.1.Enable true
```

---

### Scenario 23: Classify by Source/Destination Port

**Goal:** Map traffic ingressing on LAN4 with source port 8080 and destination port 443 to Queue 8.

#### UCI Configuration

```
config classify 'src_dest_port'
    option enable '1'
    option ifname 'eth3'
    option src_port '8080'
    option dest_port '443'
    option traffic_class '7'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.4.
obuspa -c set Device.QoS.Classification.1.SourcePort 8080
obuspa -c set Device.QoS.Classification.1.DestPort 443
obuspa -c set Device.QoS.Classification.1.TrafficClass 7
obuspa -c set Device.QoS.Classification.1.Enable true
```

---

### Scenario 24: Classify by Port Range

**Goal:** Match traffic on LAN4 with source ports 8080-8082 and destination ports 443-444, map to Queue 8.

#### UCI Configuration

```
config classify 'port_range'
    option enable '1'
    option ifname 'eth3'
    option src_port '8080'
    option src_port_range '8082'
    option dest_port '443'
    option dst_port_range '444'
    option traffic_class '7'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.4.
obuspa -c set Device.QoS.Classification.1.SourcePort 8080
obuspa -c set Device.QoS.Classification.1.SourcePortRangeMax 8082
obuspa -c set Device.QoS.Classification.1.DestPort 443
obuspa -c set Device.QoS.Classification.1.DestPortRangeMax 444
obuspa -c set Device.QoS.Classification.1.TrafficClass 7
obuspa -c set Device.QoS.Classification.1.Enable true
```

---

### Scenario 25: Classify by L3 Packet Length

**Goal:** Match packets based on IP packet length and map to a queue.

#### Minimum Packet Length

Match IPv4/IPv6 packets on LAN4 with minimum length of 900 bytes, map to Queue 8:

```
config classify 'lan4_min_len'
    option enable '1'
    option ifname 'eth3'
    option ip_len_min '900'
    option traffic_class '7'
```

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.4.
obuspa -c set Device.QoS.Classification.1.IPLengthMin 900
obuspa -c set Device.QoS.Classification.1.TrafficClass 7
obuspa -c set Device.QoS.Classification.1.Enable true
```

#### Maximum Packet Length

Match packets on LAN4 with maximum length of 900 bytes, map to Queue 8:

```
config classify 'lan4_max_len'
    option enable '1'
    option ifname 'eth3'
    option ip_len_max '900'
    option traffic_class '7'
```

```bash
obuspa -c add Device.QoS.Classification.
obuspa -c set Device.QoS.Classification.1.Interface Device.Ethernet.Interface.4.
obuspa -c set Device.QoS.Classification.1.IPLengthMax 900
obuspa -c set Device.QoS.Classification.1.TrafficClass 7
obuspa -c set Device.QoS.Classification.1.Enable true
```

> **Note:** Both `ip_len_min` and `ip_len_max` can be combined in a single rule to match a packet length range.

---

### Scenario 26: Strict Priority Scheduling

**Goal:** Configure all WAN queues to use Strict Priority scheduling. This is the default scheduling mode — higher-precedence queues are always served first.

#### UCI Configuration

```
config queue 'q_7_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '1'
    option scheduling 'SP'
    option weight '1'
    option rate '0'
    option burst_size '0'

config queue 'q_6_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '2'
    option scheduling 'SP'
    option weight '1'
    option rate '0'
    option burst_size '0'

config queue 'q_5_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '3'
    option scheduling 'SP'
    option weight '1'
    option rate '0'
    option burst_size '0'

config queue 'q_4_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '4'
    option scheduling 'SP'
    option weight '1'
    option rate '0'
    option burst_size '0'

config queue 'q_3_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '5'
    option scheduling 'SP'
    option weight '1'
    option rate '0'
    option burst_size '0'

config queue 'q_2_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '6'
    option scheduling 'SP'
    option weight '1'
    option rate '0'
    option burst_size '0'

config queue 'q_1_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '7'
    option scheduling 'SP'
    option weight '1'
    option rate '0'
    option burst_size '0'

config queue 'q_0_ae_wan'
    option enable '1'
    option ifname 'ae_wan'
    option precedence '8'
    option scheduling 'SP'
    option weight '1'
    option rate '0'
    option burst_size '0'
```

#### TR-181 Configuration

```bash
# Set all queues to SP (assuming queue instances already exist)
for i in $(seq 1 8); do
    obuspa -c set Device.QoS.Queue.$i.SchedulerAlgorithm SP
done
```

> **Note:** With SP scheduling, a higher-precedence queue must be completely empty before lower-precedence queues are serviced. This can cause starvation of low-priority queues under heavy high-priority traffic.

---

### Scenario 27: Percentage-Based Traffic Shaping

**Goal:** Shape WAN egress to 4% of the port's maximum speed. On a 1 Gbps port this is 40 Mbps; on a 10 Gbps port this is 400 Mbps.

#### UCI Configuration

```
config shaper 'shaper_wan'
    option enable '1'
    option ifname 'ae_wan'
    option rate '4'
    option burst_size '0'
```

#### TR-181 Configuration

```bash
obuspa -c add Device.QoS.Shaper.
obuspa -c set Device.QoS.Shaper.1.Interface Device.Ethernet.Interface.6.
obuspa -c set Device.QoS.Shaper.1.ShapingRate 4
obuspa -c set Device.QoS.Shaper.1.Enable true
```

> **Note:** When `ShapingRate` is between 0 and 100, it is interpreted as a **percentage** of the port's maximum link speed (auto-detected via ethtool). Values above 100 are interpreted as absolute rate in bits per second.

---

For statistics and monitoring commands, see [Statistics and Monitoring](QoS_Troubleshooting.md#statistics-and-monitoring) in the Troubleshooting guide.
