Skip to content

Commit 530738a

Browse files
Add files via upload
1 parent af481ba commit 530738a

File tree

3 files changed

+253
-0
lines changed

3 files changed

+253
-0
lines changed

Congestion_Control_using_NS2.txt

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
set ns [new Simulator]
2+
set f [ open congestion.tr w ]
3+
$ns trace-all $f
4+
set nf [ open congestion.nam w ]
5+
$ns namtrace-all $nf
6+
$ns color 1 Red
7+
$ns color 2 Blue
8+
$ns color 3 White
9+
$ns color 4 Green
10+
set n0 [$ns node]
11+
set n1 [$ns node]
12+
set n2 [$ns node]
13+
set n3 [$ns node]
14+
set n4 [$ns node]
15+
set n5 [$ns node]
16+
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
17+
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
18+
$ns duplex-link $n2 $n3 0.3Mb 200ms DropTail
19+
$ns duplex-link $n3 $n4 0.5Mb 40ms DropTail
20+
$ns duplex-link $n3 $n5 0.5Mb 30ms DropTail
21+
set tcp1 [new Agent/TCP/Reno]
22+
$ns attach-agent $n0 $tcp1
23+
set tcp2 [new Agent/TCP/Reno]
24+
$ns attach-agent $n1 $tcp2
25+
set tcp3 [new Agent/TCP/Reno]
26+
$ns attach-agent $n2 $tcp3
27+
set tcp4 [new Agent/TCP/Reno]
28+
$ns attach-agent $n1 $tcp4
29+
$tcp1 set fid_ 1
30+
$tcp2 set fid_ 2
31+
$tcp3 set fid_ 3
32+
$tcp4 set fid_ 4
33+
set sink1 [new Agent/TCPSink]
34+
$ns attach-agent $n4 $sink1
35+
set sink2 [new Agent/TCPSink]
36+
$ns attach-agent $n5 $sink2
37+
set sink3 [new Agent/TCPSink]
38+
$ns attach-agent $n3 $sink3
39+
set sink4 [new Agent/TCPSink]
40+
$ns attach-agent $n4 $sink4
41+
$ns connect $tcp1 $sink1
42+
$ns connect $tcp2 $sink2
43+
$ns connect $tcp3 $sink3
44+
$ns connect $tcp4 $sink4
45+
set ftp1 [new Application/FTP]
46+
$ftp1 attach-agent $tcp1
47+
$ftp1 set type_ FTP
48+
set ftp2 [new Application/FTP]
49+
$ftp2 attach-agent $tcp2
50+
$ftp2 set type_ FTP
51+
set ftp3 [new Application/FTP]
52+
$ftp3 attach-agent $tcp3
53+
$ftp3 set type_ FTP
54+
set ftp4 [new Application/FTP]
55+
$ftp4 attach-agent $tcp4
56+
$ftp4 set type_ FTP
57+
set p0 [new Agent/Ping]
58+
$ns attach-agent $n0 $p0
59+
set p1 [new Agent/Ping]
60+
$ns attach-agent $n4 $p1
61+
$ns connect $p0 $p1
62+
Agent/Ping instproc recv {from rtt} {
63+
$self instvar node_
64+
puts "node [$node_ id] received ping answer from \
65+
$from with round-trip-time $rtt ms."
66+
}
67+
$ns at 0.2 "$p0 send"
68+
$ns at 0.3 "$p1 send"
69+
$ns at 0.5 "$ftp1 start"
70+
$ns at 0.6 "$ftp2 start"
71+
$ns at 0.7 "$ftp3 start"
72+
$ns at 0.8 "$ftp4 start"
73+
$ns at 66.0 "$ftp4 stop"
74+
$ns at 67.0 "$ftp3 stop"
75+
$ns at 68.0 "$ftp2 stop"
76+
$ns at 70.0 "$ftp1 stop"
77+
$ns at 70.1 "$p0 send"
78+
$ns at 70.2 "$p1 send"
79+
$ns at 80.0 "finish"
80+
proc plotWindow {tcpSource outfile} {
81+
global ns
82+
set now [$ns now]
83+
set cwnd_ [$tcpSource set cwnd_]
84+
puts $outfile "$now $cwnd_"
85+
$ns at [expr $now+0.1] "plotWindow $tcpSource $outfile"
86+
}
87+
set outfile [open "congestion.xg" w]
88+
$ns at 0.0 "plotWindow $tcp1 $outfile"
89+
proc finish {} {
90+
exec nam congestion.nam &
91+
exec xgraph congestion.xg -geometry 300x300 &
92+
exit 0
93+
}
94+
$ns run

