# instance-ors-enb translates ORS enb/gnb into base enb/gnb.

{#- enb_mode indicates with which mode ors' enb is instantiated with - enb | gnb #}
{%- set enb_mode = slap_configuration['slap-software-type'] %}
{%- do assert(enb_mode in ('enb', 'gnb'), enb_mode) %}


{#- inject ORS defaults #}
{%- do RF.setdefault('tx_gain',  ors_version['current-tx-gain']) %}
{%- do RF.setdefault('rx_gain',  ors_version['current-rx-gain']) %}
{%- do RF.setdefault('earfcn',   ors_version['current-earfcn']) %}
{%- do RF.setdefault('nr_arfcn', ors_version['current-nr-arfcn']) %}
{%- do RF.setdefault('nr_band',  ors_version['current-nr-band']) %}


{#- backward compatibility: if ORS is running in gnb mode, and gnb_* parameters
    are present, replace their generic enb_* counterparts with gnb_* ones #}
{%- if enb_mode == 'gnb'  %}
{%-   set _ = slapparameter_dict  %}
{%-   if 'gnb_config_link' in _ %}
{%-     do _.update({
          'enb_config_link':    _.gnb_config_link,
          'enb_config_version': _.get('gnb_config_version'),
        })  %}
{%-   endif %}
{%-   if 'gnb_stats_fetch_period' in _  %}
{%-     do _.update({'enb_stats_fetch_period': _.gnb_stats_fetch_period}) %}
{%-   endif %}
{%-   if 'gnb_drb_stats_enabled' in _  %}
{%-     do _.update({'enb_drb_stats_enabled':  _.gnb_drb_stats_enabled}) %}
{%-   endif %}
{%- endif %}


# code of base enb
{%  include 'instance-enb-base.jinja2.cfg' %}


# let all templates know we are running in ORS mode
[config-base]
context -=
   json ors false
context +=
   key ors :ors
ors = {{ dumps(ors_version) }}


# add ORS-specific bits to published information
[publish-connection-information]
ors-version = {{ ors_version['ors-version'] }}
frequency-range-rating = {{ ors_version['range'] }}
current-tx-power-estimate = {{ ors_version['power-estimate'] }}
current-tx-gain = {{ ors_version['current-tx-gain'] }}
current-rx-gain = {{ ors_version['current-rx-gain'] }}

{%- if enb_mode == 'enb'  %}
current-earfcn  = {{ ors_version['current-earfcn'] }}
{%- elif enb_mode == 'gnb' %}
current-nr-arfcn = {{ ors_version['current-nr-arfcn'] }}
current-nr-band = {{ ors_version['current-nr-band'] }}
{%- endif %}
