Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
start to snake_case NS3
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 22 Jul 2018 21:10:46 +0000 (23:10 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 24 Jul 2018 21:26:52 +0000 (23:26 +0200)
src/surf/network_ns3.cpp
src/surf/network_ns3.hpp
src/surf/ns3/ns3_simulator.cpp
src/surf/ns3/ns3_simulator.hpp

index 8324f1d..02f139b 100644 (file)
@@ -38,7 +38,7 @@ std::vector<std::string> IPV4addr;
  * Crude globals *
  *****************/
 
-extern std::map<std::string, SgFlow*> flowFromSock;
+extern std::map<std::string, SgFlow*> flow_from_sock;
 
 static ns3::InternetStackHelper stack;
 static ns3::NodeContainer nodes;
@@ -54,9 +54,9 @@ simgrid::xbt::Extension<simgrid::kernel::routing::NetPoint, NetPointNs3> NetPoin
 
 NetPointNs3::NetPointNs3()
 {
-  ns3Node_ = ns3::CreateObject<ns3::Node>(0);
-  stack.Install(ns3Node_);
-  nodes.Add(ns3Node_);
+  ns3_node_ = ns3::CreateObject<ns3::Node>(0);
+  stack.Install(ns3_node_);
+  nodes.Add(ns3_node_);
   node_num = number_of_nodes++;
 }
 
@@ -219,16 +219,16 @@ void NetworkNS3Model::update_actions_state(double now, double delta)
     return;
   }
 
-  std::string ns3Socket;
-  for (auto elm : flowFromSock) {
-    ns3Socket                 = elm.first;
+  std::string ns3_socket;
+  for (auto elm : flow_from_sock) {
+    ns3_socket                = elm.first;
     SgFlow* sgFlow            = elm.second;
     NetworkNS3Action * action = sgFlow->action_;
     XBT_DEBUG("Processing socket %p (action %p)",sgFlow,action);
-    action->set_remains(action->get_cost() - sgFlow->sentBytes_);
+    action->set_remains(action->get_cost() - sgFlow->sent_bytes_);
 
     if (TRACE_is_enabled() && action->get_state() == kernel::resource::Action::State::STARTED) {
-      double data_delta_sent = sgFlow->sentBytes_ - action->lastSent_;
+      double data_delta_sent = sgFlow->sent_bytes_ - action->last_sent_;
 
       std::vector<LinkImpl*> route = std::vector<LinkImpl*>();
 
@@ -237,28 +237,28 @@ void NetworkNS3Model::update_actions_state(double now, double delta)
         TRACE_surf_resource_set_utilization("LINK", "bandwidth_used", link->get_cname(), action->get_category(),
                                             (data_delta_sent) / delta, now - delta, delta);
 
-      action->lastSent_ = sgFlow->sentBytes_;
+      action->last_sent_ = sgFlow->sent_bytes_;
     }
 
     if(sgFlow->finished_){
-      socket_to_destroy.push_back(ns3Socket);
-      XBT_DEBUG("Destroy socket %p of action %p", ns3Socket.c_str(), action);
+      socket_to_destroy.push_back(ns3_socket);
+      XBT_DEBUG("Destroy socket %p of action %p", ns3_socket.c_str(), action);
       action->finish(kernel::resource::Action::State::FINISHED);
     } else {
-      XBT_DEBUG("Socket %p sent %u bytes out of %u (%u remaining)", ns3Socket.c_str(), sgFlow->sentBytes_,
-                sgFlow->totalBytes_, sgFlow->remaining_);
+      XBT_DEBUG("Socket %p sent %u bytes out of %u (%u remaining)", ns3_socket.c_str(), sgFlow->sent_bytes_,
+                sgFlow->total_bytes_, sgFlow->remaining_);
     }
   }
 
   while (not socket_to_destroy.empty()) {
-    ns3Socket = socket_to_destroy.back();
+    ns3_socket = socket_to_destroy.back();
     socket_to_destroy.pop_back();
-    SgFlow* flow = flowFromSock.at(ns3Socket);
+    SgFlow* flow = flow_from_sock.at(ns3_socket);
     if (XBT_LOG_ISENABLED(ns3, xbt_log_priority_debug)) {
-      XBT_DEBUG("Removing socket %p of action %p", ns3Socket.c_str(), flow->action_);
+      XBT_DEBUG("Removing socket %p of action %p", ns3_socket.c_str(), flow->action_);
     }
     delete flow;
-    flowFromSock.erase(ns3Socket);
+    flow_from_sock.erase(ns3_socket);
   }
 }
 
