Hi Albert, I have posted the patch to solve the problem you pointed out. Could you test my patch? [Ryu-devel] [PATCH] BGPSpeaker: Support to advertise Type 1,2 Route Targe
Thanks, Iwase On 2017年01月30日 11:29, Iwase Yusuke wrote: > Hi, > > Thank you for pointing out! > > I searched Ryu BGP source code, currently, Ryu seems to support only type 0 > RT. > > https://github.com/osrg/ryu/blob/master/ryu/services/protocols/bgp/info_base/vrf.py#L269-L282 > > For a short fix, how about the following? > (Not enough tested, though...) > > > $ git diff > diff --git a/ryu/services/protocols/bgp/info_base/vrf.py > b/ryu/services/protocols/bgp/info_base/vrf.py > index c4e41ef..4de5b4e 100644 > --- a/ryu/services/protocols/bgp/info_base/vrf.py > +++ b/ryu/services/protocols/bgp/info_base/vrf.py > @@ -21,6 +21,8 @@ import abc > import logging > import six > > +import netaddr > + > from ryu.lib.packet.bgp import BGP_ATTR_TYPE_ORIGIN > from ryu.lib.packet.bgp import BGP_ATTR_TYPE_AS_PATH > from ryu.lib.packet.bgp import BGP_ATTR_TYPE_EXTENDED_COMMUNITIES > @@ -31,6 +33,8 @@ from ryu.lib.packet.bgp import BGPPathAttributeAsPath > from ryu.lib.packet.bgp import EvpnEthernetSegmentNLRI > from ryu.lib.packet.bgp import BGPPathAttributeExtendedCommunities > from ryu.lib.packet.bgp import BGPTwoOctetAsSpecificExtendedCommunity > +from ryu.lib.packet.bgp import BGPIPv4AddressSpecificExtendedCommunity > +from ryu.lib.packet.bgp import BGPFourOctetAsSpecificExtendedCommunity > from ryu.lib.packet.bgp import BGPPathAttributeMultiExitDisc > from ryu.lib.packet.bgp import BGPEncapsulationExtendedCommunity > from ryu.lib.packet.bgp import BGPEvpnEsiLabelExtendedCommunity > @@ -266,20 +270,34 @@ class VrfTable(Table): > subtype=subtype, > es_import=es_import)) > > + def _create_rt_ext_com(route_target, subtype): > + global_admin, local_admin = route_target.split(':') > + if netaddr.valid_ipv4(global_admin): > + com = BGPIPv4AddressSpecificExtendedCommunity( > + subtype=subtype, > + ipv4_address=global_admin, > + local_administrator=int(local_admin)) > + elif (global_admin.isdigit() > + and 0 <= int(global_admin) <= 0xffff): > + com = BGPTwoOctetAsSpecificExtendedCommunity( > + subtype=subtype, > + as_number=int(global_admin), > + local_administrator=int(local_admin)) > + elif (global_admin.isdigit() > + and 0xffff < int(global_admin) <= 0xffffffff): > + com = BGPFourOctetAsSpecificExtendedCommunity( > + subtype=subtype, > + as_number=int(global_admin), > + local_administrator=int(local_admin)) > + else: > + raise ValueError( > + 'Invalid route target: %s' % route_target) > + return com > + > for rt in vrf_conf.export_rts: > - as_num, local_admin = rt.split(':') > - subtype = 2 > - communities.append(BGPTwoOctetAsSpecificExtendedCommunity( > - as_number=int(as_num), > - local_administrator=int(local_admin), > - subtype=subtype)) > + communities.append(_create_rt_ext_com(rt, 2)) > for soo in vrf_conf.soo_list: > - as_num, local_admin = soo.split(':') > - subtype = 3 > - communities.append(BGPTwoOctetAsSpecificExtendedCommunity( > - as_number=int(as_num), > - local_administrator=int(local_admin), > - subtype=subtype)) > + communities.append(_create_rt_ext_com(soo, 3)) > > # Set Tunnel Encapsulation Attribute > tunnel_type = kwargs.get('tunnel_type', None) > > > Thanks, > Iwase > > > On 2017年01月27日 21:52, Albert Siersema wrote: >> Hi all, >> >> Is anyone working on BGP auto RD support, which in turn needs support >> for the "IP address" RD notation: >> <IP address>:<ID e.g. VNI> >> instead of <ASN-2>:<ID> >> Or have I overlooked something in the code which already enables these >> features ? >> If not I'll have a go at implementing this. >> >> I tried the following: >> >> vni = 655370 >> loopback_IP = "10.1.1.1" >> evpn_route_dist='{}:{}'.format(loopback_IP, vni) >> speaker.vrf_add( >> route_dist=evpn_route_dist, >> route_family=RF_L2_EVPN, >> import_rts=[evpn_route_dist], >> export_rts=[evpn_route_dist] >> ) >> >> Traceback (most recent call last): >> File >> "/usr/local/lib/python2.7/dist-packages/ryu/services/protocols/bgp/api/base.py", >> line 205, in >> call >> return call(**kwargs) >> File >> "/usr/local/lib/python2.7/dist-packages/ryu/services/protocols/bgp/api/base.py", >> line 173, in >> wrapped_fun >> return func(*req_values, **opt_items) >> File >> "/usr/local/lib/python2.7/dist-packages/ryu/services/protocols/bgp/api/prefix.py", >> line 308, in >> add_evpn_local >> route_type=route_type, **kwargs) >> File >> "/usr/local/lib/python2.7/dist-packages/ryu/services/protocols/bgp/core_managers/table_manager.py", >> line 576, in >> update_vrf_table >> pmsi_tunnel_type=pmsi_tunnel_type) >> File >> "/usr/local/lib/python2.7/dist-packages/ryu/services/protocols/bgp/info_base/vrf.py", >> line 274, in >> insert_vrf_path >> as_number=int(as_num), >> ValueError: invalid literal for int() with base 10: '10.1.1.1' >> >> Traceback (most recent call last): >> File "./bgp-ryu.py", line 198, in <module> >> bgp_speaker = myBGP() >> File "./bgp-ryu.py", line 51, in __init__ >> self.start_BGP() >> File "./bgp-ryu.py", line 164, in start_BGP >> next_hop=loopback_IPv4, >> File >> "/usr/local/lib/python2.7/dist-packages/ryu/services/protocols/bgp/bgpspeaker.py", >> line 671, in >> evpn_prefix_add >> call(func_name, **kwargs) >> File >> "/usr/local/lib/python2.7/dist-packages/ryu/services/protocols/bgp/api/base.py", >> line 211, in >> call >> raise ApiException(desc=str(e)) >> ryu.services.protocols.bgp.api.base.ApiException: 500.1 - invalid >> literal for int() with base 10: '10.1.1.1' >> >> >> Or converting the IP address to int (like an 4-byte ASN): >> >> vni = 655370 >> loopback_IP = "10.1.1.1" >> IPv4_as_int = int(ipaddress.IPv4Address(unicode(loopback_IP))) >> evpn_route_dist='{}:{}'.format(IPv4_as_int, vni) >> speaker.vrf_add( >> route_dist=evpn_route_dist, >> route_family=RF_L2_EVPN, >> import_rts=[evpn_route_dist], >> export_rts=[evpn_route_dist] >> ) >> >> File "/usr/local/lib/python2.7/dist-packages/ryu/lib/packet/bgp.py", >> line 193, in serialize_value >> return struct.pack(self._VALUE_PACK_STR, *args) >> error: 'H' format requires 0 <= number <= 65535 >> >> >> https://tools.ietf.org/html/draft-ietf-l2vpn-evpn-11#section-7.9 >> "It is RECOMMENDED to use the Type 1 RD [RFC4364]. The value field >> comprises an IP address of the PE (typically, the loopback address) >> followed by a number unique to the PE. This number may be generated by the >> PE. Or in the Unique VLAN EVPN case, the low order 12 bits may be the 12 >> bit VLAN ID, with the remaining high order 4 bits set to 0" >> Also: https://tools.ietf.org/html/rfc4364#section-4.2 >> >> Although the RFC's mention "Type 1 RD" limited to 12 bit VLAN ID's, >> RD's can actually be composed of 2-byte ASN, 4-byte ASN plus VXLAN >> VNI's. >> >> Working support for auto generated RD/RT is implemented by various >> vendors, e.g. : >> >> Cumulus "Enable EVPN with Automatic RDs and RTs": >> router bgp 65000 >> address-family evpn >> neighbor swp1 activate >> advertise-vni >> >> Juniper >> vrf-target { >> community; >> auto >> import community-name; >> export community-name; >> } >> >> Cisco (NX-OS): >> evpn >> vni <VNI> l2 >> rd auto >> route-target import auto >> route-target export auto >> >> >> Regards, >> Albert >> >> >> ------------------------------------------------------------------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, SlashDot.org! http://sdm.link/slashdot >> _______________________________________________ >> Ryu-devel mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/ryu-devel >> ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
