0% found this document useful (0 votes)
15 views

Dccn lab 2024 (1)

Uploaded by

Shaik
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)
15 views

Dccn lab 2024 (1)

Uploaded by

Shaik
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
You are on page 1/ 63

Data Communications & Computer Networks Lab

Andhra University College of Engineering

Dr. G. Sharmila Sujatha

Assistant Professor
OF COMPUTER SCIENCE DEPARTMENT
&
Ms.S.SIREESHA(SWTA)
OF COMPUTER SCIENCE DEPARTMENT
Module II: Network simulator (NS)/ C++

1. Implementation of Error Detection / Error Correction Techniques


THEORY:
Error detection and correction techniques are essential in ensuring that data is transmitted
accurately and reliably, especially in digital communication systems. When data is sent from
one device to another, it can be affected by noise or other interferences, leading to errors in the
transmitted data. To maintain the integrity of the data, error detection and correction methods
are employed.

**Error detection** involves identifying whether an error has occurred during transmission.
One common method used is the **parity check**. In this technique, a parity bit is added to
the data before transmission. The parity bit can be either even or odd, depending on the chosen
method. After the data is received, the parity is checked to see if it matches the expected value.
If it does not, an error is detected. Another popular error detection method is the **Cyclic
Redundancy Check (CRC)**, where a sequence of redundant bits is appended to the data,
which the receiver then uses to detect errors.

**Error correction** goes a step further by not only detecting the error but also correcting it.
The **Hamming code** is an example of an error correction method. It works by adding
redundant bits to the data in a way that allows the receiver to determine both the presence and
the location of an error, enabling the system to correct the error automatically. This process
ensures that the data is accurate without needing to resend it.

These techniques are crucial in various fields, such as telecommunications, data storage, and
computer networks, where the accuracy of data is paramount. By using error detection and
correction techniques, systems can significantly reduce the impact of errors, ensuring that
communication is more reliable and efficient.

CODE:
1. Parity Bit (Error Detection)
#include <iostream>
#include <string>
char calculateParityBit(std::string data) {
int count = 0;
for (char bit : data) {
if (bit == '1') {
count++;
}
}
return (count % 2 == 0) ? '0' : '1';
}
int main() {
std::string data = "1010101";
char parityBit = calculateParityBit(data);

std::cout << "Data: " << data << "\n";


std::cout << "Parity Bit (Even): " << parityBit << "\n";
data[3] = (data[3] == '0') ? '1' : '0';
parityBit = calculateParityBit(data);
std::cout << "Modified Data: " << data << "\n";
std::cout << "New Parity Bit: " << parityBit << "\n";
return 0;
}
O/P:
Parity Bit (Even): 0
Modified Data: 1011101
New Parity Bit: 1

B) Hamming Code (Error Detection and Correction):


#include <iostream>
#include <vector>
#include <cmath>
int calculateParityBits(int dataBits) {
int r = 0;
while ((1 << r) < (dataBits + r + 1)) {
r++;
}
return r;
}
std::vector<int> createHammingCode(std::vector<int> data) {
int m = data.size();
int r = calculateParityBits(m);
int n = m + r;

std::vector<int> hammingCode(n, 0);


for (int i = 0, j = 0; i < n; i++) {
if ((i + 1) && !((i + 1) & i)) {
continue;
}
hammingCode[i] = data[j++];
}
for (int i = 0; i < r; i++) {
int position = (1 << i) - 1;
for (int j = 0; j < n; j++) {
if (j & (1 << i)) {
hammingCode[position] ^= hammingCode[j];
}
}
}

return hammingCode;
}
int detectAndCorrectError(std::vector<int>& hammingCode) {
int n = hammingCode.size();
int r = 0;
while ((1 << r) < (n + 1)) {
r++;
}

int errorPosition = 0;

for (int i = 0; i < r; i++) {


int parity = 0;
for (int j = 0; j < n; j++) {
if (j & (1 << i)) {
parity ^= hammingCode[j];
}
}
if (parity != 0) {
errorPosition += (1 << i);
}
}

if (errorPosition > 0 && errorPosition <= n) {


hammingCode[errorPosition - 1] ^= 1; // Correct the error
}

return errorPosition;
}

int main() {
std::vector<int> data = {1, 0, 1, 1};
std::vector<int> hammingCode = createHammingCode(data);
std::cout << "Hamming Code: ";
for (int bit : hammingCode) {
std::cout << bit;
}
std::cout << "\n";
hammingCode[5] ^= 1;

int errorPosition = detectAndCorrectError(hammingCode);

if (errorPosition == 0) {
std::cout << "No errors detected.\n";
} else {
std::cout << "Error detected at position: " << errorPosition << "\n";
std::cout << "Corrected Hamming Code: ";
for (int bit : hammingCode) {
std::cout << bit;
}
std::cout << "\n";
}
return 0;
}
O/P:
Hamming Code: 1010011
Error detected at position: 4
Corrected Hamming Code: 1011001

C) CRC (Cyclic Redundancy Check):


#include <iostream>
#include <string>
std::string xorStrings(std::string a, std::string b) {
std::string result = "";
for (int i = 1; i < b.size(); i++) {
result += (a[i] == b[i]) ? '0' : '1';
}
return result;
}

std::string mod2Division(std::string dividend, std::string divisor) {


int pick = divisor.size();
std::string tmp = dividend.substr(0, pick);

while (pick < dividend.size()) {


if (tmp[0] == '1') {
tmp = xorStrings(divisor, tmp) + dividend[pick];
} else {
tmp = xorStrings(std::string(pick, '0'), tmp) + dividend[pick];
}
pick++;
}

if (tmp[0] == '1') {
tmp = xorStrings(divisor, tmp);
} else {
tmp = xorStrings(std::string(pick, '0'), tmp);
}

return tmp;
}

std::string encodeCRC(std::string data, std::string divisor) {


int l_key = divisor.size();
std::string appendedData = data + std::string(l_key - 1, '0');
std::string remainder = mod2Division(appendedData, divisor);

return data + remainder;


}

bool verifyCRC(std::string data, std::string divisor) {


std::string remainder = mod2Division(data, divisor);
return remainder == std::string(remainder.size(), '0');
}

