Commit 4aef2a38 authored by Muhammad Umair Khan's avatar Muhammad Umair Khan
Browse files

validate MEC015 Traffic Management API and Multi-access Traffic Steering API

parent 78ed2cee
Loading
Loading
Loading
Loading
+84 −15
Original line number Original line Diff line number Diff line
@@ -6,7 +6,6 @@
#include "loggers.hh"
#include "loggers.hh"
#include "LibHttp_JsonMessageBodyTypes.hh"
#include "LibHttp_JsonMessageBodyTypes.hh"



int json_codec_mec015::encode(const LibHttp__JsonMessageBodyTypes::JsonBody &msg, OCTETSTRING &data)
int json_codec_mec015::encode(const LibHttp__JsonMessageBodyTypes::JsonBody &msg, OCTETSTRING &data)
{
{
  loggers::get_instance().log_msg(">>> json_codec::encode: ", (const Base_Type &)msg);
  loggers::get_instance().log_msg(">>> json_codec::encode: ", (const Base_Type &)msg);
@@ -19,6 +18,24 @@ int json_codec_mec015::encode (const LibHttp__JsonMessageBodyTypes::JsonBody &ms
  {
  {
    const TrafficManagementAPI__TypesAndValues::BwInfo &bw_info = msg.bwInfo();
    const TrafficManagementAPI__TypesAndValues::BwInfo &bw_info = msg.bwInfo();
    bw_info.encode(TrafficManagementAPI__TypesAndValues::BwInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    bw_info.encode(TrafficManagementAPI__TypesAndValues::BwInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    // Convert raw buffer to string
    std::string json_str((const char *)encoding_buffer.get_data(), encoding_buffer.get_len());

    // Apply single substitution
    if (json_str.find("\"Downlink\"") != std::string::npos)
      json_str = std::regex_replace(json_str, std::regex("\"Downlink\""), "\"00\"");
    else if (json_str.find("\"Uplink\"") != std::string::npos)
      json_str = std::regex_replace(json_str, std::regex("\"Uplink\""), "\"01\"");
    else if (json_str.find("\"Symmetrical\"") != std::string::npos)
      json_str = std::regex_replace(json_str, std::regex("\"Symmetrical\""), "\"10\"");

    // Set output
    data = OCTETSTRING(json_str.length(), (const unsigned char *)json_str.c_str());
  }
  else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_bwInfoDeltas))
  {
    const TrafficManagementAPI__TypesAndValues::BwInfoDeltas &bw_info_deltas = msg.bwInfoDeltas();
    bw_info_deltas.encode(TrafficManagementAPI__TypesAndValues::BwInfoDeltas_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data());
    data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data());
  }
  }
  else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_bwchgeventsubscription))
  else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_bwchgeventsubscription))
@@ -31,14 +48,26 @@ int json_codec_mec015::encode (const LibHttp__JsonMessageBodyTypes::JsonBody &ms
  {
  {
    const TrafficManagementAPI__TypesAndValues::MtsSessionInfo &mts_session_info = msg.mtsSessionInfo();
    const TrafficManagementAPI__TypesAndValues::MtsSessionInfo &mts_session_info = msg.mtsSessionInfo();
    mts_session_info.encode(TrafficManagementAPI__TypesAndValues::MtsSessionInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    mts_session_info.encode(TrafficManagementAPI__TypesAndValues::MtsSessionInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data());
    // Convert raw buffer to string
    std::string json_str((const char *)encoding_buffer.get_data(), encoding_buffer.get_len());

    // Apply single substitution
    if (json_str.find("\"Downlink\"") != std::string::npos)
      json_str = std::regex_replace(json_str, std::regex("\"Downlink\""), "\"00\"");
    else if (json_str.find("\"Uplink\"") != std::string::npos)
      json_str = std::regex_replace(json_str, std::regex("\"Uplink\""), "\"01\"");
    else if (json_str.find("\"Symmetrical\"") != std::string::npos)
      json_str = std::regex_replace(json_str, std::regex("\"Symmetrical\""), "\"10\"");

    // Set output
    data = OCTETSTRING(json_str.length(), (const unsigned char *)json_str.c_str());
  }
  }
  else
  else
  {
  {
    loggers::get_instance().error("json_codec::encode: Not supported");
    return json_codec::encode(msg, data);
  }
  }


  loggers::get_instance().log("<<< json_codec::encode");
  loggers::get_instance().log("<<< json_codec_mec015::encode");
  return 0;
  return 0;
}
}


