2 * Copyright (c) 2007, 2008, 2009, 2010, 2011, 2012, ETH Zurich.
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.
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>
25 //#define DEBUG(x...) printf("devif_test: " x)
26 #define DEBUG(x...) do {} while (0)
30 #define MEMORY_SIZE BUF_SIZE*NUM_BUF
33 static struct devq* udp_q;
34 static struct capref memory_rx;
35 static regionid_t regid_rx;
36 static struct frame_identity id;
37 static lpaddr_t phys_rx;
42 static uint32_t ip_dst;
43 static uint64_t mac_dst;
44 static uint16_t port_src;
45 static uint16_t port_dst;
46 static const char* cardname;
48 static uint64_t tsc_per_ms;
50 static void event_cb(void* q)
55 static void convert_mac(uint64_t int_mac, struct eth_addr* mac)
57 // Also convert to network byte order
58 mac->addr[5] = int_mac & 0xFF;
59 mac->addr[4] = (int_mac & 0xFF00) >> 8;
60 mac->addr[3] = (int_mac & 0xFF0000) >> 16;
61 mac->addr[2] = (int_mac & 0xFF000000) >> 24;
62 mac->addr[1] = (int_mac & 0xFF00000000) >> 32;
63 mac->addr[0] = (int_mac & 0xFF0000000000) >> 40;
66 int main(int argc, char *argv[])
70 ip_dst = atoi(argv[1]);
71 mac_dst = strtoull(argv[2], &stop, 10);
72 port_src = atoi(argv[3]);
73 port_dst = atoi(argv[4]);
77 USER_PANIC("NO src or dst IP given \n");
82 err = frame_alloc(&memory_rx, MEMORY_SIZE, NULL);
83 if (err_is_fail(err)){
84 USER_PANIC("Allocating cap failed \n");
88 err = invoke_frame_identify(memory_rx, &id);
89 if (err_is_fail(err)) {
90 USER_PANIC("Frame identify failed \n");
93 err = vspace_map_one_frame_attr(&va_rx, id.bytes, memory_rx,
94 VREGION_FLAGS_READ_WRITE, NULL, NULL);
95 if (err_is_fail(err)) {
96 USER_PANIC("Frame mapping failed \n");
101 struct eth_addr dst_mac;
103 convert_mac(mac_dst, &dst_mac);
105 err = udp_create((struct udp_q**) &udp_q, cardname, port_src, port_dst,
106 ip_dst, dst_mac, event_cb, true);
107 if (err_is_fail(err)) {
108 USER_PANIC("Queue creation failed \n");
111 err = devq_register(udp_q, memory_rx, ®id_rx);
112 if (err_is_fail(err)) {
113 USER_PANIC("Register failed \n");
116 err = sys_debug_get_tsc_per_ms(&tsc_per_ms);
117 assert(err_is_ok(err));
119 barrelfish_usleep(1000*1000*15);
124 genoffset_t valid_data;
125 genoffset_t valid_length;
133 while (err == SYS_ERR_OK) {
134 devq_enqueue((struct devq*) udp_q, regid_rx, j*BUF_SIZE, BUF_SIZE, 0, len, NETIF_TXFLAG | NETIF_TXFLAG_LAST);
135 devq_dequeue((struct devq*) udp_q, &rid, &offset, &length, &valid_data,
136 &valid_length, &flags);