Created
December 26, 2016 14:50
-
-
Save n1chre/5911b3199439ec94e3dae734106f45ff to your computer and use it in GitHub Desktop.
Simulation in ns2 for Information networks project assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Luka Sonjic 0036476996 | |
# Matej Lipovac 0036468779 | |
# Oblikovanje simulatora | |
set ns [new Simulator] | |
# Otvaranje datoteke za NAM trace | |
set nf [open out.nam w] | |
$ns namtrace-all $nf | |
# Završna procedura | |
proc finish {} { | |
global ns nf | |
$ns flush-trace | |
close $nf | |
exec nam out.nam & | |
exit 0 | |
} | |
###################################### | |
# Topologija mreže # | |
###################################### | |
# Oblikovanje čvorova | |
set n0 [$ns node] | |
set n1 [$ns node] | |
set n2 [$ns node] | |
set n3 [$ns node] | |
set n4 [$ns node] | |
set n5 [$ns node] | |
# Povezivanje čvorova | |
$ns duplex-link $n0 $n2 1.0Mb 10ms DropTail | |
$ns duplex-link $n1 $n2 1.0Mb 5ms DropTail | |
$ns duplex-link $n2 $n3 0.5Mb 10ms DropTail | |
$ns duplex-link $n3 $n4 1.5Mb 10ms DropTail | |
$ns duplex-link $n3 $n5 0.5Mb 10ms DropTail | |
# postavi veličinu queuea na 5 | |
$ns queue-limit $n2 $n3 5 | |
###################################### | |
# TCP & FTP # | |
###################################### | |
# Tahoe sender | |
set tcp [new Agent/TCP] | |
# One ack per packet | |
set tcpsink [new Agent/TCPSink] | |
set ftp [new Application/FTP] | |
# configure tcp & ftp | |
$ns attach-agent $n0 $tcp | |
$ns attach-agent $n4 $tcpsink | |
$ns connect $tcp $tcpsink | |
$ftp attach-agent $tcp | |
$tcp set fid_ 1 | |
# prozor zagusenja = 10 | |
$tcp set window_ 10 | |
# veličina paketa = 1000 | |
$ftp set packet_size_ 1000 | |
###################################### | |
# UDP & CBR # | |
###################################### | |
#Postavljanje UDP konekcije i CBR aplikacije | |
set udp [new Agent/UDP] | |
set null [new Agent/Null] | |
set cbr [new Application/Traffic/CBR] | |
# configure udp & cbr | |
$ns attach-agent $n1 $udp | |
$ns attach-agent $n5 $null | |
$ns connect $udp $null | |
$cbr attach-agent $udp | |
$udp set fid_ 2 | |
# veličina paketa = 1000 | |
$cbr set packet_size_ 1000 | |
# brzina slanja = 512kb/s | |
$cbr set rate_ 512kb | |
# don't add random noise to departure times | |
$cbr set random_ false | |
###################################### | |
# NAM podešavanje # | |
###################################### | |
# Definicije boja | |
# tcp = ftp = 1 = crvena | |
$ns color 1 Red | |
# udp = cbr = 2 = zelena | |
$ns color 2 Green | |
# Orijentacija linkova | |
$ns duplex-link-op $n0 $n2 orient right-down | |
$ns duplex-link-op $n1 $n2 orient right-up | |
$ns duplex-link-op $n2 $n3 orient right | |
$ns duplex-link-op $n3 $n4 orient right-up | |
$ns duplex-link-op $n3 $n5 orient right-down | |
# Pozicija queuea | |
$ns duplex-link-op $n2 $n3 queuePos 0.5 | |
###################################### | |
# Simulacija # | |
###################################### | |
# Dogadaji | |
$ns at 1.0 "$cbr start" | |
$ns at 2.0 "$ftp start" | |
$ns at 4.5 "$ftp stop" | |
$ns at 4.5 "$cbr stop" | |
$ns at 5.0 "finish" | |
# Pokreni simulaciju | |
$ns run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment