[Ns-developers] Receive packet using Raw/Udp socket via loopback device

Hajime Tazaki tazaki at sfc.wide.ad.jp
Tue Apr 6 09:01:48 PDT 2010


Hi Mathieu,

At Tue, 06 Apr 2010 11:32:05 +0200,
Mathieu Lacage wrote:
>
>On Tue, 2010-04-06 at 18:16 +0900, Hajime Tazaki wrote:
>> >> >> >  bool
>> >> >> >  Node::ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
>> >> >> >                           const Address &from, const Address &to, NetDevice::PacketType packetType, bool promiscuous)
>> >> >> >  {
>> >> >> >    NS_ASSERT_MSG (Simulator::GetContext () == GetId (), "Received packet with erroneous context ; " <<
>> >> >> >                   "make sure the channels in use are correctly updating events context " <<
>> >> >> >                   "when transfering events from one node to another.");
>> >> >> > 
>> >> >> > however if we send packet to INADDR_LOOPBACK (127.0.0.1) by
>> >> >> > Ipv4RawSocket (for example), it will discard at this point,
>> >> >> > because Sender context and received context is same.
>> >> >> > 
>> >> >> > In TcpSocket, we never face this problem since TcpSocket switch
>> >> >> > the context before sending packet.
>> >> >> 
>> >> >> Right: the raw socket must change the context similarly.
>> >> >
>> >> >However, in the case you probably encountered, the problem is most
>> >> >likely that the caller did not set its own context before calling Send.
>> >> >Can you show a backtrace of the call to Send which triggers the assert ?
>> >
>> >And the value of Simulator::GetContext () and Node::GetId () ?
>> 
>> (gdb) p this->GetId()
>> $1 = 0
>> (gdb) p Simulator::GetContext()
>> $2 = 4294967295
>> 
>> 
>> If I call Send method with Simulator::ScheduleWithContext,
>> the assert doesn't happen.
>
>Ok, the real fix is to do what the caller of
>ProcessApplication::StartApplication does, that is, call
>ProcessManager::CreateWithStack with ScheduleWithContext.
>
>Something like this in ProcessManagerTestCase::DoRun:
>
>Simulator::ScheduleWithContext (manager->GetObject<Node> ()->GetId (),
>                                &ProcessManagerTestCase::DoStartRun,
>this, manager);
>
>and:
>
>ProcessManagerTestCase::DoStartRun (Ptr<ProcessManager> manager)
>{
>  uint16_t pid = manager->CreateWithStack (m_filename, 1<<20, noargs,
>noenv);
>  manager->SetFinishedCallback (pid, MakeBoundCallback
>(&ProcessManagerTestCase::Finished, &m_status));
>
>}
>
>This will require that you move "status" to a member variable "m_status"

I've added patchset within codereview.
Please take a look it.

http://codereview.appspot.com/867041/diff2/8001:12002/6003

The assert in src/node/node.cc passes now.

Even though this patch, ./test.py will never succeed without
the following changeset, which will be modified into
ns-3-dev.

http://codereview.appspot.com/805044/show

regards,
hajime


More information about the Ns-developers mailing list