Skip to content

Instantly share code, notes, and snippets.

@candh
Created November 23, 2019 17:59
Show Gist options
  • Save candh/bc9188541a5c8cbfec2b0734ea61e59a to your computer and use it in GitHub Desktop.
Save candh/bc9188541a5c8cbfec2b0734ea61e59a to your computer and use it in GitHub Desktop.
[DCCN] 1st lab NS2
#Create a simulator object
set ns [new Simulator]
#Open the NAM trace file
set nf [open out.nam w]
$ns namtrace-all $nf
# Define finish procedure
proc finish {} {
global ns nf
$ns flush-trace
#close nam trace file
close $nf
#execute nam on the trace file
exec nam out.nam &
exit 0
}
#create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 5ms RED
$ns duplex-link-op $n0 $n2 orient right-up
$ns duplex-link-op $n1 $n2 orient up
$ns duplex-link-op $n2 $n3 orient right
$n0 shape hexagon
$n1 shape hexagon
$n3 shape hexagon
$ns at 10.0 "finish"
$ns run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment