Categories
TE Computer Engineering

3. Write a program to simulate Go back N and Selective Repeat Modes of Sliding Window Protocol in peer to peer mode and demonstrate the packets captured traces using Wireshark Packet Analyzer Tool for peer to peer mode.

Download The write up here

//—–AT CLIENT SIDE——

    import java.lang.System;
    import java.net.*;
    import java.io.*;

    public class Client {
        static Socket connection;

        public static void main(String a[]) throws SocketException {
            try {
                int v[] = new int[9];
                //int g[] = new int[8];
                int n = 0;
                InetAddress addr = InetAddress.getByName(“Localhost”);
                System.out.println(addr);
                connection = new Socket(addr, 8011);
                DataOutputStream out = new DataOutputStream(
                        connection.getOutputStream());
                DataInputStream in = new DataInputStream(
                        connection.getInputStream());
                int p = in.read();
                System.out.println(“No of frame is:” + p);

                for (int i = 0; i < p; i++) {
                    v[i] = in.read();
                    System.out.println(v[i]);
                    //g[i] = v[i];
                }
                v[5] = -1;
                for (int i = 0; i < p; i++)
                 {
                    System.out.println(“Received frame is: ” + v[i]);

                    }
                for (int i = 0; i < p; i++)
                    if (v[i] == -1) {
                System.out.println(“Request to retransmit packet no “
                                + (i+1) + ” again!!”);
                        n = i;
                        out.write(n);
                        out.flush();
                    }

                System.out.println();

                    v[n] = in.read();
                System.out.println(“Received frame is: ” + v[n]);



                System.out.println(“quiting”);
            } catch (Exception e) {
                System.out.println(e);
            }

        }
    }

/* OUTPUT 
iotlab@iotlab-Veriton-M200-B360:~/sliding window$ javac Client.java
iotlab@iotlab-Veriton-M200-B360:~/sliding window$ java Client
Localhost/127.0.0.1
No of frame is:9
30
40
50
60
70
80
90
100
110
Received frame is: 30
Received frame is: 40
Received frame is: 50
Received frame is: 60
Received frame is: 70
Received frame is: -1
Received frame is: 90
Received frame is: 100
Received frame is: 110
Request to retransmit packet no 6 again!!

Received frame is: 80
quiting
iotlab@iotlab-Veriton-M200-B360:~/sliding window$
*/

