ns-3 wlan grid TCP not working while UDP is
-
18-06-2021 - |
Domanda
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)
Soluzione
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));
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow