Telecommunication Network Lab Manual

55
Telecommunication Networks

Transcript of Telecommunication Network Lab Manual

Page 1: Telecommunication Network Lab Manual

Telecommunication Networks

Ashish Ranjan, 8102333Jaypee Institute of Information Technology

Page 2: Telecommunication Network Lab Manual

Index

S.No Name of the Experiment Date Teacher’s Signature

Remarks

Page 3: Telecommunication Network Lab Manual

1

2

3

4

5

6

7

8

9

To understand the basic Unix Commands. & using those commands, calculate factorial of 9.

Design the following network with the given capacity of link & propogation delay. Give red color to the Nodes 1 to 6 & green to therest nodes. Links can be taken of any color.

UDP & TCP Simulations Using NS2

Design LAN/Ethernet

Design Ad hoc network (MANET) of three wireless mobile nodes

Analysis of trace file in TCP/UDP/LAN

TCP in wireless scenario

Comparison Of Different Tcp Congestion Avoidance Algorithms In Wireless Scenario

Studying Error Models

Page 4: Telecommunication Network Lab Manual

S.No Name of the Experiment Date Teacher’s Signature

Remarks

Page 5: Telecommunication Network Lab Manual

Experiment - 1

Aim : To understand the basic Unix Commands. & using those commands, calculate factorial of 9.

Some Basic Unix Commands :

C program related commands: 

Command  Description indent filename  To indent files containing C programs. gcc  abc.c  o‐  abc   Compile the file abc.c and create the executable abc.out.

Directories related commands:  Command Description mkdir dirname  Makes a new directory. pwd  Prints the current working directory. Rm-r/rmdir  Removes an empty directory.cd   Changes to home directory. cd ~  Changes to home directory. cd ..  Changes to parent directory. cd dirname   Changes to named directory. rename from to file  Renames the specified files by replacing the first occurrence of from

in their name by to.

 File related commands: 

Command  Description ls  Lists files and directories.ls -l  Lists files in ‘long format’ i.e containing useful info. About file such as

who owns it, exact size of file.ls -a  Lists all files and directories.ls abc*  Lists all files and directories starting with abc. mv f1 f2  Moves a file i.e gives it a different name or moves it into a different

directorycp f1 f2  Copy file1 to file2.rm f1  Removes a file.rm -i  Ask for a confirmation before deleting anything.wc f1  Gives no of lines, words and characters in a file.cat f1  To view a file.cat  >  f1  To create a file.cat  f1 f2 > f3  Concatenates file1 and file2 to file3.

Page 6: Telecommunication Network Lab Manual

gzip f1  Produces a compressed a file with .gz extension.gunzip f1  Decompress a file compressed with gzip.lpr  Prints a file.grep string f1  Prints all lines of file that contain the string.grep-v string f1  Prints all lines of the file except those that contain the string.tar -vf f.tar f1 f2  To combine multiple files into a single file.Tar-xvf f.tar  To separate an archive created by tar into separate files.

Question : Calculate factorial of 9.

Code :

Creation :- gedit ashish.c

#include<stdio.h>int main(){ int num,i,Pro=1;

printf(" Enter the Number : "); scanf("%d",&num);

for(i=1;i<=num;i++) { Pro=Pro*i; } printf(" Factorial = "); printf("%d",Pro);}

Compile :- gcc ashish.c –o ashish Run :- ./ashish

Output :-Enter the Number : 5Factorial = 120

Result :- All the basic commands are successful tried on unix & factorial of a given no. is found.

Page 7: Telecommunication Network Lab Manual

Experiment -2Aim :- Definition of a Network of links & nodes.Design the following network with the given capacity of link & propogation delay. Give red color to the Nodes 1 to 6 & green to therest nodes. Links can be taken of any color.

Theory :- A network simulator is a piece of software or hardware that predicts the behavior of a network without an actual network being present. Network simulators, as the name suggests are used by researchers, developers and engineers to design various kinds of networks, simulate and then analyze the effect of various parameters on the network performance. A typical network simulator encompasses a wide range of networking technologies and help the users to build complex networks from basic building blocks like variety of nodes and links.the help of simulators, one can design hierarchical networks using various types of nodes like computers, hubs, bridges, routers, switches, links, mobile units etc.

Code : -set ns [new Simulator]set nf [open out.nam w]$ns namtrace-all $nf

proc finish {} {global ns nf

6

1

2

1

51

3

4

9

8

7

10Mb, 10ms

40Mb, 15ms

10Mb, 10ms

25Mb, 15ms

5Mb, 5ms

15Mb, 5ms

20Mb, 5ms

0.5Mb, 15ms

Page 8: Telecommunication Network Lab Manual

$ns flush-traceexec nam out.nam &exit 0}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]

$ns simplex-link $n1 $n3 10Mb 10ms DropTail$ns duplex-link $n2 $n3 0.5Mb 15ms DropTail$ns simplex-link $n3 $n4 40Mb 15ms DropTail$ns duplex-link $n4 $n5 5Mb 5ms DropTail$ns duplex-link $n4 $n6 10Mb 10ms DropTail$ns simplex-link $n4 $n7 25Mb 5ms DropTail$ns duplex-link $n7 $n8 20Mb 5ms DropTail$ns duplex-link $n7 $n9 15Mb 5ms DropTail

$ns simplex-link-op $n1 $n3 orient right-down$ns duplex-link-op $n2 $n3 orient right-up$ns simplex-link-op $n3 $n4 orient right$ns duplex-link-op $n4 $n5 orient down$ns duplex-link-op $n4 $n6 orient up$ns simplex-link-op $n4 $n7 orient right$ns duplex-link-op $n7 $n8 orient right-up$ns duplex-link-op $n7 $n9 orient right-down

$ns simplex-link-op $n1 $n3 color "blue"$ns duplex-link-op $n2 $n3 color "blue"$ns simplex-link-op $n3 $n4 color "blue"$ns duplex-link-op $n4 $n5 color "blue"$ns duplex-link-op $n4 $n6 color "blue"$ns simplex-link-op $n4 $n7 color "blue"$ns duplex-link-op $n7 $n8 color "blue"$ns duplex-link-op $n7 $n9 color "blue"

