From bd4c0abac97ea3070dcfedbb567451d60220930e Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sun, 21 Nov 2021 23:25:59 +0000 Subject: [PATCH] move configuration under --configuration for decode and provide default config --- src/exabgp/application/decode.py | 22 ++++++++++++++++++++-- src/exabgp/application/server.py | 11 +++++++---- src/exabgp/application/validate.py | 5 +++-- src/exabgp/reactor/loop.py | 5 ++--- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/exabgp/application/decode.py b/src/exabgp/application/decode.py index 1336952cf..b4d583de0 100644 --- a/src/exabgp/application/decode.py +++ b/src/exabgp/application/decode.py @@ -5,6 +5,8 @@ import string import argparse +from exabgp.configuration.configuration import Configuration + from exabgp.debug import trace_interceptor from exabgp.environment import Env @@ -15,6 +17,18 @@ from exabgp.reactor.loop import Reactor from exabgp.logger import log +conf_all = """\ +neighbor 127.0.0.1 { + router-id 10.0.0.2; + local-address 127.0.0.1; + local-as 65533; + peer-as 65533; + + family { + all + } +} +""" def is_bgp(message): return all(c in string.hexdigits or c == ':' for c in message) @@ -25,7 +39,7 @@ def setargs(sub): sub.add_argument('-n', '--nlri', help='the data is only the NLRI', action='store_true') sub.add_argument('-d', '--debug', help='start the python debugger errors', action='store_true') sub.add_argument('-p', '--pdb', help='fire the debugger on fault', action='store_true') - sub.add_argument('configuration', help='configuration file(s)', type=str) + sub.add_argument('-c', '--configuration', help='configuration file(s)', type=str) sub.add_argument('payload', help='the BGP payload in hexadecimal', type=str) # fmt:on @@ -68,7 +82,11 @@ def cmdline(cmdarg): trace_interceptor(env.debug.pdb) sanitized = ''.join(cmdarg.payload).replace(':', '').replace(' ', '') - Reactor([getconf(cmdarg.configuration)]).check(sanitized, cmdarg.nlri) + if cmdarg.configuration: + configuration = Configuration([getconf(cmdarg.configuration)]) + else: + configuration = Configuration([conf_all], text=True) + Reactor(configuration).check(sanitized, cmdarg.nlri) if __name__ == '__main__': diff --git a/src/exabgp/application/server.py b/src/exabgp/application/server.py index 2fcc08c46..d4998c806 100755 --- a/src/exabgp/application/server.py +++ b/src/exabgp/application/server.py @@ -15,6 +15,7 @@ # import before the fork to improve copy on write memory savings from exabgp.reactor.loop import Reactor +from exabgp.configuration.configuration import Configuration from exabgp.util.dns import warn from exabgp.logger import log @@ -195,8 +196,10 @@ def run(comment, configurations, pid=0): log.info('to send commands %s%s.in' % (pipe, pipename), 'cli control') log.info('to read responses %s%s.out' % (pipe, pipename), 'cli control') + configuration = Configuration(configurations) + if not env.profile.enable: - exit_code = Reactor(configurations).run() + exit_code = Reactor(configuration).run() __exit(env.debug.memory, exit_code) try: @@ -205,7 +208,7 @@ def run(comment, configurations, pid=0): import profile if env.profile.file == 'stdout': - profiled = 'Reactor(%s).run()' % (str(configurations)) + profiled = 'Reactor(configuration).run()' exit_code = profile.run(profiled) __exit(env.debug.memory, exit_code) @@ -226,7 +229,7 @@ def run(comment, configurations, pid=0): profiler = profile.Profile() profiler.enable() try: - exit_code = Reactor(configurations).run() + exit_code = Reactor(configuration).run() except Exception: exit_code = Reactor.Exit.unknown raise @@ -249,7 +252,7 @@ def run(comment, configurations, pid=0): log.debug("-" * len(notice), 'reactor') log.debug(notice, 'reactor') log.debug("-" * len(notice), 'reactor') - Reactor(configurations).run() + Reactor(configuration).run() __exit(env.debug.memory, 1) diff --git a/src/exabgp/application/validate.py b/src/exabgp/application/validate.py index 6c13635fa..466380782 100644 --- a/src/exabgp/application/validate.py +++ b/src/exabgp/application/validate.py @@ -10,10 +10,11 @@ from exabgp.environment import getenv from exabgp.environment import getconf +from exabgp.configuration.configuration import Configuration + from exabgp.debug import trace_interceptor from exabgp.logger import log -from exabgp.reactor.loop import Reactor from exabgp.configuration.check import check_generation @@ -51,7 +52,7 @@ def cmdline(cmdarg): log.critical(f'{configuration} is not an exabgp config file', 'configuration') sys.exit(1) - config = Reactor([location]).configuration + config = Configuration([location]) if not config.reload(): log.critical(f'{configuration} is not a valid config file', 'configuration') diff --git a/src/exabgp/reactor/loop.py b/src/exabgp/reactor/loop.py index b67eadd71..799dae7f8 100644 --- a/src/exabgp/reactor/loop.py +++ b/src/exabgp/reactor/loop.py @@ -22,7 +22,6 @@ from exabgp.reactor.interrupt import Signal from exabgp.reactor.api import API -from exabgp.configuration.configuration import Configuration from exabgp.environment import getenv from exabgp.bgp.fsm import FSM @@ -51,7 +50,7 @@ class Exit(object): # [hex(ord(c)) for c in os.popen('clear').read()] clear = b''.join(bytes([int(c, 16)]) for c in ['0x1b', '0x5b', '0x48', '0x1b', '0x5b', '0x32', '0x4a']) - def __init__(self, configurations): + def __init__(self, configuration): self._ips = getenv().tcp.bind self._port = getenv().tcp.port self._stopping = getenv().tcp.once @@ -65,7 +64,7 @@ def __init__(self, configurations): self.processes = None - self.configuration = Configuration(configurations) + self.configuration = configuration self.asynchronous = ASYNC() self.signal = Signal() self.daemon = Daemon(self)