Netdev Tutorial
Netdev Tutorial
Network Functions
Part I: Virtual Switching Technologies in Linux
Toshiaki Makita
NTT Open Source Software Center
• Demo
• Setting up non-promiscuous bridge
Proceedings of netdev 0.1, Feb 14-17, 2015, Ottawa, On, Canada
pass to bridge
upper layer handler hook
eth0 eth0 eth1
promiscuous
Proceedings of netdev 0.1, Feb 14-17, 2015, Ottawa, On, Canada promiscuous
mode mode
Copyright © 2015 NTT Corp. All Rights Reserved. 5
bridge with KVM
fd
kernel read/write
bridge vfs
eth0 tap0
eth0
External SW
Proceedings of netdev 0.1, Feb 14-17, 2015, Ottawa, On, Canada
read/write read/write
macvtap0 macvtap1
macvlan
kernel eth0
Proceedings of netdev 0.1, Feb 14-17, 2015, Ottawa, On, Canada
user space
daemon Flow table OpenFlow
(ovs-vswitchd) controller
FDB
control plane
upcall
kernel openvswitch
Flow table
(datapath) (cache)
data plane
handler hook
eth0 eth1
promiscuous
Proceedings of netdev 0.1, Feb 14-17, 2015, Ottawa, On, Canada
eth0
fd
kernel read/write
openvswitch vfs
eth0 tap0
• SR-IOV
• Addition to PCI normal physical function (PF),
allow to add light weight virtual functions (VF)
• VF appears as a network interface (eth0_0, eth0_1...)
• Some SR-IOV devices have switches in them
• allow PF-VF / VF-VF communication
PF VF VF
eth0 eth0_0 eth0_1
embedded switch
qemu qemu
Guest Guest
eth0_0 eth0_1
eth0
embedded switch
• Various APIs
• ioctl
• sysfs
• netlink
• Commands
• brctl (in bridge-utils, using ioctl / sysfs)
• ip / bridge (in iproute2, using netlink)
• brctl
# brctl addbr <bridge> ... create new bridge
# brctl addif <bridge> <port> ... attach port to bridge
# brctl showmacs <bridge> ... show fdb entries
• FDB manipulation
• VLAN filtering
• Learning / flooding control
• Non-promiscuous bridge
• VLAN filtering for 802.1ad (Q-in-Q)
• FDB
• Forwarding database
• Learning: packet arrival triggers entry creation
• Source MAC address is used with incoming port
• Flood if failed to find entry
• Flood: deliver packet to all ports but incoming one
FDB kernel
MAC address Dst
learning
aa:bb:cc:dd:ee:ff eth0 bridge
...
specified port
Proceedings of netdev 0.1, Feb 14-17, 2015, Ottawa, On, Canada
kernel
master bridge
master bridge
PF VF VF
self eth0 eth0_0 eth0_1
embedded switch
embedded switch
qemu qemu
Guest 1 Guest 2
MAC A MAC C
eth1 eth0_0
VF
tap bridge
Dst. A
PF
add fdb entry eth0 MAC B
embedded switch
• 802.1Q Bridge
• Since kernel 3.9
• Filter packets according to vlan tag
• Forward packets according to vlan tag as well as mac
address
• Insert / strip vlan tag
kernel
FDB
insert / strip vlan tag
MAC address Vlan Dst
aa:bb:cc:dd:ee:ff 10 eth0 bridge
... filter disallowed vlan
eth0 eth1
VID 10
Proceedings of netdev 0.1, Feb 14-17, 2015, Ottawa, On, Canada
• Commands
• Enable VLAN filtering (disabled by default)
# echo 1 > /sys/class/net/<bridge>/bridge/vlan_filtering
• Add / delete allowed vlan
# bridge vlan add vid <vid> dev <port>
# bridge vlan del vid <vid> dev <port>
• Set pvid / untagged
# bridge vlan add vid <vid> dev <port> [pvid] [untagged]
• Dump settings
# bridge vlan show
• Traditional configuration
• Use vlan devices qemu qemu
• Needs bridges per vlan Guest Guest
• Low flexibility
• How many devices? eth0 eth0
# ifconfig -s
Iface ...
eth0 tap0 tap1
eth0.10
br10
br10 br20
eth0.20
br20
eth0.30 eth0.10 eth0.20
br30
eth0.40 eth0
br40 kernel
... Proceedings of netdev 0.1, Feb 14-17, 2015, Ottawa, On, Canada
• Other switches
• Open vSwitch
• Can also handle VLANs
# ovs-vsctl set Port <port> tag=<vid>
• Commands
# bridge link set dev <port> learning off
Proceedings of netdev 0.1, Feb 14-17, 2015, Ottawa, On, Canada
# bridge link set dev <port> flood off
Copyright © 2015 NTT Corp. All Rights Reserved. 31
Non-promiscuous bridge
• Instead of promisc
mode, unicast filtering is tap0 tap1
set for static FDB entries no learning no learning
no flooding no flooding
• Automatically enabled if bridge
meeting some conditions learning
• There is one or zero non-promisc
flooding
learning or flooding port
kernel eth0
• bridge itself is not
promiscuous mode
• VLAN filtering is enabled
Proceedings of netdev 0.1, Feb 14-17, 2015, Ottawa, On, Canada
• Command
Proceedings of netdev 0.1, Feb 14-17, 2015, Ottawa, On, Canada
# echo 0x88a8 > /sys/class/net/<bridge>/bridge/vlan_protocol
Copyright © 2015 NTT Corp. All Rights Reserved. 33
802.1ad (Q-in-Q) support for bridge
qemu
• Bridge preserves qemu
guest .1Q tag (vid Guest A
Guest C
eth0.30
30) when inserting
.1ad tag (vid 10) eth0 eth0
.1Q VID 30
• .1ad tag will be tap0 tap1
stripped at .1ad VID 10 pvid/untag pvid/untag
another end .1Q VID 30 vlan 10 vlan 20
point of .1ad bridge (.1ad mode)
network vlan10 / 20
eth0
kernel .1ad VID 10
.1Q VID 30
.1Q VID 30
Customer's Proceedings of netdev 0.1, Feb 14-17, 2015, Ottawa, On, Canada
.1ad network
another site Copyright © 2015 NTT Corp. All Rights Reserved. 34
Demo
• Steps
• Create bridge vnet0 vnet1
• Enable vlan filtering no learning no learning
• Attach guests (by libvirt) no flooding no flooding
bridge
• Add FDB entries
learning
• Set port attributes non-promisc
flooding
(learning /flooding)
kernel eth0
• Commands
• Create bridge
# ip link add br0 up type bridge
# ip link set eth0 master br0
• Enable vlan filtering
# echo 1 > /sys/class/net/br0/bridge/vlan_filtering
• Attach guests
# virsh start guest1
# virsh start guest2
• Add FDB entries ("append" overwrites if exists)
# bridge fdb append 52:54:00:xx:xx:xx dev vnet0 master temp
# bridge fdb append 52:54:00:yy:yy:yy dev vnet1 master temp
• Set port attributes
# bridge link set dev vnet0 learning off flood off
# bridge link setProceedings
devof netdev
vnet1 learning
0.1, Feb 14-17, 2015, Ottawa, On, Canadaoff flood off