Skip to content

Commit e73f92f

Browse files
authored
Some refactoring (#557)
closes #521 closes #502
1 parent 29d5073 commit e73f92f

28 files changed

Lines changed: 82 additions & 60 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if(BUILD_TESTS)
5454
target_include_directories(${TEST_NAME} PUBLIC "source")
5555
target_compile_definitions(${TEST_NAME} PRIVATE PROJECT_ROOT_DIR="${CMAKE_SOURCE_DIR}")
5656

57-
target_compile_options(${TEST_NAME} PRIVATE -Wall -Wextra)
57+
target_compile_options(${TEST_NAME} PRIVATE -Wall -Werror -Wextra)
5858
target_link_libraries(${TEST_NAME} gtest gmock gtest_main yaml-cpp matplot)
5959

6060
if (DEFINED LOG_LEVEL)

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33
## Overview
44
Not Overcomplicated Network Simulator (NoNS) is a free open source project aiming to build a discrete-event network simulator targeted at easy testing of congestion control algorithms.
55

6+
## Dependencies
7+
8+
NoNS need gnuplot & graphiz to generate plots, so install it:
9+
```
10+
sudo apt install --fix-missing gnuplot
11+
sudo apt install --fix-missing graphviz
12+
```
13+
14+
Other dependecies are designed as git submodules, so to install them, run
15+
```
16+
git submodule init
17+
git submodule update --init --recursive
18+
```
19+
620
## Build project
721
NoNS uses CMake build manager, so project builds in this way:
822

@@ -11,26 +25,12 @@ cmake -B build -DCMAKE_BUILD_TYPE=Release
1125
cmake --build build
1226
```
1327

14-
## Run project
15-
16-
```
17-
./build/nons
18-
--config path
19-
[--output-dir output-dir-name]
20-
[--no-logs]
21-
```
2228

23-
Options:
29+
## Run project
2430

25-
```
26-
-c, --config arg Path to the scenario configuration file
27-
--output-dir arg Output directory for metrics and plots
28-
(default: metrics)
29-
--no-logs Output without logs
30-
-h, --help Print usage
31-
```
31+
Build project and run it with `-h` option to see help.
3232

33-
Examples of configs are placed under [`configs`](configs/) directory. See config schemas [here](_schemas/configs/).
33+
Examples of configs that need to run NoNS are placed under [`configs`](configs/) directory. See config schemas [here](_schemas/configs/).
3434

3535
## How to add a new congestion control algorithm
3636

source/main.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
#include "logger/logger.hpp"
44
#include "parser/scenario/scenario_parser.hpp"
5+
#include "utils/filesystem.hpp"
56
#include "utils/statistics.hpp"
67

78
int main(const int argc, char** argv) {
89
cxxopts::Options options("NoNS", "Discrete-event based simulator");
910
options.add_options()("c,config", "Path to the scenario configuration file",
1011
cxxopts::value<std::string>())(
11-
"output-dir", "Output directory for metrics and plots",
12+
"output-dir", "Output directory for metrics, logs and plots",
1213
cxxopts::value<std::string>()->default_value("metrics"))(
14+
"w,wipe-output-dir", "Wipe output directory before run",
15+
cxxopts::value<bool>()->default_value("false"))(
1316
"no-logs", "Output without logs",
1417
cxxopts::value<bool>()->default_value("false"))("h,help",
1518
"Print usage");
@@ -29,6 +32,10 @@ int main(const int argc, char** argv) {
2932

3033
std::filesystem::path config_path = flags["config"].as<std::string>();
3134

35+
if (flags["wipe-output-dir"].as<bool>()) {
36+
utils::wipe_folder(output_dir);
37+
}
38+
3239
std::filesystem::path actions_summary_path(output_dir /
3340
"actions_summary.csv");
3441

@@ -38,5 +45,7 @@ int main(const int argc, char** argv) {
3845
sim::write_to_csv(actions_summary_path, summary.send_data);
3946
scenario.get_network().save_metrics(output_dir / "network");
4047

48+
std::cout << "Metrics are written to " << output_dir << "\n\n";
49+
4150
return 0;
4251
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#pragma once
2+
#include "packet.hpp"
23
#include "types.hpp"
4+
#include "utils/statistics.hpp"
35

46
namespace sim {
57

68
struct PacketAckInfo {
79
TimeNs rtt;
8-
TimeNs avg_rtt;
9-
bool ecn_flag;
10+
const utils::Statistics<TimeNs>& rtt_stat;
11+
const Packet& ack;
1012
};
1113

1214
} // namespace sim

source/network/connection/flow/tcp/tcp_flow.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ void TcpFlow::process_ack(const Packet& ack, SizeByte data_packet_size,
187187
m_metrics.delivery_rate->add_record(now, delivery_rate.value());
188188
m_context.delivery_rate_statistics.add_record(delivery_rate);
189189

190-
callback({PacketAckInfo{rtt, m_context.rtt_statistics.get_mean().value(),
191-
ack.congestion_experienced}});
190+
callback({PacketAckInfo{rtt, m_context.rtt_statistics, ack}});
192191
}
193192

194193
// After ACK with a valid RTT: formula + transition to STEADY (once)

source/network/connection/flow/tcp/tcp_flow.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct TcpFlowMetricsFilters {
1616
class TcpFlow : public IFlow, public std::enable_shared_from_this<TcpFlow> {
1717
public:
1818
constexpr static inline RTO DEFAULT_START_RTO =
19-
RTO(TimeNs(2000), Time<Second>(1));
19+
RTO(Time<Millisecond>(200), Time<Second>(1));
2020

2121
constexpr static inline bool DEFAULT_ECN_CAPABLE = true;
2222
constexpr static inline TcpFlowMetricsFilters DEFAULT_METRICS_FLAGS = {};

source/network/connection/mplb/cc/basic/basic_cc.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
namespace sim {
66

7-
void BasicCC::on_ack([[maybe_unused]] TimeNs rtt,
8-
[[maybe_unused]] TimeNs avg_rtt,
9-
[[maybe_unused]] bool ecn_flag) {}
7+
void BasicCC::on_ack([[maybe_unused]] const PacketAckInfo& info) {}
108

119
void BasicCC::on_timeout() {}
1210

source/network/connection/mplb/cc/basic/basic_cc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace sim {
66
class BasicCC : public ITcpCC {
77
public:
8-
void on_ack(TimeNs rtt, TimeNs avg_rtt, bool ecn_flag) final;
8+
void on_ack(const PacketAckInfo& info) final;
99
void on_timeout() final;
1010
TimeNs get_pacing_delay() const final;
1111
double get_cwnd() const final;

source/network/connection/mplb/cc/i_tcp_cc.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ class ITcpCC {
99
public:
1010
// Callback that triggers every time ACK receives on sender
1111
// returns true if congestion detected; false otherwice
12-
virtual void on_ack(TimeNs rtt, TimeNs avg_rtt, bool ecn_flag) = 0;
13-
14-
virtual void on_ack(PacketAckInfo info) {
15-
on_ack(info.rtt, info.avg_rtt, info.ecn_flag);
16-
}
12+
virtual void on_ack(const PacketAckInfo& info) = 0;
1713

1814
// Callback that triggers when ACK not delivered on timeout
1915
virtual void on_timeout() = 0;

source/network/connection/mplb/cc/metricable_cc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ MetricableCC::MetricableCC(std::unique_ptr<ITcpCC> a_cc,
99
MetricableCCMetricsFilters a_flags)
1010
: m_cc(std::move(a_cc)), m_metrics_filters(std::move(a_flags)) {}
1111

12-
void MetricableCC::on_ack(TimeNs rtt, TimeNs avg_rtt, bool ecn_flag) {
13-
m_cc->on_ack(rtt, avg_rtt, ecn_flag);
12+
void MetricableCC::on_ack(const PacketAckInfo& info) {
13+
m_cc->on_ack(info);
1414
record_cwnd();
1515
}
1616

0 commit comments

Comments
 (0)