0% found this document useful (0 votes)
30 views79 pages

DCC Ec2024 C2

The document is a laboratory journal for the EC-702 course on Data and Computer Communications at Dharmsinh Desai University, detailing various experiments and programming tasks related to serial communication standards such as RS232-C and UART. It includes objectives, procedures, and sample programs for tasks like byte transfer between PCs. The journal serves as a record of the student's work for the academic year 2024-2025 in the Electronics and Communication department.

Uploaded by

joshnap02619
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)
30 views79 pages

DCC Ec2024 C2

The document is a laboratory journal for the EC-702 course on Data and Computer Communications at Dharmsinh Desai University, detailing various experiments and programming tasks related to serial communication standards such as RS232-C and UART. It includes objectives, procedures, and sample programs for tasks like byte transfer between PCs. The journal serves as a record of the student's work for the academic year 2024-2025 in the Electronics and Communication department.

Uploaded by

joshnap02619
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/ 79

Laboratory journal for

EC-702 –Data & Computer


Communications

B. Tech.

SEM. VII (EC)

Department of Electronics & CommunicationFaculty of


Technology
Dharmsinh Desai University
Nadiad
Dharmsinh Desai University
Faculty of Technology
College Road, Nadiad – 387001. (Gujarat)

Certificate

This is to certify that the term work carried out in the subject of Data and
Computer Communications and recorded in this journal is the bonafide work of
Miss./Mr. ______________RollNo:______IdentityNo:_____________ of B. Tech.
semester VII in the branch of Electronics and Communication during the
academic year 2024- 2025.

Staff in charge Head of the department


Date: Date:

3
4
TABLE OF CONTENTS

Sr Title Page Date Signature


no. no.
1 Study Of UART And RS232-C Standard 5
2 Programming Serial Port for Byte Transfer & 11
Serial Port File Transfer
3 Programming Serial Port File Transfer With 19
Character Stuffing AndDe-Stuffing Protocol
4 Serial port file transfer with stop & wait 25
protocol
5 Network Planning & Study of Various 37
Network Commands
6 Understanding Packet Capturing Using 49
Wireshark and study Of Execution Of
Commands Using Wireshark
7 Study of Tcp And Ip Header Using Wireshark 53
8 Study of PING and TRACERT command using 57
Wireshark
9 Study of Dynamic Routing Protocol Using 61
CISCO Packet Tracer
10 Performance Analysis of TCP protocol using 66
NS-2

5
6
EXPERIMENT – 1
STUDY OF UART AND RS232-C STANDARD

OBJECTIVES:
(i) To understand RS232-C standard and UART functions.
(ii) To study RS232-C cabling scheme.
(iii) To test RS232-C cable using Windows inbuilt utility.

In most cases, any device you connect to the serial port will need the serial transmission converted back
to parallel so that it can be used. This can be done using a UART. On software side, there are many
more registers that you have to attend to than on a Standard Parallel Port. (SPP)

Advantages of Serial Data Transfer Over Parallel Data Transfer

 Serial Cables can be longer than Parallel cables. The serial port transmits a '1' as -3 to - 25 volts
and a '0' as +3 to +25 volts where as a parallel port transmits a '0' as 0v and a'1' as 5v. Therefore the
serial port can have a maximum swing of 50V compared to the parallel port which has a maximum
swing of 5 Volts. Therefore cable loss is not as much of a problem for serial cables then they are for
parallel.
 You don't need as many wires then parallel transmission. If your device needs to be mounted a
far distance away from the computer then 3 core cable (Null Modem Configuration) is going to be
cheaper that running 19 or 25 core cable. However you must take into account the cost of the
interfacing at each end.
 Many electronic diaries and palmtop computers have infra red capabilities build in. Serial
transmission is used where one bit is sent at a time. IrDA-1 (The first infra red specifications) was
capable of 115.2k baud and was interfaced into a UART. The pulse length however was cut down to
3/16th of an RS 232 bit length to conserve power considering these devices are mainly used on diaries,
laptops and palmtops.
 Serial Communication reduces the pin count of Microcontrollers. Only two pins are commonly
used, Transmit Data (TXD) and Receive Data (RXD) compared with at least 8pins if you use an 8 bit
Parallel method (You may also require a Strobe).

Hardware Properties

Devices which use serial cables for their communication are split into two categories. These are DCE
(Data Communications Equipment) and DTE (Data Terminal Equipment.) Data Communications
Equipments are devices such as your modem, TA adapter, plotter etc while Data Terminal Equipment
is your Computer or Terminal.
The electrical specifications of the serial port are contained in the RS232C standard. It states many
parameters such as

7
Table1.1 RS232 standard parameters

1. A "Space" (logic 0) will be between +3 and +25 Volts.


2. A "Mark" (Logic 1) will be between -3 and -25 Volts
3. The region between +3 and -3 volts is undefined.
4. An open circuit voltage should never exceed 25 volts. (In Reference
to GND)
5. A short circuit current should not exceed 500mA. The driver should
be able to handle this without damage. (Take note of this one!)

The RS 232 C standard specifies a maximum baud rate of 20,000 BPS. Serial Ports come in two
"sizes". There are the D-Type 25 pin connector and the D-Type 9 pin connector both of which are male
on the back of the PC, thus you will require a female connector on your device. Below is a table of pin
connections for the 9 pin and 25 pin D-Type connectors.

Serial Pin outs (D25 and D9 Connectors)


Table1.2 D9 & D25 Pin Connector Pin Configuration

D-Type-25 Pin No. D-Type-9 Pin No. Abbreviation Full Name


Pin 2 Pin 3 TD Transmit Data
Pin 3 Pin 2 RD Receive Data
Pin 4 Pin 7 RTS Request To Send
Pin 5 Pin 8 CTS Clear To Send
Pin 6 Pin 6 DSR Data Set Ready
Pin 7 Pin 5 SG Signal Ground
Pin 8 Pin 1 CD Carrier Detect
Pin 20 Pin 4 DTR Data Terminal Ready
Pin 22 Pin 9 RI Ring Indicator

Pin Functions
Table1.3 Pin Function of D9 Pin Connector

Abbreviation Full Name Function


