simple-webcache-comp.tcl
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:4k
源码类别:

通讯编程

开发平台:

Visual C++

  1. #
  2. #  Copyright (c) 1997 by the University of Southern California
  3. #  All rights reserved.
  4. #
  5. #  This program is free software; you can redistribute it and/or
  6. #  modify it under the terms of the GNU General Public License,
  7. #  version 2, as published by the Free Software Foundation.
  8. #
  9. #  This program is distributed in the hope that it will be useful,
  10. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. #  GNU General Public License for more details.
  13. #
  14. #  You should have received a copy of the GNU General Public License along
  15. #  with this program; if not, write to the Free Software Foundation, Inc.,
  16. #  59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  17. #
  18. #  The copyright of this module includes the following
  19. #  linking-with-specific-other-licenses addition:
  20. #
  21. #  In addition, as a special exception, the copyright holders of
  22. #  this module give you permission to combine (via static or
  23. #  dynamic linking) this module with free software programs or
  24. #  libraries that are released under the GNU LGPL and with code
  25. #  included in the standard release of ns-2 under the Apache 2.0
  26. #  license or under otherwise-compatible licenses with advertising
  27. #  requirements (or modified versions of such code, with unchanged
  28. #  license).  You may copy and distribute such a system following the
  29. #  terms of the GNU GPL for this module and the licenses of the
  30. #  other code concerned, provided that you include the source code of
  31. #  that other code when and as the GNU GPL requires distribution of
  32. #  source code.
  33. #
  34. #  Note that people who make modified versions of this module
  35. #  are not obligated to grant this special exception for their
  36. #  modified versions; it is their choice whether to do so.  The GNU
  37. #  General Public License gives permission to release a modified
  38. #  version without this exception; this exception also makes it
  39. #  possible to release a modified version which carries forward this
  40. #  exception.
  41. # $Header: /cvsroot/nsnam/ns-2/tcl/ex/simple-webcache-comp.tcl,v 1.2 2005/09/16 03:05:41 tomh Exp $
  42. #
  43. # Example script illustrating the usage of complex page in webcache. 
  44. # Thanks to Xiaowei Yang <yxw@mercury.lcs.mit.edu> for motivation and 
  45. # an original version of this script.
  46. Agent/TCP/FullTcp set segsize_ 1460
  47. Http set TRANSPORT_ FullTcp
  48. set ns [new Simulator]
  49. set f [open "comp.tr" w]
  50. $ns namtrace-all $f
  51. set log [open "comp.log" w]
  52. $ns rtproto Session
  53. set node(c) [$ns node]
  54. set node(r) [$ns node]
  55. set node(s) [$ns node]
  56. $ns duplex-link $node(s) $node(r) 100Mb 25ms DropTail
  57. $ns duplex-link $node(r) $node(c) 10Mb 25ms DropTail
  58. [$ns link $node(s) $node(r)] set queue-limit 10000
  59. [$ns link $node(r) $node(s)] set queue-limit 10000
  60. [$ns link $node(c) $node(r)] set queue-limit 10000
  61. [$ns link $node(r) $node(c)] set queue-limit 10000
  62. # Use PagePool/CompMath to generate compound page, which is a page 
  63. # containing multiple embedded objects.
  64. set pgp [new PagePool/CompMath]
  65. $pgp set main_size_ 1000 ;# Size of main page
  66. $pgp set comp_size_ 5000 ;# Size of embedded object
  67. $pgp set num_pages_ 3 ;# Number of objects per compoud page
  68. # Average age of component object: 100s
  69. set tmp [new RandomVariable/Constant]
  70. $tmp set val_ 100
  71. $pgp ranvar-obj-age $tmp
  72. # Average age of the main page: 50s
  73. set tmp [new RandomVariable/Constant]
  74. $tmp set val_ 50
  75. $pgp ranvar-main-age $tmp
  76. set server [new Http/Server/Compound $ns $node(s)]
  77. $server set-page-generator $pgp
  78. $server log $log
  79. set client [new Http/Client/Compound $ns $node(c)]
  80. set tmp [new RandomVariable/Constant]
  81. $tmp set val_ 10
  82. $client set-interval-generator $tmp
  83. $client set-page-generator $pgp
  84. $client log $log
  85. set startTime 1 ;# simulation start time
  86. set finishTime 500 ;# simulation end time
  87. $ns at $startTime "start-connection"
  88. $ns at $finishTime "finish"
  89. proc start-connection {} {
  90. global ns server  client
  91. $client connect $server
  92. # Comment out following line to continuously send requests
  93. $client start-session $server $server
  94. # Comment out following line to send out ONE request
  95. # DON't USE with start-session!!!
  96. #set pageid $server:[lindex [$client gen-request] 1]
  97. #$client send-request $server GET $pageid
  98. }
  99. proc finish {} {
  100. global ns log f client server
  101. $client stop-session $server
  102. $client disconnect $server
  103. $ns flush-trace
  104. flush $log
  105. close $log
  106. exit 0
  107. }
  108. $ns run