0% found this document useful (0 votes)
21 views

E3 CN LAB2-Algorithm

The document discusses framing methods in the OSI reference model and TCP/IP model. It defines an enum for framing methods including byte count, byte stuffing, and bit stuffing. It also defines a frame structure. Main functions include from_datalink_layer(), from_physical_layer(), and transmission_medium(). from_datalink_layer() implements byte count and byte stuffing by adding flags and escaping bytes. from_physical_layer() converts the frame to bits. transmission_medium() transmits the bits. from_link_layer() implements bit stuffing by inserting zeros after five consecutive ones.

Uploaded by

reddy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

E3 CN LAB2-Algorithm

The document discusses framing methods in the OSI reference model and TCP/IP model. It defines an enum for framing methods including byte count, byte stuffing, and bit stuffing. It also defines a frame structure. Main functions include from_datalink_layer(), from_physical_layer(), and transmission_medium(). from_datalink_layer() implements byte count and byte stuffing by adding flags and escaping bytes. from_physical_layer() converts the frame to bits. transmission_medium() transmits the bits. from_link_layer() implements bit stuffing by inserting zeros after five consecutive ones.

Uploaded by

reddy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

OSI Reference Model with framing methods (Byte count, Byte Stuffing)

enum fr_method{byte_count, byte_stuffing, bit_stuffing};

typedef struct
{
enum fr_method method;
write framing method properties
} frame;

int main()
{
char msg[] = "ABESCFLAG";
from_datalink_layer(msg);
return 0;
}

void from_datalink_layer(char packet[])


{
frame f;
f.method = assign method;
if(f.method == byte_count)
{
assign count and msg to frame
printf("\nAT DATALINK LAYER: %s %s %s\n", print count, //print message );

}
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);
}

void transmission_medium(char bits[])


{
printf("\nAT TRANSMISSION MEDIUM: %s\n", bits);
}
TCP/IP Reference Model with framing methods (Bit Stuffing)

void from_link_layer(char msg[])


{
frame f;
f.method=bit_stuffing;
char bits[1000];
if(f.method==bit_stuffing)
{
char arr[9]="";
assign SFD and EFD to frame
int i=0;
while(msg[i]!='\0')
{
Convert each character into binary form and append into frame stuffed message
i++;
}
f.s_msg[i*8]='\0';
i=0;
while(f.s_msg[i]!='\0')
{
int count=1;
if(f.s_msg[i]=='1')
{
Find if 5 1s coming then insert 0 bit to frame stuffed message
}
i++;
}
Append SFD bits into bits array
Append EFD bits into bits array
Append Stuffed message into bits array
printf("\nAT LINK LAYER: %s %s %s\n", f.SFD, f.s_msg, f.EFD);
transmission_medium(bits);
}
}

void transmission_medium(char bits[])


{
printf("\nAT TRANSMISSION MEDIUM: %s\n", bits);
}

You might also like