Lab Experiment 6
Lab Experiment 6
Implement an Ethernet LAN using n nodes and set multiple traffic nodes and
plot congestion window for different source / destination.
Topology
Code-
#set ns Simulator
set ns [new Simulator]
#create 6 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
$n1 shape box
The line set winfile [open winfile w] in Tcl is used to open a file named "winfile"
in write mode.
set winfile: This command creates a variable named winfile.
[open winfile w]: This part of the command opens a file named "winfile" in write
mode (w). The open command is used to open a file, and w specifies that the file
should be opened for writing. If the file does not exist, it will be created; if it does
exist, its contents will be truncated.
So, after executing this line, the variable winfile will hold the file handle for the
opened file, and you can use it to write data to the file.
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/802_3]
The line is creating a local area network (LAN) and associating it with three nodes ($n3,
$n4, and $n5).
set lan: This command creates a variable named lan to store the reference to the newly created
LAN.
$ns newLan: This command is a custom function or procedure used to create a new LAN.
"$n3 $n4 $n5": This string specifies the nodes that are part of the LAN. The nodes are $n3,
$n4, and $n5.
0.5Mb: Specifies the bandwidth of the LAN, in this case, it's set to 0.5 megabits per second.
40ms: Specifies the propagation delay of the LAN, here set to 40 milliseconds.
LL: Specifies the link layer type, likely set to LL (Link Layer).
Queue/DropTail: Specifies the type of queue used in the LAN, here set to a drop-tail queue.
MAC/802_3: Specifies the Medium Access Control (MAC) layer type, here set to
MAC/802_3, which is commonly used for Ethernet.
After this line is executed, the lan variable will hold the reference to the newly created LAN
object. This LAN can be used to model communication and interactions between the specified
nodes within the ns-2 simulation.
● These lines are setting some parameters for a TCP agent in an ns-2 simulation.
● $tcp set fid_ 1: This line sets the flow ID (fid_) of the TCP agent ($tcp) to 1. The flow
ID is a unique identifier assigned to a specific flow or connection in the simulation. It
helps distinguish between different flows of data.
● $tcp set packetSize_ 552: This line sets the packet size (packetSize_) of the TCP agent
($tcp) to 552 bytes. The packet size is the size of the data payload in each packet
transmitted by the TCP agent.
● These lines are used to create and write header information to a file
named "congestion1.xg."
● set outfile1 [open congestion1.xg w]: This line creates a file handle
(outfile1) by opening a file named "congestion1.xg" in write mode (w).
The file handle will be used for writing data to the file.
● These commands are preparing a file for storing data related to congestion
window size over time in the context of a network simulation.
proc plotWindow {tcpSource outfile} { ... }: This line defines a procedure named
plotWindow that takes two parameters, tcpSource (presumably a TCP source
agent) and outfile (the file handle for the output file).
global ns: This line declares the use of the global variable $ns, which typically
represents the ns-2 simulator instance.
set time 0.1: Sets the variable time to 0.1. This is the time interval at which the
procedure will be called to update the plot.
set now [$ns now]: Gets the current simulation time using $ns now and assigns
it to the variable now.
set cwnd [$tcpSource set cwnd_]: Retrieves the congestion window size (cwnd_)
from the TCP source agent ($tcpSource).
puts $outfile "$now $cwnd": Writes a line to the output file, containing the
current simulation time and the congestion window size.