libinstance.jinja2.cfg 5.9 KB
Newer Older
1 2 3
{#- Package ru/libinstance provides common instance code for handling Radio Units and cells.

    Use buildout() macro to emit instance-level code to
4
    handle configured RUs.
5

6 7 8 9
    NOTE: before importing package slaplte.jinja2 needs to already loaded as

      {%- import 'slaplte.jinja2'  as slaplte     with context %}

10
    NOTE: driver-specific logic is implemented in rudrv.buildout_ru() .
11 12
#}

13
{#- cell_list keeps cell registry #}
14 15
{%- set cell_list = {} %}
{%- do slaplte.load_cell(cell_list) %}
16 17


18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
{%- macro buildout()  %}
{#-   part emits new buildout section and registers it into buildout.parts  #}
{%-   set parts_list = [] %}
{%-   macro part(name) %}
{%-     do parts_list.append(name)  %}
[{{ name }}]
{%-   endmacro    %}

{#-   promise emits new buildout section for a promise    #}
{%-   macro promise(name)                                 %}
{{ part('promise-'+name) }}
<= monitor-promise-base
name = {{ name }}.py
config-testing = {{ slapparameter_dict.get("testing", False) }}
config-stats-period = {{ slapparameter_dict.get("enb_stats_fetch_period", 60) }}
{%-   endmacro %}

{#-   import RU drivers                           #}
{%-   import 'ru_sdr_libinstance.jinja2.cfg'      as rudrv_sdr      with context %}
{%-   import 'ru_lopcomm_libinstance.jinja2.cfg'  as rudrv_lopcomm  with context %}
{%-   import 'ru_sunwave_libinstance.jinja2.cfg'  as rudrv_sunwave  with context %}
{%-   set rudrv_dict = namespace(sdr=rudrv_sdr,
                                 lopcomm=rudrv_lopcomm,
                                 sunwave=rudrv_sunwave) %}

43 44 45 46 47 48 49 50
{#-   split slapos tap interface for each RU
      fallback to non-split approach for ntap <= 1 to avoid hard-dependecy on setcap/tapsplit

      TODO Relying on setcap and tapsplit should be removed once SlapOS is improved to
           provide several TAP interfaces to instances. See discussion at
           https://lab.nexedi.com/nexedi/slapos/merge_requests/1471#note_194356
           for details. #}
{%-   set ntap = len(list(cell_list|dictsort)) %}
51
{%-   set vtap_list = []  %}
52 53 54
[vtap]
recipe = plone.recipe.command
ntap = {{ ntap }}
55
command = {{ netcapdo }} {{ pythonwitheggs }} {{ ru_tapsplit }} {{ slaplte.tap }} ${:ntap}
56 57 58 59 60 61 62 63 64
update-command = ${:command}
stop-on-error = true

{%-   if ntap <= 1  %}
[vtap]
ntap = 0
stop-on-error = false

{%-     if ntap == 1  %}
65 66
{%-       do vtap_list.append(slaplte.tap) %}
[vtap.{{ slaplte.tap }}]
67 68 69 70 71 72 73 74
network = {{ slap_configuration['tap-ipv6-network'] }}
gateway = {{ slap_configuration['tap-ipv6-gateway'] }}
addr    = {{ slap_configuration['tap-ipv6-addr'] }}
{%-     endif %}

{%-   else  %}

{%-   for i in range(1,1+ntap)  %}
75
{%-     set tap = '%s-%d' % (slaplte.tap, i)   %}
76
{%-     do vtap_list.append(tap) %}
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
[vtap.{{ tap }}]
recipe = slapos.recipe.build
depends = ${vtap:recipe}
init =
  import types
  def readfile(path):
    with open(path) as f:
      return f.read()

  # ~ import tapsplit
  tapsplit = types.ModuleType('tapsplit')
  exec(readfile('{{ ru_tapsplit }}'), tapsplit.__dict__)

  # simulate what tapsplit would assign to the tap
  # ( tap subinterface will be created for real later at install time - when it
  #   is too late to update section options )
93
  slapnet = tapsplit.ifnet6('{{ slaplte.tap }}')
94 95 96 97 98 99 100 101 102
  tapnet  = tapsplit.netsplit(slapnet, {{ 1+ntap }}) [{{ i }}]

  options['network'] = str(tapnet)
  options['gateway'] = str(tapnet[1])
  options['addr']    = str(tapnet[-1])
{%-   endfor  %}

{%-   endif %}

103 104 105 106 107 108 109 110 111 112 113 114
# vtap_jdict maps tapname -> json(interface-info)
[vtap_jdict]
recipe = slapos.recipe.build
depends = {% for tap in vtap_list %}  ${vtap.{{tap}}:addr}  {% endfor %}
init =
  import json
{%- for tap in vtap_list %}
  tap = self.buildout['vtap.{{tap}}']
  tap = {k: tap[k]  for k in ('network', 'gateway', 'addr')}
  options['{{tap}}'] = json.dumps(tap)
{%- endfor %}

115

116
{#-   provide CPRI-based RUs IP address via DHCP #}
117
{%-   if trx == 'cpri'  %}
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
[dnsmasq-config]
recipe = slapos.recipe.template:jinja2
url = {{ru_dnsmasq_template}}
filename = dnsmasq.cfg
extensions = jinja2.ext.do
output = ${directory:etc}/${:filename}
context =
  import json_module json
  import netaddr netaddr
  section directory directory
  section vtap_jdict vtap_jdict
  json cell_list {{ cell_list | tojson }}

{{ part('dnsmasq-service') }}
recipe = slapos.cookbook:wrapper
port = 5353
ip = ${slap-configuration:tun-ipv4-addr}
command-line = {{ dnsmasq_location }}/sbin/dnsmasq --conf-file=${dnsmasq-config:output} -x ${directory:run}/dnsmasq.pid --local-service --keep-in-foreground
wrapper-path = ${directory:service}/dnsmasq
mode = 0775
hash-files =
  ${dnsmasq-config:output}

# {# promise('dnsmasq-listen') #}
#promise = check_socket_listening
#config-host = ${dnsmasq-service:ip}
#config-port = ${dnsmasq-service:port}
{%-   endif  %}


148
{#-   go through all RUs and for each RU emit generic promises and invoke
149
      RU-specific buildout handler #}
150 151
{%-   set ru_type = {'lopcomm': 'lopcomm', 'm2ru': 'sunwave'}.get(ru, 'sdr') %}
{%-   set rudrv = rudrv_dict[ru_type] %}
152 153
{%-   for cell_ref, cell in cell_list|dictsort %}
{%-     set ru_ref = cell_ref  if cell_ref != 'default'  else 'RU' %}
154 155

# {{ ru_ref }}  ({{ ru_type}})
156 157 158 159 160 161 162 163 164 165 166 167 168 169
{%-     if trx == 'sdr'  %}
{{ promise('%s-sdr-busy' % ru_ref) }}
promise = check_sdr_busy
config-sdr = {{ sdr }}
config-sdr_dev  = 0
config-dma_chan = 0

{%-     elif trx == 'cpri'  %}
{{ promise('%s-sdr-busy' % ru_ref) }}
promise = check_sdr_busy
config-sdr = {{ sdr }}
config-sdr_dev  = {{ slapparameter_dict.get('sdr_number', 0) }}
config-dma_chan = {{ cell.cpri_port_number }}

170 171 172 173 174
{{ promise('%s-cpri-lock' % ru_ref) }}
promise = check_cpri_lock
config-sdr_dev  = {{ slapparameter_dict.get('sdr_number', 0) }}
config-sfp_port = {{ cell.cpri_port_number }}
config-amarisoft-rf-info-log = ${amarisoft-rf-info-template:log-output}
175 176 177

{%-     else %}
{%-       do bug('unreachable') %}
178 179 180
{%-     endif %}

{#-     driver-specific part #}
181 182
{{      rudrv.buildout_ru(ru_ref, cell) }}
{%-   endfor %}
183 184 185 186 187 188 189 190


[buildout]
parts +=
{%- for part in parts_list %}
    {{ part }}
{%- endfor %}
{%- endmacro  %}