您的位置:首页 > 理论基础 > 计算机网络

NS3网络仿真(13): FdNetDevice的问题

2015-08-18 21:27 246 查看
快乐虾http://blog.csdn.net/lights_joy/欢迎转载,但请保留作者信息

在前面的小节中,我们使用FdNetDevice进行了实时仿真,利用NS3向一台实际的机器发送ping包,但得到的结果显然有点偏离我们的预期结果,因为ping包的响应时间明显长于正常情况下的响应时间。

这个是用NS3发送ping包的结果:


使用WireShark在NS3使用的适配器上抓包,这个是在物理网卡上抓到的包:


显然对端的响应是没有问题的,莫非问题出现在winpcap的发送上?刚好学习ICMPv4时也遇到了这样的问题,一并解决它。在网上搜了一把,貌似问题出现在打开winpcap设备时指定的参数:

if ((adhandle = pcap_open_live(m_deviceName.c_str(),	// name of the device
		65536,			// portion of the packet to capture. 
		// 65536 grants that the whole packet will be captured on all the MACs.
		1,				// promiscuous mode (nonzero means promiscuous)
		1000,			// read timeout
		errbuf			// error buffer
		)) == NULL)
	{
		fprintf(stderr, "\nUnable to open the adapter. %s is not supported by WinPcap\n", m_deviceName.c_str());
		return -1;
	}

这里的read timeout值直接来源于winpcap的示例代码,查一下此参数的意义:

read_timeout,: read timeoutin milliseconds. The read timeout is used to arrange that the read notnecessarily return immediately when a packet is seen, but that it waits forsome amount of time to allow more packets to arrive and to read multiplepackets from the OS kernel in one operation. Not all platforms support a readtimeout; on platforms that don't, the read timeout is ignored.

将此值改为1。再执行仿真


这个结果好多了~~~,再改为-1试试:


更好的结果,只是此时的CPU使用率更高。


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: