-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathOVSminiTopo.py
145 lines (121 loc) · 4.9 KB
/
OVSminiTopo.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
133
134
135
136
137
138
139
140
141
142
143
144
145
from mininet.net import Mininet
from mininet.node import RemoteController, Host, OVSKernelSwitch, Controller
from mininet.node import Switch, Link, Node, OVSController, DefaultController
from mininet.cli import CLI
from mininet.link import TCLink, Intf
from mininet.log import setLogLevel
import logging as log
from configs import *
import data_flows as df
def setup_topology():
"""
Builds the Mininet network, including all hosts, servers, switches, links.
"""
hosts = []
switches = []
links = []
log.info('Adding controller')
c0 = net.addController(name='c0'
#, controller=RemoteController,
#ip=CONTROLLER_IP,
#port=CONTROLLER_PORT,
)
# Adding a Standalone switch
#switches[0] = net.addSwitch('s21', cls=OVSKernelSwitch, failMode='standalone')
# Connecting the standalone switch to the interface on the machine/VM
#Intf('eth1', node=s21)
for switch in range(1,8):
sname = 's' + str(switch)
log.info("Adding switch %s" % sname)
s = net.addSwitch(sname)#, cls=OVSKernelSwitch)
switches.append(s)
# Connecting to VM interface
# Intf('eth2', node=switches[0])
for host in range(1,15):
hname = 'h' + str(host)
log.info("Adding host %s" % hname)
h = net.addHost(hname) #, ip=IP_PREFIX+str(host), mac=MAC_PREFIX+str(host))
hosts.append(h)
manual_links = [['s1', 'h1', 100], ['s1', 'h2', 100], ['s1', 's2', 50 ],
['s1', 's3', 50 ], #['s2', 's3', 50 ],
['s2', 's4', 50 ],
['s2', 's5', 50 ], ['s3', 's6', 50 ], ['s3', 's7', 50 ],
['s4', 'h3', 10 ], ['s4', 'h4', 10 ], ['s4', 'h5', 10 ],
['s5', 'h6', 10 ], ['s5', 'h7', 10 ], ['s5', 'h8', 10 ],
['s6', 'h9', 10 ], ['s6', 'h10',10 ], ['s6', 'h11',10 ],
['s7', 'h12',10 ], ['s7', 'h13',10 ], ['s7', 'h14',10 ],
]
for link in manual_links:
from_link = link[0]
to_link = link[1]
log.debug("Adding link from %s to %s" % (from_link, to_link))
bw = link[2]
'''
_bw = attributes.get('bw', 10) # in Mbps
_delay = '%fms' % attributes.get('latency', 10)
_jitter = '1ms'
_loss = error_rate
'''
l = net.addLink(link[0], link[1])
# l = net.addLink(net.get(from_link), net.get(to_link)
#, cls=TCLink, bw=bw
# , delay=_delay, jitter=_jitter, loss=_loss
# )
links.append(l)
# Link for internet
# l = net.addLink('h1', 's1')
# links.append(l)
'''
#Simple minimal topolgy code
#TODO: move to a different file
sname = 's' + '1'
log.info("Adding switch %s" % sname)
s = net.addSwitch(sname, cls=OVSKernelSwitch)
# for host in range(1,2):
# hname = 'h' + str(host)
# log.info("Adding host %s" % hname)
h1 = net.addHost('h1')
h = net.addHost('h2')
l = net.addLink('s1', 'h1',
cls=TCLink, bw=10
# , delay=_delay, jitter=_jitter, loss=_loss
)
l1 = net.addLink('s1', 'h2',
cls=TCLink, bw=10
# , delay=10ms, jitter=1ms, loss=error_rate
)
'''
# Build the network
log.info('Building network')
net.build()
# Start the network
log.info('Starting network')
net.start()
# info('*** Configure h1\'s controller communication interface\n')
# hosts[0].cmd('ifconfig h1-eth1 hw ether 00:00:00:00:01:11')
# info('*** Configure h1\'s IP address\n')
# hosts[0].cmd('dhclient h1-eth1')
#net.pingAll()
#Starting the internet and stream traffic
df.setup_traffic_generators(net)
#Popen("killall -9 top bwm-ng", shell=True).wait()
# Drop the user in to a CLI so user can run commands.
CLI( net )
# After the user exits the CLI, shutdown the network.
log.info('Stopping network')
net.stop()
if __name__ == '__main__':
# This runs if this file is executed directly
net = Mininet(topo=None,
build=False,
ipBase='10.0.0.0/8',
autoSetMacs=True,
)
setLogLevel( 'info' )
setup_topology()
#generators = _get_mininet_nodes(12)
#print(generators)
# Allows the file to be imported using `mn --custom <filename> --topo minimal`
# topos = {
# 'minimal': MinimalTopo
# }