$n1 color red

Page 9: Telecommunication Network Lab Manual

$n2 color red$n3 color red$n4 color red$n5 color red$n6 color red$n7 color green$n8 color green$n9 color green

$ns at 5.0 "finish"$ns run

Output :-

Result :- Given network of nodes & links is designed using network simulator.

Page 10: Telecommunication Network Lab Manual

Experiment -3

Aim :- UDP & TCP Simulations Using NS2

Theory :-

Transmission Control Protocol (TCP) and User Datagram Protocol (UDP)is a transportation protocol that is one of the core protocols of the Internet protocol suite. Both TCP and UDP work at transport layer TCP/IP model and both have very different usage.

TCP (Transmission Control Protocol) : TCP is a connection-oriented protocol, a connection can be made from client to server, and from then on any data can be sent along that connection.

Reliable - when you send a message along a TCP socket, you know it will get there unless the connection fails completely. If it gets lost along the way, the server will re-request the lost part. This means complete integrity, things don't get corrupted.

Ordered - if you send two messages along a connection, one after the other, you know the first message will get there first. You don't have to worry about data arriving in the wrong order.

Heavyweight - when the low level parts of the TCP "stream" arrive in the wrong order, resend requests have to be sent, and all the out of sequence parts have to be put back together, so requires a bit of work to piece together.

Acknowledgement - TCP primarily uses a cumulative acknowledgment scheme, where the receiver sends an acknowledgment signifying that the receiver has received all data preceding the acknowledged sequence number. 

UDP (User Datagram Protocol) : A simpler message-based connectionless protocol. With UDP you send messages(packets) across the network in chunks.

Unreliable - When you send a message, you don't know if it'll get there, it could get lost on the way.

Not ordered - If you send two messages out, you don't know what order they'll arrive in.

Lightweight - No ordering of messages, no tracking connections, etc. It's just fire and forget! This means it's a lot quicker, and the network card / OS have to do very little work to translate the data back from the packets.

Page 11: Telecommunication Network Lab Manual

Question :- Design the network drawn below with the propagation delay of 40 ms & Capacity of link is 10 Mb. Then simulate the UDP between node 0 and 9 & TCP between nodes 0 & 6 .

Network :-

Code :

set ns [new Simulator]set nf [open out.nam w]$ns namtrace-all $nf

proc finish {} {global ns nf $ns flush-traceexec nam out.nam &exit 0}

set n1 [$ns node]set n2 [$ns node]set n3 [$ns node]set n7 [$ns node]

6

2

1

51

3

4

9

8

7

10Mb, 40ms

10Mb, 40ms

10Mb, 40ms

10Mb, 40ms 10Mb, 40ms

10Mb, 40ms

10Mb, 40ms10Mb, 40ms

10

10Mb, 40ms

Page 12: Telecommunication Network Lab Manual

set n8 [$ns node]set n9 [$ns node]set n4 [$ns node]set n5 [$ns node]set n6 [$ns node]set n10 [$ns node]

$ns duplex-link $n1 $n3 10Mb 40ms DropTail$ns duplex-link $n2 $n3 10Mb 40ms DropTail$ns duplex-link $n3 $n7 10Mb 40ms DropTail$ns duplex-link $n7 $n8 10Mb 40ms DropTail$ns duplex-link $n7 $n9 10Mb 40ms DropTail$ns duplex-link $n9 $n10 10Mb 40ms DropTail$ns duplex-link $n9 $n6 10Mb 40ms DropTail$ns duplex-link $n8 $n4 10Mb 40ms DropTail$ns duplex-link $n8 $n5 10Mb 40ms DropTail

$ns duplex-link-op $n1 $n3 orient right-down$ns duplex-link-op $n2 $n3 orient right-up$ns duplex-link-op $n3 $n7 orient right$ns duplex-link-op $n7 $n8 orient right-up$ns duplex-link-op $n7 $n9 orient right-down$ns duplex-link-op $n6 $n9 orient right-up$ns duplex-link-op $n9 $n10 orient right-down$ns duplex-link-op $n4 $n8 orient right-down$ns duplex-link-op $n8 $n5 orient right-up

$ns duplex-link-op $n1 $n3 color "blue"$ns duplex-link-op $n2 $n3 color "blue"$ns duplex-link-op $n3 $n7 color "blue"$ns duplex-link-op $n7 $n8 color "blue"$ns duplex-link-op $n7 $n9 color "blue"$ns duplex-link-op $n8 $n5 color "blue"$ns duplex-link-op $n8 $n4 color "blue"$ns duplex-link-op $n6 $n9 color "blue"$ns duplex-link-op $n9 $n10 color "blue"

$n1 color red$n2 color red$n3 color red$n7 color green$n8 color green$n9 color green$n4 color black$n5 color black

Page 13: Telecommunication Network Lab Manual

$n6 color black$n10 color black

# ------------------ TCP ----------------------------- #set tcp [new Agent/TCP]$ns attach-agent $n1 $tcp

set sink [new Agent/TCPSink]$ns attach-agent $n4 $sink

$ns connect $tcp $sink

$tcp set fid_ 1$tcp set packetsize_ 552

set ftp [new Application/FTP]$ftp attach-agent $tcp

#----------------- UDP ----------------------------- #set udp0 [new Agent/UDP]$ns attach-agent $n1 $udp0

set cbr0 [new Application/Traffic/CBR]$cbr0 set packetsize_ 500$cbr0 set interval_ 0.005$cbr0 attach-agent $udp0

set null0 [new Agent/Null]$ns attach-agent $n10 $null0

$ns connect $udp0 $null0

$ns at 0.5 "$cbr0 start"$ns at 3.0 "$cbr0 stop"

$ns at 0.1 "$ftp start"$ns at 10.0 "$ftp stop"

$ns at 20.0 "finish"$ns run

Page 14: Telecommunication Network Lab Manual

Output :

UDP : Between node 0 & node 9TCP : Between node 0 & node 6

Result :

Givent Network has been drawn and UDP, TCP simulation is performed using NS2.

