Skip to content
Snippets Groups Projects
hcbf.py 1.09 KiB
Newer Older
  • Learn to ignore specific revisions
  • from .community import CommunityRouter
    
    class HCBFRouter(CommunityRouter):
        def __call__(self, packet):
            me = self.node
            dest = packet.destination
    
            if dest in me.links:
                return dest, 'direct', True
    
            if me.community is not dest.community and self.not_local_community:
                best, cbc = self.best_cbc(dest.community)
                if cbc > self.cbc(dest.community):
                    return best, 'cbc', True
    
            if self.local_community:
                if me.community is not dest.community:
                    best, ncf = self.best_ncf(dest.community)
                    if ncf > self.ncf(dest.community):
                        return best, 'ncf', True
                    elif ncf < self.ncf(dest.community):
                        return None, None, False
    
                best, ui = self.best_ui()
                if ui > self.ui():
                    return best, 'ui', True
                elif ui < self.ui():
                    return None, None, False
    
                best, lp = self.best_lp()
                if lp > self.lp():
                    return best, 'lp', True
    
            return None, None, False
    
    Jarrod Pas's avatar
    Jarrod Pas committed