コード例 #1
0
TEST(cps_api_db,db_node_list) {

    cps_api_object_t obj = cps_api_object_create();
    cps_api_object_guard og(obj);
    ASSERT_TRUE(og.get()!=nullptr);

    cps_api_node_ident ids[2] = { {"NODE1", "10.11.56.37:6379"}, {"NODE2","127.0.0.1:6379"} };
    cps_api_node_group_t _g;

    _g.id = "A";
    _g.addrs = ids;
    _g.addr_len = 2;
    _g.data_type = cps_api_node_data_1_PLUS_1_REDUNDENCY;

    ASSERT_EQ(cps_api_set_node_group(&_g),cps_api_ret_code_OK);
    ASSERT_EQ(cps_api_set_master_node("A","NODE1"),cps_api_ret_code_OK);


    cps_api_key_from_attr_with_qual(cps_api_object_key(obj),BASE_IP_IPV6,cps_api_qualifier_TARGET);
    cps_api_object_attr_add_u32(obj,BASE_IP_IPV6_VRF_ID,0);
    cps_api_object_attr_add_u32(obj,BASE_IP_IPV6_IFINDEX,1);
    cps_api_object_attr_add(obj,BASE_IP_IPV6_NAME,"Clifford",9);

    cps_api_key_set_group(obj,"A");

    ASSERT_TRUE(cps_api_commit_one(cps_api_oper_CREATE, obj, 0, 200)==cps_api_ret_code_OK);
    ASSERT_EQ(cps_api_delete_node_group("A"),cps_api_ret_code_OK);

}
コード例 #2
0
TEST(std_nas_route_test, nas_neighbor_set) {

    cps_api_object_t obj = cps_api_object_create();
    //cps_api_key_init(cps_api_object_key(obj),cps_api_qualifier_TARGET,
     //       cps_api_obj_CAT_BASE_ROUTE, BASE_ROUTE_OBJ_OBJ,0 );
    cps_api_key_from_attr_with_qual(cps_api_object_key(obj),
              BASE_ROUTE_OBJ_OBJ,cps_api_qualifier_TARGET);
    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_NBR_AF,AF_INET);

    uint32_t ip;
    struct in_addr a;
    inet_aton("6.6.6.6",&a);
    ip=a.s_addr;

    cps_api_object_attr_add(obj,BASE_ROUTE_OBJ_NBR_ADDRESS,&ip,sizeof(ip));
    int port_index = if_nametoindex("e101-001-0");
    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_NBR_IFINDEX, port_index);

    hal_mac_addr_t mac_addr = {0x00, 0x00, 0x00, 0xaa, 0xbb, 0xcc};

    cps_api_object_attr_add(obj, BASE_ROUTE_OBJ_NBR_MAC_ADDR, &mac_addr, HAL_MAC_ADDR_LEN);

    /*
     * CPS transaction
     */
    cps_api_transaction_params_t tr;
    ASSERT_TRUE(cps_api_transaction_init(&tr)==cps_api_ret_code_OK);
    cps_api_set(&tr,obj);
    ASSERT_TRUE(cps_api_commit(&tr)==cps_api_ret_code_OK);
    cps_api_transaction_close(&tr);
}
コード例 #3
0
static cps_api_return_code_t get_interface(
        const char * name, cps_api_get_params_t *param, size_t *ix) {

    cps_api_object_t obj = cps_api_object_create();
    uint_t ifix = cps_api_interface_name_to_if_index(name);

    cps_api_int_if_key_create(cps_api_object_key(obj),true,0,ifix);

    if (!cps_api_object_list_append(param->list,obj)) {
        cps_api_object_delete(obj);
        return cps_api_ret_code_ERR;
    }

    cps_api_object_attr_add(obj,cps_api_if_STRUCT_A_NAME,name,strlen(name)+1);
    cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_IFINDEX,ifix);

    unsigned int mtu;

    if (nas_os_util_int_mtu_get(name,&mtu)!=STD_ERR_OK) return cps_api_ret_code_ERR;
    cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_MTU,mtu);

    db_interface_state_t astate;
    db_interface_operational_state_t ostate;

    if (nas_os_util_int_admin_state_get(name,&astate,&ostate)!=STD_ERR_OK) return cps_api_ret_code_ERR;
    cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_ADMIN_STATE,astate);
    cps_api_object_attr_add_u32(obj,cps_api_if_STRUCT_A_OPER_STATE,ostate);

    hal_mac_addr_t mac;
    if (nas_os_util_int_mac_addr_get(name,&mac)!=STD_ERR_OK) return cps_api_ret_code_ERR;
    cps_api_object_attr_add(obj,cps_api_if_STRUCT_A_IF_MACADDR,&mac,sizeof(mac));

    return cps_api_ret_code_OK;
}
コード例 #4
0
extern "C" cps_api_return_code_t cps_api_commit_one(cps_api_operation_types_t type,
        cps_api_object_t obj, size_t retry_count, size_t ms_delay_between) {

    cps_api_transaction_params_t tr;

    if (cps_api_transaction_init(&tr)!=cps_api_ret_code_OK) {
        return cps_api_ret_code_ERR;
    }
    cps_api_transaction_guard tr_g(&tr);

    cps_api_key_set_attr(cps_api_object_key(obj),type);

    if (!cps_api_object_list_append(tr.change_list,obj)) {
        return cps_api_ret_code_ERR;
    }
    bool inf = retry_count==0;

    if (ms_delay_between==0) ms_delay_between = BASIC_WAIT_TIME;
    ms_delay_between = MILLI_TO_MICRO(ms_delay_between);

    cps_api_return_code_t rc = cps_api_ret_code_ERR;
    while (inf || (retry_count >0) ) {
        rc = cps_api_commit(&tr);
        if (rc==cps_api_ret_code_OK) {
            //since this will be erased by the caller remove it from the transaction list
            break;
        }
        if (!inf) --retry_count;
        std_usleep(ms_delay_between);
    }
    cps_api_object_list_remove(tr.change_list,0);
    return rc;
}
コード例 #5
0
TEST(std_nas_route_test, nas_route_arp_get) {
    cps_api_get_params_t gp;
    cps_api_get_request_init(&gp);

    cps_api_object_t obj = cps_api_object_list_create_obj_and_append(gp.filters);
    cps_api_key_from_attr_with_qual(cps_api_object_key(obj),BASE_ROUTE_OBJ_NBR,
                                        cps_api_qualifier_TARGET);
    unsigned short af = 2;
    cps_api_set_key_data(obj,BASE_ROUTE_OBJ_NBR_AF,cps_api_object_ATTR_T_U16,
                                 &af,sizeof(af));

    if (cps_api_get(&gp)==cps_api_ret_code_OK) {
        size_t mx = cps_api_object_list_size(gp.list);

        for ( size_t ix = 0 ; ix < mx ; ++ix ) {
            obj = cps_api_object_list_get(gp.list,ix);
            std::cout<<"ARP ENTRY "<<std::endl;
            std::cout<<"================================="<<std::endl;
            nas_route_dump_arp_object_content(obj);
            std::cout<<std::endl;
        }
    }

    cps_api_get_request_close(&gp);

}
コード例 #6
0
static t_std_error dn_nas_get_phy_media_default_setting(PLATFORM_MEDIA_TYPE_t media_type, cps_api_object_t obj)
{
    cps_api_get_params_t gp;
    cps_api_get_request_init(&gp);
    cps_api_get_request_guard rg(&gp);

    cps_api_object_t media_obj = cps_api_object_list_create_obj_and_append(gp.filters);
    t_std_error rc = STD_ERR_MK(e_std_err_INTERFACE, e_std_err_code_FAIL, 0);

    do {
        if (!cps_api_key_from_attr_with_qual(cps_api_object_key(media_obj),
                                BASE_MEDIA_MEDIA_INFO_OBJ, cps_api_qualifier_OBSERVED)) {
            break;
        }
        cps_api_set_key_data_uint(media_obj, BASE_MEDIA_MEDIA_INFO_MEDIA_TYPE, &media_type, sizeof(media_type));
        cps_api_object_attr_add_u32(media_obj, BASE_MEDIA_MEDIA_INFO_MEDIA_TYPE, media_type);
        if (cps_api_get(&gp) != cps_api_ret_code_OK)
            break;

        if (0 == cps_api_object_list_size(gp.list))
            break;

        media_obj = cps_api_object_list_get(gp.list,0);
        if (!cps_api_object_clone(obj, media_obj)) {
            break;
        }
        rc = STD_ERR_OK;
    } while(0);
    return rc;
}
コード例 #7
0
bool cps_api_nodes::load_aliases() {
    cps_db::connection_request b(cps_db::ProcessDBCache(),DEFAULT_REDIS_ADDR);
    if (!b.valid()) {
        return false;
    }

    alias_map_t _cpy;

    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_DETAILS, cps_api_qualifier_TARGET)) {
        return false;
    }

    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);
        const char *name = (const char*) cps_api_object_get_data(o,CPS_NODE_DETAILS_NAME);
        const char *alias = (const char*) cps_api_object_get_data(o,CPS_NODE_DETAILS_ALIAS);

        _cpy[name] = alias;
    }
    std::swap(_cpy,_alias_map);

    return true;
}
コード例 #8
0
bool cps_api_nodes::get_port_info(const char *group, _db_node_data *nd) {
    cps_api_object_guard og(cps_api_object_create());

    if (!cps_api_key_from_attr_with_qual(cps_api_object_key(og.get()),CPS_DB_INSTANCE_OBJ,
                                         cps_api_qualifier_TARGET)) {
        EV_LOGGING(DSAPI,ERR,"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;
    }

    cps_api_set_key_data(og.get(),CPS_DB_INSTANCE_GROUP,cps_api_object_ATTR_T_BIN,group,strlen(group)+1);
    cps_api_set_key_data(og.get(),CPS_DB_INSTANCE_NODE_ID,cps_api_object_ATTR_T_BIN,nd->_name.c_str(),strlen(nd->_name.c_str())+1);

    if (cps_db::get_object(b.get(),og.get())) {

        const char *port = (const char*) cps_api_object_get_data(og.get(),CPS_DB_INSTANCE_PORT);
        if(port == nullptr) {
            return false;
        }
        nd->_addr = port;
        return true;
    }
    return false;
}
コード例 #9
0
TEST(std_nas_route_test, nas_route_mp_delete) {

    cps_api_object_t obj = cps_api_object_create();
    //cps_api_key_init(cps_api_object_key(obj),cps_api_qualifier_TARGET,
    //        cps_api_obj_CAT_BASE_ROUTE, BASE_ROUTE_OBJ_OBJ,0 );

    cps_api_key_from_attr_with_qual(cps_api_object_key(obj),
              BASE_ROUTE_OBJ_OBJ,cps_api_qualifier_TARGET);
    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_ENTRY_AF,AF_INET);
    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_ENTRY_PREFIX_LEN,32);
    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_ENTRY_VRF_ID,0);

    uint32_t ip;
    struct in_addr a;
    inet_aton("6.6.6.6",&a);
    ip=a.s_addr;

    cps_api_object_attr_add(obj,BASE_ROUTE_OBJ_ENTRY_ROUTE_PREFIX,&ip,sizeof(ip));

    /*
     * CPS transaction
     */
    cps_api_transaction_params_t tr;
    ASSERT_TRUE(cps_api_transaction_init(&tr)==cps_api_ret_code_OK);
    cps_api_delete(&tr,obj);
    ASSERT_TRUE(cps_api_commit(&tr)==cps_api_ret_code_OK);
    cps_api_transaction_close(&tr);
    printf("___________________________________________\n");
    system("ip route show 6.6.6.6");
    printf("___________________________________________\n");
}
コード例 #10
0
t_std_error nas_get_lag_if_index (uint64_t ndi_port, hal_ifindex_t *lag_if_index)
{
    cps_api_get_params_t gp;
    cps_api_get_request_init(&gp);
    cps_api_get_request_guard rg(&gp);

    EV_LOG_TRACE(ev_log_t_INTERFACE, 2, "INTF-C", "querying for ifindex of ndi lag id 0x%x ", ndi_port);
    cps_api_object_t obj = cps_api_object_list_create_obj_and_append(gp.filters);

    cps_api_key_from_attr_with_qual(cps_api_object_key(obj), DELL_BASE_IF_CMN_IF_INTERFACES_INTERFACE_OBJ,
            cps_api_qualifier_TARGET);

    cps_api_object_attr_add_u64(obj,BASE_IF_LAG_IF_INTERFACES_INTERFACE_LAG_OPAQUE_DATA, ndi_port);
    cps_api_object_attr_add(obj,IF_INTERFACES_INTERFACE_TYPE,
                  (const char *)IF_INTERFACE_TYPE_IANAIFT_IANA_INTERFACE_TYPE_IANAIFT_IEEE8023ADLAG,
                  sizeof(IF_INTERFACE_TYPE_IANAIFT_IANA_INTERFACE_TYPE_IANAIFT_IEEE8023ADLAG));

    if (cps_api_get(&gp)==cps_api_ret_code_OK) {
        size_t mx = cps_api_object_list_size(gp.list);
        for (size_t ix = 0 ; ix < mx ; ++ix ) {
            cps_api_object_t obj = cps_api_object_list_get(gp.list,ix);
            cps_api_object_it_t it;
            cps_api_object_it_begin(obj,&it);
            cps_api_object_attr_t attr = cps_api_object_it_find(&it, DELL_BASE_IF_CMN_IF_INTERFACES_INTERFACE_IF_INDEX);
            if (!attr) {
               return  STD_ERR(INTERFACE, FAIL, 0);
            }
            *lag_if_index = cps_api_object_attr_data_u32(attr);
        }
    }
    return(STD_ERR_OK);
}
コード例 #11
0
TEST(std_nas_route_test, nas_neighbor_delete_static) {

    cps_api_object_t obj = cps_api_object_create();
    //cps_api_key_init(cps_api_object_key(obj),cps_api_qualifier_TARGET,
     //       cps_api_obj_CAT_BASE_ROUTE, BASE_ROUTE_OBJ_OBJ,0 );
    cps_api_key_from_attr_with_qual(cps_api_object_key(obj),
              BASE_ROUTE_OBJ_OBJ,cps_api_qualifier_TARGET);
    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_NBR_AF,AF_INET);

    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_NBR_TYPE,BASE_ROUTE_RT_TYPE_STATIC);
    uint32_t ip;
    struct in_addr a;
    inet_aton("6.6.6.7",&a);
    ip=a.s_addr;

    cps_api_object_attr_add(obj,BASE_ROUTE_OBJ_NBR_ADDRESS,&ip,sizeof(ip));
    int port_index = if_nametoindex("e101-001-0");
    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_NBR_IFINDEX, port_index);

    /*
     * CPS transaction
     */
    cps_api_transaction_params_t tr;
    ASSERT_TRUE(cps_api_transaction_init(&tr)==cps_api_ret_code_OK);
    cps_api_delete(&tr,obj);
    ASSERT_TRUE(cps_api_commit(&tr)==cps_api_ret_code_OK);
    cps_api_transaction_close(&tr);
}
コード例 #12
0
static void init_phy_port_obj(npu_id_t npu, port_t port, cps_api_object_t obj) {
    cps_api_key_from_attr_with_qual(cps_api_object_key(obj),
            BASE_IF_PHY_PHYSICAL_OBJ,cps_api_qualifier_TARGET);

    cps_api_object_attr_add_u32(obj,BASE_IF_PHY_PHYSICAL_NPU_ID,npu);
    cps_api_object_attr_add_u32(obj,BASE_IF_PHY_PHYSICAL_PORT_ID,port);
}
コード例 #13
0
static bool cps_api_clean_db_instance(const char *group) {
    cps_api_transaction_params_t tr;
    if (cps_api_transaction_init(&tr)!=cps_api_ret_code_OK) {
        return false;
    }

    cps_api_transaction_guard tg(&tr);
    cps_api_object_t  db_obj = cps_api_object_create();

    if(db_obj == nullptr ) return false;

    cps_api_key_from_attr_with_qual(cps_api_object_key(db_obj),CPS_DB_INSTANCE_OBJ,
                                    cps_api_qualifier_TARGET);

    cps_api_object_attr_add(db_obj,CPS_DB_INSTANCE_GROUP,group,strlen(group)+1);

    if(cps_api_delete(&tr,db_obj) != cps_api_ret_code_OK ) {
        return false;
    }

    if(cps_api_commit(&tr) != cps_api_ret_code_OK ) {
        EV_LOGGING(DSAPI,ERR,"CPS-DB","Failed to delete db instance for group %s",group);
        return false;
    }

    return true;
}
コード例 #14
0
cps_api_return_code_t ds_api_linux_interface_set_function(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 cps_api_ret_code_ERR;

    return execute_set_function(param->prev,obj);
}
コード例 #15
0
extern "C" cps_api_object_t cps_api_obj_tool_create(cps_api_qualifier_t qual,cps_api_attr_id_t id, bool add_defaults) {
    cps_api_object_guard og(cps_api_object_create());
    if (!og.valid()) return nullptr;

    if (!cps_api_key_from_attr_with_qual(cps_api_object_key(og.get()),id,qual)) {
        return nullptr;
    }

    return og.release();
}
コード例 #16
0
cps_api_return_code_t cps_api_delete_node_group(const char *grp) {
    cps_api_db_del_node_group(grp);
    cps_api_object_guard og(cps_api_object_create());
    cps_api_key_from_attr_with_qual(cps_api_object_key(og.get()),CPS_NODE_GROUP, cps_api_qualifier_TARGET);

    cps_api_object_attr_add(og.get(),CPS_NODE_GROUP_NAME,grp,strlen(grp)+1);

    cps_db::connection_request b(cps_db::ProcessDBCache(),DEFAULT_REDIS_ADDR);
    cps_db::delete_object(b.get(),og.get());
    return cps_api_ret_code_OK;
}
コード例 #17
0
cps_api_return_code_t cps_api_process_get_request(cps_api_get_params_t *param, size_t ix) {
    cps_api_return_code_t rc = cps_api_ret_code_ERR;
    char buff[SCRATCH_LOG_BUFF];
    cps_api_channel_t handle;
    cps_api_key_t *key = cps_api_object_key(cps_api_object_list_get(param->filters,ix));
    if (!cps_api_get_handle(*key,handle)) {
        EV_LOG(ERR,DSAPI,0,"NS","Failed to find owner for %s",
                cps_api_key_print(key,buff,sizeof(buff)-1));
        return cps_api_ret_code_NO_SERVICE;
    }

    do {
        cps_api_object_t o = cps_api_object_list_get(param->filters,ix);
        if (o==NULL) {
            EV_LOG(ERR,DSAPI,0,"NS","Missing filters... %s",
                                       cps_api_key_print(key,buff,sizeof(buff)-1));
            break;
        }
        if (!cps_api_send_one_object(handle,cps_api_msg_o_GET,o)) {
                   EV_LOG(ERR,DSAPI,0,"NS","Failed to send request %s",
                           cps_api_key_print(key,buff,sizeof(buff)-1));
                   break;
        }

        uint32_t op;
        do {
            if (param->timeout > 0) {
                fd_set rset;
                FD_ZERO(&rset);
                FD_SET(handle,&rset);
                if ((rc=cps_api_timeout_wait(handle,&rset,param->timeout,"CPS-OP-GET"))!=cps_api_ret_code_OK) {
                    EV_LOG(ERR,DSAPI,0,"CPS-OP-GET","Send request %s timed out",
                           cps_api_key_print(key,buff,sizeof(buff)-1));
                    break;
                }
            }
            size_t len;
            if (!cps_api_receive_header(handle,op,len)) break;
            if (op!=cps_api_msg_o_GET_RESP) break;
            cps_api_object_guard og (cps_api_receive_object(handle,len));

            if (og.valid() && cps_api_object_list_append(param->list,og.get())) {
                og.release();
            } else break;
        } while (op == cps_api_msg_o_GET_RESP);

        if (op!=cps_api_msg_o_GET_DONE) break; //leave an error code
        rc = cps_api_ret_code_OK;
    } while (0);

    cps_api_disconnect_owner(handle);

    return rc;
}
コード例 #18
0
static cps_api_return_code_t _write_function(void * context, cps_api_transaction_params_t * param,size_t ix) {
    GILLock gil;

    cps_api_object_t obj = cps_api_object_list_get(param->change_list,ix);
    if (obj==NULL) return cps_api_ret_code_ERR;

    cps_api_object_t prev = cps_api_object_list_get(param->prev,ix);
    if(prev==NULL) {
        prev = cps_api_object_list_create_obj_and_append(param->prev);
    }
    if (prev==NULL) return cps_api_ret_code_ERR;

    cps_api_operation_types_t op = cps_api_object_type_operation(cps_api_object_key(obj));

    PyObject *p = PyDict_New();
    PyRef dict(p);

    py_cps_util_set_item_to_dict(p,"change",cps_obj_to_dict(obj));
    py_cps_util_set_item_to_dict(p,"previous",cps_obj_to_dict(prev));

    static const std::map<int,std::string> trans = {
            {cps_api_oper_DELETE,"delete" },
            {cps_api_oper_CREATE,"create"},
            {cps_api_oper_SET, "set"},
            {cps_api_oper_ACTION,"rpc"}
    };

    py_cps_util_set_item_to_dict(p,"operation",PyString_FromString(trans.at(op).c_str()));

    py_callbacks_t *cb = (py_callbacks_t*)context;
    PyObject *res = cb->execute("transaction",p);

    if (res==NULL || !PyBool_Check(res) || (Py_False==(res))) {
        return cps_api_ret_code_ERR;
    }
    PyRef ret(res);

    PyObject *ch = PyDict_GetItemString(p,"change");
    if (ch==NULL) return cps_api_ret_code_ERR;

    cps_api_object_t o = dict_to_cps_obj(ch);
    cps_api_object_guard og(o);
    if(og.valid()) {
        cps_api_object_clone(obj,og.get());
    }

    PyObject *pr = PyDict_GetItemString(p,"previous");
    if (pr==NULL) return cps_api_ret_code_ERR;
    og.set(dict_to_cps_obj(pr));
    if (og.valid()) {
        cps_api_object_clone(prev,og.get());
    }
    return cps_api_ret_code_OK;
}
コード例 #19
0
bool get_netlink_data(int rt_msg_type, struct nlmsghdr *hdr, void *data) {

    cps_api_object_t obj=cps_api_object_create();
    if (!nl_get_if_info(rt_msg_type,hdr,obj)) return false;
    cps_api_object_attr_t attr = cps_api_object_attr_get(obj,cps_api_if_STRUCT_A_NAME);
    if (attr==CPS_API_ATTR_NULL) return false;
    char buff[1024];
    printf("OID = %s\n",cps_api_key_print(cps_api_object_key(obj),buff,sizeof(buff)));
    printf("Name:%s \n", (char*)cps_api_object_attr_data_bin(attr));
    cps_api_object_delete(obj);
    return true;
}
コード例 #20
0
static cps_api_return_code_t _write_function(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);
    if (obj==NULL) return cps_api_ret_code_ERR;
    cps_api_operation_types_t op = cps_api_object_type_operation(cps_api_object_key(obj));

    cps_api_object_t prev = cps_api_object_create();
    if (prev==NULL) return cps_api_ret_code_ERR;
    if (!cps_api_object_list_append(param->prev,prev)) {
        cps_api_object_delete(prev);
        return cps_api_ret_code_ERR;
    }

    cps_api_key_t _local_key;
    cps_api_key_init(&_local_key,cps_api_qualifier_TARGET,cps_api_obj_cat_ROUTE,cps_api_route_obj_EVENT,0);
    if (cps_api_key_matches(&_local_key,cps_api_object_key(obj),true)) {
        os_send_refresh(nas_nl_sock_T_ROUTE);
    } else {
        return _op(op,context,obj,prev);
    }
    return cps_api_ret_code_OK;
}
コード例 #21
0
TEST(std_nas_route_test, nas_route_add) {

    cps_api_object_t obj = cps_api_object_create();

    cps_api_key_from_attr_with_qual(cps_api_object_key(obj),
           BASE_ROUTE_OBJ_OBJ,cps_api_qualifier_TARGET);

    //cps_api_key_init(cps_api_object_key(obj),cps_api_qualifier_TARGET,
       //     cps_api_obj_CAT_BASE_ROUTE, BASE_ROUTE_OBJ_OBJ,0 );

    /*
     * Check mandatory route attributes
     *  BASE_ROUTE_OBJ_ENTRY_AF,     BASE_ROUTE_OBJ_ENTRY_VRF_ID);
     * BASE_ROUTE_OBJ_ENTRY_ROUTE_PREFIX,   BASE_ROUTE_OBJ_ENTRY_PREFIX_LEN;
     */

    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_ENTRY_AF,AF_INET);
    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_ENTRY_VRF_ID,0);
    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_ENTRY_PREFIX_LEN,32);

    uint32_t ip;
    struct in_addr a;
    inet_aton("6.6.6.6",&a);
    ip=a.s_addr;

    cps_api_object_attr_add(obj,BASE_ROUTE_OBJ_ENTRY_ROUTE_PREFIX,&ip,sizeof(ip));
    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_ENTRY_PREFIX_LEN,32);
    cps_api_attr_id_t ids[3];
    const int ids_len = sizeof(ids)/sizeof(*ids);
    ids[0] = BASE_ROUTE_OBJ_ENTRY_NH_LIST;
    ids[1] = 0;
    ids[2] = BASE_ROUTE_OBJ_ENTRY_NH_LIST_NH_ADDR;

    /*
     * Set Loopback0 NH
     */
    inet_aton("127.0.0.1",&a);
    ip=a.s_addr;
    cps_api_object_e_add(obj,ids,ids_len,cps_api_object_ATTR_T_BIN,
                    &ip,sizeof(ip));
    cps_api_object_attr_add_u32(obj,BASE_ROUTE_OBJ_ENTRY_NH_COUNT,1);

    /*
     * CPS transaction
     */
    cps_api_transaction_params_t tr;
    ASSERT_TRUE(cps_api_transaction_init(&tr)==cps_api_ret_code_OK);
    cps_api_create(&tr,obj);
    ASSERT_TRUE(cps_api_commit(&tr)==cps_api_ret_code_OK);
    cps_api_transaction_close(&tr);

}
コード例 #22
0
ファイル: nas_sflow_api.cpp プロジェクト: Azure/sonic-nas-l2
static void nas_sflow_fill_object(cps_api_object_t obj,nas_sflow_map_it it){

    cps_api_key_from_attr_with_qual(cps_api_object_key(obj),BASE_SFLOW_ENTRY_OBJ,
                                    cps_api_qualifier_TARGET);
    cps_api_set_key_data(obj,BASE_SFLOW_ENTRY_ID,cps_api_object_ATTR_T_U32,
                         &it->second.nas_sflow_id,sizeof(it->second.nas_sflow_id));
    cps_api_object_attr_add_u32(obj,BASE_SFLOW_ENTRY_ID,it->second.nas_sflow_id);
    cps_api_object_attr_add_u32(obj,BASE_SFLOW_ENTRY_IFINDEX,it->second.ifindex);
    cps_api_object_attr_add_u32(obj,BASE_SFLOW_ENTRY_DIRECTION,
                                   it->second.ndi_sflow_entry.sflow_direction);
    cps_api_object_attr_add_u32(obj,BASE_SFLOW_ENTRY_SAMPLING_RATE,
                                   it->second.ndi_sflow_entry.sampling_rate);
}
コード例 #23
0
static cps_api_return_code_t execute_set_function(cps_api_object_list_t list,
        cps_api_object_t elem) {

    size_t ix = 0;
    size_t mx = sizeof(db_linux_set_functions)/sizeof(*db_linux_set_functions);
    for ( ; ix < mx ; ++ix ) {
        if (db_linux_set_functions[ix].type ==
                cps_api_key_get_subcat(cps_api_object_key(elem))) {
            return db_linux_set_functions[ix].handler(list,elem);
        }
    }
    return cps_api_ret_code_OK;
}
コード例 #24
0
static void _ndi_port_event_update_ (ndi_port_t  *ndi_port, ndi_port_event_t event, uint32_t hwport) {
    cps_api_object_guard og(cps_api_object_create());

    init_phy_port_obj(ndi_port->npu_id,ndi_port->npu_port,og.get());

    cps_api_object_attr_add_u32(og.get(),BASE_IF_PHY_PHYSICAL_HARDWARE_PORT_ID,hwport);

    if (!(event == ndi_port_ADD || event==ndi_port_DELETE)) return ;

    cps_api_object_set_type_operation(cps_api_object_key(og.get()),event == ndi_port_ADD ?
        cps_api_oper_CREATE : cps_api_oper_DELETE );

    hal_interface_send_event(og.get());
}
コード例 #25
0
cps_api_return_code_t cps_api_process_rollback_request(cps_api_transaction_params_t *param,
        size_t ix) {
    cps_api_return_code_t rc = cps_api_ret_code_ERR;

    cps_api_object_t obj = cps_api_object_list_get(param->prev,ix);
    if (obj==NULL) {
        EV_LOG(ERR,DSAPI,0,"CPS IPC","No Revert Object");
        return rc;
    }

    cps_api_channel_t handle;
    cps_api_key_t *key = cps_api_object_key(obj);

    char buff[CPS_API_KEY_STR_MAX];
    EV_LOG(TRACE,DSAPI,0, "CPS IPC", "Object for rollback request: %s ",
                                    cps_api_key_name_print(key, buff, sizeof(buff)));

    if (!cps_api_get_handle(*key,handle)) {
        EV_LOG(ERR,DSAPI,0,"CPS IPC","No Service");
        return cps_api_ret_code_NO_SERVICE;
    }

    cps_api_channel_handle_guard hg(handle);

    rc = cps_api_ret_code_ERR;

    do {
        if (!cps_api_send_one_object(handle,cps_api_msg_o_REVERT,obj)) {
            EV_LOG(ERR,DSAPI,0,"CPS IPC","Could not send REVERT header");
            break;
        }

        uint32_t op;
           size_t len;
           if (!cps_api_receive_header(handle,op,len)) {
               EV_LOG(ERR,DSAPI,0,"CPS IPC","Failed to read the receive header for revert object");
               break;
           }

           if (op == cps_api_msg_o_RETURN_CODE) {
               if (!cps_api_receive_data(handle,&rc,sizeof(rc))) break;
           }

    } while (0);

    cps_api_disconnect_owner(handle);

    return rc;
}
コード例 #26
0
static cps_api_return_code_t _phy_int_set(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);
    if (obj==NULL) return cps_api_ret_code_ERR;

    cps_api_object_t prev = cps_api_object_list_create_obj_and_append(param->prev);
    if (prev==nullptr) return cps_api_ret_code_ERR;

    cps_api_operation_types_t op = cps_api_object_type_operation(cps_api_object_key(obj));

    if (op==cps_api_oper_SET) return _phy_set(obj,prev);

    EV_LOG(ERR,INTERFACE,0,"NAS-PHY","Invalid operation");

    return cps_api_ret_code_ERR;
}
コード例 #27
0
/**
  * This function provides NAS-QoS priority_group CPS API rollback function
  * @Param      Standard CPS API params
  * @Return   Standard Error Code
  */
cps_api_return_code_t nas_qos_cps_api_priority_group_rollback(void * context,
                                            cps_api_transaction_params_t * param,
                                            size_t ix)
{
    cps_api_object_t obj = cps_api_object_list_get(param->prev,ix);
    cps_api_operation_types_t op = cps_api_object_type_operation(cps_api_object_key(obj));

    std_mutex_simple_lock_guard p_m(&priority_group_mutex);

    if (op == cps_api_oper_SET) {
        nas_qos_cps_api_priority_group_set(obj, NULL);
    }

    return cps_api_ret_code_OK;
}
コード例 #28
0
bool cps_api_db_del_node_group(const char *group) {
    std::lock_guard<std::recursive_mutex> lg(_mutex);

    cps_api_node_data_type_t type;
    if(!_nodes->get_group_type(std::string(group),type)) {
        EV_LOGGING(DSAPI,ERR,"DEL-MASTER","Failed to get group type for %s",group);
        return false;
    }

    if(type != cps_api_node_data_1_PLUS_1_REDUNDENCY) {
        return true;
    }

    auto it = _nodes->_db_node_map.find(group);
    if( it == _nodes->_db_node_map.end()) {
        EV_LOGGING(DSAPI,ERR,"CPS-DB","No group named %s found",group);
        return false;
    }

    for ( auto node_it : it->second) {
        cps_db::connection_request b(cps_db::ProcessDBCache(),DEFAULT_REDIS_ADDR);
        if (!b.valid()) {
            return false;
        }
        cps_api_object_guard og(cps_api_object_create());

        if (!cps_api_key_from_attr_with_qual(cps_api_object_key(og.get()),CPS_DB_INSTANCE_OBJ,
                                             cps_api_qualifier_TARGET)) {
            EV_LOGGING(DSAPI,ERR,"CPS-CLS-MAP","Meta data for cluster set is not loaded.");
            return false;
        }


        cps_api_set_key_data(og.get(),CPS_DB_INSTANCE_GROUP,cps_api_object_ATTR_T_BIN,group,strlen(group)+1);
        cps_api_set_key_data(og.get(),CPS_DB_INSTANCE_NODE_ID,cps_api_object_ATTR_T_BIN,node_it._name.c_str(),
                             strlen(node_it._name.c_str())+1);

        cps_db::delete_object(b.get(),og.get());
    }

    _nodes->_master.erase(std::string(group));
    _nodes->_db_node_map.erase(std::string(group));
    _nodes->remove_master_set(std::string(group));

    return cps_api_clean_db_instance(group);

}
コード例 #29
0
t_std_error dn_nas_lag_get_ndi_ids (hal_ifindex_t if_index, nas_ndi_obj_id_table_handle_t ndi_id_data)
{
    if(ndi_id_data == NULL) {
        EV_LOG_ERR(ev_log_t_INTERFACE, 2, "INTF-C","Input ndi_data is NULL");
        return(STD_ERR(INTERFACE, PARAM, 0));
    }

    cps_api_get_params_t gp;
    cps_api_get_request_init(&gp);

    cps_api_object_t obj = cps_api_object_list_create_obj_and_append(gp.filters);
    t_std_error rc = STD_ERR(INTERFACE, FAIL, 0);

    do {
        if (!cps_api_key_from_attr_with_qual(cps_api_object_key(obj),
                DELL_BASE_IF_CMN_IF_INTERFACES_INTERFACE_OBJ, cps_api_qualifier_TARGET)) {
            break;
        }

        cps_api_object_attr_add_u32(obj,DELL_BASE_IF_CMN_IF_INTERFACES_INTERFACE_IF_INDEX, if_index);
        cps_api_object_attr_add(obj,IF_INTERFACES_INTERFACE_TYPE,
                (const char *)IF_INTERFACE_TYPE_IANAIFT_IANA_INTERFACE_TYPE_IANAIFT_IEEE8023ADLAG,
                sizeof(IF_INTERFACE_TYPE_IANAIFT_IANA_INTERFACE_TYPE_IANAIFT_IEEE8023ADLAG));

        if (cps_api_get(&gp) != cps_api_ret_code_OK)
            break;

        if (0 == cps_api_object_list_size(gp.list))
            break;

        obj = cps_api_object_list_get(gp.list,0);
        cps_api_attr_id_t  attr_list[] = {BASE_IF_LAG_IF_INTERFACES_INTERFACE_LAG_OPAQUE_DATA};

        if (!nas_ndi_obj_id_table_cps_unserialize (ndi_id_data, obj, attr_list,
                                                   sizeof (attr_list)/sizeof (cps_api_attr_id_t)))
        {
            EV_LOG_ERR(ev_log_t_INTERFACE, 2, "INTF-C","Failed to get LAG opaque data");
            break;
        }
        rc = STD_ERR_OK;

    } while (0);

    cps_api_get_request_close(&gp);
    return rc;
}
コード例 #30
0
extern "C" t_std_error dn_hal_get_interface_mac(hal_ifindex_t if_index, hal_mac_addr_t mac_addr)
{
    if(mac_addr == NULL) {
        EV_LOG_TRACE(ev_log_t_INTERFACE, 2, "INTF-C","mac_addr_ptr NULL");
        return(STD_ERR_MK(e_std_err_INTERFACE, e_std_err_code_PARAM, 0));
    }

    cps_api_get_params_t gp;
    cps_api_get_request_init(&gp);

    cps_api_object_t obj = cps_api_object_list_create_obj_and_append(gp.filters);
    t_std_error rc = STD_ERR_MK(e_std_err_INTERFACE, e_std_err_code_FAIL, 0);

    do {
        if (!cps_api_key_from_attr_with_qual(cps_api_object_key(obj),
                                DELL_BASE_IF_CMN_IF_INTERFACES_INTERFACE_OBJ, cps_api_qualifier_TARGET)) {
            break;
        }

        cps_api_object_attr_add_u32(obj,DELL_BASE_IF_CMN_IF_INTERFACES_INTERFACE_IF_INDEX, if_index);

        if (cps_api_get(&gp) != cps_api_ret_code_OK)
            break;

        if (0 == cps_api_object_list_size(gp.list))
            break;

        obj = cps_api_object_list_get(gp.list,0);

        cps_api_object_attr_t attr = cps_api_object_attr_get(obj,DELL_IF_IF_INTERFACES_INTERFACE_PHYS_ADDRESS);
        if (attr != NULL) {
            void *_mac_str = cps_api_object_attr_data_bin(attr);
            size_t addr_len = strlen(static_cast<char *>(_mac_str));
            EV_LOG_TRACE(ev_log_t_INTERFACE, 2, "INTF-C","mac_addr %s, len %d",
                         _mac_str, addr_len);

            if (std_string_to_mac((hal_mac_addr_t *)mac_addr, static_cast<const char *>(_mac_str), addr_len)) {
                rc = STD_ERR_OK;
            }
        }

    } while (0);

    cps_api_get_request_close(&gp);
    return rc;
}