creator.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #!/usr/bin/python
  2. secondaryRouters = 4
  3. hostsPerRouter = 4
  4. ###
  5. # creation of routing file for main router
  6. ###
  7. mainRouterFile = open("mainRouter.mrt", "w")
  8. mainRouterFile.write("ifconfig:\n")
  9. for i in range(0,secondaryRouters):
  10. mainRouterFile.write("name: eth%i encap: Ethernet inet_addr: 192.%i.0.1\n" % (i, i))
  11. mainRouterFile.write("MTU: 1500 Metric: 1 MULTICAST\n")
  12. mainRouterFile.write("ifconfigend.\n")
  13. mainRouterFile.write("route:\n")
  14. for i in range(0, secondaryRouters):
  15. mainRouterFile.write("192.%i.0.0 192.%i.0.2 255.255.0.0 G 0 eth%i\n" % (i, i, i))
  16. for i in range(0, secondaryRouters):
  17. mainRouterFile.write("225.0.0.1 192.%i.%i.2 255.255.255.255 G 0 eth%i\n" % (i, i, i))
  18. mainRouterFile.write("routeend.\n")
  19. mainRouterFile.close()
  20. ###
  21. # creation of routing files for secondary routers
  22. # creation of routing files for hosts
  23. ###
  24. for i in range(0, secondaryRouters):
  25. secondaryRouterFile = open("secondaryRouter%i.mrt" % i, "w")
  26. secondaryRouterFile.write("ifconfig:\n")
  27. secondaryRouterFile.write("name: eth0 encap: Ethernet inet_addr: 192.%i.0.2\n" % (i))
  28. secondaryRouterFile.write("MTU: 1500 Metric: 1 MULTICAST\n")
  29. for j in range(0, hostsPerRouter):
  30. secondaryRouterFile.write("name: eth%i encap: Ethernet inet_addr: 192.%i.%i.1\n" % (j + 1, i, j + 1))
  31. secondaryRouterFile.write("MTU: 1500 Metric: 1 MULTICAST\n")
  32. secondaryRouterFile.write("ifconfigend.\n")
  33. secondaryRouterFile.write("route:\n")
  34. for j in range(0, hostsPerRouter):
  35. secondaryRouterFile.write("192.%i.%i.2 * 255.255.255.255 H 0 eth%i\n" % (i, j + 1, j + 1))
  36. for j in range(0, hostsPerRouter):
  37. secondaryRouterFile.write("225.0.0.1 * 255.255.255.255 H 0 eth%i\n" % (j + 1))
  38. secondaryRouterFile.write("225.0.0.1 192.%i.0.1 255.255.255.255 G 0 eth0\n" % (i))
  39. secondaryRouterFile.write("default: 192.%i.0.1 255.255.255.255 G 0 eth0\n" % (i))
  40. secondaryRouterFile.write("routeend.\n")
  41. secondaryRouterFile.close()
  42. for j in range(0, hostsPerRouter):
  43. hostRoutingFile = open("host%i-%i.mrt" % (i, j), "w")
  44. hostRoutingFile.write("ifconfig:\n")
  45. hostRoutingFile.write("name: eth0 encap: Ethernet inet_addr: 192.%i.%i.2\n" % (i, j + 1))
  46. hostRoutingFile.write("MTU: 1500 Metric: 1 MULTICAST\n")
  47. hostRoutingFile.write("Groups: 225.0.0.1\n")
  48. hostRoutingFile.write("ifconfigend.\n")
  49. hostRoutingFile.write("route:\n")
  50. hostRoutingFile.write("225.0.0.1 192.%i.%i.1 255.255.255.255 G 0 eth0\n" % (i, j + 1))
  51. hostRoutingFile.write("default: 192.%i.%i.1 255.255.255.255 G 0 eth0\n" % (i, j + 1))
  52. hostRoutingFile.write("routeend.\n")
  53. hostRoutingFile.close()
  54. ###
  55. # creation of network description
  56. ###
  57. networkFile = open("multicast2.ned", "w")
  58. networkFile.write("""import "RTPHost", "Router";
  59. channel ethernet
  60. delay normal(0.00015,0.00005);
  61. datarate 10*10^6;
  62. endchannel
  63. module RTPMulticast2
  64. parameters:
  65. debug: bool;
  66. submodules:
  67. mainRouter: Router
  68. parameters:
  69. nodename = "mainRouter";
  70. numOfPorts = %i;
  71. routingFile = "mainRouter.mrt";
  72. gatesizes:
  73. in[%i];
  74. out[%i];
  75. """ % (secondaryRouters, secondaryRouters, secondaryRouters))
  76. for i in range(0, secondaryRouters):
  77. networkFile.write("""
  78. secondaryRouter%i: Router
  79. parameters:
  80. nodename = "secondaryRouter%i";
  81. numOfPorts = %i;
  82. routingFile = "secondaryRouter%i.mrt";
  83. gatesizes:
  84. in[%i];
  85. out[%i];
  86. """ % (i, i, hostsPerRouter + 1, i, hostsPerRouter + 1, hostsPerRouter + 1))
  87. for j in range(0, hostsPerRouter):
  88. networkFile.write("""
  89. host%i_%i: RTPHost
  90. parameters:
  91. """ % (i, j))
  92. networkFile.write("""
  93. debug = debug;
  94. numOfPorts = 1;
  95. nodename = "host%i-%i";
  96. routingFile = "host%i-%i.mrt";
  97. """ % (i, j, i, j))
  98. networkFile.write("""
  99. connections:
  100. """)
  101. for i in range(0, secondaryRouters):
  102. networkFile.write(""" mainRouter.out[%i] --> ethernet --> secondaryRouter%i.in[0];
  103. mainRouter.in[%i] <-- ethernet <-- secondaryRouter%i.out[0];
  104. """ % (i, i, i, i))
  105. for j in range(0, hostsPerRouter):
  106. if ((i == secondaryRouters - 1) & (j == hostsPerRouter - 1)):
  107. networkFile.write(""" secondaryRouter%i.out[%i] --> ethernet --> host%i_%i.in[0];
  108. secondaryRouter%i.in[%i] <-- ethernet <-- host%i_%i.out[0];
  109. """ % (i, j + 1, i, j, i, j + 1, i, j))
  110. else:
  111. networkFile.write(""" secondaryRouter%i.out[%i] --> ethernet --> host%i_%i.in[0];
  112. secondaryRouter%i.in[%i] <-- ethernet <-- host%i_%i.out[0];
  113. """ % (i, j + 1, i, j, i, j + 1, i, j))
  114. networkFile.write("""
  115. endmodule
  116. network
  117. rtpNetwork: RTPMulticast2
  118. parameters:
  119. debug = true;
  120. endnetwork""")
  121. networkFile.close()
  122. ###
  123. # creation of omnetpp.ini
  124. ###
  125. omnetppiniFile = open("omnetpp.ini", "w")
  126. omnetppiniFile.write("""
  127. [General]
  128. network = rtpNetwork
  129. ini-warnings = false
  130. total-stack-kb = 27535
  131. [Tkenv]
  132. default-run = 1
  133. module-messages = yes
  134. Verbose-simulation = yes
  135. [Parameters]
  136. *.numOfProcessors = 1
  137. *.profileName = "RTPAVProfile"
  138. *.destinationAddress = "225.0.0.1"
  139. *.portNumber = 5004
  140. *.bandwidth = 8000
  141. *.fileName = ""
  142. *.payloadType = 32
  143. *.autoOutputFileNames = true
  144. *.sessionEnterDelay = 0s
  145. *.transmissionStartDelay = 10s
  146. *.transmissionStopDelay = 3m
  147. *.sessionLeaveDelay = 10m
  148. """)
  149. omnetppiniFile.close()