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

📄 video.tcl

📁 一段NS2 仿真代码
💻 TCL
字号:
set ns [new Simulator]

 

set nf [open out.nam w]

$ns namtrace-all $nf

 

# generate the sending node:

#產生一個傳送節點

set send_node [$ns node]

 

# generate the routers:

#產生兩個路由器節點

set router_node_1 [$ns node]

set router_node_2 [$ns node]

 

# generate the receiving node:

#產生一個接收節點

set recv_node [$ns node]

 

# define the links between the nodes:

# 定義節點與節點之間的連線

$ns duplex-link $send_node $router_node_1 1Mb 10ms DropTail

$ns duplex-link $router_node_1 $router_node_2 1Mb 10ms DropTail

$ns duplex-link $router_node_2 $recv_node 1Mb 10ms DropTail

 

# set the maximal queue lengths of the routers:

# 設定佇列的buffer size

$ns queue-limit $router_node_1 $router_node_2 10

$ns queue-limit $router_node_2 $recv_node 10

 

# define the source

# 定義傳送端

set udp [new Agent/UDP]

$ns attach-agent $send_node $udp

 

# define the destination:

# 定義接收端

set snk [new Agent/Null] 

$ns attach-agent $recv_node $snk

 

# 把傳送端和接收端連結起來

$ns connect $udp $snk

 

# generate the video trace file ("Verbose_Jurassic_64.dat" is only an example):

#從 Verbose_Jurassic_64.dat的資料中要產生一個trace file,以提供Traffic Trace用

set original_file_name Verbose_Jurassic_64.dat

set trace_file_name video.dat

set original_file_id [open $original_file_name r]

set trace_file_id [open $trace_file_name w]

 

set last_time 0

 

while {[eof $original_file_id] == 0} {

  gets $original_file_id current_line

 

  if {[string length $current_line] == 0 ||

      [string compare [string index $current_line 0] "#"] == 0} {

    continue  

  }

 

  scan $current_line "%d%s%d" next_time type length

 

  set time [expr 1000*($next_time-$last_time)]

 

  set last_time $next_time

 

#產生binary file,要提供資料給Traffic Trace用

  puts -nonewline $trace_file_id [binary format "II" $time $length]

}

 

close $original_file_id

close $trace_file_id

 

# set the simulation end time:

# 設定模擬結束時間

set end_sim_time [expr 1.0*$last_time/1000+0.001]

 

# read the video trace file:

#把資料提功給Traffic Trace

set trace_file [new Tracefile]

$trace_file filename $trace_file_name

set video [new Application/Traffic/Trace]

$video attach-agent $udp

$video attach-tracefile $trace_file

 

# start the simulation:

# 開始模擬

$ns at 0.0 “$video start”

 

# stop the simulation:

# 結束模擬

$ns at $end_sim_time “finish”

 

#定義一個程序

proc finish {} {

  global ns nf

  $ns flush-trace

  close $nf

  exec nam out.nam &

  exit 0

}

 

#開始模擬

$ns run

⌨️ 快捷键说明

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