A Discrete-Event Network Simulator
API
outputmanager.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 
3 
4 /*
5 * Copyright (c) 2020 DLTLT
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation;
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Corresponding author: Niki Hrovatin <niki.hrovatin@famnit.upr.si>
21 */
22 
23 
24 #ifndef OUTPUTMANAGER_H
25 #define OUTPUTMANAGER_H
26 
27 #include <iostream>
28 #include <fstream>
29 #include <string>
30 #include <fstream>
31 #include "ns3/core-module.h"
32 #include <vector>
33 #include "ns3/output-stream-wrapper.h"
34 #include "ns3/internet-module.h"
35 #include <time.h>
36 #include "ns3/enums.h"
37 #include <experimental/filesystem>
38 
39 namespace ns3 {
40 
49 class OutputManager : public Object
50 {
51 
52 public:
58  OutputManager ();
59 
66  OutputManager (std::string name, uint16_t simNum, uint16_t numNodes, enum Topology, enum Routing,
67  bool printDescription);
68 
74  ~OutputManager ();
75 
76 
83  void CreateOutputFile ();
84 
89  static TypeId GetTypeId (void);
90 
96  void PrintIntro (std::string intro);
102  void SimulationEnd (std::string end_at);
103 
109  void SendOnion (int packet_size, int head_size, int body_size, int onion_path_len, Time sent_at);
115  void RecvOnion (Time recv_at);
116 
122  void AbortOnion (Time abort_at);
123 
129  void NewHandshake (int node_num, Ipv4Address node_ip, Time recv_at);
130 
136  void OnionRoutingSend (Ipv4Address send_ip, Ipv4Address recv_ip, int packet_size, int head_size,
137  int body_size, Time sent_at);
138 
144  void OnionRoutingRecv (Time recv_at);
145 
151  void PrintLine (std::string line);
152 
158  std::string Ipv4ToString (Ipv4Address ip);
159 
165  std::string CurrentTime (void);
166 
172  void AddNodeDetails (Ipv4Address node_ip, int coord_x, int coord_y);
173 
180  void AddNodeDetails (Ipv4Address node_ip, int coord_x, int coord_y, int n_degree);
181 
190  void PrintNodeDetails (std::map<uint32_t, std::string> reachable);
191 
197  enum Routing GetRouting (void);
198 
204  void SetRouting (enum Routing routing);
205 
206  Ptr<OutputStreamWrapper> m_simStreamWrapper;
207 
209 
210  std::string m_simName;
211 
212  std::string m_simDetails;
213 
214  //HEADERS
215  std::string h_onionHeader =
216  "onion_details,sim_name,sim_num,num_of_nodes,topology,routing,onion_"
217  "id,packet_size,onion_head_size,onion_body_size,onion_"
218  "path_length,sent_at,recv_at,query_time_to_return";
219  std::string h_routingHeader = "onion_routing,sim_name,sim_num,num_of_nodes,topology,routing,"
220  "onion_id,send_ip,recv_ip,packet_size,onion_head_size,onion_body_"
221  "size,sent_at,recv_at,hop_time";
222  std::string h_timeoutHeader = "timeout,sim_name,sim_num,num_of_nodes,topology,routing,onion_id,"
223  "onion_path_length,abort_time";
224  std::string h_nodeDetailsHeader = "node_details,sim_name,sim_num,num_of_nodes,topology,routing,"
225  "coord_x,coord_y,node_degree";
226 
227  //reference to the onion we are executing
228  std::string m_onionData;
229  std::string m_routingData;
230  std::string m_routingLog;
231  int m_onionId = 0;
233 
234  double t_onionDelta = 0;
235  double t_hopDelta = 0;
236 
238 
239  std::map<uint32_t,std::string>
241 
242  std::string m_outputFilePath;
243 };
244 
245 } // namespace ns3
246 
247 #endif /* OUTPUTMANAGER_H */
ns3::OutputManager::h_onionHeader
std::string h_onionHeader
header of CSV format
Definition: outputmanager.h:215
ns3::OutputManager::OutputManager
OutputManager()
Default constructor.
Definition: outputmanager.cc:47
ns3::OutputManager::SimulationEnd
void SimulationEnd(std::string end_at)
Print at the end of the simulation.
Definition: outputmanager.cc:126
ns3::OutputManager::OnionRoutingSend
void OnionRoutingSend(Ipv4Address send_ip, Ipv4Address recv_ip, int packet_size, int head_size, int body_size, Time sent_at)
Called by each node that sends an onion message.
Definition: outputmanager.cc:167
ns3::OutputManager::m_onionId
int m_onionId
identifies the onion message
Definition: outputmanager.h:231
ns3
Definition: sensornode-helper.cc:26
ns3::OutputManager::OnionRoutingRecv
void OnionRoutingRecv(Time recv_at)
Called by each node that receives an onion message.
Definition: outputmanager.cc:185
ns3::OutputManager::AddNodeDetails
void AddNodeDetails(Ipv4Address node_ip, int coord_x, int coord_y)
register node details: IP, location on the network
Definition: outputmanager.cc:217
ns3::OutputManager::SendOnion
void SendOnion(int packet_size, int head_size, int body_size, int onion_path_len, Time sent_at)
Called by the sink node when it sends a new onion message.
Definition: outputmanager.cc:135
ns3::OutputManager::CreateOutputFile
void CreateOutputFile()
Create stream wrapper and the output file, if the output file already exists, then delete the content...
Definition: outputmanager.cc:91
ns3::OutputManager::Ipv4ToString
std::string Ipv4ToString(Ipv4Address ip)
Convert an IpV4 address to a string.
Definition: outputmanager.cc:254
ns3::OutputManager::m_simDetails
std::string m_simDetails
holds details of the simulation
Definition: outputmanager.h:212
ns3::OutputManager
Class that manages the output of the simulation. ConsoleLog output and Output on ....
Definition: outputmanager.h:49
ns3::OutputManager::m_routingLog
std::string m_routingLog
holds data of the onion message traveling from hop to hop
Definition: outputmanager.h:230
ns3::OutputManager::PrintLine
void PrintLine(std::string line)
print the given argument on the csv file
Definition: outputmanager.cc:247
ns3::OutputManager::h_routingHeader
std::string h_routingHeader
header of CSV format
Definition: outputmanager.h:219
ns3::OutputManager::CurrentTime
std::string CurrentTime(void)
return the current time as a string
Definition: outputmanager.cc:262
ns3::OutputManager::m_onionData
std::string m_onionData
holds data of the onion message currently executing in the network
Definition: outputmanager.h:228
ns3::OutputManager::m_onionPathLength
int m_onionPathLength
the onion path length
Definition: outputmanager.h:232
ns3::OutputManager::m_printDescription
bool m_printDescription
boolean choice to print the description of the simulation parameters
Definition: outputmanager.h:208
ns3::OutputManager::PrintIntro
void PrintIntro(std::string intro)
Print the simulation description containing simulation settings on the csv file or on the console log...
Definition: outputmanager.cc:106
ns3::OutputManager::AbortOnion
void AbortOnion(Time abort_at)
Called when an onion is deleted.
Definition: outputmanager.cc:197
ns3::OutputManager::m_routingData
std::string m_routingData
holds data of the onion message traveling from hop to hop
Definition: outputmanager.h:229
ns3::OutputManager::GetTypeId
static TypeId GetTypeId(void)
Register this type.
Definition: outputmanager.cc:34
ns3::OutputManager::PrintNodeDetails
void PrintNodeDetails(std::map< uint32_t, std::string > reachable)
print node details on the csv file, print only nodes reachable by the sink node
Definition: outputmanager.cc:235
ns3::Topology
Topology
Enumeration defining different network topologies that can be used in the simulation.
Definition: enums.h:55
ns3::OutputManager::NewHandshake
void NewHandshake(int node_num, Ipv4Address node_ip, Time recv_at)
Called when the sink receives a new handhake message.
Definition: outputmanager.cc:210
ns3::OutputManager::t_onionDelta
double t_onionDelta
Hold time information of the onion message traveling in the network.
Definition: outputmanager.h:234
ns3::OutputManager::RecvOnion
void RecvOnion(Time recv_at)
Called by the sink node when it receives back the onion message.
Definition: outputmanager.cc:154
ns3::OutputManager::m_simName
std::string m_simName
holds the name of the simulation
Definition: outputmanager.h:210
ns3::OutputManager::m_routing
enum Routing m_routing
information on the routing protocol
Definition: outputmanager.h:237
ns3::OutputManager::m_nodeDetails
std::map< uint32_t, std::string > m_nodeDetails
holds details of nodes in the network for printing at the end of the csv file.
Definition: outputmanager.h:240
ns3::OutputManager::SetRouting
void SetRouting(enum Routing routing)
set the enum of the current routing algorithm used in the network
Definition: outputmanager.cc:270
ns3::OutputManager::GetRouting
enum Routing GetRouting(void)
return the enum of the current routing algorithm used in the network
Definition: outputmanager.cc:276
ns3::OutputManager::h_timeoutHeader
std::string h_timeoutHeader
header of CSV format
Definition: outputmanager.h:222
ns3::Routing
Routing
Enumeration defining different routing algorithms that can be used in the simulator.
Definition: enums.h:41
ns3::OutputManager::m_simStreamWrapper
Ptr< OutputStreamWrapper > m_simStreamWrapper
stream wrapper to write on file
Definition: outputmanager.h:206
ns3::OutputManager::~OutputManager
~OutputManager()
Default destructor.
Definition: outputmanager.cc:101
ns3::OutputManager::m_outputFilePath
std::string m_outputFilePath
path to the directory where output files are stored
Definition: outputmanager.h:242
ns3::OutputManager::t_hopDelta
double t_hopDelta
Hold time information of the onion message traveling from hop to hop.
Definition: outputmanager.h:235
ns3::OutputManager::h_nodeDetailsHeader
std::string h_nodeDetailsHeader
header of CSV format
Definition: outputmanager.h:224