Beispiel #1
0
    def vrf_add(self, route_dist, import_rts, export_rts, site_of_origins=None,
                route_family=RF_VPN_V4, multi_exit_disc=None):
        """ This method adds a new vrf used for VPN.

        ``route_dist`` specifies a route distinguisher value.

        ``import_rts`` specifies route targets to be imported.

        ``export_rts`` specifies route targets to be exported.

        ``site_of_origins`` specifies site_of_origin values.
        This parameter must be a list of string.

        ``route_family`` specifies route family of the VRF.
        This parameter must be RF_VPN_V4 or RF_VPN_V6.
        """

        assert route_family in (RF_VPN_V4, RF_VPN_V6),\
            'route_family must be RF_VPN_V4 or RF_VPN_V6'

        vrf = {}
        vrf[vrfs.ROUTE_DISTINGUISHER] = route_dist
        vrf[vrfs.IMPORT_RTS] = import_rts
        vrf[vrfs.EXPORT_RTS] = export_rts
        vrf[vrfs.SITE_OF_ORIGINS] = site_of_origins
        vrf[vrfs.VRF_RF] = route_family
        call('vrf.create', **vrf)
Beispiel #2
0
    def neighbor_add(self, address, remote_as,
                     enable_ipv4=DEFAULT_CAP_MBGP_IPV4,
                     enable_vpnv4=DEFAULT_CAP_MBGP_VPNV4,
                     enable_vpnv6=DEFAULT_CAP_MBGP_VPNV6):
        """ This method registers a new neighbor. The BGP speaker tries to
        establish a bgp session with the peer (accepts a connection
        from the peer and also tries to connect to it).

        ``address`` specifies the IP address of the peer. It must be
        the string representation of an IP address. Only IP v4 is
        supported now.

        ``remote_as`` specifies the AS number of the peer. It must be
        an integer between 1 and 65535.

        ``enable_ipv4`` enables IPv4 address family for this
        neighbor. The default is True.

        ``enable_vpnv4`` enables VPNv4 address family for this
        neighbor. The default is False.

        ``enable_vpnv6`` enables VPNv6 address family for this
        neighbor. The default is False.

        """
        bgp_neighbor = {}
        bgp_neighbor[neighbors.IP_ADDRESS] = address
        bgp_neighbor[neighbors.REMOTE_AS] = remote_as
        bgp_neighbor[CAP_MBGP_IPV4] = enable_ipv4
        bgp_neighbor[CAP_MBGP_VPNV4] = enable_vpnv4
        bgp_neighbor[CAP_MBGP_VPNV6] = enable_vpnv6
        call('neighbor.create', **bgp_neighbor)
Beispiel #3
0
    def prefix_del(self, prefix, route_dist=None):
        """ This method deletes a advertized prefix.

        ``prefix`` must be the string representation of an IP network
        (e.g., 10.1.1.0/24).

        ``route_dist`` specifies a route distinguisher value. This
        parameter is necessary for only VPNv4 and VPNv6 address
        families.

        """
        func_name = 'network.del'
        networks = {}
        networks[PREFIX] = prefix
        if route_dist:
            func_name = 'prefix.delete_local'
            networks[ROUTE_DISTINGUISHER] = route_dist

            ip, masklen = prefix.split('/')
            if netaddr.valid_ipv6(ip):
                networks[ROUTE_FAMILY] = vrfs.VRF_RF_IPV6
                # normalize IPv6 address expression
                networks[PREFIX] = \
                    str(netaddr.IPAddress(ip)) + '/' + masklen
            else:
                networks[ROUTE_FAMILY] = vrfs.VRF_RF_IPV4

        call(func_name, **networks)
Beispiel #4
0
    def attribute_map_set(self, address, attribute_maps):
        """This method sets attribute mapping to a neighbor.
        attribute mapping can be used when you want to apply
        attribute to BGPUpdate under specific conditions.

        ``address`` specifies the IP address of the neighbor

        ``attribute_maps`` specifies attribute_map list that are used
        before paths are advertised. All the items in the list must
        be an instance of AttributeMap class

        We can set AttributeMap to a neighbor as follows;

          pref_filter = PrefixFilter('192.168.103.0/30',
                                     PrefixFilter.POLICY_PERMIT)

          attribute_map = AttributeMap([pref_filter],
                                       AttributeMap.ATTR_LOCAL_PREF, 250)

          speaker.attribute_map_set('192.168.50.102', [attribute_map])

        """

        func_name = 'neighbor.attribute_map.set'
        param = {}
        param[neighbors.IP_ADDRESS] = address
        param[neighbors.ATTRIBUTE_MAP] = attribute_maps
        call(func_name, **param)
Beispiel #5
0
    def vrf_add(self, route_dist, import_rts, export_rts, site_of_origins=None,
                route_family=RF_VPN_V4, multi_exit_disc=None):
        """ This method adds a new vrf used for VPN.

        ``route_dist`` specifies a route distinguisher value.

        ``import_rts`` specifies a list of route targets to be imported.

        ``export_rts`` specifies a list of route targets to be exported.

        ``site_of_origins`` specifies site_of_origin values.
        This parameter must be a list of string.

        ``route_family`` specifies route family of the VRF.
        This parameter must be RF_VPN_V4, RF_VPN_V6 or RF_L2_EVPN.

        ``multi_exit_disc`` specifies multi exit discriminator (MED) value.
        It must be an integer.
        """

        assert route_family in SUPPORTED_VRF_RF,\
            'route_family must be RF_VPN_V4, RF_VPN_V6 or RF_L2_EVPN'

        vrf = {
            vrfs.ROUTE_DISTINGUISHER: route_dist,
            vrfs.IMPORT_RTS: import_rts,
            vrfs.EXPORT_RTS: export_rts,
            vrfs.SITE_OF_ORIGINS: site_of_origins,
            vrfs.VRF_RF: route_family,
            vrfs.MULTI_EXIT_DISC: multi_exit_disc,
        }

        call('vrf.create', **vrf)
Beispiel #6
0
    def neighbor_update(self, address, conf_type, conf_value):
        """ This method changes the neighbor configuration.

        ``address`` specifies the IP address of the peer.

        ``conf_type`` specifies configuration type which you want to change.
        Currently ryu.services.protocols.bgp.bgpspeaker.MULTI_EXIT_DISC
        can be specified.

        ``conf_value`` specifies value for the configuration type.
        """

        assert conf_type == MULTI_EXIT_DISC or conf_type == CONNECT_MODE

        func_name = 'neighbor.update'
        attribute_param = {}
        if conf_type == MULTI_EXIT_DISC:
            attribute_param = {neighbors.MULTI_EXIT_DISC: conf_value}
        elif conf_type == CONNECT_MODE:
            attribute_param = {neighbors.CONNECT_MODE: conf_value}

        param = {neighbors.IP_ADDRESS: address,
                 neighbors.CHANGES: attribute_param}

        call(func_name, **param)
