Commit 2149bc2d authored by Kirill Smelkov's avatar Kirill Smelkov

software/ors-amarisoft: enb+ue: Query slapparameter_dict from master only once

We are currently querying it in instance.cfg and later, once again, in e.g. instance-enb.jinja2.cfg .

However ORS mode will need to adjust slapparameter_dict with ORS defaults
and pass it further to generic enb. So it won't work if we use
slapparameter_dict obtained the second time because the second query will
return unadjusted original slapparameter_dict.

In this patch we are only doing preparatory step - redo the code not query the
master from instance-{enb,ue}.jinja2.cfg and work with slapparameter_dict and
slap_configuration already queried by instance.cfg

For UE the change is trivial.

For eNB instance-enb.jinja2.cfg used to set the defaults for com, mme, amf and
gtp in the same section used for the second query. We rework those defaults to
be applied to slapparameter_dict via jinja2 - via the same way we are going to
later use in ORS mode.

Handling defaults for everything besides gtp_addr is straightforward. For
gtp_addr it has the semantic difference when explicitly given, and given only
implicitly. In the latter case the intent of original code is to autodetect
whether to use an address on loopback, or externally-visible address.

Original code used the check for emptiness of mme_list/amf_list as the
condition for "use loopback". Since now those lists, after applying their
defaults, are never empty we rework the code to see if core address is on the
loopback or not, and use auto-GTP-on-loopback only if core is also on loopback.
This should, hopefully, be more convenient as it also works ok out of the box
if core is on loopback, but its address was explicitly specified. Previously
for such cases gtp_addr was also needed to be specified, and now it should work
without that.

No change to rendered enb.cfg and gnb.cfg besides whitespace.

