Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[NS3] unused variable removed
[simgrid.git] / src / surf / ns3 / ns3_simulator.cc
index a1dd0ed..6c167db 100644 (file)
@@ -19,6 +19,7 @@ NS3Sim SimulatorNS3;
 
 static void receive_callback(Ptr<Socket> localSocket);
 static void send_callback(Ptr<Socket> localSocket, uint32_t txSpace);
+static void datasent_callback(Ptr<Socket> localSocket, uint32_t dataSent);
 static void StartFlow(Ptr<Socket> sock,
     const char *to,
     uint16_t port_number);
@@ -42,7 +43,7 @@ NS3Sim::~NS3Sim(){
  *             port_number: The port number to use
  *             start: the time the communication start
  *             addr:  ip address
- *             TotalBytes: number of bytes to transmit
+ *             totalBytes: number of bytes to transmit
  */
 void NS3Sim::create_flow_NS3(
                Ptr<Node> src,
@@ -50,7 +51,7 @@ void NS3Sim::create_flow_NS3(
                uint16_t port_number,
                double start,
                const char *addr,
-               uint32_t TotalBytes,
+               uint32_t totalBytes,
                void * action)
 {
        if(!dict_socket) dict_socket = xbt_dict_new();
@@ -58,8 +59,9 @@ void NS3Sim::create_flow_NS3(
        sink.Install (dst);
        Ptr<Socket> sock = Socket::CreateSocket (src, TypeId::LookupByName ("ns3::TcpSocketFactory"));
        MySocket *mysocket = new MySocket();
-       mysocket->TotalBytes = TotalBytes;
-       mysocket->remaining = TotalBytes;
+       mysocket->totalBytes = totalBytes;
+       mysocket->remaining = totalBytes;
+       mysocket->bufferedBytes = 0;
        mysocket->sentBytes = 0;
        mysocket->finished = 0;
        mysocket->action = action;
@@ -80,6 +82,10 @@ double NS3Sim::get_remains_from_socket(void *socket){
        return ((MySocket *)socket)->remaining;
 }
 
+double NS3Sim::get_sent_from_socket(void *socket){
+  return ((MySocket *)socket)->sentBytes;
+}
+
 void NS3Sim::simulator_stop(double min){
        if(min > 0.0)
                Simulator::Stop(Seconds(min));
@@ -99,7 +105,7 @@ static void receive_callback(Ptr<Socket> localSocket){
   MySocket* mysocket = (MySocket*)xbt_dict_get_or_null(dict_socket,(char*)&localSocket);
   mysocket->finished = 1;
 
-  //cout << "[" << Simulator::Now ().GetSeconds() << "] " << "Received [" << mysocket->TotalBytes << "bytes],  from: " << iaddr.GetIpv4 () << " port: " << iaddr.GetPort () << endl;
+  //cout << "[" << Simulator::Now ().GetSeconds() << "] " << "Received [" << mysocket->totalBytes << "bytes],  from: " << iaddr.GetIpv4 () << " port: " << iaddr.GetPort () << endl;
        std::stringstream sstream;
                sstream << Simulator::Now ().GetSeconds();
                std::string s = sstream.str();
@@ -116,24 +122,35 @@ static void send_callback(Ptr<Socket> localSocket, uint32_t txSpace){
        localSocket->GetSockName (addr);
        InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (addr);
        MySocket* mysocket = (MySocket*)xbt_dict_get_or_null(dict_socket,(char*)&localSocket);
-       uint32_t totalBytes = mysocket->TotalBytes;
-       while ((mysocket->sentBytes) < totalBytes && localSocket->GetTxAvailable () > 0){
-      uint32_t toWrite = min ((mysocket->remaining), writeSize);
-      toWrite = min (toWrite, localSocket->GetTxAvailable ());
-      int amountSent = localSocket->Send (&data[0], toWrite, 0);
-
-      if(amountSent < 0)
-         return;
-         (mysocket->sentBytes) += amountSent;
+       uint32_t totalBytes = mysocket->totalBytes;
+       while ((mysocket->bufferedBytes) < totalBytes && localSocket->GetTxAvailable () > 0){
+         uint32_t toWrite = min ((mysocket->remaining), writeSize);
+         toWrite = min (toWrite, localSocket->GetTxAvailable ());
+         int amountSent = localSocket->Send (&data[0], toWrite, 0);
+
+         if(amountSent < 0)
+           return;
+
+         (mysocket->bufferedBytes) += amountSent;
          (mysocket->remaining) -= amountSent;
          //cout << "[" << Simulator::Now ().GetSeconds() << "] " << "Send one packet, remaining "<<  mysocket->remaining << " bytes!" << endl;
-    }
-       if ((mysocket->sentBytes) >= totalBytes){
+       }
+       if ((mysocket->bufferedBytes) >= totalBytes){
                localSocket->Close();
        }
 
 }
 
+static void datasent_callback(Ptr<Socket> localSocket, uint32_t dataSent){
+  Address addr;
+  localSocket->GetSockName (addr);
+  InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (addr);
+  MySocket* mysocket = (MySocket*)xbt_dict_get_or_null(dict_socket,(char*)&localSocket);
+  mysocket->sentBytes += dataSent;
+  //cout << "[" << Simulator::Now ().GetSeconds() << "] " << "DATASENT [" << mysocket->totalBytes << "bytes],  from: " << iaddr.GetIpv4 () << " port: " << iaddr.GetPort () << " dataSent " << dataSent <<endl;
+}
+
+
 static void StartFlow(Ptr<Socket> sock,
     const char *to,
     uint16_t port_number)
@@ -145,4 +162,5 @@ static void StartFlow(Ptr<Socket> sock,
   sock->Connect(serverAddr);
   sock->SetSendCallback (MakeCallback (&send_callback));
   sock->SetRecvCallback (MakeCallback (&receive_callback));
+  sock->SetDataSentCallback (MakeCallback (&datasent_callback));
 }