//—–AT SERVER SIDE—–

    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.net.SocketException;

    public class Server {
        static ServerSocket Serversocket;
        static DataInputStream dis;
        static DataOutputStream dos;

        public static void main(String[] args) throws SocketException {

        try {
            int a[] = { 30, 40, 50, 60, 70, 80, 90, 100, 110 };
            Serversocket = new ServerSocket(8011);
            System.out.println(“waiting for connection”);
            Socket client = Serversocket.accept();
            dis = new DataInputStream(client.getInputStream());
            dos = new DataOutputStream(client.getOutputStream());
            System.out.println(“The number of packets sent is:” + a.length);
            int y = a.length;
            dos.write(y);
            dos.flush();

            for (int i = 0; i < a.length; i++) {
                dos.write(a[i]);
                dos.flush();
            }

            int k = dis.read();

            dos.write(a[k]);
            dos.flush();

            } catch (IOException e) {
                System.out.println(e);
            } finally {
                try {
                    dis.close();
                    dos.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        }
    }

/*OUTPUT
iotlab@iotlab-Veriton-M200-B360:~/sliding window$ javac Server.java
iotlab@iotlab-Veriton-M200-B360:~/sliding window$ java Server
waiting for connection
The number of packets sent is:9
iotlab@iotlab-Veriton-M200-B360:~/sliding window$
*/

Categories
TE Computer Engineering

2. Write a program for error detection and correction for 7/8 bits ASCII codes using Hamming Codes or CRC. Demonstrate the packets captured traces using Wireshark Packet Analyzer Tool for peer to peer mode.( 50% students will perform Hamming Code and others will perform CRC).

Download The write up here

1. CRC

#include <iostream>
using namespace std;

int main()
{
    int i,j,k,l;

        //Get Frame
        int fs;
        cout<<“\n Enter Frame size: “;
        cin>>fs;

        int f[20];

        cout<<“\n Enter Frame:”;
        for(i=0;i<fs;i++)
        {
        cin>>f[i];
        }

        //Get Generator
        int gs;
        cout<<“\n Enter Generator size: “;
        cin>>gs;

        int g[20];

        cout<<“\n Enter Generator:”;
        for(i=0;i<gs;i++)
        {
        cin>>g[i];
        }

        cout<<“\n Sender Side:”;
        cout<<“\n Frame: “;
        for(i=0;i<fs;i++)
        {
        cout<<f[i];
        }
        cout<<“\n Generator :”;
        for(i=0;i<gs;i++)
        {
        cout<<g[i];
        }

        //Append 0’s
        int rs=gs-1;
        cout<<“\n Number of 0’s to be appended: “<<rs;
        for (i=fs;i<fs+rs;i++)
        {
        f[i]=0;
        }

        int temp[20];
        for(i=0;i<20;i++)
        {
        temp[i]=f[i];
        }

        cout<<“\n Message after appending 0’s :”;
        for(i=0; i<fs+rs;i++)
        {
        cout<<temp[i];
        }

        //Division
        for(i=0;i<fs;i++)
        {
        j=0;
        k=i;
        //check whether it is divisible or not
        if (temp[k]>=g[j])
        {
            for(j=0,k=i;j<gs;j++,k++)
            {
                if((temp[k]==1 && g[j]==1) || (temp[k]==0 && g[j]==0))
                {
                    temp[k]=0;
                }
                else
                {
                    temp[k]=1;
                }
            }
        }
        }

        //CRC
        int crc[15];
        for(i=0,j=fs;i<rs;i++,j++)
        {
        crc[i]=temp[j];
        }

        cout<<“\n CRC bits: “;
        for(i=0;i<rs;i++)
        {
        cout<<crc[i];
        }

        cout<<“\n Transmitted Frame: “;
        int tf[15];
        for(i=0;i<fs;i++)
        {
        tf[i]=f[i];
        }
        for(i=fs,j=0;i<fs+rs;i++,j++)
        {
        tf[i]=crc[j];
        }
        for(i=0;i<fs+rs;i++)
        {
        cout<<tf[i];
        }

        cout<<“\n Receiver side : “;
        cout<<“\n Received Frame: “;
        for(i=0;i<fs+rs;i++)
        {
        cout<<tf[i];
        }

        for(i=0;i<fs+rs;i++)
        {
        temp[i]=tf[i];
        }

        //Division
        for(i=0;i<fs+rs;i++)
        {
        j=0;
        k=i;
        if (temp[k]>=g[j])
        {
            for(j=0,k=i;j<gs;j++,k++)
            {
                if((temp[k]==1 && g[j]==1) || (temp[k]==0 && g[j]==0))
                {
                    temp[k]=0;
                }
                else
                {
                    temp[k]=1;
                }
            }
        }
        }

        cout<<“\n Reaminder: “;
        int rrem[15];
        for (i=fs,j=0;i<fs+rs;i++,j++)
        {
        rrem[j]= temp[i];
        }
        for(i=0;i<rs;i++)
        {
        cout<<rrem[i];
        }

        int flag=0;
        for(i=0;i<rs;i++)
        {
        if(rrem[i]!=0)
        {
            flag=1;
        }
        }

        if(flag==0)
        {
        cout<<“\n Since Remainder Is 0 Hence Message Transmitted From Sender To Receriver Is Correct”;
        }
        else
        {
        cout<<“\n Since Remainder Is Not 0 Hence Message Transmitted From Sender To Receriver Contains Error”;
        }
        return 0;
}

/* OUTPUT
iotlab@iotlab-Veriton-M200-B360:~$ g++ crc1.cpp
iotlab@iotlab-Veriton-M200-B360:~$ ./a.out

 Enter Frame size: 8

 Enter Frame:1
0
1
1
0
1
1
1

 Enter Generator size: 4

 Enter Generator:1
0
1
0

Sender Side:
Frame: 10110111
Generator :1010
Number of 0’s to be appended: 3
Message after appending 0’s :10110111000
CRC bits: 110
Transmitted Frame: 10110111110
Receiver side :
Received Frame: 10110111110
Reaminder: 000
Since Remainder Is 0 Hence Message Transmitted From Sender To Receriver Is Correct
*/

2. Hamming Code

 #include<iostream>

using namespace std;

int main()
{
    int data[10];
    int dataatrec[10],c,c1,c2,c3,i;

        cout<<“Enter 4 bits of data one by one\n”;
        cin>>data[7];
        cin>>data[6];
        cin>>data[5];
        cin>>data[3];

        //Calculation of even parity
        data[4]=data[5]^data[6]^data[7];
        data[2]=data[3]^data[6]^data[7];
        data[1]=data[3]^data[5]^data[7];

        cout<<“\nEncoded data is\n”;
        for(i=1;i<=7;i++)
            cout<<data[i];

        cout<<“\n\nEnter received data bits one by one\n”;
        for(i=1;i<=7;i++)
            cin>>dataatrec[i];

        c1=dataatrec[1]^dataatrec[3]^dataatrec[5]^dataatrec[7];
        c2=dataatrec[2]^dataatrec[3]^dataatrec[6]^dataatrec[7];
        c3=dataatrec[4]^dataatrec[5]^dataatrec[6]^dataatrec[7];
        c=c3*4+c2*2+c1;
        if(c==0)
        {
        cout<<“\ncongratulations there is no error: “;
    }
    else
    {
        cout<<“\nerror on the postion:”<<c;
        cout<<“\nCorrect message is:”;
        if(dataatrec[c]==0)
                 dataatrec[c]=1;
        else
                 dataatrec[c]=0;
        for (i=1;i<=7;i++)
        {
            cout<<dataatrec[i];
        }
    }

        return 0;
}

/*OUTPUT
iotlab@iotlab-Veriton-M200-B360:~$ g++ Ham.cpp
iotlab@iotlab-Veriton-M200-B360:~$ ./a.out
Enter 4 bits of data one by one
1
1
0
0

Encoded data is
1000011

Enter received data bits one by one
1
1
0
0
0
1
1

error on the postion:2
Correct message is:1000011

iotlab@iotlab-Veriton-M200-B360:~$*/

Categories
TE Computer Engineering

1. Part A: Setup a wired LAN using Layer 2 Switch and then IP switch of minimum four computers. It includes preparation of cable, testing of cable using line tester, configuration machine using IP addresses, testing using PING utility and demonstrate the PING packets captured traces using Wireshark Packet Analyzer Tool. Part B: Extend the same Assignment for Wireless using Access Point.

Refer Lab Manual

Download The write up here