Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Network Simulator – NS-2
1
JIA-HUI HUANG
INSTITUTE OF COMPUTER SCIENCE AND
INFORMATION ENGINEERING
NATIONAL TAIPEI UNIVERSITY OF
TECHNOLOGY
2007.10.15
Reference
2
http://140.116.72.80/~smallko/ns2/ns2.htm
http://www.isi.edu/nsnam/ns/
Ns document
Outline
3
Introduction
Installation
TCL script
Related tools
New protocol for NS
Examples
Conclusion
Introduction
4
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
Introduction (cont.)
5
Self-Developed
Without strong persuasion
Simulation frameworks
Commercial
OPNET
QualNet
OMNEST (commercial version of OMNetT++)
Free
NS-2 (network simulator version 2)
OMNetT++
Introduction (cont.)
6
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
Introduction (cont.)
7
Pre-processing
Traffic and topology model
Post-processing
Trace analysis, often in awk, perl, or tcl
Simulation procedure
Problems
Simulate the
environment
Modify
Run with ns-2
Analysis the
result
Finish
Yes
Finish the
simulation
No
Installation
8
Platform
Unix
Windows (cygwin)
Packages
Tcl/tk
Otcl tclcl
Ns-2
Nam
Xgraph
C++ compiler
Ns AllInOne package
Installation (cont.)
9
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
TCL script
10
TCL script for scenario setup
Scenario script format
Simulator object
Trace file
Finish procedure
Network setup (node, link, agent, parameter…)
Other procedure, if any
Event scheduling (run simulation, stop simulation …)
TCL script (cont.)
11
Example topology
CBR
0
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
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
}
1
#Create two nodes
set n0 [$ns node]
set n1 [$ns node]
#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
12
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0
set 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 n1
set 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
Related tools
13
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/
Related tools (cont.)
14
NSG
Java based ns2 scenario generator
For wireless ad-hoc scenario
Features
wireless node
Connection between nodes
Node movement
http://wushoupong.googlepages.com/ns2scenariosgeneratorc
hinese
Related tools (cont.)
15
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
New protocol for ns
16
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
Packet type
17
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_);
}
Packet type (cont.)
18
Name binding
int protoname_pkt::offset_;
static class ProtonameHeaderClass : public PacketHeaderClass {
public:
ProtonameHeaderClass()
PacketHeaderClass("PacketHeader/Protoname",
sizeof(hdr_protoname_pkt)) {
bind_offset(&hdr_protoname_pkt::offset_);
}
}
Packet type (cont.)
19
Usage
Packet* 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->…
Routing agent
20
Agent object
#include <agent.h>
….
class NewProtocol : public Agent {
protected :
…
public :
NewProtocol(nsaddr_t);
int command (int, const char*const*);
void recv(Packet*, Handler*);
….
}
Routing agent (cont.)
21
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])));
}
}
Routing agent (cont.)
22
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
Needed changes
23
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
Example1 - TCP slow start
24
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
Example1 - TCP slow start (cont.)
25
Important variables for congestion control – slow
start
cwnd – congestion window
ssthresh – defines threshold between two slow start phase and
congestion control phase
Operations – 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)
Example1 - TCP slow start (cont.)
26
TCP standards
TCP Tahoe – slow start & congestion avoidance
TCP Vegas
TCP Reno
RFC 2581
TCP NewReno
RFC 2581
RFC 2582
FACK (forward acknowledgement)
SACK (selective acknowledgement)
RFC 2018
Example1 - TCP slow start (cont.)
27
TCP experiment – congestion window
TCP Tahoe
Slow-start
Congestion avoidance
Simulation topology
Source1 (TCP)
n2
Source2(UDP)
Value
#. Of nodes
4
Link capability
2Mbps
Simulation time
5(s)
Traffic type
CBR (UDP)
FTP(TCP)
Receiver
n0
n1
parameters
n3
Example2 – queuing system
28
Queuing systems
M/M/1
M/D/1
…
Notation
Arrival process/Service time/Servers
M = exponential, D = Deterministic, ….
Queuing system – M/M/1 (cont.)
29
Arrival & departure model
Poisson arrival
Exponential distribution
single server
Parameters
Arrival rate λ
Departure rate (service time) μ
load
(stability condition : ρ < 1)
E[Q] 1
(# of packets in system)
Queuing system – M/M/1 (cont.)
30
queue.tcl
Arrival rate : 30
Departure rate : 33
E[Q] = 10
Tips
31
Ns document is not easy to understand
Error message is not very useful
Understand and Implementation
Implementation issues
Iterative design
Conclusion
32
Basic concept of NS2
Two levels of simulation
Exist modules for NS beginner
Internet domain structure
33
Example of Internet domain structure