Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Computer Network Lab Manual r22 CSD

Download as pdf or txt
Download as pdf or txt
You are on page 1of 61

lOMoARcPSD|22991856

Computer Network-lab-manual-R22 -CSD

Computer Networks (Jawaharlal Nehru Technological University, Hyderabad)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)
lOMoARcPSD|22991856

SAMSKRUTHI COLLEGE OF ENGINEERING & TECHNOLOGY


(Autonomous Institution – UGC, Govt. of India) Recognized under 2(f) and 12 (B) of UGC ACT 1956
(Affiliated to JNTUH, Hyderabad, Kondapur Village, Ghatkesar M, Hyderabad, Telangana 501301, INDIA)

DEPARTMENT OF COMPUTER SCIENCE ENGINEERING (DATA


SCIENCE)

COMPUTER NETWORKS LAB


LAB MANUAL

II B. TECH II SEMESTER REGULATION: R22/JNTUH

Prepared By

Subject Faculty : G.RAVINDER (Assistant professor)


Department of CSE (DS)
Academic Year : 2024-2024

COMPUTER SCIENCE AND ENGINEERING (Data Science)

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

SAMSKRUTHI COLLEGE OF ENGINEERING & TECHNOLOGY


(Autonomous Institution – UGC, Govt. of India) Recognized under 2(f) and 12 (B) of UGC ACT 1956
(Affiliated to JNTUH, Hyderabad, Kondapur Village, Ghatkesar M, Hyderabad, Telangana 501301, INDIA)

INDEX

S.NO NAMEOF PROGRAM

1 Vision and Mission of Institution and Department

2 COs,POs, PSOs&PEOs

3 Syllabus

4 List of Experiments

5 Programs

6 Contents beyond Syllabus

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

Vision and Mission of the Department and Institute


To become an institute of excellence by creating high quality and
innovating engineering and management professionals who would
Vision of the Institute
take the world into their stride through sustainable growth in
technology and management.
To instill moral values and promote technological, intellectual and
ethical environment to the students with an in-depth and exceptional
education that makes them employment ready as per the emerging

Mission of the trends in industry and to invoke the desire of innovation as a process
Institute of lifelong learning for a successful career in engineering and
management.
To evolve the department of computer science and engineering as a
Vision of the center of academic excellence with latest technologies to transform
Department
students into innovative global leaders.
M1:To produce competitive graduates having creative skills and
Ethical values to succeed in their fields as well as the foundation for
lifelong learning.
Mission of the
M2: By promoting research and development activities
Department
in collaboration with reputed industries and laboratories.
M3:Toanalyze,design and develop high quality software systems
Using the appropriate theory, principles, tools and processes.

Dept.of CSE CS508PC: COMPUTER NETWORKS LAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

COs, POs, PSOs &PEOs

S.NO. Course Objectives

1 To understand the working principle of various communication protocols

To understand the network simulator environment and visualize network


2 topology and Observe its performance

3 To analyze the traffic flow and the contents of protocol frames

Course Outcomes

S.NO. Course Outcomes BTL

CO1 Implement data link layer farming methods

CO2 Analyze error detection and error correction codes.

CO3 Implement and analyze routing and congestion issues in network


design
Implement Encoding and Decoding techniques used in
CO4 presentation layer

CO5 To be able to work with different network tools

Dept.of CSE CS508PC: COMPUTER NETWORKS LAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

Dept.of CSE CS508PC: COMPUTER NETWORKS LAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

S. Program Outcomes Level Expertise


Assessed by
NO.

Engineering knowledge: Apply the


knowledge of mathematics, science,
Assignment,
PO1 engineering fundamentals, and an engineering 3
Tutorials
specialization to the solution of complex
engineering problems.

Problem analysis: Identify, formulate,


review research literature, and analyze
complex engineering problems reaching Assignment,
PO2 3
substantiated conclusions using first Tutorials
principles of mathematics, natural sciences,
and engineering sciences.

Design/development of solutions: Design


solutions for complex engineering problems
and design system components or processes
Assignment,
PO3 that meet the specified needs with appropriate 3
Tutorials
consideration for the public health and safety,
and the cultural, societal, and environmental
considerations.
Conduct investigations of complex
problems: Use research-based knowledge
and research methods including design of
PO4 2 Assignments
experiments, analysis and interpretation of
data, and synthesis of the information to
provide valid conclusions.

Dept.of CSE CS508PC: COMPUTER NETWORKS LAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

PROGRAMOUTCOMES

Modern tool usage: Create, select, and apply


appropriate techniques, resources, and
modern engineering and IT tools including
PO5 2 Assignments
prediction and modeling to complex
engineering activities with an understanding
of the limitations.
The engineer and society: Apply reasoning
informed by the contextual knowledge to
assess societal, health, safety, legal and Assignment,
PO6 3
cultural issues and the consequent Tutorials
responsibilities relevant to the professional
engineering practice.

Environment and sustainability:


Understand the impact of the professional
engineering solutions in societal and
PO7 3 Guest Lectures
environmental contexts, and demonstrate the
knowledge of, and need for sustainable
development.

Ethics: Apply ethical principles and commit


PO8 to professional ethics and responsibilities and 1 --
norms of the engineering practice.
Individual and team work: Function
effectively as an individual, and as a member
PO9 1 --
or leader in diverse teams, and in
multidisciplinary settings

Dept.of CSE CS508PC: COMPUTER NETWORKS LAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

Communication: Communicate effectively


on complex engineering activities with the
PO10 engineering community and with society at 1 --
large, such as, being able to comprehend and
Write effective reports and design
documentation, make effective presentations,
and give and receive clear instructions.

Project management and finance:


Demonstrate knowledge and understanding of
the engineering and management principles
PO11 and apply these to one’s own work, as a 1 --
member and leader in a team, to manage
projects and in multidisciplinary
environments

Life-long learning: Recognize the need for,


and have the preparation and ability to engage
PO12 3 Guest Lectures
in independent and life-long learning in the
broadest context of technological change.

1- None 2-Supportive 3-Highly Related

Dept.of CSE CS508PC: COMPUTER NETWORKS LAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

PROGRAM EDUCATIONAL OBJECTIVES

