PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Research/Networks/TestNetwork/test_TestNetwork.rb

https://github.com/revenant/ipv6suite
Ruby | 146 lines | 98 code | 23 blank | 25 comment | 13 complexity | ab9e038e27eda547cc137d49d4a71f4f MD5 | raw file
  1. # {{{ Unit Test #
  2. ##Unit test for this class/module
  3. require 'test/unit'
  4. require 'bigdecimal'
  5. require 'bigdecimal/math'
  6. class TC_TestNetwork < Test::Unit::TestCase
  7. #include RStuff
  8. def test_rtrSolicitationSeparation
  9. testvec = 'VideoStream.vec'
  10. vecnum = `grep 'RS sent' #{testvec}|cut -f 2 -d ' '`.split("\n")
  11. rtrsols = `grep ^#{vecnum[0].to_i} #{testvec}|cut -f 2`.split("\n")
  12. rtrsols.collect!{|x| x.to_f}
  13. assert( rtrsols.length == 3, "max_rtr_sol is 3 by default but got #{rtrsols.length}")
  14. ans1=(rtrsols[0]-rtrsols[1]).abs
  15. assert( ans1== 4, "rtr_sol_interval is 4 by default but got #{ans1}")
  16. ans2=(rtrsols[1]-rtrsols[2]).abs
  17. assert((ans2 - 4).abs < @diffConsideredZero, "rtr_sol_interval is 4 by default but got #{ans2}")
  18. end
  19. def test_DAD
  20. #very first NS delayed by uniform(0,max_rtr_sol_delay) which is 1 by defualt
  21. #In fact acc. to rfc4862 all 1st NS done for addr configured from
  22. #multicast RA need this as all unicast addr need DAD now
  23. #we'll use odad to avoid it
  24. #NS separated RETRANS_TIMER s (1)
  25. #make it test 2 vec one with HostDupAddrDetectTransmits = 4 and other with standard of 1
  26. #standard of 1 occurs when no xml config file specified this occurs
  27. #in run 4
  28. testvec = 'VideoStream.vec'
  29. vecnum = `grep 'NS sent' #{testvec}|cut -f 2 -d ' '`.split("\n")
  30. ngbrsols = `grep ^#{vecnum[0].to_i} #{testvec}|cut -f 2`.split("\n")
  31. ngbrsols.collect!{|x| x.to_f}
  32. assert(ngbrsols.length == 1, "no of ngbrsols of r4 should only be one and is separated from addr assigned by 1")
  33. #testing with xml file run 6
  34. testvec = 'VideoStreamc.vec'
  35. #client 1 with 2 addresses and dtd defaults for retrans timer
  36. vecnum = `grep 'NS sent' #{testvec}|grep client1|cut -f 2 -d ' '`.split("\n")
  37. ngbrsols = `grep ^#{vecnum[0].to_i} #{testvec}|cut -f 2`.split("\n")
  38. ngbrsols.collect!{|x| x.to_f}
  39. ans1=(ngbrsols[0]-ngbrsols[1]).abs
  40. assert( ngbrsols.length == 8, "TestNetwork.xml HostDupAddrDetectTransmits is 4 by default but got #{ngbrsols.length}")
  41. assert( ans1== 0.12, "Default retrans_timer in netconf2.dtd is 0.12 but got #{ans1}")
  42. ans2=(ngbrsols[1]-ngbrsols[2]).abs
  43. assert(ans2 == 0.12,"Default retrans_timer in netconf2.dtd is 0.12 but got #{ans2}")
  44. ans3=(ngbrsols[2]-ngbrsols[3]).abs
  45. assert(ans3 == 0.12,"Default retrans_timer netconf2.dtd is 0.12 but got #{ans2}")
  46. #for client2 with dtd defaults
  47. vecnum = `grep 'NS sent' #{testvec}|grep client2|cut -f 2 -d ' '`.split("\n")
  48. ngbrsols = `grep ^#{vecnum[0].to_i} #{testvec}|cut -f 2`.split("\n")
  49. ngbrsols.collect!{|x| x.to_f}
  50. assert( ngbrsols.length == 2, "HostDupAddrDetectTransmits is 2 in DTD but got #{ngbrsols.length}")
  51. ans1=(ngbrsols[0]-ngbrsols[1]).abs
  52. assert( ans1 - 1 < @diffConsideredZero,
  53. "retrans_timer is 1 in TestNetwork.xml but got #{ans1}")
  54. end
  55. def test_AR
  56. #MAX_MULTICAST_SOL times NS separated by at least RETRANS_TIMER
  57. #AR NS not recorded in vec files
  58. ngbrsols = `grep -v Vid test5.out|grep 'NS(AR' |egrep '>'|cut -d ' ' -f 3`.split("\n")
  59. ngbrsols.collect!{|x| x.to_f}
  60. ans1=(ngbrsols[0]-ngbrsols[1]).abs
  61. assert( ngbrsols.length == 3, "max_multi_sol is 3 by default but got #{ngbrsols.length}")
  62. assert( ans1== 1, "retrans_timer is 1 by default (c++) but got #{ans1}")
  63. ans2=(ngbrsols[1]-ngbrsols[2]).abs
  64. assert(ans2 == 1,"retrans_timer is 1 by default (c++) but got #{ans2}")
  65. end
  66. def test_ODAD
  67. #Runs 8 and 9
  68. #notice no drops using odad
  69. wait = `grep -i drop odad.vec`
  70. assert( wait == "", "no drops when using odad: #{wait}")
  71. wait = `grep -i drop noodad.vec`
  72. assert( wait != "", "drops when not using odad: #{wait}")
  73. testvec = "odad.vec"
  74. vecnum = `grep 'NS sent' #{testvec}|grep client2|cut -f 2 -d ' '`.split("\n")
  75. ngbrsols = `grep ^#{vecnum[0].to_i} #{testvec}|cut -f 2`.split("\n")
  76. ngbrsols.collect!{|x| x.to_f}
  77. assert_in_delta(7.8, ngbrsols[0], @diffConsideredZero,
  78. "Configured ND to start on client2 at")
  79. ans1=(ngbrsols[0]-ngbrsols[1]).abs
  80. assert_in_delta(1, ans1, @diffConsideredZero, "retranstimer in xml was 1, but got #{ans1}")
  81. end
  82. require "rexml/document"
  83. include REXML
  84. def test_RA
  85. #R 2.6 does not work with rsruby :(
  86. #R_HOME=/opt/sw/R-2.6.0/lib64/R/
  87. #Do both below b4 attempting to run this
  88. #module unload R
  89. #export R_HOME=$HOME/lib64/R
  90. require 'rsruby'
  91. r = RSRuby.instance
  92. wait = `ruby ~/src/IPv6SuiteWithINET/Etc/scripts/RImportOmnet.rb rtr.vec`
  93. raise wait if $?.exitstatus > 0
  94. r.load("test2.Rdata")
  95. data=r.a_RA_recv_client1_1
  96. diffs = r.diff(data["time"])
  97. doc = Document.new File.new("TestNetwork3.xml")
  98. rtr = doc.elements["*/local[@node='rtr']/interface"]
  99. assert(diffs.max <= rtr.attributes["MaxRtrAdvInterval"].to_f, "maximum #{diffs.max} should be less than in XML #{rtr.attributes["MaxRtrAdvInterval"].to_f}")
  100. assert(diffs.min > 3, "RA response to RS should always be at least \
  101. MIN_DELAY_BETWEEN_RAS (3 in spec)")
  102. raise "min is not in array?" if diffs.delete(diffs.min).nil?
  103. #unsolicited RAs have to satisfy this
  104. assert(diffs.min >= rtr.attributes["MinRtrAdvInterval"].to_f,
  105. "Unsolicited RAs separation in sim #{diffs.min} should always be \
  106. greater than in XML #{rtr.attributes["MinRtrAdvInterval"].to_f}")
  107. wait = `rm test2.Rdata`
  108. wait = `ruby ~/src/IPv6SuiteWithINET/Etc/scripts/RImportOmnet.rb rtrmip6.vec`
  109. raise wait if $?.exitstatus > 0
  110. r.rm(:list => r.ls.call)
  111. r.load("test2.Rdata")
  112. #Need to use r.get as r.a_RA_recv_client1_1 returns cached !!!
  113. data = r.get("a.RA.recv.client1.1")
  114. diffs = r.diff(data["time"])
  115. assert(diffs.max <= rtr.attributes["MIPv6MaxRtrAdvInterval"].to_f, "maximum #{diffs.max} should be less than in XML #{rtr.attributes["MIPv6MaxRtrAdvInterval"].to_f}")
  116. assert(diffs.min >= rtr.attributes["MIPv6MinRtrAdvInterval"].to_f,
  117. "Unsolicited RAs separation in sim #{diffs.min} should always be \
  118. greater than in XML #{rtr.attributes["MIPv6MinRtrAdvInterval"].to_f}")
  119. end
  120. def setup
  121. @diffConsideredZero = BigDecimal.new("1e-7")
  122. end
  123. end