#NEWLINE# def get_bgp_attr( args , params , m , attr ) : #NEWLINE# #INDENT# line = '' #NEWLINE# r = re . compile ( '([0-9]+)\\.([0-9]+)' ) #NEWLINE# if ( attr . type == BGP_ATTR_T [ 'ATOMIC_AGGREGATE' ] ) : #NEWLINE# #INDENT# line += ' atomic-aggregate' #NEWLINE# #UNINDENT# if ( attr . len == 0 ) : #NEWLINE# #INDENT# return line #NEWLINE# #UNINDENT# if ( attr . type == BGP_ATTR_T [ 'ORIGIN' ] ) : #NEWLINE# #INDENT# line += ( ' origin %s' % ORIGIN_T [ attr . origin ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'AS_PATH' ] ) : #NEWLINE# #INDENT# as_path = '' #NEWLINE# for path_seg in attr . as_path : #NEWLINE# #INDENT# if ( path_seg [ 'type' ] == AS_PATH_SEG_T [ 'AS_SET' ] ) : #NEWLINE# #INDENT# as_path += ( '(%s) ' % ' ' . join ( path_seg [ 'val' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# as_path += ( '%s ' % ' ' . join ( path_seg [ 'val' ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# line += ( ' as-path [%s]' % as_path ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'NEXT_HOP' ] ) : #NEWLINE# #INDENT# params [ 'next_hop' ] = ( args . next_hop if args . next_hop else attr . next_hop ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'MULTI_EXIT_DISC' ] ) : #NEWLINE# #INDENT# line += ( ' med %d' % attr . med ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'LOCAL_PREF' ] ) : #NEWLINE# #INDENT# line += ( ' local-preference %d' % attr . local_pref ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'AGGREGATOR' ] ) : #NEWLINE# #INDENT# asn = attr . aggr [ 'asn' ] #NEWLINE# m = r . search ( asn ) #NEWLINE# if ( m is not None ) : #NEWLINE# #INDENT# asn = ( ( int ( m . group ( 1 ) ) * 65536 ) + int ( m . group ( 2 ) ) ) #NEWLINE# #UNINDENT# line += ( ' aggregator (%s:%s)' % ( str ( asn ) , attr . aggr [ 'id' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'COMMUNITY' ] ) : #NEWLINE# #INDENT# comm = ' ' . join ( attr . comm ) #NEWLINE# line += ( ' community [%s]' % comm ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'ORIGINATOR_ID' ] ) : #NEWLINE# #INDENT# line += ( ' originator-id %s' % attr . org_id ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'CLUSTER_LIST' ] ) : #NEWLINE# #INDENT# line += ( ' cluster-list [%s]' % ' ' . join ( attr . cl_list ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'MP_REACH_NLRI' ] ) : #NEWLINE# #INDENT# params [ 'next_hop' ] = attr . mp_reach [ 'next_hop' ] [ 0 ] #NEWLINE# if ( m . type == MRT_T [ 'TABLE_DUMP_V2' ] ) : #NEWLINE# #INDENT# if ( ( m . subtype == TD_V2_ST [ 'RIB_IPV4_UNICAST' ] ) and args . next_hop ) : #NEWLINE# #INDENT# params [ 'next_hop' ] = args . next_hop #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( m . subtype == TD_V2_ST [ 'RIB_IPV6_UNICAST' ] ) and args . next_hop6 ) : #NEWLINE# #INDENT# params [ 'next_hop' ] = args . next_hop6 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( m . type == MRT_T [ 'TABLE_DUMP' ] ) : #NEWLINE# #INDENT# if ( ( m . subtype == TD_ST [ 'AFI_IPv4' ] ) and args . next_hop ) : #NEWLINE# #INDENT# params [ 'next_hop' ] = args . next_hop #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( m . subtype == TD_ST [ 'AFI_IPv6' ] ) and args . next_hop6 ) : #NEWLINE# #INDENT# params [ 'next_hop' ] = args . next_hop6 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( m . type == MRT_T [ 'BGP4MP' ] ) or ( m . type == MRT_T [ 'BGP4MP_ET' ] ) ) : #NEWLINE# #INDENT# if ( ( attr . mp_reach [ 'afi' ] == AFI_T [ 'IPv4' ] ) and ( params [ 'flags' ] & FLAG_T [ 'IPv4' ] ) ) : #NEWLINE# #INDENT# if args . next_hop : #NEWLINE# #INDENT# params [ 'next_hop' ] = args . next_hop #NEWLINE# #UNINDENT# if ( 'nlri' in attr . mp_reach ) : #NEWLINE# #INDENT# params [ 'mp_nlri' ] = attr . mp_reach [ 'nlri' ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( attr . mp_reach [ 'afi' ] == AFI_T [ 'IPv6' ] ) and ( params [ 'flags' ] & FLAG_T [ 'IPv6' ] ) ) : #NEWLINE# #INDENT# if args . next_hop6 : #NEWLINE# #INDENT# params [ 'next_hop' ] = args . next_hop6 #NEWLINE# #UNINDENT# if ( 'nlri' in attr . mp_reach ) : #NEWLINE# #INDENT# params [ 'mp_nlri' ] = attr . mp_reach [ 'nlri' ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'MP_UNREACH_NLRI' ] ) : #NEWLINE# #INDENT# if ( ( m . type == MRT_T [ 'BGP4MP' ] ) or ( m . type == MRT_T [ 'BGP4MP_ET' ] ) ) : #NEWLINE# #INDENT# if ( ( attr . mp_unreach [ 'afi' ] == AFI_T [ 'IPv4' ] ) and ( params [ 'flags' ] & FLAG_T [ 'IPv4' ] ) ) : #NEWLINE# #INDENT# if ( 'withdrawn' in attr . mp_unreach ) : #NEWLINE# #INDENT# params [ 'mp_withdrawn' ] = attr . mp_unreach [ 'withdrawn' ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( attr . mp_unreach [ 'afi' ] == AFI_T [ 'IPv6' ] ) and ( params [ 'flags' ] & FLAG_T [ 'IPv6' ] ) ) : #NEWLINE# #INDENT# if ( 'withdrawn' in attr . mp_unreach ) : #NEWLINE# #INDENT# params [ 'mp_withdrawn' ] = attr . mp_unreach [ 'withdrawn' ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'EXTENDED_COMMUNITIES' ] ) : #NEWLINE# #INDENT# ext_comm_list = [ ] #NEWLINE# for ext_comm in attr . ext_comm : #NEWLINE# #INDENT# ext_comm_list . append ( ( '0x%016x' % ext_comm ) ) #NEWLINE# #UNINDENT# line += ( ' extended-community [%s]' % ' ' . join ( ext_comm_list ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'AS4_PATH' ] ) : #NEWLINE# #INDENT# as4_path = '' #NEWLINE# for path_seg in attr . as4_path : #NEWLINE# #INDENT# if ( path_seg [ 'type' ] == AS_PATH_SEG_T [ 'AS_SET' ] ) : #NEWLINE# #INDENT# as4_path += ( '(%s) ' % ' ' . join ( path_seg [ 'val' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# as4_path += ( '%s ' % ' ' . join ( path_seg [ 'val' ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# line += ( ' as4-path [%s]' % as4_path ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'AS4_AGGREGATOR' ] ) : #NEWLINE# #INDENT# asn = attr . as4_aggr [ 'asn' ] #NEWLINE# m = r . search ( asn ) #NEWLINE# if ( m is not None ) : #NEWLINE# #INDENT# asn = ( ( int ( m . group ( 1 ) ) * 65536 ) + int ( m . group ( 2 ) ) ) #NEWLINE# #UNINDENT# line += ( ' as4-aggregator (%s:%s)' % ( str ( asn ) , attr . as4_aggr [ 'id' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( attr . type == BGP_ATTR_T [ 'AIGP' ] ) : #NEWLINE# #INDENT# line += ( ' aigp %d' % attr . aigp [ 0 ] [ 'val' ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return line