永发信息网

求ns2中dsdv的tcl脚本与awk文件

答案:1  悬赏:40  手机版
解决时间 2021-11-28 23:57
  • 提问者网友:雪舞兮
  • 2021-11-28 06:48
求ns2中dsdv的tcl脚本与awk文件
最佳答案
  • 五星知识达人网友:醉吻情书
  • 2021-11-28 07:57
提tcl脚本
  # wrls1.tcl
  # A 3-node example for ad-hoc simulation with AODV

  # Define options
  set val(chan) Channel/WirelessChannel ;# channel type
  set val(prop) Propagation/TwoRayGround ;# radio-propagation model
  set val(netif) Phy/WirelessPhy ;# network interface type
  set val(mac) Mac/802_11 ;# MAC type
  set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
  set val(ll) LL ;# link layer type
  set val(ant) Antenna/OmniAntenna ;# antenna model
  set val(ifqlen) 50 ;# max packet in ifq
  set val(nn) 5 ;# number of mobilenodes
  set val(rp) DSDV ;# routing protocol
  set val(x) 500 ;# X dimension of topography
  set val(y) 400 ;# Y dimension of topography
  set val(stop) 150 ;# time of simulation end

  set ns [new Simulator]
  set tracefd [open simple.tr w]
  set windowVsTime2 [open win.tr w]
  set namtrace [open simwrls.nam w]

  $ns trace-all $tracefd
  $ns namtrace-all-wireless $namtrace $val(x) $val(y)

  # set up topography object
  set topo [new Topography]

  $topo load_flatgrid $val(x) $val(y)

  create-god $val(nn)

  #
  # Create nn mobilenodes [$val(nn)] and attach them to the channel.
  #

  # configure the nodes
  $ns node-config -adhocRouting $val(rp) \
  -llType $val(ll) \
  -macType $val(mac) \
  -ifqType $val(ifq) \
  -ifqLen $val(ifqlen) \
  -antType $val(ant) \
  -propType $val(prop) \
  -phyType $val(netif) \
  -channelType $val(chan) \
  -topoInstance $topo \
  -agentTrace ON \
  -routerTrace ON \
  -macTrace OFF \
  -movementTrace ON

  for {set i 0} {$i < $val(nn) } { incr i } {
  set node_($i) [$ns node]
  }

  # Provide initial location of mobilenodes
  $node_(0) set X_ 5.0
  $node_(0) set Y_ 5.0
  $node_(0) set Z_ 0.0

  $node_(1) set X_ 490.0
  $node_(1) set Y_ 285.0
  $node_(1) set Z_ 0.0

  $node_(2) set X_ 150.0
  $node_(2) set Y_ 240.0
  $node_(2) set Z_ 0.0

  $node_(3) set X_ 250.0
  $node_(3) set Y_ 240.0
  $node_(3) set Z_ 0.0

  $node_(4) set X_ 100.0
  $node_(4) set Y_ 70.0
  $node_(4) set Z_ 0.0

  # Generation of movements
  $ns at 10.0 "$node_(0) setdest 250.0 250.0 10.0"
  $ns at 15.0 "$node_(1) setdest 45.0 285.0 10.0"
  $ns at 110.0 "$node_(0) setdest 480.0 300.0 10.0"
  $ns at 70.0 "$node_(3) setdest 180.0 30.0 10.0"

  # Set a TCP connection between node_(0) and node_(1)
  set tcp [new Agent/TCP/Newreno]
  $tcp set class_ 2
  set sink [new Agent/TCPSink]
  $ns attach-agent $node_(0) $tcp
  $ns attach-agent $node_(1) $sink
  $ns connect $tcp $sink
  set ftp [new Application/FTP]
  $ftp attach-agent $tcp
  $ns at 10.0 "$ftp start"

  # Printing the window size
  proc plotWindow {tcpSource file} {
  global ns
  set time 0.01
  set now [$ns now]
  set cwnd [$tcpSource set cwnd_]
  puts $file "$now $cwnd"
  $ns at [expr $now+$time] "plotWindow $tcpSource $file" }
  $ns at 10.1 "plotWindow $tcp $windowVsTime2"

  # Define node initial position in nam
  for {set i 0} {$i < $val(nn)} { incr i } {
  # 30 defines the node size for nam
  $ns initial_node_pos $node_($i) 30
  }

  # Telling nodes when the simulation ends
  for {set i 0} {$i < $val(nn) } { incr i } {
  $ns at $val(stop) "$node_($i) reset";
  }

  # ending nam and the simulation
  $ns at $val(stop) "$ns nam-end-wireless $val(stop)"
  $ns at $val(stop) "stop"
  $ns at 150.01 "puts \"end simulation\" ; $ns halt"
  proc stop {} {
  global ns tracefd namtrace
  $ns flush-trace
  close $tracefd
  close $namtrace
  #Execute nam on the trace file
  exec nam simwrls.nam &
  exit 0
  }

  #Call the finish procedure after 5 seconds of simulation time
  $ns run

  awk文件:# 使用的是无线trace的旧格式
  BEGIN {
  highest_packet_id = 0;
  i=0;
  }
  {
  action = $1;
  time = $2;
  packet_id = $6;
  type = $7;

  # 不考虑路由包,可以保证序号为0的cbr被统计到
  if ( type == "cbr" ) {

  if ( packet_id > highest_packet_id )
  highest_packet_id = packet_id;

  #记录封包的传送时间
  if ( start_time[packet_id] == 0 )
  start_time[packet_id] = time;

  #记录CBR 的接收时间
  if ( action != "d" ) {
  if ( action == "r" ) {
  end_time[packet_id] = time;
  }
  } else {
  #把不符合条件的数据包的时间设为-1
  end_time[packet_id] = -1;
  }
  }
  }
  END {
  #当资料列全部读取完后,开始计算有效封包的端点到端点延迟时间
  for ( packet_id = 0; packet_id <= highest_packet_id; packet_id++ ) {
  start = start_time[packet_id];
  end = end_time[packet_id];
  packet_duration = end - start;

  #只把接收时间大于传送时间的记录列出来
  if ( start < end ){
  delaysum += packet_duration;
  i++;
  ratio=delaysum/i;
  printf("%f %f\n",start, ratio);
  }
  }
  }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