CNSP Lab Manual
CNSP Lab Manual
BENGALURU INDIA
Networks Laboratory
BTCS14F6600
Name
Srn
Branch
Semester
Section
Academic Year
Lab Requirements
Following are the required hardware and software for this lab, which is available in the laboratory.
• Hardware: Desktop system or Virtual machine in a cloud with OS installed. Presently in the
Lab, Pentium IV Processor having 1 GB RAM and 250 GB Hard Disk is available. Desktop
systems are dual boot having Windows as well as Linux OS installed on them.
STEP 1: Download and Extract ns2 using terminal by using given commands:
cd ~/
sudo wget http://softlayer-sng.dl.sourceforge.net/project/nsnam/allinone/ns-allinone-2.35/ns-allinone-
2.35.tar.gz
tar -xvzf ns-allinone-2.35.tar.gz
STEP 2: Ns2 requires some packages including GCC- version 4.4 to work correctly. So install all of
them by using the following command:
STEP 3: After installation of packages, we have to make a change in the “ls.h” file. Navigate to the
folder “linkstate” which is assumed be in the ns folder extracted and is in the home folder of your system.
cd ~/ns-allinone-2.35/ns-2.35/linkstate
STEP 4: Open the file named “ls.h” by using given command and scroll to the 137th line. You will find
the word “error”; change that to “this->error”. To open the file use the following command:
gedit ls.h
STEP 5: Now, we need to inform ns which version of GCC will be used. To do so, go to your ns folder
and type the following command. Here, change CC= @CC@ to CC=gcc-4.4, then save
and exit.
Sudo gedit ns-allinone-2.34/otcl-1.13/Makefile.in
STEP 6: Now we are ready to install ns2. Run the install script using the following commands:
sudo su cd ~/ns-allinone-2.35/./install
STEP 7: The final step is to tell the system, where the files for ns2 are installed or present. Open the
.bashrc file using the given command. Add the given lines but be sure that the path you are giving is the
same where the folder ns is present. For example, if you have installed it in a folder “/home/abc”, then
replace “/home/pcquest/ns-allinone-2.35/otcl-1.14” with “/home/abc/ns-allinone-2.35/otcl-1.14”.
sudo gedit ~/.bashrc
CONTENTS
SL.NO Lab Programs PAGE NO.
Part-A
1. A network consists of three nodes (n0-n2). Link existence (duplex in nature) 2
between the nodes is as follows: n0-n1 and n1-n2. The link no-n1 has 10
Kbps of bandwidth and 100 ms of delay. The link n1-n2 has 5 Mbps of
bandwidth and 200 ms of delay. Node “n0” is having some data to send to
node “n2” through node “n1”, which is a hub device. Each node uses Drop
Tail queue of which the maximum size is 10.Write a Tcl script to observe
the packet flow for the given network in network animator (NAM)..
Both FTP and TELNET are set to start at 0.3 seconds , and stop at 5
seconds. Write a Tcl script to observe the packet flow for the given
network and observe the output in NAM for this network scenario.
bandwidth and 10 ms of delay. Create two PING agents and attach them to
the nodes n0 and n2. Connect the two agents and schedule the transmission
of PING messages at an interval of 0.2 seconds and finish at 1.0 second.
Write a Tcl script to observe the packet flow for the given network and
observe the output in NAM for this network scenario.
99 99 4 0
Write a program for distance vector algorithm to find suitable path
for transmission by using the routing table for each node.
9. Using TCP/IP sockets, write a client-server program to make client send 91
the file name and the server to send back the contents of the requested file
file name “sample.txt” with the following contents:”HI I AM AT REVA
UNIVERSITY. SEE YOU SOON”. Steps for establishing a TCP socket
on the client side are the following:
Display suitable error message in case the the file is not present in the
server.
10. There is a single Server process which runs continuously in background, 105
eventhough if there is no client to interact with it. Client processes runs in
foreground and interacts with the server process. Both the client and server
processes run on the same machine.
The Client process accepts a command (a shell command) from the user and
send's it to the Server via a FIFO which is a public channel between Client
and Server for processing. Assume this FIFO name as PUBLIC fifo since
its existence is known to all clients and the server. Once the command is
received, the Server executes it using the popen–pclose sequence (which
generates an unnamed pipe in the Server process). After execution Server
process returns the output of the command executed to the client over a FIFO
which is a private channel between the client and server. Let us name this
FIFO as PRIVATE fifo. The Client, upon receipt, displays the output on the
screen.
• Create a unique name for the PRIVATE fifo and invoke it.
• Open the PUBLIC fifo in write mode.
• Generate a PUBLIC fifo and open it in both read and write mode.
Wait for the message from a Client process.
• Read the message from PUBLIC fifo.
• Open the Client's PRIVATE fifo in write mode.
• Execute the command from Client process using popen.
• Write the output into Client's PRIVATE fifo.
NOTE: Each and every Client process should have its own unique
PRIVATE fifo to receive information from Server.
11. Choose the two prime numbers, p=17 and q=11. Write a program for public 114
key encryption system using RSA algorithm to encrypt and decrypt the
message. For a message M=”he12ll34o“, show the encryption and
decryption
12. Examine node transmitting/receiving packets to/from other nodes. Using a 140
random function; vary the packet size, considering the following cases.
PART A Programs
INTRODUCTION
Simulation is a meaningful evaluation approach only when it produces “trustable” results. Validation
is needed to certify that the simulation models reproduce correctly the characteristics and dynamics
of the system under study. The validation of a network model is done by:
There are both free/open-source and proprietary network simulators available. Examples of notable
network simulators / emulators include:
• ns (open source)
a. Network design validation for enterprises / data centers /sensor networks etc.
b. Analyzing Utilities distribution communication, railway signaling / communication etc
c. Network protocol R & D
d. Defense applications such as HF / UHF / VHF MANET networks, Tactical data links etc.
There are a wide variety of network simulators, ranging from the very simple to the very complex.
Minimally, a network simulator must enable a user to
School of Computing and Information Technology Page 5
Networks Lab REVA University
1. Model the network topology specifying the nodes on the network and the links between those
nodes
2. Model the application flow (traffic) between the nodes
3. Providing network performance metrics as output
4. Visualization of the packet flow
5. Technology / protocol evaluation and device designs
6. Logging of packet / events for drill down analyses / debugging
Network emulation
A network emulator allows users to introduce real devices and applications into a test network
(simulated) that alters packet flow in such a way as to mimic the behavior of a live network. Live traffic
can pass through the simulator and be affected by objects within the simulation.
The typical methodology is that real packets from a live application reach the emulation server (where
the virtual network is simulated. The real packet gets modulated into a simulation packet. The
Simulation packet gets demodulated into real packet after experiencing effects of loss, errors, delay,
jitter etc., thereby transferring these network effects into the real packet. Thus it is as-if the real packet
flowed through the real networks but in reality it flowed through the simulated network.
Emulation is widely used in the design stage for validating communication networks prior to
deployment.
Wireshark is a free and open source packet analyzer. It is used for network troubleshooting, analysis,
software and communications protocol development, and education. Originally named Ethereal, the
project was renamed Wireshark in May 2006 due to trademark issues.[4]
Wireshark is cross-platform, using the Qt widget toolkit in current releases to implement its user
interface, and using pcap to capture packets; it runs on Linux, macOS, BSD, Solaris, some
other Unix-like operating systems, and Microsoft Windows. There is also a terminal-based (non-GUI)
version called TShark. Wireshark, and the other programs distributed with it such as TShark, are free
software, released under the terms of the GNU General Public License.
Network Simulator is mainly based on two languages.They are C++ and OTcl. OTcl is the object
oriented version of Tool Command language.The network simulator is a bank of of different network
and protocol objects. C++ helps in the following way:
Before we get into the program we should consider the following things:
• Network Animator(NAM)
• Tracing
Initialization
From the above command we get that a variable ns is being initialized by using the set command.
Here the code [new Simulator] is a instantiation of the class Simulator which uses the reserved word
'new'. So we can call all the methods present inside the class simulator by using the variable ns.
In the above we create a output trace file out.tr and a nam visualization file out.nam. But in the Tcl
script they are not called by their names declared,while they are called by the pointers initialized for
them such as tracefile1 and namfile1 respectively.The line which starts with '#' are commented.The
next line opens the file 'out.tr' which is used for writing is declared 'w'.The next line uses a simulator
method trace-all by which we will trace all the events in a particular format.
In the above the word 'proc' is used to declare a procedure called 'finish'.The word 'global' is used to
tell what variables are being used outside the procedure.
'flush-trace' is a simulator method that dumps the traces on the respective files.the command 'close'
is used to close the trace files and the command 'exec' is used to execute the nam visualization.The
command 'exit' closes the application and returns 0 as zero(0) is default for clean exit.
Thus the entire operation ends at 125 seconds.To begin the simulation we will use the command
In the above we created a node that is pointed by a variable n0.While referring the node in the script
we use $n0. Similarly we create another node n2.Now we will set a link between the two nodes.
So we are creating a bi-directional link between n0 and n2 with a capacity of 10Mb/sec and a
propagation delay of 10ms. In NS an output queue of a node is implemented as a part of a link whose
input is that node to handle the overflow at the queue.But if the buffer capacity of the output queue is
exceeded then the last packet arrived is dropped and here we will use a 'DropTail' option.Many other
options such as RED(Random Early Discard) mechanism, FQ(Fair Queuing), DRR(Deficit Round
Robin), SFQ(Stochastic Fair Queuing) are available.
So now we will define the buffer capacity of the queue related to the above link
01 #create nodes
02
03 set n0 [$ns node]
04 set n1 [$ns node]
05 set n2 [$ns node]
06 set n3 [$ns node]
07 set n4 [$ns node]
08 set n5 [$ns node]
09
10 #create links between the nodes
11
12 $ns duplex-link $n0 $n2 10Mb 10ms DropTail
13 $ns duplex-link $n1 $n2 10Mb 10ms DropTail
14 $ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
15 $ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
16 $ns duplex-link $n0 $n2 0.5Mb 40ms DropTail
17 $ns duplex-link $n0 $n2 0.5Mb 40ms DropTail
18
19 #set queue-size of the link (n2-n3) to 20
20 $ns queue-limit $n2 $n3 20
TCP
TCP is a dynamic reliable congestion protocol which is used to provide reliable transport of packets
from one host to another host by sending acknowledgements on proper transfer or loss of
packets.Thus TCP requires bi-directional links in order for acknowledgements to return to the source.
Now we will show how to set up tcp connection between two nodes
The command 'set tcp [new Agent/TCP]' gives a pointer called 'tcp' which indicates the tcp agent which
is a object of ns.Then the command '$ns attach-agent $n0 $tcp' defines the source node of tcp
connection. Next the command 'set sink [new Agent/TCPSink]' defines the destination of tcp by a
pointer called sink. The next command '$ns attach-agent $n4 $sink' defines the destination node as
n4.Next, the command '$ns connect $tcp $sink' makes the TCP connection between the source and
the destination.i.e n0 and n4.When we have several flows such as TCP, UDP etc in a network. So, to
identify these flows we mark these flows by using the command '$tcp set fid_1'. In the last line we set
the packet size of tcp as 552 while the default packet size of tcp is 1000.
File Transfer Protocol(FTP) is a standard mechanism provided by the Internet for transferring files
from one host to another. Well this is the most common task expected from a networking or a inter
networking . FTP differs from other client server applications in that it establishes between the client
and the server. One connection is used for data transfer and other one is used for providing control
information. FTP uses the services of the TCP. It needs two connections. The well Known port 21 is
used for control connections and the other port 20 is used for data transfer.
Well here we will learn in how to run a FTP connection over a TCP
In above,the command 'set ftp [new Application/FTP]' gives a pointer called 'ftp' which indicates the
FTP application.Next, we attach the ftp application with tcp agent as FTP uses the services of TCP.
UDP
The User datagram Protocol is one of the main protocols of the Internet protocol suite.UDP helps the
host to send send messages in the form of datagrams to another host which is present in a Internet
protocol network without any kind of requirement for channel transmission setup. UDP provides a
unreliable service and the datagrams may arrive out of order,appear duplicated, or go missing without
notice. UDP assumes that error checking and correction is either not necessary or performed in the
application, avoiding the overhead of such processing at the network interface level. Time-sensitive
applications often use UDP because dropping packets is preferable to waiting for delayed packets,
which may not be an option in a real-time system.
Similarly,the command 'set udp [new Agent/UDP]' gives a pointer called 'udp' which indicates the udp
agent which is a object of ns.Then the command '$ns attach-agent $n1 $udp' defines the source node
of udp connection. Next the command 'set null [new Agent/Null]' defines the destination of udp by a
pointer called null. The next command '$ns attach-agent $n5 $null' defines the destination node as
n5.Next, the command '$ns connect $udp $null' makes the UDP connection between the source and
the destination.i.e n1 and n5.When we have several flows such as TCP,UDP etc in a network. So, to
identify these flows we mark these flows by using the command '$udp set fid_2
Constant Bit Rate (CBR) is a term used in telecommunications, relating to the quality of service.When
referring to codecs, constant bit rate encoding means that the rate at which a codec's output data
should be consumed is constant. CBR is useful for streaming multimedia content on limited capacity
channels since it is the maximum bit rate that matters, not the average, so CBR would be used to take
advantage of all of the capacity. CBR would not be the optimal choice for storage as it would not
allocate enough data for complex sections (resulting in degraded quality) while wasting data on simple
sections.
In the above we define a CBR connection over a UDP one. Well we have already defined the UDP
source and UDP agent as same as TCP. Instead of defining the rate we define the time interval
between the transmission of packets in the command '$cbr set rate_0.01Mb'. Next, with the help of
the command '$cbr set random _false' we can set random noise in cbr traffic.we can keep the noise
by setting it to 'false' or we can set the noise on by the command '$cbr set random _1'. We can set by
packet size by using the command '$cbr set packetSize_(packetsize).We can set the packet size up
to sum value in bytes.
Scheduling Events
In ns the tcl script defines how to schedule the events or in other words at what time which event will
occur and stop. This can be done using the command
$ns at .
Network Animator(NAM)
When we will run the above program in ns then we can can visualize the network in the NAM. But
instead of giving random positions to the nodes, we can give suitable initial positions to the nodes and
can form a suitable topology. So, in our program we can give positions to the nodes in NAM in the
following way
We can also define the color of cbr and tcp packets for identification in NAM.For this we use the
following command
Tracing
Tracing Objects
NS simulation can produce visualization trace as well as ASCII file corresponding to the events that
are registered at the network. While tracing ns inserts four objects: EnqT,DeqT,RecvT & DrpT. EnqT
registers information regarding the arrival of packet and is queued at the input queue of the link. When
overflow of a packet occurs, then the information of thye dropped packet is registered in DrpT.DeqT
holds the information abut the packet that is dequeued instantly.RecvT hold the information about the
packet that has been received instantly.
The first field is event.It gives you four possible symbols '+' '-' 'r' 'd'.These four symbols correspond
respectively to enqueued, dequeued, received and dropped.
The second field gives the time at which the event occurs
The third field gives you the input node of the link at which the event occurs
The fourth field gives you the the output node at which the event occurs
The fifth field shows the information about the packet type.i.e whether the packet is UDP or TCP
The eight field is the flow id(fid) for IPv6 that a user can set for each flow in a tcl script.It is also used
for specifying the color of flow in NAM display
The eleventh field is the network layer protocol's packet sequence number
cat out.tr
PART-A
1 Problem Statement
A network consists of three nodes (n0-n2). Link existence (duplex in nature) between the
nodes is as follows: n0-n1 and n1-n2. The link no-n1 has 10 Kbps of bandwidth and 100 ms of
delay. The link n1-n2 has 5 Mbps of bandwidth and 200 ms of delay. Node “n0” is having some
data to send to node “n2” through node “n1”, which is a hub device. Each node uses Drop Tail
queue of which the maximum size is 10.Write a Tcl script to observe the packet flow for the given
network in network animator (NAM).
# To create simulator
#The below code sets the udp0 packets to red and udp1 packets to blue color
25. $udp0 set class_ 1
26. $udp1 set class_ 2
1 Problem Statement
A network consists of 4 nodes (n0-n3) . Here, n0 and n1 are source nodes, n2 is a router and n3
is the destination node. The duplex links between the nodes is as follows:
• n0 and n2 has 10 Mbps of bandwidth and 10 ms of delay,
• n1 and n2 has 10 Kbps of bandwidth and 100 ms of delay, and
• n2 and n3 has 10 Kbps of bandwidth and 100 ms of delay.
A TCP agent is attached to n0 and connection is established to a TCP sink agent attached to n3.
An UDP agent that is attached to n1 is connected to a NULL agent attached to n3. An FTP and a
CBR traffic generator are attached to a TCP and UDP agent, respectively. The TCP agent between
n0-n3 has a packet size of 200 bytes with a time interval of 0.01 seconds, and the UDP agent
between n1-n3 has a packet size of 300 bytes with the time interval of 0.001 seconds.
The CBR is set to start at 0.1 seconds, FTP is set to start at 0.3 seconds and both stop at 5 seconds.
Write a Tcl script to observe the packet flow for the given network and observe the output in
NAM for this network scenario.
# to create simulator
1. set ns [new Simulator]
2. set trf [open 2.tr w]
3. $ns trace-all $trf
4. set namf [open 2.nam w]
5. $ns namtrace-all $namf
# The below code is used to set the color and name's to the #nodes.
10. $ns color 1 "red"
11. $ns color 2 "green"
12. $n0 label "source1"
13. $n1 label "source2"
14. $n2 label "Router"
15. $n3 label "destination"
# To provide link
16. $ns duplex-link $n0 $n2 10Mb 10ms DropTail
17. $ns duplex-link $n1 $n2 10Kb 100ms DropTail
18. $ns duplex-link $n2 $n3 100Mb 1ms DropTail
# The below code is used assign TCP and UDP agents and traffic
19. set tcp0 [new Agent/TCP]
20. $ns attach-agent $n0 $tcp0
21. set ftp0 [new Application/FTP]
22. $ftp0 attach-agent $tcp0
23. set sink3 [new Agent/TCPSink]
24. $ns attach-agent $n3 $sink3
#The below code is used to set the packet size of ftp and udp.
31. $ftp0 set packetSize_ 200
32. $ftp0 set interval_ 0.01
School of Computing and Information Technology Page 22
Networks Lab REVA University
1 Problem Statement
A network consists of 4 nodes (n0-n3) . Here, n0 is the FTP source, and n1 is the TELNET source,
n2 is a router and n3 is the common destination node. The duplex links between the nodes is as
follows:
• n0 and n2 has 5 Mbps of bandwidth and 10 ms of delay,
• n1 and n2 has 10 Mbps of bandwidth and 10 ms of delay, and
• n2 and n3 has 15 Mbps of bandwidth and 10 ms of delay.
TCP agents are attached to n0 and n1 and connection is established to a sink agent attached to n3.
With Telnet connection, packet size is set to 500 Mega bytes with a time interval of 0.001 seconds.
The default maximum size of a packet that a TCP agent can generate is 1 kb.
Both FTP and TELNET are set to start at 0.3 seconds, and stop at 5 seconds. Write a Tcl script to
observe the packet flow for the given network and observe the output in NAM for this network
scenario.
FTP and Telnet are two very old protocols that are used on networks to add certain
functionalities. FTP is a File Transfer Protocol, and its only concern is to facilitate the transfer
of files from one point to another, along with a few management capabilities like making and
deleting directories. Telnet is a bit more like a ‘jack of all trades’, as it is simply a connection
protocol that allows a user to connect to a remote server that is listening for Telnet commands.
Once the connection is established, the user can then issue commands to the server computer,
and examine the responses that are sent back. Although both started out as command line
tools, GUIs later appeared that greatly simplified the use of FTP. Instead of knowing all the
commands and typing out all the filenames, some dedicated applications let you browse a
local drive and a remote drive, as if you are using a file explorer. It keeps all the commands
invisible to the user, thereby lessening the learning curve. This is not really possible with
Telnet, as there are a wide range of commands and parameters that can be issued to the server.
Due to the age of both software, they do not have any built-in security measures. Even usernames
and passwords are sent in plain text, making them vulnerable to sniffing. With later modifications,
people can now use secure versions of FTP, called FTPS and SFTP. On the other hand, Telnet has
been largely replaced by SSH, due to the addition of security measures. As Telnet has been
superseded by SSH, making it secure seems redundant.
Currently, FTP is still in wide use, as it is an easy way to upload files to web servers. There’s a
wide array of applications that use FTP to achieve their purpose. The use of Telnet has been
dwindling since the creation of SSH, but there are still people who use it mainly as a diagnostic
tool. Telnet provides a good view of how certain network services work, by sending commands
and examining the response to determine if it is proper or not.
3.2 Algorithm/Steps
# To provide link
15. $ns duplex-link $n0 $n2 5Mb 10ms DropTail
16. $ns duplex-link $n1 $n2 10Mb 10ms DropTail
17. $ns duplex-link $n2 $n3 15Mb 10ms DropTail
#The below code is used to connect the tcp agents & sink.
32. $ns connect $tcp0 $sink3
33. $ns connect $tcp1 $sink3
1 Problem Statement
A network consists of 6 nodes (n0-n5). The duplex links between n0 and n2, n1 and n2,n2 and
n3, n3 and n4 & n4 and n5 with 0.1 Mbps of bandwidth and 10 ms of delay. Create two PING
agents and attach them to the nodes n0 and n2. Connect the two agents and schedule the
transmission of PING messages at an interval of 0.2 seconds and finish at 1.0 second. Write a
Tcl script to observe the packet flow for the given network and observe the output in NAM for
this network scenario.
3.1 Theory
The ping command is a very common method for troubleshooting the accessibility of
devices. It uses a series of Internet Control Message Protocol (ICMP) Echo messages to
determine:
• Whether a remote host is active or inactive.
• The round-trip delay in communicating with the host, and
• Packet loss.
The command-line options for the ping utility and its output vary for its many
implementations. Options may include the size of the payload, count of tests, limits for
the number of network hops (TTL) that probes traverse, and interval between the
requests. Many systems provide a companion utility ping6, for testing on Internet
Protocol version 6 (IPv6) networks.
3.2 Algorithm/Steps
# To create nodes
6. set n0 [$ns node]
7. set n1 [$ns node]
8. set n2 [$ns node]
9. set n3 [$ns node]
10. set n4 [$ns node]
11. set n5 [$ns node]
12. set n6 [$ns node]
#The below code is used to set the color and name's to the #nodes
13. $n0 label "Ping0"
14. $n3 label "Ping3"
15. $n4 label "Ping4"
16. $n6 label "Ping6"
17. $n2 label "Router"
#The below function is executed when the ping agent receives #a reply from the
destination
41. Agent/Ping instproc recv {from rtt} { $self instvar node_
42. puts " The node [$node_ id] received an reply from $from
43. with round trip time of $rtt"
44. }
45. proc finish {} {
46. global ns naf trf
47. exec nam 4.nam &
48. $ns flush-trace
49. close $trf
50. close $naf
51. exit 0
52. }
1 Problem Statement
A network consists of n nodes (say n =6). The duplex links between the nodes is as follows:
• n0 and n2 has 2Mbps of bandwidth and 10 ms of delay,
• n1 and n2 has 2Mbps of bandwidth and 10 ms of delay,
The Simplex links between the nodes is as follows:
• n2 and n3 has 0.3Mbps of bandwidth and 100 ms of delay.
• n3 and n2 has 0.3Mbps of bandwidth and 100 ms of delay.
The LAN is established between the nodes n3, n4 and n5 with 0.5 Mbps of band width and 40ms
delay. Each node uses DropTail queue of which the maximum size is 10 . Write a Tcl script to
observe the packet flow for the given network and observe the output in NAM for this network
scenario.
2 Student Learning Outcomes
3.1 Theory
A local area network (LAN) is a group of computers that are connected together in a
localized area to communicate with one another and share resources such as printers.
Data is sent in the form of packets and to regulate the transmission of the packets,
different technologies can be used. The most widely used LAN technology is the Ethernet
and it is specified in a standard called IEEE 802.3. Other types of LAN networking
technologies include token ring and FDDI.
Ethernet uses a star topology in which the individual nodes (devices) are networked with
one another via active networking equipment such as switches. The number of networked
devices in a LAN can range from two to several thousand.
Depending on the type of twisted pair or fiber optic cables used, data rates today can
range from 100 Mbit/s to 10,000 Mbit/s.
#create Simulator
1. set ns [new Simulator]
#Finish Procedure
8. proc Finish {} {
9. global ns ntrace namfile
#Create 6 nodes
26. for {set i 0} {$i < 6} {incr i} {
27. set n($i) [$ns node]
28. }
#Setup queue between n(2) and n(3) and monitor the queue
37. $ns queue-limit $n(2) $n(3) 20
38. $ns simplex-link-op $n(2) $n(3) queuePos 0.5
#Set error model on link n(2) and n(3) and insert the error model
39. set loss_module [new ErrorModel]
40. $loss_module ranvar [new RandomVariable/Uniform]
41. $loss_module drop-target [new Agent/Null]
42. $ns lossmodel $loss_module $n(2) $n(3)
#Schedule events
66. $ns at 0.1 "$cbr0 start"
67. $ns at 1.0 "$ftp0 start"
68. $ns at 124.0 "$ftp0 stop"
69. $ns at 124.5 "$cbr0 stop"
70. $ns at 125.0 "Finish"
#Run Simulation
71. $ns run
1 Problem Statement
For a wireless network consisting of three mobile nodes (n0-n2), Nodes are configured with
the specific parameters of a wireless node. Initial location of the node is fixed. Nodes are given
mobility with fixed speed and fixed destination location. TCP agent is attached to node0 and
TCP sink agent is attached to node1. Both the agents are connected and FTP application is
attached to TCP agent. Write a Tcl script and make an ad-hoc simulation to analyze the output in
the trace file. Use the routing protocol as Adhoc on demand distance vector (AODV).
3.1 Theory
A wireless local area network (WLAN) is a wireless computer network that links two
or more devices using a wireless distribution method (often spread
spectrum or OFDM radio) within a limited area such as a home, school, computer
laboratory, or office building. This gives users the ability to move around within a local
coverage area and still be connected to the network, and can provide a connection to the
wider Internet. Most modern WLANs are based on IEEE 802.11 standards, marketed
under the Wi-Fi brand name.
All components that can connect into a wireless medium in a network are referred to as
stations (STA). All stations are equipped with wireless network interface
controllers (WNICs). Wireless stations fall into one of two categories: wireless access
points, and clients. Access points (APs), normally wireless routers, are base stations for
the wireless network. They transmit and receive radio frequencies for wireless enabled
devices to communicate with. Wireless clients can be mobile devices such as
laptops, personal digital assistants, IP phones and other smart phones, or fixed devices
such as desktops and workstations that are equipped with a wireless network interface.
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON
# Generation of movements
36. $ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
37. $ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
38. $ns at 19.0 "$node_(2) setdest 480.0 300.0 5.0"
num_nodes is set 3
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
INITIALIZE THE LIST xListHead
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 550.0
SORTING LISTS ...DONE!
end simulation
1. Simulate an Ethernet LAN using N nodes (6-10), change error rate and data rate and
compare throughput.
4. Simulate an Ethernet LAN using n nodes(6<n<10) and set multiple traffic nodes and
determine collision across different nodes.
5. Simulate an Ethernet LAN using n nodes(6<n<10) and plot Congestion window for
different source and destination
6. Simulate a simple ESS and with transmitting nodes in Wireless LAN determine the
performance with respect to transmission of packets.
PART-B
Program 7: CRC
1 Problem Statement
Assume a message represented by the polynomial M(x) = xn +.... x2+ x +1, choosing ‘n’ in the
range of 4 to 16. Message is sent from the sender with a checksum. When it arrives at the
receiver’s end, checksum is recalculated for detecting the error. Hence, write a program for error
detecting code using CRC-CCITT (16-bits), considering 10001000000100001 as the standard
divisor polynomial.
bn-1bn-2bn-3…b2b1b0
As
Ex: - 10010101110
As
X10 + X7 + X5 + X3 + X2 + X1
To compute an n-bit binary CRC, line the bits representing the input in a row, and position the
(n+1)-bit pattern representing the CRC’s divisor (called a “polynomial”) underneath the left-
hand end of the row.
11010011101100
This is first padded with zeroes corresponding to the bit length n of the CRC. Here is the first
calculation for computing a 3-bit CRC:
------------------
If the input bit above the leftmost divisor bit is 0, do nothing. If the input bit above the
leftmost divisor bit is 1, the divisor is XORed into the input (in other words, the input bit
above each 1-bit in the divisor is toggled). The divisor is then shifted one bit to the right, and
the process is repeated until the divisor reaches the right-hand end of the input row. Here is the
entire calculation:
00111011101100 000
1011
00010111101100 000
1011
00000001101100 000
1011
00000000110100 000
1011
00000000011000 000
1011
00000000001110 000
1011
00000000000101 000
101 1
-----------------
Since the leftmost divisor bit zeroed every input bit it touched, when this process ends the only
bits in the input row that can be nonzero are the n bits at the right-hand end of the row.
These n bits are the remainder of the division step, and will also be the value of the CRC
function (unless the chosen CRC specification calls for some postprocessing).
The validity of a received message can easily be verified by performing the above calculation
again, this time with the check value added instead of zeroes. The remainder should equal zero
if there are no detectable errors.
00111011101100 100
......
00000000001110 100
1011
00000000000101 100
101 1
------------------
0 <--- remainder
3.2 Algorithm.
1. Given a bit string, append 0S to the end of it (the number of 0s is the same as the
degree of the generator polynomial) let B(x) be the polynomial corresponding to B.
2. Divide B(x) by some agreed on polynomial G(x) (generator polynomial) and determine
the remainder R(x). This division is to be done using Modulo 2 Division.
3. Define T(x) = B(x) –R(x)
(T(x)/G(x) => remainder 0)
3. char data[100],concatdata[117],src_crc[17],dest_crc[17],frame[120],divident[18];
4. char divisor[18]="10001000000100001",res[17]="0000000000000000";
18. else
19. {
20. for(i=1;i<=16;i++)
21. divident[i-1]=divident[i];
22. }
23. if(node==0)
24. divident[i-1]=concatdata[j];
25. else
26. divident[i-1]=frame[j];
27. }
28. divident[i]='\0';
School of Computing and Information Technology Page 46
Networks Lab REVA University
RUN 1:
$ cc prog1.c
$ ./a.out
AT SOURCE NODE
enter the data to be send :110011
crc is 0000011000110000
data is : 110011
the frame transmitted is : 1100110000011000110000
SOURCE NODE TRANSMITTED THE FRAME
AT DESTINATION NODE
enter the received frame: 1100110000011000110000
crc is 0000000000000000
received frame is error free
AT DESTINATION NODE
enter the received frame: 1100110000011000110001
crc is 0000000000000001
3.5 Implementation Phase: Compile the Program and note the syntax errors/warning if
occurred during each compilation. Remove those syntax errors/warnings for generation
of executable file.
3.6 Simulation of Errors/Warnings:
3.6.1 Syntax Errors/Warnings:
S. No. Errors/Warnings Reflection of the Errors/Warnings in
Simulated compilation/output
1 Problem Statement
A network topology consists of n nodes (varying from 4-10). Links connecting the nodes have some
costs/weights associated with them. Links for unreachable nodes are indicated by infinity (say,
999).The sample cost adjacency matrix is given below for a network of 4 nodes:
0 2 99 99
2 0 1 99
99 1 0 4
99 99 4 0
Write a program for distance vector algorithm to find suitable path for transmission by using the
routing table for each node.
2 Student Learning Outcomes
Routing algorithm is a part of network layer software which is responsible for deciding which
output line an incoming packet should be transmitted on. If the subnet uses datagram internally,
this decision must be made anew for every arriving data packet since the best route may have
changed since last time. If the subnet uses virtual circuits internally, routing decisions are made
only when a new established route is being set up. The latter case is sometimes called session
routing, because a rout remains in force for an entire user session (e.g., login session at a terminal
or a file).
Routing algorithms can be grouped into two major classes: adaptive and non adaptive. Non
adaptive algorithms do not base their routing decisions on measurement or estimates of current
traffic and topology. Instead, the choice of route to use to get from I to J (for all I and J) is
compute in advance, offline, and downloaded to the routers when the network ids booted. This
procedure is sometime called static routing.
Adaptive algorithms, in contrast, change their routing decisions to reflect changes in the
topology, and usually the traffic as well. Adaptive algorithms differ in where they get
information (e.g., locally, from adjacent routers, or from all routers), when they change the
routes (e.g., every ∆T sec, when the load changes, or when the topology changes), and what
metric is used for optimization (e.g., distance, number of hops, or estimated transit time).
Two algorithms in particular, distance vector routing and link state routing are the most popular.
Distance vector routing algorithms operate by having each router maintain a table (i.e., vector)
giving the best known distance to each destination and which line to get there. These tables are
updated by exchanging information with the neighbors.
The distance vector routing algorithm is sometimes called by other names, including the
distributed Bellman-Ford routing algorithm and the Ford-Fulkerson algorithm, after the
researchers who developed it (Bellman, 1957; and Ford and Fulkerson, 1962). It was the original
ARPANET routing algorithm and was also used in the Internet under the RIP and in early
versions of DECnet and Novell’s IPX. AppleTalk and Cisco routers use improved distance
vector protocols.
In distance vector routing, each router maintains a routing table indexed by, and containing one
entry for, each router in subnet. This entry contains two parts: the preferred out going line to
use for that destination, and an estimate of the time or distance to that destination. The metric
used might be number of hops, time delay in milliseconds, total number of packets queued along
the path, or something similar.
The router is assumed to know the “distance” to each of its neighbor. If the metric is hops, the
distance is just one hop. If the metric is queue length, the router simply examines each queue.
If the metric is delay, the router can measure it directly with special ECHO packets hat the
receiver just time stamps and sends back as fast as possible.
Distance vector routing algorithm reacts rapidly to good news, but leisurely to bad news.
Consider a router whose best route to destination X is large. If on the next exchange neighbor
A suddenly reports a short delay to X, the router just switches over to using the line to A to send
traffic to X. In one vector exchange, the good news is processed.
To see how fast good news propagates, consider the five node (linear) subnet of following
figure, where the delay metric is the number of hops. Suppose A is down initially and all the
other routers know this. In other words, they have all recorded the delay to A as infinity.
A B C D E A B C D E
∞ ∞ ∞ ∞ Initially 1 2 3 4 Initially
7 6 7 6 After 5 exchange
7 8 7 8 After 6 exchange
∞ ∞ ∞ ∞
Many ad hoc solutions to the count to infinity problem have been proposed in the literature,
each one more complicated and less useful than the one before it. The split horizon algorithm
works the same way as distance vector routing, except that the distance to X is not reported on
line that packets for X are sent on (actually, it is reported as infinity). In the initial state of right
figure, for example, C tells D the truth about distance to A but C tells B that its distance to A is
infinite. Similarly, D tells the truth to E but lies to C.
3.2 Algorithm
1. Start
2. By convention, the distance of the node to itself is assigned to zero and when a node is
unreachable the distance is accepted as 999.
3. Accept the input distance matrix from the user (dmin]) that represents the distance
between each node in the network.
4. Store the distance between nodes in a suitable variable.
5. Calculate the minimum distance between two nodes by iterating.
If the distance between two nodes is larger than the calculated alternate available path,
replace the existing distance with the calculated distance.
59. }
60. return 0;
61. }
A A 2
B B 0
C C 1
D C 5
A B 3
B B 1
C C 0
D D 4
A C 7
B C 5
C C 4
D D 0
3.5 Implementation Phase: Compile the Program and note the syntax errors/warning if occurred
during each compilation. Remove those syntax errors/warnings for generation of executable
file.
3.6 Simulation of Errors/Warnings:
3.6.1 Syntax Errors/Warnings:
S. No. Errors/Warnings Reflection of the Errors/Warnings in
Simulated compilation/output
1 Problem Statement
Using TCP/IP sockets, write a client-server program to make client send the file name and the server to
send back the contents of the requested file file name “sample.txt” with the following contents:”HI I AM
AT REVA UNIVERSITY. SEE YOU SOON”. Steps for establishing a TCP socket on the client side are
the following:
The steps involved in establishing a TCP socket on the server side are as follows:
Display suitable error message in case the the file is not present in the server.
3.1 Theory
Several protocols for different problems) Protocol Suites or Protocol Families: TCP/IP. TCP/IP
provides end-to-end connectivity specifying how data should be
A socket is the mechanism that most popular operating systems provide to give programs
access to the network. It allows messages to be sent and received between applications
(unrelated processes) on different networked machines.
The sockets mechanism has been created to be independent of any specific type of network. IP,
however, is by far the most dominant network and the most popular use of sockets.
3.2 Algorithm/Steps
1. Start.
2. Create a socket using socket () system call.
3. Connect the socket to the address of the server using connect () system call.
4. Send the filename of required file using send () system call.
5. Read the contents of the file sent by server by recv () system call.
6. Stop.
1. Start.
2. Create a socket using socket () system call.
3. Bind the socket to an address using bind () system call.
4. Listen to the connection using listen () system call.
5. accept connection using accept()
6. Receive filename and transfer contents of file with client.
7. Stop.
Client Programming
1. #include<stdio.h>
2. #include<sys/types.h>
3. #include<sys/socket.h>
4. #include<netinet/in.h>
5. #include<sys/fcntl.h>
6. #include<stdlib.h>
7. #include<string.h>
8. #include<arpa/inet.h>
14. if(argc<4)
15. {
16. fprintf(stderr,"usage %s serverip filename port",argv[0]);
17. exit(0);
18. }
19. serip=argv[1];
20. portno=atoi(argv[3]);
/*---- Create the socket. The three arguments are: ----*/
/* 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) */
21. sockfd=socket(AF_INET,SOCK_STREAM,0);
22. if(sockfd<0)
23. {
24. perror("\n Error in creating socket.\n");
25. perror("\n Client on line.");
26. }
/*---- Connect the socket to the server using the address struct ----*/
31. if(connect(sockfd,(struct sockaddr *)&seradd,sizeof(seradd))<0)
32. {
33. perror("\n Error in connection setup \n");
34. write(sockfd,argv[2],strlen(argv[2])+1);
35. bzero(buffer,4096);
36. }
37. n=read(sockfd,buffer,4096);
38. if(n<=0)
39. {
40. perror("\n File not found");
41. exit(0);
42. }
Server Programming
1. #include<stdio.h>
2. #include<sys/types.h>
3. #include<sys/socket.h>
4. #include<netinet/in.h>
5. #include<sys/fcntl.h>
6. #include<stdlib.h>
7. int main(int argc,char *argv[])
8. {
9. int fd,sockfd,newsockfd,clilen,portno,n;
10. struct sockaddr_in seradd,cliadd;
11. char buffer[4096];
12. if(argc<2)
13. {
14. fprintf(stderr,"\n\n No port\n");
15. exit(1);
16. }
17. portno=atoi(argv[1]);
/*---- Create the socket. The three arguments are: ----*/
/* 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) */
18.
19. sockfd=socket(AF_INET,SOCK_STREAM,0);
20. if(sockfd<0)
21. {
22. error("\n error opening socket.\n");
23. bzero((char *)&seradd,sizeof(seradd));
/*---- Configure settings of the server address struct ----*/
/* Address family = Internet */
24. seradd.sin_family=AF_INET;
25. seradd.sin_addr.s_addr=(htonl)INADDR_ANY;
/* Set port number, using htons function to use proper byte order */
26. seradd.sin_port=htons(portno);
/*---- Bind the address struct to the socket ----*/
27. if(bind(sockfd,(struct sockaddr *)&seradd,sizeof(seradd))<0)
28. {
29. perror("\n IP addr cannt bind");
/*---- Listen on the socket, with 5 max connection requests queued ----*/
30. listen(sockfd,5);
31. clilen=sizeof(cliadd);
32. printf("\n Server waiting for clint request");
33. while(1)
34. {
/*---- Accept call creates a new socket for the incoming connection ----*/
35. newsockfd=accept(sockfd,(struct sockaddr *)&cliadd,&clilen);
36. if(newsockfd<0)
37. perror("\n Server cannot accept connection request ");
38. bzero(buffer,4096);
39. read(newsockfd,buffer,4096);
40. fd=open(buffer,O_RDONLY);
41. if(fd<0)
42. {
43. perror("\n File doesnot exist");
44. while(1)
45. {
46. n=read(fd,buffer,4096);
47. if(n<=0)
48. exit(0);
49. write(newsockfd,buffer,n);
50. printf("\n File transfer completet\n");
51. }
52. close(fd);
53. close(newsockfd);
54. }
55. return 0;
$ cc prog4s.c
$ ./a.out 7000
SERVER:hsr.c
SERVER:hsr.c found!
int main()
printf("\nascii of a %d",'h');
return 1;
$ cc prog4c.c
client online
server online
hsr.c
int main()
printf("\nascii of a %d",'h');
return 1;
1 Problem Statement
There is a single Server process which runs continuously in background, even though if
there is no client to interact with it. Client processes runs in foreground and interacts with the
server process. Both the client and server processes run on the same machine.
The Client process accepts a command (a shell command) from the user and send's it to the
Server via a FIFO which is a public channel between Client and Server for processing. Assume
this FIFO name as PUBLIC fifo since its existence is known to all clients and the server. Once
the command is received, the Server executes it using the popen–pclose sequence (which
generates an unnamed pipe in the Server process). After execution Server process returns the
output of the command executed to the client over a FIFO which is a private channel between the
client and server. Let us name this FIFO as PRIVATE fifo. The Client, upon receipt, displays the
output on the screen.
• Create a unique name for the PRIVATE fifo and invoke it.
• Open the PUBLIC fifo in write mode.
• Prompt for command from user.
• Write command to PUBLIC fifo for Server to process.
• Open PRIVATE fifo in read mode to read the contents from Server.
• Generate a PUBLIC fifo and open it in both read and write mode. Wait for the
message from a Client process.
• Read the message from PUBLIC fifo.
• Open the Client's PRIVATE fifo in write mode.
• Execute the command from Client process using popen.
• Write the output into Client's PRIVATE fifo.
NOTE: Each and every Client process should have its own unique PRIVATE fifo to
receive information from Server.
3.2 Algorithm/Steps
1. Start.
1. Start.
2. Create a well known FIFO using mkfifo()
3. Open FIFO in read only mode to accept request from clients.
4. When client opens the other end of FIFO in write only mode, then read the contents and
store it in buffer.
5. Create another FIFO in write mode to send replies.
6. Open the requested file by the client and write the contents into the client specified
FIFO and terminate the connection.
7. Stop.
Client Programming
1. #include<stdio.h>
2. #include<stdlib.h>
3. #include<string.h>
4. #include<fcntl.h>
5. #include<sys/types.h>
6. #include<sys/stat.h>
7. #include<unistd.h>
8. #define FIFO1 "fifo1"
9. #define FIFO2 "fifo2"
10. int main()
11. {
12. char p[100],c[5000];
13. int num,fd,fd2,f1;
14. mknod(FIFO1,S_IFIFO|0666,0); // creating a named pipe
15. mknod(FIFO2,S_IFIFO|0666,0);
16. printf("\n Client online...\n");
/*
* open them - one for reading and one
* for writing.
*/
17. fd=open(FIFO1,O_WRONLY);
18. fd2=open(FIFO2,O_RDONLY);
19. printf("Client : Enter the filename . \n\n");
20. scanf("%s",p);
21. num=write(fd,p,strlen(p));
22. if(num==-1)
23. {
24. perror("\nWrite Error.\n");
25. return 1;
26. }
27. else
28. {
29. printf("\n Waiting for reply\n");
30. if((num=read(fd2,c,5000))==-1)
33. {
34. c[num]=0;
35. printf("%s",c);
36. }
37. }
38. return 1;
39. }
Server Programming
1. #include<stdio.h>
2. #include<stdlib.h>
3. #include<string.h>
4. #include<fcntl.h>
5. #include<sys/types.h>
6. #include<sys/stat.h>
7. #include<unistd.h>
8. #define FIFO1 "fifo1"
9. #define FIFO2 "fifo2"
10.
11. int main()
12. {
13. char p[100],c[5000];
School of Computing and Information Technology Page 65
Networks Lab REVA University
18. fd=open(FIFO1,O_RDONLY);
19. fd2=open(FIFO2,O_WRONLY);
20. printf("Server online\n waiting for client \n\n");
21. if((num=read(fd,p,100))==-1)
22. perror("\n Read Error ");
23. else
24. {
25. p[num]='\0';
26. printf("\n File is %s .\n",p);
27. if((f1=open(p,O_RDONLY))<0)
28. {
29. write(fd2,"File not found",15);
30. return 1;
31. }
32. else
33. {
34. stdin=fdopen(f1,"r");
35. num=0;
36. while((ch=fgetc(stdin))!=EOF)
37. c[num++]=ch;
38. c[num]=0;
39. printf(" Server: Transfering the contents of :%s ",p);
40. if(num=write(fd2,c,strlen(c))==-1)
41. printf("\n Error in writting to FIFO\n");
42. Else
43. printf("\n File transfer completed \n");
44. }
45. }
46. }
47. }
OUTPUT: AT TERMINAL 1:
$ cc prog5s.c
$ ./a.out
server:hsr.c found
int main()
printf("\nascii of a %d",'h');
return 1;
AT TERMINAL 2:
$ cc prog5c.c
$ ./a.out
SERVER ONLINE !
hsr.c
#include<stdio.h>
int main()
printf("\nascii of a %d",'h');
return 1;
1 Problem Statement
Choose the two prime numbers, p=17 and q=11. Write a program for public key encryption
system using RSA algorithm to encrypt and decrypt the message. For a message M=”he12ll34o“,
show the encryption and decryption.
Cryptography has a long and colorful history. The message to be encrypted, known as the
plaintext, are transformed by a function that is parameterized by a key. The output of the
encryption process, known as the cipher text, is then transmitted, often by messenger or radio.
The enemy, or intruder, hears and accurately copies down the complete cipher text. However,
unlike the intended recipient, he does not know the decryption key and so cannot decrypt the
cipher text easily. The art of breaking ciphers is called cryptanalysis the art of devising ciphers
(cryptography) and breaking them (cryptanalysis) is collectively known as cryptology.
There are several ways of classifying cryptographic algorithms. They are generally categorized
based on the number of keys that are employed for encryption and decryption, and further defined
by their application and use. The three types of algorithms are as follows:
1. Secret Key Cryptography (SKC): Uses a single key for both encryption and decryption. It is
also known as symmetric cryptography.
2. Public Key Cryptography (PKC): Uses one key for encryption and another for decryption. It
is also known as asymmetric cryptography.
3. Hash Functions: Uses a mathematical transformation to irreversibly "encrypt" information
Public-key cryptography has been said to be the most significant new development in
cryptography. Generic PKC employs two keys that are mathematically related although
knowledge of one key does not allow someone to easily determine the other key. One key is used
to encrypt the plaintext and the other key is used to decrypt the cipher text. The important point
here is that it does not matter which key is applied first, but that both keys are required for the
process to work. Because pair of keys is required, this approach is also called asymmetric
cryptography.
In PKC, one of the keys is designated the public key and may be advertised as widely as the
owner wants. The other key is designated the private key and is never revealed to another party.
It is straight forward to send messages under this scheme.
The RSA algorithm is named after Ron Rivest, Adi Shamir and Len Adleman, who invented
it in 1977. The RSA algorithm can be used for both public key encryption and digital signatures.
Its security is based on the difficulty of factoring large integers.
3.2 Algorithm
1. Generate two large random primes, P and Q, of approximately equal size.
2. Compute N = P x Q
3. Compute Z = (P-1) x (Q-1).
4. Choose an integer E, 1 < E < Z, such that GCD (E, Z) = 1
5. Compute the secret exponent D, 1 < D < Z, such that E x D ≡ 1 (mod Z)
6. The public key is (N, E) and the private key is (N, D).
The message is encrypted using public key and decrypted using private key.
Example:1
2. N = P x Q = 11 x 3 = 33
Z = (P-1) x (Q-1) = 10 x 2 = 20
= 73 mod 33
= 343 mod 33
= 13.
= 137 mod 33
= 7.
Note that we don't have to calculate the full value of 13 to the power 7 here. We can
make use of the fact that a = bc mod n = (b mod n).(c mod n) mod n so we can break
down a potentially large number into its components and combine the results of easier,
smaller calculations to calculate the final value
Example:2
1. Choose p = 3 and q = 11
2. Compute n = p * q = 3 * 11 = 33
3. Compute φ(n) = (p – 1) * (q – 1) = 2 * 10 = 20
4. Choose e such that 1 < e < φ(n) and e and n are coprime. Let e = 7
5. Compute a value for d such that (d * e) % φ(n) = 1. One solution is d = 3 [(3 * 7) %
20 = 1]
6. Public key is (e, n) => (7, 33)
7. Private key is (d, n) => (3, 33)
8. The encryption of m = 2 is c = 27 % 33 = 29
9. The decryption of c = 29 is m = 293 % 33 = 2
25. phi=(p-1)*(q-1);
26. for(i=2;i<phi;i++)
27. if(gcd(i,phi)==1)
28. break;
29. e=i;
30. if((e*i-1)%phi==0)
31. break;
32. d=i;
33. for(i=0;i<strlen(msg);i++)
34. nummes[i]=msg[i]-96;
35. nofelem=strlen(msg);
36. for(i=0;i<nofelem;i++)
37. {
38. encrypt[i]=1;
39. for(j=0;j<e;j++)
40. encrypt[i]=(encrypt[i]*nummes[i])%n;
41. }
42. printf("\n Encrypted Message: \n");
43. for(i=0;i<nofelem;i++)
44. printf("%ld",encrypt[i]);
45. for(i=0;i<nofelem;i++)
46. {
47. decrypt[i]=1;
48. for(j=0;j<d;j++)
49. decrypt[i]=(decrypt[i]*encrypt[i])%n;
50. }
51. printf("\n Decrypted msg:\n");
52. for(i=0;i<nofelem;i++)
53. printf("%c",(char)(decrypt[i]+96));
54. return 0;
55. }
This algorithm has been implemented for lower case letters only
Encrypted Message:
138125-38-964545-56-999
Decrypted msg:
he12ll34o
3.5 Implementation Phase: Compile the Program and note the syntax errors/warning if
occurred during each compilation. Remove those syntax errors/warnings for generation
of executable file.
3.5 Simulation of Errors/Warnings:
3.5.1 Syntax Errors/Warnings:
S. No. Errors/Warnings Reflection of the Errors/Warnings in
Simulated compilation/output
compilation/output
1 Problem Statement
Examine node transmitting/receiving packets to/from other nodes. Using a random function; vary
the packet size, considering the following cases.
• Monitor network traffic by varying the Output rate and Bucket size.
3.1 Theory
The congesting control algorithms are basically divided into two groups: open loop and closed
loop. Open loop solutions attempt to solve the problem by good design, in essence, to make sure
it does not occur in the first place. Once the system is up and running, midcourse corrections are
not made. Open loop algorithms are further divided into ones that act at source versus ones that
act at the destination.
In contrast, closed loop solutions are based on the concept of a feedback loop if there is any
congestion. Closed loop algorithms are also divided into two sub categories: explicit feedback
and implicit feedback. In explicit feedback algorithms, packets are sent back from the point of
congestion to warn the source. In implicit algorithm, the source deduces the existence of
congestion by making local observation, such as the time needed for acknowledgment to come
back.
The presence of congestion means that the load is (temporarily) greater than the resources (in
part of the system) can handle. For subnets that use virtual circuits internally, these methods can
be used at the network layer.
Another open loop method to help manage congestion is forcing the packet to be transmitted
at a more predictable rate. This approach to congestion management is widely used in ATM
networks and is called traffic shaping.
The other method is the leaky bucket algorithm. Each host is connected to the network by an
interface containing a leaky bucket, that is, a finite internal queue. If a packet arrives at the queue
when it is full, the packet is discarded. In other words, if one or more process are already queued,
the new packet is unceremoniously discarded. This arrangement can be built into the hardware
interface or simulate d by the host operating system. In fact it is nothing other than a single server
queuing system with constant service time.
The host is allowed to put one packet per clock tick onto the network. This mechanism turns
an uneven flow of packet from the user process inside the host into an even flow of packet onto
the network, smoothing out bursts and greatly reducing the chances of congestion.
3.2 Algorithm
1. Start
2. Set the bucket size or the buffer size.
3. Set the output rate.
4. Transmit the packets such that there is no overflow.
5. Repeat the process of transmission until all packets are transmitted. (Reject packets
where its size is greater than the bucket size)
6. Stop
1. #include<stdio.h>
2. #include<stdlib.h>
3. int trand(int a)
4. {
5. int rn;
6. rn=random()%10;
7. rn=rn%a;
8. if(rn==0)
9. rn=1;
School of Computing and Information Technology Page 77
Networks Lab REVA University
10. return(rn);
11. }
12. int main()
13. {
14. int i,packet[5],psz,bsz,pszrn=0,clk,ptime,premain,orate,flag=0;
15. for(i=0;i<5;i++)
16. packet[i]=trand(6)*10;
17. printf("\n enter the o/p rate");
18. scanf("%d",&orate);
19. printf("\n enter the bucket size");
20. scanf("%d",&bsz);
21. for(i=0;i<5;i++)
22. {
23. if((packet[i]+pszrn)>bsz)
24. printf("\n incoming packet size %d is greater than bucket
size_reject”,packet[i]);
25. else
26. {
27. for(;;)
28. {
29. premain=4-i;
30. psz=packet[i];
31. pszrn+=psz;
32. printf("\nincoming packet size is %d",psz);
33. printf("\n no of packets waiting for transmission=%d",pszrn);
34. ptime=trand(4)*10;
35. printf("\n next packet will come at %d",ptime);
36. for(clk=0;clk<=ptime;clk++)
37. {
38. printf("\ntime left=%d",ptime-clk);
39. sleep(1);
40. if(pszrn)
41. {
42. if(pszrn==0)
43. printf("\n bucket is empty");
44. else
45. {
46. if(pszrn>=orate)
47. printf("%d bytes are transmitted",orate);
48. else
49. printf("\n %d bytes transmitted ",pszrn);
50. }
51. if(pszrn<=orate)
52. pszrn=0;
53. else
54. pszrn-=orate;
55. printf("\n bytes remaining %d",pszrn);
56. }
School of Computing and Information Technology Page 78
Networks Lab REVA University
57. else
58. printf("\n bytes remaining %d",pszrn);
59. }
60. if(pszrn!=0)
61. flag=1;
62. break;
63. }
64. }
65. }
66. printf("\n\n");
67. return 0;
68. }
RUN 1:
$ cc prog8.c
$ ./a.out
enter the o/p rate10
enter the bucket size5
RUN 2:
bytes remaining 0
time left =6
bytes remaining 0
time left =5
bytes remaining 0
time left =4
bytes remaining 0
time left =3
bytes remaining 0
time left =2
bytes remaining 0
time left =1
bytes remaining 0
time left =0
bytes remaining 0
incoming packet size is 10
no.of packets waiting for transmission= 10
next packet will come at 20
time left =205 bytes are transmitted
bytes remaining 5
time left =195 bytes are transmitted
bytes remaining 0
time left =18
bytes remaining 0
time left =17
bytes remaining 0
time left =16
bytes remaining 0
time left =15
bytes remaining 0
time left =14
bytes remaining 0
time left =13
bytes remaining 0
time left =12
bytes remaining 0
time left =11
bytes remaining 0
time left =10
bytes remaining 0
time left =9
bytes remaining 0
time left =8
bytes remaining 0
time left =7
bytes remaining 0
time left =6
bytes remaining 0
time left =5
bytes remaining 0
time left =4
bytes remaining 0
time left =3
bytes remaining 0
time left =2
bytes remaining 0
time left =1
bytes remaining 0
time left =0
bytes remaining 0
incoming packet size 50 is greater than bucket size_reject
incoming packet size 30 is greater than bucket size_reject
3.5 Implementation Phase: Compile the Program and note the syntax errors/warning if
occurred during each compilation. Remove those syntax errors/warnings for generation
of executable file.
3.5 Simulation of Errors/Warnings:
3.5.1 Syntax Errors/Warnings:
S. No. Errors/Warnings Reflection of the Errors/Warnings in
Simulated compilation/output
1. Generate a 1-bit self correcting Hamming code for a given input data
2. Implement DIJKSTRAs algorithm for a maximum of ten nodes in a network topology.
3. Design TCP iterative Client and Server application to reverse the given input sentence
4. Design a TCP concurrent Server to convert a given text into upper case using multiplexing
system call “select”.
5. Design a TCP concurrent Server to echo given set of sentences using Poll functions.
6. Implement the following forms of IPC. a) Pipes b) FIFO