From: Navarrop Date: Thu, 1 Sep 2011 12:43:43 +0000 (+0200) Subject: Add functions for get and reset last amount sent by ns3. X-Git-Tag: v3_6_2~169 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/53f32ad3574aa3e8c7f17b3721208313c8e8d69d Add functions for get and reset last amount sent by ns3. --- diff --git a/src/surf/network_ns3.c b/src/surf/network_ns3.c index 8777c009f7..50936abf11 100644 --- a/src/surf/network_ns3.c +++ b/src/surf/network_ns3.c @@ -439,6 +439,27 @@ static void ns3_update_actions_state(double now, double delta) xbt_dict_foreach(dict_socket,cursor,key,data){ action = (surf_action_t)ns3_get_socket_action(data); action->remains = ns3_get_socket_remains(data); + +//#ifdef HAVE_TRACING +// if (TRACE_is_enabled()) { +// double amount_sent = (action->generic_action.cost - action->generic_action.remains); +// +// // tracing resource utilization +// xbt_dynar_t route = global_routing->get_route(action->src_name, +// action->dst_name); +// network_link_GTNETS_t link; +// unsigned int i; +// xbt_dynar_foreach(route, i, link) { +// TRACE_surf_link_set_utilization (link->generic_resource.name, +// action->generic_action.data, +// (surf_action_t) action, +// (amount_sent - last_amount_sent)/(delta), +// now-delta, +// delta); +// } +// } +//#endif + if(ns3_get_socket_is_finished(data) == 1){ action->finish = now; surf_action_state_set(action, SURF_ACTION_DONE); diff --git a/src/surf/ns3/ns3_interface.cc b/src/surf/ns3/ns3_interface.cc index 03ddec0d8e..7607bdc3a3 100644 --- a/src/surf/ns3/ns3_interface.cc +++ b/src/surf/ns3/ns3_interface.cc @@ -55,11 +55,18 @@ double ns3_get_socket_remains(void *socket){ return ns3_sim->get_remains_from_socket(socket); } +double ns3_get_socket_last_amount_sent(void *socket){ + return ns3_sim->get_last_amount_sent_from_socket(socket); +} + +void ns3_reset_socket_last_amount_sent(void *socket){ + ns3_sim->reset_last_amount_sent_from_socket(socket); +} + char ns3_get_socket_is_finished(void *socket){ return ns3_sim->get_finished(socket); } - double ns3_time(){ return Simulator::Now().GetSeconds(); } diff --git a/src/surf/ns3/ns3_interface.h b/src/surf/ns3/ns3_interface.h index e6d2187751..7b9022db52 100644 --- a/src/surf/ns3/ns3_interface.h +++ b/src/surf/ns3/ns3_interface.h @@ -36,6 +36,8 @@ XBT_PUBLIC(void) ns3_simulator(double min); XBT_PUBLIC(double) ns3_time(void); XBT_PUBLIC(void*) ns3_get_socket_action(void *socket); XBT_PUBLIC(double) ns3_get_socket_remains(void *socket); +XBT_PUBLIC(double) ns3_get_socket_last_amount_sent(void *socket); +XBT_PUBLIC(void) ns3_reset_socket_last_amount_sent(void *socket); XBT_PUBLIC(char) ns3_get_socket_is_finished(void *socket); XBT_PUBLIC(void *) ns3_add_host(char * id); XBT_PUBLIC(void *) ns3_add_host_cluster(char * id); diff --git a/src/surf/ns3/ns3_simulator.cc b/src/surf/ns3/ns3_simulator.cc index a1dd0ed68c..0a2e4a58b3 100644 --- a/src/surf/ns3/ns3_simulator.cc +++ b/src/surf/ns3/ns3_simulator.cc @@ -60,6 +60,7 @@ void NS3Sim::create_flow_NS3( MySocket *mysocket = new MySocket(); mysocket->TotalBytes = TotalBytes; mysocket->remaining = TotalBytes; + mysocket->last_amount_sent = 0; mysocket->sentBytes = 0; mysocket->finished = 0; mysocket->action = action; @@ -80,6 +81,14 @@ double NS3Sim::get_remains_from_socket(void *socket){ return ((MySocket *)socket)->remaining; } +double NS3Sim::get_last_amount_sent_from_socket(void *socket){ + return ((MySocket *)socket)->last_amount_sent; +} + +void NS3Sim::reset_last_amount_sent_from_socket(void *socket){ + ((MySocket *)socket)->last_amount_sent = 0; +} + void NS3Sim::simulator_stop(double min){ if(min > 0.0) Simulator::Stop(Seconds(min)); @@ -124,7 +133,9 @@ static void send_callback(Ptr localSocket, uint32_t txSpace){ if(amountSent < 0) return; - (mysocket->sentBytes) += amountSent; + + (mysocket->last_amount_sent) += amountSent; + (mysocket->sentBytes) += amountSent; (mysocket->remaining) -= amountSent; //cout << "[" << Simulator::Now ().GetSeconds() << "] " << "Send one packet, remaining "<< mysocket->remaining << " bytes!" << endl; } diff --git a/src/surf/ns3/ns3_simulator.h b/src/surf/ns3/ns3_simulator.h index 096667067e..bd08513cb2 100644 --- a/src/surf/ns3/ns3_simulator.h +++ b/src/surf/ns3/ns3_simulator.h @@ -24,6 +24,7 @@ struct MySocket{ uint32_t sentBytes; uint32_t remaining; uint32_t TotalBytes; + uint32_t last_amount_sent; char finished; void* action; }; @@ -47,6 +48,8 @@ public: void simulator_start(void); void* get_action_from_socket(void *socket); double get_remains_from_socket(void *socket); + double get_last_amount_sent_from_socket(void *socket); + void reset_last_amount_sent_from_socket(void *socket); char get_finished(void *socket); };