render-templates 4.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/env python3

from jinja2 import Template
import os

# Values: 6 (1.4 MHz), 15 (3MHz), 25 (5MHz), 50 (10MHz), 75 (15MHz), 100 (20MHz)
LTE_N_RB_DL=100
LTE_TX_GAIN=70
LTE_RX_GAIN=30

NR_BANDWIDTH=40
NR_TX_GAIN=70
NR_RX_GAIN=50

global_context = {
16
        'generated_file_message': "This file was generated using a jinja2 template and the render-templates script, don't modify directly."
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
}

rf_mode_context_list = [
        {
            'rf_mode': 'tdd1900',

            'default_dl_earfcn': 38350,
            'default_lte_dl_freq': 1890.0,
            'default_lte_band': 39,
            'default_lte_n_rb_dl': LTE_N_RB_DL,
            'default_lte_tx_gain': LTE_TX_GAIN,
            'default_lte_rx_gain': LTE_RX_GAIN,

            'default_dl_nr_arfcn': 378000,
            'default_nr_band': 39,
            'default_nr_dl_freq': 1890.0,
            'default_nr_bandwidth': NR_BANDWIDTH,
            'default_nr_tx_gain': NR_TX_GAIN,
            'default_nr_rx_gain': NR_RX_GAIN,

            'min_frequency': 1880.0,
            'max_frequency': 1920,
        }, {
            'rf_mode': 'tdd2600',

            'default_dl_earfcn': 38050,
            'default_lte_dl_freq': 2600.0,
            'default_lte_band': 38,
            'default_lte_n_rb_dl': LTE_N_RB_DL,
            'default_lte_tx_gain': LTE_TX_GAIN,
            'default_lte_rx_gain': LTE_RX_GAIN,

            'default_dl_nr_arfcn': 520000,
            'default_nr_band': 38,
            'default_nr_dl_freq': 2600.0,
            'default_nr_bandwidth': NR_BANDWIDTH,
            'default_nr_tx_gain': NR_TX_GAIN,
            'default_nr_rx_gain': NR_RX_GAIN,

            'min_frequency': 2570,
            'max_frequency': 2620,
        }, {
            'rf_mode': 'tdd3500',

            'default_dl_earfcn': 42590,
            'default_lte_dl_freq': 3500.0,
            'default_lte_band': 42,
            'default_lte_n_rb_dl': LTE_N_RB_DL,
            'default_lte_tx_gain': LTE_TX_GAIN,
            'default_lte_rx_gain': LTE_RX_GAIN,

            'default_dl_nr_arfcn': 632628,
            'default_nr_band': 78,
            'default_nr_dl_freq': 3489.42,
            'default_nr_bandwidth': NR_BANDWIDTH,
            'default_nr_tx_gain': NR_TX_GAIN,
            'default_nr_rx_gain': NR_RX_GAIN,

            'min_frequency': 3400,
            'max_frequency': 3600,
        }, {
            'rf_mode': 'tdd3700',

            'default_dl_earfcn': 44590,
            'default_lte_dl_freq': 3700.0,
            'default_lte_band': 43,
            'default_lte_n_rb_dl': LTE_N_RB_DL,
            'default_lte_tx_gain': LTE_TX_GAIN,
            'default_lte_rx_gain': LTE_RX_GAIN,

            'default_dl_nr_arfcn': 646666,
            'default_nr_band': 78,
            'default_nr_dl_freq': 3699.99,
            'default_nr_bandwidth': NR_BANDWIDTH,
            'default_nr_tx_gain': NR_TX_GAIN,
            'default_nr_rx_gain': NR_RX_GAIN,

            'min_frequency': 3600,
            'max_frequency': 3800,
        }
]

with open('software.cfg.jinja2.json', 'r') as f:
    software_json_template = Template(f.read())
with open('instance-enb-input-schema.jinja2.json', 'r') as f:
    instance_enb_json_template = Template(f.read())
with open('instance-gnb-input-schema.jinja2.json', 'r') as f:
    instance_gnb_json_template = Template(f.read())
with open('software.jinja2.cfg', 'r') as f:
    software_template = Template(f.read())

for rf_mode_context in rf_mode_context_list:
    with open('software-{}.cfg.json'.format(rf_mode_context['rf_mode']),
              'w+') as f:
        f.write(software_json_template.render(**rf_mode_context, **global_context))
    with open('software-{}.cfg'.format(rf_mode_context['rf_mode']),
              'w+') as f:
        f.write(software_template.render(**rf_mode_context, **global_context))
    for software_type in ['enb', 'enb-epc', 'gnb', 'gnb-epc']:
        with open('instance-{}-{}-input-schema.json'.format(
                    rf_mode_context['rf_mode'],
                    software_type),
                  'w+') as f:
            if software_type in ['enb', 'enb-epc']:
                f.write(instance_enb_json_template.render(**rf_mode_context, **global_context))
            else:
                f.write(instance_gnb_json_template.render(**rf_mode_context, **global_context))