Commit bb5a1c1c authored by Yann Garcia's avatar Yann Garcia
Browse files

Add SCTP PPDID support

parent 6356e907
Loading
Loading
Loading
Loading
+1
Changes for ccsrc/Framework/include/params.hh: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ public: //! \publicsection
  static const std::string& server_mode;  //! Does the test sytem acting as a server. Default: 0
  static const std::string& local_server; //! Local server address (e.g. localhost)
  static const std::string& local_port;   //! Local listener port. Default: 80
  static const std::string& ppid;         //! SCTP Payload Protocol Identifier of the sent DATA chunks (e.g. 60 for NGAP, ETSI TS 138 412). Default: 0

  static const std::string& method;       //! HTTP method type. Default: POST
  static const std::string& uri;          //! HTTP URI value. Default: /
+1
Changes for ccsrc/Framework/src/params.cc: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ const std::string& params::privkey = std::string("privkey");
const std::string& params::server_mode        = std::string("server_mode");
const std::string& params::local_server       = std::string("local_server");
const std::string& params::local_port         = std::string("local_port");
const std::string& params::ppid               = std::string("ppid");

const std::string& params::method             = std::string("method");
const std::string& params::uri                = std::string("uri");
+34 −2
Changes for ccsrc/Protocols/Sctp/sctp_layer.cc: 34 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -3,12 +3,15 @@
#include <sys/stat.h>
#include <errno.h>
#include <chrono>
#include <cstring>
#include <arpa/inet.h>
#include <netinet/sctp.h>

#include "sctp_layer_factory.hh"

#include "loggers.hh"

sctp_layer::sctp_layer(const std::string&  p_type, const std::string&  param) : layer(p_type), SSL_Socket(), PORT(p_type.c_str()), _params(), _client_id{-1}, _time_key("sctp_layer::Handle_Fd_Event_Readable"), _reconnect_on_send{false} {
sctp_layer::sctp_layer(const std::string&  p_type, const std::string&  param) : layer(p_type), SSL_Socket(), PORT(p_type.c_str()), _params(), _client_id{-1}, _time_key("sctp_layer::Handle_Fd_Event_Readable"), _reconnect_on_send{false}, _ppid{0} {
  loggers::get_instance().log(">>> sctp_layer::sctp_layer (1): '%s', %s", to_string().c_str(), param.c_str());
  // Setup parameters
  params::convert(_params, param);
@@ -16,7 +19,7 @@ sctp_layer::sctp_layer(const std::string& p_type, const std::string& param) :

  init();                                                                                                                                                   }

sctp_layer::sctp_layer(const std::string&  p_type, const params & param) : layer(p_type), SSL_Socket(), PORT(p_type.c_str()), _params(), _client_id{-1}, _time_key("sctp_layer::Handle_Fd_Event_Readable"), _reconnect_on_send{false} {
sctp_layer::sctp_layer(const std::string&  p_type, const params & param) : layer(p_type), SSL_Socket(), PORT(p_type.c_str()), _params(), _client_id{-1}, _time_key("sctp_layer::Handle_Fd_Event_Readable"), _reconnect_on_send{false}, _ppid{0} {
  loggers::get_instance().log(">>> sctp_layer::sctp_layer (2): '%s'", to_string().c_str());
  // Setup parameters
  _params = param;
@@ -90,6 +93,18 @@ void sctp_layer::init() {
    loggers::get_instance().warning("sctp_layer::set_parameter: Unprocessed parameter: '%s'", params::local_server.c_str());
  }

  it = _params.find(params::ppid);
  if (it == _params.cend()) {
    _params.insert(std::pair<std::string, std::string>(params::ppid, "0"));
  } else {
    try {
      _ppid = static_cast<uint32_t>(std::stoul(it->second, nullptr, 0));
    } catch (const std::exception&) {
      loggers::get_instance().warning("sctp_layer::set_parameter: Invalid '%s' value: '%s', 0 is used", params::ppid.c_str(), it->second.c_str());
    }
  }
  loggers::get_instance().log("sctp_layer::init: ppid=%u", _ppid);

  parameter_set(use_connection_ASPs_name(), (!server_mode) ? "yes" : "no");
  loggers::get_instance().warning("sctp_layer::set_parameter: Limit to one simultanneous accepted connection (server_backlog == 1)");
  parameter_set(server_backlog_name(), "1"); // Limit to one simultanneous accepted connection 
@@ -222,6 +237,7 @@ bool sctp_layer::add_user_data(int p_client_id)
{
  loggers::get_instance().log(">>> sctp_layer::add_user_data: %d - _client_id: %d", p_client_id, _client_id);
  _client_id = p_client_id;
  set_default_ppid(p_client_id);
  if (_params[params::use_ssl].compare("0") == 0) {
    loggers::get_instance().log("sctp_layer::add_user_data: Non secured mode");
    return Abstract_Socket::add_user_data(p_client_id);
@@ -273,6 +289,22 @@ int sctp_layer::receive_message_on_fd(int p_client_id)
  return Abstract_Socket::receive_message_on_fd(p_client_id);
}

void sctp_layer::set_default_ppid(int p_client_id)
{
  loggers::get_instance().log(">>> sctp_layer::set_default_ppid: %d - ppid: %u", p_client_id, _ppid);

  if (_ppid == 0) { // Keep the socket default (PPID 0, unspecified)
    return;
  }
  // The PPID is opaque to SCTP and sent as given: network byte order (RFC 6458 clause 5.3.4)
  struct sctp_sndinfo info;
  std::memset(&info, 0, sizeof(info));
  info.snd_ppid = htonl(_ppid);
  if (::setsockopt(p_client_id, IPPROTO_SCTP, SCTP_DEFAULT_SNDINFO, &info, sizeof(info)) != 0) {
    loggers::get_instance().warning("sctp_layer::set_default_ppid: setsockopt(SCTP_DEFAULT_SNDINFO) failed: %s", std::strerror(errno));
  }
}

void sctp_layer::peer_disconnected(int p_client_id)
{
	loggers::get_instance().log(">>> sctp_layer::peer_disconnected: %d", p_client_id);
+7
Changes for ccsrc/Protocols/Sctp/sctp_layer.hh: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ class sctp_layer : public layer, public SSL_Socket, public PORT {
  int         _client_id;         //! Connection identifier
  std::string _time_key;          //! \todo
  bool        _reconnect_on_send; //! Set to true if connection shall be done when sending data. Otherwise, connection is established by the \see constructor
  uint32_t    _ppid;              //! SCTP Payload Protocol Identifier of the sent DATA chunks (host byte order), see params::ppid. 0: socket default left unchanged

public: //! \publicsection
  //sctp_layer(): PORT("TCP") {};
@@ -103,6 +104,12 @@ protected: //! \protectedsection
  void peer_disconnected(int p_client_id);

private: //! \privatesection
  /*!
   * \fn void set_default_ppid(int p_client_id);
   * \brief Set the default PPID of the messages sent on the connection (SCTP_DEFAULT_SNDINFO, RFC 6458 clause 8.1.31)
   * \param[in] p_client_id The connection identifier (socket file descriptor)
   */
  void set_default_ppid(int p_client_id);
  void Handle_Fd_Event(int fd, boolean is_readable, boolean is_writable, boolean is_error);
  void Handle_Timeout(double time_since_last_call);
}; // End of class sctp_layer