[转载] ACE 组播校验和出错问题解决

源地址:http://yuanmuqiuyu2000.blog.sohu.com/140904942.html

 

使用ACE框架写了个组播简单的测试工具,但是测试过程中,总是发现udp校验和出错的信息。代码如下:

#include "ace/SOCK_Dgram_Mcast.h"
#include "ace/Log_Msg.h"

int main()
{
        ACE_SOCK_Dgram_Mcast mcast;
        ACE_INET_Addr        srv_addr("224.0.0.9:520");

        if (mcast.open(srv_addr, "eth0", 1) == -1)
        {
                ACE_ERROR_RETURN((LM_ERROR, "%p"), -1);
        }

        mcast.join(srv_addr);

        // 进行RIP2协议测试

        char peer0_2[] = {
0x02, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
0xc0, 0xa8, 0x6f, 0x00, 0xff, 0xff, 0xff, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00,
0xc0, 0xa8, 0x03, 0x00, 0xff, 0xff, 0xff, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 };

        while(1)
        {
                if (mcast.send(peer0_2,sizeof(peer0_2)) == -1)
                {
                        ACE_ERROR_RETURN((LM_ERROR, "%p"), -1);
                }

                ACE_OS::sleep(5);
        }


        return 0;
}

使用wireshark抓包分析校验和出错:

Checksum: 0xa3ae [incorrect, should be 0x84dd (maybe caused by "UDP checksum offload"?)]   

 

问题根源为网卡设置上除了问题:

#ethtool -k eth0

# ethtool -k  eth0
Offload parameters for eth0:
rx-checksumming: on
tx-checksumming: off

scatter-gather: on
tcp segmentation offload: on 

 

全部关闭方法:

#ethtool -K  eth0 rx off           #K为大写

#ethtool -K eth0 tx off

#ethtool -K eth0 sg off

#ethool -K eth0 tso off

 

# ethtool -k  eth0
Offload parameters for eth0:
rx-checksumming: off
tx-checksumming: off
scatter-gather: off

tcp segmentation offload: off

问题解决!

 

另外ethtool还可以设置网卡的自适应速率等参数,前不久就遇到过一个很奇怪的事情,交换机和主机进行连接的时候,中间加上一个HUB就可以实现正常通信,但是两者直接直接连接通信不正常,丢包现象严重。最后查找出问题根源为两个设备的网口都为1000M自适应的,由于中间某个设备的网卡在1000M状态下的驱动程序有问题,导致收报的时候出错,从而出现丢包严重。但是中间加入HUB后,设备都与HUB进行协商,从而使设备的网卡速率都下降为了100M,能正常通信。

 

使用ethtool可以方便地来查看网卡的状态,速率等诸多信息:

#ethtool eth0
Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Half 1000baseT/Full 
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Half 1000baseT/Full 
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: g
        Wake-on: g
        Current message level: 0x000000ff (255)
        Link detected: yes

 

可以通过命令来设置网卡速率自协商等选项     

ethtool -s DEVNAME \
                [ speed 10|100|1000 ] \
                [ duplex half|full ]    \
                [ port tp|aui|bnc|mii|fibre ] \
                [ autoneg on|off ] \
                [ phyad %d ] \
                [ xcvr internal|external ] \
                [ wol p|u|m|b|a|g|s|d... ] \
                [ sopass %x:%x:%x:%x:%x:%x ] \
                [ msglvl %d ]

 

 

oute add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

posted @ 2013-06-22 10:34  icemoon1987  阅读(514)  评论(0编辑  收藏  举报