Skip to content

Commit

Permalink
move configuration under --configuration for decode and provide defau…
Browse files Browse the repository at this point in the history
…lt config
  • Loading branch information
thomas-mangin committed Nov 21, 2021
1 parent 19d68c2 commit bd4c0ab
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
22 changes: 20 additions & 2 deletions src/exabgp/application/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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__':
Expand Down
11 changes: 7 additions & 4 deletions src/exabgp/application/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)


Expand Down
5 changes: 3 additions & 2 deletions src/exabgp/application/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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')
Expand Down
5 changes: 2 additions & 3 deletions src/exabgp/reactor/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit bd4c0ab

Please sign in to comment.