postheadericon Protocol 1 utopia

header file


/*
   Protocol 1 (utopia)
   provides for data transmission in one direction only, from sender to receiver.
   The communication channel is assumed to be error free,
   and the receiver is assumed to be able to process all the input infinitely fast.
   Consequently, the sender just sits in a loop pumping data out onto the line as
   fast as it can.

*/


#include<stdio.h>
#include<fcntl.h>
#include<string.h>

//define the frame structure
typedef struct
{
int seqno;
int ackno;
char data[100];
}frame;

//services used @ sender side
void from_network_layer(char buffer[],int sno)
{
printf("Enter Frame [%d] : ",sno);
scanf("%s",buffer);
}

void to_physical_layer(int pid,frame *f)
{
write(pid,f,sizeof(frame));
}


//services used @ reciving side

void from_physical_layer(int pid,frame *f)
{
read(pid,f,sizeof(frame));
}

void to_network_layer(char buffer[],int sno)
{
printf("\nFrame [%d] : %s",sno,buffer);
}



Sender



#include "header.h"

void main()
{
int pid,i,no;
char buffer[100];

frame f;

system(">pipe");
pid=open("pipe",O_WRONLY);

printf("How many Frame you want to send? : ");
scanf("%d",&no);

write(pid,&no,sizeof(no));

for(i=0;i<no;i++)
{
from_network_layer(buffer,i); /*  get some data from network layer to send next layer */
strcpy(f.data,buffer);      /*  copy received data into frame's pay load for transmission */
f.seqno=i;
to_physical_layer(pid,&f); /*  send our frame on physical layer */
}
close(pid);
}

Receiver



#include "header.h"

void main()
{
int pid,no,i;
char buffer[100];
frame f;

pid=open("pipe",O_RDONLY);
read(pid,&no,sizeof(no));

printf("Total Frame Recived : %d",no);

for(i=0;i<no;i++)
{
from_physical_layer(pid,&f); /*  get some data from physical layer to send network layer */
strcpy(buffer,f.data); /*  copy received data into buffer */

to_network_layer(buffer,f.seqno); /*  send our received data to network layer */
}
close(pid);
unlink("pipe");
}




0 comments:

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.