2019-06-06 23:40:50 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- encoding: utf-8 -*-
|
2019-06-05 07:17:36 +00:00
|
|
|
|
|
|
|
from mininet.net import Mininet
|
2019-06-06 23:40:50 +00:00
|
|
|
from mininet.topo import Topo
|
2019-06-05 07:17:36 +00:00
|
|
|
from mininet.node import Controller, RemoteController, OVSController
|
|
|
|
from mininet.node import CPULimitedHost, Host, Node
|
|
|
|
from mininet.node import OVSKernelSwitch, UserSwitch
|
|
|
|
from mininet.node import IVSSwitch
|
|
|
|
from mininet.cli import CLI
|
|
|
|
from mininet.log import setLogLevel, info
|
|
|
|
from mininet.link import TCLink, Intf
|
|
|
|
from subprocess import call
|
|
|
|
|
2019-06-06 23:40:50 +00:00
|
|
|
|
|
|
|
def _init(topo):
|
|
|
|
info('*** Adding switches\n')
|
|
|
|
s1 = topo.addSwitch('s1', cls=OVSKernelSwitch)
|
|
|
|
s2 = topo.addSwitch('s2', cls=OVSKernelSwitch)
|
|
|
|
s3 = topo.addSwitch('s3', cls=OVSKernelSwitch)
|
|
|
|
|
|
|
|
info('*** Adding hosts\n')
|
|
|
|
h1 = topo.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
|
|
|
|
h2 = topo.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
|
|
|
|
h3 = topo.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
|
|
|
|
h4 = topo.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
|
|
|
|
|
|
|
|
info('*** Adding links\n')
|
2019-06-11 22:32:54 +00:00
|
|
|
topo.addLink(s1, s3, 1, 1, cls=TCLink, bw=0.7)
|
|
|
|
topo.addLink(s3, s2, 2, 2, cls=TCLink, bw=0.7)
|
|
|
|
topo.addLink(s1, s2, 3, 3, cls=TCLink, bw=1)
|
2019-06-11 01:19:33 +00:00
|
|
|
topo.addLink(h1, s1, 4, 4, cls=TCLink, bw=100)
|
|
|
|
topo.addLink(s1, h2, 5, 5, cls=TCLink, bw=100)
|
|
|
|
topo.addLink(s2, h3, 6, 6, cls=TCLink, bw=100)
|
|
|
|
topo.addLink(s2, h4, 7, 7, cls=TCLink, bw=100)
|
2019-06-06 23:40:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MyTopo(Topo):
|
|
|
|
def __init__(self):
|
|
|
|
Topo.__init__(self)
|
|
|
|
_init(self)
|
|
|
|
|
|
|
|
|
|
|
|
def myNetwork(standalone = False):
|
|
|
|
net = Mininet(
|
|
|
|
topo=None,
|
|
|
|
build=False,
|
|
|
|
ipBase="10.0.0.0/8"
|
|
|
|
)
|
|
|
|
|
|
|
|
info('*** Adding controller\n')
|
|
|
|
c0=net.addController(
|
|
|
|
name='c0',
|
|
|
|
controller=RemoteController,
|
|
|
|
ip='127.0.0.1',
|
|
|
|
protocol='tcp',
|
|
|
|
port=6633
|
|
|
|
)
|
|
|
|
|
|
|
|
_init(net)
|
|
|
|
|
|
|
|
info('*** Starting network\n')
|
2019-06-05 07:17:36 +00:00
|
|
|
net.build()
|
2019-06-06 23:40:50 +00:00
|
|
|
|
|
|
|
info('*** Starting controllers\n')
|
2019-06-05 07:17:36 +00:00
|
|
|
for controller in net.controllers:
|
|
|
|
controller.start()
|
|
|
|
|
2019-06-06 23:40:50 +00:00
|
|
|
info('*** Starting switches\n')
|
2019-06-05 07:17:36 +00:00
|
|
|
net.get('s1').start([c0])
|
|
|
|
net.get('s2').start([c0])
|
|
|
|
net.get('s3').start([c0])
|
|
|
|
|
2019-06-06 23:40:50 +00:00
|
|
|
if standalone:
|
|
|
|
info('*** Post configure switches and hosts\n')
|
|
|
|
CLI(net)
|
|
|
|
net.stop()
|
|
|
|
|
|
|
|
return net
|
|
|
|
|
2019-06-05 07:17:36 +00:00
|
|
|
|
2019-06-06 23:40:50 +00:00
|
|
|
topos = {'mytopo': MyTopo}
|
2019-06-05 07:17:36 +00:00
|
|
|
|
|
|
|
|
2019-06-06 23:40:50 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
setLogLevel("info")
|
|
|
|
myNetwork(True)
|