blob: d8d8374d7dc35c2d11a5373ca95cfe04f19f4243 [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]
carlosmscabral3d060fc2013-07-18 13:18:09 -030056 elif re.match("mem",uri):
carlosmscabral7736b822013-07-21 14:40:31 -030057 mem = uri.split('=')[1]
carlosmscabral29432252013-02-04 11:54:16 -020058 else:
59 uri_list.append((uri.split(',')[0],uri.split(',')[1]))
carlosmscabral6d3dd602013-03-23 11:12:34 -030060
carlosmscabralb9d85b72013-07-15 15:24:33 -030061 hosts.append(confCCNHost(name , app, uri_list,cpu,cores,cache))
carlosmscabral6d3dd602013-03-23 11:12:34 -030062
carlosmscabralf40ecd12013-02-01 18:15:58 -020063 return hosts
64
carlosmscabral29432252013-02-04 11:54:16 -020065def parse_routers(conf_arq):
66 'Parse routers section from the conf file.'
carlosmscabralf40ecd12013-02-01 18:15:58 -020067 config = ConfigParser.RawConfigParser()
68 config.read(conf_arq)
69
70 routers = []
carlosmscabral6d3dd602013-03-23 11:12:34 -030071
carlosmscabralf40ecd12013-02-01 18:15:58 -020072 items = config.items('routers')
carlosmscabral6d3dd602013-03-23 11:12:34 -030073
carlosmscabralf40ecd12013-02-01 18:15:58 -020074 for item in items:
75 name = item[0]
carlosmscabral6d3dd602013-03-23 11:12:34 -030076
carlosmscabralf40ecd12013-02-01 18:15:58 -020077 rest = item[1].split()
78
79 uris = rest
80 uri_list=[]
carlosmscabral29432252013-02-04 11:54:16 -020081 cpu = None
carlosmscabrale121a7b2013-02-18 18:14:53 -030082 cores = None
carlosmscabral6d3dd602013-03-23 11:12:34 -030083
carlosmscabral29432252013-02-04 11:54:16 -020084 for uri in uris:
85 if re.match("cpu",uri):
86 cpu = float(uri.split('=')[1])
carlosmscabrale121a7b2013-02-18 18:14:53 -030087 elif re.match("cores",uri):
carlosmscabral6d3dd602013-03-23 11:12:34 -030088 cores = uri.split('=')[1]
carlosmscabral29432252013-02-04 11:54:16 -020089 else:
90 uri_list.append((uri.split(',')[0],uri.split(',')[1]))
carlosmscabral6d3dd602013-03-23 11:12:34 -030091
carlosmscabrale121a7b2013-02-18 18:14:53 -030092 routers.append(confCCNHost(name=name , uri_tuples=uri_list, cpu=cpu, cores=cores))
carlosmscabral6d3dd602013-03-23 11:12:34 -030093
carlosmscabralf40ecd12013-02-01 18:15:58 -020094 return routers
95
carlosmscabral29432252013-02-04 11:54:16 -020096def parse_links(conf_arq):
97 'Parse links section from the conf file.'
carlosmscabralf40ecd12013-02-01 18:15:58 -020098 arq = open(conf_arq,'r')
carlosmscabral6d3dd602013-03-23 11:12:34 -030099
carlosmscabralf40ecd12013-02-01 18:15:58 -0200100 links = []
carlosmscabral6d3dd602013-03-23 11:12:34 -0300101
carlosmscabralf40ecd12013-02-01 18:15:58 -0200102 while True:
103 line = arq.readline()
104 if line == '[links]\n':
105 break
carlosmscabral6d3dd602013-03-23 11:12:34 -0300106
carlosmscabralf40ecd12013-02-01 18:15:58 -0200107 while True:
108 line = arq.readline()
109 if line == '':
110 break
carlosmscabral6d3dd602013-03-23 11:12:34 -0300111
carlosmscabralf40ecd12013-02-01 18:15:58 -0200112 args = line.split()
113 h1, h2 = args.pop(0).split(':')
carlosmscabral6d3dd602013-03-23 11:12:34 -0300114
carlosmscabralf40ecd12013-02-01 18:15:58 -0200115 link_dict = {}
carlosmscabral6d3dd602013-03-23 11:12:34 -0300116
carlosmscabralf40ecd12013-02-01 18:15:58 -0200117 for arg in args:
118 arg_name, arg_value = arg.split('=')
119 key = arg_name
120 value = arg_value
carlosmscabral6d3dd602013-03-23 11:12:34 -0300121 if key in ['bw','jitter','max_queue_size']:
carlosmscabralf40ecd12013-02-01 18:15:58 -0200122 value = int(value)
carlosmscabral6d3dd602013-03-23 11:12:34 -0300123 if key in ['loss']:
124 value = float(value)
carlosmscabralf40ecd12013-02-01 18:15:58 -0200125 link_dict[key] = value
carlosmscabral6d3dd602013-03-23 11:12:34 -0300126
carlosmscabralf40ecd12013-02-01 18:15:58 -0200127 links.append(confCCNLink(h1,h2,link_dict))
carlosmscabral6d3dd602013-03-23 11:12:34 -0300128
129
carlosmscabralf40ecd12013-02-01 18:15:58 -0200130 return links
carlosmscabral6d3dd602013-03-23 11:12:34 -0300131
132
133