顯示具有 ns2 標籤的文章。 顯示所有文章
顯示具有 ns2 標籤的文章。 顯示所有文章

2011年6月9日 星期四

NS2 計算電量

想要在ns2裡面,模擬節點的power consumption,
首先,先確定自己的NS2版本夠新,有安裝到新版的 energy module,
ns-2.29版以後的應該沒問題。
若不確定,請依照 energy model網頁 所寫,
看一下ns-2/trace/cmu-trace.cc 檔是不是網頁上的新版。

接下來,參考ns2網頁提供的 tcl 檔
在一開始的時候,給定每個節點多少watt的電量,
然後在  $ns_ node-config 之處,設定
energyModel $opt(energymodel) \ macTrace ON \......等等
p.s 原來的tcl,在MAC層跑的是Mac/SMAC,
但大部分我們跑的都是 Mac/802_11,
只要直接將名字取代就可以了。

這樣模擬在跑時,就會把trace記錄下來,
同時顯示動作之後,有動作的節點的剩餘電量。
模擬跑完後,打開記錄檔可以發現,
每當傳送或接收封包,節點電量就會減少,
就可以由剩餘電量倒推耗電量。

當模擬一久,trace檔會非常龐大,
我跑了3000秒,trace檔就高達3.2G...
請先有心理準備......

由於trace檔的格式,會同時具有routing 以及電量的顯示,
兩個格式不一樣,若要parse也要小心處理。
Trace format 請參考 這裡,移動以及電量的格式則是這裡

這樣就可以初步估算出電量,
但若想更精準的依照封包大小扣除電量,
則要花時間去trace ns-2/mac/wireless-phy.{h,cc}, ns-2/mobile/energy-model.{h,cc} 這些檔案了,請原諒我還沒有時間去看^^""
 
--
相關網頁:
http://www.isi.edu/ilense/software/smac/ns2_energy.html
http://www.ptt.cc/bbs/Network_Sim/M.1248944220.A.CB7.html
http://nsnam.isi.edu/nsnam/index.php/NS-2_Trace_Formats


2010年8月30日 星期一

讓 Source Insight 認得副檔名 .cc 的文件

Source Insight 的好用應該不用我再多說:P
可是對於寫NS2程式的人來說,卻有一點點不方便,
因為預設不認得 .cc 的文件,不會用C++的語法來顯示,
.cc 看起來就只是一般的文字檔,完全喪失用Source Insight寫程式的優點。

其實,只要把 .cc 加入C++檔案類的File filter裡就可以囉~
步驟如下:

1. 點選 Options / Document Options
2. Document Type 選擇 C++ Source File
3. File filter 最後面,加上 , *.cc
    也就是用逗號隔開最後一類檔案,再加上 *.cc (所有.cc)類的文件
4. 確認一下 Parsing Language 是使用C++ Language,最後 Close即可。



參考網頁:
http://www.wretch.cc/blog/JTpanda/13512203

2010年7月22日 星期四

NS2 以setdest產生節點移動檔

使用版本:ns-2.34
位置:~/ns-allinone-2.34/ns-2.34/indep-utils/cmu-scen-gen/setdest/

資料夾內的 README 有教如何產生mobility檔案,
原例如下:


Run setdest with arguments as shown below:
./setdest [-v version of setdest; 1 for original 1999 C    MU version or 2 for modified 2003 U.Michigan version ]
[-n num_of_nodes] [-p pausetime] [-s maxspeed] [-t simtime] [-x maxx] [-y maxy] > [outdir/movement-file]

Example: ./setdest -v 1 -n 20 -p 2.0 -s 10.0 -t 200 -x 500 -y 500 > scen-20-test
and the output will be written in a file called scen-20-test.


然而,README範例內容寫錯了,正確應是 [-M maxspeed]
注意 -M 才是設定最大速度的方式。


且由於setdest.cc檔已修改過,所以參數部分可以有更多選擇。
若是要使用第二種移動檔產生方式(v2 modified at 2003 by J. Yoon of U.Michigan),
參數的使用可改成:

./setdest [-v 2 (for modified 2003 U.Michigan version) ]
[-n num_of_nodes] [-p pausetime] [-s speedtype] [-m minspeed] [-M maxspeed] [-P pausetype] [-t simtime] [-x maxx] [-y maxy]

