networks record final

46
Networks Lab Part A INDEX PART –A Sl.N o. Date Program Staff Signature 1. Simulate a three nodes point – to – point network with duplex links between them. 2. Simulate a four node point-to-point network 3. Simulate the different types of Internet traffic such as FTP and TELNET over a network and analyze the throughput. 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. 5. Simulate an Ethernet LAN using n nodes (6-10), change error rate and data rate and compare throughput 6. Simulate an Ethernet LAN using n nodes and set multiple traffic nodes and determine collision across different nodes 7. Simulate an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion window for different source / destination. 8. Simulate simple ESS and with transmitting nodes in wire-less LAN by simulation and determine the performance with respect to transmission of packets PART –B 1. Write a program for error detecting code using CRC-CCITT (16- bits). 2. Write a program for frame sorting technique used in buffers. Dept. Of CSE/ISE 1

Upload: jomon-t-jose

Post on 15-Oct-2014

31 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Networks Record Final

Networks Lab Part A

PROGRAM 1

Dept. Of CSE/ISE 1

INDEXPART –A

Sl.No. Date Program Staff Signature

1. Simulate a three nodes point – to – point network with duplex links between them.

2. Simulate a four node point-to-point network

3. Simulate the different types of Internet traffic such as FTP and TELNET over a network and analyze the throughput.

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.

5. Simulate an Ethernet LAN using n nodes (6-10), change error rate and data rate and compare throughput

6. Simulate an Ethernet LAN using n nodes and set multiple traffic nodes and determine collision across different nodes

7. Simulate an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion window for different source / destination.

8. Simulate simple ESS and with transmitting nodes in wire-less LAN by simulation and determine the performance with respect to transmission of packets

PART –B1. Write a program for error detecting code using CRC-

CCITT (16- bits).2. Write a program for frame sorting technique used in

buffers.3. Write a program for distance vector algorithm to find

suitable path for transmission.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.

5. Implement the above program using as message queues or FIFOs as IPC channels.

6. Write a program for simple RSA algorithm to encrypt and decrypt the data.

7. Write a program for Hamming code generation for error diction and correction.

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

Page 2: Networks Record Final

Networks Lab Part A

Simulate a three nodes point-to-point network with duplex links between them. Set the queue size vary the bandwidth and find the number of packets dropped.

Procedure:

Step1: Select the hub icon on the toolbar and drag it onto the working window.

Step 2: 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 as node 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 a .tpl file.

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, TCPDUMP, 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.Select FIFO and set the queue size to 50 and press OK. Then click on Add. Another dialog box pops up. Click on the Command box and type the Command according to the following syntax: stg [-t duration(sec)] [-p port number] HostIPaddrand click OK.

Step 5: Double-click on host (node 2), and follow the same step as above with only change in command according to the following syntax: rtg [-t] [-w log] [-p port number] and click OK.

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 can run/pause/continue/stop/abort/disconnect/reconnect/submit a simulation. No simulation settings can be changed in this mode.

Dept. Of CSE/ISE 2

Page 3: Networks Record Final

Networks Lab Part A

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 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: To view the results, go to the filename. Results folder

Dept. Of CSE/ISE 3

Page 4: Networks Record Final

Networks Lab Part A

Sender : stcp –p 1500 –l 1024 1.0.1.2

Receiver : rtcp –p 1500 –l 1024

Parameter : Number of packets dropped.

Output: No packets dropped.

PROGRAM 2Simulate a four node point-to-point network, and connect the links as follows: n0-n2, n1-n2 and n2-n3. Apply TCP agent between n0-n3 and UDP n1-n3. Apply relevant applications over TCP and UDP agents changing the parameter and determine the number of packets by TCP/UDP.

Procedure:

Step 1: Create the topology as specified in the question, in the draw mode of the simulator.

Step 2: Go to edit mode and save the topology.

Step 3: Setup a TCP connection between node 1 and node 3 using the following commands:

stcp [-p port] [-l writesize] hostIPaddrrtcp [-p port] [-l readsize]

Step 4: Setup a UDP connection between node 2 and node 3 using the following commands:

stg [-u payload size duration] [Hostaddress]rtg [-u] [-w log]

Dept. Of CSE/ISE 4

Page 5: Networks Record Final

Networks Lab Part A