PEONo. Program Educational Objectives

To apply engineering processes and practices to software and hardware systems


PEO1
skillfully and efficiently.

Ability to understand and analyze engineering issues in a broader prospective


PEO2
with ethical responsibility.

To prepare students to fit into any industry associated with developing and
PEO3
implementation of software products or technologies.

To equip the graduates with ability to analyze, design and test the novel
PEO4
Products.

PROGRAM SPECIFI COUTCOMES

S.No. Program Specific Outcomes Level Expertise & assessed by

Proficiency skill: Potential to understand,


Implement and conduct research in various
PSO1 3 Lecture, Assignments
sub domains of Computer Science
&Engineering.

Analytical skills: Capability to apply


PSO2 theoretical knowledge to practical 3 Lecture, Assignments
implementation for a quality product.

Successful Career and


Entrepreneurship: Preparedness to adopt
PSO3 new technology with unprecedented ideas 1 ----
to be a successful entrepreneur besides a
zeal towards higher studies

1- None 2-Supportive 3-Highly Related

Dept.of CSE CS508PC: COMPUTER NETWORKS LAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

R22 B.TECH CSE(DS) III YEAR

CS508PC: COMPUTER NETWORKS LAB


III Year B.Tech.CSE (DS) I-Sem LTP C
00 31.5
Course Objectives

1. To understand the working principle of various communication protocols.


2. To understand the network simulator environment and visualize a network topology
and Observe its performance
3. To analyze the traffic flow and the contents of protocol frames

Course Outcomes
1. Implement data link layer farming methods
2. Analyze error detection and error correction codes.
3. Implement and analyze routing and congestion issues in network design.
4. Implement Encoding and Decoding techniques used in presentation layer
5. To be able to work with different network tools

List of Experiments
1. Implement the data link layer framing methods such as character, character-stuffing and
bit Stuffing.
2. Write a program to compute CRC code for the polynomials CRC-12,CRC-16 and CRC CCIP

3. Develop a simple data link layer that performs the flow control using the sliding
window protocol and loss recovery using the Go-Back-N mechanism.

4. Implement Dijsktra’s algorithm to compute the shortest path through a network

5. Take an example subnet of hosts and obtain a broadcast tree for the subnet.

6. Implement distance vector routing algorithm for obtaining routing tables at each node.

7. Implement data encryption and data decryption

8. Write a program for congestion control using Leaky bucket algorithm.

9. Write a program for frame sorting technique used in buffers.

10. Wire shark


i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters.

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

11. How to run Nmap scan

12. Operating System Detection using Nmap

13. Do the following usingNS2 Simulator


i. NS2 Simulator-Introduction
ii. Simulate to Find the Number of Packets Dropped
iii. Simulate to Find the Number of Packets Dropped by TCP/UDP
iv. Simulate to Find the Number of Packets Dropped due to Congestion
v. Simulate to Compare Data Rate &Throughput.
vi. Simulate to Plot Congestion for Different Source/Destination
vii. Simulate to Determine the Performance with respect to Transmission of Packets

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

1. Implement the data link layer framing methods such as character, character-stuffing
and bit stuffing
Write a C program to implement the data link layer framing methods such as bit stuffing.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
clrscr();
printf("enter frame
length:");scanf("%d",&n);
pritf("enter input frame(0's&1's only):");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
i=0;count=1;j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1;a[k]==1&&k<n&&count<5;k++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}
}
else
{
b[j]=a[i];
}
i++;
j++;
}

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

printf("After stuffing the frame is:");


for(i=0;i<j;i++)
printf("%d",b[i]);
getch();
}
Output:

Enterthenumberof
bits: 10
1
0
1
0
1
1
1
1
1
1
1
Data after stuffing: 10101111101

Write a C program to implement the data link layer framing method such as
character stuffing.

ProgramCode://Program for Character Stuffing


#include<stdio.h>
#include<string.h>
#include<process.h>
void main()
{
int i=0,j=0,n,pos;
chara[20],b[50],ch;
printf("Enter string\n");
scanf("%s",&a);
n=strlen(a);
printf("Enter position\n");
scanf("%d",&pos);
if(pos>n)
{
printf("invalid position,Enter again:");
scanf("%d",&pos);}
printf("Enter the character\ n");
ch=getche();

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
{
if(i==pos-1)
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
}
if(a[i]=='d'&&a[i+1]=='l'&&a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
}
b[j]=a[i];
i++;
j++;
}
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("\n frame after stuffing:\
n"); printf("%s",b);
}
Program Output:
Enter string
MLRITM

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

Enter position
2
Enter the character frame
after stuffing:
dlestxMdldleLRITMdleetx

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

2. Write a program to compute CRC code for the polynomials CRC-12,CRC-16andCRC


CCIP

//program for Cyclic Redundancy Check


#include<stdio.h>
#include<conio.h>
int main(void)
{
intdata[50],div[16],rem[16];
int datalen, divlen, i,j,k;
int ch;
clrscr();
printf("Enter the data:");
i = 0;
while((ch=fgetc(stdin)) != '\n')
{
if(ch== '1')
data[i]=1;
else
data[i]=0; i+
+;
}
datalen =i;
printf("\nEnter the divisor:");
i = 0;
while((ch=fgetc(stdin)) != '\n')
{
if(ch== '1')
div[i]=1;
else
div[i]=0; i+
+;
}
divlen =i;
for(i=datalen;i<datalen+divlen-1;i++)
data[i] = 0;
datalen=datalen+divlen-1;
for(i = 0 ; i < divlen ; i++)
rem[i] = data[i];
k=divlen-1;
while(k <datalen)

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

if(rem[0]== 1)
{
for(i=0;i<divlen;i++)
rem[i] = rem[i] ^ div[i];
}
else
{
if(k==datalen-1)
break;
for(i = 0 ; i<divlen-1;i++)
{
rem[i] = rem[i+1];
printf("%d",rem[i]);
}
rem[i] = data[++k];
printf("%d\n",rem[i]);
}
j=1;
for(i =datalen -divlen+1;i <datalen ;i++)
{
data[i] = rem[j++];
}
printf("\nThe data to be sent is\n");
for(i = 0 ; i < datalen ; i++)
printf("%d",data[i]);
getch();
return0;
}
OUTPUT:
Enter the data:10101111 Enter the divisor:1011
0011
0111
1111
1001
0100
1000
0110
The data to be sent is 10101111110

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

