📜  Ad Hoc网络中公平信道访问的增强二进制指数退避算法。

📅  最后修改于: 2021-08-24 16:32:17             🧑  作者: Mango

二进制指数退避算法通过随机化尝试访问无线信道的站点的矩来防止在同时访问期间发生数据包冲突。但是,这种随机化不能完全消除数据包冲突,从而导致系统吞吐量降低,数据包延迟和丢弃增加。此外, BEB算法还会导致站点之间的信道访问不公平。

移动Ad hoc网络是一组无线节点,可以动态地将它们自己布置为任意和临时的拓扑,而无需预先存在的基础结构即可形成网络。节点在通信时可能会动态移动,并使该节点无法计算。该节点可以轻松离开拓扑网络。

通常,此网络用于没有集中式网络基础结构管理或支持的紧急操作环境控制军事应用之类的应用中,例如路由器或基站。在IEEE 802.11标准中,分布式协调函数(DCF)算法是一种高效且基本的算法,可确保MANET与不断发展的拓扑挑战保持最佳兼容性。基于避免冲突的载波侦听多路访问(CSMA / CA)协议,DCF共享对媒体的访问,遵循“先讲话后听”的基本原理。在DCF中使用BEB算法。碰撞,节点希望重传等待这被称为回退时间的一个随机时间。在此,具有较小BT的节点将首先访问相对于具有较高BT的节点的介质。

分布式协调函数

此函数用于防止使用CSMA / CA和RTS / CTS确认帧的冲突。在发送时,发送方等待DIFS(分布式协调函数帧间间隔)时间。如果信道空闲,则发送数据帧,即RTS ACK帧,而接收方等待SIFS(短帧间间隔)时间,然后将CTS帧接收发送给发送方。如果信道繁忙,则站将等待该信道,直到感觉到空闲了DIFS时间为止。此时,它会生成随机BT来发送数据帧。

二进制指数退避算法

成功传输数据后,将调用函数CW()将CW调整为CWmin。在数据冲突期间,节点调用函数Double CW()将CW加倍,直到等于或大于CWmax。

如果节点尝试发送数据失败七次,则还会调用函数CW()来将CW调整为CWmin,因为数据包延迟和丢包增加还降低了数据帧重传的可能性。同样,出现公平问题。

公平问题

如果假定的节点A的退避时间比节点B短,则节点A将首先达到零并将竞争窗口重置为最小值,因此,第一个节点进行传输的可能性更高,一次又一次地传输其节点。

考虑文件“ aaa.txt” 。在此文件中,生成01s 。在这里, 0表示不成功,而1表示成功。下面是文本文件:

下面是上述方法的实现:

C
// C program for the above approach
#include 
#include 
#include 
#include 
  
// Driver Code
int main()
{
    // Slot time
    float slot_time = 0.00000166;
  
    int CWmin = 32, CWmax = 1024;
  
    int k;
    int i, Curr_BW = 32, counter = 0;
    float BT, Total_Backoff_time = 0;
  
    FILE* fp;
    char* f_name = "aaa.txt";
    char ch;
    int x = 0, y = 0;
  
    fp = fopen(f_name, "r+");
  
    // Open File
    if (fp == NULL) {
        printf("%s does not exists"
               " \n",
               f_name);
        return 0;
    }
  
    // Otherwise
    else {
        printf("%s: opened in read"
               " mode.\n\n",
               f_name);
    }
  
    // Read characters from the file
    while ((ch = fgetc(fp)) != EOF) {
  
        // End-of-file is reached
        if (ch == '1' || ch == '0') {
            printf("frame %c \n ", ch);
        }
  
        // If the character is 1
        if (ch == '1') {
  
            x = x + 1;
            printf("successful "
                   "Transmission\n");
            Curr_BW = CWmin;
            printf("the current "
                   "window is : %d\n",
                   Curr_BW);
  
            BT = Curr_BW * slot_time;
            printf(" =>the backoff"
                   " time is : %0.8f"
                   " \n",
                   BT);
  
            counter = 0;
        }
  
        // If the character is 0
        else if (ch == '0') {
  
            y = y + 1;
            if (counter < 7) {
  
                printf("UNsuccessful "
                       "Transmission\n");
  
                Curr_BW = Curr_BW * 2;
  
                if (Curr_BW > CWmax) {
  
                    Curr_BW = CWmax;
                }
                printf("the current "
                       "window is :"
                       " %d\n",
                       Curr_BW);
  
                counter = counter + 1;
                printf("counter is  :"
                       " %d \n ",
                       counter);
  
                BT = Curr_BW * slot_time;
  
                printf(" =>the backoff"
                       " time is : %0.8f"
                       " \n",
                       BT);
            }
  
            // Otherwise
            else {
  
                Curr_BW = CWmin;
                printf("the current"
                       " window is :"
                       " %d\n",
                       Curr_BW);
  
                BT = Curr_BW * slot_time;
                printf(" =>the backoff"
                       " time is : %0.8f"
                       " \n",
                       BT);
            }
        }
  
        if (ch == '1' || ch == '0') {
  
            // Find the Backoff Time
            Total_Backoff_time = Total_Backoff_time + BT;
  
            printf("\n");
  
            // Print the time
            printf("=>  Total Back_off"
                   " time for frame is : "
                   " %0.8f \n ",
                   Total_Backoff_time);
            printf("\n\n");
        }
    }
  
    // Print the success and
    // unsuccess number
    printf(" success num : %d\n", x);
    printf(" unsuccess num : %d\n", y);
  
    return 0;
}


