Remove more hard-coded stuff

This commit is contained in:
Wojciech Kozlowski 2019-04-07 11:16:23 +02:00
parent 228defd9f0
commit 71bc827fb2
2 changed files with 47 additions and 21 deletions

View File

@ -9,44 +9,54 @@ from mininet.cli import CLI
from util.router import Router
from util.experiment import Experiment
FRR_BIN_DIR = "/usr/lib/frr"
def start_daemon(node, daemon, conf_dir):
"""Start one FRR daemon on a given node.
"""
node.cmd("/usr/lib/frr/{daemon}"
node.cmd("{bin_dir}/{daemon}"
" -f {conf_dir}/{node_name}.conf"
" -d"
" -i /tmp/{node_name}-{daemon}.pid"
" > /tmp/{node_name}-{daemon}.out 2>&1"
.format(daemon=daemon, conf_dir=conf_dir, node_name=node.name))
.format(bin_dir=FRR_BIN_DIR,
daemon=daemon,
conf_dir=conf_dir,
node_name=node.name))
node.waitOutput()
def run(scenario):
"""Start a network scenario.
def clean():
"""Clean all state left over from a previous experiment.
"""
daemons = [
"zebra",
"staticd",
"isisd",
]
os.system("rm -f /tmp/R*.log /tmp/R*.pid /tmp/R*.out")
os.system("rm -f /tmp/h*.log /tmp/h*.pid /tmp/h*.out")
os.system("mn -c >/dev/null 2>&1")
os.system("killall -9 {} > /dev/null 2>&1".format(' '.join(daemons)))
os.system("killall -9 {} > /dev/null 2>&1"
.format(' '.join(os.listdir(FRR_BIN_DIR))))
net = Mininet(topo=scenario.topo(), switch=Router)
def run(experiment):
"""Start a network experiment.
"""
# Clean up any state from previous experiments.
clean()
# Start Mininet.
net = Mininet(topo=experiment.topo(), switch=Router)
net.start()
# WARNING: FRR can get confused unless all daemons on each node are started
# together.
for node in net.switches:
for daemon in daemons:
if node.name in getattr(scenario, daemon, set()):
conf_dir = getattr(scenario, "{}_conf".format(daemon))
for daemon in experiment.daemons:
if node.name in getattr(experiment, daemon, set()):
conf_dir = getattr(experiment, "{}_conf".format(daemon))
start_daemon(node, daemon, conf_dir)
if node.name.startswith('R'):
@ -60,18 +70,26 @@ def run(scenario):
CLI(net)
net.stop()
os.system("killall -9 {} > /dev/null 2>&1".format(' '.join(daemons)))
os.system("killall -9 {}".format(' '.join(experiment.daemons)))
if __name__ == "__main__":
def main():
"""Route 0 entry point.
"""
parser = argparse.ArgumentParser(
description='Launch a network scenario Mininet.')
description='Launch an FRR network experiment in Mininet.')
parser.add_argument('--topology', '-t', type=str, required=True,
help='the topology of the network')
parser.add_argument('--scenario', '-s', type=str, required=True,
help='the scenario to set up in the network')
ARGS = parser.parse_args()
args = parser.parse_args()
experiment = Experiment(ARGS.topology, ARGS.scenario)
experiment = Experiment(args.topology, args.scenario)
run(experiment)
if __name__ == "__main__":
main()

View File

@ -27,6 +27,9 @@ class Experiment(object):
.import_module('topology.{}.topo'.format(topology))
.NetTopo)
# Initialise list of daemons.
self.daemons = []
# Return now if the scenario is "plain".
if scenario == "plain":
return
@ -56,6 +59,11 @@ class Experiment(object):
# Each daemon entry should be a directory.
daemon_dir = os.path.join(parent_dir, daemon)
if os.path.exists(daemon_dir) and os.path.isdir(daemon_dir):
# Make sure zebra is always first on the list of daemons.
if daemon == "zebra":
self.daemons.insert(0, daemon)
else:
self.daemons.append(daemon)
setattr(self, daemon, set())
setattr(self, "{}_conf".format(daemon), daemon_dir)