Step 5: Set the output throughput log to determine the number of packets sent by TCP/UDP.

Step 6: To view the results, go to the filename.results folder.

Sender 1 : stcp –p 1500 –l 1024 1.0.1.3Sender 2 : stg -u 1024 100 1.0.1.3

Receiver : rtcp –p 1500 –l 1024 rtg –u –w log1

Parameter : Input and Output Throughput.

Output:

Output Throughput n0-n3: 605.682-942.678Input Throughput n1-n3: 1110.724-1180.210

Dept. Of CSE/ISE 5

Page 6: Networks Record Final

Networks Lab Part A

PROGRAM 3Simulate the different types of Internet traffic such as FTP a TELNET over a network and analyze the throughput.

Procedure:To setup a FTP connection:

Step 1: Create a topology of four nodes; connect these nodes to a hub.

Step 2: Go to the edit mode and setup FTP traffic between node1 and node 4 using the port number 23.

Step 3: Set the input and output throughput log file.

Step 4: To view the results, go to the filename.results folder.

To setup a TELNET connection:

Step 1: Create a topology of four nodes, connect these nodes to a hub.

Step 2: Go to the edit mode and setup a TELNET traffic between node1 and node 4 using the port number 7300.

Step 3: Set the input and output throughput log file as described in the above experiments.

Step 4: To view the results, go to the filename.results folder.

For FTP:Command used: stcp -p 23 -l 1024 1.0.1.6

rtcp -p 23 -l 1024

For TELNET:Command used: stcp -p 7300 -l 1024 1.0.1.6

rtcp -p 7300 -l 1024

Dept. Of CSE/ISE 6

Page 7: Networks Record Final

Networks Lab Part A

Sender 1 : stcp –p 1500 –l 1024 1.0.1.3Sender 2 : stcp –p 1501 –l 1024 1.0.1.3

Receiver : rtcp –p 1500 –l 1024 rtcp –p 1501 –l 1024

Parameter : Input and Output Throughput.

Output:Output Throughput n0-n3: 588.984-895.620Input Throughput n1-n3: 419.823-884.994

Dept. Of CSE/ISE 7

Page 8: Networks Record Final

Networks Lab Part A

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

Procedure:Step 1: Click on the subnet icon on the toolbar and then click on the screen of the

working window.

Step 2: Select the required number of hosts and a suitable radius between the host and the switch.

Step 3: In the edit mode, get the IP address of one of the hosts say, host 1 and then for the other host say, host2 set the drop packet and no: of collisions statistics.

Step 4: Now run the simulation.

Step 5: Now click on any one of the hosts and click on command console and ping the destination node.

Dept. Of CSE/ISE 8

Page 9: Networks Record Final

Networks Lab Part A

Sender 1 : stcp –p 1500 –l 1024 1.0.1.3

Receiver : rtcp –p 1500 –l 1024

Parameter : Number of Packets Dropped.

Output: No packets dropped.

Dept. Of CSE/ISE 9

Page 10: Networks Record Final

Networks Lab Part A

PROGRAM 5Simulate an Ethernet LAN using N- nodes(6-10), change error rate and data rate and compare the throughput.

Procedure:

Step 1: Connect one set of hosts with a hub and another set of hosts also through a hub and connect these two hubs through a switch. This forms an Ethernet LAN.

Step 2: Setup a TCP connection between a host on one hub and host on another hub using the following command:

stcp [-p port] [-l writesize] hostIPaddrrtcp [-p port] [-l readsize]

Step 3: Setup the error rate, data rate in the physical layer, input and output throughput in the mac layer as described above.

Step 4: Change error rate and data rate and compare the throughputs.

Step 5: View the results in the filename.results

Dept. Of CSE/ISE 10

Page 11: Networks Record Final

Networks Lab Part A

Sender 1 : stcp –p 1500 –l 1024 1.0.1.3

Receiver : rtcp –p 1500 –l 1024

Parameter : Input and Output Throughput.

Output:Sender Receiver

Initial Error Rate: 20.0 Initial Error Rate: 20.0Initial Data Rate:100.0 Initial Data Rate: 50.0

Input Throughput: 569.250-900.174Output Throughput: 570.768-880.440

Initial Error Rate: 20.0 Initial Error Rate: 20.0Initial Data Rate:100.0 Initial Data Rate: 50.0

