blob: b6b6ca3e17f856517f0c999e4cce8c689cda4dcf [file] [log] [blame]
carlosmscabral29432252013-02-04 11:54:16 -02001import ConfigParser, re
Ashlesh Gawande557cb842015-07-01 15:39:44 -05002import shlex
carlosmscabralf40ecd12013-02-01 18:15:58 -02003
ashuef3490b2015-02-17 11:01:04 -06004class confNDNHost():
carlosmscabral6d3dd602013-03-23 11:12:34 -03005
ashuef3490b2015-02-17 11:01:04 -06006 def __init__(self, name, app='', params='', cpu=None, cores=None, cache=None):
carlosmscabralf40ecd12013-02-01 18:15:58 -02007 self.name = name
8 self.app = app
ashuef3490b2015-02-17 11:01:04 -06009 self.uri_tuples = params
Ashlesh Gawande3a4afb12015-07-09 09:23:30 -050010 self.params = params
carlosmscabral29432252013-02-04 11:54:16 -020011 self.cpu = cpu
carlosmscabrale121a7b2013-02-18 18:14:53 -030012 self.cores = cores
ashuef3490b2015-02-17 11:01:04 -060013 self.cache = cache
14
15 # For now assume leftovers are NLSR configuration parameters
16 self.nlsrParameters = params
carlosmscabral6d3dd602013-03-23 11:12:34 -030017
carlosmscabralf40ecd12013-02-01 18:15:58 -020018 def __repr__(self):
ashuef3490b2015-02-17 11:01:04 -060019 return 'Name: ' + self.name + \
20 ' App: ' + self.app + \
21 ' URIS: ' + str(self.uri_tuples) + \
22 ' CPU: ' + str(self.cpu) + \
23 ' Cores: ' + str(self.cores) + \
24 ' Cache: ' + str(self.cache) + \
25 ' Radius: ' + str(self.radius) + \
26 ' Angle: ' + str(self.angle) + \
27 ' NLSR Parameters: ' + self.nlsrParameters
carlosmscabralf40ecd12013-02-01 18:15:58 -020028
ashuef3490b2015-02-17 11:01:04 -060029class confNDNLink():
carlosmscabral6d3dd602013-03-23 11:12:34 -030030
carlosmscabralf40ecd12013-02-01 18:15:58 -020031 def __init__(self,h1,h2,linkDict=None):
32 self.h1 = h1
33 self.h2 = h2
34 self.linkDict = linkDict
carlosmscabral6d3dd602013-03-23 11:12:34 -030035
carlosmscabralf40ecd12013-02-01 18:15:58 -020036 def __repr__(self):
37 return 'h1: ' + self.h1 + ' h2: ' + self.h2 + ' params: ' + str(self.linkDict)
carlosmscabral6d3dd602013-03-23 11:12:34 -030038
carlosmscabral29432252013-02-04 11:54:16 -020039def parse_hosts(conf_arq):
40 'Parse hosts section from the conf file.'
carlosmscabralf40ecd12013-02-01 18:15:58 -020041 config = ConfigParser.RawConfigParser()
42 config.read(conf_arq)
carlosmscabral6d3dd602013-03-23 11:12:34 -030043
carlosmscabralf40ecd12013-02-01 18:15:58 -020044 hosts = []
carlosmscabral6d3dd602013-03-23 11:12:34 -030045
ashuef3490b2015-02-17 11:01:04 -060046 items = config.items('nodes')
carlosmscabral6d3dd602013-03-23 11:12:34 -030047
ashuef3490b2015-02-17 11:01:04 -060048 #makes a first-pass read to hosts section to find empty host sections
49 for item in items:
50 name = item[0]
51 rest = item[1].split()
52 if len(rest) == 0:
53 config.set('nodes', name, '_')
54 #updates 'items' list
55 items = config.items('nodes')
56
57 #makes a second-pass read to hosts section to properly add hosts
carlosmscabralf40ecd12013-02-01 18:15:58 -020058 for item in items:
59
60 name = item[0]
carlosmscabral6d3dd602013-03-23 11:12:34 -030061
Ashlesh Gawande557cb842015-07-01 15:39:44 -050062 rest = shlex.split(item[1])
carlosmscabral6d3dd602013-03-23 11:12:34 -030063
carlosmscabralf40ecd12013-02-01 18:15:58 -020064 uris = rest
ashuef3490b2015-02-17 11:01:04 -060065 params = {}
carlosmscabral29432252013-02-04 11:54:16 -020066 cpu = None
carlosmscabrale121a7b2013-02-18 18:14:53 -030067 cores = None
ashuef3490b2015-02-17 11:01:04 -060068 cache = None
carlosmscabral6d3dd602013-03-23 11:12:34 -030069
carlosmscabralf40ecd12013-02-01 18:15:58 -020070 for uri in uris:
carlosmscabral29432252013-02-04 11:54:16 -020071 if re.match("cpu",uri):
72 cpu = float(uri.split('=')[1])
carlosmscabrale121a7b2013-02-18 18:14:53 -030073 elif re.match("cores",uri):
74 cores = uri.split('=')[1]
ashuef3490b2015-02-17 11:01:04 -060075 elif re.match("cache",uri):
76 cache = uri.split('=')[1]
77 elif re.match("mem",uri):
78 mem = uri.split('=')[1]
Ashlesh Gawande557cb842015-07-01 15:39:44 -050079 elif re.match("app",uri):
80 app = uri.split('=')[1]
81 elif re.match("_", uri):
82 app = ""
carlosmscabral29432252013-02-04 11:54:16 -020083 else:
ashuef3490b2015-02-17 11:01:04 -060084 params[uri.split('=')[0]] = uri.split('=')[1]
carlosmscabral6d3dd602013-03-23 11:12:34 -030085
ashuef3490b2015-02-17 11:01:04 -060086 hosts.append(confNDNHost(name, app, params, cpu, cores, cache))
carlosmscabral6d3dd602013-03-23 11:12:34 -030087
carlosmscabralf40ecd12013-02-01 18:15:58 -020088 return hosts
89
carlosmscabral29432252013-02-04 11:54:16 -020090def parse_links(conf_arq):
91 'Parse links section from the conf file.'
carlosmscabralf40ecd12013-02-01 18:15:58 -020092 arq = open(conf_arq,'r')
carlosmscabral6d3dd602013-03-23 11:12:34 -030093
carlosmscabralf40ecd12013-02-01 18:15:58 -020094 links = []
carlosmscabral6d3dd602013-03-23 11:12:34 -030095
carlosmscabralf40ecd12013-02-01 18:15:58 -020096 while True:
97 line = arq.readline()
98 if line == '[links]\n':
99 break
carlosmscabral6d3dd602013-03-23 11:12:34 -0300100
carlosmscabralf40ecd12013-02-01 18:15:58 -0200101 while True:
102 line = arq.readline()
103 if line == '':
104 break
carlosmscabral6d3dd602013-03-23 11:12:34 -0300105
carlosmscabralf40ecd12013-02-01 18:15:58 -0200106 args = line.split()
ashuef3490b2015-02-17 11:01:04 -0600107
108 #checks for non-empty line
109 if len(args) == 0:
110 continue
Caio Eliasc6b56032014-09-19 14:12:48 -0300111
carlosmscabralf40ecd12013-02-01 18:15:58 -0200112 h1, h2 = args.pop(0).split(':')
carlosmscabral6d3dd602013-03-23 11:12:34 -0300113
carlosmscabralf40ecd12013-02-01 18:15:58 -0200114 link_dict = {}
carlosmscabral6d3dd602013-03-23 11:12:34 -0300115
carlosmscabralf40ecd12013-02-01 18:15:58 -0200116 for arg in args:
117 arg_name, arg_value = arg.split('=')
118 key = arg_name
119 value = arg_value
carlosmscabral6d3dd602013-03-23 11:12:34 -0300120 if key in ['bw','jitter','max_queue_size']:
carlosmscabralf40ecd12013-02-01 18:15:58 -0200121 value = int(value)
carlosmscabral6d3dd602013-03-23 11:12:34 -0300122 if key in ['loss']:
123 value = float(value)
carlosmscabralf40ecd12013-02-01 18:15:58 -0200124 link_dict[key] = value
carlosmscabral6d3dd602013-03-23 11:12:34 -0300125
ashuef3490b2015-02-17 11:01:04 -0600126 links.append(confNDNLink(h1,h2,link_dict))
carlosmscabral6d3dd602013-03-23 11:12:34 -0300127
128
carlosmscabralf40ecd12013-02-01 18:15:58 -0200129 return links