コード例 #1
0
ファイル: speaker.py プロジェクト: prashanthvarma/ryu
    def is_local_router_id_greater(self):
        """Compares *True* if local router id is greater when compared to peer
        bgp id.

        Should only be called after protocol has reached OpenConfirm state.
        """
        from ryu.services.protocols.bgp.utils.bgp import from_inet_ptoi

        if not self.state == BGP_FSM_OPEN_CONFIRM:
            raise BgpProtocolException(desc="Can access remote router id only" " after open message is received")
        remote_id = self.recv_open_msg.bgpid
        local_id = self.sent_open_msg.bgpid
        return from_inet_ptoi(local_id) > from_inet_ptoi(remote_id)
コード例 #2
0
ファイル: speaker.py プロジェクト: doup123/diplomas
    def is_local_router_id_greater(self):
        """Compares *True* if local router id is greater when compared to peer
        bgp id.

        Should only be called after protocol has reached OpenConfirm state.
        """
        from ryu.services.protocols.bgp.utils.bgp import from_inet_ptoi

        if not self.state == BGP_FSM_OPEN_CONFIRM:
            raise BgpProtocolException(desc='Can access remote router id only'
                                       ' after open message is received')
        remote_id = self.recv_open_msg.bgp_identifier
        local_id = self.sent_open_msg.bgp_identifier
        return from_inet_ptoi(local_id) > from_inet_ptoi(remote_id)
コード例 #3
0
ファイル: processor.py プロジェクト: MrCocoaCat/ryu
def _cmp_by_router_id(local_asn, path1, path2):
    """Select the route received from the peer with the lowest BGP router ID.

    If both paths are eBGP paths, then we do not do any tie breaking, i.e we do
    not pick best-path based on this criteria.
    RFC: http://tools.ietf.org/html/rfc5004
    We pick best path between two iBGP paths as usual.
    """
    def get_asn(path_source):
        if path_source is None:
            return local_asn
        else:
            return path_source.remote_as

    def get_router_id(path, local_bgp_id):
        path_source = path.source
        if path_source is None:
            return local_bgp_id
        else:
            originator_id = path.get_pattr(BGP_ATTR_TYPE_ORIGINATOR_ID)
            if originator_id:
                return originator_id.value
            return path_source.protocol.recv_open_msg.bgp_identifier

    path_source1 = path1.source
    path_source2 = path2.source

    # If both paths are from NC we have same router Id, hence cannot compare.
    if path_source1 is None and path_source2 is None:
        return None

    asn1 = get_asn(path_source1)
    asn2 = get_asn(path_source2)

    is_ebgp1 = asn1 != local_asn
    is_ebgp2 = asn2 != local_asn
    # If both paths are from eBGP peers, then according to RFC we need
    # not tie break using router id.
    if is_ebgp1 and is_ebgp2:
        return None

    if ((is_ebgp1 is True and is_ebgp2 is False)
            or (is_ebgp1 is False and is_ebgp2 is True)):
        raise ValueError('This method does not support comparing ebgp with'
                         ' ibgp path')

    # At least one path is not coming from NC, so we get local bgp id.
    if path_source1 is not None:
        local_bgp_id = path_source1.protocol.sent_open_msg.bgp_identifier
    else:
        local_bgp_id = path_source2.protocol.sent_open_msg.bgp_identifier

    # Get router ids.
    router_id1 = get_router_id(path1, local_bgp_id)
    router_id2 = get_router_id(path2, local_bgp_id)

    # If both router ids are same/equal we cannot decide.
    # This case is possible since router ids are arbitrary.
    if router_id1 == router_id2:
        return None

    # Select the path with lowest router Id.
    from ryu.services.protocols.bgp.utils.bgp import from_inet_ptoi
    if from_inet_ptoi(router_id1) < from_inet_ptoi(router_id2):
        return path1
    else:
        return path2
コード例 #4
0
ファイル: processor.py プロジェクト: 5g-empower/empower-ryu
def _cmp_by_router_id(local_asn, path1, path2):
    """Select the route received from the peer with the lowest BGP router ID.

    If both paths are eBGP paths, then we do not do any tie breaking, i.e we do
    not pick best-path based on this criteria.
    RFC: http://tools.ietf.org/html/rfc5004
    We pick best path between two iBGP paths as usual.
    """
    def get_asn(path_source):
        if path_source is None:
            return local_asn
        else:
            return path_source.remote_as

    def get_router_id(path, local_bgp_id):
        path_source = path.source
        if path_source is None:
            return local_bgp_id
        else:
            originator_id = path.get_pattr(BGP_ATTR_TYPE_ORIGINATOR_ID)
            if originator_id:
                return originator_id.value
            return path_source.protocol.recv_open_msg.bgp_identifier

    path_source1 = path1.source
    path_source2 = path2.source

    # If both paths are from NC we have same router Id, hence cannot compare.
    if path_source1 is None and path_source2 is None:
        return None

    asn1 = get_asn(path_source1)
    asn2 = get_asn(path_source2)

    is_ebgp1 = asn1 != local_asn
    is_ebgp2 = asn2 != local_asn
    # If both paths are from eBGP peers, then according to RFC we need
    # not tie break using router id.
    if is_ebgp1 and is_ebgp2:
        return None

    if ((is_ebgp1 is True and is_ebgp2 is False) or
            (is_ebgp1 is False and is_ebgp2 is True)):
        raise ValueError('This method does not support comparing ebgp with'
                         ' ibgp path')

    # At least one path is not coming from NC, so we get local bgp id.
    if path_source1 is not None:
        local_bgp_id = path_source1.protocol.sent_open_msg.bgp_identifier
    else:
        local_bgp_id = path_source2.protocol.sent_open_msg.bgp_identifier

    # Get router ids.
    router_id1 = get_router_id(path1, local_bgp_id)
    router_id2 = get_router_id(path2, local_bgp_id)

    # If both router ids are same/equal we cannot decide.
    # This case is possible since router ids are arbitrary.
    if router_id1 == router_id2:
        return None

    # Select the path with lowest router Id.
    from ryu.services.protocols.bgp.utils.bgp import from_inet_ptoi
    if from_inet_ptoi(router_id1) < from_inet_ptoi(router_id2):
        return path1
    else:
        return path2