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

Merge trx-bridge into rdma-mwe

parent 18460064
CFLAGS = -Wall -O3
INCLUDE_FLAGS = -I./include
LIB_FLAGS =-lc -libverbs
LIB_FLAGS =-lc -ldl -libverbs
# Libraries after `--no-as-needed` are forcefully loaded: they are required by Amarisoft libraries
FORCE_LIB_FLAGS = -Wl,--no-as-needed -lm -lpthread
all: out/libcapulet.so out/libtrx_rdma.so out/rdma_standalone
all: out/libcapulet.so out/libpotoml.so out/libtrx_rdma.so out/rdma_standalone out/trx-bridge
install: all
ln -sr out/libcapulet.so /usr/local/lib/
......@@ -10,6 +12,7 @@ install: all
ln -sr out/libpotoml.so /usr/local/lib/
ldconfig
ln -sr out/rdma_standalone /usr/local/bin/
ln -sr out/trx-bridge /usr/local/bin/
clean:
rm out/* ||:
......@@ -34,3 +37,5 @@ out/libtrx_rdma.so: libtrx/trx_rdma.lo out/libcapulet.so
out/rdma_standalone: example/rdma_standalone.o out/libcapulet.so
gcc $(CFLAGS) -o $@ $< $(LIB_FLAGS) -L./out -lcapulet
out/trx-bridge: trx-bridge/bridge.o out/libpotoml.so
gcc $(CFLAGS) -o $@ $< $(LIB_FLAGS) $(FORCE_LIB_FLAGS) -L./out -lpotoml
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "amarisoft/trx_driver.h"
#include "common/hashtable.h"
#include "libpotoml/toml.h"
// XXX: should be part of the `app_opaque` pointer
struct PotomlTomlSubset *input_driver_config;
struct PotomlTomlSubset *output_driver_config;
char *bridge_trx_input_get_param_string(void *app_opaque, const char *prop_name) {
return potoml_toml_get_string(input_driver_config, prop_name);
}
int bridge_trx_input_get_param_double(void *app_opaque, double *pval, const char *prop_name) {
return potoml_toml_get_double(input_driver_config, prop_name);
}
char *bridge_trx_output_get_param_string(void *app_opaque, const char *prop_name) {
return potoml_toml_get_string(output_driver_config, prop_name);
}
int bridge_trx_output_get_param_double(void *app_opaque, double *pval, const char *prop_name) {
return potoml_toml_get_double(output_driver_config, prop_name);
}
int main(int argc, char *argv[]) {
struct CommonHashtableTable config;
struct PotomlTomlSubset *bridge_config;
int opt;
char result;
char *error;
char *output_lib_name = NULL;
char *input_lib_name = NULL;
char *bridge_config_path = NULL;
char *driver_config_dir = NULL;
int bridge_config_path_size;
int driver_config_dir_size;
void *input_lib_handle;
void *output_lib_handle;
int (*input_lib_init)(TRXState *s);
int (*output_lib_init)(TRXState *s);
TRXState input_trx_state;
TRXState output_trx_state;
// This is used for debugging purposes, and was improvised by nonprofessionals.
// Do not attempt to reproduce it.
for(int i = 0; i < sizeof(TRXState); i++) {
*((char *) &input_trx_state + i) = (char) (i % 255);
}
while((opt = getopt(argc, argv, "c:p:")) != -1) {
if(opt == 'c') {
bridge_config_path_size = strlen(optarg) + 1;
bridge_config_path = (char *) malloc(bridge_config_path_size * sizeof(char));
strcpy(bridge_config_path, optarg);
} else if(opt == 'p') {
driver_config_dir_size = strlen(optarg) + 1;
driver_config_dir = (char *) malloc(driver_config_dir_size * sizeof(char));
strcpy(driver_config_dir, optarg);
}
}
if(!bridge_config_path || !driver_config_dir) {
fprintf(stderr, "Missing required options: -c config_file and -p driver_config_dir\n");
return -1;
}
printf("trx-bridge: reading configuration file %s\n", bridge_config_path);
common_hashtable_initialize(&config, 255);
result = potoml_toml_parse_file(&config, bridge_config_path);
if(result != 0) {
printf("Reading configuration file returned 0x%x\n", result);
return -1;
}
bridge_config = potoml_toml_create_subset(&config, "bridge");
input_driver_config = potoml_toml_create_subset(&config, "input-driver");
output_driver_config = potoml_toml_create_subset(&config, "output-driver");
input_lib_name = potoml_toml_get_string(bridge_config, "input_driver_path");
output_lib_name = potoml_toml_get_string(bridge_config, "output_driver_path");
if(!input_lib_name || !output_lib_name) {
fprintf(stderr, "Could not find configuration parameters for input and output drivers path\n");
return -1;
}
printf("trx-bridge: opening input library %s\n", input_lib_name);
input_lib_handle = dlopen(input_lib_name, RTLD_NOW);
if(!input_lib_handle) {
fputs(dlerror(), stderr);
fputs("\n", stderr);
return -1;
}
// NULL is a possible return value, so test errors using `dlerror`
input_lib_init = dlsym(input_lib_handle, "trx_driver_init");
if((error = dlerror()) != NULL) {
fputs(error, stderr);
return -1;
}
printf("trx-bridge: opening output library %s\n", output_lib_name);
output_lib_handle = dlopen(output_lib_name, RTLD_NOW);
if(!output_lib_handle) {
fputs(dlerror(), stderr);
fputs("\n", stderr);
return -1;
}
output_lib_init = dlsym(output_lib_handle, "trx_driver_init");
if((error = dlerror()) != NULL) {
fputs(error, stderr);
return -1;
}
// Set required parameters, and nothing more
printf("trx-bridge: setting driver configuration directory to %s\n", driver_config_dir);
input_trx_state.path = driver_config_dir;
input_trx_state.trx_api_version = 15;
input_trx_state.trx_get_param_string = &bridge_trx_input_get_param_string;
input_trx_state.trx_get_param_double = &bridge_trx_input_get_param_double;
output_trx_state.trx_api_version = 15;
output_trx_state.trx_get_param_string = &bridge_trx_output_get_param_string;
output_trx_state.trx_get_param_double = &bridge_trx_output_get_param_double;
printf("trx-bridge: initializing drivers\n");
(*input_lib_init)(&input_trx_state);
(*output_lib_init)(&output_trx_state);
dlclose(input_lib_handle);
dlclose(output_lib_handle);
potoml_toml_subset_free(bridge_config);
potoml_toml_subset_free(input_driver_config);
potoml_toml_subset_free(output_driver_config);
potoml_toml_free(&config);
free((void *) bridge_config_path);
free((void *) driver_config_dir);
return 0;
}
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