Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

CN LAB MANUAL

NOTE: To run simulation program login to NCTUNS: Open Three Terminals 1.First terminal for dispatcher 2.Second terminal for coordinator 3.Third terminal for nctunsclient And perform the following procedure as given below

Part -A
EXPERIMENT 1 1.Simulate a three-node point-to-point network with a duplex link between them. Set the queue size and vary the bandwidth and find the number of packets dropped. STEPS: Step1: Select the hub icon on the toolbar and drag it onto the working window. Step2: Select the host icon on the toolbar and drag it onto the working window. Repeat this for another host icon. Step 3: Select the link icon on the toolbar and drag it on the screen from host (node 1) to the hub and again from host(node 2) to the hub. Here the hub acts asnode 3 in the point-to-point network. This leads to the creation of the 3- node point-to-point network topology. Save this topology as filename.tpl Step 4: Double-click on host(node 1), a host dialog box will open up. Click on Node editor and you can see the different layers- interface, ARP,FIFO, MAC, TCP DUMP , Physical layers. Select MAC and then select full-duplex for switches and routers and half duplex for hubs, and in log Statistics, select Number of Drop Packets, Number of Collisions, Throughput of incoming packets and Throughput of outgoing packets.

At sender side: Double-click on host(node 1), a host dialog box will open up. Click on Node editor Select MAC then Select FIFO and set the queue size to 50 and press OK. And then select half duplex for hubs and in log Statistics, select Throughput of outgoing packets. Then click on Add. Another dialog box pops up. Click on the Command box and type the Command according to the following syntax: Enter the following command stg -u 1024 100 IpDestAddr and click OK. Where stg-->Sender traffic generator
1

CN LAB MANUAL
-u--> is for UDP 1024-->is a Buffer Size 100-->Port number IpDestAddr-->is an ipaddress of destination node(receiver node) Step 5: Double-click on host (node 2), and a host dialog box will open up. Click on Node editor Select MAC then Select FIFO and set the queue size to 50 and press OK. And then select half duplex for hubs and in log Statistics, select select Number of Drop Packets,Number of Collisions,Throughput of incoming packets and follow the same step as above with only change in command according to the following syntax rtg -u 1024 100 (or) rtg -u -w log1 and click OK. Where rtg-->Receiver traffic generator -u--> is for UDP 1024-->is a Buffer Size 100-->Port number -w-->write to the log file log1-->log buffer files. Step 6: Double click on the link between node 1 and the hub to set the bandwidth to some initial value say, 10 Mbps. Repeat the same for the other node. Step 7: Click on the E button (Edit Property) present on the toolbar in order to save the changes made to the topology. Now click on the R button (Run Simulation). By doing so a user canrun/pause/continue/stop/abort/disconnect/reconnect/submit a simulation. No simulation settings can be changed in this mode. Step 8: Now go to Menu->Simulation->Run. Executing this command will submit the current simulation job to one available simulation server managed by the dispatcher. When the simulation server is executing, the user will see the time knot at the bottom of the screen move. The time knot reflects the current virtual time (progress) of the simulation case. Step 9:To start the playback, the user can left-click the start icon( |>) of the time bar located at the bottom. The animation player will then start playing the recorded packet animation. Step 10: Change the bandwidth say, 9 Mbps, and run the simulation and compare the two results. Step 11: There are two methods to view the results. First method-->Graph method.. Go to menu->G-tools->plot graph
2

CN LAB MANUAL
Open graph by opening new four file-> Graph 0,Graph11,Graph 2,Graph3 and Open filename.results folder and we can see the selected files... Second method--> Go to new terminal->go to gedit there we can open the selected log files.., 1. Draw topology as shown below

2.Set the Node parameters at the sender and receiver At sender side: stg -u 1024 100 1.0.1.2 At receiver side: rtg -u 1024 100 set the Bandwidth to sender and receiver side as 10 Mpbs 3.Run the simulation 4.Playback the simulation.we get as shown in the below snapshot

OUTPUT:By setting the bandwidth as 10 Mbps on both the links and queue size as
50 we obtain the following results:
3

CN LAB MANUAL
Output throughput n1-p1= 1177 Input throughput n3-p1= 1177 Collision and drop =0

NOTE: Reduce the bandwidth size of the receiver side as 8Mbps and follow the same procedure.we get the simulation as shown in the snapshot

OUTPUT:By changing bandwidth to 8Mbps in the destination link, we obtain the

following results: Output throughput n1-p1 =1177 Input throughput n3-p1 = ~0 Collision and drop = 1100 2. Simulate a four-node point-to-point network and connect the link as follows: Apply a TCP agent between n0 to n3 and apply a UDP agent between n1 and n3. Apply relevant applications over TCP and UDP agents changing the parameters and determine the number of packets sent by two agents.
1.Draw the topology as shown below in the snapshot

2.set the node parameters At the sender TCP agent: stcp -p 3000 -l 1024 1.0.1.3 At the Sender UDP agent:
4

CN LAB MANUAL
stg -u 1024 100 1.0.1.3 At the receiver Node(Both TCP and UDP) rtcp -p 3000 -l 1024 rtg -u 1024 100 3.Run the simulation 4.Playback the simulation. we get as shown in the below snapshot

Results: By setting the bandwidth as 100 Mbps on the TCP link and queue size as 50 we obtain the following results: Average no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets sent = 1180

Note: The result varies based on the bandwidth. 3.Simulate the different types of Internet traffic such as FTP, TELNET over a
network and analyze the throughput.

1. Draw the topology as shown below in the snapshot

CN LAB MANUAL

2.set the node parameters At the sender FTP: stcp -p 21 -l 1024 1.0.1.3 At the Sender TELNET: stcp -p 23 -l 0124 1.0.1.3 At the receiver Node(Both FTP and Telnet) For FTP rtcp -p 21 -l 1024 For TELNET rtcp -p 23 -l 1024 NOTE: Port number for FTP is 21 Port number for TELNET is 23 3.Run the simulation 4.Playback the simulation. we get as shown in the below snapshot

RESULTS: For FTP:


6

CN LAB MANUAL
Output Throughput n1- p1= 680-1097 Input Throughput n2-p1 = 680-1097

4. Simulate the transmission of ping messages over a network topology consisting of 6 nodes and find the number of packets dropped due to congestion.

1. Draw the topology as shown below as in snapshot

2.Set the Node parameters At the sender side: stcp -p 3000 -l 1024 1.0.1.6 At the receiver side: rtcp -p 3000 -l 1024

3.Run the simulation 4.Playback the simulation. we get as shown in the below snapshot

CN LAB MANUAL

5.Simulate an Ethernet LAN using N nodes (6-10), change error rate and data rate and compare throughput. STEPS: Step1: Create a topology as shown in the below figure.

2.set the node parameters At the sender: stcp p 3000 l 1024 1.0.1.6 At the receiver: rtcp p 3000 l 1024
Change error rate and data rate in Physical layer

3.Run the simulation 4.Playback the simulation. we get as shown in the below snapshot

CN LAB MANUAL

Initial error rate: 0.0 Initial data rate: 10 Mbps Output Throughput: 654-1091 Input Throughput: 654-1091 Changed error rate: 0.000001 Changed data rate: 10 Mbps

Output Throughput: 654-1091 Input Throughput: 654-1091

6.Simulate an Ethernet LAN using N nodes and set multiple traffic nodes and determine collisions across different nodes. STEPS : 1:Draw a topology as shown in the below figure.

CN LAB MANUAL

2.set the node parameters At the sender: stcp p 3000 l 1024 1.0.1.6 At the receiver: rtcp p 3000 l 1024 3.Run the simulation 4.Playback the simulation. we get as shown in the below snapshot

Graphs Sheet:

Drops at node 1 : 324-750 Drops at node 6 : 274-930 7. Simulate an Ethernet LAN using N nodes and set multiple traffic nodes and plot congestion window for different source/destination. STEPS: 1. Draw a topology as shown in the below figure.

10

CN LAB MANUAL

2.set the node parameters At the sender: stcp p 3000 l 1024 1.0.1.6 At the receiver: rtcp p 3000 l 1024 3.Run the simulation 4.Playback the simulation.

Note: The only difference between the 6th experiment and the present experiment is that here we need to plot the congestion window i.e. collision log. 8. Simulate simple BSS and with transmitting nodes in wireless LAN by simulation and determine the performance with respect to transmission of packets. STEPS: 1: Click on access point. Goto wireless interface and tick on show transmission range and then click OK. Double click on Router -> Node Editor and then Left stack -> throughput of Incoming packets Right stack -> throughput of Outgoing packets Select mobile hosts and access points then click on. 11

CN LAB MANUAL
Tools -> WLAN mobile nodes-> WLAN Generate infrastructure. Subnet ID: Port number of router (2) Gateway ID: IP address of router Mobile Host 1 ttcp t u s p 3000 1.0.1.1 Mobile Host 1 ttcp t u s p 3001 1.0.1.1 Host(Receiver) ttcp r u s p 3000 ttcp r u s p 3001

12

CN LAB MANUAL

Part B
NOTE: To Edit proram: gedit filename.c To Compile: cc filename.c T0 Run: ./a.out 1.Write a program for error detecting code using CRC-CCITT (16-bits).

#include<stdio.h> #include<string.h> #include<math.h> #define Z "0000000000000000" #define SIZE 16 char tx[500],gx[SIZE+2]="10001000000100001",reg[SIZE+2]; int len_tx,len_tx_gx,i,j,num,bit; void main() { printf("\nEnter the Transmitting polynomial in binary T(x)=\n"); scanf("%s",tx); len_tx=strlen(tx); printf("\n T(x)=%s\n",tx); strcat(tx,Z); //Append Trailing Zeroes OR the CRC sum itself printf("\n T'(x)=%s",tx); printf("\n G(x)=%s\n",gx); len_tx_gx=strlen(tx); printf("\nLength of T(X)=%d\n",len_tx); printf("\nLength of T(x).G(x)=T'(x)=%d\n",len_tx_gx); for(i=0;i<=SIZE;i++) //Perform 1st XOR operation { if(gx[i]==tx[i]) reg[i]='0'; else reg[i]='1'; } for(bit=SIZE+1;bit<=len_tx_gx-1;bit++) { for(i=0;i<=SIZE;i++) reg[i]=reg[i+1]; //Perform 1 bit left shift reg[SIZE]=tx[bit];
13

CN LAB MANUAL
//Get next bit from T'(x) if(reg[0]=='1') //Check if msb is ==1 { for(i=0;i<=SIZE;i++) { if(gx[i]==reg[i]) reg[i]='0'; else reg[i]='1'; } } //Perform further XOR } for(i=0;i<=SIZE;i++) reg[i]=reg[i+1]; printf("\n CRC Checksum =%s\n",reg); } OUTPUT: Enter the Transmitting polynomial in binary T(x)=1010 T(x)=1010 T'(x)=10100000000000000000 G(x)=10001000000100001 Length of T(X)=4 Length of T(x).G(x)=T'(x)=20 CRC Checksum =1010000101001010

14

CN LAB MANUAL
2.Write a program for frame sorting technique used in the buffers. #include<stdio.h> #include <stdlib.h> #include <string.h> struct frame { int seq; char info[100]; }; void main() { int n,i,j; struct frame t,f[10]; printf("Enter the No. of Frames : "); scanf("%d",&n); printf("Enter Information:\n"); for(i=0;i<n;i++) { f[i].seq = random()%200; scanf("%s",f[i].info); } printf("\nFrames before sorting"); for(i=0;i<n;i++) printf("\n %d %s ",f[i].seq,f[i].info); for(i=0;i<n-1;i++) for(j=0;j<n-i-1;j++) if(f[j].seq > f[j+1].seq) { t= f[j]; f[j]=f[j+1]; f[j+1] = t; } printf("\nSorted Frames"); for(i=0;i<n;i++) printf("\n %d %s ",f[i].seq,f[i].info); } OUTPUT
15

CN LAB MANUAL
Enter the No. of Frames : 5 Enter Information: java sa ecs cnlab OOMD Frames before sorting 183 java 86 sa 177 ecs 115 cnlab 193 OOMD Sorted Frames 86 sa 115 cnlab 177 ecs 183 java 193 OOMD

16

CN LAB MANUAL
3.Write a program for distance vector algorithm to find suitable path for transmission. #include<stdio.h> struct node { unsigned dist[20]; unsigned from[20]; }rt[10]; int main() { int dmat[20][20]; int n,i,j,k; 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]); rt[i].dist[j]=dmat[i][j]; rt[i].from[j]=j; } 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]=dmat[i][k]+rt[k].dist[j]; rt[i].from[j]=k; } for(i=0;i<n;i++) { printf("\n\nState value for router %d is \n",i+1); for(j=0;j<n;j++) { printf("\t\nnode %d via %d Distance%d",j+1,rt[i].from[j]+1,rt[i].dist[j]); } } printf("\n\n");
17

CN LAB MANUAL
} OUTPUT Enter the number of nodes : 3 Enter the cost matrix : 0 5 1 5 0 2 1 2 0 State value for router 1 is node 1 via 1 Distance0 node 2 via 3 Distance3 node 3 via 3 Distance1 State value for router 2 is node 1 via 3 Distance3 node 2 via 2 Distance0 node 3 via 3 Distance2 State value for router 3 is node 1 via 1 Distance1 node 2 via 2 Distance2 node 3 via 3 Distance0

18

CN LAB MANUAL
4.Using TCP/IP sockets, write a client server program to make the client send the file name and to make the server send back the contents of the requested file if present.
Client.c #include<sys/socket.h> #include<sys/types.h> #include<netinet/in.h> #include<unistd.h> #include<stdlib.h> #include<stdio.h> int main(int argc,char*argv[]) { int create_socket,cont; int bufsize = 1024; char *buffer = malloc(bufsize); char fname[256]; struct sockaddr_in address; if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0) printf("The Socket was created\n"); address.sin_family = AF_INET; address.sin_port = htons(15000); inet_pton(AF_INET,argv[1],&address.sin_addr); if(connect(create_socket,(struct sockaddr *) &address, sizeof(address)) == 0) printf("The connection was accepted with the server%s...\n",argv[1]); printf("Enter The Filename to Request : "); scanf("%s",fname); send(create_socket, fname, sizeof(fname), 0); printf("Request Accepted... Receiving File...\n\n"); printf("The contents of file are...\n\n"); while((cont=recv(create_socket, buffer, bufsize, 0))>0) { write(1, buffer, cont); }printf("\nEOF\n"); return close(create_socket); }

Server.c #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> 19

CN LAB MANUAL
#include<sys/stat.h> #include<unistd.h> #include<stdlib.h> #include<stdio.h> #include<fcntl.h> int main() { int cont,create_socket,new_socket,addrlen,fd; int bufsize = 1024; char *buffer = malloc(bufsize); char fname[256]; struct sockaddr_in address; if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0) printf("The socket was created\n"); address.sin_family = AF_INET; address.sin_addr.s_addr = INADDR_ANY; address.sin_port = htons(15000); if(bind(create_socket,(struct sockaddr *)&address,sizeof(address)) == 0) printf("Binding Socket\n"); listen(create_socket,3); addrlen =sizeof(struct sockaddr_in); new_socket = accept(create_socket,(struct sockaddr *)&address,&addrlen); if (new_socket > 0) printf("The Client %d is Connected...\n", inet_ntoa(address.sin_addr)); recv(new_socket,fname, 255,0); printf("A request for filename %s Received..\n", fname); if ((fd=open(fname, O_RDONLY))<0) {perror("File Open Failed"); exit(0);} while((cont=read(fd, buffer, bufsize))>0) { send(new_socket,buffer,cont,0); }printf("Request Completed\n"); close(new_socket); return close(create_socket); } Note: Open Terminal-1 compile and run server program Open Terminal-2 compile and run client program 20

CN LAB MANUAL
./a.out 127.0.0.1

