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

通讯编程

开发平台:

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.tcl,v 1.2 2005/09/16 03:05:42 tomh Exp $
  42. set ns [new Simulator]
  43. # Create topology/routing
  44. set node(c) [$ns node] 
  45. set node(e) [$ns node]
  46. set node(s) [$ns node]
  47. $ns duplex-link $node(s) $node(e) 1.5Mb 50ms DropTail
  48. $ns duplex-link $node(e) $node(c) 10Mb 2ms DropTail 
  49. $ns rtproto Session
  50. # HTTP logs
  51. set log [open "http.log" w]
  52. # Use PagePool/Math
  53. set pgp [new PagePool/Math]
  54. set tmp [new RandomVariable/Constant] ;# Size generator
  55. $tmp set val_ 1024  ;# average page size
  56. $pgp ranvar-size $tmp
  57. set tmp [new RandomVariable/Exponential] ;# Age generator
  58. $tmp set avg_ 5 ;# average page age
  59. $pgp ranvar-age $tmp
  60. set server [new Http/Server $ns $node(s)]
  61. $server set-page-generator $pgp
  62. $server log $log
  63. set cache [new Http/Cache $ns $node(e)]
  64. $cache log $log
  65. set client [new Http/Client $ns $node(c)]
  66. set tmp [new RandomVariable/Exponential] ;# Poisson process
  67. $tmp set avg_ 5 ;# average request interval
  68. $client set-interval-generator $tmp
  69. $client set-page-generator $pgp
  70. $client log $log
  71. set startTime 1 ;# simulation start time
  72. set finishTime 50 ;# simulation end time
  73. $ns at $startTime "start-connection"
  74. $ns at $finishTime "finish"
  75. proc start-connection {} {
  76. global ns server cache client
  77. $client connect $cache
  78. $cache connect $server
  79. $client start-session $cache $server
  80. }
  81. proc finish {} {
  82. global ns log
  83. $ns flush-trace
  84. flush $log
  85. close $log
  86. exit 0
  87. }
  88. $ns run