ns-3 wlan grid TCP not working while UDP is

2019-05-27 08:44发布

I am trying to set up a Multihop AdHoc 802.11g Network in ns-3.
To get started I used the example 'wifi-simple-adhoc-grid.cc'.

The example uses UDP, but I want to use TCP. Therefore I switched

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));

to

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);

Sending Packets is no Problem, but ReceivePacket is never called, which means, that socket Sink receives no packets.

The whole code: https://gist.github.com/3023757

Routes output by:

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

1条回答
仙女界的扛把子
2楼-- · 2019-05-27 09:23

You can call SetRevCallback function your SetAcceptCallback function.

Explicitly,

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

In the accept function

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

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

}
查看更多
登录 后发表回答