int main() {
std::string data = "1101011111";
std::string divisor = "10011";
std::string encodedData = encodeCRC(data, divisor);
std::cout << "Encoded Data: " << encodedData << "\n";
bool isValid = verifyCRC(encodedData, divisor);
std::cout << "CRC Verification: " << (isValid ? "No Error" : "Error Detected") <<
"\n";
encodedData[4] = (encodedData[4] == '0') ? '1' : '0';
isValid = verifyCRC(encodedData, divisor);
std::cout << "CRC Verification after Error: " << (isValid ? "No Error" : "Error
Detected") << "\n";

return 0;
}

O/P:
Encoded Data: 11010111110010
CRC Verification: No Error
CRC Verification after Error: Error Detected

2. Implementation of Stop and Wait Protocol and sliding window


THEORY:
Stop-and-Wait Protocol
Theory:
The Stop-and-Wait protocol is a simple flow control protocol used in data
communication. It operates as follows:
1. Sender sends a frame (packet) to the receiver and waits for an acknowledgment
(ACK) before sending the next frame.
2. Receiver receives the frame, processes it, and sends an ACK back to the sender.
3. The Sender only sends the next frame once it receives the ACK for the previous
frame.
4. If the Sender does not receive an ACK within a certain time period (timeout), it
assumes the frame was lost and retransmits it.
Advantages:
 Simplicity: The Stop-and-Wait protocol is easy to understand and implement.
 Reliable Data Transfer: Ensures that each frame is received correctly before
moving to the next.
Disadvantages:
 Inefficiency: The sender has to wait for the ACK after every frame, leading to low
utilization of the communication link, especially for long-distance communications
where the delay (latency) is high.
Sliding Window Protocol
Theory:
The Sliding Window protocol is a more efficient flow control mechanism that allows
multiple frames to be sent before requiring an acknowledgment. It operates as follows:
1. Window Size: Both sender and receiver agree on a window size (n). The window
defines the number of frames that can be sent before an acknowledgment is
required.
2. Sender: Sends multiple frames up to the window size without waiting for an ACK
for each one.
3. Receiver: Receives the frames and sends ACKs. The receiver's window slides
forward as frames are acknowledged, allowing the sender to send new frames.
4. Acknowledgments: The ACKs may be cumulative, acknowledging the receipt of
all frames up to a certain point.
5. Retransmission: If the sender doesn't receive an ACK for a frame within a timeout
period, it retransmits that frame.
Types of Sliding Window Protocols:
a. Go-Back-N (GBN):
 The sender can send multiple frames specified by the window size without waiting
for an ACK.
 If a frame is lost or an error is detected, the sender goes back and retransmits all
frames starting from the lost frame.
b. Selective Repeat (SR):
 Similar to GBN but more efficient.
 The sender retransmits only the frames that were lost or corrupted, not all
subsequent frames.
Advantages:
 Higher Efficiency: Better utilization of the communication link compared to Stop-
and-Wait.
 Flexibility: Allows multiple frames to be in transit, reducing idle time.
Disadvantages:
 Complexity: Requires more complex handling of frame sequence numbers and
ACKs.
CODE:
STOP AND WAIT PROTOCOL
#include<iostream>
#include <time.h>
#include <cstdlib>
#include<ctime>
#include <unistd.h>
using namespace std;
class timer {
private:
unsigned long begTime;
public:
void start() {
begTime = clock();
}
unsigned long elapsedTime() {
return ((unsigned long) clock() - begTime) / CLOCKS_PER_SEC;
}
bool isTimeout(unsigned long seconds) {
return seconds >= elapsedTime();
}
};
int main()
{
int frames[] = {1,2,3,4,5,6,7,8,9,10};
unsigned long seconds = 5;
srand(time(NULL));
timer t;
cout<<"Sender has to send frames : ";
for(int i=0;i<10;i++)
cout<<frames[i]<<" ";
cout<<endl;
int count = 0;
bool delay = false;
cout<<endl<<"Sender\t\t\t\t\tReceiver"<<endl;
do
{
bool timeout = false;
cout<<"Sending Frame : "<<frames[count];
cout.flush();
cout<<"\t\t";
t.start();
if(rand()%2)
{
int to = 24600 + rand()%(64000 - 24600) + 1;
for(int i=0;i<64000;i++)
for(int j=0;j<to;j++) {}
}
if(t.elapsedTime() <= seconds)
{
cout<<"Received Frame : "<<frames[count]<<" ";
if(delay)
{
cout<<"Duplicate";
delay = false;
}
cout<<endl;
count++;
}
else
{
cout<<"---"<<endl;
cout<<"Timeout"<<endl;
timeout = true;
}
t.start();
if(rand()%2 || !timeout)
{
int to = 24600 + rand()%(64000 - 24600) + 1;
for(int i=0;i<64000;i++)
for(int j=0;j<to;j++) {}
if(t.elapsedTime() > seconds )
{
cout<<"Delayed Ack"<<endl;
count--;
delay = true;
}
else if(!timeout)
cout<<"Acknowledgement : "<<frames[count]-1<<endl;
}
}while(count!=10);
return 0;
}
O/P:
Sender has to send frames : 1 2 3 4 5 6 7 8 9 10

Sender Receiver
Sending Frame : 1
---
Timeout
Sending Frame : 1 Received Frame : 1
Delayed Ack
Sending Frame : 1 ---
Timeout
Sending Frame : 1 ---
Timeout
Sending Frame : 1 Received Frame : 1 Duplicate
Acknowledgement : 1
Sending Frame : 2 Received Frame : 2
Acknowledgement : 2
Sending Frame : 3
B)Sliding Window Protocol - Selective Repeat:
#include <iostream>
#include <thread>
#include <chrono>
#include <unordered_map>
using namespace std;
const int WINDOW_SIZE = 4;

void sendFrame(int frameNumber) {


cout << "Sending frame: " << frameNumber << endl;
}

bool receiveAck(int frameNumber) {


return rand() % 2;
}
int main() {
int frameNumber = 0;
int lastAck = 0;
unordered_map<int, bool> window;

while (frameNumber < 10 || !window.empty()) {


if (frameNumber < 10 && window.size() < WINDOW_SIZE) {
sendFrame(frameNumber);
window[frameNumber] = false;
frameNumber++;
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000));

for (auto it = window.begin(); it != window.end(); ) {


if (!it->second && receiveAck(it->first)) {
cout << "Acknowledgment received for frame: " << it->first << endl;
it = window.erase(it);
} else {
++it;
}
}
for (const auto& frame : window) {
if (!frame.second) {
cout << "Resending frame: " << frame.first << endl;
sendFrame(frame.first);
}
}
}
return 0;
}
O/P:
Sending frame: 0
Acknowledgment received for frame: 0
Sending frame: 1
Resending frame: 1
Sending frame: 1
Sending frame: 2
Acknowledgment received for frame: 2
Acknowledgment received for frame: 1
Sending frame: 3
Acknowledgment received for frame: 3
Sending frame: 4
Acknowledgment received for frame: 4
Sending frame: 5
Resending frame: 5
Sending frame: 5
Sending frame: 6
Acknowledgment received for frame: 5
Resending frame: 6
Sending frame: 6
Sending frame: 7
Acknowledgment received for frame: 7
Resending frame: 6
Sending frame: 6
Sending frame: 8
Acknowledgment received for frame: 8
Resending frame: 6
Sending frame: 6
Sending frame: 9
Acknowledgment received for frame: 9
Acknowledgment received for frame: 6

