Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

Ph lc

PH LC

M ngun m phng DiffServ trong IP


set ns [new Simulator]
set nf_nam [open script2.nam w]
$ns namtrace-all $nf_nam
set nf [open script2.tr w]
$ns trace-all $nf
set f1 [open UDP1.tr w]
puts $f1 \n\"UDP_EF"
set f2 [open UDP2.tr w]
puts $f2 \n\"UDP_AF"
set f3 [open UDP3.tr w]
puts $f3 \n\"UDP_BE"
# So do ket noi mang
#
#
R0
---------R4--+--R8
#
\
/
|
\
/
# 10M ,5ms \ /
|
\ /
# R1------------ R3
|
R7-----------R9
#
/ \
|
/ \
#
/ \ 5M, 10ms |
/ \
#
R2
R5-----------R6 ---/
R10
foreach i "0 1 2 3 4 5 6 7 8 9 10" {
set R$i [$ns node]
}
# Khai bao link: nodes bw delay queue
$ns duplex-link $R0 $R3 10Mb 5ms DropTail
$ns duplex-link $R1 $R3 10Mb 5ms DropTail
$ns duplex-link $R2 $R3 10Mb 5ms DropTail
$ns simplex-link $R3 $R4
$ns simplex-link $R4 $R3
$ns simplex-link $R3 $R5
$ns simplex-link $R5 $R3
$ns simplex-link $R5 $R6
$ns simplex-link $R6 $R5
$ns simplex-link $R4 $R6
$ns simplex-link $R6 $R4

5Mb 10ms dsRED/edge


5Mb 10ms dsRED/core
5Mb 10ms RED
5Mb 10ms RED
5Mb 10ms RED
5Mb 10ms RED
5Mb 10ms dsRED/core
5Mb 10ms dsRED/edge

Ph lc

$ns simplex-link $R4 $R7


$ns simplex-link $R7 $R4
$ns simplex-link $R6 $R7
$ns simplex-link $R7 $R6

5Mb 10ms dsRED/core


5Mb 10ms dsRED/edge
5Mb 10ms RED
5Mb 10ms RED

$ns duplex-link $R7 $R8 10Mb 5ms DropTail


$ns duplex-link $R7 $R9 10Mb 5ms DropTail
$ns duplex-link $R7 $R10 10Mb 5ms DropTail
# Dinh nghia cac bien hang doi
set qEdge1ToCore [[$ns link $R3 $R4] queue]
set qEdge2ToCore [[$ns link $R7 $R4] queue]
set qEdge3ToCore [[$ns link $R6 $R4] queue]
set qCoreToEdge1 [[$ns link $R4 $R3 ] queue]
set qCoreToEdge2 [[$ns link $R4 $R7 ] queue]
set qCoreToEdge3 [[$ns link $R4 $R6 ] queue]
# Thiet lap thong so DiffServ va mode hoat dong
$qEdge1ToCore meanPktSize $packetSize
$qEdge1ToCore set numQueues_
3
$qEdge1ToCore setNumPrec
3
$qEdge1ToCore setSchedularMode PRI
$qEdge1ToCore addPolicyEntry [$R0 id] [$R8 id] TSW3CM 10 $ensureServCIR
$ensureServPIR
$qEdge1ToCore addPolicyEntry [$R1 id] [$R9 id] TSW3CM 20
$bestEffortServ1CIR $bestEffortServ1PIR
$qEdge1ToCore addPolicyEntry [$R2 id] [$R10 id] TSW3CM 30
$bestEffortServ2CIR $bestEffortServ2PIR
$qEdge1ToCore addPolicerEntry TSW3CM 10 11 12
$qEdge1ToCore addPolicerEntry TSW3CM 20 21 22
$qEdge1ToCore addPolicerEntry TSW3CM 30 31 32
$qEdge1ToCore addPHBEntry 10
0 0
$qEdge1ToCore addPHBEntry 11
0 1
$qEdge1ToCore addPHBEntry 12
0 2
$qEdge1ToCore addPHBEntry 20
1 0
$qEdge1ToCore addPHBEntry 21
1 1
$qEdge1ToCore addPHBEntry 22
12
$qEdge1ToCore addPHBEntry 30
2 0
$qEdge1ToCore addPHBEntry 31
2 1
$qEdge1ToCore addPHBEntry 32
2 2
$qEdge1ToCore addPHBEntry 0
2 2
$qEdge1ToCore configQ
0 0 20 40 0.01

Ph lc

$qEdge1ToCore configQ
$qEdge1ToCore configQ
$qEdge1ToCore configQ
$qEdge1ToCore configQ
$qEdge1ToCore configQ
$qEdge1ToCore configQ
$qEdge1ToCore configQ
$qEdge1ToCore configQ

0
0
1
1
1
2
2
2

1
2
0
1
2
0
1
2

10
10
20
10
10
20
10
10

50 0.1
50 0.3
40 0.01
50 0.1
50 0.3
40 0.01
50 0.1
50 0.3

#--------------------------------------------------------# Thiet lap luu luong