C
// C program for the above approach
  
#include 
#include 
#include 
#include 
  
// Driver Code
int main()
  
{
    int C = 12, D = 4, E = 8;
  
    int counter = 0;
  
    // Slot time
    double slot_time = 0.00000166,
           CW;
    int CWmax = 1024, CWmin = 32;
    double BT, G,
        Total_Backoff_time = 0;
  
    // C => successful sending times
    // D => Quickly decrease the the CW
    // E => linearly inc the CW
    // G => Threshold quantity
    // CW => Minimun Contention Window Size
    // BT => Backoff time
  
    // Enter the current BW
    printf("Enter the Curr_BW (CW)"
           " by user  :  ");
    scanf("%lf", &CW);
  
    FILE* fp;
    char* f_name = "aaa.txt";
    char ch;
  
    // Open the file
    fp = fopen(f_name, "r+");
  
    // If file doesn't exists
    if (fp == NULL) {
        printf("%s does not exists"
               " \n",
               f_name);
        return 0;
    }
  
    // Otherwise
    else {
        printf("%s: opened in read"
               " mode.\n\n",
               f_name);
    }
  
    // Read character by characters
    while ((ch = fgetc(fp)) != EOF) {
  
        // End-of-file
        if (ch == '0' || ch == '1') {
            printf("frame %c \n ", ch);
        }
  
        if (ch == '1' || ch == '0') {
  
            if (counter < C) {
  
                // Print the counter
                // value
                counter = counter + 1;
                printf("counter value"
                       " is : %d\n ",
                       counter);
  
                CW = CW / D;
                printf(" The CW is :"
                       " %0.8f\n",
                       CW);
  
                G = 0.125 * CW;
                printf("Value of G "
                       "[Threshold Quantity]"
                       " is : %0.8f\n",
                       G);
  
                if (CW < G) {
                    CW = G;
                    BT = CW * slot_time;
                    printf(
                        " => The"
                        " Backoff Time"
                        " is : %0.8f\n",
                        BT);
                }
                else {
                    BT = CW * slot_time;
                    printf(
                        " => The "
                        "Backoff Time"
                        " is : %0.8f\n",
                        BT);
                }
            }
            else {
                counter = 1;
                CW = CW + (E * CWmin);
  
                printf(" The CW is :"
                       " %lf\n",
                       CW);
  
                if (CW > CWmax) {
                    CW = CWmax;
  
                    BT = CW * slot_time;
                    printf(
                        " => The "
                        "Backoff Time"
                        " is : %0.8f\n",
                        BT);
                }
                else {
  
                    BT = CW * slot_time;
                    printf(
                        " => The "
                        "Backoff Time"
                        " is : %0.8f\n",
                        BT);
                }
            }
        }
  
        if (ch == '1' || ch == '0') {
  
            // Find the Backoff time
            Total_Backoff_time = Total_Backoff_time + BT;
  
            printf("\n");
  
            // Print the Back Off Time
            printf("=>  Total Back_off"
                   " time for frame is : "
                   " %0.8f \n ",
                   Total_Backoff_time);
            printf("\n\n");
        }
    }
}


