Engineering
Laboratory Manual
2. Implement a program using Python for the data link layer farming methods
such as (a) Byte Stuffing (b) Bit Stuffing (c) Character Count
3. Program to retrieve the IP address and network name by using DNS Server
4. Program to communicate with any network server to get the reply for the
given message.
5. (a) Program to calculate the parity bit for the given data word
(b) Program to calculate the checksum for the given data word using generator
Polynomial.
AIM: Implementation of data link framing methods for character stuffing in a frame.
LOGIC:
In a character data frame if a DLE is encountered between the data it is doubled and transmitted
at the receiver side it is de stuffed and original data is obtained.
Description:
In the second method, each frame starts with the ASCII character sequence DLE STX and ends
with the sequence DLE ETX.(where DLE is Data Link Escape, STX is Start of TeXt and ETX is
End of TeXt.) This method overcomes the drawbacks of the character count method. If the
destination ever loses synchronization, it only has to look for DLE STX and DLE ETX
characters. If however, binary data is being transmitted then there exists a possibility of the
characters DLE STX and DLE ETX occurring in the data. Since this can interfere with the
framing, a technique called character stuffing is used. The sender's data link layer inserts an
ASCII DLE character just before the DLE character in the data. The receiver's data link layer
removes this DLE before this data is given to the network layer. However character stuffing is
closely associated with 8-bit characters and this is a major hurdle in transmitting arbitrary sized
characters.
Character Stuffing
Souce Code:
while(True):
s=raw_input('enter ur payload: ').split();
a='flag'
b=''
for x in s:
if x==a:
x='esc '+a
if x=='esc':
x='esc'+' '+x
b=' '+b+' '+x
print b
Output:
enter ur payload: cn flag
cn esc flag
b. Bit Stuffing
AIM: Implementation of the data link framing methods for the bit stuffing in a frame.
LOGIC: Stuffing a 0 bit in a data frame in order to differentiate the header, trailer and data.
Description:
The third method allows data frames to contain an arbitrary number of bits and allows character
codes with an arbitrary number of bits per character. At the start and end of each frame is a flag
byte consisting of the special bit pattern 01111110.Whenever the sender's data link layer
encounters five consecutive 1s in the data, it automatically stuffs a zero bit into the outgoing bit
stream. This technique is called bit stuffing. When the receiver sees five consecutive 1s in the
incoming data stream, followed by a zero bit, it automatically destuffs the 0 bit. The boundary
between two frames can be determined by locating the flag pattern.
AIM: Implementation of the data link framing methods for the bit stuffing in a frame.
LOGIC: Stuffing a 0 bit in a data frame in order to differentiate the header, trailer and data.
Description:
The third method allows data frames to contain an arbitrary number of bits and allows character
codes with an arbitrary number of bits per character. At the start and end of each frame is a flag
byte consisting of the special bit pattern 01111110.Whenever the sender's data link layer
encounters five consecutive 1s in the data, it automatically stuffs a zero bit into the outgoing bit
stream. This technique is called bit stuffing. When the receiver sees five consecutive 1s in the
incoming data stream, followed by a zero bit, it automatically destuffs the 0 bit. The boundary
between two frames can be determined by locating the flag pattern.
The Internet Domain Name Service (DNS) can translate host names into equivalent IP addresses
and vice versa, as needed by various Internet programs.
Domain Name Service (DNS)
On the Internet, many communications programs deal only with IP addresses, yet allow their
users to specify machines in terms of their host names (or alias host names). Or a program which
already knows the IP address must determine the domain name for the network to which the
machine is connected. Such programs must somehow convert the host names into IP addresses
(or vice versa) behind the scenes. How do they achieve this translation between IP addresses and
host names?
The mapping of host names to IP addresses is handled through a service called Domain Name
Service (DNS). Rather than require individual machines, applications, or users to keep up with
the constant changes in host names and IP addresses, a series of special DNS servers across the
world (known as "name servers") keep track of the name/address information for all the
computers on the Internet. Applications that need to determine an IP address from a host name (or
vice versa) contact the local "name server" to supply this information.
Program:
import socket
ip = socket.gethostbyname('Localhost')
ip1 = socket.gethostbyname('www.google.com')
ip2 = socket.gethostbyaddr('www.kluniversity.in')
print(ip)
print(ip1)
print(ip2)
Expected Output:
127.0.0.1
172.217.26.196
('KLCEBLADE4', [], ['49.156.157.71