Simulation
of ISO-OSI reference Model
import java.io.*;
class osinew
{
public
static void main(String args[])throws IOException
{
int
stream[]=new int[40];
BufferedReader
br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter
the data stream(10 bits)");
for(int
i=22;i<32;i++)
{
stream[i]=Integer.parseInt(br.readLine());
}
System.out.println("the
header added in application layer is 000");
stream[21]=0;
stream[20]=0;
stream[19]=0;
for(int
i=19;i<32;i++)
{
System.out.print(""+stream[i]);
}
System.out.println();
System.out.println();
System.out.println("the
header added in presentation layer is 001");
stream[18]=1;
stream[17]=0;
stream[16]=0;
//System.out.println();
for(int
i=16;i<32;i++)
{
System.out.print(""+stream[i]);
}
System.out.println();
System.out.println();
System.out.println("the
header added in session layer is 010");
stream[15]=0;
stream[14]=1;
stream[13]=0;
//System.out.println();
for(int
i=13;i<32;i++)
{
System.out.print(""+stream[i]);
}
System.out.println();
System.out.println();
System.out.println("the
header added in transport layer is 011");
stream[12]=1;
stream[11]=1;
stream[10]=0;
//System.out.println();
for(int
i=10;i<32;i++)
{
System.out.print(""+stream[i]);
}
System.out.println();
System.out.println();
System.out.println("the
header added in network layer is 100");
stream[9]=0;
stream[8]=0;
stream[7]=1;
//System.out.println();
for(int
i=7;i<32;i++)
{
System.out.print(""+stream[i]);
}
System.out.println();
System.out.println();
System.out.println("the
header added in datalink layer is 101");//header of dll
stream[6]=1;
stream[5]=0;
stream[4]=1;
//System.out.println();
for(int
i=4;i<32;i++)
{
System.out.print(""+stream[i]);
}System.out.println();
System.out.println();
System.out.println("the
trailer added in datalink layer is 110");//trailer of dll
stream[34]=0;
stream[33]=1;
stream[32]=1;
//System.out.println();
for(int
i=4;i<35;i++)
{
System.out.print(""+stream[i]);
}
System.out.println();
System.out.println();
System.out.println("the
header added in physical layer is 000");//header of physical layer
stream[3]=0;
stream[2]=0;
stream[1]=0;
//System.out.println();
for(int
i=1;i<35;i++)
{
System.out.print(""+stream[i]);
}
System.out.println();
System.out.println();
System.out.println("the
whole stream received at the receiver side is:");
for(int
i=1;i<35;i++)
{
System.out.print(""+stream[i]);
}
System.out.println();
}
}
/* OUTPUT
solution 1
enter the data stream(10 bits)
1
1
0
0
1
0
0
1
0
1
the header added in application layer is 000
0001100100101
the header added in presentation layer is 001
0010001100100101
the header added in session layer is 010
0100010001100100101
the header added in transport layer is 011
0110100010001100100101
the header added in network layer is 100
1000110100010001100100101
the header added in datalink layer is 101
1011000110100010001100100101
the trailer added in datalink layer is 110
1011000110100010001100100101110the header added in
physical layer is 000
the whole stream received at the receiver side is:
1111011000110100010001100100101110Press any key to
continue...
solution 2:
enter the data stream(10 bits)
1
1
1
1
1
0
0
0
0
0
the header added in application layer is 000
0001111100000
the header added in presentation layer is 001
0010001111100000
the header added in session layer is 010
0100010001111100000
the header added in transport layer is 011
0110100010001111100000
the header added in network layer is 100
1000110100010001111100000
the header added in datalink layer is 101
1011000110100010001111100000
the trailer added in datalink layer is 110
1011000110100010001111100000110
the header added in physical layer is 000
0001011000110100010001111100000110
the whole stream received at the receiver side is:
0001011000110100010001111100000110
Press any key to continue...
*/
No comments:
Post a Comment