-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhost_network_setup.sh
More file actions
executable file
·103 lines (86 loc) · 4 KB
/
host_network_setup.sh
File metadata and controls
executable file
·103 lines (86 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
### NETWORK SETUP
#
# This script sets up a list of network devices to allow for
# network testing only on the host but still running traffic
# through the VM.
#
# The setup allows to ping from one host network namespace
# the other with all trafiic passing through the VM.
# i.e.
# sudo ip netns exec ns1 ping 192.168.102.10
# sudo ip netns exec ns2 ping 192.168.101.10
#
# The diagram below shows a high-level (not perfectly accurate)
# overview of the resulting network.
#
# TODO: currently, echos 1 through 9 are dropped, probably due to ARP
# INFO: There may be easier solutions to achieve the same goal.
#
# +--------- ns1 ----------+ +--------- ns2 ----------+
# | "client" | | "server" |
# | +------------------+ | | +------------------+ |
# | | veth1_ns | | | | veth2_ns | |
# | | 192.168.101.10 | | | | 192.168.102.10 | |
# | +--------+---------+ | | +--------+---------+ |
# | ^ | | ^ |
# +-----------|------------+ +-----------|------------+
# | (veth1) | (veth2)
# v v
# +--------+---------+ +--------+---------+
# | veth1_host | | veth2_host |
# | (192.168.101.20) | | (192.168.102.20) |
# +--------+---------+ +--------+---------+
# | |
# +--------+---------+ +--------+---------+
# | br1 | | br2 |
# | 192.168.101.30 | | 192.168.102.30 |
# +--------+---------+ +--------+---------+
# ^ ^
# | |
# +--------+---------+ +--------+---------+
# HOST | Tap device | | Tap device |
# -----| created by |-----------| created by |-----
# VM | virt-install | | virt-install |
# +--------+---------+ +--------+---------+
# | |
# v v
# +--------+---------+ +--------+---------+
# | eth0 | | eth1 |
# | 192.168.101.100 | | 192.168.102.100 |
# +--------+---------+ +--------+---------+
# | |
# +--------+------------------------------+---------+
# | Our XDP Program (BC-PQP) |
# + - - - - - - - - - - - - - - - - - - - - - - - - +
# | VM Kernel Networking Stack |
# +-------------------------------------------------+
#
sudo ip link add br1 type bridge
sudo ip link add br2 type bridge
sudo ip link set br1 up
sudo ip link set br2 up
sudo ip netns add ns1
sudo ip netns add ns2
sudo ip link add veth1_host type veth peer name veth1_ns
sudo ip link add veth2_host type veth peer name veth2_ns
sudo ip link set veth1_ns netns ns1
sudo ip link set veth2_ns netns ns2
sudo ip netns exec ns1 ip link set veth1_ns up
sudo ip netns exec ns2 ip link set veth2_ns up
sudo ip netns exec ns1 ip link set lo up
sudo ip netns exec ns2 ip link set lo up
sudo ip netns exec ns1 ip addr add 192.168.101.10/24 dev veth1_ns
sudo ip netns exec ns2 ip addr add 192.168.102.10/24 dev veth2_ns
sudo ip link set veth1_host master br1
sudo ip link set veth2_host master br2
sudo ip link set veth1_host up
sudo ip link set veth2_host up
sudo ip addr add 192.168.101.20/24 dev veth1_host
sudo ip addr add 192.168.102.20/24 dev veth2_host
sudo ip addr add 192.168.101.30/24 dev br1
sudo ip addr add 192.168.102.30/24 dev br2
sudo ip netns exec ns1 sysctl -w net.ipv4.ip_forward=1
sudo ip netns exec ns2 sysctl -w net.ipv4.ip_forward=1
sudo ip netns exec ns1 ip route add default via 192.168.101.100 dev veth1_ns
sudo ip netns exec ns2 ip route add default via 192.168.102.100 dev veth2_ns