Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #259 from simgrid/configfix
[simgrid.git] / src / surf / ns3 / ns3_simulator.hpp
1 /* Copyright (c) 2007-2018. 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
11 #include <ns3/node.h>
12 #include <ns3/tcp-socket-factory.h>
13
14 #include <cstdint>
15
16 namespace simgrid {
17 namespace surf {
18 class NetworkNS3Action;
19 }
20 } // namespace simgrid
21
22 class NetPointNs3 {
23 public:
24   static simgrid::xbt::Extension<simgrid::kernel::routing::NetPoint, NetPointNs3> EXTENSION_ID;
25
26   explicit NetPointNs3();
27   int node_num;
28   ns3::Ptr<ns3::Node> ns3Node_;
29 };
30
31 XBT_PUBLIC void ns3_initialize(std::string TcpProtocol);
32 extern "C" {
33 XBT_PUBLIC void ns3_simulator(double maxSeconds);
34 XBT_PUBLIC void ns3_add_link(NetPointNs3* src, NetPointNs3* dst, double bw, double lat);
35 XBT_PUBLIC void ns3_add_cluster(const char* id, double bw, double lat);
36 }
37
38 class XBT_PRIVATE SgFlow {
39 public:
40   SgFlow(uint32_t totalBytes, simgrid::surf::NetworkNS3Action* action);
41
42   // private:
43   std::uint32_t bufferedBytes_ = 0;
44   std::uint32_t sentBytes_     = 0;
45   std::uint32_t remaining_;
46   std::uint32_t totalBytes_;
47   bool finished_ = false;
48   simgrid::surf::NetworkNS3Action* action_;
49 };
50
51 void StartFlow(ns3::Ptr<ns3::Socket> sock, const char* to, uint16_t port_number);
52
53 static inline std::string transformSocketPtr(ns3::Ptr<ns3::Socket> localSocket)
54 {
55   std::stringstream sstream;
56   sstream << localSocket;
57   return sstream.str();
58 }
59
60 #endif