-
Notifications
You must be signed in to change notification settings - Fork 0
/
topo_nat.py
executable file
·105 lines (84 loc) · 3.32 KB
/
topo_nat.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
#!/usr/bin/python
"""
Copyright (C) 2015 Manuel Sanchez Lopez
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have getTransmitErrorCountd a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSSwitch, Controller, RemoteController
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info, lg
from mininet.link import TCLink, Intf
from subprocess import call
from mininet.nodelib import NAT
from mininet.topolib import TreeNet
"""
__________
/ \
h1 nat0-----| INTERNET |
| | \__________/
s1-----
______|_______
| |
s2 s3
| |
h2 h3
"""
def myNetwork():
net = Mininet( topo=None,
listenPort=6633,
build=False,
ipBase='10.0.0.0/8',
link=TCLink,
)
info( '*** Adding controller\n' )
c0=net.addController(name='c0',
controller=RemoteController,
protocols='OpenFlow13',
ip='127.0.0.1'
)
info( '*** Add switches\n')
s1 = net.addSwitch('s3', cls=OVSSwitch, mac='00:00:00:00:00:06', protocols='OpenFlow13')
s2 = net.addSwitch('s2', cls=OVSSwitch, mac='00:00:00:00:00:05', protocols='OpenFlow13')
s3 = net.addSwitch('s1', cls=OVSSwitch, mac='00:00:00:00:00:04', protocols='OpenFlow13')
info( '*** Add hosts\n')
h1 = net.addHost('h3', cls=Host, ip='10.0.0.3', mac='00:00:00:00:00:03', defaultRoute='via 10.0.0.4')
h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', mac='00:00:00:00:00:02', defaultRoute='via 10.0.0.4')
h3 = net.addHost('h1', cls=Host, ip='10.0.0.1', mac='00:00:00:00:00:01', defaultRoute='via 10.0.0.4')
# La ruta por defecto de los host es la de NAT (10.0.0.4 en este caso)
info('*** Add NAT\n')
net.addNAT().configDefault()
info( '*** Add links\n')
net.addLink(s1, s2, bw=10, delay='0.2ms')
net.addLink(s1, s3, bw=10, delay='0.2ms')
#net.addLink(s2, s1, bw=10, delay='0.2ms') #Esta linea con este controlador provoca errores.
net.addLink(s1, h1, bw=10, delay='0.2ms')
net.addLink(s2, h2, bw=10, delay='0.2ms')
net.addLink(s3, h3, bw=10, delay='0.2ms')
info( '*** Starting network\n')
net.build()
net.start()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches\n')
net.get('s3').start([c0])
net.get('s2').start([c0])
net.get('s1').start([c0])
info( '*** Post configure switches and hosts\n')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
myNetwork()