From: Lucas Schnorr Date: Wed, 7 Sep 2011 14:02:05 +0000 (+0200) Subject: [NS3] implementing more socket callbacks in order to capture the closing of a socket X-Git-Tag: v3_6_2~121 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/007694fe3d4ebd6577e1fb0a1017330b1a575a67 [NS3] implementing more socket callbacks in order to capture the closing of a socket details: - close_callback is called in place of receive_callback for some situations when the flow finishes --- diff --git a/src/surf/ns3/ns3_simulator.cc b/src/surf/ns3/ns3_simulator.cc index 54d45c8476..199d6c68d6 100644 --- a/src/surf/ns3/ns3_simulator.cc +++ b/src/surf/ns3/ns3_simulator.cc @@ -7,6 +7,7 @@ #include "surf/ns3/ns3_simulator.h" #include "xbt/dict.h" #include "xbt/log.h" +#include "xbt/sysdep.h" using namespace ns3; using namespace std; @@ -143,6 +144,28 @@ static void datasent_callback(Ptr localSocket, uint32_t dataSent){ // cout << "[" << Simulator::Now ().GetSeconds() << "] " << "datasent_cb of F[" << mysocket->totalBytes << "] " << dataSent << " sent." << endl; } +static void normalClose_callback(Ptr localSocket){ + MySocket* mysocket = (MySocket*)xbt_dict_get_or_null(dict_socket,(char*)&localSocket); +// cout << "[" << Simulator::Now ().GetSeconds() << "] " << "normalClose_cb of F[" << mysocket->totalBytes << "]" << endl; + receive_callback (localSocket); +} + +static void errorClose_callback(Ptr localSocket){ + MySocket* mysocket = (MySocket*)xbt_dict_get_or_null(dict_socket,(char*)&localSocket); +// cout << "[" << Simulator::Now ().GetSeconds() << "] " << "errorClose_cb of F[" << mysocket->totalBytes << "]" << endl; + xbt_die("NS3: a socket was closed anormally"); +} + +static void succeededConnect_callback(Ptr localSocket){ + MySocket* mysocket = (MySocket*)xbt_dict_get_or_null(dict_socket,(char*)&localSocket); +// cout << "[" << Simulator::Now ().GetSeconds() << "] " << "succeededConnect_cb of F[" << mysocket->totalBytes << "]" << endl; +} + +static void failedConnect_callback(Ptr localSocket){ + MySocket* mysocket = (MySocket*)xbt_dict_get_or_null(dict_socket,(char*)&localSocket); +// cout << "[" << Simulator::Now ().GetSeconds() << "] " << "failedConnect_cb of F[" << mysocket->totalBytes << "]" << endl; + xbt_die("NS3: a socket failed to connect"); +} static void StartFlow(Ptr sock, const char *to, @@ -150,10 +173,13 @@ static void StartFlow(Ptr sock, { InetSocketAddress serverAddr (to, port_number); - //cout << "[" << Simulator::Now().GetSeconds() << "] Starting flow to " << to << " using port " << port_number << endl; - sock->Connect(serverAddr); sock->SetSendCallback (MakeCallback (&send_callback)); sock->SetRecvCallback (MakeCallback (&receive_callback)); sock->SetDataSentCallback (MakeCallback (&datasent_callback)); + sock->SetConnectCallback (MakeCallback (&succeededConnect_callback), MakeCallback (&failedConnect_callback)); + sock->SetCloseCallbacks (MakeCallback (&normalClose_callback), MakeCallback (&errorClose_callback)); + + MySocket* mysocket = (MySocket*)xbt_dict_get_or_null(dict_socket,(char*)&sock); +// cout << "[" << Simulator::Now().GetSeconds() << "] Starting flow to " << to << " using port " << port_number << endl; }