0% found this document useful (0 votes)
20 views58 pages

Networks Lab Manual

The document is a lab manual for the Networks Laboratory course at R.M.K. Engineering College, detailing objectives, exercises, and expected outcomes for students in the Computer Science and Engineering program. It outlines various networking commands and concepts, including troubleshooting, error detection, and network programming. The manual aims to equip students with practical skills in network configuration and protocol simulation using different operating systems.

Uploaded by

kmn.cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views58 pages

Networks Lab Manual

The document is a lab manual for the Networks Laboratory course at R.M.K. Engineering College, detailing objectives, exercises, and expected outcomes for students in the Computer Science and Engineering program. It outlines various networking commands and concepts, including troubleshooting, error detection, and network programming. The manual aims to equip students with practical skills in network configuration and protocol simulation using different operating systems.

Uploaded by

kmn.cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

R.M.K.

ENGINEERING COLLEGE
(An Autonomous Institution)
R.S.M. Nagar, Kavaraipettai -601 206

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

20CS501
NETWORKS LABORATORY (LAB INTEGRATED)
LAB MANUAL

Regulation 2022

2024-2025 ODD SEMESTER

B.E. COMPUTER SCIENCE AND ENGINEERING

Prepared by Approved by Approved by

[Link] Raju, Dr.T. Sethukarasi Dr. K. A. Mohamed Junaid


Associate Professor/CSE
Professor & Head/CSE Principal

[Link],
Associate Professor/CSE
R.M.K. ENGINEERING COLLEGE
(An Autonomous Institution)
R.S.M. Nagar, Kavaraipettai -601 206

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


Vision
To evolve as a Centre of Academic Excellence and Advanced Research in the field of Computer Science and Engineering and
develop professionals who can meet with the societal issues.
Mission
M1: To provide a good environment with latest technological infrastructure facilities, teaching-learning ambience and
interaction with industry in the area of Computer Science and Engineering.
M2: To develop graduates of world class technical competence, entrepreneurial skill and to encourage for higher education in
the area of Computer Science and Engineering, with necessary skills to solve real world problems.
M3: To inculcate graduates with high social responsibility, right attitude, discipline and an inclination towards offering their
professional expertise in serving the society.
Programme Educational Objectives
PEO 1. Apply the principles and practices of Computer Science and Engineering encompassing Mathematics, Science and Basic
Engineering and to employ the modern engineering tools effectively in their profession with their world class technical
competence.
PEO 2. Possess expertise to function as members of multi-disciplinary teams and implement software technology solutions for
real world problems of international standards and will be achievers at global level.
PEO 3. Excel in the field of software industry or in higher studies endowed with the spirit of innovation and entrepreneurship by
evolving their professional knowledge on a lifelong basis.
PEO 4. Practice the profession with ethics, integrity, leadership and social responsibility with a good insight of the changing
societal needs for the benefit of humanity.
Program Specific Outcome
PSO 1: Apply knowledge acquired from the basic hardware design and software core areas of Computer Science and
Engineering for solving real world problems.
PSO 2: Apply cutting edge technologies and strong analytical skills to develop quality software in scientific and business
applications for the betterment of society and Industry.
PSO 3: Employ modern computer languages, environments and platforms in creating innovative career paths to be an
entrepreneur and with a zeal for higher studies.
R.M.K. ENGINEERING COLLEGE
(An Autonomous Institution)
R.S.M. Nagar, Kavaraipettai -601 206

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


20CS511 NETWORKS LABORATORY
OBJECTIVES:
● To explore various network commands in different Operating Systems and troubleshoot it.
● To implement the error detection & correction and flow control mechanisms in network data communication.
● To implement functionalities using raw sockets.
● To understand and implement the network programming concepts using APIs.
To simulate various network protocols and analyze their behaviour in the network
LIST OF EXERCISES:
1. Practice different network commands available in Windows and Linux Operating
Systems and troubleshoot the network.
2. Network configuration commands using Linux.
3. Error detection and correction mechanisms.
4. Flow control mechanisms.
5. Multi-client chatting in TCP and UDP using Socket programming ( C / Java)
6. Implementation of HTTP, Web Caching, FTP using socket programming.
7. Develop a DNS client server to resolve the given host name or IP address.
8. Simulation of unicast routing protocols.
9. Observing Packets across the network and Performance Analysis of various Routing
protocols.
10. Simulation of Transport layer Protocols and analysis of congestion control techniques in
the network.

OUTCOMES:
At the end of this course, the students will be able to:
CO1: Understand the various networking commands in different OS and troubleshoot it.
CO2: Perform error detection & correction and flow control mechanisms in network programming.
CO3: Program with raw sockets for network protocol implementation.
CO4: Understand the usage of various network programming APIs and application layer protocols.
CO5: Simulate various network protocols and analyze their behaviour in the network
[Link] Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute.
Capture ping and traceroute PDUs using a network protocol analyzer and examine.

AIM:

To Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute ping.

PRE LAB DISCUSSION:

Tcpdump:
The tcpdump utility allows you to capture packets that flow within your network to assist in
network troubleshooting. The following are several examples of using tcpdump with different options.
Traffic is captured based on a specified filter.
Netstat
Netstat is a common command line TCP/IP networking available in most versions of
Windows, Linux, UNIX and other operating systems.
Netstat provides information and statistics about protocols in use and current TCP/IP network
connections.
ipconfig
ipconfig is a console application designed to run from the Windows command prompt. This
utility allows you to get the IP address information of a Windows computer.
From the command prompt, type ipconfig to run the utility with default options. The output of the
default command contains the IP address, network mask, and gateway for all physical and virtual
network adapter.
nslookup
The nslookup (which stands for name server lookup) command is a network utility program used
to obtain information about internet servers. It finds name server information for domains by querying
the Domain Name System.
Trace route:
Traceroute is a network diagnostic tool used to track the pathway taken by a packet on an IP network
from source to destination. Traceroute also records the time taken for each hop the packet makes during
its route to the destination

