Lab Mannual
Lab Mannual
Lab Mannual
Department
Of
Computer Science & Engineering
Computer Network Lab Manual
For the Academic Year 201 -1
(In accordance with UPTU syllabus)
Faculty In-charge
Head of Department
Table of Content
S. No
List of Experiment
1.
2.
3.
4.
5.
Signature
7.
Implementation of CRC in C
8.
9.
10.
11.
EXPERIMENT-1
Aim: Study of different types of Network cables and practically implement the cross-wired cable and
straight through cable using clamping tool.
EXPERIMENT-2
Aim: Study of following Network Devices in Detail
Repeater
Hub
Switch
Bridge
Router
Gate Way
5. Router: A router is an electronic device that interconnects two or more computer networks, and
selectively interchanges packets of data between them. Each data packet contains address information
that a router can use to determine if the source and destination are on the same network, or if the data
packet must be transferred from one network to another. Where multiple routers are used in a large
collection of interconnected networks, the routers exchange information about target system addresses,
so that each router can build up a table showing the preferred paths between any two systems on the
interconnected networks.
6. Gate Way: In a communications network, a network node equipped for interfacing with another
network that uses different protocols.
A gateway may contain devices such as protocol translators, impedance matching devices, rate
converters, fault isolators, or signal translators as necessary to provide system interoperability. It also
requires the establishment of mutually acceptable administrative procedures between both networks.
A protocol translation/mapping gateway interconnects networks with different network protocol
technologies by performing the required protocol conversions.
EXPERIMENT-3
Aim: Study of network IP
Classification of IP address
Sub netting
Super netting
Requirements: NA
Procedure: Following is required to be study under this practical.
Classification of IP address
As show in figure we teach how the IP addresses are classified and when they are used.
Class
Class A
Class B
Class C
Class D
Class E
Address Range
1.0.0.1 to 126.255.255.254
128.1.0.1 to 191.255.255.254
192.0.1.1 to 223.255.254.254
224.0.0.0 to 239.255.255.255
240.0.0.0 to 254.255.255.254
Supports
Supports 16 million hosts on each of 127 networks.
Supports 65,000 hosts on each of 16,000 networks.
Supports 254 hosts on each of 2 million networks.
Reserved for multicast groups.
Reserved.
Sub netting
Why we Develop sub netting and How to calculate subnet mask and how to identify subnet address.
Super netting
Why we develop super netting and How to calculate supernet mask and how to identify supernet
address.
EXPERIMENT-4
Aim: Connect the computers in Local Area Network.
Requirements: NA
Procedure: On the host computer
On the host computer, follow these steps to share the Internet connection:
1. Log on to the host computer as Administrator or as Owner.
2. Click Start, and then click Control Panel.
3. Click Network and Internet Connections.
4. Click Network Connections.
5. Right-click the connection that you use to connect to the Internet. For example, if you connect to the
Internet by using a modem, right-click the connection that you want under Dial-up / other network
available.
6. Click Properties.
7. Click the Advanced tab.
8. Under Internet Connection Sharing, select the Allow other network users to connect through this
computer's Internet connection check box.
9. If you are sharing a dial-up Internet connection, select the Establish a dial-up connection whenever a
computer on my network attempts to access the Internet check box if you want to permit your computer
to automatically connect to the Internet.
10. Click OK. You receive the following message:
When Internet Connection Sharing is enabled, your LAN adapter will be set to use IP address
192.168.0.1. Your computer may lose connectivity with other computers on your network. If these other
computers have static IP addresses, it is a good idea to set them to obtain their IP addresses
automatically. Are you sure you want to enable Internet Connection Sharing?
11. Click Yes.The connection to the Internet is shared to other computers on the local area network
(LAN).The network adapter that is connected to the LAN is configured with a static IP address of
192.168.0.1 and a subnet mask of 255.255.255.0
On the client computer
To connect to the Internet by using the shared connection, you must confirm the LAN adapter IP
configuration, and then configure the client computer. To confirm the LAN adapter IP configuration,
follow these steps:
1. Log on to the client computer as Administrator or as Owner.
Allenhouse Institute of Technology, Kanpur
EXPERIMENT-5
Aim: Implementation of the Data Link Layer framing method such as bit stuffing in C
Requirements
TURBO C
Theory
Timing is recovered from the signal itself (by the carrier if the signal is analog, or by regular transitions
in the data signal or by a separate clock line if the signal is digital). Scrambling is often used to ensure
frequent transitions needed. The data transmitted may be of any bit length, but is often constrained by
the frame transfer protocol (data link or MAC protocol).
Bit-oriented framing only assumes that bit synchronization has been achieved by the underlying
hardware, and the incoming bit stream is scanned at all possible bit positions for special patterns
generated by the sender. The sender uses a special pattern (a flag pattern) to delimit frames (one flag at
each end), and has to provide for data transparency by use of bit stuffing (see below). A commonly used
flag pattern is HDLC's 01111110 flag as shown in Fig. 3.1.7. The bit sequence 01111110 is used for
both preamble and postamble for the purpose of synchronization. A frame format for bit-oriented
synchronous frame is shown in Fig. 3.1.8. Apart from the flag bits there are control fields.
This field contains the commands, responses and sequences numbers used to maintain the data flow
accountability of the link, defines the functions of the frame and initiates the logic to control the
movement of traffic between sending and receiving stations.
110100010101000001111100101010
01111110 110100010101000001101100101010 01111110
Specific pattern
Specific pattern
to represent
to represent
start of frame
end of frame
10
11011111011110011111011100011111011000
01111110
ALGORITHM
main()
{
char str[100],str1[200];
int n=0,i,j;
cout<<"Enter bit sequence: ";
gets(str);
for(i=0,j=0;i<strlen(str);i++)
{
str1[i+j]=str[i];
if(str[i]=='1')
n++;
else
n=0;
Allenhouse Institute of Technology, Kanpur
11
if(n==5)
{
j++;
str1[i+j]='0';
n=0;
}
}
str1[i+j]=NULL;
cout<<str1;
IMPORTANT QUESTIONS
1. What is bit-stuffing? Why is it used?
2. What is the concept of bit flags?
3. Why is 01111110 chosen for
12
EXPERIMENT-6
Aim: Implementation of the Data Link Layer framing method such as character stuffing in C.
Requirements
TURBO C
Theory:
The first framing method uses a field in the header to specify the number of characters in the frame.
When the data link-layer sees the character count, it knows how many characters follow, and hence
where the end of the frame is. This technique is shown in Fig. for frames of size 6, 4, and 8 characters,
respectively. The trouble with this algorithm is that the count can be garbled by a transmission error.
For example, if the character count of 4 in the second frame becomes 5, as shown in Fig., the
destination will get out of synchronization and will be unable to locate the start of next frame. Even if
the checksum is incorrect so the destination knows that the frame is bad, it still had no way of telling
where the next frame starts. Sending a frame back to the source and asking for retransmission does not
help either, since the destination doesnt know how many characters to skip over to the start of re
transmission. For this reason the character count method is rarely used. Character-oriented framing
assumes that character synchronization has already been achieved by the hardware. The sender uses
special characters to indicate the start and end of frames, and may also use them to indicate header
boundaries and to assist the Receiver gain character synchronization. Frames must be of an integral
character length.
Most commonly, a DLE (data link escape) character is used to signal that the next character is a control
character, with DLE SOH (start of header) used to indicate the start of the frame (it starts with a
header), DLE STX (start of text) used to indicate the end of the header and start of the data portion, and
DLE ETX (end of text) used to indicate the end of the frame.
ACB
DLE STX A C B DLE ETX
A serious problem occurs with this method when binary data, such as object program are being
transmitted. It may easily happen when the characters for DLE STX or DLE ETX occur in the data,
which will interfere with the framing. One way to overcome this problem is to use character stuffing
discussed below.
Allenhouse Institute of Technology, Kanpur
13
When a DLE character occurs in the header or the data portion of a frame, the sender must somehow let
the receiver know that it is not intended to signal a control character.
The sender does this by inserting an extra DLE character after the one occurring inside the frame, so
that when the receiver encounters two DLEs in a row, it immediately deletes one and interpret the other
as header or data. This is shown in Fig. Note that since the receiver has character synchronization, it
will not mistake a DLE pattern that crosses a byte boundary as a DLE signal
A B C DLESTX D
DLESOH DLESTX A B C ESC DLESTX D DLEEOT DLEEOH
The main disadvantage of this method is that it is closely tied to 8-bit characters in general and the
ASCII character code in particular. As networks grow, this disadvantage of embedding the character
code in framing mechanism becomes more and more obvious, so a new technique had to be
developed to allow arbitrary sized character.
ALGORITHM
char str[100],str1[200];
int n=0,i,j;
cout<<"Enter character sequence: "; gets(str);
if (char==DLESTX,EOTSTX,esc)
for(i=0,j=0;i<strlen(str);i++)
{
str1[i+j]=str[i];
if(str[i]=='esc esc') n++;
else
n=0;
if(n==5)
{
j++;
str1[i+j]='esc stx/EOTSTX'; n=0;
}
}
str1[i+j]=NULL;
cout<<str1;
IMPORTANT QUESTIONS
Allenhouse Institute of Technology, Kanpur
14
15
EXPERIMENT-7
Aim: Implementation of CRC In C.
Requirements
TURBO C
Theory:
Cyclic Redundancy Check
Error detection is important whenever there is a non-zero chance of your data getting corrupted.
Whether it's an Ethernet packet or a file under the control of your application, you can add a piece of
redundant information to validate it.
The simplest example is a parity bit. Many computers use one parity bit per byte of memory. Every
time the byte gets written, the computer counts the number of non-zero bits in it. If the number is ven, it
sets the ninth parity bit, otherwise it clears it. When reading the byte, the computer counts the number
of non-zero bits in the byte, plus the parity bit. If any of the nine bits is flipped, the sum will be odd and
the computer will halt with a memory error. (Of course, if two bits are flipped--a much rarer
occurrence--this system will not detect it.) For messages longer than one byte, you'd like to store more
than one bit of redundant information. You might, for instance, calculate a checksum. Just add together
all the bytes in the message and append (or store somewhere else) the sum. Usually the sum is
truncated to, say, 32 bits. This system will detect many types of corruption with a reasonable
probability. It will, however, fail badly when the message is modified by inverting or swapping groups
of bytes. Also, it will fail when you add or remove null bytes.
Calculating a Cyclic Redundancy Check is a much more robust error checking algorithm.
Optimized CRC Calculation
The main trick in optimizing the CRC calculation is to operate on bytes rather than bits. Look at the top
8 bits of the CRC register. Scan this byte from left to right. Every time you find a non-zero bit, you
XOR the key into the register at a bit offset such that this bit is turned off by the top invisible bit of the
key. (Notice that this operation can modify the remaining bits in the byte you are scanning.) XORing is
like addition, it is associative and you can do it in any order. So you can XOR together a bunch of
shifted keys corresponding to a given byte and store it for later. This is simply a section of the slow
CRC algorithm applied to our pre-calculation:
Allenhouse Institute of Technology, Kanpur
16
Algorithm
#ifndef CM_DONE
#define CM_DONE
#ifndef DONE_STYLE
typedef unsigned bool;
typedef unsigned long ulong;
typedef unsigned char*p_ubyte; #ifndef TRUE
#define FALSE 0
#define TRUE 1
#endif
#define P_(A) A
#endif
/*
crc model abstract type the following type stores the context of an
executing instance of the model algorithm.most of the fieldsare
Allenhouse Institute of Technology, Kanpur
17
model parameters which must be set before the first initializing call
to cm_ini
*/
typedef struct
{
int cm_width;
//width in bits
ulong cm_poly;
//algorithm's polynomial
ulong cm_init;
bool cm_refin;
bool cm_refot;
ulong cm_xorot;
ulong cm_reg;
}cm_t;
//name of structure
P_((p_cm_t
p_cm));
//Following
functions initialize crc model argument instance.
//All parameter fields
must be set before calling this function.
void cm_nxt
P_((p_cm_t p_cm,int ch));
void cm_blk
P_((p_cm_t p_cm,p_ubyte blk_adr,ulong blk_len));
ulong cm_crc P_((p_cm_t p_cm));
ulong cm_tab P_((p_cm_t p_cm,int index));
#endif
IMPORTANT QUESTIONS
1. What is CRC and why it is used?
2. In which layer of the OSI model is the CRC implemented?
3. What division type is used in the CRC check?
4. How are the CRC polynomials generated?
EXPERIMENT-8
Aim: Implementation of a Hamming (7,4) code to limit the noise. We have to code the 4 bit data in to
7 bit data by adding 3 parity bits. Implementation will be in C..
18
Requirements
TURBO C
Theory:
Concept of error-correction can be easily understood by examining the simplest case of single-bit
errors. As we have already seen that a single-bit error can be detected by addition of a parity bit
(VRC) with the data, which needed to be send. A single additional bit can detect error, but its not
sufficient enough to correct that error too. For correcting an error one has to know the exact position
of error, i.e. exactly which bit is in error (to locate the invalid bits). For example, to correct a single-bit
error in an ASCII character, the error correction must determine which one of the seven bits is in error.
To this, we have to add some additional redundant bits.
To calculate the numbers of redundant bits (r) required to correct d data bits, let us find out the
relationship between the two. So we have (d+r) as the total number of bits, which are to be
transmitted; then r must be able to indicate at least d+r+1 different values. Of these, one value means
no error, and remaining d+r values indicate error location of error in each of d+r locations. So, d+r+1
states must be distinguishable by r bits, and r bits can indicates 2r states. Hence, 2r must be greater
than d+r+1.
2r >= d+r+1
The value of r must be determined by putting in the value of d in the relation. For example, if d is 7,
then the smallest value of r that satisfies the above relation is 4. So the total bits, which are to be
transmitted is 11 bits (d+r = 7+4 =11).
Now let us examine how we can manipulate these bits to discover which bit is in error. A technique
developed by R.W.Hamming provides a practical solution. The solution or coding scheme he
developed is commonly known as Hamming Code. Hamming code can be applied to data units of any
length and uses the relationship between the data bits and redundant bits as discussed
P7
D6
P: PARITY BIT
D5
D4
D3
P2
P1
D: DATA BIT
Basic approach for error detection by using Hamming code is as follows:
To each group of m information bits k parity bits are added to form (m+k) bit code as shown in
Fig. 3.2.8.
Allenhouse Institute of Technology, Kanpur
19
Figure shows how hamming code is used for correction for 4-bit numbers (d4d3d2d1) with the help of
three redundant bits (r3r2r1). For the example data 1010, first r1 (0) is calculated considering the parity
of the bit positions, 1, 3, 5 and 7. Then the parity bits r2 is calculated considering bit positions 2, 3, 6
and 7. Finally, the parity bits r4 is calculated considering bit positions 4, 5, 6 and 7 as shown. If any
corruption occurs in any of the transmitted code 1010010, the bit position in error can be found out by
calculating r3r2r1 at the receiving end. For example, if the received code word is 1110010, the
recalculated value of r3r2r1 is 110, which indicates that bit position in error is 6, the decimal value of
110.
Algorithm
int getcheckbits(int n, int k)
Allenhouse Institute of Technology, Kanpur
20
{
return n-k;
}
int checkblocklength(int n, int q)
{
if(n == pow(2,q)-1)
return 1;
else return 0;
}
int getmessagebits(int n, int q)
{
return n-q;
}
void main()
{
int n=7,k=4,dmin=3;
clrscr();
if(checkblocklength(n,getcheckbits(n,k)))
if(getmessagebits(n,getcheckbits(n,k)))
{
cout<<"Block Length is correct."<<endl;
cout<<"Number of errors detected = "<<dmin-1;
}
Important Questions
1.
2. What are the positions of parity bits? On what basis are they? Decided?
3. How is the error corrected in hamming code
EXPERIMENT-9
Aim: To Implement 2 Dimensional Parity Checker In C
Requirements
TURBO C
21
Theory:
Performance can be improved by using two-dimensional parity check, which organizes the block of bits
in the form of a table. Parity check bits are calculated for each row, which is equivalent to a simple
parity check bit. Parity check bits are also calculated for all columns then both are sent along with the
data. At the receiving end these are compared with the parity bits calculated on the received data
Two- Dimension Parity Checking increases the likelihood of detecting burst errors. As we have shown
in Fig. that a 2-D Parity check of n bits can detect a burst error of n bits. A burst error of more than n
bits is also detected by 2-D Parity check with a high probability.
There is, however, one pattern of error that remains elusive. If two bits in one data unit are damaged
and two bits in exactly same position in another data unit are also damaged, the 2-D Parity check
checker will not detect an error. For example, if two data units: 11001100 and 10101100. If first and
second from last bits in each of them is changed, making the data units as 01001110 and 00101110, the
error cannot be detected by 2-D Parity check.
Algorithm:
1. input one bit of streams from user
2. check it to be of at least one byte
3. padd one extra bit in the bit stream depending on number of odd / even ones
4. now check it t be of the same
5. if
6. {
Allenhouse Institute of Technology, Kanpur
22
7. same == no error
8. else
9. error at bit stream x
Important Questions
Question-1: Explain the parity checker?
Question-2: Explain about the types of error detected by parity checker?
Question-3: Explain the concept of padding extra bit?
EXPERIMENT-10
Aim: Implementation of LZW compression algorithm in C.
Requirements
TURBO C
23
24
D ^ D 259 D^
^W
^W E 256 260 ^WE
E ^ E 261 E^
^W
^W E
^WE E 260 262 ^WEE
E^
E^ W 261 263 E^W
WE
WE B 257 264 WEB
B ^ B 265 B^
^W
^W E
^WE T 260 266 ^WET
T EOF T
A 19-symbol input has been reduced to 7-symbol plus 5-code output. Each code/symbol will
need more than 8 bits, say 9 bits.
Usually, compression doesn't start until a large number of bytes (e.g., > 100) are read in.
The LZW Decompression Algorithm is as follows:
read a character k;
output k;
w = k;
while ( read a character k )
/* k could be a character or a code. */
Allenhouse Institute of Technology, Kanpur
25
{
entry = dictionary entry for k;
output entry;
add w + entry[0] to dictionary;
w = entry;
}
Example (continued):
Input string is "^WED<256>E<260><261><257>B<260>T".
w k output index symbol
------------------------------------------^^
^ W W 256 ^W
W E E 257 WE
E D D 258 ED
D <256> ^W 259 D^
<256> E E 260 ^WE
E <260> ^WE 261 E^ <260> <261> E^ 262 ^WEE
<261> <257> WE 263 E^W
<257> B B 264 WEB
B <260> ^WE 265 B^
<260> T T 266 ^WET
Problem: What if we run out of dictionary space?
Solution 1: Keep track of unused entries and use LRU
Solution 2: Monitor compression performance and flush dictionary when performance is
poor.
Implementation Note: LZW can be made really fast; it grabs a fixed number of bits from input
stream, so bit parsing is very easy. Table lookup is automatic.
26
ALGORITHM
w := NIL;
while (there is input)
{
K := next symbol from input;
if (wK exists in the dictionary)
{
w := wK;
}
else
{
output (index(w));
add wK to the dictionary;
w := K;
}
}
Important Questions:
Question-1: What is LZW? Why is it used?
Question-2: What is the difference between LZW and LZ77?
Question-3: What is the efficiency of data compression by LZW?
EXPERIMENT-11
Aim: Program in C to encrypt 64-bit text using DES algorithm
Requirements
TURBO C
27
Theory:
DES (the Data Encryption Standard) is a symmetric block cipher developed by IBM. The algorithm
uses a 56-bit key to encipher/decipher a 64-bit block of data. The key is always presented as a 64-bit
block, every 8th bit of which is ignored. However, it is usual to set each 8th bit so that each group of 8
bits has an odd number of bits set to 1. The algorithm is best suited to implementation in hardware,
probably to discourage implementations in software, which tend to be slow by comparison. However,
modern computers are so fast that satisfactory software implementations are readily available.
DES is the most widely used symmetric algorithm in the world, despite claims that the key length is too
short. Ever since DES was first announced, controversy has raged about whether 56 bits is long enough
to guarantee security. The key length argument goes like this. Assuming that the only feasible attack on
DES is to try each key in turn until the right one is found, then 1,000,000 machines each capable of
testing 1,000,000 keys per second would find (on average) one key every 12 hours. Most reasonable
people might find this rather comforting and a good measure of the strength of the algorithm. Those
who consider the exhaustive key-search attack to be a real possibility (and to be fair the technology to
do such a search is becoming a reality) can overcome the problem by using double or triple length keys.
In fact, double length keys have been recommended for the financial industry for many years. Use of
multiple length keys leads us to the Triple-DES algorithm, in which DES is applied three times. If we
consider a triple length key to consist of three 56-bit keys K1, K2, K3 then encryption is as follows:
Encrypt with K1
Decrypt with K2
Encrypt with K3
Decryption is the reverse process:
Decrypt with K3
Encrypt with K2
Decrypt with K1
Setting K3 equal to K1 in these processes gives us a double length key K1, K2.
Setting K1, K2 and K3 all equal to K has the same effect as using a single-length (56-bit key). Thus it is
possible for a system using triple-DES to be compatible with a system using single-DES.
28
ALGORITHM
1. Ask from user about the word to encrypt
2. pass it on to the DES encrypter
3. encrpt using 64 bit DES algo
4. print the output
Important Questions
1. How many types of DES algos are there?
2. What is the difference between triple DES and normal DES?
Allenhouse Institute of Technology, Kanpur
29
3. Which of the following algorithm's RSA or DES will you prefer for 64 bit Encoding? Why.
30