Beispiel #7
0
    def neighbor_add(self, address, remote_as,
                     enable_ipv4=DEFAULT_CAP_MBGP_IPV4,
                     enable_vpnv4=DEFAULT_CAP_MBGP_VPNV4,
                     enable_vpnv6=DEFAULT_CAP_MBGP_VPNV6,
                     next_hop=None, password=None, multi_exit_disc=None):
        """ This method registers a new neighbor. The BGP speaker tries to
        establish a bgp session with the peer (accepts a connection
        from the peer and also tries to connect to it).

        ``address`` specifies the IP address of the peer. It must be
        the string representation of an IP address. Only IP v4 is
        supported now.

        ``remote_as`` specifies the AS number of the peer. It must be
        an integer between 1 and 65535.

        ``enable_ipv4`` enables IPv4 address family for this
        neighbor. The default is True.

        ``enable_vpnv4`` enables VPNv4 address family for this
        neighbor. The default is False.

        ``enable_vpnv6`` enables VPNv6 address family for this
        neighbor. The default is False.

        ``next_hop`` specifies the next hop IP address. If not
        specified, host's ip address to access to a peer is used.

        ``password`` is used for the MD5 authentication if it's
        specified. By default, the MD5 authenticaiton is disabled.

        ``multi_exit_disc`` specifies multi exit discriminator (MED) value.
        The default is None and if not specified, MED value is
        not sent to the neighbor. It must be an integer.

        """
        bgp_neighbor = {}
        bgp_neighbor[neighbors.IP_ADDRESS] = address
        bgp_neighbor[neighbors.REMOTE_AS] = remote_as
        bgp_neighbor[PEER_NEXT_HOP] = next_hop
        bgp_neighbor[PASSWORD] = password
        # v6 advertizement is available with only v6 peering
        if netaddr.valid_ipv4(address):
            bgp_neighbor[CAP_MBGP_IPV4] = enable_ipv4
            bgp_neighbor[CAP_MBGP_IPV6] = False
            bgp_neighbor[CAP_MBGP_VPNV4] = enable_vpnv4
            bgp_neighbor[CAP_MBGP_VPNV6] = enable_vpnv6
        elif netaddr.valid_ipv6(address):
            bgp_neighbor[CAP_MBGP_IPV4] = False
            bgp_neighbor[CAP_MBGP_IPV6] = True
            bgp_neighbor[CAP_MBGP_VPNV4] = False
            bgp_neighbor[CAP_MBGP_VPNV6] = False
        else:
            # FIXME: should raise an exception
            pass

        if multi_exit_disc:
            bgp_neighbor[MULTI_EXIT_DISC] = multi_exit_disc

        call('neighbor.create', **bgp_neighbor)
Beispiel #8
0
    def prefix_add(self, prefix, next_hop=None, route_dist=None):
        """ This method adds a new prefix to be advertized.

        ``prefix`` must be the string representation of an IP network
        (e.g., 10.1.1.0/24).

        ``next_hop`` specifies the next hop address for this
        prefix. This parameter is necessary for only VPNv4 and VPNv6
        address families.

        ``route_dist`` specifies a route distinguisher value. This
        parameter is necessary for only VPNv4 and VPNv6 address
        families.

        """
        func_name = 'network.add'
        networks = {}
        networks[PREFIX] = prefix
        if next_hop:
            networks[NEXT_HOP] = next_hop
        if route_dist:
            func_name = 'prefix.add_local'
            networks[ROUTE_DISTINGUISHER] = route_dist

            rf, p = self._check_rf_and_normalize(prefix)
            networks[ROUTE_FAMILY] = rf
            networks[PREFIX] = p

            if rf == vrfs.VRF_RF_IPV6 and netaddr.valid_ipv4(next_hop):
                # convert the next_hop to IPv4-Mapped IPv6 Address
                networks[NEXT_HOP] = \
                    str(netaddr.IPAddress(next_hop).ipv6())

        call(func_name, **networks)
Beispiel #9
0
 def _neighbor_create(self, ip_address='192.168.177.32',
                      remote_as=64513):
     bgp_neighbor = {}
     bgp_neighbor[neighbors.IP_ADDRESS] = str(ip_address)
     bgp_neighbor[neighbors.REMOTE_AS] = remote_as
     call('neighbor.create', **bgp_neighbor)
     return {}
Beispiel #10
0
    def prefix_add(self, prefix, next_hop=None, route_dist=None,
                   route_family=None):
        """ This method adds a new prefix to be advertized.

        ``prefix`` must be the string representation of an IP network
        (e.g., 10.1.1.0/24).

        ``next_hop`` specifies the next hop address for this
        prefix. This parameter is necessary for only VPNv4 and VPNv6
        address families.

        ``route_dist`` specifies a route distinguisher value. This
        parameter is necessary for only VPNv4 and VPNv6 address
        families.

        """
        func_name = 'network.add'
        networks = {}
        networks[PREFIX] = prefix
        if next_hop:
            networks[NEXT_HOP] = next_hop
        if route_dist:
            func_name = 'prefix.add_local'
            networks[ROUTE_DISTINGUISHER] = route_dist
        call(func_name, **networks)
Beispiel #11
0
 def _core_start(self, as_number=64512, router_id='10.0.0.1'):
     common_settings = {}
     common_settings[LOCAL_AS] = as_number
     common_settings[ROUTER_ID] = str(router_id)
     waiter = hub.Event()
     call('core.start', waiter=waiter, **common_settings)
     waiter.wait()
     return {}
Beispiel #12
0
    def vrf_del(self, route_dist):
        """ This method deletes the existing vrf.

        ``route_dist`` specifies a route distinguisher value.
        """

        vrf = {vrfs.ROUTE_DISTINGUISHER: route_dist}

        call('vrf.delete', **vrf)
Beispiel #13
0
    def evpn_prefix_del(self, route_type, route_dist, esi=0,
                        ethernet_tag_id=None, mac_addr=None, ip_addr=None,
                        ip_prefix=None):
        """ This method deletes an advertised EVPN route.

        ``route_type`` specifies one of the EVPN route type name.

        ``route_dist`` specifies a route distinguisher value.

        ``esi`` is an value to specify the Ethernet Segment Identifier.

        ``ethernet_tag_id`` specifies the Ethernet Tag ID.

        ``mac_addr`` specifies a MAC address to advertise.

        ``ip_addr`` specifies an IPv4 or IPv6 address to advertise.

        ``ip_prefix`` specifies an IPv4 or IPv6 prefix to advertise.
        """
        func_name = 'evpn_prefix.delete_local'

        # Set required arguments
        kwargs = {EVPN_ROUTE_TYPE: route_type,
                  ROUTE_DISTINGUISHER: route_dist}

        # Set route type specific arguments
        if route_type == EVPN_ETH_AUTO_DISCOVERY:
            kwargs.update({
                EVPN_ESI: esi,
                EVPN_ETHERNET_TAG_ID: ethernet_tag_id,
            })
        elif route_type == EVPN_MAC_IP_ADV_ROUTE:
            kwargs.update({
                EVPN_ETHERNET_TAG_ID: ethernet_tag_id,
                MAC_ADDR: mac_addr,
                IP_ADDR: ip_addr,
            })
        elif route_type == EVPN_MULTICAST_ETAG_ROUTE:
            kwargs.update({
                EVPN_ETHERNET_TAG_ID: ethernet_tag_id,
                IP_ADDR: ip_addr,
            })
        elif route_type == EVPN_ETH_SEGMENT:
            kwargs.update({
                EVPN_ESI: esi,
                IP_ADDR: ip_addr,
            })
        elif route_type == EVPN_IP_PREFIX_ROUTE:
            kwargs.update({
                EVPN_ETHERNET_TAG_ID: ethernet_tag_id,
                IP_PREFIX: ip_prefix,
            })
        else:
            raise ValueError('Unsupported EVPN route type: %s' % route_type)

        call(func_name, **kwargs)