@@ -78,7 +107,13 @@ int json_codec_mec015::decode(const OCTETSTRING &p_data, LibHttp__JsonMessageBod
  TTCN_EncDec::clear_error();
  TTCN_EncDec::clear_error();
  TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));
  TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));


  if ((it->second.find("\"bwInfo\"") != std::string::npos) || (it->second.find("\"fixedBWPriority\"") != std::string::npos))
  if (it->second == "[]")
  {
    msg.bwInfoList().set_size(0); // Assign bound empty list
    return 0;
  }

  if ((it->second.find("\"bwInfo\"") != std::string::npos) || (it->second.find("\"fixedBWPriority\"") != std::string::npos) || (it->second.find("\"allocationId\"") != std::string::npos))
  {
  {
    while (true)
    while (true)
    {
    {
@@ -94,9 +129,13 @@ int json_codec_mec015::decode(const OCTETSTRING &p_data, LibHttp__JsonMessageBod


    if (it->second[0] == '[')
    if (it->second[0] == '[')
    {
    {
      TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));
      OCTETSTRING json_str_oct((int)str.length(), (const unsigned char *)str.c_str());
      loggers::get_instance().log_msg("Attempting to decode BwInfoList JSON string:", json_str_oct);

      TTCN_Buffer decoding_buffer_(json_str_oct);
      TrafficManagementAPI__TypesAndValues::BwInfoList bw_info_list;
      TrafficManagementAPI__TypesAndValues::BwInfoList bw_info_list;
      bw_info_list.decode(TrafficManagementAPI__TypesAndValues::BwInfoList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      bw_info_list.decode(TrafficManagementAPI__TypesAndValues::BwInfoList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      loggers::get_instance().warning("Decoded BwInfoList successfully.");
      msg.bwInfoList() = bw_info_list;
      msg.bwInfoList() = bw_info_list;
    }
    }
    else
    else
@@ -127,24 +166,54 @@ int json_codec_mec015::decode(const OCTETSTRING &p_data, LibHttp__JsonMessageBod
    bw_chg_event_notification.decode(TrafficManagementAPI__TypesAndValues::BwChgEventNotification_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    bw_chg_event_notification.decode(TrafficManagementAPI__TypesAndValues::BwChgEventNotification_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.bwChgEventNotification() = bw_chg_event_notification;
    msg.bwChgEventNotification() = bw_chg_event_notification;
  }
  }
  else if ((it->second.find("\"mtsCapabilityInfo\"") != std::string::npos) || (it->second.find("\"mtsAccessInfo\"") != std::string::npos))
  else if ((it->second.find("\"mtsCapabilityInfo\"") != std::string::npos) || (it->second.find("\"mtsAccessInfo\"") != std::string::npos) || (it->second.find("\"allocationId\"") != std::string::npos))
  {
  {
    TrafficManagementAPI__TypesAndValues::MtsCapabilityInfo mts_cap_info;
    TrafficManagementAPI__TypesAndValues::MtsCapabilityInfo mts_cap_info;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));
    mts_cap_info.decode(TrafficManagementAPI__TypesAndValues::MtsCapabilityInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    mts_cap_info.decode(TrafficManagementAPI__TypesAndValues::MtsCapabilityInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.mtsCapabilityInfo() = mts_cap_info;
    msg.mtsCapabilityInfo() = mts_cap_info;
  }
  }
  else if ((it->second.find("\"mtsSessionInfo\"") != std::string::npos) || (it->second.find("\"mtsMode\"") != std::string::npos))
  else if ((it->second.find("\"mtsSessionInfo\"") != std::string::npos) || (it->second.find("\"sessionId\"") != std::string::npos))
  {
    while (true)
    {
      if (str.find("\"00\"") != std::string::npos)
        str = regex_replace(str, regex("\"00\""), "\"Downlink\"");
      else if (str.find("\"01\"") != std::string::npos)
        str = regex_replace(str, regex("\"01\""), "\"Uplink\"");
      else if (str.find("\"10\"") != std::string::npos)
        str = regex_replace(str, regex("\"10\""), "\"Symmetrical\"");
      else
        break;
    }
    if (it->second[0] == '[')
    {
      OCTETSTRING json_str_oct((int)str.length(), (const unsigned char *)str.c_str());
      loggers::get_instance().log_msg("Attempting to decode mtsSessionInfoList JSON string:", json_str_oct);

      TTCN_Buffer decoding_buffer_(json_str_oct);
      TrafficManagementAPI__TypesAndValues::MtsSessionInfos mts_session_infos;
      mts_session_infos.decode(TrafficManagementAPI__TypesAndValues::MtsSessionInfos_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      loggers::get_instance().warning("Decoded mtsSessionInfoList successfully");
      msg.mtsSessionInfos() = mts_session_infos;
    }
    else
    {
    {
      TrafficManagementAPI__TypesAndValues::MtsSessionInfo mts_session_info;
      TrafficManagementAPI__TypesAndValues::MtsSessionInfo mts_session_info;
      TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));
      TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));
      mts_session_info.decode(TrafficManagementAPI__TypesAndValues::MtsSessionInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      mts_session_info.decode(TrafficManagementAPI__TypesAndValues::MtsSessionInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      msg.mtsSessionInfo() = mts_session_info;
      msg.mtsSessionInfo() = mts_session_info;
    }
    }
  }
  else if (it->second.find("\"detail\"") != std::string::npos)
  {
    LibMec__TypesAndValues::ProblemDetails problem_details;
    problem_details.decode(LibMec__TypesAndValues::ProblemDetails_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.problemDetails() = problem_details;
  }
  else
  else
  {
  {
    loggers::get_instance().warning("json_codec::decode: Unsupported variant");
    return json_codec::decode(p_data, msg, p_params);
    return -1;
  }
  }


  loggers::get_instance().log_msg("<<< json_codec::decode: ", (const Base_Type &)msg);
  loggers::get_instance().log_msg("<<< json_codec::decode: ", (const Base_Type &)msg);
+59 −41

File changed.

Preview size limit exceeded, changes collapsed.

+102 −65

File changed.

Preview size limit exceeded, changes collapsed.

+21 −16
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ module TrafficManagementAPI_Functions {
    var HttpMessage v_response;
    var HttpMessage v_response;


    p_bw_allocation_id := "";
    p_bw_allocation_id := "";

    f_init_default_headers_list(-, -, v_headers);
    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
    httpPort.send(
                  m_http_request(
                  m_http_request(
@@ -46,9 +47,11 @@ module TrafficManagementAPI_Functions {
                                                                              m_body_json_bw_info(
                                                                              m_body_json_bw_info(
                                                                                                  m_bw_info(
                                                                                                  m_bw_info(
                                                                                                            p_app_instance_id,
                                                                                                            p_app_instance_id,
                                                                                                            APPLICATION_SPECIFIC_BW_ALLOCATION, // Request type
                                                                                                            APPLICATION_SPECIFIC_BW_ALLOCATION,
                                                                                                            "1024", // FixedAllocation
                                                                                                            "1024",
                                                                                                            Downlink // AllocationDirection
                                                                                                            Downlink,
                                                                                                            PX_APP_NAME,
                                                                                                            PX_APP_ALLOCATION_ID
                  ))))));
                  ))))));
    tc_ac.start;
    tc_ac.start;
    alt {
    alt {
@@ -60,10 +63,8 @@ module TrafficManagementAPI_Functions {
                                                                                                                       mw_bw_info(
                                                                                                                       mw_bw_info(
                                                                                                                                  p_app_instance_id
                                                                                                                                  p_app_instance_id
                           )))))) -> value v_response {
                           )))))) -> value v_response {
        var charstring_list v_header_location;
        // var charstring_list v_header_location;
        
        tc_ac.stop;
        tc_ac.stop;

        log("f_create_bw_allocation_resource: BwInfo resource created: ", v_response);
        log("f_create_bw_allocation_resource: BwInfo resource created: ", v_response);
        f_get_header(valueof(v_response.response.header), "Location", v_header_location);
        f_get_header(valueof(v_response.response.header), "Location", v_header_location);
        p_bw_allocation_id := regexp(
        p_bw_allocation_id := regexp(
@@ -128,7 +129,7 @@ module TrafficManagementAPI_Functions {
                                                                                                                                              PX_BW_EVENT_SUB_CALLBACK_URI,
                                                                                                                                              PX_BW_EVENT_SUB_CALLBACK_URI,
                                                                                                                                              -,
                                                                                                                                              -,
                                                                                                                                              -,
                                                                                                                                              -,
                                                                                                                                              {m_filter_criteria(PX_APP_INSTANCE_ID,-)}
                                                                                                                                              {m_filter_criteria(-,-)}
                  ))))));
                  ))))));
    tc_ac.start;
    tc_ac.start;
    alt {
    alt {
@@ -218,8 +219,10 @@ module TrafficManagementAPI_Functions {
                                                                                                                              PX_APP_INSTANCE_ID,
                                                                                                                              PX_APP_INSTANCE_ID,
                                                                                                                              APPLICATION_SPECIFIC_MTS_SESSION, // Request type
                                                                                                                              APPLICATION_SPECIFIC_MTS_SESSION, // Request type
                                                                                                                              m_qosd, // QoS
                                                                                                                              m_qosd, // QoS
                                                                                                                              LowCost, // MtsMode
                                                                                                                              QoS, // MtsMode
                                                                                                                              Downlink // TrafficDirection
                                                                                                                              Downlink, // TrafficDirection
                                                                                                                              -,
                                                                                                                              PX_APP_NAME                                                                                               
                              ))))));
                              ))))));
    tc_ac.start;
    tc_ac.start;
    alt {
    alt {
@@ -241,6 +244,8 @@ module TrafficManagementAPI_Functions {
          p_mts_session_id := v_mts_session_info_id[0];
          p_mts_session_id := v_mts_session_info_id[0];
          p_mts_session_info := v_response.response.body.json_body.mtsSessionInfo;
          p_mts_session_info := v_response.response.body.json_body.mtsSessionInfo;
        }
        }
         p_mts_session_info := v_response.response.body.json_body.mtsSessionInfo;
         log("f_create_mts_session_info_resource: BwInfo resource created: ", p_mts_session_info);
      }
      }
      [] tc_ac.timeout {
      [] tc_ac.timeout {
        log("f_create_mts_session_info_resource: Expected message not received");
        log("f_create_mts_session_info_resource: Expected message not received");
+6 −6
Original line number Original line Diff line number Diff line
@@ -8,17 +8,19 @@ module TrafficManagementAPI_Pixits {


  // LibMec/TrafficManagementAPI
  // LibMec/TrafficManagementAPI
  import from TrafficManagementAPI_TypesAndValues all;
  import from TrafficManagementAPI_TypesAndValues all;
  // LibMec/LocationAPI
  import from LocationAPI_TypesAndValues all;
  
  
  modulepar Json.String PX_APP_INSTANCE_ID := "appInst01";
  modulepar Json.String PX_APP_INSTANCE_ID := "81c51643-8c6f-4781-ad45-f8a457ca549b";
  
  
  modulepar Json.String PX_APP_INSTANCE_ID_2 := "appInst02";
  modulepar Json.String PX_APP_INSTANCE_ID_2 := "appInst02";
  
  
  modulepar Json.String PX_APP_ALLOCATION_ID := "appAllocationId01";
  modulepar Json.String PX_APP_ALLOCATION_ID := "1";
  
  
  modulepar Json.String PX_APP_NAME := "appName01";
  modulepar Json.String PX_APP_NAME := "appName01";


  modulepar Json.String PX_SESSION_IPv4 := "10.10.10.10";
  
  modulepar Json.String PX_SESSION_PORT := "1010";
  
  modulepar Json.String PX_UNKNOWN_APP_INSTANCE_ID := "appInst99";
  modulepar Json.String PX_UNKNOWN_APP_INSTANCE_ID := "appInst99";
  
  
  modulepar Json.String PX_UNKNOWN_APP_NAME := "appName99";
  modulepar Json.String PX_UNKNOWN_APP_NAME := "appName99";
@@ -27,8 +29,6 @@ module TrafficManagementAPI_Pixits {
  
  
  modulepar Json.String PX_UNKNOWN_BW_ALLOCATION_ID := "bwAllocationId99";
  modulepar Json.String PX_UNKNOWN_BW_ALLOCATION_ID := "bwAllocationId99";


  modulepar ResourceURL PX_RESOURCE_URL := "http://example.com/exampleAPI/location/v2/users?address:acr:192.0.0.1";

  modulepar Json.String PX_BW_SUBSCRIPTION_TYPE := "BwChgEventSubscription";
  modulepar Json.String PX_BW_SUBSCRIPTION_TYPE := "BwChgEventSubscription";
  
  
  modulepar Json.String PX_BW_NOTIFICATION_TYPE  := "BwChgEventNotification";
  modulepar Json.String PX_BW_NOTIFICATION_TYPE  := "BwChgEventNotification";
Loading