Commit cba2c8d4 authored by Michele Carignani's avatar Michele Carignani

Merge branch 'latest-open-draft'

parents 9ecb6cb6 4688594a
......@@ -7,7 +7,13 @@
cd "$(dirname "$0")"
cd ./docker
run_dir="$(pwd)"
./docker/build-container.sh
./docker/run-container.sh "${run_dir}"
./build.sh
#./run.sh
cd -
exit 0
# MEC Testing Framework in TTCN-3
# MEC Testing Framework in TTCN-3 - - GS 032-3
## Introduction
This repositories contains the test specifications and test adapter code for MEC Testing project in TTCN-3.
This repositories contains the test specifications and test adapter code for MEC API Conformance Testing in TTCN-3, GS 032-3.
Latest publicly available drafts are available at https://docbox.etsi.org/isg/mec/open.
**{- Disclaimer: The content of this repository is related to a DRAFT, i.e. a working document, of ETSI ISG MEC. -}**
{-The content of the repository is provided for information only and is still under development. It may be updated, replaced, or removed at any time. Do not use as reference material. -}
For more information on ETSI ISG Multi-access Edge Computing (MEC), visit https://www.etsi.org/technologies/multi-access-edge-computing.
## Contact information
Email at cti_support at etsi dot org
Email at `cti_support` at `etsi` dot `org`.
## License
Unless specified otherwise, the content of this repository and the files contained are released under the BSD-3-Clause license.
See the attached LICENSE file or visit https://forge.etsi.org/legal-matters.
## Standard links
- Multi-access Edge Computating standards, accessible [here](https://www.etsi.org/standards#page=1&search=MEC&title=1&etsiNumber=1&content=1&version=0&onApproval=1&published=1&historical=1&startDate=1988-01-15&endDate=2019-05-06&harmonized=0&keyword=&TB=&stdType=&frequency=&mandate=&collection=&sort=1).
......
......@@ -8,8 +8,6 @@
#include "loggers.hh"
#include "converter.hh"
#include "LibItsHttp_TypesAndValues.hh"
#include "LibItsHttp_MessageBodyTypes.hh"
#include "LibItsHttp_XmlMessageBodyTypes.hh"
......@@ -80,7 +78,7 @@ int http_codec::decode (const OCTETSTRING& data, LibItsHttp__TypesAndValues::Htt
response.version__minor() = std::stoi(m[2].str().c_str());
response.statuscode() = std::stoi(m[3].str().c_str());
response.statustext() = CHARSTRING(m[4].str().c_str());
LibItsHttp__TypesAndValues::HeaderLines headers;
LibItsHttp__TypesAndValues::Headers headers;
std::string content_type;
decode_headers(decoding_buffer, headers, content_type);
response.header() = headers;
......@@ -105,7 +103,7 @@ int http_codec::decode (const OCTETSTRING& data, LibItsHttp__TypesAndValues::Htt
request.uri() = CHARSTRING(m[2].str().c_str());
request.version__major() = std::stoi(m[3].str().c_str());
request.version__minor() = std::stoi(m[4].str().c_str());
LibItsHttp__TypesAndValues::HeaderLines headers;
LibItsHttp__TypesAndValues::Headers headers;
std::string content_type;
decode_headers(decoding_buffer, headers, content_type);
request.header() = headers;
......@@ -142,10 +140,10 @@ int http_codec::encode_request(const LibItsHttp__TypesAndValues::Request& p_requ
p_encoding_buffer.put_cs("\r\n");
// Encode headers excepeted the Content-Length
const LibItsHttp__TypesAndValues::HeaderLines& headers = p_request.header();
const LibItsHttp__TypesAndValues::Headers& headers = p_request.header();
std::string content_type;
for (int i = 0; i < headers.size_of(); i++) {
const LibItsHttp__TypesAndValues::HeaderLine& header = headers[i];
const LibItsHttp__TypesAndValues::Header& header = headers[i];
loggers::get_instance().log_msg("http_codec::encode_request: Processing header ", header.header__name());
if (std::string(static_cast<const char*>(header.header__name())).compare("Content-Length") == 0) { // Skip it, processed later
loggers::get_instance().log("http_codec::encode_request: Skip it");
......@@ -203,12 +201,13 @@ int http_codec::encode_request(const LibItsHttp__TypesAndValues::Request& p_requ
p_encoding_buffer.put_cs("Content-Length: ");
if (_ec.length != 0) {
loggers::get_instance().log("http_codec::encode_request: Content-Length: %s", static_cast<const char*>(int2str(_ec.length + 2/*Stand for the last CRLF*/)));
p_encoding_buffer.put_cs(static_cast<const char*>(int2str(_ec.length + 2/*Stand for the last CRLF*/)));
p_encoding_buffer.put_cs(static_cast<const char*>(int2str(_ec.length)));
_ec.is_content_length_present = 0x01;
} else {
p_encoding_buffer.put_cs("0");
_ec.is_content_length_present = 0x00;
}
loggers::get_instance().log("http_codec::encode_request: Content-Length: %d - %x", _ec.length, _ec.is_content_length_present);
p_encoding_buffer.put_cs("\r\n");
// Add message body
......@@ -216,7 +215,7 @@ int http_codec::encode_request(const LibItsHttp__TypesAndValues::Request& p_requ
if (_ec.is_content_length_present == 0x01) {
loggers::get_instance().log_msg("http_codec::encode_request: Add body ", os);
p_encoding_buffer.put_os(os);
p_encoding_buffer.put_cs("\r\n");
//p_encoding_buffer.put_cs("\r\n");
}
loggers::get_instance().log_to_hexa("<<< http_codec::encode_request: ", p_encoding_buffer);
......@@ -239,11 +238,11 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
}
p_encoding_buffer.put_cs("\r\n");
// Encode headers excepted the Content-Length
const LibItsHttp__TypesAndValues::HeaderLines& headers = p_response.header();
// Encode headers excepeted the Content-Length
const LibItsHttp__TypesAndValues::Headers& headers = p_response.header();
std::string content_type;
for (int i = 0; i < headers.size_of(); i++) {
const LibItsHttp__TypesAndValues::HeaderLine& header = headers[i];
const LibItsHttp__TypesAndValues::Header& header = headers[i];
loggers::get_instance().log_msg("http_codec::encode_response: Processing header ", header.header__name());
p_encoding_buffer.put_cs(header.header__name());
p_encoding_buffer.put_cs(": ");
......@@ -256,7 +255,8 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
if (v.size_of() > 0) {
loggers::get_instance().log_msg("http_codec::encode_response: Processing value ", v[0]);
if (std::string(static_cast<const char*>(header.header__name())).compare("Content-Type") == 0) { // Store it for HTTP body payload encoding
int j = 1;
loggers::get_instance().log("http_codec::encode_response: Storing Content-Type");
int j = 0;
while (j < v.size_of()) {
content_type += v[j++];
} // End of 'while' statement
......@@ -266,7 +266,7 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
while (j < v.size_of()) {
p_encoding_buffer.put_cs(", ");
loggers::get_instance().log_msg("http_codec::encode_response: Processing value ", v[j]);
p_encoding_buffer.put_cs(v[j]);
p_encoding_buffer.put_cs(v[j++]);
j += 1;
} // End of 'while' statement
}
......@@ -288,34 +288,39 @@ int http_codec::encode_response (const LibItsHttp__TypesAndValues::Response& p_r
_ec.length = os.lengthof();
_ec.is_content_length_present = 0x01;
}
loggers::get_instance().log("http_codec::encode_request: length=%d", _ec.length);
loggers::get_instance().log("http_codec::encode_response: length=%d", _ec.length);
} else {
loggers::get_instance().log("http_codec::encode_request: HTTP body field not present");
loggers::get_instance().log("http_codec::encode_response: HTTP body field not present");
_ec.length = 0;
_ec.is_content_length_present = 0x00;
}
// Encode Content-Length header
p_encoding_buffer.put_cs("Content-Length: ");
if (_ec.length != 0) {
p_encoding_buffer.put_cs(int2str(_ec.length + 2/*Stand for the last CRLF*/));
loggers::get_instance().log("http_codec::encode_request: Content-Length: %s", static_cast<const char*>(int2str(_ec.length + 2/*Stand for the last CRLF*/)));
p_encoding_buffer.put_cs(static_cast<const char*>(int2str(_ec.length)));
_ec.is_content_length_present = 0x01;
} else {
p_encoding_buffer.put_cs("0");
_ec.is_content_length_present = 0x00;
}
loggers::get_instance().log("http_codec::encode_response: Content-Length: %d - %x", _ec.length, _ec.is_content_length_present);
loggers::get_instance().log("http_codec::encode_request: Content-Length: %d - %x", _ec.length, _ec.is_content_length_present);
p_encoding_buffer.put_cs("\r\n");
// Add message body
p_encoding_buffer.put_cs("\r\n");
if (_ec.length != 0) {
if (_ec.is_content_length_present == 0x01) {
loggers::get_instance().log_msg("http_codec::encode_request: Add body ", os);
p_encoding_buffer.put_os(os);
p_encoding_buffer.put_cs("\r\n");
// p_encoding_buffer.put_cs("\r\n");
}
loggers::get_instance().log_to_hexa("<<< http_codec::encode_response: ", p_encoding_buffer);
return 0;
}
int http_codec::decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::HeaderLines& headers, std::string& p_content_type) {
int http_codec::decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::Headers& headers, std::string& p_content_type) {
loggers::get_instance().log(">>> http_codec::decode_headers");
loggers::get_instance().log_to_hexa("http_codec::decode_headers", decoding_buffer);
......@@ -325,7 +330,7 @@ int http_codec::decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAn
switch(get_line(decoding_buffer, cstr, true)) {
case 0: {
loggers::get_instance().log_msg("http_codec::decode_headers: ", cstr);
LibItsHttp__TypesAndValues::HeaderLine header;
LibItsHttp__TypesAndValues::Header header;
if (decode_header(cstr, header) == -1) {
loggers::get_instance().warning("http_codec::decode_headers: Failed to decode header %s", static_cast<const char*>(cstr));
return -1;
......@@ -351,7 +356,7 @@ int http_codec::decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAn
} // End of 'while' statement
}
int http_codec::decode_header(CHARSTRING& header_line, LibItsHttp__TypesAndValues::HeaderLine& header) {
int http_codec::decode_header(CHARSTRING& header_line, LibItsHttp__TypesAndValues::Header& header) {
loggers::get_instance().log_msg(">>> http_codec::decode_header", header_line);
try {
......@@ -503,8 +508,8 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
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);
// Align the payload length with the specified Content-Length value
// Align the payload length with the specified Content-Lenght value
loggers::get_instance().log("http_codec::decode_body: _dc.length=%d - body length=%d", _dc.length, s.lengthof());
OCTETSTRING body;
if (_dc.length != 0) {
......@@ -515,10 +520,11 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
body = OCTETSTRING(_dc.length, p);
}
} else {
loggers::get_instance().warning("http_codec::decode_body: No Content-Length header, process all remaining bytes");
loggers::get_instance().warning("http_codec::decode_body: No Conten-Length header, process all remaining bytes");
body = s;
}
loggers::get_instance().log_msg("http_codec::decode_body: Aligned body=", body);
loggers::get_instance().log("http_codec::decode_body: body length=%d", body.lengthof());
// Remove CRLF if any
int counter = 0;
if ((body[body.lengthof() - 1].get_octet() == 0x0d) || (body[body.lengthof() - 1].get_octet() == 0x0a)) {
......@@ -528,10 +534,9 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
}
}
loggers::get_instance().log("http_codec::decode_body: counter=%d", counter);
loggers::get_instance().log("http_codec::decode_body: body length=%d", body.lengthof());
body = OCTETSTRING(body.lengthof() - counter, static_cast<const unsigned char*>(body));
if (_dc.chunked) {
counter = 0;
if (_dc.chunked){
int counter = 0;
int prev = 0;
OCTETSTRING os(0, nullptr);
do {
......@@ -569,8 +574,8 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
}
} while (counter < body.lengthof()); // Process next chunk if any
body = os;
loggers::get_instance().log_msg("http_codec::decode_body: Finalised body=", body);
}
loggers::get_instance().log_msg("http_codec::decode_body: Finalised body=", body);
// Check if HTTP message body contains binary characters
for (int i = 0; i < body.lengthof(); i++) {
unsigned char c = body[i].get_octet();
......@@ -688,7 +693,7 @@ int http_codec::decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBod
LibItsHttp__MessageBodyTypes::HtmlBody html_body;
message_body.html__body() = CHARSTRING(body.lengthof(), (char*)static_cast<const unsigned char*>(body));
} else {
loggers::get_instance().log("http_codec::decode_body: Use textBody as default");
loggers::get_instance().log("http_codec::decode_body: Use textBdy as default");
LibItsHttp__MessageBodyTypes::TextBody text_body;
message_body.text__body() = CHARSTRING(body.lengthof(), (char*)static_cast<const unsigned char*>(body));
}
......
#pragma once
#include <memory>
#include "codec.hh"
#include "params.hh"
class Base_Type;
class Record_Type;
class TTCN_Typedescriptor_t;
class TTCN_Buffer;
namespace LibItsHttp__TypesAndValues {
class HttpMessage;
class Request;
class Response;
class HeaderLines;
class HeaderLine;
}
namespace LibItsHttp__MessageBodyTypes {
class HttpMessageBody;
}
struct encoding_context {
unsigned int length;
unsigned char is_content_length_present;
encoding_context() { reset(); };
void reset() { length = -1; is_content_length_present = 0x00; };
};
struct decoding_context {
unsigned int length;
unsigned char is_binary;
bool chunked;
decoding_context() { reset(); };
void reset() { length = -1; is_binary = 0x00; chunked = false; };
};
class http_codec: public codec <
LibItsHttp__TypesAndValues::HttpMessage,
LibItsHttp__TypesAndValues::HttpMessage>
{
encoding_context _ec;
decoding_context _dc;
std::map<std::string, std::unique_ptr<codec<Record_Type, Record_Type> > > _codecs;
public:
explicit http_codec() : codec<LibItsHttp__TypesAndValues::HttpMessage, LibItsHttp__TypesAndValues::HttpMessage>(), _ec(), _dc(), _codecs() { };
virtual ~http_codec() { };
virtual int encode (const LibItsHttp__TypesAndValues::HttpMessage&, OCTETSTRING& data);
virtual int decode (const OCTETSTRING& data, LibItsHttp__TypesAndValues::HttpMessage&, params* params = NULL);
void set_payload_codecs(const std::string& p_codecs);
private:
int encode_request (const LibItsHttp__TypesAndValues::Request& p_request, TTCN_Buffer& p_encoding_buffer);
int encode_response (const LibItsHttp__TypesAndValues::Response& p_response, TTCN_Buffer& p_encoding_buffer);
int encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody& p_message_body, OCTETSTRING& p_encoding_buffer, const std::string& p_content_type);
int decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::HeaderLines& headers, std::string& p_content_type);
int decode_header(CHARSTRING& header_line, LibItsHttp__TypesAndValues::HeaderLine& header);
int decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBodyTypes::HttpMessageBody& message_body, const std::string& p_content_type);
int get_line(TTCN_Buffer& buffer, CHARSTRING& to, const bool concatenate_header_lines = false);
}; // End of class http_codec
#pragma once
#include <memory>
#include "codec.hh"
#include "params.hh"
class Base_Type;
class Record_Type;
class TTCN_Typedescriptor_t;
class TTCN_Buffer;
namespace LibItsHttp__TypesAndValues {
class HttpMessage;
class Request;
class Response;
class Headers;
class Header;
}
namespace LibItsHttp__MessageBodyTypes {
class HttpMessageBody;
}
struct encoding_context {
unsigned int length;
unsigned char is_content_length_present;
encoding_context() { reset(); };
void reset() { length = -1; is_content_length_present = 0x00; };
};
struct decoding_context {
unsigned int length;
unsigned char is_binary;
bool chunked;
decoding_context() { reset(); };
void reset() { length = -1; is_binary = 0x00; chunked = false; };
};
class http_codec: public codec <
LibItsHttp__TypesAndValues::HttpMessage,
LibItsHttp__TypesAndValues::HttpMessage>
{
encoding_context _ec;
decoding_context _dc;
std::map<std::string, std::unique_ptr<codec<Record_Type, Record_Type> > > _codecs;
public:
explicit http_codec() : codec<LibItsHttp__TypesAndValues::HttpMessage, LibItsHttp__TypesAndValues::HttpMessage>(), _ec(), _dc(), _codecs() { };
virtual ~http_codec() { };
virtual int encode (const LibItsHttp__TypesAndValues::HttpMessage&, OCTETSTRING& data);
virtual int decode (const OCTETSTRING& data, LibItsHttp__TypesAndValues::HttpMessage&, params* params = NULL);
void set_payload_codecs(const std::string& p_codecs);
private:
int encode_request (const LibItsHttp__TypesAndValues::Request& p_request, TTCN_Buffer& p_encoding_buffer);
int encode_response (const LibItsHttp__TypesAndValues::Response& p_response, TTCN_Buffer& p_encoding_buffer);
int encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody& p_message_body, OCTETSTRING& p_encoding_buffer, const std::string& p_content_type);
int decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::Headers& headers, std::string& p_content_type);
int decode_header(CHARSTRING& header_line, LibItsHttp__TypesAndValues::Header& header);
int decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBodyTypes::HttpMessageBody& message_body, const std::string& p_content_type);
int get_line(TTCN_Buffer& buffer, CHARSTRING& to, const bool concatenate_header_lines = false);
}; // End of class http_codec
......@@ -23,19 +23,51 @@ int json_codec::encode (const LibItsHttp__JsonMessageBodyTypes::JsonBody& msg, O
} else if (msg.ischosen(LibItsHttp__JsonMessageBodyTypes::JsonBody::ALT_userTrackingSubscription)) {
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("}"));
data = /*char2oct(CHARSTRING("{\"userTrackingSubscription\": ")) + */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("}"))*/;
} 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("}"))*/;
} 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("}"))*/;
} 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);
data = char2oct(CHARSTRING("{\"CellChangeSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
} else if (msg.ischosen(LibItsHttp__JsonMessageBodyTypes::JsonBody::ALT_appContext)) {
const UEAppInterfaceAPI__TypesAndValues::AppContext& appContext = msg.appContext();
appContext.encode(UEAppInterfaceAPI__TypesAndValues::AppContext_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
const UEAppInterfaceAPI__TypesAndValues::AppContext& app_context = msg.appContext();
app_context.encode(UEAppInterfaceAPI__TypesAndValues::AppContext_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
data = char2oct(CHARSTRING("{\"AppContext\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
} else if (msg.ischosen(LibItsHttp__JsonMessageBodyTypes::JsonBody::ALT_serviceInfo)) {
const AppEnablementAPI__TypesAndValues::ServiceInfo& service_info = msg.serviceInfo();
service_info.encode(AppEnablementAPI__TypesAndValues::ServiceInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
data = /*char2oct(CHARSTRING("{\"ServiceInfo\": ")) + */OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/;
} else if (msg.ischosen(LibItsHttp__JsonMessageBodyTypes::JsonBody::ALT_appTerminationNotificationSubscription)) {
const AppEnablementAPI__TypesAndValues::AppTerminationNotificationSubscription& app = msg.appTerminationNotificationSubscription();
app.encode(AppEnablementAPI__TypesAndValues::AppTerminationNotificationSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
data = /*char2oct(CHARSTRING("{\"AppTerminationNotificationSubscription\": ")) + */OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/;
} else if (msg.ischosen(LibItsHttp__JsonMessageBodyTypes::JsonBody::ALT_dnsRule)) {
const AppEnablementAPI__TypesAndValues::DnsRule& dns_rule = msg.dnsRule();
dns_rule.encode(AppEnablementAPI__TypesAndValues::DnsRule_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
data = /*char2oct(CHARSTRING("{\"DnsRule\": ")) + */OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/;
} else if (msg.ischosen(LibItsHttp__JsonMessageBodyTypes::JsonBody::ALT_serAvailabilityNotificationSubscription)) {
const AppEnablementAPI__TypesAndValues::SerAvailabilityNotificationSubscription& ser = msg.serAvailabilityNotificationSubscription();
ser.encode(AppEnablementAPI__TypesAndValues::SerAvailabilityNotificationSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
data = /*char2oct(CHARSTRING("{\"SerAvailabilityNotificationSubscription\": ")) + */OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/;
} else if (msg.ischosen(LibItsHttp__JsonMessageBodyTypes::JsonBody::ALT_trafficRule)) {
const AppEnablementAPI__TypesAndValues::TrafficRule& traffic_rule = msg.trafficRule();
traffic_rule.encode(AppEnablementAPI__TypesAndValues::TrafficRule_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
data = /*char2oct(CHARSTRING("{\"TrafficRule\": ")) + */OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/;
} else {
loggers::get_instance().error("json_codec::encode: Not supported");
}
loggers::get_instance().log("<<< json_codec::encode");
return 0;
}
......@@ -48,62 +80,146 @@ int json_codec::decode (const OCTETSTRING& p_data, LibItsHttp__JsonMessageBodyTy
params::const_iterator it;
if (p_params == nullptr) {
loggers::get_instance().warning("json_codec::decode: Failed to access p_params (null pointer)");
return -1;
return -1; // TODO Use p_data instead of return -1
} else {
it = p_params->find("decode_str");
if (it == p_params->cend()) {
loggers::get_instance().warning("json_codec::decode: Failed to access p_params item (decode_str)");
return -1;
return -1; // TODO Use p_data instead of return -1
}
loggers::get_instance().log("json_codec::decode: it->second='%c' / '%s'", it->second.c_str()[0], it->second.c_str());
}
loggers::get_instance().log("json_codec::decode: decode_str=%s", it->second.c_str());
// Remove data structure name (if present) ...
std::string str;
if ((it->second[0] != '[') && (it->second[0] != '{')) {
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);
} else {
str = it->second;
}
// ..and create the decoding buffer
TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);
TTCN_EncDec::clear_error();
// Remove data structure name...
int idx_begin = it->second.find(":");
int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
std::string str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
// ..and create the decoding buffer
loggers::get_instance().log("json_codec::decode: decoding_buffer=%s", str.c_str());
loggers::get_instance().log("json_codec::decode: decoding_buffer='%c' / '%s'", str[0], str.c_str());
TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
if (it->second.find("\"userList\"") != std::string::npos) { // Be careful to the order
// TODO To be refined, find("\"userList\"") is not optimal
LocationAPI__TypesAndValues::UserList user_list;
user_list.decode(LocationAPI__TypesAndValues::UserList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.userList() = user_list;
if (it->second.find("\"userList\"") != std::string::npos) { // Be careful to the order
// TODO To be refined, find("\"userList\"") 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::UserList user_list;
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
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;
} else if (it->second.find("\"SubscriptionLinkList\"") != std::string::npos) { // Be careful to the order
// TODO To be refined, find("\"accessPointList\"") is not optimal
RnisAPI__TypesAndValues::SubscriptionLinkList subscription_link_list;
subscription_link_list.decode(RnisAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.subscriptionLinkList() = subscription_link_list;
} else if (it->second.find("\"transportInfoList\"") != std::string::npos) { // Be careful to the order
// TODO To be refined, find("\"accessPointList\"") is not optimal
AppEnablementAPI__TypesAndValues::TransportInfoList transport_info_list;
transport_info_list.decode(AppEnablementAPI__TypesAndValues::TransportInfoList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.transportInfoList() = transport_info_list;
} else if (it->second.find("\"userTrackingSubscription\"") != 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::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("\"userInfo\"") != std::string::npos) {
} 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 '}'
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::PeriodicTrackingSubscription periodic_tracking_subscription;
periodic_tracking_subscription.decode(LocationAPI__TypesAndValues::PeriodicTrackingSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.periodicTrackingSubscription() = periodic_tracking_subscription;
} else if (it->second.find("\"accessPointId\"") != std::string::npos) {
LocationAPI__TypesAndValues::UserInfo user_info;
user_info.decode(LocationAPI__TypesAndValues::UserInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.userInfo() = user_info;
} else if (it->second.find("\"terminalDistance\"") != 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::TerminalDistance terminal_distance;
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) {
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) {
LocationAPI__TypesAndValues::DistanceNotificationSubscription notif;
notif.decode(LocationAPI__TypesAndValues::DistanceNotificationSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.distanceNotificationSubscription() = notif;
} else if (it->second.find("\"SubscriptionLinkList\"") != std::string::npos) { // Be careful to the order
// TODO To be refined, find("\"accessPointList\"") is not optimal
RnisAPI__TypesAndValues::SubscriptionLinkList subscription_link_list;
subscription_link_list.decode(RnisAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.subscriptionLinkList() = subscription_link_list;
} else if (it->second.find("\"ueIdentityTagInfo\"") != std::string::npos) {
UEidentityAPI__TypesAndValues::UeIdentityTagInfo ue_identity_tag_info;
ue_identity_tag_info.decode(UEidentityAPI__TypesAndValues::UeIdentityTagInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.ueIdentityTagInfo() = ue_identity_tag_info;
} else if (it->second.find("\"trafficRule\"") != std::string::npos) {
AppEnablementAPI__TypesAndValues::TrafficRule traffic_rule;
traffic_rule.decode(AppEnablementAPI__TypesAndValues::TrafficRule_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.trafficRule() = traffic_rule;
} else if (it->second.find("\"serName\"") != std::string::npos) { // Be careful to the order
// TODO To be refined, find("\"accessPointList\"") is not optimal
if (it->second[0] == '[') {
AppEnablementAPI__TypesAndValues::ServiceInfoList service_info_list;
service_info_list.decode(AppEnablementAPI__TypesAndValues::ServiceInfoList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.serviceInfoList() = service_info_list;
} else {
AppEnablementAPI__TypesAndValues::ServiceInfo service_info;
service_info.decode(AppEnablementAPI__TypesAndValues::ServiceInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.serviceInfo() = service_info;
}
} else if (it->second.find("\"security\"") != std::string::npos) { // Be careful to the order
// TODO To be refined, find("\"accessPointList\"") is not optimal
AppEnablementAPI__TypesAndValues::TransportInfoList transport_info_list;
transport_info_list.decode(AppEnablementAPI__TypesAndValues::TransportInfoList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.transportInfoList() = transport_info_list;
} else if (it->second.find("\"trafficRuleId\"") != std::string::npos) {
if (it->second[0] == '[') {
AppEnablementAPI__TypesAndValues::TrafficRuleList traffic_rule_list;
traffic_rule_list.decode(AppEnablementAPI__TypesAndValues::TrafficRuleList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.trafficRuleList() = traffic_rule_list;
} else {
AppEnablementAPI__TypesAndValues::TrafficRule traffic_rule;
traffic_rule.decode(AppEnablementAPI__TypesAndValues::TrafficRule_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.trafficRule() = traffic_rule;
}
} else if (it->second.find("\"dnsRuleId\"") != std::string::npos) {
if (it->second[0] == '[') {
AppEnablementAPI__TypesAndValues::DnsRuleList dns_rule_list;
dns_rule_list.decode(AppEnablementAPI__TypesAndValues::DnsRuleList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.dnsRuleList() = dns_rule_list;
} else {
AppEnablementAPI__TypesAndValues::DnsRule dns_rule;
dns_rule.decode(AppEnablementAPI__TypesAndValues::DnsRule_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.dnsRule() = dns_rule;
}
} else if ((it->second.find("\"appInstanceId\"") != std::string::npos) && (it->second.find("\"subscriptionType\"") != std::string::npos)) {
AppEnablementAPI__TypesAndValues::AppTerminationNotificationSubscription app_term;
app_term.decode(AppEnablementAPI__TypesAndValues::AppTerminationNotificationSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.appTerminationNotificationSubscription() = app_term;
} else if ((it->second.find("\"_links\"") != std::string::npos) && (it->second.find("\"subscriptions\"") != std::string::npos)) {
AppEnablementAPI__TypesAndValues::SubscriptionLinkList sub_link_list;
sub_link_list.decode(AppEnablementAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.subscriptionLinkList__app__ens() = sub_link_list;
} else if (it->second.find("\"subscriptionType\"") != std::string::npos) {
AppEnablementAPI__TypesAndValues::SerAvailabilityNotificationSubscription ser_av;
ser_av.decode(AppEnablementAPI__TypesAndValues::SerAvailabilityNotificationSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.serAvailabilityNotificationSubscription() = ser_av;
} else if (it->second.find("\"ntpServers\"") != std::string::npos) {
AppEnablementAPI__TypesAndValues::TimingCaps timing_caps;
timing_caps.decode(AppEnablementAPI__TypesAndValues::TimingCaps_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.timingCaps() = timing_caps;
} else if (it->second.find("\"timeSourceStatus\"") != std::string::npos) {
AppEnablementAPI__TypesAndValues::CurrentTime current_time;
current_time.decode(AppEnablementAPI__TypesAndValues::CurrentTime_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.currentTime() = current_time;
} else if (it->second.find("\"CellChangeSubscription\"") != std::string::npos) {
// // Replace "type": "1" by type": "EU_IPV4_ADDRESS", "type": "2"...
// // TODO Create a method instead of copy/past
......@@ -268,23 +384,15 @@ int json_codec::decode (const OCTETSTRING& p_data, LibItsHttp__JsonMessageBodyTy
TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
bw_info.decode(BwManagementAPI__TypesAndValues::BwInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
msg.bwInfo() = bw_info;
} else if (it->second.find("\"problemDetails\"") != std::string::npos) { // TODO To be refined, problemDetails in different modules
// UEidentityAPI__TypesAndValues::ProblemDetails problem_details;
// problem_details.decode(UEidentityAPI__TypesAndValues::ProblemDetails_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
// msg.problemDetails__ue__identity() = problem_details;
RnisAPI__TypesAndValues::ProblemDetails problem_details;
problem_details.decode(RnisAPI__TypesAndValues::ProblemDetails_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
msg.problemDetails__rnis() = problem_details;
} else if (it->second.find("\"detail\"") != std::string::npos) {
LibMec__TypesAndValues::ProblemDetails problem_details;