Beispiel #14
0
    def neighbor_reset(self, address):
        """ This method reset the registered neighbor.

        ``address`` specifies the IP address of the peer. It must be
        the string representation of an IP address.

        """
        bgp_neighbor = {}
        bgp_neighbor[neighbors.IP_ADDRESS] = address
        call('core.reset_neighbor', **bgp_neighbor)
Beispiel #15
0
    def neighbor_del(self, address):
        """ This method unregister the registered neighbor. If a session with
        the peer exists, the session will be closed.

        ``address`` specifies the IP address of the peer. It must be
        the string representation of an IP address.

        """
        bgp_neighbor = {}
        bgp_neighbor[neighbors.IP_ADDRESS] = address
        call('neighbor.delete', **bgp_neighbor)
Beispiel #16
0
    def bmp_server_del(self, address, port):
        """ This method unregister the registered BMP server.

        ``address`` specifies the IP address of a BMP server.

        ``port`` specifies the listen port number of a BMP server.
        """

        func_name = 'bmp.stop'
        param = {}
        param['host'] = address
        param['port'] = port
        call(func_name, **param)
Beispiel #17
0
    def _add_networks(self, routing_settings):
        """Add networks from given settings to BGPS runtime.

        If any of the networks are miss-configured errors are logged.
        All valid networks are loaded.
        """
        networks = routing_settings.setdefault('networks', [])
        for prefix in networks:
            try:
                call('network.add', prefix=prefix)
                LOG.debug('Added network %s' % str(prefix))
            except RuntimeConfigError as e:
                LOG.error(e)
                continue
Beispiel #18
0
    def _add_vrfs(self, routing_settings):
        """Add VRFs from given settings to BGPS runtime.

        If any of the VRFs are miss-configured errors are logged.
        All valid VRFs are loaded.
        """
        vpns_conf = routing_settings.setdefault('vpns', {})
        for vrf in vpns_conf:
            try:
                call('vrf.create', **vrf)
                LOG.debug('Added vrf  %s' % str(vrf))
            except RuntimeConfigError as e:
                LOG.error(e)
                continue
Beispiel #19
0
    def bmp_server_add(self, address, port):
        """This method registers a new BMP (BGP monitoring Protocol)
        server. The BGP speaker starts to send BMP messages to the
        server. Currently, only one BMP server can be registered.

        ``address`` specifies the IP address of a BMP server.

        ``port`` specifies the listen port number of a BMP server.
        """

        func_name = 'bmp.start'
        param = {}
        param['host'] = address
        param['port'] = port
        call(func_name, **param)
Beispiel #20
0
    def _add_neighbors(self, routing_settings):
        """Add bgp peers/neighbors from given settings to BGPS runtime.

        All valid neighbors are loaded. Miss-configured neighbors are ignored
        and error is logged.
        """
        bgp_neighbors = routing_settings.setdefault('bgp_neighbors', {})
        for ip, bgp_neighbor in bgp_neighbors.items():
            try:
                bgp_neighbor[neighbors.IP_ADDRESS] = ip
                call('neighbor.create', **bgp_neighbor)
                LOG.debug('Added neighbor %s' % ip)
            except RuntimeConfigError as re:
                LOG.error(re)
                LOG.error(traceback.format_exc())
                continue
Beispiel #21
0
    def neighbor_get(self, route_type, address, format='json'):
        """ This method returns the BGP adj-RIB-in/adj-RIB-out information
        in a json format.

        ``route_type`` This parameter is necessary for only received-routes
        and sent-routes.

          received-routes : paths received and not withdrawn by given peer

          sent-routes : paths sent and not withdrawn to given peer

        ``address`` specifies the IP address of the peer. It must be
        the string representation of an IP address.

        ``format`` specifies the format of the response.
        This parameter must be 'json' or 'cli'.
        """
        show = {
            'format': format,
        }
        if route_type == 'sent-routes' or route_type == 'received-routes':
            show['params'] = ['neighbor', route_type, address, 'all']
        else:
            show['params'] = ['neighbor', 'received-routes', address, 'all']

        return call('operator.show', **show)
Beispiel #22
0
    def vrfs_get(self, subcommand='routes', route_dist=None,
                 route_family='all', format='json'):
        """ This method returns the existing vrfs.

        ``subcommand`` specifies the subcommand.

          'routes': shows routes present for vrf

          'summary': shows configuration and summary of vrf

        ``route_dist`` specifies a route distinguisher value.
        If route_family is not 'all', this value must be specified.

        ``route_family`` specifies route family of the VRF.
        This parameter must be RF_VPN_V4, RF_VPN_V6 or RF_L2_EVPN
        or 'all'.

        ``format`` specifies the format of the response.
        This parameter must be 'json' or 'cli'.
        """
        show = {
            'format': format,
        }
        if route_family in SUPPORTED_VRF_RF:
            assert route_dist is not None
            show['params'] = ['vrf', subcommand, route_dist, route_family]
        else:
            show['params'] = ['vrf', subcommand, 'all']

        return call('operator.show', **show)
Beispiel #23
0
    def attribute_map_get(self, address, route_dist=None,
                          route_family=RF_VPN_V4):
        """This method gets in-bound filters of the specified neighbor.

        ``address`` specifies the IP address of the neighbor.

        ``route_dist`` specifies route distinguisher that has attribute_maps.

        ``route_family`` specifies route family of the VRF.
        This parameter must be RF_VPN_V4 or RF_VPN_V6.

        Returns a list object containing an instance of AttributeMap

        """

        assert route_family in (RF_VPN_V4, RF_VPN_V6),\
            'route_family must be RF_VPN_V4 or RF_VPN_V6'

        func_name = 'neighbor.attribute_map.get'
        param = {}
        param[neighbors.IP_ADDRESS] = address
        if route_dist is not None:
            param[vrfs.ROUTE_DISTINGUISHER] = route_dist
            param[vrfs.VRF_RF] = route_family
        attribute_maps = call(func_name, **param)
        return attribute_maps
Beispiel #24
0
    def out_filter_set(self, address, prefix_lists,
                       route_family=OUT_FILTER_RF_IPv4_UC):
        """ This method sets out-filter to neighbor.

        ``address`` specifies the IP address of the peer.

        ``prefix_lists`` specifies prefix list to filter path advertisement.
         This parameter must be list that has PrefixList objects.

        ``route_family`` specifies the route family for out-filter.
        This parameter must be bgpspeaker.OUT_FILTER_RF_IPv4_UC or
        bgpspeaker.OUT_FILTER_RF_IPv6_UC.


        If you want to define out-filter that send only a particular
        prefix to neighbor, prefix_lists can be created as follows;

          p = PrefixList('10.5.111.0/24', policy=PrefixList.POLICY_PERMIT)

          all = PrefixList('0.0.0.0/0', policy=PrefixList.POLICY_DENY)

          pList = [p, all]

          self.bgpspeaker.out_filter_set(neighbor_address, pList)

        NOTE:
        out-filter evaluates prefixes in the order of PrefixList in the pList.

        """

        assert route_family in (OUT_FILTER_RF_IPv4_UC,
                                OUT_FILTER_RF_IPv6_UC),\
            "route family must be IPv4 or IPv6"

        if prefix_lists is None:
            prefix_lists = []

        func_name = 'neighbor.update'
        prefix_value = {'prefix_lists': prefix_lists,
                        'route_family': route_family}
        filter_param = {neighbors.OUT_FILTER: prefix_value}

        param = {}
        param[neighbors.IP_ADDRESS] = address
        param[neighbors.CHANGES] = filter_param
        call(func_name, **param)
