Go Back N协议性能评估计算方法

Go Back N协议计算指南

一、性能参数说明


基于Go Back N协议仿真测试程序,可以通过分析下面的11个参数,从而评估协议性能。

我们以下面的日志记录进行说明:

  • 输入参数
----  Go-Back-N Network Simulator Version 1.1 -------- 

Enter the number of messages to simulate: 20
Enter  packet loss probability [enter 0.0 for no loss]:0.2
Enter packet corruption probability [0.0 for no corruption]:0
Enter average time between messages from sender's layer5 [ > 0.0]:5
Enter TRACE:2
  • Trace输出
EVENT time: 0.467849,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=1): aaaaaaaaaaaaaaaaaaaa
 send_window: send packet (seq=1): aaaaaaaaaaaaaaaaaaaa

EVENT time: 5.960295,  type: 2, fromlayer3  entity: 1
  B_input: recv packet (seq=1): aaaaaaaaaaaaaaaaaaaa
  B_input: send ACK (ack=1)

EVENT time: 8.038575,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=2): bbbbbbbbbbbbbbbbbbbb
 send_window: send packet (seq=2): bbbbbbbbbbbbbbbbbbbb

EVENT time: 8.459425,  type: 2, fromlayer3  entity: 0
  A_input: got ACK (ack=1)
Warning: attempt to start a timer that is already started
  A_input: timer + 80.000000

EVENT time: 9.439863,  type: 2, fromlayer3  entity: 1
  B_input: recv packet (seq=2): bbbbbbbbbbbbbbbbbbbb
  B_input: send ACK (ack=2)

EVENT time: 11.610156,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=3): cccccccccccccccccccc
 send_window: send packet (seq=3): cccccccccccccccccccc

EVENT time: 14.876553,  type: 2, fromlayer3  entity: 0
  A_input: got ACK (ack=2)
Warning: attempt to start a timer that is already started
  A_input: timer + 80.000000

EVENT time: 15.106326,  type: 2, fromlayer3  entity: 1
  B_input: recv packet (seq=3): cccccccccccccccccccc
  B_input: send ACK (ack=3)

EVENT time: 16.664021,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=4): dddddddddddddddddddd
 send_window: send packet (seq=4): dddddddddddddddddddd

EVENT time: 17.991364,  type: 2, fromlayer3  entity: 0
  A_input: got ACK (ack=3)
Warning: attempt to start a timer that is already started
  A_input: timer + 80.000000

EVENT time: 21.240454,  type: 2, fromlayer3  entity: 1
  B_input: recv packet (seq=4): dddddddddddddddddddd
  B_input: send ACK (ack=4)

EVENT time: 25.289467,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=5): eeeeeeeeeeeeeeeeeeee
 send_window: send packet (seq=5): eeeeeeeeeeeeeeeeeeee

EVENT time: 28.731649,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=6): ffffffffffffffffffff
 send_window: send packet (seq=6): ffffffffffffffffffff

EVENT time: 28.795433,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=7): gggggggggggggggggggg
 send_window: send packet (seq=7): gggggggggggggggggggg
          TOLAYER3: packet being lost

EVENT time: 29.269722,  type: 2, fromlayer3  entity: 0
  A_input: got ACK (ack=4)
Warning: attempt to start a timer that is already started
  A_input: timer + 80.000000

EVENT time: 30.850855,  type: 2, fromlayer3  entity: 1
  B_input: recv packet (seq=5): eeeeeeeeeeeeeeeeeeee
  B_input: send ACK (ack=5)

EVENT time: 31.855524,  type: 2, fromlayer3  entity: 0
  A_input: got ACK (ack=5)
Warning: attempt to start a timer that is already started
  A_input: timer + 80.000000

EVENT time: 32.483902,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=8): hhhhhhhhhhhhhhhhhhhh
 send_window: send packet (seq=8): hhhhhhhhhhhhhhhhhhhh

EVENT time: 36.460464,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=9): iiiiiiiiiiiiiiiiiiii
 send_window: send packet (seq=9): iiiiiiiiiiiiiiiiiiii
          TOLAYER3: packet being lost

