Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions debug/debug_frr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import click
from debug.main import *


###############################################################################
#
# 'debug bgp' cli stanza
#
###############################################################################


@cli.group(cls=AliasedGroup, default_if_no_args=False)
def bgp():
"""debug bgp events """
pass

@bgp.command()
def as4():
"""debug bgp AS4 actions """
command = 'sudo vtysh -c "debug bgp as4"'
run_command(command)

@bgp.command()
def bestpath():
"""debug bgp bestpath """
command = 'sudo vtysh -c "debug bgp bestpath"'
run_command(command)

@bgp.command()
def keepalives():
"""debug bgp keepalives """
command = 'sudo vtysh -c "debug bgp keepalives"'
run_command(command)

@bgp.command()
def neighborEvents():
"""debug bgp neighbor events """
command = 'sudo vtysh -c "debug bgp neighbor-events"'
run_command(command)

@bgp.command()
def nht():
"""debug bgp nexthop tracking events """
command = 'sudo vtysh -c "debug bgp nht"'
run_command(command)

@bgp.command()
def updateGroups():
"""debug bgp update-group events """
command = 'sudo vtysh -c "debug bgp update-groups"'
run_command(command)

@bgp.command()
def updates():
"""debug bgp updates """
command = 'sudo vtysh -c "debug bgp updates"'
run_command(command)

@bgp.command()
def zebra():
"""debug bgp zebra messages """
command = 'sudo vtysh -c "debug bgp zebra"'
run_command(command)


###############################################################################
#
# 'debug zebra' cli stanza
#
###############################################################################


@cli.group(cls=AliasedGroup, default_if_no_args=False)
def zebra():
"""debug zebra events """
pass

@zebra.command()
def events():
"""debug zebra events """
command = 'sudo vtysh -c "debug zebra events"'
run_command(command)

@zebra.command()
def fpm():
"""debug zebra fpm events """
command = 'sudo vtysh -c "debug zebra fpm"'
run_command(command)

@zebra.command()
def kernel():
"""debug zebra's kernel-interface events """
command = 'sudo vtysh -c "debug zebra kernel"'
run_command(command)

@zebra.command()
def mpls():
"""debug zebra MPLS events """
command = 'sudo vtysh -c "debug zebra mpls"'
run_command(command)

@zebra.command()
def nht():
"""debug zebra next-hop-tracking events """
command = 'sudo vtysh -c "debug zebra nht"'
run_command(command)

@zebra.command()
def packet():
"""debug zebra packets """
command = 'sudo vtysh -c "debug zebra packet"'
run_command(command)

@zebra.command()
def pseudowires():
"""debug zebra pseudowire events """
command = 'sudo vtysh -c "debug zebra pseudowires"'
run_command(command)

@zebra.command()
def rib():
"""debug zebra RIB events """
command = 'sudo vtysh -c "debug zebra rib"'
run_command(command)
100 changes: 100 additions & 0 deletions debug/debug_quagga.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import click
from debug.main import *


###############################################################################
#
# 'debug bgp' cli stanza
#
###############################################################################


@cli.group(cls=AliasedGroup, default_if_no_args=False)
def bgp():
"""debug bgp events """
pass

@bgp.command()
def as4():
"""debug bgp AS4 actions """
command = 'sudo vtysh -c "debug bgp as4"'
run_command(command)

@bgp.command()
def events():
"""debug bgp events """
command = 'sudo vtysh -c "debug bgp events"'
run_command(command)

@bgp.command()
def filters():
"""debug bgp filters """
command = 'sudo vtysh -c "debug bgp filters"'
run_command(command)

@bgp.command()
def fsm():
"""debug bgp fsm """
command = 'sudo vtysh -c "debug bgp fsm"'
run_command(command)

@bgp.command()
def keepalives():
"""debug bgp keepalives """
command = 'sudo vtysh -c "debug bgp keepalives"'
run_command(command)

@bgp.command()
def updates():
"""debug bgp updates """
command = 'sudo vtysh -c "debug bgp updates"'
run_command(command)

@bgp.command()
def zebra():
"""debug bgp zebra messages """
command = 'sudo vtysh -c "debug bgp zebra"'
run_command(command)


###############################################################################
#
# 'debug zebra' cli stanza
#
###############################################################################


@cli.group(cls=AliasedGroup, default_if_no_args=False)
def zebra():
"""debug zebra events """
pass

@zebra.command()
def events():
"""debug zebra events """
command = 'sudo vtysh -c "debug zebra events"'
run_command(command)

@zebra.command()
def fpm():
"""debug zebra fpm events """
command = 'sudo vtysh -c "debug zebra fpm"'
run_command(command)

