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

Add offline/online SCTP support

parent ef634498
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -35,6 +35,10 @@ public: //! \publicsection

  static const std::string& nic;          //! Network Interface Card parameter name

  static const std::string& ip_src;      //! Source IP address parameter name
  static const std::string& ip_dst;      //! Destination IP address parameter name
  static const std::string& ip_proto;    //! IP proto parameter name

  static const std::string& server;       //! Remote server address (e.g. www.etsi.org)
  static const std::string& port;         //! Remote server port. Default: 80
  static const std::string& use_ssl;      //! Set to 1 to use SSL to communicate with the HTTP server. Default: false
+4 −0
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@ const std::string& params::filter = std::string("filter");

const std::string& params::nic          = std::string("nic");

const std::string& params::ip_src      = std::string("ip_src");
const std::string& params::ip_dst      = std::string("ip_dst");
const std::string& params::ip_proto    = std::string("ip_proto");

const std::string& params::server       = std::string("server");
const std::string& params::port         = std::string("port");
const std::string& params::use_ssl      = std::string("use_ssl");
+73 −0
Original line number Diff line number Diff line
#include "ip_offline_layer_factory.hh"

#include "loggers.hh"

ip_offline_layer::ip_offline_layer(const std::string&  p_type, const std::string&  p_param) : layer(p_type), _params() {
  loggers::get_instance().log(">>> ip_offline_layer::ip_offline_layer: '%s', %s", to_string().c_str(), p_param.c_str());
  // Setup parameters
  params::convert(_params, p_param);
}

void ip_offline_layer::send_data(OCTETSTRING& p_data, params& p_params) {
  loggers::get_instance().log_msg(">>> ip_offline_layer::send_data: ", p_data);

  //OCTETSTRING ip;
  // FIXME FSCOM: To be done
  loggers::get_instance().error("ip_offline_layer::send_data: Not implemented. On;ly for offline mode");
  //ip    += p_data;
  //send_to_all_layers(ip, static_cast<params&>(p_params));
}

void ip_offline_layer::receive_data(OCTETSTRING& p_data, params& p_params) {
  loggers::get_instance().log_msg(">>> ip_offline_layer::receive_data: ", p_data);

  // Version
  uint8_t v = static_cast<const uint8_t>(*p_data);
  OCTETSTRING version = int2oct(1, v >> 4);
  loggers::get_instance().log_msg("ip_offline_layer::receive_data: verion: ", version);
  // Length in bytes
  uint8_t length = (v & 0x0f) * 4;
  loggers::get_instance().log("ip_offline_layer::receive_data: length: %d", length);
  // DSF
  OCTETSTRING dsf = OCTETSTRING(1, 1 + static_cast<const uint8_t *>(p_data));
  loggers::get_instance().log_msg("ip_offline_layer::receive_data: dsf: ", dsf);
  // Total Length
  OCTETSTRING total_length = OCTETSTRING(2, 2 + static_cast<const uint8_t*>(p_data));
  loggers::get_instance().log_msg("ip_offline_layer::receive_data: total_length: ", total_length);
  // Identification
  OCTETSTRING id = OCTETSTRING(2, 4 + static_cast<const uint8_t*>(p_data));
  loggers::get_instance().log_msg("ip_offline_layer::receive_data: id: ", id);
  // Flags 
  OCTETSTRING flags = OCTETSTRING(2, 6 + static_cast<const uint8_t*>(p_data));
  loggers::get_instance().log_msg("ip_offline_layer::receive_data: id: ", flags);
  // TTL 
  OCTETSTRING ttl = OCTETSTRING(1, 8 + static_cast<const uint8_t*>(p_data));
  loggers::get_instance().log_msg("ip_offline_layer::receive_data: ttl: ", ttl);
  // Protocol 
  OCTETSTRING protocol = OCTETSTRING(1, 9 + static_cast<const uint8_t*>(p_data));
  loggers::get_instance().log_msg("ip_offline_layer::receive_data: protocol: ", protocol);
  // checksum 
  OCTETSTRING checksum = OCTETSTRING(2, 10 + static_cast<const uint8_t*>(p_data));
  loggers::get_instance().log_msg("ip_offline_layer::receive_data: checksum: ", checksum);
  // src 
  OCTETSTRING src = OCTETSTRING(4, 12 + static_cast<const uint8_t*>(p_data));
  loggers::get_instance().log_msg("ip_offline_layer::receive_data: src: ", src);
  // dst 
  OCTETSTRING dst = OCTETSTRING(4, 16 + static_cast<const uint8_t*>(p_data));
  loggers::get_instance().log_msg("ip_offline_layer::receive_data: dst: ", dst);

  OCTETSTRING data = OCTETSTRING(p_data.lengthof() - length, length + static_cast<const uint8_t *>(p_data));
  loggers::get_instance().log_msg("ip_offline_layer::receive_data: payload for upper layer:", data);

  // Update params
  CHARSTRING s = oct2str(dst);
  p_params.insert(std::pair<std::string, std::string>(params::ip_dst, std::string(static_cast<const char *>(s))));
  s = oct2str(src);
  p_params.insert(std::pair<std::string, std::string>(params::ip_src, std::string(static_cast<const char *>(s))));
  s = oct2str(protocol);
  p_params.insert(std::pair<std::string, std::string>(params::ip_proto, std::string(static_cast<const char *>(s))));

  receive_to_all_layers(data, static_cast<params&>(p_params));
}

