fattree.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/usr/bin/python
  2. from mininet.net import Mininet
  3. from mininet.node import Controller, RemoteController, OVSController
  4. from mininet.node import CPULimitedHost, Host, Node
  5. from mininet.node import OVSKernelSwitch, UserSwitch
  6. from mininet.node import IVSSwitch
  7. from mininet.cli import CLI
  8. from mininet.log import setLogLevel, info
  9. from mininet.link import TCLink, Intf
  10. from subprocess import call
  11. def myNetwork():
  12. net = Mininet( topo=None,
  13. build=False,
  14. ipBase='10.0.0.0/8')
  15. info( '*** Adding controller\n' )
  16. c0=net.addController(name='c0',
  17. controller=RemoteController,
  18. ip='127.0.0.1',
  19. protocol='tcp',
  20. port=6633)
  21. info( '*** Add switches\n')
  22. s19 = net.addSwitch('s19', cls=OVSKernelSwitch)
  23. s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
  24. s8 = net.addSwitch('s8', cls=OVSKernelSwitch)
  25. s14 = net.addSwitch('s14', cls=OVSKernelSwitch)
  26. s3 = net.addSwitch('s3', cls=OVSKernelSwitch)
  27. s20 = net.addSwitch('s20', cls=OVSKernelSwitch)
  28. s9 = net.addSwitch('s9', cls=OVSKernelSwitch)
  29. s15 = net.addSwitch('s15', cls=OVSKernelSwitch)
  30. s4 = net.addSwitch('s4', cls=OVSKernelSwitch)
  31. s10 = net.addSwitch('s10', cls=OVSKernelSwitch)
  32. s16 = net.addSwitch('s16', cls=OVSKernelSwitch)
  33. s5 = net.addSwitch('s5', cls=OVSKernelSwitch)
  34. s11 = net.addSwitch('s11', cls=OVSKernelSwitch)
  35. s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
  36. s6 = net.addSwitch('s6', cls=OVSKernelSwitch)
  37. s17 = net.addSwitch('s17', cls=OVSKernelSwitch)
  38. s12 = net.addSwitch('s12', cls=OVSKernelSwitch)
  39. s18 = net.addSwitch('s18', cls=OVSKernelSwitch)
  40. s7 = net.addSwitch('s7', cls=OVSKernelSwitch)
  41. s13 = net.addSwitch('s13', cls=OVSKernelSwitch)
  42. info( '*** Add hosts\n')
  43. h14 = net.addHost('h14', cls=Host, ip='10.0.0.14', defaultRoute=None)
  44. h15 = net.addHost('h15', cls=Host, ip='10.0.0.15', defaultRoute=None)
  45. h6 = net.addHost('h6', cls=Host, ip='10.0.0.6', defaultRoute=None)
  46. h7 = net.addHost('h7', cls=Host, ip='10.0.0.7', defaultRoute=None)
  47. h16 = net.addHost('h16', cls=Host, ip='10.0.0.16', defaultRoute=None)
  48. h10 = net.addHost('h10', cls=Host, ip='10.0.0.10', defaultRoute=None)
  49. h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
  50. h8 = net.addHost('h8', cls=Host, ip='10.0.0.8', defaultRoute=None)
  51. h9 = net.addHost('h9', cls=Host, ip='10.0.0.9', defaultRoute=None)
  52. h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None)
  53. h11 = net.addHost('h11', cls=Host, ip='10.0.0.11', defaultRoute=None)
  54. h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
  55. h12 = net.addHost('h12', cls=Host, ip='10.0.0.12', defaultRoute=None)
  56. h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
  57. h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
  58. h13 = net.addHost('h13', cls=Host, ip='10.0.0.13', defaultRoute=None)
  59. info( '*** Add links\n')
  60. net.addLink(s1, s5)
  61. net.addLink(s1, s7)
  62. net.addLink(s1, s9)
  63. net.addLink(s1, s11)
  64. net.addLink(s2, s5)
  65. net.addLink(s2, s7)
  66. net.addLink(s2, s9)
  67. net.addLink(s2, s11)
  68. net.addLink(s3, s6)
  69. net.addLink(s3, s8)
  70. net.addLink(s3, s10)
  71. net.addLink(s3, s12)
  72. net.addLink(s4, s12)
  73. net.addLink(s4, s10)
  74. net.addLink(s4, s8)
  75. net.addLink(s4, s6)
  76. net.addLink(s5, s13)
  77. net.addLink(s6, s14)
  78. net.addLink(s14, s5)
  79. net.addLink(s13, s6)
  80. net.addLink(s7, s16)
  81. net.addLink(s8, s15)
  82. net.addLink(s7, s15)
  83. net.addLink(s8, s16)
  84. net.addLink(s9, s17)
  85. net.addLink(s10, s18)
  86. net.addLink(s9, s18)
  87. net.addLink(s17, s10)
  88. net.addLink(s11, s19)
  89. net.addLink(s12, s20)
  90. net.addLink(s11, s20)
  91. net.addLink(s19, s12)
  92. net.addLink(s13, h1)
  93. net.addLink(s13, h2)
  94. net.addLink(s14, h3)
  95. net.addLink(s14, h4)
  96. net.addLink(s15, h5)
  97. net.addLink(s15, h6)
  98. net.addLink(s16, h7)
  99. net.addLink(s16, h8)
  100. net.addLink(s17, h9)
  101. net.addLink(s17, h10)
  102. net.addLink(s18, h11)
  103. net.addLink(s18, h12)
  104. net.addLink(s19, h13)
  105. net.addLink(s19, h14)
  106. net.addLink(s20, h15)
  107. net.addLink(s20, h16)
  108. info( '*** Starting network\n')
  109. net.build()
  110. info( '*** Starting controllers\n')
  111. for controller in net.controllers:
  112. controller.start()
  113. info( '*** Starting switches\n')
  114. net.get('s19').start([c0])
  115. net.get('s2').start([c0])
  116. net.get('s8').start([c0])
  117. net.get('s14').start([c0])
  118. net.get('s3').start([c0])
  119. net.get('s20').start([c0])
  120. net.get('s9').start([c0])
  121. net.get('s15').start([c0])
  122. net.get('s4').start([c0])
  123. net.get('s10').start([c0])
  124. net.get('s16').start([c0])
  125. net.get('s5').start([c0])
  126. net.get('s11').start([c0])
  127. net.get('s1').start([c0])
  128. net.get('s6').start([c0])
  129. net.get('s17').start([c0])
  130. net.get('s12').start([c0])
  131. net.get('s18').start([c0])
  132. net.get('s7').start([c0])
  133. net.get('s13').start([c0])
  134. info( '*** Post configure switches and hosts\n')
  135. CLI(net)
  136. net.stop()
  137. if __name__ == '__main__':
  138. setLogLevel( 'info' )
  139. myNetwork()