Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for bonding #24

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
df2c4d9
Added SRT bonding
maxsharabayko Aug 17, 2020
5bee0d0
Removed this_thread::slepp before accepting
maxsharabayko Dec 4, 2020
0f03f4f
Fixed closing listening sockets of a group
maxsharabayko Dec 4, 2020
f4fe1d1
Close old sockets before reconnecting
maxsharabayko Dec 4, 2020
a17dd84
working on member reconnect
maxsharabayko Dec 7, 2020
cc84aa1
Scheduling member link reconnection
maxsharabayko Dec 8, 2020
74e9028
Adding backup mode
maxsharabayko Dec 9, 2020
2536592
Adding per-link options.
maxsharabayko Dec 10, 2020
2511d98
Fixed group connection mode.
maxsharabayko Dec 10, 2020
a95d5f5
Set group caller PRE options
maxsharabayko Dec 21, 2020
f792d18
Fixed listener-side PRE configs
maxsharabayko Jan 20, 2021
5055a22
Printing SRC and DST URIs
maxsharabayko Jan 21, 2021
92e2320
Added connect and listen callback to socket group
maxsharabayko Jan 22, 2021
7a3c710
Corrected group log a bit
maxsharabayko Jan 22, 2021
b410b78
Resolved C++14 string operator
maxsharabayko Jan 28, 2021
f66de1f
Fixed reorder distance metric
maxsharabayko Feb 8, 2021
85b5571
Reorganized stats a bit.
maxsharabayko Feb 26, 2021
61a7857
Removed bonding to route subcommand
maxsharabayko Mar 2, 2021
38b9516
Added weight to group CSV stats
maxsharabayko Mar 11, 2021
c60366c
Added warning to metrics about loss detected
maxsharabayko Mar 19, 2021
a7fe78d
Member stats: continue after a broken member
maxsharabayko Mar 19, 2021
995c2d5
Fixed member group type log on accept
maxsharabayko Mar 29, 2021
1ad6eb2
Minor: using SOCKET type instead of int
maxsharabayko Mar 31, 2021
70a3163
Connection erro log message
maxsharabayko May 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Build results
_build*/
build/
build*/
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_subdirectory(submodule/spdlog)
SET(ENABLE_APPS ON)
SET(ENABLE_SHARED OFF)
SET(ENABLE_ENCRYPTION ON)
SET(ENABLE_EXPERIMENTAL_BONDING ON)
add_subdirectory(submodule/srt)

#set_target_properties(srt-live-transmit
Expand Down
2 changes: 1 addition & 1 deletion submodule/srt
Submodule srt updated 136 files
9 changes: 9 additions & 0 deletions xtransmit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ target_include_directories(srt-xtransmit PUBLIC
${PTHREAD_INCLUDE_DIR}
)

if (ENABLE_EXPERIMENTAL_BONDING)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_EXPERIMENTAL_BONDING=1")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_EXPERIMENTAL_BONDING=1")
endif()

if (ENABLE_STDCXX_SYNC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_STDCXX_SYNC=1")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_STDCXX_SYNC=1")
endif()

if (ENABLE_CXX17)
set(REQUIRE_CXX_VER 17)
Expand Down
52 changes: 40 additions & 12 deletions xtransmit/generate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// xtransmit
#include "socket_stats.hpp"
#include "srt_socket.hpp"
#include "srt_socket_group.hpp"
#include "udp_socket.hpp"
#include "generate.hpp"
#include "pacer.hpp"
Expand All @@ -36,7 +37,6 @@ using shared_sock = std::shared_ptr<socket::isocket>;
void run_pipe(shared_sock dst, const config& cfg, const atomic_bool& force_break)
{
vector<char> message_to_send(cfg.message_size);
iota(message_to_send.begin(), message_to_send.end(), (char)0);

const auto start_time = steady_clock::now();
const int num_messages = cfg.duration > 0 ? -1 : cfg.num_messages;
Expand Down Expand Up @@ -94,12 +94,19 @@ void run_pipe(shared_sock dst, const config& cfg, const atomic_bool& force_break
}
}

