AdvancedExample: advanced.ns

File advanced.ns, 1.8 kB (added by mike, 2 years ago)
Line 
1 source tb_compat.tcl
2 set ns [new Simulator]
3
4 # Create four nodes
5 set nodeA [$ns node]
6 set nodeB [$ns node]
7
8 # Create a RED duplex link
9 set link0 [$ns duplex-link $nodeA $nodeB 100Mb 0ms RED]
10
11 # Get the queue object for the nodeA/nodeb link and modify its RED params.
12 set queue0 [[$ns link $nodeA $nodeB] queue]
13 $queue0 set gentle_ 1
14 $queue0 set queue-in-bytes_ 0
15 $queue0 set limit_ 50
16 $queue0 set maxthresh_ 20
17 $queue0 set thresh_ 7
18 $queue0 set linterm_ 11
19 $queue0 set q_weight_ 0.004
20
21 # Create a UDP agent and attach it to nodeA
22 set udp0 [new Agent/UDP]
23 $ns attach-agent $nodeA $udp0
24
25 # Create a CBR traffic source and attach it to udp0
26 set cbr0 [new Application/Traffic/CBR]
27 $cbr0 set packetSize_ 500
28 $cbr0 set interval_ 0.005
29 $cbr0 attach-agent $udp0
30
31 # Create a TCP agent and attach it to nodeA
32 set tcp0 [new Agent/TCP]
33 $ns attach-agent $nodeA $tcp0
34
35 # Create a CBR traffic source and attach it to tcp0
36 set cbr1 [new Application/Traffic/CBR]
37 $cbr1 set packetSize_ 500
38 $cbr1 set interval_ 0.005
39 $cbr1 attach-agent $tcp0
40
41 # Create a Null agent (a UDP traffic sink) and attach it to node nodeB
42 set null0 [new Agent/Null]
43 $ns attach-agent $nodeB $null0
44
45 # Create a TCPSink agent (a TCP traffic sink) and attach it to node nodeB
46 set null1 [new Agent/TCPSink]
47 $ns attach-agent $nodeB $null1
48
49 # Connect the traffic sources with the traffic sinks
50 $ns connect $udp0 $null0 
51 $ns connect $tcp0 $null1
52
53 # And some events.
54 $ns at 60.0  "$cbr0  start"
55 $ns at 70.0  "$link0 bandwidth 10Mb duplex"
56 $ns at 80.0  "$link0 delay 10ms"
57 $ns at 90.0  "$link0 plr 0.05"
58 $ns at 100.0 "$link0 down"
59 $ns at 110.0 "$link0 up"
60 $ns at 115.0 "$cbr0  stop"
61        
62 $ns at 120.0 "$cbr1  start"
63 $ns at 130.0 "$cbr1  set packetSize_ 512"
64 $ns at 130.0 "$cbr1  set interval_ 0.01"
65 $ns at 140.0 "$link0 down"
66 $ns at 150.0 "$cbr1  stop"
67
68 #Run the simulation
69 $ns run