Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renew Network Setup and Teardown #30

Merged
merged 19 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5d28dce
Add admin_iface and admin_iface_ip_net variables to Host and its config
gierens Nov 6, 2022
8ebcb0c
Remove admin_iface settings from loadgen config
gierens Nov 6, 2022
caa1f68
Add Host.setup_admin_bridge function
gierens Nov 6, 2022
c9b3e5a
Rename Host's admin_iface to admin_bridge
gierens Nov 6, 2022
898d2bc
Add Host admin_tap variable and corresponding config setting
gierens Nov 6, 2022
e0fdaef
Revised Host.setup_admin_tap to use admin_tap variable
gierens Nov 6, 2022
d0eff02
Add test_iface settings for chair server river to autotest.cfg
gierens Nov 6, 2022
561b21d
Add test_bridge/tap/macvtap variables to Host and corresponding config
gierens Nov 6, 2022
1f5b9d3
Add Server.whoami function
gierens Nov 6, 2022
17f3016
Revise Host.setup_test_br_tap to use config and ip command
gierens Nov 6, 2022
ad44f33
Revise Host.destroy_test_br_tap to use interface variables
gierens Nov 7, 2022
a958a85
Fix length of test_macvtap name
gierens Nov 7, 2022
251bc4d
Revise Host.setup_test_macvtap to use ip command and config variables
gierens Nov 7, 2022
28fb484
Delete unused Host functions and revise Host.destroy_macvtap to use c…
gierens Nov 7, 2022
10b664a
Revise Host.cleanup_network to use destroy_test_br_tap/macvtap
gierens Nov 7, 2022
f343ed4
Comment out release_test_iface in Host.cleanup_network
gierens Nov 7, 2022
5fee791
Add Host.setup_admin_bridge to setup_network command
gierens Nov 7, 2022
69a2e86
Add error message about failed network setup to setup_network command
gierens Nov 7, 2022
551db05
Add new guest test_iface_mac to config
gierens Nov 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions autotest.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
[host]
fqdn=river.dse.in.tum.de
admin_iface=
admin_bridge=
test_iface=
test_iface_addr=
test_iface_mac=
test_iface_driv=
admin_bridge=br-gierens0
admin_bridge_ip_net=192.168.56.1/24
admin_tap=tap-gierens0
test_iface=enp81s0
test_iface_addr=0000:51:00.0
test_iface_mac=b4:96:91:b3:8b:3c
test_iface_driv=ice
test_bridge=br-gierens1
test_tap=tap-gierens1
test_macvtap=mvtap-gierens1
moongen_dir=
xdp_reflector_dir=

Expand All @@ -16,15 +20,13 @@ memory=4096
root_disk_file=
test_iface=
test_iface_addr=
test_iface_mac=
test_iface_mac=52:54:00:00:00:01
test_iface_driv=
moongen_dir=
xdp_reflector_dir=

[loadgen]
fqdn=wilfred.dse.in.tum.de
admin_iface=
admin_bridge=
test_iface=
test_iface_addr=
test_iface_mac=
Expand Down
8 changes: 8 additions & 0 deletions autotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,16 @@ def create_servers(conf: ConfigParser,
if host:
servers['host'] = Host(
conf['host']['fqdn'],
conf['host']['admin_bridge'],
conf['host']['admin_bridge_ip_net'],
conf['host']['admin_tap'],
conf['host']['test_iface'],
conf['host']['test_iface_addr'],
conf['host']['test_iface_mac'],
conf['host']['test_iface_driv'],
conf['host']['test_bridge'],
conf['host']['test_tap'],
conf['host']['test_macvtap'],
conf['guest']['root_disk_file'],
conf['guest']['test_iface_mac'],
conf['host']['moongen_dir'],
Expand Down Expand Up @@ -732,12 +738,14 @@ def setup_network(args: Namespace, conf: ConfigParser) -> None:
host: Host = create_servers(conf, guest=False, loadgen=False)['host']

try:
host.setup_admin_bridge()
host.setup_admin_tap()
if args.interface == 'brtap':
host.setup_test_br_tap()
else:
host.setup_test_macvtap()
except Exception:
error('Failed to setup network')
host.cleanup_network()


Expand Down
168 changes: 99 additions & 69 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ def exec(self: 'Server', command: str) -> str:
else:
return self.__exec_ssh(command)

def whoami(self: 'Server') -> str:
"""
Get the user name.

Parameters
----------

Returns
-------
str
The user name.
"""
return self.exec('whoami').strip()

def tmux_new(self: 'Server', session_name: str, command: str) -> None:
"""
Start a tmux session on the server.
Expand Down Expand Up @@ -842,15 +856,27 @@ class Host(Server):
>>> Host('server.test.de')
Host(fqdn='server.test.de')
"""
admin_bridge: str
admin_bridge_ip_net: str
admin_tap: str
test_bridge: str
test_tap: str
test_macvtap: str
guest_test_iface_mac: str
guest_root_disk_path: str

def __init__(self: 'Host',
fqdn: str,
admin_bridge: str,
admin_bridge_ip_net: str,
admin_tap: str,
test_iface: str,
test_iface_addr: str,
test_iface_mac: str,
test_iface_driv: str,
test_bridge: str,
test_tap: str,
test_macvtap: str,
guest_root_disk_path: str,
guest_test_iface_mac: str,
moongen_dir: str,
Expand All @@ -863,6 +889,12 @@ def __init__(self: 'Host',
----------
fqdn : str
The fully qualified domain name of the host.
admin_bridge : str
The network interface identifier of the admin bridge interface.
admin_bridge_ip_net : str
The IP address and subnet mask of the admin bridge interface.
admin_tap : str
The network interface identifier of the admin tap interface.
test_iface : str
The name of the test interface.
test_iface_addr : str
Expand All @@ -871,6 +903,12 @@ def __init__(self: 'Host',
The MAC address of the test interface.
test_iface_driv : str
The driver of the test interface.
test_bridge : str
The network interface identifier of the test bridge interface.
test_tap : str
The network interface identifier of the test tap interface.
test_macvtap : str
The network interface identifier of the test macvtap interface.
guest_root_disk_path : str
The path to the root disk of the guest.
guest_test_iface_mac : str
Expand Down Expand Up @@ -899,9 +937,32 @@ def __init__(self: 'Host',
super().__init__(fqdn, test_iface, test_iface_addr, test_iface_mac,
test_iface_driv, moongen_dir, xdp_reflector_dir,
localhost)
self.admin_bridge = admin_bridge
self.admin_bridge_ip_net = admin_bridge_ip_net
self.admin_tap = admin_tap
self.test_bridge = test_bridge
self.test_tap = test_tap
self.test_macvtap = test_macvtap
self.guest_test_iface_mac = guest_test_iface_mac
self.guest_root_disk_path = guest_root_disk_path

def setup_admin_bridge(self: 'Host'):
"""
Setup the admin bridge.

Parameters
----------

Returns
-------
"""
self.exec('sudo modprobe bridge')
self.exec(f'sudo ip link show {self.admin_bridge} 2>/dev/null' +
f' || (sudo ip link add {self.admin_bridge} type bridge; ' +
f'sudo ip addr add {self.admin_bridge_ip_net} ' +
f'dev {self.admin_bridge}; true)')
self.exec(f'sudo ip link set {self.admin_bridge} up')

def setup_admin_tap(self: 'Host'):
"""
Setup the admin tap.
Expand All @@ -916,10 +977,11 @@ def setup_admin_tap(self: 'Host'):
-------
"""
self.exec('sudo modprobe tun tap')
self.exec('sudo ip link show tap0 2>/dev/null' +
' || (sudo tunctl -t tap0 -u networkadmin' +
' && sudo brctl addif br0 tap0; true)')
self.exec('sudo ip link set tap0 up')
self.exec(f'sudo ip link show {self.admin_tap} 2>/dev/null' +
f' || (sudo ip tuntap add {self.admin_tap} mode tap;' +
f' sudo ip link set {self.admin_tap} '
f'master {self.admin_bridge}; true)')
self.exec(f'sudo ip link set {self.admin_tap} up')

def setup_test_br_tap(self: 'Host'):
"""
Expand All @@ -935,27 +997,33 @@ def setup_test_br_tap(self: 'Host'):
-------
"""
# load kernel modules
self.exec('sudo modprobe tun tap')
self.exec('sudo modprobe bridge tun tap')

# create bridge and tap device
self.exec('sudo ip link show br1 2>/dev/null || sudo brctl addbr br1')
self.exec('sudo ip link show tap1 2>/dev/null || ' +
'sudo ip tuntap add dev tap1 mode tap user networkadmin ' +
'multi_queue')
self.exec(f'sudo ip link show {self.test_bridge} 2>/dev/null ' +
f' || (sudo ip link add {self.test_bridge} type bridge; ' +
'true)')
username = self.whoami()
self.exec(f'sudo ip link show {self.test_tap} 2>/dev/null || ' +
f'(sudo ip tuntap add dev {self.test_tap} mode tap ' +
f'user {username} multi_queue; true)')

# add tap device and physical nic to bridge
tap1_output = self.exec('sudo ip link show tap1')
if 'master br1' not in tap1_output:
self.exec('sudo brctl addif br1 tap1')
tap_output = self.exec(f'sudo ip link show {self.test_tap}')
if f'master {self.test_bridge}' not in tap_output:
self.exec(f'sudo ip link set {self.test_tap} ' +
f'master {self.test_bridge}')
test_iface_output = self.exec(f'sudo ip link show {self.test_iface}')
if 'master br1' not in test_iface_output:
self.exec(f'sudo brctl addif br1 {self.test_iface}')
if f'master {self.test_bridge}' not in test_iface_output:
self.exec(f'sudo ip link set {self.test_iface} ' +
f'master {self.test_bridge}')

# bring up all interfaces (nic, bridge and tap)
self.exec(f'sudo ip link set {self.test_iface} up ' +
'&& sudo ip link set br1 up && sudo ip link set tap1 up')
f'&& sudo ip link set {self.test_bridge} up ' +
f'&& sudo ip link set {self.test_tap} up')

def destroy_br_tap(self: 'Host'):
def destroy_test_br_tap(self: 'Host'):
"""
Destroy the bridged test tap device.

Expand All @@ -965,10 +1033,8 @@ def destroy_br_tap(self: 'Host'):
Returns
-------
"""
self.exec('sudo ip link set tap1 down')
self.exec('sudo brctl delif br1 tap1')
self.exec('sudo ip link delete tap1')
self.exec('sudo brctl delbr br1')
self.exec(f'sudo ip link delete {self.test_tap} || true')
self.exec(f'sudo ip link delete {self.test_bridge} || true')

def setup_test_macvtap(self: 'Host'):
"""
Expand All @@ -983,16 +1049,17 @@ def setup_test_macvtap(self: 'Host'):
Returns
-------
"""
self.exec('sudo ip link show macvtap1 2>/dev/null' +
' || sudo ip link add link enp176s0 name macvtap1' +
' type macvtap')
self.exec('sudo ip link set macvtap1 address ' +
self.exec('sudo modprobe macvlan')
self.exec(f'sudo ip link show {self.test_macvtap} 2>/dev/null' +
f' || sudo ip link add link {self.test_iface}' +
f' name {self.test_macvtap} type macvtap')
self.exec(f'sudo ip link set {self.test_macvtap} address ' +
f'{self.guest_test_iface_mac} up')
self.exec('sudo ip link set enp176s0 up')
self.exec('sudo chmod 666' +
' /dev/tap$(cat /sys/class/net/macvtap1/ifindex)')
f' /dev/tap$(cat /sys/class/net/{self.test_macvtap}/ifindex)'
)

def destroy_macvtap(self: 'Host'):
def destroy_test_macvtap(self: 'Host'):
"""
Destroy the macvtap test interface.

Expand All @@ -1002,44 +1069,7 @@ def destroy_macvtap(self: 'Host'):
Returns
-------
"""
self.exec('sudo ip link delete macvtap1')

def setup_test_bridge(self: 'Host'):
"""
Setup test bridge.

This sets up a bridge device for the test interface of the host.

Parameters
----------
mac : str
The MAC address for the test bridge.
"""
# load kernel modules
self.exec('sudo modprobe tun tap')

# create bridge
self.exec('sudo ip link show br1 2>/dev/null || sudo brctl addbr br1')

# set bridge's MAC address
self.exec('sudo ip link set br1 down && ' +
f'sudo ip link set br1 address {self.guest_test_iface_mac}')

# add tap device and physical nic to bridge
test_iface_output = self.exec(f'sudo ip link show {self.test_iface}')
if 'master br1' not in test_iface_output:
self.exec(f'sudo brctl addif br1 {self.test_iface}')

# bring up all interfaces (nic and bridge)
self.exec(f'sudo ip link set {self.test_iface} up' +
' && sudo ip link set br1 up')

def destroy_test_bridge(self: 'Host'):
"""
Destroy the test bridge.
"""
self.exec('sudo ip link set br1 down')
self.exec('sudo brctl delbr br1')
self.exec(f'sudo ip link delete {self.test_macvtap} || true')

def run_guest(self: 'Host',
net_type: str,
Expand Down Expand Up @@ -1174,11 +1204,11 @@ def cleanup_network(self: 'Host') -> None:
Returns
-------
"""
self.release_test_iface()
# TODO
# self.release_test_iface()
self.stop_xdp_reflector(self.test_iface)
self.exec('sudo ip link delete tap1 2>/dev/null || true')
self.exec('sudo ip link delete br1 2>/dev/null || true')
self.exec('sudo ip link delete macvtap1 2>/dev/null || true')
self.destroy_test_br_tap()
self.destroy_test_macvtap()


class Guest(Server):
Expand Down