输入文件:

1010011000100011

输出:

改进和改进的二进制指数退避算法

该算法(在本文中也称为I-BEB)旨在解决节点之间的公平性问题,同时传输到点并与BEB相比降低分组延迟。

第十二成功传输后,计数器设置为1 ,竞争窗口呈指数增长。但是,I-BEB并不能解决很多公平问题。在此算法中,使用阈值是因为可能会出现这样的情况,即活动站点的数量会增加,并且会增加发生冲突的机会。当CW小于阈值时,它将其竞争窗口大小等于阈值,以增加成功传输的可能性

下面是上述方法的实现:

C

// C program for the above approach
  
#include 
#include 
#include 
#include 
  
// Driver Code
int main()
  
{
    int C = 12, D = 4, E = 8;
  
    int counter = 0;
  
    // Slot time
    double slot_time = 0.00000166,
           CW;
    int CWmax = 1024, CWmin = 32;
    double BT, G,
        Total_Backoff_time = 0;
  
    // C => successful sending times
    // D => Quickly decrease the the CW
    // E => linearly inc the CW
    // G => Threshold quantity
    // CW => Minimun Contention Window Size
    // BT => Backoff time
  
    // Enter the current BW
    printf("Enter the Curr_BW (CW)"
           " by user  :  ");
    scanf("%lf", &CW);
  
    FILE* fp;
    char* f_name = "aaa.txt";
    char ch;
  
    // Open the file
    fp = fopen(f_name, "r+");
  
    // If file doesn't exists
    if (fp == NULL) {
        printf("%s does not exists"
               " \n",
               f_name);
        return 0;
    }
  
    // Otherwise
    else {
        printf("%s: opened in read"
               " mode.\n\n",
               f_name);
    }
  
    // Read character by characters
    while ((ch = fgetc(fp)) != EOF) {
  
        // End-of-file
        if (ch == '0' || ch == '1') {
            printf("frame %c \n ", ch);
        }
  
        if (ch == '1' || ch == '0') {
  
            if (counter < C) {
  
                // Print the counter
                // value
                counter = counter + 1;
                printf("counter value"
                       " is : %d\n ",
                       counter);
  
                CW = CW / D;
                printf(" The CW is :"
                       " %0.8f\n",
                       CW);
  
                G = 0.125 * CW;
                printf("Value of G "
                       "[Threshold Quantity]"
                       " is : %0.8f\n",
                       G);
  
                if (CW < G) {
                    CW = G;
                    BT = CW * slot_time;
                    printf(
                        " => The"
                        " Backoff Time"
                        " is : %0.8f\n",
                        BT);
                }
                else {
                    BT = CW * slot_time;
                    printf(
                        " => The "
                        "Backoff Time"
                        " is : %0.8f\n",
                        BT);
                }
            }
            else {
                counter = 1;
                CW = CW + (E * CWmin);
  
                printf(" The CW is :"
                       " %lf\n",
                       CW);
  
                if (CW > CWmax) {
                    CW = CWmax;
  
                    BT = CW * slot_time;
                    printf(
                        " => The "
                        "Backoff Time"
                        " is : %0.8f\n",
                        BT);
                }
                else {
  
                    BT = CW * slot_time;
                    printf(
                        " => The "
                        "Backoff Time"
                        " is : %0.8f\n",
                        BT);
                }
            }
        }
  
        if (ch == '1' || ch == '0') {
  
            // Find the Backoff time
            Total_Backoff_time = Total_Backoff_time + BT;
  
            printf("\n");
  
            // Print the Back Off Time
            printf("=>  Total Back_off"
                   " time for frame is : "
                   " %0.8f \n ",
                   Total_Backoff_time);
            printf("\n\n");
        }
    }
}

输入文件:

1010011000100011

输出: