Commit 8ebec8de authored by Yann Garcia's avatar Yann Garcia
Browse files

Add basics Test System functionalities for AtsVRU

parent dee2bc3d
Loading
Loading
Loading
Loading
+226 −0
Original line number Diff line number Diff line
#include <memory>

#include "LibItsVru_EncdecDeclarations.hh"

#include "vru_codec.hh"
#include "loggers.hh"
#include "uppertester_vru_codec.hh"

namespace LibItsVru__EncdecDeclarations {
  /****************************************************
   * @desc    External function to encode a VamReq type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/
  BITSTRING fx__enc__VruReq(const LibItsVru__TypesAndValues::VamReq &p_vruReq) {
    loggers::get_instance().log_msg(">>> fx__enc__VruReq: ", p_vruReq);

    vru_codec   codec;
    OCTETSTRING os;
    if (codec.encode(p_vruReq.msgOut(), os) == -1) {
      loggers::get_instance().warning("fx__enc__VruReq: -1 result code was returned");
      return int2bit(0, 1);
    }

    return oct2bit(os);
  }

  /****************************************************
   * @desc    External function to decode a VamReq type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/
  INTEGER fx__dec__VruReq(BITSTRING &b, LibItsVru__TypesAndValues::VamReq &p) {
    loggers::get_instance().log(">>> fx__dec__VruReq");

    // Sanity check
    if (b.lengthof() == 0) {
      return -1;
    }

    vru_codec                   codec;
    VAM__PDU__Descriptions::VAM vru;
    OCTETSTRING                 is = bit2oct(b);

    if (codec.decode(is, vru) == -1) {
      loggers::get_instance().warning("fx__dec__VruReq: -1 result code was returned");
      return -1;
    }
    p.msgOut() = vru;

    return 0;
  }

  INTEGER fx__dec__VruInd(BITSTRING &b, LibItsVru__TypesAndValues::VamInd &p_vruInd) {
    loggers::get_instance().log(">>> fx__dec__VruInd");

    // Sanity check
    if (b.lengthof() == 0) {
      return -1;
    }

    vru_codec                   codec;
    VAM__PDU__Descriptions::VAM vru;
    OCTETSTRING                 is = bit2oct(b);

    // Calculate the size of the lower layers information
    int s = (LibItsVru__TypesAndValues::VamInd_gnNextHeader_raw_.fieldlength + LibItsVru__TypesAndValues::VamInd_gnHeaderType_raw_.fieldlength +
             LibItsVru__TypesAndValues::VamInd_gnHeaderSubtype_raw_.fieldlength + LibItsVru__TypesAndValues::VamInd_gnLifetime_raw_.fieldlength +
             LibItsVru__TypesAndValues::VamInd_gnTrafficClass_raw_.fieldlength + LibItsVru__TypesAndValues::VamInd_btpDestinationPort_raw_.fieldlength +
             LibItsVru__TypesAndValues::VamInd_btpInfo_raw_.fieldlength + LibItsVru__TypesAndValues::VamInd_ssp_raw_.fieldlength +
             LibItsVru__TypesAndValues::VamInd_its__aid_raw_.fieldlength) /
            8;
    // Decode CA message
    if (codec.decode(OCTETSTRING(is.lengthof() - s, static_cast<const unsigned char *>(is)), vru) == -1) {
      loggers::get_instance().warning("fx__dec__VruInd: -1 result code was returned");
      return -1;
    }
    p_vruInd.msgIn() = vru;
    // Decode lower layer data
    TTCN_Buffer decoding_buffer(OCTETSTRING(s, static_cast<const unsigned char *>(is) + is.lengthof() - s));
    loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer);
    // gnNextHeader
    if (decoding_buffer.get_read_len() < static_cast<size_t>(LibItsVru__TypesAndValues::VamInd_gnNextHeader_raw_.fieldlength / 8)) {
      p_vruInd.gnNextHeader().set_to_omit();
    } else {
      OCTETSTRING os;
      os.decode(LibItsVru__TypesAndValues::VamInd_gnNextHeader_descr_, decoding_buffer, TTCN_EncDec::CT_RAW);
      p_vruInd.gnNextHeader() = oct2int(os);
    }
    loggers::get_instance().log_msg("fx__dec__VruInd: gnNextHeader=", p_vruInd.gnNextHeader());
    loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer);
    // gnHeaderType
    if (decoding_buffer.get_read_len() < static_cast<size_t>(LibItsVru__TypesAndValues::VamInd_gnHeaderType_raw_.fieldlength / 8)) {
      p_vruInd.gnHeaderType().set_to_omit();
    } else {
      OCTETSTRING os;
      os.decode(LibItsVru__TypesAndValues::VamInd_gnHeaderType_descr_, decoding_buffer, TTCN_EncDec::CT_RAW);
      p_vruInd.gnHeaderType() = oct2int(os);
    }
    loggers::get_instance().log_msg("fx__dec__VruInd: gnHeaderType=", p_vruInd.gnHeaderType());
    loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer);
    // gnHeaderSubtype
    if (decoding_buffer.get_read_len() < static_cast<size_t>(LibItsVru__TypesAndValues::VamInd_gnHeaderSubtype_raw_.fieldlength / 8)) {
      p_vruInd.gnHeaderSubtype().set_to_omit();
    } else {
      OCTETSTRING os;
      os.decode(LibItsVru__TypesAndValues::VamInd_gnHeaderSubtype_descr_, decoding_buffer, TTCN_EncDec::CT_RAW);
      p_vruInd.gnHeaderSubtype() = oct2int(os);
    }
    loggers::get_instance().log_msg("fx__dec__VruInd: gnHeaderSubtype=", p_vruInd.gnHeaderSubtype());
    loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer);
    // gnLifetime
    if (decoding_buffer.get_read_len() < static_cast<size_t>(LibItsVru__TypesAndValues::VamInd_gnLifetime_raw_.fieldlength / 8)) {
      p_vruInd.gnLifetime().set_to_omit();
    } else {
      INTEGER i;
      i.decode(LibItsVru__TypesAndValues::VamInd_gnLifetime_descr_, decoding_buffer, TTCN_EncDec::CT_RAW);
      p_vruInd.gnLifetime() = i;
    }
    loggers::get_instance().log_msg("fx__dec__VruInd: gnLifetime=", p_vruInd.gnLifetime());
    loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer);
    // gnTrafficClass
    if (decoding_buffer.get_read_len() < static_cast<size_t>(LibItsVru__TypesAndValues::VamInd_gnTrafficClass_raw_.fieldlength / 8)) {
      p_vruInd.gnTrafficClass().set_to_omit();
    } else {
      OCTETSTRING os;
      os.decode(LibItsVru__TypesAndValues::VamInd_gnTrafficClass_descr_, decoding_buffer, TTCN_EncDec::CT_RAW);
      p_vruInd.gnTrafficClass() = oct2int(os);
    }
    loggers::get_instance().log_msg("fx__dec__VruInd: gnTrafficClass=", p_vruInd.gnTrafficClass());
    loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer);
    // btpDestinationPort
    if (decoding_buffer.get_read_len() < static_cast<size_t>(LibItsVru__TypesAndValues::VamInd_btpDestinationPort_raw_.fieldlength / 8)) {
      p_vruInd.btpDestinationPort().set_to_omit();
    } else {
      INTEGER i;
      i.decode(LibItsVru__TypesAndValues::VamInd_btpDestinationPort_descr_, decoding_buffer, TTCN_EncDec::CT_RAW);
      p_vruInd.btpDestinationPort() = i;
    }
    loggers::get_instance().log_msg("fx__dec__VruInd: btpDestinationPort=", p_vruInd.btpDestinationPort());
    loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer);
    // btpInfo
    if (decoding_buffer.get_read_len() < static_cast<size_t>(LibItsVru__TypesAndValues::VamInd_btpInfo_raw_.fieldlength / 8)) {
      p_vruInd.btpInfo().set_to_omit();
    } else {
      INTEGER i;
      i.decode(LibItsVru__TypesAndValues::VamInd_btpInfo_descr_, decoding_buffer, TTCN_EncDec::CT_RAW);
      p_vruInd.btpInfo() = i;
    }
    loggers::get_instance().log_msg("fx__dec__VruInd: btpInfo=", p_vruInd.btpInfo());
    loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer);
    // ssp
    if (decoding_buffer.get_read_len() < static_cast<size_t>(LibItsVru__TypesAndValues::VamInd_ssp_raw_.fieldlength / 8)) {
      p_vruInd.ssp().set_to_omit();
    } else {
      BITSTRING bs;
      bs.decode(LibItsVru__TypesAndValues::VamInd_ssp_descr_, decoding_buffer, TTCN_EncDec::CT_RAW);
      p_vruInd.ssp() = bs;
    }
    loggers::get_instance().log_msg("fx__dec__VruInd: ssp=", p_vruInd.ssp());
    loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer);
    // its__aid
    if (decoding_buffer.get_read_len() < static_cast<size_t>(LibItsVru__TypesAndValues::VamInd_its__aid_raw_.fieldlength / 8)) {
      p_vruInd.its__aid().set_to_omit();
    } else {
      INTEGER i;
      i.decode(LibItsVru__TypesAndValues::VamInd_its__aid_descr_, decoding_buffer, TTCN_EncDec::CT_RAW);
      p_vruInd.its__aid() = i;
    }
    loggers::get_instance().log_msg("fx__dec__VruInd: its_aid=", p_vruInd.its__aid());
    loggers::get_instance().log_to_hexa("fx__dec__VruInd: ", decoding_buffer);

    return 0;
  }

  BITSTRING fx__enc__VAM(const VAM__PDU__Descriptions::VAM &p_vru) {
    loggers::get_instance().log_msg(">>> fx__enc__VAM: ", p_vru);

    vru_codec   codec;
    OCTETSTRING os;
    codec.encode(p_vru, os);
    return oct2bit(os);
  }

  INTEGER fx__dec__VAM(BITSTRING &b, VAM__PDU__Descriptions::VAM &p) {
    loggers::get_instance().log(">>> fx__dec__VAM");
    vru_codec   codec;
    OCTETSTRING is = bit2oct(b);

    if (codec.decode(OCTETSTRING(is.lengthof(), static_cast<const unsigned char *>(is)), p) == -1) {
      loggers::get_instance().warning("fx__dec__VAM: -1 result code was returned");
      return -1;
    }

    return 0;
  }

  BITSTRING fx__enc__UtVruInitialize(const LibItsVru__TypesAndValues::UtVruInitialize &p_utVruInitialize) {
    loggers::get_instance().log_msg(">>> fx__enc__UtVruInitialize: ", p_utVruInitialize);

    uppertester_vru_codec codec;
    OCTETSTRING           os;
    codec.encode(p_utVruInitialize, os);
    return oct2bit(os);
  }

  /****************************************************
   * @desc    External function to decode a UtVruEventInd type
   * @param   value to encode
   * @return  encoded value
   ****************************************************/
  INTEGER fx__dec__UtVruEventInd(BITSTRING &b, LibItsVru__TypesAndValues::UtVruEventInd &p) {
    loggers::get_instance().log(">>> fx__dec__UtVruEventInd");

    uppertester_vru_codec      codec;
    OCTETSTRING                is  = bit2oct(b);
    std::unique_ptr<Base_Type> ptr = codec.decode(is);
    if (ptr == nullptr) {
      loggers::get_instance().warning("fx__dec__UtVruEventInd: -1 result code was returned");
      return -1;
    }
    p = static_cast<LibItsVru__TypesAndValues::UtVruEventInd &>(*ptr);
    return 0;
  }

} // namespace LibItsVru__EncdecDeclarations
+70 −0
Original line number Diff line number Diff line
#include <TTCN3.hh>

