bool cps_api_obj_tool_merge(cps_api_object_t main, cps_api_object_t overlay) {
    cps_api_object_it_t it;

    cps_api_object_it_begin(overlay,&it);
    do {
        CPS_CLASS_ATTR_TYPES_t _type;
        if (!cps_class_map_attr_class(cps_api_object_attr_id(it.attr),&_type)) {
            _type = CPS_CLASS_ATTR_T_LEAF;
        }
        do {
            cps_api_attr_id_t _id = cps_api_object_attr_id(it.attr);
            cps_api_object_attr_delete(main,_id);
            if (_type==CPS_CLASS_ATTR_T_LEAF_LIST) {
                if (cps_api_object_attr_get(main,_id)!=nullptr) {
                    continue;
                }
            }
        } while (0);
    } while (cps_api_object_it_next(&it));

    cps_api_object_it_begin(overlay,&it);
    do {
        size_t _attr_len = cps_api_object_attr_len(it.attr);
        if (_attr_len==0) continue;
        if (!cps_api_object_attr_add(main,cps_api_object_attr_id(it.attr),cps_api_object_attr_data_bin(it.attr),
                _attr_len)) {
            return false;
        }
    } while (cps_api_object_it_next(&it));
    return true;
}
static bool get_src_intf_attr(cps_api_object_t obj, nas_mirror_src_intf_map_t & intf_map,
                              const cps_api_object_it_t & it){

    cps_api_object_it_t it_lvl_1 = it;
    cps_api_attr_id_t ids[3] = {BASE_MIRROR_ENTRY_INTF,0, BASE_MIRROR_ENTRY_INTF_SRC };
    const int ids_len = sizeof(ids)/sizeof(ids[0]);

    for (cps_api_object_it_inside (&it_lvl_1); cps_api_object_it_valid (&it_lvl_1);
         cps_api_object_it_next (&it_lvl_1)) {

        ids[1] = cps_api_object_attr_id (it_lvl_1.attr);
        ids[2]=BASE_MIRROR_ENTRY_INTF_SRC;
        cps_api_object_attr_t src_intf = cps_api_object_e_get(obj,ids,ids_len);
        ids[2]=BASE_MIRROR_ENTRY_INTF_DIRECTION;
        cps_api_object_attr_t direction = cps_api_object_e_get(obj,ids,ids_len);

        if(src_intf == NULL){
            NAS_MIRROR_LOG(ERR,0,"Source Interface Index not passed for creating/updating a session");
            return false;
        }

        if(direction == NULL){
           NAS_MIRROR_LOG(ERR,0,"Mirroring Direction not passed for creating/updating a session");
           return false;
        }
        hal_ifindex_t ifindex = cps_api_object_attr_data_u32(src_intf);
        BASE_CMN_TRAFFIC_PATH_t dir = (BASE_CMN_TRAFFIC_PATH_t)cps_api_object_attr_data_u32(direction);
        if(intf_map.find(ifindex) == intf_map.end()){
            intf_map[ifindex] = dir;
        }
    }

    return true;
}
void nas_route_dump_peer_routing_object_content(cps_api_object_t obj){
    cps_api_object_it_t it;
    cps_api_object_it_begin(obj,&it);

    for ( ; cps_api_object_it_valid(&it) ; cps_api_object_it_next(&it) ) {

        switch (cps_api_object_attr_id(it.attr)) {

        case BASE_ROUTE_PEER_ROUTING_CONFIG_VRF_ID:
            std::cout<<"VRF Id "<<cps_api_object_attr_data_u32(it.attr)<<std::endl;
            break;

        case BASE_ROUTE_PEER_ROUTING_CONFIG_PEER_MAC_ADDR:
        {
              char mt[6];
              char mstring[20];
              memcpy(mt, cps_api_object_attr_data_bin(it.attr), 6);
              sprintf(mstring, "%x:%x:%x:%x:%x:%x", mt[0], mt[1], mt[2], mt[3], mt[4], mt[5]);
              std::cout<<"MAC "<<mstring<<std::endl;
        }
            break;

        default:
            break;
        }
    }
}
/* Parse the attributes */
static cps_api_return_code_t  nas_qos_cps_parse_attr(cps_api_object_t obj,
                                              nas_qos_priority_group &priority_group)
{
    uint64_t val;
    cps_api_object_it_t it;
    cps_api_object_it_begin(obj,&it);
    for ( ; cps_api_object_it_valid(&it) ; cps_api_object_it_next(&it) ) {
        cps_api_attr_id_t id = cps_api_object_attr_id(it.attr);
        switch (id) {
        case BASE_QOS_PRIORITY_GROUP_PORT_ID:
        case BASE_QOS_PRIORITY_GROUP_LOCAL_ID:
        case BASE_QOS_PRIORITY_GROUP_ID:
            break; // These are not settable from cps

        case BASE_QOS_PRIORITY_GROUP_BUFFER_PROFILE_ID:
            val = cps_api_object_attr_data_u64(it.attr);
            priority_group.mark_attr_dirty(id);
            priority_group.set_buffer_profile(val);
            break;

        case CPS_API_ATTR_RESERVE_RANGE_END:
            // skip keys
            break;

        default:
            EV_LOG_TRACE(ev_log_t_QOS, ev_log_s_MAJOR, "QOS", "Unrecognized option: %d", id);
            return NAS_QOS_E_UNSUPPORTED;
        }
    }


    return cps_api_ret_code_OK;
}
bool nas::ndi_obj_id_table_cps_unserialize (ndi_obj_id_table_t&  table,
                                            cps_api_object_t cps_obj,
                                            cps_api_attr_id_t *attr_id_list,
                                            size_t attr_id_size)
{
    cps_api_object_it_t it_list;

    if (!cps_api_object_it(cps_obj, attr_id_list, attr_id_size, &it_list)) {
        // Opaque data not found
        NAS_COM_ERR ("Could not find opaque attribute \n");
        return false;
    }

    int inst = 0;
    nas::ndi_obj_id_table_t  temp_table;

    for (cps_api_object_it_inside (&it_list); cps_api_object_it_valid(&it_list);
         cps_api_object_it_next (&it_list), inst++) {

        npu_id_t npu_id = 0;
        ndi_obj_id_t ndi_obj_id = 0;

        NAS_COM_TRACE (3, "Unserializing entry %d\n", inst+1);

        cps_api_object_it_t it_map_entry = it_list;

        for (cps_api_object_it_inside (&it_map_entry); cps_api_object_it_valid (&it_map_entry);
             cps_api_object_it_next (&it_map_entry)) {

            switch (cps_api_object_attr_id (it_map_entry.attr)) {
                case OPAQUE_NPU_ATTR_ID:
                    npu_id = cps_api_object_attr_data_u32 (it_map_entry.attr);
                    NAS_COM_TRACE (3, "NPU ID %d\n", npu_id);
                    break;
                case OPAQUE_NDI_OBJ_ATTR_ID:
                    ndi_obj_id = cps_api_object_attr_data_u64 (it_map_entry.attr);
                    NAS_COM_TRACE (3, "NDI Obj ID 0x%lx\n", ndi_obj_id);
                    break;
            }
        }
        temp_table[npu_id] = ndi_obj_id;
    }

    table = std::move (temp_table);
    return true;
}
示例#6
0
t_std_error nas_sflow_update_session(cps_api_object_t obj, nas_sflow_id_t id){

    unsigned int prev_sampling_rate;
    std_mutex_simple_lock_guard lock(&nas_sflow_mutex);

    nas_sflow_map_it sit = nas_sflow_table.find(id);

    if(sit == nas_sflow_table.end()){
        NAS_SFLOW_LOG(ERR,ev_log_s_MINOR,"No NAS sFlow session with Id %d exist",(int)id);
        return STD_ERR(SFLOW,NEXIST,0);
    }
    nas_sflow_entry_t & sflow_entry =  sit->second;

    cps_api_object_it_t it;
    cps_api_object_it_begin(obj,&it);

    for ( ; cps_api_object_it_valid(&it) ; cps_api_object_it_next(&it) ) {
        int attr_id = (int) cps_api_object_attr_id(it.attr);

        switch (attr_id) {

        case BASE_SFLOW_ENTRY_DIRECTION :
            if(sflow_entry.ndi_sflow_entry.sflow_direction != (BASE_CMN_TRAFFIC_PATH_t)
                    cps_api_object_attr_data_u32(it.attr)){
                if(!nas_sflow_update_session_attr(&(sflow_entry.ndi_sflow_entry),
                        BASE_SFLOW_ENTRY_DIRECTION,cps_api_object_attr_data_u32(it.attr))){
                        return STD_ERR(SFLOW,FAIL,0);
                }
                sflow_entry.ndi_sflow_entry.sflow_direction = (BASE_CMN_TRAFFIC_PATH_t)
                                                   cps_api_object_attr_data_u32(it.attr);
                NAS_SFLOW_LOG(INFO,3,"Updated sFlow session %d direction to %d",sflow_entry.nas_sflow_id,
                            sflow_entry.ndi_sflow_entry.sflow_direction);
            }
            break;

        case BASE_SFLOW_ENTRY_SAMPLING_RATE :
            if(sflow_entry.ndi_sflow_entry.sampling_rate != cps_api_object_attr_data_u32(it.attr)){
                prev_sampling_rate = sflow_entry.ndi_sflow_entry.sampling_rate;
                sflow_entry.ndi_sflow_entry.sampling_rate = cps_api_object_attr_data_u32(it.attr);
                if(!nas_sflow_update_session_attr(&(sflow_entry.ndi_sflow_entry),
                        BASE_SFLOW_ENTRY_SAMPLING_RATE, cps_api_object_attr_data_u32(it.attr))){
                    sflow_entry.ndi_sflow_entry.sampling_rate = prev_sampling_rate;
                    return STD_ERR(SFLOW,FAIL,0);
                }
                NAS_SFLOW_LOG(INFO,3,"Updated sFlow session %d sampling rate to %d",sflow_entry.nas_sflow_id,
                                    sflow_entry.ndi_sflow_entry.sampling_rate);
            }
            break;

        default:
            break;
        }
    }
    return STD_ERR_OK;
}
/* Parse the attributes */
static cps_api_return_code_t  nas_qos_cps_parse_attr(cps_api_object_t obj,
                                              nas_qos_scheduler_group &scheduler_group)
{
    uint_t val;
    uint64_t val64;
    cps_api_object_it_t it;
    cps_api_object_it_begin(obj,&it);
    for ( ; cps_api_object_it_valid(&it) ; cps_api_object_it_next(&it) ) {
        cps_api_attr_id_t id = cps_api_object_attr_id(it.attr);
        switch (id) {
        case BASE_QOS_SCHEDULER_GROUP_SWITCH_ID:
        case BASE_QOS_SCHEDULER_GROUP_ID:
            break; // These are for part of the keys

        case BASE_QOS_SCHEDULER_GROUP_CHILD_COUNT:
        case BASE_QOS_SCHEDULER_GROUP_CHILD_LIST:
            // non-configurable.
            break;


        case BASE_QOS_SCHEDULER_GROUP_PORT_ID:
            val = cps_api_object_attr_data_u32(it.attr);
            if (scheduler_group.set_port_id(val) != STD_ERR_OK)
                return NAS_QOS_E_FAIL;
            break;

        case BASE_QOS_SCHEDULER_GROUP_LEVEL:
            val = cps_api_object_attr_data_u32(it.attr);
            scheduler_group.set_level(val);
            break;

        case BASE_QOS_SCHEDULER_GROUP_SCHEDULER_PROFILE_ID:
            val64 = cps_api_object_attr_data_u64(it.attr);
            scheduler_group.set_scheduler_profile_id(val64);
            break;

        case CPS_API_ATTR_RESERVE_RANGE_END:
            // skip keys
            break;

       default:
            EV_LOG_TRACE(ev_log_t_QOS, ev_log_s_MAJOR, "QOS", "Unrecognized option: %d", id);
            return NAS_QOS_E_UNSUPPORTED;
        }
    }


    return cps_api_ret_code_OK;
}
void nas_route_dump_arp_object_content(cps_api_object_t obj){
    cps_api_object_it_t it;
    cps_api_object_it_begin(obj,&it);
    char str[INET_ADDRSTRLEN];


    for ( ; cps_api_object_it_valid(&it) ; cps_api_object_it_next(&it) ) {

        switch (cps_api_object_attr_id(it.attr)) {

        case BASE_ROUTE_OBJ_NBR_ADDRESS:
            std::cout<<"IP Address "<<inet_ntop(AF_INET,cps_api_object_attr_data_bin(it.attr),str,INET_ADDRSTRLEN)<<std::endl;
            break;

        case BASE_ROUTE_OBJ_NBR_MAC_ADDR:
        {
              char mt[6];
              char mstring[20];
              memcpy(mt, cps_api_object_attr_data_bin(it.attr), 6);
              sprintf(mstring, "%x:%x:%x:%x:%x:%x", mt[0], mt[1], mt[2], mt[3], mt[4], mt[5]);
              std::cout<<"MAC "<<mstring<<std::endl;
        }
            break;

        case BASE_ROUTE_OBJ_NBR_VRF_ID:
            std::cout<<"VRF Id "<<cps_api_object_attr_data_u32(it.attr)<<std::endl;
            break;

        case BASE_ROUTE_OBJ_NBR_IFINDEX:
            std::cout<<"Ifindex "<<cps_api_object_attr_data_u32(it.attr)<<std::endl;
            break;

        case BASE_ROUTE_OBJ_NBR_FLAGS:
            std::cout<<"Flags "<<cps_api_object_attr_data_u32(it.attr)<<std::endl;
            break;

        case BASE_ROUTE_OBJ_NBR_STATE:
            std::cout<<"State "<<cps_api_object_attr_data_u32(it.attr)<<std::endl;
            break;

        case BASE_ROUTE_OBJ_NBR_TYPE:
            std::cout<<"Type "<<cps_api_object_attr_data_u32(it.attr)<<std::endl;
            break;

        default:
            break;
        }
    }
}
示例#9
0
static bool nas_sflow_fill_session_info(cps_api_object_t obj,nas_sflow_entry_t *entry){

    cps_api_object_it_t it;
    cps_api_object_it_begin(obj,&it);

    for ( ; cps_api_object_it_valid(&it) ; cps_api_object_it_next(&it) ) {

        int id = (int) cps_api_object_attr_id(it.attr);

        switch (id) {

        case BASE_SFLOW_ENTRY_IFINDEX :
            if(entry->attr_set.contains(BASE_SFLOW_ENTRY_IFINDEX)){
                NAS_SFLOW_LOG(ERR,ev_log_s_MINOR,"Multiple Interface Index passed "
                        "for creating sFlow session");
                return false;
            }
            entry->ifindex = cps_api_object_attr_data_u32(it.attr);
            entry->attr_set.add(BASE_SFLOW_ENTRY_IFINDEX);
            break;

        case BASE_SFLOW_ENTRY_DIRECTION :
            if(entry->attr_set.contains(BASE_SFLOW_ENTRY_DIRECTION)){
                NAS_SFLOW_LOG(ERR,ev_log_s_MINOR,"Multiple Direction Attributes passed "
                                            "for creating sFlow session");
                return false;
            }
            entry->ndi_sflow_entry.sflow_direction = (BASE_CMN_TRAFFIC_PATH_t)
                                                        cps_api_object_attr_data_u32(it.attr);
            entry->attr_set.add(BASE_SFLOW_ENTRY_DIRECTION);
            break;

        case BASE_SFLOW_ENTRY_SAMPLING_RATE :
            if(entry->attr_set.contains(BASE_SFLOW_ENTRY_SAMPLING_RATE)){
                NAS_SFLOW_LOG(ERR,ev_log_s_MINOR,"Multiple Sampling Attributes passed "
                                           "for creating sFlow session");
                return false;
            }
            entry->ndi_sflow_entry.sampling_rate = cps_api_object_attr_data_u32(it.attr);
            entry->attr_set.add(BASE_SFLOW_ENTRY_SAMPLING_RATE);
            break;

        default:
            break;
        }
    }
    return nas_validate_sflow_entry(entry);
}
static bool qos_map_entry_attr_is_set(cps_api_object_t obj, nas_qos_map_type_t type)
{
    cps_api_object_it_t it;
    cps_api_object_it_begin(obj,&it);

    for ( ; cps_api_object_it_valid(&it) ; cps_api_object_it_next(&it) ) {
        cps_api_attr_id_t id = cps_api_object_attr_id(it.attr);
        if (id == qos_map_entry_obj_id(type) ||
            id == qos_map_entry_key_1_obj_id(type) ||
            id == qos_map_entry_key_2_obj_id(type) ||
            id == qos_map_entry_attr_1_obj_id(type) ||
            id == qos_map_entry_attr_2_obj_id(type))
            return true; //found
    }

    return false;

}
static bool __cps_api_obj_tool_matches_filter(cps_api_object_it_t &fit, cps_api_object_it_t &oit, bool require_all_attribs) {

    for ( ; cps_api_object_it_valid(&fit); cps_api_object_it_next(&fit)) {
        cps_api_attr_id_t id = cps_api_object_attr_id(fit.attr);

        cps_api_object_it_t tgt = oit;
        tgt.attr = cps_api_object_it_find(&tgt,id);

        if (!cps_api_object_it_valid(&tgt)) {
            if (!require_all_attribs) continue;
            return false;
        }
        if (id == CPS_API_OBJ_KEY_ATTRS) {
            cps_api_object_it_t in_fit = fit;
            cps_api_object_it_inside(&in_fit);
            cps_api_object_it_inside(&tgt);
            if (!cps_api_object_it_valid(&in_fit)) {
                continue;
            }
            if (!cps_api_object_it_valid(&tgt)) {
                if (!require_all_attribs) continue;
                return false;
            }
            if (!__cps_api_obj_tool_matches_filter(in_fit,tgt,require_all_attribs)) {
                return false;
            }
            continue;
        }

        if (!cps_api_object_attrs_compare(fit.attr,tgt.attr)==0) {
            return false;
        }
    }

    return true;
}
/* Parse the attributes */
static cps_api_return_code_t  nas_qos_cps_parse_attr(cps_api_object_t obj,
        nas_qos_map_entry  &entry )
{
    nas_qos_map_type_t type = entry.get_type();

    cps_api_object_it_t it;
    cps_api_object_it_begin(obj,&it);
    for ( ; cps_api_object_it_valid(&it) ; cps_api_object_it_next(&it) ) {
        cps_api_attr_id_t id = cps_api_object_attr_id(it.attr);
        _attr_parse_fn fn;

        if (id == qos_map_entry_attr_1_obj_id(type)) {
            fn = qos_map_entry_attr_1_parse_fn(type);
            fn(it.attr, entry);
        }

        if (id == qos_map_entry_attr_2_obj_id(type)) {
            fn = qos_map_entry_attr_2_parse_fn(type);
            fn(it.attr, entry);
        }
    }

    return cps_api_ret_code_OK;
}
static bool nas_mirror_fill_erspan_attr(cps_api_object_t obj, nas_mirror_entry *entry, bool update){

    nas::attr_set_t attrs;
    cps_api_object_it_t it;
    cps_api_object_it_begin(obj,&it);

    for ( ; cps_api_object_it_valid(&it) ; cps_api_object_it_next(&it) ) {

        int id = (int) cps_api_object_attr_id(it.attr);
        switch (id) {

        case BASE_MIRROR_ENTRY_ERSPAN_VLAN_ID:
            if(attrs.contains(BASE_MIRROR_ENTRY_ERSPAN_VLAN_ID)){
                NAS_MIRROR_LOG(ERR,ev_log_s_MINOR,"Multiple VLAN Ids passed for creating ERSPAN Mirroring session");
                   return false;
            }
            entry->set_vlan(cps_api_object_attr_data_u32(it.attr));
            attrs.add(BASE_MIRROR_ENTRY_ERSPAN_VLAN_ID);
            break;

        case BASE_MIRROR_ENTRY_DESTINATION_IP:
            if( attrs.contains(BASE_MIRROR_ENTRY_DESTINATION_IP)){
                NAS_MIRROR_LOG(ERR,ev_log_s_MINOR,"Multiple Dst IP Address passed for creating ERSPAN Mirroring session");
                return false;
            }
            entry->set_dst_ip(cps_api_object_attr_data_u32(it.attr));
            attrs.add(BASE_MIRROR_ENTRY_DESTINATION_IP);
            break;

        case BASE_MIRROR_ENTRY_SOURCE_IP:
            if( attrs.contains(BASE_MIRROR_ENTRY_SOURCE_IP)){
                NAS_MIRROR_LOG(ERR,ev_log_s_MINOR,"Multiple Source IP Address passed for creating ERSPAN Mirroring session");
                return false;
            }
            entry->set_src_ip(cps_api_object_attr_data_u32(it.attr));
            attrs.add(BASE_MIRROR_ENTRY_SOURCE_IP);
            break;


        case BASE_MIRROR_ENTRY_DEST_MAC:
            if( attrs.contains(BASE_MIRROR_ENTRY_DEST_MAC)){
                NAS_MIRROR_LOG(ERR,ev_log_s_MINOR,"Multiple Dst MAC Address passed for creating ERSPAN Mirroring session");
                return false;
            }

            entry->set_dst_mac(cps_api_object_attr_data_bin(it.attr));
            attrs.add(BASE_MIRROR_ENTRY_DEST_MAC);
            break;

        case BASE_MIRROR_ENTRY_SOURCE_MAC:
            if( attrs.contains(BASE_MIRROR_ENTRY_SOURCE_MAC)){
                NAS_MIRROR_LOG(ERR,ev_log_s_MINOR,"Multiple Source MAC Address passed for creating ERSPAN Mirroring session");
                return false;
            }
            entry->set_src_mac(cps_api_object_attr_data_bin(it.attr));
            attrs.add(BASE_MIRROR_ENTRY_SOURCE_MAC);
            break;
        }
    }

    if(update){
        return nas_mirror_update_attrs(entry,attrs);
    }
    return nas_mirror_validate_erspan_attr(attrs);
}
/**
  * This function provides NAS-QoS SCHEDULER_GROUP CPS API read function
  * @Param      Standard CPS API params
  * @Return   Standard Error Code
  */