3. Implementation and study of Goback-N and selective repeat protocols


THEORY:
The Go-Back-N (GBN) protocol is a type of sliding window protocol used for reliable data
communication. It allows the sender to transmit multiple frames before needing an
acknowledgment, but the receiver must acknowledge frames in order.
Key Features:
1. Window Size: The sender can send multiple frames (up to a predefined window
size) without waiting for individual acknowledgments for each frame.
2. Acknowledgment: The receiver acknowledges the highest-numbered frame it has
received correctly. The acknowledgment is cumulative; it implies that all frames
up to that frame have been received correctly.
3. Retransmission: If any frame is lost or corrupted, all subsequent frames from that
point need to be retransmitted. The sender goes back and retransmits the lost
frame and all frames that follow it.
4. Error Handling: If the sender does not receive an acknowledgment for a frame
within a certain time period (timeout), it retransmits that frame and all subsequent
frames.
Selective Repeat Protocol
Theory:
The Selective Repeat (SR) protocol is another type of sliding window protocol but with
more flexibility compared to Go-Back-N. It allows the sender to retransmit only the
frames that were lost or corrupted, rather than all subsequent frames.
Key Features:
1. Window Size: The sender and receiver use a sliding window of a defined size. Both
sender and receiver maintain windows to handle multiple frames.
2. Acknowledgment: The receiver sends individual acknowledgments for each
frame. It can acknowledge frames out of order if the receiver's window allows it.
3. Retransmission: If a frame is lost or corrupted, only that specific frame is
retransmitted. The receiver can buffer and process correctly received frames even
if they are received out of order.
4. Error Handling: The sender retransmits only the frames for which it has not
received an acknowledgment. The receiver can handle out-of-order frames if they
are within the window.

5. Feature Go-Back-N Selective Repeat

#include<bits/stdc++.h>
#include<ctime>
#define ll long long int
using namespace std;

void transmission(ll & i, ll & N, ll & tf, ll & tt) {


while (i <= tf) {
int z = 0;
for (int k = i; k < i + N && k <= tf; k++) {
cout << "Sending Frame " << k << "..." << endl;
tt++;
}
for (int k = i; k < i + N && k <= tf; k++) {
int f = rand() % 2;
if (!f) {
cout << "Acknowledgment for Frame " << k << "..." << endl;
z++;
} else {
cout << "Timeout!! Frame Number : " << k << " Not Received" << endl;
cout << "Retransmitting Window..." << endl;
break;
}
}
cout << "\n";
i = i + z;
}
}

int main() {
ll tf, N, tt = 0;
srand(time(NULL));
cout << "Enter the Total number of frames : ";
cin >> tf;
cout << "Enter the Window Size : ";
cin >> N;
ll i = 1;
transmission(i, N, tf, tt);
cout << "Total number of frames which were sent and resent are : " << tt <<
endl;
return 0;
}
O/P:
nter the Total number of frames : 55
Enter the Window Size : 5
Sending Frame 1...
Sending Frame 2...
Sending Frame 3...
Sending Frame 4...
Sending Frame 5...
Timeout!! Frame Number : 1 Not Received
Retransmitting Window...

Sending Frame 1...


Sending Frame 2...
Sending Frame 3...
Sending Frame 4...
Sending Frame 5...
Acknowledgment for Frame 1...
Timeout!! Frame Number : 2 Not Received
Retransmitting Window...

Sending Frame 2...


Sending Frame 3...
Sending Frame 4...
Sending Frame 5...
Sending Frame 6...
Timeout!! Frame Number : 2 Not Received
Retransmitting Window...

Sending Frame 2...


Sending Frame 3...
Sending Frame 4...
Sending Frame 5...
Sending Frame 6...
Acknowledgment for Frame 2...
Acknowledgment for Frame 3...
Timeout!! Frame Number : 4 Not Received
Retransmitting Window...

Sending Frame 4...


Sending Frame 5...
Sending Frame 6...
Sending Frame 7...
Sending Frame 8...
Acknowledgment for Frame 4...
Acknowledgment for Frame 5...
Timeout!! Frame Number : 6 Not Received
Retransmitting Window...

Sending Frame 6...


Sending Frame 7...
Sending Frame 8...
Sending Frame 9...
Sending Frame 10...
Timeout!! Frame Number : 6 Not Received
Retransmitting Window...

Sending Frame 6...


Sending Frame 7...
Sending Frame 8...
Sending Frame 9...
Sending Frame 10...
Timeout!! Frame Number : 6 Not Received
Retransmitting Window...
Sending Frame 6...
Sending Frame 7...
Sending Frame 8...
Sending Frame 9...
Sending Frame 10...
Timeout!! Frame Number : 6 Not Received
Retransmitting Window...

Sending Frame 6...


Sending Frame 7...
Sending Frame 8...
Sending Frame 9...
Sending Frame 10...
Acknowledgment for Frame 6...
Acknowledgment for Frame 7...
Timeout!! Frame Number : 8 Not Received
Retransmitting Window...

Sending Frame 8...


Sending Frame 9...
Sending Frame 10...
Sending Frame 11...
Sending Frame 12...
Acknowledgment for Frame 8...
Acknowledgment for Frame 9...
Timeout!! Frame Number : 10 Not Received
Retransmitting Window...

Sending Frame 10...


Sending Frame 11...
Sending Frame 12...
Sending Frame 13...
Sending Frame 14...
Acknowledgment for Frame 10...
Acknowledgment for Frame 11...
Acknowledgment for Frame 12...
Timeout!! Frame Number : 13 Not Received
Retransmitting Window...

Sending Frame 13...


Sending Frame 14...
Sending Frame 15...
Sending Frame 16...
Sending Frame 17...
Acknowledgment for Frame 13...
Timeout!! Frame Number : 14 Not Received
Retransmitting Window...

Sending Frame 14...


Sending Frame 15...
Sending Frame 16...
Sending Frame 17...
Sending Frame 18...
Timeout!! Frame Number : 14 Not Received
Retransmitting Window...