@zebra.command()
def kernel():
"""debug zebra's kernel-interface events """
command = 'sudo vtysh -c "debug zebra kernel"'
run_command(command)

@zebra.command()
def packet():
"""debug zebra packets """
command = 'sudo vtysh -c "debug zebra packet"'
run_command(command)

@zebra.command()
def rib():
"""debug zebra RIB events """
command = 'sudo vtysh -c "debug zebra rib"'
run_command(command)
69 changes: 48 additions & 21 deletions debug/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ def get_command(self, ctx, cmd_name):
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))


# To be enhanced. Routing-stack information should be collected from a global
# location (configdb?), so that we prevent the continous execution of this
# bash oneliner. To be revisited once routing-stack info is tracked somewhere.
def get_routing_stack():
command = "sudo docker ps | grep bgp | awk '{print$2}' | cut -d'-' -f3 | cut -d':' -f1"

try:
proc = subprocess.Popen(command,
stdout=subprocess.PIPE,
shell=True,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
result = stdout.rstrip('\n')

except OSError, e:
raise OSError("Cannot detect routing-stack")

return (result)


# Global Routing-Stack variable
routing_stack = get_routing_stack()


def run_command(command, pager=False):
if pager is True:
click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green'))
Expand All @@ -102,31 +127,33 @@ def cli():
"""SONiC command line - 'debug' command"""
pass

#
# 'bgp' group ###
#

@cli.group(cls=AliasedGroup, default_if_no_args=True)
def bgp():
"""debug bgp on """
pass

@bgp.command(default=True)
def default():
command = 'sudo vtysh -c "debug bgp"'
@cli.command()
def enable():
"""enable debugging for routing events """
command = 'sudo vtysh -c "configure terminal" -c "log syslog debugging"'
run_command(command)

@bgp.command()
def events():
"""debug bgp events on """
command = 'sudo vtysh -c "debug bgp events"'
@cli.command()
def disable():
"""disable debugging for routing events """
command = 'sudo vtysh -c "configure terminal" -c "no log syslog debugging"'
run_command(command)

@bgp.command()
def updates():
"""debug bgp events on """
command = 'sudo vtysh -c "debug bgp updates"'
run_command(command)
#
# Inserting 'debug' functionality into cli's parse-chain.
# Debugging commands are determined by the routing-stack being elected.
#
if routing_stack == "quagga":
from .debug_quagga import bgp
cli.add_command(bgp)
from .debug_quagga import zebra
cli.add_command(zebra)
elif routing_stack == "frr":
from .debug_frr import bgp
cli.add_command(bgp)
from .debug_frr import zebra
cli.add_command(zebra)


if __name__ == '__main__':
cli()
61 changes: 37 additions & 24 deletions undebug/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@ def get_command(self, ctx, cmd_name):
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))


# To be enhanced. Routing-stack information should be collected from a global
# location (configdb?), so that we prevent the continous execution of this
# bash oneliner. To be revisited once routing-stack info is tracked somewhere.
def get_routing_stack():
command = "sudo docker ps | grep bgp | awk '{print$2}' | cut -d'-' -f3 | cut -d':' -f1"

try:
proc = subprocess.Popen(command,
stdout=subprocess.PIPE,
shell=True,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
result = stdout.rstrip('\n')

except OSError, e:
raise OSError("Cannot detect routing-stack")

return (result)


# Global Routing-Stack variable
routing_stack = get_routing_stack()


def run_command(command, pager=False):
if pager is True:
click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green'))
Expand All @@ -99,33 +124,21 @@ def cli():
"""SONiC command line - 'undebug' command"""
pass


#
# 'bgp' group ###
# Inserting 'undebug' functionality into cli's parse-chain.
# Undebugging commands are determined by the routing-stack being elected.
#
if routing_stack == "quagga":
from .undebug_quagga import bgp
cli.add_command(bgp)
from .undebug_quagga import zebra
cli.add_command(zebra)
elif routing_stack == "frr":
from .undebug_frr import bgp
cli.add_command(bgp)
from .undebug_frr import zebra
cli.add_command(zebra)

# This allows us to add commands to both cli and ip groups, allowing for
@cli.group(cls=AliasedGroup, default_if_no_args=True)
def bgp():
"""undebug bgp on """
pass

@bgp.command(default=True)
def default():
command = 'sudo vtysh -c "undebug bgp"'
run_command(command)

@bgp.command()
def events():
"""undebug bgp events on """
command = 'sudo vtysh -c "undebug bgp events"'
run_command(command)

@bgp.command()
def updates():
"""undebug bgp events on """
command = 'sudo vtysh -c "undebug bgp updates"'
run_command(command)

if __name__ == '__main__':
cli()
Loading