blob: 62cc8fa6f2e9e086b66639fadab898b3f486ba26 [file] [log] [blame]
carlosmscabral29432252013-02-04 11:54:16 -02001import ConfigParser, re
carlosmscabralf40ecd12013-02-01 18:15:58 -02002
ashuef3490b2015-02-17 11:01:04 -06003class confNDNHost():
carlosmscabral6d3dd602013-03-23 11:12:34 -03004
ashuef3490b2015-02-17 11:01:04 -06005 def __init__(self, name, app='', params='', cpu=None, cores=None, cache=None):
carlosmscabralf40ecd12013-02-01 18:15:58 -02006 self.name = name
7 self.app = app
ashuef3490b2015-02-17 11:01:04 -06008 self.uri_tuples = params
carlosmscabral29432252013-02-04 11:54:16 -02009 self.cpu = cpu
carlosmscabrale121a7b2013-02-18 18:14:53 -030010 self.cores = cores
ashuef3490b2015-02-17 11:01:04 -060011 self.cache = cache
12
13 # For now assume leftovers are NLSR configuration parameters
14 self.nlsrParameters = params
carlosmscabral6d3dd602013-03-23 11:12:34 -030015
carlosmscabralf40ecd12013-02-01 18:15:58 -020016 def __repr__(self):
ashuef3490b2015-02-17 11:01:04 -060017 return 'Name: ' + self.name + \
18 ' App: ' + self.app + \
19 ' URIS: ' + str(self.uri_tuples) + \
20 ' CPU: ' + str(self.cpu) + \
21 ' Cores: ' + str(self.cores) + \
22 ' Cache: ' + str(self.cache) + \
23 ' Radius: ' + str(self.radius) + \
24 ' Angle: ' + str(self.angle) + \
25 ' NLSR Parameters: ' + self.nlsrParameters
carlosmscabralf40ecd12013-02-01 18:15:58 -020026
ashuef3490b2015-02-17 11:01:04 -060027class confNDNLink():
carlosmscabral6d3dd602013-03-23 11:12:34 -030028
carlosmscabralf40ecd12013-02-01 18:15:58 -020029 def __init__(self,h1,h2,linkDict=None):
30 self.h1 = h1
31 self.h2 = h2
32 self.linkDict = linkDict
carlosmscabral6d3dd602013-03-23 11:12:34 -030033
carlosmscabralf40ecd12013-02-01 18:15:58 -020034 def __repr__(self):
35 return 'h1: ' + self.h1 + ' h2: ' + self.h2 + ' params: ' + str(self.linkDict)
carlosmscabral6d3dd602013-03-23 11:12:34 -030036
carlosmscabral29432252013-02-04 11:54:16 -020037def parse_hosts(conf_arq):
38 'Parse hosts section from the conf file.'
carlosmscabralf40ecd12013-02-01 18:15:58 -020039 config = ConfigParser.RawConfigParser()
40 config.read(conf_arq)
carlosmscabral6d3dd602013-03-23 11:12:34 -030041
carlosmscabralf40ecd12013-02-01 18:15:58 -020042 hosts = []
carlosmscabral6d3dd602013-03-23 11:12:34 -030043
ashuef3490b2015-02-17 11:01:04 -060044 items = config.items('nodes')
carlosmscabral6d3dd602013-03-23 11:12:34 -030045
ashuef3490b2015-02-17 11:01:04 -060046 #makes a first-pass read to hosts section to find empty host sections
47 for item in items:
48 name = item[0]
49 rest = item[1].split()
50 if len(rest) == 0:
51 config.set('nodes', name, '_')
52 #updates 'items' list
53 items = config.items('nodes')
54
55 #makes a second-pass read to hosts section to properly add hosts
carlosmscabralf40ecd12013-02-01 18:15:58 -020056 for item in items:
57
58 name = item[0]
carlosmscabral6d3dd602013-03-23 11:12:34 -030059
carlosmscabralf40ecd12013-02-01 18:15:58 -020060 rest = item[1].split()
61
62 app = rest.pop(0)
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]
carlosmscabral29432252013-02-04 11:54:16 -020079 else:
ashuef3490b2015-02-17 11:01:04 -060080 params[uri.split('=')[0]] = uri.split('=')[1]
carlosmscabral6d3dd602013-03-23 11:12:34 -030081
ashuef3490b2015-02-17 11:01:04 -060082 hosts.append(confNDNHost(name, app, params, cpu, cores, cache))
carlosmscabral6d3dd602013-03-23 11:12:34 -030083
carlosmscabralf40ecd12013-02-01 18:15:58 -020084 return hosts
85
carlosmscabral29432252013-02-04 11:54:16 -020086def parse_links(conf_arq):
87 'Parse links section from the conf file.'
carlosmscabralf40ecd12013-02-01 18:15:58 -020088 arq = open(conf_arq,'r')
carlosmscabral6d3dd602013-03-23 11:12:34 -030089
carlosmscabralf40ecd12013-02-01 18:15:58 -020090 links = []
carlosmscabral6d3dd602013-03-23 11:12:34 -030091
carlosmscabralf40ecd12013-02-01 18:15:58 -020092 while True:
93 line = arq.readline()
94 if line == '[links]\n':
95 break
carlosmscabral6d3dd602013-03-23 11:12:34 -030096
carlosmscabralf40ecd12013-02-01 18:15:58 -020097 while True:
98 line = arq.readline()
99 if line == '':
100 break
carlosmscabral6d3dd602013-03-23 11:12:34 -0300101
carlosmscabralf40ecd12013-02-01 18:15:58 -0200102 args = line.split()
ashuef3490b2015-02-17 11:01:04 -0600103
104 #checks for non-empty line
105 if len(args) == 0:
106 continue
Caio Eliasc6b56032014-09-19 14:12:48 -0300107
carlosmscabralf40ecd12013-02-01 18:15:58 -0200108 h1, h2 = args.pop(0).split(':')
carlosmscabral6d3dd602013-03-23 11:12:34 -0300109
carlosmscabralf40ecd12013-02-01 18:15:58 -0200110 link_dict = {}
carlosmscabral6d3dd602013-03-23 11:12:34 -0300111
carlosmscabralf40ecd12013-02-01 18:15:58 -0200112 for arg in args:
113 arg_name, arg_value = arg.split('=')
114 key = arg_name
115 value = arg_value
carlosmscabral6d3dd602013-03-23 11:12:34 -0300116 if key in ['bw','jitter','max_queue_size']:
carlosmscabralf40ecd12013-02-01 18:15:58 -0200117 value = int(value)
carlosmscabral6d3dd602013-03-23 11:12:34 -0300118 if key in ['loss']:
119 value = float(value)
carlosmscabralf40ecd12013-02-01 18:15:58 -0200120 link_dict[key] = value
carlosmscabral6d3dd602013-03-23 11:12:34 -0300121
ashuef3490b2015-02-17 11:01:04 -0600122 links.append(confNDNLink(h1,h2,link_dict))
carlosmscabral6d3dd602013-03-23 11:12:34 -0300123
124
carlosmscabralf40ecd12013-02-01 18:15:58 -0200125 return links