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 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 3 | class confNDNHost(): |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 4 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 5 | def __init__(self, name, app='', params='', 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 |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 8 | self.uri_tuples = params |
Ashlesh Gawande | 3a4afb1 | 2015-07-09 09:23:30 -0500 | [diff] [blame] | 9 | self.params = params |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 10 | self.cpu = cpu |
carlosmscabral | e121a7b | 2013-02-18 18:14:53 -0300 | [diff] [blame] | 11 | self.cores = cores |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 12 | self.cache = cache |
| 13 | |
| 14 | # For now assume leftovers are NLSR configuration parameters |
| 15 | self.nlsrParameters = params |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 16 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 17 | def __repr__(self): |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 18 | 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 |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 27 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 28 | class confNDNLink(): |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 29 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 30 | def __init__(self,h1,h2,linkDict=None): |
| 31 | self.h1 = h1 |
| 32 | self.h2 = h2 |
| 33 | self.linkDict = linkDict |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 34 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 35 | def __repr__(self): |
| 36 | return 'h1: ' + self.h1 + ' h2: ' + self.h2 + ' params: ' + str(self.linkDict) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 37 | |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 38 | def parse_hosts(conf_arq): |
| 39 | 'Parse hosts section from the conf file.' |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 40 | config = ConfigParser.RawConfigParser() |
| 41 | config.read(conf_arq) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 42 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 43 | hosts = [] |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 44 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 45 | items = config.items('nodes') |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 46 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 47 | #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 |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 57 | for item in items: |
| 58 | |
| 59 | name = item[0] |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 60 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 61 | rest = item[1].split() |
| 62 | |
| 63 | app = rest.pop(0) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 64 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 65 | uris = rest |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 66 | params = {} |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 67 | cpu = None |
carlosmscabral | e121a7b | 2013-02-18 18:14:53 -0300 | [diff] [blame] | 68 | cores = None |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 69 | cache = None |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 70 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 71 | for uri in uris: |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 72 | if re.match("cpu",uri): |
| 73 | cpu = float(uri.split('=')[1]) |
carlosmscabral | e121a7b | 2013-02-18 18:14:53 -0300 | [diff] [blame] | 74 | elif re.match("cores",uri): |
| 75 | cores = uri.split('=')[1] |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 76 | elif re.match("cache",uri): |
| 77 | cache = uri.split('=')[1] |
| 78 | elif re.match("mem",uri): |
| 79 | mem = uri.split('=')[1] |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 80 | else: |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 81 | params[uri.split('=')[0]] = uri.split('=')[1] |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 82 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 83 | hosts.append(confNDNHost(name, app, params, cpu, cores, cache)) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 84 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 85 | return hosts |
| 86 | |
carlosmscabral | 2943225 | 2013-02-04 11:54:16 -0200 | [diff] [blame] | 87 | def parse_links(conf_arq): |
| 88 | 'Parse links section from the conf file.' |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 89 | arq = open(conf_arq,'r') |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 90 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 91 | links = [] |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 92 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 93 | while True: |
| 94 | line = arq.readline() |
| 95 | if line == '[links]\n': |
| 96 | break |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 97 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 98 | while True: |
| 99 | line = arq.readline() |
| 100 | if line == '': |
| 101 | break |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 102 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 103 | args = line.split() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 104 | |
| 105 | #checks for non-empty line |
| 106 | if len(args) == 0: |
| 107 | continue |
Caio Elias | c6b5603 | 2014-09-19 14:12:48 -0300 | [diff] [blame] | 108 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 109 | h1, h2 = args.pop(0).split(':') |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 110 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 111 | link_dict = {} |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 112 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 113 | for arg in args: |
| 114 | arg_name, arg_value = arg.split('=') |
| 115 | key = arg_name |
| 116 | value = arg_value |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 117 | if key in ['bw','jitter','max_queue_size']: |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 118 | value = int(value) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 119 | if key in ['loss']: |
| 120 | value = float(value) |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 121 | link_dict[key] = value |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 122 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 123 | links.append(confNDNLink(h1,h2,link_dict)) |
carlosmscabral | 6d3dd60 | 2013-03-23 11:12:34 -0300 | [diff] [blame] | 124 | |
| 125 | |
carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 126 | return links |