Distance_Vector_using_NS2.txt

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
set ns [new Simulator]
2+
$ns color 1 Blue
3+
$ns color 2 Red
4+
set nr [open dv.tr w]
5+
set nr1 [open dv1.tr w]
6+
set nr2 [open dv2.tr w]
7+
$ns trace-all $nr
8+
set nf [open dvProgram1.nam w]
9+
$ns namtrace-all $nf
10+
proc finish { } {
11+
global ns nr nf
12+
$ns flush-trace
13+
close $nf
14+
close $nr
15+
exec nam dvProgram1.nam &
16+
exec xgraph dv1.tr dv2.tr -geometry 800x400 &
17+
exit 0
18+
}
19+
proc record {} {
20+
global sink0 sink1 nr1 nr2
21+
set ns [Simulator instance]
22+
set time 0.5
23+
set bw0 [$sink0 set bytes_]
24+
set bw1 [$sink1 set bytes_]
25+
set now [$ns now]
26+
puts $nr1 "$now [expr $bw0/$time*8/1000000]"
27+
puts $nr2 "$now [expr $bw1/$time*8/1000000]"
28+
$sink0 set bytes_ 0
29+
$sink1 set bytes_ 0
30+
$ns at [expr $now+$time] "record"
31+
}
32+
for { set i 0 } { $i < 13} { incr i 1 } {
33+
set n($i) [$ns node]}
34+
for {set i 0} {$i < 6} {incr i} {
35+
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
36+
$ns duplex-link $n(0) $n(2) 1Mb 10ms DropTail
37+
$ns duplex-link $n(0) $n(3) 1Mb 10ms DropTail
38+
$ns duplex-link $n(0) $n(5) 1Mb 10ms DropTail
39+
$ns duplex-link $n(0) $n(6) 1Mb 10ms DropTail
40+
$ns duplex-link $n(0) $n(4) 1Mb 10ms DropTail
41+
$ns duplex-link $n(1) $n(7) 1Mb 10ms DropTail
42+
$ns duplex-link $n(2) $n(8) 1Mb 10ms DropTail
43+
$ns duplex-link $n(3) $n(9) 1Mb 10ms DropTail
44+
$ns duplex-link $n(4) $n(10) 1Mb 10ms DropTail
45+
$ns duplex-link $n(5) $n(11) 1Mb 10ms DropTail
46+
$ns duplex-link $n(6) $n(12) 1Mb 10ms DropTail
47+
$ns duplex-link $n(6) $n(1) 1Mb 10ms DropTail
48+
$ns duplex-link $n(7) $n(12) 1Mb 10ms DropTail
49+
for {set i 7} {$i < 12} {incr i} {
50+
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
51+
set tcp0 [new Agent/TCP]
52+
$tcp0 set class_ 2
53+
$ns attach-agent $n(12) $tcp0
54+
set sink0 [new Agent/TCPSink]
55+
$ns attach-agent $n(0) $sink0
56+
$ns connect $tcp0 $sink0
57+
set ftp0 [new Application/FTP]
58+
$ftp0 attach-agent $tcp0
59+
$ftp0 set type_ FTP
60+
$ftp0 set packetSize_ 200
61+
set tcp1 [new Agent/TCP]
62+
$tcp1 set class_ 1
63+
$ns attach-agent $n(9) $tcp1
64+
set sink1 [new Agent/TCPSink]
65+
$ns attach-agent $n(0) $sink1
66+
$ns connect $tcp1 $sink1
67+
set ftp1 [new Application/FTP]
68+
$ftp1 attach-agent $tcp1
69+
$ftp1 set type_ FTP
70+
$ftp1 set packetSize_ 200
71+
$ns rtproto DV
72+
$ns rtmodel-at 2.0 down $n(0) $n(6)
73+
$ns rtmodel-at 3.0 down $n(0) $n(5)
74+
$ns rtmodel-at 2.0 down $n(0) $n(1)
75+
$ns rtmodel-at 20.0 up $n(0) $n(6)
76+
$ns rtmodel-at 2.0 down $n(3) $n(9)
77+
$ns rtmodel-at 2.0 down $n(6) $n(12)
78+
$ns rtmodel-at 10.0 up $n(6) $n(12)
79+
$ns rtmodel-at 15.0 up $n(3) $n(9)
80+
$ns rtmodel-at 18.0 up $n(0) $n(1)
81+
$ns rtmodel-at 25.0 up $n(0) $n(5)
82+
$ns at 0.0 "record"
83+
$ns at 0.2 "$ftp0 start"
84+
$ns at 1.0 "$ftp1 start"
85+
$ns at 30.0 "finish"
86+
$ns run

TCP_UDP_using_NS2.txt

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
set ns [new Simulator]
2+
$ns color 1 Blue
3+
$ns color 2 Red
4+
set file1 [open out.tr w]
5+
set winfile [open WinFile w]
6+
$ns trace-all $file1
7+
set file2 [open out.nam w]
8+
$ns namtrace-all $file2
9+
proc finish {} {
10+
global ns file1 file2
11+
$ns flush-trace
12+
close $file1
13+
close $file2
14+
exec nam out.nam &
15+
exit 0
16+
}
17+
set n0 [$ns node]
18+
set n1 [$ns node]
19+
set n2 [$ns node]
20+
set n3 [$ns node]
21+
set n4 [$ns node]
22+
set n5 [$ns node]
23+
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
24+
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
25+
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
26+
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
27+
$ns duplex-link $n3 $n4 0.5Mb 40ms DropTail
28+
$ns duplex-link $n3 $n5 0.5Mb 30ms DropTail
29+
$ns duplex-link-op $n0 $n2 orient right-down
30+
$ns duplex-link-op $n1 $n2 orient right-up
31+
$ns simplex-link-op $n2 $n3 orient right
32+
$ns simplex-link-op $n3 $n2 orient left
33+
$ns duplex-link-op $n3 $n4 orient right-up
34+
$ns duplex-link-op $n3 $n5 orient right-down
35+
$ns queue-limit $n2 $n3 20
36+
set tcp [new Agent/TCP/Newreno]
37+
$ns attach-agent $n0 $tcp
38+
set sink [new Agent/TCPSink/DelAck]
39+
$ns attach-agent $n4 $sink
40+
$ns connect $tcp $sink
41+
$tcp set fid_ 1
42+
$tcp set window_ 8000
43+
$tcp set packetSize_ 552
44+
set ftp [new Application/FTP]
45+
$ftp attach-agent $tcp
46+
$ftp set type_ FTP
47+
set udp [new Agent/UDP]
48+
$ns attach-agent $n1 $udp
49+
set null [new Agent/Null]
50+
$ns attach-agent $n5 $null
51+
$ns connect $udp $null
52+
$udp set fid_ 2
53+
set cbr [new Application/Traffic/CBR]
54+
$cbr attach-agent $udp
55+
$cbr set type_ CBR
56+
$cbr set packet_size_ 1000
57+
$cbr set rate_ 0.01mb
58+
$cbr set random_ false
59+
$ns at 0.1 "$cbr start"
60+
$ns at 1.0 "$ftp start"
61+
$ns at 124.0 "$ftp stop"
62+
$ns at 124.5 "$cbr stop"
63+
proc plotWindow {tcpSource file} {
64+
global ns
65+
set time 0.1
66+
set now [$ns now]
67+
set cwnd [$tcpSource set cwnd_]
68+
set wnd [$tcpSource set window_]
69+
puts $file "$now $cwnd"
70+
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
71+
$ns at 0.1 "plotWindow $tcp $winfile"
72+
$ns at 125.0 "finish"
73+
$ns run

0 commit comments

Comments
 (0)