1. create Ubuntu20.04 VMs
qemu-img create ubuntu2004-svr-0.img 40G -f raw
qemu-img create ubuntu2004-svr-1.img 40G -f raw
qemu-system-x86_64 -enable-kvm -smp 8 -hda ubuntu2004-svr-0.img -m 8G -boot d -cdrom ubuntu-20.04-live-server-amd64.iso -device virtio-net,netdev=ubuntu2004-0 -netdev tap,id=ubuntu2004-0,ifname=tap0,script=no,downscript=no -vnc :1
qemu-system-x86_64 -enable-kvm -smp 8 -hda ubuntu2004-svr-1.img -m 8G -boot d -cdrom ubuntu-20.04-live-server-amd64.iso -device virtio-net,netdev=ubuntu2004-1 -netdev tap,id=ubuntu2004-1,ifname=tap0,script=no,downscript=no -vnc :1
2. Boot Ubuntu2004 with TAPs
qemu-system-x86_64 -enable-kvm -smp 8 -hda ubuntu2004-0.img -m 8G -device virtio-net,netdev=ubuntu2004-0 -netdev tap,id=ubuntu2004-0,ifname=tap0,script=no,downscript=no -vnc :2 &
qemu-system-x86_64 -enable-kvm -smp 8 -hda ubuntu2004-1.img -m 8G -device virtio-net,netdev=ubuntu2004-1 -netdev tap,id=ubuntu2004-1,ifname=tap1,script=no,downscript=no -vnc :3 &
3. Install OVS
rpmbuild --rebuild openvswitch-2.11.0-4.el7.src.rpm
rpm -hiv --force openvswitch-2.11.0-4.el7.centos.x86_64.rpm
4. Enable and install OVS
systemctl enable openvswitch
systemctl start openvswitch
systemctl status openvswitch
5. Add interface to OVS bridge
ovs-vsctl add-br sflow-br
ovs-vsctl add-port sflow-br tap0
ovs-vsctl add-port sflow-br tap1
ip addr add 192.168.1.55/24 dev sflow-br
ip link set sflow-br up
6. Add external interface to OVS
ip addr add 192.168.1.54/24 dev p1p1
ip link set p1p1 up
ovs-vsctl add-port sflow-br p1p1
7. add listening port in the another host.
ip addr add 192.168.1.48/24 dev p4p1
ip link set p4p1 up
192.168.1.48< ---- >192.168.1.54
8. add sFlow
COLLECTOR_IP=192.168.1.48
COLLECTOR_PORT=6343
AGENT_IP=192.168.1.54
HEADER_BYTES=128
SAMPLING_N=64
POLLING_SECS=10
ovs-vsctl -- --id=@sflow create sflow agent=${AGENT_IP} \
target="${COLLECTOR_IP}\:${COLLECTOR_PORT}" header=${HEADER_BYTES} \
sampling=${SAMPLING_N} polling=${POLLING_SECS} \
-- set bridge sflow-br sflow=@sflow
9. on the "192.168.1.48", run "sflowtool -p 6343 -l"
sflowtool -p 6343 -l
CNTR,172.16.10.3,20,6,10000000000,1,3,1532,20,0,4294967295,0,0,4294967295,29940,460,4294967295,4294967295,0,0,0
CNTR,172.16.10.3,11,6,100000000,0,3,8728,176,0,4294967295,0,0,4294967295,748940,3304,4294967295,4294967295,0,0,0