Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill the useless NS3Sim class
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 25 Mar 2016 14:41:49 +0000 (15:41 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 25 Mar 2016 14:57:41 +0000 (15:57 +0100)
Instead, inline its methods that were static anyway. I guess it's a
remaining of the C->C++ interface

src/surf/network_ns3.cpp
src/surf/ns3/ns3_simulator.cc
src/surf/ns3/ns3_simulator.h

index 5137477..d8f4ba7 100644 (file)
@@ -44,9 +44,6 @@ 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
 
-static NS3Sim* ns3_sim = 0;
-
-
 /*************
  * Callbacks *
  *************/
@@ -237,7 +234,6 @@ NetworkNS3Model::NetworkNS3Model() : NetworkModel() {
 }
 
 NetworkNS3Model::~NetworkNS3Model() {
-  delete ns3_sim;
   xbt_dynar_free_container(&IPV4addr);
   xbt_dict_free(&flowFromSock);
 }
@@ -408,14 +404,14 @@ int NetworkNS3Action::unref()
 }
 
 
-
-
-
 void ns3_simulator(double min){
-  ns3_sim->simulator_start(min);
+  if (min > 0.0) // If there is a maximum amount of time to run
+    ns3::Simulator::Stop(ns3::Seconds(min));
+  XBT_DEBUG("Start simulator for at most %fs",min);
+  ns3::Simulator::Run ();
 }
 