Data is sent using TCP

Data is sent using UDP

Acknowledgement is sent by receiver in TCP.

No such Acknowledgement in UDP.

Page 15: Telecommunication Network Lab Manual

Expriment - 4Aim : Design LAN/Ethernet .

Theory : Ethernet protocols refer to the family of local-area network (LAN) covered by the IEEE 802.3. A local area network (LAN) is a computer network that connects computers and devices in a limited geographical area such as home, school, computer laboratory or office building. Ethernett defines a number of wiring and signaling standards for the Physical Layer of the OSI networking model as well as a common addressing format and a variety of Medium Access Control procedures at the lower part of the Data Link Layer. In the Ethernet standard, there are two modes of operation: half-duplex and full-duplex modes. In the half duplex mode, data are transmitted using the popular CSMA/CD protocol on a shared medium. The main disadvantages of the half-duplex are the efficiency and distance limitation, in which the link distance is limited by the minimum MAC frame size. This restriction reduces the efficiency drastically for high-rate transmission. Therefore, the carrier extension technique is used to ensure the minimum frame size of 512 bytes in Gigabit Ethernet to achieve a reasonable link distance.Full duplex is a well know mode of operation in wide area telecommunication networks.

Four data rates are currently defined for operation over optical fiber and twisted-pair cables:

10 Mbps - 10Base-T Ethernet (IEEE 802.3) 100 Mbps - Fast Ethernet (IEEE 802.3u) 1000 Mbps - Gigabit Ethernet (IEEE 802.3z) 10-Gigabit - 10 Gbps Ethernet (IEEE 802.3ae).

Ethernet uses a protocol called CSMA/CD, this stands for Carrier Sense, Multiple Access with Collision Detection. To understand what this means lets separate the three parts.

Carrier Sense - When a device connected to an Ethernet network wants to send

data it first checks to make sure it has a carrier on which to send its data (usually a piece of copper cable connected to a hub or another machine).

Multiple Access - This means that all machines on the network are free to use the network whenever they like so long as no one else is transmitting.

Collision Detection - A means of ensuring that when two machines start to transmit data simultaneously, that the resultant corrupted data is discarded, and re-transmissions are generated at differing time intervals.

Ethernet confuses people because it is a 'broadcast' protocol--the packet is broadcasted to all hosts on the network, but the packet is only 'destined' for the host whose MAC address matches the one in the desitnation MAC field of the Ethernet frame

Page 16: Telecommunication Network Lab Manual

Question :- Design the folowing Lan/Ethernet with given specifications.

Capacity of link is 15 Mb . Propogation delay is of 20ms. Data Packets are transmitted b/w nodes 0 & 10 using FTP/IP protocol. Data Packets are transmitted b/w nodes 2 & 8 using UDP protocol.

Code :-

set ns [new Simulator]set nf [open out.nam w]$ns namtrace-all $nf

proc finish {} { global ns nf

$ns flush-traceexec nam out.nam &exit 0}

set n0 [$ns node]set n1 [$ns node]

6

2

1 5

1 3

4

9

8

7

10

0

Page 17: Telecommunication Network Lab Manual

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]set lan [ $ns newLan "$n5 $n6 $n7 $n8 $n9 $n10" 0.5Mb 40ms LL Queue/Droptail Mac/Csma/Cd Channel ]

$ns duplex-link $n0 $n1 15Mb 20ms DropTail$ns duplex-link $n1 $n2 15Mb 20ms DropTail$ns duplex-link $n2 $n3 15Mb 20ms DropTail$ns duplex-link $n2 $n4 15Mb 20ms DropTail$ns duplex-link $n3 $n5 15Mb 20ms DropTail$ns duplex-link $n4 $n6 15Mb 20ms DropTail$ns duplex-link $n4 $n7 15Mb 20ms DropTail

$ns duplex-link-op $n0 $n1 orient right$ns duplex-link-op $n2 $n1 orient up$ns duplex-link-op $n2 $n3 orient right-up$ns duplex-link-op $n2 $n4 orient right-down$ns duplex-link-op $n3 $n5 orient right$ns duplex-link-op $n4 $n6 orient right-up$ns duplex-link-op $n4 $n7 orient right-down

$n0 color black$n1 color black$n2 color red$n3 color red$n4 color black$n5 color red$n7 color black$n6 color black$n8 color red$n9 color black$n10 color black

Page 18: Telecommunication Network Lab Manual

$ns duplex-link-op $n2 $n3 color blue$ns duplex-link-op $n3 $n5 color blue

#--------- TCP ----------- #set tcp [new Agent/TCP]$ns attach-agent $n0 $tcp

set sink [new Agent/TCPSink]$ns attach-agent $n10 $sink

$ns connect $tcp $sink

$tcp set fid_ 1$tcp set packetsize_ 552

set ftp [new Application/FTP]$ftp attach-agent $tcp

# ------- UDP ------------- #set udp0 [new Agent/UDP]$ns attach-agent $n2 $udp0

set cbr0 [new Application/Traffic/CBR]$cbr0 set packetsize_ 500$cbr0 set interval_ 0.005$cbr0 attach-agent $udp0

set null0 [new Agent/Null]$ns attach-agent $n8 $null0

$ns connect $udp0 $null0$ns at 0.5 "$cbr0 start"$ns at 3.0 "$cbr0 stop"

$ns at 0.1 "$ftp start"$ns at 10.0 "$ftp stop"

$ns at 20.0 "finish"$ns run

Page 19: Telecommunication Network Lab Manual

Output :-

Result :- Given LAN/Ethernet is designed & output is observed.

Fig .1 :- LAN Fig.2 :- TCP

Fig .4 :- TCP/IP b/w 0 & 10. UDP b/w nodes 2 & 8

Fig .3 :- Fall of Data Packets

Page 20: Telecommunication Network Lab Manual

Experiment - 5

Aim :- Design Ad hoc network (MANET) of three wireless mobile nodes.

