0001
0002
0003
0004
0005
0006
0007
0008 WAIT_TIME=1
0009 NUM_NETIFS=4
0010 STABLE_MAC_ADDRS=yes
0011 NETIF_CREATE=no
0012 lib_dir=$(dirname $0)/../../../net/forwarding
0013 source $lib_dir/tc_common.sh
0014 source $lib_dir/lib.sh
0015
0016 require_command dcb
0017
0018 h1=${NETIFS[p1]}
0019 swp1=${NETIFS[p2]}
0020 swp2=${NETIFS[p3]}
0021 h2=${NETIFS[p4]}
0022
0023 H1_IPV4="192.0.2.1"
0024 H2_IPV4="192.0.2.2"
0025 H1_IPV6="2001:db8:1::1"
0026 H2_IPV6="2001:db8:1::2"
0027
0028 h1_create()
0029 {
0030 simple_if_init $h1 $H1_IPV4/24 $H1_IPV6/64
0031 }
0032
0033 h1_destroy()
0034 {
0035 simple_if_fini $h1 $H1_IPV4/24 $H1_IPV6/64
0036 }
0037
0038 h2_create()
0039 {
0040 simple_if_init $h2 $H2_IPV4/24 $H2_IPV6/64
0041 }
0042
0043 h2_destroy()
0044 {
0045 simple_if_fini $h2 $H2_IPV4/24 $H2_IPV6/64
0046 }
0047
0048 h1_vlan_create()
0049 {
0050 local vid=$1
0051
0052 vlan_create $h1 $vid
0053 simple_if_init $h1.$vid $H1_IPV4/24 $H1_IPV6/64
0054 ip link set $h1.$vid type vlan \
0055 egress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 \
0056 ingress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
0057 }
0058
0059 h1_vlan_destroy()
0060 {
0061 local vid=$1
0062
0063 simple_if_fini $h1.$vid $H1_IPV4/24 $H1_IPV6/64
0064 vlan_destroy $h1 $vid
0065 }
0066
0067 h2_vlan_create()
0068 {
0069 local vid=$1
0070
0071 vlan_create $h2 $vid
0072 simple_if_init $h2.$vid $H2_IPV4/24 $H2_IPV6/64
0073 ip link set $h2.$vid type vlan \
0074 egress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 \
0075 ingress-qos-map 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
0076 }
0077
0078 h2_vlan_destroy()
0079 {
0080 local vid=$1
0081
0082 simple_if_fini $h2.$vid $H2_IPV4/24 $H2_IPV6/64
0083 vlan_destroy $h2 $vid
0084 }
0085
0086 vlans_prepare()
0087 {
0088 h1_vlan_create 100
0089 h2_vlan_create 100
0090
0091 tc qdisc add dev ${h1}.100 clsact
0092 tc filter add dev ${h1}.100 egress protocol ipv4 \
0093 flower ip_proto icmp action skbedit priority 3
0094 tc filter add dev ${h1}.100 egress protocol ipv6 \
0095 flower ip_proto icmpv6 action skbedit priority 3
0096 }
0097
0098 vlans_destroy()
0099 {
0100 tc qdisc del dev ${h1}.100 clsact
0101
0102 h1_vlan_destroy 100
0103 h2_vlan_destroy 100
0104 }
0105
0106 switch_create()
0107 {
0108 ip link set ${swp1} up
0109 ip link set ${swp2} up
0110
0111
0112 ip link add br0 type bridge
0113 ip link set ${swp1} master br0
0114 ip link set ${swp2} master br0
0115 ip link set br0 up
0116 }
0117
0118 switch_destroy()
0119 {
0120 ip link del br0
0121 }
0122
0123 setup_prepare()
0124 {
0125 vrf_prepare
0126
0127 h1_create
0128 h2_create
0129 switch_create
0130 }
0131
0132 cleanup()
0133 {
0134 pre_cleanup
0135
0136 h2_destroy
0137 h1_destroy
0138 switch_destroy
0139
0140 vrf_cleanup
0141 }
0142
0143 dscp_cs_to_tos()
0144 {
0145 local dscp_cs=$1
0146
0147
0148
0149 echo $((${dscp_cs} << 5))
0150 }
0151
0152 run_test()
0153 {
0154 local test_name=$1; shift
0155 local if_name=$1; shift
0156 local tc=$1; shift
0157 local tos=$1; shift
0158 local counter_name="rx_green_prio_${tc}"
0159 local ipv4_before
0160 local ipv4_after
0161 local ipv6_before
0162 local ipv6_after
0163
0164 ipv4_before=$(ethtool_stats_get ${swp1} "${counter_name}")
0165 ping_do ${if_name} $H2_IPV4 "-Q ${tos}"
0166 ipv4_after=$(ethtool_stats_get ${swp1} "${counter_name}")
0167
0168 if [ $((${ipv4_after} - ${ipv4_before})) -lt ${PING_COUNT} ]; then
0169 RET=1
0170 else
0171 RET=0
0172 fi
0173 log_test "IPv4 ${test_name}"
0174
0175 ipv6_before=$(ethtool_stats_get ${swp1} "${counter_name}")
0176 ping_do ${if_name} $H2_IPV6 "-Q ${tos}"
0177 ipv6_after=$(ethtool_stats_get ${swp1} "${counter_name}")
0178
0179 if [ $((${ipv6_after} - ${ipv6_before})) -lt ${PING_COUNT} ]; then
0180 RET=1
0181 else
0182 RET=0
0183 fi
0184 log_test "IPv6 ${test_name}"
0185 }
0186
0187 port_default_prio_get()
0188 {
0189 local if_name=$1
0190 local prio
0191
0192 prio="$(dcb -j app show dev ${if_name} default-prio | \
0193 jq '.default_prio[]')"
0194 if [ -z "${prio}" ]; then
0195 prio=0
0196 fi
0197
0198 echo ${prio}
0199 }
0200
0201 test_port_default()
0202 {
0203 local orig=$(port_default_prio_get ${swp1})
0204 local dmac=$(mac_get ${h2})
0205
0206 dcb app replace dev ${swp1} default-prio 5
0207
0208 run_test "Port-default QoS classification" ${h1} 5 0
0209
0210 dcb app replace dev ${swp1} default-prio ${orig}
0211 }
0212
0213 test_vlan_pcp()
0214 {
0215 vlans_prepare
0216
0217 run_test "Trusted VLAN PCP QoS classification" ${h1}.100 3 0
0218
0219 vlans_destroy
0220 }
0221
0222 test_ip_dscp()
0223 {
0224 local port_default=$(port_default_prio_get ${swp1})
0225 local tos=$(dscp_cs_to_tos 4)
0226
0227 dcb app add dev ${swp1} dscp-prio CS4:4
0228 run_test "Trusted DSCP QoS classification" ${h1} 4 ${tos}
0229 dcb app del dev ${swp1} dscp-prio CS4:4
0230
0231 vlans_prepare
0232 run_test "Untrusted DSCP QoS classification follows VLAN PCP" \
0233 ${h1}.100 3 ${tos}
0234 vlans_destroy
0235
0236 run_test "Untrusted DSCP QoS classification follows port default" \
0237 ${h1} ${port_default} ${tos}
0238 }
0239
0240 trap cleanup EXIT
0241
0242 ALL_TESTS="
0243 test_port_default
0244 test_vlan_pcp
0245 test_ip_dscp
0246 "
0247
0248 setup_prepare
0249 setup_wait
0250
0251 tests_run
0252
0253 exit $EXIT_STATUS