• Kirill Smelkov's avatar
    software/ors-amarisoft: enb.jinja2.cfg: Stop using C Preprocessor and switch to Jinja2 completely · 79370ebf
    Kirill Smelkov authored
    To support multiple Radio Units and multiple cells, we will need to loop over them
    and emit corresponding configuration parts taking RU/Cell parameters into
    account for each part. We currently handle some such parameters at Jinja2 level
    (e.g. dl_earfcn), while some other parameters at CPP level (e.g. cell
    bandwidth) and rely on enb to preprocess generated enb.cfg with CPP on its own.
    
    While CPP works ok for simple 1RU-1CELL cases, and CPP is also the tool that Amarisoft
    itself uses in its examples, it has the limitation that it cannot cooperate
    with loops. In other words there can be only one global N_RB_DL #define, and it
    cannot be different for different cells while we are looping over them at
    Jinja2 level. That means that we cannot use CPP to handle multiple cells.
    
    For this reason switch enb.jinja2.cfg to be using Jinja2 only without CPP.
    
    While rendered enb.cfg/gnb.cfg change, we can see that they change in expected
    way, with leaving only blocks that should be active for input parameters. See
    the Appendix for details.
    
    The switch is straightforward but one thing deserves to be mentioned: due to
    limitation of Jinja2, where macros can return only strings, we use JSON
    encoding to be able to return arbitrary types - integers, floats, dicts, etc,
    and use a convention to name such macros with j prefix and wrap their usage
    with J so that whole invocation does not add much noise. See added slaplte.J
    documentation for details.
    
    /cc @lu.xu, @tomo, @xavier_thompson, @Daetalus
    /reviewed-by @jhuge
    /reviewed-on !1520
    
    --------
    
    Appendix. Diff for rendered enb.cfg/gnb.cfg before and after this patch
    
    ```
    $ git diff --no-index config/{old,out}
    ```
    
    ```diff
    diff --git a/config/old/enb.cfg b/config/out/enb.cfg
    index 23e56c9a9..ee2661640 100644
    --- a/config/old/enb.cfg
    +++ b/config/out/enb.cfg
    @@ -1,14 +1,6 @@
    
    -#define TDD                 1
    -
    -#define N_RB_DL             50
    -
    -#define N_ANTENNA_DL        2
    -
    -#define N_ANTENNA_UL        2
    -
    
     {
    
    @@ -44,8 +36,8 @@
       cell_list: [
         {
           rf_port: 0,
    -      n_antenna_dl: N_ANTENNA_DL,
    -      n_antenna_ul: N_ANTENNA_UL,
    +      n_antenna_dl: 2,
    +      n_antenna_ul: 2,
    
           cell_id: 0x00,
           tac: 0x0001,
    @@ -59,83 +51,33 @@
    
         manual_ref_signal_power: true,
    
    -
    -#if TDD == 1
         uldl_config: 6,
         sp_config: 7,
    -#endif
    -
    -    n_rb_dl: N_RB_DL,
    -#if N_RB_DL == 6
    -    si_coderate: 0.30,
    -#else
    -    si_coderate: 0.20,
    -#endif
    +    n_rb_dl: 50,
    +    si_coderate: 0.2,
    
         pdsch_dedicated: {
    -#if N_ANTENNA_DL == 4
    -      p_a: -6,
    -#elif N_ANTENNA_DL == 2
           p_a: -3,
    -#else
    -      p_a: 0,
    -#endif
           p_b: -1,
         },
    
    -#if N_RB_DL == 6
    -    pdcch_format: 1,
    -#else
    -    pdcch_format: 2,
    -#endif
    -
    -#if N_RB_DL == 6
    -    prach_config_index: 15,
    -#else
    +    pdcch_format:       2,
         prach_config_index: 4,
    -#endif
    -
    -#if N_RB_DL == 6
    -    initial_cqi: 5,
    -#else
    -    initial_cqi: 3,
    -#endif
    +    initial_cqi:        3,
    
         pucch_dedicated: {
           n1_pucch_sr_count: 11,
           cqi_pucch_n_rb: 1,
           n1_pucch_an_cs_count: 8,
           n3_pucch_an_n_rb: 3,
    -#if TDD == 1
           tdd_ack_nack_feedback_mode: "multiplexing", /* TDD only */
    -#endif
         },
    -
    -#if N_ANTENNA_DL >= 2
         m_ri: 8,
         transmission_mode: 3,
    -#endif
    
         srs_dedicated: {
    -#if N_RB_DL == 6
    -      srs_bandwidth_config: 7,
    -      srs_bandwidth: 1,
    -#elif N_RB_DL == 15
    -      srs_bandwidth_config: 6,
    -      srs_bandwidth: 1,
    -#elif N_RB_DL == 25
    -      srs_bandwidth_config: 3,
    -      srs_bandwidth: 1,
    -#elif N_RB_DL == 50
           srs_bandwidth_config: 2,
           srs_bandwidth: 2,
    -#elif N_RB_DL == 75
    -      srs_bandwidth_config: 2,
    -      srs_bandwidth: 2,
    -#else
    -      srs_bandwidth_config: 2,
    -      srs_bandwidth: 3,
    -#endif
           srs_subframe_config: 3,
           srs_period: 40,
           srs_hopping_bandwidth: 0,
    diff --git a/config/old/gnb.cfg b/config/out/gnb.cfg
    index 5bfd3bb01..0b6a1445c 100644
    --- a/config/old/gnb.cfg
    +++ b/config/out/gnb.cfg
    @@ -1,13 +1,6 @@
    
    -#define TDD                 1
    -
    -
    -#define N_ANTENNA_DL        2
    -
    -#define N_ANTENNA_UL        2
    -
    
     {
    
    @@ -50,8 +43,8 @@
       nr_cell_list: [
       {
         rf_port: 0,
    -    n_antenna_dl: N_ANTENNA_DL,
    -    n_antenna_ul: N_ANTENNA_UL,
    +    n_antenna_dl: 2,
    +    n_antenna_ul: 2,
    
         cell_id: 0x01,
         n_id_cell: 500,
    @@ -108,29 +101,10 @@
         csi_rs: {
           nzp_csi_rs_resource: [
             {
    -#if N_ANTENNA_DL == 1
    -          n_ports: 1,
    -          frequency_domain_allocation: "row2",
    -          bitmap: "100000000000",
    -          cdm_type: "no_cdm",
    -#elif N_ANTENNA_DL == 2
               n_ports: 2,
               frequency_domain_allocation: "other",
               bitmap: "100000",
               cdm_type: "fd_cdm2",
    -#elif N_ANTENNA_DL == 4
    -          n_ports: 4,
    -          frequency_domain_allocation: "row4",
    -          bitmap: "100",
    -          cdm_type: "fd_cdm2",
    -#elif N_ANTENNA_DL == 8
    -          n_ports: 8,
    -          frequency_domain_allocation: "other",
    -          bitmap: "110011",
    -          cdm_type: "fd_cdm2",
    -#else
    -#error unsupported number of DL antennas
    -#endif
             },
    
           ],
    @@ -148,22 +122,10 @@
    
           csi_report_config: [
             {
    -#if N_ANTENNA_DL > 1
               codebook_config: {
                 codebook_type: "type1",
                 sub_type: "typeI_SinglePanel",
    -#if N_ANTENNA_DL == 2
    -#elif N_ANTENNA_DL == 4
    -            n1: 2,
    -            n2: 1,
    -            codebook_mode: 1,
    -#elif N_ANTENNA_DL == 8
    -            n1: 4,
    -            n2: 1,
    -            codebook_mode: 1,
    -#endif
               },
    -#endif
             },
           ],
         },
    ```
    79370ebf
instance-gnb.jinja2.cfg 10.9 KB