Title: to Using the Network Simulator NS
1- Introduction
- to Using the Network Simulator NS
- by Chung Ling Chi, Gigi
2Outline
- Introduction
- Interface to the Interpreter (The duality of OTcl
and C) - Topology Generation, the nodes and the links
- Agents
- Example
- Conclusion
3Introduction
- NS is a discrete event simulator targeted at
networking research. - Network researchers can study the complex
interactions between network protocols in complex
topologies and with a rich set of traffic
generators. - extend its functionality
4Otcl and C The Duality
Interface to the Interpreter
- NS is an object oriented simulator, written in
C, with an OTcl interpreter as a frontend.
5OTcl Linkage
Interface to the Interpreter
- C ltgt OTcl
- class Tcl C methods to access the interpreter
- class TclObject Root of basic object hierarchy in
ns - class TclClass C class to set up the TclObject
- hierarchy
- class TclCommand Basic Script to provide limited
global - commands to the interpreter
- class EmbeddedTcl Container for Tcl scripts that
are - pre-loaded at startup
- class InstVar Internal class to bind C member
- variables to OTcl instance variables
6Class Tcl
Interface to the Interpreter
- The class Tcl
- Obtain a handle
- Invoke Otcl procedures
- Retrieve the result from the interpreter
- On invocation, pass a result string to the
interpreter - Return Success/Failure return codes
7Class Tcl C Methods to access OTcl
Interface to the Interpreter
8Class TclObject
Interface to the Interpreter
- Base class for most classes in the interpreted
and compiled hierarchies of ns - Hierarchy mirrored in C and OTcl
- For example
9Class TclObject Hierarchy and Shadowing
Interface to the Interpreter
10Class TclObject Creation/Deletion Mechanisms
Interface to the Interpreter
- Global procedure new
- Global procedure delete
11Class TclObject Binding Variables
Interface to the Interpreter
- Makes identical C member variables to Otcl
instance variables - Syntax
- Initialisation through OTcl class variables
- Other methods bind() (integer), bind_time()
(time variables), bind_bw() (bandwidth
variables), bind_bool() (boolean variables)
12Examples of Specify Bound Variables
Interface to the Interpreter
13Class TclObject command() methods
Interface to the Interpreter
- Shadow object is accessed by a cmd procedure,
called instproclike - For example, distance? is an instance
procedure of an Adaptive SRM agent
14command() methods call sequence
Interface to the Interpreter
15Class TclClass
Interface to the Interpreter
- Programmer defines C hierarchy that is mirrored
in Otcl - not all classes are mirrored exactly
16Class TclClass Definition
Interface to the Interpreter
- For example, Adaptive SRM agent class in C is
mirrored into Agent/SRM/Adaptive
17Class TclClass Mechanism
Interface to the Interpreter
- Static initialisation by compiler
- Run time activation at startup
18Class InstVar
Interface to the Interpreter
- One object per bound variable
- Created by TclObjectbind() call
- Constructor activity
- 1. Point to C member variable
- 2. Create instance variable for interpreted
object - 3. Enable trap read/writes to instance variable
- using Tcl_TraceVar()
19OTcl Linkage Summary
Interface to the Interpreter
- Class Tcl
- primitives to access the interpreter
- Class TclObject root object for mirrored
hierarchies - Unifies interpreted and compiled hierarchy
- Provide seamless access to ns objects in compiled
code and interpreted scripts - Class TclClass class that sets up the
interpreted hierarchy - establish interpreted hierarchy
- shadowing methods
20Nodes
Topology Generation
- Configuring the node
- -- Control function
- -- Address and port number
- management,
- unicast routing functions
- -- Agent management
- -- Adding neighbors
21Multicast Node
Topology Generation
22Classifiers
Topology Generation
- Table of slots
- Each slot can point to a TclObject
- When a packet is received
- classify() identifies the slot to forward the
packet to - If slot is invalid, the classifier calls
no-slot() - Many different types of classifiers
- Address Classifier parse address in packet
- Multipath Classifier returns next slot number to
use - Replicator uses classifier as a table
23Classifier Methods
Topology Generation
- Install entries into classifier
- install
- installNext
- Query entries in classifier
- elements returns current list of elements
inserted - slot returns handle of object in the specified
slot - Delete entry in a particular slot
- clear
- classify internal method receives a packet,
and returns a slot number for that packet
24Links
Topology Generation
25Connectors
Topology Generation
- Connectors receive incoming packets, and usually
transmit them to their target or drop-target_ - Many different types of connectors
- Queue holds a certain number of
packets. Packets exceeding their queue-size
are sent to the queues trop-target_. - DelayLink models delay/bandwidth of the link for
detailed simulations. - DynaLink decrements TTLs on each packet, drops
the packer if the TTL becomes zero. - TTLChecker transmit packets if the link is up,
drop packet otherwise
26Connector methods
Topology Generation
- Add tracing or monitoring
- Library support
- trace
- attach-monitors
- init-monitor
- C Trace class objects are implemented
- Define trace file format
- example of trace file
27Agents
Agents
- Endpoints where network-layer packets are
constructed or consumed - implementation of protocols at various layers
- Agent state
28Agent Methods
Agents
- Packet generation and reception
- Packet allocpkt() allocate new packet and assign
its fields - Packet allocpkt(int) allocate new packet with a
data payload of n bytes and assign its fields - Member functions to be over-ridden by classes
- void timeout(timeout number)
- subclass-specific time out method
- void recv(Packet, Handler)
- receiving agent main receive path of packets
29Protocol Agents
Agents
30OTcl Linkage
Agents
- Creating and Manipulating Agents
- Default Values
- link bind member variable between OTcl and C
(in ns/tcl/lib/ns-default)
31Tcp, TCP Sink Agents
Example
- Agents
- Class TCPAgent a simplified TCP sender to send
packet - Class TCPSinkAgent receiving the packets and
return acknowledgments - Creating the Agent
- OTcl code
32Tcp, TCP Sink Agents
Example
33Tcp, TCP Sink Agents
Example
- Starting the agent
- OTcl code
- C code
34Tcp, TCP Sink Agents
Example
- Processing Input at Receiver (class TcpSinkAgent)
35Tcp, TCP Sink Agents
Example
- Processing Responses at the Sender (class
TcpAgent)
36Tcp, TCP Sink Agents
Example
- Implementing Timers
- derived from an abstract base class TimerHandler
- public member functions
- protected members
37Tcp, TCP Sink Agents
Example
- agent wish to override the Agenttimeout()
method - Timers used in Tahoe TCP Agent
- delsnd_timer_ delays sending of packets by a
small random amount of time to avoid phase
efforts - rtx_timer_ retransmission timer
- burstsnd_timer_ helps TCP to stagger the
transmission of a large window into several
smaller bursts
38Tcp, TCP Sink Agents
Example
- Three timer classes (in ns/tcp.h)
39Tcp, TCP Sink Agents
Example
- Timer initalized with this pointer
40Tcp, TCP Sink Agents
Example
- Define schedule timer events
41Tcp, TCP Sink Agents
Example
42Tcp, TCP Sink Agents
Example
set ns new Simulator set f open out.tr w ns
trace-all f set nf open out.nam w ns
namtrace-all nf set s1 ns node set s2 ns
node set r1 ns node set k1 ns node ns
duplex-link s1 r1 10Mb 0.1ms DropTail ns
duplex-link s2 k1 10Mb 0.1ms DropTail ns
simplex-link r1 k1 3.20Mb 20ms DropTail ns
simplex-link k1 r1 0.032Mb 20ms DropTail ns
queue-limit r1 k1 8 ns queue-limit k1 r1 8
43Tcp, TCP Sink Agents
Example
set tcp ns create-connection TCP s1 TCPSink
s2 1 tcp set fid_ 1 tcp set flow_id 1 tcp
set window_ 1000 set ftp tcp attach-app
FTP ns at 0.0 "ftp start" ns at 50.0
"finish" proc finish global ns f nf ns
flush-trace close f close nf puts "running
nam..." exec nam out.nam exit 0 ns run
44Tcp, TCP Sink Agents
Example
- Using Nam
- Tcl/TK based animation tool for viewing network
simulation traces and real world packet trace
data. - The trace file is generated by ns (out.nam)
k1
s1
s2
r1
45Tcp, TCP Sink Agents
Example
46Tcp, TCP Sink Agents
Example
- View the information of packet and ack
47Tcp, TCP Sink Agents
Example
- Analysis on the trace file (out.tr)
48Conclusion
- ftp//mash.cs.berkeley.edu/dist/vint/
- download software ns-allinone-2.1b5a
- run in Unix
- http//www-mash.cs.berkeley.edu/ns/
- download documentation