Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove unnecessary calls to c_str().
[simgrid.git] / src / surf / network_ns3.cpp
index a35400c..0a71792 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -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++;
 }
 
@@ -73,7 +73,7 @@ static void clusterCreation_cb(simgrid::kernel::routing::ClusterCreationArgs* cl
 
     // Create private link
     std::string host_id   = cluster->prefix + std::to_string(i) + cluster->suffix;
-    NetPointNs3* host_src = sg_host_by_name(host_id.c_str())->pimpl_netpoint->extension<NetPointNs3>();
+    NetPointNs3* host_src = simgrid::s4u::Host::by_name(host_id)->pimpl_netpoint->extension<NetPointNs3>();
     xbt_assert(host_src, "Cannot find a NS3 host of name %s", host_id.c_str());
 
     // Any NS3 route is symmetrical
@@ -136,11 +136,9 @@ static void postparse_cb()
  *********/
 void surf_network_model_init_NS3()
 {
-  if (surf_network_model)
-    return;
+  xbt_assert(surf_network_model == nullptr, "Cannot set the network model twice");
 
   surf_network_model = new simgrid::kernel::resource::NetworkNS3Model();
-  all_existing_models->push_back(surf_network_model);
 }
 
 static simgrid::config::Flag<std::string>
@@ -155,6 +153,8 @@ NetworkNS3Model::NetworkNS3Model() : NetworkModel(Model::UpdateAlgo::FULL)
   xbt_assert(not sg_link_energy_is_inited(),
              "LinkEnergy plugin and NS3 network models are not compatible. Are you looking for Ecofen, maybe?");
 
+  all_existing_models.push_back(this);
+
   NetPointNs3::EXTENSION_ID = simgrid::kernel::routing::NetPoint::extension_create<NetPointNs3>();
 
   ns3_initialize(ns3_tcp_model.get().c_str());
@@ -173,8 +173,8 @@ NetworkNS3Model::~NetworkNS3Model() {
   IPV4addr.clear();
 }
 
-LinkImpl* NetworkNS3Model::createLink(const std::string& name, double bandwidth, double latency,
-                                      s4u::Link::SharingPolicy policy)
+LinkImpl* NetworkNS3Model::create_link(const std::string& name, double bandwidth, double latency,
+                                       s4u::Link::SharingPolicy policy)
 {
   return new LinkNS3(this, name, bandwidth, latency);
 }
@@ -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);
   }
 }
 
@@ -277,17 +277,17 @@ LinkNS3::LinkNS3(NetworkNS3Model* model, const std::string& name, double bandwid
 
 LinkNS3::~LinkNS3() = default;
 
-void LinkNS3::apply_event(tmgr_trace_event_t event, double value)
+void LinkNS3::apply_event(profile::Event* event, double value)
 {
   THROW_UNIMPLEMENTED;
 }
-void LinkNS3::set_bandwidth_trace(tmgr_trace_t trace)
+void LinkNS3::set_bandwidth_profile(profile::Profile* profile)
 {
-  xbt_die("The NS3 network model doesn't support bandwidth traces");
+  xbt_die("The NS3 network model doesn't support bandwidth profiles");
 }
-void LinkNS3::set_latency_trace(tmgr_trace_t trace)
+void LinkNS3::set_latency_profile(profile::Profile* profile)
 {
-  xbt_die("The NS3 network model doesn't support latency traces");
+  xbt_die("The NS3 network model doesn't support latency profiles");
 }
 
 /**********
@@ -295,19 +295,17 @@ void LinkNS3::set_latency_trace(tmgr_trace_t trace)
  **********/
 
 NetworkNS3Action::NetworkNS3Action(kernel::resource::Model* model, double totalBytes, s4u::Host* src, s4u::Host* dst)
-    : NetworkAction(model, totalBytes, false)
+    : NetworkAction(model, totalBytes, false), src_(src), dst_(dst)
 {
   XBT_DEBUG("Communicate from %s to %s", src->get_cname(), dst->get_cname());
 
-  src_ = src;
-  dst_ = dst;
   static int port_number = 1025; // Port number is limited from 1025 to 65 000
 
   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());
@@ -321,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.");
@@ -445,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",