cps_api_return_code_t nas_qos_cps_api_scheduler_group_read (void * context,
                                            cps_api_get_params_t * param,
                                            size_t ix)
{
    cps_api_object_t obj = cps_api_object_list_get(param->filters, ix);
    cps_api_object_attr_t sg_attr = cps_api_get_key_data(obj, BASE_QOS_SCHEDULER_GROUP_ID);
    uint32_t port_id = 0, level;
    bool have_port = false, have_level = false;
    if (!sg_attr) {
        cps_api_object_it_t it;
        cps_api_object_it_begin(obj, &it);
        for ( ; cps_api_object_it_valid(&it); cps_api_object_it_next(&it)) {
            cps_api_attr_id_t id = cps_api_object_attr_id(it.attr);
            if (id == BASE_QOS_SCHEDULER_GROUP_PORT_ID) {
                port_id = cps_api_object_attr_data_u32(it.attr);
                have_port = true;
            } else if (id == BASE_QOS_SCHEDULER_GROUP_LEVEL) {
                level = cps_api_object_attr_data_u32(it.attr);
                have_level = true;
            }
        }
    }

    if (!sg_attr && !have_port) {
        EV_LOG_TRACE(ev_log_t_QOS, ev_log_s_MINOR, "NAS-QOS",
                     "Invalid input attributes for reading");
        return NAS_QOS_E_MISSING_KEY;
    }

    uint_t switch_id = 0;
    nas_obj_id_t scheduler_group_id = (sg_attr? cps_api_object_attr_data_u64(sg_attr): 0);

    EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS", "Read switch id %u, scheduler_group id 0x%016lX\n",
                    switch_id, scheduler_group_id);

    std_mutex_simple_lock_guard p_m(&scheduler_group_mutex);

    if (have_port) {
        nas_qos_port_scheduler_group_init(port_id);
    }
    nas_qos_switch * p_switch = nas_qos_get_switch(switch_id);
    if (p_switch == NULL)
        return NAS_QOS_E_FAIL;

    std::vector<nas_qos_scheduler_group *> sg_list;
    if (sg_attr) {
        nas_qos_scheduler_group *scheduler_group = p_switch->get_scheduler_group(scheduler_group_id);
        if (scheduler_group == NULL) {
            EV_LOG_TRACE(ev_log_t_QOS, ev_log_s_MINOR, "NAS-QOS",
                         "Could not find scheduler group with ID %llu", scheduler_group_id);
            return NAS_QOS_E_FAIL;
        }
        sg_list.push_back(scheduler_group);
    } else {
        int match_level = have_level ? (int)level : -1;
        p_switch->get_port_scheduler_groups(port_id, match_level, sg_list);
    }

    /* fill in data */
    cps_api_object_t ret_obj;

    for (auto scheduler_group: sg_list) {
        ret_obj = cps_api_object_list_create_obj_and_append (param->list);
        if (ret_obj == NULL) {
            EV_LOG_TRACE(ev_log_t_QOS, ev_log_s_MINOR, "NAS-QOS",
                         "Failed to create cps object");
            return cps_api_ret_code_ERR;
        }

        cps_api_key_from_attr_with_qual(cps_api_object_key(ret_obj),BASE_QOS_SCHEDULER_GROUP_OBJ,
                cps_api_qualifier_TARGET);
        cps_api_set_key_data(ret_obj, BASE_QOS_SCHEDULER_GROUP_SWITCH_ID,
                cps_api_object_ATTR_T_U32,
                &switch_id, sizeof(uint32_t));
        scheduler_group_id = scheduler_group->get_scheduler_group_id();
        cps_api_set_key_data(ret_obj, BASE_QOS_SCHEDULER_GROUP_ID,
                cps_api_object_ATTR_T_U64,
                &scheduler_group_id, sizeof(uint64_t));

        cps_api_object_attr_add_u32(ret_obj,
                                    BASE_QOS_SCHEDULER_GROUP_CHILD_COUNT,
                                    scheduler_group->get_child_count());

        for (uint32_t idx = 0; idx < scheduler_group->get_child_count(); idx++) {
            cps_api_object_attr_add_u64(ret_obj,
                                        BASE_QOS_SCHEDULER_GROUP_CHILD_LIST,
                                        scheduler_group->get_child_id(idx));
        }

        cps_api_object_attr_add_u32(ret_obj, BASE_QOS_SCHEDULER_GROUP_PORT_ID,
                                    scheduler_group->get_port_id());
        cps_api_object_attr_add_u32(ret_obj, BASE_QOS_SCHEDULER_GROUP_LEVEL,
                                    scheduler_group->get_level());
        cps_api_object_attr_add_u64(ret_obj, BASE_QOS_SCHEDULER_GROUP_SCHEDULER_PROFILE_ID,
                                    scheduler_group->get_scheduler_profile_id());
    }

    return cps_api_ret_code_OK;
}
/**
  * This function provides NAS-QoS priority_group stats CPS API clear function
  * To clear the priority_group stats, set relevant counters to zero
  * @Param    Standard CPS API params
  * @Return   Standard Error Code
  */
