summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2016-09-05 09:41:37 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-09-07 10:01:28 +0900
commitc09925e1f511d9a22a11444e0aa4d40d57bc93cf (patch)
treed8691f0ecbd05a710258f48f736e2f7bc8602cfe
parent396473593e26258f94a9596a685bcfba56ca9a08 (diff)
test_bgpspeaker: Add UT for advertising VNI for EVPN
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/tests/unit/services/protocols/bgp/core_managers/test_table_manager.py49
-rw-r--r--ryu/tests/unit/services/protocols/bgp/test_bgpspeaker.py44
-rw-r--r--ryu/tests/unit/services/protocols/bgp/utils/test_validation.py12
3 files changed, 105 insertions, 0 deletions
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 dee57a32..a53e4c43 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 243ef4b3..67ef3e97 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 dc33a966..6d5f6ac3 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))