This patch enables BGPSpeaker to set the capability for IPv6 unicast
address family.

Signed-off-by: IWASE Yusuke <iwase.yusu...@gmail.com>
---
 ryu/services/protocols/bgp/bgp_sample_conf.py | 32 ++++++++++++++++++++++-----
 ryu/services/protocols/bgp/bgpspeaker.py      | 26 +++++++++-------------
 ryu/tests/integrated/common/ryubgp.py         | 11 +++++----
 3 files changed, 42 insertions(+), 27 deletions(-)

diff --git a/ryu/services/protocols/bgp/bgp_sample_conf.py 
b/ryu/services/protocols/bgp/bgp_sample_conf.py
index 4c40fef..a15192d 100644
--- a/ryu/services/protocols/bgp/bgp_sample_conf.py
+++ b/ryu/services/protocols/bgp/bgp_sample_conf.py
@@ -1,6 +1,7 @@
 import os
 
 from ryu.services.protocols.bgp.bgpspeaker import RF_VPN_V4
+from ryu.services.protocols.bgp.bgpspeaker import RF_VPN_V6
 from ryu.services.protocols.bgp.bgpspeaker import RF_L2_EVPN
 from ryu.services.protocols.bgp.bgpspeaker import EVPN_MAC_IP_ADV_ROUTE
 from ryu.services.protocols.bgp.bgpspeaker import TUNNEL_TYPE_VXLAN
@@ -25,11 +26,13 @@ BGP = {
             'address': '172.17.0.2',
             'remote_as': 65002,
             'enable_ipv4': True,
+            'enable_ipv6': True,
             'enable_vpnv4': True,
+            'enable_vpnv6': True,
         },
         {
             'address': '172.17.0.3',
-            'remote_as': 65000,
+            'remote_as': 65001,
             'enable_evpn': True,
         },
     ],
@@ -38,16 +41,25 @@ BGP = {
     # The parameters for each VRF table are the same as the arguments of
     # BGPSpeaker.vrf_add() method.
     'vrfs': [
+        # Example of VRF for IPv4
         {
             'route_dist': '65001:100',
             'import_rts': ['65001:100'],
             'export_rts': ['65001:100'],
             'route_family': RF_VPN_V4,
         },
+        # Example of VRF for IPv6
         {
-            'route_dist': '65000:200',
-            'import_rts': ['65000:200'],
-            'export_rts': ['65000:200'],
+            'route_dist': '65001:150',
+            'import_rts': ['65001:150'],
+            'export_rts': ['65001:150'],
+            'route_family': RF_VPN_V6,
+        },
+        # Example of VRF for EVPN
+        {
+            'route_dist': '65001:200',
+            'import_rts': ['65001:200'],
+            'export_rts': ['65001:200'],
             'route_family': RF_L2_EVPN,
         },
     ],
@@ -66,10 +78,20 @@ BGP = {
             'next_hop': '172.17.0.1',
             'route_dist': '65001:100',
         },
+        # Example of IPv6 prefix
+        {
+            'prefix': '2001:db8:1::/64',
+        },
+        # Example of VPNv6 prefix
+        {
+            'prefix': '2001:db8:2::/64',
+            'next_hop': '172.17.0.1',
+            'route_dist': '65001:150',
+        },
         # Example of EVPN prefix
         {
             'route_type': EVPN_MAC_IP_ADV_ROUTE,
-            'route_dist': '65000:200',
+            'route_dist': '65001:200',
             'esi': 0,
             'ethernet_tag_id': 0,
             'tunnel_type': TUNNEL_TYPE_VXLAN,
diff --git a/ryu/services/protocols/bgp/bgpspeaker.py 
b/ryu/services/protocols/bgp/bgpspeaker.py
index 4934e41..9e30d3e 100644
--- a/ryu/services/protocols/bgp/bgpspeaker.py
+++ b/ryu/services/protocols/bgp/bgpspeaker.py
@@ -64,6 +64,7 @@ from ryu.services.protocols.bgp.rtconf.base import 
CAP_FOUR_OCTET_AS_NUMBER
 from ryu.services.protocols.bgp.rtconf.base import MULTI_EXIT_DISC
 from ryu.services.protocols.bgp.rtconf.base import SITE_OF_ORIGINS
 from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_IPV4
+from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_IPV6
 from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_VPNV4
 from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_VPNV6
 from ryu.services.protocols.bgp.rtconf.neighbors import DEFAULT_CAP_MBGP_EVPN
@@ -289,6 +290,7 @@ class BGPSpeaker(object):
 
     def neighbor_add(self, address, remote_as,
                      enable_ipv4=DEFAULT_CAP_MBGP_IPV4,
+                     enable_ipv6=DEFAULT_CAP_MBGP_IPV6,
                      enable_vpnv4=DEFAULT_CAP_MBGP_VPNV4,
                      enable_vpnv6=DEFAULT_CAP_MBGP_VPNV6,
                      enable_evpn=DEFAULT_CAP_MBGP_EVPN,
@@ -313,6 +315,9 @@ class BGPSpeaker(object):
         ``enable_ipv4`` enables IPv4 address family for this
         neighbor. The default is True.
 
+        ``enable_ipv6`` enables IPv6 address family for this
+        neighbor. The default is False.
+
         ``enable_vpnv4`` enables VPNv4 address family for this
         neighbor. The default is False.
 
@@ -371,23 +376,12 @@ class BGPSpeaker(object):
             CONNECT_MODE: connect_mode,
             CAP_ENHANCED_REFRESH: enable_enhanced_refresh,
             CAP_FOUR_OCTET_AS_NUMBER: enable_four_octet_as_number,
+            CAP_MBGP_IPV4: enable_ipv4,
+            CAP_MBGP_IPV6: enable_ipv6,
+            CAP_MBGP_VPNV4: enable_vpnv4,
+            CAP_MBGP_VPNV6: enable_vpnv6,
+            CAP_MBGP_EVPN: enable_evpn,
         }
-        # 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
diff --git a/ryu/tests/integrated/common/ryubgp.py 
b/ryu/tests/integrated/common/ryubgp.py
index 5b5114a..35c9afe 100644
--- a/ryu/tests/integrated/common/ryubgp.py
+++ b/ryu/tests/integrated/common/ryubgp.py
@@ -18,8 +18,6 @@ from __future__ import absolute_import
 import logging
 import time
 
-import netaddr
-
 from . import docker_base as base
 
 LOG = logging.getLogger(__name__)
@@ -61,9 +59,10 @@ class RyuBGPContainer(base.BGPContainer):
             n_addr = info['neigh_addr'].split('/')[0]
             c << "            'address': '%s'," % n_addr
             c << "            'remote_as': %s," % str(peer.asn)
-            if netaddr.IPNetwork(n_addr).version == 4:
-                c << "            'enable_ipv4': True,"
-                c << "            'enable_vpnv4': True,"
+            c << "            'enable_ipv4': True,"
+            c << "            'enable_ipv6': True,"
+            c << "            'enable_vpnv4': True,"
+            c << "            'enable_vpnv6': True,"
             c << '        },'
             c << '    ],'
         c << "    'routes': ["
@@ -201,7 +200,7 @@ class RyuBGPContainer(base.BGPContainer):
             time.sleep(1)
         return result
 
-    def run(self, wait=False):
+    def run(self, wait=False, w_time=WAIT_FOR_BOOT):
         w_time = super(RyuBGPContainer,
                        self).run(wait=wait, w_time=self.WAIT_FOR_BOOT)
         return w_time
-- 
2.7.4


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to