TD Transmit Data Serial Data Output (TXD)
RD Receive Data Serial Data Input (RXD)
CTS Clear to Send This line indicates that the Modem is ready to exchange
data.
DCD Data Carrier When the modem detects a "Carrier" from the modem at the
Detect other end of the phone line, this Line becomes active.
DSR Data Set Ready This tells the UART that the modem is ready to establish a
link.
DTR Data Terminal This is the opposite of DSR. This tells the Modem that the
Ready UART is ready to link.
RTS Request To Send This line informs the Modem that the UART is ready to
exchange data.
8
RI Ring Indicator Goes active when modem detects a ringing signal from the
PSTN.

Null Modems

A Null Modem is used to connect two DTE's together without using intermediate DCEs..

9D to 25D Conversion

Fig.1.1 Null Modem ConfigurationThe UART (8250 and Compatibles)

UART stands for Universal Asynchronous Receiver / Transmitter. UART 8250 is the device that
controls the serial port. Most cards will have the UART's integrated into other chips which may also
control your parallel port, games port, floppy or hard disk drives and are typically surface mount
devices. The 8250 series, which includes the 16450, 16550, 16650, & 16750 UARTS are the most
commonly found type in your PC.
All the UARTs pins are TTL compatible. That includes TD, RD, RI, DCD, DSR, CTS, DTR and RTS
which all interface into your serial plug, typically a D-type connector. Therefore RS 232 Level
Converters are used.

The UART requires a Clock to run. If you look at your serial card a common crystal found is either a
1.8432 MHZ or an 18.432 MHZ Crystal. This clock will be used for the Programmable Baud Rate
Generator which directly interfaces into the transmit timing circuits but not directly into the receiver
timing circuits. For this an external connection mast be made from pin 15 (BaudOut) to pin 9 (Receiver
clock in.) Note that the clock signal will be at Baud rate * 16.

Registers

RBR, THR, IER, IIR, FCR, LCR, MCR, LSR, MSR, SCR, DLL, DLM
9
The communication between the processor and the UART is completely controlled by twelve registers.
These registers can be read or written to check and change the behavior of the communication device.
Each register is eight bits wide. On a PC compatible, the registers are accessible in the I/O port map.

RBR: Receiver buffer register (RO)

The receiver buffer register contains the byte received if no FIFO is used, or the oldest unreadbyte with
Fife’s. If FIFO buffering is used, each new read action of the register will yield the next byte, until no
more bytes are present. Bit 0 in the line status register can be used tocheck if all received bytes
have been read. This bit will change to zero if no more bytes are present.

THR: Transmitter holding register (WO)

The transmitter holding register is used to buffer outgoing characters. If no FIFO buffering is used,
only one character can be stored. Otherwise the amount of characters depends on the type of UART.
Bit 5 in the line status register can be used to check if new information must be written to the
transmitter holding register. The value 1 indicates that the register is empty. If FIFO buffering is used,
more than one character can be written to the transmitter holding register when the bit signals an empty
state. There is no indication of the amount of bytes currently present in the transmitter FIFO.

The transmitter holding register is not used to transfer the data directly. The byte is first transferred to a
shift register where the information is broken in single bits which are sent one by one.

LCR: Line control registers (R/W)

The line control register is used at initialization to set the communication parameters. Parity and
number of data bits can be changed for example. The register also controls the accessibility of the
DLL and DLM registers. Because they are only accessed at initializationwhen no communication
occurs this register swapping has no influence on performance.

Bit Value Detail


0,1 Bit 1 Bit 0 Data Word Length
0 0 5 Bits
0 1 6 Bits
1 0 7 Bits
1 1 8 Bits
2 0 1 stop bit
1 1.5 stop bits(5 bits word)
2 stop bits (6,7 or 8 bit word)
3,4,5 Bit 5 Bit 4 Bit 3
X X 0 No parity
0 0 1 Odd Parity
0 1 1 Even Parity
1 0 1 High Parity(stick)
1 1 1 Low Parity(stick)
6 0 Break signal disabled
10
1 Break signal enabled
7 0 DLAB : RBR, THR and IER accessible
1 DLAB : DLL and DLM accessible
Table1.4 LCR: Line Control Registers

Common settings are:


8 data bits, one stop bit, no parity
7 data bits, one stop bit, even parity

LSR : Line status register (RO)


The line status register shows the current state of communication. Errors are reflected in thisregister.
The state of the receiver and transmitter buffers is also available.

Bit Comment
0 Data available
1 Overrun error
2 Parity error
3 Framing error
4 Break signal received
5 THR is empty
6 THR is empty, and line is idle
7 Erroneous data in FIFO

Table1.5 LSR : Line status register

Bit 5 and 6 both show the state of the transmitting cycle. The difference is, that bit 5 turns highas soon
as the transmitter holding register is empty whereas bit 6 indicates that also the shift register which
outputs the bits on the line is empty

DLL and DLM : Divisor latch registers (R/W)

The frequency (1.8432 MHz) is divided by 16 to generate the time base for communication. Because of
this division, the maximum allowed communication speed is 115200 bps. Modern UARTS like the
16550 are capable of handling higher input frequencies up to 24 MHz which makes it possible to
communicate with a maximum speed of 1.5 Mbps. This 115200 bps communication speed is not
suitable for all applications. To change the communication speed, the frequency can be further
decreased by dividing it by a programmable value. For very slow communications, this value can go
beyond 255. Therefore, the divisor is stored in two separate bytes, the DLL and DLM which contain
the least, and most significant byte.

It is necessary that both the transmitting and receiving UART use the same time base. Defaultvalues
have been defined which are commonly used. The table shows the most common values with the
appropriate settings of the divisor latch bytes.

Speed(bp Divisor DLL DLM

11
s)
50 2304 0x00 0x09
300 384 0x80 0x01
1200 96 0x60 0x00
2400 48 0x30 0x00
4800 24 0x18 0x00
9600 12 0x0C 0x00
19200 6 0x06 0x00
38400 3 0x03 0x00
57600 2 0x02 0x00
115200 1 0x01 0x00

Table1.6 DLL and DLM : Divisor latch registers

CONCLUSION:
______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
____________________________________________________

12
EXEPERIMENT -2

PROGRAMMING SERIAL PORT FOR BYTE TRANSFER

OBJECTIVE:
(i) To verify serial port communication between two PCs by writing simple C code.(Bytetransfer).

SAMPLE PROGRAM (TRANSMITTER) :


#include<unistd.h>

#include <stdio.h>

#include <sys/io.h>

int main()

char data='B';

ioperm(0x3f8,7,1);

outb(0x83,0x3fb);

outb(0x0c,0x3f8);

outb(0x00,0x3f9);