3. Develop a simple data link layer that performs the flow control using the sliding window
protocol, and loss recovery using the Go-Back-N mechanism

SLIDING WINDOW PROTOCOL,


#include<stdio.h>
int main()
{
int window size,sent=0,ack,i;
printf("enter window size\n");
scanf("%d",&windowsize);
while(1)
{
for( i=0;i<windowsize;i++)
{
printf("Frame%d has been transmitted.\n",sent);
sent++;
if(sent ==windowsize)
break;
}
printf("\nPlease enter the last Acknowledgement received.\n");
scanf("%d",&ack);

if(ack==windowsize)
break;

else
} sent=ack;
return0;
}

output:-

Output
Enterwindowsize:3
Enter number of frames to transmit:5
Enter 5 frames: 12 5 89 4 6
With sliding window protocol the frames will be sent in the following manner(assuming
no corruption of frames)
After sending 3 frames a teach stage sender waits for acknowledgement sent by the
receiver
12589
Acknowledgement of above frames sent is received by
sender 4 6
Acknowledgement of above frames sent is received by sender

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

GOBACKN PROTOCOL
#include<stdio.h>
int main()
{
int windowsize,sent=0,ack,i;
printf("enter window size\ n");
scanf("%d",&windowsize);
while(1)
{
for( i=0;i<windowsize;i++)
{
printf("Frame%d has been transmitted.\n",sent);
sent++;
if(sent==windowsize)
break;
}
printf("\n Please enter the last Acknowledgement received.\n");
scanf("%d",&ack);

if(ack==windowsize)
break;
else
sent=ack;
}
return0;
}
output:-
enter window
size 8
Frame0 has been transmitted.
Frame1 has been transmitted.
Frame2 has been transmitted.
Frame3 has been transmitted.
Frame4 has been transmitted.
Frame5 has been transmitted.
Frame6 has been transmitted.
Frame7 has been transmitted.
Please enter the last Acknowledgement
received. 2
Frame2 has been transmitted.
Frame3 has been transmitted.

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

Frame4 has been transmitted.


Frame5 has been transmitted.
Frame6 has been transmitted.
Frame7 has been transmitted.

Please enter the last Acknowledgement


received. 8

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

4. Implement Dijsktra’s algorithm to compute the shortest path through a network

Write a C program to Implement Dijkstra’s Algorithm to compute the


shortest path through a given path.

#include<stdio.h>
#include<conio.h>
#define INFINITY
#define MAX 10
void dijkstra(int G[MAX][MAX],int n,int startnode);
int main()
{
int G[MAX][MAX],i,j,n,u;
printf("Enterno.ofvertices:");
scanf("%d",&n);
printf("\nEnter the adjacency matrix:\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++) scanf("%d",&G[i]
[j]);
printf("\nEnter the startingnode:");
scanf("%d",&u);
dijkstra(G,n,u);
return0;
}
void dijkstra(int G[MAX][MAX],int n,int startnode)
{
int cost[MAX] [MAX],distance[MAX],pred[MAX];
int visited[MAX],count,mindistance,nextnode,i,j;
//pred[] stores the predecessor of each node
//count gives the number of nodes seen so far
//create the cost matrix for(i=0;i<n;i+
+)
for(j=0;j<n;j++)if(G[i][j]==0)
cost[i][j]=INFINITY;
else
cost[i][j]=G[i][j];
//initialize pred[],distance[] and visited[]
for(i=0;i<n;i++)
{
distance[i]=cost[startnode][i];
pred[i]=startnode;
visited[i]=0;
}
distance[startnode]=0;
visited[startnode]=1;count=1;

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

while(count<n-1)
{
mindistance=INFINITY;
//next node gives the node at minimum distance
for(i=0;i<n;i++)
if(distance[i]<mindistance&&!visited[i])
{
mindistance=distance[i];
nextnode=i;
}
//check if a better path exists through nextnode
visited[nextnode]=1;
for(i=0;i<n;i++)
if(!visited[i])
if(mindistance+cost[nextnode][i]<distance[i])
{

distance[i]=mindistance+cost[nextnode][i];
} pred[i]=nextnode;

count++;

}
//print the path and distance of each node
for (i=0;i<n;i++)
if(i!=startnode)
{
printf("\nDistance of node%d=%d",i,distance[i]);
printf("\nPath=%d",i);
j=i;
do
{
j=pred[j];
printf("<-%d",j);

while(j!=startnode);
}
}

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

5. Take an example subnet of hosts and obtain a broadcast tree for the subnet.
#include<stdio.h>
int a[10][10],n;
main()
{
int i,j,root; clrscr();
printf("Enter no.of nodes:");
scanf("%d",&n);
printf("Enteradjacentmatrix\ n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
printf("Enterconnectingof%d>%d::",i,j);
scanf("%d",&a[i][j]);
}
printf("Enterrootnode:");
scanf("%d",&root);
adj(root);
}
adj(int k)
{
int i,j;
printf("Adjacent node of rootnode::\n");
printf("%d\n",k);
for(j=1;j<=n;j++)
{
if(a[k][j]==1||a[j][k]==1) printf("%d\t",j);
}
printf("\n");
for(i=1;i<=n;i++)
{
if((a[k][j]==0)&&(a[i][k]==0)&&(i!=k))
printf("%d",i);
}
}
OUTPUT:
Enterno.ofnodes:5
Enteradjacent matrix
Enterconnectingof1–>1::0Enterconnectingof 1–>2::1Enter connectingof1–>3::1
Enterconnectingof1–>4::0Enterconnectingof 1–>5::0Enter connectingof2–>1::1
Enterconnectingof2–>2::0Enterconnectingof 2–>3::1Enter connectingof2–>4::1
Enterconnectingof2–>5::0Enterconnectingof 3–>1::1Enter connectingof3–>2::1
Enterconnectingof3–>3::0Enterconnectingof 3–>4::0Enter connectingof3–>5::0
Enterconnectingof4–>1::0Enterconnectingof 4–>2::1Enter connectingof4–>3::0
Enterconnectingof4–>4::0Enterconnectingof 4–>5::1Enter connectingof5–>1::0
Enter connecting of 5–>2::0
Enterconnectingof5–>3::0Enterconnectingof5–>4::1Enterconnectingof5–
>5::0 Enter root node:2
Adjacentnodeofrootnode: 2
134
5
Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