void xtransmit::generate::run(const string& dst_url, const config& cfg, const atomic_bool& force_break)
void xtransmit::generate::run(const vector<string>& dst_urls, const config& cfg, const atomic_bool& force_break)
{
const UriParser uri(dst_url);
if (dst_urls.empty())
{
spdlog::error(LOG_SC_GENERATE "No destination URI was provided");
return;
}

shared_sock sock;
shared_sock connection;
vector<UriParser> urls;
for (const string& url : dst_urls)
{
urls.emplace_back(UriParser(url));
}

const bool write_stats = cfg.stats_file != "" && cfg.stats_freq_ms > 0;
// make_unique is not supported by GCC 4.8, only starting from GCC 4.9 :(
Expand All @@ -121,39 +128,60 @@ void xtransmit::generate::run(const string& dst_url, const config& cfg, const at
do {
try
{
if (uri.proto() == "udp")
shared_sock sock;
shared_sock connection;

if (urls.size() == 1)
{
connection = make_shared<socket::udp>(uri);
if (urls[0].proto() == "udp")
{
connection = make_shared<socket::udp>(urls[0]);
}
else
{
sock = make_shared<socket::srt>(urls[0]);
socket::srt* s = dynamic_cast<socket::srt*>(sock.get());
const bool accept = s->mode() == socket::srt::LISTENER;
if (accept)
s->listen();
connection = accept ? s->accept() : s->connect();
}
}
else
{
sock = make_shared<socket::srt>(uri);
socket::srt* s = static_cast<socket::srt*>(sock.get());
const bool accept = s->mode() == socket::srt::LISTENER;
sock = make_shared<socket::srt_group>(urls);
socket::srt_group* s = dynamic_cast<socket::srt_group*>(sock.get());
const bool accept = s->mode() == socket::srt_group::LISTENER;
if (accept)
{
s->listen();
}
connection = accept ? s->accept() : s->connect();
}

if (stats)
stats->add_socket(connection);
run_pipe(connection, cfg, force_break);
if (stats && cfg.reconnect)
stats->clear();
}
catch (const socket::exception& e)
{
spdlog::warn(LOG_SC_GENERATE "{}", e.what());
if (stats)
stats->clear();
}
} while (cfg.reconnect && !force_break);
}

CLI::App* xtransmit::generate::add_subcommand(CLI::App& app, config& cfg, string& dst_url)
CLI::App* xtransmit::generate::add_subcommand(CLI::App& app, config& cfg, vector<string>& dst_urls)
{
const map<string, int> to_bps{{"kbps", 1000}, {"Mbps", 1000000}, {"Gbps", 1000000000}};
const map<string, int> to_ms{{"s", 1000}, {"ms", 1}};
const map<string, int> to_sec{{"s", 1}, {"min", 60}, {"mins", 60}};

CLI::App* sc_generate = app.add_subcommand("generate", "Send generated data (SRT, UDP)")->fallthrough();
sc_generate->add_option("dst", dst_url, "Destination URI");
sc_generate->add_option("dst", dst_urls, "Destination URI")->expected(1, 10);
sc_generate->add_option("--msgsize", cfg.message_size, "Size of a message to send");
sc_generate->add_option("--sendrate", cfg.sendrate, "Bitrate to generate")
->transform(CLI::AsNumberWithUnit(to_bps, CLI::AsNumberWithUnit::CASE_SENSITIVE));
Expand Down
5 changes: 3 additions & 2 deletions xtransmit/generate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ struct config
std::string playback_csv;
};

void run(const std::string& dst_url, const config& cfg, const std::atomic_bool& force_break);
void run(const std::vector<std::string>& dst_urls, const config& cfg, const std::atomic_bool& force_break);

CLI::App* add_subcommand(CLI::App& app, config& cfg, std::vector<std::string>& dst_urls);

CLI::App* add_subcommand(CLI::App& app, config& cfg, std::string& dst_url);
} // namespace generate
} // namespace xtransmit
1 change: 1 addition & 0 deletions xtransmit/metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace metrics
// TODO: latency measurements
inline void validate_packet(const vector<char>& payload)
{
// TODO: validate payload
const auto sys_time_now = system_clock::now();
const auto std_time_now = steady_clock::now();

Expand Down
6 changes: 3 additions & 3 deletions xtransmit/metrics_reorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ class reorder
{
const uint64_t lost = pkt_seqno - m_stats.expected_seqno;
m_stats.pkts_lost += lost;
//spdlog::warn(LOG_SC_RFC4737 "Detected loss of {} packets", lost);
spdlog::warn("[METRICS] Detected loss of {} packets (seqno [{}; {}))", lost, m_stats.expected_seqno, pkt_seqno);
m_stats.expected_seqno = pkt_seqno + 1;
}
else // Packet reordering: pkt_seqno < m_seqno
{
++m_stats.pkts_reordered;
const uint64_t reorder_dist = pkt_seqno - m_stats.expected_seqno;
const uint64_t reorder_dist = m_stats.expected_seqno - pkt_seqno;
m_stats.reorder_dist = std::max(m_stats.reorder_dist, reorder_dist);

//spdlog::warn(LOG_SC_RFC4737 "Detected reordered packet, dist {}", reorder_dist);
spdlog::warn("[METRICS] Detected reordered packet, seqno {}, expected {} (dist {})", pkt_seqno, m_stats.expected_seqno, reorder_dist);
}
}

