使用多个NIC广播的UDP数据包 [英] Broadcasting UDP packets using multiple NICs

查看:132
本文介绍了使用多个NIC广播的UDP数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个嵌入式系统在Linux中的摄像机控制器(非实时)。我在获得网络做我想做的事情的一个问题。该系统有3个网卡,1个100BASE-T和2个千兆端口。我钩慢一上来为摄像机(这是所有支持)和更快的是点对点连接到其他机器。我所试图做的是从摄像机获取图像,做了一点处理,然后使用UDP其他每个网卡的播放。

I'm building an embedded system for a camera controller in Linux (not real-time). I'm having a problem getting the networking to do what I want it to do. The system has 3 NICs, 1 100base-T and 2 gigabit ports. I hook the slower one up to the camera (that's all it supports) and the faster ones are point-to-point connections to other machines. What I am attempting to do is get an image from the camera, do a little processing, then broadcast it using UDP to each of the other NICs.

下面是我的网络配置:

为eth0:地址:192.168.1.200 BCAST 192.168.1.255子网掩码:255.255.255.0(这是100BASE-T)结果
eth1的:地址:192.168.2.100 BCAST 192.168.2.255子网掩码:255.255.255.0结果
ETH2:地址:192.168.3.100 BCAST 192.168.3.255子网掩码:255.255.255.0

eth0: addr: 192.168.1.200 Bcast 192.168.1.255 Mask: 255.255.255.0 (this is the 100base-t)
eth1: addr: 192.168.2.100 Bcast 192.168.2.255 Mask: 255.255.255.0
eth2: addr: 192.168.3.100 Bcast 192.168.3.255 Mask: 255.255.255.0

图片即将在关将私有协议的eth0的,所以这是一个原始套接字。我可以播出的eth1或eth2上就好了。但是,当我尝试其他后它们传播到两个,一个,我得到很多的eth0网络打嗝的和错误的。

The image is coming in off eth0 in a proprietary protocol, so it's a raw socket. I can broadcast it to eth1 or eth2 just fine. But when I try to broadcast it to both, one after the other, I get lots of network hiccups and errors on eth0.

我初始化UDP套接字是这样的:

I initialize the UDP sockets like this:

sock2=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); // Or sock3
sa.sin_family=AF_INET;
sa.sin_port=htons(8000);
inet_aton("192.168.2.255",&sa.sin_addr); // Or 192.168.3.255
setsockopt(sock2, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast));
bind(sock2,(sockaddr*)&sa,sizeof(sa));

sendto(sock2,&data,sizeof(data),0,(sockaddr*)&sa,sizeof(sa)); // sizeof(data)<1100 bytes

我这样做对每个插槽分开,并分别致电SENDTO。当我做一个或另一个,它的罚款。当我尝试的同时发送,为et​​h0开始变得糟糕的数据包。

I do this for each socket separately, and call sendto separately. When I do one or the other, it's fine. When I try to send on both, eth0 starts getting bad packets.

这是为什么发生这种情况的任何想法?它是一个配置错误,有没有更好的方法来做到这一点?

Any ideas on why this is happening? Is it a configuration error, is there a better way to do this?

编辑:
感谢所有帮助,我一直在尝试一些事情,展望于此。这个问题似乎没有被广播,严格说来。我取代了广播code与单播的命令,它具有相同的行为。我想我明白的行为更好,但不知道如何解决它。

Thanks for all the help, I've been trying some things and looking into this more. The issue does not appear to be broadcasting, strictly speaking. I replaced the broadcast code with a unicast command and it has the same behavior. I think I understand the behavior better, but not how to fix it.

下面是发生了什么。在eth0我应该得到的图像每隔50ms。当我在eth1发出的图像(或2)需要大约1.5ms的发送图像。当我尝试它需要大约45ms,同时在两个及ETH1 ETH2发,偶尔跳跃到90毫秒。当这超出了50ms的窗口,为eth0的缓冲区开始建立。我失去了包时的缓冲区满,当然。

Here is what is happening. On eth0 I am supposed to get an image every 50ms. When I send out an image on eth1 (or 2) it takes about 1.5ms to send the image. When I try to send on both eth1 and eth2 at the same time it takes about 45ms, occasionally jumping to 90ms. When this goes beyond the 50ms window, eth0's buffer starts to build. I lose packets when the buffer gets full, of course.

所以我的修订问题。为什么会从1.5毫秒到45ms去只是通过一个以太网端口将两个?

So my revised question. Why would it go from 1.5ms to 45ms just by going from one ethernet port to two?

下面是我的初始code:

Here is my initialization code:

sock[i]=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
sa[i].sin_family=AF_INET;
sa[i].sin_port=htons(8000);
inet_aton(ip,&sa[i].sin_addr);

//If Broadcasting
char buffer[]="eth1" // or eth2
setsockopt(sock[i],SOL_SOCKET,SO_BINDTODEVICE,buffer,5);
int b=1;
setsockopt(sock[i],SOL_SOCKET,SO_BROADCAST,&b,sizeof(b));

下面是我送code:

for(i=0;i<65;i++) {
  sendto(sock[0],&data[i],sizeof(data),0,sa[0],sizeof(sa[0]));
  sendto(sock[1],&data[i],sizeof(data),0,sa[1],sizeof(sa[1]));
}

这是pretty基础。

It's pretty basic.

任何想法?感谢您的所有伟大的帮助!

Any ideas? Thanks for all your great help!

推荐答案

这是一个很长的时间,但我找到了答案,我的问题,所以我想我会把这里的情况下,任何人都曾经发现它。

It's been a long time, but I found the answer to my question, so I thought I would put it here in case anyone else ever finds it.

两个千兆以太网端口实际上是在PCI桥断PCI-EX preSS总线。在PCI-EX preSS总线是内部的主板,但它是一个PCI总线要去卡。桥和总线没有足够的带宽,实际送出的图像,快速。如果只有一个网卡使数据被发送到缓冲区,它看起来非常快给我,但花了更长的时间实际上得到通过总线,出牌,就到了电线。第二个NIC是慢,因为缓冲区已满。尽管更改缓冲区大小掩盖了问题,它实际上并没有发送数据的任何速度更快,我仍然在第三个NIC越来越丢弃的数据包。

The two Gigabit Ethernet ports were actually on a PCI bridge off the PCI-express bus. The PCI-express bus was internal to the motherboard, but it was a PCI bus going to the cards. The bridge and the bus did not have enough bandwidth to actually send out the images that fast. With only one NIC enabled the data was sent to the buffer and it looked very quick to me, but it took much longer to actually get through the bus, out the card, and on to the wire. The second NIC was slower because the buffer was full. Although changing the buffer size masked the problem, it did not actually send the data out any faster and I was still getting dropped packets on the third NIC.

在结束时,100Base-T的卡实际上是建在主板上,因此有一个更快的总线到它,导致比千兆端口整体更快带宽..通过将照相机切换到千兆位线和一个千兆线路的100Base-T的线,我能够满足要求。

In the end, the 100Base-T card was actually built onto the motherboard, therefore had a faster bus to it, resulting in overall faster bandwidth than the gigabit ports.. By switching the camera to a gigabit line and one of the gigabit lines to the 100Base-T line I was able to meet the requirements.

奇怪的。

这篇关于使用多个NIC广播的UDP数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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