Chinaunix首页 | 论坛 | 博客
  • 博客访问: 102283
  • 博文数量: 21
  • 博客积分: 415
  • 博客等级: 一等列兵
  • 技术积分: 228
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-11 12:17
文章分类

全部博文(21)

文章存档

2014年(1)

2012年(7)

2011年(13)

分类: C/C++

2012-11-29 22:40:02

最近在学习ns2--network simulator。
以下是对教材《ns与网络模拟》入门案例的一个理解:
程序:

点击(此处)折叠或打开

  1. set ns [new Simulator]

  2. set tracefd [open example1.tr w]
  3. $ns trace-all $tracefd
  4. set namtracefd [open example1.nam w]
  5. $ns namtrace-all $namtracefd

  6. proc finish {} {
  7.         global ns tracefd namtracefd
  8.         $ns flush-trace
  9.         close $tracefd
  10.         close $namtracefd
  11.         exec nam example1.nam &
  12.         exit 0
  13. }

  14. set n0 [$ns node]
  15. set n1 [$ns node]

  16. $ns duplex-link $n0 $n1 1Mb 10ms DropTail

  17. set udp0 [new Agent/UDP]
  18. $ns attach-agent $n0 $udp0

  19. set cbr0 [new Application/Traffic/CBR]
  20. $cbr0 set packetSize_ 500
  21. $cbr0 set interval_ 0.005
  22. $cbr0 attach-agent $udp0
  23. set null0 [new Agent/Null]
  24. $ns attach-agent $n1 $null0
  25. $ns connect $udp0 $null0
  26. $ns at 0.5 "$cbr0 start"
  27. $ns at 4.5 "$cbr0 stop"
  28. $ns at 5.0 "finish"

  29. $ns run
整个这段代码描述了如下场景:
阅读(1167) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~