2012年3月27日 星期二

NS-2 on Fedora 14設定傳輸範圍

2007.10.22
許多人在做NS2的wireless部分時,通常都會發現傳輸範圍到底該如何做設定,這也困惑了我很久
所以整理了這篇來詳述我找到的做法~也很感謝傅冠提供了網管人2007.September P.122~P.127

在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
Phy/WirelessPhy set RXThresh_ 3.652e-10
Phy/WirelessPhy set bandwidth_ 2e6
Phy/WirelessPhy set Pt_ 0.28183815
Phy/WirelessPhy set freq_ 914e+6
Phy/WirelessPhy set L_ 1.0

Phy/WiredPhy set bandwidth_ 10e6


人家都說NS預設傳送/接收範圍 = 250m/550m,但是從這個預設值來看
似乎還看不出有什麼關聯性,沒有250也沒有550呀!到底是什麼一回事呢?

原來它是經由一個公式算出來的
RXThresh_是節點可傳送到的範圍
CSThresh_是節點可監聽到附近網路活動的範圍
而那個公式就存在C:\cygwin\home\Administrator\ns-allinone-2.30\ns-2.30\indep-utils\propagation\threshold.cc
打開後你會發現:

double TwoRay(double Pt, double Gt, double Gr, double ht, double hr, double L, double d, double lambda)
{
/*
* if d < crossover_dist, use Friis free space model
* if d >= crossover_dist, use two ray model
*
* Two-ray ground reflection model.
*
* Pt * Gt * Gr * (ht^2 * hr^2)
* Pr = ---------------------------- * d^4 * L *
* The original equation in Rappaport's book assumes L = 1.
* To be consistant with the free space equation, L is added here.
*/

double Pr; // received power
double crossover_dist = (4 * M_PI * ht * hr) / lambda;

if (d < crossover_dist)
Pr = Friis(Pt, Gt, Gr, lambda, L, d);
else
Pr = Pt * Gt * Gr * (hr * hr * ht * ht) / (d * d * d * d * L);

return Pr;
}
沒錯這就是我們的公式,其中:
Pr就是我們要的RXThresh,它代表的就是我們要的傳輸距離
Pt = transmit power
Gt = transmit antenna gain
Gr = receive antenna gain
ht = transmit antenna height
hr = receive antenna height
d = distance (例如250m)

我們將使用threshold.cc來換算出RXThresh _值 (CSThresh_同理)
步驟:
1. 在Cygwin下找到threshold.cc後,將他編譯(在這裡我把他叫test,這時會在同一個資料夾下出現一個test.exe)



P.S.:如果在這個編譯的過程中出現了錯誤訊息,是因為這版本的g++不認識iostream.h 檔。
解決方式是,將 threshold.cc 檔打開,將原本的 #include iostream.h 刪除,然後加入下面三列指令,最後將儲存起來:

儲存後,重新執行g++ threshold.cc -o test

2. 以下是執行的格式,其中other-options可以不用,最後的distance,初始設定以公尺為單位
如果我們要傳輸距離為100m,我們就鍵入100


最後程式幫我們算出RXThresh_,就可以在腳本裡面做傳輸範圍的設定囉!

EX :
#設定trace file
set ns [new Simulator] ;#產生ns simulator
Phy/WirelessPhy set RXThresh_ 1.42681e-08 ;#設定傳輸範圍為 100m

後記:因為程式裡有小數點精準度的小誤差,如果自己用公式寫一支程式來測試會比較準哦!

參考資料:http://ns2lab.pixnet.net/blog/post/10050300
                    http://www.redmaple.idv.tw/index.php/archives/212

2012年3月26日 星期一

NS2.35 on Fedora 14 執行nam檔



若無法運行nam檔, cd到ns-allinone-2.35/ns-2.35的目錄下先登錄root(打su)在執行make install
terminal shows

for d in /usr/local/man/man1; do \
if [ ! -d $d ]; then \
mkdir -p $d ;\
fi;\
done
/usr/bin/install -c -m 755 ns /usr/local/bin
/usr/bin/install -c -m 644 ns.1 /usr/local/man/man1

subsequently, cd到 ns-allinone-2.35/nam-1.15(nam目錄下), 一樣在root權限下執行make install
terminal shows

/usr/bin/install -c -m 755 nam /usr/local/bin

把ns和nam的路徑添加到系统路徑下(通常ns和nam只依賴於usr/lib下)then OK