This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

To drop packets

Website and forum-related announcements and discussion, and anything else that doesn't fit in the above forums.
Post Reply
j
jnc_xavier
Voice
Posts: 4
Joined: Sat Aug 20, 2011 8:40 am
Location: India

To drop packets

Post by jnc_xavier »

how do i write a basic tcl script in ns2 to drop packets in a wired scenario just by changing bandwidth n delay values.

this is my script:

Code: Select all

set val(stop)   7.0                         ;# time of simulation end 
 
#=================================== 
#        Initialization         
#=================================== 
#Create a ns simulator 
set ns [new Simulator] 
 
#Open the NS trace file 
set tracefile [open wr5nodes.tr w] 
$ns trace-all $tracefile 
 
#Open the NAM trace file 
set namfile [open wr5nodes.nam w] 
$ns namtrace-all $namfile 
 
#=================================== 
#        Nodes Definition         
#=================================== 
#Create 5 nodes 
set n0 [$ns node] 
set n1 [$ns node] 
set n2 [$ns node] 
set n3 [$ns node] 
set n4 [$ns node] 
 
#=================================== 
#        Links Definition         
#=================================== 
#Createlinks between nodes 
$ns duplex-link $n0 $n1 100.0Mb 10ms DropTail 
$ns queue-limit $n0 $n1 50 
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail 
$ns queue-limit $n1 $n2 50 
$ns duplex-link $n1 $n3 100.0Mb 10ms DropTail 
$ns queue-limit $n1 $n3 50 
$ns duplex-link $n1 $n4 100.0Mb 10ms DropTail 
$ns queue-limit $n1 $n4 50 
 
#Give node position (for NAM) 
$ns duplex-link-op $n0 $n1 orient right 
$ns duplex-link-op $n1 $n2 orient right-up 
$ns duplex-link-op $n1 $n3 orient right 
$ns duplex-link-op $n1 $n4 orient right-down

set tcp [new Agent/TCP]
set tcpsink [new Agent/TCPSink]
$ns attach-agent $n0 $tcp
$ns attach-agent $n1 $tcpsink
$ns connect $tcp $tcpsink

set tcp1 [new Agent/TCP]
set tcpsink1 [new Agent/TCPSink]
$ns attach-agent $n1 $tcp1
$ns attach-agent $n2 $tcpsink1
$ns connect $tcp1 $tcpsink1

set tcp2 [new Agent/TCP]
set tcpsink2 [new Agent/TCPSink]
$ns attach-agent $n1 $tcp2
$ns attach-agent $n4 $tcpsink2
$ns connect $tcp2 $tcpsink2

set tcp3 [new Agent/TCP]
set tcpsink3 [new Agent/TCPSink]
$ns attach-agent $n2 $tcp3
$ns attach-agent $n1 $tcpsink3
$ns connect $tcp3 $tcpsink3

set tcp4 [new Agent/TCP]
set tcpsink4 [new Agent/TCPSink]
$ns attach-agent $n1 $tcp4
$ns attach-agent $n0 $tcpsink4
$ns connect $tcp4 $tcpsink4

set tcp5 [new Agent/TCP]
set tcpsink5 [new Agent/TCPSink]
$ns attach-agent $n0 $tcp5
$ns attach-agent $n1 $tcpsink5
$ns connect $tcp5 $tcpsink5

set tcp6 [new Agent/TCP]
set tcpsink6 [new Agent/TCPSink]
$ns attach-agent $n1 $tcp6
$ns attach-agent $n3 $tcpsink6
$ns connect $tcp6 $tcpsink6

set tcp7 [new Agent/TCP]
set tcpsink7 [new Agent/TCPSink]
$ns attach-agent $n4 $tcp7
$ns attach-agent $n1 $tcpsink7
$ns connect $tcp7 $tcpsink7

set tcp8 [new Agent/TCP]
set tcpsink8 [new Agent/TCPSink]
$ns attach-agent $n2 $tcp8
$ns attach-agent $n1 $tcpsink8
$ns connect $tcp8 $tcpsink8

set tcp9 [new Agent/TCP]
set tcpsink9 [new Agent/TCPSink]
$ns attach-agent $n1 $tcp9
$ns attach-agent $n0 $tcpsink9
$ns connect $tcp9 $tcpsink9

set cbr [new  Application/Traffic/CBR] 
set cbr1 [new  Application/Traffic/CBR] 
set cbr2 [new  Application/Traffic/CBR]
set cbr3 [new  Application/Traffic/CBR]
set cbr4 [new  Application/Traffic/CBR]
set cbr5 [new  Application/Traffic/CBR]
set cbr6 [new  Application/Traffic/CBR]
set cbr7 [new  Application/Traffic/CBR]
set cbr8 [new  Application/Traffic/CBR]
set cbr9 [new  Application/Traffic/CBR]

$cbr attach-agent $tcp
$cbr1 attach-agent $tcp1
$cbr2 attach-agent $tcp2
$cbr3 attach-agent $tcp3
$cbr4 attach-agent $tcp4
$cbr5 attach-agent $tcp5
$cbr6 attach-agent $tcp6
$cbr7 attach-agent $tcp7
$cbr8 attach-agent $tcp8
$cbr9 attach-agent $tcp9
 
#Define a 'finish' procedure 
proc finish {} { 
    global ns tracefile namfile 
    $ns flush-trace 
    close $tracefile 
    close $namfile 
}

$ns at 0.5 "$cbr start" 	
$ns at 1.0 "$cbr stop"

$ns at 1.0 "$cbr1 start" 	
$ns at 1.5 "$cbr1 stop"

$ns at 1.5 "$cbr2 start" 	
$ns at 2.0 "$cbr2 stop"

$ns at 2.0 "$cbr3 start" 	
$ns at 2.5 "$cbr3 stop"

$ns at 2.5 "$cbr4 start" 	
$ns at 3.0 "$cbr4 stop"

$ns at 3.5 "$cbr5 start" 	
$ns at 4.0 "$cbr5 stop"

$ns at 4.0 "$cbr6 start" 	
$ns at 4.5 "$cbr6 stop"

$ns at 5.0 "$cbr7 start" 	
$ns at 5.5 "$cbr7 stop"

$ns at 5.0 "$cbr8 start" 	
$ns at 5.5 "$cbr8 stop"

$ns at 5.5 "$cbr9 start" 	
$ns at 6.0 "$cbr9 stop"
 
$ns at $val(stop) "$ns nam-end-wireless $val(stop)" 
$ns at $val(stop) "finish" 
$ns at $val(stop) "puts \"done\" ; $ns halt"
 
$ns run
Jan Xavier
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

This is mainly an eggdrop-oriented forum. Help with pure tcl-scripting shouldn't be much of a problem, as the tcl-syntax should be the same in most extensions.
However, support for an independent extension such as Ns2 is generally beyond this forum. If you seek aid in integrating Ns2 with eggdrop, we will gladly try and help with that - though this sounds more to me as a sole Ns2 issue.

I'll leave this thread for now though, in case there happens to be an Ns2- expert among the forum members.

/NML_375
Moderator
NML_375
j
jnc_xavier
Voice
Posts: 4
Joined: Sat Aug 20, 2011 8:40 am
Location: India

Post by jnc_xavier »

plz do help if someone's out there :(
Jan Xavier
Post Reply