-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_basic.py
108 lines (88 loc) · 2.99 KB
/
example_basic.py
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
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from comnetsemu.cli import CLI, spawnXtermDocker
from comnetsemu.net import Containernet, VNFManager
from mininet.link import TCLink
from mininet.log import info, setLogLevel
from mininet.node import Controller
if __name__ == "__main__":
# Only used for auto-testing.
AUTOTEST_MODE = os.environ.get("COMNETSEMU_AUTOTEST_MODE", 0)
setLogLevel("info")
prj_folder = "/home/ubuntu/comnetsemu_free5gc"
mongodb_folder = "/home/ubuntu/mongodbdata"
net = Containernet(controller=Controller, link=TCLink, xterms=False)
info("*** Add controller\n")
net.addController("c0")
info("*** Creating hosts\n")
info("*** Add core network\n")
core = net.addDockerHost(
"core",
dimage="free5gc",
ip="192.168.0.101",
#dcmd="/free5gc/scripts/run_core.sh",
docker_args={
"hostname": "core",
"ports": {"5000/tcp":5000,"8000" :8000},
"volumes": {
prj_folder + "/free5gc/config":{
"bind": "/free5gc/config",
"mode": "rw",
},
prj_folder + "/free5gc/scripts":{
"bind": "/free5gc/scripts",
"mode": "rw",
},
prj_folder + "/log": {
"bind": "/free5gc/log",
"mode": "rw",
},
mongodb_folder :{
"bind": "/free5gc/mongodb",
"mode": "rw",
},
},
"cap_add": ["NET_ADMIN"],
"sysctls": {"net.ipv4.ip_forward": 1},
"devices": "/dev/net/tun:/dev/net/tun:rwm"
},
)
info("*** Add gNB and UE\n")
gnb = net.addDockerHost(
"gnb",
dimage="ueransim",
ip="192.168.0.102",
#dcmd="echo",
docker_args={
"hostname": "gnb",
"volumes": {
prj_folder + "/ueransim/config":{
"bind": "/UERANSIM/config",
"mode": "rw",
},
prj_folder + "/ueransim/scripts":{
"bind": "/UERANSIM/scripts",
"mode": "rw",
},
prj_folder + "/log": {
"bind": "/UERANSIM/log",
"mode": "rw",
},
},
"cap_add": ["NET_ADMIN"],
"devices": "/dev/net/tun:/dev/net/tun:rwm"
},
)
info("*** Adding switch\n")
s1 = net.addSwitch("s1")
s2 = net.addSwitch("s2")
info("*** Adding links\n")
net.addLink(gnb, s1, bw=1000, delay="1ms", intfName1="gnb-s1", intfName2="s1-gnb")
net.addLink(s1, s2, bw=1000, delay="10ms", intfName1="s1-s2", intfName2="s2-s1")
net.addLink(core, s2, bw=1000, delay="1ms", intfName1="core-s2", intfName2="s2-core")
info("\n*** Starting network\n")
net.start()
if not AUTOTEST_MODE:
CLI(net)
net.stop()