Ejemplo n.º 1
0
TEST(std_nas_route_test, nas_neighbor_set_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);

    hal_mac_addr_t mac_addr = {0x00, 0x00, 0x11, 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);
}
Ejemplo n.º 2
0
static bool qos_map_add_int_by_type(cps_api_object_t obj,
        cps_api_attr_id_t id,
        uint_t val,
        cps_api_object_ATTR_TYPE_t type)
{
    switch (type) {
    case cps_api_object_ATTR_T_BIN:
    {
        uint8_t val8 = (uint8_t) val;
        return cps_api_object_attr_add(obj, id, &val8, sizeof(uint8_t));
    }
    case cps_api_object_ATTR_T_U16:
    {
        uint16_t val16 = (uint16_t) val;
        return cps_api_object_attr_add(obj, id, &val16, sizeof(uint16_t));
    }
    case cps_api_object_ATTR_T_U32:
    {
        uint32_t val32 = (uint32_t) val;
        return cps_api_object_attr_add(obj, id, &val32, sizeof(uint32_t));
    }
    case cps_api_object_ATTR_T_U64:
    {
        uint64_t val64 = (uint64_t) val;
        return cps_api_object_attr_add(obj, id, &val64, sizeof(uint64_t));
    }
    default:
        return false;
    }
}
Ejemplo n.º 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;
}
Ejemplo n.º 4
0
TEST(std_nas_route_test, nas_neighbor_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_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);

    /*
     * 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);
}
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;
}
Ejemplo n.º 6
0
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);

}
Ejemplo n.º 7
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);
}
Ejemplo n.º 8
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");
}
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;
}
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;
}
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);

}
Ejemplo n.º 12
0
cps_api_return_code_t cps_api_set_node_group(cps_api_node_group_t *group) {

    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,group->id,strlen(group->id)+1);

    for ( size_t ix = 0; ix < group->addr_len; ++ix ) {
        cps_api_attr_id_t _ip[]= {CPS_NODE_GROUP_NODE,ix,CPS_NODE_GROUP_NODE_IP};
        cps_api_object_e_add(og.get(),_ip,sizeof(_ip)/sizeof(*_ip),cps_api_object_ATTR_T_BIN,
                             group->addrs[ix].addr,strlen(group->addrs[ix].addr)+1);
        cps_api_attr_id_t _alias[]= {CPS_NODE_GROUP_NODE,ix,CPS_NODE_GROUP_NODE_NAME};
        cps_api_object_e_add(og.get(),_alias,sizeof(_alias)/sizeof(*_alias),cps_api_object_ATTR_T_BIN,
                             group->addrs[ix].node_name,strlen(group->addrs[ix].node_name)+1);
    }

    cps_api_object_attr_add(og.get(),CPS_NODE_GROUP_TYPE,&group->data_type,sizeof(group->data_type));

    cps_db::connection_request b(cps_db::ProcessDBCache(),DEFAULT_REDIS_ADDR);
    if (!b.valid()) {
        return cps_api_ret_code_ERR;
    }
    cps_api_object_guard tmp(cps_api_object_create());

    if (!cps_api_object_clone(tmp.get(),og.get())) {
        return cps_api_ret_code_ERR;
    }

    bool changed = false;
    if (cps_db::get_object(b.get(),tmp.get())) {
        changed = true;
    }

    (void)changed;
    if (!cps_db::store_object(b.get(),og.get())) {
        return cps_api_ret_code_ERR;
    }

    if(group->data_type == cps_api_node_data_1_PLUS_1_REDUNDENCY) {
        return cps_api_create_global_instance(group);
    }
    ///TODO send out changed...

    return cps_api_ret_code_OK;
}
Ejemplo n.º 13
0
static void nas_mirror_fill_object(cps_api_object_t obj, nas_mirror_table_it it){

    nas_mirror_entry & entry = it->second;
    cps_api_key_from_attr_with_qual(cps_api_object_key(obj),BASE_MIRROR_ENTRY_OBJ,
                                    cps_api_qualifier_TARGET);
    nas_mirror_id_t id = entry.get_id();
    cps_api_set_key_data(obj,BASE_MIRROR_ENTRY_ID,cps_api_object_ATTR_T_U32,
                         &id,sizeof(id));
    cps_api_object_attr_add_u32(obj,BASE_MIRROR_ENTRY_ID,id);

    nas::ndi_obj_id_table_t mirror_opaque_data_table;
    mirror_opaque_data_table[entry.get_npu_id()] = entry.get_ndi_id();
    cps_api_attr_id_t  attr_id_list[] = {BASE_MIRROR_ENTRY_OPAQUE_DATA};
    nas::ndi_obj_id_table_cps_serialize (mirror_opaque_data_table, obj, attr_id_list,
                                         sizeof(attr_id_list)/sizeof(attr_id_list[0]));


    cps_api_object_attr_add_u32(obj,BASE_MIRROR_ENTRY_DST_INTF,entry.get_dst_intf());
    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(auto src_it = entry.get_src_intf_map()->begin() ; src_it != entry.get_src_intf_map()->end() ; ++src_it){
        cps_api_object_e_add(obj,ids,ids_len,cps_api_object_ATTR_T_U32,&(src_it->first),sizeof(src_it->first));
        ids[2]=BASE_MIRROR_ENTRY_INTF_DIRECTION;
        cps_api_object_e_add(obj,ids,ids_len,cps_api_object_ATTR_T_U32,&(src_it->second),sizeof(src_it->second));
        ids[2]=BASE_MIRROR_ENTRY_INTF_SRC;
        ++ids[1];
    }

    cps_api_object_attr_add_u32(obj,BASE_MIRROR_ENTRY_FLOW_ENABLED,entry.get_flow());
    cps_api_object_attr_add_u32(obj,BASE_MIRROR_ENTRY_TYPE,entry.get_mode());

    if(entry.get_mode() == BASE_MIRROR_MODE_RSPAN){
        cps_api_object_attr_add_u32(obj,BASE_MIRROR_ENTRY_VLAN,entry.get_vlan_id());
    }

    if(entry.get_mode() == BASE_MIRROR_MODE_ERSPAN){
        cps_api_object_attr_add_u32(obj,BASE_MIRROR_ENTRY_SOURCE_IP,entry.get_dst_ip()->u.v4_addr);
        cps_api_object_attr_add_u32(obj,BASE_MIRROR_ENTRY_DESTINATION_IP,entry.get_src_ip()->u.v4_addr);
        cps_api_object_attr_add(obj,BASE_MIRROR_ENTRY_SOURCE_MAC,(void *)entry.get_src_mac(),sizeof(hal_mac_addr_t));
        cps_api_object_attr_add(obj,BASE_MIRROR_ENTRY_DEST_MAC,(void *)entry.get_dst_mac(),sizeof(hal_mac_addr_t));
        cps_api_object_attr_add_u32(obj,BASE_MIRROR_ENTRY_ERSPAN_VLAN_ID,entry.get_vlan_id());
    }
}
Ejemplo n.º 14
0
static inline bool os_interface_lag_add_member_name(hal_ifindex_t ifix, cps_api_object_t obj)
{
    char if_name[HAL_IF_NAME_SZ+1];
    if (cps_api_interface_if_index_to_name(ifix,if_name,  sizeof(if_name))==NULL) {
        return false;
    }

    cps_api_object_attr_add(obj, DELL_IF_IF_INTERFACES_INTERFACE_MEMBER_PORTS_NAME, if_name, strlen(if_name)+1);
    return true;
}
Ejemplo n.º 15
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;
}
Ejemplo n.º 16
0
cps_api_return_code_t cps_api_set_identity(const char *name, const char **alias, size_t len) {
    cps_db::connection_request b(cps_db::ProcessDBCache(),DEFAULT_REDIS_ADDR);
    if (!b.valid()) {
        return cps_api_ret_code_ERR;
    }

    cps_api_object_guard og(cps_api_object_create());

    cps_api_key_from_attr_with_qual(cps_api_object_key(og.get()),CPS_NODE_DETAILS, cps_api_qualifier_TARGET);
    cps_api_object_attr_add(og.get(),CPS_NODE_DETAILS_ALIAS,name,strlen(name)+1);

    size_t ix = 0;
    for (; ix < len ; ++ix ) {
        cps_api_object_attr_add(og.get(),CPS_NODE_DETAILS_NAME,alias[ix],strlen(alias[ix])+1);
        if (!cps_db::store_object(b.get(),og.get())) {
            EV_LOG(ERR,DSAPI,0,"SET-IDENT","Failed to update identity setting for local node");
        }
        cps_api_object_attr_delete(og.get(),CPS_NODE_DETAILS_NAME);
    }
    return cps_api_ret_code_OK;
}
Ejemplo n.º 17
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);

}
Ejemplo n.º 18
0
t_std_error nas_os_util_int_get_if_details(const char *name, cps_api_object_t obj)
{
    struct ifreq  ifr;
    strncpy(ifr.ifr_ifrn.ifrn_name,name,sizeof(ifr.ifr_ifrn.ifrn_name)-1);
    const int NAS_LINK_MTU_HDR_SIZE = 32;

    int sock = socket(AF_INET, SOCK_DGRAM, 0);
    if (sock==-1) return STD_ERR(INTERFACE,FAIL,errno);

    t_std_error err = STD_ERR(INTERFACE,FAIL,errno);

    cps_api_object_attr_add(obj, IF_INTERFACES_INTERFACE_NAME, name, (strlen(name)+1));

    do {
        if (ioctl(sock, SIOCGIFFLAGS, &ifr) >= 0) {
            cps_api_object_attr_add_u32(obj,BASE_IF_LINUX_IF_INTERFACES_INTERFACE_IF_FLAGS, ifr.ifr_flags);
            cps_api_object_attr_add_u32(obj,IF_INTERFACES_INTERFACE_ENABLED,
                (ifr.ifr_flags & IFF_UP) ? true :false);
        } else break;

        ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
        if (ioctl(sock, SIOCGIFHWADDR, &ifr) >= 0) {
            char buff[40];
            const char *_p = std_mac_to_string((const hal_mac_addr_t *)(ifr.ifr_hwaddr.sa_data),
                                                buff, sizeof(buff));
            cps_api_object_attr_add(obj,DELL_IF_IF_INTERFACES_INTERFACE_PHYS_ADDRESS,_p,strlen(_p)+1);
        } else break;

        if (ioctl(sock, SIOCGIFMTU, &ifr) >= 0) {
            cps_api_object_attr_add_u32(obj, DELL_IF_IF_INTERFACES_INTERFACE_MTU,
                                        (ifr.ifr_mtu  + NAS_LINK_MTU_HDR_SIZE));
        } else break;

        err = STD_ERR_OK;
    } while(0);

    close(sock);
    return err;
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
0
TEST(std_nas_route_test, nas_route_delete_scale) {

    char ip_addr[256];
    int i=1, j=1;
    uint32_t ip;
    struct in_addr a;



    for(i=1; i<65; i++) {
        for (j=1; j<251; j++) {

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


    snprintf(ip_addr,256, "11.10.%d.%d",i,j);
    //printf ("Delete Route:%s \n", ip_addr);

    inet_aton(ip_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);
        }
    }

}
Ejemplo n.º 21
0
TEST(std_nas_route_test, nas_peer_routing_config_set) {
    cps_api_object_t obj = cps_api_object_create();

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

    cps_api_object_attr_add_u32(obj,BASE_ROUTE_PEER_ROUTING_CONFIG_VRF_ID,0);

    hal_mac_addr_t mac_addr = {0x01, 0x22, 0x23, 0x24, 0x25, 0x26};

    cps_api_object_attr_add(obj, BASE_ROUTE_PEER_ROUTING_CONFIG_PEER_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);
}
Ejemplo n.º 22
0
//Scale tests for route add/delete
TEST(std_nas_route_test, nas_route_add_scale) {
    char ip_addr[256];
    int i=1, j=1 ,count=0;
    uint32_t ip;
    struct in_addr a;


   for(i=1; i<101; i++) {
       for (j=1; j<251; j++) {

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


    snprintf(ip_addr,256, "11.10.%d.%d",i,j);
   // printf ("Add Route:%s, NH:1.1.1.4\n", ip_addr);

    inet_aton(ip_addr,&a);
    //inet_aton("6.6.6.6",&a);
    ip=a.s_addr;
    //printf ("Route:%d\n", ip);
    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  NH
     */
    inet_aton("1.1.1.4",&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);
    count++;

       }
   }
printf("Sent %d Routes\n", count);
}
Ejemplo n.º 23
0
cps_api_return_code_t cps_api_create_global_instance(cps_api_node_group_t *group) {
    if(group == nullptr) return cps_api_ret_code_ERR;

    size_t local_node_ix;
    if(!cps_api_find_local_node(group,local_node_ix)) {
        EV_LOGGING(DSAPI,ERR,"SET-GLOBAL","Failed to find local node in group %s",group);
        return cps_api_ret_code_ERR;
    }

    if(local_node_ix >= group->addr_len) {
        return cps_api_ret_code_ERR;
    }

    cps_api_transaction_params_t tr;
    if (cps_api_transaction_init(&tr)!=cps_api_ret_code_OK) {
        EV_LOGGING(DSAPI,ERR,"SET-GLOBAL","Failed to init transaction");
        return cps_api_ret_code_ERR;
    }

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

    if(db_obj == nullptr ) return cps_api_ret_code_ERR;

    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->id,strlen(group->id)+1);

    if(cps_api_create(&tr,db_obj) != cps_api_ret_code_OK ) {
        return cps_api_ret_code_ERR;
    }

    if(cps_api_commit(&tr) != cps_api_ret_code_OK ) {
        EV_LOGGING(DSAPI,ERR,"SET-GLOBAL","Failed to create new global instance for %s",group);
        return cps_api_ret_code_ERR;
    }

    cps_api_object_t ret_obj = cps_api_object_list_get(tr.change_list,0);
    if (ret_obj == nullptr ) {
        EV_LOGGING(DSAPI,ERR,"SET-GLOBAL","Failed to find db instance port info for %s",group);
        return cps_api_ret_code_ERR;
    }

    // Get the port where new db instance was started
    const char * db_port = (const char*) cps_api_object_get_data(ret_obj,CPS_DB_INSTANCE_PORT);
    std::string _db_port = db_port;

    /*
     * Push the group name local node id and its port to local/remote DB.
     */
    cps_api_node_ident & node = group->addrs[local_node_ix];
    cps_api_object_guard db_node(cps_api_object_create());
    if (db_node.get() == nullptr) {
        return cps_api_ret_code_ERR;
    }

    cps_api_key_from_attr_with_qual(cps_api_object_key(db_node.get()),CPS_DB_INSTANCE_OBJ, cps_api_qualifier_TARGET);

    cps_api_set_key_data(db_node.get(),CPS_DB_INSTANCE_GROUP,cps_api_object_ATTR_T_BIN,group->id,strlen(group->id)+1);
    cps_api_set_key_data(db_node.get(),CPS_DB_INSTANCE_NODE_ID,cps_api_object_ATTR_T_BIN,node.node_name,strlen(node.node_name)+1);
    cps_api_object_attr_add(db_node.get(),CPS_DB_INSTANCE_PORT,_db_port.c_str(),strlen(_db_port.c_str())+1);


    if (!cps_api_node_set_iterate(group->id,[&db_node](const std::string &name,void *c) {
    cps_db::connection_request r(cps_db::ProcessDBCache(),name.c_str());

        cps_db::store_object(r.get(),db_node.get());
        return;

    },nullptr)) {
        return cps_api_ret_code_ERR;
    }
    return cps_api_ret_code_OK;
}
Ejemplo n.º 24
0
bool cps_api_key_set_group(cps_api_object_t obj,const char *group) {
    return cps_api_object_attr_add(obj,CPS_OBJECT_GROUP_GROUP,group,strlen(group)+1);
}