mac: move further init/config into ctor to allow early logging, etc.

master
Andre Puschmann 5 years ago
parent a868a13409
commit 92f0d58856

@ -37,9 +37,10 @@ template <class SubH>
class pdu
{
public:
pdu(uint32_t max_subheaders_) :
pdu(uint32_t max_subheaders_, srslte::log* log_) :
max_subheaders(max_subheaders_),
subheaders(max_subheaders_),
log(log_),
nof_subheaders(0),
cur_idx(-1),
pdu_len(0),
@ -152,6 +153,7 @@ protected:
bool pdu_is_ul;
byte_buffer_t* buffer_tx = nullptr;
int last_sdu_idx;
srslte::log* log = nullptr;
/* Prepares the PDU for parsing or writing by setting the number of subheaders to 0 and the pdu length */
virtual void init_(byte_buffer_t* buffer_tx_, uint32_t pdu_len_bytes, bool is_ulsch)
@ -291,11 +293,11 @@ private:
class sch_pdu : public pdu<sch_subh>
{
public:
sch_pdu(uint32_t max_subh) : pdu(max_subh) {}
sch_pdu(uint32_t max_subh, srslte::log* log) : pdu(max_subh, log) {}
void parse_packet(uint8_t* ptr);
uint8_t* write_packet();
uint8_t* write_packet(srslte::log* log_h);
uint8_t* write_packet(srslte::log* log);
bool has_space_ce(uint32_t nbytes, bool var_len = false);
bool has_space_sdu(uint32_t nbytes);
int get_pdu_len();
@ -356,7 +358,7 @@ private:
class rar_pdu : public pdu<rar_subh>
{
public:
rar_pdu(uint32_t max_rars = 16);
rar_pdu(uint32_t max_rars = 16, srslte::log* log_ = nullptr);
void set_backoff(uint8_t bi);
bool has_backoff();
@ -382,7 +384,7 @@ public:
class mch_pdu : public sch_pdu
{
public:
mch_pdu(uint32_t max_subh) : sch_pdu(max_subh) {}
mch_pdu(uint32_t max_subh, srslte::log* log) : sch_pdu(max_subh, log) {}
private:
/* Prepares the PDU for parsing or writing by setting the number of subheaders to 0 and the pdu length */

@ -57,7 +57,13 @@ void sch_pdu::parse_packet(uint8_t* ptr)
if (n_sub >= 0) {
subheaders[nof_subheaders - 1].set_payload_size(n_sub);
} else {
ERROR("Reading MAC PDU: negative payload for last subheader\n");
ERROR("Corrupted MAC PDU (read_len=%d, pdu_len=%d)\n", read_len, pdu_len);
if (log) {
log->info_hex(ptr, pdu_len, "Corrupted MAC PDU (read_len=%d, pdu_len=%d)\n", read_len, pdu_len);
}
// reset PDU
init_(buffer_tx, pdu_len, pdu_is_ul);
}
}
}
@ -828,7 +834,7 @@ void rar_pdu::fprint(FILE* stream)
pdu::fprint(stream);
}
rar_pdu::rar_pdu(uint32_t max_rars_) : pdu(max_rars_)
rar_pdu::rar_pdu(uint32_t max_rars_, srslte::log* log_) : pdu(max_rars_, log_)
{
backoff_indicator = 0;
has_backoff_indicator = false;

@ -193,7 +193,7 @@ int mac_sch_pdu_pack_test1()
rlc.write_sdu(2, sdu_len);
const uint32_t pdu_size = 25;
srslte::sch_pdu pdu(10);
srslte::sch_pdu pdu(10, &mac_log);
byte_buffer_t buffer;
pdu.init_tx(&buffer, pdu_size, true);
@ -256,7 +256,7 @@ int mac_sch_pdu_pack_test2()
const uint32_t pdu_size = 21;
srslte::sch_pdu pdu(10);
srslte::sch_pdu pdu(10, &mac_log);
byte_buffer_t buffer;
pdu.init_tx(&buffer, pdu_size, true);
@ -323,7 +323,7 @@ int mac_sch_pdu_pack_test3()
rlc.write_sdu(2, 130);
const uint32_t pdu_size = 150;
srslte::sch_pdu pdu(10);
srslte::sch_pdu pdu(10, &mac_log);
byte_buffer_t buffer;
pdu.init_tx(&buffer, pdu_size, true);
@ -377,7 +377,7 @@ int mac_sch_pdu_pack_test4()
mac_log.set_hex_limit(100000);
const uint32_t pdu_size = 10;
srslte::sch_pdu pdu(10);
srslte::sch_pdu pdu(10, &mac_log);
byte_buffer_t buffer;
pdu.init_tx(&buffer, pdu_size, true);
@ -430,7 +430,7 @@ int mac_sch_pdu_pack_error_test()
rlc.write_sdu(1, 8);
const uint32_t pdu_size = 150;
srslte::sch_pdu pdu(10);
srslte::sch_pdu pdu(10, &mac_log);
byte_buffer_t buffer;
pdu.init_tx(&buffer, pdu_size, true);

@ -37,12 +37,18 @@ class ue : public srslte::read_pdu_interface,
public srslte::pdu_queue::process_callback
{
public:
ue();
ue(uint16_t rnti,
uint32_t nof_prb,
sched_interface* sched,
rrc_interface_mac* rrc_,
rlc_interface_mac* rlc,
srslte::log* log_);
virtual ~ue();
void reset();
void start_pcap(srslte::mac_pcap* pcap_);
void set_tti(uint32_t tti);
void config(uint16_t rnti, uint32_t nof_prb, sched_interface *sched, rrc_interface_mac *rrc_, rlc_interface_mac *rlc, srslte::log *log_h);
@ -76,8 +82,7 @@ public:
void metrics_dl_pmi(uint32_t dl_cqi);
void metrics_dl_cqi(uint32_t dl_cqi);
bool is_phy_added;
bool is_phy_added = false;
int read_pdu(uint32_t lcid, uint8_t *payload, uint32_t requested_bytes);
private:
@ -87,28 +92,28 @@ private:
std::vector<uint32_t> lc_groups[4];
uint32_t phr_counter;
uint32_t dl_cqi_counter;
uint32_t dl_ri_counter;
uint32_t dl_pmi_counter;
uint32_t phr_counter = 0;
uint32_t dl_cqi_counter = 0;
uint32_t dl_ri_counter = 0;
uint32_t dl_pmi_counter = 0;
mac_metrics_t metrics;
srslte::mac_pcap* pcap;
uint64_t conres_id;
uint16_t rnti;
uint32_t last_tti;
uint32_t nof_failures;
srslte::mac_pcap* pcap = nullptr;
uint64_t conres_id = 0;
uint16_t rnti = 0;
uint32_t last_tti = 0;
uint32_t nof_failures = 0;
const static int NOF_RX_HARQ_PROCESSES = SRSLTE_FDD_NOF_HARQ;
const static int NOF_TX_HARQ_PROCESSES = SRSLTE_FDD_NOF_HARQ * SRSLTE_MAX_TB;
srslte_softbuffer_tx_t softbuffer_tx[NOF_TX_HARQ_PROCESSES];
srslte_softbuffer_rx_t softbuffer_rx[NOF_RX_HARQ_PROCESSES];
uint8_t* pending_buffers[NOF_RX_HARQ_PROCESSES];
uint8_t* pending_buffers[NOF_RX_HARQ_PROCESSES] = {nullptr};
// For DL there are two buffers, one for each Transport block
srslte::byte_buffer_t tx_payload_buffer[SRSLTE_FDD_NOF_HARQ][SRSLTE_MAX_TB];
@ -117,14 +122,14 @@ private:
srslte::pdu_queue pdus;
srslte::sch_pdu mac_msg_dl, mac_msg_ul;
srslte::mch_pdu mch_mac_msg_dl;
rlc_interface_mac *rlc;
rrc_interface_mac* rrc;
srslte::log *log_h;
sched_interface* sched;
bool conres_id_available;
rlc_interface_mac* rlc = nullptr;
rrc_interface_mac* rrc = nullptr;
srslte::log* log_h = nullptr;
sched_interface* sched = nullptr;
bool conres_id_available = false;
// Mutexes
pthread_mutex_t mutex;

@ -481,8 +481,7 @@ int mac::rach_detected(uint32_t tti, uint32_t preamble_idx, uint32_t time_adv)
pthread_rwlock_rdlock(&rwlock);
// Create new UE
ue_db[last_rnti] = new ue;
ue_db[last_rnti]->config(last_rnti, cell.nof_prb, &scheduler, rrc_h, rlc_h, log_h);
ue_db[last_rnti] = new ue(last_rnti, cell.nof_prb, &scheduler, rrc_h, rlc_h, log_h);
// Set PCAP if available
if (pcap) {
@ -985,8 +984,7 @@ void mac::write_mcch(sib_type2_s* sib2, sib_type13_r9_s* sib13, mcch_msg_s* mcch
mcch->pack(bref);
current_mcch_length = bref.distance_bytes(&mcch_payload_buffer[1]);
current_mcch_length = current_mcch_length + rlc_header_len;
ue_db[SRSLTE_MRNTI] = new ue;
ue_db[SRSLTE_MRNTI]->config(SRSLTE_MRNTI, cell.nof_prb, &scheduler, rrc_h, rlc_h, log_h);
ue_db[SRSLTE_MRNTI] = new ue(SRSLTE_MRNTI, cell.nof_prb, &scheduler, rrc_h, rlc_h, log_h);
rrc_h->add_user(SRSLTE_MRNTI);
}

@ -33,56 +33,28 @@
namespace srsenb {
ue::ue() :
mac_msg_dl(20),
mch_mac_msg_dl(10),
mac_msg_ul(20),
conres_id_available(false),
dl_ri_counter(0),
dl_pmi_counter(0),
conres_id(0),
last_tti(0),
ue::ue(uint16_t rnti_,
uint32_t nof_prb,
sched_interface* sched_,
rrc_interface_mac* rrc_,
rlc_interface_mac* rlc_,
srslte::log* log_) :
rnti(rnti_),
sched(sched_),
rrc(rrc_),
rlc(rlc_),
log_h(log_),
mac_msg_dl(20, log_h),
mch_mac_msg_dl(10, log_h),
mac_msg_ul(20, log_h),
pdus(128)
{
rrc = NULL;
sched = NULL;
rlc = NULL;
log_h = NULL;
rnti = 0;
pcap = NULL;
nof_failures = 0;
phr_counter = 0;
dl_cqi_counter = 0;
is_phy_added = false;
for (int i = 0; i < NOF_RX_HARQ_PROCESSES; i++) {
pending_buffers[i] = NULL;
}
bzero(&metrics, sizeof(mac_metrics_t));
bzero(&mutex, sizeof(pthread_mutex_t));
bzero(softbuffer_tx, sizeof(softbuffer_tx));
bzero(softbuffer_rx, sizeof(softbuffer_rx));
pthread_mutex_init(&mutex, NULL);
}
ue::~ue()
{
for (int i = 0; i < NOF_RX_HARQ_PROCESSES; i++) {
srslte_softbuffer_rx_free(&softbuffer_rx[i]);
}
for (int i = 0; i < NOF_TX_HARQ_PROCESSES; i++) {
srslte_softbuffer_tx_free(&softbuffer_tx[i]);
}
pthread_mutex_destroy(&mutex);
}
void ue::config(uint16_t rnti_, uint32_t nof_prb, sched_interface *sched_, rrc_interface_mac *rrc_, rlc_interface_mac *rlc_, srslte::log *log_h_)
{
rnti = rnti_;
rlc = rlc_;
rrc = rrc_;
log_h = log_h_;
sched = sched_;
pdus.init(this, log_h);
for (int i = 0; i < NOF_RX_HARQ_PROCESSES; i++) {
@ -92,18 +64,23 @@ void ue::config(uint16_t rnti_, uint32_t nof_prb, sched_interface *sched_, rrc_i
srslte_softbuffer_tx_init(&softbuffer_tx[i], nof_prb);
}
// don't need to reset because just initiated the buffers
bzero(&metrics, sizeof(mac_metrics_t));
nof_failures = 0;
for (int i = 0; i < NOF_RX_HARQ_PROCESSES; i++) {
pending_buffers[i] = NULL;
}
// Set LCID group for SRB0 and SRB1
set_lcg(0, 0);
set_lcg(1, 0);
}
ue::~ue()
{
for (int i = 0; i < NOF_RX_HARQ_PROCESSES; i++) {
srslte_softbuffer_rx_free(&softbuffer_rx[i]);
}
for (int i = 0; i < NOF_TX_HARQ_PROCESSES; i++) {
srslte_softbuffer_tx_free(&softbuffer_tx[i]);
}
pthread_mutex_destroy(&mutex);
}
void ue::reset()
{
bzero(&metrics, sizeof(mac_metrics_t));

@ -43,11 +43,10 @@ public:
class demux : public srslte::pdu_queue::process_callback
{
public:
demux();
demux(srslte::log* log_);
void init(phy_interface_mac_common* phy_h_,
rlc_interface_mac* rlc,
mac_interface_demux* mac,
srslte::log* log_h_,
srslte::timers::timer* time_alignment_timer);
bool process_pdus();
@ -82,11 +81,11 @@ private:
bool is_uecrid_successful;
phy_interface_mac_common* phy_h;
srslte::log* log_h;
srslte::timers::timer* time_alignment_timer;
rlc_interface_mac* rlc;
mac_interface_demux* mac;
phy_interface_mac_common* phy_h = nullptr;
srslte::log* log_h = nullptr;
srslte::timers::timer* time_alignment_timer = nullptr;
rlc_interface_mac* rlc = nullptr;
mac_interface_demux* mac = nullptr;
// Buffer of PDUs
srslte::pdu_queue pdus;

@ -54,10 +54,10 @@ namespace srsue {
class mux
{
public:
mux();
mux(srslte::log* log_);
~mux(){};
void reset();
void init(rlc_interface_mac *rlc, srslte::log *log_h, bsr_interface_mux *bsr_procedure, phr_proc *phr_procedure_);
void init(rlc_interface_mac* rlc, bsr_interface_mux* bsr_procedure, phr_proc* phr_procedure_);
void step(const uint32_t tti);

@ -30,30 +30,28 @@
namespace srsue {
demux::demux() :
mac_msg(20),
mch_mac_msg(20),
pending_mac_msg(20),
demux::demux(srslte::log* log_) :
mac_msg(20, log_),
mch_mac_msg(20, log_),
pending_mac_msg(20, log_),
rlc(NULL),
log_h(log_),
is_uecrid_successful(false),
phy_h(nullptr),
log_h(nullptr),
time_alignment_timer(nullptr),
mac(nullptr)
{
}
void demux::init(phy_interface_mac_common* phy_h,
rlc_interface_mac* rlc,
mac_interface_demux* mac,
srslte::log* log_h,
srslte::timers::timer* time_alignment_timer)
void demux::init(phy_interface_mac_common* phy_,
rlc_interface_mac* rlc_,
mac_interface_demux* mac_,
srslte::timers::timer* time_alignment_timer_)
{
this->phy_h = phy_h;
this->log_h = log_h;
this->rlc = rlc;
this->mac = mac;
this->time_alignment_timer = time_alignment_timer;
phy_h = phy_;
rlc = rlc_;
mac = mac_;
time_alignment_timer = time_alignment_timer_;
pdus.init(this, log_h);
bzero(&mch_lcids, SRSLTE_N_MCH_LCIDS);
}
@ -177,7 +175,7 @@ void demux::process_pdu(uint8_t* mac_pdu, uint32_t nof_bytes, srslte::pdu_queue:
void demux::process_sch_pdu_rt(uint8_t* buff, uint32_t nof_bytes)
{
srslte::sch_pdu mac_msg_rt(20);
srslte::sch_pdu mac_msg_rt(20, log_h);
mac_msg_rt.init_rx(nof_bytes);
mac_msg_rt.parse_packet(buff);

@ -37,7 +37,14 @@ using namespace asn1::rrc;
namespace srsue {
mac::mac(srslte::log* log_) : timers(64), pdu_process_thread(&demux_unit), mch_msg(10), pcap(nullptr), log_h(log_)
mac::mac(srslte::log* log_) :
timers(64),
pdu_process_thread(&demux_unit),
mch_msg(10, log_),
mux_unit(log_),
demux_unit(log_),
pcap(nullptr),
log_h(log_)
{
// Create PCell HARQ entities
auto ul = ul_harq_entity_ptr(new ul_harq_entity());
@ -76,8 +83,8 @@ bool mac::init(phy_interface_mac_lte* phy, rlc_interface_mac* rlc, rrc_interface
bsr_procedure.init(rlc_h, log_h, &timers);
phr_procedure.init(phy_h, log_h, &timers);
mux_unit.init(rlc_h, log_h, &bsr_procedure, &phr_procedure);
demux_unit.init(phy_h, rlc_h, this, log_h, timers.get(timer_alignment));
mux_unit.init(rlc_h, &bsr_procedure, &phr_procedure);
demux_unit.init(phy_h, rlc_h, this, timers.get(timer_alignment));
ra_procedure.init(
phy_h, rrc, log_h, &uernti, timers.get(timer_alignment), timers.get(contention_resolution_timer), &mux_unit);
sr_procedure.init(phy_h, rrc, log_h);

@ -32,14 +32,13 @@
namespace srsue {
mux::mux() : pdu_msg(MAX_NOF_SUBHEADERS)
mux::mux(srslte::log* log_) : pdu_msg(MAX_NOF_SUBHEADERS, log_), log_h(log_)
{
msg3_flush();
}
void mux::init(rlc_interface_mac *rlc_, srslte::log *log_h_, bsr_interface_mux *bsr_procedure_, phr_proc *phr_procedure_)
void mux::init(rlc_interface_mac* rlc_, bsr_interface_mux* bsr_procedure_, phr_proc* phr_procedure_)
{
log_h = log_h_;
rlc = rlc_;
bsr_procedure = bsr_procedure_;
phr_procedure = phr_procedure_;

Loading…
Cancel
Save