Sending Frame 14...


Sending Frame 15...
Sending Frame 16...
Sending Frame 17...
Sending Frame 18...
Acknowledgment for Frame 14...
Acknowledgment for Frame 15...
Timeout!! Frame Number : 16 Not Received
Retransmitting Window...

Sending Frame 16...


Sending Frame 17...
Sending Frame 18...
Sending Frame 19...
Sending Frame 20...
Acknowledgment for Frame 16...
Acknowledgment for Frame 17...
Timeout!! Frame Number : 18 Not Received
Retransmitting Window...

Sending Frame 18...


Sending Frame 19...
Sending Frame 20...
Sending Frame 21...
Sending Frame 22...
Acknowledgment for Frame 18...
Acknowledgment for Frame 19...
Acknowledgment for Frame 20...
Acknowledgment for Frame 21...
Acknowledgment for Frame 22...

Sending Frame 23...


Sending Frame 24...
Sending Frame 25...
Sending Frame 26...
Sending Frame 27...
Timeout!! Frame Number : 23 Not Received
Retransmitting Window...

Sending Frame 23...


Sending Frame 24...
Sending Frame 25...
Sending Frame 26...
Sending Frame 27...
Timeout!! Frame Number : 23 Not Received
Retransmitting Window...

Sending Frame 23...


Sending Frame 24...
Sending Frame 25...
Sending Frame 26...
Sending Frame 27...
Acknowledgment for Frame 23...
Acknowledgment for Frame 24...
Acknowledgment for Frame 25...
Timeout!! Frame Number : 26 Not Received
Retransmitting Window...

Sending Frame 26...


Sending Frame 27...
Sending Frame 28...
Sending Frame 29...
Sending Frame 30...
Acknowledgment for Frame 26...
Acknowledgment for Frame 27...
Timeout!! Frame Number : 28 Not Received
Retransmitting Window...

Sending Frame 28...


Sending Frame 29...
Sending Frame 30...
Sending Frame 31...
Sending Frame 32...
Timeout!! Frame Number : 28 Not Received
Retransmitting Window...

Sending Frame 28...


Sending Frame 29...
Sending Frame 30...
Sending Frame 31...
Sending Frame 32...
Acknowledgment for Frame 28...
Timeout!! Frame Number : 29 Not Received
Retransmitting Window...

Sending Frame 29...


Sending Frame 30...
Sending Frame 31...
Sending Frame 32...
Sending Frame 33...
Acknowledgment for Frame 29...
Acknowledgment for Frame 30...
Timeout!! Frame Number : 31 Not Received
Retransmitting Window...
Sending Frame 31...
Sending Frame 32...
Sending Frame 33...
Sending Frame 34...
Sending Frame 35...
Acknowledgment for Frame 31...
Timeout!! Frame Number : 32 Not Received
Retransmitting Window...

Sending Frame 32...


Sending Frame 33...
Sending Frame 34...
Sending Frame 35...
Sending Frame 36...
Acknowledgment for Frame 32...
Timeout!! Frame Number : 33 Not Received
Retransmitting Window...

Sending Frame 33...


Sending Frame 34...
Sending Frame 35...
Sending Frame 36...
Sending Frame 37...
Acknowledgment for Frame 33...
Acknowledgment for Frame 34...
Timeout!! Frame Number : 35 Not Received
Retransmitting Window...

Sending Frame 35...


Sending Frame 36...
Sending Frame 37...
Sending Frame 38...
Sending Frame 39...
Timeout!! Frame Number : 35 Not Received
Retransmitting Window...

Sending Frame 35...


Sending Frame 36...
Sending Frame 37...
Sending Frame 38...
Sending Frame 39...
Acknowledgment for Frame 35...
Acknowledgment for Frame 36...
Acknowledgment for Frame 37...
Acknowledgment for Frame 38...
Acknowledgment for Frame 39...

Sending Frame 40...


Sending Frame 41...
Sending Frame 42...
Sending Frame 43...
Sending Frame 44...
Acknowledgment for Frame 40...
Acknowledgment for Frame 41...
Acknowledgment for Frame 42...
Acknowledgment for Frame 43...
Timeout!! Frame Number : 44 Not Received
Retransmitting Window...
Sending Frame 44...
Sending Frame 45...
Sending Frame 46...
Sending Frame 47...
Sending Frame 48...
Acknowledgment for Frame 44...
Acknowledgment for Frame 45...
Timeout!! Frame Number : 46 Not Received
Retransmitting Window...

Sending Frame 46...


Sending Frame 47...
Sending Frame 48...
Sending Frame 49...
Sending Frame 50...
Timeout!! Frame Number : 46 Not Received
Retransmitting Window...

Sending Frame 46...


Sending Frame 47...
Sending Frame 48...
Sending Frame 49...
Sending Frame 50...
Acknowledgment for Frame 46...
Timeout!! Frame Number : 47 Not Received
Retransmitting Window...

Sending Frame 47...


Sending Frame 48...
Sending Frame 49...
Sending Frame 50...
Sending Frame 51...
Acknowledgment for Frame 47...
Acknowledgment for Frame 48...
Timeout!! Frame Number : 49 Not Received
Retransmitting Window...

Sending Frame 49...


Sending Frame 50...
Sending Frame 51...
Sending Frame 52...
Sending Frame 53...
Timeout!! Frame Number : 49 Not Received
Retransmitting Window...

Sending Frame 49...


Sending Frame 50...
Sending Frame 51...
Sending Frame 52...
Sending Frame 53...
Acknowledgment for Frame 49...
Timeout!! Frame Number : 50 Not Received
Retransmitting Window...

Sending Frame 50...


Sending Frame 51...
Sending Frame 52...
Sending Frame 53...
Sending Frame 54...
Timeout!! Frame Number : 50 Not Received
Retransmitting Window...

Sending Frame 50...


Sending Frame 51...
Sending Frame 52...
Sending Frame 53...
Sending Frame 54...
Timeout!! Frame Number : 50 Not Received
Retransmitting Window...

Sending Frame 50...


Sending Frame 51...
Sending Frame 52...
Sending Frame 53...
Sending Frame 54...
Acknowledgment for Frame 50...
Timeout!! Frame Number : 51 Not Received
Retransmitting Window...

Sending Frame 51...


Sending Frame 52...
Sending Frame 53...
Sending Frame 54...
Sending Frame 55...
Acknowledgment for Frame 51...
Acknowledgment for Frame 52...
Timeout!! Frame Number : 53 Not Received
Retransmitting Window...

