生成节点场景的方法

本文详细介绍了如何通过自定义生成节点位置文件,利用nsgenscen工具创建随机网络拓扑,并在LeaCH协议测试脚本中应用。包括节点位置文件的创建、修改与重命名过程,以及对不同拓扑尺寸的分析比较。通过生成的100节点网络拓扑,展示了在1000*1000范围内与100*100范围内的节点通信能量消耗差异,并通过gnuplot工具进行了可视化呈现。
生成节点场景的方法是,在mit/uAMPS/sims目录下有一个名为genscen的文件,该文件是用来生成节点的场景文件,这个可以在leach_test脚本中找到。
# leach_test
……
#Topology
#  This file is the scenario that we are going to run.
#  This file can be editted manually if you are very careful to create
#  a predefined topology.  To generate a random topology go to the
#  ./mit/uAMPS/sims directory and run 'ns genscen'.
topology_file="mit/uAMPS/sims/100nodes.txt"
……
ns tcl/ex/wireless.tcl  /
-sc mit/uAMPS/sims/nodescen /
-rp $alg /
-x $x /
-y $y /
-nn $nn /
-stop $stop /
-eq_energy $eq_energy /
-init_energy $init_energy /
-filename $filename /
-dirname $dirname /
-topo $topology_file /
-num_clusters $num_clusters /
-bs_x $bs_x /
-bs_y $bs_y 2>$dirname/$filename.err 1>$dirname/$filename.out &

进入mit/uAMPS/sims目录下,发现在运行./test之前就事先存在一个100nodes.txt文件,把它删除,我们自己也可以手动运行ns genscen来生成一个新的new100nodes.txt文件,这个文件里保存的就是随机生成的100个节点的位置信息,内容类似如下:
65.745973803916002    92.581722416254564
21.008649990432268    92.380389195112684
37.201202259027028    40.606367467253641
71.218022131928251    61.297971318148988
35.003944130150579    11.288995440718249
……

【注意】从leach_test脚本可知,100nodes.txt文件是事先生成好的, 如果这个文件不存在的话,运行./test会在leach.err文件中发现如下错误信息:
# leach.err
INITIALIZE THE LIST xListHead
couldn't open "mit/uAMPS/sims/100nodes.txt": no such file or directory
    while executing
"open $opt(topo) r"
    invoked from within
"set filename [open $opt(topo) r]"
    (file "mit/uAMPS/sims/nodescen" line 3)
    invoked from within
"source.orig mit/uAMPS/sims/nodescen"
    ("uplevel" body line 1)
    invoked from within
"uplevel source.orig [list $fileName]"
    invoked from within
"if [$instance_ is_http_url $fileName] {
set buffer [$instance_ read_url $fileName]
uplevel eval $buffer
} else {
uplevel source.orig [list $fileName]
..."
    (procedure "source" line 8)
    invoked from within
"source $opt(sc)"
    invoked from within
"if { $opt(sc) == "" } {
    puts "*** NOTE: no scenario file specified."
        set opt(sc) "none"
} else {
    puts "Loading scenario file..."
    source $op..."
    (file "tcl/ex/wireless.tcl" line 293)

打开事先存在的100nodes.txt文件,发现节点的位置信息是在100*100的范围内,但是从leach_test脚本中,却发现x=1000 y=1000,即是在1000*1000的范围内。所以打开genscen文件进行修改:
# genscen
set outf [open "new100nodes.txt" w]
set num_nodes 100
set rng [new RNG]
$rng seed 0
# set lim 100
set lim 1000 # modified

for {set i 1} {$i <= $num_nodes} {incr i} {
    set x [$rng uniform 0 $lim]
    set y [$rng uniform 0 $lim]
    puts $outf "$x/t$y"
}
修改后切换到~/ns-allinone-2.27/ns-2.27/mit/uAMPS/sims路径下,重新运行ns genscen来生成一个新的new100nodes.txt文件,打开后内容类似如下:
878.56345711209042    853.09648879482245
443.34628593332428    208.33796365574838
31.64275643957907    710.22841646812321
527.89944202075685    348.46698834955089
859.54059840158595    567.67113533228223
……
【注意】leach_test脚本的设置的文件名为100nodes.txt,所以要将新生成的文件new100nodes.txt重命名为100nodes.txt,然后再./test才能成功。

使用gnuplot工具对修改后的100nodes.txt进行画图显示如下:

pic

对于1000*1000的网络拓扑,由于距离加大了,相对于100*100的网络拓扑节点通信消耗的能量更多。
通过对1000*1000的leach.alive分析可以看出,在time=81s的时候,此时网络中仅有4个存活的节点。
0.000000 100
10.000000 91
20.000000 83
30.000000 67
40.000000 67
50.000000 34
60.000000 26
70.000000 14
80.000000 10
81.200000 4
图示如下:
pic

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值