You are on page 1of 11

COMPUTER SCIENCE AND ENGINEERING

FACULTY OF ENGINEERING AND TECHNOLOGY


COMPUTER NETWOTKS (303105304)
ENROLLMENT NO: -2203031241019

PRACTICAL – 04
AIM: Data Link Layer (Error Correction).
 Data Link Layer (Error Correction): Write a program to implement error detection and correction
using HAMMING code concept. Make a test rum to input data stream and verify error
correction feature.
 Hamming code is a set of error-correction codes that can be used to detect and correct the errors
that can occur when the data is moved or stored from the sender to the receiver. It is a technique
developed by R.W. Hamming for error correction.
Steps:
1. Enter the Data to be transmitted
2. Calculate the no of redundant bits required
3. Determine the parity bits
4. Create error data for testing
5. Check for errors
If the message contains m𝑚number of data bits, r𝑚number of redundant bits are added to it so that m𝑚 is
able to indicate at least (m + r+ 1) different states. Here, (m + r) indicates location of an error in each of (𝑚
+ 𝑚) bit positions and one additional state indicates no error. Since, r𝑚 bits can indicate 2r𝑚 states, 2r𝑚
must be at least equal to (m + r + 1). Thus the following equation should hold 2r ≥ m+r+1 Step 2 −
Positioning the redundant bits.
The redundant bits are parity bits. A parity bit is an extra bit that makes the number of 1s either even or
odd. The two types of parity are –

Even Parity: Here the total number of bits in the message is made even.
Odd Parity: Here the total number of bits in the message is made odd.
Each redundant bit, ri, is calculated as the parity, generally even parity, based upon its bit position. It
covers all bit positions whose binary representation includes a 1 in the ith position except the position of
ri.

Decoding a message in Hamming Code:


Once the receiver gets an incoming message, it performs recalculations to detect errors and correct them.
The steps for recalculation are −

Step 1 − Calculation of the number of redundant bits:


Using the same formula as in encoding, the number of redundant bits are ascertained.2r
≥ m + r + 1 where m is the number of data bits and r is the number of redundant bits.

Step 2 − Positioning the redundant bits:


The r redundant bits placed at bit positions of powers of 2, i.e. 1, 2, 4, 8, 16 etc. Step 3 − Parity checking
The decimal equivalent of the parity bits binary values is calculated. If it is 0, there is no

CN|4B18-AI|PIET 17
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHNOLOGY
COMPUTER NETWOTKS (303105304)
ENROLLMENT NO: -2203031241019
error. Otherwise, the decimal value gives the bit position which has error. For example, if c1c2c3c4 =
1001, it
implies that the data bit at position 9, decimal equivalent of 1001, has error. The bit is flipped to get the
correct message.

Hamming Code in Python:

def calcRedundantBits(m):
For I in range(m):
if(2**i>=m+i+1):
return i
def posRedundantBits(data,r):
j=0
k=1
m= len(data)
res = ‘‘
for i in range (1, m+r+1):
if (i ==2**j):
res = res+‘0’
j += 1
else:
res= res +data[-1*k]
k+=1
return res[::-1]
def calcParityBits(arr, r):
n = len(arr)
for i in range(r):
val = 0
for j in range(1, n + 1):
if(j & (2**i) == (2**i)):
val = val ^ int(arr[-1 * j])
arr = arr[:n-(2**i)] + str(val) + arr[n-(2**i)+1:]
CN|4B18-AI|PIET 18
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHNOLOGY
COMPUTER NETWOTKS (303105304)
ENROLLMENT NO: -2203031241019
return arr
def detectError(arr, nr): n = len(arr)
res = 0
for i in range(nr):
val = 0
for j in range(1, n + 1):
if(j & (2**i) == (2**i)):
val = val ^ int(arr[-1 * j]) res = res + val*(10**i) return int(str(res), 2)
data = '1011001'
m = len(data)
r = calcRedundantBits(m)
arr = posRedundantBits(data, r)
arr = calcParityBits(arr, r)
print("Data transferred is " + arr)
arr = '11101001110
print("Error Data is " + arr)
correction = detectError(arr, r)
if(correction==0):
print("There is no error in the received message.")
else:
print("The position of error is ",len(arr)-correction+1,"from the left")

OUTPUT:

CN|4B18-AI|PIET 19
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHNOLOGY
COMPUTER NETWOTKS (303105304)
ENROLLMENT NO: -2203031241019

PRACTICAL – 05

AIM: Virtual LAN: Simulate Virtual LAN(VLAN) configuration using CISCO Packet Tracer
Simulation.
Procedure:
Step 1: Take 2 Switches and 6 PC
Step 2: Connect the pc’s to Switch and Switch to Router with copper straight-through wire.
Step 3: Assign ip’s to pc’s accordingly pc0(192.168.1.2), pc1(192.168.1.3) and pc2(192.168.1.4)
Step 4: Assign ip’s in pc3(192.168.1.6), pc4(192.168.1.7) and pc5(192.168.1.8)

Now divide the network into two virtual Local Area Networks, VLAN1 & VLAN2 VLAN1 PCs:
PC1,PC2,PC3
VLAN2 P S: PC0,PC4,PC5
VLAN Configuration on Switch 1
After PC IP configurations, now, we can start our VLAN Packet Tracer Configuration steps. Here, we will
follow the below steps:
1. We will set access ports that will access specific VLANs. We will do this with “switchport mode
access” command under these interfaces.

