Multiple fixes:
- fixed destination MAC address set when adding a source and a sink according to IANA specs - fixed retrieval of network interface MAC address - added <list> inclusion to header files using std::list - fixed regression test suite - additional minor changes
This commit is contained in:
parent
a70505989f
commit
dff3ab3cba
@ -21,7 +21,7 @@
|
||||
#include "browser.hpp"
|
||||
|
||||
using namespace std::chrono;
|
||||
using second_t = std::chrono::duration<double, std::ratio<1> >;
|
||||
using second_t = std::chrono::duration<double, std::ratio<1> >;
|
||||
|
||||
std::shared_ptr<Browser> Browser::create(
|
||||
std::shared_ptr<Config> config) {
|
||||
@ -40,7 +40,7 @@ std::list<RemoteSource> Browser::get_remote_sources() {
|
||||
std::list<RemoteSource> sources_list;
|
||||
std::shared_lock sources_lock(sources_mutex_);
|
||||
for (auto const& [id, source] : sources_) {
|
||||
sources_list.emplace_back(source);
|
||||
sources_list.push_back(source);
|
||||
}
|
||||
return sources_list;
|
||||
}
|
||||
@ -121,7 +121,8 @@ bool Browser::worker() {
|
||||
|
||||
std::unique_lock sources_lock(sources_mutex_);
|
||||
std::experimental::erase_if(sources_, [offset](auto entry) {
|
||||
if ((offset - entry.second.last_seen) > (entry.second.announce_period * 10)) {
|
||||
if ((offset - entry.second.last_seen) >
|
||||
(entry.second.announce_period * 10)) {
|
||||
// remove from remote SAP sources
|
||||
BOOST_LOG_TRIVIAL(info)
|
||||
<< "browser:: SAP source " << entry.second.id << " timeout";
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <list>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "sap.hpp"
|
||||
@ -36,7 +37,7 @@ struct RemoteSource {
|
||||
std::string name;
|
||||
std::string sdp;
|
||||
uint32_t last_seen; /* seconds from daemon startup */
|
||||
uint32_t announce_period; /* period between annoucementis */
|
||||
uint32_t announce_period; /* period between annoucements */
|
||||
};
|
||||
|
||||
class Browser {
|
||||
@ -48,7 +49,6 @@ class Browser {
|
||||
Browser& operator=(const Browser&) = delete;
|
||||
virtual ~Browser(){ stop(); };
|
||||
|
||||
// session manager interface
|
||||
bool start() {
|
||||
if (!running_) {
|
||||
running_ = true;
|
||||
|
@ -56,7 +56,7 @@ std::pair<uint32_t, std::string> get_interface_ip(
|
||||
|
||||
std::pair<std::array<uint8_t, 6>, std::string> get_interface_mac(
|
||||
const std::string& interface_name) {
|
||||
std::array<uint8_t, 6> mac{0x01, 0x00, 0x5e, 0x01, 0x00, 0x01};
|
||||
std::array<uint8_t, 6> mac{0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
int fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
BOOST_LOG_TRIVIAL(error)
|
||||
@ -75,14 +75,12 @@ std::pair<std::array<uint8_t, 6>, std::string> get_interface_mac(
|
||||
}
|
||||
close(fd);
|
||||
|
||||
if (*ifr.ifr_hwaddr.sa_data != 0) {
|
||||
uint8_t* sa = reinterpret_cast<uint8_t*>(ifr.ifr_hwaddr.sa_data);
|
||||
std::copy(sa, sa + 8, std::begin(mac));
|
||||
}
|
||||
uint8_t* sa = reinterpret_cast<uint8_t*>(ifr.ifr_hwaddr.sa_data);
|
||||
std::copy(sa, sa + 8, std::begin(mac));
|
||||
|
||||
char str_mac[18];
|
||||
sprintf(str_mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0], mac[1], mac[2],
|
||||
mac[3], mac[4], mac[5]);
|
||||
sprintf(str_mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
/*BOOST_LOG_TRIVIAL(debug) << "interface " << interface_name << " MAC address "
|
||||
<< str_mac;*/
|
||||
|
||||
|
@ -440,6 +440,19 @@ bool SessionManager::save_status() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::array<uint8_t, 6> get_mcast_mac_addr(uint32_t mcast_ip) {
|
||||
// As defined by IANA, the most significant 24 bits of an IPv4 multicast
|
||||
// MAC address are 0x01005E. // Bit 25 is 0, and the other 23 bits are the
|
||||
// least significant 23 bits of an IPv4 multicast address.
|
||||
uint64_t mac_addr = 0x01005E000000 | (mcast_ip & 0x7FFFFF);
|
||||
return { static_cast<uint8_t>(mac_addr >> 40),
|
||||
static_cast<uint8_t>(mac_addr >> 32),
|
||||
static_cast<uint8_t>(mac_addr >> 24),
|
||||
static_cast<uint8_t>(mac_addr >> 16),
|
||||
static_cast<uint8_t>(mac_addr >> 8),
|
||||
static_cast<uint8_t>(mac_addr) };
|
||||
}
|
||||
|
||||
std::error_code SessionManager::add_source(const StreamSource& source) {
|
||||
if (source.id > stream_id_max) {
|
||||
BOOST_LOG_TRIVIAL(error) << "session_manager:: source id "
|
||||
@ -472,8 +485,10 @@ std::error_code SessionManager::add_source(const StreamSource& source) {
|
||||
info.stream.m_usDestPort = config_->get_rtp_port();
|
||||
info.stream.m_ui32SSRC = rand() % 65536; // use random number
|
||||
std::copy(source.map.begin(), source.map.end(), info.stream.m_aui32Routing);
|
||||
std::copy(std::begin(config_->get_mac_addr()), std::end(config_->get_mac_addr()),
|
||||
auto mcast_mac_addr = get_mcast_mac_addr(info.stream.m_ui32DestIP);
|
||||
std::copy(std::begin(mcast_mac_addr), std::end(mcast_mac_addr),
|
||||
info.stream.m_ui8DestMAC);
|
||||
|
||||
info.refclk_ptp_traceable = source.refclk_ptp_traceable;
|
||||
info.enabled = source.enabled;
|
||||
info.io = source.io;
|
||||
@ -709,7 +724,9 @@ std::error_code SessionManager::add_sink(const StreamSink& sink) {
|
||||
// info.m_ui32SSRC = 65544;
|
||||
// info.m_ucDSCP = source.dscp;
|
||||
// info.m_byTTL = source.ttl;
|
||||
// info.m_ui8DestMAC
|
||||
auto mcast_mac_addr = get_mcast_mac_addr(info.stream.m_ui32DestIP);
|
||||
std::copy(std::begin(mcast_mac_addr), std::end(mcast_mac_addr),
|
||||
info.stream.m_ui8DestMAC);
|
||||
|
||||
std::unique_lock sinks_lock(sinks_mutex_);
|
||||
auto const it = sinks_.find(sink.id);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <map>
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
#include <list>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "driver_manager.hpp"
|
||||
|
@ -16,6 +16,6 @@
|
||||
"syslog_server": "255.255.255.254:1234",
|
||||
"status_file": "",
|
||||
"interface_name": "lo",
|
||||
"mac_addr": "01:00:5e:01:00:01",
|
||||
"mac_addr": "00:00:00:00:00:00",
|
||||
"ip_addr": "127.0.0.1"
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ BOOST_AUTO_TEST_CASE(get_config) {
|
||||
BOOST_CHECK_MESSAGE(syslog_server == "255.255.255.254:1234", "config as excepcted");
|
||||
BOOST_CHECK_MESSAGE(status_file == "", "config as excepcted");
|
||||
BOOST_CHECK_MESSAGE(interface_name == "lo", "config as excepcted");
|
||||
BOOST_CHECK_MESSAGE(mac_addr == "01:00:5e:01:00:01", "config as excepcted");
|
||||
BOOST_CHECK_MESSAGE(mac_addr == "00:00:00:00:00:00", "config as excepcted");
|
||||
BOOST_CHECK_MESSAGE(ip_addr == "127.0.0.1", "config as excepcted");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user