First commit
diff --git a/conf_parser.py b/conf_parser.py
new file mode 100644
index 0000000..68792ac
--- /dev/null
+++ b/conf_parser.py
@@ -0,0 +1,108 @@
+import ConfigParser
+
+class confCCNHost():
+
+ def __init__(self, name, app='', uri_tuples=''):
+ self.name = name
+ self.app = app
+ self.uri_tuples = uri_tuples
+
+ def __repr__(self):
+ return 'Name: ' + self.name + ' App: ' + self.app + ' URIS: ' + str(self.uri_tuples)
+
+class confCCNLink():
+
+ def __init__(self,h1,h2,linkDict=None):
+ self.h1 = h1
+ self.h2 = h2
+ self.linkDict = linkDict
+
+ def __repr__(self):
+ return 'h1: ' + self.h1 + ' h2: ' + self.h2 + ' params: ' + str(self.linkDict)
+
+def extrai_hosts(conf_arq):
+ 'Extrai hosts da secao hosts do arquivo de configuracao'
+ config = ConfigParser.RawConfigParser()
+ config.read(conf_arq)
+
+ hosts = []
+
+ items = config.items('hosts')
+
+ for item in items:
+
+ name = item[0]
+
+ rest = item[1].split()
+
+ app = rest.pop(0)
+
+ uris = rest
+ uri_list=[]
+ for uri in uris:
+ uri_list.append((uri.split(',')[0],uri.split(',')[1]))
+
+ hosts.append(confCCNHost(name , app, uri_list))
+
+ return hosts
+
+def extrai_routers(conf_arq):
+ 'Extrai routers da secao routers do arquivo de configuracao'
+ config = ConfigParser.RawConfigParser()
+ config.read(conf_arq)
+
+ routers = []
+
+ items = config.items('routers')
+
+ for item in items:
+ name = item[0]
+
+ rest = item[1].split()
+
+ uris = rest
+ uri_list=[]
+ for uri in uris:
+ uri_list.append((uri.split(',')[0],uri.split(',')[1]))
+
+ routers.append(confCCNHost(name=name , uri_tuples=uri_list))
+
+ return routers
+
+def extrai_links(conf_arq):
+ 'Extrai links da secao links do arquivo de configuracao'
+ arq = open(conf_arq,'r')
+
+ links = []
+
+ while True:
+ line = arq.readline()
+ if line == '[links]\n':
+ break
+
+ while True:
+ line = arq.readline()
+ if line == '':
+ break
+
+ args = line.split()
+ h1, h2 = args.pop(0).split(':')
+
+ link_dict = {}
+
+ for arg in args:
+ arg_name, arg_value = arg.split('=')
+ key = arg_name
+ value = arg_value
+ if key in ['loss','bw','jitter']:
+ value = int(value)
+
+ link_dict[key] = value
+
+ links.append(confCCNLink(h1,h2,link_dict))
+
+
+ return links
+
+
+