EVENT time: 36.798424,  type: 2, fromlayer3  entity: 1
  B_input: recv packet (seq=6): ffffffffffffffffffff
  B_input: send ACK (ack=6)

EVENT time: 39.976803,  type: 2, fromlayer3  entity: 1
  B_input: not the expected seq. send NAK (ack=6)

EVENT time: 44.952938,  type: 2, fromlayer3  entity: 0
  A_input: got ACK (ack=6)
Warning: attempt to start a timer that is already started
  A_input: timer + 80.000000

EVENT time: 45.325787,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=10): jjjjjjjjjjjjjjjjjjjj
 send_window: send packet (seq=10): jjjjjjjjjjjjjjjjjjjj

EVENT time: 45.626087,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=11): kkkkkkkkkkkkkkkkkkkk
 send_window: send packet (seq=11): kkkkkkkkkkkkkkkkkkkk

EVENT time: 50.230320,  type: 2, fromlayer3  entity: 0
  A_input: got NAK (ack=6). drop.

EVENT time: 50.332897,  type: 2, fromlayer3  entity: 1
  B_input: not the expected seq. send NAK (ack=6)
          TOLAYER3: packet being lost

EVENT time: 53.431808,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=12): llllllllllllllllllll
 send_window: send packet (seq=12): llllllllllllllllllll

EVENT time: 54.884609,  type: 2, fromlayer3  entity: 1
  B_input: not the expected seq. send NAK (ack=6)

EVENT time: 56.689381,  type: 2, fromlayer3  entity: 1
  B_input: not the expected seq. send NAK (ack=6)

EVENT time: 59.354839,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=13): mmmmmmmmmmmmmmmmmmmm
 send_window: send packet (seq=13): mmmmmmmmmmmmmmmmmmmm
          TOLAYER3: packet being lost

EVENT time: 60.580311,  type: 2, fromlayer3  entity: 0
  A_input: got NAK (ack=6). drop.

EVENT time: 63.766899,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=14): nnnnnnnnnnnnnnnnnnnn
 send_window: send packet (seq=14): nnnnnnnnnnnnnnnnnnnn

EVENT time: 65.803215,  type: 2, fromlayer3  entity: 1
  B_input: not the expected seq. send NAK (ack=6)
          TOLAYER3: packet being lost

EVENT time: 68.434067,  type: 2, fromlayer3  entity: 0
  A_input: got NAK (ack=6). drop.

EVENT time: 71.390114,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=15): oooooooooooooooooooo
 send_window: send packet (seq=15): oooooooooooooooooooo

EVENT time: 72.517166,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=16): pppppppppppppppppppp
 send_window: send packet (seq=16): pppppppppppppppppppp

EVENT time: 72.550797,  type: 2, fromlayer3  entity: 1
  B_input: not the expected seq. send NAK (ack=6)
          TOLAYER3: packet being lost

EVENT time: 75.854424,  type: 2, fromlayer3  entity: 1
  B_input: not the expected seq. send NAK (ack=6)

EVENT time: 77.397987,  type: 2, fromlayer3  entity: 0
  A_input: got NAK (ack=6). drop.

EVENT time: 80.231331,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=17): qqqqqqqqqqqqqqqqqqqq
 send_window: send packet (seq=17): qqqqqqqqqqqqqqqqqqqq

EVENT time: 80.467850,  type: 0, timerinterrupt   entity: 0
  A_timerinterrupt: resend packet (seq=7): gggggggggggggggggggg
  A_timerinterrupt: resend packet (seq=8): hhhhhhhhhhhhhhhhhhhh
  A_timerinterrupt: resend packet (seq=9): iiiiiiiiiiiiiiiiiiii
  A_timerinterrupt: resend packet (seq=10): jjjjjjjjjjjjjjjjjjjj
  A_timerinterrupt: resend packet (seq=11): kkkkkkkkkkkkkkkkkkkk
  A_timerinterrupt: resend packet (seq=12): llllllllllllllllllll
  A_timerinterrupt: resend packet (seq=13): mmmmmmmmmmmmmmmmmmmm
  A_timerinterrupt: resend packet (seq=14): nnnnnnnnnnnnnnnnnnnn
  A_timerinterrupt: resend packet (seq=15): oooooooooooooooooooo
  A_timerinterrupt: resend packet (seq=16): pppppppppppppppppppp
  A_timerinterrupt: resend packet (seq=17): qqqqqqqqqqqqqqqqqqqq
  A_timerinterrupt: timer + 80.000000