Beispiel #25
0
    def vrf_add(self, route_dist, import_rts, export_rts, site_of_origins=None,
                multi_exit_disc=None):
        """ This method adds a new vrf used for VPN.

        ``route_dist`` specifies a route distinguisher value.

        ``import_rts`` specifies route targets to be imported.

        ``export_rts`` specifies route targets to be exported.

        """

        vrf = {}
        vrf[vrfs.ROUTE_DISTINGUISHER] = route_dist
        vrf[vrfs.IMPORT_RTS] = import_rts
        vrf[vrfs.EXPORT_RTS] = export_rts
        call('vrf.create', **vrf)
Beispiel #26
0
    def _start_core(self, settings):
        """Starts BGPS core using setting and given pool.
        """
        # Get common settings
        routing_settings = settings.BGP.get('routing')
        common_settings = {}

        # Get required common settings.
        try:
            common_settings[LOCAL_AS] = routing_settings.pop(LOCAL_AS)
            common_settings[ROUTER_ID] = routing_settings.pop(ROUTER_ID)
        except KeyError as e:
            raise ApplicationException(
                desc='Required minimum configuration missing %s' %
                     e)

        # Get optional common settings
        common_settings[BGP_SERVER_PORT] = \
            routing_settings.get(BGP_SERVER_PORT, DEFAULT_BGP_SERVER_PORT)
        common_settings[REFRESH_STALEPATH_TIME] = \
            routing_settings.get(REFRESH_STALEPATH_TIME,
                                 DEFAULT_REFRESH_STALEPATH_TIME)
        common_settings[REFRESH_MAX_EOR_TIME] = \
            routing_settings.get(REFRESH_MAX_EOR_TIME,
                                 DEFAULT_REFRESH_MAX_EOR_TIME)
        common_settings[LABEL_RANGE] = \
            routing_settings.get(LABEL_RANGE, DEFAULT_LABEL_RANGE)

        # Start BGPS core service
        waiter = hub.Event()
        call('core.start', waiter=waiter, **common_settings)


        waiter.wait()

        LOG.debug('Core started %s', CORE_MANAGER.started)
        # Core manager started add configured neighbor and vrfs
        if CORE_MANAGER.started:
            # Add neighbors.
            self._add_neighbors(routing_settings)

            # Add Vrfs.
            self._add_vrfs(routing_settings)

            # Add Networks
            self._add_networks(routing_settings)
Beispiel #27
0
    def _set_filter(self, filter_type, address, filters):
        assert filter_type in ('in', 'out'),\
            'filter type must be \'in\' or \'out\''

        assert all(isinstance(f, Filter) for f in filters),\
            'all the items in filters must be an instance of Filter sub-class'

        if filters is None:
            filters = []

        func_name = 'neighbor.' + filter_type + '_filter.set'
        param = {}
        param[neighbors.IP_ADDRESS] = address
        if filter_type == 'in':
            param[neighbors.IN_FILTER] = filters
        else:
            param[neighbors.OUT_FILTER] = filters
        call(func_name, **param)
Beispiel #28
0
    def prefix_del(self, prefix, route_dist=None, route_family=None):
        """ This method deletes a advertized prefix.

        ``prefix`` must be the string representation of an IP network
        (e.g., 10.1.1.0/24).

        ``route_dist`` specifies a route distinguisher value. This
        parameter is necessary for only VPNv4 and VPNv6 address
        families.

        """
        func_name = 'network.del'
        networks = {}
        networks[PREFIX] = prefix
        if route_dist:
            func_name = 'prefix.delete_local'
            networks[ROUTE_DISTINGUISHER] = route_dist
        call(func_name, **networks)
Beispiel #29
0
    def _set_filter(self, filter_type, address, filters):
        assert filter_type in ("in", "out"), "filter type must be 'in' or 'out'"

        assert all(
            isinstance(f, Filter) for f in filters
        ), "all the items in filters must be an instance of Filter sub-class"

        if filters is None:
            filters = []

        func_name = "neighbor." + filter_type + "_filter.set"
        param = {}
        param[neighbors.IP_ADDRESS] = address
        if filter_type == "in":
            param[neighbors.IN_FILTER] = filters
        else:
            param[neighbors.OUT_FILTER] = filters
        call(func_name, **param)
Beispiel #30
0
    def _set_filter(self, filter_type, address, filters):
        assert filter_type in ('in', 'out'),\
            'filter type must be \'in\' or \'out\''

        assert all(isinstance(f, Filter) for f in filters),\
            'all the items in filters must be an instance of Filter sub-class'

        if filters is None:
            filters = []

        func_name = 'neighbor.' + filter_type + '_filter.set'
        param = {}
        param[neighbors.IP_ADDRESS] = address
        if filter_type == 'in':
            param[neighbors.IN_FILTER] = filters
        else:
            param[neighbors.OUT_FILTER] = filters
        call(func_name, **param)
Beispiel #31
0
    def attribute_map_set(self,
                          address,
                          attribute_maps,
                          route_dist=None,
                          route_family=RF_VPN_V4):
        """This method sets attribute mapping to a neighbor.
        attribute mapping can be used when you want to apply
        attribute to BGPUpdate under specific conditions.

        ``address`` specifies the IP address of the neighbor

        ``attribute_maps`` specifies attribute_map list that are used
        before paths are advertised. All the items in the list must
        be an instance of AttributeMap class

        ``route_dist`` specifies route dist in which attribute_maps
        are added.

        ``route_family`` specifies route family of the VRF.
        This parameter must be RF_VPN_V4 or RF_VPN_V6.

        We can set AttributeMap to a neighbor as follows;

          pref_filter = PrefixFilter('192.168.103.0/30',
                                     PrefixFilter.POLICY_PERMIT)

          attribute_map = AttributeMap([pref_filter],
                                       AttributeMap.ATTR_LOCAL_PREF, 250)

          speaker.attribute_map_set('192.168.50.102', [attribute_map])

        """

        assert route_family in (RF_VPN_V4, RF_VPN_V6),\
            'route_family must be RF_VPN_V4 or RF_VPN_V6'

        func_name = 'neighbor.attribute_map.set'
        param = {}
        param[neighbors.IP_ADDRESS] = address
        param[neighbors.ATTRIBUTE_MAP] = attribute_maps
        if route_dist is not None:
            param[vrfs.ROUTE_DISTINGUISHER] = route_dist
            param[vrfs.VRF_RF] = route_family
        call(func_name, **param)
Beispiel #32
0
    def _start_core(self, settings):
        """Starts BGPS core using setting and given pool.
        """
        # Get common settings
        routing_settings = settings.BGP.get('routing')
        common_settings = {}

        # Get required common settings.
        try:
            common_settings[LOCAL_AS] = routing_settings.pop(LOCAL_AS)
            common_settings[ROUTER_ID] = routing_settings.pop(ROUTER_ID)
        except KeyError as e:
            raise ApplicationException(
                desc='Required minimum configuration missing %s' %
                     e)

        # Get optional common settings
        common_settings[BGP_SERVER_PORT] = \
            routing_settings.get(BGP_SERVER_PORT, DEFAULT_BGP_SERVER_PORT)
        common_settings[REFRESH_STALEPATH_TIME] = \
            routing_settings.get(REFRESH_STALEPATH_TIME,
                                 DEFAULT_REFRESH_STALEPATH_TIME)
        common_settings[REFRESH_MAX_EOR_TIME] = \
            routing_settings.get(REFRESH_MAX_EOR_TIME,
                                 DEFAULT_REFRESH_MAX_EOR_TIME)
        common_settings[LABEL_RANGE] = \
            routing_settings.get(LABEL_RANGE, DEFAULT_LABEL_RANGE)

        # Start BGPS core service
        waiter = hub.Event()
        call('core.start', waiter=waiter, **common_settings)
        waiter.wait()

        LOG.debug('Core started %s' % CORE_MANAGER.started)
        # Core manager started add configured neighbor and vrfs
        if CORE_MANAGER.started:
            # Add neighbors.
            self._add_neighbors(routing_settings)

            # Add Vrfs.
            self._add_vrfs(routing_settings)

            # Add Networks
            self._add_networks(routing_settings)