Expand Down
53 changes: 39 additions & 14 deletions xtransmit/receive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// xtransmit
#include "socket_stats.hpp"
#include "srt_socket.hpp"
#include "srt_socket_group.hpp"
#include "udp_socket.hpp"
#include "receive.hpp"
#include "metrics.hpp"
Expand All @@ -32,8 +33,6 @@ using shared_sock = std::shared_ptr<socket::isocket>;
#define LOG_SC_RECEIVE "RECEIVE "




void trace_message(const size_t bytes, const vector<char> &buffer, int conn_id)
{
::cout << "RECEIVED MESSAGE length " << bytes << " on conn ID " << conn_id;
Expand Down Expand Up @@ -137,12 +136,19 @@ void run_pipe(shared_sock src, const config &cfg, const atomic_bool &force_break
}
}

void xtransmit::receive::run(const string &src_url, const config &cfg, const atomic_bool &force_break)
void xtransmit::receive::run(const vector<string> &src_urls, const config &cfg, const atomic_bool &force_break)
{
const UriParser uri(src_url);
if (src_urls.empty())
{
spdlog::error(LOG_SC_RECEIVE "No destination URI was provided");
return;
}

shared_sock sock;
shared_sock conn;
vector<UriParser> urls;
for (const string& url : src_urls)
{
urls.emplace_back(url);
}

unique_ptr<socket::stats_writer> stats;

Expand All @@ -164,17 +170,33 @@ void xtransmit::receive::run(const string &src_url, const config &cfg, const ato
do {
try
{
if (uri.proto() == "udp")
shared_sock sock;
shared_sock conn;

if (urls.size() == 1)
{
conn = make_shared<socket::udp>(uri);
if (urls[0].proto() == "udp")
{
conn = make_shared<socket::udp>(urls[0]);
}
else
{
sock = make_shared<socket::srt>(urls[0]);
socket::srt* s = dynamic_cast<socket::srt*>(sock.get());
const bool accept = s->mode() == socket::srt::LISTENER;
if (accept)
s->listen();
conn = accept ? s->accept() : s->connect();
}
}
else
{
sock = make_shared<socket::srt>(uri);
socket::srt* s = static_cast<socket::srt*>(sock.get());
const bool accept = s->mode() == socket::srt::LISTENER;
if (accept)
sock = make_shared<socket::srt_group>(urls);
socket::srt_group* s = dynamic_cast<socket::srt_group*>(sock.get());
const bool accept = s->mode() == socket::srt_group::LISTENER;
if (accept) {
s->listen();
}
conn = accept ? s->accept() : s->connect();
}

Expand All @@ -187,16 +209,18 @@ void xtransmit::receive::run(const string &src_url, const config &cfg, const ato
catch (const socket::exception & e)
{
spdlog::warn(LOG_SC_RECEIVE "{}", e.what());
if (stats)
stats->clear();
}
} while (cfg.reconnect && !force_break);
}

CLI::App* xtransmit::receive::add_subcommand(CLI::App& app, config& cfg, string& src_url)
CLI::App* xtransmit::receive::add_subcommand(CLI::App& app, config& cfg, vector<string>& src_urls)
{
const map<string, int> to_ms{ {"s", 1000}, {"ms", 1} };

CLI::App* sc_receive = app.add_subcommand("receive", "Receive data (SRT, UDP)")->fallthrough();
sc_receive->add_option("src", src_url, "Source URI");
sc_receive->add_option("--input,-i,src", src_urls, "Source URI");
sc_receive->add_option("--msgsize", cfg.message_size, "Size of a buffer to receive message payload");
sc_receive->add_option("--statsfile", cfg.stats_file, "output stats report filename");
sc_receive->add_option("--statsfreq", cfg.stats_freq_ms, "output stats report frequency (ms)")
Expand All @@ -208,6 +232,7 @@ CLI::App* xtransmit::receive::add_subcommand(CLI::App& app, config& cfg, string&
sc_receive->add_option("--metricsfreq", cfg.metrics_freq_ms, "Metrics report frequency")
->transform(CLI::AsNumberWithUnit(to_ms, CLI::AsNumberWithUnit::CASE_SENSITIVE));
sc_receive->add_flag("--twoway", cfg.send_reply, "Both send and receive data");
sc_receive->add_option("--input-group", cfg.inputs, "More input group URLs for SRT bonding");

return sc_receive;
}
Expand Down
6 changes: 4 additions & 2 deletions xtransmit/receive.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <atomic>
#include <string>
#include <vector>

// Third party libraries
#include "CLI/CLI.hpp"
Expand All @@ -21,14 +22,15 @@ namespace xtransmit {
int message_size = 1316;
int stats_freq_ms = 0;
std::string stats_file;
std::vector<std::string> inputs;
};



void run(const std::string& url, const config& cfg,
void run(const std::vector<std::string>& urls, const config& cfg,
const std::atomic_bool& force_break);

CLI::App* add_subcommand(CLI::App& app, config& cfg, std::string& src_url);
CLI::App* add_subcommand(CLI::App& app, config& cfg, std::vector<std::string>& src_urls);


} // namespace receive
Expand Down
12 changes: 9 additions & 3 deletions xtransmit/route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace route
if(uri.proto() == "srt")
{
shared_sock socket = make_shared<socket::srt>(uri);
socket::srt* s = static_cast<socket::srt*>(socket.get());
socket::srt* s = dynamic_cast<socket::srt*>(socket.get());
const bool accept = s->mode() == socket::srt::LISTENER;
if (accept)
s->listen();
Expand All @@ -95,6 +95,12 @@ namespace route
void xtransmit::route::run(const string& src_url, const string& dst_url,
const config& cfg, const atomic_bool& force_break)
{
if (src_url.empty() || dst_url.empty())
{
spdlog::error(LOG_SC_ROUTE "Empty source/destination was provided");
return;
}

try {
const bool write_stats = cfg.stats_file != "" && cfg.stats_freq_ms > 0;
// make_unique is not supported by GCC 4.8, only starting from GCC 4.9 :(
Expand Down Expand Up @@ -130,8 +136,8 @@ CLI::App* xtransmit::route::add_subcommand(CLI::App& app, config& cfg, string& s
const map<string, int> to_ms{ {"s", 1000}, {"ms", 1} };

CLI::App* sc_route = app.add_subcommand("route", "Route data (SRT, UDP)")->fallthrough();
sc_route->add_option("src", src_url, "Source URI");
sc_route->add_option("dst", dst_url, "Destination URI");
sc_route->add_option("-i,src", src_url, "Source URI")->expected(1);
sc_route->add_option("-o,dst", dst_url, "Destination URI")->expected(1);
sc_route->add_option("--msgsize", cfg.message_size, "Size of a buffer to receive message payload");
sc_route->add_flag("--bidir", cfg.bidir, "Enable bidirectional transmission");
sc_route->add_option("--statsfile", cfg.stats_file, "output stats report filename");
Expand Down
Loading