forked from stevelorenz/comnetsemu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdockerhostcli.py
executable file
·62 lines (48 loc) · 1.56 KB
/
dockerhostcli.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
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
"""
About: Basic example to spawn Xterms for Docker hosts
"""
from comnetsemu.cli import CLI
from comnetsemu.net import Containernet
from mininet.link import TCLink
from mininet.log import info, setLogLevel
from mininet.node import Controller
def testTopo():
# xterms=True, spawn xterms for all nodes after net.start()
net = Containernet(controller=Controller, link=TCLink, xterms=True)
info("*** Adding controller\n")
net.addController("c0")
info("*** Adding hosts\n")
h1 = net.addDockerHost(
"h1",
dimage="dev_test",
ip="10.0.0.1/24",
docker_args={"cpuset_cpus": "0", "nano_cpus": int(1e8), "hostname": "h1"},
)
h2 = net.addDockerHost(
"h2",
dimage="dev_test",
ip="10.0.0.2/24",
docker_args={"cpuset_cpus": "0", "nano_cpus": int(1e8), "hostname": "h2"},
)
h3 = net.addHost("h3", ip="10.0.0.3/24")
h4 = net.addHost("h4", ip="10.0.0.4/24")
info("*** Adding switch\n")
s1 = net.addSwitch("s1")
info("*** Creating links\n")
net.addLinkNamedIfce(s1, h1, bw=10, delay="100ms")
net.addLinkNamedIfce(s1, h2, bw=10, delay="100ms")
net.addLinkNamedIfce(s1, h3, bw=10, delay="100ms")
net.addLinkNamedIfce(s1, h4, bw=10, delay="100ms")
info("*** Starting network\n")
net.start()
info("*** Enter CLI\n")
info("Use help command to get CLI usages\n")
CLI(net)
info("*** Stopping network")
net.stop()
if __name__ == "__main__":
setLogLevel("info")
testTopo()