set sink1 [new Agent/LossMonitor]
$ns attach-agent $R8 $sink1
$sink1 clear
set sink2 [new Agent/LossMonitor]
$ns attach-agent $R9 $sink2
$sink2 clear
set sink3 [new Agent/LossMonitor]
$ns attach-agent $R10 $sink3
$sink3 clear
set null1 [new Agent/Null]
$ns attach-agent $R8 $null1
set null2 [new Agent/Null]
$ns attach-agent $R9 $null2
set null3 [new Agent/Null]
$ns attach-agent $R10 $null3
# Thiet lap cac luong UDP tu nguon den dich
set udp1 [new Agent/UDP]
$udp1 set packetSize_ $ensureServPacketSize
$ns attach-agent $R0 $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ $ensureServPacketSize
$cbr1 set rate_ $ensureServRate
$cbr1 attach-agent $udp1
$udp1 set fid_ 1
$ns color 1 red
$ns connect $udp1 $sink1
set udp2 [new Agent/UDP]
$udp2 set packetSize_ $bestEffortServ1PacketSize
$ns attach-agent $R1 $udp2

Ph lc

set cbr2 [new Application/Traffic/CBR]


$cbr2 set packetSize_ $bestEffortServ1PacketSize
$cbr2 set rate_ $bestEffortServ1Rate
$cbr2 attach-agent $udp2
$udp2 set fid_ 2
$ns color 2 green
$ns connect $udp2 $sink2
set udp3 [new Agent/UDP]
$udp3 set packetSize_ $bestEffortServ2PacketSize
$ns attach-agent $R2 $udp3
set cbr3 [new Application/Traffic/CBR]
$cbr3 set packetSize_ $bestEffortServ2PacketSize
$cbr3 set rate_ $bestEffortServ2Rate
$cbr3 attach-agent $udp3
$udp3 set fid_ 3
$ns color 3 blue
$ns connect $udp3 $sink3
#---------------------------------------------------------# Thu tuc xuat tong so packet nhan duoc o cac sink
proc recv-pkts {} {
global sink1 sink2 sink3 f1 f2 f3
set ns [Simulator instance]
set msg " Luong UDP1 da truyen [$sink1 set expected_] goi, mat [$sink1 set
nlost_] goi, ti le mat goi la [string range [expr [$sink1 set nlost_]*100.0/[$sink1 set
expected_]] 0 3] */*"
puts $msg
$ns trace-annotate $msg
set msg " Luong UDP2 da truyen [$sink2 set expected_] goi, mat [$sink2 set
nlost_] goi, ti le mat goi la [string range [expr [$sink2 set nlost_]*100.0/[$sink2 set
expected_]] 0 3] */*"
puts $msg
$ns trace-annotate $msg
set msg " Luong UDP3 da truyen [$sink3 set expected_] goi, mat [$sink3 set
nlost_] goi, ti le mat goi la [string range [expr [$sink3 set nlost_]*100.0/[$sink3 set
expected_]] 0 3] */*"
puts $msg
$ns trace-annotate $msg

Ph lc

#---------------------------------------# Thu tuc bat bang thong


proc record {} {
global sink1 totalpkt1 f1 sink2 totalpkt2 f2 sink3 totalpkt3 f3
set ns [Simulator instance]
set time 0.05
#How many bytes have been received by the traffic sink?
set bw1 [$sink1 set bytes_]
set bw2 [$sink2 set bytes_]
set bw3 [$sink3 set bytes_]
set now [$ns now]
# Tinh bang thong (MBit/s)
puts $f1 "$now [expr $bw1/$time*8/1000000]"
puts $f2 "$now [expr $bw2/$time*8/1000000]"
puts $f3 "$now [expr $bw3/$time*8/1000000]"
$sink1 set bytes_ 0
$sink2 set bytes_ 0
$sink3 set bytes_ 0
$ns at [expr $now+$time] "record"
}
#--------------------------------------------------# Thu tuc goi ham ket thuc
proc finish {} {
global ns nf nf_nam f1 f2 f3 throughput
$ns flush-trace
close $nf
close $nf_nam
close $f1
close $f2
close $f3
exec cat UDP1.tr >@ $throughput
exec cat UDP2.tr >@ $throughput
exec cat UDP3.tr >@ $throughput
close $throughput
exec xgraph -bb -bg white -fg black -zg black -x time(s) -y "BW(Mb/s)"
-geometry 800x400 -t "SCRIPT2 MO PHONG MANG IP SU DUNG DIFFSERV"
-tf "helvetica-13" throughput.xg &
}
$ns run

Ph lc

M phng mng MPLS kt hp DiffServ


# Khai bao node
set R0 [$ns node]
set R1 [$ns node]
set R2 [$ns node]
set LSR3 [$ns mpls-node]
set LSR4 [$ns mpls-node]
set LSR5 [$ns mpls-node]
set LSR6 [$ns mpls-node]
set LSR7 [$ns mpls-node]
set R8 [$ns node]
set R9 [$ns node]
set R10 [$ns node]
# link: nodes bw delay queue
$ns duplex-link $R0 $LSR3 10Mb 5ms DropTail
$ns duplex-link $R1 $LSR3 10Mb 5ms DropTail
$ns duplex-link $R2 $LSR3 10Mb 5ms DropTail
$ns simplex-link $LSR3 $LSR4
$ns simplex-link $LSR4 $LSR3
$ns simplex-link $LSR3 $LSR5
$ns simplex-link $LSR5 $LSR3
$ns simplex-link $LSR5 $LSR6
$ns simplex-link $LSR6 $LSR5
$ns simplex-link $LSR4 $LSR6
$ns simplex-link $LSR6 $LSR4
$ns simplex-link $LSR4 $LSR7
$ns simplex-link $LSR7 $LSR4
$ns simplex-link $LSR6 $LSR7
$ns simplex-link $LSR7 $LSR6

5Mb 10ms dsRED/edge


5Mb 10ms dsRED/core
5Mb 10ms RED
5Mb 10ms RED
5Mb 10ms RED
5Mb 10ms RED
5Mb 10ms dsRED/core
5Mb 10ms dsRED/edge
5Mb 10ms dsRED/core
5Mb 10ms dsRED/edge
5Mb 10ms RED
5Mb 10ms RED

$ns duplex-link $LSR7 $R8 10Mb 5ms DropTail


$ns duplex-link $LSR7 $R9 10Mb 5ms DropTail
$ns duplex-link $LSR7 $R10 10Mb 5ms DropTail
$qEdge1ToCore meanPktSize $packetSize
$qEdge1ToCore set numQueues_
3
$qEdge1ToCore setNumPrec
3
$qEdge1ToCore setSchedularMode PRI

Ph lc

$qEdge1ToCore addPolicyEntry [$R0 id] [$R8 id] TSW3CM 10 $ensureServCIR


$ensureServPIR
$qEdge1ToCore addPolicyEntry [$R1 id] [$R9 id] TSW3CM 20
$bestEffortServ1CIR $bestEffortServ1PIR
$qEdge1ToCore addPolicyEntry [$R2 id] [$R10 id] TSW3CM 30
$bestEffortServ2CIR $bestEffortServ2PIR
$qEdge1ToCore addPolicerEntry TSW3CM 10 11 12
$qEdge1ToCore addPolicerEntry TSW3CM 20 21 22
$qEdge1ToCore addPolicerEntry TSW3CM 30 31 32
$qEdge1ToCore addPHBEntry 10
0 0
$qEdge1ToCore addPHBEntry 11
0 1
$qEdge1ToCore addPHBEntry 12
0 2
$qEdge1ToCore addPHBEntry 20
1 0
$qEdge1ToCore addPHBEntry 21
1 1
$qEdge1ToCore addPHBEntry 22
12
$qEdge1ToCore addPHBEntry 30
2 0
$qEdge1ToCore addPHBEntry 31
2 1
$qEdge1ToCore addPHBEntry 32
2 2
$qEdge1ToCore addPHBEntry 0
2 2
$qEdge1ToCore configQ
0 0 20 40 0.01
$qEdge1ToCore configQ
0 1 10 50 0.1
$qEdge1ToCore configQ
0 2 10 50 0.3
$qEdge1ToCore configQ
1 0 20 40 0.01
$qEdge1ToCore configQ
1 1 10 50 0.1
$qEdge1ToCore configQ
1 2 10 50 0.3
$qEdge1ToCore configQ
2 0 20 40 0.01
$qEdge1ToCore configQ
2 1 10 50 0.1
$qEdge1ToCore configQ
2 2 10 50 0.3
# Cau hinh LDP agent tren tat ca cac nut MPLS
$ns configure-ldp-on-all-mpls-nodes
# Thiet lap mau cho cac ban tin
$ns ldp-request-color
blue
$ns ldp-mapping-color
red
$ns ldp-withdraw-color
magenta
$ns ldp-release-color
orange
$ns ldp-notification-color green

Ph lc

# Thiet lap LSP


proc notify-erlsp-setup {node lspid} {
global cbr1 cbr2 cbr3 LSR3 LSR4 LSR7
set ns [Simulator instance]
set module [$node get-module "MPLS"]
switch $lspid {
9999 { # LSP_9999 choose shortest path to edgress
set msg " [string range [$ns now] 0 3]s: Tunnel LSP_$lspid
(Ingress=LSR[$node id]) tu dong chon duong ngan nhat den Egress !"
puts $msg
$ns trace-annotate $msg
}
default {
puts " Error!"
exit 1
}
}
}
#------------------------------------------------------# Co che khoi phuc: SIMPLE-DYNAMIC
#$ns enable-reroute simple-dynamic
#[$LSR4 get-module "MPLS"] set-protection-flow 0.1 0.01 8 -1
#[$LSR4 get-module "MPLS"] set-protection-flow 0.1 0.01 9 -1
#[$LSR4 get-module "MPLS"] set-protection-flow 0.1 0.01 10 -1
#[$LSR3 get-module "MPLS"] enable-data-driven
}
$ns run

You might also like