Beispiel #33
0
    def evpn_prefix_del(self,
                        route_type,
                        route_dist,
                        esi=0,
                        ethernet_tag_id=None,
                        mac_addr=None,
                        ip_addr=None):
        """ This method deletes an advertised EVPN route.

        ``route_type`` specifies one of the EVPN route type name.

        ``route_dist`` specifies a route distinguisher value.

        ``esi`` is an integer value to specify the Ethernet Segment
        Identifier. 0 is the default and denotes a single-homed site.

        ``ethernet_tag_id`` specifies the Ethernet Tag ID.

        ``mac_addr`` specifies a MAC address to advertise.

        ``ip_addr`` specifies an IPv4 or IPv6 address to advertise.
        """
        func_name = 'evpn_prefix.delete_local'

        # Set required arguments
        kwargs = {EVPN_ROUTE_TYPE: route_type, ROUTE_DISTINGUISHER: route_dist}

        # Set route type specific arguments
        if route_type == EVPN_MAC_IP_ADV_ROUTE:
            kwargs.update({
                EVPN_ESI: esi,
                EVPN_ETHERNET_TAG_ID: ethernet_tag_id,
                MAC_ADDR: mac_addr,
                IP_ADDR: ip_addr,
            })
        elif route_type == EVPN_MULTICAST_ETAG_ROUTE:
            kwargs.update({
                EVPN_ETHERNET_TAG_ID: ethernet_tag_id,
                IP_ADDR: ip_addr,
            })
        else:
            raise ValueError('Unsupported EVPN route type: %s' % route_type)

        call(func_name, **kwargs)
Beispiel #34
0
    def rib_get(self, family='ipv4'):
        """ This method returns the BGP routing information in a json
        format. This will be improved soon.

        ``family`` specifies the address family of the RIB.

        """
        show = {}
        show['params'] = ['rib', family]
        return call('operator.show', **show)
Beispiel #35
0
    def vrf_add(self,
                route_dist,
                import_rts,
                export_rts,
                site_of_origins=None,
                route_family=RF_VPN_V4,
                multi_exit_disc=None):
        """ This method adds a new vrf used for VPN.

        ``route_dist`` specifies a route distinguisher value.

        ``import_rts`` specifies a list of route targets to be imported.

        ``export_rts`` specifies a list of route targets to be exported.

        ``site_of_origins`` specifies site_of_origin values.
        This parameter must be a list of string.

        ``route_family`` specifies route family of the VRF.
        This parameter must be one of the following.

        - RF_VPN_V4 (default) = 'ipv4'
        - RF_VPN_V6           = 'ipv6'
        - RF_L2_EVPN          = 'evpn'
        - RF_VPNV4_FLOWSPEC   = 'ipv4fs'

        ``multi_exit_disc`` specifies multi exit discriminator (MED) value.
        It must be an integer.
        """
        if route_family not in SUPPORTED_VRF_RF:
            raise ValueError('Unsupported route_family: %s' % route_family)

        vrf = {
            vrfs.ROUTE_DISTINGUISHER: route_dist,
            vrfs.IMPORT_RTS: import_rts,
            vrfs.EXPORT_RTS: export_rts,
            vrfs.SITE_OF_ORIGINS: site_of_origins,
            vrfs.VRF_RF: route_family,
            vrfs.MULTI_EXIT_DISC: multi_exit_disc,
        }

        call('vrf.create', **vrf)
Beispiel #36
0
    def prefix_del(self, prefix, route_dist=None):
        """ This method deletes a advertised prefix.

        ``prefix`` must be the string representation of an IP network.

        ``route_dist`` specifies a route distinguisher value.
        """
        func_name = 'network.del'
        networks = {
            PREFIX: prefix,
        }
        if route_dist:
            func_name = 'prefix.delete_local'
            networks[ROUTE_DISTINGUISHER] = route_dist

            rf, p = self._check_rf_and_normalize(prefix)
            networks[ROUTE_FAMILY] = rf
            networks[PREFIX] = p

        call(func_name, **networks)
Beispiel #37
0
    def prefix_add(self, prefix, next_hop=None, route_dist=None):
        """ This method adds a new prefix to be advertized.

        ``prefix`` must be the string representation of an IP network
        (e.g., 10.1.1.0/24).

        ``next_hop`` specifies the next hop address for this
        prefix. This parameter is necessary for only VPNv4 and VPNv6
        address families.

        ``route_dist`` specifies a route distinguisher value. This
        parameter is necessary for only VPNv4 and VPNv6 address
        families.

        """
        func_name = 'network.add'
        networks = {}
        networks[PREFIX] = prefix
        if next_hop:
            networks[NEXT_HOP] = next_hop
        if route_dist:
            func_name = 'prefix.add_local'
            networks[ROUTE_DISTINGUISHER] = route_dist

            # check if the prefix address is IPv6 address
            ip, masklen = prefix.split('/')
            if netaddr.valid_ipv6(ip):
                networks[ROUTE_FAMILY] = vrfs.VRF_RF_IPV6
                # convert the next_hop address to IPv4-Mapped IPv6 Address
                # if it is IPv4 address
                if netaddr.valid_ipv4(next_hop):
                    networks[NEXT_HOP] = \
                        str(netaddr.IPAddress(next_hop).ipv6())

                # normalize IPv6 address expression
                networks[PREFIX] = \
                    str(netaddr.IPAddress(ip)) + '/' + masklen
            else:
                networks[ROUTE_FAMILY] = vrfs.VRF_RF_IPV4

        call(func_name, **networks)
Beispiel #38
0
    def neighbor_update(self, address, conf_type, conf_value):
        """ This method changes the neighbor configuration.

        ``conf_type`` specifies configuration type which you want to change.
        Currently ryu.services.protocols.bgp.bgpspeaker.NEIGHBOR_CONF_MED
        can be specified.

        ``conf_value`` specifies value for the configuration type.

        """

        assert conf_type == NEIGHBOR_CONF_MED

        func_name = 'neighbor.update'
        attribute_param = {}
        if conf_type == NEIGHBOR_CONF_MED:
            attribute_param = {neighbors.MULTI_EXIT_DISC: conf_value}

        param = {neighbors.IP_ADDRESS: address,
                 neighbors.CHANGES: attribute_param}
        call(func_name, **param)
Beispiel #39
0
    def neighbors_get(self, format='json'):
        """ This method returns a list of the BGP neighbors.

        ``format`` specifies the format of the response.
        This parameter must be 'json' or 'cli'.
        """
        show = {
            'params': ['neighbor'],
            'format': format,
        }

        return call('operator.show', **show)
