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)
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'
});
}
-static simgrid::config::Flag<std::string> ns3_tcp_model(
- "ns3/TcpModel",
- "The ns-3 tcp model can be: NewReno or Cubic", "default");
+static simgrid::config::Flag<std::string> 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<std::string> 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.", "",
"LinkEnergy plugin and ns-3 network models are not compatible. Are you looking for Ecofen, maybe?");
NetPointNs3::EXTENSION_ID = routing::NetPoint::extension_create<NetPointNs3>();
- 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) {
ns3::Ptr<ns3::Socket> 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<uint32_t>(totalBytes), this));
- sink_from_sock.try_emplace(transform_socket_ptr(sock), apps);
+ flow_from_sock.try_emplace(sock_addr, new SgFlow(static_cast<uint32_t>(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);
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<ns3::Socket> socket)
{
auto it = flow_from_sock.find(transform_socket_ptr(socket));
void start_flow(ns3::Ptr<ns3::Socket> 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)
#include <ns3/node.h>
#include <ns3/tcp-socket-factory.h>
+#include <ns3/udp-socket-factory.h>
#include <ns3/wifi-module.h>
#include <cstdint>
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;