CN Lab Manual Master
CN Lab Manual Master
TECHNOLOGY MEERUT
LAB MANUAL
(Computer Networks Lab)
1
Vision of Institute
Mission of Institute
The mission of the institute is to educate young aspirants in various technical fields to fulfill
global requirement of human resources by providing sustainable quality education, trai ning and
invigorating environment besides molding them into skilled competent and socially responsible
citizens who will lead the building of a powerful nation.
COs
1. To understand the basic concepts of networking devices and connectivity.
programming.
5 To design and configure a network using Cisco Packet Tracer. Also, use
2
S.No.
Running and using services / commands like ping, trace route, nslookup, 5
arp etc. (Verify the connectivity of your workstation to the internet.)
1a
9
To study network CONNECTING DEVICES.
1b
Write a C program:
13
For OSI model simulation.
2
17
26
To implement RSA Algorithm (Encryption and Decryption).
8
3
Value Addition:
10a
10b
4
Practical no. 1a
Objective: Running and using services / commands like ping, trace route, nslookup,
arp etc . (Verify the connectivity of your workstation to the internet).
Experiment
1. Verify the connectivity of your workstation to the internet.
2. Open the Command Prompt of the operating system using either of the following
methods:
Click on Start > All Programs > Accessories > Command Prompt or
Click on Start > Run, enter cmd (short for command) and click on ok.
A Command Prompt screen should open.
3. Gather TCP/IP configuration information: Type ipconfig (short for IP configuration)
and press Enter. The screen will show the IP address, subnet mask, and default
gateway for your computer’s connection.
Notice the values in the Command Prompt. The IP address and the default gateway should
be in the same network or subnet, otherwise this host would not be able to commu nicate
outside the network. In figure 1, the subnet mask tells us that the first three octets of the IP
address and the default gateway must be the same in order to be in the same network.
4. Check more detailed TCP/IP configuration information: Type ipconfig /all and
press Enter. What are the DNS and DHCP server addresses? What are their
functions? What is the MAC of the network interface card?
5
5. Ping the IP address of another computer. Note that for the ping and tracert
commands to work the PC firewalls have to be disabled. Why do you think this is so?
Ask the IP address of the workstation that is being used by another group o f
students. Then type ping, space, and the IP address that you received, then press
Enter. Notice the outputs. Figure 2 shows a successful result of a ping to a given IP
address.
6. Ping the IP address of the gateway router from the details that have been observed
in the output of step 4 above. If the ping is successful, it means that there is a
physical connectivity to the router on the local network and probably the rest of the
world.
7. Ping the Loopback IP address of your computer. Type the following command: ping
127.0.0.1. The IP address 127.0.0.1 is reserved for loopback testing. If the ping is
successful, then TCP/IP is properly installed and functioning on this computer .
8. You can also ping using names like websites. Ping the IP address of the cisco
website. Type ping, space and www.cisco.com, then press Enter. Notice the
6
outputs. A DNS server will resolve the name to an IP address and the ping will be
successful only in the existence of the DNS server.
9. Ping www.ee.uct.ac.za and observe the results. Is there a difference in time between
the results shown by pinging www.cisco.com and www.ee.uct.ac.za. If so why and if
not why?
10. Trace the route to the Cisco website. Type tracert www.cisco.com and press enter.
In a successful output, you will see listings of all routers the tracert requests had to
pass through to get to the destination.
11. Trace the route to the website of the Department of Electrical Engineering. Type
tracert www.ee.uct.ac.za and press enter. The output should take less time than
that of step 9. In the same way gmail.com can be traced out as shown in figure 3.
7
Important Questions
1. What command is commonly used to test network connectivity and measure round-
trip time between two devices?
2. Which command provides information about the IP configuration of a computer,
including IP address, subnet mask, and default gateway?
3. What does the 'nslookup' command primarily do?
4. Which command is used to reset the Windows Sockets (Winsock) catalog to resolve
network-related issues?
5. What is the purpose of the 'tracert' command?
6. Which command is used to flush and reset the contents of the DNS client resolver
cache?
7. What does the 'ping' command measure?
8. Which command provides information about network interfaces, including MAC
addresses and connection status?
9. What does the 'netsh winsock reset' command do?
10. Which command is used to trace the route taken by packets from the source to the
destination?
8
Practical no. 1b
Passive Hubs
A passive hub is just a connector. It connects the wires coming from different
branches. In a star-topology Ethernet LAN, a passive hub is just a point where the
signals coming from different stations collide; the hub is the collision point. This
type of a hub is part of the media; its location in the Internet model is below the
physical layer.
Repeaters
A repeater is a device that operates only in the physical layer. Signals that carry
information within a network can travel a fixed distance before a ttenuation
endangers the integrity of the data. A repeater receives a signal and, before it
becomes too weak or corrupted, regenerates the original bit pattern. The repeater
then sends the refreshed signal as shown in figure 4.
A repeater does not actually connect two LANs; it connects two segments of the same LAN.
The segments connected are still part of one single LAN. A repeater is not a device that can
connect two LANs of different protocols.
Active Hubs
9
An active hub is actually a multipart repeater. It is normally used to create connections
between stations in a physical star topology. We have seen examples of hubs in some
Ethernet implementations (lOBase-T, for example). However, hubs can also be used to
create multiple levels of hierarchy, as shown in figure 5. The hierarchical use of hubs
removes the length limitation of 10Base-T (100 m).
Transparent Bridges
A transparent bridge is a bridge in which the stations are completely unaware of the
bridge's existence. If a bridge is added or deleted from the system, reconfiguration of the
stations is unnecessary. According to the IEEE 802.1 d specification, a system equipped
with transparent bridges must meet three criteria:
A two-layer switch is a bridge, a bridge with many ports and a design that allows better
(faster) performance. A bridge with a few ports can connect a few LANs together. A bridge
with many ports may be able to allocate a unique port to each station, with each station on
its own independent entity. This means no competing traffic (no collision, as we saw in
Ethernet).
A two-layer switch, as a bridge does, makes a filtering decision based on the MAC address
of the frame it received. However, a two-layer switch can be more sophisticated. It can have
a buffer to hold the frames for processing. It can have a switching factor that forwards the
frames faster. Some new two-layer switches, called cut-through switches, have been
designed to forward the frame as soon as they check the MAC addresses in the header of
the frame.
Routers
A router is a three-layer device that routes packets based on their logical addresses (host-
to-host addressing). A router normally connects LANs and WANs in the Internet and has a
routing table that is used for making decisions about the route. The routing tables are
normally dynamic and are updated using routing protocols.
Three-Layer Switches
A three-layer switch is a router, but a faster and more sophisticated. The switching fabric in
a three-layer switch allows faster table lookup and forwarding. In this book, we use the
terms router and three-layer switch interchangeably.
Gateway
A gateway is normally a computer that operates in all five layers of the Internet or seven
layers of OSI model. A gateway takes an application message, reads it, and interprets it.
11
This means that it can be used as a connecting device between two internetworks that use
different models. For example, a network designed to use the OSI model can be connected
to another network using the Internet model. The gateway connecting the two systems can
take a frame as it arrives from the first system, move it up to the OSI application layer, and
remove the message.
Important Questions:
1. What device operates at the Data Link Layer (Layer 2) of the OSI model and
connects multiple devices within the same LAN?
2. Which device is used to segment a network into different collision domains,
effectively reducing collisions in Ethernet networks?
3. What is the primary function of a router in a network?
4. Which device connects multiple networks together, typically using IP addresses to
route data between them?
5. What connecting device operates at the Physical Layer (Layer 1) of the OSI model
and regenerates signals to extend the range of a network?
6. Which device makes forwarding decisions based on MAC addresses and operates at
both Layer 2 and Layer 3 of the OSI model?
7. What is the primary purpose of a hub in a network?
8. Which connecting device is known for creating separate collision domains for each
of its ports, preventing collisions on the network?
9. What device connects devices to a network wirelessly using radio waves?
10. What connecting device is designed to regenerate signals and extend the distance of
a network by amplifying the signal strength?
12
Practical no. 2
Objective: OSI model simulation.
PROGRAM DESCRIPTION:
The OSI Model deals with connecting open system. This model does not specify the exact
services and protocols to use in each layer. Therefore, the OSI Model is not a network
architecture. This model has seven layers. They are Physical layer, Data link layer,
Presentation layer, Network layer, Session layer, Transport layer and Application layer. At
sender side, each layer adds the header. The length of string i.e., number of bytes are not
restricted up to Session layer.
ALGORITHM:
1. Read the input string and address.
2. Add application header.
3. Print the string.
4. Add the presentation layer header.
5. Print the string.
6. Add the Session layer header.
7. Print the string.
8. Add the Transport layer header.
9. Print the string.
10. Add the Network layer header.
11. Print the string.
12. Add the Data link layer header.
13. Print the string
14. Add the physical layer header.
15. Print the string.
13
INPUT: Enter the string: hai
OUTPUT: TRANSMITTER:
Important Questions:
14
Practical no. 3
Objective: Write C program to find the throughput of Pure Aloha and Slotted Aloha.
Problem Statement: C program to implement Pure Aloha
Input Description: Take input value of G (Channel load per packet time)
= G x e-2G
Input: G=1/2
Output: S=0.184
Test Cases:
1. G=1/2 S=0.184
Question-3
Input Description: Take input value of G (Channel load per packet time)
= G x e-G
Input: G=1
Output: S=0.368
15
Test Cases:
1. G=1 S=0.368
Important Questions:
1. In which multiple access protocol does a station send its data whenever it has a
frame to transmit without checking for the channel's status first?
2. What is the primary disadvantage of Pure Aloha in terms of efficiency and channel
utilization?
3. In Slotted Aloha, time is divided into fixed intervals. What is transmitted only at the
beginning of each time slot?
4. Which of the following statements is true regarding collision resolution in Pure
Aloha and Slotted Aloha?
5. In Slotted Aloha, what is the key advantage over Pure Aloha that leads to improved
channel efficiency?
16
Practical no. 4
Parity: Parity of a number refers to whether it contains an odd or even number of 1 -bits.
The number has “odd parity”, if it contains odd number of 1-bits and is “even parity” if it
contains even number of 1-bits.
Main idea of the below solution is – Loop while n is not 0 and in loop unset one of the set
bits and invert parity.
Algorithm: getParity(n)
1. Initialize parity = 0
2. Loop while n != 0
a. Invert parity
parity = !parity
b. Unset rightmost set bit
n = n & (n-1)
3. return parity
Example:
Initialize: n = 13 (1101) parity = 0
17
Important Questions:
1. In Even Parity, how is the parity bit chosen to ensure even parity for a set of data
bits?
2. Which of the following statements is true regarding Even Parity and Odd Parity?
3. In Odd Parity, how is the parity bit chosen to ensure odd parity for a set of data bits?
4. Which type of parity is more resilient to single-bit errors?
5. If a binary data sequence is 1100110, what would be the parity bit for Even Parity?
18
Practical no. 5
19
Important Questions:
1. What is the primary purpose of framing in networking?
2. Which framing technique uses a specific bit sequence at the beginning and end of a
frame to delineate the frame boundaries?
3. In HDLC (High-Level Data Link Control) framing, what field is used for error
detection?
4. What framing technique involves inserting a special pattern into the data stream
when a specific condition is met, such as consecutive 1s?
5. Which framing technique is commonly used in Ethernet networks and involves a
preamble, start frame delimiter, and frame check sequence?
Practical no. 6
CRC uses Generator Polynomial which is available on both sender and receiver side. An
example generator polynomial is of the form like x3 + x + 1. This generator polynomial
represents key 1011. Another example is x 2 + 1 that represents key 101.
Sender Side (Generation of Encoded Data from Data and Generator Polynomial (or
Key)):
1. The binary data is first augmented by adding k-1 zeros in the end of the data
2. Use modulo-2 binary division to divide binary data by the key and store remainder of
division.
3. Append the remainder at the end of the data to form the encoded data and send the
same
.
20
Receiver Side (Check if there are errors introduced in transmission)
Perform modulo-2 division again and if remainder is 0, then there are no errors. In this we
will focus only on finding the remainder i.e. check word and the code word.
Modulo 2 Division:
The process of modulo-2 binary division is the same as the familiar division process we use
for decimal numbers. Just that instead of subtraction, we use XOR here.
In each step, a copy of the divisor (or data) is XORed with the k bits of the dividend (or
key).
The result of the XOR operation (remainder) is (n-1) bits, which is used for the next
step after 1 extra bit is pulled down to make it n bits long.
When there are no bits left to pull down, we have a result. The (n-1)-bit remainder
which is appended at the sender side.
Illustration:
21
Receiver Side:
Receiver Side:
23
Important Questions:
1. What is the primary purpose of Cyclic Redundancy Check (CRC) in networking?
2. In CRC, what type of polynomial division is used for error detection?
3. Which statement accurately describes the role of CRC in error detection?
4. What is the key advantage of using CRC for error detection in comparison to simple
parity checks?
5. In CRC, what is the remainder called after performing polynomial division for error
checking?
Practical no. 7
The idea! The idea of RSA is based on the fact that it is difficult to factorize a large integer.
The public key consists of two numbers where one number is multiplication of two large
prime numbers. And private key is also derived from the same two prime numbers. So if
somebody can factorize the large number, the private key is compromised. Therefore
encryption strength totally lies on the key size and if we double or triple the key size, the
strength of encryption increases exponentially. RSA keys can be typically 1024 or 2048 bits
24
long, but experts believe that 1024 bit keys could be broken in the near future. But till now
it seems to be an infeasible task.
25
Important Questions
Practical no. 8
Objective:
Write a C program for IPV4, Implementation of decimal to binary, and Implementation of
binary to decimal.
Hexadecimal Notation
26
Classful Addressing
The 32 bit IP address is divided into five sub-classes which is depicted in figure 6. These
are:
Class A
Class B
Class C
Class D
Class E
Each of these classes has a valid range of IP addresses. Classes D and E are reserved for
multicast and experimental purposes respectively. The order of bits in the first octet
determine the classes of IP address.
Network ID
Host ID
The class of IP address is used to determine the bits used for network ID and host ID and
the number of total networks and hosts possible in that particular class. Each ISP or
network administrator assigns IP address to each device that is connected to its network.
27
Important Questions:
Practical no. 9
To understand this concept first we have to know little about traffic shaping. Traffic
Shaping is a mechanism to control the amount and the rate of the traffic sent to the
network. Approach of congestion management is called Traffic shaping. Traffic shaping
helps to regulate rate of data transmission and reduces congestion.
There are 2 types of traffic shaping algorithms:
1. Leaky Bucket
2. Token Bucket
Suppose we have a bucket in which we are pouring water in a random order but we have to
get water in a fixed rate, for this we will make a hole at the bottom of the bucket. It will
ensure that water coming out is in a some fixed rate, and also if bucket will full we will stop
pouring in it.
The input rate can vary, but the output rate remains constant. Similarly, in networking, a
technique called leaky bucket can smooth out bursty traffic. Bursty chunks are stored in the
bucket and sent out at an average rate.
28
Fig. 7. Leaky bucket for shaping the traffic
In the figure, we assume that the network has committed a bandwidth of 3 Mbps for a host.
The use of the leaky bucket shapes the input traffic to make it conform to this commitment.
In figure 7 the host sends a burst of data at a rate of 12 Mbps for 2 s, f or a total of 24 Mbits
of data. The host is silent for 5 s and then sends data at a rate of 2 Mbps for 3 s, for a total of
6 Mbits of data. In all, the host has sent 30 Mbits of data in 10 s. The leaky bucket smooths
the traffic by sending out data at a rate of 3 Mbps during the same 10 s.
Without the leaky bucket, the beginning burst may have hurt the network by consuming
more bandwidth than is set aside for this host. We can also see that the leaky bucket may
prevent congestion.
A simple leaky bucket algorithm can be implemented using FIFO queue. A FIFO queue holds
the packets. If the traffic consists of fixed-size packets (e.g., cells in ATM networks), the
process removes a fixed number of packets from the queue at each tick of the clock. If the
traffic consists of variable-length packets, the fixed output rate must be based on the
number of bytes or bits.
Packet=
Since n> front of Queue i.e. n>200
29
Therefore, n=1000-200=800
Packet size of 200 is sent to the network.
Important Questions:
1. What is the primary purpose of the Leaky Bucket algorithm in networking?
2. How does the Leaky Bucket algorithm control the rate of outgoing traffic?
3. In the context of the Leaky Bucket algorithm, what does the "leaky" aspect signify?
4. What is the role of the Leaky Bucket algorithm in handling bursty traffic?
5. In the Leaky Bucket algorithm, what happens if the bucket is already full and new
packets arrive?
30
Practical no. 10a
Step 1: Start Packet Tracer You will see the start screen as shown below.
Step 3: After selecting “Generic” click on the main area. You will see a Hub.
Step 4: Select “End Devices” and then click at “Generic” Choosing Devices and Connections
We will begin building our network topology by selecting devices and the media in which
to connect them. Several types of devices and network connections can be used.
Step 6: Select “Connections” from Power Cycle Devices and click on “Automatically choose
Connection Type”
Step 8: Double click on a PC, a box will appear. Click on the “Desktop” tab.
Step 10: Write the IP address of your network and click at the Subnet mask filed. Subnet
Mask will appear automatically.
Step11: Repeat Step 10 to set the IPs for all the PCs.
31
Step 13: Drag and Drop the message to the source device and then to the Destination device
In this case my source device is PC1 and destination device is PC4.
Step 14: Select the Simulation Mode at the bottom right corner.
Step 16: Observe the path of the Message from source to Hub, then to all devices. And then
from Destination to Hub then back to the source.
Step 17: Finally observe the marks. If the source PC is marked correct it means you have
successfully established the connection.
Screenshots:
32
Fig. 11.2. Step 2
33
Fig. 11.7. Step 7
34
Fig. 11.10. Step 10
35
Fig. 11.14. Step 14
Important Questions:
1. What is Cisco Packet Tracer primarily used for in the context of networking
education?
2. Which of the following devices can be simulated in Cisco Packet Tracer?
3. What does the "Simulation" mode in Cisco Packet Tracer allow users to do?
4. In Cisco Packet Tracer, what feature allows users to visually represent the flow of
data through a network?
5. Which of the following protocols is commonly used in Cisco Packet Tracer for device
configuration?
36
Practical no. 10b
THEORY
Wireshark is a tool that allows packet traces to be sniffed, captured and analyzed. Before
Wireshark (or in general, any packet capture tool) is used, careful consideration should be
given to where in the network packets are to be captured. Refer to the capture setup pages
in the wireshark.org wiki for technical details on various deployment scenarios. If it is
unclear which deployment scenario should be used to capture traces for a particular
problem, consider opening a service request with Novell Technical Services for assistance.
Part 1
1. Is your browser running HTTP version 1.0 or 1.1? What version of HTTP is the server
running?
2. What languages (if any) does your browser indicate that it can accept to the server?
3. What is the IP address of your computer?
4. What is the status code returned from the server to your browser?
5. When was the HTML file that you are retrieving last modified at the server?
6. How many bytes of content are being returned to your browser?
7. By inspecting the raw data in the packet content window, do you see any headers within
the data that are not displayed in the packet-listing window? If so, name one.
Part 2
8. Inspect the contents of the first HTTP GET request from your browser to the server.
Do you see an “IF-MODIFIED-SINCE” line in the HTTP GET?
9. Inspect the contents of the server response. Did the server explicitly return the Contents
of the file? How can you tell?
10. Now inspect the contents of the second HTTP GET request from your browser to the
server. Do you see an “IF-MODIFIED-SINCE:” line in the HTTP GET? If so, what information
follows the “IF-MODIFIED-SINCE:” header?
37
11. What is the HTTP status code and phrase returned from the server in response to this
second HTTP GET? Did the server explicitly return the contents of the file? Explain.
Part 3
12. How many HTTP GET request messages did your browser send? Which packet number
in the trace contains the GET message for the Bill or Rights?
13. Which packet number in the trace contains the status code and phrase associated with
the response to the HTTP GET request?
14. What is the status code and Phrase in the response?
15. How many data-containing TCP segments were needed to carry the single HTTP
response and the text of the Bill of Rights?
Part 4
16. How many HTTP GET request messages did your browser send? To which
Internet addresses were these GET requests sent?
17. Can you tell whether your browser downloaded the two images serially, or whether
they were downloaded from the two web sites in parallel? Explain.
Part 5
Let’s try visiting a web site that is password-protected and examine the sequence of HTTP
message exchanged for such a site. The URL http://gaia.cs.umass.edu/wireshark-
labs/protected_pages/HTTP-wireshark-file5.html is password protected. The username is
“wireshark-students” (without the quotes), and the password is “network” (again, without
the quotes). So let’s access this “secure”
Password-protected site. Do the following:
•Make sure your browser’s cache is cleared, as discussed above, and close down
your browser. Then, start up your browser
•Start up the Wireshark packet sniffer
•Enter the following URL into your browser
http://gaia.cs.umass.edu/wireshark-labs/protected_pages/HTTP-wiresharkfile5.
Html Type the requested user name and password into the pop up box.
•Stop Wireshark packet capture, and enter “http” in the display-filter-specification
window, so that only captured HTTP messages will be displayed later in the
38
packet-listing window.
•(Note: If you are unable to run Wireshark on a live network connection, you can
use the http-ethereal-trace-5 packet trace to answer the questions below; see
footnote 2. This trace file was gathered while performing the steps above on one
of the author’s computers.)
Now let’s examine the Wireshark output. You might want to first read up on HTTP
authentication by reviewing the easy-to-read material on “HTTP Access Authentication
Framework” at http://frontier.userland.com/stories/storyReader$2159
18. What is the server’s response (status code and phrase) in response to the initial HTTP
GET message from your browser?
19. When your browser’s sends the HTTP GET message for the second time, what new field
is included in the HTTP GET message?
OUTPUT
1. Version 1.1
3. 192.168.1.102
4.200 Ok
5.73 bytes
7.No
8. NO
11. Status code: 304 No it does not return any information explicitly as we cannot see any
line based text data or any other return type.
13.Packet no: 14
39
14. status code : 200 phrase: OK
17. The browser downloaded the images serially as the arrival times of both the images are
different and they are in separate tcp packet.
Fig.
12.1.
Snaps
hot of
questi
on 1,2
40
Fig. 12.2. Snapshot of question 3,4,16
41
Fig. 12.4. Snapshot of question 9,10,11
42
Fig. 12.5. Snapshot of question 15
43
Fig. 12.7. Snapshot of question 18
44
Important Questions:
1. What is the main purpose of Wireshark?
2. In Wireshark, what type of information can you capture and analyze?
3. Which layer of the OSI model is Wireshark capable of capturing and analyzing?
4. What does a packet capture in Wireshark typically include?
5. How does Wireshark help troubleshoot network issues?
THEORY:
Socket programming is a way of connecting two nodes on a network to communicate with
each other. One socket (node) listens on a particular port at an IP, while other socket
reaches out to the other to form a connection. Server forms the listener socket while client
reaches out to the server.
45
int sockfd = socket(domain, type, protocol)
Setsockopt:
This helps in manipulating options for the socket referred by the file descriptor
sockfd. This is completely optional, but it helps in reuse of address and port. Prevents
error such as: “address already in use”.
Bind:
socklen_t addrlen);
After creation of the socket, bind function binds the socket to the address and port
number specified in addr(custom data structure). In the example code, we bind the
server to the localhost, hence we use INADDR_ANY to specify the IP address.
Listen:
It puts the server socket in a passive mode, where it waits for the client to approach
the server to make a connection. The backlog, defines the maximum length to which
46
the queue of pending connections for sockfd may grow. If a connection request
arrives when the queue is full, the client may receive an error with an indication of
ECONNREFUSED.
Accept:
It extracts the first connection request on the queue of pending connections for the
listening socket, sockfd, creates a new connected socket, and returns a new file
descriptor referring to that socket. At this point, connection is established between
client and server, and they are ready to transfer data.
Connect:
socklen_t addrlen);
The connect () system call connects the socket referred to by the file descriptor
sockfd to the address specified by addr. Server’s address and port is specified in addr.
The steps involved in establishing a socket on the client side are as follows:
2.Connect the socket to the address of the server using the connect() system call
3.Send and receive data. There are a number of ways to do this, but the simplest is to use
the read() and write() system calls.
47
The steps involved in establishing a socket on the server side are as follows:
2. Bind the socket to an address using the bind() system call. For a server socket on the
Internet, an address consists of a port number on the host machine.
4. Accept a connection with the accept() system call. This call typically blocks until a client
connects with the server.
Important Questions:
The End
48