سؤال

ns-3 users! I'm newbie in ns-3 Please, help me to understand something here: http://code.nsnam.org/ns-3-dev/file/tip/examples/wireless/wifi-simple-adhoc-grid.cc

I can not understand something here (lines from 209 to 217):

  $ TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
  Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (sinkNode), tid); //sinkNode=0
  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);
  source->Connect (remote);$

What is going on here? just FYI: code attached.

PLEASE, HELP ME! THANK YOU ALL! :)

هل كانت مفيدة؟

المحلول

Commented source code below.

Get the unique id of the factory class that can create udp sockets

TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");

Actually create a udp socket on node "sinkNode" (whatever that is)

Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (sinkNode), tid);

Bind the socket we just created to the 'any' ipv4 address

InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
recvSink->Bind (local);

Make the socket forward the packets it received to the "ReceivePacket" function

recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));

Create a udp socket on the sending node

Ptr<Socket> source = Socket::CreateSocket (c.Get (sourceNode), tid);

Connect the udp socket to the ip address and port number of the udp socket that was created on the sink node. This just sets the default "to" ip address for packets that are sent over this socket

InetSocketAddress remote = InetSocketAddress (i.GetAddress (sinkNode, 0), 80);
source->Connect (remote);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top