cps_api_return_code_t nas_qos_cps_api_priority_group_stat_clear (void * context,
                                            cps_api_transaction_params_t * param,
                                            size_t ix)
{
    cps_api_object_t obj = cps_api_object_list_get(param->change_list,ix);
    cps_api_operation_types_t op = cps_api_object_type_operation(cps_api_object_key(obj));

    if (op != cps_api_oper_SET)
        return NAS_QOS_E_UNSUPPORTED;

    cps_api_object_attr_t port_id_attr = cps_api_get_key_data(obj, BASE_QOS_PRIORITY_GROUP_STAT_PORT_ID);
    cps_api_object_attr_t local_id_attr = cps_api_get_key_data(obj, BASE_QOS_PRIORITY_GROUP_STAT_LOCAL_ID);

    if (port_id_attr == NULL ||
        local_id_attr == NULL) {
        EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS",
                "Incomplete key: port-id, priority_group local id must be specified\n");
        return NAS_QOS_E_MISSING_KEY;
    }
    uint32_t switch_id = 0;
    nas_qos_priority_group_key_t key;
    key.port_id = cps_api_object_attr_data_u32(port_id_attr);
    key.local_id = *(uint8_t *)cps_api_object_attr_data_bin(local_id_attr);


    EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS",
            "Read switch id %u, port_id %u priority_group local_id %u stat\n",
            switch_id, key.port_id,  key.local_id);

    std_mutex_simple_lock_guard p_m(&priority_group_mutex);

    // If the port is not be initialized yet, initialize it in NAS
    nas_qos_port_priority_group_init(key.port_id);

    nas_qos_switch *switch_p = nas_qos_get_switch(switch_id);
    if (switch_p == NULL) {
        EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS", "switch_id %u not found", switch_id);
        return NAS_QOS_E_FAIL;
    }

    nas_qos_priority_group * priority_group_p = switch_p->get_priority_group(key);
    if (priority_group_p == NULL) {
        EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS", "Priority Group not found");
        return NAS_QOS_E_FAIL;
    }

    std::vector<BASE_QOS_PRIORITY_GROUP_STAT_t> counter_ids;

    cps_api_object_it_t it;
    cps_api_object_it_begin(obj,&it);
    for ( ; cps_api_object_it_valid(&it) ; cps_api_object_it_next(&it) ) {
        cps_api_attr_id_t id = cps_api_object_attr_id(it.attr);
        switch (id) {
        case BASE_QOS_PRIORITY_GROUP_STAT_PORT_ID:
        case BASE_QOS_PRIORITY_GROUP_STAT_LOCAL_ID:
            break;

        case BASE_QOS_PRIORITY_GROUP_STAT_PACKETS:
        case BASE_QOS_PRIORITY_GROUP_STAT_BYTES:
        case BASE_QOS_PRIORITY_GROUP_STAT_WATERMARK_BYTES:
            counter_ids.push_back((BASE_QOS_PRIORITY_GROUP_STAT_t)id);
            break;

        case BASE_QOS_PRIORITY_GROUP_STAT_CURRENT_OCCUPANCY_BYTES:
            // READ-only
            break;

        default:
            EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS",
                    "Unknown priority_group STAT flag: %u, ignored", id);
            break;
        }
    }

    if (ndi_qos_clear_priority_group_stats(priority_group_p->get_ndi_port_id(),
                                priority_group_p->ndi_obj_id(),
                                &counter_ids[0],
                                counter_ids.size()) != STD_ERR_OK) {
        EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS", "Priority Group stats clear failed");
        return NAS_QOS_E_FAIL;
    }


    return  cps_api_ret_code_OK;

}
static bool nas_mirror_fill_entry(cps_api_object_t obj,nas_mirror_entry *entry
                                 ,nas_mirror_src_intf_map_t  & new_intf_map,bool update){

    nas::attr_set_t attrs;
    cps_api_object_it_t it;

    cps_api_object_it_begin(obj,&it);

    for ( ; cps_api_object_it_valid(&it) ; cps_api_object_it_next(&it) ) {

        int id = (int) cps_api_object_attr_id(it.attr);
        switch (id) {

        case BASE_MIRROR_ENTRY_DST_INTF :
            if(attrs.contains(BASE_MIRROR_ENTRY_DST_INTF) ||
               attrs.contains(BASE_MIRROR_ENTRY_LAG_OPAQUE_DATA)){
                NAS_MIRROR_LOG(ERR,ev_log_s_MINOR,"Multiple Destination Interface Index passed "
                        "for creating/updating Mirroring session");
                return false;
            }

            entry->set_dst_intf(cps_api_object_attr_data_u32(it.attr));
            interface_ctrl_t intf_ctrl;
            if(!nas_mirror_intf_to_port(entry->get_dst_intf(),&intf_ctrl)){
                return false;
            }

            entry->set_dst_port(intf_ctrl.npu_id,intf_ctrl.port_id);
            attrs.add(BASE_MIRROR_ENTRY_DST_INTF);
            break;

        case BASE_MIRROR_ENTRY_LAG_OPAQUE_DATA :
            if(attrs.contains(BASE_MIRROR_ENTRY_LAG_OPAQUE_DATA) ||
               attrs.contains(BASE_MIRROR_ENTRY_DST_INTF)){
                NAS_MIRROR_LOG(ERR,0,"Multiple Destination Lag opaque data "
                               "passed for creating/updating Mirroring session");
                return false;
            }

            {
                nas::ndi_obj_id_table_t lag_opaque_data_table;
                cps_api_attr_id_t  attr_id_list[] = {BASE_MIRROR_ENTRY_LAG_OPAQUE_DATA};
                if(!nas::ndi_obj_id_table_cps_unserialize (lag_opaque_data_table, obj,attr_id_list,
                                                           sizeof(attr_id_list)/
                                                           sizeof(attr_id_list[0]))){
                    NAS_MIRROR_LOG(ERR,0,"Failed to unserialize lag opaque data");
                    return false;
                }

                auto lag_opaue_it = lag_opaque_data_table.begin();
                if(lag_opaue_it == lag_opaque_data_table.end()){
                    NAS_MIRROR_LOG(ERR,0,"No lag opaque data passed");
                    return false;
                }

                entry->set_ndi_lag_id(lag_opaue_it->first,lag_opaue_it->second);
            }
            attrs.add(BASE_MIRROR_ENTRY_LAG_OPAQUE_DATA);
            break;

        case BASE_MIRROR_ENTRY_INTF:
            if(!update) attrs.add(BASE_MIRROR_ENTRY_INTF);
            if(!get_src_intf_attr(obj, new_intf_map , it)) return false;
            break;

        case BASE_MIRROR_ENTRY_FLOW_ENABLED :
            entry->set_flow(cps_api_object_attr_data_u32(it.attr));
            break;

        case BASE_MIRROR_ENTRY_TYPE:
            if(attrs.contains(BASE_MIRROR_ENTRY_TYPE)){
                NAS_MIRROR_LOG(ERR,ev_log_s_MINOR,"Multiple Mirror types passed "
                        "for creating Mirroring session");
                return false;
            }
            entry->set_mode((BASE_MIRROR_MODE_t)cps_api_object_attr_data_u32(it.attr));
            attrs.add(BASE_MIRROR_ENTRY_TYPE);
            break;
        }
    }

    if(update){
        if(!nas_mirror_update_attrs(entry,attrs)) return false;
        if(new_intf_map.size() > 0){
            if(!entry->update_src_intf_map(new_intf_map)) return false;
        }
    }
    else{
        if(!nas_mirror_validate_attr(attrs)) return false;
    }

    if(entry->get_mode() == BASE_MIRROR_MODE_RSPAN ){
        if(!nas_mirror_fill_rspan_attr(obj,entry,update)){
            return false;
        }
    }

    if(entry->get_mode() == BASE_MIRROR_MODE_ERSPAN){
       if(!nas_mirror_fill_erspan_attr(obj,entry,update)){
           return false;
       }
    }

    return true;
}
示例#17
0
bool cps_api_nodes::load_groups() {
    cps_api_object_guard og(cps_api_object_create());
    if (!cps_api_key_from_attr_with_qual(cps_api_object_key(og.get()),CPS_NODE_GROUP, cps_api_qualifier_TARGET)) {
        EV_LOG(ERR,DSAPI,0,"CPS-CLS-MAP","Meta data for cluster set is not loaded.");
        return false;
    }
    cps_db::connection_request b(cps_db::ProcessDBCache(),DEFAULT_REDIS_ADDR);

    if (!b.valid()) {
        return false;
    }

    group_data_t cpy;

    cps_api_object_list_guard lg(cps_api_object_list_create());
    if (!cps_db::get_objects(b.get(),og.get(),lg.get())) return false;

    for (size_t ix = 0,mx = cps_api_object_list_size(lg.get()); ix < mx ; ++ix ) {
        cps_api_object_t o = cps_api_object_list_get(lg.get(),ix);
        std::vector<_db_node_data> v;
        const char *name = (const char*) cps_api_object_get_data(o,CPS_NODE_GROUP_NAME);
        _node_data nd;



        cps_api_node_data_type_t *_type = (cps_api_node_data_type_t*)cps_api_object_get_data(o,CPS_NODE_GROUP_TYPE);
        if (_type==nullptr) {
            EV_LOGGING(DSAPI,ERR,"NODE-LOAD","Could not get the group type for group %s",name);
            return false;
        }
        nd.type = *_type;
        cps_api_object_attr_t _node_group = cps_api_object_attr_get(o,CPS_NODE_GROUP_NODE);
        if (_node_group==nullptr) continue; ///TODO log

        cps_api_object_it_t it;
        cps_api_object_it_from_attr(_node_group,&it);
        cps_api_object_it_inside(&it);

        while (cps_api_object_it_valid(&it)) {
            cps_api_attr_id_t id = cps_api_object_attr_id(it.attr);
            (void)id;
            cps_api_object_it_t elem = it;

            cps_api_object_it_inside(&elem);

            if (!cps_api_object_it_valid(&elem)) continue;
            _db_node_data db_node;
            cps_api_object_attr_t _ip =cps_api_object_it_find(&elem,CPS_NODE_GROUP_NODE_IP);
            cps_api_object_attr_t _name =cps_api_object_it_find(&elem,CPS_NODE_GROUP_NODE_NAME);
            if (_ip==nullptr || _name==nullptr) continue;
            const char *__ip = (const char*)cps_api_object_attr_data_bin(_ip);
            const char *__name =(const char*)cps_api_object_attr_data_bin(_name);

            if(nd.type == cps_api_node_data_1_PLUS_1_REDUNDENCY) {
                db_node._name = __name;
                if(get_port_info(name,&db_node)) {
                    auto lst = cps_string::split(std::string(__ip),":");
                    if (lst.size()!=2) {
                        return false;
                    }
                    db_node._addr = lst[0] + ':'+ db_node._addr;
                    v.push_back(std::move(db_node));
                }
                else {
                    EV_LOGGING(DSAPI,ERR,"CPS-DB","Failed to get port info for group %s and node %s",
                               name,__name);
                }

            }

            if(v.size()>0) {
                _db_node_map[name] = v;
                update_slaves(name);
            }

            _alias_map[__name] = __ip;

            const char * _alias = this->addr(__ip);
            if (_alias!=nullptr) __ip = _alias;

            nd._addrs.push_back(__ip);
            cps_api_object_it_next(&it);
        }
        cpy[name] = nd;
    }

    size_t _new_hash = cps_api_nodes::gen_hash(cpy);

    if (_new_hash==_hash) return false;  ///TODO is this unique enough?

    std::swap(_groups,cpy);
    _hash = _new_hash;
    return true;

}
示例#18
0
void nas_acl_set_action_list (const cps_api_object_t     obj,
                              const cps_api_object_it_t& it,
                              nas_acl_entry&             entry)
{
    /*
     * Encoding of ACL Entry Action parameters, with the following
     * sample action parameters:
     *   1. Ingress Mirroring
     *   2. Redirect Port
     *   3. Forward
     *
     * ------------------------------------------------------------------------
     * | Type : BASE_ACL_ENTRY_ACTION  (ACTION-List-Attr)                     |
     * | Len  : Length of Val                                                 |
     * | Val  ----------------------------------------------------------------|
     * |      | Type : 'list_index' = 0                                       |
     * |      | Len  : Length of Val                                          |
     * |      | Val  ---------------------------------------------------------|
     * |      |      | Type : BASE_ACL_ENTRY_ACTION_TYPE                      |
     * |      |      | Len  : Length of Val                                   |
     * |      |      | Val  : BASE_ACL_ACTION_TYPE_SET_POLICER     <--        |
     * |      |      |                                               |        |
     * |      |      |                                  --------------------  |
     * |      |      |                                  |'action_type_val' |  |
     * |      |      |                                  --------------------  |
     * |      |      |--------------------------------------------------------|
     * |      |      | Type : BASE_ACL_ENTRY_ACTION_POLICER_VALUE  <--        |
     * |      |      |                                               |        |
     * |      |      |                             -------------------------- |
     * |      |      |                             |'action_map.val.attr_id'| |
     * |      |      |                             -------------------------- |
     * |      |      | Len  : Length of Val                                   |
     * |      |      | Val  --------------------------------------------------|
     * |      |      |      | Type : BASE_ACL_ENTRY_ACTION_POLICER_VALUE_INDEX|
     * |      |      |      | Len  : Length of Val                            |
     * |      |      |      | Val  : <mirror-id>                              |
     * |      |      |      |                                                 |
     * |      |      |      | Type : BASE_ACL_ENTRY_ACTION_POLICER_VALUE_DATA |
     * |      |      |      | Len  : Length of Val                            |
     * |      |      |      | Val  : <mirror-blob-data>                       |
     * |      |      |      --------------------------------------------------|
     * |      |      |                                                        |
     * |      |      ---------------------------------------------------------|
     * |      |                                                               |
     * |      ----------------------------------------------------------------|
     * |      | Type : 'list_index' = 1                                       |
     * |      | Len  : Length of Val                                          |
     * |      | Val  ---------------------------------------------------------|
     * |      |      | Type : BASE_ACL_ENTRY_ACTION_TYPE                      |
     * |      |      | Len  : Length of Val                                   |
     * |      |      | Val  : BASE_ACL_ACTION_TYPE_FORWARD   <----            |
     * |      |      |                                           |            |
     * |      |      |                                  -------------------   |
     * |      |      |                                 |'action_type_val' |   |
     * |      |      |                                  -------------------   |
     * |      |      |     NOTE: There is no further data for this action.    |
     * |      |      ---------------------------------------------------------|
     * |      |                                                               |
     * |      ----------------------------------------------------------------|
     * |      |                                                               |
     * |      |                           ...                                 |
     * |      |                                                               |
     * |      ----------------------------------------------------------------|
     * |      | Type : 'list_index' = N                                       |
     * |      | Len  : Length of Val                                          |
     * |      | Val  ---------------------------------------------------------|
     * |      |      | Type : BASE_ACL_ENTRY_ACTION_TYPE                      |
     * |      |      | Len  : Length of Val                                   |
     * |      |      | Val  : BASE_ACL_ACTION_TYPE_REDIRECT_PORT      <--     |
     * |      |      |                                                  |     |
     * |      |      |                                 --------------------   |
     * |      |      |                                 |'action_type_val' |   |
     * |      |      |                                 --------------------   |
     * |      |      |--------------------------------------------------------|
     * |      |      | Type : BASE_ACL_ENTRY_ACTION_REDIRECT_PORT_VALUE       |
     * |      |      |                                              ^         |
     * |      |      |                                              |         |
     * |      |      |                             -------------------------- |
     * |      |      |                             |'action_map.val.attr_id'| |
     * |      |      |                             -------------------------- |
     * |      |      | Len  : Length of Val                                   |
     * |      |      | Val  : <if-index>                                      |
     * |      |      ---------------------------------------------------------|
     * |      |                                                               |
     * |      ----------------------------------------------------------------|
     * |                                                                      |
     * ------------------------------------------------------------------------
     */

    BASE_ACL_ACTION_TYPE_t     action_type_val;
    cps_api_object_it_t        it_action_list = it;
    cps_api_attr_id_t          list_index = 0;
    nas::attr_list_t           parent_attr_id_list;
    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 (cps_api_object_it_inside (&it_action_list);
         cps_api_object_it_valid (&it_action_list);
         cps_api_object_it_next (&it_action_list)) {

        parent_attr_id_list.clear ();
        parent_attr_id_list.push_back (BASE_ACL_ENTRY_ACTION);

        list_index = cps_api_object_attr_id (it_action_list.attr);

        parent_attr_id_list.push_back (list_index);

        cps_api_object_it_t it_action_attr = it_action_list;
        cps_api_object_it_inside (&it_action_attr);
        if (!cps_api_object_it_valid (&it_action_attr)) {
            throw nas::base_exception {NAS_ACL_E_MISSING_ATTR, __PRETTY_FUNCTION__,
                                       "Missing list container for ACTION in object"};
        }

        bool is_dupl;
        auto attr_action_type = nas_acl_get_attr (it_action_attr,
                                                 BASE_ACL_ENTRY_ACTION_TYPE, &is_dupl);

        if (attr_action_type == NULL) {
            throw nas::base_exception {NAS_ACL_E_MISSING_ATTR, __PRETTY_FUNCTION__,
                                       "Missing ACTION_TYPE attribute"};
        }
        if (is_dupl) {
            throw nas::base_exception {NAS_ACL_E_DUPLICATE, __PRETTY_FUNCTION__,
                                       "Duplicate ACTION_TYPE attribute"};
        }

        action_type_val = (BASE_ACL_ACTION_TYPE_t)
            cps_api_object_attr_data_u32 (attr_action_type);

        NAS_ACL_LOG_DETAIL ("action_type_val: %d (%s)", action_type_val,
                            nas_acl_action_t::type_name (action_type_val));

        nas_acl_set_action_attr (obj, entry, action_type_val,
                                 parent_attr_id_list, true);
    }
}
/**
  * This function provides NAS-QoS priority_group stats CPS API read function
  * @Param    Standard CPS API params
  * @Return   Standard Error Code
  */
