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);
* 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,
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();
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;
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));
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();
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)
sock->Connect(serverAddr);
sock->SetSendCallback (MakeCallback (&send_callback));
sock->SetRecvCallback (MakeCallback (&receive_callback));
+ sock->SetDataSentCallback (MakeCallback (&datasent_callback));
}