Professional Documents
Culture Documents
CN Programs On NS2
CN Programs On NS2
OBJECTIVE
Write a script to evaluate the effect of network components on network performance to design and
implement LAN with various topologies.
THEORY
In wired network, nodes communicate using the communication model that consists of Transport
Control Protocol (TCP) agent, TCPSink agent, and File Transfer Protocol (FTP) application. The sender
node is attached to the TCP agent while the receiver node is attached to the TCPSink agent. The
connection between TCP agent and TCPSink agent is established using the keyword “connect”.
Transport agent (TCP) and application (FTP) are connected using the keyword “attach-agent”. TCP
agent sends data to TCPSink agent. On receiving the data packet, TCPSink agent sends the
acknowledgement to the TCP agent that in turn processes the acknowledgements and adjusts the data
transmission rate. The dropped packets interpreted as a sign of congestion. The alternative to this is
the model consisting of UDP (User Datagram Protocol) agent, Null agent, and CBR (Constant Bit Rate)
application where UDP agent attaches to nodes and Null agent signifies a sink, and connection is over
CBR, without any need of acknowledgements for communication.
In computer networking, topology refers to the layout of the connected devices. Bus networks use a
common backbone link to connect all devices. The single link acts as a shared communication medium
that devices attach to with an interface connector. In case of a ring network, every device has exactly
two neighbors for communication purposes. All messages travel through a ring in the same direction
(either clockwise or counterclockwise). A failure in any cable or device breaks the loop and can take
down the entire network.
The first ns2 TCL script builds a simple two node model following a bus topology, that is, a fixed link
between the two connected nodes. However, the link failure in the wired network leads to intolerable
performance degradation. Therefore, it becomes necessary to use an efficient routing protocol that
automatically recovers the link from the link failure. Distance Vector (DV) routing protocol
automatically recovers the link failure by using alternative path for data transmission. In Distance
Vector (DV), each node sends periodic route updates for every 2 seconds. Apart from the periodic
updates, each node/agent sends triggered updates as a result of changes in the forwarding table in
the node if any. This occurs either due to changes in the network topology or the node received a
route update and as a result, it composes a fresh route. This has been represented in the second tcl
script which shows a ring topology. Both these network topologies have been checked for
performance using awk scripts of average throughput and average end to end delay.
CODE
For a bus topology:
#Create a simulator object
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
$ns run
$ns rtproto DV
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
#Schedule events for the CBR agent and the network dynamics
$ns run
OUTPUT
For bus topology-
OBJECTIVE
Write a script to simulate the effects of queuing disciplines on network performance.
THEORY
Every node simulated by the ns2 tool consists of a buffer in the form of a queue to handle packets at
that node. Various queuing mechanisms suggest how the packets in the queue are managed, i.e.
inserted, removed or dropped based on the network conditions and requirements.
In Droptail queuing mechanism, each packet is treated identically and traffic is not differentiated. With
tail drop, when the queue is filled to its maximum capacity, the newly arriving packets are dropped
until the queue has enough room to accept incoming traffic. This is the most common queue
mechanism shown in the first tcl script here.
Stochastic Fairness Queuing (SFQ) is a classless queuing discipline available for traffic control. It does
not shape traffic but only schedules the transmission of packets, based on flows. The goal is to ensure
fairness so that each flow is able to send data in turn, thus preventing any single flow from drowning
out the rest. This may in fact have some effect in mitigating a Denial of Service attempt. SFQ is work-
conserving and therefore always delivers a packet if it has one available.
Random Early Detection (RED) is a congestion avoidance queuing mechanism (as opposed to a
congestion administration mechanism) that is potentially useful, particularly in high-speed transit
networks. It is an active queue management mechanism that operates on the average queue size and
drops packets on the basis of statistics information. If the buffer is empty, all incoming packets are
acknowledged. As the queue size increases, the probability for discarding a packet also increases.
When the buffer is full, the probability becomes equal to 1 and all incoming packets are dropped.
In terms of network performance, using RED in place of DropTail and SFQ in the given script yields
higher average throughput value and lesser average end to end delay.
CODE
#Create a simulator object
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
$ns run
OUTPUT
OBJECTIVE
Write a script to show advanced usage of tool with exponential traffic.
THEORY
Exponential traffic objects generate On/Off traffic. During "on" periods, packets are generated at a
constant burst rate. During "off" periods, no traffic is generated. Burst times and idle times are taken
from exponential distributions. Configuration parameters are:
PacketSize_ : constant size of packets generated
burst_time_ : average on time for generator
idle_time_ : average off time for generator
rate_ : sending rate during on time
This tcl script provides exposure to more diverse traffic generators and helps in learning the basics on
how to postprocess a simulation to get useful information.
The ns-allinone package consists of xgraph-a plotting program which can be used to create graphic
representations of simulation results.
CODE
set ns [new Simulator]
#Create 5 nodes
proc finish {} {
global f0 f1 f2
close $f0
close $f1
close $f2
exit 0
#'node' and attaches an Expoo traffic generator to the agent with the
#characteristic values 'size' for packet size 'burst' for burst time,
#'idle' for idle time and 'rate' for burst peak rate. The procedure connects
#the source with the previously defined traffic sink 'sink' and returns the
#source object.
return $traffic
#three traffic sinks sink0/1/2 and writes it to the three files f0/1/2.
proc record {} {
#Set the time after which the procedure should be called again
$ns run
OUTPUT
The x axis of graph records the time in ms and the y axis denotes the bandwidth in Mbps. The
different colored graph lines depict the record for the different trace files with varying traffic rates.