Skip to content
Related Articles

Related Articles

Improve Article

Slow Start Backoff Algorithm for Ad-Hoc

  • Last Updated : 19 Oct, 2020

If the receiver proclaims a large window-size, larger than what the network en-route can manage, then there will always be packet losses. So there will be re-transmissions as well. However, the sender can’t send all the packets for which ACK (Acknowledgement) has not been received. Because of this way, even more congestion in the network will be caused. Moreover, the sender cannot be sure about the packets that have been lost due to transmission. It might be that this is the only packet that has been lost. It will also be not know how many packets have been actually received and buffered by the receiver. In that case, the sender will have superfluously sent various packets.
So the re-transmission of the packets also follows slow – start backoff mechanism. However, we do precisely need to keep an upper bound on the size of the packets as it gets increases in slow start, to prevent it from the increasing in unbounded and causing congestion. In slow – start backoff mechanism 
the threshold window size is half the value of the size of the congestion window.
Prerequisite: Back-off Algorithm for CSMA/CD 
Algorithm of Slow-Start Mechanism:- 
 

repeat
 if ACK frame received then successful transmission
  if current backoff window size <= Wm then
   if current backoff window size = W0 then
    current backoff window size = W0
  else
  current backoff window size =  current backoff window size ÷ 2
 else
 current backoff window size = current backoff window size-W0
else
 if current backoff window size < Wm then
 current backoff window size = current backoff window size × 2
  else frame lost due to collision or interference
   if current backoff window size = Wn then
   current backoff window size = Wn
   else
 current backoff window size = current backoff window size +W0
until no more frame to transmit
end


Examples: 
 

This represents the successful transmission because Threshold window is lesser the current window. 
Input : 
Enter the Threshold value:–>512 
Enter the Current backoff window size:–>64 
Output : 
Backoff Window Size is:–>128 
Backoff Window Size is:–>96 
Successful transmission 
Backoff Window Size is:–>32 
Successful transmission 
Backoff Window Size is:–>32 
Backoff Window Size is:–>128 
Backoff Window Size is:–>96 
Successful transmission 
Backoff Window Size is:–>32
This represents the unsuccessful transmission because Tthe hreshold window is greater the current window. 
Input : 
Enter the Threshold value:–>512 
Enter the Current backoff window size:–>1024 
Output : 
Frame lost due to collision or interferenceBackoff Window Size is:–>1056 
Successful transmission 
Backoff Window Size is:–>512 
Successful transmission 
Backoff Window Size is:–>512 
Frame lost due to collision or interferenceBackoff Window Size is:–>1056 
Successful transmission 
Backoff Window Size is:–>512 
 

Notations:- 
 

W0 -->  Initial backoff window size
Wm -->  Threshold
Wn -->  Maximum backoff window size
ACK --> Acknowledgement
Curr_BT --> Current  backoff window size


Implementation of the Slow-Start Mechanism:- 
 



CPP




#include <cstdlib>
#include <iostream>
#include <math.h>
#include <random>
#include <string>
#include <time.h>
 
using namespace std;
 
void signal(int array_ACK[])
{
    srand(time_t(0));
    for (int i = 0; i < 5; i++) {
        array_ACK[i] = rand() % 2;
    }
}
 
void Slow_Start_Backoff(int Wm, int Wo, int Wn,
                        int Curr_BT, int array_ACK[])
{
    // Taking ACK Binary values in
    // array by user one by one
 
    // backoff_win_size defines
    // backoff window size
 
    int backoff_win_size = 0;
 
    // Printing of backoff window size takes place
 
    for (int j = 0; j < 5; j++) {
        if (array_ACK[j] == 1) {
            cout << "Successful transmission" << endl;
            if (Curr_BT <= Wm) {
                if (Curr_BT == Wo) {
                    Curr_BT = Wo;
                    cout << "Backoff Window Size is:-->"
                            << Curr_BT << endl;
                }
                else {
                    Curr_B= Curr_BT / 2;
                    cout << "Backoff Window Size is:-->"
                            << Curr_BT << endl;
                }
            }
            else {
                Curr_BT = Curr_BT - Wo;
                cout << "Backoff Window Size is:-->"
                        << Curr_BT << endl;
            }
        }
        else {
            if (Curr_BT < Wm) {
                Curr_BT = Curr_BT * 2;
                cout << "Backoff Window Size is:-->"
                        << Curr_BT << endl;
            }
            else {
                cout << "Frame lost due to collision"
                        <<" or interference";
            }
            if (Curr_BT == Wn) {
                Curr_BT = Wn;
                cout << "Backoff Window Size is:-->"
                        << Curr_BT << endl
                            << endl;
            }
            else {
                Curr_BT = Curr_BT + Wo;
                cout << "Backoff Window Size is:-->"
                        << Curr_BT << endl;
            }
        }
    }
}
 
// Driver Code
int main()
{
    int Wm, Wo, Wn, Curr_BT;
    int array_ACK[5];
 
    Wo = 32; // Initial backoff window size
    Wn = 1024; // Maximum backoff window size
 
    // Curr_BT defines the current backoff window size
 
    cout << "Enter the Threshold value:-->";
    cin >> Wm; // Threshold backoff window size
    cout << "Enter the Current backoff window size:-->";
    cin >> Curr_BT;
    signal(array_ACK);
    Slow_Start_Backoff(Wm, Wo, Wn, Curr_BT, array_ACK);
 
    return 0;
}

How the data sent in the form of packets through the network:-
Any type of data gets converted into the binary formate and this binary format contains 0’s and 1’s bytes 
which gets divided into the small binary bit sequences called packets.
Now, we are implementing code in which the random matrix of 0’s and 1’s generates and suppose the binary file bit sequence arranged in the matrix row-wise in fixed-length (Taking a Length 10). Then each row of the matrix represents a single data packet that is going to be transmitted.
Implementation of the Random Matrix Generator:-
 

CPP




// C++ program to construct the
// Random Matrix Generator.
#include <iostream>
#include <iterator>
#include <list>
#include <random>
#include <string>
using namespace std;
 
void showlist(list<string> l1)
{
    list<string>::iterator it;
    cout << "list of frame packets are "
            <<"show as below :-> " << endl;
    cout << endl;
     
    for (it = l1.begin(); it != l1.end(); ++it)
        cout << *it << endl;
    cout << '\n';
}
 
// Driver Code
int main()
{
    int x, y, k = 1;
    string s, s1, s2;
     
    list<string> l1;
     
    srand(time_t(0));
     
    cout << "Rows: " << endl;
    cin >> x;
     
    cout << "Columns: " << endl;
    cin >> y;
     
    int randomNums[x][y];
    std::string temp[x];
     
    int random;
     
    for (int i = 0; i < x; i++) {
     
        // This loop is for the row
        for (int p = 0; p < y; p++) {
             
            // Here you would randomize each
            // element for the array.
            random = rand() % 2;
            randomNums[i][p] = random;
        }
    }
 
    for (int i = 0; i < x; i++) {
         
        // This loop is for the row
        for (int p = 0; p < y; p++) {
             
            // Here you would randomize each
            // element for the array.
            cout << randomNums[i][p] << "\t";
        }
         
        cout << endl;
    }
    cout << endl;
     
    // concatenation of the bits in the matrix row
    // to form a single data packet
    for (int i = 0; i < x; i++) {
         
        temp[i] = to_string(randomNums[i][0]);
         
        for (int j = 0; j < y; ++j) {
             
            s1 = temp[i];
            s2 = to_string(randomNums[i][j]);
 
            s = s1 + s2;
 
            temp[i] = s;
            k++;
        }
         
        temp[i].erase(temp[i].begin() + 1);
        l1.push_back(temp[i]);
    }
 
    showlist(l1);
    return 0;
}

Example: 
 

Input: 
Rows: 
10 
Columns: 
10 
Output: 
0 1 1 0 1 1 0 1 0 1 
0 0 0 0 0 0 1 1 0 0 
0 1 1 0 1 1 0 1 1 1 
0 1 0 0 0 0 1 0 0 0 
0 0 1 1 0 0 1 0 0 0 
0 0 0 0 1 0 1 1 1 0 
0 0 1 1 0 0 1 1 0 1 
1 1 0 0 1 1 0 0 0 1 
1 1 0 0 1 0 1 1 1 1 
0 1 0 1 1 0 0 1 1 1 
list of frame packets are show as below :-> 
0110110101 
0000001100 
0110110111 
0100001000 
0011001000 
0000101110 
0011001101 
1100110001 
1100101111 
0101100111 
 

Reference: Slow Start Backoff Algorithm for Ad-Hoc Wireless Networks
 

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.




My Personal Notes arrow_drop_up
Recommended Articles
Page :