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