6. Implement distance vector routing algorithm for obtaining routing tables at each node.

#include<stdio.h>

struct node
{
unsigned dist[20];
unsignedfrom[20];
}
rt[10];
int main()
{
int dmat[20][20];
intn,i,j,k,count=0;
printf("\nEnter the number of nodes:");
scanf("%d",&n);
printf("\nEnter the cost matrix:\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&dmat[i][j]);
dmat[i][i]=0;
rt[i].dist[j]=dmat[i][j];
rt[i].from[j]=j;
}
do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j])
{
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
}
while(count!=0);
for(i=0;i<n;i++)
{
printf("\n\nState value for router%dis\n",i+1);
for(j=0;j<n;j++)
{
printf("\t\nnode%dvia%dDistance%d",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
}

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

OUTPUT:
[cseb332@Insat5E~]$ccdst.c
[cseb332@Insat5E ~]$ ./a.out

Enterthenumberofnodes:4 Enter
the cost matrix:
035 99
3099 1
540 2
9912 0
Statevalueforrouter1is
node 1 via 1 Distance0
node2via2Distance3
node3via3Distance5
node4via2Distance4
Statevalueforrouter2is
node 1 via 1 Distance3
node2via2Distance0
node3via4Distance3
node4via4Distance1
Statevalueforrouter3is
node 1 via 1 Distance5
node2via4Distance3
node3via3Distance0
node4via4Distance2
Statevalueforrouter4is
node 1 via 2 Distance4
node2via2Distance1
node3via3Distance2
node4via4Distance0

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

7. Implement data encryption and data decryption


#include<stdio.h>
#include<conio.h>
#include<string.h>
int p10[]={3,5,2,7,4,10,1,9,8,6},
p8[]={6,3,7,4,8,5,10,9},
p4[]={2,4,3,1};
int ip[]={2,6,3,1,4,8,5,7},
ipinv[]={4,1,3,5,7,2,8,6},
ep[]={4,1,2,3,2,3,4,1};
ints0[][4]={{1,0,3,2,},{3,2,1,0},{0,2,1,3,},{3,1,3,2}};
int s1[][4]={{0,1,2,3},{2,0,1,3},{3,0,1,0},{2,1,0,3}};
void
permute(charop[],charip[],i
ntp[],intn){ int i;
for(i=0;i<n;i++)op[i]=ip[p[i]-1];
op[i]='\0';
}
void circularls(charpr[],intn)
{
int i;
charch=pr[0];
for(i=0;i<n-1;i++)
pr[i]=pr[i+1];
pr[i]=ch;
}
voidkeygen(chark1[],chark2[],charkey[])
{
charkeytemp[11];
permute(keytemp,key,p10,10);
circularls(keytemp,5);
circularls(keytemp+5,5);
permute(k1,keytemp,p8,8);
circularls(keytemp,5);
circularls(keytemp,5);
circularls(keytemp+5,5);
circularls(keytemp+5,5);
permute(k2,keytemp,p8,8);
}
voidxor(charop[],charip[])
{
inti;
for(i=0;i<strlen(op)&&i<str len(ip);i++)
op[i]=(op[i]-'0')^(ip[i]-'0')+'0';
}

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

void sbox(char op[],char ip[],int s[][4])


{
int value;
value=s[(ip[0]-'0')*2+(ip[3]-'0')][(ip[1]-'0')*2+(ip[2]-'0')];
op[0]=value/2+'0';
op[1]=value%2+'0';
op[2]='\0';
}
void fk(char op[],char ip[],char k[])
{
charl[5],r[5],tmp[9],tmp1[9],tmp2[9];
strncpy(l,ip,4); l[4]='\0';
strncpy(r,ip+4,4);r[4]='\0';
permute(tmp,r,ep,8);
xor(tmp,k);
sbox(tmp1,tmp,s0);sbox(tmp2,tmp+4,s1);
strcat(tmp1,tmp2);
permute(tmp,tmp1,p4,4);
xor(tmp,l);
strcat(tmp,r);
strcpy(op,tmp);
}
voidsw(charpr[])
{
chartmp[9];
strncpy(tmp,pr+4,4);
strncpy(tmp+4,pr,4);
tmp[8]='\0';
strcpy(pr,tmp);
}
void main()
{
char key[11],k1[9],k2[9],plain[9],cipher[9],tmp[9];
clrscr();
printf("enter 10 bit key:");
gets(key); if(strlen(key)!=10)
printf("invalidkeylength!!");
else
{
keygen(k1,k2,key);
printf("subkeyk1::");
puts(k1);
printf("subkeyk2::");
puts(k2);
printf("enter 8 bit plain text:");
gets(plain);
Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

if(strlen(plain)!=8)
printf("invalidlengthplaintext!!");
permute(tmp,plain,ip,8);
fk(cipher,tmp,k1);
sw(cipher);
fk(tmp,cipher,k2);
permute(cipher,tmp,ipinv,8);
printf("cipher teaxt is::");
puts(cipher);
/* decryption process*/
permute(tmp,cipher,ip,8);
fk(plain,tmp,k2);
sw(plain); fk(tmp,plain,k1);
permute(plain,tmp,ipinv,8);
printf("decryptedtextis::");
puts(plain);
}
getch();
}

OUTPUT:
Enter10bitkey:1456987203Subkeyk1::17062538 Sub
keyk2::25893401
Enter8bitplaintext:computerCiphertextis::epfnmrct
Decrypted text is::computer

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

8. Write a program for congestion control using Leaky bucket algorithm.


#include<stdio.h>
#include<string.h>
int min(intx,inty)
{
if(x<y)
returnx;
else
returny;
}

int main()
{
intdrop=0,mini,nsec,cap,count=0,i,inp[25],process;
syste("clear");
printf("Enter The Bucket Size\n");
scanf("%d",&cap);
printf("Enter The Processing Rate\n");
scanf("%d",&process);
printf("EnterTheNo.Of Seconds You Want To Stimulate\n");
scanf("%d",&nsec);
for(i=0;i<nsec;i++)
{
printf("Enter The Size Of The Packet Entering At %d sec\n",i+1);
scanf("%d",&inp[i]);
}
printf("\nSecond|PacketRecieved|PacketSent|PacketLeft|PacketDropped|\n");
printf(" \n");
for(i=0;i<nsec;i++)
{
count+=inp[i];
if(count>cap)
{
drop=count-cap;
count=cap;
}
printf("%d",i+1);
printf("\t%d",inp[i]);
mini=min(count,process);
printf("\t\t%d",mini);
count=count-mini;
printf("\t\t%d",count);
printf("\t\t%d\n",drop);
drop=0;
}
for(;count!=0;i++)

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

{
if(count>cap)
{
drop=count-cap;
count=cap;
}
printf("%d",i+1);
printf("\t0");
mini=min(count,process);
printf("\t\t%d",mini);
count=count-mini;
printf("\t\t%d",count);
printf("\t\t%d\n",drop);
}
}
$cc –o CongestionCongestion.c
$./Congestion
EnterTheBucketSize 5
EnterTheProcessingRate 2
EnterTheNo.OfSecondsYouWantToStimulate 3
EnterTheSizeOfThePacketEnteringAt1sec 5
EnterTheSizeOfThePacketEnteringAt1sec 4
EnterTheSizeOfThePacketEnteringAt1sec 3
Second|PacketRecieved|PacketSent|Packet Left|PacketDropped|
1 5 2 3 0
2 4 2 3 2
3 3 2 3 1
4 0 2 1 0
5 0

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

9. Write a program for frame sorting technique used in buffers.

#include<stdio.h>
#include<string.h>
#defineFRAM_TXT_SIZ3
#defineMAX_NOF_FRAM127
char str[FRAM_TXT_SIZ*MAX_NOF_FRAM];
structframe//structure maintained to hold frames
{
char
text[FRAM_TXT_SIZ];
int seq_no;
}
fr[MAX_NOF_FRAM],shuf_ary[MAX_NOF_FRAM];
int assign_seq_no() //function which splits message
{
int k=0,i,j;//intoframesandassignssequenceno
for(i=0;i<strlen(str);k++)
{
fr[k].seq_no=k;
for(j=0;j<FRAM_TXT_SIZ&&str[i]!='\0';j++)
fr[k].text[j] = str[i++];
}
printf("\nAfterassigningsequencenumbers:\n");
for(i=0; i < k; i++)
printf("%d:%s ",i,fr[i].text);
returnk;//kgivesnoofframes
}
voidgenerate(int *random_ary,constintlimit)//generatearrayofrandomnos
{
intr,i=0,j;
while(i <limit)
{
r =random()% limit;

for(j=0;j<i;j++)
if(random_ary[j] == r )
Break;
if(i==j) random_ary[i++]=r;
}
}
Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

voidshuffle(constintno_frames)//functionshufflesthe frames
{
inti,k=0,random_ary[no_frames];
generate(random_ary, no_frames);
for(i=0; i < no_frames; i++)
shuf_ary[i] = fr[random_ary[i]];
printf("\n\nAFTERSHUFFLING:\n");
for(i=0; i < no_frames; i++)
printf("%d:%s",shuf_ary[i].seq_no,shuf_ary[i].text);
}
void sort(constintno_frames)//sortsthe frames
{
inti,j,flag=1;
struct frame hold;
for(i=0;i<no_frames-1&&flag==1;i++)//searchforframesinsequence
{
flag=0;
for(j=0;j<no_frames-1-i;j++)//(basedonseqno.)and display
if(shuf_ary[j].seq_no>shuf_ary[j+1].seq_no)
{
hold = shuf_ary[j];
shuf_ary[j]=shuf_ary[j+1];
shuf_ary[j+1] = hold;
flag=1;
}
}
}
intmain()
{
int no_frames,i;
printf("Enterthemessage:");
gets(str);
no_frames=assign_seq_no();
shuffle(no_frames);
sort(no_frames); printf("\n\
nAFTER SORTING\n");
for(i=0;i<no_frames;i++)
printf("%s",shuf_ary[i].text);
printf("\n\n");
}

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

[root@localhostnwcn]#./a.out
Enter the message:Welcome To Acharya Institute of Technology
After assigning sequence numbers:
0:Wel1:com2:eT3:oA4:cha5:rya6:In 7:sti8:tut9:eo10:fT11:ech12:nol13:ogy AFTER
SHUFFLING:
1:com4:cha9:eo5:rya3:oA10:fT2:eT6:In11:ech13:ogy0:Wel8:tut12:nol7:sti AFTER
SORTING
WelcomeToAcharyaInstituteofTechnology

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

10. Wire shark


i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters.

Capturing Packets
After downloading and installing Wires hark, you can launch it and double-click the name of a network
interface under Capture to start capturing packets on that interface. For example, if you want to capture traffic
on your wireless network, click your wireless interface .You can configure advanced features by clicking
Capture > Options, but this isn’t necessary for now

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

Inspecting Packets
Click a packet to select it and you can dig down to view its details.

Start Wire shark, click on Statistics.


How to do it…

1. From the Statistics menu,choose Capture File Properties:

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

11. How to run Nmap scan


Nmap is one of the most popular network mappers in the infosec world. It’s utilized by cyber
security professionals and newbies alike to audit and discover local and remote open ports, as
well as hosts and network information.
Nmap can be used to:

 Create a complete computer network map.


 Find remote IP addresses of any hosts.
 Get the OS system and software details.
 Detect open ports on local and remote systems.
 Audit server security standards.
 Find vulnerabilities on remote and local hosts.
Nmap command examples
Let’s get to know a few useful command-line based scans that can be performed using Nmap.

1. Basic Nmap Scan against IP or host

nNow,if you want to scan a hostname, simply replace the IP for the host, as you see below:

nmap cloudflare.com

These kinds of basic scans are perfect for your first steps when starting with map

2. Scan specific ports or scan entire port ranges on a local or remote server nmap -p 1-65535 local host

In this example, we scanned all 65535 ports for our local host computer.

Nmap is able to scan all possible ports, but you can also scan specific ports, which will report
faster results. See below:

nmap-p80,4438.8.8.8

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

12. Operating System Detection using Nmap

Detect OS and services

This is the command to scan and search for the OS(and the OS version) on a host. This command
will provide valuable information for the enumeration phase of your network security assessment
(if you only want to detect the operating system, type nmap -O 192.168.0.9):

nmap-A 192.168.0.9

Standard service detection

This is the command to scan for running service.Nmap contains a database of about 2,200 well-
known services and associated ports. Examples of these services are HTTP (port 80), SMTP
(port 25), DNS (port 53), and SSH (port 22):

nmap-sV192.168.0.9

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

13. Do the following using NS2 Simulator

i. NS-2SimulatorIntroduction

NS2standsforNetworkSimulatorVersion2.Itisanopen-sourceevent-drivensimulator designed
specifically for research in computer communication networks.

FeaturesofNS2
It is a discrete event simulator for networking research.
It provides substantial support to simulate bunch of protocols likeTCP,FTP,UDP,httpsand DSR.
It simulates wired and wireless network.
It is primarily Unix based.
Uses TCL as its scripting language.
Otcl:Object oriented support
Tclcl:C++ and otcl linkage
Discrete event scheduler Basic Architecture
NS2 consists of two key languages: C++ and Object-oriented Tool Command Language
(Outcall). While the C++ defines the internal mechanism (i.e., a backend) of the simulation
objects, the OTcl sets up simulation by assembling and configuring the objects as well as
scheduling discrete events. The C++ and the OTcl are linked together using TclCL

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

ii. Simulate to Find the Number of Packets

Create a new Simulation Instance


set ns [new Simulator]
set band width1.75Mb
#Turn on the Trace and the animation files
set f [open out.tr w]
set nf[openout.nam w]
$ns trace-all$f
$ns namtrace-all$nf
#Define the finish procedure to perform at the end of the simulation

proc finish {} {
global f nf ns
$nsflush-trace
close $f
close$nf
exec namout.nam &
#execawk-f1.awkout.tr&
exit 0
}
#Create the
nodes set n0 [$ns
node] set n1 [$ns
node] set n2 [$ns
node]

#Label the nodes


$n0label"TCPSource"
$n1label"UDP Source"
$n2label"Sink"
#Set the color
$nscolor1 red
$nscolor2 yellow
#Create the Topology
$ns duplex-link $n0 $n1 $bandwidth 10ms DropTail
$ns duplex-link$n1 $n21.75Mb20ms DropTail
#Attach a Queue of size N Packets between the nodes n1 n2
$ns queue-limit $n1 $n2 10
#Make the Link Orientation
$ns duplex-link-op$n0 $n1orient right
$ns duplex-link-op$n1 $n2orient right

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

#Create a UDP Agent and attach to the node n1


set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
#Create a CBR Traffic source and attach to the UDP Agent
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
#Specify the Packet Size and interval
$cbr0 set packetSize_500
$cbr0 set interval_ 0.005
#Create a Null Agent and attach to the noden2
set null0 [new Agent/Null]
$ns attach-agent $n2 $null0
#Connect the CBR Traffic source to the Null agent
$ns connect $udp0 $null0
#Create a TCP agent and attach to the noden0
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
#Create a FTP source and attach to the TCP agent
set ftp0 [new Application/FTP]
#Attach the FTP source to the TCP Agent
$ftp0 attach-agent $tcp0
#Create a TCPSink agent and attach to the noden2
set sink [new Agent/TCPSink]
$ns attach-agent $n2 $sink
#Specify the Maxfile Size in Bytes
$ftp0setmaxPkts_ 1000
#Connect the TCP Agent with the TCPSink
$ns connect $tcp0 $sink
$udp0 setclass_1
$tcp0 setclass_2
#Schedule the Events
$ns at0.1"$cbr0 start"
$n sat1.0"$ftp0 start"
$ns at4.0"$ftp0 stop"
$ns at4.5"$cbr0 stop"
$ns at5.0 "finish"
$ns run

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

Now run the code using


ns filename.tcl
you will get something like this:

iii. Simulate to Find the Number of Packets Dropped by TCP/UDP

Create a new Simulation Instance


set ns [new Simulator]
set bandwidth 1.75Mb
#Turn on the Trace and the animation files
set f [open out.tr w]
set nf[open out.nam w]
$ns trace-all $f
$ns namtrace-all $nf
#Define the finish procedure to perform at the end of the simulation
proc finish {} {
global f nf ns
$ns flush-trace
close $f
close $nf
exec nam out.nam&
#exec awk-f1.awkout.tr&
exit 0
}
#Create the
nodes set n0 [$ns
node] set n1 [$ns
node] set n2 [$ns
node] #Label the
nodes
Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

$n0 label "TCP Source"


$n1 label "UDP Source"

$n2 label
"Sink"# Set the
color
$ns color1 red
$ns color 2 yellow
#Create the Topology
$ns duplex-link $n0 $n1 $band width10 ms DropTail
$ns duplex-link $n1 $n21.75Mb 20ms DropTail
#Attach a Queue of size N Packets between the nodes n1 n2
$ns queue-limit $n1 $n210
#Make the Link Orientation
$ns duplex-link-op $n0 $n1orient right
$ns duplex-link-op $n1 $n2 orient right
#Create a UDP Agent and attach to the node
n1 set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
#Create a CBR Traffic source and attach to the UDP Agent
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
#Specify the Packet Size and interval
$cbr0setpacketSize_500
$cbr0setinterval_ 0.005
#Create a Null Agent and attachtothenoden2
set null0 [new Agent/Null]
$nsattach-agent$n2$null0
#Connect the CBR Traffic source to the Null agent
$ns connect $udp0 $null0
#Create a TCP agent and attach to the noden0
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
#Create a FTP source and attach to the TCP agent
set ftp0 [new Application/FTP]
#Attach the FTP source to the TCP Agent
$ftp0 attach-agent $ tcp0
#Create a TCP Sink agent and attach to the noden2
set sink [new Agent/TCPSink]
$ns attach-agent $n2 $sink
#Specify the Maxfile Size in Bytes
$ftp0 setmaxPkts_ 1000
#Connect the TCP Agent with the TCPSink
$ns connect $tcp0 $sink
Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

$udp0 setclass_1

$tcp0 setclass_2
#Schedule the
Events
$ns at0.1"$cbr0 start"
$ns at1.0"$ftp0 start"
$ns at4.0"$ftp0 stop"
$ns at4.5"$cbr0 stop"
$ns at5.0 "finish"
$ns run

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

iv. Simulate to Find the Number of Packets Dropped due to Congestion

#Create a new Simulation Instance


set ns [new Simulator]
set bandwidth1.75Mb
#Turn on the Trace and the animation files
set f [open out.tr w]
set nf[openout.nam w]
$ns trace-all $f
$ns namtrace-all $nf
#Define the finish procedure to perform at the end of the simulation
proc finish{}
{
global f nf ns
$ns flush-trace
close $f
close $nf
exec nam out.nam&
#exec awk-f1.awkout.tr&
exit 0
}
#Create the nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]

#Label the nodes


$n0 label"TCPSource"
$n1 label"UDP Source"
$n2 label"Sink"

#Set the color

$nscolor1 red
$nscolor2 yellow
#Create the Topology
$ns duplex-link$n0 $n1$band width10ms DropTail
$ns duplex-link$n1 $n21.75Mb 20ms DropTail
#Attach a Queue of size N Packets between the nodes n1 n2
$ns queue-limit $n1$n210
#Make the Link Orientation

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

$ns duplex-link-op$n0$n1orient right


$ns duplex-link-op $n1 $n2 orient right
#Create a UDP Agent and attach to the noden1
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
#Create a CBR Traffic source and attach to the UDPAgent
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
#Specify the Packet Size and interval
$cbr0 set packetSize_500
$cbr0 set interval_ 0.005
#Create a Null Agent and attach to the noden2
set null0 [new Agent/Null]
$ns attach-agent $n2 $null0
#Connect the CBR Traffic source to the Null agent
$ns connect $udp0 $null0
#Create a TCP agent and attach to the noden0
set tcp0 [new Agent/TCP]
$ns attach-agent$n0 $tcp0
#Create a FTP source and attach to the TCP agent
set ftp0 [new Application/FTP]
#Attach the FTP source to the TCP Agent
$ftp0 attach-agent $tcp0
#Create a TCPSink agent and attach to the noden2
set sink [new Agent/TCPSink]
$ns attach-agent$n 2$sink
#Specify the Max file Size in Bytes
$ftp0 set maxPkts_ 1000
#Connect the TCP Agent with the TCPSink
$ns connect $tcp0 $sink
$udp0 setclass_1
$tcp0 setclass_2
#Schedule the Events
$ns at0.1"$cbr0 start"
$ns at1.0"$ftp0 start"
$ns at4.0"$ftp0 stop"
$ns at4.5"$cbr0 stop"
$ns at5.0 "finish"
$ns run

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

v. Simulate to Compare Data Rate & Throughput

#Filename:sample27.tcl
#Simulat or Instance Creation
set ns [new Simulator]

#Fixing the co-ordinate of simulation area


set val(x) 500
set val(y)500
#Define options
set val(chan) Channel/Wireless Channel;
#channel type
setval(prop)Propagation/TwoRayGround;
#radio-propagation model set val(netif) Phy/WirelessPhy ;
# network interface type
setval(mac)Mac/802_11;
#MAC type
setval(ifq)Queue/DropTail/PriQueue;
#interfacequeuetype set val(ll) LL ;
# link layer type
setval(ant) Antenna/Omni Antenna;
#antennamodel set val(ifqlen) 50 ;
# max packet in if q setval(nn)3;
#number of mobile nodes set val(rp) AODV ;
# routing protocol
setval(x)500;
#Xdimension of topography setval(y)500;
#Ydimension of topography set val(stop) 10.0 ;
# time of simulation end
Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

#set up topography object

set topo [new Topography]


$topo load_flat grid $val(x) $val(y)

#Nam File Creation nam–network animator


set nam file [open sample27.nam w]

#Tracing all the events and cofiguration


$ns nam trace-all-wireless $namfile $val(x) $val(y)

#Trace File creation


set trace file[opensample27.trw]

#Tracing all the events and cofiguration


$ns trace-all $trace file

#general operational descriptor-storing the hop details in the network


create-god $val(nn)

#configurethe nodes
$ns node-config –adhoc Routing $val(rp)\
-llType $val(ll)\
-mac Type $val(mac)\
-ifq Type $val(ifq)\
-ifq Len $val(ifqlen) \
-ant Type $val(ant)\
-prop Type$val(prop)\
-phy Type$val(netif)\
-channel Type$val(chan)\
-topo Instance$topo\
-agent TraceON\
-router TraceON\
-mac TraceOFF\
-movement Trace ON

# Node Creation

for{seti0}{$i<3}{incri}
{

set node_($i) [$ns node]


$node_($i)color black

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

#Location fixing for a single node

$node_(0)setX_ 258
$node_(0)setY_ 222
$node_(0)setZ_ 0

for{seti1}{$i<3}{incri}
{

$node_($i)setX_[expr rand()*$val(x)]
$node_($i)setY_[expr rand()*$val(y)]
$node_($i)setZ_ 0

}
#Label and coloring

for{seti0}{$i<3}{incri} {

$nsat0.1 "$node_($i)colorblue"
$nsat 0.1"$node_($i)labelNode$i"

}
#Size of the node

for{seti0}{$i<3}{incri} {

$nsinitial_node_pos$node_($i)30

}
#******************************Defining Communication Between node0 and all nodes
****************************8

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

for{seti1}{$i<3}{incri} {

#Defining a transport agent for sending


set udp [new Agent/UDP]

#Attaching transport agent to sender node


$ns attach-agent $node_($i)$udp

#Defining a transport agent for receiving


set null [new Agent/Null]

#Attaching transport agent to receiver node


$ns attach-agent $node_(0)$null

#Connecting sending and receiving transport agents


$ns connect $udp $null

#Defining Application instance


set cbr[newApplication/Traffic/CBR]

#Attaching transport agent to application agent


$cbr attach-agent $udp

#Packet size in bytes and interval in seconds definition


$cbr set packet Size_512
$cbr set interval_0.1

#data packet generation starting time


$ns at1.0"$cbr start"

#data packet generation ending time


#$ns at 6.0 "$cbr stop"

}
#ending nam and the simulation
$ns at$val(stop)"$ns nam-end-wireless$ val(stop)"
$ns at$val(stop)"stop"

#Stopping the scheduler


$ns at10.01"puts\"end simulation\";$ns halt"
#$ns at 10.01 "$ns halt"

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

exec awk-f Throughput.awk sample27.tr>Throughput.tr&


#Starting scheduler
$ns run
#filename:Throughput.awk

#———Formula————:

Throughput =

received_data*8/DataTransmissionPeriod#———

AWK script Format——–#


The script has the followingformat:
BEGIN{}
{
content
}
END {}
Begin part comprises of initialization of variable.
Commands in thecontent part scan every row of trace file only once.
Ex:
if(pattern){
action;
}

If the pattern is matched with the line in the trace in the trace file specified action will be
performed.

In the END partfinal calculation is performed on the data obtained from the content part.#

———Steps————:

1. set pattern and action for received data


2. apply the received data value in the formula to calculate throughput in

bits/s Execution:

ns sample27.tcl

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

vi. Simulate to Plot Congestion for Different Source/Destination

set ns[new Simulator]


set nf[open"lab3.nam"w]
$ns nam trace-all$nf
set tf[open"lab3.tr"w]
$ns trace-all $tf
set n0[$nsnode]
$n0 label"src1"
$n0 color "magenta"

set n1[$ns node]


$n1 color "red"
set n2[$nsnode]
$n2 label"src2"
$n2 color"magenta"
set n4 [$ns node]
$n4 color "red"
set n3[$nsnode]
$n3 label"dest2"
$n3 color "blue"
set n5[$nsnode]
Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

$n5 label"dest1"

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

$n5 color "blue"


$ns make-lan"$n0$n1$n2$n3$n4"100Mb10ms LLQueue/DropTail Mac/802_3
$ns duplex-link$n4$n5100Mb10msDropTail set
tcp0 [new Agent/TCP]
$ns attach-agent$n0$tcp0
set ftp0[newApplication/FTP]
$ft p0attach-agent$tcp0
$ft p0setpacketSize_1000
$ft p0setinterval_ 0.005
set Sink0[newAgent/TCPSink]
$ns attach-agent$n5$Sink0
$ns connect$tcp0$Sink0
set tcp1[newAgent/TCP]
$ns attach-agent$n2$tcp1
set ftp1[new Application/FTP]
$ft p1attach-agent$tcp1
$ft p1setpacketSize_10000
$ft p1setinterval_0.0005
set Sink1[newAgent/TCPSink]
$ns attach-agent$n3$Sink1
$ns connect$tcp1$Sink1 set
file0 [open "file0.tr"w]
$tcp0 attach $file0
set file1[open"file1.tr"w]
$tcp1attach $file1
$tcp0 tracecwnd_
$tcp1 trace cwnd_proc finish
{}
{
global ns nf tf
$ns flush-trace
close$nf close
$tf
exec namlab3.nam&
exit 0
}
$ns at0.1"$ftp0 start"
$ns at0.5"$ftp0stop"
$ns at0.8"$ftp0 start"
$ns at0.9"$ftp1 start"
$ns at1.1"$ftp1stop"
$ns at1.5"$ftp0 stop"

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

$ns at1.8"$ftp1 start"


$ns at2.2"$ftp1stop"
$ns at2.9 "finish"
$ns run

AWKfile(Open a new edit or using“gedit command”and write a wkfile and save with“.awk”
extension)

cwnd:-means congestion window

BEGIN{
}
{
if($6=="cwnd_")
{
printf("%f\t%f\n",$1,$7);
}
}
END{
}

vii. Simulate to Determine the Performance with respect to Transmission of Packets

# basic1.tclsimulation: A---R---B

#Create a simulator object


set ns[new Simulator]

#Open the nam filebasic1.nam and the variable-trace file basic1.tr


set nam file [open basic1.nam w]
$ns nam trace-all$nam file
set trace file[openbasic1.trw]
$ns trace-all$trace file

#Define a 'finish' procedure


proc finish {} {
global ns nam file trace file
$ns flush-trace
close $namfile
close $tracefile
exit 0
}

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

#Create the network nodes


set A [$ns node]
setR[$nsnode]
setB[$nsnode]

#Create a duplexlink between the nodes

$ns duplex-link$A$R10Mb10msDropTail
$ns duplex-link$R$B800Kb50msDropTail

#The queue size at$Ristobe7,including the packet being sent


$ns queue-limit$R$B7

#some hints for nam


#color packets off low 0 red
$ns color 0 Red
$ns duplex-link-op$A$R orient right
$ns duplex-link-op$R$B orient right
$ns duplex-link-op$R$B queue Pos0.5

#Create a TCP sending agent and attach it to A


set tcp0 [new Agent/TCP/Reno]
#We make our one-and-only flow beflow0
$tcp0 set class_0
$tcp0 set window_100
$tcp0 set packetSize_960
$ns attach-agent $A $tcp0

#Let'strace some variables


$tcp0 attach $trace file
$tcp0 tracevar cwnd_
$tcp0 tracevar ssthresh_
$tcp0tracevar ack_
$tcp0tracevar maxseq_

#Create a TCP receive agent (a traffic sink) and attach it to B


set end0 [new Agent/TCPSink]
$ns attach-agent$B $end0

#Connect the traffic source with the traffic sink


$ns connect$tcp0 $end0

#Schedule the connection data flow;


start sending data atT=0,stopatT=10.0

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)


lOMoARcPSD|22991856

set my ftp[new Application/FTP]


$my ft pattach-agent$tcp0
$ns at0.0"$my ftp start"
$ns at 10.0 "finish"

#Run the simulation

$ns run

Dept.of CSE CS508PC:COMPUTERNETWORKSLAB

Downloaded by Alluri rudresh varma (rudreshvarma@gmail.com)

You might also like