Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
void pkt_tx(tw_tx_t * handle)
{

curr_time_cycle = tw_get_current_timer_cycles();
if((curr_time_cycle - prev_stats_calc) > ppsdelay)
{
 prev_stats_calc=curr_time_cycle;


    if((global_stats_option.pkts_tx < PacketLimit || PacketLimit == 0) && (global_stats_option.secs_passed < user_params.test_runtime || user_params.test_runtime == 0))
    {
        if (dst_eth_addr == NULL) {
            struct arp_table * temp_arp_entry = tw_search_arp_table(tw_be_to_cpu_32(user_params.server_ip));
            if(temp_arp_entry == NULL )
            {
                if (arp_secs!=global_stats_option.secs_passed) {
                    tw_construct_arp_packet(user_params.server_ip, phy_port_id);
                    arp_secs=global_stats_option.secs_passed;
                    total_arps++;
                } else
                {
                    return;
                }
            }
            else
            dst_eth_addr = &temp_arp_entry->eth_mac;
        }
        else {
            eth = tx_buf->data;
            ip  = (struct ipv4_hdr* )(eth + 1);
            udp = (struct udp_hdr* )(ip + 1);
            udp->src_port = tw_cpu_to_be_16(7777);
            udp->dst_port = tw_cpu_to_be_16(user_params.server_port);
            udp->dgram_len = tw_cpu_to_be_16(tx_buf->size - sizeof(struct ether_hdr) - sizeof(struct ipv4_hdr));
            udp->dgram_cksum = 0;
            ip->total_length = tw_cpu_to_be_16(tx_buf->size - sizeof(struct ether_hdr));
            ip->next_proto_id = UDP_PROTO_ID;
            ip->src_addr = ipv4_tw0;
            ip->dst_addr = tw_cpu_to_be_32(user_params.server_ip);
            ip->version_ihl = 0x45;
            ip->time_to_live = 63;
            ip->hdr_checksum =tw_ipv4_cksum(ip);
            eth->ether_type = tw_cpu_to_be_16(ETHER_TYPE_IPv4);
            tw_copy_ether_addr(dst_eth_addr, &(eth->d_addr));
            tw_copy_ether_addr(port_info[phy_port_id].eth_mac, &(eth->s_addr));
            tw_send_pkt(tx_buf, "tw0");
        }
    }
 }
}
Ejemplo n.º 3
0
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;
}