EVENT time: 81.956238,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=18): rrrrrrrrrrrrrrrrrrrr
 send_window: send packet (seq=18): rrrrrrrrrrrrrrrrrrrr

EVENT time: 83.008820,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=19): ssssssssssssssssssss
 send_window: send packet (seq=19): ssssssssssssssssssss

EVENT time: 86.149239,  type: 2, fromlayer3  entity: 1
  B_input: not the expected seq. send NAK (ack=6)
          TOLAYER3: packet being lost

EVENT time: 90.211800,  type: 1, fromlayer5  entity: 0
  A_output: bufferred packet (seq=20): tttttttttttttttttttt
 send_window: send packet (seq=20): tttttttttttttttttttt

EVENT time: 93.544029,  type: 2, fromlayer3  entity: 1
 Simulator terminated at time 91.544029
 after sending 20 msgs from layer5

二、各性能参数计算方法

1. 接收端吞吐率


一共收到了20个packet,用时93.544029个time unit,因此 r = 20 / 91.544029 = 0.2184 ( p k t / t i m e _ u n i t ) r=20/91.544029=0.2184(pkt/time\_unit) r=20/91.544029=0.2184(pkt/time_unit)

2. 发送端超时重传次数


设置一个每重传一次就加1的全局变量即可。本次A_timerinterrupt共重传了1次。

3. 发送端超时packet个数


如下:

EVENT time: 80.467850,  type: 0, timerinterrupt   entity: 0
  A_timerinterrupt: resend packet (seq=7): gggggggggggggggggggg
  A_timerinterrupt: resend packet (seq=8): hhhhhhhhhhhhhhhhhhhh
  A_timerinterrupt: resend packet (seq=9): iiiiiiiiiiiiiiiiiiii
  A_timerinterrupt: resend packet (seq=10): jjjjjjjjjjjjjjjjjjjj
  A_timerinterrupt: resend packet (seq=11): kkkkkkkkkkkkkkkkkkkk
  A_timerinterrupt: resend packet (seq=12): llllllllllllllllllll
  A_timerinterrupt: resend packet (seq=13): mmmmmmmmmmmmmmmmmmmm
  A_timerinterrupt: resend packet (seq=14): nnnnnnnnnnnnnnnnnnnn
  A_timerinterrupt: resend packet (seq=15): oooooooooooooooooooo
  A_timerinterrupt: resend packet (seq=16): pppppppppppppppppppp
  A_timerinterrupt: resend packet (seq=17): qqqqqqqqqqqqqqqqqqqq

因此重传了6个packet,N_pkt_retran=6。

4. 正确接收packet数


观察函数B_input代码,可知当打印下列语句时则为正确接收数据包:

printf("  B_input: recv packet (seq=%d): ", packet.seqnum);

设置一个全局变量,每打印一次加1即可。本次共接收按序packet共计6次。

5. 乱序接收packet数


观察函数B_input代码,可知当打印下列语句时则为正确接收数据包:

printf("  B_input: not the expected seq. send NAK (ack=%d)\n", packet_to_send.acknum);

设置一个全局变量,每打印一次加1即可。本次共接收乱序packet共计8次。

6. 接收packet总数


顺序加乱序的packet求和,N_pkt_total=14(然而,这只是输出的)

7. 发送端Layer5丢包数量


观察A_output函数,当打印下列语句时,说明buffer已满,不能发送数据:

printf("  A_output: buffer full. drop the message: %s\n", data);

