Exemplo n.º 1
0
    def add_bgp_peer(self,
                     speaker_as,
                     peer_ip,
                     peer_as,
                     auth_type='none',
                     password=None):
        curr_speaker = self.cache.get_bgp_speaker(speaker_as)
        if not curr_speaker:
            raise bgp_driver_exc.BgpSpeakerNotAdded(local_as=speaker_as,
                                                    rtid=self.routerid)

        # Validate peer_ip and peer_as.
        utils.validate_as_num('remote_as', peer_as)
        utils.validate_string(peer_ip)
        utils.validate_auth(auth_type, password)

        # Notify Ryu about BGP Peer addition
        curr_speaker.neighbor_add(address=peer_ip,
                                  remote_as=peer_as,
                                  password=password,
                                  connect_mode=CONNECT_MODE_ACTIVE)
        LOG.info(
            _LI('Added BGP Peer %(peer)s for remote_as=%(as)d to '
                'BGP Speaker running for local_as=%(local_as)d.'), {
                    'peer': peer_ip,
                    'as': peer_as,
                    'local_as': speaker_as
                })
 def test_validate_as_num_with_string_as_num(self):
     with self.assertRaisesRegex(
             bgp_driver_exc.InvalidParamType, EXC_INV_PARAMTYPE % {
                 'param': 'local_as',
                 'param_type': 'integer'
             }):
         bgp_driver_utils.validate_as_num('local_as', '64512')
Exemplo n.º 3
0
    def add_bgp_speaker(self, speaker_as):
        curr_speaker = self.cache.get_bgp_speaker(speaker_as)
        if curr_speaker is not None:
            raise bgp_driver_exc.BgpSpeakerAlreadyScheduled(
                current_as=speaker_as, rtid=self.routerid)

        # Ryu can only support One speaker
        if self.cache.get_hosted_bgp_speakers_count() == 1:
            raise bgp_driver_exc.BgpSpeakerMaxScheduled(count=1)

        # Validate input parameters.
        # speaker_as must be an integer in the allowed range.
        utils.validate_as_num('local_as', speaker_as)

        # Notify Ryu about BGP Speaker addition.
        # Please note: Since, only the route-advertisement support is
        # implemented we are explicitly setting the bgp_server_port
        # attribute to 0 which disables listening on port 179.
        curr_speaker = bgpspeaker.BGPSpeaker(
            as_number=speaker_as,
            router_id=self.routerid,
            bgp_server_port=0,
            best_path_change_handler=best_path_change_cb,
            peer_down_handler=bgp_peer_down_cb,
            peer_up_handler=bgp_peer_up_cb)
        LOG.info(
            _LI('Added BGP Speaker for local_as=%(as)d with '
                'router_id= %(rtid)s.'), {
                    'as': speaker_as,
                    'rtid': self.routerid
                })

        self.cache.put_bgp_speaker(speaker_as, curr_speaker)
Exemplo n.º 4
0
    def add_bgp_speaker(self, speaker_as):
        curr_speaker = self.cache.get_bgp_speaker(speaker_as)
        if curr_speaker is not None:
            raise bgp_driver_exc.BgpSpeakerAlreadyScheduled(
                current_as=speaker_as, rtid=self.routerid)

        # Ryu can only support One speaker
        if self.cache.get_hosted_bgp_speakers_count() == 1:
            raise bgp_driver_exc.BgpSpeakerMaxScheduled(count=1)

        # Validate input parameters.
        # speaker_as must be an integer in the allowed range.
        utils.validate_as_num('local_as', speaker_as)

        # Notify Ryu about BGP Speaker addition.
        curr_speaker = bgpspeaker.BGPSpeaker(
            as_number=speaker_as,
            router_id=self.routerid,
            bgp_server_port=179,
            best_path_change_handler=self.best_path_change_cb,
            peer_down_handler=self.bgp_peer_down_cb,
            peer_up_handler=self.bgp_peer_up_cb)
        LOG.info(
            _LI('Added BGP Speaker for local_as=%(as)d with '
                'router_id= %(rtid)s.'), {
                    'as': speaker_as,
                    'rtid': self.routerid
                })

        self.cache.put_bgp_speaker(speaker_as, curr_speaker)