Input Throughput: 595.056-898.656Output Throughput: 590.502-898.656

Dept. Of CSE/ISE 11

Page 12: Networks Record Final

Networks Lab Part A

PROGRAM 6Simulate an Ethernet LAN using N nodes and set multiple traffic nodes and determine collision across different nodes.

Procedure:

Step 1: Connect one set of hosts with a hub and another set of hosts also through a hub and connect these two hubs through a switch. This forms an Ethernet LAN.

Step 2: Setup multiple traffic connections between the hosts on one hub and hosts on another hub using the following command:

stcp [-p port] [-l writesize] hostIPaddrrtcp [-p port] [-l readsize]

Step 3: Setup the collision log at the destination hosts in the MAC layer.

Step 4: View the results in the filename.results.

Dept. Of CSE/ISE 12

Page 13: Networks Record Final

Networks Lab Part A

Sender 1 : stcp –p 1500 –l 1024 1.0.1.3

Receiver : rtcp –p 1500 –l 1024

Parameter : Number of Collision Packets.

Output:

Sender Receiver

Initial Error Rate: 0.0 Initial Error Rate: 0.0Initial Data Rate:10.0 Initial Data Rate: 5.0

Number of collisions : 290-1062

Initial Error Rate: 5.0 Initial Error Rate: 5.0Initial Data Rate:10.0 Initial Data Rate: 5.0

Number of collisions : 284-1080

Dept. Of CSE/ISE 13

Page 14: Networks Record Final

Networks Lab Part A

PROGRAM 7Simulate an Ethernet LAN using N nodes and set multiple traffic nodes and plot congestion window for different source/destination.

Procedure:Step 1: Connect one set of hosts with a hub and another set of hosts also through a hub and connect these two hubs through a switch. This forms an Ethernet LAN.

Step 2: Setup multiple traffic connections between the hosts on one hub and hosts on another hub using the following command:

stcp [-p port] [-l writesize] hostIPaddrrtcp [-p port] [-l readsize]

Step 3: Setup the collision log at the destination hosts in the MAC layer as described in the earlier experiments.

Step 4: To plot the congestion window go to Menu->Tools->Plot Graph->File->open->filename.results->filename.coll.log

Step 5: View the results in the filename.results.

Dept. Of CSE/ISE 14

Page 15: Networks Record Final

Networks Lab Part A

Sender 1 : stcp –p 1500 –l 1024 1.0.1.3Sender2 : stcp –p 1501 –l 1024 1.0.3

Receiver : rtcp –p 1500 –l 1024 rtcp –p 1501 –l 1024

Parameter : Number of Collision Packets and Packets Dropped.

Output:

Collision Packets for sender: 6- 384Collision Packets for receiver: 522-1068

Packets Dropped for sender: 6-384Packets Dropped for receiver: 522-1068

Dept. Of CSE/ISE 15

Page 16: Networks Record Final

Networks Lab Part A

PROGRAM 8Simulate simple ESS and with transmitting nodes in wireless LAN simulation and determine the performance with respect to transmission of packets.

Procedure:

Step 1: In the Draw mode, Select a Host/node and place it on the top.Step 2: Place a router below it.Step 3: Place two access points to the left and right of the router.Step 4: Connect these with point-to-point networkStep 5: Select Mobile Nodes and place them in all four directions of the access points.Step 6: Connect these with multipoint network.Step 7: Select Subnet Node option and click on each access points and mobile nodes such that we have two subnets for two parts. Step 8: In the edit mode, select Host -> add and insert the command rtcp –r –u –s -p [port]Step 9: Select each mobile node ->application -> add and insert the command ttcp –t –u –s –p [port] [receiver’s IP]Step 10: Click on Link between router and access point, Select delay=10000 and click CIAL.Step 11: In Run mode, Go to Simulation and select RunStep 12: To start the playback, the user can left-click the start icon ( |>) of the time located at the bottom. The animation player will then start playing the recorded packet animation.

Dept. Of CSE/ISE 16

Page 17: Networks Record Final

Networks Lab Part A

Sender : ttcp –t –u –s –p 1504 1.0.5.1Receiver : ttcp –t –u –s –p 1500

Input Throughput: 0.0-655.308Output Throughput: 0.0-655.

