blob: 68792acfe3a32efcf5b4145fdf78d86359d7b567 [file] [log] [blame]
carlosmscabralf40ecd12013-02-01 18:15:58 -02001import ConfigParser
2
3class confCCNHost():
4
5 def __init__(self, name, app='', uri_tuples=''):
6 self.name = name
7 self.app = app
8 self.uri_tuples = uri_tuples
9
10 def __repr__(self):
11 return 'Name: ' + self.name + ' App: ' + self.app + ' URIS: ' + str(self.uri_tuples)
12
13class confCCNLink():
14
15 def __init__(self,h1,h2,linkDict=None):
16 self.h1 = h1
17 self.h2 = h2
18 self.linkDict = linkDict
19
20 def __repr__(self):
21 return 'h1: ' + self.h1 + ' h2: ' + self.h2 + ' params: ' + str(self.linkDict)
22
23def extrai_hosts(conf_arq):
24 'Extrai hosts da secao hosts do arquivo de configuracao'
25 config = ConfigParser.RawConfigParser()
26 config.read(conf_arq)
27
28 hosts = []
29
30 items = config.items('hosts')
31
32 for item in items:
33
34 name = item[0]
35
36 rest = item[1].split()
37
38 app = rest.pop(0)
39
40 uris = rest
41 uri_list=[]
42 for uri in uris:
43 uri_list.append((uri.split(',')[0],uri.split(',')[1]))
44
45 hosts.append(confCCNHost(name , app, uri_list))
46
47 return hosts
48
49def extrai_routers(conf_arq):
50 'Extrai routers da secao routers do arquivo de configuracao'
51 config = ConfigParser.RawConfigParser()
52 config.read(conf_arq)
53
54 routers = []
55
56 items = config.items('routers')
57
58 for item in items:
59 name = item[0]
60
61 rest = item[1].split()
62
63 uris = rest
64 uri_list=[]
65 for uri in uris:
66 uri_list.append((uri.split(',')[0],uri.split(',')[1]))
67
68 routers.append(confCCNHost(name=name , uri_tuples=uri_list))
69
70 return routers
71
72def extrai_links(conf_arq):
73 'Extrai links da secao links do arquivo de configuracao'
74 arq = open(conf_arq,'r')
75
76 links = []
77
78 while True:
79 line = arq.readline()
80 if line == '[links]\n':
81 break
82
83 while True:
84 line = arq.readline()
85 if line == '':
86 break
87
88 args = line.split()
89 h1, h2 = args.pop(0).split(':')
90
91 link_dict = {}
92
93 for arg in args:
94 arg_name, arg_value = arg.split('=')
95 key = arg_name
96 value = arg_value
97 if key in ['loss','bw','jitter']:
98 value = int(value)
99
100 link_dict[key] = value
101
102 links.append(confCCNLink(h1,h2,link_dict))
103
104
105 return links
106
107
108