diff --git a/debug/debug_frr.py b/debug/debug_frr.py new file mode 100644 index 0000000000..a75f9e82dc --- /dev/null +++ b/debug/debug_frr.py @@ -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) diff --git a/debug/debug_quagga.py b/debug/debug_quagga.py new file mode 100644 index 0000000000..189737f86b --- /dev/null +++ b/debug/debug_quagga.py @@ -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) diff --git a/debug/main.py b/debug/main.py index 1b3a6dfc25..472198f624 100755 --- a/debug/main.py +++ b/debug/main.py @@ -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')) @@ -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() diff --git a/undebug/main.py b/undebug/main.py index 0203d10d22..5ec384991b 100644 --- a/undebug/main.py +++ b/undebug/main.py @@ -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')) @@ -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() diff --git a/undebug/undebug_frr.py b/undebug/undebug_frr.py new file mode 100644 index 0000000000..f6beb6a60c --- /dev/null +++ b/undebug/undebug_frr.py @@ -0,0 +1,124 @@ +import click +from debug.main import * + + +############################################################################### +# +# 'undebug bgp' cli stanza +# +############################################################################### + + +@cli.group(cls=AliasedGroup, default_if_no_args=False) +def bgp(): + """undebug bgp events """ + pass + +@bgp.command() +def as4(): + """undebug bgp AS4 actions """ + command = 'sudo vtysh -c "no debug bgp as4"' + run_command(command) + +@bgp.command() +def bestpath(): + """undebug bgp bestpath """ + command = 'sudo vtysh -c "no debug bgp bestpath"' + run_command(command) + +@bgp.command() +def keepalives(): + """undebug bgp keepalives """ + command = 'sudo vtysh -c "no debug bgp keepalives"' + run_command(command) + +@bgp.command() +def neighborEvents(): + """undebug bgp neighbor events """ + command = 'sudo vtysh -c "no debug bgp neighbor-events"' + run_command(command) + +@bgp.command() +def nht(): + """undebug bgp nexthop tracking events """ + command = 'sudo vtysh -c "no debug bgp nht"' + run_command(command) + +@bgp.command() +def updateGroups(): + """undebug bgp update-group events """ + command = 'sudo vtysh -c "no debug bgp update-groups"' + run_command(command) + +@bgp.command() +def updates(): + """undebug bgp updates """ + command = 'sudo vtysh -c "no debug bgp updates"' + run_command(command) + +@bgp.command() +def zebra(): + """undebug bgp zebra messages """ + command = 'sudo vtysh -c "no debug bgp zebra"' + run_command(command) + + +############################################################################### +# +# 'undebug zebra' cli stanza +# +############################################################################### + + +@cli.group(cls=AliasedGroup, default_if_no_args=False) +def zebra(): + """undebug zebra events """ + pass + +@zebra.command() +def events(): + """undebug zebra events """ + command = 'sudo vtysh -c "no debug zebra events"' + run_command(command) + +@zebra.command() +def fpm(): + """undebug zebra fpm events """ + command = 'sudo vtysh -c "no debug zebra fpm"' + run_command(command) + +@zebra.command() +def kernel(): + """undebug zebra's kernel-interface events """ + command = 'sudo vtysh -c "no debug zebra kernel"' + run_command(command) + +@zebra.command() +def mpls(): + """undebug zebra MPLS events """ + command = 'sudo vtysh -c "no debug zebra mpls"' + run_command(command) + +@zebra.command() +def nht(): + """undebug zebra next-hop-tracking events """ + command = 'sudo vtysh -c "no debug zebra nht"' + run_command(command) + +@zebra.command() +def packet(): + """undebug zebra packets """ + command = 'sudo vtysh -c "no debug zebra packet"' + run_command(command) + +@zebra.command() +def pseudowires(): + """undebug zebra pseudowire events """ + command = 'sudo vtysh -c "no debug zebra pseudowires"' + run_command(command) + +@zebra.command() +def rib(): + """undebug zebra RIB events """ + command = 'sudo vtysh -c "no debug zebra rib"' + run_command(command) diff --git a/undebug/undebug_quagga.py b/undebug/undebug_quagga.py new file mode 100644 index 0000000000..9a0d703867 --- /dev/null +++ b/undebug/undebug_quagga.py @@ -0,0 +1,100 @@ +import click +from undebug.main import * + + +############################################################################### +# +# 'undebug bgp' cli stanza +# +############################################################################### + + +@cli.group(cls=AliasedGroup, default_if_no_args=False) +def bgp(): + """undebug bgp events """ + pass + +@bgp.command() +def as4(): + """undebug bgp AS4 actions """ + command = 'sudo vtysh -c "no debug bgp as4"' + run_command(command) + +@bgp.command() +def events(): + """undebug bgp events """ + command = 'sudo vtysh -c "no debug bgp events"' + run_command(command) + +@bgp.command() +def filters(): + """undebug bgp filters """ + command = 'sudo vtysh -c "no debug bgp filters"' + run_command(command) + +@bgp.command() +def fsm(): + """undebug bgp fsm """ + command = 'sudo vtysh -c "no debug bgp fsm"' + run_command(command) + +@bgp.command() +def keepalives(): + """undebug bgp keepalives """ + command = 'sudo vtysh -c "no debug bgp keepalives"' + run_command(command) + +@bgp.command() +def updates(): + """undebug bgp updates """ + command = 'sudo vtysh -c "no debug bgp updates"' + run_command(command) + +@bgp.command() +def zebra(): + """undebug bgp zebra messages """ + command = 'sudo vtysh -c "no debug bgp zebra"' + run_command(command) + + +############################################################################### +# +# 'undebug zebra' cli stanza +# +############################################################################### + + +@cli.group(cls=AliasedGroup, default_if_no_args=False) +def zebra(): + """undebug zebra events """ + pass + +@zebra.command() +def events(): + """undebug zebra events """ + command = 'sudo vtysh -c "no debug zebra events"' + run_command(command) + +@zebra.command() +def fpm(): + """undebug zebra fpm events """ + command = 'sudo vtysh -c "no debug zebra fpm"' + run_command(command) + +@zebra.command() +def kernel(): + """undebug zebra's kernel-interface events """ + command = 'sudo vtysh -c "no debug zebra kernel"' + run_command(command) + +@zebra.command() +def packet(): + """undebug zebra packets """ + command = 'sudo vtysh -c "no debug zebra packet"' + run_command(command) + +@zebra.command() +def rib(): + """undebug zebra RIB events """ + command = 'sudo vtysh -c "no debug zebra rib"' + run_command(command)