Commit cc1a4d62 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f92ceda0
# Program slapos-render-config is handy during config/ templates development.
#
# It mimics the way config files are generated during the build but runs much
# faster compared to full `slapos node software` + `slapos node instance` runs.
import zc.buildout.buildout # XXX workaround for bug in vvv
from slapos.recipe.template import jinja2_template
import json, copy, sys, pprint import json, copy, sys, pprint
# XXX test both enb.cfg + ue.cfg simultaneously
config = "enb" # j2render renders config/<config>.jinja2.cfg into config/<config>.cfg with provided json parameters.
json_params_empty = """{ def j2render(config, jcfg):
"rf_mode": 'fdd', ctx = json.loads(jcfg)
"slap_configuration": { textctx = ''
}, for k, v in ctx.items():
"directory": { textctx += 'json %s %s\n' % (k, json.dumps(v))
}, textctx += 'import json_module json\n'
"slapparameter_dict": { buildout = None # stub
} r = jinja2_template.Recipe(buildout, "recipe", {
}""" 'extensions': 'jinja2.ext.do',
'url': 'config/{}.jinja2.cfg'.format(config),
'output': 'config/{}.cfg'.format(config),
'context': textctx,
'import-list': 'rawfile lte.jinja2 config/lte.jinja2',
})
# avoid dependency on zc.buildout.download and the need to use non-stub buildout section
def _read(url, *args):
with open(url, *args) as f:
return f.read()
r._read = _read
# iSHARED appends new shared instance with specified configuration to shared_instance_list. # for template debugging
shared_instance_list = [] r.context.update({
def iSHARED(title, slave_reference, cfg): 'print': lambda *argv: print(*argv, file=sys.stderr),
ishared = { 'pprint': lambda obj: pprint.pprint(obj, sys.stderr),
'slave_title': title, })
'slave_reference': slave_reference,
'slap_software_type': "enb", with open('config/{}.cfg'.format(config), 'w+') as f:
'_': json.dumps(cfg) f.write(r._render().decode())
}
shared_instance_list.append(ishared)
return ishared # Instance ...
class Instance:
def __init__(self):
self.shared_instance_list = []
# ishared appends new shared instance with specified configuration to .shared_instance_list .
def ishared(self, title, slave_reference, cfg):
ishared = {
'slave_title': title,
'slave_reference': slave_reference,
'slap_software_type': "enb",
'_': json.dumps(cfg)
}
self.shared_instance_list.append(ishared)
return ishared
# ---- eNB ----
# 3 cells sharing SDR-based RU consisting of 2 SDR boards (4tx + 4rx ports max) # 3 cells sharing SDR-based RU consisting of 2 SDR boards (4tx + 4rx ports max)
# RU definition is embedded into cell for simplicity of management # RU definition is embedded into cell for simplicity of management
def iRU1_SDR_tLTE2_tNR(): def iRU1_SDR_tLTE2_tNR(ienb):
RU1 = { RU1 = {
'ru_type': 'sdr', 'ru_type': 'sdr',
'ru_link_type': 'sdr', 'ru_link_type': 'sdr',
...@@ -40,7 +74,7 @@ def iRU1_SDR_tLTE2_tNR(): ...@@ -40,7 +74,7 @@ def iRU1_SDR_tLTE2_tNR():
'rx_gain': 52, 'rx_gain': 52,
} }
iSHARED('Cell 1a', '_CELL1_a', { ienb.ishared('Cell 1a', '_CELL1_a', {
'cell_type': 'lte', 'cell_type': 'lte',
'rf_mode': 'tdd', 'rf_mode': 'tdd',
'bandwidth': '5 MHz', 'bandwidth': '5 MHz',
...@@ -50,7 +84,7 @@ def iRU1_SDR_tLTE2_tNR(): ...@@ -50,7 +84,7 @@ def iRU1_SDR_tLTE2_tNR():
'ru': RU1, # RU definition embedded into CELL 'ru': RU1, # RU definition embedded into CELL
}) })
iSHARED('Cell 1b', '_CELL1_b', { ienb.ishared('Cell 1b', '_CELL1_b', {
'cell_type': 'lte', 'cell_type': 'lte',
'rf_mode': 'tdd', 'rf_mode': 'tdd',
'bandwidth': '5 MHz', 'bandwidth': '5 MHz',
...@@ -63,7 +97,7 @@ def iRU1_SDR_tLTE2_tNR(): ...@@ -63,7 +97,7 @@ def iRU1_SDR_tLTE2_tNR():
} }
}) })
iSHARED('Cell 1c', '_CELL1_c', { ienb.ishared('Cell 1c', '_CELL1_c', {
'cell_type': 'nr', 'cell_type': 'nr',
'rf_mode': 'tdd', 'rf_mode': 'tdd',
'bandwidth': 5, 'bandwidth': 5,
...@@ -80,7 +114,7 @@ def iRU1_SDR_tLTE2_tNR(): ...@@ -80,7 +114,7 @@ def iRU1_SDR_tLTE2_tNR():
# LTE + NR cells that use CPRI-based Lopcomm radio units # LTE + NR cells that use CPRI-based Lopcomm radio units
# here we instantiate RUs separately since embedding RU into a cell is demonstrated by CELL1_a above # here we instantiate RUs separately since embedding RU into a cell is demonstrated by CELL1_a above
def iRU2_LOPCOMM_fLTE_fNR(): def iRU2_LOPCOMM_fLTE_fNR(ienb):
RU2_a = { RU2_a = {
'ru_type': 'lopcomm', 'ru_type': 'lopcomm',
'ru_link_type': 'cpri', 'ru_link_type': 'cpri',
...@@ -106,10 +140,10 @@ def iRU2_LOPCOMM_fLTE_fNR(): ...@@ -106,10 +140,10 @@ def iRU2_LOPCOMM_fLTE_fNR():
RU2_b['tx_gain'] += 10 RU2_b['tx_gain'] += 10
RU2_b['rx_gain'] += 10 RU2_b['rx_gain'] += 10
iSHARED('Radio Unit 2a', '_RU2_a', RU2_a) ienb.ishared('Radio Unit 2a', '_RU2_a', RU2_a)
iSHARED('Radio Unit 2b', '_RU2_b', RU2_b) ienb.ishared('Radio Unit 2b', '_RU2_b', RU2_b)
iSHARED('Cell 2a', '_CELL2_a', { ienb.ishared('Cell 2a', '_CELL2_a', {
'cell_type': 'lte', 'cell_type': 'lte',
'rf_mode': 'fdd', 'rf_mode': 'fdd',
'bandwidth': '5 MHz', 'bandwidth': '5 MHz',
...@@ -122,7 +156,7 @@ def iRU2_LOPCOMM_fLTE_fNR(): ...@@ -122,7 +156,7 @@ def iRU2_LOPCOMM_fLTE_fNR():
} }
}) })
iSHARED('Cell 2b', '_CELL2_b', { ienb.ishared('Cell 2b', '_CELL2_b', {
'cell_type': 'nr', 'cell_type': 'nr',
'rf_mode': 'fdd', 'rf_mode': 'fdd',
'bandwidth': 5, 'bandwidth': 5,
...@@ -137,11 +171,10 @@ def iRU2_LOPCOMM_fLTE_fNR(): ...@@ -137,11 +171,10 @@ def iRU2_LOPCOMM_fLTE_fNR():
}) })
# ---- for tests ---- # ---- for tests ----
# 2 FDD cells working via shared SDR board # 2 FDD cells working via shared SDR board
def iRU3_SDR1_fLTE2(): def iRU3_SDR1_fLTE2(ienb):
RU = { RU = {
'ru_type': 'sdr', 'ru_type': 'sdr',
'ru_link_type': 'sdr', 'ru_link_type': 'sdr',
...@@ -152,7 +185,7 @@ def iRU3_SDR1_fLTE2(): ...@@ -152,7 +185,7 @@ def iRU3_SDR1_fLTE2():
'rx_gain': 61, 'rx_gain': 61,
} }
iSHARED('Cell 3a', '_CELL3_a', { ienb.ishared('Cell 3a', '_CELL3_a', {
'cell_type': 'lte', 'cell_type': 'lte',
'rf_mode': 'fdd', 'rf_mode': 'fdd',
'bandwidth': '5 MHz', 'bandwidth': '5 MHz',
...@@ -162,7 +195,7 @@ def iRU3_SDR1_fLTE2(): ...@@ -162,7 +195,7 @@ def iRU3_SDR1_fLTE2():
'ru': RU, 'ru': RU,
}) })
iSHARED('Cell 3b', '_CELL3_b', { ienb.ishared('Cell 3b', '_CELL3_b', {
'cell_type': 'lte', 'cell_type': 'lte',
'rf_mode': 'fdd', 'rf_mode': 'fdd',
'bandwidth': '5 MHz', 'bandwidth': '5 MHz',
...@@ -176,70 +209,49 @@ def iRU3_SDR1_fLTE2(): ...@@ -176,70 +209,49 @@ def iRU3_SDR1_fLTE2():
}) })
def do_enb():
ienb = Instance()
iRU1_SDR_tLTE2_tNR(ienb)
#iRU2_LOPCOMM_fLTE_fNR(ienb)
#iRU3_SDR1_fLTE2(ienb)
jshared_instance_list = json.dumps(ienb.shared_instance_list)
json_params = """{
"sib23_file": "sib2_3.asn",
"slap_configuration": {
"tap-name": "slaptap9",
"slap-computer-partition-id": "slappart9",
"configuration.default_lte_imsi": "001010123456789",
"configuration.default_lte_k": "00112233445566778899aabbccddeeff",
"configuration.default_lte_inactivity_timer": 10000,
"configuration.default_nr_imsi": "001010123456789",
"configuration.default_nr_k": "00112233445566778899aabbccddeeff",
"configuration.default_nr_inactivity_timer": 10000,
"slave-instance-list": %(jshared_instance_list)s
},
"directory": {
"log": "log",
"etc": "etc",
"var": "var"
},
"slapparameter_dict": {
}
}""" % locals()
iRU1_SDR_tLTE2_tNR() j2render('enb', json_params)
#iRU2_LOPCOMM_fLTE_fNR()
#iRU3_SDR1_fLTE2()
jshared_instance_list = json.dumps(shared_instance_list)
json_params = """{
"sib23_file": "sib2_3.asn",
"slap_configuration": {
"tap-name": "slaptap9",
"slap-computer-partition-id": "slappart9",
"configuration.default_lte_imsi": "001010123456789",
"configuration.default_lte_k": "00112233445566778899aabbccddeeff",
"configuration.default_lte_inactivity_timer": 10000,
"configuration.default_nr_imsi": "001010123456789",
"configuration.default_nr_k": "00112233445566778899aabbccddeeff",
"configuration.default_nr_inactivity_timer": 10000,
"slave-instance-list": %(jshared_instance_list)s
},
"directory": {
"log": "log",
"etc": "etc",
"var": "var"
},
"slapparameter_dict": {
}
}""" % globals()
import zc.buildout.buildout # XXX workaround for bug in vvv
from slapos.recipe.template import jinja2_template
# ---- UE ----
# j2render renders config/<config>.jinja2.cfg into config/<config>.cfg def do_ue():
def j2render(config): pass # XXX temp
ctx = json.loads(json_params)
textctx = ''
for k, v in ctx.items():
textctx += 'json %s %s\n' % (k, json.dumps(v))
textctx += 'import json_module json\n'
buildout = None # stub
r = jinja2_template.Recipe(buildout, "recipe", {
'extensions': 'jinja2.ext.do',
'url': 'config/{}.jinja2.cfg'.format(config),
'output': 'config/{}.cfg'.format(config),
'context': textctx,
'import-list': 'rawfile lte.jinja2 config/lte.jinja2',
})
# avoid dependency on zc.buildout.download and the need to use non-stub buildout section
def _read(url, *args):
with open(url, *args) as f:
return f.read()
r._read = _read
# debugging
r.context.update({
'print': lambda *argv: print(*argv, file=sys.stderr),
'pprint': lambda obj: pprint.pprint(obj, sys.stderr),
})
with open('config/{}.cfg'.format(config), 'w+') as f: def main():
f.write(r._render().decode()) do_enb()
do_ue()
j2render(config) # XXX temp if __name__ == '__main__':
main()
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