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 @@ ...@@ -32,11 +32,12 @@
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: eNB_name - key: eNB_name
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: plmn_list - key: mcc
env: env: "@MCC@"
mcc: "@MCC@" - key: mnc
mnc: "@MNC@" env: "@MNC@"
mnc_length: "@MNC_LENGTH@" - key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code - key: tracking_area_code
env: "@TAC@" env: "@TAC@"
- key: local_s_if_name - key: local_s_if_name
...@@ -75,11 +76,12 @@ ...@@ -75,11 +76,12 @@
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: eNB_name - key: eNB_name
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: plmn_list - key: mcc
env: env: "@MCC@"
mcc: "@MCC@" - key: mnc
mnc: "@MNC@" env: "@MNC@"
mnc_length: "@MNC_LENGTH@" - key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code - key: tracking_area_code
env: "@TAC@" env: "@TAC@"
- key: local_n_if_name - key: local_n_if_name
...@@ -136,11 +138,12 @@ ...@@ -136,11 +138,12 @@
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: eNB_name - key: eNB_name
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: plmn_list - key: mcc
env: env: "@MCC@"
mcc: "@MCC@" - key: mnc
mnc: "@MNC@" env: "@MNC@"
mnc_length: "@MNC_LENGTH@" - key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code - key: tracking_area_code
env: "@TAC@" env: "@TAC@"
- key: eutra_band - key: eutra_band
...@@ -187,11 +190,12 @@ ...@@ -187,11 +190,12 @@
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: eNB_name - key: eNB_name
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: plmn_list - key: mcc
env: env: "@MCC@"
mcc: "@MCC@" - key: mnc
mnc: "@MNC@" env: "@MNC@"
mnc_length: "@MNC_LENGTH@" - key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code - key: tracking_area_code
env: "@TAC@" env: "@TAC@"
- key: eutra_band - key: eutra_band
...@@ -226,11 +230,12 @@ ...@@ -226,11 +230,12 @@
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: eNB_name - key: eNB_name
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: plmn_list - key: mcc
env: env: "@MCC@"
mcc: "@MCC@" - key: mnc
mnc: "@MNC@" env: "@MNC@"
mnc_length: "@MNC_LENGTH@" - key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code - key: tracking_area_code
env: "@TAC@" env: "@TAC@"
- key: local_s_if_name - key: local_s_if_name
...@@ -271,11 +276,12 @@ ...@@ -271,11 +276,12 @@
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: eNB_name - key: eNB_name
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: plmn_list - key: mcc
env: env: "@MCC@"
mcc: "@MCC@" - key: mnc
mnc: "@MNC@" env: "@MNC@"
mnc_length: "@MNC_LENGTH@" - key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code - key: tracking_area_code
env: "@TAC@" env: "@TAC@"
- key: eutra_band - key: eutra_band
...@@ -316,11 +322,12 @@ ...@@ -316,11 +322,12 @@
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: eNB_name - key: eNB_name
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: plmn_list - key: mcc
env: env: "@MCC@"
mcc: "@MCC@" - key: mnc
mnc: "@MNC@" env: "@MNC@"
mnc_length: "@MNC_LENGTH@" - key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code - key: tracking_area_code
env: "@TAC@" env: "@TAC@"
- key: eutra_band - key: eutra_band
...@@ -361,11 +368,12 @@ ...@@ -361,11 +368,12 @@
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: eNB_name - key: eNB_name
env: "@ENB_NAME@" env: "@ENB_NAME@"
- key: plmn_list - key: mcc
env: env: "@MCC@"
mcc: "@MCC@" - key: mnc
mnc: "@MNC@" env: "@MNC@"
mnc_length: "@MNC_LENGTH@" - key: mnc_length
env: "@MNC_LENGTH@"
- key: tracking_area_code - key: tracking_area_code
env: "@TAC@" env: "@TAC@"
- key: eutra_band - key: eutra_band
......
...@@ -82,47 +82,32 @@ def main(): ...@@ -82,47 +82,32 @@ def main():
with open(f'{inputfile}', mode='r') as inputfile, \ with open(f'{inputfile}', mode='r') as inputfile, \
open(outputfile1, mode='w') as outputfile: open(outputfile1, mode='w') as outputfile:
for line in inputfile: for line in inputfile:
count = 0
if re.search(r'EHPLMN_LIST', line): if re.search(r'EHPLMN_LIST', line):
outputfile.write(line) outputfile.write(line)
continue continue
if re.search(r'sd = 0x1;', line): templine = 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
for key in config["config"]: for key in config["config"]:
if line.find(key["key"]) >= 0: if templine.find(key["key"]) >= 0:
count += 1 if re.search(r'preference', templine): # false positive
if re.search(r'preference', line): continue
templine = line if re.search(r'sdr_addrs', templine): # false positive
elif re.search(r'mnc_length', line) and key["key"] == "mnc":
continue 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): elif re.search('downlink_frequency', line):
templine = re.sub(r'[0-9]+', key["env"], line) templine = re.sub(r'[0-9]+', key["env"], line)
elif re.search('uplink_frequency_offset', line): elif re.search('uplink_frequency_offset', line):
templine = re.sub(r'[0-9]+', key["env"], line) templine = re.sub(r'[0-9]+', key["env"], line)
# next: matches key = ( "SOMETHING" ) or key = [ "SOMETHING" ]
elif re.search(r'"(.*?)"', line): elif re.search(key["key"] + "\s*=\s*[\(\[]\s*\"[0-9.a-zA-Z:_-]+\"\s*[\)\]]", templine):
templine = re.sub(r'(?<=")[^"]*(?=")', key["env"], line) templine = re.sub("(" + key["key"] + "\s*=\s*[\(\[]\s*\")[0-9.a-zA-Z:_-]+(\"[\)\]])",
elif re.search(r'[0-9]', line): r'\1' + key["env"] + r"\2", templine)
templine = re.sub(r'\d+', key["env"], line) # next: matches key = "SOMETHING" or key = [SOMETHING],
outputfile.write(templine) 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:_/-]+([\"\]])",
if count == 0: r'\1' + key["env"] + r"\2", templine)
outputfile.write(line) # 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__": if __name__ == "__main__":
main() main()
...@@ -32,11 +32,16 @@ ...@@ -32,11 +32,16 @@
env: "@GNB_NAME@" env: "@GNB_NAME@"
- key: gNB_name - key: gNB_name
env: "@GNB_NAME@" env: "@GNB_NAME@"
- key: plmn_list - key: mcc
env: env: "@MCC@"
mcc: "@MCC@" - key: mnc
mnc: "@MNC@" env: "@MNC@"
mnc_length: "@MNC_LENGTH@" - key: mnc_length
env: "@MNC_LENGTH@"
- key: sst
env: "@NSSAI_SST@"
- key: sd
env: "@NSSAI_SD@"
- key: tracking_area_code - key: tracking_area_code
env: "@TAC@" env: "@TAC@"
- key: enable_x2 - key: enable_x2
...@@ -81,6 +86,8 @@ ...@@ -81,6 +86,8 @@
env: "@TAC@" env: "@TAC@"
- key: sst - key: sst
env: "@NSSAI_SST@" env: "@NSSAI_SST@"
- key: sd
env: "@NSSAI_SD@"
- key: ipv4 - key: ipv4
env: "@AMF_IP_ADDRESS@" env: "@AMF_IP_ADDRESS@"
- key: GNB_INTERFACE_NAME_FOR_NG_AMF - key: GNB_INTERFACE_NAME_FOR_NG_AMF
...@@ -141,6 +148,8 @@ ...@@ -141,6 +148,8 @@
env: "@TAC@" env: "@TAC@"
- key: sst - key: sst
env: "@NSSAI_SST@" env: "@NSSAI_SST@"
- key: sd
env: "@NSSAI_SD@"
- key: ipv4 - key: ipv4
env: "@AMF_IP_ADDRESS@" env: "@AMF_IP_ADDRESS@"
- key: GNB_INTERFACE_NAME_FOR_NG_AMF - key: GNB_INTERFACE_NAME_FOR_NG_AMF
...@@ -171,6 +180,8 @@ ...@@ -171,6 +180,8 @@
env: "@TAC@" env: "@TAC@"
- key: sst - key: sst
env: "@NSSAI_SST@" env: "@NSSAI_SST@"
- key: sd
env: "@NSSAI_SD@"
- key: ipv4 - key: ipv4
env: "@AMF_IP_ADDRESS@" env: "@AMF_IP_ADDRESS@"
- key: GNB_INTERFACE_NAME_FOR_NG_AMF - key: GNB_INTERFACE_NAME_FOR_NG_AMF
...@@ -209,6 +220,8 @@ ...@@ -209,6 +220,8 @@
env: "@TAC@" env: "@TAC@"
- key: sst - key: sst
env: "@NSSAI_SST@" env: "@NSSAI_SST@"
- key: sd
env: "@NSSAI_SD@"
- key: ipv4 - key: ipv4
env: "@AMF_IP_ADDRESS@" env: "@AMF_IP_ADDRESS@"
- key: GNB_INTERFACE_NAME_FOR_NG_AMF - key: GNB_INTERFACE_NAME_FOR_NG_AMF
...@@ -249,6 +262,8 @@ ...@@ -249,6 +262,8 @@
env: "@TAC@" env: "@TAC@"
- key: sst - key: sst
env: "@NSSAI_SST@" env: "@NSSAI_SST@"
- key: sd
env: "@NSSAI_SD@"
- key: ipv4 - key: ipv4
env: "@AMF_IP_ADDRESS@" env: "@AMF_IP_ADDRESS@"
- key: GNB_INTERFACE_NAME_FOR_NG_AMF - 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