carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 1 | import ConfigParser, re |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 2 | |
| 3 | class confCCNHost(): |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 4 | |
carlosmscabral | b9d85b7 | 2013-07-15 15:24:33 -0300 | [diff] [blame] | 5 | def __init__(self, name, app='', uri_tuples='', cpu=None, cores=None, cache=None): |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 6 | self.name = name |
| 7 | self.app = app |
| 8 | self.uri_tuples = uri_tuples |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 9 | self.cpu = cpu |
carlosmscabral | e121a7b | 2013-02-18 18:14:53 -0300 | [diff] [blame] | 10 | self.cores = cores |
carlosmscabral | b9d85b7 | 2013-07-15 15:24:33 -0300 | [diff] [blame] | 11 | self.cache = cache |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 12 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 13 | def __repr__(self): |
carlosmscabral | b9d85b7 | 2013-07-15 15:24:33 -0300 | [diff] [blame] | 14 | return 'Name: ' + self.name + ' App: ' + self.app + ' URIS: ' + str(self.uri_tuples) + ' CPU:' + str(self.cpu) + ' Cores:' +str(self.cores) + ' Cache: ' + str(self.cache) |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 15 | |
| 16 | class confCCNLink(): |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 17 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 18 | def __init__(self,h1,h2,linkDict=None): |
| 19 | self.h1 = h1 |
| 20 | self.h2 = h2 |
| 21 | self.linkDict = linkDict |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 22 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 23 | def __repr__(self): |
| 24 | return 'h1: ' + self.h1 + ' h2: ' + self.h2 + ' params: ' + str(self.linkDict) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 25 | |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 26 | def parse_hosts(conf_arq): |
| 27 | 'Parse hosts section from the conf file.' |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 28 | config = ConfigParser.RawConfigParser() |
| 29 | config.read(conf_arq) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 30 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 31 | hosts = [] |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 32 | |
carlosmscabral | b9d85b7 | 2013-07-15 15:24:33 -0300 | [diff] [blame] | 33 | items = config.items('nodes') |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 34 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 35 | for item in items: |
| 36 | |
| 37 | name = item[0] |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 38 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 39 | rest = item[1].split() |
| 40 | |
| 41 | app = rest.pop(0) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 42 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 43 | uris = rest |
| 44 | uri_list=[] |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 45 | cpu = None |
carlosmscabral | e121a7b | 2013-02-18 18:14:53 -0300 | [diff] [blame] | 46 | cores = None |
carlosmscabral | b9d85b7 | 2013-07-15 15:24:33 -0300 | [diff] [blame] | 47 | cache = None |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 48 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 49 | for uri in uris: |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 50 | if re.match("cpu",uri): |
| 51 | cpu = float(uri.split('=')[1]) |
carlosmscabral | e121a7b | 2013-02-18 18:14:53 -0300 | [diff] [blame] | 52 | elif re.match("cores",uri): |
| 53 | cores = uri.split('=')[1] |
carlosmscabral | b9d85b7 | 2013-07-15 15:24:33 -0300 | [diff] [blame] | 54 | elif re.match("cache",uri): |
| 55 | cache = uri.split('=')[1] |
carlosmscabral | 3d060fc | 2013-07-18 13:18:09 -0300 | [diff] [blame] | 56 | elif re.match("mem",uri): |
carlosmscabral | 7736b82 | 2013-07-21 14:40:31 -0300 | [diff] [blame] | 57 | mem = uri.split('=')[1] |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 58 | else: |
| 59 | uri_list.append((uri.split(',')[0],uri.split(',')[1])) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 60 | |
carlosmscabral | b9d85b7 | 2013-07-15 15:24:33 -0300 | [diff] [blame] | 61 | hosts.append(confCCNHost(name , app, uri_list,cpu,cores,cache)) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 62 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 63 | return hosts |
| 64 | |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 65 | def parse_routers(conf_arq): |
| 66 | 'Parse routers section from the conf file.' |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 67 | config = ConfigParser.RawConfigParser() |
| 68 | config.read(conf_arq) |
| 69 | |
| 70 | routers = [] |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 71 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 72 | items = config.items('routers') |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 73 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 74 | for item in items: |
| 75 | name = item[0] |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 76 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 77 | rest = item[1].split() |
| 78 | |
| 79 | uris = rest |
| 80 | uri_list=[] |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 81 | cpu = None |
carlosmscabral | e121a7b | 2013-02-18 18:14:53 -0300 | [diff] [blame] | 82 | cores = None |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 83 | |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 84 | for uri in uris: |
| 85 | if re.match("cpu",uri): |
| 86 | cpu = float(uri.split('=')[1]) |
carlosmscabral | e121a7b | 2013-02-18 18:14:53 -0300 | [diff] [blame] | 87 | elif re.match("cores",uri): |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 88 | cores = uri.split('=')[1] |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 89 | else: |
| 90 | uri_list.append((uri.split(',')[0],uri.split(',')[1])) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 91 | |
carlosmscabral | e121a7b | 2013-02-18 18:14:53 -0300 | [diff] [blame] | 92 | routers.append(confCCNHost(name=name , uri_tuples=uri_list, cpu=cpu, cores=cores)) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 93 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 94 | return routers |
| 95 | |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 96 | def parse_links(conf_arq): |
| 97 | 'Parse links section from the conf file.' |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 98 | arq = open(conf_arq,'r') |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 99 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 100 | links = [] |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 101 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 102 | while True: |
| 103 | line = arq.readline() |
| 104 | if line == '[links]\n': |
| 105 | break |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 106 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 107 | while True: |
| 108 | line = arq.readline() |
| 109 | if line == '': |
| 110 | break |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 111 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 112 | args = line.split() |
| 113 | h1, h2 = args.pop(0).split(':') |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 114 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 115 | link_dict = {} |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 116 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 117 | for arg in args: |
| 118 | arg_name, arg_value = arg.split('=') |
| 119 | key = arg_name |
| 120 | value = arg_value |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 121 | if key in ['bw','jitter','max_queue_size']: |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 122 | value = int(value) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 123 | if key in ['loss']: |
| 124 | value = float(value) |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 125 | link_dict[key] = value |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 126 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 127 | links.append(confCCNLink(h1,h2,link_dict)) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 128 | |
| 129 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 130 | return links |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 131 | |
| 132 | |
| 133 | |