mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-05-08 22:06:10 +02:00
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>
This commit is contained in:
parent
396473593e
commit
c09925e1f5
@ -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'
|
||||
|
||||
@ -71,6 +71,50 @@ class Test_BGPSpeaker(unittest.TestCase):
|
||||
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_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')
|
||||
|
||||
@ -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))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user