def _test_update_flowspec_global_table(self, learn_path_mock, flowspec_family, rules, prefix, is_withdraw, actions=None): # Instantiate TableCoreManager tbl_mng = table_manager.TableCoreManager(None, None) # Test tbl_mng.update_flowspec_global_table( flowspec_family=flowspec_family, rules=rules, actions=actions, is_withdraw=is_withdraw, ) # Check call_args_list = learn_path_mock.call_args_list ok_(len(call_args_list) == 1) # learn_path should be called once args, kwargs = call_args_list[0] ok_(len(kwargs) == 0) # no keyword argument output_path = args[0] eq_(None, output_path.source) eq_(prefix, output_path.nlri.prefix) eq_(None, output_path.nexthop) eq_(is_withdraw, output_path.is_withdraw)
def _test_update_flowspec_vrf_table(self, flowspec_family, route_family, route_dist, rules, prefix, is_withdraw, actions=None): # 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_flowspec_vrf_table( flowspec_family=flowspec_family, route_dist=route_dist, rules=rules, actions=actions, is_withdraw=is_withdraw, ) # Check call_args_list = vrf_table_mock.insert_vrffs_path.call_args_list ok_(len(call_args_list) == 1) # insert_vrffs_path should be called once args, kwargs = call_args_list[0] ok_(len(args) == 0) # no positional argument eq_(prefix, kwargs['nlri'].prefix) eq_(is_withdraw, kwargs['is_withdraw'])
def _test_update_global_table(self, learn_path_mock, prefix, next_hop, is_withdraw, expected_next_hop): # Prepare test data origin = BGPPathAttributeOrigin(BGP_ATTR_ORIGIN_IGP) aspath = BGPPathAttributeAsPath([[]]) pathattrs = OrderedDict() pathattrs[BGP_ATTR_TYPE_ORIGIN] = origin pathattrs[BGP_ATTR_TYPE_AS_PATH] = aspath pathattrs = str(pathattrs) # Instantiate TableCoreManager tbl_mng = table_manager.TableCoreManager(None, None) # Test tbl_mng.update_global_table( prefix=prefix, next_hop=next_hop, is_withdraw=is_withdraw, ) # Check call_args_list = learn_path_mock.call_args_list ok_(len(call_args_list) == 1) # learn_path should be called once args, kwargs = call_args_list[0] ok_(len(kwargs) == 0) # no keyword argument output_path = args[0] eq_(None, output_path.source) eq_(prefix, output_path.nlri.prefix) eq_(pathattrs, str(output_path.pathattr_map)) eq_(expected_next_hop, output_path.nexthop) eq_(is_withdraw, output_path.is_withdraw)
def _test_update_vrf_table(self, prefix_inst, route_dist, prefix_str, next_hop, route_family, route_type, is_withdraw=False, **kwargs): # 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, is_withdraw=is_withdraw, **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_(is_withdraw, kwargs['is_withdraw']) if is_withdraw: eq_(None, kwargs['next_hop']) eq_(False, kwargs['gen_lbl']) else: eq_(next_hop, kwargs['next_hop']) eq_(True, kwargs['gen_lbl'])
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_no_vrf(self): # Prepare test data route_dist = '65000:100' ip_network = '192.168.0.0' ip_prefix_len = 24 prefix_str = '%s/%d' % (ip_network, ip_prefix_len) next_hop = '10.0.0.1' route_family = VRF_RF_IPV4 route_type = None # should be ignored kwargs = {} # should be ignored # Instantiate TableCoreManager tbl_mng = table_manager.TableCoreManager(None, None) tbl_mng._tables = {} # no table # 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, **kwargs)