Computer Network Lab Experiments-1
Computer Network Lab Experiments-1
Computer Network Lab Experiments-1
Passive Hubs
A passive hub is just a connector. It connects the wires coming from different
branches. In a star-topology Ethernet LAN, a passive hub is just a point where the
signals coming from different stations collide; the hub is the collision point. This
type of a hub is part of the media; its location in the Internet model is below the
physical layer.
Repeaters
A repeater is a device that operates only in the physical layer. Signals that carry
information within a network can travel a fixed distance before attenuation
endangers the integrity of the data. A repeater receives a signal and, before it
becomes too weak or corrupted, regenerates the original bit pattern. The repeater
then sends the refreshed signal.
A repeater does not actually connect two LANs; it connects two segments of the same
LAN. The segments connected are still part of one single LAN. A repeater is not a device
that can connect two LANs of different protocols.
Active Hubs
An active hub is actually a multipart repeater. It is normally used to create connections
between stations in a physical star topology. We have seen examples of hubs in some
Ethernet implementations (lOBase-T, for example). However, hubs can also be used to
create multiple levels of hierarchy, as shown in Figure. The hierarchical use of hubs
removes the length limitation of 10Base-T (100 m).
Bridges
A bridge operates in both the physical and the data link layer. As a physical layer device,
it regenerates the signal it receives. As a data link layer device, the bridge can check the
physical (MAC) addresses (source and destination) contained in the frame.
Transparent Bridges
A transparent bridge is a bridge in which the stations are completely unaware of the
bridge's existence. If a bridge is added or deleted from the system, reconfiguration of the
stations is unnecessary. According to the IEEE 802.1 d specification, a system equipped
with transparent bridges must meet three criteria:
Two-Layer Switches
When we use the term switch, we must be careful because a switch can mean two
different things. We must clarify the term by adding the level at which the device operates.
We can have a two-layer switch or a three-layer switch. A three-layer switch is used at
the network layer; it is a kind of router. The two-layer switch performs at the physical
and data link layers.
A two-layer switch is a bridge, a bridge with many ports and a design that allows better
(faster) performance. A bridge with a few ports can connect a few LANs together. A bridge
with many ports may be able to allocate a unique port to each station, with each station
on its own independent entity. This means no competing traffic (no collision, as we saw
in Ethernet).
A two-layer switch, as a bridge does, makes a filtering decision based on the MAC
address of the frame it received. However, a two-layer switch can be more sophisticated.
It can have a buffer to hold the frames for processing. It can have a switching factor that
forwards the frames faster. Some new two-layer switches, called cut-through switches,
have been designed to forward the frame as soon as they check the MAC addresses in
the header of the frame.
Routers
A router is a three-layer device that routes packets based on their logical addresses (host-
to-host addressing). A router normally connects LANs and WANs in the Internet and has
a routing table that is used for making decisions about the route. The routing tables are
normally dynamic and are updated using routing protocols.
Three-Layer Switches
A three-layer switch is a router, but a faster and more sophisticated. The switching fabric
in a three-layer switch allows faster table lookup and forwarding. In this book, we use the
terms router and three-layer switch interchangeably.
Gateway
A gateway is normally a computer that operates in all five layers of the Internet or seven
layers of OSI model. A gateway takes an application message, reads it, and interprets it.
This means that it can be used as a connecting device between two internetworks that
use different models. For example, a network designed to use the OSI model can be
connected to another network using the Internet model. The gateway connecting the two
systems can take a frame as it arrives from the first system, move it up to the OSI
application layer, and remove the message.
Experiment No. 2
Experiment
1. Verify the connectivity of your workstation to the internet.
2. Open the Command Prompt of the operating system using either of the following
methods:
Click on Start > All Programs > Accessories > Command Prompt
or Click on Start > Run, enter cmd (short for command) and click on
ok. A Command Prompt screen should open.
3. Gather TCP/IP configuration information: Type ipconfig (short for IP configuration)
and press Enter. The screen will show the IP address, subnet mask, and default
gateway for your computer’s connection.
Notice the values in the Command Prompt. The IP address and the default gateway
should be in the same network or subnet, otherwise this host would not be able to
communicate outside the network. In Fig. 3, the subnet mask tells us that the first three
octets of the IP address and the default gateway must be the same in order to be in the
same network.
4. Check more detailed TCP/IP configuration information: Type ipconfig /all and
press Enter. What are the DNS and DHCP server addresses? What are their
functions? What is the MAC of the network interface card?
5. Ping the IP address of another computer. Note that for the ping and tracert
commands to work the PC firewalls have to be disabled. Why do you think this is
so? Ask the IP address of the workstation that is being used by another group of
students. Then type ping, space, and the IP address that you received, then
press Enter. Notice the outputs. Fig. 4 shows a successful result of a ping to a given
IP address.
6. Ping the IP address of the gateway router from the details that have been observed
in the output of step 4 above. If the ping is successful, it means that there is a
physical connectivity to the router on the local network and probably the rest of the
world.
7. Ping the Loopback IP address of your computer. Type the following command: ping
127.0.0.1. The IP address 127.0.0.1 is reserved for loopback testing. If the ping is
successful, then TCP/IP is properly installed and functioning on this computer.
8. You can also ping using names like websites. Ping the IP address of the cisco
website. Type ping, space and www.cisco.com, then press Enter. Notice the
outputs. A DNS server will resolve the name to an IP address and the ping will be
successful only in the existence of the DNS server.
9. Ping www.ee.uct.ac.za and observe the results. Is there a difference in time
between the results shown by pinging www.cisco.com and www.ee.uct.ac.za. If so
why and if not why?
10. Trace the route to the Cisco website. Type tracert www.cisco.com and press enter.
In a successful output, you will see listings of all routers the tracert requests had to
pass through to get to the destination.
11. Trace the route to the website of the Department of Electrical Engineering. Type tracert
www.ee.uct.ac.za and press enter. The output should take less time than that of step
9.
Algorithm:
Step 1: Initially give the user 2 choices, whether to character stuff or to directly exit, if wrong
choice is entered then prompt an invalid choice message.
Step 2: Intake from the user the number of characters which are to be character
stuffed. Step 3: Then the characters which are to be stuffed are to be taken inside
the for loop.
Step 4: Original data is displayed and the characters to be stuffed at the start and end of the
frame are uploaded in the program.
Step 5: If DLE character is present then stuff DLE character before it.
Step 6: The characters DLESTX are inserted at the start and end of
the data. Step 7: The data along with the stuffed characters are
displayed Step 8: The original data is recovered and displayed on the
receiving side Step 9: Stop
Program :
#include<stdio.h
>
#include<conio.h
>
#include<stdlib.h>
void charc(void);
void main()
{
int
choice;
while(1
)
{
printf("\n\n\n1.character stuffing");
printf("\n\n2.exit");
printf("\n\n\nenterchoice");
scanf("%d",&choice);
printf("%d",choice);
if(choice>2)
printf("\n\n invalid option ... please renter");
switch(choice)
{
case
1:charc();
break;
case 2:_exit(0);
}
}
}
void charc(void)
{
clrscr();
char
c[50],d[50],t[50];
int i,m,j;
printf("enter the number of
characters\n"); scanf("%d",&m);printf("\n
enter the characters\n");
for(i=0;i<m+1;i++)
{
scanf("%c",&c[i]);
}
printf("\n original data\n");
for(i=0;i<m+1;i++)
printf("%c",c[i]);d[0]='d';
d[1]='l';d[2]='e';
d[3]='s';d[4]='t'
; d[5]='x';
for(i=0,j=6;i<m+1;i++,j++)
{
if((c[i]=='d'&&c[i+1]=='l'&& c[i+2]=='e'))
{
d[j]='d'; j++;
d[j]='l'; j++;
d[j]='e';
j++;
m=m+3;
}
d[j]=c[i];
}
m=m+6;
m++; d[m]='d';
m++;
d[m]='l'; m++;
d[m]='e'; m++;
d[m]='s'; m++;
d[m]='t'; m++;
d[m]='x';
m++;
printf("\n\n transmitted data: \n"); for(i=0;i<m;i++)
{
printf("%c",d[i]);
}
for(i=6,j=0;i<m-6;i++,j++)
{
if(d[i]=='d'&&d[i+1]=='l'&&d[i+2]=='e'&&d[i+3]=='d'&&d[i+4]=='l'&&d[i+5]=='e')
i=i+3;
t[j]=d[i];
}
printf("\n\nreceived data:"); for(i=0;i<j;i++)
{
printf("%c",t[i]);
}
}
PROGRAM:
#include<stdio.h> #include<string.h>
main()
{
int i,j,k,l,count=0,n; char s[100],cs[50];
clrscr();
printf("\n ENTER THE BIT STRING:");
gets(s);
n=strlen(s);
printf("\nTHE STRING IS\n");
for(i=0;i<n;)
{
if(s[i]==s[i+1])
{
count=2; i++;
while(s[i]==s[i+1]
)
{ i++;
count++;
}
if(count>=5)
{
printf("$");
if(count<10)
printf("0");
printf("%d%c",count,s[i])
; i++;
}
else
{
for(j=0;j<count;j++)
printf("%c",s[i]);
i++;
}
}
else
{
printf("%c",s[i]);
i++;
}
}
getch(); }
INPUT/OUTPUT:
123AAAAAAAAAATYKKKPPP
P P THE STRING IS
123$10ATYKKK$05P
#include<stdio.h>
#include<string.h>
main()
{
int i,j,k,l,n,count;
char s[100],cs[50]; clrscr();
printf("\n ENTER THE STUFFED STRING :");
gets(s); n=strlen(s);
printf("\nTHE STRING IS\n");
for(i=0;i<n;)
{
if(s[i]=='$')
{ i++;
count=(s[i]-'0')*10+(s[i+1]-'0');
if(count<5)
{ clrscr();
printf("INVALIDE MESSAGE");
exit(1);
}
while(count>0)
{
printf("%c",s[i+2])
; count--;
}
i=i+3;
}
else
{
printf("%c",s[i]); i++;
}
}
getch(); }
INPUT/OUTPUT:
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int b[100],b1[100],l,k,n=0,i,j,z,i1,s[20],f[8]={0,1,1,1,1,1,1,0},j1;
static int a[100];
char ch='y',bs[50];
clrscr();do
{
i1=z=n=0; clrscr();
printf("\n Enter the bit string(space for each
byte)"); gets(bs);
for(i=0;bs[i]!='\0';i++)
if(bs[i]!=' ')
b[n++]=bs[i]-'0';
for(i=0;i<n;i++)
{
if(b[i]==1)
{
i1++;
if(i1==5){s[z++]=i+1;i1=0;
}
}
else i1=0;
} j1=j=0;
for(i=0;i<z;i++)
{
while(j<s[i])
b1[j1++]=b[j
++];
b1[j1++]=0;
}
while(j1<n+z)
b1[j1++]=b[j++];
l=n/8;
for(i=0;l>0;i++
)
{
a[i]=l%2; l=l/2;
}
printf("\nAfter stuffing
:"); for(j=7;j>=0;j--)
printf("%d",a[j]);
printf(" ");
for(k=0;k<8;k++)
printf("%d",f[k]);
printf(" ");
for(k=0;k<j1;k++
)
printf("%d",b1[k])
; printf(" ");
for(k=0;k<8;k++)
printf("%d",f[k]);
printf("\n\n Do u want to continue?");
ch=getch();
}
while(ch=='y' || ch=='Y');
getch();
}
INPUT/OUTPUT:
include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int i,n,n1,k,j,ni,len;
char f[8]={'0','1','1','1','1','1','1','0'},st[100];
static int
ds[100]; clrscr();
printf("\n\nEnter the stuffed
data"); gets(st);
n=strlen(st);
ni=k=0;
for(i=8;i<16;i++)
if(st[i]!=f[k++])
{
printf("\nError in flag");
exit(1);
}
k=0;
for(i=n-8;i<n;i++)
if(f[k++]!=st[i])
{
printf("\nError in flag");
exit(1);
}
for(i=0;i<n;i++
) st[i]=st[i]-'0';
len=0;
j=7;
for(i=0;i<8;i++)
len+=pow(2,i)*st[j--
]; k=ni=j=0;
for(i=16;i<n-8;i++)
{
if(st[i]==1)
{
ni++;
if(ni==5)
{
ds[j++]=1;
i++;
k++;
ni=0
;}
else
ds[j++]=1;
}
else
ds[j++]=0;
}
n1=n-24-k;
if(len*8!=n1)
{
printf("\n Error in data
length"); exit(1);
}
printf("\n After destuffing
")
; for(i=0;i<n1;i++)
printf("%d",ds[i]);
getch();
}
INPUT/OUTPUT:
Algorithm
PROGRAM:
#include<stdio.h>
#include<math.h
>main()
{
int i,j,k,m,n,cl;
char a[10],b[100],c[100];
clrscr();
printf("\n ENTER POLYNANOMIAL:");
scanf("%s",a);
printf("\n ENTER THE FRAME:");
scanf("%s",b);
m=strlen(a);
n=strlen(b);
for(i=0;i<m;i++) /* To eliminat first zeros
in polynomial */
{
if(a[i]=='1')
{
m=m-i; break;
}
}
for(k=0;k<m;k++) /* To Adjust the polynomial
*/ a[k]=a[k+i];
cl=m+n-1;
for(i=0;i<n;i++) /* To copy the original frame to c[]*/
c[i]=b[i];
for(i=n;i<cl;i++) /* To add n-1 zeros at the end of frame */
c[i]='0';
c[i]='\0'; /*To make it as a string */
for(i=0;i<n;i++) /* To set polynomial remainder at end of c[]*/
if(c[i]=='1')
{
for(j=i,k=0;k<m;k++,j++)
if(a[k]==c[j])
c[j]='0';
else c[j]='1';
}
for(i=0;i<n;i++) /* To copy original data in c[] */ c[i]=b[i];
printf("\n THE MESSAGE IS: %s",c);
getch();
}
INPUT/OUTPUT:
#include<stdio.h>
#include<math.h
>main()
{
int i,j,k,m,n,cl;
char a[10],c[100]; clrscr();
printf("\n ENTER POLYNANOMIAL:");
scanf("%s",a);
printf("\n ENTER THE CRC FRAME:");
scanf("%s",c); m=strlen(a);
cl=strlen(c);
for(i=0;i<m;i++) /* To eliminat first zeros in polynomial
*/
{
if(a[i]=='1')
{ m=m-i; break; }
}
for(k=0;k<m;k++) /* To Adjust the polynomial */
a[k]=a[k+i];
n=cl-m+1;
for(i=0;i<n;i++) /* To check polynomial remainder is
zero or not */ if(c[i]=='1')
{
for(j=i,k=0;k<m;k++,j++) if(a[k]==c[j])
c[j]='0';
else c[j]='1';
}
for(i=0;i<cl;i++) /* To copy original data in c[]
*/ if(c[i]=='1')
{
printf("\n THERE IS SOME ERROR IN MESSAGE :");
break;
}
if(i==cl)
printf("\n MESSAGE IS CORRECT");
getch(); }
INPUT/OUTPUT :
ERROR IN MESSAGE:
10011101011 MESSAGE IS
CORRECT
Experiment No. 5
Objective: Implement Dijkstra’s algorithm to compute the shortest path through a graph.
Algorithm:
1. Assign to every node a tentative distance value: set it to zero for our initial node and to
infinity for all other nodes.
2. Mark all nodes unvisited. Set the initial node as current. Create a set of the unvisited
nodes called the unvisited set consisting of all the nodes.
3. For the current node, consider all of its unvisited neighbors and calculate their tentative
distances. For example, if the current node A is marked with a distance of 6, and the edge
connecting it with a neighbor B has length 2, then the distance to B (through A) will be 6 +
2 = 8. If this distance is less than the previously recorded tentative distance of B, then
overwrite that distance. Even though a neighbor has been examined, it is not marked as
"visited" at this time, and it remains in the unvisited set.
4. When we are done considering all of the neighbors of the current node, mark the
current node as visited and remove it from the unvisited set. A visited node will never be
checked again.
5. If the destination node has been marked visited (when planning a route between two
specific nodes) or if the smallest tentative distance among the nodes in the unvisited set
is infinity (when planning a complete traversal; occurs when there is no connection
between the initial node and remaining unvisited nodes), then stop. The algorithm has
finished.
6. Select the unvisited node that is marked with the smallest tentative distance, and set it
as the new "current node" then go back to step 3.
PROGRAM:
#include<stdio.h>
#include<string.h>
#include<math.h>
main()
{
int
u,v,num,i,j,l,k,s[10],min,cost[10][10],dist[10],path[10],n;
clrscr();
printf("\n ENTER VERTECES:");
scanf("%d",&n);
printf("\n ENTER ADJECENCY MATRIX:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
scanf("%d",&cost[i][j]);
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i==j) cost[i][j]=0;
else if(cost[i][j]==-1)
cost[i][j]=30000;
printf("\nENTER SOURCE VERTEX:");
scanf("%d",&v); clrscr();
for(i=1;i<=n;i++)
{
s[i]=0;
path[i]=v; dist[i]=cost[v][i];
}
dist[v]=0;
for(num=2;num<=n;num++)
{
min=30000; u=0;
for(i=1;i<=n;i++)
{
if(s[i]!=1) if(min>dist[i])
{
u=i; min=dist[i];
}
}
s[u]=1;
for(i=1;i<=n;i++)
{ if(s[i]!=1)
if(dist[i]>(min+cost[u][i]))
{
dist[i]=min+cost[u][i];
path[i]=u;
}
}
}
printf("\n");
printf("\nPATH MATRIX:\n");
printf("\nDISTANCE NODE
PATH\n");
for(i=1;i<=n;i++)
{ printf("\n
%d",dist[i]); printf("
%d ",i);
j=i;
do
{
printf(" --> %d
",path[j]); u=path[j];
j=u;
}while(u!=v);
}
getch();}
INPUT/OUTPUT:
ENTER VERTECES:8
0 2 -1 -1 -1 -1 6 -1
2 0 7 -1 2 -1 -1 -1
-1 7 0 3 -1 3 -1 -1
-1 -1 3 0 -1 -1 -1 2
-1 2 -1 -1 0 2 1 -1
-1 -1 3 -1 2 0 -1 2
6 -1 -1 -1 1 -1 0 4
-1 -1 -1 2 -1 2 4 0
PATH MATRIX:
0 1 --> 1
2 2 --> 1
9 3 --> 2 --> 1
10 4 --> 8 --> 6 --> 5 --> 2 --> 1
4 5 --> 2 --> 1
6 6 --> 5 --> 2 --> 1
5 7 --> 5 --> 2 --> 1
8 8 --> 6 --> 5 --> 2 --> 1
Exercise:
1. Write a program for implementing link state
routing using Dijkstra’s algorithm
2. Write a program for Flooding algorithm
Experiment No. 6
Objective: Take an example subnet graph with weights indicating delay between nodes
#include<stdio.h>
#include<conio.h>
struct full
{
char line[10],dest[10];
int hops;
}f[20];
main()
{
int
nv,min,minver,i
; char
sv[2],temp;
clrscr();
printf("\nEnter number of
vertices:"); scanf("%d",&nv);
printf("\n Enter source vertex:
"); scanf("%s",sv);
printf("\n Enter full table for source vertex %s :\n",sv);
for(i=0;i<nv;i++)
scanf("%s %s %d",f[i].dest,f[i].line,&f[i].hops);
printf("\n HIERARCHIAL TABLE\n\n");
for(i=0;i<nv;)
{
if(sv[0]==f[i].dest[0])
{
printf("\n %s %s %d",f[i].dest,f[i].line,f[i].hops);
i++;
}
else
{
min=1000; minver=0;
temp=f[i].dest[0];
while(temp==f[i].dest[0])
{
if(min>f[i].hops)
{
min=f[i].hops; minver=i;
} i++;
}
printf("\n %c %s %d ",temp,f[minver].line,f[minver].hops);
}
}
getch();
}
INPUT/OUTPUT:
Exercise:
1. Implement path vector routing protocol.
2. Routing Information Protocol
Experiment No. 7
Objective: Now obtain Routing table for each node using distance vector routing
algorithm
Algorithm:
1) This step initializes distances from source to all vertices as infinite and distance to
source itself as 0. Create an array dist[] of size |V| with all values as infinite except dist[src]
where srcis source vertex.
2) This step calculates shortest distances. Do following |V|-1 times where |V| is the number
of vertices in given graph.
…..a) Do following for each edge v-u
………………If dist[v] > dist[u] + weight of edge uv, then update dist[v]
………………….dist[v] = dist[u] + weight of edge uv
3) This step reports if there is a negative weight cycle in graph. Do following for each edge
u-v
……If dist[v] > dist[u] + weight of edge uv, then “Graph contains negative weight
cycle” The idea of step 3 is, step 2 guarantees shortest distances if graph doesn’t contain
negative weight cycle. If we iterate through all edges one more time and get a shorter path
for any vertex, then there is a negative weight cycle
Program:
#include<stdio.h>
#include<math.h> #include<conio.h> main()
{
int
i,j,k,nv,sn,noadj,edel[20],tdel[20][20],min;
char sv,adver[20],ch;
clrscr();
printf("\n ENTER THE NO.OF VERTECES:");
scanf("%d",&nv);
printf("\n ENTER THE SOURCE
VERTEX NUM,BER AND NAME:");
scanf("%d",&sn);
flushall(); sv=getchar();
printf("\n NETER NO.OF ADJ VERTECES
TO VERTEX %c",sv);
scanf("%d",&noadj);
for(i=0;i<noadj;i++)
{
printf("\n ENTER TIME DELAY and NODE NAME:");
scanf("%d %c",&edel[i],&adver[i]);
}
for(i=0;i<noadj;i++)
{
printf("\n ENTER THE TIME DELAY FROM %c to ALL OTHER
NODES: ",adver[i]);
for(j=0;j<nv;j++)
scanf("%d",&tdel[i][j]);
}
INPUT/OUTPUT:
DELAY VIA--VERTEX
8 a
20 a
28 i
20 h
17 i
30 i
18 h
12 h
10 i
0 -
6 k
15 k
Exercise:
1. Routing table for each node using hierarchical routing algorithm
Objective: Take a 64 bit plain text and encrypt the same using DES algorithm.
Algorithm:
1.2.1 Perform the following permutation on the 64-bit key. (The parity bits are
discarded, reducing the key to 56 bits. Bit 1 of the permuted block is bit 57 of the original
key, bit 2 isbit 49, and so on with bit56 being bit 4 of the original key.)
1.2.2 Split the permuted key into two halves. The first 28 bits are called C[0] and
thelast 28 bits are called D[0].
1.2.3 Calculate the 16 subkeys. Start with i = 1.
1.2.3.1 Perform one or two circular left shifts on both C[i-1] and D[i-1] to get C[i] and
D[i],respectively.
1.2.3.3 Loop back to 1.2.3.1 until K[16] has been
calculated. 2 Process a 64-bit data block.
2.1 Get a 64-bit data block. If the block is shorter than 64 bits, it should be padded
as appropriate for the application.
2.2 Perform the following permutation on the data
2.4.1 Expand the 32-bit R[i-1] into 48 bits according to the bit-selection
2.4.3 Break E(R[i-1]) xor K[i] into eight 6-bit blocks. Bits 1-6 are B[1], bits 7-12 are
B[2], and so on with bits 43-48 being B[8].
2.4.4 Substitute the values found in the S-boxes for all B[j]. Start with j = 1. All
valuesin the S-boxes should be considered 4 bits wide.
2.4.4.1 Take the 1st and 6th bits of B[j] together as a 2-bit value (call it m) indicating
the row in S[j] to look in for the substitution.
2.4.4.2 Take the 2nd through 5th bits of B[j] together as a 4-bit value (call it n)
indicating the column in S[j] to find the substitution.
2.4.4.3 Replace B[j] with
S[j][m][n]. Substitution Box 1
(S[1])
2.4.4.4 Loop back to 2.4.4.1 until all 8 blocks have been replaced.
below.Permutation P
2.4.6 Exclusive-or the resulting value with L[i-1]. Thus, all together, your R[i] = L[i-1]
xor P(S[1](B[1])...S[8](B[8])), where B[j] is a 6-bit block of E(R[i-1]) xor K[i]. (The function
for R[i] is written as, R[i] = L[i-1] xor f(R[i-1], K[i]).)
2.4.7 L[i] = R[i-1].
2.4.8 Loop back to 2.4.1 until K[16] has been applied.
2.5 Perform the following permutation on the
Program:
#include<stdio.h
>
#include<conio.h>
void main()
{
int k[15],k1[15],k2[15],i,j,p[15],p1[15],p2[15];
int p10[10]={3,5,2,7,4,10,1,9,8,6};
int p8[10]={6,3,7,4,8,5,10,9};
int t1,t2,t3,t4,t[4],b[10],s,h,a;
int ip[8]={2,6,3,1,4,8,5,7};
int ep[8]={4,1,2,3,2,3,4,1};
int ip1[8]={4,1,3,5,7,2,8,6};
int p4[4]={2,3,4,1};
int s0[4][4]={{1,0,3,2},{3,2,1,0},{0,2,1,3},{3,1,3,2}};
int s1[4][4]={{0,1,2,3},{2,0,1,3},{3,0,1,0},{2,1,0,3}};
clrscr();
printf("\n\tSimplified-DES\n");
printf("\n");
printf("\nEnter the plain text of 8 bits length::\n");
for(i=0;i<8;i++)
scanf("%d",&p2[i]);
printf("\n\nEnter the key of 10 bits length::\n");
for(i=0;i<10;i++)
scanf("%d",&k[i]);
printf("\n\nKey
Generation::\n");
for(i=0;i<10;i++)
{
j=p10[i];
p[i]=k[j-
1];
}
t1=p[0];
t2=p[5];
for(i=0;i<4;i++)
p[i]=p[i+1];
p[i]=t1;
for(i=5;i<9;i++)
p[i]=p[i+1];
p[i]=t2;
for(i=0;i<8;i++)
{
j=p8[i];
k1[i]=p[j-
1];
}
t1=p[0];
t2=p[1];
t3=p[5];
t4=p[6];
for(i=0;i<3;i++)
{
p[i]=p[i+2];
}
p[i]=t1;
i++;
p[i]=t2;
for(i=5;i<8;i++)
p[i]=p[i+2];
p[i]=t3;
i++;
p[i]=t4;
for(i=0;i<8;i++)
{
j=p8[i];
k2[i]=p[j-
1];
}
printf("\nkey
k1::");
for(i=0;i<8;i++)
printf("%d",k1[i]);
printf("\nkey
k2::");
for(i=0;i<8;i++)
printf("%d",k2[i]);
for(i=0;i<8;i++)
p[i]=p2[i];
for(a=0;a<2;a++)
{
if(a==0)
{
for(i=0;i<8;i++)
{
j=ip[i];
p1[i]=p[j-
1];
}
}
for(i=0;i<4;i++)
{
if(a==0)
k[i]=p1[i+4];
if(a==1)
{
k[i]=p[i+4];
for(i=0;i<8;i++)
b[i]=p[i];
}
}
for(i=0;i<8;i++)
{
j=ep[i];
p[i]=k[j-
1];
}
for(i=0;i<8;i++)
{
if(a==0)
{
if(p[i]==k1[i])
k[i]=0;
else
k[i]=1;
}
if(a==1)
{
if(p[i]==k2[i])
k[i]=0;
else
k[i]=1;
}
}
j=0;
for(i=0;i<8;i=i+4)
{
if(k[i]==0&&k[i+3]==0)
{
t[j]=0
;j++;
}
if(k[i]==0&&k[i+3]==1)
{
t[j]=1
;j++;
}
if(k[i]==1&&k[i+3]==0)
{
t[j]=2
;j++;
}
if(k[i]==1&&k[i+3]==1)
{
t[j]=3
;j++;
}
if(k[i+1]==0&&k[i+2]==0)
{
t[j]=0
;j++;
}
if(k[i+1]==0&&k[i+2]==1)
{
t[j]=1
;j++;
}
if(k[i+1]==1&&k[i+2]==0)
{
t[j]=2
;j++;
}
if(k[i+1]==1&&k[i+2]==1)
{
t[j]=3
;j++;
}
}
s=s0[t[0]][t[1]]
;
h=s1[t[2]][t[3]];
if(s==0)
{
k[0]=0;
k[1]=0;
}
if(s==1)
{
k[0]=0;
k[1]=1;
}
if(s==2)
{
k[0]=1;
k[1]=0;
}
if(s==3)
{
k[0]=1;
k[1]=1;
}
if(h==0)
{
k[2]=0;
k[3]=0;
}
if(h==1)
{
k[2]=0;
k[3]=1;
}
if(h==2)
{
k[2]=1;
k[3]=0;
}
if(h==3)
{
k[2]=1;
k[3]=1;
}
for(i=0;i<4;i++)
{
j=p4[i];
p[i]=k[j-
1];
}
for(i=0;i<4;i++)
{
if(a==0)
{
if(p1[i]==p[i])
k[i]=0;
else
k[i]=1;
}
if(a==1)
{
if(b[i]==p[i])
k[i]=0;
else
k[i]=1;
}}
if(a==0)
{
for(i=0;i<4;i++)
p[i]=p1[i+4];
for(i=0;i<4;i++)
p[i+4]=k[i];
}
if(a==1)
{
for(i=4;i<8;i++)
k[i]=b[i];
for(i=0;i<8;i++)
{
j=ip1[i];
p[i]=k[j-
1];
}
}
}
printf("\n\nThe cipher text::");
for(i=0;i<8;i++)
printf("%d",p[i]);
getch(); }
OUTPUT
******************
Simplified-
DES
0
Enter the key of 10 bits length::
1
0
1
Key Generation::
key
k1::
111
001
00
key
k2::
010
100
11
Objective: Write a program for error detecting code using CRC-CCITT (16- bits).
import java.util.*;
class crc {
public static void main(String args[]) {
Scanner scan = new
Scanner(System.in); int n;
data[i] = scan.nextInt();
}
Objective: Write a program to find the shortest path between vertices using bellman-
ford Algorithm
import java.util.Scanner;
public class BellmanFord
{
private int D[];
private int num_ver;
public static final int MAX_VALUE = 999;
public BellmanFord(int num_ver)
{
this.num_ver = num_ver;
D = new int[num_ver + 1];
}
public void BellmanFordEvaluation(int source, int A[][])
{
for (int node = 1; node <= num_ver; node++)
{
D[node] = MAX_VALUE;
}
D[source] = 0;
for (int node = 1; node <= num_ver - 1; node++)
{
for (int sn = 1; sn <= num_ver; sn++)
{
for (int dn = 1; dn <= num_ver; dn++)
{
if (A[sn][dn] != MAX_VALUE)
{
if (D[dn] > D[sn]+ A[sn][dn])
D[dn] = D[sn] + A[sn][dn];
}
}
}
}
for (int sn = 1; sn <= num_ver; sn++)
{
for (int dn = 1; dn <= num_ver; dn++)
{
if (A[sn][dn] != MAX_VALUE)
{
if (D[dn] > D[sn]+ A[sn][dn])
System.out.println("The Graph contains negative egde cycle");
}
}
}
for (int vertex = 1; vertex <= num_ver; vertex++)
{
System.out.println("distance of source " + source + " to "+ vertex + "is" + D[vertex]);
}
}
public static void main(String[ ] args)
{
int num_ver = 0;
int source;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of vertices");
num_ver = scanner.nextInt();
int A[][] = new int[num_ver + 1][num_ver + 1];
System.out.println("Enter the adjacency
matrix"); for (int sn = 1; sn <= num_ver; sn++)
{
for (int dn = 1; dn <= num_ver; dn++)
{
A[sn][dn] = scanner.nextInt();
if (sn == dn)
{
A[sn][dn] = 0;
continue;
}
if (A[sn][dn] == 0)
{
A[sn][dn] = MAX_VALUE;
}
}
}
System.out.println("Enter the source vertex");
source = scanner.nextInt();
BellmanFord b = new BellmanFord (num_ver);
b.BellmanFordEvaluation(source, A);
scanner.close();
}
}
Experiment No. 11
import java.net.*;
import java.io.*;
public class server1
{
public static void main(String args[]) throws Exception
{ // establishing the connection with the
server ServerSocket sersock = new
ServerSocket(4000); System.out.println("Server ready
for connection");
Socket sock = sersock.accept(); // binding with port:
4000 System.out.println("Connection is successful");
String str;
while((str = contentRead.readLine()) != null) // reading line-by-line from file
{
pwrite.println(str); // sending each line to client
}
String str;
while((str = socketRead.readLine()) != null) // reading line-by-line
{
System.out.println(str);
}
pwrite.close(); socketRead.close(); keyRead.close();
}
}
Experiment No. 12
import java.net.*;
import java.io.*;
class userver {
public static void main(String args[])throws Exception{
Socket s=new Socket("localhost",3333);
DataInputStream din=new DataInputStream(s.getInputStream());
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
String str="",str2="";
while(!str.equals("stop")){
str=br.readLine();
dout.writeUTF(str);
dout.flush();
str2=din.readUTF();
System.out.println("client says: "+str2);
}
dout.close();
s.close();
}}
String str="",str2="";
while(!str.equals("stop")){
str=din.readUTF();
System.out.println("server says:
"+str); str2=br.readLine();
dout.writeUTF(str2);
dout.flush();
}
din.close();
s.close();
ss.close();
}}
Experiment No.13
Objective: Write a program for simple RSA algorithm to encrypt and decrypt the
data.
import java.io.DataInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Random;
private BigInteger p;
private BigInteger q;
private BigInteger N;
private BigInteger e;
private BigInteger d;
private Random r;
public rsa()
r = new Random();
p = BigInteger.probablePrime(bitlength, r);
q = BigInteger.probablePrime(bitlength,
r); N = p.multiply(q);
phi = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
e = BigInteger.probablePrime(bitlength / 2, r);
e.add(BigInteger.ONE);
d = e.modInverse(phi);
this.e = e;
this.d = d;
this.N = N;
@SuppressWarnings("deprecation")
teststring = in.readLine();
// encrypt
// decrypt
bytesToString(decrypted)); System.out.println("Decrypted
test += Byte.toString(b);
return test;
}
// Encrypt message
// Decrypt message
}
Experiment No. 14
Objective: Write a program for congestion control using leaky bucket algorithm.
import java.io.*;
import java.util.*;
class Queue
{
int q[],f=0,r=0,size;
void insert(int n)
{
Scanner in = new Scanner(System.in);
q=new int[10];
for(int i=0;i<n;i++)
{
System.out.print("\nEnter " + i + " element: ");
int ele=in.nextInt();
if(r+1>10)
{
System.out.println("\nQueue is full \nLost Packet:
"+ele); break;
}
else
{ r++;
q[i]=ele;
}
}
}
void delete()
{
Scanner in = new Scanner(System.in);
Thread t=new Thread();
if(r==0)
System.out.print("\nQueue empty ");
{
{
try
{
} else
for(int i=f;i<r;i++)
t.sleep(1000);
catch(Exception e){} System.out.print("\nLeaked Packet: "+q[i]);
f++;
}
}
System.out.println();
}
}
}
Experiment No.: 15
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(PORT);
if ((status
= connect(client_fd, (struct
sockaddr*)&serv_addr,
sizeof(serv_addr)))
< 0) {
printf("\nConnection Failed \n");
return -1;
}
send(client_fd, hello, strlen(hello), 0);
printf("Hello message sent\n");
valread = read(client_fd, buffer,
1024 - 1); // subtract 1 for
the null
//
terminator at the end
printf("%s\n", buffer);
// closing the connected socket
close(client_fd);
return 0;
}
Viva Questions
1. What are functions of different layers?
2. Differentiate between TCP/IP Layers and OSI Layers
3. Why header is required?
4. What is the use of adding header and trailer to frames?
5. What is encapsulation?
6. Why fragmentation requires?
7. What is MTU?
8. Which layer imposes MTU?
9. Differentiate between flow control and congestion control.
10. Differentiate between Point-to-Point Connection and End-to-End connections.
11. What are protocols running in different layers?
12. What is Protocol Stack?
13. Differentiate between TCP and UDP.
14. Differentiate between Connectionless and connection oriented connection.
15. Why frame sorting is required?
16. What is meant by subnet?
17. What is meant by Gateway?
18. What is an IP address?
19. What is MAC address?
20. Why IP address is required when we have MAC address?
21. What is meant by port?
22. What are ephemerical port number and well known port numbers?
23. What is a socket?
24. What are the parameters of socket()?
25. Describe bind(), listen(), accept(),connect(), send() and recv().
26. What are system calls? Mention few of them.
27. What is IPC? Name three techniques.
28. Explain mkfifo(), open(), close() with parameters.
29. What is meant by file descriptor?
30. What is meant by traffic shaping?
31. How do you classify congestion control algorithms?
32. Differentiate between Leaky bucket and Token bucket.
33. How do you implement Leaky bucket?
34. How do you generate busty traffic?
35. What is the polynomial used in CRC-CCITT?
36. What are the other error detection algorithms?
37. What is difference between CRC and Hamming code?
38. Why Hamming code is called 7,4 code?
39. What is odd parity and even parity?
40. What is meant by syndrome?
41. What is generator matrix?
42. What is spanning tree?
43. Where Prim’s algorithm does finds its use in Networks?
44. Differentiate between Prim’s and Kruskal’s algorithm.
45. What are Routing algorithms?
46. How do you classify routing algorithms? Give examples for each.
47. What are drawbacks in distance vector algorithm?
48. How routers update distances to each of its neighbor?
49. How do you overcome count to infinity problem?
50. What is cryptography?
51. How do you classify cryptographic algorithms?
52. What is public key?
53. What is private key?
54. What are key, ciphertext and plaintext?
55. What is simulation?
56. What are advantages of simulation?
57. Differentiate between Simulation and Emulation.
58. What is meant by router?
59. What is meant by bridge?
60. What is meant by switch?
61. What is meant by hub?
62. Differentiate between route, bridge, switch and hub.
63. What is ping and telnet?
64. What is FTP?
65. What is BER?
66. What is meant by congestion window?
67. What is BSS?
68. What is incoming throughput and outgoing throughput?
69. What is collision?
70. How do you generate multiple traffics across different sender-receiver pairs?
71. How do you setup Ethernet LAN?
72. What is meant by mobile host?
73. Name few other Network simulators
74. Differentiate between logical and physical address.
75. Which address gets affected if a system moves from one place to another place?
76. What is ICMP? What are uses of ICMP? Name few.
77. Which layer implements security for data?