E3 CN LAB2-Algorithm
E3 CN LAB2-Algorithm
typedef struct
{
enum fr_method method;
write framing method properties
} frame;
int main()
{
char msg[] = "ABESCFLAG";
from_datalink_layer(msg);
return 0;
}
}
else if(f.method== byte_stuffing)
{
Append FLAG to SFD, EFD and append packet to frame stuffed message
int i=0;
while(f.s_msg[i]!='\0')
{
char flags[][5] = {"FLAG", "ESC"};
if(f.s_msg[i]=='F')
{
Find whether it is FLAG word or not using flags[0][j] and append ESC if it is FLAG.
}
else if(f.s_msg[i]=='E')
{
Find whether it is FLAG word or not using flags[1][j] and append ESC if it is ESC.
}
i++;
}
f.s_msg[i]='\0';
printf("\nAT DATALINK LAYER: %s %s %s\n", SFD, STUFFED MESSAGE, EFD);
}
from_physical_layer(f);
void from_physical_layer(frame f)
{
char bits[1000]="";
if(f.method==byte_count)
{
Convert count and message to binary form and append into bits array
}
else if(f.method==byte_stuffing)
{
char arr[8]="", FLAG[9]="01111110";
int ESC = 27;
append SFD flag bits into bits array
while(f.s_msg[i]!='\0')
{
char flags[][5] = {"FLAG", "ESC"};
if(f.s_msg[i]=='E' && check==0)
{
Find out whether it is ESC or not, insert ESC bits to bits array.
}
check = 0;
convert each character into bits and append bits into bits array.
i++;
k++;
}
append EFD flag bits into bits array
}
printf("\nAT PHYSICAL LAYER: %s\n", bits, strlen(bits));
transmission_medium(bits);
}