NS-3 WLAN网TCP不工作,而UDP(ns-3 wlan grid TCP not worki

2019-09-18 20:46发布

我想建立一个多跳的AdHoc 802.11g标准的网络在NS-3。
要开始我使用的示例“wifi-simple-adhoc-grid.cc”。

本例使用UDP,但我想用TCP。 因此,我切换

TypeId tid = ns3::UdpSocketFactory::GetTypeId();
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (sinkNode), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));

TypeId tid = ns3::TcpSocketFactory::GetTypeId();
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (sinkNode), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));

Ptr<Socket> source = Socket::CreateSocket (c.Get (sourceNode), tid);
InetSocketAddress remote = InetSocketAddress (i.GetAddress (sinkNode, 0), 80);

发送数据包是没有问题的,但ReceivePacket不会被调用,这意味着,插座灌不接收数据包。

整个代码: https://gist.github.com/3023757

路线输出方式:

Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> 
("wifi-multihop.routes", std::ios::out)

Answer 1:

您可以拨打SetRevCallback功能时,您SetAcceptCallback功能。

明确地说,

recvSink->SetAcceptCallback (MakeNullCallback<bool, Ptr<Socket>,const Address &> (),MakeCallback(&accept));

在接受功能

void accept(Ptr<Socket> socket,const ns3::Address& from)
{

    std::cout<<"Connection accepted"<< std::endl;
    socket->SetRecvCallback (MakeCallback (&ReceivePacket));

}


文章来源: ns-3 wlan grid TCP not working while UDP is