outb(0x03,0x3fb);

while(((inb(0x3fd))&0x60)!=0x60);

outb(data,0x3f8);

printf("data transmitted=%c",data);

Output:

13
SAMPLE PROGRAM (RECEIVER) :

#include<unistd.h>

#include <stdio.h>

#include <sys/io.h>

int main( )

char data;

ioperm(0x3f8,7,1);

outb(0x83,0x3fb);

outb(0x0c,0x3f8);

outb(0x00,0x3f9);

outb(0x03,0x3fb);

while(((inb(0x3fd)) & 0x01)!=0x01);

data=inb(0x3f8);

printf("data received=%c",data);

OUTPUT:

14
ASSIGNMENT:

1. To verify serial port communication between two PCs by writing simple C code for string
transfer.
PROGRAM (TRANSMITTER):
#include<unistd.h>
#include<stdio.h>
#include<sys/io.h>
int main()
{
int i=0;
char c[]="Hello";
ioperm(0x3f8,7,1);
outb(0x83,0x3fb);
outb(0x0c,0x3f8);
outb(0x00,0x3f9);
outb(0x03,0x3fb);
do
{
while((inb(0x3fd) & 0x60)!=0x60);
outb(c[i],0x3f8);
printf("%c",c[i]);
}
while(c[i++]!='\0');
printf("\nString Transmitted.\n");
}

OUTPUT:

15
PROGRAM (RECEIVER):
#include<unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/io.h>
int main()
{
int i=0;
char data[100];
ioperm(0x3f8,7,1);
outb(0x83,0x3fb);
outb(0x0c,0x3f8);
outb(0x00,0x3f9);
outb(0x03,0x3fb);
do{
while(((inb(0x3fd)) & 0x01)!=0x01);
data[i]=inb(0x3f8);
printf("%c",data[i]);
//i=i+1;
}while(i++<5);

printf("\nData Received=%s\n",data);
}
OUTPUT:

2. To verify serial port communication between two PCs by writing simple C code for string
transfer.

16
SAMPLE PROGRAM (TRANSMITTER):

#include<unistd.h>
#include<stdio.h>
#include<sys/io.h>
int main()
{
FILE *f1;
char c;
ioperm(0x3f8,7,1);
outb(0x83,0x3fb);
outb(0x0c,0x3f8);
outb(0x00,0x3f9);
outb(0x03,0x3fb);
f1=fopen("tx.txt","r");do
{
while((inb(0x3fd) & 0x60)!=0x60);
c=getc(f1);
outb(c,0x3f8);
printf("%c",c);
}
while(c!=EOF);
fclose(f1);
printf("\nthe file transmitted\n");
}

17
OUTPUT:

SAMPLE PROGRAM (RECEIVER) :

#include<stdio.h>
#include<sys/io.h>
#include<unistd.h>
int main()
{
FILE *f1;
char ch;
ioperm(0x3f8,7,1);
outb(0x83,0x3fb);
outb(0x0c,0x3f8);
outb(0x00,0x3f9);
outb(0x03,0x3fb);
f1=fopen("Rx.txt","w");
do
{
while(((inb(0x3fd)) & 0x01)!=0x01);
ch=inb(0x3f8);
putc(ch,f1);
printf("%c",ch);
}
while(ch!=EOF);
fclose(f1);
printf("\nTHE FILE RECEIVED\n");
}

OUTPUT:

18
CONCLUSION:
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

19
20
EXPERIMENT – 3

PROGRAMMING SERIAL PORT FOR CHARACTER STUFFING AND

DESTUFFING

OBJECTIVES:
(i) Implementation of file transfer with Framing techniques.

PROGRAM (TRANSMITTER):

#include <unistd.h>
#include<stdio.h>
#include <sys/io.h>
int main()
{
char ch;
int i=0;
int frame=0;
FILE *ptr;
ptr = fopen("file_transmitter.txt","r");
ioperm(0x3f8,7,1);
outb(0x83,0x3fb);
outb(0x0c,0x3f8);
outb(0x00,0x3f9);
outb(0x03,0x3fb);
int a = -1;
do
{
while(((inb(0x3fd))&0x60)!=0x60);
i++;
if(i<=8)
{
ch = getc(ptr);
outb(ch,0x3f8);
printf("Character Transmitted = %c\n",ch);
}
else
{
frame++; i=0;
printf("frame Transmitted = %d\n",frame);
}
}
while(ch!= EOF);
printf("file Transmitted");
return 0;
}

OUTPUT:

21
PROGRAM (RECIEVER):

#include <stdio.h>
#include <unistd.h>
#include <sys/io.h>
int main()
{
char ch[8];
int i=-1;
FILE *ptr;
ptr = fopen("kj_rx.txt","w");
ioperm(0x3f8,7,1);
outb(0x83,0x3fb);
outb(0x0c,0x3f8);
outb(0x00,0x3f9);
outb(0x03,0x3fb);
do
{
while(((inb(0x3fd))&0x01)!=0x01);
i++;
ch[i]=inb(0x3f8);
printf("Character Received = %c\n",ch[i]);
putc(ch[i],ptr);
if(i==7)
{
printf("Frame Received = %c\n");
i=0;
}
}
while(ch[i]!= EOF);
fclose(ptr);
printf("file received");
22
}

OUTPUT:

(ii) Implement character stuffing & de-stuffing concept

SAMPLE PROGRAM (TRANSMITTER):

#include<unistd.h>
#include<stdio.h>
#include<sys/io.h>
#define DLE 0x10
#define STX 0x02
#define ETX 0x03
int main()
{
FILE *f1;
char a[20];
int i=2,flag=0,j;
ioperm(0x3f8,7,1);
outb(0x83,0x3fb);
outb(0x0c,0x3f8);
outb(0x00,0x3f9);
outb(0x03,0x3fb);
f1=fopen("Tx.txt","r");
do
{
a[0]=DLE;
a[1]=STX;i=2;

23
j=0;
while((j<8) && (flag==0))
{
a[i]=getc(f1);
if (a[i]==EOF)
flag=1;
if (a[i]==DLE)
{
i++;
a[i]=DLE;
}
i++;
j++;
}
a[i]=DLE;
i++;
a[i]=ETX;
j=0;
do
{
while((inb(0x3fd) & 0x60)!=0x60);
outb(a[j],0x3f8);
printf("%c",a[j]);
j++;
}
while(j<(i+1));
}
while(flag!=1);
printf("\nthe file transmitted\n\n");
}

OUTPUT:

24
SAMPLE PROGRAM (RECEIVER):

#include<unistd.h>
#include<stdio.h>
#include<sys/io.h>
#define DLE 0x10
#define STX 0x02
#define ETX 0x03
int main()
{
FILE *f1;
char a[20];
int i,j,flag=0;
ioperm(0x3f8,7,1);
outb(0x83,0x3fb);
outb(0x0c,0x3f8);
outb(0x00,0x3f9);
outb(0x03,0x3fb);
f1=fopen("hp6.txt","w");
do
{
i=0;
do
{
while(((inb(0x3fd)) & 0x01)!=0x01);
a[i]=inb(0x3f8);
i++;
}
while(a[i-1]!=ETX);
for(j=0;j<i;j++)
{
printf("%c",a[j]);
}
j=0;
while(j<i)
{
if(a[j]==EOF)
flag=1;
if((a[j]!=DLE) && (a[j]!=STX) && (a[j]!=ETX))
{
putc(a[j],f1);j++;
}
else if((a[j]==DLE) && (a[j+1]==DLE))

25
{
putc(a[j],f1);j+=2;
}
else
j++;
}
}
while(flag==0);
fclose(f1);
printf("\nTHE FILE RECEIVED\n");
}
}
OUTPUT:

CONCLUSION:
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________

26
EXPERIMENT – 4
SERIAL PORT FILE TRANSFER WITH
STOP & WAIT PROTOCOL

OBJECTIVES:
(i) To Implement simple stop and wait protocol

(ii) To understand the role of timer in the protocol.

SAMPLE PROGRAM:
#include<stdio.h>

#include<stdlib.h>

char seq='0',ack='0';

int flag=1;

int count=0;

FILE *fp1,*fp2;

void inc()

int n;

n=atoi(&seq); //ascii to integer conversion of the sequence number

if(n%2==0) //for even frame, send seq=1

seq='1';

else //for odd frame, send seq=0

seq='0';

void receiver(char *fr)

27
int j;

long int n;

if(fr[0]==seq) //for correct reception

printf("\nFrame Received\n");

printf("%c",fr[0]);

for(j=1;j<6;j++) //recreating the whole frame and storing into a file

if(fr[j]!=EOF)

fputc(fr[j],fp2);

printf("%c",fr[j]);

else

fputc(fr[j],fp2);

printf("%c",fr[j]);

break;

count++;

ack=seq;

printf("\nAck Sent=%c\n",ack);

void physical_layer(char *frm)

{
28
receiver(frm);

void sender()

int i;

char data[6];

while(flag)

printf("\nFrame Generated\n");

data[0]=seq;

printf("%c",data[0]);

for (i=1;i<6;i++) //Generate Frame of length 5

data[i]=fgetc(fp1);

printf("%c",data[i]);

if (data[i]==EOF)

flag=0;

break;

physical_layer(data); //send the generated frame

printf("Ack received=%c\n",ack);

if(ack!=seq)

physical_layer(data);

printf("Ack received=%c\n",ack);

inc();
29
}

else

inc();

int main()

fp1=fopen("Tx.txt","r");

fp2=fopen("Rx.txt","w");

sender();

fclose(fp1);

fclose(fp2);

return 0;

FILE CONTENT TO BE TRANSMITTED:

30
OUTPUT:

31
RECEIVED FILE CONTENT:

MODIFICATIONS:
1) Demonstrate the retransmission of data at sender side using wrong Acknowledgement

#include<stdio.h>

#include<stdlib.h>

char seq='0',ack='0';

int flag=1;

int count=0;

FILE *fp1,*fp2;

void inc()

int n;

n=atoi(&seq); //ascii to integer conversion of the sequence number

if(n%2==0)

seq='1'; //for even frame, send seq=1

else

32
seq='0'; //for odd frame, send seq=0

void receiver(char *fr)

int j;

long int n;

if(fr[0]==seq) //for correct reception

printf("\nFrame Received\n");

printf("%c",fr[0]);

for(j=1;j<6;j++) //recreating the whole frame and storing into a file

if(fr[j]!=EOF)

fputc(fr[j],fp2);

printf("%c",fr[j]);

else

fputc(fr[j],fp2);

printf("%c",fr[j]);

break;

count++;

ack=seq;

printf("\nAck Sent=%c\n",ack);

}
33
}

void physical_layer(char *frm)

receiver(frm);

if(count==3) //create a intentional problem of sending wrong acknowledgement

ack='2';

void sender()

int i;

char data[6];

while(flag)

printf("\nFrame Generated\n");

data[0]=seq;

printf("%c",data[0]);

for (i=1;i<6;i++) //Generate Frame of length 5

data[i]=fgetc(fp1);

printf("%c",data[i]);

if (data[i]==EOF)

flag=0;

break;

physical_layer(data);

printf("Ack received=%c\n",ack);
34
if(ack!=seq)

physical_layer(data);

printf("Ack received=%c\n",ack);

printf("**Received retransmitted Frame**\n");

inc();

else

inc();

int main()

fp1=fopen("tx.txt","r");

fp2=fopen("Rx.txt","w");

sender();

fclose(fp1);

fclose(fp2);

return 0;

FILE CONTENT TO BE TRANSMITTED:

OUTPUT:

35
RECEIVED FILE CONTENT:

36
2) Demonstrate the retransmission of data at sender side Timer timeout.

#include<unistd.h>

#include <signal.h>

#include <sys/time.h>

#include<stdio.h>

#include<sys/io.h>

#define INTERVAL 2

#define N 5

int flag, event, flag_timeout;

char ack;

