Top Banner
JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS- 2 1
33

JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Jan 02, 2016

Download

Documents

Ezra Powell
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

JIA-HUI HUANG

INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING

NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY2007.10.15

Network Simulator – NS-21

Page 2: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Reference

http://140.116.72.80/~smallko/ns2/ns2.htmhttp://www.isi.edu/nsnam/ns/Ns document

2

Page 3: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Outline

IntroductionInstallationTCL scriptRelated toolsNew protocol for NSExamplesConclusion

3

Page 4: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Introduction

Methods for network research Analytical

General expression or close form Mathematical model

Emulation Real code Duplicates the functions of one system with a different

system Simulation

Abstract model Behavior of system

4

Page 5: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Introduction (cont.)

Self-Developed Without strong persuasion

Simulation frameworks Commercial

OPNET QualNet OMNEST (commercial version of OMNetT++)

Free NS-2 (network simulator version 2) OMNetT++

5

Page 6: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Introduction (cont.)

Ns-2 is a discrete event simulator Scheduler Advance of time depends on the timing of events

Object-oriented simulator C++ : fast to run, slower to change – protocol

implementation Otcl : slower to run, fast to change – simulation

configuration

Components Ns – simulator itself Nam – network animator

Visualize ns (or other) output

6

Page 7: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Introduction (cont.)

Pre-processing Traffic and topology model

Post-processing Trace analysis, often in awk, perl, or tcl

Simulation procedure

Problems

Simulate the environment

Run with ns-2

Analysis the result

Finish

Modify

No

Finish the simulation

Yes

7

Page 8: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Installation

Platform Unix Windows (cygwin)

Packages Tcl/tk Otcl tclcl Ns-2 Nam Xgraph C++ compiler

Ns AllInOne package

8

Page 9: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Installation (cont.)

Cygwin, AllInOne installation (windows) http://140.116.72.80/~smallko/ns2/setup_en.htm

Installation problems http://www.isi.edu/nsnam/ns/ns-problems.html#general

Cygwin setup gcc

Ns-2 setup Path setting Cygwin/home/user-name/.bashrc

Testing (startxwin.bat) - ~/ns-allinone-x.x/ns-x.x/ns-tutorial/examples

9

Page 10: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

TCL script

TCL script for scenario setupScenario script format

Simulator object Trace file Finish procedure Network setup (node, link, agent, parameter…) Other procedure, if any Event scheduling (run simulation, stop simulation …)

10

Page 11: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

TCL script (cont.)

Example topology

0 1CBR

#Create a simulator objectset ns [new Simulator]

#Open the nam trace fileset nf [open out.nam w]$ns namtrace-all $nf

#Define a 'finish' procedureproc 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}

11

Page 12: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

#Create two nodesset n0 [$ns node]set n1 [$ns node]

#Create a duplex link between the nodes$ns duplex-link $n0 $n1 1Mb 10ms DropTail

#Create a UDP agent and attach it to node n0set udp0 [new Agent/UDP]$ns attach-agent $n0 $udp0

# Create a CBR traffic source and attach it to udp0set cbr0 [new Application/Traffic/CBR]$cbr0 set packetSize_ 500$cbr0 set interval_ 0.005$cbr0 attach-agent $udp0

#Create a Null agent (a traffic sink) and attach it to node n1set null0 [new Agent/Null]$ns attach-agent $n1 $null0#Connect the traffic source with the traffic sink$ns connect $udp0 $null0#Schedule events for the CBR agent$ns at 0.5 "$cbr0 start"$ns at 4.5 "$cbr0 stop"#Call the finish procedure after 5 seconds of simulation time$ns at 5.0 "finish"

#Run the simulation$ns run

12

Page 13: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Related tools

nsBench Graphical User Interface For NS Language - java Features

Nodes, simplex/duplex links and Lans Agents: TCP, UDP, TCP/Reno, … Application Traffic: FTP, Telnet, …. …. http://www.mnlab.cs.depaul.edu/projects/nsbench/

13

Page 14: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Related tools (cont.)

NSG Java based ns2 scenario generator For wireless ad-hoc scenario Features

wireless node Connection between nodes Node movement

http://wushoupong.googlepages.com/ns2scenariosgeneratorchinese

14

Page 15: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Related tools (cont.)

Topology Generator Georgia Tech Internetwork Topology Models (GT-ITM) How closely model correlate with real network ? Transit-Stub model Transit domain

Interconnect stub domains Example topology

15

Page 16: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

New protocol for ns

Packet type Structure declaration – packet header Name binding

Bind packet header to TCL interface Usage

Routing agent MANET routing protocol Agent object Tcl hook Important functions

16

Page 17: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Packet type

