forked from stevelorenz/comnetsemu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_scenario.py
124 lines (98 loc) · 3.97 KB
/
example_scenario.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
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSKernelSwitch, UserSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from _thread import start_new_thread
import os, stat
import json
import time
import csv
import requests
import sys
sys.path.append("./controller")
sys.path.append(".")
print(os.getcwd())
print(sys.path.__str__())
from config import Config
# s2
# h1 10ms / \ 10ms h4
# h2 -- s1 s3 -- h5
# h3 14ms \ / 14ms h6
# s4
###################################################################
############### Scenario - 6 Hosts #############################
###################################################################
def stop_controller():
requests.put('http://0.0.0.0:8080/simpleswitch/params/stop_flag', data=json.dumps({"stop_flag": True}))
def startIperf(host1, host2, bw, port, timeTotal):
# host2.cmd("iperf -s -u -p {} &".format(port))
print("Host {} to Host {} Bandwidth: {}".format(host1.name, host2.name, bw))
command = "iperf -c {} -u -p {} -t {} -b {}M &".format(host2.IP(), port, timeTotal, bw)
host1.cmd(command)
def min_to_sec(min):
return min * 60
def four_switches_network():
net = Mininet(topo=None,
build=False,
ipBase='10.0.0.0/8', link=TCLink)
queue_lenght = Config.queue_lenght
timeTotal = min_to_sec(Config.duration_iperf_per_load_level_minutes)
controllerIP = '127.0.0.1'
info('*** Adding controller\n')
c0 = net.addController(name='c0',
controller=RemoteController,
ip=controllerIP,
protocol='tcp',
port=6633)
info('*** Add switches\n')
s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
s3 = net.addSwitch('s3', cls=OVSKernelSwitch)
s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
info('*** Add hosts\n')
h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None)
h6 = net.addHost('h6', cls=Host, ip='10.0.0.6', defaultRoute=None)
info('*** Add links\n')
net.addLink(s1, s2, delay='10ms', use_tbf=True, bw=3, max_queue_size=queue_lenght, latency_ms=10000000,
burst=1000000)
net.addLink(s2, s3, delay='10ms', use_tbf=True, bw=3, max_queue_size=queue_lenght, latency_ms=10000000,
burst=1000000)
net.addLink(s1, s4, delay='14ms', use_tbf=True, bw=4, max_queue_size=queue_lenght, latency_ms=10000000,
burst=1000000)
net.addLink(s4, s3, delay='14ms', use_tbf=True, bw=4, max_queue_size=queue_lenght, latency_ms=10000000,
burst=1000000)
net.addLink(h1, s1)
net.addLink(h2, s1)
net.addLink(h3, s1)
net.addLink(h4, s3)
net.addLink(h5, s3)
net.addLink(h6, s3)
info('*** Starting network\n')
net.build()
info('*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info('*** Starting switches\n')
net.get('s1').start([c0])
net.get('s2').start([c0])
net.get('s3').start([c0])
net.get('s4').start([c0])
time.sleep(15)
print("Starting iperf ")
start_new_thread(startIperf, (h1, h4, 2.75, 5001, timeTotal))
start_new_thread(startIperf, (h2, h5, 1.75, 5001, timeTotal))
start_new_thread(startIperf, (h3, h6, 1.75, 5001, timeTotal))
time.sleep(timeTotal)
stop_controller()
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel('info')
four_switches_network()