| Welcome to my blog!

Meet the Author

Roshan is an undergarduate student in Information and Communication Technologies from Vavuniya Campus of the University of Jaffna.He is very much interesting on IT related Topics and the technical stuffs.Roshan is also a creative mind with lots of ideas and potential writter..!

Subscribe to this blog!

Receive the latest posts by email. Just enter your email below if you want to subscribe!

Tuesday, December 9, 2014

Using NS






The post is based on a assement i was given in my campus and the Question is mentioned here
Q:Write a tcl script that forms a network as follows



Consisting one central router as 0 and two regional routers as 1 and 2.
-Set DV protocol
-Each regional router has four sub routers as given in the picture.
-Create
--Black links: 512Kbps bandwidth with 5ms delay.
--Brown links: 512Kbps Bandwidth with 5ms delay.
--Blue links: 512Kbps Bandwidth with 5ms delay.
--Create UDP packet transfer between blue nodes.


main simulation
-Start : 0sec
-Finish:4sec
-Size : 512bits

Create TCP packet transfer between green nodes.

-Start : 1sec
-Finish:3sec

Create UDP packet transfer between red nodes in opposite direction.

-Start : 3sec
-Finish:4sec
-Size : 512bits
-You should differentiate the colors of each packet.


Put the labels for nodes as
Central Router.
Regional Router.
Internal Routers.
Put label backbone to blue color links.


Place buffers in regional router’s brown links as well as to blue links with size 20.
Break down the brown link of node 2.
Suggest any way to transfer packets between blue nodes.
Create a TCP packet transfer inside any region in between green and blue nodes with default packet size 
  • Suggest a way to transfer packets between internal nodes without handling regional routers


Explain briefly about the obtained trace file.
Network engineer suggest that to create router 0 as the wireless router and all others as wireless nodes, give some pros and cons regarding this.
So the answer is as follows as all the comments are put correctly i hope you can understand it easily! :)
#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
view raw NS Code hosted with ❤ by GitHub







· So the discription about the scenario is this
 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.
·    We can use internal router to transfer the packets between internal nodes. It is good to have direct link between both internal routers. Then we can transfer packets between different internal nodes.
·    The central router should be the main point in the network so we can make the link between nodes to have a big band width and a better time delay. And the queue size should be high to reduce the number of drop packets.

·    Because of the breakdown of the link the only path will be removed then the packets will get lost so if we can make the structure more different which can have a another link to make another possible path the problem will be reduced

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 :(




So lets try to understand some of its statements.......hope this will useful for you...




·    + 0.00017 0 1 rtProtoDV 11 ------- 0 0.1 1.1 -1 1

Enqueue rtProtoDV packet at 0.00017 seconds with 11bits packet size between 0 and 1 nodes; flag is
0; src_address is 0.1; dst_address is 1.1; sequence number 1;packet id is 1

-     - 0.00017 0 1 rtProtoDV 11 ------- 0 0.1 1.1 -1 1

Dequeue above mention packet with same detail at 0.00017 second

·    r 0.005342 0 1 rtProtoDV 11 ------- 0 0.1 1.1 -1 1

Receive rtProtoDV packet node 0 to node 1 at 0. 005342 second, with 11bits size. Flag is 0;
src_address is 0.1; dst_address is 1.1; seq_num is 1;packet id is 11

·    + 0.1 9 3 cbr 512 ------- 1 9.0 6.0 1 75

Receive cbr packet node 5 to node 4 at 1.283857 second, with 512bits size. Flag is 3; src_address is
9.0; dst_address is 6.0; seq_num is 1; packet id is 75

·    r 1.039375 5 4 ack 40 ------- 2 5.0 10.0 0 98

Receive acknowledgement packet node 5 to node 4 at 1.039375 second, with 40bits size. Flag is 2;
src_address is 5.0; dst_address is 10.0; seq_num is 2; packet id is 98


·    + 1.0675 10 3 tcp 1040 ------- 2 10.0 5.0 1 99

Enqueue tcp packet at 1.0675 seconds with 1040bits packet size between 10 and 3 nodes; flag is 2;
src_address is 10.0; dst_address is 5.0; sequence number 1; packet id is 99

·    d 2.152429 4 1 cbr 512 3 5.0 9.0 234 389

Drop cbr packet at 2.152429 seconds with 512bits packet size between 4 and 1 nodes; flag is 3;
src_address is 5.0; dst_address is 9.0; sequence number 234; packet id is 389

·    v 3.5 link-down 4 2

Link down between node 4 and node 2 at 3.5 seconds.Because these links are duplex links. Then both directions of links must down.

Pros and Cons when create router 0 as the wireless router and all others as wireless nodes

Pros
·    Distance between two internal nodes are same
·    Each node have independent connections
·    It is less cost
·    Availability is high
·    It gives more security because it centralized

Cons
·    Data traffic is high on the node 0
·    Packet drop may happen
·    Packet transmission will slower because of the traffic
·    If central router down, whole the network will down
·    Transmission bandwidth is less than wired connections
·    Less security when the transmission
rkarunarathna
rkarunarathna Web Developer,Programer

Roshan is an undergarduate student in Information and Communication Technologies from Vavuniya Campus of the University of Jaffna.He is very much interesting on IT related Topics and the technical stuffs.Roshan is also a creative mind with lots of ideas and potential writter..!

No comments :

Post a Comment