Sending Frame 53...


Sending Frame 54...
Sending Frame 55...
Acknowledgment for Frame 53...
Acknowledgment for Frame 54...
Timeout!! Frame Number : 55 Not Received
Retransmitting Window...

Sending Frame 55...


Acknowledgment for Frame 55...

Total number of frames which were sent and resent are : 199

B) SELECTIVE REPEAT:
#include <iostream>
#include <thread>
#include <chrono>
#include <unordered_map>

using namespace std;

const int WINDOW_SIZE = 4;


const int TOTAL_FRAMES = 10;

void sendFrame(int frameNumber) {


cout << "Sending frame: " << frameNumber << endl;
}

bool receiveAck(int frameNumber) {


return rand() % 2;
}
int main() {
int nextFrameToSend = 0;
unordered_map<int, bool> window;

while (nextFrameToSend < TOTAL_FRAMES || !window.empty()) {


if (window.size() < WINDOW_SIZE && nextFrameToSend < TOTAL_FRAMES) {
sendFrame(nextFrameToSend);
window[nextFrameToSend] = false;
nextFrameToSend++;
}

std::this_thread::sleep_for(std::chrono::milliseconds(1000));

for (auto it = window.begin(); it != window.end(); ) {


if (!it->second && receiveAck(it->first)) {
cout << "Acknowledgment received for frame: " << it->first << endl;
it = window.erase(it);
} else {
++it;
}
}

for (const auto& frame : window) {


if (!frame.second) {
cout << "Resending frame: " << frame.first << endl;
sendFrame(frame.first);
}
}
}
return 0;
}
O/P:
ending frame: 0
Acknowledgment received for frame: 0
Sending frame: 1
Resending frame: 1
Sending frame: 1
Sending frame: 2
Acknowledgment received for frame: 2
Acknowledgment received for frame: 1
Sending frame: 3
Acknowledgment received for frame: 3
Sending frame: 4
Acknowledgment received for frame: 4
Sending frame: 5
Resending frame: 5
Sending frame: 5
Sending frame: 6
Acknowledgment received for frame: 5
Resending frame: 6
Sending frame: 6
Sending frame: 7
Acknowledgment received for frame: 7
Resending frame: 6
Sending frame: 6
Sending frame: 8
Acknowledgment received for frame: 8
Resending frame: 6
Sending frame: 6
Sending frame: 9
Acknowledgment received for frame: 9
Acknowledgment received for frame: 6

4 Implementation of High Level Data Link Control


THEORY:
High-Level Data Link Control (HDLC) is a protocol for providing reliable data
communication over point-to-point and multipoint links. HDLC operates at the data link
layer (Layer 2) of the OSI model and is used for error correction and flow control in data
communication systems.
Key Features of HDLC:
1. Framing: HDLC uses framing to encapsulate data into units called frames. Each
frame contains control information and data.
2. Error Detection: HDLC includes error detection using a cyclic redundancy check
(CRC).
3. Flow Control: HDLC provides flow control mechanisms to manage the rate of
data transmission.
4. Acknowledgment: It supports acknowledgment mechanisms to confirm the
receipt of frames.
5. Frame Types: HDLC supports three types of frames: Information frames (I-
frames), Supervisory frames (S-frames), and Unnumbered frames (U-frames).
CODE:
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
const std::string FLAG = "01111110";
const int FCS_POLYNOMIAL = 0x07;
const int POLYNOMIAL = 0x1D;
std::string calculateCRC8(const std::string& data) {
unsigned char crc = 0x00;
for (char bit : data) {
crc ^= bit;
for (int i = 0; i < 8; i++) {
if (crc & 0x80) {
crc = (crc << 1) ^ FCS_POLYNOMIAL;
} else {
crc <<= 1;
}
}
}
return std::bitset<8>(crc).to_string();
}
std::string addHDLCFrame(const std::string& data) {
std::string frame;
frame += FLAG;
frame += "00000001";
frame += "00000011";
frame += data;
std::string crc = calculateCRC8(frame);
frame += crc;
frame += FLAG;
return frame;
}
std::string removeHDLCFrame(const std::string& frame) {
std::string data;
std::string crc;
size_t start = frame.find(FLAG) + FLAG.length();
size_t end = frame.rfind(FLAG);

if (start != std::string::npos && end != std::string::npos && end > start) {


std::string frameContent = frame.substr(start, end - start);
crc = frameContent.substr(frameContent.length() - 8);
data = frameContent.substr(0, frameContent.length() - 8);
}
return data;
}

int main() {
std::string data = "10101010";
std::string frame = addHDLCFrame(data);

std::cout << "HDLC Frame: " << frame << std::endl;

std::string extractedData = removeHDLCFrame(frame);


std::cout << "Extracted Data: " << extractedData << std::endl;

return 0;
}
O/P:
HDLC Frame: 011111100000000100000011101010100010010101111110
Extracted Data: 000000010000001110101010

5 Study of Socket Programming and Client – Server model using java


