Example for Configuring Traffic Statistics
Networking Requirements
As shown in Figure 9-2, the MAC address of PC1 is 0000-0000-0003 and PC1 is connected to the WAN-side network device through the switch. The Router is required to collect statistics on packets with the source MAC address of 0000-0000-0003.
Configuration Roadmap
- Configure interfaces so that the Router can connect to the switch and PC1.
- Configure an ACL to match packets with the source MAC address of 0000-0000-0003.
- Configure a traffic classifier and reference the ACL in the traffic classifier.
- Configure a traffic behavior so that the Router collects statistics on packets matching rules.
- Configure a traffic policy, bind the traffic policy to the traffic classifier and traffic behavior, and apply the traffic policy to the inbound direction of Eth2/0/0 so that the Router collects statistics on packets with the source MAC address of 0000-0000-0003.
Procedure
- Create VLANs and configure interfaces.
# Create VLAN 20 on the Router.
<Huawei> system-view [Huawei] sysname Router [Router] vlan 20 [Router-vlan20] quit
# Configure Eth2/0/0 on the Router as a trunk interface and add Eth2/0/0 to VLAN 20.
[Router] interface ethernet 2/0/0 [Router-Ethernet2/0/0] port link-type trunk [Router-Ethernet2/0/0] port trunk allow-pass vlan 20 [Router-Ethernet2/0/0] quit
# Create VLAN 20 on the switch, configure GE1/0/2 as a trunk interface and GE1/0/1 as an access interface, and add GE1/0/2 to VLAN 20.
<Huawei> system-view [Huawei] sysname Switch [Switch] vlan 20 [Switch-vlan20] quit [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
- Configure an ACL.
# Create ACL 4000 (Layer 2 ACL) on the Router to match packets with the source MAC address of 0000-0000-0003.
[Router] acl 4000 [Router-acl-L2-4000] rule permit source-mac 0000-0000-0003 ffff-ffff-ffff [Router-acl-L2-4000] quit
- Configure a traffic classifier.
# Create a traffic classifier c1 on the Router and reference ACL 4000 in the traffic classifier.
[Router] traffic classifier c1 [Router-classifier-c1] if-match acl 4000 [Router-classifier-c1] quit
- Configure a traffic behavior.
# Create a traffic behavior b1 on the Router and configure the traffic statistics action in the traffic behavior.
[Router] traffic behavior b1 [Router-behavior-b1] statistic enable [Router-behavior-b1] quit
- Configure a traffic policy and apply the traffic policy to an interface.
# Create a traffic policy p1 on the Router and bind the traffic policy to the traffic classifier and traffic behavior.
[Router] traffic policy p1 [Router-trafficpolicy-p1] classifier c1 behavior b1 [Router-trafficpolicy-p1] quit
# Apply the traffic policy p1 to Eth2/0/0.
[Router] interface ethernet 2/0/0 [Router-Ethernet2/0/0] traffic-policy p1 inbound [Router-Ethernet2/0/0] quit
- Verify the configuration.
# View the ACL configuration.
<Router> display acl 4000 L2 ACL 4000, 1 rule Acl's step is 5 rule 5 permit source-mac 0000-0000-0003
# View the traffic classifier configuration.
<Router> display traffic classifier user-defined User Defined Classifier Information: Classifier: c1 Operator: OR Rule(s) : if-match acl 4000
# View the traffic policy configuration.
<Router> display traffic policy user-defined p1 User Defined Traffic Policy Information: Policy: p1 Classifier: c1 Operator: OR Behavior: b1 statistic: enable Precedence: 5
# View the traffic statistics.
<Router> display traffic policy statistics interface ethernet 2/0/0 inbound Interface: Ethernet2/0/0 Traffic policy inbound: p1 Rule number: 1 Current status: OK! Item Sum(Packets/Bytes) Rate(pps/bps) ------------------------------------------------------------------------------- Matched 0/0 0/0 Passed 0/0 0/0 Dropped 0/0 0/0 Filter 0/0 0/0 CAR 0/0 0/0 Queue Matched 0/0 0/0 Enqueued 0/0 0/0 Discarded 0/0 0/0 CAR 0/0 0/0 Green packets 0/0 0/0 Yellow packets 0/0 0/0 Red packets 0/0 0/0
Configuration Files
Router configuration file
# sysname Router # vlan batch 20 # acl number 4000 rule 5 permit source-mac 0000-0000-0003 # traffic classifier c1 operator or if-match acl 4000 # traffic behavior b1 statistic enable # traffic policy p1 classifier c1 behavior b1 precedence 5 # interface Ethernet2/0/0 port link-type trunk port trunk allow-pass vlan 20 traffic-policy p1 inbound # return
Switch configuration file
# sysname Switch # vlan batch 20 # interface GigabitEthernet1/0/1 port link-type access port default vlan 20 # interface GigabitEthernet1/0/2 port link-type trunk port trunk allow-pass vlan 20 # return