t_std_error nas_mac_publish_entry(nas_mac_entry_t *entry,bool is_static,bool flush_all, cps_api_operation_types_t op){ if(entry == nullptr){ NAS_MAC_LOG(ERR,0,"Null MAC entry pointer passed to convert it to cps object"); return STD_ERR(MAC,PARAM,0); } cps_api_object_t obj = cps_api_object_create(); if(obj == nullptr){ NAS_MAC_LOG(ERR,0,"Failed to allocate memory to cps object"); return STD_ERR(MAC,NOMEM,0); } cps_api_key_t key; cps_api_key_from_attr_with_qual(&key, BASE_MAC_TABLE_OBJ, cps_api_qualifier_OBSERVED); cps_api_object_set_type_operation(&key,op); cps_api_object_set_key(obj,&key); if(!flush_all){ cps_api_object_attr_add_u32(obj,BASE_MAC_TABLE_IFINDEX,entry->ifindex); cps_api_object_attr_add_u32(obj,BASE_MAC_TABLE_ACTIONS,entry->pkt_action); cps_api_object_attr_add_u16(obj,BASE_MAC_TABLE_VLAN,entry->entry_key.vlan_id); cps_api_object_attr_add(obj,BASE_MAC_TABLE_MAC_ADDRESS,(void*)entry->entry_key.mac_addr, sizeof(entry->entry_key.mac_addr)); cps_api_object_attr_add_u32(obj,BASE_MAC_TABLE_STATIC,is_static); } NAS_MAC_LOG(INFO,3,"Publishing an event with operation %d",op); return nas_mac_event_publish(obj); }
bool cps_delete_mac(){ // Create and initialize the transaction object cps_api_transaction_params_t tran; if (cps_api_transaction_init(&tran) != cps_api_ret_code_OK ){ return false; } // Create and initialize the key cps_api_key_t key; cps_api_key_from_attr_with_qual(&key, BASE_MAC_TABLE_OBJ, cps_api_qualifier_TARGET); // Create the object cps_api_object_t obj = cps_api_object_create(); if(obj == NULL ){ cps_api_transaction_close(&tran); return false; } // Set the key for the object cps_api_object_set_key(obj,&key); // Add attributes mandatory to create MAC address entry uint8_t mac_addr[6] = {0x0,0xa,0xb,0xc,0xd,0xe}; uint16_t vlan_id = 131; cps_api_object_attr_add(obj,BASE_MAC_TABLE_MAC_ADDRESS, mac_addr, sizeof(hal_mac_addr_t)); cps_api_object_attr_add_u32(obj,BASE_MAC_TABLE_IFINDEX,if_nametoindex("e101-001-0") ); cps_api_object_attr_add_u16(obj,BASE_MAC_TABLE_VLAN,vlan_id); // Add the object along with the operation to transaction if(cps_api_delete(&tran,obj) != cps_api_ret_code_OK ){ cps_api_delete_object(obj); return false; }
static t_std_error dn_pas_fan_get1( cps_api_get_params_t *param, cps_api_qualifier_t qual, uint_t entity_type, uint_t slot, uint_t fan_idx ) { cps_api_key_t rec_key[1]; pas_fan_t *rec; cps_api_object_t resp_obj; /* Look up object in cache */ cps_api_key_init(rec_key, cps_api_qualifier_OBSERVED, cps_api_obj_CAT_BASE_PAS, BASE_PAS_FAN_OBJ, 3, entity_type, slot, fan_idx ); rec = (pas_fan_t *) dn_pas_res_get(rec_key); if (rec == 0) { /* Not found */ return (STD_ERR(PAS, NEXIST, 0)); } /* Compose respose object */ resp_obj = cps_api_object_create(); if (resp_obj == CPS_API_OBJECT_NULL) { EV_LOG_ERR(ev_log_t_PAS, 3, "PAS", "%s, allocate response object failed\n", __FUNCTION__); return (STD_ERR(PAS, NOMEM, 0)); } dn_pas_obj_key_fan_set(resp_obj, qual, true, entity_type, true, slot, true, fan_idx ); dn_pas_lock(); if ((!rec->valid || qual == cps_api_qualifier_REALTIME) && !dn_pald_diag_mode_get()) { /* Cache not valid or realtime object requested => Update cache from hardware */ dn_entity_poll(rec->parent, true); } if (rec->parent->present) { /* Add result attributes to response object */ if (qual == cps_api_qualifier_TARGET) { cps_api_object_attr_add_u16(resp_obj, BASE_PAS_FAN_SPEED, rec->targ_speed ); } else { cps_api_object_attr_add_u8(resp_obj, BASE_PAS_FAN_OPER_STATUS, rec->oper_fault_state->oper_status ); cps_api_object_attr_add_u8(resp_obj, BASE_PAS_FAN_FAULT_TYPE, rec->oper_fault_state->fault_type ); cps_api_object_attr_add_u16(resp_obj, BASE_PAS_FAN_SPEED, rec->obs_speed ); cps_api_object_attr_add_u8(resp_obj, BASE_PAS_FAN_SPEED_PCT, rec->max_speed != 0 ? (100 * rec->obs_speed) / rec->max_speed : 0 ); cps_api_object_attr_add_u16(resp_obj, BASE_PAS_FAN_MAX_SPEED, rec->max_speed ); } } dn_pas_unlock(); /* Add response object to get response */ if (!cps_api_object_list_append(param->list, resp_obj)) { cps_api_object_delete(resp_obj); return (STD_ERR(PAS, FAIL, 0)); } return (STD_ERR_OK); }
static t_std_error dn_pas_fan_set1( cps_api_transaction_params_t *param, cps_api_qualifier_t qual, uint_t entity_type, uint_t slot, uint_t fan_idx, bool speed_valid, uint_t speed, bool speed_pct_valid, uint_t speed_pct ) { cps_api_key_t rec_key[1]; pas_fan_t *rec; cps_api_object_t old_obj; pas_oper_fault_state_t prev_oper_fault_state[1]; t_std_error rc = STD_ERR_OK; uint_t targ_speed = 0; bool notif = false; /* Look up object in cache */ cps_api_key_init(rec_key, cps_api_qualifier_OBSERVED, cps_api_obj_CAT_BASE_PAS, BASE_PAS_FAN_OBJ, 3, entity_type, slot, fan_idx ); rec = (pas_fan_t *) dn_pas_res_get(rec_key); if (rec == 0) { /* Not found */ return (STD_ERR(PAS, NEXIST, 0)); } *prev_oper_fault_state = *rec->oper_fault_state; old_obj = cps_api_object_create(); if (old_obj == CPS_API_OBJECT_NULL) return (STD_ERR(PAS, NOMEM, 0)); dn_pas_obj_key_fan_set(old_obj, qual, true, entity_type, true, slot, true, fan_idx ); cps_api_object_attr_add_u16(old_obj, BASE_PAS_FAN_SPEED, rec->targ_speed ); if (!cps_api_object_list_append(param->prev, old_obj)) { cps_api_object_delete(old_obj); return (STD_ERR(PAS, FAIL, 0)); } old_obj = CPS_API_OBJECT_NULL; /* No longer owned */ targ_speed = rec->targ_speed; if (speed_pct_valid) { targ_speed = (speed_pct * rec->max_speed) / 100; } if (speed_valid) targ_speed = speed; if (targ_speed == rec->targ_speed) return rc; dn_pas_lock(); if(!dn_pald_diag_mode_get()) { rc = sdi_fan_speed_set(rec->sdi_resource_hdl, targ_speed); } dn_pas_unlock(); if (STD_IS_ERR(rc)) { dn_pas_oper_fault_state_update(rec->oper_fault_state, PLATFORM_FAULT_TYPE_EHW ); } else { rec->targ_speed = targ_speed; } if (rec->oper_fault_state->oper_status != prev_oper_fault_state->oper_status) { notif = true; } if (notif) dn_fan_notify(rec); return (rc); }