Hi, there , I am trying to do a routing protocol simulation using ns3, but find out that I have some difficulty in understanding the usage of PacketSocket. I found this code snippet somewhere
PacketSocketAddress socket;
socket.SetAllDevices ();
socket.SetPhysicalAddress (gwdev.Get (0)->GetBroadcast());
socket.SetProtocol(0);
TypeId psfid = TypeId::LookupByName ("ns3::PacketSocketFactory");
for (uint32_t i = 0; i < m_numNodes*layers; i++)
{
Ptr<Socket> nodeSocket = Socket::CreateSocket (node.Get (i), psfid);
nodeSocket->SetAllowBroadcast(true);
nodeSocket->Bind ();
nodeSocket->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this));
nodeSocket->Connect (socket);
Ptr<Socket> gwSocket = Socket::CreateSocket (gw.Get (0), psfid);
gwSocket->SetAllowBroadcast(true);
gwSocket->Bind();
gwSocket->SetRecvCallback (MakeCallback (&Experiment::GWReceivePacket, this));
}
where the node is a NodeContainer for underwater node and gw is a NodeContainer for sink node.
I can't understand what exactly the PacketSocketAddress does and how underwater nodes connect to each other, also, I can't find any useful document. Can anyone explain this code snippet to me? Thank you in advance.