Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add functions for get and reset last amount sent by ns3.
authorNavarrop <Pierre.Navarro@imag.fr>
Thu, 1 Sep 2011 12:43:43 +0000 (14:43 +0200)
committerNavarrop <Pierre.Navarro@imag.fr>
Thu, 1 Sep 2011 12:43:43 +0000 (14:43 +0200)
src/surf/network_ns3.c
src/surf/ns3/ns3_interface.cc
src/surf/ns3/ns3_interface.h
src/surf/ns3/ns3_simulator.cc
src/surf/ns3/ns3_simulator.h

index 8777c00..50936ab 100644 (file)
@@ -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);
index 03ddec0..7607bdc 100644 (file)
@@ -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();
 }
index e6d2187..7b9022d 100644 (file)
@@ -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);
index a1dd0ed..0a2e4a5 100644 (file)
@@ -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<Socket> 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;
     }
index 0966670..bd08513 100644 (file)
@@ -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);
 };