为方便读者,本教材中连续四行及以上程序源码(脚本),本网站将直接提供,直接输入使用。
global ns
set ns [new Simulator]
HandoffManager/Term set elevation_mask_ 8.2
HandoffManager/Term set term_handoff_int_ 10
HandoffManager/Sat set sat_handoff_int_ 10
HandoffManager/Sat set latitude_threshold_ 60
HandoffManager/Sat set longitude_threshold_ 10
HandoffManager set handoff_randomization_ true
SatRouteObject set metric_delay_ true
SatRouteObject set data_driven_computation_ true
ns-random 1
Agent set ttl_ 32
global opt
set opt(chan) Channel/Sat
set opt(bw_down) 1.5Mb
set opt(bw_up) 1.5Mb
set opt(bw_isl) 25Mb
set opt(phy) Phy/Sat
set opt(mac) Mac/Sat
set opt(ifq) Queue/DropTail
set opt(qlim) 50
set opt(ll) LL/Sat
set opt(wiredRouting) OFF
set opt(alt) 780
set opt(inc) 86.4
set outfile [open sat-Iridium.tr w]
$ns trace-all $outfile
$ns node-config -satNodeType polar \
-llType $opt(ll) \
-ifqType $opt(ifq) \
-ifqLen $opt(qlim) \
-macType $opt(mac) \
-phyType $opt(phy) \
-channelType $opt(chan) \
-downlinkBW $opt(bw_down) \
-wiredRouting $opt(wiredRouting)
set alt $opt(alt)
set inc $opt(inc)
source sat-Iridium-nodes.tcl
source sat-Iridium-links.tcl
$ns node-config -satNodeType terminal
set n100 [$ns node]
$n100 set-position 39.54 116.28; # BeiJing
set n101 [$ns node]
$n101 set-position 31.12 121.26; # ShangHai
$n100 add-gsl polar $opt(ll) $opt(ifq) $opt(qlim) $opt(mac) $opt(bw_up) \
$opt(phy) [$n0 set downlink_] [$n0 set uplink_]
$n101 add-gsl polar $opt(ll) $opt(ifq) $opt(qlim) $opt(mac) $opt(bw_up) \
$opt(phy) [$n0 set downlink_] [$n0 set uplink_]
$ns trace-all-satlinks $outfile
set udp0 [new Agent/UDP]
$ns attach-agent $n100 $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set interval_ 60.01
set null0 [new Agent/Null]
$ns attach-agent $n101 $null0
$ns connect $udp0 $null0
$ns at 1.0 "$cbr0 start"
set satrouteobject_ [new SatRouteObject]
$satrouteobject_ compute_routes
$ns at 86400.0 "finish"
proc finish {} {
global ns outfile
$ns flush-trace
close $outfile
exit 0
}
$ns run
BEGIN {
highest_packet_id=0;
}
{
action=$1;
time=$2;
from=$3;
to=$4;
type=$5;
size=$6;
flow_id=$8;
src=$9;
dst=$10;
seq_no=$11;
packet_id=$12;
if (packet_id > highest_packet_id)
highest_packet_id =packet_id;
if (start_time[packet_id]==0)
start_time[packet_id] =time;
if(flow_id ==0&&action !="d")
{
if(action=="r"&&to=="67") {
end_time[packet_id]=time;
}
else
{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];
delay=end-start;
if (start < end) printf( "%f %f\n",start,delay)
}
}
set term pdfcairo font "simsun,10"
set out "delay.pdf"
set size 1,0.7
set key right top
set ylabel "时延/s"
set xlabel "时间/s"
plot "delay.d" u 1:2 w lp lw 2 lc rgb "black" t "端到端时延"
Node/SatNode set time_advance_ 0
HandoffManager/Term set elevation_mask_ 40
HandoffManager/Term set term_handoff_int_ 10
HandoffManager/Sat set sat_handoff_int_ 10
HandoffManager/Sat set latitude_threshold_ 60
HandoffManager/Sat set longitude_threshold_ 8
HandoffManager set handoff_randomization_ true
SatRouteObject set metric_delay_ true
SatRouteObject set data_driven_computation_ true
ns-random 1
Agent set ttl_ 32
global opt
set opt(chan) Channel/Sat
set opt(bw_down) 1.5Mb
set opt(bw_up) 1.5Mb
set opt(bw_isl) 155Mb
set opt(phy) Phy/Sat
set opt(mac) Mac/Sat
set opt(ifq) Queue/DropTail
set opt(qlim) 50
set opt(ll) LL/Sat
set opt(wiredRouting) OFF
set opt(alt) 1375
set opt(inc) 84.7
global ns
set ns [new Simulator]
set outfile [open sat-teledesic.tr w]
$ns trace-all $outfile
$ns node-config -satNodeType polar \
-llType $opt(ll) \
-ifqType $opt(ifq) \
-ifqLen $opt(qlim) \
-macType $opt(mac) \
-phyType $opt(phy) \
-channelType $opt(chan) \
-downlinkBW $opt(bw_down) \
-wiredRouting $opt(wiredRouting)
set alt $opt(alt)
set inc $opt(inc)
source sat-teledesic-nodes.tcl
source sat-teledesic-links.tcl
$ns node-config -satNodeType terminal
set n100 [$ns node]
$n100 set-position 39.54 116.28; # BeiJing
set n101 [$ns node]
$n101 set-position 31.12 121.26; # ShangHai
$n100 add-gsl polar $opt(ll) $opt(ifq) $opt(qlim) $opt(mac) $opt(bw_up) \
$opt(phy) [$n(100) set downlink_] [$n(100) set uplink_]
$n101 add-gsl polar $opt(ll) $opt(ifq) $opt(qlim) $opt(mac) $opt(bw_up) \
$opt(phy) [$n(100) set downlink_] [$n(100) set uplink_]
$ns trace-all-satlinks $outfile
set udp0 [new Agent/UDP]
$ns attach-agent $n100 $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set interval_ 60
set null0 [new Agent/Null]
$ns attach-agent $n101 $null0
$ns connect $udp0 $null0
$ns at 1.0 "$cbr0 start"
set satrouteobject_ [new SatRouteObject]
$satrouteobject_ suppress_initial_computation
$ns at 0.5 "$satrouteobject_ compute_routes"
$ns at 86400.0 "finish"
proc finish {} {
global ns outfile
$ns flush-trace
close $outfile
exit 0
}
$ns run