1/* 2 * Copyright (c) 2007, 2008, 2009, 2010, 2011, 2012, ETH Zurich. 3 * All rights reserved. 4 * 5 * This file is distributed under the terms in the attached LICENSE file. 6 * If you do not find this file, copies can be found by writing to: 7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 8 */ 9 10#include <stdlib.h> 11#include <stdio.h> 12#include <time.h> 13#include <barrelfish/barrelfish.h> 14#include <barrelfish/waitset.h> 15#include <barrelfish/waitset_chan.h> 16#include <barrelfish/deferred.h> 17#include <barrelfish/sys_debug.h> 18#include <devif/queue_interface.h> 19#include <devif/backends/net/udp.h> 20#include <bench/bench.h> 21#include <net_interfaces/flags.h> 22 23 24#define BENCH 25//#define DEBUG(x...) printf("devif_test: " x) 26#define DEBUG(x...) do {} while (0) 27 28#define BUF_SIZE 2048 29#define NUM_BUF 1024 30#define MEMORY_SIZE BUF_SIZE*NUM_BUF 31 32 33static struct devq* udp_q; 34static struct capref memory_rx; 35static regionid_t regid_rx; 36static struct frame_identity id; 37static lpaddr_t phys_rx; 38static void* va_rx; 39 40 41static uint16_t len; 42static uint32_t ip_dst; 43static uint64_t mac_dst; 44static uint16_t port_src; 45static uint16_t port_dst; 46static const char* cardname; 47 48static uint64_t tsc_per_ms; 49 50static void event_cb(void* q) 51{ 52 return; 53} 54 55int main(int argc, char *argv[]) 56{ 57 if (argc > 6) { 58 char* stop; 59 ip_dst = atoi(argv[1]); 60 mac_dst = strtoull(argv[2], &stop, 10); 61 port_src = atoi(argv[3]); 62 port_dst = atoi(argv[4]); 63 cardname = argv[5]; 64 len = atoi(argv[6]); 65 } else { 66 USER_PANIC("NO src or dst IP given \n"); 67 } 68 69 errval_t err; 70 // Allocate memory 71 err = frame_alloc(&memory_rx, MEMORY_SIZE, NULL); 72 if (err_is_fail(err)){ 73 USER_PANIC("Allocating cap failed \n"); 74 } 75 76 // RX frame 77 err = invoke_frame_identify(memory_rx, &id); 78 if (err_is_fail(err)) { 79 USER_PANIC("Frame identify failed \n"); 80 } 81 82 err = vspace_map_one_frame_attr(&va_rx, id.bytes, memory_rx, 83 VREGION_FLAGS_READ_WRITE, NULL, NULL); 84 if (err_is_fail(err)) { 85 USER_PANIC("Frame mapping failed \n"); 86 } 87 88 phys_rx = id.base; 89 90 err = udp_create((struct udp_q**) &udp_q, cardname, port_src, port_dst, 91 ip_dst, event_cb, true); 92 if (err_is_fail(err)) { 93 USER_PANIC("Queue creation failed \n"); 94 } 95 96 err = devq_register(udp_q, memory_rx, ®id_rx); 97 if (err_is_fail(err)) { 98 USER_PANIC("Register failed \n"); 99 } 100 101 err = sys_debug_get_tsc_per_ms(&tsc_per_ms); 102 assert(err_is_ok(err)); 103 104 barrelfish_usleep(1000*1000*15); 105 106 regionid_t rid; 107 genoffset_t offset; 108 genoffset_t length; 109 genoffset_t valid_data; 110 genoffset_t valid_length; 111 uint64_t flags; 112 113 err = SYS_ERR_OK; 114 115 assert(len < 1500); 116 117 int j = 0; 118 while (err == SYS_ERR_OK) { 119 devq_enqueue((struct devq*) udp_q, regid_rx, j*BUF_SIZE, BUF_SIZE, 0, len, NETIF_TXFLAG | NETIF_TXFLAG_LAST); 120 devq_dequeue((struct devq*) udp_q, &rid, &offset, &length, &valid_data, 121 &valid_length, &flags); 122 j = (j+1) % NUM_BUF; 123 } 124 125} 126 127