注意,在第二種移動方式中, -s 為選擇 speed type,-m -M 才是分別設定最小跟最大速度的方式。

若想要分別大量產生 v1 及 v2 的移動檔,
可以使用make-scen.csh (v1) 跟 make-scen-steadystate.csh (v2)。

2010年3月16日 星期二

如何在 ubuntu 9.10,安裝 ns-2.34

參考網頁:
http://ns-2.blogspot.com/2009/11/how-to-install-ns-234-on-ubuntu-910.html

第一步:從 Sourceforge下載ns-allinone-2.34.tar.gz

第二步:放在local端,ex: /home/NS2,解壓縮
$ cd /home/NS2
$ tar -zxvf ns-allinone-2.34.tar.gz

第三步:安裝一些其他必要的檔案
$ sudo apt-get install build-essential autoconf automake libxmu-dev

第四步:安裝ns2
$ cd ns-allinone-2.34
$ ./install

第五步:如果出錯了,是由於otcl-1.13 和 gcc-4.4.1/g++-4.4.1 (ubuntu 9.10內建的版本)不太合,無法compile,所以需要改安裝 g++-4.3版
$ sudo apt-get install g++-4.3
$ CC=gcc-4.3 CXX=g++-4.3 ./install

接著,還要再修改otcl資料夾內的Makefile.in
$ cd otcl-1.13
$ sudo gedit Makefile.in

把第7行的 CC= 改掉
From :
CC= @CC@

To:
CC= gcc-4.3

存檔後離開。

$ cd .. (應該會回到 ns-allinone-2.34資料夾底下)
$ ./install

第六步:修改環境變數、path
$ gedit ~/.bashrc

將以下幾行加在檔案的最後面,/home/NS2/ 則必須根據你自己的檔案名做更改。
ns2安裝完成後,最後面會提醒你要修改.bashrc,如果不知道/home/NS2/ 要替換成什麼,請參考ns2給的path。

# LD_LIBRARY_PATH
OTCL_LIB=/home/NS2/ns-allinone-2.34/otcl-1.13
NS2_LIB=/home/NS2/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB

# TCL_LIBRARY
TCL_LIB=/home/NS2/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB

# PATH
XGRAPH=/home/simulator/ns-allinone-2.34/bin:/home/simulator/ns-allinone-2.34/tcl8.4.18/unix:/home/simulator/ns-allinone-2.34/tk8.4.18/unix
NS=/home/simulator/ns-allinone-2.34/ns-2.34/
NAM=/home/simulator/ns-allinone-2.34/nam-1.14/
export PATH=$PATH:$XGRAPH:$NS:$NAM

第七步:驗證是否安裝成功
$ cd ns-2.34
$ ./validate

完成後會出現:
validate overall report: all tests passed

恭喜 :)
--
如果仍然不行,請參考這個網頁所給的第二種方法,然後再./install一次

2008年9月13日 星期六

NS2內DSDV疑似bug造成無窮迴圈的修正

最近在跑NS2,一開始跑很久都跑不完,
我還不以為意,以為是scenario太複雜,所以要跑很久...。
直到那天我放著模擬跑,人出去看電影,回來發現竟然還在跑(驚!),
我才覺得不對勁(也太遲鈍了吧.....囧)
反覆檢查後發現,程式在DSDV內會進入無窮迴圈,導致怎麼跑都跑不完。
於是就把dsdv.cc打開來修改一下:
ns-2.x/dsdv/dsdv.cc

void DSDV_Agent::processUpdate (Packet * p) function內,
約791行附近,有個 if 判斷這麼寫著:

// see if we can send off any packets we've got queued
if (rte.q && rte.metric != BIG)
{
Packet *queued_p;
while ((queued_p = rte.q->deque()))
// XXX possible loop here
// while ((queued_p = rte.q->deque()))
// Only retry once to avoid looping
// for (int jj = 0; jj <>length(); jj++){
// queued_p = rte.q->deque();
recv(queued_p, 0); // give the packets to ourselves to forward
// }
delete rte.q;
rte.q = 0;
table_->AddEntry(rte); // record the now zero'd queue
}


