UDP丢包模拟&可能性 [英] UDP Packet loss simulation & probability

查看:28
本文介绍了UDP丢包模拟&可能性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建一个与多个 arduino 板通信的服务器软件.由于硬件原因,我使用的是 UDP 协议.我有一个非常简单的机制,可以在大多数情况下在包裹丢失时重新发送包裹.我现在有两个问题:

I am currently creating a server software that communicates with multiple arduino boards. Due to the hardware, I am using the UDP Protocol. I have a pretty simple mechanism that will resend packages in most of the cases when they get lost. I have two questions now:

UDP 数据包在没有 Internet 访问、大约 20 个 arduino 和一台计算机的网络中丢失的可能性有多大?是否还需要重新发送方法?

How probable is it that UDP Packets get lost in a Network with no Internet access and about 20 arduinos and one computer? Is it even neccessary to have a resend method?

有没有一种方法可以模拟此网络中的 UDP 数据包丢失,以检查重新发送机制是否正常工作?

Is there a way I can simulate UDP Packet loss in this network to check if the resend mechanisms are working?

推荐答案

UDP 数据包在网络中丢失的可能性有多大?互联网接入和大约 20 个 arduino 和一台计算机?

How probable is it that UDP Packets get lost in a Network with no Internet access and about 20 arduinos and one computer?

数据包迟早会被丢弃的概率是 100%.

The probability is 100% that sooner or later a packet will be dropped.

如果您想要更详细的统计数据,例如数据包在任何特定时间段内被丢弃的概率,唯一真正知道的方法是尝试并找出答案(例如使用数据包中的序列号,以便接收者可以通过记录跳过的序列号来检测数据包何时被丢弃).概率很大程度上取决于数据包的大小、发送数据包的速度、接收器的 CPU 速度、接收器花费 CPU 时间执行的其他任务、以太网交换机的质量、质量您的以太网电缆、月相等.

If you want a more detailed statistic, like the probability of a packet being dropped within any particular period of time, the only real way to know is to try it and found out (using e.g. sequence numbers in the packets so that the receiver(s) can detect when a packet has been dropped by noting the skipped sequence-number). The probability will depend very much on the size of the packets, the speed at which the packets are being sent, the CPU speed of the receivers, what other tasks the receivers are spending CPU time on, the quality of your Ethernet switch, the quality of your Ethernet cables, the phase of the moon, etc etc.

是否需要重发方法?

这取决于丢包的后果.对于某些应用程序(例如流式音频或视频,或音频计量数据),丢弃数据包没什么大不了的;您只是忽略了一些数据丢失的事实,并像往常一样继续处理下一个数据包.对于其他应用程序(例如文件传输/接收),数据包的丢失意味着接收器需要的数据丢失,因此您需要有一些方法可以从丢失中恢复,例如通过检测它并触发重新发送,否则整个传输将失败(或者至少接收器最终只会得到部分文件).

That depends on what the consequences would be to having a packet dropped. For some applications (e.g. streaming audio or video, or audio-metering data), dropping a packet is no big deal; you just ignore the fact that some data was lost, and continue on with the next packet as usual. For other applications (e.g. file transmit/receive), the loss of a packet means the loss of data that the receiver needs, so you'll want to have some way to recover from that loss, e.g. by detecting it and triggering a resend, or else the entire transfer will fail (or at least the receiver will end up with only a partial file).

有没有办法可以模拟这个网络中的 UDP 数据包丢失来检查重发机制是否有效?

Is there a way I can simulate UDP Packet loss in this network to check if the resend mechanisms are working?

当然,只需在接收器中添加一些逻辑,以便它们偶尔假装没有收到数据包:

Sure, just put some logic into the receivers so that they occasionally pretend to not have received a packet:

int numBytesReceived = recv(...);
if ((rand()%100) == 0)   // Simulate a 1% packet loss rate
{
    printf("Pretending to have dropped a packet!
");
}
else
{ 
    // handle the incoming packet as usual
}

这篇关于UDP丢包模拟&可能性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