Commands:
Tcpdump:
Display traffic between 2 hosts:
To display all traffic between two hosts (represented by variables host1 and host2): # tcpdump
host host1 and host2
Display traffic from a source or destination host only:
To display traffic from only a source (src) or destination (dst) host:
# tcpdump src host
# tcpdump dst host
Display traffic for a specific protocol
Provide the protocol as an argument to display only traffic for a specific protocol, for example tcp,
udp, icmp, arp
# tcpdump protocol
For example to display traffic only for the tcp traffic :
# tcpdump tcp
Filtering based on source or destination port
To filter based on a source or destination port:
# tcpdump src port ftp
# tcpdump dst port http

Netstat
Netstat is a common command line TCP/IP networking available in most versions of
Windows, Linux, UNIX and other operating systems.
Netstat provides information and statistics about protocols in use and current TCP/IP network
connections. The Windows help screen (analogous to a Linux or UNIX for netstat reads as follows:
displays protocol statistics and current TCP/IP network connections.

#netstat

ipconfig
In Windows, ipconfig is a console application designed to run from the Windows command
prompt. This utility allows you to get the IP address information of a Windows computer.
Using ipconfig
From the command prompt, type ipconfig to run the utility with default options. The output of the default
command contains the IP address, network mask, and gateway for all physical and virtual network
adapter.

#ipconfig
nslookup
The nslookup (which stands for name server lookup) command is a network utility program used
to obtain information about internet servers. It finds name server information for domains by querying
the Domain Name System.

The nslookup command is a powerful tool for diagnosing DNS problems. You know you're
experiencing a DNS problem when you can access a resource by specifying its IP address but not its
DNS name.

#nslookup

Trace route:

Traceroute uses Internet Control Message Protocol (ICMP) echo packets with variable time to live (TTL)
values. The response time of each hop is calculated. To guarantee accuracy, each hop is queried multiple
times (usually three times) to better measure the response of that particular hop.
Traceroute is a network diagnostic tool used to track the pathway taken by a packet on an IP network
from source to destination. Traceroute also records the time taken for each hop the packet makes during
its route to the destination. Traceroute uses Internet Control Message Protocol (ICMP) echo packets
with variable time to live (TTL) [Link] response time of each hop is calculated. To guarantee
accuracy, each hop is queried multiple times (usually three times) to better measure the response of that
particular hop. Traceroute sends packets with TTL values that gradually increase from packet to packet,
starting with TTL value of one. Routers decrement TTL values of packets by one when routing and
discard packets whose TTL value has reached zero, returning the ICMP error message ICMP Time
Exceeded.

For the first set of packets, the first router receives the packet, decrements the TTL value and
drops the packet because it then has TTL value zero. The router sends an ICMP Time Exceeded message
back to the source. The next set of packets are given a TTL value of two, so the first router forwards the
packets, but the second router drops them and replies with ICMP Time Exceeded.
Proceeding in this way, traceroute uses the returned ICMP Time Exceeded messages to build a list of
routers that packets traverse, until the destination is reached and returns an ICMP Echo Reply
message.

With the tracert command shown above, we're asking tracert to show us the path from the local
computer all the way to the network device with the hostname
[Link].

#tracert [Link]

2. Ping:

The ping command sends an echo request to a host available on the network. Using this command,
you can check if your remote host is responding well or not. Tracking and isolating hardware and
software problems. Determining the status of the network and various foreign hosts. The ping command
is usually used as a simple way to verify that a computer can communicate over the networkwith another
computer or network device. The ping command operates by sending Internet Control Message Protocol
(ICMP) Echo Request messages to the destination computer and waiting for a response

# ping172.16.6.2
RESULT:
Thus the various networks commands like tcpdump, netstat, ifconfig,
nslookup and traceroute ping are executed successfully.
[Link] Learn to use Network configuration commands using Linux.

AIM:

To Learn to use Network configuration commands using Linux.

[Link] Command

ifconfig (interface configurator) command is used to initialize an interface, assign IP Address to


interface and enable or disable interface on demand.
With this command, you can view IP Address and Hardware / MAC address assign to interface
and also MTU (Maximum transmission unit) size.

# ifconfig

eth0 Link encap:Ethernet HWaddr [Link]


inet addr:[Link] Bcast:[Link]
Mask:[Link]
inet6 addr: fe80::20c:29ff:fe28:fd4c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6093 errors:0 dropped:0 overruns:0
frame:0
TX packets:4824 errors:0 dropped:0 overruns:0
carrier:0
collisions:0 txqueuelen:1000
RX bytes:6125302 (5.8 MiB) TX bytes:536966 (524.3
KiB)
Interrupt:18 Base address:0x2000

lo Link encap:Local Loopback


inet addr:[Link] Mask:[Link]
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0
carrier:0
collisions:0 txqueuelen:0
RX bytes:480 (480.0 b) TX bytes:480 (480.0 b)

1. Ping Command

Ping (Packet INternet Groper) command is the best way to test connectivity between
two nodes. Whether it is Local Area Network (LAN) or Wide AreaNetwork (WAN).

Ping uses ICMP (Internet Control Message Protocol) to communicate to other devices.
You can ping hostname or ip address using the below commands.
# ping [Link]

PING [Link] ([Link]) 56(84) bytes of data.


64 bytes from [Link]: icmp_seq=1 ttl=44 time=203 ms
64 bytes from [Link]: icmp_seq=2 ttl=44 time=201 ms
64 bytes from [Link]: icmp_seq=3 ttl=44 time=201 ms

OR

# ping [Link]

PING [Link] ([Link]) 56(84) bytes of data.


64 bytes from [Link]: icmp_seq=1 ttl=47 time=284 ms
64 bytes from [Link]: icmp_seq=2 ttl=47 time=287 ms
64 bytes from [Link]: icmp_seq=3 ttl=47 time=285 ms

2. Traceroute Command

traceroute is a network troubleshooting utility that shows the number of hops taken to
reach a destination also determines packets traveling path. Below we are tracing the
route to the global DNS server IP Address and able to reach destination also shows the
path of that packet is traveling.

# traceroute [Link]

traceroute to [Link] ([Link]), 30 hops max, 60 byte


packets
1 [Link] ([Link]) 0.217 ms 0.624 ms 0.133
ms
2 [Link].[Link] ([Link]) 2.343 ms
1.910 ms 1.799 ms
3 [Link] ([Link]) 4.334 ms
4.001 ms 5.619 ms
4 [Link] ([Link]) 5.386 ms 6.490 ms 6.224 ms
5 [Link] ([Link]) 7.798
ms 7.614 ms 7.378 ms
6 [Link].[Link]
([Link]) 10.852 ms 5.389 ms 4.322 ms
7 [Link] ([Link])
5.836 ms 5.590 ms 5.503 ms
8 [Link] ([Link])
216.909 ms 198.864 ms 201.737 ms
9 [Link] ([Link])
203.305 ms 203.141 ms 202.888 ms
10 [Link] ([Link])
200.552 ms 202.463 ms 202.222 ms
11 [Link] ([Link])
205.446 ms 215.885 ms 202.867 ms
12 [Link] ([Link])
202.675 ms 201.540 ms 203.972 ms
13 [Link] ([Link])
203.732 ms 203.496 ms 202.951 ms
14 [Link] ([Link])
203.858 ms 203.373 ms 203.208 ms
15 [Link] ([Link]) 201.093 ms [Link]
([Link]) 206.597 ms [Link] ([Link])
204.178 ms
16 [Link] ([Link]) 205.960 ms
205.740 ms 205.487 ms
17 [Link] ([Link]) 203.867
ms [Link] ([Link]) 202.850
ms [Link] ([Link]) 202.351
ms
18 [Link] ([Link]) 201.771
ms 201.185 ms 201.120 ms
19 [Link] ([Link]) 202.407
ms 201.479 ms [Link]
([Link]) 208.145 ms
20 [Link] ([Link]) 200.572
ms [Link] ([Link]) 200.402
ms [Link] ([Link]) 203.573
ms
21 [Link] ([Link]) 199.725 ms 199.190 ms
202.488 ms

3. Netstat Command

Netstat (Network Statistic) command displays connection info, routing table


information, etc. To display routing table information use option as -r.

# netstat -r

Kernel IP routing table


Destination Gateway Genmask Flags MSS
Window irtt Iface
[Link] * [Link] U 0
0 0 eth0
* [Link] U 0
0 0 eth0
default [Link] [Link] UG 0
0 0 eth0
4. Dig Command

Dig (domain information groper) query DNS related information


like A Record, CNAME, MX Record, etc. This command is mainly used to
troubleshoot DNS-related queries.

# dig [Link]; <<>> DiG 9.8.2rc1-RedHat-9.8.2-


0.10.rc1.el6 <<>> [Link]
;; global options: +cmd
;; Got answer:
;; ->>HEADER<

5. Nslookup Command

nslookup command is also used to find out DNS-related queries. The following
examples show A Record (IP Address) of [Link].

# nslookup [Link]
Server: [Link]
Address: 4.2 2.2#53

Non-authoritative answer:
[Link] canonical name = [Link].
Name: [Link]
Address: [Link]

6. Route Command

route command also shows and manipulates the ip routing table. To see the default
routing table in Linux, type the following command.

# route

Kernel IP routing table


Destination Gateway Genmask Flags Metric
Ref Use Iface
[Link] * [Link] U 0
0 0 eth0
link-local * [Link] U 1002
0 0 eth0
default [Link] [Link] UG 0
0 0 eth0

7. Host Command

host command to find a name to IP or IP to name in IPv4 or IPv6 and also


query DNS records.

# host [Link]

[Link] has address [Link]


[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has address [Link]
[Link] has IPv6 address [Link]

8. Arp Command

ARP (Address Resolution Protocol) is useful to view/add the contents of the


kernel’s ARP tables. To see the default table use the command as.

# arp -e

Address HWtype HWaddress Flags


Mask Iface
[Link] ether [Link] C
eth0

9. Ethtool Command

ethtool is a replacement for mii-tool. It is to view, setting speed and duplex of


your Network Interface Card (NIC). You can set duplex permanently
in /etc/sysconfig/network-scripts/ifcfg-eth0 with ETHTOOL_OPTS variable.

# ethtool eth0

Settings for eth0:


Current message level: 0x00000007 (7)
Link detected: yes
10. Iwconfig Command

iwconfig command in Linux is used to configure a wireless network interface. You


can see and set the basic Wi-Fi details like SSID channel and encryption. You can refer
man page of iwconfig to know more.

# iwconfig [interface]

11. Hostname Command

The hostname is to identify in a network. Execute the hostname command to see the
hostname of your box. You can set hostname permanently in /etc/sysconfig/network.
Need to reboot box once set a proper hostname.

# hostname

[Link]

RESULT:
Thus the various networks configuration commands are executed successfully.
EX.NO3 Simulation of Error CorrectionCode(CRC)

AIM

To Simulation of Error Correction Code using Java.

PROCEDURE

Cyclicredundancycheck(CRC)

• Unlike checksum scheme, which is based on addition, CRC is based on


binarydivision.
• In CRC, a sequence of redundant bits, called cyclic redundancy check bits,
areappended to the end of data unit so that the resulting data unit becomes
exactlydivisibleby asecond, predeterminedbinarynumber.
• At the destination, the incoming data unit is divided by the same number. If
atthis step there is no remainder, the data unit is assumed to be correct and
istherefore accepted.
• A remainder indicates that the data unit has been damaged in transit and
thereforemust berejected.
Example:

ALGORITHM :

1. Open the editor and type the program for error detection
2. Get the input in the form of bits.
3. Append the redundancy bits.
4. Divide the appended data using a divisor polynomial.
5. The resulting data should be transmitted to the receiver.
6. At the receiver the received data is entered.
7. The same process is repeated at the receiver.
8. If the remainder is zero there is no error otherwise there is some error in the received bits
9. Run the program.
PSEUDOCODE

Since a CRC is fundamentally bit-oriented, the order that you assign to bits in bytes matters. You can do it
big-endian:

function crc(bit array bitString[1..len], int polynomial) {


shiftRegister := initial value // commonly all 0 bits or all 1 bits
for i from 1 to len {
if most significant bit of shiftRegister xor bitString[i] = 1 {
shiftRegister := (shiftRegister left shift 1) xor polynomial
} else {
shiftRegister := (shiftRegister left shift 1)
}
}
return shiftRegister
}

Or you can do it little-endian. This turns out to be more convenient in practice, and matches the order of bits
sent over RS-232 (so the CRC burst error detection property holds):

function crc(bit array bitString[1..len], int polynomial) {


shiftRegister := initial value // commonly all 0 bits or all 1 bits
for i from 1 to len {
if (least significant bit of shiftRegister) xor bitString[i] = 1 {
shiftRegister := (shiftRegister right shift 1) xor polynomial
} else {
shiftRegister := (shiftRegister right shift 1)
}
}
return shiftRegister
}

There are two convenient optimizations:

• The bit bitString[i] can be simply XORed into the shiftRegister before the test. It gets shifted away in
the next step anyway.
• The above can be thought of as looking up entry (shiftRegister & 1) in a two-entry table whose entries
are 0 and polynomial You can do multiple bits at the same time with a larger table.
RESULT:
Thus the error detection and error correction is implemented successfully
Flow control mechanisms

[Link](a) Implementation of Sliding Window Protocol

AIM:

To write a java program to perform sliding window protocol

ALGORITHM:

1. Start theprogram.
2. Get the frame size from the user
3. create the frame based on the user request. [Link] send frames toserver
from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal
to client.
6. Stop the program

PSEUDOCODE

begin
frame s, r; //s and r denotes frames to be sent and received
SeqNo = 0; // Initialise sequence number of outbound frame
RSeqNo = 0; // Initialise sequence number of expected frame
while (true) //check repeatedly
do
Wait_For_Event(); //wait for availability of packet
if ( Event(Request_For_Transfer) AND canSend) then
Get_Data_From_Network_Layer();
s = Make_Frame(SeqNo);
Store_Copy_Frame(s);
Start_Timer(s);
SeqNo = SeqNo + 1;
end if;
Wait_For_Event(); //wait for arrival of frame
if ( Event(Frame_Arrival) then
r = Receive_Frame_From_Physical_Layer();
if ( [Link] = RSeqNo ) then
Extract_Data(r);
Deliver_Data_To_Network_Layer(r);
Stop_Timer(r);
RSeqNo = RSeqNo + 1;
end if
end if
[Link] = [Link];
Send_Frame_To_Physical_Layer(s);

Start_Timer(s);
SeqNo = SeqNo + 1;
end while
end
OUTPUT:
//SENDEROUTPUT
Enter the no. of frames :
4Enter 4 Messages to
besend

hiiihow
ru
i amfine
howisevryone
Acknowledgmentreceivedfor4frames

Doyouwantstosendsomemore frames : no

//RECEIVEROUTPUT
ThereceivedFrame0is:hiiiTherece
ived Frame 1is:howru
ThereceivedFrame2is:iamfine
Thereceived Frame 3is:howiseveryone
[Link](b) Implementation of Stop and Wait Protocol

AIM

To write a java program to perform sliding window protocol

ALGORITHM:

1. Start the program.


2. Get the frame size from the user
3. To create the frame based on the user request.
4. To send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send
NACK signal to client.
6. Stop the program

PSEUDOCODE

Sender Site Algorithm of Simplex Stop and Wait Protocol


SeqNo = 0; // Initialise sequence number of outbound frame
canSend = True; //Allow the first frame to be sent
while (true) //check repeatedly
do
Wait_For_Event(); //wait for availability of packet
if ( Event(Request_For_Transfer) AND canSend) then
Get_Data_From_Network_Layer();
frame = Make_Frame(SeqNo);
Store_Copy_Frame([Link]);
Send_Frame_To_Physical_Layer([Link]);
Start_Timer([Link]);
SeqNo = SeqNo + 1;
canSend = False;
else if ( Event(Acknowledgement_Arrival)) then
Receive_ACK();
if ( ACK_No = SeqNo ) then
Stop_Timer ([Link]);
canSend = True;
end if
else if ( Event( Timer &gt; Max_time)) then
Resend_Frame_To_Physical_Layer([Link]-1);
Start_Timer([Link]-1);
end if
end while

end
Receiver Site Algorithm of Simplex Stop andWait Protocol
begin
RSeqNo = 0; // Initialise sequence number of expected frame
while (true) //check repeatedly
do
Wait_For_Event(); //wait for arrival of frame
if ( Event(Frame_Arrival) then
Receive_Frame_From_Physical_Layer();
if ( Corrupted ( [Link] )
doNothing();
else if ( [Link] = RSeqNo ) then
Extract_Data();
Deliver_Data_To_Network_Layer();
RSeqNo = RSeqNo + 1;
end if
Send_ACK(ACKframe[RSeqNo]);
end if
end while
end
OUTPUT:

//SENDEROUTPUT
WaitingforConnection....
reciver>connected
.
Enter thedata tosend....
myname
data
sent>0mwaitingfo
rack.....
receiver
>packetrecievedd
ata sent>1y
waiting forack.....
receiver
>packetrecievedd
ata sent>0n
waiting forack.....
receiver
>packetrecievedd
ata sent>1a
waiting forack.....
Time outresendingdata....
data
sent>1awaitingfor
ack.....
receiver
>packetrecievedd
ata sent>0m
waiting forack.....
receiver
>packetrecievedd
ata sent>1e

waiting forack.....
receiver
>packetrecieved
All data sent. exiting.

//RECEIVEROUTPUT
waitingforconnection...
Connectionestablished:
receiver >0m
receiver >1y
receiver >0n
receiver >1a
receiver >1a duplicate
datareceiver >0m
receiver >1e
Data
recived=mynamewaitin
gforconnection...

RESULT:
Thus the flow control mechanism is implemented successfully.
EXNO:5 Multi-client chatting in TCP and UDP using Socket programming

AIM
To write a java program for application using TCP Sockets Links

PROCEDURE:
• In the TCP Echo client a socket is created. Using the socket a connection is made to the
server using the connect() function. After a connection is established, we send messages
input from the user and display the data received from the server using send() and read()
functions.

• In the TCP Echo server, we create a socket and bind to a advertized port number. After
binding the process listens for incoming connections. Then an infinite loop is started to
process the client requests for connections. After a connection is requested, it accepts the
connection from the client machine and forks a new process.

• The new process receives data from the lient using recv() function and echoes the same data
using the send() function. Please note hat this server is capable of handling multiple clients
as it forks a new process for every client trying to connect to the server. TCP socket
routines enable reliable IP communication using the transmission control protocol (TCP).

• The implementation of the Transmission Control Protocol (TCP) in the Network Component.
TCP runs on top of the Internet Protocol (IP). TCP is a connection- oriented and reliable,
full duplex protocol supporting a pair of byte streams, one for each
direction.

• A TCP connection must be established before exchanging data. TCP retransmits data that do
not reach the final destination due to errors or data corruption. Data is delivered in the
sequence of its transmission
a. Echo client and echo server

ALGORITHM

Client
1. Start
2. Create the TCP socket
3. Establish connection with the server
4. Get the message to be echoed from the user
5. Send the message to the server
6. Receive the message echoed by the server
7. Display the message received from the server
8. Terminate the connection
9. Stop

Server
1. Start
2. Create TCP socket, make it a listening socket
3. Accept the connection request sent by the client for connection establishment
4. Receive the message sent by the client
5. Display the received message
6. Send the received message to the client from which it receives
7. Close the connection when client initiates termination and server becomes a listening
server, waiting for clients.
8. Stop.
PSEUDOCODE

TCP client
Create socket, connectSocket
Do an active connect specifying the IP address and port number of server
Read and Write Data Into connectSocket to Communicate with server
Close connectSocket

TCP server
Create socket (serverSocket)
Bind socket to a specific port where clients can contact you
Register with the kernel your willingness to listen that on socket for client to contact you
Loop Accept new connection (connectSocket)
Read and Write Data Into connectSocket to Communicate with client
Close connectSocket
End Loop
Close serverSocket

OUTPUT
Server
C:\Program
Files\Java\jdk1.5.0\bin>[Link]:\Program
Files\Java\jdk1.5.0\bin>javaEServerC:\Program
Files\Java\jdk1.5.0\bin>
Client
C:\ProgramFiles\Java\jdk1.5.0\bin>[Link]
C:\ProgramFiles\Java\jdk1.5.0\bin>javaEClientClient:
HaiServer
Server:Hai
ServerClient:Hell
oServer:HelloCli
ent:endServer:en
dClient:ds
SocketClosed!
[Link]

ALGORITHM

Client
1. Start
2. Create the UDP datagram socket
3. Get the request message to be sent from the user
4. Send the request message to the server
5. If the request message is “END” go to step 10
6. Wait for the reply message from the server
7. Receive the reply message sent by the server
8. Display the reply message received from the server
9. Repeat the steps from 3 to 8
10. Stop
Server
1. Start
2. Create UDP datagram socket, make it a listening socket
3. Receive the request message sent by the client
4. If the received message is “END” go to step 10
5. Retrieve the client’s IP address from the request message received
6. Display the received message
7. Get the reply message from the user
8. Send the reply message to the client
9. Repeat the steps from 3 to 8.
10. Stop.

PSEUDOCODE

UDP server
Create socket
Bind socket to a specific port where clients can contact you
Loop (Receive UDP Message from client x)+ (Send UDP Reply to client x)*
Close Socket

UDP client
Create socket
Loop (Send Message To Well-known port of server)+ (Receive Message From Server)
Close Socket
OUTPUT:
Server

C:\ProgramFiles\Java\jdk1.5.0\bin>[Link]
C:\ProgramFiles\Java\jdk1.5.0\bin>javaUDPserver
press ctrl+c to quit the
programClient:Hai Server
Server:Hello
ClientClient:How
are YouServer:Iam
Fine

Client

C:\ProgramFiles\Java\jdk1.5.0\bin>[Link]:\Program
Files\Java\jdk1.5.0\bin>javaUDPclientserver waiting

Client:Hai
ServerServer:Hello
ClieClient:Howare
YouServer:IamFine

RESULT:
Multi-client chatting in TCP and UDP using Socket programming is executed successfully.
EXNO:6 Implementation of HTTP, Web Caching, FTP using socket programming

AIM
To write a java program for socket for HTTP for web page upload and download .

PROCEDURE:
• HTTP means HyperText Transfer Protocol. HTTP is the underlying protocol used by
the World Wide Web and this protocol defines how messages are formatted and
transmitted, and what actions Web servers and browsers should take in response to
various commands.
• For example, when you enter a URL in your browser, this actually sends an HTTP
command to the Web server directing it to fetch and transmit the requested Web page.
• The other main standard that controls how the World Wide Web works is HTML,
which covers how Web pages are formatted and displayed. HTTP functions as
a request–response protocol in the client–server computing model.
• A web browser, for example, may be the client and an application running on a
computer hosting a website may be the server.
• The client submits an HTTP request message to the server. The server, which
provides resources such as HTML files and other content, or performs other functions
on behalf of the client, returns a responsemessage to the client.
• The response contains completion status information about the request and may also
contain requested content in its message body.

PSEUDOCODE:

Client:
Begin
Create socket and establish the connection with the server.
Read the image to be uploaded from the disk
Send the image read to the server
Terminate the connection
End.

Server:
Begin
Create socket, bind IP address and port number with the created socket and make servera
listening server.
Accept the connection request from the client
Receive the image sent by the client.
Display the image.
Close the connection.
End.
OUTPUT:
When you run the client code, following output screen would appear on client side.

RESULT
Thus socket for HTTP for web page upload and download is executed successfully.
EXNO:7 Develop a DNS client server to resolve the given host name or IP address

AIM
To write a java program for DNS application

PROCEDURE:

• The Domain Name System (DNS) is a hierarchical decentralized naming system for
computers, services, or other resources connected to the Internet or a private network. It
associates various information with domain names assigned to each of the participating
entities.

• The domain name space refers a hierarchy in the internet naming structure. This
hierarchy has multiple levels (from 0 to 127), with a root at the top. The following
diagram shows the domain name space hierarchy.
• Name server contains the DNS database. This database comprises of various names and
their corresponding IP addresses. Since it is not possible for a single server to maintain
entire DNS database, therefore, the information is distributed among many DNS servers.

• Types of Name Servers


• Root Server is the top level server which consists of the entire DNS tree. It does not
contain the information about domains but delegates the authority to the other server
• Primary Server stores a file about its zone. It has authority to create, maintain, and update
the zone file.
• Secondary Server transfers complete information about a zone from another server which
may be primary or secondary server. The secondary server does not have authority to
create or update a zone file.

• DNS is a TCP/IP protocol used on different platforms. The domain name space is divided
into three different sections: generic domains, country domains, and inverse domain.

• The main function of DNS is to translate domain names into IP Addresses, which
computers can understand.

• It also provides a list of mail servers which accept Emails foreach domain name. Each
domain name in DNS will nominate a set of name servers to be
authoritative for its DNS records.
PSEUDOCODE

Server
1. Begin
2. Create UDP datagram socket
3. Create a table that maps host name and IP address
4. Receive the host name from the client
5. Retrieve the client’s IP address from the received datagram
6. Get the IP address mapped for the host name from the table.
7. Display the host name and corresponding IP address
8. Send the IP address for the requested host name to the client
9. End

Client
Begin
Create UDP datagram socket.
Get the host name from the client
Send the host name to the server
Wait for the reply from the server
Receive the reply datagram and read the IP address for the requested host name
Display the IP address.
End.
OUTPUT
Server
javac [Link]
java udpdnsserver
Press Ctrl + C to Quit Request for host [Link]
Request for host [Link]
Request for host [Link]

Client
>javac [Link]
>java udpdnsclient
Enter the hostname : [Link]
IP Address: [Link]
>java udpdnsclient
Enter the hostname : [Link]
IP Address: [Link]
>java udpdnsclient
Enter the hostname : [Link]
IP Address: Host Not Found

RESULT:
Thus the java application program using UDP Sockets to implement DNS was developed and
executed successfully
EXNO:8 Simulation of unicast routing protocols

AIM:
To write a ns2 program for implementing unicast routing protocol.

PROCEDURE:

• When a device has multiple paths to reach a destination, it always selects one path
by preferring it over others. This selection process is termed as Routing. Routing
is done by special network devices called routers or it can be done by means of
software processes.

• The software based routers have limited functionality and limited scope.A router
is always configured with some default route. A default route tells the router
where to forward a packet if there is no route found for specific destination.

• In case there are multiple path existing to reach the same destination, router can
make decision based on the following [Link] can be statically
configured or dynamically learnt. One route can be configured to be preferred over
[Link] of the traffic on the internet and intranets known as unicast data or
unicast traffic is sent with specified destination. Routing unicast data over the
internet is called unicast routing.

• It is the simplest form of routing because the destination is already known. Hence
the router just has to look up the routing table and forward the packet to next hop.
• Multicasting in computer network is a group communication, where a sender(s)
send data to multiple receivers simultaneously. It supports one – to – many and
many – to – many data transmission across LANs or WANs. Through the process
of multicasting, the communication and processing overhead of sending the same
data packet or data frame in minimized.

• Multicast IP Routing protocols are used to distribute data (for example,


audio/video streaming broadcasts) to multiple recipients. Using multicast, a source
can send a single copy of data to a single multicast address, which is then distributed
to an entire group of recipients.
• The key difference between broadcast and multicast is that in the broadcast the
packet is delivered to all the host connected to the network whereas,
in multicast packet is delivered to intended recipients only.
• Multicast Message. Multicasting identifies logical groups of computers. A
single message can then be sent to the group. Multicast Message.
Multicasting uses the Internet Group Management Protocol (IGMP) to identify
groups and group members.
PSEUDOCODE:
Begin
Declare the global variables ns for creating a new simulator.
Set the color for packets.
Open the network animator file in the name of file2 in the write mode.
Open the trace file in the name of file 1 in the write mode.
Set the unicast routing protocol to transfer the packets in network.
Create the required no of nodes.
Create the duplex-link between the nodes including the delay time,bandwidthand
dropping queue mechanism.
Give the position for the links between the nodes.
Set a tcp reno connection for source node.
Set the destination node using tcp sink.
Setup a ftp connection over the tcp connection.
Down the connection between any nodes at a particular time.
Reconnect the downed connection at a particular time.
Define the finish procedure.
In the definition of the finish procedure declare the global variables ns, file1, and file2.
Close the trace file and name file and execute the network animation file.
At the particular time call the finish procedure.
End.
RESULT:
Thus unicast routing protocols was developed and executed successfully.
EXNO:9 Observing Packets across the network and Performance Analysis of various Routing protocols

AIM:

To simulate the Distance vector and link state routing protocols using NS2.

PRE LAB DISCUSSION:

LINK STATE ROUTING


Routing is the process of selecting best paths in a network. In the past, the term routing
was also used to mean forwarding network traffic among networks. However this latter function
is much better described as simply forwarding. Routing is performed for many kinds of networks,
including the telephone network (circuit switching), electronic data networks (such as the Internet),
and transportation networks. This article is concerned primarily with routing in electronic data
networks using packet switching technology.
In packet switching networks, routing directs packet forwarding (the transit of logically
addressed network packets from their source toward their ultimate destination) through
intermediate nodes. Intermediate nodes are typically network hardware devices such as routers,
bridges, gateways, firewalls, or switches. General-purpose computers can also forward packets
and perform routing, though they are not specialized hardware and may suffer from limited
performance. The routing process usually directs forwarding on the basis of routing tables which
maintain a record of the routes to various network destinations. Thus, constructing routing tables,
which are held in the router's memory, is very important for efficient routing. Most routing
algorithms use only one network path at a time. Multipath routing techniques enable the use of
multiple alternative paths.

In case of overlapping/equal routes, the following elements are considered in order to


decide which routes get installed into the routing table (sorted by priority):
1. Prefix-Length: where longer subnet masks are preferred (independent of whether it is
within a routing protocol or over different routing protocol)
2. Metric: where a lower metric/cost is preferred (only valid within one and the same
routing protocol)
3. Administrative distance: where a lower distance is preferred (only valid between different
routing protocols)
Routing, in a more narrow sense of the term, is often contrasted with bridging in its
assumption that network addresses are structured and that similar addresses imply proximity
within the network. Structured addresses allow a single routing table entry to represent the route
to a group of devices. In large networks, structured addressing (routing, in the narrow sense)
outperforms unstructured addressing (bridging). Routing has become the dominant form of
addressing on the Internet. Bridging is still widely used within localized environments.
b. Flooding
Flooding is a simple routing algorithm in which every incoming packet is sent through
every outgoing link except the one it arrived on. Flooding is used in bridging and in systems such
as Usenet and peer-to-peer file sharing and as part of some routing protocols, including OSPF,
DVMRP, and those used in ad-hoc wireless [Link] are generally two types of flooding
available, Uncontrolled Flooding and Controlled Flooding. Uncontrolled Flooding is the fatal law
of flooding. All nodes have neighbours and route packets indefinitely. More than two neighbours
creates a broadcast storm.
Controlled Flooding has its own two algorithms to make it reliable, SNCF (Sequence
Number Controlled Flooding) and RPF (Reverse Path Flooding). In SNCF, the node attaches its
own address and sequence number to the packet, since every node has a memory of addresses and
sequence numbers. If it receives a packet in memory, it drops it immediately while in RPF, the
node will only send the packet forward. If it is received from the next node, it sends it back tothe
sender.

Distance vector Routing:


In computer communication theory relating to packet-switched networks, a distance-
vector routing protocol is one of the two major classes of routing protocols, the other major class
being the link-state protocol. Distance-vector routing protocols use the Bellman–Fordalgorithm,
Ford–Fulkerson algorithm, or DUAL FSM (in the case of Cisco Systems's protocols) to calculate
paths.

A distance-vector routing protocol requires that a router informs its neighbors of topology
changes periodically. Compared to link-state protocols, which require a router to inform all the
nodes in a network of topology changes, distance-vector routing protocols have less computational
complexity and message overhead.

The term distance vector refers to the fact that the protocol manipulates vectors (arrays)
of distances to other nodes in the network. The vector distance algorithm was the original
ARPANET routing algorithm and was also used in the internet under the name of RIP (Routing
Information Protocol).Examples of distance-vector routing protocols include RIPv1 and RIPv2
and IGRP.

Method
Routers using distance-vector protocol do not have knowledge of the entire path to a
destination. Instead they use two methods:
1. Direction in which router or exit interface a packet should be forwarded.
2. Distance from its destination
Distance-vector protocols are based on calculating the direction and distance to any link in
a network. "Direction" usually means the next hop address and the exit interface. "Distance" isa
measure of the cost to reach a certain node. The least cost route between any two nodes is the route
with minimum distance. Each node maintains a vector (table) of minimum distance to
every node. The cost of reaching a destination is calculated using various route metrics. RIP uses
the hop count of the destination whereas IGRP takes into account other information such as node
delay and available bandwidth.
Updates are performed periodically in a distance-vector protocol where all or part of a
router's routing table is sent to all its neighbors that are configured to use the same distance- vector
routing protocol. RIP supports cross-platform distance vector routing whereas IGRP is a Cisco
Systems proprietary distance vector routing protocol. Once a router has this information it is able
to amend its own routing table to reflect the changes and then inform its neighbors of the changes.
This process has been described as ‗routing by rumor‘ because routers are relying on the
information they receive from other routers and cannot determine if the information is actually
valid and true. There are a number of features which can be used to help with instability and
inaccurate routing information.
EGP and BGP are not pure distance-vector routing protocols because a distance-vector
protocol calculates routes based only on link costs whereas in BGP, for example, the local route
preference value takes priority over the link cost.

Count-to-infinity problem
The Bellman–Ford algorithm does not prevent routing loops from happening and suffers
from the count-to-infinity problem. The core of the count-to-infinity problem is that if A tells B
that it has a path somewhere, there is no way for B to know if the path has B as a part of it. To see
the problem clearly, imagine a subnet connected like A–B–C–D–E–F, and let the metric between
the routers be "number of jumps". Now suppose that A is taken offline. In the vector- update-
process B notices that the route to A, which was distance 1, is down – B does not receive the vector
update from A. The problem is, B also gets an update from C, and C is still not aware of the fact
that A is down – so it tells B that A is only two jumps from C (C to B to A), which is false. This
slowly propagates through the network until it reaches infinity (in which case the algorithm
corrects itself, due to the relaxation property of Bellman–Ford).

ALGORITHM:

1. Create a Simulator object.


2. Set routing as dynamic.
3. Open the trace and nam trace files.
4. Define the finish procedure.
5. Create nodes and the links between them.
6. Create the agents and attach them to the nodes.
7. Create the applications and attach them to the udp agent.
8. Connect udp and null..
9. At 1 sec the link between node 1 and 2 is broken.
10. At 2 sec the link is up again.
11. Run the simulation.
OUTPUT:
DISTANCE VECTOR ROUTING ALGORITHM

ALGORITHM:
1. Create a simulator object
2. Set routing protocol to Distance Vector routing
3. Trace packets on all links onto NAM trace and text trace file
4. Define finish procedure to close files, flush tracing and run NAM
5. Create eight nodes
6. Specify the link characteristics between nodes
7. Describe their layout topology as a octagon
8. Add UDP agent for node n1
9. Create CBR traffic on top of UDP and set traffic parameters.
10. Add a sink agent to node n4
11. Connect source and the sink
12. Schedule events as follows:
a. Start traffic flow at 0.5
b. Down the link n3-n4 at 1.0
c. Up the link n3-n4 at 2.0
d. Stop traffic at 3.0
e. Call finish procedure at 5.0
13. Start the scheduler
14. Observe the traffic route when link is up and down
15. View the simulated events and trace file analyze it
16. Stop

OUTPUT
$ ns [Link]
RESULT:

Thus the simulation for Distance vector and link state routing protocols was
done usingNS2.
EX NO:10 Simulation of Transport layer Protocols and analysis of congestion control
techniques inthe network.

AIM:
To Study Network simulator (NS).and Simulation of Congestion Control
Algorithms using NS

PROCEDURE:

NET WORK SIMULATOR (NS2)

Congestion Control Algorithms


• Slow start
• Additive increase/multiplicative decrease
• Fast retransmit and Fast recovery

Case Study: A simple Wireless network.

Ad hoc routing,
mobile IP, sensor-
MAC Tracing,
visualization and
various utilitie
NS(Network
Simulators)

Most of the commercial simulators are GUI driven, while some


network simulators are CLI driven. The network model / configuration
describes the state of the network (nodes,routers, switches, links) and the
events (data transmissions, packet error etc.). An important output of
simulations are the trace files. Trace files log every packet, every event that
occurred in the simulation and are used for analysis. Network simulators can
also provide other tools to facilitate visual analysis of trends and potential
trouble spots.
Most network simulators use discrete event simulation, in which a
list of pending "events" is stored, and those events are processed in order, with
some events triggering future events—such as the event of the arrivalof a
packet at one node triggering the event of the arrival of that packet at a
downstream node.
Simulation of networks is a very complex task. For example, if
congestion is high, then estimation of the average occupancy is challenging
because of high variance. To estimate the likelihood of a buffer overflow in
a network, the time required for an accurate answer can be extremely large.
Specialized techniques such as "control variates" and "importance sampling"
have been developed to speed simulation.

Examples of network simulators

There are many both free/open-source and proprietary network


simulators. Examples of notable network simulation software are, ordered
after how often they are mentioned in research papers:
1. ns (open source)
2. OPNET (proprietary software)
3. NetSim (proprietary software)

Uses of network simulators

Network simulators serve a variety of needs. Compared to the cost and


time involved in setting up an entire test bed containing multiple networked
computers, routers and data links, network simulators are relatively fast and
inexpensive. They allow engineers, researchers to test

scenarios that might be particularly difficult or expensive to emulate using


real hardware - for instance, simulating a scenario with several nodes or
experimenting with a new protocol in the network. Network simulators are
particularly useful in allowing researchers to test new networking protocols
or changes to existing protocols in a controlled and reproducible environment.
A typical network simulator encompasses a wide range of networking
technologies and can help the users to build complex networks from basic
building blocks such as a variety of nodes and links. With the help of
simulators, one can design hierarchical networks using various types of nodes
like computers, hubs, bridges, routers, switches, links, mobile unitsetc.

Various types of Wide Area Network (WAN) technologies like TCP,


ATM, IP etc. and Local Area Network (LAN) technologies like Ethernet,
token rings etc., can all be simulated with a typical simulator and the user can
test, analyze various standard results apart from devising some novel protocol
or strategy for routing etc. Network simulators are also widely used to
simulate battlefield networks in Network-centric warfare.

There are a wide variety of network simulators, ranging from thevery


simple to the very complex. Minimally, a network simulator must enable a
user to represent a network topology, specifying the nodes on the network,
the links between those nodes and the traffic between the nodes.
More complicated systems may allow the user to specify everything about the
protocols used to handle traffic in a network. Graphical applications allow
users to easily visualize the workings of their simulated environment. Text-
based applications may provide a less intuitive interface, but may permit
more advanced forms of customization.

Packet loss

Packet loss occurs when one or more packets of data travellingacross


a computer network fail to reach their destination. Packet loss is distinguished
as one of the three main error types encountered in digital communications;
the other two being bit error and spurious packets caused due to noise.

Packets can be lost in a network because they may be dropped when


a queue in the network node overflows. The amount of packet loss during the
steady state is another important property of a congestion control scheme.
The larger the value of packet loss, the more difficult it is for transportlayer
protocols to maintain high bandwidths, the sensitivity to loss of individual
packets, as well as to frequency and patterns of loss among longer packet sequences
is strongly dependent on the application itself.

Throughput

Throughput is the main performance measure characteristic, and most


widely used. In communication networks, such as Ethernet or packet radio,
throughput or network throughput is the average rate of successful message
delivery over a communication channel.

Throughput is usually measured inbitsper second (bit/s orbps), and


sometimes in data packets per second or data packets per time slot. This
measures how soon the receiver is able to get a certain amount of data send
by the sender. It is determined as the ratio of the total data received to the end
to end delay. Throughput is an importantfactor which directly impacts the
network performance.
Delay
Delay is the time elapsed while a packet travels from one point e.g., source
premise

network ingress to destination premise or network degrees. The larger the


value of delay, the more difficult it is for transport layer protocols to maintain
highbandwidths. We will calculate end to end delay

Queue Length
A queuing system in networks can be described as packets arriving for
service, waiting for service if it is not immediate, and if having waited for

service, leaving the system after being served. Thus queue length is very
important characteristic to determine that how well the active queue
management of the congestion control algorithm has been working.

Congestion control Algorithms

Slow-start is used in conjunction with other algorithms to avoid sending


more data than the network is capable of transmitting, that is, to avoid causing
network congestion. The additive increase/multiplicative decrease (AIMD)
algorithm is a feedback control algorithm.

AIMD combines linear growth of the congestion window with an


exponential reduction when a congestion takes place. Multiple flows using
AIMD congestion control will eventually converge to use equal amounts of a
contended link. Fast Retransmit is an enhancement to TCP that reduces the
time a sender waits before retransmitting a lost segment.

RESULT:

Thus we have Studied Network simulator (NS) and Simulation of Congestion Control
Algorithms using NS.

You might also like