[buildout]
parts =
  switch-softwaretype

eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true

[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}

[jinja2-template-base]
recipe = slapos.recipe.template:jinja2
output = $${buildout:directory}/$${:filename}
extra-context =
context =
    import json_module json
    key eggs_directory buildout:eggs-directory
    key develop_eggs_directory buildout:develop-eggs-directory
    raw buildout_directory ${buildout:directory}
    section slap_connection slap-connection
    key slapparameter_dict slap-configuration:configuration
    key epc_ipv4 ethernet-ip:ipv4
    $${:extra-context}

[amarisoft]
recipe = slapos.recipe.build
init =
  import os
  lte_version = "2021-09-18"
  path = "/opt/amarisoft/v" + lte_version
  options['lte-version'] = lte_version
  options['path'] = path
  options['enb'] = path + "/enb"
  options['mme'] = path + "/mme"
  options['ims'] = path + "/ims"

[ethernet-ip]
recipe = slapos.recipe.build
init =
  import netifaces
  for i in netifaces.interfaces():
      if not (i.startswith("slaptun") or i.startswith("re6stnet") or i == "lo"):
          a = netifaces.ifaddresses(i)
          if netifaces.AF_INET in a:
              try:
                  options['ipv4'] = a[netifaces.AF_INET][0]['addr']
              except:
                  options['ipv4'] = "0.0.0.0"

[switch-softwaretype]
recipe = slapos.cookbook:switch-softwaretype
enb-epc = dynamic-template-lte-enb-epc:output
gnb-epc = dynamic-template-lte-gnb-epc:output
epc = dynamic-template-lte-epc:output
enb = dynamic-template-lte-enb:output
gnb = dynamic-template-lte-gnb:output
mme = dynamic-template-lte-mme:output
RootSoftwareInstance = $${:enb-epc}

[dynamic-template-lte-enb-epc]
< = jinja2-template-base
url = ${template-lte-enb-epc:target}
filename = instance-lte-enb-epc.cfg
extensions = jinja2.ext.do
extra-context =
    raw monitor_template ${monitor2-template:output}
    key slave_instance_list slap-configuration:slave-instance-list
 
[dynamic-template-lte-gnb-epc]
< = jinja2-template-base
url = ${template-lte-gnb-epc:target}
filename = instance-lte-gnb-epc.cfg
extensions = jinja2.ext.do
extra-context =
    raw monitor_template ${monitor2-template:output}
    key slave_instance_list slap-configuration:slave-instance-list

[dynamic-template-lte-epc]
< = jinja2-template-base
url = ${template-lte-epc:target}
filename = instance-lte-epc.cfg
extensions = jinja2.ext.do
extra-context =
    raw monitor_template ${monitor2-template:output}
    key slave_instance_list slap-configuration:slave-instance-list
 
[dynamic-template-lte-enb]
< = jinja2-template-base
url = ${template-lte-enb:target}
filename = instance-lte-enb.cfg
extensions = jinja2.ext.do
extra-context =
    raw monitor_template ${monitor2-template:output}
    key enb amarisoft:enb
    raw enb_template   ${enb.jinja2.cfg:target}
    raw sib23   ${sib23.asn:target}
    raw ltelogs_template   ${ltelogs.jinja2.sh:target}
    raw sdr_busy_promise   ${sdr-busy-promise:target}
    raw openssl_location ${openssl:location}
    raw default_dl_earfcn ${enb:default-dl-earfcn}
    raw default_lte_dl_freq ${enb:default-lte-dl-freq}
    raw default_lte_band ${enb:default-lte-band}
    raw default_lte_n_rb_dl ${enb:default-lte-n-rb-dl}
    raw default_lte_tx_gain ${enb:default-lte-tx-gain}
    raw default_lte_rx_gain ${enb:default-lte-rx-gain}
    raw min_frequency ${enb:min-frequency}
    raw max_frequency ${enb:max-frequency}

[dynamic-template-lte-gnb]
< = jinja2-template-base
url = ${template-lte-gnb:target}
filename = instance-lte-gnb.cfg
extensions = jinja2.ext.do
extra-context =
    raw monitor_template ${monitor2-template:output}
    key enb amarisoft:enb
    raw gnb_template   ${gnb.jinja2.cfg:target}
    raw ltelogs_template   ${ltelogs.jinja2.sh:target}
    raw sdr_busy_promise   ${sdr-busy-promise:target}
    raw openssl_location ${openssl:location}
    raw default_dl_nr_arfcn ${enb:default-dl-nr-arfcn}
    raw default_nr_band ${enb:default-nr-band}
    raw default_nr_dl_freq ${enb:default-nr-dl-freq}
    raw default_nr_bandwidth ${enb:default-nr-bandwidth}
    raw default_nr_tx_gain ${enb:default-nr-tx-gain}
    raw default_nr_rx_gain ${enb:default-nr-rx-gain}
    raw default_nr_ssb_pos_bitmap ${enb:default-nr-ssb-pos-bitmap}
    raw min_frequency ${enb:min-frequency}
    raw max_frequency ${enb:max-frequency}

[dynamic-template-lte-mme]
< = jinja2-template-base
url = ${template-lte-mme:target}
filename = instance-lte-mme.cfg
extensions = jinja2.ext.do
extra-context =
    raw monitor_template ${monitor2-template:output}
    raw interface_up_promise   ${interface-up-promise:target}
    key mme amarisoft:mme
    raw mme_template   ${mme.jinja2.cfg:target}
    raw ims_template   ${ims.jinja2.cfg:target}
    raw ltelogs_template   ${ltelogs.jinja2.sh:target}
    raw openssl_location ${openssl:location}
    raw nghttp2_location ${nghttp2:location}
    key ue_db_path ue-db-config:output

[ue-db-config]
recipe = slapos.recipe.template:jinja2
url = ${ue_db.jinja2.cfg:target}
filename = ue_db.cfg
extensions = jinja2.ext.do
output = $${buildout:directory}/$${:filename}
context =
    import json_module json
    key slave_instance_list slap-configuration:configuration.slave-list
