Parser fix to avoid infinite loop
Refs: #4627
Change-Id: I629bb76b3a1dbba4f44aac6ee258000a8d5ade7e
diff --git a/ndn/conf_parser.py b/ndn/conf_parser.py
index 725c1b0..dfadeab 100644
--- a/ndn/conf_parser.py
+++ b/ndn/conf_parser.py
@@ -171,41 +171,36 @@
def parse_links(conf_arq):
'Parse links section from the conf file.'
- arq = open(conf_arq,'r')
+ arq = open(conf_arq, 'r')
links = []
+ linkSectionFlag = False
- while True:
- line = arq.readline()
- if line == '[links]\n':
- break
+ for line in arq:
+ if linkSectionFlag:
+ args = line.split()
- while True:
- line = arq.readline()
- if line == '':
- break
+ # checks for non-empty line
+ if len(args) == 0:
+ continue
- args = line.split()
+ h1, h2 = args.pop(0).split(':')
- #checks for non-empty line
- if len(args) == 0:
- continue
+ link_dict = {}
- h1, h2 = args.pop(0).split(':')
+ for arg in args:
+ arg_name, arg_value = arg.split('=')
+ key = arg_name
+ value = arg_value
+ if key in ['bw','jitter','max_queue_size']:
+ value = int(value)
+ if key in ['loss']:
+ value = float(value)
+ link_dict[key] = value
- link_dict = {}
+ links.append(confNDNLink(h1,h2,link_dict))
- for arg in args:
- arg_name, arg_value = arg.split('=')
- key = arg_name
- value = arg_value
- if key in ['bw','jitter','max_queue_size']:
- value = int(value)
- if key in ['loss']:
- value = float(value)
- link_dict[key] = value
+ elif line == "[links]\n":
+ linkSectionFlag = True
- links.append(confNDNLink(h1,h2,link_dict))
-
-
- return links
+ return links
\ No newline at end of file