cps_api_return_code_t nas_qos_cps_api_priority_group_stat_read (void * context,
                                            cps_api_get_params_t * param,
                                            size_t ix)
{

    cps_api_object_t obj = cps_api_object_list_get(param->filters, ix);
    cps_api_object_attr_t port_id_attr = cps_api_get_key_data(obj, BASE_QOS_PRIORITY_GROUP_STAT_PORT_ID);
    cps_api_object_attr_t local_id_attr = cps_api_get_key_data(obj, BASE_QOS_PRIORITY_GROUP_STAT_LOCAL_ID);

    if (port_id_attr == NULL ||
        local_id_attr == NULL ) {
        EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS",
                "Incomplete key: port-id, priority_group local id must be specified\n");
        return NAS_QOS_E_MISSING_KEY;
    }
    uint32_t switch_id = 0;
    nas_qos_priority_group_key_t key;
    key.port_id = cps_api_object_attr_data_u32(port_id_attr);
    key.local_id = *(uint8_t *)cps_api_object_attr_data_bin(local_id_attr);


    EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS",
            "Read switch id %u, port_id %u priority_group local id %u stat\n",
            switch_id, key.port_id, key.local_id);

    std_mutex_simple_lock_guard p_m(&priority_group_mutex);

    // If the port is not be initialized yet, initialize it in NAS
    nas_qos_port_priority_group_init(key.port_id);

    nas_qos_switch *switch_p = nas_qos_get_switch(switch_id);
    if (switch_p == NULL) {
        EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS", "switch_id %u not found", switch_id);
        return NAS_QOS_E_FAIL;
    }

    nas_qos_priority_group * priority_group_p = switch_p->get_priority_group(key);
    if (priority_group_p == NULL) {
        EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS", "Priority Group not found");
        return NAS_QOS_E_FAIL;
    }

    nas_qos_priority_group_stat_counter_t stats = {0};
    std::vector<BASE_QOS_PRIORITY_GROUP_STAT_t> counter_ids;

    cps_api_object_it_t it;
    cps_api_object_it_begin(obj,&it);
    for ( ; cps_api_object_it_valid(&it) ; cps_api_object_it_next(&it) ) {
        cps_api_attr_id_t id = cps_api_object_attr_id(it.attr);
        switch (id) {
        case BASE_QOS_PRIORITY_GROUP_STAT_PORT_ID:
        case BASE_QOS_PRIORITY_GROUP_STAT_LOCAL_ID:
            break;

        case BASE_QOS_PRIORITY_GROUP_STAT_PACKETS:
        case BASE_QOS_PRIORITY_GROUP_STAT_BYTES:
        case BASE_QOS_PRIORITY_GROUP_STAT_CURRENT_OCCUPANCY_BYTES:
        case BASE_QOS_PRIORITY_GROUP_STAT_WATERMARK_BYTES:
            counter_ids.push_back((BASE_QOS_PRIORITY_GROUP_STAT_t)id);
            break;

        default:
            EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS", "Unknown priority_group STAT flag: %u, ignored", id);
            break;
        }
    }

    if (ndi_qos_get_priority_group_stats(priority_group_p->get_ndi_port_id(),
                                priority_group_p->ndi_obj_id(),
                                &counter_ids[0],
                                counter_ids.size(),
                                &stats) != STD_ERR_OK) {
        EV_LOG_TRACE(ev_log_t_QOS, 3, "NAS-QOS", "Priority Group stats get failed");
        return NAS_QOS_E_FAIL;
    }

    // return stats objects to cps-app
    cps_api_object_t ret_obj = cps_api_object_list_create_obj_and_append(param->list);
    if (ret_obj == NULL) {
        return cps_api_ret_code_ERR;
    }

    cps_api_key_from_attr_with_qual(cps_api_object_key(ret_obj),
            BASE_QOS_PRIORITY_GROUP_STAT_OBJ,
            cps_api_qualifier_TARGET);
    cps_api_set_key_data(ret_obj, BASE_QOS_PRIORITY_GROUP_STAT_PORT_ID,
            cps_api_object_ATTR_T_U32,
            &(key.port_id), sizeof(uint32_t));
    cps_api_set_key_data(ret_obj, BASE_QOS_PRIORITY_GROUP_STAT_LOCAL_ID,
            cps_api_object_ATTR_T_BIN,
            &(key.local_id), sizeof(uint8_t));

    uint64_t val64;
    for (uint_t i=0; i< counter_ids.size(); i++) {
        BASE_QOS_PRIORITY_GROUP_STAT_t id = counter_ids[i];
        val64 = get_stats_by_type(&stats, id);
        cps_api_object_attr_add_u64(ret_obj, id, val64);
    }

    return  cps_api_ret_code_OK;

}