Signed-off-by: IWASE Yusuke <[email protected]>
---
 .../bgp/core_managers/test_table_manager.py        | 49 ++++++++++++++++++++++
 .../unit/services/protocols/bgp/test_bgpspeaker.py | 44 +++++++++++++++++++
 .../protocols/bgp/utils/test_validation.py         | 12 ++++++
 3 files changed, 105 insertions(+)

diff --git 
a/ryu/tests/unit/services/protocols/bgp/core_managers/test_table_manager.py 
b/ryu/tests/unit/services/protocols/bgp/core_managers/test_table_manager.py
index dee57a3..a53e4c4 100644
--- a/ryu/tests/unit/services/protocols/bgp/core_managers/test_table_manager.py
+++ b/ryu/tests/unit/services/protocols/bgp/core_managers/test_table_manager.py
@@ -157,6 +157,55 @@ class Test_TableCoreManager(unittest.TestCase):
                                     next_hop, route_family, route_type,
                                     **kwargs)
 
+    @mock.patch(
+        'ryu.services.protocols.bgp.core_managers.TableCoreManager.__init__',
+        mock.MagicMock(return_value=None))
+    def test_update_vrf_table_l2_evpn_with_vni(self):
+        # Prepare test data
+        route_dist = '65000:100'
+        prefix_str = None  # should be ignored
+        kwargs = {
+            'ethernet_tag_id': 100,
+            'mac_addr': 'aa:bb:cc:dd:ee:ff',
+            'ip_addr': '192.168.0.1',
+            'vni': 500,
+        }
+        esi = EvpnArbitraryEsi(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+        prefix_inst = EvpnMacIPAdvertisementNLRI(
+            route_dist=route_dist,
+            esi=esi,
+            **kwargs)
+        next_hop = '10.0.0.1'
+        route_family = VRF_RF_L2_EVPN
+        route_type = EvpnMacIPAdvertisementNLRI.ROUTE_TYPE_NAME
+        tunnel_type = 'vxlan'
+        kwargs['esi'] = 0
+
+        # Instantiate TableCoreManager
+        tbl_mng = table_manager.TableCoreManager(None, None)
+        vrf_table_mock = mock.MagicMock()
+        tbl_mng._tables = {(route_dist, route_family): vrf_table_mock}
+
+        # Test
+        tbl_mng.update_vrf_table(
+            route_dist=route_dist,
+            prefix=prefix_str,
+            next_hop=next_hop,
+            route_family=route_family,
+            route_type=route_type,
+            tunnel_type=tunnel_type,
+            **kwargs)
+
+        # Check
+        call_args_list = vrf_table_mock.insert_vrf_path.call_args_list
+        ok_(len(call_args_list) == 1)  # insert_vrf_path should be called once
+        args, kwargs = call_args_list[0]
+        ok_(len(args) == 0)  # no positional argument
+        eq_(str(prefix_inst), str(kwargs['nlri']))
+        eq_(next_hop, kwargs['next_hop'])
+        eq_(False, kwargs['gen_lbl'])  # should not generate MPLS labels
+        eq_(tunnel_type, kwargs['tunnel_type'])
+
     def test_update_vrf_table_ipv4_withdraw(self):
         # Prepare test data
         route_dist = '65000:100'
diff --git a/ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py 
b/ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py
index 243ef4b..67ef3e9 100644
--- a/ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py
+++ b/ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py
@@ -74,6 +74,50 @@ class Test_BGPSpeaker(unittest.TestCase):
     @mock.patch('ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
                 mock.MagicMock(return_value=None))
     @mock.patch('ryu.services.protocols.bgp.bgpspeaker.call')
+    def test_evpn_prefix_add_mac_ip_adv_vni(self, mock_call):
+        # Prepare test data
+        route_type = bgpspeaker.EVPN_MAC_IP_ADV_ROUTE
+        route_dist = '65000:100'
+        esi = 0  # denotes single-homed
+        ethernet_tag_id = 200
+        mac_addr = 'aa:bb:cc:dd:ee:ff'
+        ip_addr = '192.168.0.1'
+        vni = 500
+        next_hop = '10.0.0.1'
+        tunnel_type = bgpspeaker.TUNNEL_TYPE_VXLAN
+        expected_kwargs = {
+            'route_type': route_type,
+            'route_dist': route_dist,
+            'esi': esi,
+            'ethernet_tag_id': ethernet_tag_id,
+            'mac_addr': mac_addr,
+            'ip_addr': ip_addr,
+            'vni': vni,
+            'next_hop': next_hop,
+            'tunnel_type': tunnel_type,
+        }
+
+        # Test
+        speaker = bgpspeaker.BGPSpeaker(65000, '10.0.0.1')
+        speaker.evpn_prefix_add(
+            route_type=route_type,
+            route_dist=route_dist,
+            esi=esi,
+            ethernet_tag_id=ethernet_tag_id,
+            mac_addr=mac_addr,
+            ip_addr=ip_addr,
+            vni=vni,
+            next_hop=next_hop,
+            tunnel_type=tunnel_type,
+        )
+
+        # Check
+        mock_call.assert_called_with(
+            'evpn_prefix.add_local', **expected_kwargs)
+
+    @mock.patch('ryu.services.protocols.bgp.bgpspeaker.BGPSpeaker.__init__',
+                mock.MagicMock(return_value=None))
+    @mock.patch('ryu.services.protocols.bgp.bgpspeaker.call')
     def test_evpn_prefix_add_multicast_etag(self, mock_call):
         # Prepare test data
         route_type = bgpspeaker.EVPN_MULTICAST_ETAG_ROUTE
diff --git a/ryu/tests/unit/services/protocols/bgp/utils/test_validation.py 
b/ryu/tests/unit/services/protocols/bgp/utils/test_validation.py
index dc33a96..6d5f6ac 100644
--- a/ryu/tests/unit/services/protocols/bgp/utils/test_validation.py
+++ b/ryu/tests/unit/services/protocols/bgp/utils/test_validation.py
@@ -201,3 +201,15 @@ class Test_Utils_Validation(unittest.TestCase):
 
     def test_is_valid_ethernet_tag_id_over(self):
         eq_(False, validation.is_valid_ethernet_tag_id(0xffffffff + 1))
+
+    def test_is_valid_vni(self):
+        ok_(validation.is_valid_vni(100))
+
+    def test_is_valid_vni_not_int(self):
+        eq_(False, validation.is_valid_vni('foo'))
+
+    def test_is_valid_vni_negative(self):
+        eq_(False, validation.is_valid_vni(-1))
+
+    def test_is_valid_vni_over(self):
+        eq_(False, validation.is_valid_vni(0xffffff + 1))
-- 
2.7.4


------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to