Skip to content

Commit

Permalink
resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuyang Cao committed Sep 21, 2024
2 parents d090096 + 5b5ee5d commit 2fd21fc
Show file tree
Hide file tree
Showing 26 changed files with 2,374 additions and 1,144 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Implement on top of srsRAN_4G UE code, decode the DCI and SIB information for 5G

## Requirements

We tested this system on Ubuntu 22.04 system and it may support other version of Ubuntu. To build this project and make it run properly, the following libraries are needed.
We tested this system on Ubuntu 22.04 system and it may support other version of Ubuntu. To build this project and make it run properly, the following libraries are needed. Please refer to the [wiki page](https://github.com/PrincetonUniversity/NG-Scope-5G/wiki) for feature description and detailed build instruction.

[UHD libraries](https://files.ettus.com/manual/page_install.html):

Expand Down Expand Up @@ -51,7 +51,9 @@ sudo ldconfig
# to double check, libs should appear at /usr/local/lib and header liquid.h should appear at /usr/local/include/liquid/
```

For different USRP daughterboard, different `config.yaml` should be used.
For different USRP daughterboard, different `config.yaml` should be used. Please refer to the sample `config.yaml` in `./nrscope/config/config.yaml` and the explanatory comment in it.


CBX:

```
Expand Down
26 changes: 14 additions & 12 deletions nrscope/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
nof_usrp_dev: 1
usrp_setting_0:
ssb_freq: 3488160000 #1989850000 #1970450000 #3489600000 #3649440000 #3650880000 # 1970450000 #2600040000 #3488160000 #3685440000 #3561600000 #1842050000 #2528550000 #3565920000 #2524950000 #2523750000 # 3565920000 # 2527350000 #3408960000 # should be set to the ssb frequency of the cell
rf_args: "clock=external,serial=32B0F2F,type=x300,master_clock_rate=200000000,sampling_rate=25000000" #"type=x300" #"clock=external" for TwinRX
# rf_args: "clock=external,type=x300,sampling_rate=23040000" #"type=x300" #"clock=external" for CBX
rx_gain: 90 # for x310 CBX, max rx gain is 31.5, for b210, it's around 80, for x310 TwinRX, max rx gain is 90
srate_hz: 25000000 #11520000 #11520000 #23040000 (CBX)
srsran_srate_hz: 23040000
nof_carriers: 1
nof_antennas: 1
ssb_freq: 3660960000 # Set to the ssb frequency of the cell, could be obtained with the cell scan function
rf_args: "clock=external,type=x300,serial=32B0F2F,master_clock_rate=200000000,sampling_rate=50000000" # For TwinRX daughterboard
# rf_args: "clock=external,type=x300,sampling_rate=23040000" #"type=x300" #"clock=external" # For CBX daughterboard
rx_gain: 80 # for x310 CBX, max rx gain is 31.5, for b210, it's around 80, for x310 TwinRX, max rx gain is 90
srate_hz: 50000000 # the sampling rate of USRP, integer division of 200MHz for TwinRX, and 5G sampling rate for CBX: 11520000 or 23040000
srsran_srate_hz: 46080000 # the sampling for real signal processing, should be in 5G sampling rate, multiple of 1.92 MHz.
nof_carriers: 1 # srsRAN rf setting, always set to be 1 for now.
nof_antennas: 1 # srsRAN rf setting, always set to be 1 for now.
scs_index: 1 #(0: 15kHz, 1: 30kHz, ..., the u in standard)
rf_log_level: "debug"
nof_rnti_worker_groups: 1
nof_bwps: 2
nof_rnti_worker_groups: 1 # number of of threads for DCI decoding, each will divide the UEs into small groups
nof_bwps: 1 # number of BWP of the cell
nof_workers: 4 # using worker pool to asynchronously process the slot data
cpu_affinity: true # pin the worker's thread into CPU or not.

log_name: "a.csv" #"/home/wanhr/Documents/data/nrscope/evaluation/coverage_amarisoft/dci_tx_50.csv" # x (0-10), y(0-8) coordinates
log_name: "a.csv"
google_dataset_id: "ngscope5g_dci_log_wanhr"

# usrp_setting_1:
# dl_freq: 3649440000 #3685440000 #3561600000 #1842050000 #2528550000 #3565920000 #2524950000 #2523750000 # 3565920000 # 2527350000 #3408960000 # should be set to the ssb frequency of the cell
# dl_freq: 3649440000 # should be set to the ssb frequency of the cell
# rf_args: "serial=31993A8,clock=external,type=b200" #"type=x300" #"clock=external"
# rx_gain: 30 # for x310, max rx gain is 31.5, for b210, it's around 80
# srate_hz: 23040000
Expand Down
23 changes: 14 additions & 9 deletions nrscope/hdr/dci_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define DCI_DECODER_H

#include "nrscope/hdr/nrscope_def.h"
#include "nrscope/hdr/task_scheduler.h"
// #include "nrscope/hdr/task_scheduler.h"

class DCIDecoder{
public:
Expand Down Expand Up @@ -54,14 +54,19 @@ class DCIDecoder{
DCIDecoder(uint32_t max_nof_rntis);
~DCIDecoder();

int dci_decoder_and_reception_init(srsran_ue_dl_nr_sratescs_info arg_scs_,
TaskSchedulerNRScope* task_scheduler_nrscope,
cf_t* input[SRSRAN_MAX_PORTS],
u_int8_t bwp_id);

int decode_and_parse_dci_from_slot(srsran_slot_cfg_t* slot,
TaskSchedulerNRScope* task_scheduler_nrscope,
cf_t * raw_buffer);
int DCIDecoderandReceptionInit(WorkState* state,
int bwp_id,
cf_t* input[SRSRAN_MAX_PORTS]);

int DecodeandParseDCIfromSlot(srsran_slot_cfg_t* slot,
WorkState* state,
std::vector <DCIFeedback>& sharded_results,
std::vector <std::vector <uint16_t> >& sharded_rntis,
std::vector<uint32_t>& nof_sharded_rntis,
std::vector <float>& dl_prb_rate,
std::vector <float>& dl_prb_bits_rate,
std::vector <float>& ul_prb_rate,
std::vector <float>& ul_prb_bits_rate);

// int dci_thread(TaskSchedulerNRScope* task_scheduler_nrscope);
};
Expand Down
116 changes: 104 additions & 12 deletions nrscope/hdr/nrscope_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ struct cell_searcher_args_t {
srsran::srsran_band_helper bands;

// Deduce band number
uint16_t band = bands.get_band_from_dl_freq_Hz_and_scs(base_carrier.dl_center_frequency_hz, scs_input);
uint16_t band = bands.get_band_from_dl_freq_Hz_and_scs(
base_carrier.dl_center_frequency_hz, scs_input);

srsran_assert(band != UINT16_MAX, "Invalid band");

// Deduce point A in Hz
double pointA_Hz =
bands.get_abs_freq_point_a_from_center_freq(base_carrier.nof_prb, base_carrier.dl_center_frequency_hz);
bands.get_abs_freq_point_a_from_center_freq(
base_carrier.nof_prb, base_carrier.dl_center_frequency_hz);

// Deduce DL center frequency ARFCN
uint32_t pointA_arfcn = bands.freq_to_nr_arfcn(pointA_Hz);
Expand All @@ -92,7 +94,8 @@ struct cell_searcher_args_t {
// ssb_scs = srsran_subcarrier_spacing_30kHz;

// Deduce SSB center frequency ARFCN
// uint32_t ssb_arfcn = bands.get_abs_freq_ssb_arfcn(band, ssb_scs, pointA_arfcn);
// uint32_t ssb_arfcn =
// bands.get_abs_freq_ssb_arfcn(band, ssb_scs, pointA_arfcn);
// srsran_assert(ssb_arfcn, "Invalid SSB center frequency");

duplex_mode = bands.get_duplex_mode(band);
Expand Down Expand Up @@ -163,18 +166,106 @@ typedef struct ScanLogNode_ ScanLogNode;
uint32 pci;
};

struct sib1_task_element{
srsran_ue_sync_nr_outcome_t outcome;
srsran_slot_cfg_t slot;
};
typedef struct WorkState_ WorkState;
struct WorkState_{
uint32_t nof_threads;
uint32_t nof_rnti_worker_groups;
uint8_t nof_bwps;
bool cpu_affinity;

struct rach_task_element{
uint32_t slot_sz;

};
cell_searcher_args_t args_t;
cell_search_result_t cell;
srsue::nr::cell_search::ret_t cs_ret;
srsue::nr::cell_search::cfg_t srsran_searcher_cfg_t;
coreset0_args coreset0_args_t;
srsran_coreset_t coreset0_t;

struct dci_task_element{
srsran_ue_dl_nr_sratescs_info arg_scs;

asn1::rrc_nr::sib1_s sib1;
std::vector<asn1::rrc_nr::sys_info_s> sibs;
std::vector<int> found_sib;
std::vector<int> sibs_to_be_found;

asn1::rrc_nr::rrc_setup_s rrc_setup;
asn1::rrc_nr::cell_group_cfg_s master_cell_group;
asn1::rrc_nr::rrc_recfg_s rrc_recfg;

bool sib1_found; // SIB 1 decoded, we can start the RACH thread
bool rach_found;

bool all_sibs_found; // All SIBs are decoded, stop the SIB thread now.

bool sib1_inited; // SIBsDecoder is initialized.
bool rach_inited; // RACHDecoder is initialized.
bool dci_inited; // DCIDecoder is initialized.

uint32_t nof_known_rntis;
std::vector<uint16_t> known_rntis;
};

typedef struct SlotResult_ SlotResult;
struct SlotResult_{
/* 3GPP only marks system frame up to 10.24 seconds, 0-1023.
We want to also capture the level above that. */
uint64_t sf_round;
/* slot and system frame information */
srsran_slot_cfg_t slot;
srsran_ue_sync_nr_outcome_t outcome;

/* The worker works on SIBs decoding */
bool sib_result;
bool found_sib1;
asn1::rrc_nr::sib1_s sib1;
std::vector<asn1::rrc_nr::sys_info_s> sibs;
std::vector<int> found_sib;

/* The worker works on RACH decoding */
bool rach_result;
bool found_rach;
asn1::rrc_nr::rrc_setup_s rrc_setup;
asn1::rrc_nr::cell_group_cfg_s master_cell_group;
uint32_t new_rnti_number;
std::vector<uint16_t> new_rntis_found;

/* The worker works on DCI decoding */
bool dci_result;
std::vector <DCIFeedback> dci_feedback_results;

/* Define the compare operator between structure by sf_round,
sfn and slot idx */
bool operator<(const SlotResult& other) const {
/* If the sf_round is different */
if (sf_round < other.sf_round) return true;
if (sf_round > other.sf_round) return false;

/* If the sfn is different */
if (outcome.sfn < other.outcome.sfn) return true;
if (outcome.sfn > other.outcome.sfn) return false;

/* If the sfn is the same */
return slot.idx < other.slot.idx;
}

bool operator==(const SlotResult& other) const {
return sf_round == other.sf_round && outcome.sfn == other.outcome.sfn &&
slot.idx == other.slot.idx;
}

/* The + operator depends on the SCS, so it's not defined here. */
};

bool CompareSlotResult (SlotResult a, SlotResult b);

namespace NRScopeTask{
extern std::vector<SlotResult> global_slot_results;
extern std::mutex queue_lock;
extern std::mutex task_scheduler_lock;
extern std::mutex worker_locks[128];
}

};

/**
* @brief Function brought from phch_cfg_nr.c
Expand Down Expand Up @@ -215,5 +306,6 @@ uint32_t get_P(uint32_t bwp_nof_prb, bool config_1_or_2);
/**
* Calculate nof_rbgs, from sched_nr_rb.cc
*/
uint32_t get_nof_rbgs(uint32_t bwp_nof_prb, uint32_t bwp_start, bool config1_or_2);
uint32_t get_nof_rbgs(uint32_t bwp_nof_prb, uint32_t bwp_start,
bool config1_or_2);
#endif
78 changes: 78 additions & 0 deletions nrscope/hdr/nrscope_worker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#ifndef NRSCOPE_WORKER_H
#define NRSCOPE_WORKER_H

#include "nrscope/hdr/nrscope_def.h"
#include "nrscope/hdr/rach_decoder.h"
#include "nrscope/hdr/sibs_decoder.h"
#include "nrscope/hdr/dci_decoder.h"

namespace NRScopeTask{

class NRScopeWorker{
public:
cf_t* rx_buffer;
srsran::rf_buffer_t rf_buffer_t;

WorkState worker_state;
RachDecoder rach_decoder;
SIBsDecoder sibs_decoder;
std::vector<std::unique_ptr <DCIDecoder> > dci_decoders;

/* Job indicator */
sem_t smph_has_job;
bool busy;
int worker_id;

/* Worker thread */
std::thread worker_thread;

/* For DCI sharded results */
std::vector<uint32_t> nof_sharded_rntis;
std::vector <std::vector <uint16_t> > sharded_rntis;
std::vector <DCIFeedback> sharded_results;
std::vector <DCIFeedback> results;
std::vector <float> dl_prb_rate;
std::vector <float> dl_prb_bits_rate;
std::vector <float> ul_prb_rate;
std::vector <float> ul_prb_bits_rate;

uint64_t sf_round;
srsran_slot_cfg_t slot; /* Current slot. */
srsran_ue_sync_nr_outcome_t outcome; /* Sync outcome, including the sfn */

NRScopeWorker();
~NRScopeWorker();

/* This is called right after entering the radio_nr.cc,
The cell's information is set to the worker,
so the worker can set its buffer.*/
int InitWorker(WorkState task_scheduler_state, int worker_id_);

/* Start the worker thread */
void StartWorker();

/* Set worker's state the same as the scheduler's state,
and initilize the decoders if needed. This function will be called
before the job starts, so don't need to consider about the thread
safe thing. */
int SyncState(WorkState* task_scheduler_state);

/* Copy the buffer and the slot structure from the task_scheduler */
void CopySlotandBuffer(uint64_t sf_round_,
srsran_slot_cfg_t slot_,
srsran_ue_sync_nr_outcome_t outcome_,
cf_t* rx_buffer_);

int InitSIBDecoder();
int InitRACHDecoder();
int InitDCIDecoders();

int MergeResults();

private:
void Run();
};

}

#endif
15 changes: 7 additions & 8 deletions nrscope/hdr/rach_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "srsran/common/band_helper.h"

#include "nrscope/hdr/nrscope_def.h"
#include "nrscope/hdr/task_scheduler.h"
// #include "nrscope/hdr/task_scheduler.h"

class RachDecoder{
public:
Expand Down Expand Up @@ -50,15 +50,14 @@ class RachDecoder{
RachDecoder();
~RachDecoder();

int rach_decoder_init(TaskSchedulerNRScope* task_scheduler_nrscope);
int RACHDecoderInit(WorkState state);

int rach_reception_init(srsran_ue_dl_nr_sratescs_info arg_scs_,
TaskSchedulerNRScope* task_scheduler_nrscope,
cf_t* input[SRSRAN_MAX_PORTS]);
int RACHReceptionInit(WorkState* state,
cf_t* input[SRSRAN_MAX_PORTS]);

int decode_and_parse_msg4_from_slot(srsran_slot_cfg_t* slot,
TaskSchedulerNRScope* task_scheduler_nrscope,
cf_t * raw_buffer);
int DecodeandParseMS4fromSlot(srsran_slot_cfg_t* slot,
WorkState* state,
SlotResult* result);

// int rach_thread(TaskSchedulerNRScope* task_scheduler_nrscope);
};
Expand Down
Loading

0 comments on commit 2fd21fc

Please sign in to comment.