--Black links: 512Kbps bandwidth with 5ms delay.
-Start : 0sec
Create TCP packet transfer between green nodes.
Create UDP packet transfer between red nodes in opposite direction.
- Suggest a way to transfer packets between internal nodes without handling regional routers
#create a simulator project set ns [new Simulator] | |
#set routing protocol | |
$ns rtproto DV | |
# open the nam and tr trace file set nf [open out.nam w] | |
$ns namtrace-all $nf | |
$ns use-newtrace | |
set tracefd [open output.tr w] | |
$ns trace-all $tracefd | |
#add colors to our nodes | |
$ns color 1 red | |
$ns color 2 blue | |
$ns color 3 green | |
$ns color 4 orange | |
#define 'finish' procedure proc finish {} | |
{ | |
global ns nf | |
$ns flush-trace | |
#close the trace function close $nf | |
#execute nam on the trace file | |
exec nam out.nam & | |
exit 0 | |
} | |
#create nodes | |
set n0 [$ns node] | |
set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set n5 [$ns node] set n6 [$ns node] set n7 [$ns node] set n8 [$ns node] set n9 [$ns node] set n10 [$ns node] | |
#we can add colours to the nodes | |
$n0 color purple | |
$n1 color blue | |
$n2 color blue | |
$n3 color orange | |
$n4 color orange | |
$n5 color green | |
$n6 color blue | |
$n7 color red | |
$n8 color red | |
$n9 color blue | |
$n10 color green | |
#we can add names to the nodes | |
$n0 label "Central Router" | |
$n1 label "Regional Router" | |
$n2 label "Regional Router" | |
$n3 label "Internal Router" | |
$n4 label "Internal Router" | |
# we can add shapes to nodes | |
$n0 shape hexagon | |
$n1 shape box | |
$n2 shape box | |
#create a duplex link between the nodes | |
$ns duplex-link $n0 $n1 512kb 5ms DropTail | |
$ns duplex-link $n0 $n2 512kb 5ms DropTail | |
$ns duplex-link $n1 $n3 512kb 5ms DropTail | |
$ns duplex-link $n2 $n4 512kb 5ms DropTail | |
$ns duplex-link $n4 $n5 512kb 5ms DropTail | |
$ns duplex-link $n4 $n6 512kb 5ms DropTail | |
$ns duplex-link $n4 $n7 512kb 5ms DropTail | |
$ns duplex-link $n3 $n8 512kb 5ms DropTail | |
$ns duplex-link $n3 $n9 512kb 5ms DropTail | |
$ns duplex-link $n3 $n10 512kb 5ms DropTail | |
#change link color | |
$ns duplex-link-op $n0 $n1 color blue | |
$ns duplex-link-op $n0 $n2 color blue | |
$ns duplex-link-op $n1 $n3 color brown | |
$ns duplex-link-op $n2 $n4 color brown | |
#we create queue/buffer | |
$ns duplex-link-op $n0 $n1 queuePos 0.5 | |
$ns duplex-link-op $n0 $n2 queuePos 0.5 | |
$ns duplex-link-op $n2 $n4 queuePos 0.5 | |
$ns duplex-link-op $n1 $n3 queuePos 0.5 | |
#we limit the Queue/buffer | |
$ns queue-limit $n0 $n1 20 | |
$ns queue-limit $n0 $n2 20 | |
$ns queue-limit $n2 $n4 20 | |
$ns queue-limit $n1 $n3 20 | |
#adding labels to out links | |
$ns duplex-link-op $n0 $n1 label "Backbone" | |
$ns duplex-link-op $n0 $n2 label "Backbone" | |
#we can give the location of nodes related to other nodes | |
$ns duplex-link-op $n0 $n1 orient left | |
$ns duplex-link-op $n0 $n2 orient right | |
$ns duplex-link-op $n1 $n3 orient left | |
$ns duplex-link-op $n2 $n4 orient right | |
$ns duplex-link-op $n4 $n5 orient right-up | |
$ns duplex-link-op $n4 $n6 orient right | |
$ns duplex-link-op $n4 $n7 orient right-down | |
$ns duplex-link-op $n3 $n8 orient left-up | |
$ns duplex-link-op $n3 $n9 orient left | |
$ns duplex-link-op $n3 $n10 orient left-down | |
#:::::::::::::::::::::create 1st UDP:::::::::::::::::::::::;; | |
#create a UDP agent and attach it to the node number set udp1 [new Agent/UDP] | |
$ns attach-agent $n9 $udp1 | |
#attach color | |
$udp1 set class_ 1 | |
#create a null agent(a traffic sink) and attch it to node n5 set null0 [new Agent/Null] | |
$ns attach-agent $n6 $null0 | |
#create the trafic source with the trafic sink | |
$ns connect $udp1 $null0 | |
#set up ftp over top connection | |
set cbr0 [new Application/Traffic/CBR] | |
$cbr0 attach-agent $udp1 | |
#set packet sizes | |
$cbr0 set packetSize_ 512 | |
$cbr0 set interval_ 0.1 | |
#schedule events for ftp agent | |
$ns at 0 "$cbr0 start" | |
$ns at 4 "$cbr0 stop" | |
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
#create a TCP agent and attach it to the node number | |
set top1 [new Agent/TCP] | |
$ns attach-agent $n10 $top1 | |
$top1 set class_ 2 | |
#create a null agent(a traffic sink) and attch it to node n1 set sink1 [new Agent/TCPSink] | |
$ns attach-agent $n5 $sink1 | |
#create the trafic source with the trafic sink | |
$ns connect $top1 $sink1 | |
#set up ftp over top connection set ftp1 [new Application/FTP] | |
$ftp1 attach-agent $top1 | |
#set packet sizes | |
$ftp1 set packetSize_ 512 | |
$ftp1 set interval_ 0.1 | |
#schedule events for ftp agent | |
$ns at 1 "$ftp1 start" | |
$ns at 3 "$ftp1 stop" | |
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
#create a UDP agent and attach it to the node number | |
set udp2 [new Agent/UDP] | |
$ns attach-agent $n7 $udp2 | |
#attach colour | |
$udp2 set class_ 3 | |
#create a null agent(a traffic sink) and attach it to node n5 set null1 [new Agent/Null] | |
$ns attach-agent $n8 $null1 | |
#create the traffic source with the traffic sink | |
$ns connect $udp2 $null1 | |
#set up ftp over top connection | |
set cbr1 [new Application/Traffic/CBR] | |
$cbr1 attach-agent $udp2 | |
#set packet sizes | |
$cbr1 set packetSize_ 512 | |
$cbr1 set interval_ 0.1 | |
#schedule events for ftp agent | |
$ns at 3 "$cbr1 start" | |
$ns at 4 "$cbr1 stop" | |
#:::::::::::::::::::::::::::::::::::::::::::: | |
#::::::::::::::::::::::::::::::::create 2nd TCP::::::::::::::::::::::::::: | |
#create a TCP agent and attach it to the node number set top2 [new Agent/TCP] | |
$ns attach-agent $n5 $top2 | |
$top2 set class_ 4 | |
#create a null agent(a traffic sink) and attach it to node n1 set sink2 [new Agent/TCPSink] | |
$ns attach-agent $n6 $sink2 | |
#create the traffic source with the traffic sink | |
$ns connect $top2 $sink2 | |
#set up ftp over top connection set ftp2 [new Application/FTP] | |
$ftp2 attach-agent $top2 | |
#set packet sizes | |
$ftp2 set packetSize_ 512 | |
$ftp2 set interval_ 0.1 | |
#schedule events for ftp agent | |
$ns at 3.5 "$ftp2 start" | |
$ns at 4 "$ftp2 stop" | |
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
#we are down the link at our desire | |
$ns rtmodel-at 3.5 down $n2 $n4 | |
$ns rtmodel-at 4.2 down $n2 $n4 | |
#call the finish procedure after 5 seconds simulation time | |
$ns at 4.5 "finish" | |
#$ns at 0.0 "start" | |
#run the simulation | |
$ns run |
After the break down of the brown link of node 2, the packet transfer path between blue nodes is disconnected. To keep the packet transfer we can suggest, break down brown link after the end of packet transferring between blue nodes. Thus we can suggest to have link between central router and internal router.
when you create the simulation and as we have coded to have a nam and tr files.those will be saved in the location original simulation code is.So lets see how this trace file is organized.The image was taken from internet i couldn't remember the link :(
No comments :
Post a Comment