设置一个全局变量,每打印一次加1即可。本次没有这样的丢包。

8. 链路丢包数量


A端输出TOLAYER3: packet being lost的次数,共3次。

9. 仿真结束时缓冲区剩余packet


修改代码如下:

terminate:{
   float bufremain;
   bufremain=buffer_next % BUF_SIZE;
   printf("%f\n",bufremain);
   printf(" Simulator terminated at time %f\n after sending %d msgs from layer5\n",time,nsim);

}

即可输出缓冲区余量。

10. 仿真结束时发送剩余packet


在terminate中添加如下代码:

   sndremain=(nextseq-base)%window_size-1;
   printf(" Sender Remains: %f pkts\n",sndremain);

即可输出发送端数据包余量。

11. 发送端缓冲区长度


根据代码来看,全局变量BUFSIZE值为64,代表64pkts。

三、说明

由于本人水平有限,上述说明仅供参考

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,以下是一个简单的 C++ 程序,用于模拟实现 Go-back-N 协议: ```c++ #include <iostream> #include <vector> using namespace std; // 数据包结构体 struct Packet { int seq; // 序号 string data; // 数据 }; // 发送方发送数据 void sender(vector<Packet>& packets, int window_size, int timeout) { int next_seq = 0; // 下一个要发送的序号 int base = 0; // 窗口起始位置 int unacked = 0; // 已发送但未确认的数据包数量 // 模拟循环发送数据包 while (true) { // 发送窗口内的未确认数据包 while (unacked < window_size && next_seq < packets.size()) { cout << "发送数据包 " << next_seq << endl; // 模拟发送数据包 // send_packet(packets[next_seq]); next_seq++; unacked++; } // 等待确认或超时 // receive_ack(timeout); // 检查是否有确认 if (unacked > 0) { cout << "等待确认..." << endl; // 模拟接收确认 bool received_ack = true; if (received_ack) { cout << "接收到确认 " << base << endl; base++; unacked--; } else { cout << "未接收到确认,超时重传" << endl; next_seq = base; unacked = 0; } } // 检查是否已发送完毕 if (base == packets.size()) { break; } } } // 接收方接收数据 void receiver(vector<Packet>& packets, int window_size, int timeout) { int expected_seq = 0; // 期望接收的序号 int base = 0; // 窗口起始位置 // 模拟循环接收数据包 while (true) { // 模拟接收数据包 Packet packet; // 接收到的数据包 // receive_packet(packet); // 如果接收到的数据包的序号等于期望接收的序号 if (packet.seq == expected_seq) { cout << "接收到数据包 " << expected_seq << ",并发送确认" << endl; // 模拟发送确认 // send_ack(expected_seq); expected_seq++; base++; // 将窗口向前滑动,以便接收更多数据包 while (packets[base].seq < expected_seq && base < packets.size()) { base++; } } else { cout << "接收到数据包 " << packet.seq << ",但不是期望接收的序号" << endl; // 模拟发送确认 // send_ack(expected_seq - 1); } // 检查是否已接收完毕 if (base == packets.size()) { break; } } } int main() { // 创建数据包 vector<Packet> packets; packets.push_back({0, "Hello"}); packets.push_back({1, "World"}); packets.push_back({2, "Go-back-N"}); packets.push_back({3, "Protocol"}); packets.push_back({4, "Simulation"}); packets.push_back({5, "Example"}); // 设置窗口大小和超时时间 int window_size = 3; int timeout = 500; // 启动发送方和接收方 sender(packets, window_size, timeout); receiver(packets, window_size, timeout); return 0; } ``` 上述程序实现了一个简单的 Go-back-N 协议模拟。在程序中,发送方和接收方都使用了一个循环来模拟数据包的发送和接收过程。在发送过程中,发送方会根据窗口大小和超时时间来控制发送的数据包数量,并等待接收到确认或超时后重传。在接收过程中,接收方会等待接收到数据包后发送确认,并将窗口向前滑动以便接收更多的数据包。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值