#include "loggers.hh"
#include "registration.hh"

#include "AdapterControlPort_VRU.hh"
#include "vru_layer.hh"

//=============================================================================
namespace LibItsVru__TestSystem {

  AdapterControlPort::AdapterControlPort(const char *par_port_name) : AdapterControlPort_BASE(par_port_name) {}

  AdapterControlPort::~AdapterControlPort() {}

  void AdapterControlPort::set_parameter(const char * /*parameter_name*/, const char * /*parameter_value*/) {}

  /*void AdapterControlPort::Handle_Fd_Event(int fd, boolean is_readable,
          boolean is_writable, boolean is_error) {}*/

  void AdapterControlPort::Handle_Fd_Event_Error(int /*fd*/) {}

  void AdapterControlPort::Handle_Fd_Event_Writable(int /*fd*/) {}

  void AdapterControlPort::Handle_Fd_Event_Readable(int /*fd*/) {}

  /*void AdapterControlPort::Handle_Timeout(double time_since_last_call) {}*/

  void AdapterControlPort::user_map(const char * /*system_port*/) {}

  void AdapterControlPort::user_unmap(const char * /*system_port*/) {}

  void AdapterControlPort::user_start() {}

  void AdapterControlPort::user_stop() {}

  void AdapterControlPort::outgoing_send(const LibItsCommon__TypesAndValues::AcGnssPrimitive & /*send_par*/) {}

  void AdapterControlPort::outgoing_send(const LibItsCommon__TypesAndValues::AcSecPrimitive &send_par) {
    loggers::get_instance().log_msg(">>> AdapterControlPort::outgoing_send: ", send_par);

    // Register this object for AdapterControlPort
    vru_layer *p = registration<vru_layer>::get_instance().get_item(std::string("VRU"));
    if (p != NULL) {
      loggers::get_instance().log("AdapterControlPort::outgoing_send: Got VRU layer %p", p);
      LibItsCommon__TypesAndValues::AdapterControlResults response;
      response.acSecResponse() = BOOLEAN(true);
      if (send_par.ischosen(LibItsCommon__TypesAndValues::AcSecPrimitive::ALT_acEnableSecurity)) {
        loggers::get_instance().log("AdapterControlPort::outgoing_send: Enable secured mode");
        std::string str(static_cast<const char *>(send_par.acEnableSecurity().certificateId()));
        if (p->enable_secured_mode(str, send_par.acEnableSecurity().enforceSecurity()) == -1) {
          response.acSecResponse() = BOOLEAN(false);
        }
      } else if (send_par.ischosen(LibItsCommon__TypesAndValues::AcSecPrimitive::ALT_acDisableSecurity)) {
        loggers::get_instance().log("AdapterControlPort::outgoing_send: Disable secured mode");
        if (p->disable_secured_mode() == -1) {
          response.acSecResponse() = BOOLEAN(false);
        }
      } else {
        response.acSecResponse() = BOOLEAN(false);
      }
      // Send response
      loggers::get_instance().log_msg("AdapterControlPort::outgoing_send: Send response: ", response);
      incoming_message(response);
    } else {
      loggers::get_instance().error("AdapterControlPort::outgoing_send: VRU not registered");
    }
  }

} // namespace LibItsVru__TestSystem
+36 −0
Original line number Diff line number Diff line
#ifndef AdapterControlPort_VRU_HH
#define AdapterControlPort_VRU_HH
//=============================================================================
#include "LibItsVru_TestSystem.hh"

