fork download
  1. #!/user/bin/python3
  2.  
  3. import sys
  4. from mininet.cli import CLI
  5. from mininet.log import setLogLevel
  6. from mininet.net import Mininet
  7. from mininet.topo import Topo
  8. from mininet.node import RemoteController, OVSSwitch
  9. from mininet.clean import Cleanup
  10. from mininet.link import TCLink
  11.  
  12. from time import sleep
  13. import json
  14. import requests
  15.  
  16. class test_topo( Topo ):
  17. def build(self):
  18. s1 = self.addSwitch('s1', port=6653)
  19. s2 = self.addSwitch("s2", port=6653)
  20. for i in range(0, 10):
  21. name = 'h' + str(i)
  22. h_buf = self.addHost(name)
  23. self.addLink(name, 's1')
  24.  
  25. #for i in range(5, 10):
  26. #name = "h" + str(i)
  27. #h_buf = self.addHost(name)
  28. #self.addLink(name, "s2")
  29.  
  30. #self.addLink("s2", "s1", cls = TCLink, bw = 500)
  31. #print("bandwidth: {bandwidth}".format(bandwidth = int(sys.argv[2])))
  32.  
  33. def run_test_topo():
  34. "Bootstrap a Mininet network using the Minimal Topology"
  35.  
  36. # Cleanup.cleanup()
  37.  
  38. # Create an instance of our topology
  39. topo = test_topo()
  40.  
  41. # Create a network based on the topology using OVS and controlled by
  42. # a remote controller.
  43. controller_ip = '0.0.0.0'
  44. controller_port = 6653
  45.  
  46. net = Mininet(
  47. topo=topo, xterms=False,
  48. controller=lambda name: RemoteController( name, ip=controller_ip, port=controller_port),
  49. switch=OVSSwitch,
  50. autoSetMacs=True )
  51.  
  52. # Actually start the network
  53. net.start()
  54.  
  55. print("loading the net, 30 sec count down...")
  56. sleep(5)
  57. print("net is completed")
  58.  
  59. s1 = net.get('s1')
  60. #s2 = net.get('s2')
  61. s1.cmd('ovs-vsctl set bridge s1 protocols=OpenFlow10,OpenFlow11,OpenFlow12,OpenFlow13,OpenFlow14,OpenFlow15')
  62. #s1.cmd('ovs-vsctl set bridge s1 datapath_type=netdev')
  63. s1.cmd('ovs-vsctl meter-features s1 -O OpenFlow13')
  64. #s2.cmd('ovs-vsctl set bridge s2 protocols=OpenFlow10,OpenFlow11,OpenFlow12,OpenFlow13,OpenFlow14,OpenFlow15')
  65. #s2.cmd('ovs-vsctl set bridge s2 datapath_type=netdev')
  66. #s2.cmd('ovs-vsctl meter-features s2 -O OpenFlow13')
  67. sleep(5)
  68.  
  69. print("conducting ping and starting up all servers")
  70. #cntr = 0
  71. for i in range(0, 5):
  72. #if cntr == 20:
  73. # cntr = 0
  74. #print("wait...")
  75. #sleep(30)
  76. #print("end...")
  77. time = 15
  78. name_ser = "h" + str(i)
  79. name_cli = "h" + str(i + 5)
  80. host_buf = net.get(name_ser)
  81. cli_buf = net.get(name_cli)
  82. sampling_time = 2
  83. print(i+1)
  84. host_buf.cmd("ping 10.0.0.{host_name})".format(host_name = i + 5 + 1 ))
  85. #host_buf.cmd("iperf3 -s -i {sampling_time} -J > ./log_dir/{log_name}.txt &".format(sampling_time = sampling_time, log_name = name_ser))
  86. host_buf.cmd("iperf3 -s -i {sampling_time} -J > ./log_dir_reno/normal_seed_{log_name}.txt &".format(sampling_time = sampling_time,log_name = name_ser))
  87. sleep(5)
  88. ip = "10.0.0" + str(i+1)
  89. cli_buf.cmd("iperf3 -c {ip} -t {time} &".format(ip = ip, time = time))
  90. #cntr = cntr + 1
  91. print("ping is completed")
  92.  
  93. print("let the packets fly...")
  94. #sleep(15)
  95.  
  96. #print("seed: {argv}".format(argv = sys.argv[1]))
  97.  
  98.  
  99.  
  100. #cntr = 0
  101. #flow_block = 20
  102. #print("first round start")
  103. # for i in range(0, 5):
  104. # if cntr == 20:
  105. # cntr = 0
  106. # time = time + 20
  107.  
  108. #host_buf = net.get("h" + str(i))
  109. #print(i)
  110. #ip = "10.0.0" + str((i + 5) )
  111. #host_buf.cmd("iperf3 -c {ip} -t {time} &".format(ip = ip, time = time))
  112. #cntr = cntr + 1
  113. #sleep(5)
  114.  
  115.  
  116. #print("first round end")
  117.  
  118. #start = end
  119. #end = start + flow_block
  120. #time = 100
  121. #for i in range(0, 10):
  122. # print(start, " ~ ", end)
  123. # for j in range(start, end):
  124. # host_buf = net.get("h" + str(j))
  125. # ip = "10.0." + str((int)((j + 120 + 1) / 256)) + "." + str((j + 120 + 1) % 256)
  126. #host_buf.cmd("iperf3 -c {ip} -t {time} &".format(ip = ip, time = time))
  127.  
  128. # start = end
  129. #end = end + flow_block
  130.  
  131. #if start >= 120:
  132. # start = start % 120
  133.  
  134. # if end > 120:
  135. # end = end % 120
  136.  
  137. # sleep(20)
  138.  
  139. #CLI(net)
  140. sleep(60)
  141. net.stop()
  142. print("Finish")
  143. CLI.do_quit
  144.  
  145. if __name__ == '__main__':
  146. run_test_topo()
  147. sleep(120)
  148.  
Runtime error #stdin #stdout #stderr 0.15s 23444KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 4, in <module>
ModuleNotFoundError: No module named 'mininet'