5G-MAG Reference Tools - MBMS Middleware
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MBMS_RT::Middleware Class Reference

#include <Middleware.h>

Collaboration diagram for MBMS_RT::Middleware:
Collaboration graph

Public Member Functions

 Middleware (boost::asio::io_service &io_service, const libconfig::Config &cfg, const std::string &api_url, const std::string &iface)
 
std::shared_ptr< Serviceget_service (const std::string &service_id)
 
void set_service (const std::string &service_id, std::shared_ptr< Service > service)
 

Private Member Functions

void tick_handler ()
 
void control_tick_handler ()
 
bool _handle_local_service_announcement ()
 

Private Attributes

bool _seamless = false
 
MBMS_RT::RpRestClient _rp
 
MBMS_RT::RestHandler _api
 
MBMS_RT::CacheManagement _cache
 
bool _control_system = false
 
MBMS_RT::ControlSystemRestClient _control
 
boost::posix_time::seconds _control_tick_interval = boost::posix_time::seconds(10)
 
boost::asio::deadline_timer _control_timer
 
std::unique_ptr< MBMS_RT::ServiceAnnouncement_service_announcement = {nullptr}
 
std::map< std::string, std::shared_ptr< Service > > _services
 
boost::posix_time::seconds _tick_interval
 
boost::asio::deadline_timer _timer
 
const libconfig::Config & _cfg
 
const std::string & _interface
 
boost::asio::io_service & _io_service
 

Detailed Description

Definition at line 33 of file Middleware.h.

Constructor & Destructor Documentation

◆ Middleware()

MBMS_RT::Middleware::Middleware ( boost::asio::io_service &  io_service,
const libconfig::Config &  cfg,
const std::string &  api_url,
const std::string &  iface 
)
Parameters
io_service
cfg
api_url
iface

Definition at line 27 of file Middleware.cpp.

30  : _rp(cfg), _control(cfg), _cache(cfg, io_service), _api(cfg, api_url, _cache, &_service_announcement, _services),
32  _cfg(cfg), _interface(iface), _io_service(io_service) {
33  cfg.lookupValue("mw.seamless_switching.enabled", _seamless);
34  if (_seamless) {
35  spdlog::info("Seamless switching mode enabled");
36  }
37  cfg.lookupValue("mw.control_system.enabled", _control_system);
38  if (_control_system) {
39  int secs = 10;
40  cfg.lookupValue("mw.control_system.interval", secs);
41  _control_tick_interval = boost::posix_time::seconds(secs);
42  spdlog::info("Control System API enabled");
43  }
44 
46  _timer.async_wait(boost::bind(&Middleware::tick_handler, this)); //NOLINT
47  _control_timer.async_wait(boost::bind(&Middleware::control_tick_handler, this)); //NOLINT
48 }
const std::string & _interface
Definition: Middleware.h:63
std::unique_ptr< MBMS_RT::ServiceAnnouncement > _service_announcement
Definition: Middleware.h:56
boost::asio::io_service & _io_service
Definition: Middleware.h:64
std::map< std::string, std::shared_ptr< Service > > _services
Definition: Middleware.h:57
boost::posix_time::seconds _control_tick_interval
Definition: Middleware.h:52
MBMS_RT::CacheManagement _cache
Definition: Middleware.h:48
MBMS_RT::RpRestClient _rp
Definition: Middleware.h:46
boost::posix_time::seconds _tick_interval
Definition: Middleware.h:59
const libconfig::Config & _cfg
Definition: Middleware.h:62
MBMS_RT::RestHandler _api
Definition: Middleware.h:47
MBMS_RT::ControlSystemRestClient _control
Definition: Middleware.h:51
bool _handle_local_service_announcement()
Definition: Middleware.cpp:54
boost::asio::deadline_timer _control_timer
Definition: Middleware.h:53
boost::asio::deadline_timer _timer
Definition: Middleware.h:60
static Config cfg
Global configuration object.
Definition: main.cpp:111

Member Function Documentation

◆ _handle_local_service_announcement()

auto MBMS_RT::Middleware::_handle_local_service_announcement ( )
private
Returns
{bool} Whether a local SA file was used

Definition at line 54 of file Middleware.cpp.

54  {
55  try {
56  bool local_service_enabled = false;
57  std::string local_bootstrap_file;
58 
59  _cfg.lookupValue("mw.local_service.enabled", local_service_enabled);
60  _cfg.lookupValue("mw.local_service.bootstrap_file", local_bootstrap_file);
61 
62  if (local_service_enabled && local_bootstrap_file != "") {
63  spdlog::info("Reading service announcement from file at {}", local_bootstrap_file);
64  std::ifstream ifs(local_bootstrap_file);
65  std::string sa_multipart((std::istreambuf_iterator<char>(ifs)),
66  (std::istreambuf_iterator<char>()));
67  std::string tmgi = "";
68  _cfg.lookupValue("mw.local_service.tmgi", tmgi);
69  std::string mcast_address = "";
70  _cfg.lookupValue("mw.local_service.mcast_address", mcast_address);
71 
72  _service_announcement = std::make_unique<MBMS_RT::ServiceAnnouncement>(_cfg, tmgi, mcast_address, 0, _interface,
74  boost::bind(&Middleware::get_service, this,
75  _1), //NOLINT
76  boost::bind(&Middleware::set_service, this,
77  _1, _2)); //NOLINT
78  _service_announcement->parse_bootstrap(sa_multipart);
79 
80  return true;
81  }
82  return false;
83  } catch (...) {
84  return false;
85  }
86 }
std::shared_ptr< Service > get_service(const std::string &service_id)
Definition: Middleware.cpp:149
void set_service(const std::string &service_id, std::shared_ptr< Service > service)
Definition: Middleware.h:38

