配置流量统计示例
组网需求
如图8-2所示,PC1的MAC地址为0000-0000-0003,它连接在Switch的GE1/0/1端口上,实现与其他设备的互连互通。现希望Switch对源MAC为0000-0000-0003的报文进行流量统计。
配置思路
- 配置各接口,实现Switch与Router、PC1互通。
- 配置ACL规则,匹配源MAC为0000-0000-0003的报文。
- 配置流分类,实现基于上述ACL规则对报文进行分类。
- 配置流行为,实现对满足规则的报文进行流量统计。
- 配置流策略,绑定上述流分类和流行为,并应用到接口GE1/0/1的入方向,实现对该接口收到的源MAC为0000-0000-0003的报文进行流量统计。
操作步骤
- 创建VLAN并配置各接口
# 在Switch上创建VLAN20。
<HUAWEI> system-view [HUAWEI] sysname Switch [Switch] vlan 20 [Switch-vlan20] quit
# 配置接口GE1/0/1为Access类型接口,接口GE1/0/2为Trunk类型接口,并将GE1/0/1和GE1/0/2加入VLAN20。
[Switch] interface gigabitethernet 1/0/1 [Switch-GigabitEthernet1/0/1] port link-type access [Switch-GigabitEthernet1/0/1] port default vlan 20 [Switch-GigabitEthernet1/0/1] quit [Switch] interface gigabitethernet 1/0/2 [Switch-GigabitEthernet1/0/2] port link-type trunk [Switch-GigabitEthernet1/0/2] port trunk allow-pass vlan 20 [Switch-GigabitEthernet1/0/2] quit
# 创建VLANIF20,并配置IP地址10.10.10.2/24。
[Switch] interface vlanif 20 [Switch-Vlanif20] ip address 10.10.10.2 24 [Switch-Vlanif20] quit
请配置Router与Switch对接的接口IP地址为10.10.10.1/24。
- 配置ACL规则
# 在Switch上创建编码为4000的二层ACL,匹配源MAC为0000-0000-0003的报文。
[Switch] acl 4000 [Switch-acl-L2-4000] rule permit source-mac 0000-0000-0003 ffff-ffff-ffff [Switch-acl-L2-4000] quit
- 配置流分类
# 在Switch上创建流分类c1,匹配规则为ACL 4000。
[Switch] traffic classifier c1 operator and [Switch-classifier-c1] if-match acl 4000 [Switch-classifier-c1] quit
- 配置流行为
# 在Switch上创建流行为b1,并配置流量统计动作。
[Switch] traffic behavior b1 [Switch-behavior-b1] statistic enable [Switch-behavior-b1] quit
- 配置流策略并应用到接口上
# 在Switch上创建流策略p1,将流分类和对应的流行为进行绑定。
[Switch] traffic policy p1 [Switch-trafficpolicy-p1] classifier c1 behavior b1 [Switch-trafficpolicy-p1] quit
# 将流策略p1应用到接口GE1/0/1。
[Switch] interface gigabitethernet 1/0/1 [Switch-GigabitEthernet1/0/1] traffic-policy p1 inbound [Switch-GigabitEthernet1/0/1] quit
- 验证配置结果
# 查看ACL规则的配置信息。
[Switch] display acl 4000 L2 ACL 4000, 1 rule Acl's step is 5 rule 5 permit source-mac 0000-0000-0003
# 查看流分类的配置信息。
[Switch] display traffic classifier user-defined User Defined Classifier Information: Classifier: c1 Precedence: 5 Operator: AND Rule(s) : if-match acl 4000 Total classifier number is 1
# 查看流策略的配置信息。
[Switch] display traffic policy user-defined p1 User Defined Traffic Policy Information: Policy: p1 Classifier: c1 Operator: AND Behavior: b1 Permit Statistic: enable
# 查看流量统计信息。
[Switch] display traffic policy statistics interface gigabitethernet 1/0/1 inbound Interface: GigabitEthernet1/0/1 Traffic policy inbound: p1 Rule number: 1 Current status: success Statistics interval: 300 --------------------------------------------------------------------- Board : 1 --------------------------------------------------------------------- Matched | Packets: 0 | Bytes: 0 | Rate(pps): 0 | Rate(bps): 0 --------------------------------------------------------------------- Passed | Packets: 0 | Bytes: 0 | Rate(pps): 0 | Rate(bps): 0 --------------------------------------------------------------------- Dropped | Packets: 0 | Bytes: 0 | Rate(pps): 0 | Rate(bps): 0 --------------------------------------------------------------------- Filter | Packets: 0 | Bytes: 0 --------------------------------------------------------------------- Car | Packets: 0 | Bytes: 0 ---------------------------------------------------------------------
配置文件
Switch的配置文件
# sysname Switch # vlan batch 20 # acl number 4000 rule 5 permit source-mac 0000-0000-0003 # traffic classifier c1 operator and precedence 5 if-match acl 4000 # traffic behavior b1 permit statistic enable # traffic policy p1 match-order config classifier c1 behavior b1 # interface Vlanif20 ip address 10.10.10.2 255.255.255.0 # interface GigabitEthernet1/0/1 port link-type access port default vlan 20 traffic-policy p1 inbound # interface GigabitEthernet1/0/2 port link-type trunk port trunk allow-pass vlan 20 # return