forked from cnp3/CampusNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ucl_topo
executable file
·71 lines (65 loc) · 2.79 KB
/
ucl_topo
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
#!/bin/bash
# Create a virtual network using network namespaces and veth pairs
# to connect them.
# Assuming $CONFIGDIR == "cfg":
# * Files in cfg/<Node name> will be overlaid over /etc, i.e. if a file with
# the same name exists in both directory, the one in cfg/<Node name> will
# be the one used.
# * If cfg/<Node name>_$BOOT (defaults to cfg/<Node name>_boot) exists and
# is executable, it will be executed when the node is created
# * If cfg/<Node name>_$STARTUP (defaults to cfg/<Node name>_start) exists and
# is executable, it will be executed when the whole network has started
#
# You can override any of these settings on a per-topology basis
# Group number
GROUPNUMBER=9
# Node configs
CONFIGDIR=ucl_group9
# boot script name
BOOT="boot.sh"
# startup script name
STARTUP="start.sh"
PREFIXLEN=48
PREFIXBASE_as200="fd00:200:${GROUPNUMBER}" #::/${PREFIXLEN_as200}"
PREFIXBASE_as300="fd00:300:${GROUPNUMBER}"
# You can reuse the above two to generate ip addresses/routes, ...
# in you boot and startup scripts
# e.g. "${PREFIXBASE}:1234::/$((PREFIXLEN+16))"
# This function describes the network topology that we want to emulate
function mk_topo {
echo "@@ Adding links and nodes"
# Build a minimal UCL network
# Nodes are created on the fly, and their interface are assigned as
# <node name>-eth<count>, where count starts at 0 and is increased by 1
# after each new interface
add_link Michotte SH1C # Michotte-eth0 <-> SH1C-eth0
add_link SH1C Halles # SH1C-eth1 <-> Halles-eth0
add_link Michotte Carnoy # Michotte-eth1 <-> Carnoy-eth0
add_link Halles Pythagore # Halles-eth1 <-> Pythagore-eth0
add_link Carnoy Pythagore # Carnoy-eth1 <-> Pythagore-eth1
add_link Carnoy Stevin # Carnoy-eth2 <-> Stevin-eth0
add_link Stevin Pythagore # Stevin-eth1 <-> Pythagore-eth2
echo "@@ Adding LANs"
# You can add your LANs here
mk_LAN Stevin LUC
mk_LAN Carnoy TOM
mk_LAN Carnoy NS1 MO1
mk_LAN Halles NS2 MO2
mk_LAN SH1C SH1 SH2
mk_LAN Pythagore GUI
mk_LAN Michotte ART
echo "@@ Bridging the network"
# Connect to belneta and belnetb
bridge_node Pythagore eth1 belneta
bridge_node Halles eth2 belnetb
echo "@@ Making the virtual network reachable from the host machine"
# Enable IPv6 forwarding on the bridges
sysctl -w net.ipv6.conf.breth1.forwarding=1
sysctl -w net.ipv6.conf.breth2.forwarding=1
# Add (hopefully) unique source addresses on the bridge
ip address add dev breth1 "fd00:300::${GROUPNUMBER}:1/64"
ip address add dev breth2 "fd00:200::${GROUPNUMBER}:1/64"
# Route the virtual network prefixes over the bridges
ip route add "fd00:300:${GROUPNUMBER}::/48" via "fd00:300::${GROUPNUMBER}"
ip route add "fd00:200:${GROUPNUMBER}::/48" via "fd00:200::${GROUPNUMBER}"
}