Dept. Of CSE/ISE 17

Page 18: Networks Record Final

Networks Lab Part B

PROGRAM 1Write a program for error detecting code using CRC-CCITT (16- bits).

Program:#include<stdio.h>#include<string.h>#include<conio.h>#define N strlen(g)char t[128], cs[128], g[]="10001000000100001";int a, e, c;void xor() { for(c=1;c<N;c++) cs[c]=((cs[c]==g[c])?'0':'1');}void crc() { for(e=0;e<N;e++) cs[e]=t[e]; do { if(cs[0]=='1') xor(); for(c=0;c<N-1;c++) cs[c]=cs[c+1]; cs[c]=t[e++]; }while(e<=a+N-1);}void main() { clrscr(); printf("\nEnter poly : "); scanf("%s",t); printf("\nGenerating Polynomial is : %s",g); a=strlen(t); for(e=a;e<a+N-1;e++) t[e]='0'; printf("\nModified t[u] is : %s",t); crc(); printf("\nChecksum is : %s",cs); for(e=a;e<a+N-1;e++) t[e]=cs[e-a]; printf("\nFinal Codeword is : %s",t); printf("\nTest Error detection 0(yes) 1(no) ? : "); scanf("%d",&e); if(e==0) { printf("Enter position where error is to inserted : "); scanf("%d",&e); t[e]=(t[e]=='0')?'1':'0'; printf("Errorneous data : %s\n",t); } crc(); for (e=0;(e<N-1)&&(cs[e]!='1');e++); if(e<N-1) printf("Error detected."); else printf("No Error Detected."); getch(); }

Dept. Of CSE/ISE 18

Page 19: Networks Record Final

Networks Lab Part B

OUTPUT

Enter poly : 1011101Generating Polynomial is : 10001000000100001Modified t[u] is : 10111010000000000000000Checksum is : 1000101101011000Final Codeword is : 10111011000101101011000Test Error detection 0(yes) 1(no) ? : 0Enter position where you want to insert error : 3Errorneous data : 10101011000101101011000Error detected.Enter poly : 1011101Generating Polynomial is : 10001000000100001Modified t[u] is : 10111010000000000000000Checksum is : 1000101101011000Final Codeword is : 10111011000101101011000Test Error detection 0(yes) 1(no) ? : 1No Error Detected.

Dept. Of CSE/ISE 19

Page 20: Networks Record Final

Networks Lab Part B

PROGRAM 2Write a program for frame sorting technique used in buffers.

Program:

#include<stdio.h>struct frame{

char info[15];int fno;

};struct frame arr[10];int n;void sort(){

int i,j;struct frame temp;for(i=0;i<n-1;i++){

for(j=0;j<n-i-1;j++)if(arr[j].fno>arr[j+1].fno){

temp=arr[j];arr[j]=arr[j+1];arr[j+1]=temp;

}}

}int main(){

int i,j;printf("Enter the no.of frames\n");scanf("%d",&n);printf("Enter the frame no and data into the frame\n");for(i=0;i<n;i++)scanf("%d %s",&arr[i].fno,arr[i].info);sort();printf("sorted frame and data are:\n");for(i=0;i<n;i++)printf("%d\t%s\n",arr[i].fno,arr[i].info);return 0;

}

Dept. Of CSE/ISE 20

Page 21: Networks Record Final

Networks Lab Part B

OUTPUT

Enter the no.of frames 4Enter the frame no and data into the frame4 ise 1 we 3 to 4 belongSorted frame and data are:Webelongtoise1 we2 belong3 to4 ise

Dept. Of CSE/ISE 21

Page 22: Networks Record Final

Networks Lab Part B

PROGRAM 3Write a program for distance vector algorithm to find suitable path for transmission.

Program:

#include<stdio.h>#include<stdlib.h>

int a[8][8],n;

void floid(){

int i,j,k;

for(k=1;k<=n;k++){

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

for(j=1;j<=n;j++){

a[i][j]=min(a[i][j],a[i][k]+a[k][j]);}

}}

}

int min(int a,int b){

return a<b?a:b;}

