srsLTE/srsue/test/ttcn3/hdr/ttcn3_srb_interface.h

161 lines
4.9 KiB
C
Raw Normal View History

/**
2019-09-16 12:17:21 -07:00
*
* \section COPYRIGHT
2019-09-16 12:17:21 -07:00
*
* Copyright 2013-2020 Software Radio Systems Limited
2019-09-16 12:17:21 -07:00
*
* 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.
2019-09-16 12:17:21 -07:00
*
*/
#ifndef SRSUE_TTCN3_SRB_INTERFACE_H
#define SRSUE_TTCN3_SRB_INTERFACE_H
#include "srslte/common/buffer_pool.h"
#include "srslte/common/common.h"
2020-04-21 12:53:37 -07:00
#include "srslte/mac/pdu.h"
2019-09-16 12:17:21 -07:00
#include "ttcn3_interfaces.h"
#include "ttcn3_port_handler.h"
2019-09-16 12:17:21 -07:00
#include <srslte/interfaces/ue_interfaces.h>
using namespace srslte;
// The SRB interface
class ttcn3_srb_interface : public ttcn3_port_handler
2019-09-16 12:17:21 -07:00
{
public:
ttcn3_srb_interface() : pool(byte_buffer_pool::get_instance()) {}
~ttcn3_srb_interface() = default;
2019-09-16 12:17:21 -07:00
int init(ss_srb_interface* syssim_, srslte::log* log_, std::string net_ip_, uint32_t net_port_)
2019-09-16 12:17:21 -07:00
{
syssim = syssim_;
log = log_;
net_ip = net_ip_;
net_port = net_port_;
initialized = true;
log->debug("Initialized.\n");
return port_listen();
2019-09-16 12:17:21 -07:00
}
void tx(const uint8_t* buffer, uint32_t len)
2019-09-16 12:17:21 -07:00
{
if (initialized) {
log->info_hex(buffer, len, "Sending %d B to Titan\n", len);
send(buffer, len);
2019-09-16 12:17:21 -07:00
} else {
log->error("Trying to transmit but port not connected.\n");
}
}
private:
///< Main message handler
int handle_message(const unique_byte_array_t& rx_buf, const uint32_t n)
2019-09-16 12:17:21 -07:00
{
log->debug_hex(rx_buf->begin(), n, "Received %d B from remote.\n", n);
2019-09-16 12:17:21 -07:00
// 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);
2019-09-16 12:17:21 -07:00
// 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;
2019-09-16 12:17:21 -07:00
Document document;
if (document.Parse((char*)&rx_buf->at(2)).HasParseError() || document.IsObject() == false) {
log->error_hex((uint8*)&rx_buf->at(2), json_len, "Error parsing incoming data.\n");
return SRSLTE_ERROR;
}
2019-09-16 12:17:21 -07:00
// Pretty-print
StringBuffer buffer;
PrettyWriter<StringBuffer> writer(buffer);
document.Accept(writer);
log->info("Received JSON with %d B\n%s\n", json_len, (char*)buffer.GetString());
// check for common
assert(document.HasMember("Common"));
assert(document["Common"].IsObject());
// Check for request type
assert(document.HasMember("RrcPdu"));
assert(document["RrcPdu"].IsObject());
// Get request type
const Value& rrcpdu = document["RrcPdu"];
if (rrcpdu.HasMember("Ccch")) {
rx_buf_offset += 2;
handle_ccch_pdu(document, &rx_buf->at(rx_buf_offset), n - rx_buf_offset);
} else if (rrcpdu.HasMember("Dcch")) {
rx_buf_offset += 2;
uint32_t lcid = document["Common"]["RoutingInfo"]["RadioBearerId"]["Srb"].GetInt();
handle_dcch_pdu(document, lcid, &rx_buf->at(rx_buf_offset), n - rx_buf_offset, ttcn3_helpers::get_follow_on_flag(document));
} else {
log->error("Received unknown request.\n");
2019-09-16 12:17:21 -07:00
}
return SRSLTE_SUCCESS;
2019-09-16 12:17:21 -07:00
}
// Todo: move to SYSSIM
void handle_ccch_pdu(Document& document, const uint8_t* payload, const uint16_t len)
{
log->info_hex(payload, len, "Received CCCH RRC PDU\n");
// pack into byte buffer
unique_byte_buffer_t pdu = pool_allocate_blocking;
pdu->N_bytes = len;
memcpy(pdu->msg, payload, pdu->N_bytes);
syssim->add_ccch_pdu(
ttcn3_helpers::get_timing_info(document), ttcn3_helpers::get_cell_name(document), std::move(pdu));
2019-12-17 08:45:10 -08:00
// TODO: is there a better way to check for RRCConnectionReestablishment?
if (ccch_is_rrc_reestablishment(document)) {
syssim->reestablish_bearer(ttcn3_helpers::get_cell_name(document), 1);
}
2019-09-16 12:17:21 -07:00
}
// Todo: move to SYSSIM
void
handle_dcch_pdu(Document& document, const uint16_t lcid, const uint8_t* payload, const uint16_t len, bool follow_on)
2019-09-16 12:17:21 -07:00
{
2020-02-06 01:57:21 -08:00
log->info_hex(payload, len, "Received DCCH RRC PDU (lcid=%d)\n", lcid);
2019-09-16 12:17:21 -07:00
// pack into byte buffer
unique_byte_buffer_t pdu = pool_allocate_blocking;
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);
2019-09-16 12:17:21 -07:00
}
bool ccch_is_rrc_reestablishment(Document& document)
{
const Value& dcch = document["RrcPdu"]["Ccch"];
if (dcch.HasMember("message_")) {
if (dcch["message_"].HasMember("c1")) {
if (dcch["message_"]["c1"].HasMember("rrcConnectionReestablishment")) {
return true;
}
}
}
return false;
}
ss_srb_interface* syssim = nullptr;
2019-09-16 12:17:21 -07:00
byte_buffer_pool* pool = nullptr;
// struct sctp_sndrcvinfo sri = {};
// struct sockaddr_in client_addr;
2019-09-16 12:17:21 -07:00
};
#endif // SRSUE_TTCN3_SRB_INTERFACE_H