-
Notifications
You must be signed in to change notification settings - Fork 19
/
example_topo
executable file
·55 lines (48 loc) · 1.87 KB
/
example_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
#!/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
#
# IMPORTANT NOTE: Node names MUST NOT exceed 9 characters.
# This is due to the limitation to 14 characters of interface names
# You can override any of these settings on a per-topology basis
# Group number
GROUPNUMBER=255
# Node configs
CONFIGDIR=example_cfg
# boot script name
BOOT="boot"
# startup script name
STARTUP="start"
PREFIXBASE="fd00:${GROUPNUMBER}"
PREFIXLEN=32
# You can reuse the above two to generate ip addresses/routes, ...
# 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 small network BELNET - BXL - LLN
# Nodes are creadted 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
# e.g. BXL-eth0 links to LLN-eth0
add_link BXL LLN
# BXL-eth1 links to BELNET-eth0
add_link BXL BELNET
echo "@@ Adding LANs"
# Create a new LAN (subnet), attached to BELNET, with 2 hosts: B1 and B2
mk_LAN BELNET B1 B2
# Same but with 4 hosts in LLN
mk_LAN LLN L1 L2 L3 L4
echo "@@ Briding the network"
# Connect BELNET to its two connectivity providers
bridge_node BELNET eth1 as200
bridge_node BELNET eth2 as300
}