Exemplo n.º 5
0
    def add_bgp_speaker(self, speaker_as):
        curr_speaker = self.cache.get_bgp_speaker(speaker_as)
        if curr_speaker is not None:
            raise bgp_driver_exc.BgpSpeakerAlreadyScheduled(
                                                    current_as=speaker_as,
                                                    rtid=self.routerid)

        # Ryu can only support One speaker
        if self.cache.get_hosted_bgp_speakers_count() == 1:
            raise bgp_driver_exc.BgpSpeakerMaxScheduled(count=1)

        # Validate input parameters.
        # speaker_as must be an integer in the allowed range.
        utils.validate_as_num('local_as', speaker_as)

        # Notify Ryu about BGP Speaker addition.
        # Please note: Since, only the route-advertisement support is
        # implemented we are explicitly setting the bgp_server_port
        # attribute to 0 which disables listening on port 179.
        curr_speaker = bgpspeaker.BGPSpeaker(as_number=speaker_as,
                             router_id=self.routerid, bgp_server_port=0,
                             best_path_change_handler=best_path_change_cb,
                             peer_down_handler=bgp_peer_down_cb,
                             peer_up_handler=bgp_peer_up_cb)
        LOG.info(_LI('Added BGP Speaker for local_as=%(as)d with '
                     'router_id= %(rtid)s.'),
                 {'as': speaker_as, 'rtid': self.routerid})

        self.cache.put_bgp_speaker(speaker_as, curr_speaker)
 def test_validate_as_num_with_invalid_min_range(self):
     allowed_range = ('\[' + str(bgp_consts.MIN_ASNUM) + '-' +
                      str(bgp_consts.MAX_4BYTE_ASNUM) + '\]')
     with self.assertRaisesRegex(
             bgp_driver_exc.InvalidParamRange, EXC_INV_PARAMRANGE % {
                 'param': 'local_as',
                 'range': allowed_range
             }):
         bgp_driver_utils.validate_as_num('local_as', 0)
 def test_validate_as_num_with_invalid_min_range(self):
     allowed_range = ('\[' +
                      str(bgp_consts.MIN_ASNUM) + '-' +
                      str(bgp_consts.MAX_4BYTE_ASNUM) +
                      '\]')
     with self.assertRaisesRegex(
             bgp_driver_exc.InvalidParamRange,
             EXC_INV_PARAMRANGE % {'param': 'local_as',
                                   'range': allowed_range}):
         bgp_driver_utils.validate_as_num('local_as', 0)
Exemplo n.º 8
0
    def add_bgp_peer(self,
                     speaker_as,
                     peer_ip,
                     peer_as,
                     auth_type='none',
                     password=None,
                     enable_evpn=None,
                     hold_time=None,
                     connect_mode=CONNECT_MODE_ACTIVE):
        curr_speaker = self.cache.get_bgp_speaker(speaker_as)
        if not curr_speaker:
            raise bgp_driver_exc.BgpSpeakerNotAdded(local_as=speaker_as,
                                                    rtid=self.routerid)

        # Validate peer_ip and peer_as.
        utils.validate_as_num('remote_as', peer_as)
        ip_version = utils.validate_ip_addr(peer_ip)
        utils.validate_auth(auth_type, password)
        if password is not None:
            password = encodeutils.to_utf8(password)

        kwargs = {}
        if enable_evpn is not None:
            kwargs['enable_evpn'] = enable_evpn
        if hold_time is not None:
            kwargs['hold_time'] = hold_time
        # Notify Ryu about BGP Peer addition
        if ip_version == lib_consts.IP_VERSION_4:
            enable_ipv4 = True
            enable_ipv6 = False
        else:
            enable_ipv4 = False
            enable_ipv6 = True
        curr_speaker.neighbor_add(address=peer_ip,
                                  remote_as=peer_as,
                                  enable_ipv4=enable_ipv4,
                                  enable_ipv6=enable_ipv6,
                                  password=password,
                                  connect_mode=connect_mode,
                                  **kwargs)
        LOG.info(
            _LI('Added BGP Peer %(peer)s for remote_as=%(as)d to '
                'BGP Speaker running for local_as=%(local_as)d.'), {
                    'peer': peer_ip,
                    'as': peer_as,
                    'local_as': speaker_as
                })
    def add_bgp_peer(self, speaker_as, peer_ip, peer_as,
                     auth_type='none', password=None):
        curr_speaker = self.cache.get_bgp_speaker(speaker_as)
        if not curr_speaker:
            raise bgp_driver_exc.BgpSpeakerNotAdded(local_as=speaker_as,
                                                    rtid=self.routerid)

        # Validate peer_ip and peer_as.
        utils.validate_as_num('remote_as', peer_as)
        utils.validate_string(peer_ip)
        utils.validate_auth(auth_type, password)

        # Notify Ryu about BGP Peer addition
        curr_speaker.neighbor_add(address=peer_ip,
                                  remote_as=peer_as,
                                  password=password,
                                  connect_mode=CONNECT_MODE_ACTIVE)
        LOG.info(_LI('Added BGP Peer %(peer)s for remote_as=%(as)d to '
                     'BGP Speaker running for local_as=%(local_as)d.'),
                 {'peer': peer_ip, 'as': peer_as, 'local_as': speaker_as})
 def test_validate_as_num_with_valid_as_num(self):
     self.assertIsNone(bgp_driver_utils.validate_as_num('local_as', 64512))
Exemplo n.º 11
0
 def test_validate_as_num_with_string_as_num(self):
     with self.assertRaisesRegex(
             bgp_driver_exc.InvalidParamType,
             EXC_INV_PARAMTYPE % {'param': 'local_as',
                                  'param_type': 'integer'}):
         bgp_driver_utils.validate_as_num('local_as', '64512')
Exemplo n.º 12
0
 def test_validate_as_num_with_valid_as_num(self):
     self.assertIsNone(bgp_driver_utils.validate_as_num('local_as',
                                                        64512))