From 84b6ab29e2861d096c8d500c6bd56289bfe90664 Mon Sep 17 00:00:00 2001 From: Navarrop Date: Thu, 8 Sep 2011 13:31:33 +0200 Subject: [PATCH 1/1] Add model Reno, NewReno and Tahoe with ns3 --cfg=ns3/TcpModel:MODEL --- src/surf/network_ns3.c | 3 ++- src/surf/ns3/ns3_interface.cc | 32 ++++++++++++++++++++++++++++++-- src/surf/ns3/ns3_interface.h | 2 +- src/surf/ns3/ns3_simulator.cc | 9 +++++++-- src/surf/surf.c | 4 ++-- src/surf/surf_config.c | 8 +++++++- 6 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/surf/network_ns3.c b/src/surf/network_ns3.c index 0d18ffd378..095f401d92 100644 --- a/src/surf/network_ns3.c +++ b/src/surf/network_ns3.c @@ -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"); } diff --git a/src/surf/ns3/ns3_interface.cc b/src/surf/ns3/ns3_interface.cc index e89afd37fe..0640c954f0 100644 --- a/src/surf/ns3/ns3_interface.cc +++ b/src/surf/ns3/ns3_interface.cc @@ -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) diff --git a/src/surf/ns3/ns3_interface.h b/src/surf/ns3/ns3_interface.h index 0efbdfa90e..1eb29ea2e7 100644 --- a/src/surf/ns3/ns3_interface.h +++ b/src/surf/ns3/ns3_interface.h @@ -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); diff --git a/src/surf/ns3/ns3_simulator.cc b/src/surf/ns3/ns3_simulator.cc index 6c167db7da..91a21f094c 100644 --- a/src/surf/ns3/ns3_simulator.cc +++ b/src/surf/ns3/ns3_simulator.cc @@ -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 sock = Socket::CreateSocket (src, TypeId::LookupByName ("ns3::TcpSocketFactory")); + Ptr sock = Socket::CreateSocket (src, + TcpSocketFactory::GetTypeId()); + MySocket *mysocket = new MySocket(); mysocket->totalBytes = totalBytes; mysocket->remaining = totalBytes; diff --git a/src/surf/surf.c b/src/surf/surf.c index 09c7ccd220..8acdd3576f 100644 --- a/src/surf/surf.c +++ b/src/surf/surf.c @@ -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, diff --git a/src/surf/surf_config.c b/src/surf/surf_config.c index fbbfc7aebf..4cc63c8852 100644 --- a/src/surf/surf_config.c +++ b/src/surf/surf_config.c @@ -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(); -- 2.20.1