Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / kernel / resource / models / ns3 / ns3_simulator.hpp
1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef NS3_SIMULATOR_HPP
7 #define NS3_SIMULATOR_HPP
8
9 #include "simgrid/s4u/Host.hpp"
10 #include "src/kernel/resource/models/network_ns3.hpp"
11
12 #include <ns3/node.h>
13 #include <ns3/tcp-socket-factory.h>
14 #include <ns3/udp-socket-factory.h>
15 #include <ns3/wifi-module.h>
16
17 #include <cstdint>
18
19 class XBT_PRIVATE NetPointNs3 {
20 public:
21   static simgrid::xbt::Extension<simgrid::kernel::routing::NetPoint, NetPointNs3> EXTENSION_ID;
22
23   explicit NetPointNs3();
24   ns3::Ptr<ns3::Node> ns3_node_ = ns3::CreateObject<ns3::Node>(0);
25   std::string ipv4_address_;
26 };
27
28 XBT_PRIVATE void ns3_simulator(double max_seconds);
29 XBT_PRIVATE void ns3_add_direct_route(const simgrid::kernel::routing::NetPoint* src,
30                                       const simgrid::kernel::routing::NetPoint* dst, double bw, double lat,
31                                       simgrid::s4u::Link::SharingPolicy policy);
32
33 class XBT_PRIVATE SgFlow {
34 public:
35   SgFlow(uint32_t totalBytes, simgrid::kernel::resource::NetworkNS3Action* action)
36       : total_bytes_(totalBytes), remaining_(totalBytes), action_(action)
37   {
38   }
39
40   // private:
41   std::uint32_t buffered_bytes_ = 0;
42   std::uint32_t sent_bytes_     = 0;
43   std::uint32_t total_bytes_;
44   std::uint32_t remaining_;
45   bool finished_ = false;
46   simgrid::kernel::resource::NetworkNS3Action* action_;
47 };
48
49 XBT_PRIVATE void start_flow(ns3::Ptr<ns3::Socket> sock, const char* to, uint16_t port_number);
50
51 static inline std::string transform_socket_ptr(ns3::Ptr<ns3::Socket> local_socket)
52 {
53   std::stringstream sstream;
54   sstream << local_socket;
55   return sstream.str();
56 }
57
58 #endif