-void ns3_create_flow(const char* a,const char *b,double start,u_int32_t TotalBytes,simgrid::surf::NetworkNS3Action * action)
+void ns3_create_flow(const char* a,const char *b,double startTime,u_int32_t TotalBytes,simgrid::surf::NetworkNS3Action * action)
 {
   int node1 = ns3_find_host(a)->node_num;
   int node2 = ns3_find_host(b)->node_num;
@@ -426,7 +422,19 @@ void ns3_create_flow(const char* a,const char *b,double start,u_int32_t TotalByt
   char* addr = (char*)xbt_dynar_get_as(IPV4addr,node2,char*);
 
   XBT_DEBUG("ns3_create_flow %d Bytes from %d to %d with Interface %s",TotalBytes, node1, node2,addr);
-  ns3_sim->create_flow_NS3(src_node, dst_node, port_number, start, addr, TotalBytes, action);
+  ns3::PacketSinkHelper sink("ns3::TcpSocketFactory", ns3::InetSocketAddress (ns3::Ipv4Address::GetAny(), port_number));
+  sink.Install (dst_node);
+
+  ns3::Ptr<ns3::Socket> sock = ns3::Socket::CreateSocket (src_node, ns3::TcpSocketFactory::GetTypeId());
+
+  xbt_dict_set(flowFromSock, transformSocketPtr(sock), new SgFlow(TotalBytes, action), NULL);
+
+  sock->Bind(ns3::InetSocketAddress(port_number));
+  XBT_DEBUG("Create flow starting to %fs + %fs = %fs",
+      startTime-ns3::Simulator::Now().GetSeconds(), ns3::Simulator::Now().GetSeconds(), startTime);
+
+  ns3::Simulator::Schedule (ns3::Seconds(startTime-ns3::Simulator::Now().GetSeconds()),
+      &StartFlow, sock, addr, port_number);
 
   port_number++;
   xbt_assert(port_number <= 65000, "Too many connections! Port number is saturated.");
@@ -434,9 +442,6 @@ void ns3_create_flow(const char* a,const char *b,double start,u_int32_t TotalByt
 
 // initialize the NS3 interface and environment
 void ns3_initialize(const char* TcpProtocol){
-  xbt_assert(!ns3_sim, "ns3 already initialized");
-  ns3_sim = new NS3Sim();
-
 //  tcpModel are:
 //  "ns3::TcpNewReno"
 //  "ns3::TcpReno"
index b4b76d4..e7b3382 100644 (file)
@@ -18,64 +18,14 @@ xbt_dict_t flowFromSock = xbt_dict_new_homogeneous(delete_mysocket);; // ns3::so
 static void receive_callback(ns3::Ptr<ns3::Socket> socket);
 static void send_callback(ns3::Ptr<ns3::Socket> sock, uint32_t txSpace);
 static void datasent_callback(ns3::Ptr<ns3::Socket> socket, uint32_t dataSent);
-static void StartFlow(ns3::Ptr<ns3::Socket> sock, const char *to, uint16_t port_number);
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ns3);
 
-NS3Sim::NS3Sim(){
-}
-
-static inline const char *transformSocketPtr (ns3::Ptr<ns3::Socket> localSocket)
-{
-  static char key[24];
-  std::stringstream sstream;
-  sstream << localSocket ;
-  sprintf(key,"%s",sstream.str().c_str());
-
-  return key;
-}
-
 SgFlow::SgFlow(uint32_t totalBytes, simgrid::surf::NetworkNS3Action * action) {
   totalBytes_ = totalBytes;
   remaining_ = totalBytes;
   action_ = action;
 }
-/*
- * This function creates a flow from src to dst
- *
- * Parameters
- *             src: node source
- *             dst: node destination
- *             port_number: The port number to use
- *             start: the time the communication start
- *             addr:  ip address
- *             totalBytes: number of bytes to transmit
- */
-void NS3Sim::create_flow_NS3(ns3::Ptr<ns3::Node> src, ns3::Ptr<ns3::Node> dst, uint16_t port_number,
-               double startTime, const char *ipAddr, uint32_t totalBytes,
-               simgrid::surf::NetworkNS3Action * action)
-{
-       ns3::PacketSinkHelper sink("ns3::TcpSocketFactory", ns3::InetSocketAddress (ns3::Ipv4Address::GetAny(), port_number));
-       sink.Install (dst);
-
-       ns3::Ptr<ns3::Socket> sock = ns3::Socket::CreateSocket (src, ns3::TcpSocketFactory::GetTypeId());
-
-       xbt_dict_set(flowFromSock, transformSocketPtr(sock), new SgFlow(totalBytes, action), NULL);
-
-       sock->Bind(ns3::InetSocketAddress(port_number));
-       XBT_DEBUG("Create flow starting to %fs + %fs = %fs",
-           startTime-ns3::Simulator::Now().GetSeconds(), ns3::Simulator::Now().GetSeconds(), startTime);
-
-       ns3::Simulator::Schedule (ns3::Seconds(startTime-ns3::Simulator::Now().GetSeconds()),
-           &StartFlow, sock, ipAddr, port_number);
-}
-
-void NS3Sim::simulator_start(double min){
-  if(min > 0.0)
-    ns3::Simulator::Stop(ns3::Seconds(min));
-  XBT_DEBUG("Start simulator '%f'",min);
-  ns3::Simulator::Run ();
-}
 
 static SgFlow* getFlowFromSocket(ns3::Ptr<ns3::Socket> socket) {
        return (SgFlow*)xbt_dict_get_or_null(flowFromSock, transformSocketPtr(socket));
@@ -149,7 +99,7 @@ static void failedConnect_callback(ns3::Ptr<ns3::Socket> socket){
   xbt_die("NS3: a socket failed to connect");
 }
 
-static void StartFlow(ns3::Ptr<ns3::Socket> sock, const char *to, uint16_t port_number)
+void StartFlow(ns3::Ptr<ns3::Socket> sock, const char *to, uint16_t port_number)
 {
   ns3::InetSocketAddress serverAddr (to, port_number);
 
index 89c10d2..8cec673 100644 (file)
@@ -37,22 +37,17 @@ public:
   simgrid::surf::NetworkNS3Action* action_;
 };
 
-//Simulator s;
-class NS3Sim {
+void StartFlow(ns3::Ptr<ns3::Socket> sock, const char *to, uint16_t port_number);
 
-private:
+static inline const char *transformSocketPtr (ns3::Ptr<ns3::Socket> localSocket)
+{
+  static char key[24];
+  std::stringstream sstream;
+  sstream << localSocket ;
+  sprintf(key,"%s",sstream.str().c_str());
 
-public:
-  NS3Sim();
-  void create_flow_NS3(ns3::Ptr<ns3::Node> src,
-            ns3::Ptr<ns3::Node> dst,
-            std::uint16_t port_number,
-            double start,
-            const char *addr,
-            std::uint32_t TotalBytes,
-            simgrid::surf::NetworkNS3Action * action);
-  void simulator_start(double min);
-};
+  return key;
+}
 
 #endif                          /* __cplusplus */