Theory : An ad hoc network is a collection of mobile nodes forming a temporary network without the aid of any centralized administration or standard support services. MANET are formed by a group of nodes that can transmit and receive data and also relay data among themselves. Communication between nodes is made over wireless links. A pair of nodes can establish a wireless link among themselves only if they are within transmission range of each other. An important feature of ad hoc networks is that routes between two hosts may consist of hops through other hosts in the network When a sender node wants to communicate with a receiver node, it may happen that they are not within communication range of each other. However, they might have the chance to communicate if other hosts that lie in-between are willing to forward packets for them. This characteristic of MANET is known as multihopping.

Figure 1.1 illustrates an ad hoc network with four wireless mobile nodes. In this example, each node is within transmission range of two neighboring nodes (indicated by the circles around each node), but is out of range of a third. If two nodes which are not within range of each other wish to exchange information, they must enlist the aid of intermediary nodes to forward information on their behalf. In Figure 1.1, if node 1 sends a packet to node 4, it must send it first to node 2 (or 3). Node 2 can then forward the packet on to node 4.

Figure 5.1: Ad hoc network of four wireless mobile nodes.

Each time a packet is transmitted to a neighboring node, it is said to have made a hop. In the above example, when node 1 sends a packet to node 4, the packet makes two hops: first from node 1 to node 2, and second from node 2 to node 4.

Page 21: Telecommunication Network Lab Manual

Code :-

set val(chan) Channel/WirelessChannelset val(prop) Propagation/TwoRayGroundset val(netif) Phy/WirelessPhyset val(mac) Mac/802_11set val(ifq) Queue/DropTail/PriQueueset val(ll) LLset val(ant) Antenna/OmniAntennaset val(ifqlen) 50set val(nn) 3set val(rp) DSDVset val(x) 500set val(y) 400set val(stop) 150

set ns [new Simulator]set tracefd [open simple.tr w]set windowVsTime2 [open win.tr w]set namtrace [open simwrls.nam w]

$ns trace-all $tracefd$ns namtrace-all-wireless $namtrace $val(x) $val(y)

set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

$ns node-config -adhocRouting $val(rp) \-llType $val(ll) \-macType $val(mac) \-ifqType $val(ifq) \-ifqLen $val(ifqlen) \-antType $val(ant) \-propType $val(prop) \-phyType $val(netif) \-channelType $val(chan) \

Page 22: Telecommunication Network Lab Manual

-topoInstance $topo \-agentTrace ON \-routerTrace ON \-macTrace OFF \-movementTrace ON \

for {set i 0} {$i < $val(nn) } { incr i } {

set node_($i) [$ns node] }

$node_(0) set X_ 2.0$node_(0) set Y_ 5.0$node_(0) set Z_ 0.0

$node_(1) set X_ 15.0$node_(1) set Y_ 20.0$node_(1) set Z_ 0.0

$node_(2) set X_ 5.0$node_(2) set Y_ 10.0$node_(2) set Z_ 0.0

$ns at 15.0 "$node_(0) setdest 45.0 285.0 10.0"$ns at 30.0 "$node_(2) setdest 100.0 100.0 15.0"

set tcp [new Agent/TCP/Newreno]$tcp set class_ 2set sink [new Agent/TCPSink]$ns attach-agent $node_(0) $tcp$ns attach-agent $node_(1) $sink$ns connect $tcp $sinkset ftp [new Application/FTP]$ftp attach-agent $tcp$ns at 10.0 "$ftp start"

for {set i 0} {$i < $val(nn) } { incr i } {

$ns initial_node_pos $node_($i) 30 }

Page 23: Telecommunication Network Lab Manual

for {set i 0} {$i < $val(nn) } { incr i } {

$ns at $val(stop) "$node_($i) reset"; }

$ns at $val(stop) "$ns nam-end-wireless $val(stop)"$ns at $val(stop) "stop"$ns at 150.01 "puts \"end simulation\" ; $ns halt"proc stop {} {

global ns tracefd namtrace$ns flush-traceclose $tracefdclose $namtrace

}$ns run

Output :-

Figure 5.2: Ad hoc network of three wireless mobile nodes.

Result :- Ad hoc network of three wireless mobile nodes is successfully designed &

implemented on NS2.

Page 24: Telecommunication Network Lab Manual

Experiment - 6

Aim :- Analysis of trace file in TCP/UDP/LAN.

Theory : -

An example of a trace file (without the tcp header fields) might appear as follows:

+ 1.84375 0 2 cbr 210 ------- 0 0.0 3.1 225 610- 1.84375 0 2 cbr 210 ------- 0 0.0 3.1 225 610r 1.84471 2 1 cbr 210 ------- 1 3.0 1.0 195 600r 1.84566 2 0 ack 40 ------- 2 3.2 0.1 82 602+ 1.84566 0 2 tcp 1000 ------- 2 0.1 3.2 102 611- 1.84566 0 2 tcp 1000 ------- 2 0.1 3.2 102 611r 1.84609 0 2 cbr 210 ------- 0 0.0 3.1 225 610+ 1.84609 2 3 cbr 210 ------- 0 0.0 3.1 225 610d 1.84609 2 3 cbr 210 ------- 0 0.0 3.1 225 610- 1.8461 2 3 cbr 210 ------- 0 0.0 3.1 192 511r 1.84612 3 2 cbr 210 ------- 1 3.0 1.0 196 603+ 1.84612 2 1 cbr 210 ------- 1 3.0 1.0 196 603- 1.84612 2 1 cbr 210 ------- 1 3.0 1.0 196 603+ 1.84625 3 2 cbr 210 ------- 1 3.0 1.0 199 612

Here we see 14 trace entries, five enque operations (indicated by “+” in the first column), four deque operations (indicated by “-”), four receive events (indicated by “r”), and one drop event. (this had better be a trace fragment, or some packets would have just vanished!). The simulated time (in seconds) at which each event occurred is listed in the second column. The next two fields indicate between which two nodes tracing is happening. The next field is a descriptive name for the the type of packet seen. The next field is the packet’s size, as encoded in its IP header.The next field contains the flags, which not used in this example. The next field gives the IP flow identifier field as defined for IP version 6. In ns v2, the flow ID field is available for this purpose, but any additional should be placed in its own separate field, possibly in some other header. The subsequent two fields indicate the packet’s source and destination node addresses, respectively. The following field indicates the sequence number. The last field is a unique packet identifier. Each new packet created in the simulation is assigned a new, unique identifier.

