From 407c5f0ef34bfddb4ac2cb3c876858272b429d23 Mon Sep 17 00:00:00 2001 From: Alex Lane Date: Tue, 9 Mar 2021 22:13:23 -0600 Subject: [PATCH] Allow for creation of net object without topology and mixed topology fixes refs: #5160, #5162 Change-Id: I54c2be3a9b4ee152057a8c4f1b52c9abd7b1a2a1 --- minindn/minindn.py | 39 +++++++++++++++++++++++-------------- minindn/wifi/minindnwifi.py | 31 +++++++++++++++-------------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/minindn/minindn.py b/minindn/minindn.py index 8bdec13..d6eaffc 100644 --- a/minindn/minindn.py +++ b/minindn/minindn.py @@ -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) \ No newline at end of file + 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)) \ No newline at end of file diff --git a/minindn/wifi/minindnwifi.py b/minindn/wifi/minindnwifi.py index b2ca7f4..d1ab0a9 100644 --- a/minindn/wifi/minindnwifi.py +++ b/minindn/wifi/minindnwifi.py @@ -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