Advertisement
enr1g

Untitled

Mar 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. #!/usr/bin/python                                                                            
  2.  
  3. from functools import partial
  4. from mininet.node import RemoteController, Switch
  5. from mininet.cli import CLI
  6. from mininet.link import Intf
  7.  
  8. from mininet.topo import Topo
  9. from mininet.net import Mininet
  10. from mininet.util import dumpNodeConnections
  11. from mininet.log import setLogLevel
  12.  
  13.  
  14. class LinearSwitch(Topo):
  15.     "Single switch connected to n hosts."
  16.     def build(self, n=3):
  17.         for i in range(n):
  18.             self.addSwitch('s%d' % (i + 1))
  19.  
  20.         for i in range(n - 1):
  21.             self.addLink('s%d' % (i + 1), 's%d' % (i + 2))
  22.  
  23.         # Intf('eth2', node=Switch('s1'))
  24.         # Intf('eth3', node=Switch('s%d' % n))
  25.  
  26. def simpleTest():
  27.     "Create and test a simple network"
  28.     topo = LinearSwitch(n=3)
  29.     net = Mininet(topo=topo, controller=partial(RemoteController, ip="172.18.0.3", port=6633))
  30.     Intf('eth2', net.switches[0])
  31.     Intf('eth3', net.switches[-1])
  32.     net.start()
  33.     print "Dumping host connections"
  34.     dumpNodeConnections(net.hosts)
  35.     # print "Testing network connectivity"
  36.     # net.pingAll()
  37.     CLI(net)
  38.     net.stop()
  39.  
  40. if __name__ == '__main__':
  41.     # Tell mininet to print useful information
  42.     setLogLevel('info')
  43.     simpleTest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement