-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-Node.sh
120 lines (92 loc) · 4.5 KB
/
4-Node.sh
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
###############################################################
# Topology
# _______ 5mbit, 5ms _______ 10mbit, 10ms _______
# | |-----------------| r1 |----------------| |
# | h1 | |_______| | h2 |
# | | _______ | |
# | | | r2 | | |
# |_______|-----------------|_______|----------------|_______|
# 10mbit, 10ms 50mbit, 10ms
##############################################################
#!/bin/sh
#Create four network namespaces: h1 and h2
ip netns add h1
ip netns add h2
ip netns add r1
ip netns add r2
# Disable the reverse path filtering
sysctl -w net.ipv4.conf.all.rp_filter=0
# Enable MPTCP on both the network namespaces
ip netns exec h2 sysctl -w net.mptcp.enabled=1
ip netns exec h1 sysctl -w net.mptcp.enabled=1
# Configuring the C flag
ip netns exec h1 sysctl -w net.mptcp.allow_join_initial_addr_port=1
ip netns exec h2 sysctl -w net.mptcp.allow_join_initial_addr_port=1
#Create two virtual ethernet (veth) pairs
ip link add eth1a netns h1 type veth peer eth1b netns r1
ip link add eth2a netns h1 type veth peer eth2b netns r2
ip link add eth3a netns r1 type veth peer eth3b netns h2
ip link add eth4a netns r2 type veth peer eth4b netns h2
# Assign IP address to each interface on h1
ip -n h1 address add 10.0.0.1/24 dev eth1a
ip -n h1 address add 192.168.0.1/24 dev eth2a
# Assign IP address to each interface on r1
ip -n r1 address add 10.0.0.2/24 dev eth1b
ip -n r1 address add 10.0.1.1/24 dev eth3a
# Assign IP address to each interface on r2
ip -n r2 address add 192.168.0.2/24 dev eth2b
ip -n r2 address add 192.168.1.1/24 dev eth4a
# Assign IP address to each interface on h2
ip -n h2 address add 10.0.1.2/24 dev eth3b
ip -n h2 address add 192.168.1.2/24 dev eth4b
# Set the data rate and delay on the veth devices at h1
ip netns exec h1 tc qdisc add dev eth1a root netem delay 5ms rate 5mbit
ip netns exec h1 tc qdisc add dev eth2a root netem delay 10ms rate 10mbit
# Set the data rate and delay on the veth devices at r1
ip netns exec r1 tc qdisc add dev eth3a root netem delay 5ms rate 10mbit
ip netns exec r1 tc qdisc add dev eth1b root netem delay 10ms rate 5mbit
# Set the data rate and delay on the veth devices at r2
ip netns exec r2 tc qdisc add dev eth2b root netem delay 10ms rate 10mbit
ip netns exec r2 tc qdisc add dev eth4a root netem delay 10ms rate 50mbit
# Set the data rate and delay on the veth devices at h2
ip netns exec h2 tc qdisc add dev eth3b root netem delay 5ms rate 10mbit
ip netns exec h2 tc qdisc add dev eth4b root netem delay 10ms rate 50mbit
# Turn ON all ethernet devices
ip -n h1 link set eth1a up
ip -n h1 link set eth2a up
ip -n r1 link set eth1b up
ip -n r1 link set eth3a up
ip -n r2 link set eth2b up
ip -n r2 link set eth4a up
ip -n h2 link set eth3b up
ip -n h2 link set eth4b up
# Define subflows for MPTCP
ip -n h1 mptcp endpoint flush
ip -n h1 mptcp limits set subflow 2 add_addr_accepted 2
ip -n h2 mptcp endpoint flush
ip -n h2 mptcp limits set subflow 2 add_addr_accepted 2
# Path Management 'in-kernel' using ip mptcp
ip -n h2 mptcp endpoint add 192.168.1.2 dev eth4b id 1 signal
ip -n h1 mptcp endpoint add 192.168.0.1 dev eth2a id 1 fullmesh
# Enable IP forwarding
ip netns exec r1 sysctl -w net.ipv4.ip_forward=1
ip netns exec r2 sysctl -w net.ipv4.ip_forward=1
# Create two routing tables for two interace in h1
ip netns exec h1 ip rule add from 10.0.0.1 table 1
ip netns exec h1 ip rule add from 192.168.0.1 table 2
# Configure the two routing tables of h1
ip netns exec h1 ip route add 10.0.0.0/24 dev eth1a scope link table 1
ip netns exec h1 ip route add default via 10.0.0.2 dev eth1a table 1
ip netns exec h1 ip route add 192.168.0.0/24 dev eth2a scope link table 2
ip netns exec h1 ip route add default via 192.168.0.2 dev eth2a table 2
# Create two routing tables for two interace in h2
ip netns exec h2 ip rule add from 10.0.1.2 table 3
ip netns exec h2 ip rule add from 192.168.1.2 table 4
# Configure the two routing tables
ip netns exec h2 ip route add 10.0.1.0/24 dev eth3b scope link table 3
ip netns exec h2 ip route add default via 10.0.1.1 dev eth3b table 3
ip netns exec h2 ip route add 192.168.1.0/24 dev eth4b scope link table 4
ip netns exec h2 ip route add default via 192.168.1.1 dev eth4b table 4
# Global Default route for h1 and h2
ip netns exec h1 ip route add default scope global nexthop via 10.0.0.2 dev eth1a
ip netns exec h2 ip route add default scope global nexthop via 192.168.1.1 dev eth4b