Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
and now fix NS3 builds, bummer
[simgrid.git] / src / surf / network_ns3.cpp
index 16d6986..c82909d 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "simgrid/sg_config.h"
 #include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
-#include "src/kernel/routing/NetCard.hpp"
+#include "src/kernel/routing/NetPoint.hpp"
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/surf_private.h"
 
@@ -44,9 +44,9 @@ static int number_of_links = 1;
 static int number_of_networks = 1;
 static int port_number = 1025; //Port number is limited from 1025 to 65 000
 
-simgrid::xbt::Extension<simgrid::kernel::routing::NetCard, NetCardNs3> NetCardNs3::EXTENSION_ID;
+simgrid::xbt::Extension<simgrid::kernel::routing::NetPoint, NetPointNs3> NetPointNs3::EXTENSION_ID;
 
-NetCardNs3::NetCardNs3()
+NetPointNs3::NetPointNs3()
 {
   ns3::Ptr<ns3::Node> node = ns3::CreateObject<ns3::Node>(0);
   stack.Install(node);
@@ -58,11 +58,6 @@ NetCardNs3::NetCardNs3()
  * Callbacks *
  *************/
 
-static void netcardCreation_cb(simgrid::kernel::routing::NetCard* netcard)
-{
-  netcard->extension_set<NetCardNs3>(new NetCardNs3());
-}
-
 static void clusterCreation_cb(sg_platf_cluster_cbarg_t cluster)
 {
   char* lat = bprintf("%fs", cluster->lat);
@@ -70,12 +65,12 @@ static void clusterCreation_cb(sg_platf_cluster_cbarg_t cluster)
 
   for (int i : *cluster->radicals) {
     // Routers don't create a router on the other end of the private link by themselves.
-    // We just need this router to be given an ID so we create a temporary NetCardNS3 so that it gets one
-    NetCardNs3* host_dst = new NetCardNs3();
+    // We just need this router to be given an ID so we create a temporary NetPointNS3 so that it gets one
+    NetPointNs3* host_dst = new NetPointNs3();
 
     // Create private link
     char* host_id = bprintf("%s%d%s", cluster->prefix, i, cluster->suffix);
-    NetCardNs3* host_src = sg_host_by_name(host_id)->pimpl_netcard->extension<NetCardNs3>();
+    NetPointNs3* host_src = sg_host_by_name(host_id)->pimpl_netpoint->extension<NetPointNs3>();
     xbt_assert(host_src, "Cannot find a NS3 host of name %s", host_id);
 
     ns3_add_link(host_src->node_num, host_dst->node_num, bw,lat);
@@ -94,9 +89,10 @@ static void clusterCreation_cb(sg_platf_cluster_cbarg_t cluster)
   xbt_free(bw);
 }
 
-static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetCard* src,
-                             simgrid::kernel::routing::NetCard* dst, simgrid::kernel::routing::NetCard* gw_src,
-                             simgrid::kernel::routing::NetCard* gw_dst, std::vector<Link*>* link_list)
+static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetPoint* src,
+                             simgrid::kernel::routing::NetPoint* dst, simgrid::kernel::routing::NetPoint* gw_src,
+                             simgrid::kernel::routing::NetPoint* gw_dst,
+                             std::vector<simgrid::surf::LinkImpl*>* link_list)
 {
   if (link_list->size() == 1) {
     simgrid::surf::LinkNS3* link = static_cast<simgrid::surf::LinkNS3*>(link_list->at(0));
@@ -110,8 +106,8 @@ static void routeCreation_cb(bool symmetrical, simgrid::kernel::routing::NetCard
     XBT_DEBUG("\tLink (%s) bdw:%s lat:%s", link->getName(), link_bdw, link_lat);
 
     // create link ns3
-    NetCardNs3* host_src = src->extension<NetCardNs3>();
-    NetCardNs3* host_dst = dst->extension<NetCardNs3>();
+    NetPointNs3* host_src = src->extension<NetPointNs3>();
+    NetPointNs3* host_dst = dst->extension<NetPointNs3>();
 
     xbt_assert(host_src != nullptr, "Network element %s does not seem to be NS3-ready", src->cname());
     xbt_assert(host_dst != nullptr, "Network element %s does not seem to be NS3-ready", dst->cname());
@@ -154,13 +150,16 @@ namespace simgrid {
 namespace surf {
 
 NetworkNS3Model::NetworkNS3Model() : NetworkModel() {
-  NetCardNs3::EXTENSION_ID = simgrid::kernel::routing::NetCard::extension_create<NetCardNs3>();
+  NetPointNs3::EXTENSION_ID = simgrid::kernel::routing::NetPoint::extension_create<NetPointNs3>();
 
   ns3_initialize(ns3_tcp_model.get().c_str());
 
-  simgrid::kernel::routing::NetCard::onCreation.connect(&netcardCreation_cb);
+  simgrid::kernel::routing::NetPoint::onCreation.connect([](simgrid::kernel::routing::NetPoint* pt) {
+    pt->extension_set<NetPointNs3>(new NetPointNs3());
+
+  });
   simgrid::surf::on_cluster.connect(&clusterCreation_cb);
-  simgrid::surf::on_postparse.connect(&postparse_cb);
+  simgrid::s4u::onPlatformCreated.connect(&postparse_cb);
   simgrid::s4u::NetZone::onRouteCreation.connect(&routeCreation_cb);
 
   LogComponentEnable("UdpEchoClientApplication", ns3::LOG_LEVEL_INFO);
@@ -174,8 +173,8 @@ NetworkNS3Model::~NetworkNS3Model() {
   xbt_dict_free(&flowFromSock);
 }
 
-Link* NetworkNS3Model::createLink(const char* name, double bandwidth, double latency,
-                                  e_surf_link_sharing_policy_t policy)
+LinkImpl* NetworkNS3Model::createLink(const char* name, double bandwidth, double latency,
+                                      e_surf_link_sharing_policy_t policy)
 {
   return new LinkNS3(this, name, bandwidth, latency);
 }
@@ -232,7 +231,7 @@ void NetworkNS3Model::updateActionsState(double now, double delta)
         action->getState() == Action::State::running){
       double data_delta_sent = sgFlow->sentBytes_ - action->lastSent_;
 
-      std::vector<Link*> route = std::vector<Link*>();
+      std::vector<LinkImpl*> route = std::vector<LinkImpl*>();
 
       action->src_->routeTo(action->dst_, &route, nullptr);
       for (auto link : route)
@@ -265,12 +264,12 @@ void NetworkNS3Model::updateActionsState(double now, double delta)
  ************/
 
 LinkNS3::LinkNS3(NetworkNS3Model* model, const char* name, double bandwidth, double latency)
-    : Link(model, name, nullptr)
+    : LinkImpl(model, name, nullptr)
 {
   bandwidth_.peak = bandwidth;
   latency_.peak   = latency;
 
-  Link::onCreation(this);
+  LinkImpl::onCreation(this);
 }
 
 LinkNS3::~LinkNS3() = default;
@@ -299,7 +298,7 @@ NetworkNS3Action::NetworkNS3Action(Model* model, double size, s4u::Host* src, s4
   dst_ = dst;
   ns3_create_flow(src, dst, surf_get_clock(), size, this);
 
-  Link::onCommunicate(this, src, dst);
+  LinkImpl::onCommunicate(this, src, dst);
 }
 
 void NetworkNS3Action::suspend() {
@@ -343,8 +342,8 @@ void ns3_simulator(double maxSeconds)
 void ns3_create_flow(simgrid::s4u::Host* src, simgrid::s4u::Host* dst, double startTime, u_int32_t TotalBytes,
                      simgrid::surf::NetworkNS3Action* action)
 {
-  int node1 = src->pimpl_netcard->extension<NetCardNs3>()->node_num;
-  int node2 = dst->pimpl_netcard->extension<NetCardNs3>()->node_num;
+  int node1 = src->pimpl_netpoint->extension<NetPointNs3>()->node_num;
+  int node2 = dst->pimpl_netpoint->extension<NetPointNs3>()->node_num;
 
   ns3::Ptr<ns3::Node> src_node = nodes.Get(node1);
   ns3::Ptr<ns3::Node> dst_node = nodes.Get(node2);