如果接收器宣称有一个大的窗口大小,大于网络途中可以管理的大小,那么总会有数据包丢失。因此也会有重新传输。但是,发送方无法发送尚未收到ACK(确认)的所有数据包。由于这种方式,将在网络中引起更多的拥塞。而且,发送者不能确定由于传输而丢失的分组。可能这是唯一丢失的数据包。也将不知道接收器实际已经接收和缓冲了多少个分组。在这种情况下,发送方将多余地发送各种数据包。
因此,数据包的重传也遵循缓慢的–启动退避机制。但是,我们确实需要在缓慢启动时增加数据包大小的上限,以防止数据包无限制增长并导致拥塞。慢速启动机制
阈值窗口大小是拥塞窗口大小的一半。
先决条件: CSMA / CD的退避算法
慢启动机制算法:-
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
例子:
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
表示法:-
W0 --> Initial backoff window size
Wm --> Threshold
Wn --> Maximum backoff window size
ACK --> Acknowledgement
Curr_BT --> Current backoff window size
慢启动机制的实现:
CPP
#include
#include
#include
#include
#include
#include
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;
}
CPP
// C++ program to construct the
// Random Matrix Generator.
#include
#include
#include
#include
#include
using namespace std;
void showlist(list l1)
{
list::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 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;
}
数据如何以分组形式通过网络发送:-
任何类型的数据都将转换为二进制格式,并且此二进制格式包含0和1的字节
它被分成一些小的二进制位序列,称为数据包。
现在,我们正在实现其中生成0和1的随机矩阵的代码,并假设二进制文件位序列以固定长度(以长度10计)按行排列。然后,矩阵的每一行代表将要发送的单个数据包。
随机矩阵生成器的实现:
CPP
// C++ program to construct the
// Random Matrix Generator.
#include
#include
#include
#include
#include
using namespace std;
void showlist(list l1)
{
list::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 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;
}
例子:
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
参考: Ad-Hoc无线网络的慢速启动退避算法