Included CPULimitedCCNHost parsing
diff --git a/conf_parser.py b/conf_parser.py
deleted file mode 100644
index 68792ac..0000000
--- a/conf_parser.py
+++ /dev/null
@@ -1,108 +0,0 @@
-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
-
-
-
diff --git a/miniccnx b/miniccnx
index 99ff449..edbbb17 100644
--- a/miniccnx
+++ b/miniccnx
@@ -2,12 +2,11 @@
from mininet.topo import Topo
from mininet.net import Mininet
-from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel, output, info
from mininet.cli import CLI
from mininet.node import CPULimitedCCNHost, CCNHost
from mininet.link import TCLink
-from conf_parser import extrai_hosts,extrai_routers, extrai_links
+from mininet.conf_parser import parse_hosts,parse_routers, parse_links
import os.path
import optparse
import datetime
@@ -34,17 +33,22 @@
def __init__(self, conf_arq, **opts):
Topo.__init__(self, **opts)
- hosts_conf = extrai_hosts(conf_arq)
- routers_conf = extrai_routers(conf_arq)
- links_conf = extrai_links(conf_arq)
+ hosts_conf = parse_hosts(conf_arq)
+ routers_conf = parse_routers(conf_arq)
+ links_conf = parse_links(conf_arq)
self.isTCLink = False
+ self.isLimited = False
for host in hosts_conf:
- self.addHost(host.name, app=host.app, fib=host.uri_tuples,cpu=.025)
+ if host.cpu != None and self.isLimited != True:
+ self.isLimited = True
+ self.addHost(host.name, app=host.app, fib=host.uri_tuples,cpu=host.cpu)
for router in routers_conf:
- self.addHost(router.name,fib=router.uri_tuples)
+ if router.cpu != None and self.isLimited != True:
+ self.isLimited = True
+ self.addHost(router.name,fib=router.uri_tuples,cpu=router.cpu)
for link in links_conf:
if len(link.linkDict) == 0:
@@ -69,8 +73,12 @@
t = datetime.datetime.now()
- if topo.isTCLink == True:
+ if topo.isTCLink == True and topo.isLimited == True:
net = Mininet(topo,host=CPULimitedCCNHost,link=TCLink)
+ elif topo.isTCLink == True and topo.isLimited == False:
+ net = Mininet(topo,host=CCNHost,link=TCLink)
+ elif topo.isTCLink == False and topo.isLimited == True:
+ net = Mininet(topo,host=CPULimitedCCNHost)
else:
net = Mininet(topo,host=CCNHost)
diff --git a/mininet/conf_parser.py b/mininet/conf_parser.py
index 68792ac..642b4b1 100644
--- a/mininet/conf_parser.py
+++ b/mininet/conf_parser.py
@@ -1,14 +1,15 @@
-import ConfigParser
+import ConfigParser, re
class confCCNHost():
- def __init__(self, name, app='', uri_tuples=''):
+ def __init__(self, name, app='', uri_tuples='', cpu=None):
self.name = name
self.app = app
self.uri_tuples = uri_tuples
+ self.cpu = cpu
def __repr__(self):
- return 'Name: ' + self.name + ' App: ' + self.app + ' URIS: ' + str(self.uri_tuples)
+ return 'Name: ' + self.name + ' App: ' + self.app + ' URIS: ' + str(self.uri_tuples) + ' CPU:' + str(self.cpu)
class confCCNLink():
@@ -20,8 +21,8 @@
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'
+def parse_hosts(conf_arq):
+ 'Parse hosts section from the conf file.'
config = ConfigParser.RawConfigParser()
config.read(conf_arq)
@@ -39,15 +40,19 @@
uris = rest
uri_list=[]
+ cpu = None
for uri in uris:
- uri_list.append((uri.split(',')[0],uri.split(',')[1]))
+ if re.match("cpu",uri):
+ cpu = float(uri.split('=')[1])
+ else:
+ uri_list.append((uri.split(',')[0],uri.split(',')[1]))
- hosts.append(confCCNHost(name , app, uri_list))
+ hosts.append(confCCNHost(name , app, uri_list,cpu))
return hosts
-def extrai_routers(conf_arq):
- 'Extrai routers da secao routers do arquivo de configuracao'
+def parse_routers(conf_arq):
+ 'Parse routers section from the conf file.'
config = ConfigParser.RawConfigParser()
config.read(conf_arq)
@@ -62,15 +67,20 @@
uris = rest
uri_list=[]
- for uri in uris:
- uri_list.append((uri.split(',')[0],uri.split(',')[1]))
+ cpu = None
- routers.append(confCCNHost(name=name , uri_tuples=uri_list))
+ for uri in uris:
+ if re.match("cpu",uri):
+ cpu = float(uri.split('=')[1])
+ else:
+ uri_list.append((uri.split(',')[0],uri.split(',')[1]))
+
+ routers.append(confCCNHost(name=name , uri_tuples=uri_list, cpu=cpu))
return routers
-def extrai_links(conf_arq):
- 'Extrai links da secao links do arquivo de configuracao'
+def parse_links(conf_arq):
+ 'Parse links section from the conf file.'
arq = open(conf_arq,'r')
links = []
diff --git a/mininet/node.py b/mininet/node.py
index 4c54d75..99d2cc5 100644
--- a/mininet/node.py
+++ b/mininet/node.py
@@ -798,7 +798,6 @@
r = CPULimitedHost.config(self,cpu,cores, **params)
- print 'nozess'
self.setParam( r, 'app', fib=fib )
self.setParam( r, 'fib', app=app)