Packet header #include <packet.h>

#define HDR_PROTONAME_PKT(p) hdr_protoname_pkt::access(p)struct hdr_protoname_pkt {

…. (define some fields of packet)static int offset_;inline static int& offset() { return offset_ ; }inline static hdr_protoname_pkt* access(const Packet* p) {

return (hdr_protoname_pkt*)p->access(offset_); }

17

Page 18: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Packet type (cont.)

Name bindingint protoname_pkt::offset_;static class ProtonameHeaderClass : public PacketHeaderClass {public:

ProtonameHeaderClass()PacketHeaderClass("PacketHeader/Protoname",

sizeof(hdr_protoname_pkt)) { bind_offset(&hdr_protoname_pkt::offset_);}

}

18

Page 19: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Packet type (cont.)

UsagePacket* p = allocpkt();

struct hdr_cmn* ch = HDR_CMN(p); struct hdr_ip* ih = HDR_IP(p); struct hdr_protoname_pkt* ph = HDR_PROTONAME_PKT(p);

ph->….

ih->….

ch->…

19

Page 20: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Routing agent

Agent object#include <agent.h>

….class NewProtocol : public Agent {protected :

…public :

NewProtocol(nsaddr_t);int command (int, const char*const*);void recv(Packet*, Handler*);

….}

20

Page 21: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Routing agent (cont.)

Tcl hook Let NewProtocl to be instantiated from Tcl.static class ProtonameClass : public TclClass {public:

ProtonameClass() : TclClass("Agent/Protoname") {}TclObject* create(int argc, const char*const* argv) {

assert(argc == 5);return (new

Protoname((nsaddr_t)Address::instance().str2addr(argv[4])));}

}

21

Page 22: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Routing agent (cont.)

Important functions Command()

Operations that we went to make accessible from TCL maodv-join-group maodv-leave-group Example - maodv.cc, MAODV_SimScript.tcl, cbr-5-3-2

Recv () Invoked whenever the routing agent receives a packet

22

Page 23: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Needed changes

Needed changes Packet type declaration - \ns-x.xx\common\packet.h Tracing support - \ns-x.xx\cmu-trace.h Tcl library

Tcl\lib\ns-packet.tcl Tcl\lib\ns-default.tcl

Priority queue - \queue\priqueue.cc Make file

23

Page 24: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Example1 - TCP slow start

Transport layer protocol UDP – user datagram protocol (connectionless,

unreliable service) TCP – transmission control protocol (connect-oriented,

reliable, with flow and congestion control service) Connection-oriented – three-way handshaking Reliable – acknowledgment, retransmission Flow control – sender won’t buffers by transmitting to

much and too fast Congestion control – to limit the total amount of data

entering the internet

24

Page 25: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Example1 - TCP slow start (cont.)

Important variables for congestion control – slow start cwnd – congestion window ssthresh – defines threshold between two slow start

phase and congestion control phaseOperations – slow start

When connection begins, increase rate exponentially fast until first loss event (slow start phase)

Set ssthresh = cwnd/2 Set cwnd = 1 and perform slow start process For cwnd >= ssthresh, increase cwnd linearly

(congestion avoidance)

25

Page 26: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Example1 - TCP slow start (cont.)

TCP standards TCP Tahoe – slow start & congestion avoidance

RFC 2581 TCP Vegas TCP Reno

RFC 2581 TCP NewReno

RFC 2582 FACK (forward acknowledgement) SACK (selective acknowledgement)

RFC 2018

26

Page 27: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Example1 - TCP slow start (cont.)

TCP experiment – congestion window TCP Tahoe

Slow-start Congestion avoidance

n0

n1

n2 n3

Simulation topology

Receiver

Source2(UDP)

Source1 (TCP)

27

Page 28: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Example2 – queuing system

Queuing systems M/M/1 M/D/1 …

Notation Arrival process/Service time/Servers M = exponential, D = Deterministic, ….

28

Page 29: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Queuing system – M/M/1 (cont.)

Arrival & departure model Poisson arrival Exponential distribution

single serverParameters

Arrival rate λ Departure rate (service time) μ load (stability condition : ρ < 1)

(# of packets in system)

1

][QE

29

Page 30: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Queuing system – M/M/1 (cont.)

queue.tcl Arrival rate : 30 Departure rate : 33 E[Q] = 10

30

Page 31: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Tips31

Ns document is not easy to understandError message is not very usefulUnderstand and ImplementationImplementation issuesIterative design

Page 32: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Conclusion

Basic concept of NS2Two levels of simulationExist modules for NS beginner

32

Page 33: JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15 Network Simulator – NS-2 1.

Internet domain structure

Example of Internet domain structure

33