-
Notifications
You must be signed in to change notification settings - Fork 3
/
emulator.py
133 lines (111 loc) · 3.61 KB
/
emulator.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from mininet.topo import Topo
from mininet.node import (Controller, RemoteController, OVSKernelSwitch,
CPULimitedHost, OVSController)
from mininet.net import Mininet
from mininet.link import TCLink
from mininet.cli import CLI
from mininet.util import custom, irange
from mininet.log import setLogLevel, info, warn, error, debug
from subprocess import Popen, PIPE
from argparse import ArgumentParser
import multiprocessing
from time import sleep
import os
import sys
import json
from network import (DumbbellNet, SingleSwitchNet, SinglepathTreeNet,
MultipathTreeNet, FatTreeNet, ShamrockNet,
RegularTreeNet, ManagementNet)
from applauncher import HadoopTest, IperfTest
from nat import connectToGateway, establishRoutes, startNAT, stopNAT
from sshd import startSSH, stopSSH
def RunTest(net=None, remoteController=False, enableNAT=True):
mgntController, mgntSwitch = ManagementNet(net)
if enableNAT:
root = connectToGateway(net, switch='mgnt0')
net.build()
info( '*** Starting controller\n' )
for controller in net.controllers:
controller.start()
info( '*** Starting %s switches\n' % len( net.switches ) )
for switch in net.switches:
info( switch.name + ' ')
if switch.name != "mgnt0":
switch.start( [net.controllers[0]])
mgntSwitch.start([mgntController])
info( '\n' )
if enableNAT:
startNAT(root)
establishRoutes(net)
startSSH(net)
# wait for the switches to connect to the controller
info('** Waiting for switches to connect to the controller\n')
sleep(5)
if remoteController:
sleep(30)
#CLI(net)
hosts = net.hosts
#sleep(30)
#net.pingAll()
#net.pingAll()
net.ping(hosts=hosts, timeout="1")
if remoteController:
net.ping(hosts=hosts, timeout="1")
net.ping(hosts=hosts, timeout="1")
#CLI(net)
HadoopTest(hosts)
#IperfTest(hosts)
#CLI(net)
if enableNAT:
stopNAT(root)
stopSSH(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
json_file = open("config.json")
config = json.load(json_file)
json_file.close()
print config
#sys.exit()
topology = config["networkTopology"]
if topology == "singleswitch":
net = SingleSwitchNet(numHosts=config["numHostsPerSwitch"],
bw=config["bandwidthMininet"],
cpu=config["cpuLimit"],
#cpu=0.05,
queue=config["queue"],
remoteController=config["remoteController"])
elif topology == "dumbbell":
net = DumbbellNet(numSwitches=config["numSwitches"],
numHostsPerSwitch=config["numHostsPerSwitch"],
L=config["numberTrunkLinks"],
bw=config["bandwidthMininet"],
cpu=config["cpuLimit"],
queue=config["queue"],
remoteController=config["remoteController"])
elif topology == "singlepathtree":
net = SinglepathTreeNet(depth=2, fanout=4,
bw=config["bandwidthMininet"],
cpu=config["cpuLimit"],
queue=config["queue"],
remoteController=config["remoteController"])
elif topology == "multipathtree":
net = MultipathTreeNet(depth=2, fanout=4,
bw=config["bandwidthMininet"],
cpu=config["cpuLimit"],
queue=config["queue"])
elif topology == "fattree":
net = FatTreeNet(k=4,
bw=config["bandwidthMininet"],
cpu=config["cpuLimit"],
queue=config["queue"])
elif topology == "shamrock":
net = ShamrockNet(bw=config["bandwidthMininet"],
cpu=config["cpuLimit"],
queue=config["queue"],
remoteController=config["remoteController"])
else:
print "Error: Unknown topology type."
sys.exit(1)
RunTest(net=net, remoteController=config["remoteController"])
os.system('sudo mn -c')