Commit 09db9c30 authored by Robert Schmidt's avatar Robert Schmidt

generateTemplate.py: allow multiple replacements in a single line

- especially for plmn_list, will allow to be followed by an MCC/MNC in a
  single line
- tightens regexes to match replacements more accurately, e.g., "val =
  key" (instead of just searching for "key)
- no special rule for SD, which matches SD values (and not the SD
  field). However, currently it is not possible to specify multiple SDs
  (multiple SSTs was already not possible)
parent 46bbd3f9
......@@ -32,11 +32,12 @@
env: "@ENB_NAME@"
- key: eNB_name
env: "@ENB_NAME@"
- key: plmn_list
env:
mcc: "@MCC@"
mnc: "@MNC@"
mnc_length: "@MNC_LENGTH@"
- key: mcc
env: "@MCC@"
- key: mnc
env: "@MNC@"
- key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code
env: "@TAC@"
- key: local_s_if_name
......@@ -75,11 +76,12 @@
env: "@ENB_NAME@"
- key: eNB_name
env: "@ENB_NAME@"
- key: plmn_list
env:
mcc: "@MCC@"
mnc: "@MNC@"
mnc_length: "@MNC_LENGTH@"
- key: mcc
env: "@MCC@"
- key: mnc
env: "@MNC@"
- key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code
env: "@TAC@"
- key: local_n_if_name
......@@ -136,11 +138,12 @@
env: "@ENB_NAME@"
- key: eNB_name
env: "@ENB_NAME@"
- key: plmn_list
env:
mcc: "@MCC@"
mnc: "@MNC@"
mnc_length: "@MNC_LENGTH@"
- key: mcc
env: "@MCC@"
- key: mnc
env: "@MNC@"
- key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code
env: "@TAC@"
- key: eutra_band
......@@ -187,11 +190,12 @@
env: "@ENB_NAME@"
- key: eNB_name
env: "@ENB_NAME@"
- key: plmn_list
env:
mcc: "@MCC@"
mnc: "@MNC@"
mnc_length: "@MNC_LENGTH@"
- key: mcc
env: "@MCC@"
- key: mnc
env: "@MNC@"
- key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code
env: "@TAC@"
- key: eutra_band
......@@ -226,11 +230,12 @@
env: "@ENB_NAME@"
- key: eNB_name
env: "@ENB_NAME@"
- key: plmn_list
env:
mcc: "@MCC@"
mnc: "@MNC@"
mnc_length: "@MNC_LENGTH@"
- key: mcc
env: "@MCC@"
- key: mnc
env: "@MNC@"
- key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code
env: "@TAC@"
- key: local_s_if_name
......@@ -271,11 +276,12 @@
env: "@ENB_NAME@"
- key: eNB_name
env: "@ENB_NAME@"
- key: plmn_list
env:
mcc: "@MCC@"
mnc: "@MNC@"
mnc_length: "@MNC_LENGTH@"
- key: mcc
env: "@MCC@"
- key: mnc
env: "@MNC@"
- key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code
env: "@TAC@"
- key: eutra_band
......@@ -316,11 +322,12 @@
env: "@ENB_NAME@"
- key: eNB_name
env: "@ENB_NAME@"
- key: plmn_list
env:
mcc: "@MCC@"
mnc: "@MNC@"
mnc_length: "@MNC_LENGTH@"
- key: mcc
env: "@MCC@"
- key: mnc
env: "@MNC@"
- key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code
env: "@TAC@"
- key: eutra_band
......@@ -361,11 +368,12 @@
env: "@ENB_NAME@"
- key: eNB_name
env: "@ENB_NAME@"
- key: plmn_list
env:
mcc: "@MCC@"
mnc: "@MNC@"
mnc_length: "@MNC_LENGTH@"
- key: mcc
env: "@MCC@"
- key: mnc
env: "@MNC@"
- key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code
env: "@TAC@"
- key: eutra_band
......
......@@ -82,47 +82,32 @@ def main():
with open(f'{inputfile}', mode='r') as inputfile, \
open(outputfile1, mode='w') as outputfile:
for line in inputfile:
count = 0
if re.search(r'EHPLMN_LIST', line):
outputfile.write(line)
continue
if re.search(r'sd = 0x1;', line):
templine = re.sub(r'sd = 0x1;', 'sd = 0x@NSSAI_SD0@;', line)
outputfile.write(templine)
continue
if re.search(r'sd = 0x010203;', line):
templine = re.sub(r'sd = 0x010203;', 'sd = 0x@NSSAI_SD0@;', line)
outputfile.write(templine)
continue
if re.search(r'sd = 0x112233;', line):
templine = re.sub(r'sd = 0x112233;', 'sd = 0x@NSSAI_SD1@;', line)
outputfile.write(templine)
continue
templine = line
for key in config["config"]:
if line.find(key["key"]) >= 0:
count += 1
if re.search(r'preference', line):
templine = line
elif re.search(r'mnc_length', line) and key["key"] == "mnc":
if templine.find(key["key"]) >= 0:
if re.search(r'preference', templine): # false positive
continue
if re.search(r'sdr_addrs', templine): # false positive
continue
elif re.search(r'plmn_list', line) and type(key["env"]) is dict:
templine = re.sub(r'[0-9]+', '""', line)
templine = re.sub(r'\"\"', key["env"]["mcc"], templine, 1)
templine = re.sub(r'\"\"', key["env"]["mnc"], templine, 1)
templine = re.sub(r'\"\"', key["env"]["mnc_length"], templine, 1)
elif re.search('downlink_frequency', line):
templine = re.sub(r'[0-9]+', key["env"], line)
elif re.search('uplink_frequency_offset', line):
templine = re.sub(r'[0-9]+', key["env"], line)
elif re.search(r'"(.*?)"', line):
templine = re.sub(r'(?<=")[^"]*(?=")', key["env"], line)
elif re.search(r'[0-9]', line):
templine = re.sub(r'\d+', key["env"], line)
outputfile.write(templine)
if count == 0:
outputfile.write(line)
# next: matches key = ( "SOMETHING" ) or key = [ "SOMETHING" ]
elif re.search(key["key"] + "\s*=\s*[\(\[]\s*\"[0-9.a-zA-Z:_-]+\"\s*[\)\]]", templine):
templine = re.sub("(" + key["key"] + "\s*=\s*[\(\[]\s*\")[0-9.a-zA-Z:_-]+(\"[\)\]])",
r'\1' + key["env"] + r"\2", templine)
# next: matches key = "SOMETHING" or key = [SOMETHING],
elif re.search(key["key"] + "\s*=\s*[\"\[][0-9.a-zA-Z:_/-]+[\"\]]", templine):
templine = re.sub("(" + key["key"] + "\s*=\s*[\"\[])[0-9.a-zA-Z:_/-]+([\"\]])",
r'\1' + key["env"] + r"\2", templine)
# next: matches key = NUMBER
elif re.search(key["key"] + "\s*=\s*[x0-9]+", templine): # x for "0x" hex start
templine = re.sub("(" + key["key"] + "\s*=\s*(?:0x)?)[x0-9]+", r"\1" + key["env"], templine)
outputfile.write(templine)
if __name__ == "__main__":
main()
......@@ -32,11 +32,16 @@
env: "@GNB_NAME@"
- key: gNB_name
env: "@GNB_NAME@"
- key: plmn_list
env:
mcc: "@MCC@"
mnc: "@MNC@"
mnc_length: "@MNC_LENGTH@"
- key: mcc
env: "@MCC@"
- key: mnc
env: "@MNC@"
- key: mnc_length
env: "@MNC_LENGTH@"
- key: sst
env: "@NSSAI_SST@"
- key: sd
env: "@NSSAI_SD@"
- key: tracking_area_code
env: "@TAC@"
- key: enable_x2
......@@ -81,6 +86,8 @@
env: "@TAC@"
- key: sst
env: "@NSSAI_SST@"
- key: sd
env: "@NSSAI_SD@"
- key: ipv4
env: "@AMF_IP_ADDRESS@"
- key: GNB_INTERFACE_NAME_FOR_NG_AMF
......@@ -141,6 +148,8 @@
env: "@TAC@"
- key: sst
env: "@NSSAI_SST@"
- key: sd
env: "@NSSAI_SD@"
- key: ipv4
env: "@AMF_IP_ADDRESS@"
- key: GNB_INTERFACE_NAME_FOR_NG_AMF
......@@ -171,6 +180,8 @@
env: "@TAC@"
- key: sst
env: "@NSSAI_SST@"
- key: sd
env: "@NSSAI_SD@"
- key: ipv4
env: "@AMF_IP_ADDRESS@"
- key: GNB_INTERFACE_NAME_FOR_NG_AMF
......@@ -209,6 +220,8 @@
env: "@TAC@"
- key: sst
env: "@NSSAI_SST@"
- key: sd
env: "@NSSAI_SD@"
- key: ipv4
env: "@AMF_IP_ADDRESS@"
- key: GNB_INTERFACE_NAME_FOR_NG_AMF
......@@ -249,6 +262,8 @@
env: "@TAC@"
- key: sst
env: "@NSSAI_SST@"
- key: sd
env: "@NSSAI_SD@"
- key: ipv4
env: "@AMF_IP_ADDRESS@"
- key: GNB_INTERFACE_NAME_FOR_NG_AMF
......
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