For UDP :-Code :-set ns [new Simulator]set nf [open out.nam w]$ns namtrace-all $nf

set tracefile1 [ open lab6a.tr w]

Page 25: Telecommunication Network Lab Manual

$ns trace-all $tracefile1

proc finish {} { global ns nf

$ns flush-traceexec nam out.nam &exit 0}

set n0 [$ns node] set n1 [$ns node]set n2 [$ns node]set n3 [$ns node]set n4 [$ns node]set n5 [$ns node]

$ns duplex-link $n0 $n2 1Mb 10ms DropTail $ns duplex-link $n2 $n1 1Mb 10ms DropTail$ns duplex-link $n2 $n3 1Mb 10ms DropTail$ns duplex-link $n3 $n4 1Mb 10ms DropTail$ns duplex-link $n3 $n5 1Mb 10ms DropTail

$ns duplex-link-op $n0 $n2 orient right-up $ns duplex-link-op $n2 $n1 orient left-up$ns duplex-link-op $n2 $n3 orient right$ns duplex-link-op $n3 $n4 orient right-down$ns duplex-link-op $n3 $n5 orient right-up

$ns duplex-link-op $n0 $n2 color "red" $ns duplex-link-op $n1 $n2 color "green"$ns duplex-link-op $n3 $n2 color "blue"$ns duplex-link-op $n3 $n4 color "black"$ns duplex-link-op $n3 $n5 color "purple"

# ------- UDP ------------- #set udp0 [new Agent/UDP]$ns attach-agent $n0 $udp0

set cbr0 [new Application/Traffic/CBR]$cbr0 set packetsize_ 500$cbr0 set interval_ 0.005$cbr0 attach-agent $udp0

set null0 [new Agent/Null]$ns attach-agent $n5 $null0

$ns connect $udp0 $null0$ns at 0.5 "$cbr0 start"$ns at 4.0 "$cbr0 stop"

Page 26: Telecommunication Network Lab Manual

$ns at 5.0 "finish"$ns run

Figure : UDP

For TCP

Code :-set ns [new Simulator]set nf [open out.nam w]$ns namtrace-all $nf

set tracefile1 [ open lab6b.tr w]$ns trace-all $tracefile1

proc finish {} { global ns nf

$ns flush-traceexec nam out.nam &exit 0}

set n0 [$ns node] set n1 [$ns node]set n2 [$ns node]set n3 [$ns node]set n4 [$ns node]set n5 [$ns node]

$ns duplex-link $n0 $n2 1Mb 10ms DropTail $ns duplex-link $n2 $n1 1Mb 10ms DropTail$ns duplex-link $n2 $n3 1Mb 10ms DropTail$ns duplex-link $n3 $n4 1Mb 10ms DropTail

Page 27: Telecommunication Network Lab Manual

$ns duplex-link $n3 $n5 1Mb 10ms DropTail

$ns duplex-link-op $n0 $n2 orient right-up $ns duplex-link-op $n2 $n1 orient left-up$ns duplex-link-op $n2 $n3 orient right$ns duplex-link-op $n3 $n4 orient right-down$ns duplex-link-op $n3 $n5 orient right-up

$ns duplex-link-op $n0 $n2 color "red" $ns duplex-link-op $n1 $n2 color "green"$ns duplex-link-op $n3 $n2 color "blue"$ns duplex-link-op $n3 $n4 color "black"$ns duplex-link-op $n3 $n5 color "purple"

$n1 shape box $n4 shape box

# ------- TCP ------------- #set tcp [new Agent/TCP]$ns attach-agent $n1 $tcp

set sink [new Agent/TCPSink]$ns attach-agent $n4 $sink

$ns connect $tcp $sink

$tcp set fid_ 1$tcp set packetsize_ 552

set ftp [new Application/FTP]$ftp attach-agent $tcp

$ns at 0.1 "$ftp start"$ns at 5.0 "$ftp stop"

$ns at 5.0 "finish"$ns run

Page 28: Telecommunication Network Lab Manual

Figure. TCP

For LANCode :- set ns [new Simulator]set nf [open out.nam w]$ns namtrace-all $nfset tracefile1 [ open out.tr w]$ns trace-all $tracefile1

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]set n11 [$ns node]set n12 [$ns node]

$ns duplex-link $n0 $n1 15Mb 25ms DropTail$ns duplex-link-op $n0 $n1 orient right-down$ns duplex-link $n2 $n3 15Mb 25ms DropTail$ns duplex-link-op $n2 $n3 orient right$ns duplex-link $n3 $n1 15Mb 25ms DropTail$ns duplex-link-op $n3 $n1 orient right-up$ns duplex-link $n1 $n7 15Mb 25ms DropTail$ns duplex-link-op $n1 $n7 orient right

Page 29: Telecommunication Network Lab Manual

$ns duplex-link $n7 $n9 15Mb 25ms DropTail$ns duplex-link-op $n7 $n9 orient right-down$ns duplex-link $n4 $n5 15Mb 25ms DropTail$ns duplex-link-op $n4 $n5 orient right-down$ns duplex-link $n6 $n5 15Mb 25ms DropTail$ns duplex-link-op $n6 $n5 orient right-up$ns duplex-link $n5 $n8 15Mb 25ms DropTail$ns duplex-link-op $n5 $n8 orient right$ns duplex-link $n8 $n9 15Mb 25ms DropTail$ns duplex-link-op $n8 $n9 orient right-up

#setup a tcp2 connection b/w n0 to n10set tcp2 [new Agent/TCP]$ns attach-agent $n0 $tcp2set sink [new Agent/TCPSink]$ns attach-agent $n10 $sink$ns connect $tcp2 $sink$tcp2 set fid_ 1

set ftp2 [new Application/FTP]$ftp2 attach-agent $tcp2

#setup a tcp1 connection b/w n4 to n12set tcp1 [new Agent/TCP]$ns attach-agent $n4 $tcp1set sink [new Agent/TCPSink]$ns attach-agent $n12 $sink$ns connect $tcp1 $sink$tcp1 set fid_ 2

set ftp1 [new Application/FTP]$ftp1 attach-agent $tcp1

#setup a udp connection b/w n2 to n11set udp1 [new Agent/UDP]$ns attach-agent $n2 $udp1set null [new Agent/Null]$ns attach-agent $n11 $null$ns connect $udp1 $null$udp1 set fid_ -1

#cbr for the above udpset cbr [new Application/Traffic/CBR]$cbr attach-agent $udp1$ftp1 attach-agent $tcp1

Page 30: Telecommunication Network Lab Manual

set lan [$ns newLan "$n9 $n10 $n11 $n12" 50Mb 20ms LL Queue/DropTail MAC/Csma/Cd Channel]

$ns duplex-link $n1 $n2 10Mb 30ms DropTail$ns duplex-link $n2 $n3 1Mb 15ms DropTail$ns duplex-link $n3 $n4 20Mb 10ms DropTail$ns duplex-link $n3 $n5 .5Mb 50ms DropTail

$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-downset tcp [new Agent/TCP]$ns attach-agent $n1 $tcpset sink [new Agent/TCPSink]$ns attach-agent $n5 $sink$ns connect $tcp $sink$tcp set fid_ -1$tcp set packetSize_ 552set ftp [new Application/FTP]$ftp attach-agent $tcp$ns queue-limit $n1 $n2 2$ns queue-limit $n2 $n3 2$ns queue-limit $n3 $n5 2

proc finish { } {global ns nf$ns flush-traceclose $nfexec nam out.nam &exit0}$ns at 0.0 "$ftp start"$ns at 400.0 "$ftp stop"$ns at 500.0 "finish"$ns run

Page 31: Telecommunication Network Lab Manual

Fig. LAN

Output :-

Trace File of UDP : + 0.5 0 2 cbr 210 ------- 0 0.0 5.0 0 0- 0.5 0 2 cbr 210 ------- 0 0.0 5.0 0 0 . . .- 4.99668 2 3 cbr 210 ------- 0 0.0 5.0 897 897r 4.99836 2 3 cbr 210 ------- 0 0.0 5.0 895 895+ 4.99836 3 5 cbr 210 ------- 0 0.0 5.0 895 895- 4.99836 3 5 cbr 210 ------- 0 0.0 5.0 895 895+ 5 0 2 cbr 210 ------- 0 0.0 5.0 900 900- 5 0 2 cbr 210 ------- 0 0.0 5.0 900 900

Trace File of TCP :+ 0.1 1 2 tcp 40 ------- 1 1.0 4.0 0 0- 0.1 1 2 tcp 40 ------- 1 1.0 4.0 0 0r 0.11032 1 2 tcp 40 ------- 1 1.0 4.0 0 0

.

.

.r 4.9984 2 1 ack 40 ------- 1 4.0 1.0 555 1127+ 4.9984 1 2 tcp 1040 ------- 1 1.0 4.0 575 1134r 4.99904 2 3 tcp 1040 ------- 1 1.0 4.0 561 1106+ 4.99904 3 4 tcp 1040 ------- 1 1.0 4.0 561 1106- 4.99904 3 4 tcp 1040 ------- 1 1.0 4.0 561 1106

Trace File of LAN :+ 0 1 3 tcp 40 ------- -1 1.0 5.0 0 0- 0 1 3 tcp 40 ------- -1 1.0 5.0 0 0

Page 32: Telecommunication Network Lab Manual

r 0.025021 1 3 tcp 40 ------- -1 1.0 5.0 0 0...

- 400.036799 3 1 ack 40 ------- -1 5.0 1.0 5854 12206r 400.052349 3 1 ack 40 ------- -1 5.0 1.0 5853 12205r 400.061821 3 1 ack 40 ------- -1 5.0 1.0 5854 12206

Result :- Trace Files in TCP / UDP/ LAN are analysed.

Page 33: Telecommunication Network Lab Manual

Experiment - 7

Aim :- TCP IN WIRELESS SCENARIO

Theory : - An important performance measure of TCP is average throughput. Throughput is the average rate of successful message delivery over a communication channel. It is usually measured in bits per second (bit/s or bps), and sometimes in data packets per second or data packets per time.

Code :-

set ns [new Simulator] #Creating object of Simulator class

set nf [open out.nam w] # creating the nam file used for visualization and opening the created file out.nam in the write mode

$ns namtrace-all $nf # nf is the pointer to the nam fileset tf [open out.tr w] # creating the trace file (output files with data on simulation) and opening the created file out.tr in write mode

$ns trace-all $tf # tf is the pointer to the trace file, where all the traces are to recorded # defining the procedure finishproc finish {} {

global ns nf tf$ns flush-traceclose $nf#close $tfexec nam out.nam &exit 0

}

# defining nodesset n0 [$ns node] set n1 [$ns node]

Page 34: Telecommunication Network Lab Manual

$ns at 1.0 "$n0 label \"FTP\""

# creating links between nodes$ns duplex-link $n0 $n1 2Mb 100ms DropTail

#Set error model on link n0 to n1 set loss_module [new ErrorModel]$loss_module set rate_ 0.02 # error rate= 2% $loss_module ranvar [new RandomVariable/Uniform] #uniformly distributed RV$loss_module drop-target [new Agent/Null]$ns lossmodel $loss_module $n0 $n1

#setup a TCP connectionset tcp [new Agent/TCP] $ns attach-agent $n0 $tcpset sink [new Agent/TCPSink/DelAck]$ns attach-agent $n1 $sink$ns connect $tcp $sink$tcp set fid_ 1

#setup an FTP over TCP connectionset ftp [new Application/FTP] $ftp attach-agent $tcp$ftp set type_ FTP

#scheduling$ns at 1.0 "$ftp start" $ns at 100.0 "$ftp stop"

$ns at 120.0 "finish"$ns run

Page 35: Telecommunication Network Lab Manual

OUTPUT

10-2

10-1

100

101

102

