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 | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 56 | else: |
| 57 | uri_list.append((uri.split(',')[0],uri.split(',')[1])) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 58 | |
carlosmscabral | b9d85b7 | 2013-07-15 15:24:33 -0300 | [diff] [blame^] | 59 | hosts.append(confCCNHost(name , app, uri_list,cpu,cores,cache)) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 60 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 61 | return hosts |
| 62 | |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 63 | def parse_routers(conf_arq): |
| 64 | 'Parse routers section from the conf file.' |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 65 | config = ConfigParser.RawConfigParser() |
| 66 | config.read(conf_arq) |
| 67 | |
| 68 | routers = [] |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 69 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 70 | items = config.items('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 | for item in items: |
| 73 | name = item[0] |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 74 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 75 | rest = item[1].split() |
| 76 | |
| 77 | uris = rest |
| 78 | uri_list=[] |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 79 | cpu = None |
carlosmscabral | e121a7b | 2013-02-18 18:14:53 -0300 | [diff] [blame] | 80 | cores = None |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 81 | |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 82 | for uri in uris: |
| 83 | if re.match("cpu",uri): |
| 84 | cpu = float(uri.split('=')[1]) |
carlosmscabral | e121a7b | 2013-02-18 18:14:53 -0300 | [diff] [blame] | 85 | elif re.match("cores",uri): |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 86 | cores = uri.split('=')[1] |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 87 | else: |
| 88 | uri_list.append((uri.split(',')[0],uri.split(',')[1])) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 89 | |
carlosmscabral | e121a7b | 2013-02-18 18:14:53 -0300 | [diff] [blame] | 90 | routers.append(confCCNHost(name=name , uri_tuples=uri_list, cpu=cpu, cores=cores)) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 91 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 92 | return routers |
| 93 | |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 94 | def parse_links(conf_arq): |
| 95 | 'Parse links section from the conf file.' |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 96 | arq = open(conf_arq,'r') |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 97 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 98 | links = [] |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 99 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 100 | while True: |
| 101 | line = arq.readline() |
| 102 | if line == '[links]\n': |
| 103 | break |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 104 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 105 | while True: |
| 106 | line = arq.readline() |
| 107 | if line == '': |
| 108 | break |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 109 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 110 | args = line.split() |
| 111 | h1, h2 = args.pop(0).split(':') |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 112 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 113 | link_dict = {} |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 114 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 115 | for arg in args: |
| 116 | arg_name, arg_value = arg.split('=') |
| 117 | key = arg_name |
| 118 | value = arg_value |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 119 | if key in ['bw','jitter','max_queue_size']: |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 120 | value = int(value) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 121 | if key in ['loss']: |
| 122 | value = float(value) |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 123 | link_dict[key] = value |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 124 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 125 | links.append(confCCNLink(h1,h2,link_dict)) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 126 | |
| 127 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 128 | return links |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 129 | |
| 130 | |
| 131 | |