int main(){

int i,j;

printf("\n Enter the number of routers:");scanf("%d",&n);

printf("\n Enter the distance matrix values \n");for(i=1;i<=n;i++)

for(j=1;j<=n;j++){

scanf("%d",&a[i][j]);

Dept. Of CSE/ISE 22

Page 23: Networks Record Final

Networks Lab Part B

if(a[i][j]==0)a[i][j]=999;

if(i==j)a[i][j]=0;

}floid();

printf("\n Distance vector matrix \n");for(i=1;i<=n;i++)

{ for(j=1;j<=n;j++)

printf("%2d",a[i][j]);

printf("\n");}

}

Dept. Of CSE/ISE 23

Page 24: Networks Record Final

Networks Lab Part B

OUTPUT

Enter the number of routers:4Enter the distance matrix values0 1 3 9991 0 999 13 999 0 2999 1 2 0Distance vector matrix: 0 1 3 21 0 3 13 3 0 22 1 2 0

Dept. Of CSE/ISE 24

Page 25: Networks Record Final

Networks Lab Part B

PROGRAM 4Using 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 Program:

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<sys/types.h>#include<sys/socket.h>#include<netinet/in.h>#include<sys/fcntl.h>#include<arpa/inet.h>

int main(int argc,char *argv[]){

int sockfd,portno,n;struct sockaddr_in serv_addr;char buffer[4096],*servip;

if(argc<4){

fprintf(stderr,"usage %s serverip filename port \n",argv[0]);exit(0);

}servip=argv[1];portno=atoi(argv[3]);sockfd=socket(AF_INET,SOCK_STREAM,0);if(sockfd<0)

perror("error opening socket");printf("client online \n");bzero((char*)&serv_addr,sizeof(serv_addr));serv_addr.sin_family=AF_INET;serv_addr.sin_addr.s_addr=inet_addr(servip);serv_addr.sin_port=htons(portno);

if(connect(sockfd,(struct sockaddr*)&serv_addr,sizeof(serv_addr))<0)perror("error connecting");write(sockfd,argv[2],strlen(argv[2])+1);bzero(buffer,4096);n=read(sockfd,buffer,4096);

if(n<=0){

Dept. Of CSE/ISE 25

Page 26: Networks Record Final

Networks Lab Part B

perror("file not found");exit(0);

}write(1,buffer,n);

}

Server Program:

#include<stdio.h>#include<stdlib.h>#include<sys/types.h>#include<sys/socket.h>#include<netinet/in.h>#include<sys/fcntl.h>

int main(int argc, char*argv[]){

int fd,sockfd,newsockfd,clilen,portno,n;struct sockaddr_in serv_addr,cli_addr;char buffer[4096];

if(argc<2){

fprintf(stderr,"no port\n");exit(1);

}

portno=atoi(argv[1]);sockfd=socket(AF_INET,SOCK_STREAM,0);if(sockfd<0)

error("error opening socket");zero((char*)&serv_addr,sizeof(serv_addr));serv_addr.sin_family=AF_INET;serv_addr.sin_addr.s_addr=(htonl)INADDR_ANY;serv_addr.sin_port=htons(portno);

if(bind(sockfd,(struct sockaddr*)&serv_addr,sizeof(serv_addr))<0)perror("error binding");listen(sockfd,5);clilen=sizeof(cli_addr);printf("SERVER waiting for the CLIENT------\n");

while(1){

newsockfd=accept(sockfd,(struct sockaddr*)&cli_addr,&clilen);if(newsockfd<0)

Dept. Of CSE/ISE 26

Page 27: Networks Record Final

Networks Lab Part B

perror("error on accept");bzero(buffer,4096);read(newsockfd,buffer,4096);fd=open(buffer,O_RDONLY);

if(fd<0)perror("file open error");

while(1){

n=read(fd,buffer,4096);if(n<=0) exit(0);write(newsockfd,buffer,n);printf("Transfer Completed \n");

}close(fd);close(newsockfd);

}return 0;

}

Dept. Of CSE/ISE 27

Page 28: Networks Record Final

Networks Lab Part B

OUTPUT

Server:cc –o serv prog4b.c./serv 1111Client onlineTransfer complete!

Client:cc –o cli prog4a.c./cli 127.0.0.1 prog3.c 1111Server waiting for the client....

#include<stdio.h>#include<stdlib.h>Int a[8][8],n;int main()....

Dept. Of CSE/ISE 28

Page 29: Networks Record Final

Networks Lab Part B

