Network Simulator (NS-2)

Slides:



Advertisements
Similar presentations
Ns Tutorial 成功大學電機所電腦與網路組 博士候選人 柯志亨
Advertisements

FCU, Department of ECE, IC Design Research Lab. TEL: # 4945 Pre-SIm , Post-Sim.
資料蒐集的方法(三):實驗法(實驗設計) (第七章)
布林代數的應用--- 全及項(最小項)和全或項(最大項)展開式
3Com Switch 4500 切VLAN教學.
PowerPoint2010 李燕秋 版面配置 版面配置指的是每一個頁面的內容配置 方式,不同的版面配置會有對應的母片。
What is static?. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1; this.instanceX =
在 Ad-hoc 網路中實現點對 點發送訊息與廣播訊息. 檔案下載  範例程式可在下列網址取得  DEMO 程式可在下列網址取得
高速網路實驗室 High Speed Network Group Lab Final Project-Routing 張宜鴦.
Network Simulator 2 Tejas Vasavada.
1 Web of Science 利用指引 單元二 瀏覽與處理查詢結果. 2 瀏覽檢索結果 查出的結果,預設以時間排列, 使用者可改變結果的排列方式: 還可以依被引用次數、相關度、 第一作者、刊名、出版年等排序 回到前先查的結果畫面 點選想看資料的完整書目 本館訂購範圍的期刊 全文,便可直接連結.
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 參 實驗法.
1 Network Simulator (NS-2). 2 講義 Network Simulator (NS2) Part 1: 下載 Part 2: 安裝與測試 Part 3: 劇本 Part 4: 數據.
Graph V(G 1 )={0, 1, 2, 3, 4, 5, 6, 7, 8, 9} E(G 1 )={(0, 2), (0, 3), (1, 4), (2, 3), (2, 5), (2, 6), (3, 6), (3, 7), (4, 7), (5, 6), (5,
1 實驗二 : SIP User Mobility 實驗目的 藉由 Registra 和 Redirect Server 的設計,深入瞭解 SIP 的運 作及訊息格式。 實作部分 ( 1 )實作一個 Registrar 來接收 SIP REGISTER ,而且 要將 REGISTER 中 Contact.
:New Land ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11871: New Land 解題者:施博修 解題日期: 2011 年 6 月 8 日 題意:國王有一個懶兒子,為了勞動兒子,他想了一個 辦法,令他在某天早上開始走路,直到太陽下山前,靠.
: OPENING DOORS ? 題組: Problem Set Archive with Online Judge 題號: 10606: OPENING DOORS 解題者:侯沛彣 解題日期: 2006 年 6 月 11 日 題意: - 某間學校有 N 個學生,每個學生都有自己的衣物櫃.
1.1 電腦的特性 電腦能夠快速處理資料:電腦可在一秒內處理數百萬個 基本運算,這是人腦所不能做到的。原本人腦一天的工 作量,交給電腦可能僅需幾分鐘的時間就處理完畢。 電腦能夠快速處理資料:電腦可在一秒內處理數百萬個 基本運算,這是人腦所不能做到的。原本人腦一天的工 作量,交給電腦可能僅需幾分鐘的時間就處理完畢。
STAT0_sampling Random Sampling  母體: Finite population & Infinity population  由一大小為 N 的有限母體中抽出一樣本數為 n 的樣 本,若每一樣本被抽出的機率是一樣的,這樣本稱 為隨機樣本 (random sample)
JAVA 程式設計與資料結構 第十四章 Linked List. Introduction Linked List 的結構就是將物件排成一列, 有點像是 Array ,但是我們卻無法直接經 由 index 得到其中的物件 在 Linked List 中,每一個點我們稱之為 node ,第一個 node.
Department of Air-conditioning and Refrigeration Engineering/ National Taipei University of Technology 模糊控制設計使用 MATLAB 李達生.
JAVA 程式設計與資料結構 第十章 GUI Introdution III. File Chooser  File Chooser 是一個選擇檔案的圖形介面, 無論我們是要存檔還是要開啟檔案,使 用這個物件都會讓我們覺得容易且舒適。
Chapter 13 塑模靜態觀點:物件圖 Static View : Object Diagram.
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
24-6 設定開始與結束場景中的 程式 最後我們要替這個遊戲收個尾, 幫它把開始 的等待畫面跟結束畫面處理一下。
© The McGraw-Hill Companies, Inc., 2006© The McGraw-Hill Companies, Inc., 2007 Chapter 7 位址解析通訊協定及 反向位址解析通訊協定.
Chapter 20 塑模動態觀點:狀態圖 Statechart Diagram. 學習目標  說明狀態圖的目的  定義狀態圖的基本記號  展示狀態圖的建構  定義活動、內部事件及遞延事件的狀態 圖記號.
錄音筆,MP3 撥放器, 隨身碟 之原理及規格. 定義 錄音筆 – 以錄音為首要功能 MP3 撥放器 – 以播放音樂為首要功能 隨身碟 – 以行動碟為功能.
: Happy Number ★ ? 題組: Problem Set Archive with Online Judge 題號: 10591: Happy Number 解題者:陳瀅文 解題日期: 2006 年 6 月 6 日 題意:判斷一個正整數 N 是否為 Happy Number.
: Fast and Easy Data Compressor ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10043: Fast and Easy Data Compressor 解題者:葉貫中 解題日期: 2007 年 3.
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 參 資料蒐集的方法.
: Ahoy, Pirates! ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11402: Ahoy, Pirates! 解題者:李重儀 解題日期: 2008 年 8 月 26 日 題意:有一個海盜島有 N 個海盜,他們的編號 (id)
1-6 動畫的文件屬性 舞台是動畫實際播放的畫面, 所以舞台的大 小與長寬比例對將來動畫的呈現有很大的 影響。 Flash 預設的舞台尺寸是 550 Pixels × 400 Pixels, 背景為白色, 如果要更改舞台大小與 背景色, 請執行『修改 / 文件』命令, 開啟文 件屬性 (Document.
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
資料結構實習-一 參數傳遞.
6-2 認識元件庫與內建元件庫 Flash 的元件庫分兩種, 一種是每個動畫專 屬的元件庫 (Library) ;另一種則是內建元 件庫 (Common Libraries), 兩者皆可透過 『視窗』功能表來開啟, 以下即為您說明。
Day 3 Outline Multicast example (from Day 2) Wireless Misc. utilities
Dynamic Multi-signatures for Secure Autonomous Agents Panayiotis Kotzanikolaou Mike Burmester.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
Image Interpolation Use SSE 指導教授 : 楊士萱 學 生 : 楊宗峰 日 期 :
Network Simulator Tutorial. The Network Simulator - ns-2 NS2 is a discrete event simulator targeted at networking research.
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Learning Method in Multilingual Speech Recognition Author : Hui Lin, Li Deng, Jasha Droppo Professor: 陳嘉平 Reporter: 許峰閤.
Chapter 10 m-way 搜尋樹與B-Tree
網路介紹及其運用 講師陳炯勳. 5-2 IP 協定 ( 一 ) IP 協定運作 (1) – 網路成員:主機 (Host) 與路由器 (Router) – 路由表 – 電報傳輸運作.
概念性產品企劃書 呂學儒 李政翰.
NS2 - Overview Ming-Feng Yang. 2 2 Outline Introduction OTcl Trace File NAM Xgraph.
無線通訊網路 Mac 層 TDM 通訊模式的操作與效能研究 專題生 : 林書弘、蔡逸祥、毛建翔、王政 華 指導教授 : 黃依賢.
論文研討 2 學分 授課教師:吳俊概. 第一節 論文發表的目的 第二節 論文發表的歷程 第三節 投稿過程 第四節 退稿處理 學術期刊論文的製作與發表.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2009.
1 2 Network Simulator (NS-2) I-Wei Ting ( 丁義偉 ) 2007/09/26.
專題成果報告 胺基酸功能預測開發環境 指導教授:歐昱言 邱彥豪 邱顯鈞.
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 壹 企業研究導論.
指導教授 : 林啟芳 教授 組員 : 邱秉良 林育賢. 何謂 GPS  GPS 即全球定位系統,是一個中距離圓 型軌道衛星導航系統。它可以為地球表面 絕大部分地區( 98% )提供準確的定位、 測速和高精度的時間標準。
資料結構實習-六.
著作權所有 © 旗標出版股份有限公司 第 14 章 製作信封、標籤. 本章提要 製作單一信封 製作單一郵寄標籤.
幼兒行為觀察與記錄 第八章 事件取樣法.
第 1 章 PC 的基本構造. 本章提要 PC 系統簡介 80x86 系列 CPU 及其暫存器群 記憶體: Memory 80x86 的分節式記憶體管理 80x86 的 I/O 結構 學習組合語言的基本工具.
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
Wireless Networking and Systems CSE 590 ns2 tutorial.
NS2 - Wireless Network Ming-Feng Yang. 2 2 Outline Basic wireless model Extensions wireless model Example - Ad hoc network Example – WLAN Example – Mobile.
Date : 2010/11/23 Speaker : Chia-Wen Lu 1.  Network Simulation  Introduction to NS2  Simple Simulation Example 2.
1 Network Simulator Tutorial. 2 Network Simulation * Motivation: Learn fundamentals of evaluating network performance via simulation Overview: fundamentals.
1 NS Fundamentals. USC INFORMATION SCIENCES INSTITUTE 2 OTcl and C++: The Duality C++ OTcl Pure C++ objects Pure OTcl objects C++/OTcl split objects ns.
NS-2 Shahin Shayandeh December 2004 Session 1. Ns-2, the Network Simulator  A discrete event simulator Simple model  Focused on modeling network protocols.
Network Simulator with Mobile IP 2003 Huang – Yu Liu.
DMET 602: Networks and Media Lab Amr El Mougy Yasmeen EssamAlaa Tarek.
1 Network Simulator 2 Install Chao-Ying Chiu
Presentation transcript:

Network Simulator (NS-2) 2009/3/31 I-Wei Ting (丁義偉)

Outline Part 1: Introduction Part 2: NS2 directory structure Part 3: Network Scenario

A: What is network simulator? NS is a discrete event simulator targeted at networking research. Ns provides substantial support for simulation of TCP, routing, and multicast protocols over wired and wireless (local and satellite) networks. NS began as the REAL network simulator in 1989 and has evolved over the past few years. In 1995 ns development was supported by DARPA through the VINT project at LBL, Xerox PARC, UCB, and USC/ISI. In 1996, the first version of ns2 was release.

Version http://www.isi.edu/nsnam/ns/CHANGES.html ns-2.34 pending ns-2.33 released on March 31, 2008 .. ns-2.30 released on Sept 26, 2006 ns-2.1b9 released on Sat Apr 13 16:26:33 PDT 2002 ns-2.0a1 Wed Nov 6 13:57:31 PST 1996 v1.0a1 Mon Jul 31 16:05:08 PDT 1995 http://www.isi.edu/nsnam/ns/CHANGES.html

Why we use it? New protocol is not easily implemented in real. (development, money, time, device, people) New protocol is not easily verified in the world. (mobile IP, ad hoc…etc, more nodes or network topology) New protocol is not easily compared others (How to convince other people?) Network Simulator simulates protocol layers (physical, datalink, network, transport, applicatoin)

B: Where do I get NS2? http://www.isi.edu/nsnam/ns

Step 1

Step 2

C: What platforms does NS2 run on and how to install NS2? Operation systems (FreeBSD, Linux, SunOS, Solaris, Windows) Setup for Linux-based system If the file is put at /root Step 1: cd /root Step 2: tar zxvf ns-allinone-2.30.tar.gz Step 3: cd /root/ns-allinone-2.30 Step 4: ./install Setup for win9x/2000/XP 中文教學網站-柯志亨(Chih-Heng, Ke) http://140.116.72.80/~smallko/ns2/ns2.htm 安裝流程 http://140.116.72.80/~smallko/ns2/setup.htm 註:在裝cygwin時,要自已勾選全部的套件,以免lost套件,無法compiler過去。

D: Where can I find documentation for NS2? download http://www.isi.edu/nsnam/ns/ns-documentation.html

E: Where are some tutorial I can start from? http://www.isi.edu/nsnam/ns/tutorial/index.html

F: What protocols does NS2 support? Application layer: Traffic models and applications Web, FTP, telnet, constant-bit rate, real audio Translation layer: Transport protocols Unicast: TCP(Reno,Vegas,etc.), UDP Multicast: SRM Network layer: Routing and queueing Wired routing: Dijkstra,DV Wireless routing: mobile IP Ad hoc routing :DSR,AODV,TORA,DSDV Queueing protocols: RED, drop-tail, SFQ etc Data link layer Ethernet, 802.11 Physical layer Wired(point-to-point, LANs), wireless (multiple propagation models)…

Part 2: NS2 structure A: Why use two programming language? B: Overview for NS2 structure C: Directory structure D: How to run a scenario in NS2

A: Why using two programming language to implement? 第一:需要一種程式設計語言,能夠有效率的處理位元組(Byte),封包標頭(Packet Header)等資訊,需要應用合適的演算法在大量的資料上。因此,程式內部的運行速度(run-time speed)就非常重要。(c++) 第二: 許多網路中的研究工作都圍繞著網路元件和環境參數的設置和改變而進行的,需要在短時間內快速的開發和模擬出所需要的網路環境(scenarios),並且方便修改和發現、修復。在這種情形下,(run-around time)就顯得很重要了,因為模擬環境的建立和參數資訊的配置只需要運行一次。(Otcl) NS2 is an object-oriented, discrete event driven network simulator developed at UC Berkely written in C++ and OTcl. C++ for “data” Per packet action OTcl for “control” Periodic or triggered action

B: Overview for NS2 structure

Event-driven simulator … E9 E8 E7 E6 E5 E4 E3 E2 E1 Simulation Time

C: Directory structure (After install) ns-allinone-2.30 tcl8.4 tk8.4 bin ….. ns-2.30 nam-1.12 Execute files Source node (C++)

D: How to run a scenario in NS2 (linux-based) Step 1: cd /root/ns-allinone-2.30 Step 2: cd bin Step 3: ./ns my_scenario.tcl

Part 3: Network Scenario A: What is network scenario? B: How to write a simple scenario C: How to run a scenario in NS2 (linux-based) D: How to get the trace file?

A: What is network scenario? (人、事、時、地、物) http://www.isi.edu/nsnam/ns/tutorial/index.html

B: How to write a simple scenario? 1.建立一個模擬器物件 (Must) set ns [new Simulator] 2.開啟一個nam trace 檔案 (Option) set nf [open out.nam w] $ns namtrace-all $nf 3.宣告一個finish程序(Must) proc finish {} { global ns nf $ns flush-trace # Close the trace file close $nf # Execute nam on the trace file exec nam out.nam & exit 0 }

(simulation environment) 1.建立節點及其屬性 Wired node Wireless node wireless mobile IP ad-hoc networks 2.建立節點之間的實體連線及其性質 3.建立傳輸的應用程式及其傳輸速率

1、建立有線的節點 (Created wired nodes) set my_node0 [$ns node] set my_node1 [$ns node] 2、建立實體連線 (Created physical link) $ns duplex-link $n0 $n2 2Mb 10ms SFQ $ns simple-link $n1 $n2 3Mb 2ms RED 雙向、單向,頻寬,延遲時間,佇列的種類 (DropTail, FQ, SFQ, RED, CBQ) 3、設定佇列的大小 (set queue length) $ns queue-limit $my_node0 $my_node1 50 4、設定節點及連線的label、顏色(color) (Option) $ns duplex-link-op $n0 $n1 color "green” $ns duplex-link-op $n0 $n1 label“line1”

5、設定連線的成本 (link cost) $ns cost $my_node1 $my_node2 10 $ns cost $my_node0 $my_node2 5 6、設定繞路(routing)屬性 預設 :static routing 靜態 routing : $ns rtproto Static 動態 routing : $ns rtproto DV $ns rtproto DV $n1 $n2 $n3

7、建立UTP連線 set udp0 [new Agent/UDP]  #建立Agent $ns attach-agent $n0 $udp0 #此Agent連於n0節點上 set cbr0 [new Application/Traffic/CBR] #應用程式 $cbr0 set packetSize_ 400 #封包大小(bytes) $cbr0 set interval_ 0.25 #設定傳送的間隔 $cbr0 attach-agent $udp0 set sink [new Agent/LossMonitor] #建立接受端 $ns attach-agent $n3 $sink #接受端節點 $ns connect $udp0 $sink #將傳送端及接受端連在一起

8、建立FTP連線 set tcp [new Agent/TCP] #建立TCP連線 $ns attach-agent $n0 $tcp #將此TCP連至n0節點 set ftp [new Application/FTP] #建立一個FTP應用程式 $ftp attach-agent $tcp #將此FTP連至TCP物件 set sink [new Agent/TCPSink] #建立TCP的接受端 $ns attach-agent $n3 $sink #將接受端連至n3節點 $ns connect $tcp $sink #將傳送端及接受端連在一起

(time schedular, event occur) 此部份要安排事件發生的前後順序 例如: 第2秒, A節點開始傳輸UTP封包到B節點 第3秒, C節點開始傳輸TCP封包到D節點 第17秒, A節點結束傳送 第16秒, C節點結束傳送 $ns at 2 "$cbr0 start" $ns at 17 “$cbr0 stop” $ns at 3 "$ftp start" $ns at 16 “$ftp stop” $ns at 20 "finish" 設定某連線中斷及修復 $ns rtmodel-at 1.0 down $my_node1 $my_node $ns rtmodel-at 2.0 up $my_node1 $my_node2

(Any Editor: notepad,ultra-editor…) 1. set ns [new Simulator] 2. set nf [open out.nam w] 3. $ns namtrace-all $nf 4. proc finish {} { 5. global ns nf 6. $ns flush-trace 7. close $nf 8. exec ./nam out.nam & 9. exit 0 10 } 11. set n0 [$ns node] 12. set n1 [$ns node] 13. set n2 [$ns node] 14. set n3 [$ns node] 15. $ns duplex-link $n0 $n2 2Mb 10ms DropTail 16. $ns duplex-link $n1 $n2 2Mb 10ms DropTail 17. $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail 18. $ns queue-limit $n2 $n3 10 (Option) (Option)

19. set tcp [new Agent/TCP] 20. $ns attach-agent $n0 $tcp 21. set sink [new Agent/TCPSink] 22. $ns attach-agent $n3 $sink 23. $ns connect $tcp $sink 24. set ftp [new Application/FTP] 25. $ftp attach-agent $tcp 26. set udp [new Agent/UDP] 27. $ns attach-agent $n1 $udp 28. set null [new Agent/LossMonitor] 29. $ns attach-agent $n3 $null 30. $ns connect $udp $null 31. set cbr [new Application/Traffic/CBR] 32. $cbr attach-agent $udp 33. $cbr set packet_size_ 1000 34. $cbr set interval_ 0.25

35. $ns at 0.1 "$cbr start" 36. $ns at 1.0 "$ftp start" 37. $ns at 4.0 "$ftp stop" 38. $ns at 4.5 "$cbr stop" 39. $ns at 5.0 "finish" 40. $ns run

C: How to run a scenario in NS2 (linux-based) Step 1: cd /root/ns-allinone-2.30 Step 2: cd bin Step 3: ./ns my_scenario.tcl

Useful additional program NAM: Viewing network simulation traces and real world packet traces

C: How to get the trace file? set my_trace [open demo1.tr w] $ns trace-all $my_trace 1 2 3 4 5 6 7 8 9 10 11 12 r 1.340958 ack 40 ------- 3.2 0.1 181 + - 1.341225 cbr 210 0.0 3.1 84 166 1.453111 tcp 60 97 81 d

每個欄位所代表的意義如下: 1.代表事件的類別 r:代表目的端收到packet +:代表 packet 放入 queue 中 -:代表 packet 從 queue 中取出 d:代表 queue 已經滿了,這個 packet 被 drop 掉 2.代表事件發生的時間 3.代表 packet 的 source node 4.代表 packet 的 destination node 5.代表 packet 的類別 6.代表 packet 的大小 (encoded in IP header) 7.代表 packet 的 flags 8.代表 connection(flow) 的 id 9.代表 source address ( node.port ) 10.代表 destinations address ( node.port ) 11.代表 packet 的 sequence number ( network layer protocol's ) 12.代表 packet 的 id ( unique )

Set f1 [open demo1.record w] proc record { } { global null f1 set ns [Simulator instance] set time 0.1 set now [$ns now] set bw [$null set bytes_ ] puts $f1 “$now $bw” $null set bytes_ 0 $ns at [expr $now+$time] “record” } $ns at 0.0 “record” LossMonitor nlost_ :Number of packets lost npkts_ :Number of packets received bytes_ :Number of bytes received lastPktTime_ :Time at which the last packet was received expected_ :The expected sequence number of the next packet

Network Setting  Sender:Node 1, 2, 3  Receiver:Node 7  Using CBR  Packet Size:1000(k)  Time Interval:1 (s)  Simulation Time:15 (s)

Tcl Code #Create a simulator object set ns [new Simulator] #Define different colors for data flows $ns color 1 Blue $ns color 2 Red $ns color 3 Green #Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf #Open the trace file set nd [open out.tr w] $ns trace-all $nd

Tcl Code #Define a 'finish' procedure proc finish {} { global ns nd nf $ns flush-trace #Close the trace file close $nd close $nf #Execute nam on the trace file exec nam out.nam & exit 0 }

Tcl Code s0 r0 s1 r2 d s2 r1 #Create four nodes set s0 [$ns node] set r0 [$ns node] set r1 [$ns node] set r2 [$ns node] set d [$ns node] #Create links between the nodes $ns duplex-link $s0 $r0 10Mb 10ms DropTail $ns duplex-link $s1 $r0 10Mb 10ms DropTail $ns duplex-link $s2 $r1 10Mb 10ms DropTail $ns duplex-link $r0 $r2 10Mb 10ms DropTail $ns duplex-link $r1 $r2 10Mb 10ms DropTail $ns duplex-link $r2 $d 10Mb 10ms DropTail s0 r0 s1 r2 d s2 r1

Tcl Code #Set position of each node $ns duplex-link-op $s0 $r0 orient right-down $ns duplex-link-op $s1 $r0 orient right-up $ns duplex-link-op $s2 $r1 orient right-up $ns duplex-link-op $r0 $r2 orient right-down $ns duplex-link-op $r1 $r2 orient right-up $ns duplex-link-op $r2 $d orient right #Monitor the queue for the link $ns duplex-link-op $r0 $r2 queuePos 0.5 $ns duplex-link-op $r1 $r2 queuePos 0.5 $ns duplex-link-op $r2 $d queuePos 0.5

Tcl Code #Set flow ID $udp0 set fid_ 1 $udp1 set fid_ 2 #Schedule events for the CBR agents $ns at 0.0 "$cbr0 start" $ns at 0.0 "$cbr1 start" $ns at 0.0 "$cbr2 start" $ns at 15.0 "$cbr0 stop" $ns at 15.0 "$cbr1 stop" $ns at 15.0 "$cbr2 stop“ #Call the finish procedure after 5 seconds of simulation time $ns at 15.0 "finish" #Run the simulation $ns run

Simulation

Analyze Result out.tr + 0 1 3 cbr 1000 ------- 2 1.0 6.1 0 1 ...

Analyze Result event Src addr:(node).(port) r:receive(at to_node) Time From To node Pkt node Pkt type Flags size Fid Src addr Dst addr Seq Num Pkt id + 1 3 cbr 1000 2 1.0 6.1 - 4 5 2.0 6 7 8 event r:receive(at to_node) +:enqueue(at queue) -:dequeue(at queue) d:drop (at queue) Src addr:(node).(port) Dst addr:(node).(port)

awk – measure delay BEGIN { #程式初始化,設定一變數以記錄目前最高處理封包的ID。 highest_packet_id = 0; } { action = $1; time = $2; from = $3; to = $4; type = $5; pktsize = $6; flow_id = $8; src = $9; dst = $10; seq_no = $11; packet_id = $12;

awk – measure delay #記錄目前最高的packet ID if ( packet_id > highest_packet_id ) highest_packet_id = packet_id; #記錄封包的傳送時間 if ( start_time[packet_id] == 0 ) start_time[packet_id] = time; #記錄CBR (flow_id=1) 的接收時間 if ( flow_id == 3 && action != "d" ) { if ( action == "r" ) { end_time[packet_id] = time; } } else { #把不是flow_id=2的封包或者是flow_id=2但此封包被drop的時間設為-1 end_time[packet_id] = -1;

awk – measure delay END { #當資料列全部讀取完後,開始計算有效封包的端點到端點延遲時間 for ( packet_id = 0; packet_id <= highest_packet_id; packet_id++ ) { start = start_time[packet_id]; end = end_time[packet_id]; packet_duration = end - start; #只把接收時間大於傳送時間的記錄列出來 if ( start < end ) printf("%f %f\n", start, packet_duration); }

Result Executing: $awk –f measure-delay.awk out.tr 0.010800 0.022400 0.000800 0.034000 0.001600 0.034800 0.002400 0.035600 0.003200 0.036400 1.000000 0.033200 .....

Wireless Ad hoc network client server 2 1 3 4 5 6

my_scenario.tcl 1. set val(chan) Channel/WirelessChannel 2. set val(prop) Propagation/TwoRayGround 3. set val(netif) Phy/WirelessPhy 4. set val(mac) Mac/802_11 5. set val(ifq) Queue/DropTail/PriQueue 6. set val(ll) LL 7. set val(ant) Antenna/OmniAntenna 8. set val(ifqlen) 50 9. set val(nn) 7 10. set val(rp) AODV 11. set ns [new Simulator] 12. set tracefd [open my_scenario.tr w] 13. $ns trace-all $tracefd

14. set nf [open my_scenario.nam w] 15. $ns namtrace-all-wireless $nf 1000 1000 16. set topo [new Topography] 17. $topo load_flatgrid 1000 1000 18. create-god $val(nn) 19. $ns node-config -adhocRouting $val(rp) \ 20. -llType $val(ll) \ 21. -macType $val(mac) \ 22. -ifqType $val(ifq) \ 23. -ifqLen $val(ifqlen) \ 24. -antType $val(ant) \ 25. -propType $val(prop) \ 26. -phyType $val(netif) \ 27. -channelType $val(chan) \ 28. -topoInstance $topo \ 29. -agentTrace ON \ 30. -routerTrace ON \ 31. -macTrace OFF \ 32. -movementTrace OFF

33. $node_(0) set X_ 1.0 34. $node_(0) set Y_ 999.0 35. $node_(1) set X_ 100.0 36. $node_(1) set Y_ 500.0 37. $node_(2) set X_ 250.0 38. $node_(2) set Y_ 500.0 39. $node_(3) set X_ 400.0 40. $node_(3) set Y_ 500.0 41. $node_(4) set X_ 550.0 42. $node_(4) set Y_ 500.0 43. $node_(5) set X_ 700.0 44. $node_(5) set Y_ 500.0 45. $node_(6) set X_ 850.0 46. $node_(6) set Y_ 500.0

47. set udp0 [new Agent/UDP] 48. set null0 [new Agent/Null] 49. $ns attach-agent $node_(2) $udp0 50. $ns attach-agent $node_(6) $null0 51. $ns connect $udp0 $null0 52. set cbr0 [new Application/Traffic/CBR] 53. $cbr0 set type_ CBR 54. $cbr0 set packet_size_ 500 55. $cbr0 set interval_ 0.5 56. $cbr0 attach-agent $udp0 57. $ns at 0.0 "$node_(0) setdest 1 999 10" 58. $ns at 0.0 "$node_(1) setdest 100 500 10" 59. $ns at 0.0 "$node_(2) setdest 250 500 10" 60. $ns at 0.0 "$node_(3) setdest 400 500 10" 61. $ns at 0.0 "$node_(4) setdest 550 500 10" 62. $ns at 0.0 "$node_(5) setdest 700 500 10" 63. $ns at 0.0 "$node_(6) setdest 850 500 10"

64. $ns at 100.0 "$cbr0 start" 65. $ns at 105.0 "$cbr0 stop" 66. $ns at 110.0 "stop" 67. proc stop {} { 68. global ns tracefd nf 69. $ns flush-trace 70. exit 0 71. } 72. $ns run

Consideration of TCL and C++ Topic:SimpleCache protocol 1. How to choose source and destination in different time? 2. How to configure the query action? 3. How to simulate cache operation? 4. How to apply routing protocol to create routing path? 5. How to write the caching protocol? client server 2 4 1 3 5 6

D N H S E B 3 4 D N H S A 1 2 E C 4 D N H S A B 2 E 1 4 D N H S A C 3 DSDV A B C D DSR A A-B A-B-C A B C D A-B-C-D A-B-C-D A-B-C-D AODV RREQ RREQ RREQ A B C E RREP RREP RREP D N H S E B 3 4 D N H S A 1 2 E C 4 D N H S A B 2 E 1 4 D N H S A C 3 4

/root/ns-allinone-2.30/ns-2.30/aodv (aodv.cc, aodv.h) // Event-driven sequential for the basic request and response // Description 1: Each MH executes Query_Model(...) each second. // // QueryTimer trigger Query_Model(...) --> Requester_Lookup_Local_Cache(...) // If local miss, run AODV routing to create the routing path. // --> [AODV: sendRequest(...)-->...--> recvReply(...)] // --> Begin_to_Data_Discovery_Process(index,rt->rt_dst) // --> Requester_Send_Data_Request(source, destination, query_data_id); // --> Recv_Data_Request_from_Requester(p); // --> Intermediate_Forward_Data_Request(p); // --> Recv_Data_Request_from_Intermdiate(p); // ........... // --> Original_Server_Send_Data_Reply(p) // --> Recv_Data_Reply_from_Original_Server(p); // --> Intermediate_Forward_Data_Reply(p); // --> Recv_Data_Reply_from_Intermediate(p); // ........... // --> Requester_Recv_Data_Reply(p)

1. void QueryTimer::handle(Event*) agent->query_model(); Scheduler::instance().schedule(this, &intr, 1); } …. E10 E9 E8 E7 E6 E5 E4 E3 E2 E1 第2秒 第1秒 Simulation Time

2. query_model() 第2秒 第1秒 Simulation Time …. E10 E9 E8 E7 E6 E5 E4 E3

Useful variable CURRENT_TIME printf(“\n current_time=%.5f”,CURRENT_TIME); index: printf(“\n node_id =%d”,index);

How to compile source code? 1. cd /root/ns-allinone-2.30/ns-2.30 2. make