1 from __future__ import absolute_import
3 from ryu.services.protocols.bgp.base import ActivityException
4 from ryu.services.protocols.bgp.operator.command import Command
5 from ryu.services.protocols.bgp.operator.command import CommandsResponse
6 from ryu.services.protocols.bgp.operator.command import STATUS_ERROR
7 from ryu.services.protocols.bgp.operator.command import STATUS_OK
8 from ryu.services.protocols.bgp.operator.commands.responses import (
10 from .route_formatter_mixin import RouteFormatterMixin
13 class RibBase(Command, RouteFormatterMixin):
14 supported_families = [
30 help_msg = 'show all routes for address family'
31 param_help_msg = '<address-family>'
34 def __init__(self, *args, **kwargs):
35 super(Rib, self).__init__(*args, **kwargs)
39 def action(self, params):
40 if len(params) != 1 or params[0] not in self.supported_families:
41 return WrongParamResp()
42 from ryu.services.protocols.bgp.operator.internal_api \
43 import WrongParamError
45 return CommandsResponse(
47 self.api.get_single_rib_routes(params[0])
49 except WrongParamError as e:
50 return WrongParamResp(e)
53 def cli_resp_formatter(cls, resp):
54 if resp.status == STATUS_ERROR:
55 return RibBase.cli_resp_formatter(resp)
56 return cls._format_family_header() + cls._format_family(resp.value)
59 help_msg = 'show routes for all RIBs'
62 def action(self, params):
64 return WrongParamResp()
67 for family in self.supported_families:
68 ret[family] = self.api.get_single_rib_routes(family)
69 return CommandsResponse(STATUS_OK, ret)
70 except ActivityException as e:
71 return CommandsResponse(STATUS_ERROR, e)
74 def cli_resp_formatter(cls, resp):
75 if resp.status == STATUS_ERROR:
76 return RibBase.cli_resp_formatter(resp)
77 ret = cls._format_family_header()
78 for family, data in resp.value.items():
79 ret += 'Family: {0}\n'.format(family)
80 ret += cls._format_family(data)