Created
November 10, 2013 17:58
-
-
Save scriptnull/7401533 to your computer and use it in GitHub Desktop.
Basics of TCL scripting.
UDP agent is used as example.
check http://csis.bits-pilani.ac.in/faculty/murali/resources/tutorials/ns2.htm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create ns | |
set ns [ new Simulator ] | |
#output file | |
set outputfile [ open out.nam w ] | |
$ns namtrace-all $outputfile | |
#trace file | |
set tracefile [ open out.tr w ] | |
$ns trace-all $tracefile | |
#node creation | |
set n0 [ $ns node ] | |
set n1 [ $ns node ] | |
#link creation | |
$ns duplex-link $n0 $n1 1mb 10ms DropTail | |
#agent creation | |
set udp0 [ new Agent/UDP ] | |
$ns attach-agent $n0 $udp0 | |
#udp ends in a null agent | |
set null0 [ new Agent/Null ] | |
$ns attach-agent $n1 $null0 | |
#connect UDP n Null agent | |
$ns connect $udp0 $null0 | |
#set color for UDP agent | |
$udp0 set class_ 1 red | |
#simulating traffic over the connection | |
set cbr0 [new Application/Traffic/CBR] | |
$cbr0 attach-agent $udp0 | |
proc finish {} { | |
global ns tracefile outputfile | |
$ns flush-trace | |
close $tracefile | |
close $outputfile | |
puts "running nam.... " | |
exec nam out.nam & | |
exit 0 | |
} | |
#start cbr traffic at 1st second of simulation | |
$ns at 1.0 "$cbr0 start" | |
#finish the ns simulation at 60 seconds | |
$ns at 60.0 "finish" | |
#run the ns simulator | |
$ns run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment