Ejemplo n.º 1
0
Archivo: upcall.c Proyecto: mchalla/ivs
static void
ind_ovs_upcall_request_pktin(uint32_t port_no, struct ind_ovs_port *port,
                             struct nlattr *packet, struct nlattr *key, uint8_t reason, uint64_t metadata)
{
    if (ind_ovs_benchmark_mode || aim_ratelimiter_limit(&port->pktin_limiter, monotonic_us()) == 0) {
        ind_ovs_bh_request_pktin(port_no, packet, key, reason, metadata);
    } else {
        if (aim_ratelimiter_limit(&port->upcall_log_limiter, monotonic_us()) == 0) {
            LOG_WARN("rate limiting packet-ins from port %s", port->ifname);
        }
    }
}
Ejemplo n.º 2
0
void
aim_log_vcommon(aim_log_t* l, aim_log_flag_t flag,
                aim_ratelimiter_t* rl, uint64_t time,
                const char* fname, const char* file, int line,
                const char* fmt, va_list vargs)
{
    const char* color = NULL;

    if(flag == AIM_LOG_FLAG_MSG || flag == AIM_LOG_FLAG_FATAL ||
       aim_log_enabled(l, flag)) {
        if(rl == NULL || aim_ratelimiter_limit(rl, time) == 0) {

            if(aim_pvs_isatty(l->pvs) == 1) {
                if((color = aim_log_flag_color__(flag))) {
                    aim_printf(l->pvs, color);
                }
            }

            aim_log_output__(l, fname, file, line, fmt, vargs);

            if(color) {
                aim_printf(l->pvs, color_reset__);
            }
        }
    }
}
Ejemplo n.º 3
0
void
aim_log_vcustom(aim_log_t* l, int fid,
                aim_ratelimiter_t* rl, uint64_t time,
                const char* fname, const char* file, int line,
                const char* fmt, va_list vargs)
{
    if(aim_log_custom_enabled(l, fid)) {
        if(rl == NULL || aim_ratelimiter_limit(rl, time) == 0) {
            aim_log_output__(l, fname, file, line, fmt, vargs);
        }
    }
}
Ejemplo n.º 4
0
ucli_status_t
vt_ucli_module__spam__(ucli_context_t* uc)
{
    aim_ratelimiter_t counter_rl;
    aim_ratelimiter_t send_rl;
    int count = 0;
    int last = 0;
    int pps = -1;

    UCLI_COMMAND_INFO(uc,
                      "spam", 3,
                      "$summary#Spam packet data on the given VPI."
                      "$args#<vpi_spec> <packet_data> <pps>");

    UCLI_ARGPARSE_OR_RETURN(uc, "{vpi}{idata}i",
                            &vtc->vpi, vtc->data, &vtc->size, &pps);

    aim_ratelimiter_init(&counter_rl, 1000000, 0, NULL);
    aim_ratelimiter_init(&send_rl, 1000000/pps, 0, NULL);

    for(;;) {
        uint64_t now = os_time_monotonic();
        if(aim_ratelimiter_limit(&counter_rl, now) == 0) {
            ucli_printf(uc, "Sent %d packets - %d pps\n", count,
                        (count - last));
            last = count;

        }
        if(aim_ratelimiter_limit(&send_rl, now) == 0) {
            if(vpi_send(vtc->vpi, vtc->data, vtc->size) < 0) {
                return ucli_error(uc, "vpi_send() failed.");
            }
            count++;
        }
        else {
            os_sleep_usecs(1);
        }
    }
    return UCLI_STATUS_OK;
}
Ejemplo n.º 5
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;
}