diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2014-05-06 08:48:04 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-05-10 01:14:56 +0900 |
commit | 2430fc7c17fc999a9733aae134afcb3c0535b049 (patch) | |
tree | 0fa9123006f0299e8978a768587a19c3b4b40c55 | |
parent | e3a3c7dc0c5857a315bb158b30ce6eb3a69302f7 (diff) |
bgp: improve how to show rib
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
4 files changed, 21 insertions, 12 deletions
diff --git a/ryu/services/protocols/bgp/operator/commands/show/rib.py b/ryu/services/protocols/bgp/operator/commands/show/rib.py index 34d4a18a..94e16574 100644 --- a/ryu/services/protocols/bgp/operator/commands/show/rib.py +++ b/ryu/services/protocols/bgp/operator/commands/show/rib.py @@ -15,7 +15,7 @@ class RibBase(Command, RouteFormatterMixin): class Rib(RibBase): - help_msg = 'show all routes for address family (only vpnv4 supported)' + help_msg = 'show all routes for address family' param_help_msg = '<address-family>' command = 'rib' diff --git a/ryu/services/protocols/bgp/operator/commands/show/route_formatter_mixin.py b/ryu/services/protocols/bgp/operator/commands/show/route_formatter_mixin.py index 2f58f681..10c56e90 100644 --- a/ryu/services/protocols/bgp/operator/commands/show/route_formatter_mixin.py +++ b/ryu/services/protocols/bgp/operator/commands/show/route_formatter_mixin.py @@ -3,12 +3,14 @@ import StringIO class RouteFormatterMixin(object): + fmtstr = ' {0:<3s} {1:<32s} {2:<20s} {3:<15s} {4:<6s} {5:<6s} {6:<}\n' + @classmethod def _format_family_header(cls): ret = '' ret += ('Status codes: * valid, > best\n') - ret += ' {0:<3s} {1:<32s} {2:<20s} {3:<10s} {4:<20s} {5:<}\n'.format( - '', 'Network', 'Next Hop', 'Reason', 'Metric', 'Path') + ret += cls.fmtstr.format('', 'Network', 'Next Hop', 'Reason', 'Metric', + 'LocPrf', 'Path') return ret @classmethod @@ -24,6 +26,7 @@ class RouteFormatterMixin(object): bpr = path.get('bpr') next_hop = path.get('nexthop') med = path.get('metric') + localpref = path.get('localpref') # Construct path status string. path_status = '*' if is_best: @@ -35,10 +38,10 @@ class RouteFormatterMixin(object): prefix = path.get('prefix') # Append path info to String buffer. - buff.write( - ' {0:<3s} {1:<32s} {2:<20s} {3:<20s} {4:<10s} {5:<}\n'. - format(path_status, prefix, next_hop, bpr, str(med), - ' '.join(map(str, aspath)))) + buff.write(cls.fmtstr.format(path_status, prefix, + next_hop, bpr, str(med), + str(localpref), + ' '.join(map(str, aspath)))) for dist in dest_list: for idx, path in enumerate(dist.get('paths')): diff --git a/ryu/services/protocols/bgp/operator/internal_api.py b/ryu/services/protocols/bgp/operator/internal_api.py index c98ab69f..c3a420e2 100644 --- a/ryu/services/protocols/bgp/operator/internal_api.py +++ b/ryu/services/protocols/bgp/operator/internal_api.py @@ -10,6 +10,7 @@ from ryu.lib.packet.bgp import RF_RTC_UC from ryu.lib.packet.bgp import BGP_ATTR_TYPE_ORIGIN from ryu.lib.packet.bgp import BGP_ATTR_TYPE_AS_PATH from ryu.lib.packet.bgp import BGP_ATTR_TYPE_MULTI_EXIT_DISC +from ryu.lib.packet.bgp import BGP_ATTR_TYPE_LOCAL_PREF from ryu.lib.packet.bgp import BGP_ATTR_ORIGIN_IGP from ryu.lib.packet.bgp import BGP_ATTR_ORIGIN_EGP @@ -110,14 +111,13 @@ class InternalApi(object): else: aspath = '' - origin = path.get_pattr(BGP_ATTR_TYPE_ORIGIN).value + origin = path.get_pattr(BGP_ATTR_TYPE_ORIGIN) + origin = origin.value if origin else None if origin == BGP_ATTR_ORIGIN_IGP: origin = 'i' elif origin == BGP_ATTR_ORIGIN_EGP: origin = 'e' - else: - origin = None nexthop = path.nexthop.value # Get the MED path attribute @@ -125,13 +125,19 @@ class InternalApi(object): med = med.value if med else '' # Get best path reason bpr = dst.best_path_reason if path == dst.best_path else '' + + # Get local preference + localpref = path.get_pattr(BGP_ATTR_TYPE_LOCAL_PREF) + localpref = localpref.value if localpref else '' + return {'best': (path == dst.best_path), 'bpr': bpr, 'prefix': path.nlri.formatted_nlri_str, 'nexthop': nexthop, 'metric': med, 'aspath': aspath, - 'origin': origin} + 'origin': origin, + 'localpref': localpref} for path in dst.known_path_list: ret['paths'].append(_path_to_dict(dst, path)) diff --git a/ryu/services/protocols/bgp/processor.py b/ryu/services/protocols/bgp/processor.py index e56224de..a5fcbcce 100644 --- a/ryu/services/protocols/bgp/processor.py +++ b/ryu/services/protocols/bgp/processor.py @@ -161,7 +161,7 @@ BPR_UNKNOWN = 'Unknown' BPR_ONLY_PATH = 'Only Path' BPR_REACHABLE_NEXT_HOP = 'Reachable Next Hop' BPR_HIGHEST_WEIGHT = 'Highest Weight' -BPR_LOCAL_PREF = 'Local Pref.' +BPR_LOCAL_PREF = 'Local Pref' BPR_LOCAL_ORIGIN = 'Local Origin' BPR_ASPATH = 'AS Path' BPR_ORIGIN = 'Origin' |