Example for Configuring sFlow
Networking Requirements
As shown in Figure 12-3, traffic between network 1 and network 2 is exchanged through SwitchA. Maintenance personnel need to monitor the traffic on GE1/0/2 and devices to locate unexpected traffic and ensure normal network operation on network 1.
Configuration Roadmap
To configure sFlow, you can configure SwitchA as an sFlow agent and enable sFlow (including flow sampling and counter sampling) on GE1/0/2 so that the agent collects network traffic statistics. The agent encapsulates traffic statistics into sFlow packets and sends sFlow packets from GE1/0/1 to the sFlow collector. The collector displays the network traffic statistics based on information in the received sFlow packets.
The configuration roadmap is as follows:
- Configure an IP address for each switch interface.
- Configure sFlow agent and collector information on the device.
- Configure flow sampling on the interface.
- Configure counter sampling on the interface.
Procedure
- Configure an IP address for the interface of SwitchA.
# Configure an IP address for the interface of SwitchA according to Figure 12-3.
<HUAWEI> system-view [HUAWEI] sysname SwitchA [SwitchA] vlan batch 10 20 30 [SwitchA] interface gigabitethernet 1/0/1 [SwitchA-GigabitEthernet1/0/1] port link-type access [SwitchA-GigabitEthernet1/0/1] port default vlan 10 [SwitchA-GigabitEthernet1/0/1] quit [SwitchA] interface vlanif 10 [SwitchA-Vlanif10] ip address 10.1.10.1 24 [SwitchA-Vlanif10] quit [SwitchA] interface gigabitethernet 1/0/2 [SwitchA-GigabitEthernet1/0/2] port link-type hybrid [SwitchA-GigabitEthernet1/0/2] port hybrid pvid vlan 20 [SwitchA-GigabitEthernet1/0/2] port hybrid untagged vlan 20 [SwitchA-GigabitEthernet1/0/2] quit [SwitchA] interface vlanif 20 [SwitchA-Vlanif20] ip address 10.1.20.1 24 [SwitchA-Vlanif20] quit [SwitchA] interface gigabitethernet 1/0/3 [SwitchA-GigabitEthernet1/0/3] port link-type hybrid [SwitchA-GigabitEthernet1/0/3] port hybrid pvid vlan 30 [SwitchA-GigabitEthernet1/0/3] port hybrid untagged vlan 30 [SwitchA-GigabitEthernet1/0/3] quit [SwitchA] interface vlanif 30 [SwitchA-Vlanif30] ip address 10.1.30.1 24 [SwitchA-Vlanif30] quit
- Configure sFlow agent and collector information.
# Configure an IP address for the sFlow agent.
[SwitchA] sflow agent ip 10.1.10.1
# Configure sFlow collector information: ID 2, IP address 10.1.10.2, and description netserver.
[SwitchA] sflow collector 2 ip 10.1.10.2 description netserver
- Configure flow sampling.
# Set the sampling rate.
[SwitchA] interface gigabitethernet 1/0/2 [SwitchA-GigabitEthernet1/0/2] sflow flow-sampling rate 4000
# Specify collector 2 as the target collector to receive sFlow packets sent by the agent.
[SwitchA-GigabitEthernet1/0/2] sflow flow-sampling collector 2
- Configure counter sampling.
# Set the counter sampling interval to 120s.
[SwitchA-GigabitEthernet1/0/2] sflow counter-sampling interval 120
# Specify collector 2 as the target collector to receive sFlow packets sent by the agent.
[SwitchA-GigabitEthernet1/0/2] sflow counter-sampling collector 2 [SwitchA-GigabitEthernet1/0/2] quit [SwitchA] quit
- Verify the configuration.
# After the configuration is complete, run the display sflow command on SwitchA to check the global sFlow configuration.
<SwitchA> display sflow sFlow Version 5 Information: -------------------------------------------------------------------------- Agent Information: IP Address: 10.1.10.1(CLI) Address family: IPV4 Vpn-instance: NA -------------------------------------------------------------------------- Collector Information: Collector ID: 2 IP Address: 10.1.10.2 Address family: IPV4 Vpn-instance: NA Port: 6343 Datagram size: 1400 Time out: NA Description: netserver -------------------------------------------------------------------------- Port on slot 1 Information: Interface: GE1/0/2 Flow-sample collector: 2 Counter-sample collector : 2 Flow-sample rate(1/x): 4000 Counter-sample interval(s): 120 Flow-sample maxheader: 64 Flow-sample direction: IN,OUT -------------------------------------------------------------------------- Port on slot 2 Information: -------------------------------------------------------------------------- Port on slot 3 Information:
Configuration File
SwitchA configuration file
# sysname SwitchA # vlan batch 10 20 30 # interface Vlanif10 ip address 10.1.10.1 255.255.255.0 # interface Vlanif20 ip address 10.1.20.1 255.255.255.0 # interface Vlanif30 ip address 10.1.30.1 255.255.255.0 # interface GigabitEthernet1/0/1 port link-type access port default vlan 10 # interface GigabitEthernet1/0/2 port link-type hybrid port hybrid pvid vlan 20 port hybrid untagged vlan 20 sflow counter-sampling collector 2 sflow counter-sampling interval 120 sflow flow-sampling collector 2 sflow flow-sampling rate 4000 # interface GigabitEthernet1/0/3 port link-type hybrid port hybrid pvid vlan 30 port hybrid untagged vlan 30 # sflow collector 2 ip 10.1.10.2 description netserver # sflow agent ip 10.1.10.1 # return