[Ns-bugs] [Bug 154] New: Attach sockets to nodes
bugzilla-daemon@nsnam-www.ece.gatech.edu
bugzilla-daemon at nsnam-www.ece.gatech.edu
Thu Mar 27 09:18:19 PDT 2008
http://www.nsnam.org/bugzilla/show_bug.cgi?id=154
Summary: Attach sockets to nodes
Product: ns-3
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P3
Component: node module
AssignedTo: ns-bugs at isi.edu
ReportedBy: gjcarneiro at gmail.com
I just spent about an hour debugging a problem in a student's NS-3 program.
And the student spent probably a day :-) But I think this problem can be
easily prevented...
The student's code had roughly this structure:
using namespace ns3;
class Test
{
public:
void ReceivePacket (Ptr<Socket> socket, Ptr<Packet> packet, const Address
&from);
bool run(void);
};
void Test::ReceivePacket (Ptr<Socket> socket, Ptr<Packet> packet, const Address
&from)
{
NS_LOG_INFO("receive packet");
[...]
}
bool
Test::run(void)
{
[...] creates nodes [...]
NS_LOG_INFO ("create socket receive");
Ptr<SocketFactory> socketFactory= rxNode->GetObject<Udp> ();
Ptr<Socket> rxSocket= socketFactory->CreateSocket();
rxSocket=->Bind (InetSocketAddress (Ipv4Address ("10.1.4.2"), 1234));
rxSocket=->SetRecvCallback (MakeCallback (&Test::ReceivePacket, this));
NS_LOG_INFO("send socket ");
Ptr<SocketFactory> n0SocketFactory = n0->GetObject<Udp> ();
Ptr<Socket> n0socket = n0SocketFactory->CreateSocket ();
Ptr<Packet> packet=Create <Packet>();
NS_LOG_INFO("....");
n0socket->SendTo (InetSocketAddress (Ipv4Address("10.1.4.2"),
1234),packet);
return true;
}
int
main (int argc, char *argv[])
{
Test teste;
teste.run();
[...]
NS_LOG_INFO ("Run Simulation.");
Simulator::StopAt (Seconds (3.0));
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
}
This code does not work because "Ptr<Socket> rxSocket" inside Test.run() goes
out of scope before the simulation even begins, and so the socket is destroyed.
I would propose that nodes would keep a list of pointers to sockets. They
would release those references when the socket is Close()ed, or when the node
is disposed. This is more or less what is done with Applications already...
--
Configure bugmail: http://www.nsnam.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
More information about the Ns-bugs
mailing list