| 79 | |
| 80 | == Come rendere `h4` raggiungibile da `h1` |
| 81 | |
| 82 | {{{#!sh |
| 83 | from mininet.topo import Topo |
| 84 | from mininet.net import Mininet |
| 85 | from mininet.link import TCLink |
| 86 | from mininet.cli import CLI |
| 87 | |
| 88 | class MyTopo(Topo): |
| 89 | def __init__(self): |
| 90 | Topo.__init__(self) |
| 91 | s1 = self.addSwitch('s1') |
| 92 | s2 = self.addSwitch('s2') |
| 93 | |
| 94 | h = [] |
| 95 | for i in xrange(4): |
| 96 | h.append(self.addHost('h' + str(i+1))) |
| 97 | |
| 98 | self.addLink(s1, h[0]) |
| 99 | self.addLink(s1, h[1]) |
| 100 | self.addLink(s2, h[2]) |
| 101 | self.addLink(s2, h[3]) |
| 102 | self.addLink(s1, s2, bw=10) |
| 103 | |
| 104 | |
| 105 | if __name__ == '__main__': |
| 106 | net = Mininet(topo=MyTopo(), link=TCLink) |
| 107 | h1, h2 = net.get('h1','h2') |
| 108 | h1.setIP('192.168.1.10/24') |
| 109 | h2.setIP('192.168.1.20/24') |
| 110 | |
| 111 | h3, h4 = net.get('h3','h4') |
| 112 | h3.setIP('192.168.2.100/24') |
| 113 | h4.setIP('192.168.2.200/24') |
| 114 | |
| 115 | # essendo i due switch direttamente collegati |
| 116 | # e` sufficiente aggiungere le rotte di default |
| 117 | for h in net.hosts: |
| 118 | h.setDefaultRoute(intf=h.intf()) |
| 119 | |
| 120 | |
| 121 | net.start() |
| 122 | CLI(net) |
| 123 | net.stop() |
| 124 | }}} |
| 125 | |