fat_tree_topo.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/env python
  2. from mininet.topo import Topo
  3. from mininet.util import dumpNodeConnections
  4. from mininet.net import Mininet
  5. from mininet.node import OVSController
  6. from mininet.log import setLogLevel
  7. from subprocess import call
  8. class fatTreeTopo(Topo):
  9. def __init__(self):
  10. super(fatTreeTopo, self).__init__()
  11. # create switches and add them to lists for reference
  12. # note: switch/host number is list index offset by 1
  13. core = [self.addSwitch('c0'),
  14. self.addSwitch('c1'),
  15. self.addSwitch('c2'),
  16. self.addSwitch('c3')]
  17. aggregations = [
  18. [self.addSwitch('a01'),
  19. self.addSwitch('a02')],
  20. [self.addSwitch('a11'),
  21. self.addSwitch('a12')],
  22. [self.addSwitch('a21'),
  23. self.addSwitch('a22')],
  24. [self.addSwitch('a31'),
  25. self.addSwitch('a32')]]
  26. edges = [
  27. self.addSwitch('e1'),
  28. self.addSwitch('e2'),
  29. self.addSwitch('e3'),
  30. self.addSwitch('e4')
  31. ]
  32. hosts = []
  33. for i in range(1,9):
  34. hosts.append(self.addHost('h' + str(i)))
  35. # create links between edge switches and hosts
  36. for i in range(0,4):
  37. self.addLink(edges[i], hosts[2*i])
  38. self.addLink(edges[i], hosts[2*i+1])
  39. # create links between aggregation switches and edge switches
  40. for i in range(0,2):
  41. self.addLink(aggregations[i], edges[2*i])
  42. self.addLink(aggregations[i], edges[2*i+1])
  43. # create links between core switch and aggregation switches
  44. self.addLink(core, aggregations[0])
  45. self.addLink(core, aggregations[1])
  46. def speed2int(s):
  47. scale = {
  48. 'gbits/sec': 1e9,
  49. 'mbits/sec': 1e6,
  50. 'kbits/sec': 1e3,
  51. 'bits/sec': 1
  52. }
  53. l = s.split(' ')
  54. return int(float(l[0]) * scale[l[1].lower()])
  55. def speed2str(n):
  56. if n >= 1e9:
  57. return str(float(n) / 1e9) + ' Gbps'
  58. if n >= 1e6:
  59. return str(float(n) / 1e6) + ' Mbps'
  60. if n >= 1e3:
  61. return str(float(n) / 1e3) + ' Kbps'
  62. return str(n) + ' bps'
  63. # stop existing OVS controllers
  64. call(["pkill", "ovs-controller"])
  65. # verbose output for mininet
  66. setLogLevel('info')
  67. topo = fatTreeTopo()
  68. net = Mininet(topo=topo, controller=OVSController)
  69. net.start()
  70. print "Node connections dump:"
  71. dumpNodeConnections(net.hosts)
  72. print "Connectivity (ping) test:"
  73. net.pingAll()
  74. def test_speed(host1_no, host2_no):
  75. server_speed, client_speed = net.iperf((
  76. net.get('h' + str(host1_no)),
  77. net.get('h' + str(host2_no))
  78. ))
  79. return speed2int(server_speed)
  80. print "##### Throughput in same rack:"
  81. speeds = [
  82. test_speed(1,2),
  83. test_speed(3,4),
  84. test_speed(5,6),
  85. test_speed(7,8)
  86. ]
  87. print "##### Average throughput: " + speed2str(sum(speeds) / len(speeds))
  88. print ""
  89. print "##### Throughput in different racks but in same aggregation switch:"
  90. speeds = [
  91. test_speed(1,3),
  92. test_speed(2,4),
  93. test_speed(5,7),
  94. test_speed(6,8)
  95. ]
  96. print "##### Average throughput: " + speed2str(sum(speeds) / len(speeds))
  97. print ""
  98. print "##### Throughput in different racks and different aggregation switches:"
  99. speeds = [
  100. test_speed(1,5),
  101. test_speed(2,6),
  102. test_speed(3,7),
  103. test_speed(4,8)
  104. ]
  105. print "##### Average throughput: " + speed2str(sum(speeds) / len(speeds))
  106. print ""
  107. net.stop()