配置步骤
定义acl,匹配SwitchA访问SwitchB的流量,在做流量统计时应尽量保证匹配的情况精确,避免抓取到其他业务流量,使流量统计不准确。
[H3C]acl number 999
[H3C-acl-adv-999]description traffic accounting for host SwitchA to host SwitchB
[H3C-acl-adv-999]rule 10 permit icmp source 2.2.2.2 0 destination 3.3.3.3 0
定义流分类,匹配acl定义的PCA访问PCB的web流量。
[H3C]traffic classifier traffic_accounting_from_SwitchA_to_SwitchB
[H3C-classifier-traffic_accounting_from_SwitchA_to_SwitchB]if-match acl 999
定义流行为,统计报文个数
[H3C]traffic behavior traffic_accounting_from_SwitchA_to_SwitchB
[H3C-behavior-traffic_accounting_from_SwitchA_to_SwitchB]accounting packet
定义qos策略,关联流分类和流行为
[H3C]qos policy traffic_accounting_from_SwitchA_to_SwitchB
[H3C-qospolicy-traffic_accounting_from_SwitchA_to_SwitchB]classifier traffic_accounting_from_SwitchA_to_SwitchB behavior traffic_accounting_from_SwitchA_to_SwitchB
在2/0/1的入方向和2/0/2的出访问下发qos策略,来统计报文是否到达设备和是否被设备转发给SwitchB。
[H3C]interface GigabitEthernet2/0/1
[H3C-GigabitEthernet2/0/1]qos apply policy traffic_accounting_from_SwitchA_to_SwitchB inbound
[H3C]interface GigabitEthernet2/0/2
[H3C-GigabitEthernet2/0/2]qos apply policy traffic_accounting_from_SwitchA_to_SwitchB outbound
使SwitchA访问SwitchB,查看接口GigabitEthernet2/0/1流量统计结果
[H3C]display qos policy interface GigabitEthernet 2/0/1
Interface: GigabitEthernet2/0/1
Direction: Inbound
Policy: traffic_accounting_from_SwitchA_to_SwitchB
Classifier: traffic_accounting_from_SwitchA_to_SwitchB
Operator: AND
Rule(s) : If-match acl 999
Behavior: traffic_accounting_from_SwitchA_to_SwitchB
Accounting Enable:
5 (Packets)
根据结果看出有5个报文进行交换机。查看接口GigabitEthernet2/0/2流量统计结果
[H3C]display qos policy interface GigabitEthernet 2/0/2
Interface: GigabitEthernet2/0/2
Direction: Outbound
Policy: traffic_accounting_from_SwitchA_to_SwitchB
Classifier: traffic_accounting_from_SwitchA_to_SwitchB
Operator: AND
Rule(s) : If-match acl 999
Behavior: traffic_accounting_from_SwitchA_to_SwitchB
Accounting Enable:
5 (Packets)
有5个报文从交换机发出,说明从A到B转发正常
配置文件
#
acl number 999
description traffic accounting for host SwitchA to host SwitchB
rule 10 permit icmp source 2.2.2.2 0 destination 3.3.3.3 0 acl number
#
traffic classifier traffic_accounting_from_SwitchA_to_SwitchB
if-match acl 999
#
traffic behavior traffic_accounting_from_SwitchA_to_SwitchB
accounting packet
#
qos policy traffic_accounting_from_SwitchA_to_SwitchB
classifier traffic_accounting_from_SwitchA_to_SwitchB behavior traffic_accounting_from_SwitchA_to_SwitchB
#
interface GigabitEthernet2/0/1
qos apply policy traffic_accounting_from_SwitchA_to_SwitchB inbound
#
interface GigabitEthernet2/0/2
qos apply policy traffic_accounting_from_SwitchA_to_SwitchB outbound
注意事项
-
对匹配的流量计一定要尽量精确,避免其他流量影响统计结果。
-
注意流量双向性和qos策略下发的方向要正确下发。