PROGRAM 5Implement the above program using as message queues or FIFOs as IPC channels.

Client Program:

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<fcntl.h>#include<sys/types.h>#include<sys/stat.h>#include<unistd.h>#define FIFO1 "fifo1"#define FIFO2 "fifo2"

int main(){

char p[100],c[5000];int num1,num2,f1,fd,fd2;

mknod(FIFO1,S_IFIFO | 0666,0);mknod(FIFO2,S_IFIFO | 0666,0);

printf("\n Client Running---\n");fd=open(FIFO1,O_WRONLY);fd2=open(FIFO2,O_RDONLY);

printf("\n Client:Enter the filename\n");scanf("%s",p);num1=write(fd,p,strlen(p));

if(num1==-1){

perror("write error \n");return 1;

}else{

printf("Waiting for reply----\n");if((num2=read(fd2,c,5000))==-1)

perror("Transfer error \n");else{

c[num2]='\0';if(strcmp(c,"ERROR")==0){

Dept. Of CSE/ISE 29

Page 30: Networks Record Final

Networks Lab Part B

printf("\n File not found...Connection ended\n");return 1;

}printf("File received: The contents are..\n");printf("%s",c);

}}return 1;

}

Server Program:

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<fcntl.h>#include<sys/types.h>#include<sys/stat.h>#define FIFO1 "fifo1"#define FIFO2 "fifo2"

int main(){

char p[100],c[5000];int num1,num2,fd,fd2;int f1;

mknod(FIFO1,S_IFIFO | 0666,0); mknod(FIFO2,S_IFIFO | 0666,0);

printf("\n SERVER Online---\n"); fd=open(FIFO1,O_RDONLY); fd2=open(FIFO2,O_WRONLY);

printf("Client Online\n waiting for request---\n\n");if((num1=read(fd,p,100))==-1)

perror("read error \n");else{

p[num1]='\0';if((f1=open(p,O_RDONLY))<0){

perror("\nFILE");write(fd2,"ERROR",strlen("ERROR"));

Dept. Of CSE/ISE 30

Page 31: Networks Record Final

Networks Lab Part B

return 1;}else{

num2=read(f1,c,5000);if(num2==-1)

perror("read");else{

printf("SERVER:Transferring the content:%s",p);num2=write(fd2,c,5000);

}}

}printf("\n Transfer completed");return 1;

}

Dept. Of CSE/ISE 31

Page 32: Networks Record Final

Networks Lab Part B

OUTPUT

Server:

[root@localhost CN Lab] ./s.oWaiting for connection Request..Connection Established..Client has requested file alpha[root@localhost CN Lab]

Client:[root@localhost CN Lab] ./c.oTrying to Connect to Server..Connected..Enter the filename to request from server: alphaWaiting for Server to reply..This a demo of client server using SocketsJust for trial.Now End of file[root@localhost CN Lab]

Dept. Of CSE/ISE 32

Page 33: Networks Record Final

Networks Lab Part B

PROGRAM 6Write a program for simple RSA algorithm to encrypt and decrypt the data.

Program:

#include <stdio.h>#include <string.h>#include <conio.h>#include <math.h>int mult(unsigned int x, unsigned int y, unsigned int n) { unsigned long int k=1; int j; for (j=1; j<=y; j++) k = (k * x) % n; return (unsigned int) k;} void main () { char msg[100]; unsigned int pt[100], ct[100], n, d, e, p, q, i; printf("Enter message : "); gets(msg); //strcpy(pt, msg); for(i=0;i<strlen(msg);i++) pt[i]=msg[i]; n = 253; d = 17; e = 13; printf("\nCT = "); for(i=0; i<strlen(msg); i++) ct[i] = mult(pt[i], e,n); for(i=0; i<strlen(msg); i++) printf("%d ", ct[i]); printf("\nPT = "); for(i=0; i<strlen(msg); i++) printf("%c", pt[i]); for(i=0; i<strlen(msg); i++) pt[i] = mult(ct[i], d,n) ;}

Dept. Of CSE/ISE 33

Page 34: Networks Record Final

Networks Lab Part B

OUTPUT

Enter message: alpha

CT = 113 3 129 213 113

PT = alpha

Dept. Of CSE/ISE 34

Page 35: Networks Record Final

Networks Lab Part B

PROGRAM 7Write a program for Hamming code generation for error detection and correction.

Program:

#include<iostream.h>#include<conio.h>#include<stdlib.h>#include<stdio.h>

char data[5];int encoded[8], edata[7], syndrome[3];int hmatrix[3][7]= { 1,0,0,0,1,1,1, 0,1,0,1,0,1,1,

0,0,1,1,1,0,1};char gmatrix[4][8]={ "0111000", "1010100", "1100010", "1110001"};void main() { int i,j; clrscr(); cout<<"Hamming Code --- Encoding\n"; cout<<"Enter 4 bit data : "; cin>>data; cout<<"Generator Matrix\n"; for(i=0;i<4;i++) cout<<"\t"<<gmatrix[i]<<"\n"; cout<<"Encoded Data : "; for(i=0;i<7;i++) { for(j=0;j<4;j++) encoded[i]+=((data[j]- '0')*(gmatrix[j][i]- '0')); encoded[i]=encoded[i]%2; cout<<encoded[i]<<" "; } cout<<"\nHamming code --- Decoding\n"; cout<<"Enter Encoded bits as received : "; for(i=0;i<7;i++) cin>>edata[i]; for(i=0;i<3;i++) { for(j=0;j<7;j++) syndrome[i]=syndrome[i]+(edata[j]*hmatrix[i][j]); syndrome[i]=syndrome[i]%2; } for(j=0;j<7;j++) if ((syndrome[0]==hmatrix[0][j])&&(syndrome[1]==hmatrix[1][j])&&

(syndrome[2]==hmatrix[2][j])) break;

Dept. Of CSE/ISE 35

Page 36: Networks Record Final

Networks Lab Part B

if(j==7) cout<<"Data is error free!!\n"; else { cout<<"Error received at bit number "<<j+1<<" of the data\n"; edata[j]=!edata[j]; cout<<"The Correct data Should be : "; for(i=0;i<7;i++) cout<<edata[i]<<" ";} } }

Dept. Of CSE/ISE 36

Page 37: Networks Record Final

Networks Lab Part B

OUTPUT

Hamming Code --- EncodingEnter 4 bit data : 1 0 1 0Generator Matrix 0111000 1010100 1100010 1110001Encoded Data : 1 0 1 1 0 1 0Hamming code --- DecodingEnter Encoded bits as received : 1 0 1 1 0 1 1Error received at bit number 7 of the dataThe Correct data Should be : 1 0 1 1 0 1 0

Hamming Code --- EncodingEnter 4 bit data : 1 0 1 0Generator Matrix 0111000 1010100 1100010 1110001Encoded Data: 1 0 1 1 0 1 0Hamming code --- DecodingEnter Encoded bits as received: 1 0 1 1 0 1 0Data is error free!!

Dept. Of CSE/ISE 37

Page 38: Networks Record Final

Networks Lab Part B

PROGRAM 8Write a program for congestion control using leaky bucket algorithm.

Program:

#include<iostream.h>#include<dos.h>#include<stdlib.h>#define bucketSize 512void bktInput(int a,int b) { if(a>bucketSize) cout<<"\n\t\tBucket overflow"; else { delay(500); while(a>b){

cout<<"\n\t\t"<<b<<" bytes outputted.";a-=b;delay(500);

} if (a>0) cout<<"\n\t\tLast "<<a<<" bytes sent\t"; cout<<"\n\t\tBucket output successful"; }}void main() { int op, pktSize; randomize(); cout<<"Enter output rate : "; cin>>op; for(int i=1;i<=5;i++){ delay(random(1000)); pktSize=random(1000); cout<<"\nPacket no "<<i<<"\tPacket size = "<<pktSize; bktInput(pktSize,op); }}

Dept. Of CSE/ISE 38

Page 39: Networks Record Final

Networks Lab Part B

OUTPUT

Enter output rate : 100Packet no 0 Packet size = 3 Bucket output successful Last 3 bytes sentPacket no 1 Packet size = 33 Bucket output successful Last 33 bytes sentPacket no 2 Packet size = 117 Bucket output successful 100 bytes outputted. Last 17 bytes sentPacket no 3 Packet size = 95 Bucket output successful Last 95 bytes sentPacket no 4 Packet size = 949 Bucket overflow

Dept. Of CSE/ISE 39