猜測這邊就是infinite loop形成的原因。
本來應該是要將queue裡面積存的packet取出然後送出,
可是會造成while永遠為true,形成無窮迴圈,bug就產生啦。
將它改成以下,應該就沒問題了


// see if we can send off any packets we've got queued
if (rte.q && rte.metric != BIG)
{
Packet *queued_p;
printf("DEGUB => in DSDV_Agent::processUpdate:795, rte.q->length()= %d\n",rte.q->length() );
//printf is only for debug :P

Packet** temp_array = new Packet*[rte.q->length()] ;

for(int i=0; i< rte.q->length(); i++){
temp_array[i] = rte.q->deque();
}

for(int i=0; i< rte.q->length(); i++){
recv(temp_array[i], 0);
}

delete rte.q;
rte.q = 0;
table_->AddEntry(rte); // record the now zero'd queue
}


//--
萬分感謝千益學弟,以及gdb的幫忙^_________^

至於blog中顯示程式碼區塊的方法,請參考:p
http://hdj-berkeley.blogspot.com/2008/06/blog.html

2008年8月14日 星期四

讓 UltraEdit 認得 tcl 語法

打開 UltraEdit 的語法檔案 wordfile.txt
一般是在 C:\Program Files\IDM Computer Solutions\UltraEdit-32\wordfile.txt
將以下的文字複製後,貼在 wordfile.txt 最後面即可。

/L20"Tcl/tk" Line Comment = # String Chars = "' Escape Char = \ DisableMLS File Extensions = TCL TK
/Delimiters = ~!@%^&*()+=|\/{}[]:;"' <> ,?#
/Function String = "proc ^([a-zA-Z_0-9]++ {[ a-zA-Z_0-9{}]++^)"
/Function String 1 = "method ^([a-zA-Z_0-9]++ {[ a-zA-Z_0-9{}]++^)"
/Function String 2 = "^(constructor^) {*}*{"
/Function String 3 = "^(destructor^) {}"
/Function String 4 = "public ^(variable[ ^t]+[a-zA-Z_0-9]+^)"
/Function String 5 = "public ^(common[ ^t]+[A-Z_0-9]+^)"
/Indent Strings = "{"
/Unindent Strings = "}"
/Open Brace Strings = "{" "(" "["
/Close Brace Strings = "}" ")" "]"
/Open Fold Strings = "{"
/Close Fold Strings = "}"
/C1"Commands"
after append array auto_execok auto_load auto_mkindex auto_reset
bgerror break
case catch cd class clock close common concat constructor continue
destructor
else elseif eof error eval exec exit expr
fblocked fconfigure file fileevent flush for foreach format
gets glob global
history
if incr info inherit interp
join
lappend lindex linsert list llength load lrange lreplace lsearch lsort
method
open
package parray pid private proc protected public puts pwd
read regexp regsub rename return
scan seek set socket source split string subst switch
tcl_endOfWord tcl_startOfNextWord tcl_startOfPreviousWord
tcl_wordBreakAfter tcl_wordBreakBefore tell time
trace
unknown unset update uplevel upvar
variable vwait
while
/C2"Library Variables"
ErrorCode ErrorInfo
auto_execs auto_index auto_noexec auto_noload auto_path
env
tcl_library tcl_nonwordchars tcl_patchLevel tcl_pkgPath tcl_platform
tcl_precision tcl_rcFileName tcl_rcRsrcName tcl_version tcl_wordchars
unknown_active
/C3"Keywords"
bell bind bindtags bitmap button
canvas checkbutton clipboard
destroy
entry event
focus frame
grab grid
image
label listbox lower
menu menubutton message
option
pack photo place
radiobutton raise
scale scrollbar selection send
text tk tk_bindForTraversal tk_bisque tk_chooseColor tk_dialog tk_focusFollowsMouse
tk_focusNext tk_focusPrev tk_getOpenFile tk_getSaveFile tk_menuBar tk_messageBox
tk_optionMenu tk_popup tk_setPalette tkerror tkvars tkwait toplevel
winfo wm
/C4"Variable Substitutions"
** $
/C5"Delimiters"
!
%
&
(
)
*
+
,
// /
:
;
< = >
?
@
[
]
^
{
|
}
~



//參考網頁
http://hi.baidu.com/wirelesscat/blog/item/3ca99723cd1d05579822ed9a.html
Related Posts with Thumbnails