bool nas_acl_counter_t::_validate_entry_counter (counter c_type, npu_id_t npu_id, ndi_obj_id_t *ndi_counter_id_p) const noexcept { switch (c_type) { case counter::PKT: if (!is_pkt_count_enabled ()) { NAS_ACL_LOG_ERR ("Packet counter NOT enabled for counter %ld\n", counter_id()); return false; } break; case counter::BYTE: if (!is_byte_count_enabled ()) { NAS_ACL_LOG_ERR ("Byte counter NOT enabled for counter %ld\n", counter_id()); return false; } break; } auto it = _ndi_obj_ids.find (npu_id); if (it == _ndi_obj_ids.end()) { NAS_ACL_LOG_ERR ("ACL Counter %ld not available in this NPU %d\n", counter_id(), npu_id); return false; } *ndi_counter_id_p = it->second; return true; }
bool nas_acl_fill_action_attr (cps_api_object_t obj, const nas_acl_action_t& action, BASE_ACL_ACTION_TYPE_t action_type_val, nas::attr_list_t parent_attr_id_list) { nas_acl_common_data_list_t common_data_list; auto map_kv = nas_acl_get_action_map().find (action_type_val); if (map_kv == nas_acl_get_action_map().end ()) { return false; } const nas_acl_action_info_t& map_info = map_kv->second; (action.*(map_info.get_fn)) (common_data_list); parent_attr_id_list.push_back (map_info.val.attr_id); if (!nas_acl_copy_data_to_obj (obj, parent_attr_id_list, map_info.val, map_info.child_list, common_data_list)) { NAS_ACL_LOG_ERR ("nas_acl_copy_data_to_obj() failed for Match type %d (%s)", action_type_val, nas_acl_action_t::type_name (action_type_val)); return false; } return true; }
bool nas_acl_fill_action_attr_list (cps_api_object_t obj, const nas_acl_entry& entry) { nas::attr_list_t parent_attr_id_list; cps_api_attr_id_t list_index = 0; BASE_ACL_ACTION_TYPE_t action_type_val; nas_acl_common_data_list_t common_data_list; // Parent attr list to build attr hierarchy // - ACTION-List-Attr . Action-ListIndex . Action-Value-Attr . Action-Value-Child-Attr parent_attr_id_list.reserve(NAS_ACL_MAX_ATTR_DEPTH); // Of this the following hierarchy is filled in this function // - ACTION-List-Attr . Action-ListIndex for (const auto& action_kv: entry.get_action_list ()) { action_type_val = action_kv.second.action_type (); auto map_kv = nas_acl_get_action_map().find (action_type_val); if (map_kv == nas_acl_get_action_map().end ()) { return false; } const nas_acl_action_info_t& map_info = map_kv->second; parent_attr_id_list.clear (); parent_attr_id_list.push_back (BASE_ACL_ENTRY_ACTION); parent_attr_id_list.push_back (list_index); parent_attr_id_list.push_back (BASE_ACL_ENTRY_ACTION_TYPE); if (!cps_api_object_e_add (obj, parent_attr_id_list.data (), parent_attr_id_list.size (), cps_api_object_ATTR_T_U32, &action_type_val, sizeof (uint32_t))) { return false; } parent_attr_id_list.pop_back (); if (map_info.val.data_type != NAS_ACL_DATA_NONE) { if (!nas_acl_fill_action_attr (obj, action_kv.second, action_type_val, parent_attr_id_list)) { NAS_ACL_LOG_ERR ("nas_acl_copy_data_to_obj() failed for Match type %d (%s)", action_type_val, nas_acl_action_t::type_name (action_type_val)); return false; } } list_index++; } return true; }
static t_std_error _cps_init () { cps_api_operation_handle_t handle; cps_api_return_code_t rc; cps_api_registration_functions_t f; rc = cps_api_operation_subsystem_init (&handle,1); if (rc != cps_api_ret_code_OK) { NAS_ACL_LOG_ERR ("NAS ACL CPS Subsystem Init failed"); return STD_ERR(QOS, FAIL, rc); } memset (&f, 0, sizeof(f)); f.handle = handle; f._read_function = nas_acl_cps_api_read; f._write_function = nas_acl_cps_api_write; f._rollback_function = nas_acl_cps_api_rollback; /* * Register all ACL objects * TODO: Need to check with CPS app teams, if ACL needs to register for * OBSERVED state. */ cps_api_key_init (&f.key, cps_api_qualifier_TARGET, cps_api_obj_CAT_BASE_ACL, 0, /* register all sub-categories */ 0); rc = cps_api_register (&f); if (rc != cps_api_ret_code_OK) { NAS_ACL_LOG_ERR ("NAS ACL CPS object Register failed"); return STD_ERR(QOS, FAIL, rc); } return STD_ERR_OK; }
void nas_acl_action_t::set_action_ifindex_list (const nas_acl_common_data_list_t& val_list) { _a_info.values_type = NDI_ACL_ACTION_PORTLIST; for (auto match_data: val_list) { for (auto port: match_data.ifindex_list) { if (nas_acl_utl_is_ifidx_type_lag(port)) { NAS_ACL_LOG_ERR("LAG port %d is not allowed to be added to port list", port); continue; } _ifindex_list.push_back (port); } } }
t_std_error nas_acl_counter_t::get_byte_count_ndi (npu_id_t npu_id, uint64_t* byte_count_p) const noexcept { t_std_error rc = STD_ERR_OK; ndi_obj_id_t ndi_counter_id = 0; if (!_validate_entry_counter (counter::BYTE, npu_id, &ndi_counter_id)) { return NAS_ACL_E_INCONSISTENT; } if ((rc = ndi_acl_counter_get_byte_count (npu_id, ndi_counter_id, byte_count_p)) != STD_ERR_OK) { NAS_ACL_LOG_ERR ("NDI Byte counter Get returned error %d for NPU %d\n", rc, npu_id); return rc; } return NAS_ACL_E_NONE; }