コード例 #1
0
ファイル: twarp.c プロジェクト: twister2016/twister
bool isSameNetwork(char* ip)
{
    uint32_t ipp = tw_convert_ip_str_to_dec(ip);
    uint32_t desAnd = ipp & tw_get_subnet_mask("tw0");
    uint32_t souAnd = tw_get_ip_addr("tw0") & tw_get_subnet_mask("tw0");
    return desAnd == souAnd;
}
コード例 #2
0
ファイル: twudpsend.c プロジェクト: Nauman10/twister
int main(int argc, char **argv) {
    tw_init_global();
    ipv4_tw0 = tw_cpu_to_be_32(tw_get_ip_addr("tw0"));
    parse_user_params("udp_traffic_data");
    tw_map_port_to_engine("tw0", "engine0");
    phy_port_id = tw_eth_name_to_id("tw0");
    tx_buf = tw_new_buffer(user_params.payload_size);
    global_stats_option.secs_passed=0;
    ppsdelay = tw_get_tsc_hz()/user_params.pps_limit;
    user_app_main(NULL);
    return 0;
}
コード例 #3
0
ファイル: twiperf.c プロジェクト: twister2016/twister
int twiperf_parse_arguments(struct iperf_test *test, int argc, char **argv) /*parsing user given arguments*/
{
    int udp_flag, ethernet_flag;
    static struct option longopts[] = { { "udp", no_argument, NULL, 'u' }, { "ethernet",
    no_argument, NULL, 'e' }, { "server", no_argument, NULL, 's' }, { "client",
    required_argument, NULL, 'c' }, { "help", no_argument, NULL, 'h' }, { "port",
    required_argument, NULL, 'p' }, { "bytes", required_argument, NULL, 'n' }, { "bandwith", required_argument, NULL, 'b'},
    { NULL, 0, NULL, 0 } };
    int flag;
    server_flag = client_flag = udp_flag = ethernet_flag = 0;
    test->packet_size = 1500; //initialized to default value of 64 bytes pcket size
    test->server_port = 5001;  //initialized to default port of 5001
    test->client_port = 7777;  //initialized to default port of 5001
    test->test_runtime = 0;  //initialized to default infinite runtime

    udp_flag = 1;
    test->protocol_id = 2;

    while ((flag = getopt_long(argc, argv, "b:n:p:uec:hs", longopts, NULL)) != -1)
    {
        switch (flag)
        {
            case 'p':
                test->server_port = atoi(optarg);
                break;
            case 'n':
                test->packet_size = atoi(optarg);
                break;
            case 'b':
                test->rate = unit_atof_rate(optarg);
                rate_flag = 1;
                client_flag = 1;
                break;
            case 'c':
                client_flag = 1;
                test->role = 2;
                test->client_mac = tw_get_ether_addr("tw0");
                test->server_ip = tw_cpu_to_be_32(tw_convert_ip_str_to_dec(strdup(optarg)));

                if(test->server_ip == 0)
                {
                    twiperf_usage();
                    exit(1);
                }

                test->client_ip = tw_cpu_to_be_32(tw_get_ip_addr("tw0"));
                break;
            case 's':
                server_flag = 1;
                test->role = 1;
                test->server_mac = tw_get_ether_addr("tw0");
                test->server_ip = tw_cpu_to_be_32(tw_get_ip_addr("tw0"));
                break;
            case 'e':
                ethernet_flag = 1;
                udp_flag = 0;
                test->protocol_id = 1;
                break;
            case 'u':
                udp_flag = 1;
                test->protocol_id = 2;
                break;
            case 'h':
                twiperf_usage();
                exit(1);
                break;
            default:
                twiperf_usage();
                exit(1);
        }
    }

    if(server_flag == 1 && client_flag == 1 || udp_flag == 1 && ethernet_flag == 1)
    {
        twiperf_usage();
        exit(1);
    }

    if(server_flag == 0 && client_flag == 0 || udp_flag == 0 && ethernet_flag == 0)
    {
        twiperf_usage();
        exit(1);
    }

    if((test->role != 1) && (test->role != 2))
    {
        i_errno = IENOROLE;
        return -1;
    }

    if(udp_flag == 1 && test->packet_size > MAX_UDP_BLOCKSIZE)
    {
        i_errno = IEUDPBLOCKSIZE;
        return -1;
    }
    return 0;
}