Beispiel #40
0
    def rib_get(self, family='ipv4', format='json'):
        """ This method returns the BGP routing information in a json
        format. This will be improved soon.

        ``family`` specifies the address family of the RIB.

        ``format`` specifies the format of the response.
        This parameter must be 'json' or 'cli'.
        """
        show = {'params': ['rib', family], 'format': format}

        return call('operator.show', **show)
Beispiel #41
0
    def vrfs_get(self, format='json'):
        """ This method returns the existing vrfs.

        ``format`` specifies the format of the response.
        This parameter must be 'json' or 'cli'.
        """
        show = {
            'params': ['vrf', 'routes', 'all'],
            'format': format,
        }

        return call('operator.show', **show)
Beispiel #42
0
    def vrf_add(self,
                route_dist,
                import_rts,
                export_rts,
                site_of_origins=None,
                route_family=RF_VPN_V4,
                multi_exit_disc=None):
        """ This method adds a new vrf used for VPN.

        ``route_dist`` specifies a route distinguisher value.

        ``import_rts`` specifies a list of route targets to be imported.

        ``export_rts`` specifies a list of route targets to be exported.

        ``site_of_origins`` specifies site_of_origin values.
        This parameter must be a list of string.

        ``route_family`` specifies route family of the VRF.
        This parameter must be RF_VPN_V4, RF_VPN_V6 or RF_L2_EVPN.

        ``multi_exit_disc`` specifies multi exit discriminator (MED) value.
        It must be an integer.
        """

        assert route_family in SUPPORTED_VRF_RF,\
            'route_family must be RF_VPN_V4, RF_VPN_V6 or RF_L2_EVPN'

        vrf = {
            vrfs.ROUTE_DISTINGUISHER: route_dist,
            vrfs.IMPORT_RTS: import_rts,
            vrfs.EXPORT_RTS: export_rts,
            vrfs.SITE_OF_ORIGINS: site_of_origins,
            vrfs.VRF_RF: route_family,
            vrfs.MULTI_EXIT_DISC: multi_exit_disc,
        }

        call('vrf.create', **vrf)
Beispiel #43
0
    def prefix_del(self, prefix, route_dist=None):
        """ This method deletes a advertized prefix.

        ``prefix`` must be the string representation of an IP network
        (e.g., 10.1.1.0/24).

        ``route_dist`` specifies a route distinguisher value. This
        parameter is necessary for only VPNv4 and VPNv6 address
        families.

        """
        func_name = 'network.del'
        networks = {}
        networks[PREFIX] = prefix
        if route_dist:
            func_name = 'prefix.delete_local'
            networks[ROUTE_DISTINGUISHER] = route_dist

            rf, p = self._check_rf_and_normalize(prefix)
            networks[ROUTE_FAMILY] = rf
            networks[PREFIX] = p

        call(func_name, **networks)
Beispiel #44
0
    def attribute_map_get(self, address):
        """This method gets in-bound filters of the specified neighbor.

        ``address`` specifies the IP address of the neighbor.

        Returns a list object containing an instance of AttributeMap

        """

        func_name = 'neighbor.attribute_map.get'
        param = {}
        param[neighbors.IP_ADDRESS] = address
        attribute_maps = call(func_name, **param)
        return attribute_maps
Beispiel #45
0
    def flowspec_prefix_del(self, flowspec_family, rules, route_dist=None):
        """ This method deletes an advertised Flow Specification route.

        ``flowspec_family`` specifies one of the flowspec family name.

        ``rules`` specifies NLRIs of Flow Specification as
        a dictionary type value.

        ``route_dist`` specifies a route distinguisher value.
        """
        func_name = 'flowspec.del'

        # Set required arguments
        kwargs = {
            FLOWSPEC_FAMILY: flowspec_family,
            FLOWSPEC_RULES: rules,
        }

        if flowspec_family == FLOWSPEC_FAMILY_VPNV4:
            func_name = 'flowspec.del_local'
            kwargs.update({ROUTE_DISTINGUISHER: route_dist})

        call(func_name, **kwargs)
Beispiel #46
0
    def neighbor_state_get(self, address=None, format='json'):
        """ This method returns the state of peer(s) in a json
        format.

        ``address`` specifies the address of a peer. If not given, the
        state of all the peers return.

        """
        show = {}
        show['params'] = ['neighbor', 'summary']
        if address:
            show['params'].append(address)
        show['format'] = format
        return call('operator.show', **show)
Beispiel #47
0
    def in_filter_get(self, address):
        """This method gets in-bound filters of the specified neighbor.

        ``address`` specifies the IP address of the neighbor.

        Returns a list object containing an instance of Filter sub-class

        """

        func_name = 'neighbor.in_filter.get'
        param = {}
        param[neighbors.IP_ADDRESS] = address
        in_filter = call(func_name, **param)
        return in_filter
Beispiel #48
0
    def out_filter_get(self, address):
        """ This method gets out-filter setting from the specified neighbor.

        ``address`` specifies the IP address of the peer.

        Returns a list object containing an instance of Filter sub-class

        """

        func_name = 'neighbor.out_filter.get'
        param = {}
        param[neighbors.IP_ADDRESS] = address
        out_filter = call(func_name, **param)
        return out_filter
Beispiel #49
0
    def neighbor_state_get(self, address=None, format='json'):
        """ This method returns the state of peer(s) in a json
        format.

        ``address`` specifies the address of a peer. If not given, the
        state of all the peers return.

        ``format`` specifies the format of the response.
        This parameter must be 'json' or 'cli'.
        """
        show = {
            'params': ['neighbor', 'summary'],
            'format': format,
        }
        if address:
            show['params'].append(address)

        return call('operator.show', **show)
Beispiel #50
0
    def neighbor_get(self, routetype, address, format='json'):
        """ This method returns the BGP adj-RIB-in information in a json
        format.

        ``routetype`` This parameter is necessary for only received-routes
        and sent-routes.

          received-routes : paths received and not withdrawn by given peer

          sent-routes : paths sent and not withdrawn to given peer

        ``address`` specifies the IP address of the peer. It must be
        the string representation of an IP address.

        """
        show = {}
        if routetype == 'sent-routes' or routetype == 'received-routes':
            show['params'] = ['neighbor', routetype, address, 'all']
        else:
            show['params'] = ['neighbor', 'received-routes', address, 'all']
        show['format'] = format
        return call('operator.show', **show)
Beispiel #51
0
    def vrfs_get(self,
                 subcommand='routes',
                 route_dist=None,
                 route_family='all',
                 format='json'):
        """ This method returns the existing vrfs.

        ``subcommand`` specifies one of the following.

        - 'routes': shows routes present for vrf
        - 'summary': shows configuration and summary of vrf

        ``route_dist`` specifies a route distinguisher value.
        If route_family is not 'all', this value must be specified.

        ``route_family`` specifies route family of the VRF.
        This parameter must be one of the following.

        - RF_VPN_V4  = 'ipv4'
        - RF_VPN_V6  = 'ipv6'
        - RF_L2_EVPN = 'evpn'
        - 'all' (default)

        ``format`` specifies the format of the response.
        This parameter must be one of the following.

        - 'json' (default)
        - 'cli'
        """
        show = {
            'format': format,
        }
        if route_family in SUPPORTED_VRF_RF:
            assert route_dist is not None
            show['params'] = ['vrf', subcommand, route_dist, route_family]
        else:
            show['params'] = ['vrf', subcommand, 'all']

        return call('operator.show', **show)
Beispiel #52
0
 def bmp_stop(self, host, port):
     func_name = 'bmp.stop'
     param = {}
     param['host'] = host
     param['port'] = port
     call(func_name, **param)