@@ -304,8 +304,8 @@ NetworkNS3Action::NetworkNS3Action(kernel::resource::Model* model, double totalB
   unsigned int node1 = src->pimpl_netpoint->extension<NetPointNs3>()->node_num;
   unsigned int node2 = dst->pimpl_netpoint->extension<NetPointNs3>()->node_num;
 
-  ns3::Ptr<ns3::Node> src_node = src->pimpl_netpoint->extension<NetPointNs3>()->ns3Node_;
-  ns3::Ptr<ns3::Node> dst_node = dst->pimpl_netpoint->extension<NetPointNs3>()->ns3Node_;
+  ns3::Ptr<ns3::Node> src_node = src->pimpl_netpoint->extension<NetPointNs3>()->ns3_node_;
+  ns3::Ptr<ns3::Node> dst_node = dst->pimpl_netpoint->extension<NetPointNs3>()->ns3_node_;
 
   xbt_assert(node2 < IPV4addr.size(), "Element %s is unknown to NS3. Is it connected to any one-hop link?",
              dst->pimpl_netpoint->get_cname());
@@ -319,11 +319,11 @@ NetworkNS3Action::NetworkNS3Action(kernel::resource::Model* model, double totalB
 
   ns3::Ptr<ns3::Socket> sock = ns3::Socket::CreateSocket(src_node, ns3::TcpSocketFactory::GetTypeId());
 
-  flowFromSock.insert({transformSocketPtr(sock), new SgFlow(totalBytes, this)});
+  flow_from_sock.insert({transform_socket_ptr(sock), new SgFlow(totalBytes, this)});
 
   sock->Bind(ns3::InetSocketAddress(port_number));
 
-  ns3::Simulator::ScheduleNow(&StartFlow, sock, addr.c_str(), port_number);
+  ns3::Simulator::ScheduleNow(&start_flow, sock, addr.c_str(), port_number);
 
   port_number++;
   xbt_assert(port_number <= 65000, "Too many connections! Port number is saturated.");
@@ -443,8 +443,8 @@ void ns3_add_link(NetPointNs3* src, NetPointNs3* dst, double bw, double lat) {
   int srcNum = src->node_num;
   int dstNum = dst->node_num;
 
-  ns3::Ptr<ns3::Node> a = src->ns3Node_;
-  ns3::Ptr<ns3::Node> b = dst->ns3Node_;
+  ns3::Ptr<ns3::Node> a = src->ns3_node_;
+  ns3::Ptr<ns3::Node> b = dst->ns3_node_;
 
   XBT_DEBUG("\tAdd PTP from %d to %d bw:'%f Bps' lat:'%fs'", srcNum, dstNum, bw, lat);
   pointToPoint.SetDeviceAttribute("DataRate",
index fed2548..7b18dca 100644 (file)
@@ -54,7 +54,7 @@ public:
   void update_remains_lazy(double now) override;
 
   // private:
-  double lastSent_ = 0;
+  double last_sent_ = 0;
   s4u::Host* src_;
   s4u::Host* dst_;
 };
index 64230a0..1ee8447 100644 (file)
@@ -12,7 +12,7 @@
 
 #include <algorithm>
 
-std::map<std::string, SgFlow*> flowFromSock; // ns3::sock -> SgFlow
+std::map<std::string, SgFlow*> flow_from_sock; // ns3::sock -> SgFlow
 
 static void receive_callback(ns3::Ptr<ns3::Socket> socket);
 static void datasent_cb(ns3::Ptr<ns3::Socket> socket, uint32_t dataSent);
@@ -21,25 +21,25 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ns3);
 
 SgFlow::SgFlow(uint32_t totalBytes, simgrid::kernel::resource::NetworkNS3Action* action)
 {
-  totalBytes_ = totalBytes;
+  total_bytes_ = totalBytes;
   remaining_  = totalBytes;
   action_     = action;
 }
 
 static SgFlow* getFlowFromSocket(ns3::Ptr<ns3::Socket> socket)
 {
-  auto it = flowFromSock.find(transformSocketPtr(socket));
-  return (it == flowFromSock.end()) ? nullptr : it->second;
+  auto it = flow_from_sock.find(transform_socket_ptr(socket));
+  return (it == flow_from_sock.end()) ? nullptr : it->second;
 }
 
 static void receive_callback(ns3::Ptr<ns3::Socket> socket)
 {
   SgFlow* flow = getFlowFromSocket(socket);
-  XBT_DEBUG("received on F[%p, total: %u, remain: %u]", flow, flow->totalBytes_, flow->remaining_);
+  XBT_DEBUG("received on F[%p, total: %u, remain: %u]", flow, flow->total_bytes_, flow->remaining_);
 
   if (flow->finished_ == false) {
     flow->finished_ = true;
-    XBT_DEBUG("recv_cb of F[%p, %p, %u]", flow, flow->action_, flow->totalBytes_);
+    XBT_DEBUG("recv_cb of F[%p, %p, %u]", flow, flow->action_, flow->total_bytes_);
     XBT_DEBUG("Stop simulator at %f seconds", ns3::Simulator::Now().GetSeconds());
     ns3::Simulator::Stop(ns3::Seconds(0.0));
     ns3::Simulator::Run();
@@ -49,13 +49,13 @@ static void receive_callback(ns3::Ptr<ns3::Socket> socket)
 static void send_cb(ns3::Ptr<ns3::Socket> sock, uint32_t txSpace)
 {
   SgFlow* flow = getFlowFromSocket(sock);
-  XBT_DEBUG("Asked to write on F[%p, total: %u, remain: %u]", flow, flow->totalBytes_, flow->remaining_);
+  XBT_DEBUG("Asked to write on F[%p, total: %u, remain: %u]", flow, flow->total_bytes_, flow->remaining_);
 
   if (flow->remaining_ == 0) // all data was already buffered (and socket was already closed)
     return;
 
   /* While not all is buffered and there remain space in the buffers */
-  while (flow->bufferedBytes_ < flow->totalBytes_ && sock->GetTxAvailable() > 0) {
+  while (flow->buffered_bytes_ < flow->total_bytes_ && sock->GetTxAvailable() > 0) {
 
     // Send at most 1040 bytes (data size in a TCP packet), as NS3 seems to not split correctly by itself
     uint32_t toWrite = std::min({flow->remaining_, sock->GetTxAvailable(), std::uint32_t(1040)});
@@ -67,14 +67,14 @@ static void send_cb(ns3::Ptr<ns3::Socket> sock, uint32_t txSpace)
     int amountSent = sock->Send(0, toWrite, 0);
 
     xbt_assert(amountSent > 0, "Since TxAvailable>0, amountSent should also >0");
-    flow->bufferedBytes_ += amountSent;
+    flow->buffered_bytes_ += amountSent;
     flow->remaining_ -= amountSent;
 
     XBT_DEBUG("%f: sent %d bytes over flow %p (still %u to go)", ns3::Simulator::Now().GetSeconds(), amountSent, flow,
               flow->remaining_);
   }
 
-  if (flow->bufferedBytes_ >= flow->totalBytes_)
+  if (flow->buffered_bytes_ >= flow->total_bytes_)
     sock->Close();
 }
 
@@ -82,39 +82,39 @@ static void datasent_cb(ns3::Ptr<ns3::Socket> socket, uint32_t dataSent)
 {
   /* The tracing wants to know */
   SgFlow* flow = getFlowFromSocket(socket);
-  flow->sentBytes_ += dataSent;
-  XBT_DEBUG("datasent_cb of F[%p, %p, %u] %u sent (%u total)", flow, flow->action_, flow->totalBytes_, dataSent,
-            flow->sentBytes_);
+  flow->sent_bytes_ += dataSent;
+  XBT_DEBUG("datasent_cb of F[%p, %p, %u] %u sent (%u total)", flow, flow->action_, flow->total_bytes_, dataSent,
+            flow->sent_bytes_);
 }
 
 static void normalClose_callback(ns3::Ptr<ns3::Socket> socket)
 {
   SgFlow* flow = getFlowFromSocket(socket);
-  XBT_DEBUG("normalClose_cb of F[%p, %p, %u]", flow, flow->action_, flow->totalBytes_);
+  XBT_DEBUG("normalClose_cb of F[%p, %p, %u]", flow, flow->action_, flow->total_bytes_);
   receive_callback(socket);
 }
 
 static void errorClose_callback(ns3::Ptr<ns3::Socket> socket)
 {
   SgFlow* flow = getFlowFromSocket(socket);
-  XBT_DEBUG("errorClose_cb of F[%p, %p, %u]", flow, flow->action_, flow->totalBytes_);
+  XBT_DEBUG("errorClose_cb of F[%p, %p, %u]", flow, flow->action_, flow->total_bytes_);
   xbt_die("NS3: a socket was closed anormally");
 }
 
 static void succeededConnect_callback(ns3::Ptr<ns3::Socket> socket)
 {
   SgFlow* flow = getFlowFromSocket(socket);
-  XBT_DEBUG("succeededConnect_cb of F[%p, %p, %u]", flow, flow->action_, flow->totalBytes_);
+  XBT_DEBUG("succeededConnect_cb of F[%p, %p, %u]", flow, flow->action_, flow->total_bytes_);
 }
 
 static void failedConnect_callback(ns3::Ptr<ns3::Socket> socket)
 {
   SgFlow* mysocket = getFlowFromSocket(socket);
-  XBT_DEBUG("failedConnect_cb of F[%p, %p, %u]", mysocket, mysocket->action_, mysocket->totalBytes_);
+  XBT_DEBUG("failedConnect_cb of F[%p, %p, %u]", mysocket, mysocket->action_, mysocket->total_bytes_);
   xbt_die("NS3: a socket failed to connect");
 }
 
-void StartFlow(ns3::Ptr<ns3::Socket> sock, const char* to, uint16_t port_number)
+void start_flow(ns3::Ptr<ns3::Socket> sock, const char* to, uint16_t port_number)
 {
   SgFlow* flow = getFlowFromSocket(sock);
   ns3::InetSocketAddress serverAddr(to, port_number);
@@ -128,7 +128,7 @@ void StartFlow(ns3::Ptr<ns3::Socket> sock, const char* to, uint16_t port_number)
   // Notice when we actually sent some data (mostly for the TRACING module)
   sock->SetDataSentCallback(MakeCallback(&datasent_cb));
 
-  XBT_DEBUG("startFlow of F[%p, %p, %u] dest=%s port=%d", flow, flow->action_, flow->totalBytes_, to, port_number);
+  XBT_DEBUG("startFlow of F[%p, %p, %u] dest=%s port=%d", flow, flow->action_, flow->total_bytes_, to, port_number);
 
   sock->SetConnectCallback(MakeCallback(&succeededConnect_callback), MakeCallback(&failedConnect_callback));
   sock->SetCloseCallbacks(MakeCallback(&normalClose_callback), MakeCallback(&errorClose_callback));
index c7c496c..714ebfe 100644 (file)
@@ -20,7 +20,7 @@ public:
 
   explicit NetPointNs3();
   int node_num;
-  ns3::Ptr<ns3::Node> ns3Node_;
+  ns3::Ptr<ns3::Node> ns3_node_;
 };
 
 XBT_PUBLIC void ns3_initialize(std::string TcpProtocol);
@@ -33,17 +33,17 @@ public:
   SgFlow(uint32_t total_bytes, simgrid::kernel::resource::NetworkNS3Action* action);
 
   // private:
-  std::uint32_t bufferedBytes_ = 0;
-  std::uint32_t sentBytes_     = 0;
+  std::uint32_t buffered_bytes_ = 0;
+  std::uint32_t sent_bytes_     = 0;
   std::uint32_t remaining_;
-  std::uint32_t totalBytes_;
+  std::uint32_t total_bytes_;
   bool finished_ = false;
   simgrid::kernel::resource::NetworkNS3Action* action_;
 };
 
-void StartFlow(ns3::Ptr<ns3::Socket> sock, const char* to, uint16_t port_number);
+void start_flow(ns3::Ptr<ns3::Socket> sock, const char* to, uint16_t port_number);
 
-static inline std::string transformSocketPtr(ns3::Ptr<ns3::Socket> local_socket)
+static inline std::string transform_socket_ptr(ns3::Ptr<ns3::Socket> local_socket)
 {
   std::stringstream sstream;
   sstream << local_socket;