5.Implement the above program using as message queues or FIFOs as IPC channels.
Fifoclient.c #include<stdio.h> #include<unistd.h> #include<sys/stat.h> #include<fcntl.h> #include<string.h> #define FIFO1 "fifo1" #define FIFO2 "fifo2" #define PERMS 0666 char fname[256]; int main() { ssize_t n; char buff[512]; int readfd,writefd; printf("Trying to Connect to Server..\n"); writefd = open(FIFO1, O_WRONLY, 0); readfd = open(FIFO2, O_RDONLY, 0); printf("Connected..\n"); printf("Enter the filename to request from server: "); scanf("%s",fname); write(writefd, fname, strlen(fname)); printf("Waiting for Server to reply..\n"); while((n=read(readfd,buff,512))>0) write(1,buff,n); close(readfd); close(writefd); return 0; } Fifoserver.c #include<stdio.h> #include<unistd.h> #include<sys/stat.h> #include<fcntl.h> #include<string.h> #define FIFO1 "fifo1" #define FIFO2 "fifo2" 21

CN LAB MANUAL
#define PERMS 0666 char fname[256]; int main() { int readfd, writefd, fd; ssize_t n; char buff[512]; if (mkfifo(FIFO1, PERMS)<0) printf("Cant Create FIFO Files\n"); if (mkfifo(FIFO2, PERMS)<0) printf("Cant Create FIFO Files\n"); printf("Waiting for connection Request..\n"); readfd =open(FIFO1, O_RDONLY, 0); writefd=open(FIFO2, O_WRONLY, 0); printf("Connection Established..\n"); read(readfd, fname, 255); printf("Client has requested file %s\n", fname); if ((fd=open(fname,O_RDWR))<0) { strcpy(buff,"File does not exist..\n"); write(writefd, buff, strlen(buff)); } else { while((n=read(fd, buff,512))>0) write(writefd, buff, n); }close(readfd); unlink(FIFO1); close(writefd); unlink(FIFO2); } Note: Open Terminal-1 compile and run server program Open Terminal-2 compile and run client program

22

CN LAB MANUAL
6.Write a program for simple RSA algorithm to encrypt and decrypt the data #include <stdio.h> #include <math.h> #include <string.h> #include<ctype.h> long double plain_text[100]; long double cipher_text[100]; char text[100]; long double gcd(long double z, long double n) { if(n==0) return z; else return gcd(n,fmodl(z,n)); } int isprime(long double n) { long double i; for(i=2;i<=sqrt(n);i++) if(fmodl(n,i)==0) return 0; return 1; } long double crypt( long double msg,long double key,long double n) { int i; long double C=1; for(i=0;i< key;i++) C=fmodl((C*msg),n); C =fmodl(C,n); return C; } void main() { long double p,q,n,z,d,e,k; int i; printf("\n Enter two prime numbers p,q \n"); scanf("%Lf%Lf",&p,&q); if( isprime(p) && isprime(q) )
23

CN LAB MANUAL
{ n=p*q; z=(p-1)*(q-1); for(k=2;k<z;k++) if( gcd(k,z)==1) { e=k; break; } for(k=e+1;k<n;k++) if( fmodl((k*e),z)==1 ) { d=k; break; } printf("\n Public key { e,n } = { %Lf,%Lf }",e,n); printf("\n Private key { d,n } = { %Lf,%Lf }",d,n); printf("\n Enter some text\n"); scanf("%s",text); for(i=0;i<strlen(text);i++) { plain_text[i]=tolower(text[i])-'a'+1; printf("%Lf\t",plain_text[i]); } printf("\n---<After ENCRYPTION>--\n"); for(i=0;i<strlen(text);i++) { cipher_text[i]=crypt(plain_text[i],e,n); printf("%Lf\t",cipher_text[i]); } printf("\n---<After DECRYPTION>--\n"); for(i=0;i<strlen(text);i++) { plain_text[i]=crypt(cipher_text[i],d,n); printf("%Lf\t",plain_text[i]); } printf("\n\n\n"); for(i=0; i<strlen(text); i++) printf("%c",(char)plain_text[i]+'a'-1); } else printf("number entered is not prime\n");
24

