From f0d9b333b20362fe6b9b4c3b0b9963fdf9ef5b8e Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Thu, 7 Sep 2017 13:19:53 +0200 Subject: [PATCH] Improved stability when UE reattaches --- lib/include/srslte/phy/phch/pdsch.h | 1 + lib/include/srslte/phy/phch/pusch.h | 1 + lib/include/srslte/upper/gw.h | 2 ++ lib/src/phy/phch/pdsch.c | 5 +++- lib/src/phy/phch/pusch.c | 6 ++-- lib/src/upper/gw.cc | 44 +++++++++++++++++------------ srsue/hdr/mac/ul_harq.h | 3 +- srsue/src/phy/phch_worker.cc | 28 +++++++++--------- 8 files changed, 54 insertions(+), 36 deletions(-) diff --git a/lib/include/srslte/phy/phch/pdsch.h b/lib/include/srslte/phy/phch/pdsch.h index 7c959f65c..7ef2d9b3d 100644 --- a/lib/include/srslte/phy/phch/pdsch.h +++ b/lib/include/srslte/phy/phch/pdsch.h @@ -61,6 +61,7 @@ typedef struct SRSLTE_API { uint32_t max_re; + uint16_t ue_rnti; bool is_ue; /* buffers */ diff --git a/lib/include/srslte/phy/phch/pusch.h b/lib/include/srslte/phy/phch/pusch.h index 834750e38..2328c8ff3 100644 --- a/lib/include/srslte/phy/phch/pusch.h +++ b/lib/include/srslte/phy/phch/pusch.h @@ -71,6 +71,7 @@ typedef struct SRSLTE_API { srslte_cell_t cell; bool is_ue; + uint16_t ue_rnti; uint32_t max_re; srslte_dft_precoding_t dft_precoding; diff --git a/lib/include/srslte/upper/gw.h b/lib/include/srslte/upper/gw.h index a9d58d2af..aa92ddc32 100644 --- a/lib/include/srslte/upper/gw.h +++ b/lib/include/srslte/upper/gw.h @@ -74,6 +74,8 @@ private: bool if_up; uint32_t lcid; + uint32_t current_ip_addr; + long ul_tput_bytes; long dl_tput_bytes; struct timeval metrics_time[3]; diff --git a/lib/src/phy/phch/pdsch.c b/lib/src/phy/phch/pdsch.c index 6bacf99cf..c33a0d1d3 100644 --- a/lib/src/phy/phch/pdsch.c +++ b/lib/src/phy/phch/pdsch.c @@ -381,6 +381,7 @@ int srslte_pdsch_set_rnti(srslte_pdsch_t *q, uint16_t rnti) { } } } + q->ue_rnti = rnti; q->users[rnti_idx]->cell_id = q->cell.id; q->users[rnti_idx]->sequence_generated = true; } else { @@ -400,6 +401,7 @@ void srslte_pdsch_free_rnti(srslte_pdsch_t* q, uint16_t rnti) } free(q->users[rnti_idx]); q->users[rnti_idx] = NULL; + q->ue_rnti = 0; } } @@ -527,7 +529,8 @@ static srslte_sequence_t *get_user_sequence(srslte_pdsch_t *q, uint16_t rnti, // The scrambling sequence is pregenerated for all RNTIs in the eNodeB but only for C-RNTI in the UE if (q->users[rnti_idx] && q->users[rnti_idx]->sequence_generated && - q->users[rnti_idx]->cell_id == q->cell.id && + q->users[rnti_idx]->cell_id == q->cell.id && + q->ue_rnti == rnti && ((rnti >= SRSLTE_CRNTI_START && rnti < SRSLTE_CRNTI_END) || !q->is_ue)) { return &q->users[rnti_idx]->seq[codeword_idx][sf_idx]; diff --git a/lib/src/phy/phch/pusch.c b/lib/src/phy/phch/pusch.c index ee01484d8..f52bbbb42 100644 --- a/lib/src/phy/phch/pusch.c +++ b/lib/src/phy/phch/pusch.c @@ -453,6 +453,7 @@ int srslte_pusch_set_rnti(srslte_pusch_t *q, uint16_t rnti) { return SRSLTE_ERROR; } } + q->ue_rnti = rnti; q->users[rnti_idx]->cell_id = q->cell.id; q->users[rnti_idx]->sequence_generated = true; } else { @@ -471,17 +472,18 @@ void srslte_pusch_free_rnti(srslte_pusch_t *q, uint16_t rnti) { } free(q->users[rnti_idx]); q->users[rnti_idx] = NULL; + q->ue_rnti = 0; } } - static srslte_sequence_t *get_user_sequence(srslte_pusch_t *q, uint16_t rnti, uint32_t sf_idx, uint32_t len) { uint32_t rnti_idx = q->is_ue?0:rnti; // The scrambling sequence is pregenerated for all RNTIs in the eNodeB but only for C-RNTI in the UE if (q->users[rnti_idx] && q->users[rnti_idx]->sequence_generated && - q->users[rnti_idx]->cell_id == q->cell.id && + q->users[rnti_idx]->cell_id == q->cell.id && + q->ue_rnti == rnti && ((rnti >= SRSLTE_CRNTI_START && rnti < SRSLTE_CRNTI_END) || !q->is_ue)) { return &q->users[rnti_idx]->seq[sf_idx]; diff --git a/lib/src/upper/gw.cc b/lib/src/upper/gw.cc index af5e45762..321d8d9e9 100644 --- a/lib/src/upper/gw.cc +++ b/lib/src/upper/gw.cc @@ -42,7 +42,9 @@ namespace srslte { gw::gw() :if_up(false) -{} +{ + current_ip_addr = 0; +} void gw::init(srsue::pdcp_interface_gw *pdcp_, srsue::ue_interface *ue_, log *gw_log_, uint32_t lcid_) { @@ -77,6 +79,8 @@ void gw::stop() thread_cancel(); } wait_thread_finish(); + + current_ip_addr = 0; } // TODO: tear down TUN device? @@ -126,38 +130,42 @@ void gw::write_pdu(uint32_t lcid, byte_buffer_t *pdu) *******************************************************************************/ error_t gw::setup_if_addr(uint32_t ip_addr, char *err_str) { - if(!if_up) - { + if (ip_addr != current_ip_addr) { + if(!if_up) + { if(init_if(err_str)) { gw_log->error("init_if failed\n"); return(ERROR_CANT_START); } - } + } - // Setup the IP address - sock = socket(AF_INET, SOCK_DGRAM, 0); - ifr.ifr_addr.sa_family = AF_INET; - ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr = htonl(ip_addr); - if(0 > ioctl(sock, SIOCSIFADDR, &ifr)) - { + // Setup the IP address + sock = socket(AF_INET, SOCK_DGRAM, 0); + ifr.ifr_addr.sa_family = AF_INET; + ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr = htonl(ip_addr); + if(0 > ioctl(sock, SIOCSIFADDR, &ifr)) + { err_str = strerror(errno); gw_log->debug("Failed to set socket address: %s\n", err_str); close(tun_fd); return(ERROR_CANT_START); - } - ifr.ifr_netmask.sa_family = AF_INET; - ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr("255.255.255.0"); - if(0 > ioctl(sock, SIOCSIFNETMASK, &ifr)) - { + } + ifr.ifr_netmask.sa_family = AF_INET; + ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr("255.255.255.0"); + if(0 > ioctl(sock, SIOCSIFNETMASK, &ifr)) + { err_str = strerror(errno); gw_log->debug("Failed to set socket netmask: %s\n", err_str); close(tun_fd); return(ERROR_CANT_START); - } + } - // Setup a thread to receive packets from the TUN device - start(GW_THREAD_PRIO); + current_ip_addr = ip_addr; + + // Setup a thread to receive packets from the TUN device + start(GW_THREAD_PRIO); + } return(ERROR_NONE); } diff --git a/srsue/hdr/mac/ul_harq.h b/srsue/hdr/mac/ul_harq.h index 9ce3b37ca..e57af77ba 100644 --- a/srsue/hdr/mac/ul_harq.h +++ b/srsue/hdr/mac/ul_harq.h @@ -369,7 +369,8 @@ private: current_irv = 0; is_msg3 = is_msg3_; Info("UL %d: New TX%s, RV=%d, TBS=%d, RNTI=%d\n", - pid, is_msg3?" for Msg3":"", get_rv(), cur_grant.n_bytes[0], cur_grant.rnti); + pid, is_msg3?" for Msg3":"", get_rv(), cur_grant.n_bytes[0], + is_msg3?harq_entity->rntis->temp_rnti:cur_grant.rnti); generate_tx(tti_tx, action); } } diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index fff8d2ca4..0e9932224 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -606,7 +606,7 @@ bool phch_worker::decode_pdcch_ul(mac_interface_phy::mac_grant_t* grant) { Error("Converting RAR message to UL grant\n"); return false; - } + } grant->rnti_type = SRSLTE_RNTI_TEMP; grant->is_from_rar = true; grant->has_cqi_request = false; // In contention-based Random Access CQI request bit is reserved @@ -681,22 +681,22 @@ void phch_worker::reset_uci() bzero(&uci_data, sizeof(srslte_uci_data_t)); } -void phch_worker::set_uci_ack(bool ack[SRSLTE_MAX_CODEWORDS], uint32_t nof_tb) { - if (nof_tb > 0) { - uci_data.uci_ack = (uint8_t) ((ack[0]) ? 1 : 0); - } + void phch_worker::set_uci_ack(bool ack[SRSLTE_MAX_CODEWORDS], uint32_t nof_tb) { + if (nof_tb > 0) { + uci_data.uci_ack = (uint8_t) ((ack[0]) ? 1 : 0); + } - if (nof_tb > 1) { - uci_data.uci_ack_2 = (uint8_t) ((ack[1]) ? 1 : 0); - } + if (nof_tb > 1) { + uci_data.uci_ack_2 = (uint8_t) ((ack[1]) ? 1 : 0); + } - if (nof_tb > 2) { - Error("Number of transport blocks is not supported"); - } + if (nof_tb > 2) { + Error("Number of transport blocks is not supported"); + } - uci_data.uci_ack_len = nof_tb; + uci_data.uci_ack_len = nof_tb; -} + } void phch_worker::set_uci_sr() { @@ -1075,7 +1075,7 @@ int phch_worker::read_ce_abs(float *ce_abs) { int phch_worker::read_pdsch_d(cf_t* pdsch_d) { - memcpy(pdsch_d, ue_dl.pdsch.d, ue_dl.pdsch_cfg.nbits[0].nof_re*sizeof(cf_t)); + memcpy(pdsch_d, ue_dl.pdsch.d[0], ue_dl.pdsch_cfg.nbits[0].nof_re*sizeof(cf_t)); return ue_dl.pdsch_cfg.nbits[0].nof_re; }