From 9968818212009838ddb313c510317c5d0969af16 Mon Sep 17 00:00:00 2001
From: Kirill Smelkov <kirr@nexedi.com>
Date: Tue, 26 Dec 2023 17:29:10 +0300
Subject: [PATCH] .

---
 software/ors-amarisoft/config/enb.jinja2.cfg  |  6 ++--
 .../ors-amarisoft/instance-enb.jinja2.cfg     |  3 ++
 software/ors-amarisoft/k/krequest-cb5.enb+    |  5 +++-
 software/ors-amarisoft/k/krequest-ors.enb.old |  4 +++
 software/ors-amarisoft/slaplte.jinja2         | 18 +++++------
 .../ors-amarisoft/slapos-render-config.py     | 30 ++++++++++++++-----
 6 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/software/ors-amarisoft/config/enb.jinja2.cfg b/software/ors-amarisoft/config/enb.jinja2.cfg
index 7f397b0ebb..ba5fc25e88 100644
--- a/software/ors-amarisoft/config/enb.jinja2.cfg
+++ b/software/ors-amarisoft/config/enb.jinja2.cfg
@@ -8,8 +8,10 @@
 {%- if _standalone is defined %}
 {%-   set iru_dict   = {} %}
 {%-   set icell_dict = {} %}
+{%-   set ipeer_dict = {} %}
 {%-   set ipeercell_dict = {} %}
 {%-   do slaplte.load_iru_and_icell(iru_dict, icell_dict, icell_kind='enb') %}
+{%-   do slaplte.load_ipeer(ipeer_dict) %}
 {%-   do slaplte.load_ipeercell(ipeercell_dict) %}
 {%-   do slaplte.check_loaded_everything()  %}
 {%- endif %}