100

101

102

103

104

error %

No.

of

pac

kets

receiv

ed

TCP: TAHOE

Fig 1: No. of packets vs. error % plot(logarithmic) for Tahoe (default TCP scheme)

LEARNING OUTCOMES

We learned how to replicate wired cum wireless network by using error model. We learned how to read the trace file and used it for plotting the graph. With the help of the graph, we saw that the throughput decreases as the error rate

in the link increases.

Page 36: Telecommunication Network Lab Manual

Experiment - 8

Aim :- Comparison Of Different Tcp Congestion Avoidance Algorithms In Wireless Scenario.

Theory : -

Modern implementations of TCP contain four intertwined algorithms: Slow-start, congestion avoidance, fast retransmit, and fast recovery.

Slow Start: Slow Start, a requirement for TCP software implementations is a mechanism used by the sender to control the transmission rate, otherwise known as sender-based flow control. This is accomplished through the return rate of acknowledgements from the receiver. When a TCP connection first begins, the Slow Start algorithm initializes a congestion window to one segment which is the maximum segment size ( MSS ) initialized by the receiver during the connection establishment phase. When acknowledgements are returned by the receiver, the congestion window increases by one segment for each acknowledgement returned. Thus, the sender can transmit the minimum of the congestion window and the advertised window of the receiver, which is simply called the transmission window.

Congestion Avoidance: During the initial data transfer phase of a TCP connection the Slow Start algorithm is used. However, there may be a point during Slow Start that the network is forced to drop one or more packets due to overload or congestion. If this happens, Congestion Avoidance is used to slow the transmission rate. However, Slow Start is used in conjunction with Congestion Avoidance as the means to get the data transfer going again so it doesn’t slow down and stay slow. In the Congestion Avoidance algorithm a retransmission timer expiring or the reception of duplicate ACKs can implicitly signal the sender that a network congestion situation is occurring. The sender immediately sets its transmission window to one half of the current window size (the minimum of the congestion window and the receiver’s advertised window size), but to at least two segments. If congestion was indicated by a timeout, the congestion window is reset to one segment, which automatically puts the sender into Slow Start mode. If congestion was indicated by duplicate ACKs, the Fast Retransmit and Fast Recovery algorithms are invoked.

Fast Retransmit: When a duplicate ACK is received, the sender does not know if it is because a TCP segment was lost or simply that a segment was delayed and received out of order at the receiver. If the receiver can re-order segments, it should not be long before the receiver sends the latest expected acknowledgement. Typically no more than one or two duplicate ACKs should be received when simple out of order conditions exist. If however

Page 37: Telecommunication Network Lab Manual

more than two duplicate ACKs are received by the sender, it is a strong indication that at least one segment has been lost. The TCP sender will assume enough time has lapsed for all segments to be properly re-ordered by the fact that the receiver had enough time to send three duplicate ACKs. When three or more duplicate ACKs are received, the sender does not even wait for a retransmission timer to expire before retransmitting the segment. This process is called the Fast Retransmit algorithm.

Fast Recovery: Since the Fast Retransmit algorithm is used when duplicate ACKs are being received, the TCP sender has implicit knowledge that there is data still flowing to the receiver.The reason is because duplicate ACKs can only be generated when a segment is received. This is a strong indication that serious network congestion may not exist and that the lost segment was a rare event. So instead of reducing the flow of data abruptly by going all the way into Slow Start, the sender only enters Congestion Avoidance mode. Rather than start at a window of one segment as in Slow Start mode, the sender resumes transmission with a larger window, incrementing as if in Congestion Avoidance mode. This allows for higher throughput under the condition of only moderate congestion.

Along with the congestion the losses can be due to noisy links. This is especially true in case of radio links e.g. in cellular phones or in satellite links. A link may become in fact completely disconnected for some period or it may suffer from occasional interferences (due to shadowing, fading, etc) that cause packets to contain errors and then to be dropped. For that, we introduce an error model where we assume that packets are dropped on forward link independently with some constant fixed probability.

An important performance measure of TCP is average throughput. Throughput is the average rate of successful message delivery over a communication channel. It is usually measured in bits per second (bit/s or bps), and sometimes in data packets per second or data packets per time.

Code :-

set ns [new Simulator] #Creating object of Simulator class

set nf [open out.nam w] # creating the nam file used for visualization and opening the created file out.nam in the write mode

$ns namtrace-all $nf # nf is the pointer to the nam fileset tf [open out.tr w] # creating the trace file (output files with data on simulation) and opening the created file out.tr in write mode

Page 38: Telecommunication Network Lab Manual

$ns trace-all $tf # tf is the pointer to the trace file, where all the traces are to recorded # defining the procedure finishproc finish {} {

global ns nf tf$ns flush-traceclose $nf#close $tfexec nam out.nam &exit 0

}

# defining nodesset n0 [$ns node] set n1 [$ns node]

$ns at 1.0 "$n0 label \"FTP\""

# creating links between nodes$ns duplex-link $n0 $n1 2Mb 100ms DropTail

#Set error model on link n0 to n1 set loss_module [new ErrorModel]$loss_module set rate_ 0.02 # error rate= 2% $loss_module ranvar [new RandomVariable/Uniform] #uniformly distributed RV$loss_module drop-target [new Agent/Null]$ns lossmodel $loss_module $n0 $n1

#setup a TCP connectionset tcp [new Agent/TCP] # defining different congestion OR avoidance algos #set tcp [new Agent/TCP/NewReno] OR#set tcp [new Agent/TCP/Vegas] $ns attach-agent $n0 $tcpset sink [new Agent/TCPSink/DelAck]$ns attach-agent $n1 $sink

Page 39: Telecommunication Network Lab Manual

$ns connect $tcp $sink$tcp set fid_ 1

#setup an FTP over TCP connectionset ftp [new Application/FTP] $ftp attach-agent $tcp$ftp set type_ FTP

#scheduling$ns at 1.0 "$ftp start" $ns at 100.0 "$ftp stop"

$ns at 120.0 "finish"$ns run

Output

Page 40: Telecommunication Network Lab Manual

