Ejemplo n.º 1
0
static void
nc_master_test(struct sockaddr *slave, int test_tcp, int test_udp,
               int test_slave_loads, int test_master_loads)
{
    int s, i;
    struct sockaddr_storage my_addr;
    struct pause pause_times[] = {
        {0,0}, {1,10}, {5,10}, {10,10}, {1,1} };


    s = socket(slave->sa_family, SOCK_DGRAM, 0);
    if (s < 0) {
        pexit("datagram socket");
    }

    memset(&my_addr, 0, sizeof(my_addr));
    ((struct sockaddr *)&my_addr)->sa_family = slave->sa_family;
#ifndef __linux
    ((struct sockaddr *)&my_addr)->sa_len = slave->sa_len;
#endif
    switch (slave->sa_family) {
    case AF_INET:
        ((struct sockaddr_in *)&my_addr)->sin_addr.s_addr = htonl(INADDR_ANY);
        ((struct sockaddr_in *)&my_addr)->sin_port = htons(NC_MASTER_PORT);
        break;
    case AF_INET6:
        ((struct sockaddr_in6 *)&my_addr)->sin6_addr = in6addr_any;
        ((struct sockaddr_in6 *)&my_addr)->sin6_port = htons(NC_MASTER_PORT);
        break;
    default:
        pexit("strange sockaddr family");
    }
    if (bind(s, (struct sockaddr *) &my_addr, sa_len((struct sockaddr *)&my_addr)) < 0) {
        pexit("UDP bind <main>");
    }

    test_printf("================== No load, master at 100%% ========================\n");
    if (test_udp) {
        do_udp_test(s, NC_REQUEST_UDP_ECHO, slave, 640, 1024, 0, 0);
        do_udp_test(s, NC_REQUEST_UDP_SEND, slave, 640, 1024, 0, 0);
        do_udp_test(s, NC_REQUEST_UDP_RECV, slave, 640, 1024, 0, 0);
    }
    if (test_tcp) {
        do_tcp_test(s, NC_REQUEST_TCP_ECHO, slave, 640, 1024, 0, 0);
        do_tcp_test(s, NC_REQUEST_TCP_SEND, slave, 640, 1024, 0, 0);
        do_tcp_test(s, NC_REQUEST_TCP_RECV, slave, 640, 1024, 0, 0);
        do_tcp_test(s, NC_REQUEST_TCP_ECHO, slave, 64, 10240, 0, 0);
    }

    if (test_slave_loads) {
        if (do_set_load(s, slave, 0)) {
            test_printf("\n====================== Various slave compute loads ===================\n");
            for (i = 0;  i < 60;  i += 10) {
                test_printf(">>>>>>>>>>>> slave processing load at %d%%\n", i);                
                do_set_load(s, slave, i);
                if (test_udp) {
                    do_udp_test(s, NC_REQUEST_UDP_ECHO, slave, 2048, 1024, 0, 0);
                }
                if (test_tcp) {
                    do_tcp_test(s, NC_REQUEST_TCP_ECHO, slave, 2048, 1024, 0, 0);
                }
            }
        }
    }

    if (test_master_loads) {
        if (do_start_idle(s, slave)) {
            test_printf("\n====================== Various master loads ===================\n");
            test_printf("Testing IDLE for %d seconds\n", IDLE_TEST_TIME);
            test_delay(IDLE_TEST_TIME*100);
            do_stop_idle(s, slave, true);
            for (i = 0;  i < LENGTH(pause_times);  i++) {
                if (test_udp) {
                    do_start_idle(s, slave);
                    do_udp_test(s, NC_REQUEST_UDP_ECHO, slave, 2048, 1024, 
                                pause_times[i].pause_ticks, pause_times[i].pause_threshold);
                    do_stop_idle(s, slave, false);
                }
                if (test_tcp) {
                    do_start_idle(s, slave);
                    do_tcp_test(s, NC_REQUEST_TCP_ECHO, slave, 2048, 1024, 
                                pause_times[i].pause_ticks, pause_times[i].pause_threshold);
                    do_stop_idle(s, slave, false);
                }
            }
        }
    }

//    do_disconnect(s, slave);
    close(s);
}
Ejemplo n.º 2
0
static void
nc_master(struct test_params *p)
{
    int s, i;
    struct sockaddr_in slave, my_addr;
    struct hostent *host;
    struct pause pause_times[] = {
        {0,0}, {1,10}, {5,10}, {10,10}, {1,1} };

    if (p->argc != 2) {
        test_printf("Need exactly 'master <host>'\n");
        return;
    }

    s = socket(AF_INET, SOCK_DGRAM, 0);
    if (s < 0) {
        pexit("datagram socket");
    }

    memset(&my_addr, 0, sizeof(my_addr));
    my_addr.sin_family = AF_INET;
#ifdef __ECOS
    my_addr.sin_len = sizeof(my_addr);
#endif
    my_addr.sin_port = htons(NC_MASTER_PORT);
    my_addr.sin_addr.s_addr = INADDR_ANY;

    if (bind(s, (struct sockaddr *) &my_addr, sizeof(my_addr)) < 0) {
        pexit("bind");
    }

    host = gethostbyname(p->argv[1]);
    if (host == (struct hostent *)NULL) {
        pexit("gethostbyname");
    }

    memset(&slave, 0, sizeof(slave));
    slave.sin_family = AF_INET;
#ifdef __ECOS
    slave.sin_len = sizeof(slave);
#endif
    slave.sin_port = htons(NC_SLAVE_PORT);
    memcpy(&slave.sin_addr.s_addr, host->h_addr, host->h_length);

    test_printf("================== No load, master at 100%% ========================\n");
#if 0
    do_udp_test(s, NC_REQUEST_UDP_ECHO, &slave, 640, 1024, 0, 0);
    do_udp_test(s, NC_REQUEST_UDP_SEND, &slave, 640, 1024, 0, 0);
    do_udp_test(s, NC_REQUEST_UDP_RECV, &slave, 640, 1024, 0, 0);
    do_tcp_test(s, NC_REQUEST_TCP_ECHO, &slave, 640, 1024, 0, 0);
    do_tcp_test(s, NC_REQUEST_TCP_SEND, &slave, 640, 1024, 0, 0);
    do_tcp_test(s, NC_REQUEST_TCP_RECV, &slave, 640, 1024, 0, 0);
#endif
    do_tcp_test(s, NC_REQUEST_TCP_ECHO, &slave, 64, 10240, 0, 0);

    if (do_set_load(s, &slave, 0)) {
        test_printf("\n====================== Various slave compute loads ===================\n");
        for (i = 0;  i < 60;  i += 10) {
            test_printf(">>>>>>>>>>>> slave processing load at %d%%\n", i);
            do_set_load(s, &slave, i);
            do_udp_test(s, NC_REQUEST_UDP_ECHO, &slave, 2048, 1024, 0, 0);
            do_tcp_test(s, NC_REQUEST_TCP_ECHO, &slave, 2048, 1024, 0, 0);
        }
    }

    if (do_start_idle(s, &slave)) {
        test_printf("\n====================== Various master loads ===================\n");
        test_printf("Testing IDLE for %d seconds\n", IDLE_TEST_TIME);
        test_delay(IDLE_TEST_TIME*100);
        do_stop_idle(s, &slave, true);
        for (i = 0;  i < LENGTH(pause_times);  i++) {
            do_start_idle(s, &slave);
            do_udp_test(s, NC_REQUEST_UDP_ECHO, &slave, 2048, 1024, 
                        pause_times[i].pause_ticks, pause_times[i].pause_threshold);
            do_stop_idle(s, &slave, false);
            do_start_idle(s, &slave);
            do_tcp_test(s, NC_REQUEST_TCP_ECHO, &slave, 2048, 1024, 
                        pause_times[i].pause_ticks, pause_times[i].pause_threshold);
            do_stop_idle(s, &slave, false);
        }
    }

    do_disconnect(s, &slave);
    close(s);
}