2. We will also set the VLAN, that this port will access.
3. After that, we will set the trunk port that will carry multiple VLANs with “switchport mode
trunk” command.

4. Then we will also set this port with “no negotiate” command to prevent
negotiation about the port role.

CN|4B18-AI|PIET 20
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHNOLOGY
COMPUTER NETWOTKS (303105304)
ENROLLMENT NO: -2203031241019
5. Lastly, we will set the allowed VLANs with “switchport trunk allowed vlan”
command on this trunk and save our configuration.
Switch 1(config)# interface fastEthernet 0/2
Switch 1(config-if)# switchport mode access
Switch 1(config-if)# switchport access vlan 2
Switch 1(config)# interface fastEthernet 0/3
Switch 1(config-if)# switchport mode access
Switch 1(config-if)# switchport access vlan 2
Switch 1(config)# interface fastEthernet 0/4
Switch 1(config-if)# switchport mode access
Switch 1(config-if)# switchport access vlan 3
Switch 1(config)# interface fastEthernet 0/1
Switch 1(config-if)# switchport mode trunk
Switch 1(config-if)# switchport nonegotiate
Switch 1(config-if)# switchport trunk allowed vlan 2-4

Switch 1# copy running-config startup-config

The excepted outcome should be like the below picture; the command is do show history
after exiting from config t and then config.

CN|4B18-AI|PIET 21
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHNOLOGY
COMPUTER NETWOTKS (303105304)
ENROLLMENT NO: -2203031241019
VLAN Configuration on Switch 2
After configuring the first switch, we will configure switch 2 similar to switch 1 as below. Switch
2(config)# interface fastEthernet 0/2
Switch 2(config-if)# switchport mode access Switch
2(config-if)# switchport access vlan 3 Switch 2(config)#
interface fastEthernet 0/3 Switch 2(config-if)# switchport
mode access Switch 2(config-if)# switchport access vlan 2
Switch 2(config)# interface fastEthernet 0/4 Switch
2(config-if)# switchport mode access Switch 2(config-if)#
switchport access vlan 2 Switch 2(config)# interface
fastEthernet 0/1 Switch 2(config-if)# switchport mode
trunk Switch 2(config-if)# switchport nonegotiate
Switch 2(config-if)# switchport trunk allowed vlan 2-4 Switch 2# copy
running-config startup-config
The excepted outcome should be like the below picture; the command is do show historyafter exiting from
config t and then config.

CN|4B18-AI|PIET 22
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHNOLOGY
COMPUTER NETWOTKS (303105304)
ENROLLMENT NO: -2203031241019
Checking VLAN Configuration
Our last step of VLAN configuration is verification. to verify our VLAN Packet Tracer Configuration,
we will use verification commands like “show vlan brief“, “show interfaces“, “show interfaces trunk” etc.
The expected outcome after sending packet datagram units, from PC1(vlan1) TO PC5(vlan2) and PC1
TO PC2 is successful.

CN|4B18-AI|PIET 23
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHNOLOGY
COMPUTER NETWOTKS (303105304)
ENROLLMENT NO: -2203031241019

PRACTICAL – 06

AIM: Configuration of wireless LAN(WLAN) using CISCO Packet Tracer.


PROCEDURE:
Take a wireless router named WRT300N from /Network devices/Wireless devices.Now, Connect the
wireless router0 with End devices such as computers and laptops. Here Unlike every Other Wired
connection do not make wired connections. Instead follow the below steps, Double-click on the router
and go to the graphical user interface section.
Where we can
allocate Any classes’/classless IP Addresses.

In GUI, in the wireless section we can configure the SSID, Network mode and Radio Band.

For implementing security on wireless network go to the config section in the router, where we can
implement Many types of Password methodologies. WPA-PSK,WEP etc.

CN|4B18-AI|PIET 24
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHNOLOGY
COMPUTER NETWOTKS (303105304)
ENROLLMENT NO: -2203031241019

Now that the router is configured we have to configure our end devices(computers and laptops) Click on
the PC and go to the physical section then turn off the power. Remove the PT-HOST Module From the
bottom and insert WMP300N module at the bottom of the CPU. As shown in the figure.

After this step the PC can be able to connect to wireless internet connections. For that gointo desktop section. In the
PC then select PC WIRELESS

CN|4B18-AI|PIET 25
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHNOLOGY
COMPUTER NETWOTKS (303105304)
ENROLLMENT NO: -2203031241019
Connect to the wireless network, enter the password. Now it is connected to the wireless network.
Proceed with the same step again with another Computer.
Remove the PT-HOST Module and insert WMP300N wireless module to support wireless connections.

Then, go to Desktop/PC-Wireless/ and connect with the same network.

Now that our computers are configured to connect the wireless network. Configure the laptop the same
way.
First, turn off the power of laptop and then remove PT-LAPTOP module, drag it on the main menu of
modules, Select WPC300N insert it on to the laptop.
For connecting it to the network follow the same steps as a computer.
/desktop/PC-Wireless. Find the network names LIGHT then click connect, enter WEP Password. Now
it’s connected.

CN|4B18-AI|PIET 26
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHNOLOGY
COMPUTER NETWOTKS (303105304)
ENROLLMENT NO: -2203031241019

Now all our End-devices are connected to the WRT300N wireless router. To verify the connection.
A PDU(Packet Datagram Unit) has been sent from,

Laptop0 – PC4
PC3 – Laptop0
PC4 – PC3
All the three packet transmissions are successful. We can say we correctly configured the
WLAN network.

CN|4B18-AI|PIET 27

You might also like