雲端計算與網路 - Final Project Reporter: Green Advisor: Hsueh-Wen Tseng
Outline What is NS2 How to use NS2 NS2 安裝 NS2 程式語法 NS2 的 Tracefile 解析 How to do a final project Example: localclfs.tcl
What is NS2 3
What is NS2 4
What is NS2 5
How to Use NS2 The Network Simulator: NS2 介紹 : http://www.isi.edu/nsnam/ns/ns-build.html 下載 : http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone- 2.35.tar.gz/download?use_mirror=ncu&r=http%3A%2F%2Fwww.isi.edu%2Fnsnam%2Fns%2Fnsbuild.html&use_mirror=ncu Allinone 的 packetage 所有的 library 都包在裡面 目前最新版本 : 2.35 不同的套件會有版本相依性問題, 建議根據所使用的程式檔需求去安裝 NS2 版本
How to Use NS2 確認是否下載 解壓縮 tar zxvf ns-allinone-2.35.tar.gz // 解壓縮指令 sudo apt-get install build-essential autoconf automake libxmu-dev // 安裝相關套件 sudo apt-get install 是管理者權限, 所以要輸入密碼 之後就一直輸入 y 按 enter 即可 安裝套件
How to Use NS2 // 因為原本 ns-allinone-2.35, 適合裝在 ubuntu12.04, 但如果裝在 ubuntu14.04, 就區要改必須要修改某些 library 語法 cd ns-allinone-2.35 cd ns-2.35/linkstate/ls.h 把第 143 行的 void earseall(){erase (basemap::begin(), basemap::end());} 改為 void earseall(){this->erase (basemap::begin(), basemap::end());} cd../.. // 回到 ns-allinone-2.35 目錄下
How to Use NS2 在 ns-allinone-2.35 目錄下 執行./install 執行完後, 打開 /home/ 使用者 /.bashrc, 在檔案末端增加環境變數 export PATH="$PATH:/home/ 使用者 /ns-allinone-2.35/bin:/home/ 使用者 /ns-allinone-2.35/tcl8.5.1 0/unix:/home/ 使用者 /nsallinone-2.35/tk8.5.10/unix" export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/ 使用者 /ns-allinone-2.35/otcl-1.14, /home/newliv ing/ns-allinone- 2.35/lib" export TCL_LIBRARY="$TCL_LIBRARY:home/ 使用者 /nsallinone-2.35/tcl8.5.10/library 修改完後, 執行 source.bashrc, 使其立即生效
How to Use NS2 只要在使用者目錄下輸入 ns, 會出現 % 的符號就代表成功 為了確保內部的 library 是否有問題 可以進入 ns-2.35 的目錄下 輸入./validate, 驗證每個 library 範例程式碼 : ns-allinone-2.35.tar\ns-allinone-2.35\ns-allinone-2.35\ns- 2.35\tcl\ex
How to Use NS2 簡單語法教學 註解 #set RTT 0.0001 // 將該行註解 顯示變數 puts RTT $RTT // 顯示 RTT 的值 ($RTT) 設定變數 set B 250 // B=250 set N [lindex $argv 0] // 設定 N 由命令列輸入第一個參數 set data [list 250 2048 2048 ] // 設定 data list 其值為 250,2048,2048 set t [expr 250/$diffV] // 設定 t=250/ 變數 diffv 讀取變數 $M // 讀取變數 M [lindex $deadline $j] // 讀取 list deadline 的第 j 個值 [llength $size] //list size 的長度
簡單語法教學 If/else 表示 if {$N == 1} //if(n==1) { set diffv 1 How to Use NS2 // 設定變數 diffv=1 } For 迴圈表示 for {set i 0} {$i < $N} {incr i} //for(i=0;i<$n;i++) { set start($i) 0 // 設定陣列 start[i]=0 }
How to Use NS2 簡單語法教學 設定亂數 set rng [new RNG] // 設定亂數 $rng seed 0 // 設定亂數種子 0 表示每次重新取亂數值 set r [new RandomVariable/Uniform] // 設定亂數型態 $r use-rng $rng // 引入亂數種子 $r set min_ 1.0 // 設定亂數區間最小值 $r set max_ 1000.0 // 設定亂數區間最大值 set RTT [expr 0.0001*[$r value]] // 設定 RTT 值為 0.0001* 亂數值 設定函數 set receiver 0 // 設定函數變數初始值 proc Receiver { } { // 設定函數名稱 global ns packetmax transferno // 引入全域變數.. } $ns at $receiver Receiver // 設定何時啟動
How to Use NS2 簡單語法教學 建立節點 $ns color 0 Red // 設定顏色代號 set nqueue [$ns node] // 設定 nqueue 節點 set n($i) [$ns node] // 設定陣列 n($i) 節點 $nqueue color red // 設定 nqueue 節點為紅色 $nqueue shape box // 設定 nqueue 節點形狀為方形 set enablenam 0 // 是否顯示動畫 0 不顯示 ; 1 顯示
How to Use NS2 簡單語法教學 建立鏈結 $ns duplex-link $n($i) $nqueue $inputlinerate [expr $RTT/4] DropTail // 設定 Link 為雙向, 由 $n($i) 接到 $nqueue, 而且速率為 RTT/4, 且封包會存在 Queue 中, 滿了才 Drop $ns simplex-link $nqueue $nclient $linerate [expr $RTT/4] $switchalg // 設定 Link 為單向, 由 $nqueue 接到 $nclient, 而且速率為 RTT/4, 交換器是 $switchalg 型態 $ns queue-limit $nqueue $nclient $B // 設定從 nqueue 到 nclient 的 Queue 大小為 B set qfile [$ns monitor-queue $nqueue $nclient [open queue.tr w] $tracesamplinginterval] // 將 Queue 的狀態寫入檔案
How to Use NS2 簡單語法教學 導入流量 建立 TCP 流量 set tcp($i) [new Agent/TCP/Newreno] // 採用 TCP 的版本, 建立送端 set sink($i) [new Agent/TCPSink] // 建立收端 $ns attach-agent $n($i) $tcp($i) // 將節點和送端連結 $ns attach-agent $nclient $sink($i) // 將節點和收端連結 $tcp($i) set fid_ [expr $i] // 設定送端編號 $sink($i) set fid_ [expr $i] // 設定收端編號 $ns connect $tcp($i) $sink($i) // 收送端建立連結 建立 UDP 流量 set udp($i) [new Agent/UDP] // 採用 UDP 版本, 建立送端 $ns attach-agent $n($i) $udp($i) // 將節點和送端連結 $ns connect $udp($i) $sink($i) // 收送端建立連結
How to Use NS2 簡單語法教學 導入流量 建立 TCP 流量 set ftp($i) [new Application/FTP] // 導入 FTP 流量 $ftp($i) attach-agent $tcp($i) // 以 TCP 送 FTP 流量 $ns at $start($i) $ftp($i) send [expr [lindex $size $j]] // 設定何時傳送 FTP 流量和傳送大小 $tcp($i) set clfs_deadline_ [lindex $deadline $j] // 設定 TCP 封包的截止時間 $tcp($i) set clfs_size_ [lindex $size $j] // 設定 TCP 封包的大小 建立 UDP 流量 set cbr($i) [new Application/Traffic/CBR] // 導入固定速率流量 $cbr($i) set packetsize_ 1000000 // 設定封包大小 $cbr($i) set interval_ 0.005 // 設定傳送週期 ( 秒 ) $cbr($i) attach-agent $udp($i) // 以 UDP 傳送
How to Use NS2 簡單語法教學 寫入 Tracefile set nf [open clfs-tcptrace.ns w] ; # 設定 Tracefile 寫入檔 $ns trace-all $nf // 設定 Tracefile 寫入檔
How to Use NS2 簡單語法教學 格式參考資料 http://nsnam.isi.edu/nsnam/index.php/ns- 2_Trace_Formats 擷取 Tracefile r: 接收 +: 送入 -: 送出 d:drop 狀態 時間 來源端 封包型態 目的地 封包大小 流量編號 封包編號
How to Use NS2 簡單語法教學 擷取 Tracefile 方法 1 proc finish {} { // 執行結束寫入檔案 set result1 [exec awk {{if ($5 == "tcp") c1+=1;} END {print c1 }} clfs-tcptrace.ns] // 利用 AWK 去計算 TRACEFILE 的第五欄是 TCP 封包的 if { [string length $result1] == 0 } { // 計算 TCP 封包數目 set result1 0 } puts "TCP Packet:$result1" // 顯示 TCP 封包數目 }
How to Use NS2 簡單語法教學 擷取 Tracefile 方法 2 寫 AWK 參見 delay.awk 範例檔 執行 awk f delay.awk clfs-tcptrace.ns 善用 linux 指令和 shell script
How to Do a Final Project 和期中報告主題相符 只要一個簡單的 IDEA 即可 要秀出欲呈現的效果與效能 動畫 / 圖表
What is TCP Incast... Drop!!! 23
Case 1 What is TCP Incast LinkRate Input = 10 Gbps LinkRate output = 1 Gbps Case 2 Drop!!! 1Gbps 1Gbps 24
Related Works Modified or new TCP protocol DCTCP, D2TC Reduce RTO min Schemes in data link layer Flow control, QCN Schedule in application layer Limit the number of requests Host based control Difficult to estimate RTT 25
Cross-Layer Application Task Schedule RTT = 0.0001s = 100 μs Sender Request ACK Receiver Response ACK 26
Cross-Layer Application Task Schedule How to group??? When to send??? N... 27
Show Your Code
Simulation Results
Simulation Results