Beispiel #53
0
 def vrfs_get(self):
     show = {}
     show['params'] = ['vrf', 'routes', 'all']
     return call('operator.show', **show)
Beispiel #54
0
    def neighbor_add(
            self,
            address,
            remote_as,
            enable_ipv4=DEFAULT_CAP_MBGP_IPV4,
            enable_vpnv4=DEFAULT_CAP_MBGP_VPNV4,
            enable_vpnv6=DEFAULT_CAP_MBGP_VPNV6,
            enable_evpn=DEFAULT_CAP_MBGP_EVPN,
            enable_enhanced_refresh=DEFAULT_CAP_ENHANCED_REFRESH,
            enable_four_octet_as_number=DEFAULT_CAP_FOUR_OCTET_AS_NUMBER,
            next_hop=None,
            password=None,
            multi_exit_disc=None,
            site_of_origins=None,
            is_route_server_client=False,
            is_next_hop_self=False,
            local_address=None,
            local_port=None,
            local_as=None,
            connect_mode=DEFAULT_CONNECT_MODE):
        """ This method registers a new neighbor. The BGP speaker tries to
        establish a bgp session with the peer (accepts a connection
        from the peer and also tries to connect to it).

        ``address`` specifies the IP address of the peer. It must be
        the string representation of an IP address. Only IPv4 is
        supported now.

        ``remote_as`` specifies the AS number of the peer. It must be
        an integer between 1 and 65535.

        ``enable_ipv4`` enables IPv4 address family for this
        neighbor. The default is True.

        ``enable_vpnv4`` enables VPNv4 address family for this
        neighbor. The default is False.

        ``enable_vpnv6`` enables VPNv6 address family for this
        neighbor. The default is False.

        ``enable_evpn`` enables Ethernet VPN address family for this
        neighbor. The default is False.

        ``enable_enhanced_refresh`` enables Enhanced Route Refresh for this
        neighbor. The default is False.

        ``enable_four_octet_as_number`` enables Four-Octet AS Number
        capability for this neighbor. The default is True.

        ``next_hop`` specifies the next hop IP address. If not
        specified, host's ip address to access to a peer is used.

        ``password`` is used for the MD5 authentication if it's
        specified. By default, the MD5 authentication is disabled.

        ``multi_exit_disc`` specifies multi exit discriminator (MED) value.
        The default is None and if not specified, MED value is
        not sent to the neighbor. It must be an integer.

        ``site_of_origins`` specifies site_of_origin values.
        This parameter must be a list of string.

        ``is_route_server_client`` specifies whether this neighbor is a
        router server's client or not.

        ``is_next_hop_self`` specifies whether the BGP speaker announces
        its own ip address to iBGP neighbor or not as path's next_hop address.

        ``local_address`` specifies Loopback interface address for
        iBGP peering.

        ``local_port`` specifies source TCP port for iBGP peering.

        ``local_as`` specifies local AS number per-peer.
        The default is the AS number of BGPSpeaker instance.

        ``connect_mode`` specifies how to connect to this neighbor.
        CONNECT_MODE_ACTIVE tries to connect from us.
        CONNECT_MODE_PASSIVE just listens and wait for the connection.
        CONNECT_MODE_BOTH use both methods.
        The default is CONNECT_MODE_BOTH.
        """
        bgp_neighbor = {
            neighbors.IP_ADDRESS: address,
            neighbors.REMOTE_AS: remote_as,
            PEER_NEXT_HOP: next_hop,
            PASSWORD: password,
            IS_ROUTE_SERVER_CLIENT: is_route_server_client,
            IS_NEXT_HOP_SELF: is_next_hop_self,
            CONNECT_MODE: connect_mode,
            CAP_ENHANCED_REFRESH: enable_enhanced_refresh,
            CAP_FOUR_OCTET_AS_NUMBER: enable_four_octet_as_number,
        }
        # v6 advertisement is available with only v6 peering
        if netaddr.valid_ipv4(address):
            bgp_neighbor[CAP_MBGP_IPV4] = enable_ipv4
            bgp_neighbor[CAP_MBGP_IPV6] = False
            bgp_neighbor[CAP_MBGP_VPNV4] = enable_vpnv4
            bgp_neighbor[CAP_MBGP_VPNV6] = enable_vpnv6
            bgp_neighbor[CAP_MBGP_EVPN] = enable_evpn
        elif netaddr.valid_ipv6(address):
            bgp_neighbor[CAP_MBGP_IPV4] = False
            bgp_neighbor[CAP_MBGP_IPV6] = True
            bgp_neighbor[CAP_MBGP_VPNV4] = False
            bgp_neighbor[CAP_MBGP_VPNV6] = False
            bgp_neighbor[CAP_MBGP_EVPN] = enable_evpn
        else:
            # FIXME: should raise an exception
            pass

        if multi_exit_disc:
            bgp_neighbor[MULTI_EXIT_DISC] = multi_exit_disc

        if site_of_origins:
            bgp_neighbor[SITE_OF_ORIGINS] = site_of_origins

        if local_address:
            bgp_neighbor[LOCAL_ADDRESS] = local_address

        if local_port:
            bgp_neighbor[LOCAL_PORT] = local_port

        if local_as:
            bgp_neighbor[LOCAL_AS] = local_as

        call('neighbor.create', **bgp_neighbor)
Beispiel #55
0
 def _core_start(self, settings):
     waiter = hub.Event()
     call('core.start', waiter=waiter, **settings)
     waiter.wait()
