1

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! :)

1 Answer 1

5

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.