OneCompiler

network_simulation.tcl

86

Create a simulator object

set ns [new Simulator]

Create two nodes (node1 and node2)

set node1 [nsnode]setnode2[ns node] set node2 [ns node]

Create a link between the nodes with bandwidth, delay, and queue size

nsduplexlinkns duplex-link node1 $node2 1Mb 10ms DropTail

Create a TCP connection from node1 to node2

set tcp [new Agent/TCP]
nsattachagentns attach-agent node1 $tcp

Create a sink (receiver) on node2

set sink [new Agent/TCPSink]
nsattachagentns attach-agent node2 $sink

Set up a TCP connection between the nodes

nsconnectns connect tcp $sink

Set the start and stop times for the simulation

nsat0.5"starttrafficns at 0.5 "start-traffic tcp sink"sink" ns at 5.0 "finish"

Run the simulation

$ns run

Define the traffic pattern (for example, a simple TCP flow)

proc start-traffic {tcp sink} {
$tcp send 1000
}