Exemple #1
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;
}
/*
 * icmpa_init
 *
 * API to init the ICMP Agent
 * This should only be done once at the beginning.
 */
indigo_error_t
icmpa_init (void)
{
    if (icmpa_is_initialized()) return INDIGO_ERROR_NONE;

    AIM_LOG_INFO("init");

    /*
     * Register system debug counters
     */
    debug_counter_register(&pkt_counters.icmp_total_in_packets,
                           "icmpa.icmp_total_in_packets",
                           "Packet-ins recv'd by icmpa");
    debug_counter_register(&pkt_counters.icmp_total_out_packets,
                           "icmpa.icmp_total_out_packets",
                           "Icmp packets sent by lacpa");
    debug_counter_register(&pkt_counters.icmp_total_passed_packets,
                           "icmpa.icmp_total_passed_packets",
                            "Packet-ins passed by icmpa");
    debug_counter_register(&pkt_counters.icmp_internal_errors,
                           "icmpa.icmp_internal_errors",
                           "Internal errors in icmpa");

    ICMPA_MEMSET(&port_pkt_counters[0], 0,
                 sizeof(icmpa_typecode_packet_counter_t) * (MAX_PORTS+1));
    aim_ratelimiter_init(&icmp_pktin_log_limiter, 1000*1000, 5, NULL);

    /*
     * Register listerner for packet_in
     */
    if (indigo_core_packet_in_listener_register(
        (indigo_core_packet_in_listener_f) icmpa_packet_in_handler) < 0) {
        AIM_LOG_FATAL("Failed to register for packet_in in ICMPA module");
        return INDIGO_ERROR_INIT;
    }

    icmp_initialized = true;
    return INDIGO_ERROR_NONE;
}
Exemple #3
0
void
ind_ovs_port_added(uint32_t port_no, const char *ifname, of_mac_addr_t mac_addr)
{
    indigo_error_t err;

    if (ind_ovs_ports[port_no]) {
        return;
    }

    struct ind_ovs_port *port = calloc(1, sizeof(*port));
    if (port == NULL) {
        LOG_ERROR("failed to allocate port");
        return;
    }

    strncpy(port->ifname, ifname, sizeof(port->ifname));
    port->dp_port_no = port_no;
    port->mac_addr = mac_addr;
    aim_ratelimiter_init(&port->upcall_log_limiter, 1000*1000, 5, NULL);
    aim_ratelimiter_init(&port->pktin_limiter, PORT_PKTIN_INTERVAL, PORT_PKTIN_BURST_SIZE, NULL);
    pthread_mutex_init(&port->quiesce_lock, NULL);
    pthread_cond_init(&port->quiesce_cvar, NULL);

    port->notify_socket = ind_ovs_create_nlsock();
    if (port->notify_socket == NULL) {
        goto cleanup_port;
    }

    if (nl_socket_set_nonblocking(port->notify_socket) < 0) {
        LOG_ERROR("failed to set netlink socket nonblocking");
        goto cleanup_port;
    }

    struct nl_msg *msg = ind_ovs_create_nlmsg(ovs_vport_family, OVS_VPORT_CMD_SET);
    nla_put_u32(msg, OVS_VPORT_ATTR_PORT_NO, port_no);
    nla_put_u32(msg, OVS_VPORT_ATTR_UPCALL_PID,
                nl_socket_get_local_port(port->notify_socket));
    err = ind_ovs_transact(msg);
    if (err < 0) {
        LOG_ERROR("datapath failed to configure port %s", ifname);
        goto cleanup_port;
    }

    if (!ind_ovs_get_interface_flags(ifname, &port->ifflags)) {
        /* Bring interface up if not already */
        if (!(port->ifflags & IFF_UP)) {
            port->ifflags |= IFF_UP;
            (void) ind_ovs_set_interface_flags(ifname, port->ifflags);
        }
    } else {
        /* Not a netdev, fake the interface flags */
        port->ifflags = IFF_UP;
    }

    /* Ensure port is fully populated before publishing it. */
    __sync_synchronize();

    ind_ovs_ports[port_no] = port;

    if ((err = port_status_notify(port_no, OF_PORT_CHANGE_REASON_ADD)) < 0) {
        LOG_WARN("failed to notify controller of port addition");
        /* Can't cleanup the port because it's already visible to other
         * threads. */
    }

    ind_ovs_upcall_register(port);
    LOG_INFO("Added port %s", port->ifname);
    ind_ovs_kflow_invalidate_all();
    return;

cleanup_port:
    assert(ind_ovs_ports[port_no] == NULL);
    if (port->notify_socket) {
        nl_socket_free(port->notify_socket);
    }
    free(port);
}
Exemple #4
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;
}