Title: A Tutorial of NS2 and its Wireless Simulation
1A Tutorial of NS-2 and its Wireless Simulation
2Agenda
- Introduction to NS-2
- What is NS-2
- NS-2 vs GloMoSim OPNET
- NS-2 Basics
- Wireless Simulation
- PHY Layer
- MAC Layer
- Example My Fading Extension
- Bugs
3What is NS-2
- NS-2 (Network Simulator 2) is
- a TCL interpreter ?
- a C project ?
- a protocol stack ?
- NS-2 is
- a network simulator using TCL scripts as
configuration interface and using C
objects/functions to simulate network
components/protocols
4What is NS-2 (cont)
- NS-2
- can do packet level simulation
- supports a variety of wired/wireless protocols
- is essentially a centralized discrete event
scheduler - For more information
- NS-2 http//www.isi.edu/nsnam/ns/
- Baisi Forum http//www.baisi.net/forum-440-1.html
- My wireless tutorial http//www.cse.cuhk.edu.hk/
ywang/ns2.html
5NS-2 vs GloMoSim OPNET
6NS-2 Basics
7NS-2 Basics (cont)
- Network Components
- Simple components
- correspond to a single C object
- Compound components
- a combination of multiple simple components
- Example
8NS-2 Basics (cont)
- Node component
- Link component
9NS-2 Basics (cont)
- class Event
- defined by time, uid, next, handler
- class Packet is a subclass of Event
- Timer is a subclass of Event
- class Handler
- All network components are its subclasses
- TimerHander which handles expired timers
- Scheduler
- void Schedulerschedule(Handler h, Event e,
double delay)
10NS-2 Basics (cont)
Note There are no real time, timer and packet
tx/rx in ns-2 as in UNIX network programming.
11NS-2 Basics (cont)
- Example 1 A and B are two mobile nodes within tx
range. A wants to send packet p to B.
12NS-2 Basics (cont)
13NS-2 Basics (cont)
- recv function is often the entry to each network
component / protocol - e.g. in 802.11
14Wireless Simulation
- The inner structure of a wireless node
-
15Limitations in Simulating Mobile Wireless Networks
- Nodes do not move significantly over the length
of time they transmit or receive a packet. This
assumption holds only for mobile nodes of
high-rate and low-speed. - Consider a node with the sending rate of 10Kbps
and moving speed of 10m/s, during its receiving a
packet of 1500B, the node moves 12m. Thus, the
surrounding can change significantly and cause
reception failure. - Node velocity is insignificant compared to the
speed of light. In particular, none of the
provided propagation models include Doppler
effects, although they could.
16PHY layer class Channel
- Its function is to deliver packets from a
wireless node to its neighbors within sensing
range - I. Stamp txinfo in packets before sending, for
receivers to calculate receiving power -
- II. Send packets to the nodes within the sensing
range distCST_ for sensing or receiving
17PHY layer class WirelessPhy (NetIF)
- Its function is to transmit/receive packets
to/from Channel - Transmitting
- Receiving
- Calculate receiving power
- can not sense the packet
- can sense but can not decode the packet
- can decode the packet (Note that SNR will be
checked in MAC layer for finally receiving the
packet)
18MAC layer class Mac802_11 (cont)
- Its function is to send/receive packets to/from
NetIF - Sending CSMA/CA
- Receiving SNR threshold based capture model
- Need to understand its state transition diagram
19MAC layer class Mac802_11 (cont)
20MAC layer class Mac802_11 (cont)
21MAC layer class Mac802_11 (cont)
22MAC layer class Mac802_11 (cont)
- Example 1 controlling backoff timer
23MAC layer class Mac802_11 (cont)
- Sending packets (CSMA/CA)
Note Packets will be transmitted in
backoffHandler() after mhBackoff_ expires
24MAC layer class Mac802_11 (cont)
- Receiving packets (capture)
25My Fading Extension
- Standard NS-2 does not consider fading effect
26Example 1 of fading effect
- How fading affects TCP throughput
(a) Without fading
(b) With fading
27Example 2 of fading effect
- How fading affects flow fairness
(a) Without fading
(b) With fading
28Bugs in NS-2
- Oversimplifications
- E.g. there is no scanning for WLAN
(Discovery/Select/Authentication/Association) - Standard Misinterpretation
- E.g. abuse of EIFS
29