◆ control_tick_handler()

void MBMS_RT::Middleware::control_tick_handler ( )
private

Definition at line 124 of file Middleware.cpp.

124  {
125  if (_control_system) {
126  try {
127  auto status = _rp.getStatus();
128  auto cinr = status.at("cinr_db").as_double();
129  spdlog::debug("CINR ist {}", cinr);
130 
131  std::vector<std::string> tmgis;
132  auto services = _control.sendHello(cinr, tmgis);
133  for (const auto &ctrl_service: services.as_array()) {
134  spdlog::debug("control system sent service: {}", ctrl_service.serialize());
135  }
136  } catch (...) {}
137  }
138 
139 
140  _control_timer.expires_at(_control_timer.expires_at() + _control_tick_interval);
141  _control_timer.async_wait(boost::bind(&Middleware::control_tick_handler, this)); //NOLINT
142 }
web::json::value getStatus()

◆ get_service()

auto MBMS_RT::Middleware::get_service ( const std::string &  service_id)
Parameters
{string}service_id
Returns

Definition at line 149 of file Middleware.cpp.

149  {
150  if (_services.find(service_id) != _services.end()) {
151  return _services[service_id];
152  } else {
153  return nullptr;
154  }
155 }

◆ set_service()

void MBMS_RT::Middleware::set_service ( const std::string &  service_id,
std::shared_ptr< Service service 
)
inline

Definition at line 38 of file Middleware.h.

38 { _services[service_id] = service; };

◆ tick_handler()

void MBMS_RT::Middleware::tick_handler ( )
private

Definition at line 91 of file Middleware.cpp.

91  {
92  auto mchs = _rp.getMchInfo();
93  for (auto const &mch: mchs.as_array()) {
94  for (auto const &mtch: mch.at("mtchs").as_array()) {
95  auto tmgi = mtch.at("tmgi").as_string();
96  auto dest = mtch.at("dest").as_string();
97  unsigned tsi = 0;
98  _cfg.lookupValue("mw.service_announcement_tsi", tsi);
99  auto is_service_announcement = std::stoul(tmgi.substr(0, 6), nullptr, 16) < 0xF;
100  if (!dest.empty() && is_service_announcement && !_service_announcement) {
101  // automatically start receiving the service announcement
102  // 26.346 5.2.3.1.1 : the pre-defined TSI value shall be "0".
103  _service_announcement = std::make_unique<MBMS_RT::ServiceAnnouncement>(_cfg, tmgi, dest, tsi, _interface,
104  _io_service,
105  _cache, _seamless,
106  boost::bind(&Middleware::get_service,
107  this, _1),
108  boost::bind(&Middleware::set_service,
109  this, _1, _2)); //NOLINT
110  _service_announcement->start_flute_receiver(dest);
111  }
112  }
113  }
114 
116 
117  _timer.expires_at(_timer.expires_at() + _tick_interval);
118  _timer.async_wait(boost::bind(&Middleware::tick_handler, this)); //NOLINT
119 }
web::json::value getMchInfo()

Member Data Documentation

◆ _api

MBMS_RT::RestHandler MBMS_RT::Middleware::_api
private

Definition at line 47 of file Middleware.h.

◆ _cache

MBMS_RT::CacheManagement MBMS_RT::Middleware::_cache
private

Definition at line 48 of file Middleware.h.

◆ _cfg

const libconfig::Config& MBMS_RT::Middleware::_cfg
private

Definition at line 62 of file Middleware.h.

◆ _control

MBMS_RT::ControlSystemRestClient MBMS_RT::Middleware::_control
private

Definition at line 51 of file Middleware.h.

◆ _control_system

bool MBMS_RT::Middleware::_control_system = false
private

Definition at line 50 of file Middleware.h.

◆ _control_tick_interval

boost::posix_time::seconds MBMS_RT::Middleware::_control_tick_interval = boost::posix_time::seconds(10)
private

Definition at line 52 of file Middleware.h.

◆ _control_timer

boost::asio::deadline_timer MBMS_RT::Middleware::_control_timer
private

Definition at line 53 of file Middleware.h.

◆ _interface

const std::string& MBMS_RT::Middleware::_interface
private

Definition at line 63 of file Middleware.h.

◆ _io_service

boost::asio::io_service& MBMS_RT::Middleware::_io_service
private

Definition at line 64 of file Middleware.h.

◆ _rp

MBMS_RT::RpRestClient MBMS_RT::Middleware::_rp
private

Definition at line 46 of file Middleware.h.

◆ _seamless

bool MBMS_RT::Middleware::_seamless = false
private

Definition at line 43 of file Middleware.h.

◆ _service_announcement

std::unique_ptr<MBMS_RT::ServiceAnnouncement> MBMS_RT::Middleware::_service_announcement = {nullptr}
private

Definition at line 56 of file Middleware.h.

◆ _services

std::map<std::string, std::shared_ptr<Service> > MBMS_RT::Middleware::_services
private

Definition at line 57 of file Middleware.h.

◆ _tick_interval

boost::posix_time::seconds MBMS_RT::Middleware::_tick_interval
private

Definition at line 59 of file Middleware.h.

◆ _timer

boost::asio::deadline_timer MBMS_RT::Middleware::_timer
private

Definition at line 60 of file Middleware.h.


The documentation for this class was generated from the following files: