#NEWLINE# def _cmp_by_origin( path1 , path2 ) : #NEWLINE# #INDENT# 'Select the best path based on origin attribute.\n\n    IGP is preferred over EGP; EGP is preferred over Incomplete.\n    If both paths have same origin, we return None.\n    ' #NEWLINE# def get_origin_pref( origin ) : #NEWLINE# #INDENT# if ( origin . value == BGP_ATTR_ORIGIN_IGP ) : #NEWLINE# #INDENT# return 3 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( origin . value == BGP_ATTR_ORIGIN_EGP ) : #NEWLINE# #INDENT# return 2 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( origin . value == BGP_ATTR_ORIGIN_INCOMPLETE ) : #NEWLINE# #INDENT# return 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# LOG . error ( 'Invalid origin value encountered %s.' , origin ) #NEWLINE# return 0 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# origin1 = path1 . get_pattr ( BGP_ATTR_TYPE_ORIGIN ) #NEWLINE# origin2 = path2 . get_pattr ( BGP_ATTR_TYPE_ORIGIN ) #NEWLINE# assert ( ( origin1 is not None ) and ( origin2 is not None ) ) #NEWLINE# if ( origin1 . value == origin2 . value ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# origin1 = get_origin_pref ( origin1 ) #NEWLINE# origin2 = get_origin_pref ( origin2 ) #NEWLINE# if ( origin1 == origin2 ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( origin1 > origin2 ) : #NEWLINE# #INDENT# return path1 #NEWLINE# #UNINDENT# #UNINDENT# return path2