mirror of
https://github.com/Wojtek242/route0.git
synced 2024-11-22 07:05:25 +01:00
Remove more hard-coded stuff
This commit is contained in:
parent
228defd9f0
commit
71bc827fb2
60
route-0.py
60
route-0.py
@ -9,44 +9,54 @@ from mininet.cli import CLI
|
|||||||
from util.router import Router
|
from util.router import Router
|
||||||
from util.experiment import Experiment
|
from util.experiment import Experiment
|
||||||
|
|
||||||
|
FRR_BIN_DIR = "/usr/lib/frr"
|
||||||
|
|
||||||
|
|
||||||
def start_daemon(node, daemon, conf_dir):
|
def start_daemon(node, daemon, conf_dir):
|
||||||
"""Start one FRR daemon on a given node.
|
"""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"
|
" -f {conf_dir}/{node_name}.conf"
|
||||||
" -d"
|
" -d"
|
||||||
" -i /tmp/{node_name}-{daemon}.pid"
|
" -i /tmp/{node_name}-{daemon}.pid"
|
||||||
" > /tmp/{node_name}-{daemon}.out 2>&1"
|
" > /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()
|
node.waitOutput()
|
||||||
|
|
||||||
|
|
||||||
def run(scenario):
|
def clean():
|
||||||
"""Start a network scenario.
|
"""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/R*.log /tmp/R*.pid /tmp/R*.out")
|
||||||
os.system("rm -f /tmp/h*.log /tmp/h*.pid /tmp/h*.out")
|
os.system("rm -f /tmp/h*.log /tmp/h*.pid /tmp/h*.out")
|
||||||
os.system("mn -c >/dev/null 2>&1")
|
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()
|
net.start()
|
||||||
|
|
||||||
# WARNING: FRR can get confused unless all daemons on each node are started
|
# WARNING: FRR can get confused unless all daemons on each node are started
|
||||||
# together.
|
# together.
|
||||||
for node in net.switches:
|
for node in net.switches:
|
||||||
for daemon in daemons:
|
for daemon in experiment.daemons:
|
||||||
if node.name in getattr(scenario, daemon, set()):
|
if node.name in getattr(experiment, daemon, set()):
|
||||||
conf_dir = getattr(scenario, "{}_conf".format(daemon))
|
conf_dir = getattr(experiment, "{}_conf".format(daemon))
|
||||||
start_daemon(node, daemon, conf_dir)
|
start_daemon(node, daemon, conf_dir)
|
||||||
|
|
||||||
if node.name.startswith('R'):
|
if node.name.startswith('R'):
|
||||||
@ -60,18 +70,26 @@ def run(scenario):
|
|||||||
|
|
||||||
CLI(net)
|
CLI(net)
|
||||||
net.stop()
|
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(
|
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,
|
parser.add_argument('--topology', '-t', type=str, required=True,
|
||||||
help='the topology of the network')
|
help='the topology of the network')
|
||||||
parser.add_argument('--scenario', '-s', type=str, required=True,
|
parser.add_argument('--scenario', '-s', type=str, required=True,
|
||||||
help='the scenario to set up in the network')
|
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)
|
run(experiment)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
@ -27,6 +27,9 @@ class Experiment(object):
|
|||||||
.import_module('topology.{}.topo'.format(topology))
|
.import_module('topology.{}.topo'.format(topology))
|
||||||
.NetTopo)
|
.NetTopo)
|
||||||
|
|
||||||
|
# Initialise list of daemons.
|
||||||
|
self.daemons = []
|
||||||
|
|
||||||
# Return now if the scenario is "plain".
|
# Return now if the scenario is "plain".
|
||||||
if scenario == "plain":
|
if scenario == "plain":
|
||||||
return
|
return
|
||||||
@ -56,6 +59,11 @@ class Experiment(object):
|
|||||||
# Each daemon entry should be a directory.
|
# Each daemon entry should be a directory.
|
||||||
daemon_dir = os.path.join(parent_dir, daemon)
|
daemon_dir = os.path.join(parent_dir, daemon)
|
||||||
if os.path.exists(daemon_dir) and os.path.isdir(daemon_dir):
|
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, daemon, set())
|
||||||
setattr(self, "{}_conf".format(daemon), daemon_dir)
|
setattr(self, "{}_conf".format(daemon), daemon_dir)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user