CN Lab Manual
CN Lab Manual
CN Lab Manual
.Common NS classes
The following figure shows the most commonly used NS classes in writing anetwork simulation:
Application/FTP
Agent/TCP/Reno Agent/TCPSink
Node Node
$NS duplex-link
2. Links: links are created using the duplex-link method call in an Ns simulation object.
5. Application/FTP: simulate an continuously transmitting agent that uses a TCP protocol (Tahoe, Reno, or some other version of
TCP)
A Application/FTP needs to be attached to some TCP agent (see figure)
1.Create transport source agents (Agent/TCP/Reno) and transport sink agents (Agent/TCP/Sink)|
2. Associate the transport source/sink agent to a end point node
3. Connect a source transport agent to a transport sink agent
.Using NS
oIn order to use the NS simulator, you need to create a Simulator object
o Example:
.Creating Nodes in NS
o The Node class in NS is used to simulate routers
oThe node must be created through the special method node defined in the Simulator class.
object in NS that you use to simulate ONE
router:
The following expression will return a Node
[Sns node]
o Use a set command to remember the Node object in some variable (e.g., n0):
.Creating Linksin NS
o Links in NS are used to provide connectivity between Nodes (routers)
3. Propagation delay
Often, you want to experiment with the same network configuration but using diferent bottleneck link capacities.
For example, the bottleneck link isftimes the normal bandwidth in other network links
o Trick:
set bw 10
set f 9.5
o
Example: set the queue length to 10 packets
o Each class (DropTail, RED, FQ, etc) of queue has its own default queue size
oYou can change the buffer size ofa class of queue using the set queue-limit command in the class Queue/QUEUE-CLASS
.Routingin NS
After you created the nodes and connected them through links, NS will provide Internet routing automatically
oSo, aftercreated the nodes and connected them through links, you have an Internet.
o All you need to do now is:
Add transport protocol to the end point nodes (no need to do so to intermediate nodes)
oThere are an ever increasing number ofsending transport agents (because people are developing new TCP transnmission protocols to
improve network performance.
o There are 2 receiving transport agents that sends back ACKs to the sending agent.
2. Agent/TCPSink/DelAck: ACK is delayed. Receiver sends ACK packet after receiving 2 packets or after a certain delay
(tries to reduce number of ACK packets)
Example:
o Example:
set ns [new Simulator
set node1 [$ns node]
set tcp1 [new Agent/TCP/Reno]
o Exanmple:
(tcp1 and sink1 must also be attached to nodes, this step is omitted)
o After a TCP agent has been created, you can set some of its parameters (using the set command of the TCP agent)
Example:
new Application/FTP
o Example:
[new Application/FTP]
set ftp1
.Associating FTP Traffic Generator with a TCP protocl module
o You need to associate a FTP traftic generator with a sending TCP module
oThe association is made using the attach-agent method defined in the Application/FTP class.
o Example:
oThe FTP traffic generator canbe stopped usingthe stap method defined in the Application/FTP class.
o Example:
o NOTE: the TCP module does not need to be stopped and in fact, cannot be stopped.
When the FTP traffic generator stops generating traffic, TCP will have no data to send and will "go quiet"
You can start the FTP again after stopping it.
Part- A Programs
.Implenment three nodes point - to - point network with duplex links berwee
the queue size, ped.
vary the bandwidth, and find the number of
packets uP
procfinish (0
$ns flush-trace
close $ntrace
close $namfile
HExecute NAM Animation file.
#To call subprocesses within another process, exec is used, which creates a suopr
it to complete.
*Brep" isa simple yet powerful unix/linux command. It searchesfor a given string
is the syntax of grep
exit 0
#Give node
position/orientation (for NAM)
$ns duplex-link-op $no $ni orient right
# You can modify the que length as well to observe variation in packet.
Stcp0set class_1
#Schedule events
$ns at 0.0 "$ftp0 start"
$ns run
$ns flush-trace
close $ntrace
close $namfile
exit
#Connect the nodes with two links $ns duplex-link $no $n1 1Mb 10ms DropTail
and n5
#Create two ping agents and attach them to the nodes n0
$p0set class_1
Sns attach-agent $n(0) $po
# You can modify the que length as well to observe variation in packet.
#create Congestion
#Schedule events
$ns run