From 85db2a47dbe6f0abfd25c308909806122d1ac1da Mon Sep 17 00:00:00 2001
From: Kirill Smelkov <kirr@nexedi.com>
Date: Wed, 29 Nov 2023 09:55:45 +0000
Subject: [PATCH] software/ors-amarisoft: enb: Factor rx-saturated promise to
 generic ru library and to be per-RU

Similarly to sdr-busy, if we have several radio units, we want each of them to
have its own rx-saturated promise.

See https://lab.nexedi.com/nexedi/slapos.toolbox/merge_requests/126 for
corresponding part in slapos.toolbox that makes check_rx_saturated per-RU
configurable.

Not touching gnb.jinja2.cfg as currently gnb does not support multicell at all,
and in the future it will be sole enb.cfg to handle both LTE and NR
simultaneously.

/cc @xavier_thompson, @Daetalus
/reviewed-by @jhuge, @lu.xu
/reviewed-on https://lab.nexedi.com/nexedi/slapos/merge_requests/1485
---
 software/ors-amarisoft/buildout.hash.cfg         | 4 ++--
 software/ors-amarisoft/instance-enb.jinja2.cfg   | 9 ---------
 software/ors-amarisoft/ru/libinstance.jinja2.cfg | 9 ++++++++-
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/software/ors-amarisoft/buildout.hash.cfg b/software/ors-amarisoft/buildout.hash.cfg
index 69e267536..399ea4125 100644
--- a/software/ors-amarisoft/buildout.hash.cfg
+++ b/software/ors-amarisoft/buildout.hash.cfg
@@ -32,7 +32,7 @@ md5sum = ab666fdfadbfc7d8a16ace38d295c883
 
 [ru_libinstance.jinja2.cfg]
 _update_hash_filename_ = ru/libinstance.jinja2.cfg
-md5sum = 4d29c7d06109cc9ecda37f60045336e8
+md5sum = 6febf4dc601ba5feb30aa402f37265cf
 
 [ru_sdr_libinstance.jinja2.cfg]
 _update_hash_filename_ = ru/sdr/libinstance.jinja2.cfg
@@ -80,7 +80,7 @@ md5sum = 52da9fe3a569199e35ad89ae1a44c30e
 
 [template-enb]
 _update_hash_filename_ = instance-enb.jinja2.cfg
-md5sum = 6074adea3c4b30c7b726981e9e40b8a7
+md5sum = 3b380ac8a44aafc30cc6d87b35860fd6
 
 [template-gnb]
 _update_hash_filename_ = instance-gnb.jinja2.cfg
diff --git a/software/ors-amarisoft/instance-enb.jinja2.cfg b/software/ors-amarisoft/instance-enb.jinja2.cfg
index 51e9411f4..00a68be03 100644
--- a/software/ors-amarisoft/instance-enb.jinja2.cfg
+++ b/software/ors-amarisoft/instance-enb.jinja2.cfg
@@ -16,7 +16,6 @@ parts =
 {% endif %}
   check-baseband-latency.py
   check-amarisoft-stats-log.py
-  check-rx-saturated.py
   monitor-base
   publish-connection-information
 
@@ -386,11 +385,3 @@ output = ${directory:plugins}/check-amarisoft-stats-log.py
 config-testing = {{ slapparameter_dict.get("testing", False) }}
 config-amarisoft-stats-log = ${amarisoft-stats-template:log-output}
 config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
-[check-rx-saturated.py]
-<= macro.promise
-promise = check_rx_saturated
-config-testing = {{ slapparameter_dict.get("testing", False) }}
-config-rf-rx-chan-list = {{ list(range(0, int(slapparameter_dict.get('n_antenna_ul', default_n_antenna_ul)))) }}
-config-amarisoft-stats-log = ${amarisoft-stats-template:log-output}
-config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
-config-max-rx-sample-db = {{ slapparameter_dict.get("max_rx_sample_db", 0) }}
diff --git a/software/ors-amarisoft/ru/libinstance.jinja2.cfg b/software/ors-amarisoft/ru/libinstance.jinja2.cfg
index 13128a643..b7f0d0add 100644
--- a/software/ors-amarisoft/ru/libinstance.jinja2.cfg
+++ b/software/ors-amarisoft/ru/libinstance.jinja2.cfg
@@ -149,8 +149,9 @@ hash-files =
       RU-specific buildout handler #}
 {%-   set ru_type = {'lopcomm': 'lopcomm', 'm2ru': 'sunwave'}.get(ru, 'sdr') %}
 {%-   set rudrv = rudrv_dict[ru_type] %}
-{%-   for cell_ref, cell in cell_list|dictsort %}
+{%-   for i, (cell_ref, cell) in enumerate(cell_list|dictsort) %}
 {%-     set ru_ref = cell_ref  if cell_ref != 'default'  else 'RU' %}
+{%-     set n_antenna_ul = int(slapparameter_dict.get('n_antenna_ul', default_n_antenna_ul))  %}
 
 # {{ ru_ref }}  ({{ ru_type}})
 {%-     if trx == 'sdr'  %}
@@ -177,6 +178,12 @@ config-amarisoft-rf-info-log = ${amarisoft-rf-info-template:log-output}
 {%-       do bug('unreachable') %}
 {%-     endif %}
 
+{{ promise('%s-rx-saturated' % ru_ref) }}
+promise = check_rx_saturated
+config-rf-rx-chan-list = {{ list(range(i*n_antenna_ul, (i+1)*n_antenna_ul)) }}
+config-amarisoft-stats-log = ${amarisoft-stats-template:log-output}
+config-max-rx-sample-db = {{ slapparameter_dict.get("max_rx_sample_db", 0) }}
+
 {#-     driver-specific part #}
 {{      rudrv.buildout_ru(ru_ref, cell) }}
 {%-   endfor %}
-- 
2.30.9