博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ns-2 tcp-udp模拟实验
阅读量:7222 次
发布时间:2019-06-29

本文共 1966 字,大约阅读时间需要 6 分钟。

模拟一个网络环境,该环境中包含两个传输节点s1,s2,路由器r,和资料接收端d.

大概如下图所示:

 

源代码:

 

set ns [new Simulator]

$ns color 1 Blue
$ns color 2 Red

set nf [open out.nam w]

$ns namtrace-all $nf

set nd [open out.tr w]

$ns trace-all $nd

proc finish {} {

global ns nf nd
$ns flush-trace
close $nf
close $nd
exec nam out.nam &
exit 0
}

set s1 [$ns node]

set s2 [$ns node]

set r [$ns node]

set d [$ns node]

$ns duplex-link $s1 $r 2Mb 10ms DropTail

$ns duplex-link $s2 $r 2Mb 10ms DropTail
$ns duplex-link $r $d 1.7Mb 20ms DropTail

$ns queue-limit $r $d 10

$ns duplex-link-op $s1 $r orient right-down

$ns duplex-link-op $s2 $r orient right-up
$ns duplex-link-op $r $d orient right

$ns duplex-link-op $r $d queuePos 0.5

set tcp [new Agent/TCP]

$ns attach-agent $s1 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $d $sink
$ns connect $tcp $sink

$tcp set fid_ 1

set ftp [new Application/FTP]

$ftp attach-agent $tcp
$ftp set type_ FTP

set udp [new Agent/UDP]

$ns attach-agent $s2 $udp
set null [new Agent/Null]
$ns attach-agent $d $null
$ns connect $udp $null

$udp set fid_ 2

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp
$cbr set type_ CBR

$cbr set packet_size_ 1000

$cbr set rate_ 1mb

$cbr set random_ false

$ns at 0.1 "$cbr start"

$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"

$ns at 4.5 "$ns detach-agent $s1 $tcp"

$ns at 4.5 "$ns detach-agent $d $sink"

$ns at 5.0 "finish"

$ns run

 

程序运行图

 

out.tr部分记录:

+ 0.1 1 2 cbr 1000 ------- 2 1.0 3.1 0 0

- 0.1 1 2 cbr 1000 ------- 2 1.0 3.1 0 0

+ 0.108 1 2 cbr 1000 ------- 2 1.0 3.1 1 1

- 0.108 1 2 cbr 1000 ------- 2 1.0 3.1 1 1

r 0.114 1 2 cbr 1000 ------- 2 1.0 3.1 0 0

 

 

数据格式如下:

 

r:receive(at to-node)                      src-addr:node.port

+:enqueue(at queue)                          dst-addr:node.port

-:dequeue(at queue)

d:drop(at queue)

以上述第一行数据为例,大概就是说有一个封包packet id 为0,资料流id为2,序号为0,长度为1000字节,type为 CBR ,它是从来源端1.0要到目的地3.1,在时间0.1秒的时候,从节点1(s2)进入了节点2(r)的队列中。

 

to be continued

转载于:https://www.cnblogs.com/xlchen/p/4151366.html

你可能感兴趣的文章
Apache HTTP Server搭建虚拟主机
查看>>
(译).NET4.X 并行任务中Task.Start()的FAQ
查看>>
git log显示
查看>>
java中相同名字不同返回类型的方法
查看>>
Rails NameError uninitialized constant class solution
查看>>
Android 获取SDCard中某个目录下图片
查看>>
设置cookies第二天0点过期
查看>>
【转载】NIO客户端序列图
查看>>
poj_2709 贪心算法
查看>>
【程序员眼中的统计学(11)】卡方分布的应用
查看>>
文件夹工具类 - FolderUtils
查看>>
http://blog.csdn.net/huang_xw/article/details/7090173
查看>>
lua学习例子
查看>>
研究:印度气候变暖速度加剧 2040年或面临重灾
查看>>
python爬虫——爬取豆瓣TOP250电影
查看>>
C++与Rust操作裸指针的比较
查看>>
了解webpack-4.0版本(一)
查看>>
如何培养良好的编程风格
查看>>
Netty Channel源码分析
查看>>
基于 HTML5 WebGL 的 3D 机房
查看>>