blob: 395c6d73853d96246bec57d213e15c180dd465c0 [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
Ashlesh Gawande3a4afb12015-07-09 09:23:30 -05009 self.params = params
carlosmscabral29432252013-02-04 11:54:16 -020010 self.cpu = cpu
carlosmscabrale121a7b2013-02-18 18:14:53 -030011 self.cores = cores
ashuef3490b2015-02-17 11:01:04 -060012 self.cache = cache
13
14 # For now assume leftovers are NLSR configuration parameters
15 self.nlsrParameters = params
carlosmscabral6d3dd602013-03-23 11:12:34 -030016
carlosmscabralf40ecd12013-02-01 18:15:58 -020017 def __repr__(self):
ashuef3490b2015-02-17 11:01:04 -060018 return 'Name: ' + self.name + \
19 ' App: ' + self.app + \
20 ' URIS: ' + str(self.uri_tuples) + \
21 ' CPU: ' + str(self.cpu) + \
22 ' Cores: ' + str(self.cores) + \
23 ' Cache: ' + str(self.cache) + \
24 ' Radius: ' + str(self.radius) + \
25 ' Angle: ' + str(self.angle) + \
26 ' NLSR Parameters: ' + self.nlsrParameters
carlosmscabralf40ecd12013-02-01 18:15:58 -020027
ashuef3490b2015-02-17 11:01:04 -060028class confNDNLink():
carlosmscabral6d3dd602013-03-23 11:12:34 -030029
carlosmscabralf40ecd12013-02-01 18:15:58 -020030 def __init__(self,h1,h2,linkDict=None):
31 self.h1 = h1
32 self.h2 = h2
33 self.linkDict = linkDict
carlosmscabral6d3dd602013-03-23 11:12:34 -030034
carlosmscabralf40ecd12013-02-01 18:15:58 -020035 def __repr__(self):
36 return 'h1: ' + self.h1 + ' h2: ' + self.h2 + ' params: ' + str(self.linkDict)
carlosmscabral6d3dd602013-03-23 11:12:34 -030037
carlosmscabral29432252013-02-04 11:54:16 -020038def parse_hosts(conf_arq):
39 'Parse hosts section from the conf file.'
carlosmscabralf40ecd12013-02-01 18:15:58 -020040 config = ConfigParser.RawConfigParser()
41 config.read(conf_arq)
carlosmscabral6d3dd602013-03-23 11:12:34 -030042
carlosmscabralf40ecd12013-02-01 18:15:58 -020043 hosts = []
carlosmscabral6d3dd602013-03-23 11:12:34 -030044
ashuef3490b2015-02-17 11:01:04 -060045 items = config.items('nodes')
carlosmscabral6d3dd602013-03-23 11:12:34 -030046
ashuef3490b2015-02-17 11:01:04 -060047 #makes a first-pass read to hosts section to find empty host sections
48 for item in items:
49 name = item[0]
50 rest = item[1].split()
51 if len(rest) == 0:
52 config.set('nodes', name, '_')
53 #updates 'items' list
54 items = config.items('nodes')
55
56 #makes a second-pass read to hosts section to properly add hosts
carlosmscabralf40ecd12013-02-01 18:15:58 -020057 for item in items:
58
59 name = item[0]
carlosmscabral6d3dd602013-03-23 11:12:34 -030060
carlosmscabralf40ecd12013-02-01 18:15:58 -020061 rest = item[1].split()
62
63 app = rest.pop(0)
carlosmscabral6d3dd602013-03-23 11:12:34 -030064
carlosmscabralf40ecd12013-02-01 18:15:58 -020065 uris = rest
ashuef3490b2015-02-17 11:01:04 -060066 params = {}
carlosmscabral29432252013-02-04 11:54:16 -020067 cpu = None
carlosmscabrale121a7b2013-02-18 18:14:53 -030068 cores = None
ashuef3490b2015-02-17 11:01:04 -060069 cache = None
carlosmscabral6d3dd602013-03-23 11:12:34 -030070
carlosmscabralf40ecd12013-02-01 18:15:58 -020071 for uri in uris:
carlosmscabral29432252013-02-04 11:54:16 -020072 if re.match("cpu",uri):
73 cpu = float(uri.split('=')[1])
carlosmscabrale121a7b2013-02-18 18:14:53 -030074 elif re.match("cores",uri):
75 cores = uri.split('=')[1]
ashuef3490b2015-02-17 11:01:04 -060076 elif re.match("cache",uri):
77 cache = uri.split('=')[1]
78 elif re.match("mem",uri):
79 mem = uri.split('=')[1]
carlosmscabral29432252013-02-04 11:54:16 -020080 else:
ashuef3490b2015-02-17 11:01:04 -060081 params[uri.split('=')[0]] = uri.split('=')[1]
carlosmscabral6d3dd602013-03-23 11:12:34 -030082
ashuef3490b2015-02-17 11:01:04 -060083 hosts.append(confNDNHost(name, app, params, cpu, cores, cache))
carlosmscabral6d3dd602013-03-23 11:12:34 -030084
carlosmscabralf40ecd12013-02-01 18:15:58 -020085 return hosts
86
carlosmscabral29432252013-02-04 11:54:16 -020087def parse_links(conf_arq):
88 'Parse links section from the conf file.'
carlosmscabralf40ecd12013-02-01 18:15:58 -020089 arq = open(conf_arq,'r')
carlosmscabral6d3dd602013-03-23 11:12:34 -030090
carlosmscabralf40ecd12013-02-01 18:15:58 -020091 links = []
carlosmscabral6d3dd602013-03-23 11:12:34 -030092
carlosmscabralf40ecd12013-02-01 18:15:58 -020093 while True:
94 line = arq.readline()
95 if line == '[links]\n':
96 break
carlosmscabral6d3dd602013-03-23 11:12:34 -030097
carlosmscabralf40ecd12013-02-01 18:15:58 -020098 while True:
99 line = arq.readline()
100 if line == '':
101 break
carlosmscabral6d3dd602013-03-23 11:12:34 -0300102
carlosmscabralf40ecd12013-02-01 18:15:58 -0200103 args = line.split()
ashuef3490b2015-02-17 11:01:04 -0600104
105 #checks for non-empty line
106 if len(args) == 0:
107 continue
Caio Eliasc6b56032014-09-19 14:12:48 -0300108
carlosmscabralf40ecd12013-02-01 18:15:58 -0200109 h1, h2 = args.pop(0).split(':')
carlosmscabral6d3dd602013-03-23 11:12:34 -0300110
carlosmscabralf40ecd12013-02-01 18:15:58 -0200111 link_dict = {}
carlosmscabral6d3dd602013-03-23 11:12:34 -0300112
carlosmscabralf40ecd12013-02-01 18:15:58 -0200113 for arg in args:
114 arg_name, arg_value = arg.split('=')
115 key = arg_name
116 value = arg_value
carlosmscabral6d3dd602013-03-23 11:12:34 -0300117 if key in ['bw','jitter','max_queue_size']:
carlosmscabralf40ecd12013-02-01 18:15:58 -0200118 value = int(value)
carlosmscabral6d3dd602013-03-23 11:12:34 -0300119 if key in ['loss']:
120 value = float(value)
carlosmscabralf40ecd12013-02-01 18:15:58 -0200121 link_dict[key] = value
carlosmscabral6d3dd602013-03-23 11:12:34 -0300122
ashuef3490b2015-02-17 11:01:04 -0600123 links.append(confNDNLink(h1,h2,link_dict))
carlosmscabral6d3dd602013-03-23 11:12:34 -0300124
125
carlosmscabralf40ecd12013-02-01 18:15:58 -0200126 return links