LEARNING OUTCOMES

We learned how to use different congestion avoidance algorithms of TCP With the help of the graph we concluded that TCP Vegas in the best algorithm out of TCP Tahoe

and TCP NewReno in terms of number of packets received at a particular error rate of the link.

Page 41: Telecommunication Network Lab Manual

Experiment 9

AIM:-

Studying Error Models

THEORY

There has been renewed interest in exploring the functionality of TCP under the new conditions imposed by heterogeneous networks that are evolving at a fast pace. So, a researcher must have the means to test TCP under different conditions. He will have to replicate the wired-cum-wireless world in as realistic way as possible. Therefore one must have some error model in order to simulate losses in the network.

The broad characteristics of error model are:

Rate-based vs. Temporal error models :- Rate-based error models have a user specified deterministic or probabilistic drop rate on a per-segment basis. In the latter case, the model drops a segment based on a Bernoulli trial with the specified probability. In a temporal error model, the user specifies the proportion of time that the channel is “bad” or “good”. In the bad state any segment that happens to be coming along is corrupted, whereas in the good state no segments are dropped. Since a rate-based model will corrupt a specified proportion of segments irrespective of the protocol behavior, it is difficult, under such a model, to confidently assess the impact of the proposed improvements to existing protocols or the performance gain of new ones.

Synchronized vs. non-synchronized error models :- A TCO connection between two hosts could have the same forward and reverse paths, or could have at least one different link in the two paths. In the former case, whenever the forward path is in the bad state so should the reverse path be, and vice versa. In this sense, the error model has to be synchronized in both directions. On the other hand, if the forward and reverse paths are different, even if they exhibit the same error characteristics, the model should not be synchronized.

A simple example of creating an error model with a packet error rate of 1% is –

set loss_module [new ErrorModel] # create a loss_module and set its $loss_module set rate_ 0.01 packet error rate to 1 percent

# optional: set the unit and random variable

Page 42: Telecommunication Network Lab Manual

$loss_module unit pkt # error unit: packets (the default) $loss_module ranvar [new RandomVariable/Uniform]

$loss_module drop-target [new Agent/Null] # set target for dropped packets

The ErrorModel class is derived from the Connector base class. As the result, it inherits some methods for hooking up objects such as target and drop-target. If the drop target exists, it will receive corrupted packets from ErrorModel. Otherwise, ErrorModel just marks the error_ flag of the packet's common header, thereby, allowing agents to handle the loss. The ErrorModel also defines additional Tcl method unit to specify the unit of error and ranvar to specify the random variable for generating errors. If not specified, the unit of error will be in packets, and the random variable will be uniform distributed from 0 to 1.

Types of distribution of random variable:-

1. Pareto Distribution- It is constructed by specifying its expectation and shape parameter , the default values are 1.0 and 1.5 resp.βset r1 [new RandomVariable/Pareto]$r1 set avg_ 10.0$r1 set shape_ 1.2

2. Constant- A degenerated RV is the constant which equals to its value.

set r2 [new RandomVariable/Constant]$r2 set val_ 5.0

3. Uniform Distribution- It is defined through the smallest and largest point in its support whixh is 0 and 1 by default.

set r3 [new RandoVariable/Uniform] $r3 set min_ 0.0$r3 set max_ 10.0

4. Exponential Distribution- It is defined through its average value.

set r4 [new RandomVariable/Exponential]$r4 set avg_ 5

5. Hyperexponential Distribution-

set r5 [new RandomVariable/HyperExponential]

Page 43: Telecommunication Network Lab Manual

$r5 set avg_ 1.0$r5 set cov_ 4.0

In addition to the basic class ErrorModel described above, there are several other types of error modules-

MrouteErrorModel: error model for multicast routing, now inherits from trace. ErrorModel/Periodic: models periodic packet drops (drop every nth packet we

see).

SelectErrorModel: for Selective packet drop.

ErrorModel/TwoState: Two-State: error-free and error.

ErrorModel/TwoStateMarkov, ErrorModel/Expo, ErrorModel/Empirical: inherit from ErrorModel/TwoState.

ErrorModel/List: specify a list of packets/bytes to drop, which could be in any order.

ErrorModel/Uniform: Uniform error model.

A predominant error model in literature is a two state continuous time Markovian chain.

A B

As depicted, the “automaton” alternates between two states (A and B) which can have different dropping rates, possibly corresponding to “good” periods where the network does not corrupt packets, and “bad” periods when packets are dropped. The model uses the exponential distribution to determine the sojourn time in each state. In a given state we decide whether to drop, or not drop, an incoming packet according to, say, a random distribution. For example, if the specified drop rate for the B state is 10% then, while the automaton is in state B, an incoming packet is dropped according to a Bernoulli trial with probability 10%. This model is rate-based, because the decision of whether to drop a packet or not is predetermined according to a fixed rate. In other words, it does not matter when exactly a segment will actually arrive at the receiver: each and every segment undergoes a Bernoulli trial at the specified drop probability. The same two-state model can also be configured as time-based. Here, instead of assigning a drop rate to each state, we designate one as a “good” state where no segments

are dropped, and the other one as “bad” where all segments are dropped. The sojourn times in each state are still sampled from a random distribution.

set $rvGood [new RandomVariable/Exponential] # Create 2 exponential random

Page 44: Telecommunication Network Lab Manual

variable (for Markov model)

$rvgood set avg_ xxx # xxx is the error-free parameterset $rvLoss [new RandomVariable/Exponential]$rvloss set avg_ xxx # xxx is the error parameter

set em [new ErrorModel/TwoState] # Now create a 2 state Markov $em ranvar 0 $rvgood # error model and assign$em ranvar 1 $rvloss # the parameters

Similarly, a multi-state error model can be implemented. Transitions to the next error state occur at the end of the duration of the current state. The next error state is then selected using the transition state matrix. To create a multi-state error model, the following parameters should be supplied

states: an array of states (error models). periods: an array of state durations.

trans: the transition state model matrix.

transunit: one of [pkt|byte|time].

sttype: type of state transitions to use: either time or pkt.

nstates: number of states.

start: the start state.