-
Notifications
You must be signed in to change notification settings - Fork 45
/
Pkt_Topo_with_loop.py
62 lines (52 loc) · 1.77 KB
/
Pkt_Topo_with_loop.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
__author__ = 'Ehsan'
from mininet.node import CPULimitedHost
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.log import setLogLevel, info
from mininet.node import RemoteController
from mininet.cli import CLI
"""
Instructions to run the topo:
1. Go to directory where this fil is.
2. run: sudo -E python Pkt_Topo_with_loop.py
"""
class Simple3PktSwitch(Topo):
"""Simple topology example."""
def __init__(self, **opts):
"""Create custom topo."""
# Initialize topology
super(Simple3PktSwitch, self).__init__(**opts)
# Add hosts and switches
h1 = self.addHost('h1')
h2 = self.addHost('h2')
h3 = self.addHost('h3')
opts = dict(protocols='OpenFlow13')
# Adding switches
s1 = self.addSwitch('s1', dpid="0000000000000001", opts=opts)
s2 = self.addSwitch('s2', dpid="0000000000000002", opts=opts)
s3 = self.addSwitch('s3', dpid="0000000000000003", opts=opts)
# Add links
self.addLink(h1, s1)
self.addLink(h2, s2)
self.addLink(h3, s3)
self.addLink(s1, s2)
self.addLink(s1, s3)
self.addLink(s2, s3)
def installStaticFlows(net):
for sw in net.switches:
info('Adding flows to %s...' % sw.name)
sw.dpctl('add-flow', 'in_port=1,actions=output=2')
sw.dpctl('add-flow', 'in_port=2,actions=output=1')
info(sw.dpctl('dump-flows'))
def run():
c = RemoteController('c', '0.0.0.0', 6633)
net = Mininet(topo=Simple3PktSwitch(), host=CPULimitedHost, controller=None)
net.addController(c)
net.start()
# installStaticFlows( net )
CLI(net)
net.stop()
# if the script is run directly (sudo custom/optical.py):
if __name__ == '__main__':
setLogLevel('info')
run()