Commit 32b7eeda authored by YannGarcia's avatar YannGarcia
Browse files

Validate MEC-013 against MEC Sandbox

parent 9f3d6ba6
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -57,9 +57,7 @@ int http_codec::decode (const OCTETSTRING& data, LibItsHttp__TypesAndValues::Htt
    return -1;
  }
  loggers::get_instance().log_msg("http_codec::decode: message_id: ", message_id);
  if (message_id.lengthof() < 6) { // HTTP/ 
    return -1;
  }

  // Extract parameters
  try {
    std::string str(static_cast<const char*>(message_id));
@@ -558,6 +556,12 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
        loggers::get_instance().log("http_codec::decode_body: str: '%s'", str.c_str());
        int len = std::stoi(str, nullptr, 16);//converter::get_instance().string_to_int(str);
        loggers::get_instance().log("http_codec::decode_body: Chunk len: %d", len);
        if (len > body.lengthof()) { // Missing data :(
          loggers::get_instance().warning("http_codec::decode_body: Missing data and chunked mode");
          _params->insert(std::pair<std::string, std::string>("missing_data", "1"));
          _params->log();
          return -1;
        }
        while (counter < body.lengthof() && ((body[counter].get_octet() == '\r') || (body[counter].get_octet() == '\n'))) { // Skip additional \n
          counter += 1;
        } // End of 'while' statement
+27 −4
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ using namespace std; // Required for isnan()
#include "LibItsHttp_TypesAndValues.hh"
#include "LibItsHttp_TestSystem.hh"

http_layer::http_layer(const std::string & p_type, const std::string & param) : t_layer<LibItsHttp__TestSystem::HttpPort>(p_type), _params(), _device_mode{false}
http_layer::http_layer(const std::string & p_type, const std::string & param) : t_layer<LibItsHttp__TestSystem::HttpPort>(p_type), _params(), _device_mode{false}, _stream_buffer(0, NULL)
{
  loggers::get_instance().log(">>> http_layer::http_layer: %s, %s", to_string().c_str(), param.c_str());
  // Setup parameters
@@ -86,10 +86,33 @@ void http_layer::receive_data(OCTETSTRING& data, params& params)

  // Decode HTTP message
  LibItsHttp__TypesAndValues::HttpMessage http_message;
  if (!_stream_buffer.is_bound()) {
    if (data.lengthof() < 6) { // 'HTTP/' or 'GET /'
      loggers::get_instance().warning("http_layer::receive_data: Inconsistant buffer length");
      return;
    }
    if (_codec.decode(data, http_message, &params) == -1) {
    loggers::get_instance().warning("http_layer::receive_data: Failed to decode data");
      loggers::get_instance().warning("http_layer::receive_data (0): Failed to decode data");
      return;
    }
  } else {
    _stream_buffer += data;
    if (_codec.decode(_stream_buffer, http_message, &params) == -1) {
      loggers::get_instance().warning("http_layer::receive_data (1): Failed to decode data");
      return;
    }
  }
  params::const_iterator it = params.find("missing_data");
  if (it != params.cend()) {
    // Store data and wait for the next stream
    loggers::get_instance().warning("http_layer::receive_data: Missing data, save current stream");
    _stream_buffer += data;
    return; // Terminate here
  } else {
    // Reset stream buffer and continue
    loggers::get_instance().log("http_layer::receive_data: Reset stream buffer");
    _stream_buffer.clean_up();
  }
  if (_device_mode) {
    OCTETSTRING os;
    if (http_message.ischosen(LibItsHttp__TypesAndValues::HttpMessage::ALT_response)) {
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ class http_layer : public t_layer<LibItsHttp__TestSystem::HttpPort> {
  params _params;
  http_codec _codec;
  bool _device_mode;
  OCTETSTRING _stream_buffer; 

public: //! \publicsection
  /*!
+48 −4
Original line number Diff line number Diff line
@@ -24,18 +24,22 @@ int json_codec::encode (const LibItsHttp__JsonMessageBodyTypes::JsonBody& msg, O
    const LocationAPI__TypesAndValues::UserTrackingSubscription& user_tracking_subscription = msg.userTrackingSubscription();
    user_tracking_subscription.encode(LocationAPI__TypesAndValues::UserTrackingSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = char2oct(CHARSTRING("{\"userTrackingSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibItsHttp__JsonMessageBodyTypes::JsonBody::ALT_periodicNotificationSubscription)) {
    const LocationAPI__TypesAndValues::PeriodicNotificationSubscription& periodic_notification_subscription = msg.periodicNotificationSubscription();
    periodic_notification_subscription.encode(LocationAPI__TypesAndValues::PeriodicNotificationSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = char2oct(CHARSTRING("{\"periodicNotificationSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibItsHttp__JsonMessageBodyTypes::JsonBody::ALT_zonalTrafficSubscription)) {
    const LocationAPI__TypesAndValues::ZonalTrafficSubscription& zonal_traffic_subscription = msg.zonalTrafficSubscription();
    zonal_traffic_subscription.encode(LocationAPI__TypesAndValues::ZonalTrafficSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = /*char2oct(CHARSTRING("{\"zonalTrafficSubscription\": ")) + */OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/;
    data = char2oct(CHARSTRING("{\"zonalTrafficSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibItsHttp__JsonMessageBodyTypes::JsonBody::ALT_circleNotificationSubscription)) {
    const LocationAPI__TypesAndValues::CircleNotificationSubscription& notif = msg.circleNotificationSubscription();
    notif.encode(LocationAPI__TypesAndValues::CircleNotificationSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = /*char2oct(CHARSTRING("{\"circleNotificationSubscription\": ")) + */OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/;
    data = char2oct(CHARSTRING("{\"circleNotificationSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibItsHttp__JsonMessageBodyTypes::JsonBody::ALT_distanceNotificationSubscription)) {
    const LocationAPI__TypesAndValues::DistanceNotificationSubscription& notif = msg.distanceNotificationSubscription();
    notif.encode(LocationAPI__TypesAndValues::DistanceNotificationSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = /*char2oct(CHARSTRING("{\"distanceNotificationSubscription\": ")) + */OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/;
    data = char2oct(CHARSTRING("{\"distanceNotificationSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibItsHttp__JsonMessageBodyTypes::JsonBody::ALT_cellChangeSubscription)) {
    const RnisAPI__TypesAndValues::CellChangeSubscription& cell_change_subscription = msg.cellChangeSubscription();
    cell_change_subscription.encode(RnisAPI__TypesAndValues::CellChangeSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
@@ -135,7 +139,10 @@ int json_codec::decode (const OCTETSTRING& p_data, LibItsHttp__JsonMessageBodyTy
    user_list.decode(LocationAPI__TypesAndValues::UserList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.userList() = user_list;
  } else if (it->second.find("\"accessPointList\"") != std::string::npos) { // Be careful to the order
    // TODO To be refined, find("\"accessPointList\"") is not optimal
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::AccessPointList access_point_list;
    access_point_list.decode(LocationAPI__TypesAndValues::AccessPointList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.accessPointList() = access_point_list;
@@ -147,6 +154,35 @@ int json_codec::decode (const OCTETSTRING& p_data, LibItsHttp__JsonMessageBodyTy
    LocationAPI__TypesAndValues::UserTrackingSubscription user_tracking_subscription;
    user_tracking_subscription.decode(LocationAPI__TypesAndValues::UserTrackingSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.userTrackingSubscription() = user_tracking_subscription;






  } else if (it->second.find("\"periodicNotificationSubscription\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::PeriodicNotificationSubscription periodic_notification_subscription;
    periodic_notification_subscription.decode(LocationAPI__TypesAndValues::PeriodicNotificationSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.periodicNotificationSubscription() = periodic_notification_subscription;
  } else if (it->second.find("\"zonalTrafficSubscription\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::ZonalTrafficSubscription zonal_traffic_subscription;
    zonal_traffic_subscription.decode(LocationAPI__TypesAndValues::ZonalTrafficSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.zonalTrafficSubscription() = zonal_traffic_subscription;







  } else if (it->second.find("\"periodicTrackingSubscription\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
@@ -168,10 +204,18 @@ int json_codec::decode (const OCTETSTRING& p_data, LibItsHttp__JsonMessageBodyTy
    terminal_distance.decode(LocationAPI__TypesAndValues::TerminalDistance_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.terminalDistance() = terminal_distance;
  } else if (it->second.find("\"enteringLeavingCriteria\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::CircleNotificationSubscription notif;
    notif.decode(LocationAPI__TypesAndValues::CircleNotificationSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.circleNotificationSubscription() = notif;
  } else if (it->second.find("\"distanceNotificationSubscription\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::DistanceNotificationSubscription notif;
    notif.decode(LocationAPI__TypesAndValues::DistanceNotificationSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.distanceNotificationSubscription() = notif;
+8 −5
Original line number Diff line number Diff line
@@ -90,17 +90,20 @@ tcp_layer::tcp_layer(const std::string & p_type, const std::string & param) : la
      }
    }
    // Set trusted CA file
    it = _params.find(params::mutual_auth);
    /*it = _params.find(params::mutual_auth);
    if (it == _params.cend()) {
      parameter_set(ssl_trustedCAlist_file_name(), it->second.c_str());
      _params.insert(std::pair<std::string, std::string>(std::string("mutual_tls"), it->second));
    } else {
      parameter_set(ssl_trustedCAlist_file_name(), "/usr/share/ca-certificates/mozilla/Amazon_Root_CA_1.crt");
    }
      }*/
    // Set additional certificates
    //parameter_set(ssl_trustedCAlist_file_name(), "../certificates/out/certs/CA_dsa.cert.pem"); // FIXME Use a parameter
    //parameter_set(ssl_private_key_file_name(), "../certificates/out/privates/e5e11abad8003766e4a7b721afb175a189b5f4cc7046af9b0d8eaebb86f28c40_server_dsa.key.pem");
    //parameter_set(ssl_certificate_file_name(), "../certificates/out/certs/e5e11abad8003766e4a7b721afb175a189b5f4cc7046af9b0d8eaebb86f28c40_server_dsa.cert.pem");
    parameter_set(ssl_trustedCAlist_file_name(), "../certificates/out/certs/CA_rsa.cert.pem"); // FIXME Use a parameter
    parameter_set(ssl_private_key_file_name(), "../certificates/out/privates/96ea9868b49aebca76608fa2579e9c4884c14cc2c867d34423a4841e2225342d_server_rsa.key.pem");
    parameter_set(ssl_certificate_file_name(), "../certificates/out/certs/96ea9868b49aebca76608fa2579e9c4884c14cc2c867d34423a4841e2225342d_server_rsa.cert.pem");
  } else {
    parameter_set(ssl_trustedCAlist_file_name(), "../certificates/out/certs/CA_rsa.cert.pem"); // FIXME Use a parameter
    parameter_set(ssl_certificate_file_name(), "../certificates/out/certs/96ea9868b49aebca76608fa2579e9c4884c14cc2c867d34423a4841e2225342d_client_rsa.cert.pem");
  }
  set_ttcn_buffer_usercontrol(false);
  set_handle_half_close(true);
Loading