You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
srsRAN_4G/srsue/test/ttcn3/hdr/ttcn3_drb_interface.h

137 lines
4.4 KiB
C++

/**
*
* \section COPYRIGHT
*
* Copyright 2013-2020 Software Radio Systems Limited
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
*
*/
#ifndef SRSUE_TTCN3_DRB_INTERFACE_H
#define SRSUE_TTCN3_DRB_INTERFACE_H
#include "srslte/common/buffer_pool.h"
#include "srslte/common/common.h"
#include "srslte/mac/pdu.h"
#include "ttcn3_interfaces.h"
#include "ttcn3_port_handler.h"
#include <srslte/asn1/asn1_utils.h>
#include <srslte/interfaces/ue_interfaces.h>
using namespace srslte;
// The DRB interface
class ttcn3_drb_interface : public ttcn3_port_handler
{
public:
explicit ttcn3_drb_interface(srslog::basic_logger& logger) : ttcn3_port_handler(logger) {}
~ttcn3_drb_interface() = default;
int init(ss_srb_interface* syssim_, std::string net_ip_, uint32_t net_port_)
{
syssim = syssim_;
net_ip = net_ip_;
net_port = net_port_;
initialized = true;
logger.debug("Initialized.");
return port_listen();
}
void tx(const uint8_t* buffer, uint32_t len)
{
if (initialized) {
logger.info(buffer, len, "Sending %d B to Titan", len);
send(buffer, len);
} else {
logger.error("Trying to transmit but port not connected.");
}
}
private:
///< Main message handler
int handle_message(const unique_byte_array_t& rx_buf, const uint32_t n)
{
logger.debug(rx_buf->begin(), n, "Received %d B from remote.", n);
// Chop incoming msg, first two bytes are length of the JSON
// (see IPL4_EUTRA_SYSTEM_Definitions.ttcn
uint16_t json_len = ((uint16_t)rx_buf->at(0) << 8) | rx_buf->at(1);
// The data part after the JSON starts right here but handling
// is done in the respective functions
uint16_t rx_buf_offset = json_len + 2;
Document document;
if (document.Parse((char*)&rx_buf->at(2)).HasParseError() || document.IsObject() == false) {
logger.error((uint8*)&rx_buf->at(2), json_len, "Error parsing incoming data.");
return SRSLTE_ERROR;
}
// Pretty-print
StringBuffer buffer;
PrettyWriter<StringBuffer> writer(buffer);
document.Accept(writer);
logger.info("Received JSON with %d B\n%s", json_len, (char*)buffer.GetString());
// check for common
assert(document.HasMember("Common"));
assert(document["Common"].IsObject());
// Check for user data
assert(document.HasMember("U_Plane"));
assert(document["U_Plane"].IsObject());
// Handle Pdus
const Value& uplane = document["U_Plane"];
assert(uplane.HasMember("SubframeDataList"));
assert(uplane["SubframeDataList"].IsArray());
uint32_t lcid = document["Common"]["RoutingInfo"]["RadioBearerId"]["Drb"].GetInt() + 2;
for (Value::ConstValueIterator itr = uplane["SubframeDataList"].Begin(); itr != uplane["SubframeDataList"].End();
++itr) {
assert(itr->HasMember("PduSduList"));
assert((*itr)["PduSduList"].IsObject());
if ((*itr)["PduSduList"].HasMember("PdcpSdu")) {
assert((*itr)["PduSduList"]["PdcpSdu"].IsArray());
const Value& sdulist = (*itr)["PduSduList"]["PdcpSdu"];
for (Value::ConstValueIterator sdu_itr = sdulist.Begin(); sdu_itr != sdulist.End(); ++sdu_itr) {
assert(sdu_itr->IsString());
string sdustr = sdu_itr->GetString();
asn1::dyn_octstring octstr(sdustr.size());
octstr.from_string(sdustr);
handle_sdu(document, lcid, octstr.data(), octstr.size(), ttcn3_helpers::get_follow_on_flag(document));
}
} else if ((*itr)["PduSduList"].HasMember("MacPdu")) {
logger.warning("Not handling MacPdu type.");
} else {
logger.warning("Not handling this PduSdu type.");
}
}
return SRSLTE_SUCCESS;
}
void handle_sdu(Document& document, const uint16_t lcid, const uint8_t* payload, const uint16_t len, bool follow_on)
{
logger.info(payload, len, "Received DRB PDU (lcid=%d)", lcid);
// pack into byte buffer
unique_byte_buffer_t pdu = srslte::make_byte_buffer();
pdu->N_bytes = len;
memcpy(pdu->msg, payload, pdu->N_bytes);
syssim->add_dcch_pdu(ttcn3_helpers::get_timing_info(document),
ttcn3_helpers::get_cell_name(document),
lcid,
std::move(pdu),
follow_on);
}
ss_srb_interface* syssim = nullptr;
};
#endif // SRSUE_TTCN3_DRB_INTERFACE_H