Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add model Reno, NewReno and Tahoe with ns3
authorNavarrop <Pierre.Navarro@imag.fr>
Thu, 8 Sep 2011 11:31:33 +0000 (13:31 +0200)
committerNavarrop <Pierre.Navarro@imag.fr>
Thu, 8 Sep 2011 11:31:51 +0000 (13:31 +0200)
--cfg=ns3/TcpModel:MODEL

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/surf.c
src/surf/surf_config.c

index 0d18ffd..095f401 100644 (file)
@@ -371,7 +371,8 @@ void surf_network_model_init_NS3(const char *filename)
        surf_network_model->extension.network.communicate = ns3_communicate;
 
        /* Added the initialization for NS3 interface */
-       if (ns3_initialize()) {
+
+       if (ns3_initialize(xbt_cfg_get_string(_surf_cfg_set,"ns3/TcpModel"))) {
        xbt_die("Impossible to initialize NS3 interface");
        }
 
index e89afd3..0640c95 100644 (file)
@@ -92,10 +92,38 @@ int ns3_finalize(void){
 }
 
 // initialize the NS3 interface and environment
-int ns3_initialize(void){
+int ns3_initialize(const char* TcpProtocol){
   xbt_assert(!ns3_sim, "ns3 already initialized");
   ns3_sim = new NS3Sim();
-  return 0;
+
+//  tcpModel are:
+//  "ns3::TcpNewReno"
+//  "ns3::TcpReno"
+//  "ns3::TcpTahoe"
+
+  Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); // 1000-byte packet for easier reading
+  Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1));
+
+  if(!strcmp(TcpProtocol,"default")){
+         return 0;
+  }
+  if(!strcmp(TcpProtocol,"Reno")){
+         XBT_INFO("Switching Tcp protocol to '%s'",TcpProtocol);
+         Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue("ns3::TcpReno"));
+         return 0;
+  }
+  if(!strcmp(TcpProtocol,"NewReno")){
+         XBT_INFO("Switching Tcp protocol to '%s'",TcpProtocol);
+         Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue("ns3::TcpNewReno"));
+         return 0;
+  }
+  if(!strcmp(TcpProtocol,"Tahoe")){
+         XBT_INFO("Switching Tcp protocol to '%s'",TcpProtocol);
+         Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue("ns3::TcpTahoe"));
+         return 0;
+  }
+
+  XBT_ERROR("The ns3/TcpModel must be : NewReno or Reno or Tahoe");
 }
 
 void * ns3_add_host(char * id)
index 0efbdfa..1eb29ea 100644 (file)
@@ -30,7 +30,7 @@ extern "C" {
 #endif
 
 XBT_PUBLIC(int)    ns3_finalize(void);
-XBT_PUBLIC(int)    ns3_initialize(void);
+XBT_PUBLIC(int)    ns3_initialize(const char* TcpProtocol);
 XBT_PUBLIC(int)    ns3_create_flow(const char* a,const char *b,double start,u_int32_t TotalBytes,void * action);
 XBT_PUBLIC(void)   ns3_simulator(double min);
 XBT_PUBLIC(double) ns3_time(void);
index 6c167db..91a21f0 100644 (file)
@@ -55,9 +55,14 @@ void NS3Sim::create_flow_NS3(
                void * action)
 {
        if(!dict_socket) dict_socket = xbt_dict_new();
-       PacketSinkHelper sink ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny(), port_number));
+
+       PacketSinkHelper sink ("ns3::TcpSocketFactory",
+                                                       InetSocketAddress (Ipv4Address::GetAny(),
+                                                       port_number));
        sink.Install (dst);
-       Ptr<Socket> sock = Socket::CreateSocket (src, TypeId::LookupByName ("ns3::TcpSocketFactory"));
+       Ptr<Socket> sock = Socket::CreateSocket (src,
+                                                       TcpSocketFactory::GetTypeId());
+
        MySocket *mysocket = new MySocket();
        mysocket->totalBytes = totalBytes;
        mysocket->remaining = totalBytes;
index 09c7ccd..8acdd35 100644 (file)
@@ -134,8 +134,8 @@ s_surf_model_description_t surf_network_model_description[] = {
 #endif
 #ifdef HAVE_NS3
   {"NS3",
-   "TODO",
-   NULL, surf_network_model_init_NS3},
+   "Use NS3 tcp model",
+       NULL, surf_network_model_init_NS3},
 #endif
   {"Reno",
    "Model using lagrange_solve instead of lmm_solve (experts only)", NULL,
index fbbfc7a..4cc63c8 100644 (file)
@@ -442,7 +442,13 @@ void surf_config_init(int *argc, char **argv)
                      xbt_cfgelm_int, &default_value_int, 0, 1,
                      _surf_cfg_cb__gtnets_jitter_seed, NULL);
 #endif
-
+#ifdef HAVE_NS3
+    xbt_cfg_register(&_surf_cfg_set, "ns3/TcpModel",
+                     "The ns3 tcp model can be : NewReno or Reno or Tahoe",
+                     xbt_cfgelm_string, NULL, 1, 1,
+                     NULL, NULL);
+    xbt_cfg_setdefault_string(_surf_cfg_set, "ns3/TcpModel", "default");
+#endif
     if (!surf_path) {
       /* retrieves the current directory of the        current process */
       const char *initial_path = __surf_get_initial_path();