Adjust ipv6-random usage in core-network for consistency with enb as well.
parent 86e9a774
...@@ -68,6 +68,29 @@ ...@@ -68,6 +68,29 @@
{{- _[float(bandwidth.removesuffix(' MHz'))] | tojson }} {{- _[float(bandwidth.removesuffix(' MHz'))] | tojson }}
{%- endmacro %} {%- endmacro %}
{#- jhostport splits address into (host,port) pair. #}
{%- macro jhostport(addr) %}
{%- set _ = namespace() %}
{%- if ':' not in addr %}
{%- set _.host = addr %}
{%- set _.port = None %}
{%- else %}
{%- set head, tail = addr.rsplit(':', 1) %}
{%- if ':' not in head %}
{%- set _.host = head %}
{%- set _.port = tail %}
{%- else %}
{%- if addr.startswith('[') %}
{%- set _.host = addr[1:addr.index(']')] %}
{%- set _.port = tail %}
{%- else %}
{%- set _.host = addr %}
{%- set _.port = None %}
{%- endif %}
{%- endif %}
{%- endif %}
{{- (_.host, _.port) | tojson }}
{%- endmacro -%}
{%- if do_lte %} {%- if do_lte %}
{%- if slapparameter_dict.get('tdd_ul_dl_config', '[Configuration 2] 5ms 2UL 6DL (default)') == '[Configuration 2] 5ms 2UL 6DL (default)' %} {%- if slapparameter_dict.get('tdd_ul_dl_config', '[Configuration 2] 5ms 2UL 6DL (default)') == '[Configuration 2] 5ms 2UL 6DL (default)' %}
...@@ -108,69 +131,67 @@ ...@@ -108,69 +131,67 @@
{{ slaplte.ru_config(ru, cell_dict, slapparameter_dict) }} {{ slaplte.ru_config(ru, cell_dict, slapparameter_dict) }}
{%- if slapparameter_dict.get('websocket_password', '') %} {%- if slapparameter_dict.get('websocket_password', '') %}
com_addr: "[{{ gtp_addr_v6 }}]:{{ slap_configuration['configuration.com_ws_port'] }}", com_addr: "[{{ gtp_addr_v6 }}]:{{ slapparameter_dict.com_ws_port }}",
com_auth: { com_auth: {
password: "{{ slapparameter_dict['websocket_password'] }}", password: "{{ slapparameter_dict['websocket_password'] }}",
}, },
{%- else %} {%- else %}
com_addr: "{{ slap_configuration['configuration.com_addr'] }}:{{ slap_configuration['configuration.com_ws_port'] }}", com_addr: "{{ slapparameter_dict.com_addr }}:{{ slapparameter_dict.com_ws_port }}",
{%- endif %} {%- endif %}
{%- if do_lte %} {%- if do_lte %}
// LTE core network // LTE core network
mme_list: [ mme_list: [
{% if slapparameter_dict.get('mme_list', '') %} {%- for _, mme in slapparameter_dict.mme_list |dictsort %}
{%- for i, k in enumerate(slapparameter_dict['mme_list']) %}
{%- if i == 0 %}
{ {
{%- else -%} mme_addr: "{{ mme['mme_addr'] }}",
, {
{%- endif %}
mme_addr: "{{ slapparameter_dict['mme_list'][k]['mme_addr'] }}",
}
{%- endfor -%}
{% else %}
{
mme_addr: "{{ slap_configuration['configuration.mme_addr'] }}",
}, },
{% endif %} {%- endfor %}
], ],
{%- endif %} {%- endif %}
{%- if do_nr %} {%- if do_nr %}
// NR core network // NR core network
amf_list: [ amf_list: [
{% if slapparameter_dict.get('amf_list', '') %} {%- for _, amf in slapparameter_dict.amf_list |dictsort %}
{%- for i, k in enumerate(slapparameter_dict['amf_list']) %}
{%- if i == 0 %}
{
{%- else -%}
, {
{%- endif %}
amf_addr: "{{ slapparameter_dict['amf_list'][k]['amf_addr'] }}",
}
{%- endfor -%}
{% else %}
{ {
amf_addr: "{{ slap_configuration['configuration.amf_addr'] }}", amf_addr: "{{ amf['amf_addr'] }}",
}, },
{% endif %} {%- endfor %}
], ],
{%- endif %} {%- endif %}
{% if slapparameter_dict.get('mme_list', '') or slapparameter_dict.get('amf_list', '') %} {#- listen-address for GTP-U - either explicitly given, or autodetect #}
{% if slapparameter_dict.get('gtp_addr') %} {%- if slapparameter_dict.get('gtp_addr') %}
gtp_addr: "{{ slapparameter_dict.get('gtp_addr') }}", gtp_addr: "{{ slapparameter_dict.gtp_addr }}",
{% else %} {%- else %}
{% if slapparameter_dict.get('use_ipv4', False) %} {#- use loopback if address of core network is on loopback as well #}
gtp_addr: "{{ gtp_addr_v6 }}", {%- set vcore = [] %}
{% else %} {%- if do_lte %}
{%- do vcore.extend(slapparameter_dict.mme_list |dictsort |map(attribute='1.mme_addr')) %}
{%- endif %}
{%- if do_nr %}
{%- do vcore.extend(slapparameter_dict.amf_list |dictsort |map(attribute='1.amf_addr')) %}
{%- endif %}
{#- remove optional :port from addresses and see if they are on loopback #}
{%- set vip = [] %}
{%- for a in vcore %}
{%- set _ = namespace() %}
{%- set _.ip = J(jhostport(a))[0] %}
{%- set _.islo = netaddr.IPAddress(_.ip).is_loopback() %}
{%- do vip.append(_) %}
{%- endfor %}
{%- if len(vip) > 0 and all(vip |map(attribute='islo')) %}
gtp_addr: "{{ gtp_addr_lo }}",
{%- else %}
{#- core is external - use external ipv4/ipv6 #}
{%- if slapparameter_dict.use_ipv4 %}
gtp_addr: "{{ gtp_addr_v4 }}", gtp_addr: "{{ gtp_addr_v4 }}",
{% endif %} {%- else %}
{% endif %} gtp_addr: "{{ gtp_addr_v6 }}",
{% else %} {%- endif %}
gtp_addr: "{{ slap_configuration['configuration.gtp_addr'] }}", {%- endif %}
{% endif %} {%- endif %}
{%- if do_nr %} {%- if do_nr %}
{% if slapparameter_dict.get('xn_peers', '') %} {% if slapparameter_dict.get('xn_peers', '') %}
......
...@@ -183,7 +183,7 @@ context = ...@@ -183,7 +183,7 @@ context =
section directory directory section directory directory
section slap_configuration slap-configuration section slap_configuration slap-configuration
key slapparameter_dict slap-configuration:configuration key slapparameter_dict slap-configuration:configuration
key gtp_addr_v6 slap-configuration:ipv6-random raw gtp_addr_v6 {{ my_ipv6 }}
raw gtp_addr_v4 {{ lan_ipv4 }} raw gtp_addr_v4 {{ lan_ipv4 }}
import netaddr netaddr import netaddr netaddr
key ifup_empty mme-ifup-empty:wrapper-path key ifup_empty mme-ifup-empty:wrapper-path
...@@ -245,7 +245,7 @@ password = {{ slapparameter_dict['monitor-password'] | string }} ...@@ -245,7 +245,7 @@ password = {{ slapparameter_dict['monitor-password'] | string }}
[publish-connection-information] [publish-connection-information]
<= monitor-publish <= monitor-publish
recipe = slapos.cookbook:publish.serialised recipe = slapos.cookbook:publish.serialised
core-network-ipv6 = ${slap-configuration:ipv6-random} core-network-ipv6 = {{ my_ipv6 }}
core-network-ipv4 = {{ lan_ipv4 }} core-network-ipv4 = {{ lan_ipv4 }}
amarisoft-version = {{ lte_version }} amarisoft-version = {{ lte_version }}
license-expiration = {{ lte_expiration }} license-expiration = {{ lte_expiration }}
......
...@@ -5,6 +5,20 @@ ...@@ -5,6 +5,20 @@
{%- set do_lte = (enb_mode == 'enb') %} {%- set do_lte = (enb_mode == 'enb') %}
{%- set do_nr = (enb_mode == 'gnb') %} {%- set do_nr = (enb_mode == 'gnb') %}
{#- defaults for global eNB/gNB parameters.
TODO automatically load enb defaults from JSON schema #}
{%- set enb_defaults = {
'com_ws_port': 9001,
'com_addr': '127.0.1.2',
'mme_list': {'1': {'mme_addr': '127.0.1.100'}},
'amf_list': {'1': {'amf_addr': '127.0.1.100'}},
'use_ipv4': False,
} %}
{%- set gtp_addr_lo = '127.0.1.1' %}
{%- for k,v in enb_defaults|dictsort %}
{%- do slapparameter_dict.setdefault(k, v) %}
{%- endfor %}
{#- defaults for eNB radio parameters. {#- defaults for eNB radio parameters.
NOTE they are installed temporary and will go away after switch to generic multiRU. #} NOTE they are installed temporary and will go away after switch to generic multiRU. #}
{%- do RF.setdefault('tx_gain', slapparameter_dict.get('tx_gain', 0)) %} {%- do RF.setdefault('tx_gain', slapparameter_dict.get('tx_gain', 0)) %}
...@@ -36,6 +50,12 @@ offline = true ...@@ -36,6 +50,12 @@ offline = true
{%- import 'ru_libinstance.jinja2.cfg' as rulib with context %} {%- import 'ru_libinstance.jinja2.cfg' as rulib with context %}
{{ rulib.buildout() }} {{ rulib.buildout() }}
[myslap]
# NOTE we don't query slapos.cookbook:slapconfiguration the second time because
# slapparameter_dict is potentially modified with defaults.
parameter_dict = {{ dumps(slapparameter_dict) }}
configuration = {{ dumps(slap_configuration) }}
[monitor-httpd-conf-parameter] [monitor-httpd-conf-parameter]
httpd-include-file = {{ buildout_directory }}/etc/httpd-include-file.conf httpd-include-file = {{ buildout_directory }}/etc/httpd-include-file.conf
...@@ -51,19 +71,6 @@ minimum = 8035 ...@@ -51,19 +71,6 @@ minimum = 8035
maximum = 8055 maximum = 8055
ip = ${monitor-instance-parameter:monitor-httpd-ipv6} ip = ${monitor-instance-parameter:monitor-httpd-ipv6}
[slap-configuration]
recipe = slapos.cookbook:slapconfiguration.serialised
computer = {{ slap_connection['computer-id'] }}
partition = {{ slap_connection['partition-id'] }}
url = {{ slap_connection['server-url'] }}
key = {{ slap_connection['key-file'] }}
cert = {{ slap_connection['cert-file'] }}
configuration.com_ws_port = 9001
configuration.com_addr = 127.0.1.2
configuration.mme_addr = 127.0.1.100
configuration.amf_addr = 127.0.1.100
configuration.gtp_addr = 127.0.1.1
[directory] [directory]
recipe = slapos.cookbook:mkdirectory recipe = slapos.cookbook:mkdirectory
...@@ -130,7 +137,7 @@ drb_stats_logspec = ...@@ -130,7 +137,7 @@ drb_stats_logspec =
rotatespec = 100MB.9 rotatespec = 100MB.9
logspec = ${:stats_logspec} ${:drb_stats_logspec} logspec = ${:stats_logspec} ${:drb_stats_logspec}
{%- if slapparameter_dict.get("websocket_password", "") %} {%- if slapparameter_dict.get("websocket_password", "") %}
websock = ws://[${slap-configuration:ipv6-random}]:9001 websock = ws://[{{my_ipv6}}]:9001
{%- else %} {%- else %}
websock = ws://127.0.1.2:9001 websock = ws://127.0.1.2:9001
{%- endif %} {%- endif %}
...@@ -190,10 +197,11 @@ extra-context = ...@@ -190,10 +197,11 @@ extra-context =
context = context =
json ors false json ors false
section directory directory section directory directory
section slap_configuration slap-configuration key slap_configuration myslap:configuration
key slapparameter_dict slap-configuration:configuration key slapparameter_dict myslap:parameter_dict
key gtp_addr_v6 slap-configuration:ipv6-random raw gtp_addr_v6 {{ my_ipv6 }}
raw gtp_addr_v4 {{ lan_ipv4 }} raw gtp_addr_v4 {{ lan_ipv4 }}
raw gtp_addr_lo {{ gtp_addr_lo }}
raw tx_gain {{ RF.tx_gain }} raw tx_gain {{ RF.tx_gain }}
raw rx_gain {{ RF.rx_gain }} raw rx_gain {{ RF.rx_gain }}
raw earfcn {{ RF.dl_earfcn }} raw earfcn {{ RF.dl_earfcn }}
...@@ -251,9 +259,9 @@ import-list = ...@@ -251,9 +259,9 @@ import-list =
<= monitor-publish <= monitor-publish
recipe = slapos.cookbook:publish.serialised recipe = slapos.cookbook:publish.serialised
{%- if slapparameter_dict.get("websocket_password", "") %} {%- if slapparameter_dict.get("websocket_password", "") %}
websocket_url = ws://[${slap-configuration:ipv6-random}]:9001 websocket_url = ws://[{{my_ipv6}}]:9001
{%- endif %} {%- endif %}
enb-ipv6 = ${slap-configuration:ipv6-random} enb-ipv6 = {{ my_ipv6 }}
enb-ipv4 = {{ lan_ipv4 }} enb-ipv4 = {{ lan_ipv4 }}
{%- if enb_mode == 'enb' %} {%- if enb_mode == 'enb' %}
current-earfcn = {{ RF.dl_earfcn }} current-earfcn = {{ RF.dl_earfcn }}
......
...@@ -20,6 +20,12 @@ eggs-directory = {{ eggs_directory }} ...@@ -20,6 +20,12 @@ eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }} develop-eggs-directory = {{ develop_eggs_directory }}
offline = true offline = true
[myslap]
# see instance-enb.jinja2.cfg about myslap
parameter_dict = {{ dumps(slapparameter_dict) }}
configuration = {{ dumps(slap_configuration) }}
[monitor-httpd-conf-parameter] [monitor-httpd-conf-parameter]
httpd-include-file = {{ buildout_directory }}/etc/httpd-include-file.conf httpd-include-file = {{ buildout_directory }}/etc/httpd-include-file.conf
port = ${monitor-instance-parameter:monitor-httpd-port} port = ${monitor-instance-parameter:monitor-httpd-port}
...@@ -34,14 +40,6 @@ minimum = 8035 ...@@ -34,14 +40,6 @@ minimum = 8035
maximum = 8055 maximum = 8055
ip = ${monitor-instance-parameter:monitor-httpd-ipv6} ip = ${monitor-instance-parameter:monitor-httpd-ipv6}
[slap-configuration]
recipe = slapos.cookbook:slapconfiguration.serialised
computer = {{ slap_connection['computer-id'] }}
partition = {{ slap_connection['partition-id'] }}
url = {{ slap_connection['server-url'] }}
key = {{ slap_connection['key-file'] }}
cert = {{ slap_connection['cert-file'] }}
[directory] [directory]
recipe = slapos.cookbook:mkdirectory recipe = slapos.cookbook:mkdirectory
software = {{ buildout_directory }} software = {{ buildout_directory }}
...@@ -99,9 +97,9 @@ recipe = slapos.recipe.template:jinja2 ...@@ -99,9 +97,9 @@ recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do extensions = jinja2.ext.do
context = context =
section directory directory section directory directory
section slap_configuration slap-configuration
section pub_info publish-connection-information section pub_info publish-connection-information
key slapparameter_dict slap-configuration:configuration key slap_configuration myslap:configuration
key slapparameter_dict myslap:parameter_dict
raw default_lte_bandwidth {{ default_lte_bandwidth }} raw default_lte_bandwidth {{ default_lte_bandwidth }}
raw default_nr_bandwidth {{ default_nr_bandwidth }} raw default_nr_bandwidth {{ default_nr_bandwidth }}
raw default_n_antenna_dl {{ default_n_antenna_dl }} raw default_n_antenna_dl {{ default_n_antenna_dl }}
...@@ -125,8 +123,8 @@ output = ${directory:etc}/ue.cfg ...@@ -125,8 +123,8 @@ output = ${directory:etc}/ue.cfg
[publish-connection-information] [publish-connection-information]
<= monitor-publish <= monitor-publish
recipe = slapos.cookbook:publish.serialised recipe = slapos.cookbook:publish.serialised
rue_bind_addr = ${slap-configuration:ipv6-random} rue_bind_addr = {{my_ipv6}}
com_addr = [${slap-configuration:ipv6-random}]:9002 com_addr = [{{my_ipv6}}]:9002
monitor-gadget-url = ${:monitor-base-url}/gadget/software.cfg.html monitor-gadget-url = ${:monitor-base-url}/gadget/software.cfg.html
[monitor-instance-parameter] [monitor-instance-parameter]
......
...@@ -34,6 +34,7 @@ context = ...@@ -34,6 +34,7 @@ context =
section slap_connection slap-connection section slap_connection slap-connection
key slapparameter_dict slap-configuration:configuration key slapparameter_dict slap-configuration:configuration
key lan_ipv4 lan-ip:ipv4 key lan_ipv4 lan-ip:ipv4
key my_ipv6 slap-configuration:ipv6-random
raw rf_mode ${rf-mode:rf-mode} raw rf_mode ${rf-mode:rf-mode}
raw software_name ${rf-mode:software-name} raw software_name ${rf-mode:software-name}
raw trx ${rf-mode:trx} raw trx ${rf-mode:trx}
......
...@@ -217,7 +217,7 @@ extensions = jinja2.ext.do ...@@ -217,7 +217,7 @@ extensions = jinja2.ext.do
log-output = ${directory:var}/log/amarisoft-rf-info.json.log log-output = ${directory:var}/log/amarisoft-rf-info.json.log
context = context =
section directory directory section directory directory
key slapparameter_dict slap-configuration:configuration key slapparameter_dict myslap:parameter_dict
key log_file :log-output key log_file :log-output
raw stats_period {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }} raw stats_period {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
raw testing {{ testing }} raw testing {{ testing }}
...@@ -240,7 +240,7 @@ extensions = jinja2.ext.do ...@@ -240,7 +240,7 @@ extensions = jinja2.ext.do
log-output = ${directory:var}/log/amarisoft-stats.json.log log-output = ${directory:var}/log/amarisoft-stats.json.log
context = context =
section directory directory section directory directory
key slapparameter_dict slap-configuration:configuration key slapparameter_dict myslap:parameter_dict
key log_file :log-output key log_file :log-output
raw stats_period {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }} raw stats_period {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
raw testing {{ testing }} raw testing {{ testing }}
......
...@@ -25,7 +25,7 @@ is_firmware_updated = ${directory:etc}/{{ru_ref}}.is_firmware_updated ...@@ -25,7 +25,7 @@ is_firmware_updated = ${directory:etc}/{{ru_ref}}.is_firmware_updated
context = context =
section directory directory section directory directory
section vtap vtap.{{ cell._tap }} section vtap vtap.{{ cell._tap }}
key slapparameter_dict slap-configuration:configuration key slapparameter_dict myslap:parameter_dict
key log_file :log-output key log_file :log-output
key software_reply_json_log_file :software-reply-json-log-output key software_reply_json_log_file :software-reply-json-log-output
key remote_file_path :remote-file-path key remote_file_path :remote-file-path
...@@ -105,7 +105,7 @@ is_netconf_connected = ${directory:etc}/{{ru_ref}}.is_netconf_connected ...@@ -105,7 +105,7 @@ is_netconf_connected = ${directory:etc}/{{ru_ref}}.is_netconf_connected
context = context =
section directory directory section directory directory
section vtap vtap.{{ cell._tap }} section vtap vtap.{{ cell._tap }}
key slapparameter_dict slap-configuration:configuration key slapparameter_dict myslap:parameter_dict
key log_file :log-output key log_file :log-output
key json_log_file :json-log-output key json_log_file :json-log-output
key cfg_json_log_file :cfg-json-log-output key cfg_json_log_file :cfg-json-log-output
...@@ -242,7 +242,7 @@ recipe = slapos.cookbook:userinfo ...@@ -242,7 +242,7 @@ recipe = slapos.cookbook:userinfo
recipe = slapos.cookbook:free_port recipe = slapos.cookbook:free_port
minimum = 22222 minimum = 22222
maximum = 22231 maximum = 22231
ip = ${slap-configuration:ipv6-random} ip = {{my_ipv6}}
[sshd-config] [sshd-config]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
......
...@@ -43,6 +43,16 @@ def do(src, out, rat, slapparameter_dict): ...@@ -43,6 +43,16 @@ def do(src, out, rat, slapparameter_dict):
assert rat in ('lte', 'nr') assert rat in ('lte', 'nr')
jdo_lte = json.dumps(rat == 'lte') jdo_lte = json.dumps(rat == 'lte')
jdo_nr = json.dumps(rat == 'nr') jdo_nr = json.dumps(rat == 'nr')
defaults = {
"com_ws_port": 9001,
"com_addr": "127.0.1.2",
"mme_list": {"1": {"mme_addr": "127.0.1.100"}},
"amf_list": {"1": {"amf_addr": "127.0.1.100"}},
"gtp_addr": "127.0.1.1",
}
slapparameter_dict = slapparameter_dict.copy()
for k, v in defaults.items():
slapparameter_dict.setdefault(k, v)
jslapparameter_dict = json.dumps(slapparameter_dict) jslapparameter_dict = json.dumps(slapparameter_dict)
json_params_empty = """{ json_params_empty = """{
"rf_mode": 'fdd', "rf_mode": 'fdd',
...@@ -68,12 +78,7 @@ def do(src, out, rat, slapparameter_dict): ...@@ -68,12 +78,7 @@ def do(src, out, rat, slapparameter_dict):
"sib23_file": "sib", "sib23_file": "sib",
"drb_file": "drb", "drb_file": "drb",
"slap_configuration": { "slap_configuration": {
"tap-name": "slaptap9", "tap-name": "slaptap9"
"configuration.com_ws_port": 9001,
"configuration.com_addr": "127.0.1.2",
"configuration.amf_addr": "127.0.1.100",
"configuration.mme_addr": "127.0.1.100",
"configuration.gtp_addr": "127.0.1.1"
}, },
"default_lte_bandwidth": "10 MHz", "default_lte_bandwidth": "10 MHz",
"default_lte_imsi": "001010123456789", "default_lte_imsi": "001010123456789",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment