From cc59c899f56e8837af3c157f91b6b35b8370c13d Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 20 May 2023 23:46:51 +0200 Subject: [PATCH] Rename cfg 'ns3/TcpModel' to 'ns3/UdpModel' --- docs/source/Configuring_SimGrid.rst | 10 ++-- .../network-ns3/s4u-network-ns3-timed.tesh | 16 +++++-- src/kernel/resource/models/network_ns3.cpp | 46 +++++++++++++------ .../resource/models/ns3/ns3_simulator.cpp | 10 ++-- .../resource/models/ns3/ns3_simulator.hpp | 6 ++- 5 files changed, 56 insertions(+), 32 deletions(-) diff --git a/docs/source/Configuring_SimGrid.rst b/docs/source/Configuring_SimGrid.rst index b0167728db..45a12bce01 100644 --- a/docs/source/Configuring_SimGrid.rst +++ b/docs/source/Configuring_SimGrid.rst @@ -547,12 +547,12 @@ are meant to be detached as well. Configuring ns-3 ^^^^^^^^^^^^^^^^ -**Option** ``ns3/TcpModel`` **Default:** "default" (ns-3 default) +**Option** ``ns3/NetworkModel`` **Default:** "default" (ns-3 default TCP) -When using ns-3, there is an extra item ``ns3/TcpModel``, corresponding -to the ``ns3::TcpL4Protocol::SocketType`` configuration item in -ns-3. The only valid values (enforced on the SimGrid side) are -'default' (no change to the ns-3 configuration), 'NewReno' or 'Cubic'. +When using ns-3, the item ``ns3/NetworkModel`` can be used to switch between TCP or UDP, and switch the used TCP variante. If +the item is left unchanged, ns-3 uses the default TCP implementation. With a value of "UDP", ns-3 is set to use UDP instead. +With the value of either 'NewReno' or 'Cubic', the ``ns3::TcpL4Protocol::SocketType`` configuration item in ns-3 is set to the +corresponding protocol. **Option** ``ns3/seed`` **Default:** "" (don't set the seed in ns-3) diff --git a/examples/cpp/network-ns3/s4u-network-ns3-timed.tesh b/examples/cpp/network-ns3/s4u-network-ns3-timed.tesh index 44178b881d..23ec6c55de 100644 --- a/examples/cpp/network-ns3/s4u-network-ns3-timed.tesh +++ b/examples/cpp/network-ns3/s4u-network-ns3-timed.tesh @@ -48,20 +48,28 @@ $ ${bindir:=.}/s4u-network-ns3 ${platfdir}/onelink.xml ${srcdir}/onelink_d.xml - p 2hosts 1link NewReno (no timing change) -$ ${bindir:=.}/s4u-network-ns3 ${platfdir}/onelink.xml ${srcdir}/onelink_d.xml --cfg=network/model:ns-3 --cfg=ns3/TcpModel:NewReno "--log=root.fmt:[%h:%a(%i)%e%r]%e[%c/%p]%e%m%n" +$ ${bindir:=.}/s4u-network-ns3 ${platfdir}/onelink.xml ${srcdir}/onelink_d.xml --cfg=network/model:ns-3 --cfg=ns3/NetworkModel:NewReno "--log=root.fmt:[%h:%a(%i)%e%r]%e[%c/%p]%e%m%n" > [:maestro(0) 0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'ns-3' -> [:maestro(0) 0.000000] [xbt_cfg/INFO] Configuration change: Set 'ns3/TcpModel' to 'NewReno' +> [:maestro(0) 0.000000] [xbt_cfg/INFO] Configuration change: Set 'ns3/NetworkModel' to 'NewReno' > [:maestro(0) 0.000000] [res_ns3/INFO] Switching Tcp protocol to 'NewReno' > [C1:worker(2) 1.104600] [s4u_test/INFO] FLOW[1] : Receive 10000 bytes from S1 to C1 p 2hosts 1link Cubic (no timing change) -$ ${bindir:=.}/s4u-network-ns3 ${platfdir}/onelink.xml ${srcdir}/onelink_d.xml --cfg=network/model:ns-3 --cfg=ns3/TcpModel:Cubic "--log=root.fmt:[%h:%a(%i)%e%r]%e[%c/%p]%e%m%n" +$ ${bindir:=.}/s4u-network-ns3 ${platfdir}/onelink.xml ${srcdir}/onelink_d.xml --cfg=network/model:ns-3 --cfg=ns3/NetworkModel:Cubic "--log=root.fmt:[%h:%a(%i)%e%r]%e[%c/%p]%e%m%n" > [:maestro(0) 0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'ns-3' -> [:maestro(0) 0.000000] [xbt_cfg/INFO] Configuration change: Set 'ns3/TcpModel' to 'Cubic' +> [:maestro(0) 0.000000] [xbt_cfg/INFO] Configuration change: Set 'ns3/NetworkModel' to 'Cubic' > [:maestro(0) 0.000000] [res_ns3/INFO] Switching Tcp protocol to 'Cubic' > [C1:worker(2) 1.104600] [s4u_test/INFO] FLOW[1] : Receive 10000 bytes from S1 to C1 +p 2hosts 1link UDP + +# $ ${bindir:=.}/s4u-network-ns3 ${platfdir}/onelink.xml ${srcdir}/onelink_d.xml --cfg=network/model:ns-3 --cfg=ns3/NetworkModel:UDP "--log=root.fmt:[%h:%a(%i)%e%r]%e[%c/%p]%e%m%n" +# > [:maestro(0) 0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'ns-3' +# > [:maestro(0) 0.000000] [xbt_cfg/INFO] Configuration change: Set 'ns3/NetworkModel' to 'UDP' +# > [:maestro(0) 0.000000] [res_ns3/INFO] Switching network protocol to 'UDP' +# > [C1:worker(2) 1.104600] [s4u_test/INFO] FLOW[1] : Receive 10000 bytes from S1 to C1 + p Crosstraffic TCP option DISABLED $ ${bindir:=.}/s4u-network-ns3 ${platfdir}/crosstraffic.xml ${srcdir}/crosstraffic_d.xml --cfg=network/model:ns-3 --cfg=network/crosstraffic:0 > [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'ns-3' diff --git a/src/kernel/resource/models/network_ns3.cpp b/src/kernel/resource/models/network_ns3.cpp index de4b36e3f2..2d316939b4 100644 --- a/src/kernel/resource/models/network_ns3.cpp +++ b/src/kernel/resource/models/network_ns3.cpp @@ -288,9 +288,9 @@ static void XBT_ATTRIB_CONSTRUCTOR(800) simgrid_ns3_network_model_register() }); } -static simgrid::config::Flag ns3_tcp_model( - "ns3/TcpModel", - "The ns-3 tcp model can be: NewReno or Cubic", "default"); +static simgrid::config::Flag ns3_network_model_name("ns3/NetworkModel", {"ns3/TcpModel"}, + "The ns-3 tcp model can be: NewReno or Cubic", + "default", [](const std::string&) {}); static simgrid::config::Flag ns3_seed( "ns3/seed", "The random seed provided to ns-3. Either 'time' to seed with time(), blank to not set (default), or a number.", "", @@ -318,20 +318,34 @@ NetworkNS3Model::NetworkNS3Model(const std::string& name) : NetworkModel(name) "LinkEnergy plugin and ns-3 network models are not compatible. Are you looking for Ecofen, maybe?"); NetPointNs3::EXTENSION_ID = routing::NetPoint::extension_create(); - auto const& TcpProtocol = ns3_tcp_model.get(); - - if (TcpProtocol != "UDP") { + auto const& NetworkProtocol = ns3_network_model_name.get(); + + if (NetworkProtocol == "UDP") { + /*UdpClient=0 +UdpEchoClientApplication=0 +UdpEchoServerApplication=0 +UdpL4Protocol=0 +UdpServer=0 +UdpSocket=0 +UdpSocketImpl=0 +UdpTraceClient=0*/ + LogComponentEnable("UdpSocket", ns3::LOG_LEVEL_DEBUG); + LogComponentEnable("UdpL4Protocol", ns3::LOG_LEVEL_DEBUG); + } else { ns3::Config::SetDefault("ns3::TcpSocket::SegmentSize", ns3::UintegerValue(1000)); ns3::Config::SetDefault("ns3::TcpSocket::DelAckCount", ns3::UintegerValue(1)); ns3::Config::SetDefault("ns3::TcpSocketBase::Timestamp", ns3::BooleanValue(false)); } - if (TcpProtocol == "NewReno" || TcpProtocol == "Cubic") { - XBT_INFO("Switching Tcp protocol to '%s'", TcpProtocol.c_str()); - ns3::Config::SetDefault("ns3::TcpL4Protocol::SocketType", ns3::StringValue("ns3::Tcp" + TcpProtocol)); + if (NetworkProtocol == "NewReno" || NetworkProtocol == "Cubic") { + XBT_INFO("Switching Tcp protocol to '%s'", NetworkProtocol.c_str()); + ns3::Config::SetDefault("ns3::TcpL4Protocol::SocketType", ns3::StringValue("ns3::Tcp" + NetworkProtocol)); - } else if (TcpProtocol != "default") { - xbt_die("The ns3/TcpModel must be: NewReno or Cubic"); + } else if (NetworkProtocol == "UDP") { + XBT_INFO("Switching network protocol to UDP."); + + } else if (NetworkProtocol != "default") { + xbt_die("The ns3/NetworkModel must be: NewReno, Cubic or UDP but it's '%s'", NetworkProtocol.c_str()); } routing::NetPoint::on_creation.connect([](routing::NetPoint& pt) { @@ -576,13 +590,15 @@ NetworkNS3Action::NetworkNS3Action(Model* model, double totalBytes, s4u::Host* s ns3::Ptr sock = ns3::Socket::CreateSocket(src_node, ns3::TcpSocketFactory::GetTypeId()); - XBT_DEBUG("Create socket %s for a flow of %.0f Bytes from %s to %s with Interface %s", - transform_socket_ptr(sock).c_str(), totalBytes, src->get_cname(), dst->get_cname(), addr.c_str()); + auto sock_addr = transform_socket_ptr(sock); + XBT_DEBUG("Create socket %s for a flow of %.0f Bytes from %s to %s with Interface %s", sock_addr.c_str(), totalBytes, + src->get_cname(), dst->get_cname(), addr.c_str()); - flow_from_sock.try_emplace(transform_socket_ptr(sock), new SgFlow(static_cast(totalBytes), this)); - sink_from_sock.try_emplace(transform_socket_ptr(sock), apps); + flow_from_sock.try_emplace(sock_addr, new SgFlow(static_cast(totalBytes), this)); + sink_from_sock.try_emplace(sock_addr, apps); sock->Bind(ns3::InetSocketAddress(port_number)); + ns3::Simulator::ScheduleNow(&start_flow, sock, addr.c_str(), port_number); port_number = 1 + (port_number % UINT16_MAX); diff --git a/src/kernel/resource/models/ns3/ns3_simulator.cpp b/src/kernel/resource/models/ns3/ns3_simulator.cpp index 0c13eab9e2..72cdaa16c3 100644 --- a/src/kernel/resource/models/ns3/ns3_simulator.cpp +++ b/src/kernel/resource/models/ns3/ns3_simulator.cpp @@ -25,11 +25,6 @@ static void datasent_cb(ns3::Ptr socket, uint32_t dataSent); XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_ns3); -SgFlow::SgFlow(uint32_t totalBytes, simgrid::kernel::resource::NetworkNS3Action* action) - : total_bytes_(totalBytes), remaining_(totalBytes), action_(action) -{ -} - static SgFlow* getFlowFromSocket(ns3::Ptr socket) { auto it = flow_from_sock.find(transform_socket_ptr(socket)); @@ -141,10 +136,11 @@ XBT_ATTRIB_NORETURN static void failedConnect_callback(ns3::Ptr soc void start_flow(ns3::Ptr sock, const char* to, uint16_t port_number) { SgFlow* flow = getFlowFromSocket(sock); - ns3::InetSocketAddress serverAddr(to, port_number); + ns3::InetSocketAddress serverAddr(to, port_number); sock->Connect(serverAddr); - // tell the tcp implementation to call send_cb again + + // tell the network implementation to call send_cb again // if we blocked and new tx buffer space becomes available sock->SetSendCallback(MakeCallback(&send_cb)); // Notice when we actually sent some data (mostly for the TRACING module) diff --git a/src/kernel/resource/models/ns3/ns3_simulator.hpp b/src/kernel/resource/models/ns3/ns3_simulator.hpp index 375b6bba40..d7e35a43a7 100644 --- a/src/kernel/resource/models/ns3/ns3_simulator.hpp +++ b/src/kernel/resource/models/ns3/ns3_simulator.hpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -31,7 +32,10 @@ XBT_PRIVATE void ns3_add_direct_route(const simgrid::kernel::routing::NetPoint* class XBT_PRIVATE SgFlow { public: - SgFlow(uint32_t total_bytes, simgrid::kernel::resource::NetworkNS3Action* action); + SgFlow(uint32_t totalBytes, simgrid::kernel::resource::NetworkNS3Action* action) + : total_bytes_(totalBytes), remaining_(totalBytes), action_(action) + { + } // private: std::uint32_t buffered_bytes_ = 0; -- 2.20.1