@@ -56,7 +58,7 @@
 {%-       for peercell_ref, ipeercell in ipeercell_dict|dictsort %}
 {%-         set ncell = ipeercell['_']  %}
             {
-{%-           if ncell.peer_cell_type == 'lte' %}
+{%-           if ncell.cell_type == 'lte' %}
               rat:          "eutra",
               cell_id:      {{ ncell.e_cell_id }},  // -> {{ peercell_ref }}
               n_id_cell:    {{ ncell.pci }},
@@ -64,7 +66,7 @@
               tac:          {{ ncell.tac }},
               allowed_meas_bandwidth: {{ jlte_n_rb_dl(ncell.bandwidth) }},
               antenna_port_1: false,                        // XXX XXX XXX stub
-{%-           elif ncell.peer_cell_type == 'nr' %}
+{%-           elif ncell.cell_type == 'nr' %}
               rat:          "nr",
               nr_cell_id:   {{ ncell.nr_cell_id }}, // -> {{ peercell_ref }}
               gnb_id_bits:  {{ ncell.gnb_id_bits }},
diff --git a/software/ors-amarisoft/instance-enb.jinja2.cfg b/software/ors-amarisoft/instance-enb.jinja2.cfg
index 61619adf60..f591738676 100644
--- a/software/ors-amarisoft/instance-enb.jinja2.cfg
+++ b/software/ors-amarisoft/instance-enb.jinja2.cfg
@@ -35,7 +35,9 @@ offline = true
 {%- set icell_kind='enb'                                        %}
 {%- import 'slaplte.jinja2'            as slaplte with context  %}
 {%- import 'ru_libinstance.jinja2.cfg' as rulib   with context  %}
+{%- set ipeer_dict = {}                                         %}
 {%- set ipeercell_dict = {}                                     %}
+{%- do slaplte.load_ipeer(ipeercell_dict)                       %}
 {%- do slaplte.load_ipeercell(ipeercell_dict)                   %}
 {%- do slaplte.check_loaded_everything()                        %}
 
@@ -320,6 +322,7 @@ output = ${directory:etc}/enb.cfg
 extra-context =
     json iru_dict {{ rulib.iru_dict | tojson }}
     json icell_dict {{ rulib.icell_dict | tojson }}
+    json ipeer_dict {{ ipeer_dict | tojson }}
     json ipeercell_dict {{ ipeercell_dict | tojson }}
     import json_module json
 import-list =
diff --git a/software/ors-amarisoft/k/krequest-cb5.enb+ b/software/ors-amarisoft/k/krequest-cb5.enb+
index 925d97ea59..6b35219a9d 100755
--- a/software/ors-amarisoft/k/krequest-cb5.enb+
+++ b/software/ors-amarisoft/k/krequest-cb5.enb+
@@ -83,6 +83,7 @@ iru2 = iENB(eref('RU2'), RU2)
 # Cells
 CELL1 = {
     'cell_type':    'lte',
+    'cell_kind':    'enb',
     'rf_mode':      'fdd',
     'bandwidth':    '20 MHz',
     'dl_earfcn':    100,        # 2120 @ B1
@@ -104,6 +105,7 @@ CELL2['ru']['ru_ref'] = eref('RU2')
 if 0:   # to test 5G
     CELL2 = {
         'cell_type':    'nr',
+        'cell_kind':    'enb',
         'rf_mode':      'fdd',
         'bandwidth':    5,
         'dl_nr_arfcn':  537200,     # 2686 MHz
@@ -135,7 +137,8 @@ uRU['cpri_link']['sfp_port'] = 3
 uRU['mac_addr'] = '90:A9:F7:C0:00:04'
 
 uCELL = {
-    'ue_cell_type': 'lte',
+    'cell_type':    'lte',
+    'cell_kind':    'ue',
     'rf_mode':      'fdd',
 
     'dl_earfcn':    300,
diff --git a/software/ors-amarisoft/k/krequest-ors.enb.old b/software/ors-amarisoft/k/krequest-ors.enb.old
index 50b3a7dcc0..cdd5d6cf7c 100755
--- a/software/ors-amarisoft/k/krequest-ors.enb.old
+++ b/software/ors-amarisoft/k/krequest-ors.enb.old
@@ -64,6 +64,7 @@ RU1 = {
 
 CELL1_a = {
     'cell_type':    'lte',
+    'cell_kind':    'enb',
     'rf_mode':      'tdd',
     'bandwidth':    '5 MHz',
     'dl_earfcn':    38050,      # 2600 MHz
@@ -77,6 +78,7 @@ iCELL1_a = kslap.iSHARED(enb1, 'CELL1_a', CELL1_a)
 
 CELL1_b = {
     'cell_type':    'lte',
+    'cell_kind':    'enb',
     'rf_mode':      'tdd',
     'bandwidth':    '5 MHz',
     'dl_earfcn':    38100,      # 2605 MHz
@@ -121,6 +123,7 @@ iRU2_b = kslap.iSHARED(enb1, 'RU2_b', RU2_b)
 
 kslap.iSHARED(enb1, 'CELL2_a', {
     'cell_type':    'lte',
+    'cell_kind':    'enb',
     'rf_mode':      'fdd',
     'bandwidth':    '5 MHz',
     'dl_earfcn':    3350,       # 2680 MHz
@@ -134,6 +137,7 @@ kslap.iSHARED(enb1, 'CELL2_a', {
 
 kslap.iSHARED(enb1, 'CELL2_b', {
     'cell_type':    'nr',
+    'cell_kind':    'enb',
     'rf_mode':      'fdd',
     'bandwidth':    5,
     'dl_nr_arfcn':  537200,     # 2686 MHz
diff --git a/software/ors-amarisoft/slaplte.jinja2 b/software/ors-amarisoft/slaplte.jinja2
index 5f58ef3ff7..ee5bd48f1c 100644
--- a/software/ors-amarisoft/slaplte.jinja2
+++ b/software/ors-amarisoft/slaplte.jinja2
@@ -198,8 +198,7 @@
 {%-         endfor  %}
 {%-       endif %}
 {%-       do iru_dict.update({ref: iru})  %}
-{%-     elif (icell_kind == 'enb' and 'cell_type' in _)    or
-             (icell_kind == 'ue'  and 'ue_cell_type' in _)  %}
+{%-     elif 'cell_type' in _  and  _.get('cell_kind') == icell_kind  %}
 {%-       set icell = ishared %}
 {%-       if icell_kind == 'enb'  %}
 {%-         for k, v in defaults['cell/%s' % _.cell_type].items() %}
@@ -208,13 +207,10 @@
 {%-         for k, v in defaults['cell/%s/%s' % (_.cell_type, _.rf_mode)].items() %}
 {%-           do _.setdefault(k, v) %}
 {%-         endfor  %}
-{%-         set xcell_type = _.cell_type  %}
-{%-       else  %}
-{%-         set xcell_type = _.ue_cell_type %}
 {%-       endif %}
-{%-       if xcell_type == 'lte'  %}
+{%-       if _.cell_type == 'lte'  %}
 {%-         do _.setdefault('ul_earfcn',    J(jdefault_ul_earfcn(_.dl_earfcn))) %}
-{%-       elif xcell_type == 'nr' %}
+{%-       elif _.cell_type == 'nr' %}
 {%-         do _.setdefault('ul_nr_arfcn',  J(jdefault_ul_nr_arfcn(_.dl_nr_arfcn, _.nr_band)))  %}
 {%-         do _.setdefault('subcarrier_spacing', 30  if _.rf_mode == 'tdd'  else 15)  %}           {# XXX just leave at 30 ? #}
 {%-         do _.setdefault('ssb_nr_arfcn', J(jdefault_ssb_nr_arfcn(_.dl_nr_arfcn, _.nr_band)))  %}
@@ -330,14 +326,14 @@
 {%-   for ishared in qshared_instance_list  %}
 {%-     set ref = J(jref_of_shared(ishared))  %}
 {%-     set _ = ishared['_']  %}
-{%-     if 'peer_cell_type'   in _  %}
+{%-     if 'cell_type' in _  and  _.get('cell_kind') == 'enb_peer'  %}
 {%-       set ipeercell = ishared %}
-{%-       for k, v in defaults['peercell/' + _.peer_cell_type].items()  %}
+{%-       for k, v in defaults['peercell/' + _.cell_type].items()  %}
 {%-         do _.setdefault(k, v) %}
 {%-       endfor  %}
-{%-       if _.peer_cell_type == 'lte'  %}
+{%-       if _.cell_type == 'lte'  %}
 {%-         do _.setdefault('ul_earfcn',    J(jdefault_ul_earfcn(_.dl_earfcn))) %}
-{%-       elif _.peer_cell_type == 'nr' %}
+{%-       elif _.cell_type == 'nr' %}
 {%-         do _.setdefault('ul_nr_arfcn',  J(jdefault_ul_nr_arfcn(_.dl_nr_arfcn, _.nr_band)))  %}
 {%-         do _.setdefault('subcarrier_spacing',
                     30  if nrarfcn_module.get_duplex_mode(_.nr_band).lower() == 'tdd'  else
diff --git a/software/ors-amarisoft/slapos-render-config.py b/software/ors-amarisoft/slapos-render-config.py
index 93dfd689fb..c6386d1085 100755
--- a/software/ors-amarisoft/slapos-render-config.py
+++ b/software/ors-amarisoft/slapos-render-config.py
@@ -93,6 +93,7 @@ def iRU1_SDR_tLTE2_tNR(ienb):
 
     ienb.ishared('CELL_a', {
         'cell_type':    'lte',
+        'cell_kind':    'enb',
         'rf_mode':      'tdd',
         'bandwidth':    '5 MHz',
         'dl_earfcn':    38050,      # 2600 MHz
@@ -103,6 +104,7 @@ def iRU1_SDR_tLTE2_tNR(ienb):
 
     ienb.ishared('CELL_b', {
         'cell_type':    'lte',
+        'cell_kind':    'enb',
         'rf_mode':      'tdd',
         'bandwidth':    '5 MHz',
         'dl_earfcn':    38100,      # 2605 MHz
@@ -116,6 +118,7 @@ def iRU1_SDR_tLTE2_tNR(ienb):
 
     ienb.ishared('CELL_c', {
         'cell_type':    'nr',
+        'cell_kind':    'enb',
         'rf_mode':      'tdd',
         'bandwidth':    10,
         'dl_nr_arfcn':  523020,     # 2615.1 MHz
@@ -153,6 +156,7 @@ def iRU2_SDR_tLTE_tNR(ienb):
 
     ienb.ishared('CELL_a', {
         'cell_type':    'lte',
+        'cell_kind':    'enb',
         'rf_mode':      'tdd',
         'bandwidth':    '5 MHz',
         'dl_earfcn':    38050,      # 2600 MHz
@@ -166,6 +170,7 @@ def iRU2_SDR_tLTE_tNR(ienb):
 
     ienb.ishared('CELL_b', {
         'cell_type':    'nr',
+        'cell_kind':    'enb',
         'rf_mode':      'tdd',
         'bandwidth':    10,
         'dl_nr_arfcn':  523020,     # 2615.1 MHz
@@ -211,6 +216,7 @@ def iRU2_LOPCOMM_fLTE_fNR(ienb):
 
     ienb.ishared('CELL_a', {
         'cell_type':    'lte',
+        'cell_kind':    'enb',
         'rf_mode':      'fdd',
         'bandwidth':    '5 MHz',
         'dl_earfcn':    3350,       # 2680 MHz
@@ -224,6 +230,7 @@ def iRU2_LOPCOMM_fLTE_fNR(ienb):
 
     ienb.ishared('CELL_b', {
         'cell_type':    'nr',
+        'cell_kind':    'enb',
         'rf_mode':      'fdd',
         'bandwidth':    5,
         'dl_nr_arfcn':  537200,     # 2686 MHz
@@ -253,6 +260,7 @@ def iRU1_SDR1_fLTE2(ienb):
 
     ienb.ishared('CELL_a', {
         'cell_type':    'lte',
+        'cell_kind':    'enb',
         'rf_mode':      'fdd',
         'bandwidth':    '5 MHz',
         'dl_earfcn':    3350,      # 2680 MHz (Band 7)
@@ -263,6 +271,7 @@ def iRU1_SDR1_fLTE2(ienb):
 
     ienb.ishared('CELL_b', {
         'cell_type':    'lte',
+        'cell_kind':    'enb',
         'rf_mode':      'fdd',
         'bandwidth':    '5 MHz',
         'dl_earfcn':    3050,      # 2650 MHz (Band 7)
@@ -304,6 +313,7 @@ def iRU2_LOPCOMM_fLTE2(ienb):
         ienb.ishared('RU_0002', RU_0002)
         ienb.ishared('CELL2', {
             'cell_type':    'lte',
+            'cell_kind':    'enb',
             'rf_mode':      'fdd',
             'bandwidth':    '20 MHz',
             'dl_earfcn':    100,        # 2120 MHz   @ B1
@@ -319,6 +329,7 @@ def iRU2_LOPCOMM_fLTE2(ienb):
         ienb.ishared('RU_0004', RU_0004)
         ienb.ishared('CELL4', {
             'cell_type':    'lte',
+            'cell_kind':    'enb',
             'rf_mode':      'fdd',
             'bandwidth':    '20 MHz',
             'dl_earfcn':    500,        # 2160 MHz  @ B1
@@ -341,7 +352,8 @@ def do_enb():
     # add 2 peer cells
     if 1:
         ienb.ishared('PEER1', {
-            'peer_cell_type':   'lte',
+            'cell_type':        'lte',
+            'cell_kind':        'enb_peer',
             'e_cell_id':        '0x12345',
             'pci':              35,
             'dl_earfcn':        700,
@@ -349,7 +361,8 @@ def do_enb():
             'tac':              123,
         })
         ienb.ishared('PEER2', {
-            'peer_cell_type':   'nr',
+            'cell_type':        'nr',
+            'cell_kind':        'enb_peer',
             'nr_cell_id':       '0x77712',
             'gnb_id_bits':      22,
             'dl_nr_arfcn':      520000,
@@ -394,10 +407,9 @@ def do_enb():
         ishared['_'] = _
         if 'ru_type' in _:
             iru_dict[ref] = ishared
-        elif 'cell_type' in _:
-            icell_dict[ref] = ishared
-        elif 'peer_cell_type' in _:
-            ipeercell_dict[ref] = ishared
+        elif 'cell_type' in _  and  _.get('cell_kind') in {'enb', 'enb_peer'}:
+            idict = {'enb': icell_dict, 'enb_peer': ipeercell_dict} [_['cell_kind']]
+            idict[ref] = ishared
         else:
             raise AssertionError('enb: unknown shared instance %r' % (ishared,))
 
@@ -435,7 +447,8 @@ def do_enb():
 def do_ue():
     iue = Instance('ue')
     iue.ishared('UCELL1', {
-        'ue_cell_type': 'lte',
+        'cell_type':    'lte',
+        'cell_kind':    'ue',
         'rf_mode':      'tdd',
         'bandwidth':    '5 MHz',
         'dl_earfcn':    38050,      # 2600 MHz
@@ -450,7 +463,8 @@ def do_ue():
         }
     })
     iue.ishared('UCELL2', {
-        'ue_cell_type': 'nr',
+        'cell_type':    'nr',
+        'cell_kind':    'ue',
         'rf_mode':      'fdd',
         'bandwidth':    5,
         'dl_nr_arfcn':  537200,     # 2686 MHz
-- 
2.30.9