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; }
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; }
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; }
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); } }
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; }