Classification

Tests for HTB traffic classification using tc matches. Verifies that traffic lands on the correct leaf class by checking both rate and byte counters.

Test HTB Traffic Classification

Description

Verifies that traffic is classified into the correct leaf class. Only TCP traffic on port 8080 is sent, which must land on class 2. Class 3 (TCP any other port) must show zero bytes, confirming the match directs traffic to the intended class and not elsewhere.

Scenario

Step 1: Set the following configuration in DUT0 :

set interfaces ethernet eth0 address 10.0.0.2/24
set interfaces ethernet eth0 traffic control out QDISC
set system login user admin authentication encrypted-password '$6$GSjsCj8gHLv$/VcqU6FLi6CT2Oxn0MJQ2C2tqnRDrYKNF8HIYWJp68nvXvPdFccDsT04.WtigUONbKYrgKg8d6rEs8PjljMkH0'
set traffic control QDISC type htb bandwidth 100
set traffic control QDISC type htb class 1 bandwidth percentage 50
set traffic control QDISC type htb class 1 ceiling percentage 100
set traffic control QDISC type htb class 2 bandwidth rate 30
set traffic control QDISC type htb class 2 parent 1
set traffic control QDISC type htb class 3 bandwidth rate 20
set traffic control QDISC type htb class 3 parent 1
set traffic control QDISC type htb class 4 bandwidth percentage 10
set traffic control QDISC type htb default-class 4
set traffic control QDISC type htb match 1 class 2
set traffic control QDISC type htb match 1 ip destination port 8080
set traffic control QDISC type htb match 1 ip protocol tcp
set traffic control QDISC type htb match 2 class 3
set traffic control QDISC type htb match 2 ip protocol tcp

Step 2: Set the following configuration in DUT1 :

set interfaces ethernet eth0 address 10.0.0.1/24
set system login user admin authentication encrypted-password '$6$GSjsCj8gHLv$/VcqU6FLi6CT2Oxn0MJQ2C2tqnRDrYKNF8HIYWJp68nvXvPdFccDsT04.WtigUONbKYrgKg8d6rEs8PjljMkH0'

Step 3: Ping the IP address 10.0.0.1 from DUT0:

admin@DUT0$ ping 10.0.0.1 count 1 size 56 timeout 1
Show output
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=2.08 ms

--- 10.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 2.084/2.084/2.084/0.000 ms

Step 4: Initiate a bandwidth test from DUT0 to DUT1

admin@DUT1$ monitor test performance server port 8080
admin@DUT0$ monitor test performance client 10.0.0.1 duration 5 port 8080 parallel 1
Expect the following output on DUT0:
Connecting to host 10.0.0.1, port 8080
[  5] local 10.0.0.2 port 50218 connected to 10.0.0.1 port 8080
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  4.45 MBytes  37.3 Mbits/sec  107   29.7 KBytes
[  5]   1.00-2.00   sec  3.48 MBytes  29.2 Mbits/sec   53   29.7 KBytes
[  5]   2.00-3.00   sec  3.42 MBytes  28.6 Mbits/sec   64   29.7 KBytes
[  5]   3.00-4.00   sec  3.29 MBytes  27.7 Mbits/sec   56   28.3 KBytes
[  5]   4.00-5.00   sec  3.54 MBytes  29.7 Mbits/sec   62   26.9 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-5.00   sec  18.2 MBytes  30.5 Mbits/sec  342             sender
[  5]   0.00-5.01   sec  17.5 MBytes  29.3 Mbits/sec                  receiver

iperf Done.

Step 5: Run the command traffic control show on DUT0 and check whether the output matches the following regular expressions:

class 2\s+1:1\s+[1-9]
class 3\s+1:1\s+0
Show output
Traffic control for interface 'eth0' - 'egress' mode

--------------------------------------------------------------------------------------
 ID    traffic control        type         parent  bytes sent  pkts sent  pkts dropped
--------------------------------------------------------------------------------------
1:0    QDISC            htb                root      19260682      12746            32
1:1    QDISC            class 1            1:0       19259782      12738             0
  1:2  QDISC            class 2            1:1       19259782      12738             0
  1:3  QDISC            class 3            1:1              0          0             0
1:4    QDISC            class 4 (default)  1:0            900          8             0
4:0    -                htb                1:2       19259782      12738            32
5:0    -                htb                1:3              0          0             0
3:0    -                htb                1:4            900          8             0