Commit 7f42ecaf authored by Titouan Soulard's avatar Titouan Soulard

Parameters exchange: allow bidirectionnal exchange

Parameters need to be exchanged in both way using UDP, so the initial (unused) `capabilities` packet
was dropped in favor of sending client's parameters with the request.
parent db9638c7
......@@ -2,6 +2,9 @@ CFLAGS = -Wall -O3
all: udp_send udp_recv rdma_server
clean:
rm bin/*
udp_send: udp_send.c udp_rdma.c
gcc $(CFLAGS) -o bin/$@ $?
......
......@@ -16,7 +16,9 @@ int main(void) {
struct ibv_qp *ibv_dev_qp;
struct ibv_mr *ibv_dev_mr;
struct ibv_port_attr ibv_dev_attr;
struct udp_rdma_parameters local_params;
struct udp_rdma_parameters remote_params;
void *memory_buffer;
int result;
......@@ -87,13 +89,13 @@ int main(void) {
local_params.size = ibv_dev_mr->length;
local_params.key = ibv_dev_mr->rkey;
printf("LID: %d | QPN: %d | PSN: %d\n", local_params.lid, local_params.qpn, local_params.psn);
udp_rdma_dump_packet(&local_params);
if(!serve_rdma_udp_parameters(&local_params)) {
if(!udp_rdma_receive_parameters(&local_params, &remote_params)) {
return -1;
}
printf("Parameters sent to peer\n");
udp_rdma_dump_packet(&remote_params);
/******************************
******* Global cleanup *******
......
#include "udp_rdma.h"
bool serve_rdma_udp_parameters(struct udp_rdma_parameters *rdma_params) {
bool udp_rdma_receive_parameters(struct udp_rdma_parameters *local_params, struct udp_rdma_parameters *remote_params) {
struct addrinfo server_hints;
struct addrinfo *server_infos;
struct sockaddr client_addr;
//struct udp_query_parameters *rdma_req_params;
socklen_t client_addr_size = sizeof(struct sockaddr_storage);
const size_t buffer_length = sizeof(struct udp_query_parameters);
const size_t buffer_length = sizeof(struct udp_rdma_parameters);
int result, server_socket;
char receive_buffer[buffer_length];
......@@ -47,10 +46,9 @@ bool serve_rdma_udp_parameters(struct udp_rdma_parameters *rdma_params) {
return false;
}
// XXX: assumes client has requested everything (`rdma_req_params` unused)
//rdma_req_params = (struct udp_query_parameters *) receive_buffer;
memcpy((void *) remote_params, (void *) receive_buffer, buffer_length);
result = sendto(server_socket, (void *) rdma_params, sizeof(struct udp_rdma_parameters), MSG_CONFIRM, &client_addr, client_addr_size);
result = sendto(server_socket, (void *) local_params, buffer_length, MSG_CONFIRM, &client_addr, client_addr_size);
if(result == -1) {
perror("sendto error");
return false;
......@@ -61,12 +59,10 @@ bool serve_rdma_udp_parameters(struct udp_rdma_parameters *rdma_params) {
return true;
}
bool receive_rdma_udp_parameters(const char *hostname, struct udp_rdma_parameters *rdma_params) {
bool udp_rdma_send_parameters(const char *hostname, struct udp_rdma_parameters *local_params, struct udp_rdma_parameters *remote_params) {
struct addrinfo server_hints;
struct addrinfo *server_infos;
struct udp_query_parameters rdma_req_params;
const size_t buffer_length = sizeof(struct udp_rdma_parameters);
int result, server_socket;
char receive_buffer[buffer_length];
......@@ -91,8 +87,7 @@ bool receive_rdma_udp_parameters(const char *hostname, struct udp_rdma_parameter
}
// Create and send a query with full capabilities
rdma_req_params.requested = REQ_LID | REQ_QPN | REQ_ADDR | REQ_SIZE | REQ_KEY;
result = sendto(server_socket, (void *) &rdma_req_params, sizeof(struct udp_query_parameters), 0, server_infos->ai_addr, server_infos->ai_addrlen);
result = sendto(server_socket, (void *) local_params, buffer_length, 0, server_infos->ai_addr, server_infos->ai_addrlen);
if(result == -1) {
perror("sendto error");
return false;
......@@ -106,7 +101,7 @@ bool receive_rdma_udp_parameters(const char *hostname, struct udp_rdma_parameter
return false;
}
memcpy((void *) rdma_params, (void *) receive_buffer, buffer_length);
memcpy((void *) remote_params, (void *) receive_buffer, buffer_length);
close(server_socket);
freeaddrinfo(server_infos);
......@@ -114,3 +109,8 @@ bool receive_rdma_udp_parameters(const char *hostname, struct udp_rdma_parameter
return true;
}
void udp_rdma_dump_packet(struct udp_rdma_parameters *rdma_params) {
printf("LID: 0x%x | QPN: 0x%x | PSN: 0x%x\n", rdma_params->lid, rdma_params->qpn, rdma_params->psn);
printf("addr: %p | size: %ld | key: 0x%x\n", rdma_params->addr, rdma_params->size, rdma_params->key);
}
......@@ -9,16 +9,6 @@
#include <sys/types.h>
#include <sys/socket.h>
#define REQ_LID 0x1
#define REQ_QPN 0x2
#define REQ_ADDR 0x4
#define REQ_SIZE 0x8
#define REQ_KEY 0x10
struct udp_query_parameters {
uint8_t requested;
};
struct udp_rdma_parameters {
uint16_t lid;
uint32_t qpn;
......@@ -28,6 +18,7 @@ struct udp_rdma_parameters {
uint32_t key;
};
bool serve_rdma_udp_parameters(struct udp_rdma_parameters *rdma_params);
bool receive_rdma_udp_parameters(const char *hostname, struct udp_rdma_parameters *rdma_params);
bool udp_rdma_receive_parameters(struct udp_rdma_parameters *local_params, struct udp_rdma_parameters *remote_params);
bool udp_rdma_send_parameters(const char *hostname, struct udp_rdma_parameters *local_params, struct udp_rdma_parameters *remote_params);
void udp_rdma_dump_packet(struct udp_rdma_parameters *rdma_params);
#include "udp_rdma.h"
int main(void) {
struct udp_rdma_parameters rdma_params;
void *dummy_pointer = (void *) 0xABCDEF00;
bool result;
struct udp_rdma_parameters local_params;
struct udp_rdma_parameters remote_params;
rdma_params.lid = 0x1234;
rdma_params.qpn = 0x12345678;
rdma_params.addr = dummy_pointer;
rdma_params.size = 8;
rdma_params.key = 0x87654321;
void *dummy_pointer = (void *) 0xABCDEF00;
result = serve_rdma_udp_parameters(&rdma_params);
local_params.lid = 0x1234;
local_params.qpn = 0x12345678;
local_params.psn = 0x9ABCDE;
local_params.addr = dummy_pointer;
local_params.size = 8;
local_params.key = 0x87654321;
if(result) {
printf("Successfully sent RDMA informations to client\n");
return 0;
} else {
return 1;
}
udp_rdma_dump_packet(&local_params);
udp_rdma_receive_parameters(&local_params, &remote_params);
udp_rdma_dump_packet(&remote_params);
}
#include "udp_rdma.h"
int main(void) {
struct udp_rdma_parameters local_params;
struct udp_rdma_parameters remote_params;
const char server_hostname[16] = "192.168.16.10";
struct udp_rdma_parameters rdma_params;
bool result;
void *dummy_pointer = (void *) 0x00FEDCBA;
result = receive_rdma_udp_parameters(server_hostname, &rdma_params);
local_params.lid = 0x4321;
local_params.qpn = 0x87654321;
local_params.psn = 0xEDCBA9;
local_params.addr = dummy_pointer;
local_params.size = 8;
local_params.key = 0x12345678;
if(result) {
printf("Received LID 0x%x from %s\n", rdma_params.lid, server_hostname);
return 0;
} else {
return 1;
}
udp_rdma_dump_packet(&local_params);
udp_rdma_send_parameters(server_hostname, &local_params, &remote_params);
udp_rdma_dump_packet(&remote_params);
}
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