void send_char(char c){

while((inb(0x3fd) & 0x60)!=0x60);

outb(c, 0x3f8);

printf("%c", c);

char receive_char(void){

char c;

//printf("\nAck wait.");

while((inb(0x3fd) & 0x01)!=0x01 && flag_timeout);

if(flag) c = 'T';

else c = inb(0x3f8);

//c = getchar();

//getchar();

printf("Got = %c\n\n", c);

return c;

37
int wait_for_event( );

void alarm_wakeup (){

flag = 1;

wait_for_event( );

int wait_for_event(){

printf("\nflag = %d\n", flag);

if (flag){ /* TIMEOUT occurrence */

printf("Timeout %d sec...\n", INTERVAL);

flag_timeout = 0;

event = 0;

return 0;

}else{

printf("Waiting...");

flag_timeout = 1;

ack = receive_char();

event = 1;

return 1;

int timer_init(){

int event,num;

struct itimerval tout_val;

tout_val.it_interval.tv_sec = 0;

tout_val.it_interval.tv_usec = 0;

tout_val.it_value.tv_sec = INTERVAL;

tout_val.it_value.tv_usec = 0;
38
setitimer(ITIMER_REAL, &tout_val,0);

signal(SIGALRM,alarm_wakeup);

flag = 0;

event = wait_for_event( );

return event;

int endOfFile = 0;

int endOfFile1 = 0;

void from_network_layer(FILE *f, char packet[N]){

char CHAR;

int i;

for(i=0; i<N; i++){

CHAR = getc(f);

packet[i] = CHAR;

if(CHAR == EOF){

fclose(f);

endOfFile1 = 1;

break;

void to_physical_layer(char frame[N+1]){

int i;

for(i=0; i<=N; i++){

send_char(frame[i]);

}
39
}

int main(void){

static FILE *f;

f = fopen("source.txt", "r");

char packet[N];

char frame[N+1];

char seqNo = '0';

int i;

int x = 0;

ioperm(0x3f8,7,1);

outb(0x83,0x3fb);

outb(0x0c,0x3f8);

outb(0x00,0x3f9);

outb(0x03,0x3fb);

from_network_layer(f, &packet);

while(!endOfFile){

//Packet => Frame

endOfFile = endOfFile1;

frame[0] = seqNo;

//printf("%c", frame[0]);

for(i=1; i<=N; i++){

frame[i] = packet[i-1];

//printf("%c", packet[i-1]);

to_physical_layer(&frame);
40
timer_init();

//ack = receive_char();

if(event){

if(ack == seqNo){

seqNo = (seqNo=='0' ? '1' : '0');

from_network_layer(f, &packet);

x = 0;

x++;

if(x < 5) continue;

else break;

return 0;

OUTPUT:

41
FILE CONTENT TO BE TRANSMITTED:

CONCLUSION:
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________

42
EXPERIMENT 5
NETWORK PLANNING & STUDY OF VARIOUS
NETWORK COMMANDS
OBJECTIVE:
(i) To study network devices and the specifications of each for existing network plan

(ii) To study existing network plan

(iii) To draw a new network plan as per the new constraints

(iv) To test different network utilities like ping, tracert, arp, ipconfig

(v) To study and use different options for these utilities.

Hub
A network hub or repeater hub is a device for connecting multiple twisted pair or fiber optic Ethernet
devices together and thus making them act as a single network segment. Hubs work at the physical layer
(layer 1) of the OSI model. The device is thus a form of multiport repeater. Repeater hubs also participate
in collision detection, forwarding a jam signal to all ports if it detects a collision. Hubs also often come
with a BNC and/or AUI connector to allow connection to legacy 10BASE2 or 10BASE5 network
segments. The availability of low-priced network switches has largely rendered hubs obsolete but they are
still seen in older installations and more specialized applications.

A network hub is a fairly unsophisticated broadcast device. Hubs do not manage any of the traffic that
comes through them, and any packet entering any port is broadcast out on all other ports. Since every
packet is being sent out through all other ports, packet collisions result— which greatly impedes the
smooth flow of traffic.

Types of Hubs

1. Passive (A hub which does not need an external power source, because it does not regenerate the signal
and therefore falls as part of the cable, with respect to maximum cable lengths)

2. Active (A hub which regenerates the signal and therefore needs an external power supply)

3. Intelligent (A hub which provides error detection (e.g. excessive collisions) and also does what an active
hub does)

Passive hubs do not amplify the electrical signal of incoming packets before broadcasting them out to the
network. Active hubs, on the other hand, do perform this amplification, as does a different type of
dedicated network device called a repeater. Another, not so common, name for the term concentrator is
referring to a passive hub and the term multiport repeater is referred to an active hub.

Intelligent hubs add extra features to an active hub that are of particular importance to businesses. An
intelligent hub typically is stackable (built in such a way that multiple units can be placed one on top of

43
the other to conserve space). It also typically includes remote management capabilities via Simple
Network Management Protocol (SNMP) and virtual LAN (VLAN) support.

Uses

For inserting a protocol analyzer into a network connection, a hub is an alternative to a network tap or port
mirroring.

Some computer clusters require each member computer to receive all of the traffic going to the cluster A
hub will do this naturally; using a switch requires special configuration.

When a switch is accessible for end users to make connections, for example, in a conference room, an
inexperienced or careless user (or saboteur) can bring down the network by connecting two ports together,
causing a loop. This can be prevented by using a hub, where a loop will break other users on the hub, but
not the rest of the network. (It can also be prevented by buying switches that can detect and deal with
loops, for example by implementing the Spanning Tree Protocol).

A hub with a 10BASE2 port can be used to connect devices that only support 10BASE2 to a modern
network. The same goes for linking in an old thicknet network segment using an AUI port on a hub
(individual devices that were intended for thicknet can be linked to modern Ethernet by using an AUI-
10BASE-T transceiver).

Switch
In networks, a device that filters and forwards packets between LAN segments. Switches operate at the
data link layer (layer 2) and sometimes the network layer (layer 3) of the OSI Reference Model and
therefore support any packet protocol. LANs that use switches to join segments are called switched LANs
or, in the case of Ethernet networks, switched Ethernet LANs.

Layer-1 Hubs Versus Higher-Layer Switches

A network hub, or repeater, is a fairly unsophisticated network device. Hubs do not manage any of the
traffic that comes through them. Any packet entering a port is broadcast out or "repeated" on every other
port, except for the port of entry. Since every packet is repeated on every other port, packet collisions
result, which slows down the network.

There are specialized applications where a hub can be useful, such as copying traffic to multiple network
sensors. High end switches have a feature which does the same thing called port mirroring. There is no
longer any significant price difference between a hub and a low-end switch.

Layer 2

A network bridge, operating at the Media Access Control (MAC) sublayer of the data link layer, may
interconnect a small number of devices in a home or office. This is a trivial case of bridging, in which the
bridge learns the MAC address of each connected device. Single bridges also can provide extremely high
performance in specialized applications such as storage area networks.

Once a bridge learns the topology through a spanning tree protocol, it forwards data link layer frames
using a layer 2 forwarding method. There are four forwarding methods a bridge can use, of which the
second through fourth method were performance-increasing methods when used on "switch" products with
the same input and output port speeds:
44
1. Store and forward: The switch buffers and, typically, performs a checksum on each frame before
forwarding it on.

2. Cut through: The switch reads only up to the frame's hardware address before starting to forward it. There
is no error checking with this method.

3. Fragment free: A method that attempts to retain the benefits of both "store and forward" and "cut through".
Fragment free checks the first 64 bytes of the frame, where addressing information is stored. According to
Ethernet specifications, collisions should be detected during the first 64 bytes of the frame, so frames that
are in error because of a collision will not be forwarded. This way the frame will always reach its intended
destination. Error checking of the actual data in the packet is left for the end device in Layer 3 or Layer 4
(OSI), typically a router.

4. Adaptive switching: A method of automatically switching between the other three modes.

Cut-through switches have to fall back to store and forward if the outgoing port is busy at the time the
packet arrives. While there are specialized applications, such as storage area networks, where the input and
output interfaces are the same speed, this is rarely the case in general LAN applications. In LANs, a switch
used for end user access typically concentrates lower speed (e.g., 10/100 Mbit/s) into a higher speed (at
least 1 Gbit/s). Alternatively, a switch that provides access to server ports usually connects to them at a
much higher speed than is used by end user devices.

Layer 3

Within the confines of the Ethernet physical layer, a layer 3 switch can perform some or all of the
functions normally performed by a router. A true router is able to forward traffic from one type of network
connection (e.g., T1, DSL) to another (e.g., Ethernet, WiFi). The most common layer-3 capability is
awareness of IP multicast. With this awareness, a layer3 switch can increase efficiency by delivering the
traffic of a multicast group only to ports where the attached device has signaled that it wants to listen to
that group. If a switch is not aware of multicasting and broadcasting, frames are also forwarded on all
ports of each broadcast domain, but in the case of IP multicast this causes inefficient use of bandwidth. To
work around this problem some switches implement IGMP snooping.

Layer 4

While the exact meaning of the term Layer-4 switch is vendor-dependent, it almost always starts with a
capability for network address translation, but then adds some type of load distribution based on TCP
sessions. The device may include a stateful firewall, a VPN concentrator, or be an IPSec security gateway.

Layer 7

Layer 7 switches may distribute loads based on URL or by some installation-specific technique to
recognize application-level transactions. A Layer-7 switch may include a web cache and participate in a
content delivery network.

45
Fig.5.1 Router

Router

A device that forwards data packets along networks. A router is connected to at least two networks,
commonly two LANs or WANs or a LAN and its ISP’s network. Routers are located at gateways, the
places where two or more networks connect.

Routers use headers and forwarding tables to determine the best path for forwarding the packets, and they
use protocols such as ICMP to communicate with each other and configure the best route between any two
hosts. Very little filtering of data is done through routers.

Types of routers

Routers may provide connectivity inside enterprises, between enterprises and the Internet, and inside
Internet Service Providers (ISPs). The largest routers (for example the Cisco CRS-1 or
Juniper T1600) interconnect ISPs, are used inside ISPs, or may be used in very large enterprise networks.
The smallest routers provide connectivity for small and home offices. Routers for Internet connectivity
and internal use

Routers intended for ISP and major enterprise connectivity will almost invariably exchange routing
information with the Border Gateway Protocol (BGP). RFC 4098 defines several types of BGP-speaking
routers:

• Edge Router: Placed at the edge of an ISP network, it speaks external BGP (eBGP) to a BGP
speaker in another provider or large enterprise Autonomous System(AS).

• Subscriber Edge Router: Located at the edge of the subscriber's network, it speaks eBGP to its
provider's AS(s). It belongs to an end user (enterprise) organization.

• Inter-provider Border Router: Interconnecting ISPs, this is a BGP speaking router that maintains
BGP sessions with other BGP speaking routers in other providers' ASes.

• Core router: A router that resides within the middle or backbone of the LAN network rather than at
its periphery.

46
Within an ISP: Internal to the provider's AS, such a router speaks internal BGP (iBGP) to that provider's
edge routers, other intra-provider core routers, or the provider's inter-provider border routers.

"Internet backbone:" The Internet does not have a clearly identifiable backbone, as did its predecessors.
See default-free zone (DFZ). Nevertheless, it is the major ISPs' routers that make up what many would
consider the core. These ISPs operate all four types of the BGP-speaking routers described here. In ISP
usage, a "core" router is internal to an ISP, and used to interconnect its edge and border routers. Core
routers may also have specialized functions in virtual private networks based on a combination of BGP
and Multi-Protocol Label Switching (MPLS). Routers are also used for port forwarding for private servers.

RJ45

The RJ45 is a modular connector used to terminate twisted pair and multiconductor flat cable. It is not in
common use, but RJ45 is used as the name for the 8P8C modular connector, which is commonly used to
terminate Ethernet cable.

Originally, there was only the true telephone RJ45. It is one of the many registered jacks, like RJ11, a
standard from which it gets the "RJ" in its name. As a registered jack, true telephone RJ45 specifies both
the physical connector and wiring pattern. The true telephone RJ45 uses a special, keyed 8P2C modular
connector, with Pins 5 and 4 wired for tip and ring of a single telephone line and Pins 7 and 8 connected to
a programming resistor. It is meant to be used with a high speed modem, and is obsolete today.

FIG.5.2 Network Diagram of lab 9

In this diagram BACKBONE SERVER connected to GATEWAY SERVER through SWITCH 192.168.1.X.
this GATEWAY further connected with HUB A. HUB A is internally connected with HUB B and all the
computers of IP address 192.168.11.2 to 192.168.11.18. and HUB B is connected with all computers with
IP address 192.168.11.34 to 192.168.11.46

(iv) To test different network utilities like ping, tracert, arp, ipconfig

(v) To study and use different options for these utilities

Ping
47
If any system (host or router) want to communicate with the other system (host or route) then it is
necessary to check the communication is possible or not? For this, first of all we have to check for
destination system is reachable or not. Due to hardware failure or any other reason it is possible the system
may on network but not reachable. How can we detect that the destination system is reachable or not?

PING command is useful for checking the reach ability of the system.

PROCEDURE:
(1) First go to command prompt
(2) For help and information about this command type ping /?
(3) Type ping IP address of system

EXAMPLE
ping /?all – List all the ping utilities available with their description

Fig 5.3 Options for ping

48
ping www.google.com

Fig 5.4 Ping to any website


Tracert
When one system (host or router) send the packet of data to another system then there be two possibilities,
Packet directly reach to destination system or it pass through one or more routers.
TRACERT command is useful to trace the route through which packet passes.

Procedure:
(1) First go to command prompt
(2) For help and information about this command type tracert /?
(3) Type tracert IP address or name of the destination.

49
Ipconfig
The "ipconfig" command allows the operating system to setup network interfaces and allow the user to
view information about the configured network interfaces. In absence of arguments, it displays the status
of currently active interface. If a single interface argument is given it displays the status of the given
interface only.
PROCEDURE:
(1) First go to command prompt
(2) For help and information about this command type ipconfig /?
(3) Type ipconfig.
(4) ipconfig /? – List all the ipconfig options available with their description

50
ipconfig

Fig 5.8 Output of ipconfig command


ARP
The Address Resolution Protocol (or ARP) is used to map the Internet Protocol address of a machine to its
Ethernet address. It simply uses a table which lists each host, its IP address and its Ethernet address. You
can view the the ARP table on your machine via the arp -a command. When a datagram is received
addressed to an IP address on your network the router uses this table to find the Ethernet address of the
specified host and forwards the datagram appropriately.

Procedure
(1) First go to command prompt
(2) For help and information about this command type arp /?
(3) Type arp -a
arp /?
51
Fig 5.9 Options for arp
arp -a

Fig 5.10 Output of arp Command

52
CONCLUSION:
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________

53
54
EXPERIMENT 6

UNDERSTANDING PACKET CAPTURING USING


WIRESHARK AND STUDY OF EXECUTION OF COMMANDS USING
WIRESHARK
OBJECTIVE:
(I) Understanding of packet capturing tool
Wireshark is a network packet analyzer. A network packet analyzer will try to capture network packets and
tries to display that packet data as detailed as possible.

PROCEDURE:
1. Open Wireshark
2. Select Wi-Fi in your device. (Select Ethernet if observing on a wired network device)

Fig 6.1
3. Select Start to start capturing packets

Fig 6.2

55
Fig 6.3

4. Click on Stop to stop capturing

Fig 6.4

Analyse the data captured in wireshark

56
CONCLUSION:
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________

57
58
EXPERIMENT 7

STUDY OF TCP AND IP HEADER USING WIRESHARK


OBJECTIVES:
(I) Analysis of captured packets
(II) Access IP header using Wireshark

PROCEDURE:
1. Prepare Wireshark for a packet capture.
2. Open a Command Prompt window.
3. Type “ping <IP address or website>”; Do NOT press ENTER.
4. Start Wireshark packet capture.
5. Press ENTER in Command Prompt window. You should obtain a series of replies in command prompt.
6. Stop packet capture when Command Prompt returns.
7. Save the contents in the Command Prompt window using a screen capture.

PROTOCOL ANALYSIS:

Fig 8.1 Analysis of frame for given command

IP Header
Command: ping 192.168.51.207

59
Fig 8.2 Analysis of IP header for given command

TCP Header:

Fig 8.3 Analysis of TCP header for given command

60
Ping 192.168.51.209 from 192.168.51.207

Fig 8.4 Analysis of TCP header for given command

Fig 8.5 Analysis of TCP header for given command

61
CONCLUSION:
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________

62
EXPERIMENT 8
STUDY OF PING AND TRACERT COMMANDS USING WIRESHARK
OBJECTIVE:
1. Implementation of PING command

2. Implementation of TRACERT command

THEORY:

Wireshark is a powerful network protocol analyzer that allows users to capture and interactively browse
the traffic running on a computer network. When studying the ping and tracert commands using Wireshark,
you can analyze the Internet Control Message Protocol (ICMP) packets. The ping command sends ICMP
Echo Request packets to a target host and waits for Echo Reply packets, while tracert (or traceroute) maps
the route taken by packets to reach a destination by incrementing the Time to Live (TTL) value and
observing ICMP Time Exceeded messages from intermediate routers1. By examining these packets in
Wireshark, you can gain insights into network latency, packet loss, and the path taken by data packets. The
TTL timeout during execution helps prevent packets from circulating indefinitely in the network by
limiting the number of hops they can traverse.

SAMPLE PING COMMAND EXECUTION

Fig 8.1 Execution of ping 192.168.1.100

63
Fig 8.2. Execution of TTL time out(request)

Fig 8.3. Execution of TTL time out(reply)

SAMPLE TRACERT COMMAND EXECUTION

64
Fig 8.3 TRACERT Execution

Fig 8.4. TRACERT time out (Request)

65
Fig 8.5. TRACERT time out (Reply)

CONCLUSION:
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________

66
EXPERIMENT 9
Study of Dynamic Routing Protocol using
CISCO Packet Tracer
OBJECTIVE:

1. Communication between two PCs

2. Switch to Switch communication

3. Communication between two switches through router.

4. Communication between two routers

THEORY:

Dynamic routing protocols automatically update routing tables based on the current state of the network,

ensuring efficient data packet forwarding. Cisco Packet Tracer is a powerful tool that allows users to

simulate these protocols in a virtual environment. By configuring networks with tools like OSPF, EIGRP,

and RIP, you can observe their behavior, fast convergence, and scalability, providing a hands-on

understanding of how dynamic routing enhances network performance and reliability.

SAMPLE EXECUTION:

1) Communication between two PCs.

67
2) Switch to Switch communication

68
3) Communication between two switches through router.

69
4) Communication between two routers

70
CONCLUSION:
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________

71
72
EXPERIMENT – 10
PERFORMANCE ANALYSIS OF TCP PROTOCOL USING NS-2

OBJECTIVE:
(i) Introduction of Network simulator ns-2
(ii) Understanding of network simulator ns-2
(iii) Impact of link error rate on TCP performance (throughput, cwnd).
(iv) Plot the graph for TCP cwnd.

THEORY:

ns-2 is a network simulator for simulating computer networks and protocols. It was chosen because it is
free, open source and is used commonly by the research community for evaluating work in computer
networks. ns-2 support simulation of routing protocols over both wired as well as wireless networks, and
also supports links from Ethernet to satellite links. It also includes various models to represent the
characteristics and behavioral aspects of different network devices and components. A user has complete
access over the entire software setup and can attempt any kind of modifications.

ns-2 is an event driven network simulator, written in c++ language with an OTcl interpreter as a front end.
The simulator supports a class hierarchy in c++ and a similar class hierarchy within the OTcl interpreter.
The two hierarchies are closely related to each other, from the user’s perspective. There is one to one
correspondence between a class in the interpreted hierarchy and one in the compiled hierarchy.

ns-2 uses two languages because simulator has two different kind of things to do. On one hand detailed
simulations of protocols require a system programming language, which can efficiently manipulate packet
headers, and implement algorithms that run over large data sets. For this task run time speed is important
and turn-around time is less important. On the other hand, a large part of network research involves slightly
varying parameters or configurations, or quickly exploring a number of scenarios. In this case, interaction
time (change the model and re-run) is more important. That’s why, ns satisfy both of this needs with two
languages, c++ and OTcl.

C++ is fast to run but slower to change as large amount of program need to change, making it more suitable
for detailed protocol implementation. OTcl runs much slower but can be changed very quickly and
interactively, making it ideal for simulation configuration.

SIMULATION WITH NS:

ns is invoked with scripts which defines the simulation. The scripting language creates the simulation
objects with appropriate links between them. Often analytical or evaluation experiments involve slight
variation in configurations and parameters. OTcl is easy to change and therefore it is ideal to use for
simulation configuration. Network Simulator includes The Network Animator, which is helping Network
Simulator to support a graphical environment. The Network Animator uses the parameters from the script
and writes it into .namfile and thenaccording to that it will create a topology identical to the script. So we
can see graphically how the packets are forwarded and traffic is handled in the network, so this can give
the more realistic implementation and observation.xgraph inbuilt utility of ns can be used to plot graphs.
Based on individual requirements and preferences, plots of various network parameters can be generated.

73
An overview of how to run simulation in ns is shown in Fig below-

Overview of simulation

INSTALLATION PROCEDURE:

1. Copy ns-allinone-2.30.tar.gz file to /root


2. Type tar xvzf ns-allinone-2.30.tar.gz and press enter
3. Directory of the name ns-allinone-2.30 will be created
4. After entering in this directory, type ./install and press enter
5. After the completion of the installation set the library paths in .bash_profile file in /root
6. After the completion of the installation goto ns-2.30 directory which is in the ns-allinone-2.30 directory
7. In this directory goto ns-2.30/tcl directory
8. In this directory goto ex directory. .tcl files will be available there.
9. To run .tcl files type ns filename.tcl
10. To view source code type vi filename.tcl

TCL Script:
set ns [new Simulator]
$ns color 0 blue
$ns color 1 red $ns color 2 green set n0
[$ns node] set n1 [$ns node] set n2 [$ns
node] set n3 [$ns node] set f [open
out1.tr w] ns trace-all $f set nf [open
out1.nam w]
$ns namtrace-all $nf
$ns trace-all $f
set tcptrace [open tracelink w]
$ns duplex-link $n0 $n2 5Mb 2ms DropTail
$ns duplex-link $n1 $n2 5Mb 2ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
$ns duplex-link-op $n0 $n2 orient right-up
$ns duplex-link-op $n1 $n2 orient right-down
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n2 $n3 queuePos 0.5
74
$ns queue-limit $n2 $n3 50 # ErrorModel
set em [new ErrorModel] $em unit pkt
$em set rate_ 0.00 #error rate
# Introducing PER on n0-r0 link
$em ranvar [new RandomVariable/Uniform]
$em drop-target [new Agent/Null] $ns lossmodel
$em $n2 $n3 set tcp1 [new Agent/TCP] $tcp1 set
class_ 2 set sink1 [new Agent/TCPSink] $ns
attach-agent $n0 $tcp1
$ns attach-agent $n3 $sink1 $ns connect $tcp1
$sink1 set ftp1 [new Application/FTP] $ftp1
attach-agent $tcp1 $ns at 0.1 "$ftp1 start" set
tcp [new Agent/TCP] $tcp set class_ 2
$tcp set packetSize_ 500 # Packet size
$ns add-agent-trace $tcp trname $tcptrace
$ns monitor-agent-trace $tcp
$tcp tracevar rtt\_
$tcp tracevar cwnd\_
$tcp tracevar ssthresh\_
$tcp tracevar nrexmitpack\_
$tcp tracevar dupacks\_
$tcp tracevar ack\_
$tcp tracevar seqno\_
$tcp tracevar srtt\_
$tcp tracevar rttvar\_
$tcp tracevar backoff\_ $tcp tracevar
maxseq_ set sink [new Agent/TCPSink] $ns
attach-agent $n1 $tcp
$ns attach-agent $n3 $sink $ns connect $tcp
$sink set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 0.2 "$ftp start"
$ns at 0.0001 "$tcp set ssthresh_ 50"
#$ns at 1.35 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
$ns at 20.0 "finish" proc finish {}
{ global ns f nf tcptrace $ns flush-
trace close $f
close $nf close $tcptrace puts
"running nam..." exec nam out1.nam
& exec awk { { if ($6 == "cwnd_")
{ print $1,$7
}
}
} tracelink > cwnd exec xgraph cwnd
}
$ns run

75
PROCEDURE:
1. Form a topology of nodes s0,no and r0 with link between so and r0 with data rate 100mbps with 1ms
delay and between no and ro with 40 mbps and 20ms delay.
2. Vary values of delay and observe the changes in network utilisation and srtt .
3. Now, vary values of ssthresh and note down the duration of slow start mode in TCP.
4. change error rate and note how it affects network utilisation and cwnd.
5. Now, queue size is fixed and cwnd is varied.observe network utilisation.
6. Use these formulas

Throughput= No. of bits/total time


Utilization=throughput/bottleneck BW
where, bottleneck BW is the max data rate defined in a particular link.

OUTPUT:

The output of TCL script are:

1) Tracefile
2) Nam file
1)Tracefile:

2)Nam File

76
Nam File output

Simulating the Nam File

OBSERVATION TABLE:

For observation, packet size=500 and simulation time = 100 seconds. The error rate is
varied as per the table

77
RESULT:

For error rate = 0,


Maximum sequence number = 39488
⸫ Throughput = 39488*500*8/100
= 1.58 Mbps

Congestion window graph for error rate = 0

For error rate = 0.001,


Maximum sequence number = 38734
⸫ Throughput = 38734*500*8/100
= 1.55 Mbps

78
Congestion window graph for error rate = 0.001
For error rate = 0.01,
Maximum sequence number = 33564
⸫ Throughput = 33564*500*8/100
= 1.34 Mbps

CONCLUSION:
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________

79

You might also like