def _validate_open_msg(self, open_msg):
        """Validates BGP OPEN message according from application context.

        Parsing modules takes care of validating OPEN message that need no
        context. But here we validate it according to current application
        settings. RTC or RR/ERR are MUST capability if peer does not support
        either one of them we have to end session.
        """
        assert open_msg.type == BGP_MSG_OPEN

        opt_param_cap_map = open_msg.opt_param_cap_map

        # Validate remote AS number.
        remote_as = open_msg.my_as
        # Try to get AS number from Four-Octet AS number capability.
        cap4as = opt_param_cap_map.get(BGP_CAP_FOUR_OCTET_AS_NUMBER, None)
        if cap4as is None:
            if remote_as == AS_TRANS:
                # Raise Bad Peer AS error message, if my_as is AS_TRANS
                # and without Four-Octet AS number capability.
                raise bgp.BadPeerAs()
            self.cap_four_octet_as_number = False
        else:
            # Note: Even if the peer has Four-Octet AS number capability,
            # keep the local capability setting
            remote_as = cap4as.as_number
            self.cap_four_octet_as_number = True
        #  Validate remote AS number with local setting.
        if remote_as != self._peer.remote_as:
            raise bgp.BadPeerAs()

        # Validate bgp version number.
        if open_msg.version != BGP_VERSION_NUM:
            raise bgp.UnsupportedVersion(BGP_VERSION_NUM)
def _validate_open_msg ( self , open_msg ) : assert open_msg . type == BGP_MSG_OPEN opt_param_cap_map = open_msg . opt_param_cap_map remote_as = open_msg . my_as cap4as = opt_param_cap_map . get ( BGP_CAP_FOUR_OCTET_AS_NUMBER , None ) if cap4as is None : if remote_as == AS_TRANS : raise bgp . BadPeerAs ( ) self . cap_four_octet_as_number = False else : remote_as = cap4as . as_number self . cap_four_octet_as_number = True if remote_as != self . _peer . remote_as : raise bgp . BadPeerAs ( ) if open_msg . version != BGP_VERSION_NUM : raise bgp . UnsupportedVersion ( BGP_VERSION_NUM )
Validates BGP OPEN message according from application context.

        Parsing modules takes care of validating OPEN message that need no
        context. But here we validate it according to current application
        settings. RTC or RR/ERR are MUST capability if peer does not support
        either one of them we have to end session.