有线网络四节点(星型拓扑,UDP连接,带宽测量)
来源:互联网 发布:3dstart软件下载 编辑:程序博客网 时间:2024/06/01 10:51
实现4节点星型网络场景中网络带宽的测量,给出模拟过程中带宽变化情况的曲线图(Xgraph绘制)!
链接:http://blog.chinaunix.net/u3/105477/showart_2087772.html
学习的知识点:
#场景描述:
#有线新星结构, 四节点, 三条UDP连接,中心节点公用
#测量模拟过程中,各条UDP连接的带宽!
#以下是一些基本设置,在看过NS系列--NS2入门实例1、2、3之后,阅读肯定没问题的啦!
set ns [new Simulator]
set tracefd [open trace.tr w]
$ns trace-all $tracefd
set namtracefd [open namtrace.nam w]
$ns namtrace-all $namtracefd
set f0 [open out0.tr w]
set f1 [open out1.tr w]
set f2 [open out2.tr w]
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
$ns duplex-link $n0 $n3 1Mb 100ms DropTail
$ns duplex-link $n1 $n3 1Mb 100ms DropTail
$ns duplex-link $n2 $n3 1Mb 100ms DropTail
$ns duplex-link $n4 $n3 1Mb 100ms DropTail
#参数的意义: node sink size burst idle rate
# node:数据流的发起节点
# sink:数据流对应的接收代理
# size、idle、rate:数据包大小、idle时间、发包速率
proc attach-expoo-traffic { node sink size burst idle rate } {
#生成simulator实例对象,用于整个仿真过程
set ns [Simulator instance]
#创建UDP代理,并与soure节点相关联
set source [new Agent/UDP]
$ns attach-agent $node $source
#Create an Expoo traffic agent and set its configuration parameters
set traffic [new Application/Traffic/Exponential]
$traffic set packetSize_ $size
$traffic set burst_time_ $burst
$traffic set idle_time_ $idle
$traffic set rate_ $rate
# Attach traffic source to the traffic generator
$traffic attach-agent $source
#Connect the source and the sink
$ns connect $source $sink
return $traffic
}
proc record {} {
#注意:自己写采样过程时,把要用到的变量做声明很重要!
global sink0 sink1 sink2 f0 f1 f2
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.5
#How many bytes have been received by the traffic sinks?
set bw0 [$sink0 set bytes_]
set bw1 [$sink1 set bytes_]
set bw2 [$sink2 set bytes_]
#Get the current time
set now [$ns now]
#Calculate the bandwidth (in MBit/s) and write it to the files
puts $f0 "$now [expr $bw0/$time*8/1000000]"
puts $f1 "$now [expr $bw1/$time*8/1000000]"
puts $f2 "$now [expr $bw2/$time*8/1000000]"
#Reset the bytes_ values on the traffic sinks
#这点很重要,以重新采样时不受前一次的影响,与NS2实现机制有关,暂时可忽略!
$sink0 set bytes_ 0
$sink1 set bytes_ 0
$sink2 set bytes_ 0
#Re-schedule the procedure
$ns at [expr $now+$time] "record"
}
#LossMonitor的特点:?
set sink0 [new Agent/LossMonitor]
set sink1 [new Agent/LossMonitor]
set sink2 [new Agent/LossMonitor]
$ns attach-agent $n4 $sink0
$ns attach-agent $n4 $sink1
$ns attach-agent $n4 $sink2
#调用过程proc attach-expoo-traffic { node sink size burst idle rate }
#可以很方便的设置同一类型的数据流
set source0 [attach-expoo-traffic $n0 $sink0 200 2s 1s 100k]
set source1 [attach-expoo-traffic $n1 $sink1 200 2s 1s 200k]
set source2 [attach-expoo-traffic $n2 $sink2 200 2s 1s 300k]
proc finish {} {
global f0 f1 f2 tracefd namtracefd
close $f0
close $f1
close $f2
close $tracefd
close $namtracefd
exec nam namtrace.nam &
#Call xgraph to display the results
exec xgraph out0.tr out1.tr out2.tr -geometry 800x400 &
exit 0
}
$ns at 0.0 "record"
$ns at 10.0 "$source0 start"
$ns at 10.0 "$source1 start"
$ns at 10.0 "$source2 start"
$ns at 50.0 "$source0 stop"
$ns at 50.0 "$source1 stop"
$ns at 50.0 "$source2 stop"
$ns at 60.0 "finish"
$ns run
- 有线网络四节点(星型拓扑,UDP连接,带宽测量)
- 有线网络,(七节点环形拓扑,动态路由协议DV的演示)
- 有线局域网拓扑结构――星型结构(三、四)
- 网络测量和拓扑发现
- 网络拓扑结构设计(四)
- ubuntu9.04 有线网络连接
- 树莓派连接有线网络配置
- 生成网络节点拓扑场景
- 节点的网络拓扑距离
- Ubuntu有线网络无法连接解决
- fedora 有线网络连接问题
- Ubuntu有线网络无法连接解决
- raspberry pi 的 有线网络连接
- 判断有线网络连接的方式
- ubuntu14.4.04无法连接有线网络
- Ubuntu有线网络无法连接—有线网络连接图标变为灰色,无法点击
- 有线局域网拓扑结构――环型结构(三)
- 带宽测试初探(UDP发包方式)
- 颜色#RRGGBB与string 相互转换
- 数据结构顺序表
- 动态添加控件的事件可以写在类中
- zsniff
- 'CONVERSION_EXIT_ATINN_INPUT' 什么用?
- 有线网络四节点(星型拓扑,UDP连接,带宽测量)
- web中缓存的使用
- IP划分方法
- SQL Server数据库锁机制及类型
- http://v.youku.com/v_show/id_XMTUyNzg4NzU2.html
- Java Socket编程
- MyEclipse安装后一定要做的几件事-如改变文件编码
- MFC文档视图结构内幕
- C# 二进制、十进制、十六进制互转