ns 覆盖范围 RXThresh的计算
在../tcl/lib/ns-default.tcl中,有如下几行:
# Initialize the SharedMedia interface with parameters to make
# it work like the 914MHz Lucent WaveLAN DSSS radio interface
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 1.559e-11 ;#550m
Phy/WirelessPhy set RXThresh_ 3.652e-10 ;#250m
Phy/WirelessPhy set bandwidth_ 2e6 ;#2Mbps
Phy/WirelessPhy set Pt_ 0.28183815 ;#传输功率
Phy/WirelessPhy set freq_ 914e+6
Phy/WirelessPhy set L_ 1.0
默认载波侦听距离为550米,无线节点覆盖范围250米,带宽2Mbps
RXThresh_ 门限的生成可以使用NS中的~ns/indep-utils/propagation/threshold.cc文件来生成可执行文件 a.out
具体方法如下:
先进入文件夹,找到threshold.cc文件
[root@localhost propagation]# g++ threshold.cc
生成了a.out文件
附:1. 要执行 ./a.out即可
是因为环境变量 $PATH 中没有当前目录;
也可以 $set $PATH=$PATH:当前目录(比如/home/you)
2. 编译c用 gcc 命令
编译c++ 用 g++ 命令
然后假如要生成RXThresh_ 为 100m,则
使用的是TwoRayGround模型
[root@localhost propagation]# ./a.out -m TwoRayGround -r 0.95 100
则可得到要用的门限
[root@localhost propagation]# ./a.out -m TwoRayGround -r 0.95 100
distance = 100
propagation model: TwoRayGround
Selected parameters:
transmit power: 0.281838
frequency: 9.14e+08
transmit antenna gain: 1
receive antenna gain: 1
system loss: 1
transmit antenna height: 1.5
receive antenna height: 1.5
Receiving threshold RXThresh_ is: 1.42681e-08
红色的即为所要的值
附:使用说明
USAGE: find receiving threshold for certain communication range (distance)
SYNOPSIS: threshold -m <propagation-model> [other-options] distance
<propagation-model>: FreeSpace, TwoRayGround or Shadowing
[other-options]: set parameters other than default values:
Common parameters:
-Pt <transmit-power>
-fr <frequency>
-Gt <transmit-antenna-gain>
-Gr <receive-antenna-gain>
-L <system-loss>
For two-ray ground model:
-ht <transmit-antenna-height>
-hr <receive-antenna-height>
For shadowing model:
-pl <path-loss-exponent>
-std <shadowing-deviation>
-d0 <reference-distance>
-r <receiving-rate>
用法如下 :
root@ubuntu:~/ns-allinone-2.34/ns-2.34/indep-utils/propagation$ ./threshold
USAGE: find receiving threshold for certain communication range (distance)
SYNOPSIS: threshold -m <propagation-model> [other-options] distance
<propagation-model>: FreeSpace, TwoRayGround or Shadowing //三种传输模型
[other-options]: set parameters other than default values: //以下参数均可自行配置
Common parameters:
-Pt <transmit-power>
-fr <frequency>
-Gt <transmit-antenna-gain>
-Gr <receive-antenna-gain>
-L <system-loss>
For two-ray ground model:
-ht <transmit-antenna-height>
-hr <receive-antenna-height>
For shadowing model:
-pl <path-loss-exponent>
-std <shadowing-deviation>
-d0 <reference-distance>
-r <receiving-rate>
该程序的是用C++编写的,位于NS2文件夹下的 ns-allinone-2.34/ns-2.34/indep-utils/propagation/.
程序源码需要编译才能运行:
$g++ -lm threshold.cc -o threshold
然而本人在编译时出现问题:
root@ubuntu:~/ns-allinone-2.34/ns-2.34/indep-utils/propagation$ g++ -lm threshold.cc -o threshold
threshold.cc:56:22: error: iostream.h: 没有那个文件或目录
threshold.cc: In function ‘int main(int, char**)’:
threshold.cc:181: error: ‘cout’ was not declared in this scope
threshold.cc:181: error: ‘endl’ was not declared in this scope
threshold.cc:206: error: ‘cout’ was not declared in this scope
threshold.cc:206: error: ‘endl’ was not declared in this scope
threshold.cc:211: error: ‘strcmp’ was not declared in this scope
threshold.cc:215: error: ‘strcmp’ was not declared in this scope
threshold.cc:218: error: ‘strcmp’ was not declared in this scope
threshold.cc:221: error: ‘strcmp’ was not declared in this scope
threshold.cc:224: error: ‘strcmp’ was not declared in this scope
threshold.cc:227: error: ‘strcmp’ was not declared in this scope
threshold.cc:230: error: ‘strcmp’ was not declared in this scope
threshold.cc:233: error: ‘strcmp’ was not declared in this scope
threshold.cc:236: error: ‘strcmp’ was not declared in this scope
threshold.cc:239: error: ‘strcmp’ was not declared in this scope
threshold.cc:242: error: ‘strcmp’ was not declared in this scope
threshold.cc:245: error: ‘strcmp’ was not declared in this scope
threshold.cc:259: error: ‘strcmp’ was not declared in this scope
排查问题发现,threshold.cc源文件中缺少相关头文件,或者头文件错误,原文如下:
#include <math.h>
#include <stdlib.h>
修改成如下就可以正常编译了:
#include <math.h>
#include <stdlib.h>
#include <iostream> //增加该头文件以引用输出函数
#include <string.h> //增加该头文件以引用'strcmp'函数
using namespace std; //增加命名空间的声明