Esempio n. 1
0
int
onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst)
{
    uint32_t bytes[7];
    char* path;
    FILE* fp;

    path = as5812_54x_sfp_get_port_path(0, "sfp_is_present_all");
    fp = fopen(path, "r");

    if(fp == NULL) {
        AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file.");
        return ONLP_STATUS_E_INTERNAL;
    }
    int count = fscanf(fp, "%x %x %x %x %x %x %x",
                       bytes+0,
                       bytes+1,
                       bytes+2,
                       bytes+3,
                       bytes+4,
                       bytes+5,
                       bytes+6
                       );
    fclose(fp);
    if(count != AIM_ARRAYSIZE(bytes)) {
        /* Likely a CPLD read timeout. */
        AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file.");
        return ONLP_STATUS_E_INTERNAL;
    }

    /* Mask out non-existant QSFP ports */
    bytes[6] &= 0x3F;

    /* Convert to 64 bit integer in port order */
    int i = 0;
    uint64_t presence_all = 0 ;
    for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) {
        presence_all <<= 8;
        presence_all |= bytes[i];
    }

    /* Populate bitmap */
    for(i = 0; presence_all; i++) {
        int p;
        port_qsfp_cpld_map__(i, &p);
        AIM_BITMAP_MOD(dst, p, (presence_all & 1));
        presence_all >>= 1;
    }

    return ONLP_STATUS_OK;
}
Esempio n. 2
0
int
onlp_i2c_mux_select(onlp_i2c_mux_device_t* dev, int channel)
{
    int i;
    for(i = 0; i < AIM_ARRAYSIZE(dev->driver->channels); i++) {
        if(dev->driver->channels[i].channel == channel) {
            AIM_LOG_VERBOSE("i2c_mux_select: Selecting channel %2d on device '%s'  [ bus=%d addr=0x%x offset=0x%x value=0x%x ]...",
                        channel, dev->name, dev->bus, dev->devaddr,
                        dev->driver->control, dev->driver->channels[i].value);

            int rv = onlp_i2c_writeb(dev->bus,
                                     dev->devaddr,
                                     dev->driver->control,
                                     dev->driver->channels[i].value,
                                     0);

            if(rv < 0) {
                AIM_LOG_ERROR("i2c_mux_select: Selecting channel %2d on device '%s'  [ bus=%d addr=0x%x offset=0x%x value=0x%x ] failed: %d",
                              channel, dev->name, dev->bus, dev->devaddr,
                              dev->driver->control, dev->driver->channels[i].value, rv);
            }
            return rv;
        }
    }
    return ONLP_STATUS_E_PARAM;
}
Esempio n. 3
0
int
onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst)
{
    uint32_t bytes[4];
    FILE* fp = fopen(SFP_EEPROM_NODE(sfp_is_present_all), "r");
    
    if(fp == NULL) {
        AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file.");
        return ONLP_STATUS_E_INTERNAL;
    }
    int count = fscanf(fp, "%x %x %x %x",
                       bytes+0,
                       bytes+1,
                       bytes+2,
                       bytes+3
                       );
    fclose(fp);
    if(count != AIM_ARRAYSIZE(bytes)) {
        /* Likely a CPLD read timeout. */
        AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file.");
        return ONLP_STATUS_E_INTERNAL;
    }

    /* Convert to 64 bit integer in port order */
    int i = 0;
    uint32_t presence_all = 0 ;
    for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) {
        presence_all <<= 8;
        presence_all |= bytes[i];
    }

    /* Populate bitmap */
    for(i = 0; presence_all; i++) {
        AIM_BITMAP_MOD(dst, i, (presence_all & 1));
        presence_all >>= 1;
    }

    return ONLP_STATUS_OK;
}
Esempio n. 4
0
int
onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
{
    uint32_t bytes[6];
    uint32_t *ptr = bytes;
    FILE* fp;

    /* Read present status of port 0~23 */
    int addr, i = 0;

    for (addr = 60; addr <= 62; addr+=2) {
        if (addr == 60) {
            fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD1, "r");
        }
        else {
            fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD2, "r");
        }

        if(fp == NULL) {
            AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr);
            return ONLP_STATUS_E_INTERNAL;
        }

        int count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2);
        fclose(fp);
        if(count != 3) {
            /* Likely a CPLD read timeout. */
            AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr);
            return ONLP_STATUS_E_INTERNAL;
        }

        ptr += count;
    }

    /* Convert to 64 bit integer in port order */
    i = 0;
    uint64_t rx_los_all = 0 ;
    for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) {
        rx_los_all <<= 8;
        rx_los_all |= bytes[i];
    }

    /* Populate bitmap */
    for(i = 0; rx_los_all; i++) {
        AIM_BITMAP_MOD(dst, i, (rx_los_all & 1));
        rx_los_all >>= 1;
    }

    return ONLP_STATUS_OK;
}
static void 
faultd_signal_handler__(int signal, siginfo_t* siginfo, void* context)
{
    int rv; 

    /*
     * Make sure we syncronize properly with other threads that
     * may *also* be faulting
     */
    rv = pthread_spin_trylock(&thread_lock__); 

    if (rv == EBUSY) { 
        sigset_t mask; 
        sigemptyset(&mask); 
        pselect(0, NULL, NULL, NULL, NULL, &mask); 
    }
    
    /*
     * Generate our fault information. 
     */ 
    faultd_info__.pid = getpid(); 
    faultd_info__.tid = 0; 
    faultd_info__.signal = signal; 
    faultd_info__.signal_code = siginfo->si_code; 
    faultd_info__.fault_address = siginfo->si_addr; 
    faultd_info__.last_errno = errno; 

    faultd_info__.backtrace_size = signal_backtrace__(faultd_info__.backtrace, 
                                                      AIM_ARRAYSIZE(faultd_info__.backtrace),
                                                      context, 0); 
    faultd_info__.backtrace_symbols = (void*)1; 
    if(faultd_client__) { 
        faultd_client_write(faultd_client__, &faultd_info__); 
    }
    if(localfd__ >= 0) { 
        char* signame = strsignal(faultd_info__.signal); 
        char* nl = "\n"; 
        write(localfd__, signame, strlen(signame)+1); 
        write(localfd__, nl, 2); 
        backtrace_symbols_fd(faultd_info__.backtrace, 
                             faultd_info__.backtrace_size, 
                             localfd__); 
    }

    /* 
     * Unlock spinlock, in case this signal wasn't fatal
     */
    pthread_spin_unlock(&thread_lock__); 
}
Esempio n. 6
0
int
onlp_i2c_mux_channels_deselect(onlp_i2c_mux_channels_t* mcs)
{
    int i;
    for(i = AIM_ARRAYSIZE(mcs->channels) - 1; i >= 0; i--) {
        if(mcs->channels[i].mux) {
            int rv = onlp_i2c_mux_channel_deselect(mcs->channels + i);
            if(rv < 0) {
                /** Error already reported. */
                return rv;
            }
        }
    }
    return 0;
}
Esempio n. 7
0
int
onlp_i2c_mux_channels_select(onlp_i2c_mux_channels_t* mcs)
{
    int i;
    for(i = 0; i < AIM_ARRAYSIZE(mcs->channels); i++) {
        if(mcs->channels[i].mux) {
            int rv = onlp_i2c_mux_channel_select(mcs->channels + i);
            if(rv < 0) {
                /** Error already reported */
                return rv;
            }
        }
    }
    return 0;
}
Esempio n. 8
0
void
test_bucket(void)
{
    struct {
        uint32_t k;
        uint32_t bucket;
        uint32_t reverse;
    } tests[] = {
        { 0, 0, 0 },
        { 1, 1, 1 },
        { 2, 2, 2 },
        { 14, 14, 14 },
        { 15, 15, 15 },
        { 16, 16, 16 },
        { 17, 17, 17 },
        { 30, 30, 30 },
        { 31, 31, 31 },
        { 32, 32, 32 },
        { 33, 32, 32 },
        { 34, 33, 34 },
        { 62, 47, 62 },
        { 63, 47, 62 },
        { 64, 48, 64 },
        { 65, 48, 64 },
        { 66, 48, 64 },
        { 67, 48, 64 },
        { 68, 49, 68 },
        { UINT32_MAX, 463, 4160749568 },
    };

    int i;
    for (i = 0; i < AIM_ARRAYSIZE(tests); i++) {
        uint32_t actual = histogram_bucket(tests[i].k);
        if (tests[i].bucket != actual) {
            AIM_DIE("histogram_bucket test failed: k=%u expect=%u actual=%u",
                    tests[i].k, tests[i].bucket, actual);
        }

        AIM_ASSERT(tests[i].bucket == histogram_bucket(tests[i].reverse));

        actual = histogram_key(tests[i].bucket);
        if (tests[i].reverse != actual) {
            AIM_DIE("histogram_key test failed: bucket=%u expect=%u actual=%u",
                    tests[i].bucket, tests[i].reverse, actual);
        }
    }
}
Esempio n. 9
0
File: upcall.c Progetto: mchalla/ivs
static void *
ind_ovs_upcall_thread_main(void *arg)
{
    struct ind_ovs_upcall_thread *thread = arg;

    while (!thread->finished) {
        struct epoll_event events[128];
        thread->log_upcalls = aim_log_enabled(AIM_LOG_STRUCT_POINTER, AIM_LOG_FLAG_VERBOSE);
        int n = epoll_wait(thread->epfd, events, AIM_ARRAYSIZE(events),
                           1000 /* check finished flag once per second */);
        if (n < 0 && errno != EINTR) {
            LOG_ERROR("epoll_wait failed: %s", strerror(errno));
            abort();
        } else if (n > 0) {
            int j;
            for (j = 0; j < n; j++) {
                ind_ovs_handle_port_upcalls(thread, events[j].data.ptr);
            }
        }
    }

    return NULL;
}
Esempio n. 10
0
int
onlp_sfpi_init(void)
{
    /**
     * Initialize the SFP presence and reset GPIOS.
     */
    int i;
    int rv;
    for(i = 0; i < AIM_ARRAYSIZE(sfpmap__); i++) {
        if( (rv = onlp_gpio_export(sfpmap__[i].mod_abs_gpio_number, ONLP_GPIO_DIRECTION_IN)) < 0) {
            AIM_LOG_ERROR("Failed to initialize MOD_ABS gpio %d",
                          sfpmap__[i].mod_abs_gpio_number);
            return -1;
        }
        if( (rv = onlp_gpio_export(sfpmap__[i].reset_gpio_number, ONLP_GPIO_DIRECTION_HIGH)) < 0) {
            AIM_LOG_ERROR("Failed to initialize RESET gpio %d",
                          sfpmap__[i].reset_gpio_number);
            return -1;
        }
    }

    return ONLP_STATUS_OK;
}
Esempio n. 11
0
int
onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
{
    uint32_t bytes[8];
    int i = 0;
    uint64_t rx_los_all = 0;
    
    bytes[0]=bytes[1]=bytes[2]=bytes[3]=bytes[4]=bytes[5]=0x0;
    bytes[6]=0x0f;
    bytes[7]=0x0;
    
    for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) {
        rx_los_all <<= 8;
        rx_los_all |= bytes[i];
    }

    /* Populate bitmap */
    for(i = 0; rx_los_all; i++) {
        AIM_BITMAP_MOD(dst, i, (rx_los_all & 1));
        rx_los_all >>= 1;
    }

    return ONLP_STATUS_OK;
}
Esempio n. 12
0
static ucli_status_t
ppe_ucli_utm__dfk__(ucli_context_t* uc)
{
    ppe_dfk_t dfk; 
    ppe_field_t fields[4]; 
    uint8_t* verify_data;
    unsigned int verify_data_size; 
    int rv = UCLI_STATUS_OK; 
    unsigned int i; 

    UCLI_COMMAND_INFO(uc, 
                      "dfk", AIM_ARRAYSIZE(fields)+1, 
                      "Generate and verify a dynamic field key."); 
    UCLI_ARGPARSE_OR_RETURN(uc, 
                            "{ppe_field}{ppe_field}{ppe_field}{ppe_field}{data}", 
                            fields+0, fields+1, fields+2, fields+3, 
                            &verify_data, &verify_data_size); 

    ppe_dfk_init(&dfk, fields, AIM_ARRAYSIZE(fields)); 
    i = ppe_packet_dfk(&ppec->ppep, &dfk); 

    if(i != verify_data_size) { 
        rv = ucli_error(uc, "dfk size is %d, verify data size is %d", 
                        i, verify_data_size); 
        goto dfk_error;
    }

    for(i = 0; i < AIM_ARRAYSIZE(fields); i++) {
        const ppe_field_info_t* fi = ppe_field_info_get(fields[i]); 
        int exists = ppe_field_exists(&ppec->ppep, fi->field); 
        if(exists && ( (dfk.mask & (1<<i)) == 0)) { 
            /* Should be in the field key but isn't.*/
            rv = ucli_error(uc, "%{ppe_field} exists in packet but not in field key.", 
                            fi->field);
            goto dfk_error; 
        }
        if(!(exists) && (dfk.mask & (1<<i))) { 
            /* Should not be in the field key but is. */
            rv = ucli_error(uc, "%{ppe_field} is in the key but not the packet.", 
                            fi->field); 
            goto dfk_error; 
        }
        
    }
    for(i = 0; i < verify_data_size; i++) { 
        if(verify_data[i] != dfk.data[i]) { 
            rv = ucli_error(uc, "key data mismatch at byte %d.\nkey=%{data}, verify=%{data}", 
                            i, dfk.data, verify_data_size, verify_data, verify_data_size);         
            goto dfk_error; 
        }
    }
    for(i = 0; i < AIM_ARRAYSIZE(fields); i++) {
        if(dfk.mask & (1<<i)) {         
            const ppe_field_info_t* fi = ppe_field_info_get(fields[i]); 
            if(fi->size_bits <= 32) { 
                uint32_t pdata;
                uint32_t kdata; 
                ppe_field_get(&ppec->ppep, fi->field, &pdata); 
                ppe_dfk_field_get(&dfk, fi->field, &kdata); 
                if(pdata != kdata) { 
                    rv = ucli_error(uc, "field_get mismatch: p=0x%x, k=0x%x"); 
                    goto dfk_error; 
                }
            }
            else { 
                unsigned int i; 
                uint8_t pdata[128]; 
                uint8_t kdata[128]; 
                
                ppe_wide_field_get(&ppec->ppep, fi->field, pdata); 
                ppe_dfk_wide_field_get(&dfk, fi->field, kdata); 
                for(i = 0; i < fi->size_bits/8; i++) { 
                    if(pdata[i] != kdata[i]) { 
                        rv = ucli_error(uc, "wide_field_get mismatch @ %d: p=0x%x k=0x%x", 
                                        i, pdata[i], kdata[i]); 
                        goto dfk_error; 
                    }
                }
            }
        }
    }

    aim_free(verify_data); 
    ppe_dfk_destroy(&dfk); 
    return UCLI_STATUS_OK; 

 dfk_error:
    ucli_printf(uc, "key: "); 
    ppe_dfk_show(&dfk, &uc->pvs); 
    ppe_dfk_destroy(&dfk); 
    aim_free(verify_data); 
    ucli_printf(uc, "\n"); 
    return rv; 
}
Esempio n. 13
0
/*
 * For AC power Front to Back :
 *	* If any fan fail, please fan speed register to 15
 *	* The max value of Fan speed register is 9
 *		[LM75(48) + LM75(49) + LM75(4A)] > 174  => set Fan speed value from 4 to 5
 *		[LM75(48) + LM75(49) + LM75(4A)] > 182  => set Fan speed value from 5 to 7
 *		[LM75(48) + LM75(49) + LM75(4A)] > 190  => set Fan speed value from 7 to 9
 *
 *		[LM75(48) + LM75(49) + LM75(4A)] < 170  => set Fan speed value from 5 to 4
 *		[LM75(48) + LM75(49) + LM75(4A)] < 178  => set Fan speed value from 7 to 5
 *		[LM75(48) + LM75(49) + LM75(4A)] < 186  => set Fan speed value from 9 to 7
 *
 *
 * For  AC power Back to Front :
 *	* If any fan fail, please fan speed register to 15
 *	* The max value of Fan speed register is 10
 *		[LM75(48) + LM75(49) + LM75(4A)] > 140  => set Fan speed value from 4 to 5
 *		[LM75(48) + LM75(49) + LM75(4A)] > 150  => set Fan speed value from 5 to 7
 *		[LM75(48) + LM75(49) + LM75(4A)] > 160  => set Fan speed value from 7 to 10
 *
 *		[LM75(48) + LM75(49) + LM75(4A)] < 135  => set Fan speed value from 5 to 4
 *		[LM75(48) + LM75(49) + LM75(4A)] < 145  => set Fan speed value from 7 to 5
 *		[LM75(48) + LM75(49) + LM75(4A)] < 155  => set Fan speed value from 10 to 7
 */
int
onlp_sysi_platform_manage_fans(void)
{
    int i = 0, arr_size, temp;
    fan_ctrl_policy_t *policy;
    int cur_duty_cycle, new_duty_cycle;
    onlp_thermal_info_t thermal_1, thermal_2, thermal_3;

    int  fd, len;
    char  buf[10] = {0};

    /* Get each fan status
     */
    for (i = 1; i <= NUM_OF_FAN_ON_MAIN_BROAD; i++)
    {
        onlp_fan_info_t fan_info;

        if (onlp_fan_info_get(ONLP_FAN_ID_CREATE(i), &fan_info) != ONLP_STATUS_OK) {
            AIM_LOG_ERROR("Unable to get fan(%d) status\r\n", i);
            return ONLP_STATUS_E_INTERNAL;
        }

        /* Decision 1: Set fan as full speed if any fan is failed.
         */
        if (fan_info.status & ONLP_FAN_STATUS_FAILED) {
            AIM_LOG_ERROR("Fan(%d) is not working, set the other fans as full speed\r\n", i);
            return onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_CYCLE_MAX);
        }

        /* Decision 1.1: Set fan as full speed if any fan is not present.
         */
        if (!(fan_info.status & ONLP_FAN_STATUS_PRESENT)) {
            AIM_LOG_ERROR("Fan(%d) is not present, set the other fans as full speed\r\n", i);
            return onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_CYCLE_MAX);
        }

        /* Get fan direction (Only get the first one since all fan direction are the same)
         */
        if (i == 1) {
            if (fan_info.status & ONLP_FAN_STATUS_F2B) {
                policy   = fan_ctrl_policy_f2b;
                arr_size = AIM_ARRAYSIZE(fan_ctrl_policy_f2b);
            }
            else {
                policy   = fan_ctrl_policy_b2f;
                arr_size = AIM_ARRAYSIZE(fan_ctrl_policy_b2f);
            }
        }
    }

    /* Get current fan speed
     */
    fd = open(FAN_SPEED_CTRL_PATH, O_RDONLY);
    if (fd == -1){
        AIM_LOG_ERROR("Unable to open fan speed control node (%s)", FAN_SPEED_CTRL_PATH);
        return ONLP_STATUS_E_INTERNAL;
    }

    len = read(fd, buf, sizeof(buf));
    close(fd);
    if (len <= 0) {
        AIM_LOG_ERROR("Unable to read fan speed from (%s)", FAN_SPEED_CTRL_PATH);
        return ONLP_STATUS_E_INTERNAL;
    }
    cur_duty_cycle = atoi(buf);


    /* Decision 2: If no matched fan speed is found from the policy,
     *             use FAN_DUTY_CYCLE_MIN as default speed
     */
	for (i = 0; i < arr_size; i++) {
	    if (policy[i].duty_cycle != cur_duty_cycle)
		    continue;

		break;
	}

	if (i == arr_size) {
        return onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), policy[0].duty_cycle);
	}

    /* Get current temperature
     */
    if (onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(2), &thermal_1) != ONLP_STATUS_OK ||
        onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(3), &thermal_2) != ONLP_STATUS_OK ||
        onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(4), &thermal_3) != ONLP_STATUS_OK) {
        AIM_LOG_ERROR("Unable to read thermal status");
        return ONLP_STATUS_E_INTERNAL;
    }
    temp = thermal_1.mcelsius + thermal_2.mcelsius + thermal_3.mcelsius;


    /* Decision 3: Decide new fan speed depend on fan direction/current fan speed/temperature
     */
    new_duty_cycle = cur_duty_cycle;

    if ((temp >= policy[i].temp_up_adjust) && (i != (arr_size-1))) {
	    new_duty_cycle = policy[i+1].duty_cycle;
	}
	else if ((temp <= policy[i].temp_down_adjust) && (i != 0)) {
	    new_duty_cycle = policy[i-1].duty_cycle;
	}

	if (new_duty_cycle == cur_duty_cycle) {
        /* Duty cycle does not change, just return */
	    return ONLP_STATUS_OK;
	}

    return onlp_fan_percentage_set(ONLP_FAN_ID_CREATE(1), new_duty_cycle);
}
Esempio n. 14
0
int aim_main(int argc, char* argv[])
{
    int i;

    {
        const char* tstStrings[] = { "This", "is", "a", "complete", "sentence." };
        char* join = aim_strjoin(" ", tstStrings, AIM_ARRAYSIZE(tstStrings));
        if(strcmp(join, "This is a complete sentence.")) {
            printf("fail: join='%s'\n", join);
        }
        AIM_FREE(join);
    }

    for(i = 0; i < argc; i++) {
        aim_printf(&aim_pvs_stdout, "arg%d: '%s'\n", i, argv[i]);
    }

    {
        /* Test data */
        char data[2500];
        memset(data, 0xFF, sizeof(data));
        aim_printf(&aim_pvs_stdout, "data is %{data}", data, sizeof(data));
    }

    {
        char* sdata = "DEADBEEFCAFE";
        char* data;
        int size;
        aim_sparse(&sdata, &aim_pvs_stdout, "{data}", &data, &size);
        aim_printf(&aim_pvs_stdout, "data is %{data}\n", data, size);
        aim_free(data);
    }

    utest_list();

    AIM_LOG_MSG("Should print 1-27");
    AIM_LOG_MSG("%d %d %d %d %d %d %d %d %d "
                "%d %d %d %d %d %d %d %d %d "
                "%d %d %d %d %d %d %d %d %d",
                1, 2, 3, 4, 5, 6, 7, 8, 9,
                10, 11, 12, 13, 14, 15, 16, 17, 18,
                19, 20, 21, 22, 23, 24, 25, 26, 27);


    aim_printf(&aim_pvs_stdout, "aim_pvs_stdout from %s:%d\n",
               __FILE__, __LINE__);


    {
        char c;
        aim_pvs_t* pvs = aim_pvs_buffer_create();
        aim_printf(pvs, "\nConsider ");
        aim_printf(pvs, "%s ", "the");
        aim_printf(pvs, "alphabet: ");
        for(c = 'A'; c <= 'Z'; c++) {
            aim_printf(pvs, "%c", c);
        }
        aim_printf(pvs, "\n");
        {
            char* s = aim_pvs_buffer_get(pvs);
            aim_printf(&aim_pvs_stdout, "first: %s", s);
            free(s);
            aim_printf(pvs, "(second)");
            s = aim_pvs_buffer_get(pvs);
            aim_printf(&aim_pvs_stdout, "second: %s", s);
            free(s);
            aim_pvs_destroy(pvs);
        }
        {
            aim_ratelimiter_t rl;
            aim_ratelimiter_init(&rl, 10, 5, NULL);

            /* 5 (6?) tokens available at t=0 */
            assert(aim_ratelimiter_limit(&rl, 0) == 0);
            assert(aim_ratelimiter_limit(&rl, 0) == 0);
            assert(aim_ratelimiter_limit(&rl, 0) == 0);
            assert(aim_ratelimiter_limit(&rl, 0) == 0);
            assert(aim_ratelimiter_limit(&rl, 0) == 0);
            assert(aim_ratelimiter_limit(&rl, 0) == 0);
            assert(aim_ratelimiter_limit(&rl, 0) < 0);

            /* Another token at t=10 */
            assert(aim_ratelimiter_limit(&rl, 10) == 0);
            assert(aim_ratelimiter_limit(&rl, 10) < 0);

            /* Nothing at t=15 */
            assert(aim_ratelimiter_limit(&rl, 15) < 0);

            /* 4 more tokens granted by t=50 */
            assert(aim_ratelimiter_limit(&rl, 50) == 0);
            assert(aim_ratelimiter_limit(&rl, 50) == 0);
            assert(aim_ratelimiter_limit(&rl, 50) == 0);
            assert(aim_ratelimiter_limit(&rl, 50) == 0);
            assert(aim_ratelimiter_limit(&rl, 50) < 0);
        }
        {
            aim_printf(&aim_pvs_stdout, "valgrind_status=%d\n",
                       aim_valgrind_status());
        }

        AIM_LOG_MSG("%{aim_error}", AIM_ERROR_PARAM);
    }

    return 0;
}
Esempio n. 15
0
int
onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst)
{
    uint32_t bytes[7], *ptr = NULL;
    FILE* fp;
    int addr;

    ptr = bytes;

    for (addr = 60; addr <= 62; addr+=2) {
        /* Read present status of port 0~53 */
        int count = 0;
        char file[64] = {0};
        int bus = (addr == 60) ? 4 : 5;
        
        sprintf(file, MODULE_PRESENT_ALL_ATTR, bus, addr);
        fp = fopen(file, "r");
        if(fp == NULL) {
            AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD(0x%d).", addr);
            return ONLP_STATUS_E_INTERNAL;
        }

        if (addr == 60) { /* CPLD1 */
            count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2);
            fclose(fp);
            if(count != 3) {
                /* Likely a CPLD read timeout. */
                AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr);
                return ONLP_STATUS_E_INTERNAL;
            }
        }
        else { /* CPLD2 */
            count = fscanf(fp, "%x %x %x %x", ptr+0, ptr+1, ptr+2, ptr+3);
            fclose(fp);
            if(count != 4) {
                /* Likely a CPLD read timeout. */
                AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr);
                return ONLP_STATUS_E_INTERNAL;
            }
        }

        ptr += count;
    }

    /* Mask out non-existant QSFP ports */
    bytes[6] &= 0x3F;

    /* Convert to 64 bit integer in port order */
    int i = 0;
    uint64_t presence_all = 0 ;
    for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) {
        presence_all <<= 8;
        presence_all |= bytes[i];
    }

    /* Populate bitmap */
    for(i = 0; presence_all; i++) {
        AIM_BITMAP_MOD(dst, i, (presence_all & 1));
        presence_all >>= 1;
    }

    return ONLP_STATUS_OK;
}