Commit 92df19e3 authored by garciay's avatar garciay
Browse files

STF545: Execute first EA tests

parent 7fd2a03a
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
#include "LibItsPki_EncdecDeclarations.hh"

#include "etsi_ts102941_data.hh"
#include "etsi_ts102941_types_enrolment_inner_request.hh"
#include "etsi_ts102941_types_enrolment_inner_response.hh"

@@ -7,6 +8,32 @@

namespace LibItsPki__EncdecDeclarations {

  BITSTRING fx__enc__EtsiTs102941Data(const EtsiTs102941MessagesItss::EtsiTs102941Data& p_etsi_ts_102941_data) {
    loggers::get_instance().log_msg(">>> fx__enc__EtsiTs102941Data: ", p_etsi_ts_102941_data);

    etsi_ts102941_data codec;
    OCTETSTRING os;
    if (codec.encode(p_etsi_ts_102941_data, os) == -1) {
      loggers::get_instance().warning("fx__enc__EtsiTs102941Data: -1 result code was returned");
      return int2bit(0, 1);
    }
    
    return oct2bit(os);
  }

  INTEGER fx__dec__EtsiTs102941Data(BITSTRING& b, EtsiTs102941MessagesItss::EtsiTs102941Data& p_etsi_ts_102941_data) {
    loggers::get_instance().log_msg(">>> fx__dec__EtsiTs102941Data: ", b);

    etsi_ts102941_data codec;
    OCTETSTRING is = bit2oct(b);
    if (codec.decode(is, p_etsi_ts_102941_data) == -1) {
      loggers::get_instance().warning("fx__dec__EtsiTs102941Data: -1 result code was returned");
      return -1;
    }
    
    return 0;
  }

