PadicoTM

Documentation

« back to PM2 home.
bench_UDP.c
Go to the documentation of this file.
1/* bench_VIO.c
2 */
3
4#include <netdb.h>
5#include "bench_common.h"
6#include <Padico/VIO.h>
7#include <Padico/Module.h>
8#include <Padico/NetAccess.h>
9
10int bench_udp_init(void);
11int bench_udp_run(int argc, char**argv);
12void bench_udp_finalize(void);
13
14PADICO_MODULE_DECLARE(bench_UDP, bench_udp_init, bench_udp_run, bench_udp_finalize);
15
16#define DEFAULT_PORT 5040
17
18static int port = DEFAULT_PORT;
19
20static struct sockaddr_in local_addr;
22static struct sockaddr_in remote_addr;
24static int bench_fd;
25
27{
28 int rc;
29 struct hostent*he;
30 bench_fd = padico_vio_socket(PF_INET, SOCK_DGRAM, 0);
31 local_addr.sin_family = AF_INET;
32 local_addr.sin_port = htons(port);
34 if(rc != 0)
35 {
36 padico_warning("cannot bind on port %d\n", port);
37 return -1;
38 }
39 he = gethostbyname(server_name);
40 if(he == NULL)
41 {
42 padico_warning("cannot resolve host=**%s**\n", server_name);
43 return -1;
44 }
45 // memcpy(&remote_addr.sin_addr, he->h_addr_list[0], sizeof(remote_addr.sin_addr));
46 memcpy(&remote_addr.sin_addr,
47 padico_topo_host_getaddr(padico_topo_node_gethost(padico_na_madio_getnodebyrank((padico_na_rank()+1)%2))),
48 sizeof(remote_addr.sin_addr));
49 remote_addr.sin_family = AF_INET;
50 remote_addr.sin_port = htons(port);
51 return 0;
52}
53
58
59void udp_server(char*buffer, int lenbuf, int num_roundtrip)
60{
61 int i;
62 struct sockaddr from_addr;
63 int from_addr_size = sizeof(from_addr);
64 for(i=0; i<num_roundtrip; i++)
65 {
67 padico_vio_recvfrom_madio(bench_fd, buffer, lenbuf, 0, &from_addr, &from_addr_size);
68 }
69}
70
71void udp_client(char*buffer, int lenbuf, int num_roundtrip)
72{
73 int i;
74 struct sockaddr from_addr;
75 int from_addr_size = sizeof(from_addr);
76 for(i=0; i<num_roundtrip; i++)
77 {
78 padico_vio_recvfrom_madio(bench_fd, buffer, lenbuf, 0, &from_addr, &from_addr_size);
80 }
81}
82
84{
85 "UDP",
88};
89
90int bench_udp_run(int argc, char**argv)
91{
93 return 0;
94}
return NULL
Definition Shm.h:88
static socklen_t remote_addr_size
Definition bench_UDP.c:23
int bench_udp_run(int argc, char **argv)
Definition bench_UDP.c:90
#define DEFAULT_PORT
Definition bench_UDP.c:16
void udp_client(char *buffer, int lenbuf, int num_roundtrip)
Definition bench_UDP.c:71
int bench_udp_init(void)
Definition bench_UDP.c:26
static int port
Definition bench_UDP.c:18
struct bench_desc_s udp_bench
Definition bench_UDP.c:83
static socklen_t local_addr_size
Definition bench_UDP.c:21
static struct sockaddr_in remote_addr
Definition bench_UDP.c:22
static struct sockaddr_in local_addr
Definition bench_UDP.c:20
void bench_udp_finalize(void)
Definition bench_UDP.c:54
void udp_server(char *buffer, int lenbuf, int num_roundtrip)
Definition bench_UDP.c:59
static int bench_fd
Definition bench_UDP.c:24
static int num_roundtrip
void the_bench(const struct bench_desc_s *b)
static char * buffer
padico_rc_t rc
Definition PadicoTM.h:146
padico_topo_host_t padico_topo_node_gethost(padico_topo_node_t node)
Get the host hosting a node.
Definition topology.c:1927
const struct in_addr * padico_topo_host_getaddr(padico_topo_host_t host)
Get the canonical IP address of a host.
Definition topology.c:1977
#define padico_na_rank()
Definition Topology.h:324
ssize_t padico_vio_recvfrom_madio(int s, void *buf, size_t len, int flags, struct sockaddr *from, int *fromlen)
int padico_vio_bind(int s, const struct sockaddr *name, socklen_t namelen)
Definition vio.c:1182
ssize_t padico_vio_sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, int tolen)
Definition vio.c:1011
int padico_vio_socket(int domain, int type, int protocol)
Definition vio.c:1156
int padico_vio_close(int fd)
Definition vio.c:492