Http cial csie ncku edu tw courses
This presentation is the property of its rightful owner.
Sponsored Links
1 / 68

cial.csie.ncku.tw/courses/ PowerPoint PPT Presentation


  • 114 Views
  • Uploaded on
  • Presentation posted in: General

http://cial.csie.ncku.edu.tw/courses/. Network Simulator (NS-2). 2007/09/26. [email protected] I-Wei Ting ( 丁義偉 ). What is network? (Distributed systems). D. B. G. A. E. C. F. K. H. Outline. Part 1: Introduction for Network Simulator 2 Part 2: NS2 structure

Download Presentation

cial.csie.ncku.tw/courses/

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Http cial csie ncku edu tw courses

http://cial.csie.ncku.edu.tw/courses/


Network simulator ns 2

Network Simulator (NS-2)

2007/09/26

[email protected]

I-Wei Ting (丁義偉)


What is network distributed systems

What is network?(Distributed systems)

D

B

G

A

E

C

F

K

H


Outline

Outline

  • Part 1: Introduction for Network Simulator 2

  • Part 2: NS2 structure

  • Part 3: Network Scenario


Part 1 introduction for network simulator 2

Part 1: Introduction for Network Simulator 2

  • A: What is Network Simulator?

  • B: Where do I get NS2?

  • C: What platforms does NS2 run on and how to install NS2?

  • D: Where can I find documentation for NS2?

  • E: Where are some sample scripts I can start from?

  • F: What protocols does NS2 support?


A what is network simulator

A: What is network simulator?

  • History of NS2

    • 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.

  • Why we use it?

    • New protocol is not easily implemented.

      • (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)


Cial csie ncku tw courses

  • Currently the package contains:

    • Tcl release 8.4.5 (required component)

    • Tk release 8.4.5 (required component)

    • Otcl release 1.8 (required component)

    • TclCL release 1.15 (required component)

    • Ns release 2.27 (required component)

    • Nam release 1.10 (optional component)

    • Xgraph version 12 (optional component)

    • CWeb version 3.4g (optional component)

    • SGB version 1.0 (?) (optional component, builds sgblib for all UNIX type platforms)

    • Gt-itm gt-itm and sgb2ns 1.1 (optional component)

    • Zlib version 1.1.4 (optional, but required should Nam be used)


B where do i get ns2

B: Where do I get NS2?

http://www.isi.edu/nsnam/ns


Cial csie ncku tw courses

Step 1


Cial csie ncku tw courses

Step 2


Cial csie ncku tw courses

Step 3


Cial csie ncku tw courses

Step 4


C what platforms does ns2 run on and how to install ns2

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


D where can i find documentation for ns2

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

E: Where are some tutorial I can start from?

http://www.isi.edu/nsnam/ns/tutorial/index.html


F what protocols does ns2 support

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

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

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

B: Overview for NS2 structure


Event driven simulator

Event-driven simulator

Event 1

Simulation Time


C directory structure after install

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++)


Part 3 network scenario

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

A: What is network scenario? (人、事、時、地、物)

http://www.isi.edu/nsnam/ns/tutorial/index.html


B how to write a simple scenario

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

(simulation environment)

  • 1.建立節點及其屬性

    • Wired node

    • Wireless node

      • wireless mobile IP

      • ad-hoc networks

  • 2.建立節點之間的實體連線及其性質

  • 3.建立傳輸的應用程式及其傳輸速率


1 created wired nodes

1、建立有線的節點 (Created wired nodes)

2、建立實體連線 (Created physical link)

  • set my_node0 [$ns node]

  • set my_node1 [$ns node]

  • $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

5、設定連線的成本 (link cost)

6、設定繞路(routing)屬性

  • $ns cost $my_node1 $my_node2 10

  • $ns cost $my_node0 $my_node2 5

  • 預設 :static routing

  • 靜態 routing:$ns rtproto Static

  • 動態 routing :$ns rtproto DV

  • $ns rtproto DV$n1 $n2 $n3


7 utp

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

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

(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


Cial csie ncku tw courses

(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)


Cial csie ncku tw courses

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


Cial csie ncku tw courses

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

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

Useful additional program

  • NAM: Viewing network simulation traces and real world packet traces


Cial csie ncku tw courses

C: How to get the trace file?

set my_trace [open demo1.tr w]

$ns trace-all $my_trace


Cial csie ncku tw courses

  • 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


Cial csie ncku tw courses

  • 每個欄位所代表的意義如下:

  • 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 )


Source codes about cbr traffic

Source codes about CBR traffic

  • /root/ns-allinone-2.30/ns-2.30/tools/cbr_traffic.cc

    • CBR_Traffic::CBR_Traffic()

    • void CBR_Traffic::start()

    • void CBR_Traffic::init()

    • double CBR_Traffic::next_interval(…)

  • /root/ns-allinone-2.30/ns-2.30/apps/udp.cc

    • void UdpAgent::Sendmsg(…)

    • void UdpAgent::recv(…)

  • /root/ns-allinone-2.30/ns-2.30/tools/loss-monitor.cc

    • void LossMonitor::recv(…)


My scenario tcl

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


Cial csie ncku tw courses

  • 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


Cial csie ncku tw courses

  • 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


Cial csie ncku tw courses

  • 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"


Cial csie ncku tw courses

  • 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

client

server

c

i

s


Root ns allinone 2 30 ns 2 30 aodv aodv cc aodv h

/root/ns-allinone-2.30/ns-2.30/aodv aodv.cc, aodv.h

  • 1. void QueryTimer::handle(Event*)

  • 2. query_model()

  • 3. [sendRequest()…recvReply()]

  • //Create routing path from the source and destination(Server)

  • 4.  data_discovery_process(…)

  • 5.  original_send_data_request(…)

  • 6.  recv_Data_request_from_original(…)

  • 7.  intermediate_node_forward_request(…)

  • 8.  recv_Data_request_from_intermediate(…)

  • 9.  intermediate_node_forward_request(…)

  • ….

  • ….

  • ….

  • 10. data_source_send_data_reply(…)


Cial csie ncku tw courses

  • 10.  data_source_send_data_reply(…)

  • 11.  recv_Data_Reply_from_data_source(…)

  • 12.  intermediate_node_forward_reply(…)

  • 13.  recv_Data_reply_from_intermediate(…)

  •  intermediate_node_forward_reply(…)

  • ….

  • ….

  • ….

  • 14.  original_source_recv_data(…)


1 void querytimer handle event

1. void QueryTimer::handle(Event*)

  • void QueryTimer::handle(Event*) {

  • agent->query_model();

  • Scheduler::instance().schedule(this, &intr, 1);

  • }

第2秒

第1秒

Simulation Time


2 query model

2. query_model()

第2秒

第1秒

Simulation Time


3 sendrequest recvreply

3. [sendRequest()…recvReply()]

  • 4. data_discovery_process(…)

  • 5. original_send_data_request(…)

Phase 1: Data Request process

  • recvReply() Trigger data_discovery_process(…)

A

  • 6. recv_Data_request_from_original(…)

  • 7. intermediate_node_forward_reply(…)

B

  • 10.data_source_send_data_reply(…)

D

  • 8. recv_Data_request_from_original(…)

9. intermediate_node_forward_request(…)

C


Cial csie ncku tw courses

  • 14. original_source_recv_data(…)

Phase 2: Data Reply process

A

  • 13. recv_Data_reply_from_intermediate(…)

  • 12. intermediate_node_forward_reply(…)

B

  • 10. data_source_send_data_reply(…)

D

  • 11. recv_Data_Reply_from_data_source(…)

12. intermediate_node_forward_reply(…)

C


Cial csie ncku tw courses

???

A

B

void AODV::recv(Packet *p)

recv_Data_request_from_original(…)

original_source_recv_data(…)

  • recv_Data_reply_from_intermediate(…)

  • recv_Data_request_from_original(…)


Useful variable

Useful variable

  • CURRENT_TIME

    • printf(“\n current_time=%.5f”,CURRENT_TIME);

  • index:

    • printf(“\n node_id =%d”,index);


How to compile source code

How to compile source code?

  • 1. cd /root/ns-allinone-2.30/ns-2.30

  • 2. make


Assistant for source codes

Assistant for source codes

  • 林呈俞 [email protected]

  • 張凱焯 [email protected]

  • 林意勝 [email protected]

  • 陳宥佐 [email protected]

側門

側門

資工系辦

正門

CIAL Lab

1樓

側門


To do

To do

  • 1. Install NS2

  • 2. Replace files in “aodv” directory to given files

  • 3. Execute my_scenario.tcl

  • 4. Revise my_scenario.tcl

    • 1000m x 1000m, 100 nodes

  • 5. Know the process of received messages

1

4

3

2

7

8

5

6

11

9

10

13

12


Real traces in the internet traffic archive

Real Traces in the Internet Traffic Archive

  • http://ita.ee.lbl.gov/html/traces.html


Download and extract

Download and Extract

  • If the file is put in /root

  • Step 1: cd /root

  • Step 2: tar zxvf UCB-home-IP-848278026- 848292426.tr.gz

  • Step 3: cd /root/UCB-home-IP-848278026- 848292426.tr.gz

  • Step 4: cp X /root/ns-allinone-2.29/ns-2.29/indep-utils/webtrace-conv


How to convert real trace for ns2

How to convert real trace for NS2 ?

  • cd /root/ns-allinone-2.29/ns-2.29/indep-utils/webtrace-conv

  • Four directory

    • dec

      • DEC proxy trace (1996),

    • epa

      • EPA web server trace

    • nlanr

      • NLANR proxy trace

    • ucb

      • UCB Home-IP trace


Cial csie ncku tw courses

  • cd /root/ns-allinone-2.29/ns-2.29/indep-utils/webtrace-conv/ucb

  • ./ucb-tr-stat 1000 50 0 < ucb_trace_file.tr

  • reqlog

    • {<time> <clientID> <serverID> <URL_ID>}

    • i <Duration> <Number_of_unique_URLs>

  • pglog

    • <serverID> <URL_ID> <PageSize> <AccessCount>


Previous projects

Previous projects

  • NS2 parts:

  • 1. static and dynamic routing experiments, NS2

  • 2. Web cache replacement, NS2

  • 3. Connection processing simulation between proxy, server, and clients, NS2

  • 4. topology generator, NS2

  • 5. Analysis delay jitter from FTP and CBR Application, NS2

  • 6. Analysis the trace file from the web application, NS2

  • Others:

  • 7. Modify Apache codes for providing different level of transmission bandwidth

  • 8. Data mining for http request

  • 9. Bookmark checker, JSP, JAVA

  • 10. Http(p2p), visual C++

  • 11. VoIP, SIP,JAVA

  • 12. Remote monitor system, JSP


  • Login