  BITSTRING fx__enc__InnerEcRequest(const EtsiTs102941TypesEnrolment::InnerEcRequest& p_inner_request) {
    loggers::get_instance().log_msg(">>> fx_enc_InnerEcRequest: ", p_inner_request);

+3 −7
Original line number Diff line number Diff line
#include "LibItsCommon_Functions.hh"
#include <chrono>
#include <math.h>

#include "base_time.hh"

#ifndef M_PI
#define M_PI	3.14159265358979323846
#endif
@@ -16,13 +17,8 @@ namespace LibItsCommon__Functions
   */
  INTEGER fx__getCurrentTime(
) {
    unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L;  // TODO Add a global method such as its_tme() & its_time_mod() beacuse it is used also in geonetworking_layer
    /*unsigned long long its_ref_time = 1072911600000L;
    struct timeval tv;
    gettimeofday(&tv, NULL);
    unsigned long long ms = tv.tv_sec * 1000 + tv.tv_usec / 1000;*/
    INTEGER i;
    i.set_long_long_val(ms);
    i.set_long_long_val(base_time::get_instance().get_its_current_time());
    return i;
  }
  /**
+2 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ private:
public:
  static registration<TItem>& get_instance();

  virtual ~registration() { if (_instance != nullptr) delete _instance; };
  
public:
  void add_item(const std::string& type, TItem* f);
  TItem * get_item(const std::string& type);
+7 −11
Original line number Diff line number Diff line
#include <thread>
#include <chrono>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -13,6 +12,8 @@

#include "security_services.hh"

#include "base_time.hh"

#include "converter.hh"

using namespace LibItsGeoNetworking__TypesAndValues;
@@ -286,8 +287,7 @@ void geonetworking_layer::receive_data(OCTETSTRING& data, params& params) {
              eh->lsReplyHeader().dstPosVector().latitude() = sopv->latitude();
              eh->lsReplyHeader().dstPosVector().longitude() = sopv->longitude();
              // Update timestamp
              unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L;  // TODO Add method such as its_tme() & its_time_mod() beacuse it is used also in LibItsCommon_externals
              eh->lsReplyHeader().srcPosVector().timestamp__().set_long_long_val(ms);
              eh->lsReplyHeader().srcPosVector().timestamp__().set_long_long_val(base_time::get_instance().get_its_current_time());
              eh->lsReplyHeader().dstPosVector().timestamp__() = eh->lsReplyHeader().srcPosVector().timestamp__();
              
              loggers::get_instance().log_msg("geonetworking_layer::receive_data: ", *_ls_reply);
@@ -485,8 +485,7 @@ void geonetworking_layer::send_beacon() {
    loggers::get_instance().error("geonetworking_layer::send_beacon: Wrong cast");
  }
  // Update timestamp
  unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L;  // TODO Add method such as its_time() & its_time_mod()
  eh->beaconHeader().srcPosVector().timestamp__().set_long_long_val((unsigned int)ms);
  eh->beaconHeader().srcPosVector().timestamp__().set_long_long_val((unsigned int)base_time::get_instance().get_its_current_time());
  //loggers::get_instance().log_msg("geonetworking_layer::send_beacon: ", *_beacon);
  // Encode message using TITAN because of payload in omited
  TTCN_Buffer encoding_buffer;
@@ -943,8 +942,7 @@ int geonetworking_layer::build_geonetworking_pdu(OCTETSTRING& data, params& para
      _shb_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof();
      _shb_packet->gnPacket().packet().payload() = OPTIONAL<OCTETSTRING>(data);
      // Update timestamp
      unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L;  // TODO Add method such as its_tme() & its_time_mod()
      eh->shbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(ms));
      eh->shbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(base_time::get_instance().get_its_current_time()));
      
      loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: shb: ", *_shb_packet);
      // Encode GeoNetworking PDU
@@ -970,8 +968,7 @@ int geonetworking_layer::build_geonetworking_pdu(OCTETSTRING& data, params& para
      _tsb_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof();
      _tsb_packet->gnPacket().packet().payload() = OPTIONAL<OCTETSTRING>(data);
      // Update timestamp
      unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L;  // TODO Add method such as its_tme() & its_time_mod()
      eh->tsbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(ms));
      eh->tsbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(base_time::get_instance().get_its_current_time()));
      
      loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: tsb: ", *_tsb_packet);
      // Encode GeoNetworking PDU
@@ -999,8 +996,7 @@ int geonetworking_layer::build_geonetworking_pdu(OCTETSTRING& data, params& para
    _gbc_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof();
    _gbc_packet->gnPacket().packet().payload() = OPTIONAL<OCTETSTRING>(data);
    // Update timestamp
    unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L;  // TODO Add method such as its_tme() & its_time_mod()
    eh->geoBroadcastHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(ms));
    eh->geoBroadcastHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(base_time::get_instance().get_its_current_time()));
    
    loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: gbc: ", *_gbc_packet);

+34 −7
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ int http_codec::decode (const OCTETSTRING& data, LibItsHttp__TypesAndValues::Htt
      response.header() = headers;
      loggers::get_instance().log_to_hexa("Before decoding Body: ", decoding_buffer);
      LibItsHttp__MessageBodyTypes::HttpMessageBody body;
      if (decode_body(decoding_buffer, body) == -1) {
      if (decode_body(decoding_buffer, body, std::string("application/x-its-request"/*TODO Add Content-Type*/)) == -1) {
        response.body().set_to_omit();
      } else {
        response.body() = OPTIONAL<LibItsHttp__MessageBodyTypes::HttpMessageBody>(body);
@@ -106,7 +106,7 @@ int http_codec::decode (const OCTETSTRING& data, LibItsHttp__TypesAndValues::Htt
      request.header() = headers;
      OPTIONAL<LibItsHttp__MessageBodyTypes::HttpMessageBody> body;
      body.set_to_omit();
      if (decode_body(decoding_buffer, body) == -1) {
      if (decode_body(decoding_buffer, body, std::string("application/x-its-request"/*TODO Add Content-Type*/)) == -1) {
        request.body().set_to_omit();
      } else {
        request.body() = body;
@@ -375,6 +375,7 @@ int http_codec::decode_header(CHARSTRING& header_line, LibItsHttp__TypesAndValue

int http_codec::encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody& p_message_body, OCTETSTRING& p_encoding_buffer, const std::string& p_content_type) {
  loggers::get_instance().log_msg(">>> http_codec::encode_body: ", (const Base_Type&)p_message_body);
  loggers::get_instance().log("http_codec::encode_body: # of codecs=%d - %p", _codecs.size(), this);

  // Sanity check
  if (p_content_type.empty()) {
@@ -446,15 +447,20 @@ int http_codec::encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody&
  return 0;
}

int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBodyTypes::HttpMessageBody& message_body) {
int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBodyTypes::HttpMessageBody& message_body, const std::string& p_content_type) {
  loggers::get_instance().log(">>> http_codec::decode_body");
  loggers::get_instance().log_to_hexa("http_codec::decode_body", decoding_buffer);
  loggers::get_instance().log("http_codec::decode_body: # of codecs=%d", _codecs.size());
  loggers::get_instance().log("http_codec::decode_body: Content-Type=%s", p_content_type.c_str());
  loggers::get_instance().log("http_codec::decode_body: # of codecs=%d - %p", _codecs.size(), this);

  // Sanity check
  // Sanity checks
  if (decoding_buffer.get_len() - decoding_buffer.get_pos() <= 0) {
    return -1;
  }
  /* TODO Uncommentif (p_content_type.empty()) {
    loggers::get_instance().warning("http_codec::encode_body: Failed to select a codec for  HTTP body payload");
    return -1;
    }*/

  OCTETSTRING s(decoding_buffer.get_len() - decoding_buffer.get_pos(), decoding_buffer.get_data() + decoding_buffer.get_pos());
  loggers::get_instance().log_msg("http_codec::decode_body: raw body=", s);
@@ -497,8 +503,29 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
  LibItsHttp__MessageBodyTypes::HttpMessageBody v;
  if (_dc.is_binary == 0x01) {
    LibItsHttp__BinaryMessageBodyTypes::BinaryBody bb;
    bool processed = false;
    // TODO To be refined adding a string identifier to check which codec to use. E.g. held_code.id() returns "xmlns=\"urn:ietf:params:xml:ns:geopriv:held\">"
    if (p_content_type.find("x-its") != std::string::npos) {
      loggers::get_instance().log("http_codec::decode_body: Find 'x-its'");
      /*std::for_each(
                    _codecs.cbegin(),
                    _codecs.cend(),
                    [](const std::pair<const std::string, std::unique_ptr<codec<Record_Type, Record_Type> > >& p)
                    {
                      loggers::get_instance().log("http_codec::decode_body: Key='%s', %p", p.first.c_str(), p.second.get());
                    }
                    );*/
      if (_codecs["http_its"].get() != nullptr) { // TODO Use params
        loggers::get_instance().log("http_codec::decode_body: Call 'http_etsi_ieee1609dot2_codec'");
        _codecs["http_its"]->decode(body, bb.ieee1609dot2__data());
        processed = true;
      }
    } // TODO Add new HTTP message codec here
    if (!processed) {
      loggers::get_instance().warning("http_codec::decode_body: Unsupported HTTP codec, use raw field as default");
      bb.raw() = body;
      message_body.binary__body() = bb;
    }
  } else {
    // Convert into string
    params p;
Loading