Commit 70ffc288 authored by Titouan Soulard's avatar Titouan Soulard

example: add argument for device name

parent b26ab9e6
......@@ -4,31 +4,30 @@ Minimal working examples for RDMA: standalone server and client and library for
## Configuring an RDMA interface
In order to run this RDMA example, you will need to create a RDMA interface on two virtual machines:
In order to run this RDMA example, you will need to create a RDMA interface on two virtual machines.
For instance, to use RoCE (RDMA over Converged Ethernet) on interface `enp1s0`:
```bash
modprobe rdma_rxe
rdma link add rxe0 type rxe netdev enp1s0
rdma link show
mkdir -p /sys/kernel/config/rdma_cm/rxe0
```
## Standalone server and client
The provided `rdma_standalone` example allows reading the memory of one computer from another one.
On one machine, run the server program, which will read content to be put in the shared memory from STDIN:
```bash
make install
rdma_standalone < README.md
rdma_standalone -d rxe0 < README.md
```
The other machine will act as a client, so we need to pass it the IP address of the server:
```bash
make install
rdma_standalone -c 192.168.16.10 < Makefile
rdma_standalone -d rxe0 -c 192.168.16.10 < Makefile
```
The client should (almost) immediately display the content of `README.md`, and the server the content of `Makefile`.
......
......@@ -38,13 +38,22 @@ int main(int argc, char *argv[]) {
pthread_t serve_mr_td;
struct ServeMrThreadContext serve_mr_td_ctx;
size_t remote_host_size;
size_t device_name_size;
int allocated_size;
int server_socket;
char remote_host[16];
int opt;
char *remote_host;
char *device_name;
char in_mr_fc;
bool is_client;
bool result;
int allocated_size = 16384 * sizeof(char);
bool is_client = false;
// Preallocate some variables
allocated_size = 16384 * sizeof(char);
remote_host = NULL;
device_name = NULL;
is_client = false;
srand48(getpid() * time(NULL));
result = common_hashtable_initialize(&mr_mgr, 33);
......@@ -56,14 +65,26 @@ int main(int argc, char *argv[]) {
/******************************
**** Arguments processing ****
******************************/
// Detect if a server was given; if any, act as a client
if(argc >= 3) {
if(strcmp(argv[1], "-c") == 0) {
strcpy((void *) remote_host, (void *) argv[2]);
while((opt = getopt(argc, argv, "c:d:")) != -1) {
// Detect if a server was given; if any, act as a client
if(opt == 'c') {
remote_host_size = strlen(optarg) + 1;
remote_host = (char *) malloc(remote_host_size * sizeof(char));
strcpy(remote_host, optarg);
is_client = true;
} else if(opt == 'd') {
device_name_size = strlen(optarg) + 1;
device_name = (char *) malloc(device_name_size * sizeof(char));
strcpy(device_name, optarg);
}
}
if(device_name == NULL) {
fprintf(stderr, "Device name is mandatory: use option `-d`\n");
return -1;
}
// Set up remote address
if(is_client) {
memset(&server_hints, 0, sizeof(struct addrinfo));
......@@ -79,7 +100,7 @@ int main(int argc, char *argv[]) {
/******************************
***** RDMA initialization ****
******************************/
result = capulet_rdma_ib_initialize_device(&rdma_ctx, "rxe0");
result = capulet_rdma_ib_initialize_device(&rdma_ctx, device_name);
if(!result) {
fprintf(stderr, "Device initialization failed\n");
return -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment