static bool _get_ifinfo (hal_ifindex_t ifindex, interface_ctrl_t *intf_ctrl_p)
{
    intf_ctrl_p->q_type = HAL_INTF_INFO_FROM_IF;
    intf_ctrl_p->if_index = ifindex;

    return (dn_hal_get_interface_info(intf_ctrl_p) == STD_ERR_OK);
}
Beispiel #2
0
t_std_error hal_form_nbr_entry(ndi_neighbor_t *p_nbr_entry, t_fib_nh *p_nh)
{
    interface_ctrl_t intf_ctrl;

    if (p_nh->p_arp_info) {
        memcpy(&(p_nbr_entry->egress_data.neighbor_mac), &(p_nh->p_arp_info->mac_addr), HAL_RT_MAC_ADDR_LEN);
        p_nbr_entry->egress_data.vlan_id  = p_nh->p_arp_info->vlan_id;
        p_nbr_entry->state  = (uint32_t)p_nh->p_arp_info->state;
    }

    if(STD_IP_IS_ADDR_ZERO(&p_nh->key.ip_addr)) {
        return STD_ERR_MK(e_std_err_ROUTE, e_std_err_code_FAIL, 0);
    }

    if(p_nh->key.ip_addr.af_index == HAL_RT_V4_AFINDEX) {
        memcpy(&(p_nbr_entry->ip_addr.u.v4_addr), &(p_nh->key.ip_addr.u.v4_addr), HAL_RT_V4_ADDR_LEN);
    } else {
        memcpy(&(p_nbr_entry->ip_addr.u.v6_addr), &(p_nh->key.ip_addr.u.v6_addr), HAL_RT_V6_ADDR_LEN);
    }
    p_nbr_entry->ip_addr.af_index = p_nh->key.ip_addr.af_index;

    if (p_nh->p_arp_info) {
        memset(&intf_ctrl, 0, sizeof(interface_ctrl_t));
        intf_ctrl.q_type = HAL_INTF_INFO_FROM_IF;
        intf_ctrl.if_index = p_nh->p_arp_info->if_index;

        if ((dn_hal_get_interface_info(&intf_ctrl)) == STD_ERR_OK) {
            p_nbr_entry->egress_data.port_tgid = intf_ctrl.port_id;
        }
    }

    return STD_ERR_OK;

}
Beispiel #3
0
t_std_error nas_sflow_create_session(cps_api_object_t obj){

    cps_api_object_attr_t ifindex_attr;
    cps_api_attr_id_t ifindex_attr_id = BASE_SFLOW_ENTRY_IFINDEX;

    ifindex_attr = cps_api_object_e_get (obj, &ifindex_attr_id, 1);

    if (ifindex_attr == NULL) {
        NAS_SFLOW_LOG(ERR,ev_log_s_MINOR,"No Interface Index passed for creating sFlow session");
        return STD_ERR(SFLOW,CFG,0);
    }

    nas_sflow_entry_t nas_sflow_entry;

    if(!nas_sflow_fill_session_info(obj,&nas_sflow_entry)){
        return STD_ERR(SFLOW,CFG,0);
    }

    interface_ctrl_t intf_ctrl;
    memset(&intf_ctrl, 0, sizeof(interface_ctrl_t));

    intf_ctrl.q_type = HAL_INTF_INFO_FROM_IF;
    intf_ctrl.if_index = nas_sflow_entry.ifindex;

    if (dn_hal_get_interface_info(&intf_ctrl) != STD_ERR_OK) {
        NAS_SFLOW_LOG(ERR,0,"Interface %d has NO slot %d, port %d",
                intf_ctrl.if_index, intf_ctrl.npu_id, intf_ctrl.port_id);
        return STD_ERR(SFLOW,FAIL,0);
    }

    nas_sflow_entry.ndi_sflow_entry.port_id = intf_ctrl.port_id;
    nas_sflow_entry.ndi_sflow_entry.npu_id = intf_ctrl.npu_id;
    nas_sflow_entry.ndi_sflow_entry.enabled = true;

    std_mutex_simple_lock_guard lock(&nas_sflow_mutex);

    if(ndi_sflow_create_session(&(nas_sflow_entry.ndi_sflow_entry)) != STD_ERR_OK){
        return STD_ERR(SFLOW,FAIL,0);
    }

    if(!nas_sflow_update_direction(&nas_sflow_entry.ndi_sflow_entry,true)){
        NAS_SFLOW_LOG(ERR,0,"Failed to add source ports to session %llu ",
                      nas_sflow_entry.ndi_sflow_entry.ndi_sflow_id);
        ndi_sflow_delete_session(&nas_sflow_entry.ndi_sflow_entry);
        return STD_ERR(SFLOW,FAIL,0);
    }

    nas_sflow_entry.nas_sflow_id= nas_sflow_get_next_index();
    cps_api_set_key_data(obj,BASE_SFLOW_ENTRY_ID,cps_api_object_ATTR_T_U32,
                         &nas_sflow_entry.nas_sflow_id,sizeof(nas_sflow_entry.nas_sflow_id));
    NAS_SFLOW_LOG(INFO,0,"Created new nas sflow entry with id %d",nas_sflow_entry.nas_sflow_id);
    nas_sflow_table.insert(nas_sflow_pair(nas_sflow_entry.nas_sflow_id,std::move(nas_sflow_entry)));

    return STD_ERR_OK;
}
static bool nas_mirror_intf_to_port(hal_ifindex_t ifindex,interface_ctrl_t *intf_ctrl){
    memset(intf_ctrl, 0, sizeof(interface_ctrl_t));
    intf_ctrl->q_type = HAL_INTF_INFO_FROM_IF;
    intf_ctrl->if_index = ifindex;

    if (dn_hal_get_interface_info(intf_ctrl) != STD_ERR_OK) {
        NAS_MIRROR_LOG(ERR,0,"Interface %d has NO slot %d, port %d",
                   intf_ctrl->if_index, intf_ctrl->npu_id, intf_ctrl->port_id);
        return false;
    }

    return true;
}
t_std_error nas_mac_delete_entries_from_hw(nas_mac_entry_t *entry, bool static_type,
                                           ndi_mac_delete_type_t del_type,
                                           bool subtype_all) {
    t_std_error rc = STD_ERR_OK;
    ndi_obj_id_t obj_id;
    interface_ctrl_t intf_ctrl;
    memset(&intf_ctrl, 0, sizeof(interface_ctrl_t));
    intf_ctrl.q_type = HAL_INTF_INFO_FROM_IF;
    intf_ctrl.if_index = entry->ifindex;

    ndi_mac_entry_t ndi_mac_entry;
    memset(&ndi_mac_entry, 0, sizeof(ndi_mac_entry_t));

    if ((del_type == NDI_MAC_DEL_BY_PORT) || (del_type == NDI_MAC_DEL_BY_PORT_VLAN))
    {
        if ((rc = dn_hal_get_interface_info(&intf_ctrl)) != STD_ERR_OK) {
             NAS_MAC_LOG(ERR, ev_log_s_MAJOR,"Get interface info failed for if index 0x%x.", entry->ifindex);
             return rc;
        }
        if(intf_ctrl.int_type == nas_int_type_LAG)
        {
           if(nas_mac_lag_obj_id_get(entry->ifindex, obj_id) == STD_ERR_OK)
           {
              ndi_mac_entry.ndi_lag_id = obj_id;
           }
        }
        else
        {
           ndi_mac_entry.npu_id = 0; /* TODO: Handle multiple NPU scenerio */
           ndi_mac_entry.port_info.npu_id = intf_ctrl.npu_id;
           ndi_mac_entry.port_info.npu_port = intf_ctrl.port_id;
        }
    }

    ndi_mac_entry.vlan_id = entry->entry_key.vlan_id;

    if (del_type == NDI_MAC_DEL_SINGLE_ENTRY) {
        memcpy(ndi_mac_entry.mac_addr, entry->entry_key.mac_addr, sizeof(hal_mac_addr_t));
    }
    ndi_mac_entry.is_static = static_type;

    if ((rc = ndi_delete_mac_entry(&ndi_mac_entry, del_type, subtype_all) != STD_ERR_OK)) {
        NAS_MAC_LOG(ERR, ev_log_s_MAJOR,"Error deleting NDI MAC entry with vlan id %d",
            entry->entry_key.vlan_id);
        return rc;
    }
    return STD_ERR_OK;
}