⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drr.tcl

📁 Red script...bkabkabkblswajhaqhoiioajogjaojoiljoig
💻 TCL
字号:
#Kreiranje objekta simulator
set ns [new Simulator]

#Otvaranje NAM trace file-a
set nf [open /home/lab/out.nam w]
$ns namtrace-all $nf

#Otvaranje Trace file-a
set tf [open /home/lab/out.tr w]
$ns trace-all $tf
#**********************************************
#Otvaranje file-a za pracenje reda cekanja
set qq [open /home/lab/out.queue w]

#*********************************************
#Definisanje'finish' procedure
proc finish {} {
        global ns nf tf
        $ns flush-trace
        #Close the NAM trace file
        close $nf
        #Close the Trace file
        close $tf
        #Execute NAM on the trace file
        exec nam /home/lab/out.nam &
        exit 0
}
#************************************************

set tcpnum 2 

#Kreiranje dva cvora na prenosnom linku
  set n(1) [$ns node]
  set n(2) [$ns node]

  #Kreiranje rubnih cvorova
  for {set i 1} {$i <= $tcpnum} {incr i} {
      set s($i) [$ns node]
      set r($i) [$ns node]
  }

  
  #Kreiranje rubnih linkova
  for {set i 1} {$i <= $tcpnum} {incr i} {
      $ns duplex-link $s($i) $n(1) 1Mb 1ms DropTail
      $ns duplex-link $n(2) $r($i) 1Mb 1ms DropTail
  }


#**********************************************


Simulator instproc get-link { node1 node2 } {
    $self instvar link_
    set id1 [$node1 id]
    set id2 [$node2 id]
    return $link_($id1:$id2)
}

 #Kreiranje linka uskog grla
$ns duplex-link $n(1) $n(2) 1Mb 1ms DRR
set l [$ns get-link $n(1) $n(2)]
set qu [$l queue]
$qu blimit 52000
$qu buckets 2


#************************************************

#Monitoring reda cekanja  (za NAM)
$ns duplex-link-op $n(1) $n(2) queuePos 0.5

#*****************************************

  #Postavljanje TCP konekcija
  for {set i 1} {$i <= $tcpnum} {incr i} {
      set tcp($i) [new Agent/TCP/Reno]
      set sink($i) [new Agent/TCPSink]
      $ns attach-agent $s($i) $tcp($i)
      $ns attach-agent $r($i) $sink($i)
      $ns connect $tcp($i) $sink($i)

      $tcp($i) set fid_ $i
      $tcp($i) set window_ 20
      $tcp($i) set packetSize_ 1000
  }

  #Postavljanje FTP konekcija
  for {set i 1} {$i <= $tcpnum} {incr i} {
      set ftp($i) [new Application/FTP]
      $ftp($i) attach-agent $tcp($i)
      $ftp($i) set type_ FTP
  }

#*********************************************************
# Monitoring reda cekanja
set monitor [$ns monitor-queue $n(1) $n(2) /home/lab/queue.out]
proc queueLength {sum number} {
global ns monitor qq
set time 0.1
set len [$monitor set pkts_]
set now [$ns now]
set sum [expr $sum+$len]
set number [expr $number+1]

puts "[expr 1.0*$sum/$number]"
puts $qq "[expr 1.0*$sum/$number]" 
$ns at [expr $now+$time] "queueLength $sum $number"}
$ns at 0 "queueLength 0 0"

# Iniciranje pocetka  i zavrsetka konekcija
  for {set i 1} {$i <= $tcpnum} {incr i} {
      $ns at 0.1 "$ftp($i) start"
      $ns at 10.0 "$ftp($i) stop"
  }
#Pozivanje finish procedure poslije 10 sekundi simulacije
$ns at 10.0 "finish"

  $ns run



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -