#NEWLINE# def _cmp_by_router_id( local_asn , path1 , path2 ) : #NEWLINE# #INDENT# 'Select the route received from the peer with the lowest BGP router ID.\n\n    If both paths are eBGP paths, then we do not do any tie breaking, i.e we do\n    not pick best-path based on this criteria.\n    RFC: http://tools.ietf.org/html/rfc5004\n    We pick best path between two iBGP paths as usual.\n    ' #NEWLINE# def get_asn( path_source ) : #NEWLINE# #INDENT# if ( path_source is None ) : #NEWLINE# #INDENT# return local_asn #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return path_source . remote_as #NEWLINE# #UNINDENT# #UNINDENT# def get_router_id( path_source , local_bgp_id ) : #NEWLINE# #INDENT# if ( path_source is None ) : #NEWLINE# #INDENT# return local_bgp_id #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return path_source . protocol . recv_open_msg . bgp_identifier #NEWLINE# #UNINDENT# #UNINDENT# path_source1 = path1 . source #NEWLINE# path_source2 = path2 . source #NEWLINE# if ( ( path_source1 is None ) and ( path_source2 is None ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# asn1 = get_asn ( path_source1 ) #NEWLINE# asn2 = get_asn ( path_source2 ) #NEWLINE# is_ebgp1 = ( asn1 != local_asn ) #NEWLINE# is_ebgp2 = ( asn2 != local_asn ) #NEWLINE# if ( is_ebgp1 and is_ebgp2 ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# if ( ( ( is_ebgp1 is True ) and ( is_ebgp2 is False ) ) or ( ( is_ebgp1 is False ) and ( is_ebgp2 is True ) ) ) : #NEWLINE# #INDENT# raise ValueError ( 'This method does not support comparing ebgp with ibgp path' ) #NEWLINE# #UNINDENT# if ( path_source1 is not None ) : #NEWLINE# #INDENT# local_bgp_id = path_source1 . protocol . sent_open_msg . bgp_identifier #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# local_bgp_id = path_source2 . protocol . sent_open_msg . bgp_identifier #NEWLINE# #UNINDENT# router_id1 = get_router_id ( path_source1 , local_bgp_id ) #NEWLINE# router_id2 = get_router_id ( path_source2 , router_id2 ) #NEWLINE# if ( router_id1 == router_id2 ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# from ryu.services.protocols.bgp.utils.bgp import from_inet_ptoi #NEWLINE# if ( from_inet_ptoi ( router_id1 ) < from_inet_ptoi ( router_id2 ) ) : #NEWLINE# #INDENT# return path1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return path2