daily pastebin goal
80%
SHARE
TWEET

topology.py

a guest Sep 6th, 2017 196 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. from mininet.net import Mininet
  4. from mininet.link import TCLink
  5. from mininet.node import Controller, RemoteController, OVSController
  6. from mininet.node import CPULimitedHost, Host, Node
  7. from mininet.node import OVSKernelSwitch, UserSwitch
  8. from mininet.node import IVSSwitch
  9. from mininet.cli import CLI
  10. from mininet.log import setLogLevel, info
  11. from mininet.link import TCLink, Intf
  12. from subprocess import call
  13.  
  14. def myNetwork():
  15.     net = Mininet( topo=None, link=TCLink, build=False)
  16.  
  17.     info( '*** Adding controller\n' )
  18.  
  19.     c1 = net.addController(name='c1', controller=RemoteController, ip='10.12.99.3', protocol='tcp', port=6633)
  20.  
  21.     info( '*** Add switches\n')
  22.  
  23.     for i in range(0, 10) :
  24.         net.addSwitch('s' + str(i+1), cls=OVSKernelSwitch, protocols='OpenFlow13');
  25.  
  26.     info( '*** Add hosts\n')
  27.  
  28.     net.addHost('h1', cls=Host, ip='10.0.1.1', defaultRoute=None);
  29.     net.addHost('h2', cls=Host, ip='10.0.1.2', defaultRoute=None);
  30.     net.addHost('h3', cls=Host, ip='10.0.1.3', defaultRoute=None);
  31.     net.addHost('h4', cls=Host, ip='10.0.1.4', defaultRoute=None);
  32.     net.addHost('h5', cls=Host, ip='10.0.2.1', defaultRoute=None);
  33.     net.addHost('h6', cls=Host, ip='10.0.2.2', defaultRoute=None);
  34.     net.addHost('h7', cls=Host, ip='10.0.2.3', defaultRoute=None);
  35.     net.addHost('h8', cls=Host, ip='10.0.2.4', defaultRoute=None);
  36.  
  37.     info( '*** Add links\n')
  38.  
  39.     # 3-LAYER TOPOLOGY
  40.     linkopts = dict(bw=10, delay='5ms', jitter='2ms');
  41.    
  42.     #     < H >         <-- external hosts
  43.     #       G           <-- Pseudo gateway switch
  44.     #       |
  45.     #     L-B         <-- load balancer
  46.     #    / / \ \
  47.     #  /  /   \  \    
  48.     #  O  O   O  O      <-- out switches
  49.     #  <full-mesh>
  50.     #  E  E   E  E      <-- exterior-facing switches
  51.     #  |  |   |  |
  52.     #  H  H   H  H      <-- internal hosts
  53.    
  54.     # External hosts & the pseudo gateway
  55.     net.addLink(net.switches[0], net.hosts[0], **linkopts);
  56.     net.addLink(net.switches[0], net.hosts[1], **linkopts);
  57.     net.addLink(net.switches[0], net.hosts[2], **linkopts);
  58.     net.addLink(net.switches[0], net.hosts[3], **linkopts);
  59.    
  60.     # Pseudo gateway and the hash load balancer
  61.     net.addLink(net.switches[1], net.switches[0], **linkopts);
  62.    
  63.     # The load balancer & the out switches
  64.     net.addLink(net.switches[1], net.switches[2], **linkopts);
  65.     net.addLink(net.switches[1], net.switches[3], **linkopts);
  66.     net.addLink(net.switches[1], net.switches[4], **linkopts);
  67.     net.addLink(net.switches[1], net.switches[5], **linkopts);
  68.    
  69.     # The out switches & the exterior-facing switches
  70.     net.addLink(net.switches[2], net.switches[6], **linkopts);
  71.     net.addLink(net.switches[2], net.switches[7], **linkopts);
  72.     net.addLink(net.switches[2], net.switches[8], **linkopts);
  73.     net.addLink(net.switches[2], net.switches[9], **linkopts);
  74.     net.addLink(net.switches[3], net.switches[6], **linkopts);
  75.     net.addLink(net.switches[3], net.switches[7], **linkopts);
  76.     net.addLink(net.switches[3], net.switches[8], **linkopts);
  77.     net.addLink(net.switches[3], net.switches[9], **linkopts);
  78.     net.addLink(net.switches[4], net.switches[6], **linkopts);
  79.     net.addLink(net.switches[4], net.switches[7], **linkopts);
  80.     net.addLink(net.switches[4], net.switches[8], **linkopts);
  81.     net.addLink(net.switches[4], net.switches[9], **linkopts);
  82.     net.addLink(net.switches[5], net.switches[6], **linkopts);
  83.     net.addLink(net.switches[5], net.switches[7], **linkopts);
  84.     net.addLink(net.switches[5], net.switches[8], **linkopts);
  85.     net.addLink(net.switches[5], net.switches[9], **linkopts);
  86.    
  87.     # The hosts
  88.     net.addLink(net.switches[6], net.hosts[4], **linkopts);
  89.     net.addLink(net.switches[7], net.hosts[5], **linkopts);
  90.     net.addLink(net.switches[8], net.hosts[6], **linkopts);
  91.     net.addLink(net.switches[9], net.hosts[7], **linkopts);
  92.  
  93.     info( '*** Starting network\n')
  94.  
  95.     net.build()
  96.  
  97.     info( '*** Starting controllers\n')
  98.  
  99.     for controller in net.controllers:
  100.         controller.start()
  101.    
  102.     info( '*** Starting switches\n')
  103.  
  104.     for switch in net.switches:
  105.         switch.start([c1]);
  106.    
  107.     net.hosts[0].cmd("ping h2");
  108.    
  109.     CLI(net)
  110.  
  111.     net.stop()
  112.  
  113. if __name__ == '__main__':
  114.     setLogLevel( 'info' )
  115.     myNetwork()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top