Ns2简单有限网络仿真实验

更新时间:2023-06-06 17:12:21 阅读: 评论:0

Ns2简单有限⽹络仿真实验Ns2简单有限⽹络仿真实验
1.编写Otcl脚本⽂件yy.tcl
2.终端:l即可进⾏仿真
注意:在 建⽴⼀条UDP的联机时,不要忘记添加
$ns attach-agent $n3 $null
我在代码中也特别标注出来了。
//Otcl脚本,⽂本⽂件后缀名为.tcl即可
#产⽣⼀个仿真的对象
t ns [new Simulator]
#针对不同的资料流定义不同的颜⾊,这是要给NAM⽤的
$ns color 1 Green
$ns color 2 Red
#开启⼀个NAM trace file
t nf [open out.nam w]
$ns namtrace-all $nf
#开启⼀个trace file,⽤来记录封包传送的过程
t nd [ w]
$ns trace-all $nd
#定义⼀个结束的程序
proc finish {}{
global ns nf nd wnd_trace
$ns flush-trace
长沙有什么好玩的旅游景点
clo $nf
clo $nd
#以背景执⾏的⽅式去执⾏NAM
exec nam out.nam &
exit 0
}
#产⽣6个⽹络节点
t n0 [$ns node]有关教育的名言
t n1 [$ns node]
t n2 [$ns node]
t n3 [$ns node]不得不的英语
t n4 [$ns node]
t n5 [$ns node]
#把节点连接起来
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail
$ns duplex-link $n3 $n4 1.7Mb 30ms DropTail
$ns duplex-link $n3 $n5 1.5Mb 30ms DropTail
#设定ns2到ns3之间的Queue Size为10个封包⼤⼩
$ns queue-limit $n2 $n3 10
$ns queue-limit $n3 $n4 5
$ns queue-limit $n3 $n5 10
#设定节点的位置,这是要给NAM⽤的
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down
#观测n2到n3之间queue的变化,这是要给NAM⽤的
t tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
t sink [new Agent/TCPSink]
$ns attach-agent $n5 $sink
$ns connect $tcp $sink
#在NAM中,TCP的联机会以Green表⽰
$tcp t fid_ 1
#在TCP联机之上建⽴FTP应⽤程序
t ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp t type_ FTP
#建⽴⼀条UDP的联机
t udp [new Agent/UDP]
$ns attach-agent $n1 $udp
t null [new Agent/Null]
///
//不要忘记添加这句话,否则运⾏不了
$ns attach-agent $n3 $null
///
$ns connect $udp $null
#在NAM中,UDP的联机会以红⾊表⽰
$udp t fid_ 2
#在UDP联机之上建⽴CBR应⽤程序
t cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr t type_ CBR
$cbr t packet_size_ 1000
$cbr t rate_ 1mb
$cbr t random_ fal
#设定FTP和CBR资料传送开始和结束时间
$ns at 0.1"$cbr start"
$ns at 1.0"$ftp start"
$ns at 4.0"$ftp stop"
$ns at 4.5"$cbr stop"
#结束TCP的联机(不⼀定需要写下⾯的程序代码来实际结束联机)
$ns at 4.5"$ns detach-agent $n0 $tcp;$ns detach-agent $n3 $sink"
#在仿真环境中,5秒后去呼叫finish来结束仿真(这样要注意仿真环境中的5秒并⼀定等于实际仿真的时间)
必有回响的上一句是什么$ns at 5.0"finish"
#执⾏仿真
$ns run
接下来是数据分析
1. 把测量CBR封包端点到端点间延迟时间的awk程序,写在档案measure-delay.awk档案中。(也就是新建⼀个.awk⽂件:gedit
measure-delay.awk)
#测量CBR封包端点到端点间延迟时间的awk程序
BEGIN {
#程序初始化,设定⼀变量以记录⽬前最⾼处理封包的ID
highest_packet_id =0;
}
{
action = $1;
time = $2;
node_1 = $3;
node_2 = $4;
type = $5;
flow_id = $8;
node_1_address = $9;
node_2_address = $10;
政策创新q_no = $11;山东多大面积
packet_id = $12;
#记录⽬前最⾼的packet ID
if(packet_id > highest_packet_id)
highest_packet_id = packet_id;
#记录封包的传送时间
if(start_time[packet_id]==0)
start_time[packet_id]= time;
#记录CBR(flow_id =2)的接收时间
if( flow_id ==2&& action !="d"){
if(action =="r"){
end_time[packet_id]= time;
}
}el{
#把不是flow_id =2的封包或者是flow_id =2但此封包被drop的时间设为-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)printf("%f %f\n",start,packet_duration);
}
}
结果如下:会出来好多组数据(这⾥不全部列出了,⼤概就是下⾯这些),⽤画图软件把这些点画出来会容易看些。
0.100000 0.038706
0.108000 0.038706
0.116000 0.038706
0.868000 0.038706
1.956000 0.038706
1.964000 0.038706
1.972000 0.038706
1.980000 0.038706
2.124000 0.038706
当代青年楷模事迹2.508000 0.041529
2.516000 0.038706
2.708000 0.041812
2.884000 0.047647
3.804000 0.076165
3.812000 0.077765
3.820000 0.074471
3.828000 0.076071
4.156000 0.038706
4.164000 0.038706
4.460000 0.038706
4.468000 0.038706
2.jitter延迟时间变化量delay variance 创建⽂件measure-jitter.awk

本文发布于:2023-06-06 17:12:21,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/886354.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:时间   封包   结束   传送   出来   端点   记录   资料
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图