CN LAB MANUAL
} To Compile cc lm filename.c OUTPUT Enter two prime numbers p,q 3 13 Public key { e,n } = { 5.000000,39.000000 } Private key { d,n } = { 29.000000,39.000000 } Enter some text HKBK 8.000000 11.000000 2.000000 11.000000 ---<After ENCRYPTION>-8.000000 20.000000 32.000000 20.000000 ---<After DECRYPTION>-8.000000 11.000000 2.000000 11.000000

25

CN LAB MANUAL
7. Write a program for Hamming code generation for error detection and correction. #include <stdio.h> main() { int g[7][4]={ 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1, 0,1,1,1, 1,0,1,1, 1,1,0,1}, h[3][7]={0,1,1,1,1,0,0, 1,0,1,1,0,1,0, 1,1,0,1,0,0,1}, c[7]={0,0,0,0,0,0,0}, s[3]={0,0,0},d[4],i,j,count; //clrscr(); printf("Enter the 4 Data bits:\n"); for(i=0;i<4;i++) scanf("%d",&d[i]); for(i=0;i<7;i++) /*Codeword Generation*/ for(j=0;j<4;j++) c[i]=(c[i]+g[i][j]*d[j])%2; printf("Codeword :\n"); for(i=0;i<7;i++) printf("%d ",c[i]); printf("\nEnter Received codeword :\n"); for(i=0;i<7;i++) scanf("%d",&c[i]); for(i=0;i<3;i++) /*Syndrome Vector Generation*/ for(j=0;j<7;j++) s[i]=(s[i]+h[i][j]*c[j])%2; printf("\nSyndrome Vector:\n"); for(i=0;i<3;i++) printf("%d ",s[i]); for(i=0;i<7;i++) {
26

CN LAB MANUAL
count=0; for(j=0;j<3;j++) if(h[j][i] == s[j])count++; if(count == 3) { printf("\nError occured in Codeword at %d Postion",i+1); printf("\nCorrected CodeWord is :\n"); c[i] ^= 1; for(i=0;i<7;i++) printf("%2d",c[i]); break; } } if(count!=3)printf("\nNo Error in Codeword"); } OUTPUT 1. Enter the 4 Data bits: 1011 Codeword : 1011010 Enter Received codeword : 1011010 Syndrome Vector: 000 No Error in Codeword 2.Enter the 4 Data bits: 1011 Codeword : 1011010 Enter Received codeword : 1011110 Syndrome Vector: 100 Error occured in Codeword at 5 Postion Corrected CodeWord is : 1011010
27

CN LAB MANUAL
8.Write a program for Congestion control using the leaky bucket algorithm. #include <stdio.h> #include <stdlib.h> void main() { int bs,or,ip,cbs=0,i; printf("\nEnter Bucket Size:"); scanf("%d",&bs); printf("Enter Output Rate:"); scanf("%d",&or); printf(" Input Packet Current Bucket Output Discarded\n"); printf(" Size contains rate Bytes"); for(;;) { ip=rand()%201; cbs+=ip; if(cbs>(bs+or)) { printf("\n\t%3d\t\t%3d\t%3d\t%3d",ip,bs,or,cbs-(bs+or)); cbs=bs; } else { if(cbs<or) printf("\n\t%3d\t\t%3d\t%3d\t%3d",ip,cbs,0,0); else { cbs-=or; printf("\n\t%3d\t\t%3d\t%3d\t%3d",ip,cbs,or,0); } } sleep(1); } } OUTPUT
28

CN LAB MANUAL
Enter Bucket Size:200 Enter Output Rate:50 Input Packet Current Bucket Output Discarded Size contains rate Bytes 19 19 0 0 100 69 50 0 147 166 50 0 184 200 50 100 155 200 50 105 97 200 50 47 67 200 50 17 129 200 50 79 105 200 50 55 7 157 50 0 53 160 50 0 172 200 50 82 134 200 50 84 85 200 50 35 143 200 50 93 100 200 50 50 198 200 50 148 27 177 50 0

29

You might also like