Esempio n. 1
0
void reply_udp_payload(tw_rx_t * handle, tw_buf_t * buffer) {
    eth = buffer->data;
    eth_type = tw_be_to_cpu_16(eth->ether_type);
        switch (eth_type) {
            case ETHER_TYPE_ARP:
                tw_arp_parser(buffer, "tw0");
                break;
            case ETHER_TYPE_IPv4:
                ipHdr_d = buffer->data + sizeof(struct ether_hdr);
                dst_ip  = (ipHdr_d->dst_addr);
                src_ip = (ipHdr_d->src_addr);
                ipHdr_d->dst_addr = (src_ip);
                ipHdr_d->src_addr = (dst_ip);
                ipHdr_d->hdr_checksum = tw_ipv4_cksum(ipHdr_d);

                udp_hdr_d = (struct udp_hdr *)ipHdr_d + sizeof(struct ipv4_hdr);
                dst_port = (udp_hdr_d->dst_port);
                src_port = (udp_hdr_d->src_port);
                udp_hdr_d->dst_port = (src_port);
                udp_hdr_d->src_port = (dst_port);
                udp_hdr_d->dgram_cksum = 0;

                tw_copy_ether_addr(&(eth->s_addr), &(eth->d_addr));
                tw_copy_ether_addr(dst_eth, &(eth->s_addr));
                tw_send_pkt(buffer, "tw0");
                break;
                
        }
 
}
Esempio n. 2
0
void reply_payload(tw_rx_t * handle, tw_buf_t * buffer)
{
    struct ether_hdr * eth = buffer->data;
    tw_copy_ether_addr(&(eth->s_addr), &(eth->d_addr));
    tw_copy_ether_addr(dst_eth, &(eth->s_addr));
    tw_send_pkt(buffer, "tw0");
}
Esempio n. 3
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");
        }
    }
 }
}
Esempio n. 4
0
/* reply_udp_payload acts as udp server; switches the IP and ports, mac addresses and echoes back the packet to sender*/
void reply_udp_payload(tw_rx_t * handle, tw_buf_t * buffer)
{
    test_stats.datagrams_recv++;
    eth = buffer->data;
    eth_type = tw_be_to_cpu_16(eth->ether_type);
    ipHdr_d = buffer->data + sizeof(struct ether_hdr);
    dst_ip = (ipHdr_d->dst_addr);
    src_ip = (ipHdr_d->src_addr);
    ipHdr_d->dst_addr = (src_ip);
    ipHdr_d->src_addr = (dst_ip);
    ipHdr_d->hdr_checksum = tw_ipv4_cksum(ipHdr_d);
    udp_hdr_d = (struct udp_hdr *) ipHdr_d + sizeof(struct ipv4_hdr);
    dst_port = (udp_hdr_d->dst_port);
    src_port = (udp_hdr_d->src_port);
    udp_hdr_d->dst_port = (src_port);
    udp_hdr_d->src_port = (dst_port);
    udp_hdr_d->dgram_cksum = 0;
    tw_copy_ether_addr(&(eth->s_addr), &(eth->d_addr));
    tw_copy_ether_addr(test.server_mac, &(eth->s_addr));
    tw_send_pkt(buffer, "tw0");
    test_stats.datagrams_sent++;
}