In Figure 1, the MAC address of PC1 is 0000-0000-0003, and PC1 connects to GE0/0/1 on the Switch. The Switch is required to collect statistics on packets with the source MAC address of 0000-0000-0003.
# Create VLAN 20 on the Switch.
<HUAWEI> system-view [HUAWEI] sysname Switch [Switch] vlan 20 [Switch-vlan20] quit
# Configure GE0/0/1 as an access interface and GE0/0/2 as a trunk interface, and add them to VLAN 20.
[Switch] interface gigabitethernet 0/0/1 [Switch-GigabitEthernet0/0/1] port link-type access [Switch-GigabitEthernet0/0/1] port default vlan 20 [Switch-GigabitEthernet0/0/1] quit [Switch] interface gigabitethernet 0/0/2 [Switch-GigabitEthernet0/0/2] port link-type trunk [Switch-GigabitEthernet0/0/2] port trunk allow-pass vlan 20 [Switch-GigabitEthernet0/0/2] quit
# Create VLANIF 20 and configure IP address 10.10.10.2/24 for it.
[Switch] interface vlanif 20 [Switch-Vlanif20] ip address 10.10.10.2 24 [Switch-Vlanif20] quit
Configure IP address 10.10.10.1/24 for the router interface connected to the Switch.
# Create ACL 4000 (Layer 2 ACL) on the Switch to match packets with the source MAC address of 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
# Create a traffic classifier c1 on the Switch and reference ACL 4000 in the traffic classifier.
[Switch] traffic classifier c1 operator and [Switch-classifier-c1] if-match acl 4000 [Switch-classifier-c1] quit
# Create a traffic behavior b1 on the Switch and configure the traffic statistics collection action in the traffic behavior.
[Switch] traffic behavior b1 [Switch-behavior-b1] statistic enable [Switch-behavior-b1] quit
# Create a traffic policy p1 on the Switch and bind the traffic classifier and traffic behavior to the traffic policy.
[Switch] traffic policy p1 [Switch-trafficpolicy-p1] classifier c1 behavior b1 [Switch-trafficpolicy-p1] quit
# Apply the traffic policy p1 to GE0/0/1.
[Switch] interface gigabitethernet 0/0/1 [Switch-GigabitEthernet0/0/1] traffic-policy p1 inbound [Switch-GigabitEthernet0/0/1] quit
# View the ACL configuration.
[Switch] 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.
[Switch] display traffic classifier user-defined
User Defined Classifier Information:
Classifier: c1
Operator: AND
Rule(s) : if-match acl 4000
Total classifier number is 1
# View the traffic policy configuration.
[Switch] display traffic policy user-defined p1
User Defined Traffic Policy Information:
Policy: p1
Classifier: c1
Operator: AND
Behavior: b1
Statistic: enable
# View the traffic statistics.
[Switch] display traffic policy statistics interface gigabitethernet 0/0/1 inbound Interface: GigabitEthernet0/0/1 Traffic policy inbound: p1 Rule number: 1 Current status: success Statistics interval: 300 --------------------------------------------------------------------- Board : 0 --------------------------------------------------------------------- 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 configuration file
# sysname Switch # vlan batch 20 # acl number 4000 rule 5 permit source-mac 0000-0000-0003 # traffic classifier c1 operator and if-match acl 4000 # traffic behavior b1 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 GigabitEthernet0/0/1 port link-type access port default vlan 20 traffic-policy p1 inbound # interface GigabitEthernet0/0/2 port link-type trunk port trunk allow-pass vlan 20 # return