1+ # STEP1
2+ set ns [new Simulator]
3+ set tf [open p2p_code.tr w]
4+ $ns trace-all $tf
5+ set nm [open p2p_code.nam w]
6+ $ns namtrace-all $tf
7+
8+ # STEP2 Building Topology
9+ # A
10+ set n0 [$ns node]
11+ set n1 [$ns node]
12+ set n2 [$ns node]
13+ set n3 [$ns node]
14+
15+ # B : name the nodes
16+ $n0 label " Source1/udp0"
17+ $n1 label " Source2/udp1"
18+ $n2 label " IntermidiateNode/Router"
19+ $n3 label " Destination Node"
20+
21+ # C : Vary bandwidth to observe packet drop
22+ $ns duplex-link $n0 $n2 10Mb 300ms DropTail
23+ $ns duplex-link $n1 $n2 10Mb 300ms DropTail
24+ $ns duplex-link $n2 $n3 1Mb 300ms DropTail
25+
26+ # D : Set queue size between node
27+ $ns set queue-limit $n0 $n2 10
28+ $ns set queue-limit $n1 $n2 10
29+ $ns set queue-limit $n2 $n3 5
30+
31+ # E : Color the Packets
32+ $ns color 1 " green"
33+ $ns color 2 " yellow"
34+
35+ # Step3
36+ # A : Attach udp agents to n0 and n1 and null agent to n3
37+ set udp0 [new Agent/UDP]
38+ $ns attach-agent $n0 $udp0
39+
40+ set cbr0 [new Application/Traffic/CBR]
41+ $cbr0 attach-agent $udp0
42+
43+ set null3 [new Agent/Null]
44+ $ns attach-agent $n3 $null3
45+
46+ set udp1 [new Agent/UDP]
47+ $ns attach-agent $n1 $udp1
48+
49+ set cbr1 [new Application/Traffic/CBR]
50+ $cbr1 attach-agent $udp1
51+
52+ # B : set udp0 to respective color
53+ $udp0 set class_ 1
54+ $udp1 set class_ 2
55+
56+ # step4 : connecting agents
57+ $ns connect $udp0 $null3
58+ $ns connect $udp1 $null3
59+
60+ # step5 : set parameter
61+ $cbr1 set packetSize_ 200Mb
62+ # set packet interal
63+ $cbr1 set interval_ 0.001
64+
65+
66+ # Step6
67+ proc finish { } {
68+ global ns tf
69+ $ns flush-trace
70+ exec nam egl-nam
71+ close $tf
72+ exit 0
73+ }
74+
75+ $ns at 0.1 " $cbr0 start"
76+ $ns at 0.5 " $cbr1 start"
77+ $ns at 10.0 " finish"
78+ $ns run
0 commit comments