blob: f241e88c3054eef7c198120cf52e97e977a1ccf6 [file] [log] [blame]
carlosmscabral29432252013-02-04 11:54:16 -02001import ConfigParser, re
carlosmscabralf40ecd12013-02-01 18:15:58 -02002
3class confCCNHost():
carlosmscabral6d3dd602013-03-23 11:12:34 -03004
carlosmscabralb9d85b72013-07-15 15:24:33 -03005 def __init__(self, name, app='', uri_tuples='', cpu=None, cores=None, cache=None):
carlosmscabralf40ecd12013-02-01 18:15:58 -02006 self.name = name
7 self.app = app
8 self.uri_tuples = uri_tuples
carlosmscabral29432252013-02-04 11:54:16 -02009 self.cpu = cpu
carlosmscabrale121a7b2013-02-18 18:14:53 -030010 self.cores = cores
carlosmscabralb9d85b72013-07-15 15:24:33 -030011 self.cache = cache
carlosmscabral6d3dd602013-03-23 11:12:34 -030012
carlosmscabralf40ecd12013-02-01 18:15:58 -020013 def __repr__(self):
carlosmscabralb9d85b72013-07-15 15:24:33 -030014 return 'Name: ' + self.name + ' App: ' + self.app + ' URIS: ' + str(self.uri_tuples) + ' CPU:' + str(self.cpu) + ' Cores:' +str(self.cores) + ' Cache: ' + str(self.cache)
carlosmscabralf40ecd12013-02-01 18:15:58 -020015
16class confCCNLink():
carlosmscabral6d3dd602013-03-23 11:12:34 -030017
carlosmscabralf40ecd12013-02-01 18:15:58 -020018 def __init__(self,h1,h2,linkDict=None):
19 self.h1 = h1
20 self.h2 = h2
21 self.linkDict = linkDict
carlosmscabral6d3dd602013-03-23 11:12:34 -030022
carlosmscabralf40ecd12013-02-01 18:15:58 -020023 def __repr__(self):
24 return 'h1: ' + self.h1 + ' h2: ' + self.h2 + ' params: ' + str(self.linkDict)
carlosmscabral6d3dd602013-03-23 11:12:34 -030025
carlosmscabral29432252013-02-04 11:54:16 -020026def parse_hosts(conf_arq):
27 'Parse hosts section from the conf file.'
carlosmscabralf40ecd12013-02-01 18:15:58 -020028 config = ConfigParser.RawConfigParser()
29 config.read(conf_arq)
carlosmscabral6d3dd602013-03-23 11:12:34 -030030
carlosmscabralf40ecd12013-02-01 18:15:58 -020031 hosts = []
carlosmscabral6d3dd602013-03-23 11:12:34 -030032
carlosmscabralb9d85b72013-07-15 15:24:33 -030033 items = config.items('nodes')
carlosmscabral6d3dd602013-03-23 11:12:34 -030034
carlosmscabralf40ecd12013-02-01 18:15:58 -020035 for item in items:
36
37 name = item[0]
carlosmscabral6d3dd602013-03-23 11:12:34 -030038
carlosmscabralf40ecd12013-02-01 18:15:58 -020039 rest = item[1].split()
40
41 app = rest.pop(0)
carlosmscabral6d3dd602013-03-23 11:12:34 -030042
carlosmscabralf40ecd12013-02-01 18:15:58 -020043 uris = rest
44 uri_list=[]
carlosmscabral29432252013-02-04 11:54:16 -020045 cpu = None
carlosmscabrale121a7b2013-02-18 18:14:53 -030046 cores = None
carlosmscabralb9d85b72013-07-15 15:24:33 -030047 cache = None
carlosmscabral6d3dd602013-03-23 11:12:34 -030048
carlosmscabralf40ecd12013-02-01 18:15:58 -020049 for uri in uris:
carlosmscabral29432252013-02-04 11:54:16 -020050 if re.match("cpu",uri):
51 cpu = float(uri.split('=')[1])
carlosmscabrale121a7b2013-02-18 18:14:53 -030052 elif re.match("cores",uri):
53 cores = uri.split('=')[1]
carlosmscabralb9d85b72013-07-15 15:24:33 -030054 elif re.match("cache",uri):
55 cache = uri.split('=')[1]
carlosmscabral29432252013-02-04 11:54:16 -020056 else:
57 uri_list.append((uri.split(',')[0],uri.split(',')[1]))
carlosmscabral6d3dd602013-03-23 11:12:34 -030058
carlosmscabralb9d85b72013-07-15 15:24:33 -030059 hosts.append(confCCNHost(name , app, uri_list,cpu,cores,cache))
carlosmscabral6d3dd602013-03-23 11:12:34 -030060
carlosmscabralf40ecd12013-02-01 18:15:58 -020061 return hosts
62
carlosmscabral29432252013-02-04 11:54:16 -020063def parse_routers(conf_arq):
64 'Parse routers section from the conf file.'
carlosmscabralf40ecd12013-02-01 18:15:58 -020065 config = ConfigParser.RawConfigParser()
66 config.read(conf_arq)
67
68 routers = []
carlosmscabral6d3dd602013-03-23 11:12:34 -030069
carlosmscabralf40ecd12013-02-01 18:15:58 -020070 items = config.items('routers')
carlosmscabral6d3dd602013-03-23 11:12:34 -030071
carlosmscabralf40ecd12013-02-01 18:15:58 -020072 for item in items:
73 name = item[0]
carlosmscabral6d3dd602013-03-23 11:12:34 -030074
carlosmscabralf40ecd12013-02-01 18:15:58 -020075 rest = item[1].split()
76
77 uris = rest
78 uri_list=[]
carlosmscabral29432252013-02-04 11:54:16 -020079 cpu = None
carlosmscabrale121a7b2013-02-18 18:14:53 -030080 cores = None
carlosmscabral6d3dd602013-03-23 11:12:34 -030081
carlosmscabral29432252013-02-04 11:54:16 -020082 for uri in uris:
83 if re.match("cpu",uri):
84 cpu = float(uri.split('=')[1])
carlosmscabrale121a7b2013-02-18 18:14:53 -030085 elif re.match("cores",uri):
carlosmscabral6d3dd602013-03-23 11:12:34 -030086 cores = uri.split('=')[1]
carlosmscabral29432252013-02-04 11:54:16 -020087 else:
88 uri_list.append((uri.split(',')[0],uri.split(',')[1]))
carlosmscabral6d3dd602013-03-23 11:12:34 -030089
carlosmscabrale121a7b2013-02-18 18:14:53 -030090 routers.append(confCCNHost(name=name , uri_tuples=uri_list, cpu=cpu, cores=cores))
carlosmscabral6d3dd602013-03-23 11:12:34 -030091
carlosmscabralf40ecd12013-02-01 18:15:58 -020092 return routers
93
carlosmscabral29432252013-02-04 11:54:16 -020094def parse_links(conf_arq):
95 'Parse links section from the conf file.'
carlosmscabralf40ecd12013-02-01 18:15:58 -020096 arq = open(conf_arq,'r')
carlosmscabral6d3dd602013-03-23 11:12:34 -030097
carlosmscabralf40ecd12013-02-01 18:15:58 -020098 links = []
carlosmscabral6d3dd602013-03-23 11:12:34 -030099
carlosmscabralf40ecd12013-02-01 18:15:58 -0200100 while True:
101 line = arq.readline()
102 if line == '[links]\n':
103 break
carlosmscabral6d3dd602013-03-23 11:12:34 -0300104
carlosmscabralf40ecd12013-02-01 18:15:58 -0200105 while True:
106 line = arq.readline()
107 if line == '':
108 break
carlosmscabral6d3dd602013-03-23 11:12:34 -0300109
carlosmscabralf40ecd12013-02-01 18:15:58 -0200110 args = line.split()
111 h1, h2 = args.pop(0).split(':')
carlosmscabral6d3dd602013-03-23 11:12:34 -0300112
carlosmscabralf40ecd12013-02-01 18:15:58 -0200113 link_dict = {}
carlosmscabral6d3dd602013-03-23 11:12:34 -0300114
carlosmscabralf40ecd12013-02-01 18:15:58 -0200115 for arg in args:
116 arg_name, arg_value = arg.split('=')
117 key = arg_name
118 value = arg_value
carlosmscabral6d3dd602013-03-23 11:12:34 -0300119 if key in ['bw','jitter','max_queue_size']:
carlosmscabralf40ecd12013-02-01 18:15:58 -0200120 value = int(value)
carlosmscabral6d3dd602013-03-23 11:12:34 -0300121 if key in ['loss']:
122 value = float(value)
carlosmscabralf40ecd12013-02-01 18:15:58 -0200123 link_dict[key] = value
carlosmscabral6d3dd602013-03-23 11:12:34 -0300124
carlosmscabralf40ecd12013-02-01 18:15:58 -0200125 links.append(confCCNLink(h1,h2,link_dict))
carlosmscabral6d3dd602013-03-23 11:12:34 -0300126
127
carlosmscabralf40ecd12013-02-01 18:15:58 -0200128 return links
carlosmscabral6d3dd602013-03-23 11:12:34 -0300129
130
131