namespace LibItsVru__TestSystem {

  class AdapterControlPort : public AdapterControlPort_BASE {
  public:
    AdapterControlPort(const char *par_port_name = NULL);
    ~AdapterControlPort();

    void set_parameter(const char *parameter_name, const char *parameter_value);

  private:
    /* void Handle_Fd_Event(int fd, boolean is_readable,
            boolean is_writable, boolean is_error); */
    void Handle_Fd_Event_Error(int fd);
    void Handle_Fd_Event_Writable(int fd);
    void Handle_Fd_Event_Readable(int fd);
    /* void Handle_Timeout(double time_since_last_call); */
  protected:
    void user_map(const char *system_port);
    void user_unmap(const char *system_port);

    void user_start();
    void user_stop();

    void outgoing_send(const LibItsCommon__TypesAndValues::AcGnssPrimitive &send_par);

    void outgoing_send(const LibItsCommon__TypesAndValues::AcSecPrimitive &send_par);
  };

} // namespace LibItsVru__TestSystem

#endif
+90 −0
Original line number Diff line number Diff line
#include "uppertester_vru_layer_factory.hh"

#include "UpperTesterPort_VRU.hh"
#include "loggers.hh"

//=============================================================================
namespace LibItsVru__TestSystem {

  UpperTesterPort::UpperTesterPort(const char *par_port_name)
    : UpperTesterPort_BASE(par_port_name), _cfg_params(), _layer_params(), _layer(NULL), _time_key("UpperTesterPort_Vru::outgoing_send") {
    loggers::get_instance().log("UpperTesterPort_Vru::UpperTesterPort_Vru");
  }

  UpperTesterPort::~UpperTesterPort() {
    if (_layer != NULL) {
      delete _layer;
    }
  }

  void UpperTesterPort::set_parameter(const char *parameter_name, const char *parameter_value) {
    loggers::get_instance().log("UpperTesterPort_Vru::set_parameter: %s=%s", parameter_name, parameter_value);
    _cfg_params.insert(std::pair<std::string, std::string>(std::string(parameter_name), std::string(parameter_value)));
    _cfg_params.log();
  }

  /*void UpperTesterPort::Handle_Fd_Event(int fd, boolean is_readable,
    boolean is_writable, boolean is_error) {}*/

  void UpperTesterPort::Handle_Fd_Event_Error(int /*fd*/) {}

  void UpperTesterPort::Handle_Fd_Event_Writable(int /*fd*/) {}

  void UpperTesterPort::Handle_Fd_Event_Readable(int /*fd*/) {}

  /*void UpperTesterPort::Handle_Timeout(double time_since_last_call) {}*/

  void UpperTesterPort::user_map(const char *system_port) {
    loggers::get_instance().log(">>> UpperTesterPort_Vru::user_map: %s", system_port);
    // Build layer stack
    params_its::iterator it = _cfg_params.find(std::string("params"));
    if (it != _cfg_params.end()) {
      loggers::get_instance().log("UpperTesterPort_Vru::user_map: %s", it->second.c_str());
      _layer = layer_stack_builder::get_instance()->create_layer_stack(it->second.c_str());
      if (static_cast<uppertester_vru_layer *>(_layer) == NULL) {
        loggers::get_instance().error("UpperTesterPort_Vru::user_map: Invalid stack configuration: %s", it->second.c_str());
      }
      static_cast<uppertester_vru_layer *>(_layer)->add_upper_port(this);
    } else {
      loggers::get_instance().error("UpperTesterPort_Vru::user_map: No layers defined in configuration file");
    }
  }

  void UpperTesterPort::user_unmap(const char *system_port) {
    loggers::get_instance().log(">>> UpperTesterPort_Vru::user_unmap: %s", system_port);
    if (_layer != NULL) {
      delete _layer;
      _layer = NULL;
    }
  }

  void UpperTesterPort::user_start() {}

  void UpperTesterPort::user_stop() {}

  void UpperTesterPort::outgoing_send(const LibItsVru__TypesAndValues::UtVruInitialize &send_par) {
    loggers::get_instance().log_msg(">>> UppertesterPort_Vru::outgoing_send: ", send_par);

    float duration;
    loggers::get_instance().set_start_time(_time_key);
    static_cast<uppertester_vru_layer *>(_layer)->sendMsg(send_par, _layer_params);
    loggers::get_instance().set_stop_time(_time_key, duration);
  }

  void UpperTesterPort::receiveMsg(const Base_Type &p_ind, const params &p_params) {
    loggers::get_instance().log_msg(">>> UpperTesterPort_Vru::receive_msg: ", p_ind);
    // Sanity check
    if (!p_ind.is_bound()) {
      return;
    }

    if (std::string(p_ind.get_descriptor()->name).compare("@LibItsVru_TypesAndValues.UtVruResults") == 0) { // TODO To be refined
      incoming_message(static_cast<const LibItsVru__TypesAndValues::UtVruResults &>(p_ind));
    } else if (std::string(p_ind.get_descriptor()->name).compare("@LibItsVru_TypesAndValues.UtVruEventInd") == 0) {
      incoming_message(static_cast<const LibItsVru__TypesAndValues::UtVruEventInd &>(p_ind));
    } else {
      loggers::get_instance().warning("UpperTesterPort_Vru::receive_msg: Message not processed: %s", p_ind.get_descriptor()->name);
    }
  }

} // namespace LibItsVru__TestSystem
+43 −0
Original line number Diff line number Diff line
#ifndef UpperTesterPort_VRU_HH
#define UpperTesterPort_VRU_HH

#include "layer.hh"
#include "params_its.hh"

//=============================================================================
#include "LibItsVru_TestSystem.hh"
namespace LibItsVru__TestSystem {

  class UpperTesterPort : public UpperTesterPort_BASE {
    params_its  _cfg_params;
    params_its  _layer_params;
    layer *     _layer;
    std::string _time_key;

  public:
    UpperTesterPort(const char *par_port_name = NULL);
    ~UpperTesterPort();

    void set_parameter(const char *parameter_name, const char *parameter_value);

    void receiveMsg(const Base_Type &, const params &);

  private:
    /* void Handle_Fd_Event(int fd, boolean is_readable,
       boolean is_writable, boolean is_error); */
    void Handle_Fd_Event_Error(int fd);
    void Handle_Fd_Event_Writable(int fd);
    void Handle_Fd_Event_Readable(int fd);
    /* void Handle_Timeout(double time_since_last_call); */
  protected:
    void user_map(const char *system_port);
    void user_unmap(const char *system_port);

    void user_start();
    void user_stop();

    void outgoing_send(const LibItsVru__TypesAndValues::UtVruInitialize &send_par);
  };

} // namespace LibItsVru__TestSystem
#endif
Loading