CODE:
Server Code (SimpleServer.java):
import java.io.*;
import java.net.*;
public class SimpleServer {
public static void main(String[] args) {
int port = 12345;
try (ServerSocket serverSocket = new ServerSocket(port)) {
System.out.println("Server started and listening on port " + port);
while (true) {
Socket clientSocket = serverSocket.accept();
System.out.println("Client connected: " + clientSocket.getInetAddress());
BufferedReader in = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
String message = in.readLine();
System.out.println("Received from client: " + message);
out.println("Hello from server!");
in.close();
out.close();
clientSocket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Client Code (SimpleClient.java):
import java.io.*;
import java.net.*;
public class SimpleClient {
public static void main(String[] args) {
String serverAddress = "localhost";
int port = 12345;
try (Socket socket = new Socket(serverAddress, port)) {
System.out.println("Connected to server");
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
out.println("Hello from client!");
String response = in.readLine();
System.out.println("Received from server: " + response);
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
O/P:
Compile the Java Files
javac SimpleServer.java SimpleClient.java
1 Run the Server
java SimpleServer
2 Run the Client
java SimpleClient

6 Write a socket Program for Echo/Ping/Talk commands using JAVA

1 ECHO
CODE: ECHO SERVER
import java.io.*;
import java.net.*;

public class EchoServer {


public static void main(String[] args) {
int port = 12345;
try (ServerSocket serverSocket = new ServerSocket(port)) {
System.out.println("Echo Server started on port " + port);
while (true) {
try (Socket clientSocket = serverSocket.accept();
BufferedReader in = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true)) {

String inputLine;
while ((inputLine = in.readLine()) != null) {
if (inputLine.equalsIgnoreCase("EXIT")) {
System.out.println("Client requested to exit.");
break;
}
String response = processCommand(inputLine);
out.println(response);
}
} catch (IOException e) {
System.err.println("Error handling client: " + e.getMessage());
}
}
} catch (IOException e) {
System.err.println("Error starting server: " + e.getMessage());
}
}

private static String processCommand(String command) {


switch (command.toUpperCase()) {
case "PING":
return "PONG";
case "TALK":
return "Hello! How can I help you?";
case "ECHO":
return "ECHO Command Received";
default:
return "Unknown Command";
}
}
}
ECHO CLIENT :
import java.io.*;
import java.net.*;

public class EchoClient {


public static void main(String[] args) {
String serverAddress = "localhost"; // Server address
int port = 12345; // Server port

try (Socket socket = new Socket(serverAddress, port);


BufferedReader in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader userInput = new BufferedReader(new
InputStreamReader(System.in))) {

System.out.println("Connected to the server.");


String userInputLine;

while (true) {
System.out.print("Enter command (PING, TALK, ECHO, EXIT): ");
userInputLine = userInput.readLine();
if (userInputLine == null || userInputLine.equalsIgnoreCase("EXIT")) {
out.println("EXIT");
break;
}
out.println(userInputLine);
String response = in.readLine();
System.out.println("Server response: " + response);
}
} catch (IOException e) {
System.err.println("Error connecting to server: " + e.getMessage());
}
}
}
Echo Server:
import java.io.*;
import java.net.*;

public class EchoServer {


public static void main(String[] args) {
int port = 12345; // Server port
try (ServerSocket serverSocket = new ServerSocket(port)) {
System.out.println("Echo Server started on port " + port);
while (true) {
try (Socket clientSocket = serverSocket.accept();
BufferedReader in = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true)) {

String inputLine;
while ((inputLine = in.readLine()) != null) {
if (inputLine.equalsIgnoreCase("EXIT")) {
System.out.println("Client requested to exit.");
break;
}
String response = processCommand(inputLine);
out.println(response);
}
} catch (IOException e) {
System.err.println("Error handling client: " + e.getMessage());
}
}
} catch (IOException e) {
System.err.println("Error starting server: " + e.getMessage());
}
}

private static String processCommand(String command) {


switch (command.toUpperCase()) {
case "PING":
return "PONG";
case "TALK":
return "Hello! How can I help you?";
case "ECHO":
return "ECHO Command Received";
default:
return "Unknown Command";
}
}
}
Echo Client:
import java.io.*;
import java.net.*;

public class EchoClient {


public static void main(String[] args) {
String serverAddress = "localhost";
int port = 12345; // Server port

try (Socket socket = new Socket(serverAddress, port);


BufferedReader in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader userInput = new BufferedReader(new
InputStreamReader(System.in))) {

System.out.println("Connected to the server.");


String userInputLine;

while (true) {
System.out.print("Enter command (PING, TALK, ECHO, EXIT): ");
userInputLine = userInput.readLine();
if (userInputLine == null || userInputLine.equalsIgnoreCase("EXIT")) {
out.println("EXIT");
break;
}
out.println(userInputLine);
String response = in.readLine();
System.out.println("Server response: " + response);
}
} catch (IOException e) {
System.err.println("Error connecting to server: " + e.getMessage());
}
}
}
PING:
Echo Server
import java.io.*;
import java.net.*;

public class EchoServer {


public static void main(String[] args) {
int port = 12345; // Server port
try (ServerSocket serverSocket = new ServerSocket(port)) {
System.out.println("Echo Server started on port " + port);
while (true) {
try (Socket clientSocket = serverSocket.accept();
BufferedReader in = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true)) {

String inputLine;
while ((inputLine = in.readLine()) != null) {
if (inputLine.equalsIgnoreCase("EXIT")) {
System.out.println("Client requested to exit.");
break;
}
String response = processCommand(inputLine);
out.println(response);
}
} catch (IOException e) {
System.err.println("Error handling client: " + e.getMessage());
}
}
} catch (IOException e) {
System.err.println("Error starting server: " + e.getMessage());
}
}
private static String processCommand(String command) {
switch (command.toUpperCase()) {
case "PING":
return "PONG";
case "TALK":
return "Hello! How can I help you?";
case "ECHO":
return "ECHO Command Received";
default:
return "Unknown Command";
}
}
}
Client:
import java.io.*;
import java.net.*;

public class EchoClient {


public static void main(String[] args) {
String serverAddress = "localhost";
int port = 12345; // Server port

try (Socket socket = new Socket(serverAddress, port);


BufferedReader in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader userInput = new BufferedReader(new
InputStreamReader(System.in))) {

System.out.println("Connected to the server.");


String userInputLine;

while (true) {
System.out.print("Enter command (PING, TALK, ECHO, EXIT): ");
userInputLine = userInput.readLine();
if (userInputLine == null || userInputLine.equalsIgnoreCase("EXIT")) {
out.println("EXIT");
break;
}
out.println(userInputLine);
String response = in.readLine();
System.out.println("Server response: " + response);
}
} catch (IOException e) {
System.err.println("Error connecting to server: " + e.getMessage());
}
}
}

7. Implementation of distance vector routing algorithm


THEORY:
The Distance Vector Routing Algorithm is a fundamental technique used to determine
the optimal path for data packets in a network. Each router in the network maintains a
routing table that lists the shortest known distance to every other router and the next hop
along that path. Initially, routers populate their tables with direct distances to their
immediate neighbors and set distances to other routers as infinite. Periodically, each
router exchanges its distance vector table with its neighboring routers. Upon receiving
this information, a router updates its own table if it discovers a shorter path to a
destination through the neighbor. This process continues until all routers converge on the
shortest paths. The algorithm is known for its simplicity but can suffer from issues such
as slow convergence and the count-to-infinity problem, where routes to unreachable
nodes might increase indefinitely. Despite these challenges, the Distance Vector Routing
Algorithm remains a crucial part of many routing protocols, including RIP (Routing
Information Protocol), due to its ease of implementation and effectiveness in various
network scenarios.
CODE:
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
const int INF = INT_MAX;
const int NUM_ROUTERS = 4;
void printTable(const vector<vector<int>>& distanceTable) {
cout << "Router\t";
for (int i = 0; i < NUM_ROUTERS; ++i)
cout << i << "\t";
cout << endl;

for (int i = 0; i < NUM_ROUTERS; ++i) {


cout << i << "\t";
for (int j = 0; j < NUM_ROUTERS; ++j) {
if (distanceTable[i][j] == INF)
cout << "INF\t";
else
cout << distanceTable[i][j] << "\t";
}
cout << endl;
}
}
void initializeTable(vector<vector<int>>& distanceTable, const vector<vector<int>>&
costMatrix) {
for (int i = 0; i < NUM_ROUTERS; ++i) {
for (int j = 0; j < NUM_ROUTERS; ++j) {
distanceTable[i][j] = costMatrix[i][j];
}
}
}
void updateTable(vector<vector<int>>& distanceTable, const vector<vector<int>>&
costMatrix) {
bool updated;
do {
updated = false;
for (int i = 0; i < NUM_ROUTERS; ++i) {
for (int j = 0; j < NUM_ROUTERS; ++j) {
for (int k = 0; k < NUM_ROUTERS; ++k) {
if (distanceTable[i][k] != INF && costMatrix[k][j] != INF &&
distanceTable[i][j] > distanceTable[i][k] + costMatrix[k][j]) {
distanceTable[i][j] = distanceTable[i][k] + costMatrix[k][j];
updated = true;
}
}
}
}
} while (updated);
}

int main() {
vector<vector<int>> costMatrix = {
{0, 1, INF, 3},
{1, 0, 1, 7},
{INF, 1, 0, 2},
{3, 7, 2, 0}
};
vector<vector<int>> distanceTable(NUM_ROUTERS,
vector<int>(NUM_ROUTERS, INF));
initializeTable(distanceTable, costMatrix);
cout << "Initial Distance Vector Table:\n";
printTable(distanceTable);
updateTable(distanceTable, costMatrix);
cout << "\nUpdated Distance Vector Table:\n";
printTable(distanceTable);
return 0;
}
O/P:
Initial Distance Vector Table:
Router 0 1 2 3
0 0 1 INF 3
1 1 0 1 7
2 INF 1 0 2
3 3 7 2 0

Updated Distance Vector Table:


Router 0 1 2 3
0 0 1 2 3
1 1 0 1 3
2 2 1 0 2
3 3 3 2 0
8. Implementation of Link state routing algorithm
THEORY:
The Link State Routing Algorithm is a network routing technique where each router
maintains a complete map of the network. Initially, each router knows only about its
immediate neighbors and their link costs. It periodically sends Link State Advertisements
(LSAs) to all other routers, sharing information about its connections and link states.
Once a router receives LSAs from all other routers, it constructs a global network map.
Using this map, the router applies Dijkstra's algorithm to compute the shortest paths
from itself to every other router in the network. This method offers quicker convergence
and more accurate routing decisions compared to distance vector algorithms, but it
requires more memory and computational resources to handle the full network topology.
CODE:
#include <iostream>
#include <vector>
#include <climits>
#include <iomanip>
using namespace std;
const int INF = INT_MAX;
const int NUM_NODES = 4;
int minDistance(const vector<int>& dist, const vector<bool>& sptSet) {
int min = INF, min_index;
for (int v = 0; v < NUM_NODES; ++v) {
if (!sptSet[v] && dist[v] <= min) {
min = dist[v];
min_index = v;
}
}
return min_index;
}
void dijkstra(const vector<vector<int>>& graph, int src) {
vector<int> dist(NUM_NODES, INF);
vector<bool> sptSet(NUM_NODES, false);
dist[src] = 0;
for (int count = 0; count < NUM_NODES - 1; ++count) {
int u = minDistance(dist, sptSet);
sptSet[u] = true;

for (int v = 0; v < NUM_NODES; ++v) {


if (!sptSet[v] && graph[u][v] != INF && dist[u] != INF &&
dist[u] + graph[u][v] < dist[v]) {
dist[v] = dist[u] + graph[u][v];
}
}
}
cout << "Vertex\tDistance from Source\n";
for (int i = 0; i < NUM_NODES; ++i) {
cout << i << "\t" << (dist[i] == INF ? "INF" : to_string(dist[i])) << endl;
}
}

int main() {
vector<vector<int>> graph = {
{0, 1, INF, 3},
{1, 0, 1, 7},
{INF, 1, 0, 2},
{3, 7, 2, 0}
};

int src = 0;

dijkstra(graph, src);

return 0;
}
O/P:
Vertex Distance from Source
0 0
1 1
2 2
3 3
EXPERIMENT: 01
AIM: Study of different types of network cables and to practically implement the cross-wired cable and
straight through cable using clamping tool.
H/W & S/W REQUIRED: RJ 45 Connector, Crimp Tool, Ethernet Cable (Twisted Pair Cable).
THEORY:
A twisted pair cable consists of two insulated conductors twisted together in the shape of a spiral. It can be
shielded or unshielded. The unshielded twisted pair cables are very cheap and easy to install. But they are
very badly affected by the electromagnetic noise interference. Twisting of wires will reduce the effect of
noise or external interference. The induced emf into the two wires due to interference tends to cancel each
other due to twisting. Number of twists per unit length will determine the quality of cable. More twists
mean better quality. There are 3 types of UTP cables:
1. Straight-through cable
2. Crossover cable
3. Roll-over cable

Straight-through cable
Straight-Through refers to cables that have the pin assignments on each end of the cable. In other words,
Pin 1 connector A goes to Pin 1 on connector B, Pin 2 to Pin 2 etc. Straight-Through wired cables are most
commonly used to connect a host to client. When we talk about cat5e patch cables, the Straight-through
wired cat5e patch cable is used to connect computers, printers and other network client devices to the router,
switch or hub (the host device in this instance).
Crossover cable
Crossover wired cables (commonly called crossover cables) are very much like Straight-through cables
with the exception that TX and RX lines are crossed (they are at opposite positions on either end of the
cable. Using the 568-B standard as an example, you will see that Pin 1 on connector A goes to Pin 3 on
connector B. Pin 2 on connector A goes to Pin 6 on connector B etc. Crossover cables are most commonly
used to connect two hosts directly. Examples would be connecting a computer directly to another computer,
connecting a switch directly to another switch, or connecting a router to a router. Note: While in the past
when connecting two host devices directly a crossover cable was required. Now days most devices have
auto sensing technology that detects the cable and device and crosses pairs when needed.

Roll-over cable
Rollover wired cables most commonly called rollover cables, have opposite pin assignments on each end
of the cable or in other words it is "rolled over". Pin 1 of connector A would be connected to Pin 8 of
connector B. Pin 2 of connector A would be connected to Pin 7 of connector B and so on. Rollover cables,
sometimes referred to as Yost cables are most commonly used to connect to a devices console port to make
programming changes to the device. Unlike crossover and straight-wired cables, rollover cables are not
intended to carry data but instead create an interface with the device.
Crimp Tool
Following is the crimp tool for RJ 45 cable:
ACTIVITY:
STEPS
1. Start by stripping off about 2 inches of the plastic jacket off the end of the cable. Be very careful at
this point, as to not nick or cut into the wires, which are inside. Doing so could alter the
characteristics of your cable, or even worse render is useless. Check the wires, one more time for
nicks or cuts. If there are any, just whack the whole end off, and start over.
2. Spread the wires apart, but be sure to hold onto the base of the jacket with your other hand. You do
not want the wires to become untwisted down inside the jacket. Category 5 cable must only have
1/2 of an inch of 'untwisted' wire at the end; otherwise it will be 'out of spec'. At this point, you
obviously have ALOT more than 1/2 of an inch of un-twisted wire.
3. You have 2 end jacks, which must be installed on your cable. If you are using a pre-made cable,
with one of the ends whacked off, you only have one end to install - the crossed over end. Below
are two diagrams, which show how you need to arrange the cables for each type of cable end.
RESULT:
Straight-through cable and crossover cable have been successfully implemented.
SUPPLEMENT MATERIAL:

• Ethernet Cables, UTP vs STP, Straight vs Crossover, CAT 5,5e,6,7,8 Network Cables
• How to Make an Ethernet Cable! - FD500R
EXPERIMENT: 02
AIM: To connect two or more PCs or Laptops in a Local Area Network (LAN).
S/W REQUIRED: CISCO Packet Simulator
ACTIVITY 1:
Connecting two computers (point-to-point connection) using an Ethernet crossover cable.
STEPS
1. Open Cisco Packet Tracer (CPT).
2. Click on “End Devices” and select “PC”. Repeat this to create another “PC”.
3. Click on “Connections” and select “Copper Cross-Over” and connect the two PCs. The network
design will be as shown below:

4. Click on the first PC to see the PC controls. Click on “Desktop” tab. Click on “IP Configuration”.
Give the IP address value as “192.168.1.10”. Close the window.
5. Repeat the above step for the second PC and assign the IP address as “192.168.1.20”.
6. Enter “Simulation” mode.
7. Click on “Add Simple PDU” and click on one PC as the source and click on another PC to make it
the destination.
8. Run the simulation.
RESULT:
Two PCs were connected using a crossover cable and communication between the two PCs was observed.

ACTIVITY 2:
Creating a star topology using 4 PCs and a hub.
STEPS
1. Open CPT.
2. Click on “End Devices” and select “PC”. Repeat this to create another 3 PCs.
3. Click on “Network Devices” and select “Hubs” sub category. Now select “PT-Hub” and place it
on the workspace.
4. Name the hub as “Hub” and the 4 PCs as “A”, “B”, “C”, and “D”.
5. Connect the 4 PCs with the hub using a Copper Straight-Through cable. The network design will
be as shown below:

6. Now assign IP address to the PCs A, B, C, and D as 192.168.2.2, 192.168.2.3, 192.168.2.4, and
192.168.2.5 respectively.
7. Click on “Add Simple PDU” and click on PC “A” as the source and click on another PC “D” to
make it the destination.
8. Run the simulation and observe the behavior of the hub.
RESULT:
4 PCs were connected to a hub using a straight-through cable forming a star topology and communication
between the two PCs was observed. Also, behavior of the hub was observed.

ACTIVITY 3:
Creating a star topology using 4 PCs and a switch.
STEPS
Repeat the steps of the above activity. But, instead of a hub use a switch. While selecting a switch, you can
select 2960 switch which a well-known and used switch. The network design will look as shown below:

RESULT:
4 PCs were connected to a switch using a straight-through cable forming a star topology and communication
between the two PCs was observed. Also, behavior of the switch was observed.
EXPERIMENT: 03
AIM: To study basic network commands and network configuration commands.
S/W REQUIRED: Command Prompt/Terminal, Cisco Packet Tracer
ACTIVITY 1:
STEPS
1. Make sure that your system is connected to Internet.
2. Open command prompt and type “ping google.com”. The output would be as shown below:

3. Open command prompt and type “tracert google.com”. The output would be as shown below:
4. Open command prompt and type “nslookup google.com”. The output would be as shown below:

5. Open command prompt and type “pathping google.com”. The output would be as shown below:
ACTIVITY 2:
STEPS
1. Open Cisco Packet Tracer.
2. Click on “Network Devices” and click on “Routers” and then click on the router “2901” to create
a router in the logical workspace.
3. Click on the router again to open the options panel.
4. Click on “CLI” (Command Line Interface) tab.
5. Type the different commands given above and observe the output.
RESULT:
Networking commands and network configuration commands were successfully practiced.
EXPERIMENT: 04
AIM: To configure a network topology using packet tracer.
S/W REQUIRED: Cisco Packet Tracer
ACTIVITY:
STEPS
1. Open Cisco Packet Tracer.
2. Create a LAN containing a switch (2960) and 3 PCs. Name the PCs as A, B, and C.
3. Assign IP addresses to PCs created in the above step as 10.0.1.2, 10.0.1.3, and 10.0.1.4.
4. Connect all the 3 PCs to the switch.
5. Create another LAN containing a switch and 3 PCs. Name the PCs as D, E, and F.
6. Assign IP addresses to PCs created in the above step as 192.168.1.2, 192.168.1.3, and 192.168.1.4.
7. Connect all the 3 PCs to the switch.
8. Create a router (2901).
9. Connect both the switches to the router. Take care that while connecting the switches to the router,
GigabitEthernet ports are selected. The network design looks as shown below:

10. Now, we have to configure the router interfaces. Click on router to open the options. Click on
“Config”. Click on GigabitEthernet0/0 interface on the left-hand side. Give the IP address as
10.0.1.1 and change (click) the “Port Status” as “On”.
11. Repeat the above step for GigabitEthernet0/1 with IP address as 192.168.1.1.
12. For PCs A, B, and C change the “Default Gateway” in “IP Configuration” to 10.0.1.1.
13. For PCs D, E, and F change the “Default Gateway” in “IP Configuration” to 192.168.1.1. Final
network design will be as shown below:
14. Go to simulation mode and add a PDU from the source as PC A and the destination as PC F. Click
on play and watch the data flow.
RESULT:
Two LANs were connected using a router and the topology has been tested.

You might also like