Beispiel #56
0
    def evpn_prefix_add(self,
                        route_type,
                        route_dist,
                        esi=0,
                        ethernet_tag_id=None,
                        mac_addr=None,
                        ip_addr=None,
                        ip_prefix=None,
                        gw_ip_addr=None,
                        vni=None,
                        next_hop=None,
                        tunnel_type=None,
                        pmsi_tunnel_type=None,
                        redundancy_mode=None):
        """ This method adds a new EVPN route to be advertised.

        ``route_type`` specifies one of the EVPN route type name. The
        supported route types are EVPN_ETH_AUTO_DISCOVERY,
        EVPN_MAC_IP_ADV_ROUTE, EVPN_MULTICAST_ETAG_ROUTE, EVPN_ETH_SEGMENT
        and EVPN_IP_PREFIX_ROUTE.

        ``route_dist`` specifies a route distinguisher value.

        ``esi`` is an value to specify the Ethernet Segment Identifier.
        0 is the default and denotes a single-homed site.
        If you want to advertise esi other than 0,
        it must be set as dictionary type.
        If esi is dictionary type, 'type' key must be set
        and specifies ESI type.
        For the supported ESI type, see :py:mod:`ryu.lib.packet.bgp.EvpnEsi`.
        The remaining arguments are the same as that for
        the corresponding class.

        ``ethernet_tag_id`` specifies the Ethernet Tag ID.

        ``mac_addr`` specifies a MAC address to advertise.

        ``ip_addr`` specifies an IPv4 or IPv6 address to advertise.

        ``ip_prefix`` specifies an IPv4 or IPv6 prefix to advertise.

        ``gw_ip_addr`` specifies an IPv4 or IPv6 address of
        gateway to advertise.

        ``vni`` specifies an Virtual Network Identifier for VXLAN
        or Virtual Subnet Identifier for NVGRE.
        If tunnel_type is not TUNNEL_TYPE_VXLAN or TUNNEL_TYPE_NVGRE,
        this field is ignored.

        ``next_hop`` specifies the next hop address for this prefix.

        ``tunnel_type`` specifies the data plane encapsulation type
        to advertise.
        By the default, this attribute is not advertised.
        The supported encapsulation types are TUNNEL_TYPE_VXLAN and
        TUNNEL_TYPE_NVGRE.

        ``pmsi_tunnel_type`` specifies the type of the PMSI tunnel attribute
        used to encode the multicast tunnel identifier.
        This field is advertised only if route_type is
        EVPN_MULTICAST_ETAG_ROUTE.
        By the default, this attribute is not advertised.
        The supported PMSI tunnel types are PMSI_TYPE_NO_TUNNEL_INFO and
        PMSI_TYPE_INGRESS_REP.
        This attribute can also carry vni if tunnel_type is specified.

        ``redundancy_mode`` specifies a redundancy mode type.
        The supported redundancy mode types are REDUNDANCY_MODE_ALL_ACTIVE
        and REDUNDANCY_MODE_SINGLE_ACTIVE.
        """
        func_name = 'evpn_prefix.add_local'

        # Check the default values
        if not next_hop:
            next_hop = '0.0.0.0'

        # Set required arguments
        kwargs = {
            EVPN_ROUTE_TYPE: route_type,
            ROUTE_DISTINGUISHER: route_dist,
            NEXT_HOP: next_hop
        }

        # Set optional arguments
        if tunnel_type:
            kwargs[TUNNEL_TYPE] = tunnel_type

        # Set route type specific arguments
        if route_type == EVPN_ETH_AUTO_DISCOVERY:
            # REDUNDANCY_MODE is parameter for extended community
            kwargs.update({
                EVPN_ESI: esi,
                EVPN_ETHERNET_TAG_ID: ethernet_tag_id,
                REDUNDANCY_MODE: redundancy_mode,
            })
            if vni is not None:
                kwargs[EVPN_VNI] = vni
        elif route_type == EVPN_MAC_IP_ADV_ROUTE:
            kwargs.update({
                EVPN_ESI: esi,
                EVPN_ETHERNET_TAG_ID: ethernet_tag_id,
                MAC_ADDR: mac_addr,
                IP_ADDR: ip_addr,
            })
            # Set tunnel type specific arguments
            if tunnel_type in [TUNNEL_TYPE_VXLAN, TUNNEL_TYPE_NVGRE]:
                kwargs[EVPN_VNI] = vni
        elif route_type == EVPN_MULTICAST_ETAG_ROUTE:
            kwargs.update({
                EVPN_ETHERNET_TAG_ID: ethernet_tag_id,
                IP_ADDR: ip_addr,
            })
            # Set tunnel type specific arguments
            if tunnel_type in [TUNNEL_TYPE_VXLAN, TUNNEL_TYPE_NVGRE]:
                kwargs[EVPN_VNI] = vni
            # Set PMSI Tunnel Attribute arguments
            if pmsi_tunnel_type in [
                    PMSI_TYPE_NO_TUNNEL_INFO, PMSI_TYPE_INGRESS_REP
            ]:
                kwargs[PMSI_TUNNEL_TYPE] = pmsi_tunnel_type
            elif pmsi_tunnel_type is not None:
                raise ValueError('Unsupported PMSI tunnel type: %s' %
                                 pmsi_tunnel_type)
        elif route_type == EVPN_ETH_SEGMENT:
            kwargs.update({
                EVPN_ESI: esi,
                IP_ADDR: ip_addr,
            })
        elif route_type == EVPN_IP_PREFIX_ROUTE:
            kwargs.update({
                EVPN_ESI: esi,
                EVPN_ETHERNET_TAG_ID: ethernet_tag_id,
                IP_PREFIX: ip_prefix,
                GW_IP_ADDR: gw_ip_addr,
            })
            # Set tunnel type specific arguments
            if tunnel_type in [TUNNEL_TYPE_VXLAN, TUNNEL_TYPE_NVGRE]:
                kwargs[EVPN_VNI] = vni
        else:
            raise ValueError('Unsupported EVPN route type: %s' % route_type)

        call(func_name, **kwargs)
Beispiel #57
0
    def shutdown(self):
        """ Shutdown BGP speaker

        """
        call('core.stop')
Beispiel #58
0
    def neighbor_add(self, address, remote_as,
                     enable_ipv4=DEFAULT_CAP_MBGP_IPV4,
                     enable_vpnv4=DEFAULT_CAP_MBGP_VPNV4,
                     enable_vpnv6=DEFAULT_CAP_MBGP_VPNV6,
                     next_hop=None, password=None, multi_exit_disc=None,
                     site_of_origins=None, is_route_server_client=False):
        """ This method registers a new neighbor. The BGP speaker tries to
        establish a bgp session with the peer (accepts a connection
        from the peer and also tries to connect to it).

        ``address`` specifies the IP address of the peer. It must be
        the string representation of an IP address. Only IP v4 is
        supported now.

        ``remote_as`` specifies the AS number of the peer. It must be
        an integer between 1 and 65535.

        ``enable_ipv4`` enables IPv4 address family for this
        neighbor. The default is True.

        ``enable_vpnv4`` enables VPNv4 address family for this
        neighbor. The default is False.

        ``enable_vpnv6`` enables VPNv6 address family for this
        neighbor. The default is False.

        ``next_hop`` specifies the next hop IP address. If not
        specified, host's ip address to access to a peer is used.

        ``password`` is used for the MD5 authentication if it's
        specified. By default, the MD5 authenticaiton is disabled.

        ``multi_exit_disc`` specifies multi exit discriminator (MED) value.
        The default is None and if not specified, MED value is
        not sent to the neighbor. It must be an integer.

        ``site_of_origins`` specifies site_of_origin values.
        This parameter must be a list of string.

        ``is_route_server_client`` specifies whether this neighbor is a
        router server's client or not.
        """
        bgp_neighbor = {}
        bgp_neighbor[neighbors.IP_ADDRESS] = address
        bgp_neighbor[neighbors.REMOTE_AS] = remote_as
        bgp_neighbor[PEER_NEXT_HOP] = next_hop
        bgp_neighbor[PASSWORD] = password
        bgp_neighbor[IS_ROUTE_SERVER_CLIENT] = is_route_server_client
        # v6 advertizement is available with only v6 peering
        if netaddr.valid_ipv4(address):
            bgp_neighbor[CAP_MBGP_IPV4] = enable_ipv4
            bgp_neighbor[CAP_MBGP_IPV6] = False
            bgp_neighbor[CAP_MBGP_VPNV4] = enable_vpnv4
            bgp_neighbor[CAP_MBGP_VPNV6] = enable_vpnv6
        elif netaddr.valid_ipv6(address):
            bgp_neighbor[CAP_MBGP_IPV4] = False
            bgp_neighbor[CAP_MBGP_IPV6] = True
            bgp_neighbor[CAP_MBGP_VPNV4] = False
            bgp_neighbor[CAP_MBGP_VPNV6] = False
        else:
            # FIXME: should raise an exception
            pass

        if multi_exit_disc:
            bgp_neighbor[MULTI_EXIT_DISC] = multi_exit_disc

        if site_of_origins:
            bgp_neighbor[SITE_OF_ORIGINS] = site_of_origins

        call('neighbor.create', **bgp_neighbor)
Beispiel #59
0
 def vrfs_get(self, format='json'):
     show = {}
     show['params'] = ['vrf', 'routes', 'all']
     show['format'] = format
     return call('operator.show', **show)