ip_offline_layer_factory ip_offline_layer_factory::_f;
+48 −0
Original line number Diff line number Diff line
/*!
 * \file      ip_offline_layer.hh
 * \brief     Header file for ITS IP protocol layer definition.
 * \author    ETSI TTF T041
 * \copyright ETSI Copyright Notification
 *            No part may be reproduced except as authorized by written permission.
 *            The copyright and the foregoing restriction extend to reproduction in all media.
 *            All rights reserved.
 * \version   0.1
 */
#pragma once

#include "params.hh"
#include "t_layer.hh"

class ip_offline_layer : public layer {
  params _params; //! Layer parameters

public: //! \publicsection
  /*!
   * \brief Specialised constructor
   *        Create a new instance of the ip_offline_layer class
   * \param[in] p_type \todo
   * \param[in] p_param \todo
   */
  ip_offline_layer(const std::string& p_type, const std::string& p_param);
  /*!
   * \brief Default destructor
   */
  virtual ~ip_offline_layer(){};

  /*!
   * \virtual
   * \fn void send_data(OCTETSTRING& data, params& p_params);
   * \brief Send bytes formated data to the lower layers
   * \param[in] p_data The data to be sent
   * \param[in] p_params Some parameters to overwrite default value of the lower layers parameters
   */
  virtual void send_data(OCTETSTRING& p_data, params& p_params);
  /*!
   * \virtual
   * \fn void receive_data(OCTETSTRING& data, params& p_params);
   * \brief Receive bytes formated data from the lower layers
   * \param[in] p_data The bytes formated data received
   * \param[in] p_params Some lower layers parameters values when data was received
   */
  virtual void receive_data(OCTETSTRING& p_data, params& p_params);
}; // End of class ip_offline_layer
+42 −0
Original line number Diff line number Diff line
/*!
 * \file      ip_offline_layer_factory.hh
 * \brief     Header file for ITS Ethernet protocol layer factory.
 * \author    ETSI TTF T041
 * \copyright ETSI Copyright Notification
 *            No part may be reproduced except as authorized by written permission.
 *            The copyright and the foregoing restriction extend to reproduction in all media.
 *            All rights reserved.
 * \version   0.1
 */
#pragma once

#include "layer_stack_builder.hh"

#include "ip_offline_layer.hh"

/*!
 * \class ip_offline_layer_factory
 * \brief  This class provides a factory class to create an ip_offline_layer class instance
 */
class ip_offline_layer_factory : public layer_factory {
  static ip_offline_layer_factory _f; //! Reference to the unique instance of this class
public:                             //! \publicsection
  /*!
   * \brief Default constructor
   *        Create a new instance of the ip_offline_layer_factory class
   * \remark The ETH layer identifier is ETH
   */
  ip_offline_layer_factory() {
    // register factory
    layer_stack_builder::register_layer_factory("IP_OFFLINE", this);
  };
  /*!
   * \fn layer* create_layer(const std::string&  type, const std::string&  param);
   * \brief  Create the layers stack based on the provided layers stack description
   * \param[in] p_type The provided layers stack description
   * \param[in] p_params Optional parameters
   * \return 0 on success, -1 otherwise
   * \inline
   */
  inline virtual layer *create_layer(const std::string& p_type, const std::string& p_param) { return new ip_offline_layer(p_type, p_param); };
}; // End of class ip_offline_layer_factory
Loading