Allow for creation of net object without topology and mixed topology fixes

refs: #5160, #5162

Change-Id: I54c2be3a9b4ee152057a8c4f1b52c9abd7b1a2a1
This commit is contained in:
Alex Lane committed 2021-05-14 14:48:59 -05:00
1 parent 0ed7772f3f
commit 407c5f0ef3
2 files changed
+40 -30

No files matched your search

+24 -15
View File
@@ -53,11 +53,13 @@ class Minindn(object):
workDir = '/tmp/minindn'
resultDir = None
def __init__(self, parser=argparse.ArgumentParser(), topo=None, topoFile=None, **mininetParams):
def __init__(self, parser=argparse.ArgumentParser(), topo=None, topoFile=None, noTopo=False, link=TCLink, **mininetParams):
"""Create MiniNDN object
parser: Parent parser of Mini-NDN parser
topo: Mininet topo object (optional)
topoFile: Mininet topology file location (optional)
noTopo: Allows specification of topology after network object is initialized (optional)
link: Allows specification of default Mininet link type for connections between nodes (optional)
mininetParams: Any params to pass to Mininet
"""
self.parser = Minindn.parseArgs(parser)
@@ -72,7 +74,7 @@ class Minindn(object):
else:
self.topoFile = topoFile
if topo is None:
if topo is None and not noTopo:
try:
info('Using topology file {}\n'.format(self.topoFile))
self.topo = self.processTopo(self.topoFile)
@@ -82,16 +84,12 @@ class Minindn(object):
else:
self.topo = topo
self.net = Mininet(topo=self.topo, link=TCLink, **mininetParams)
if not noTopo:
self.net = Mininet(topo=self.topo, link=link, **mininetParams)
else:
self.net = Mininet(link=link, **mininetParams)
for host in self.net.hosts:
if 'params' not in host.params:
host.params['params'] = {}
homeDir = '{}/{}'.format(Minindn.workDir, host.name)
host.params['params']['homeDir'] = homeDir
host.cmd('mkdir -p {}'.format(homeDir))
host.cmd('export HOME={} && cd ~'.format(homeDir))
self.initParams(self.net.hosts)
self.cleanups = []
@@ -102,10 +100,10 @@ class Minindn(object):
process = Popen(['ndnsec-get-default', '-k'], stdout=PIPE, stderr=PIPE)
output, error = process.communicate()
if process.returncode == 0:
Minindn.ndnSecurityDisabled = '/dummy/KEY/-%9C%28r%B8%AA%3B%60' in output
info('Dummy key chain patch is installed in ndn-cxx. Security will be disabled.\n')
Minindn.ndnSecurityDisabled = '/dummy/KEY/-%9C%28r%B8%AA%3B%60' in output
info('Dummy key chain patch is installed in ndn-cxx. Security will be disabled.\n')
else:
debug(error)
debug(error)
except:
pass
@@ -239,4 +237,15 @@ class Minindn(object):
'Utility method to perform cleanup steps and exit after catching exception'
Minindn.cleanUp()
info(format_exc())
exit(1)
exit(1)
def initParams(self, nodes):
'''Initialize Mini-NDN parameters for array of nodes'''
for host in nodes:
if 'params' not in host.params:
host.params['params'] = {}
host.params['params']['workDir'] = Minindn.workDir
homeDir = '{}/{}'.format(Minindn.workDir, host.name)
host.params['params']['homeDir'] = homeDir
host.cmd('mkdir -p {}'.format(homeDir))
host.cmd('export HOME={} && cd ~'.format(homeDir))
+16 -15
View File
@@ -42,12 +42,14 @@ from mn_wifi.link import WirelessLink
from minindn.minindn import Minindn
class MinindnWifi(Minindn):
""" Class for handling default args, Mininet object and home directories """
def __init__(self, parser=argparse.ArgumentParser(), topo=None, topoFile=None, **mininetParams):
""" Class for handling default args, Mininet-wifi object and home directories """
def __init__(self, parser=argparse.ArgumentParser(), topo=None, topoFile=None, noTopo=False, link=WirelessLink, **mininetParams):
"""Create Mini-NDN-Wifi object
parser: Parent parser of Mini-NDN-Wifi parser (use to specify experiment arguments)
topo: Mininet topo object (optional)
topoFile: topology file location (optional)
noTopo: Allows specification of topology after network object is initialized (optional)
link: Allows specification of default Mininet/Mininet-Wifi link type for connections between nodes (optional)
mininetParams: Any params to pass to Mininet-WiFi
"""
self.parser = self.parseArgs(parser)
@@ -63,7 +65,7 @@ class MinindnWifi(Minindn):
else:
self.topoFile = topoFile
if topo is None:
if topo is None and not noTopo:
try:
info('Using topology file {}\n'.format(self.topoFile))
self.topo = self.processTopo(self.topoFile)
@@ -73,24 +75,23 @@ class MinindnWifi(Minindn):
else:
self.topo = topo
self.net = Mininet_wifi(topo=self.topo, ifb=self.args.ifb, link=WirelessLink, **mininetParams)
if not noTopo:
self.net = Mininet_wifi(topo=self.topo, ifb=self.args.ifb, link=link, **mininetParams)
else:
self.net = Mininet_wifi(ifb=self.args.ifb, link=link, **mininetParams)
# Prevents crashes running mixed topos
nodes = self.net.stations + self.net.hosts + self.net.cars
self.initParams(nodes)
for host in self.net.stations:
if 'params' not in host.params:
host.params['params'] = {}
host.params['params']['workDir'] = Minindn.workDir
homeDir = "{}/{}".format(Minindn.workDir, host.name)
host.params['params']['homeDir'] = homeDir
debug(host.cmd("mkdir -p {}".format(homeDir)))
debug(host.cmd('export HOME={} && cd ~'.format(homeDir)))
try:
process = Popen(['ndnsec-get-default', '-k'], stdout=PIPE, stderr=PIPE)
output, error = process.communicate()
if process.returncode == 0:
Minindn.ndnSecurityDisabled = '/dummy/KEY/-%9C%28r%B8%AA%3B%60' in output
info('Dummy key chain patch is installed in ndn-cxx. Security will be disabled.\n')
Minindn.ndnSecurityDisabled = '/dummy/KEY/-%9C%28r%B8%AA%3B%60' in output
info('Dummy key chain patch is installed in ndn-cxx. Security will be disabled.\n')
else:
debug(error)
debug(error)
except:
pass