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

查看:367
本文介绍了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数据包丢失的可能性有多大 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?

迟早一个数据包将被丢弃的可能性为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.

是否需要重新发送方法?

Is it even neccessary to have a resend method?

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

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!\n");
}
else
{ 
    // handle the incoming packet as usual
}

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

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