[buildout]
parts =
  directory
  ltelogs
  lte-enb-config
  lte-enb-service
  sdr-busy-promise
  monitor-base
  publish-connection-information

extends = {{ monitor_template }}

eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}
offline = true

[slap-configuration]
recipe = slapos.cookbook:slapconfiguration
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.network_name = RAPIDSPACE
configuration.domain = rapid.space
configuration.mme_ws_port = 9000
configuration.enb_ws_port = 9002
configuration.ims_ws_port = 9003
configuration.ims_addr = 127.0.0.1
configuration.ims_bind = 127.0.0.2
configuration.enb_addr = 127.0.1.1
configuration.default_dl_earfcn = {{ default_dl_earfcn }}
configuration.default_lte_dl_freq = {{ default_lte_dl_freq }}
configuration.default_lte_band = {{ default_lte_band }}
configuration.default_lte_n_rb_dl = {{ default_lte_n_rb_dl }}
configuration.default_lte_tx_gain = {{ default_lte_tx_gain }}
configuration.default_lte_rx_gain = {{ default_lte_rx_gain }}

[directory]
recipe = slapos.cookbook:mkdirectory
software = {{ buildout_directory }}
home = ${buildout:directory}
etc = ${:home}/etc
var = ${:home}/var
etc = ${:home}/etc
bin = ${:home}/bin
run = ${:var}/run
script = ${:etc}/run
service = ${:etc}/service
promise = ${:etc}/promise
log = ${:var}/log

[ltelogs]
recipe = slapos.recipe.template:jinja2
template = {{ ltelogs_template }}
rendered = ${directory:home}/ltelogs.sh
mode = 0775
extensions = jinja2.ext.do
context =
  section directory directory

[lte-enb-sh-wrapper]
recipe = slapos.recipe.template:jinja2
rendered = ${directory:bin}/${:_buildout_section_name_}
mode = 0700
template =
  inline:#!/bin/sh
  sudo /opt/amarisoft/rm-tmp-lte | true;
  {{ enb }}/lteenb ${directory:etc}/enb.cfg >> ${directory:log}/enb-output.cfg 2>> ${directory:log}/enb-output.cfg

### eNodeB (enb)
[lte-enb-service]
recipe = slapos.cookbook:wrapper
init = ${ltelogs:rendered} ${directory:log}/enb.log; sleep 2
command-line = ${lte-enb-sh-wrapper:rendered}
wrapper-path = ${directory:service}/lte-enb
mode = 0775
reserve-cpu = True
pidfile = ${directory:run}/enb.pid
hash-files =
  ${lte-enb-config:rendered}
  ${lte-enb-sh-wrapper:rendered}
environment =
  LD_LIBRARY_PATH={{ openssl_location }}/lib
  AMARISOFT_PATH=/opt/amarisoft/.amarisoft

[config-base]
recipe = slapos.recipe.template:jinja2
mode = 0664
extensions = jinja2.ext.do
context =
  section directory directory
  section slap_configuration slap-configuration
  key slapparameter_dict slap-configuration:configuration
  raw gtp_addr {{ local_ipv4 }}
  import  netaddr netaddr

[lte-enb-config]
<= config-base
template = {{ enb_template }}
rendered = ${directory:etc}/enb.cfg

[publish-connection-information]
<= monitor-publish
recipe = slapos.cookbook:publish
ipv4 = {{ local_ipv4 }}

[monitor-instance-parameter]
{% if slapparameter_dict.get("name", None) %}
monitor-title = {{ slapparameter_dict['name'] | string }}
{% endif %}
{% if slapparameter_dict.get("monitor-password", None) %}
password = {{ slapparameter_dict['monitor-password'] | string }}
{% endif %}

# Add custom promise to check if /dev/sdr0 is busy
[sdr-busy-promise]
recipe = slapos.cookbook:promise.plugin
eggs = slapos.core
file = {{ sdr_busy_promise }}
output = ${directory:plugins}/check-sdr-busy.py
