summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--kiro-client.c205
-rw-r--r--kiro-client.h87
3 files changed, 297 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 5505df9..26e4da3 100644
--- a/Makefile
+++ b/Makefile
@@ -5,16 +5,19 @@ LDFLAGS= -lrdmacm -libverbs -lpthread $(shell pkg-config --libs gobject-2.0)
all: base
-base: kiro-trb.o
+base: kiro-trb.o kiro-client.o
kiro-cbr.o: kiro-trb.c kiro-trb.h
$(CC) $(CFLAGS) $(LDFLAGS) -c kiro-trb.c -o kiro-trb.o
+kiro-client.o: kiro-client.c kiro-client.h
+ $(CC) $(CFLAGS) $(LDFLAGS) -c kiro-client.c -o kiro-client.o
+
test-trb: test
test: kiro-trb.o test.c
- $(CC) $(CFLAGS) $(LDFLAGS) test.c kiro-trb.o -o test-tbr
+ $(CC) $(CFLAGS) $(LDFLAGS) test.c kiro-trb.o -o test-trb
clean:
diff --git a/kiro-client.c b/kiro-client.c
new file mode 100644
index 0000000..9fa15ac
--- /dev/null
+++ b/kiro-client.c
@@ -0,0 +1,205 @@
+/* Copyright (C) 2014 Timo Dritschler <timo.dritschler@kit.edu>
+ (Karlsruhe Institute of Technology)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License along
+ with this library; if not, write to the Free Software Foundation, Inc., 51
+ Franklin St, Fifth Floor, Boston, MA 02110, USA
+*/
+
+/**
+ * SECTION: kiro-client
+ * @Short_description: KIRO RDMA Client / Consumer
+ * @Title: KiroClient
+ *
+ * KiroClient implements the client / active / consumer side of the the RDMA
+ * Communication Channel. It uses a KIRO-CLIENT to manage data read from the Server.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <rdma/rdma_verbs.h>
+#include <glib.h>
+#include "kiro-client.h"
+#include "kiro-rdma.h"
+
+
+/*
+ * Definition of 'private' structures and members and macro to access them
+ */
+
+#define KIRO_CLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), KIRO_TYPE_CLIENT, KiroClientPrivate))
+
+struct _KiroClientPrivate {
+
+ /* Properties */
+ // PLACEHOLDER //
+
+ /* 'Real' private structures */
+ /* (Not accessible by properties) */
+ struct rdma_event_channel *ec; // Main Event Channel
+ struct rdma_cm_id *conn; // Connection to the Server
+
+
+};
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (KiroClient, kiro_client, G_TYPE_OBJECT);
+
+
+static void kiro_client_init (KiroClient *self)
+{
+ KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE(self);
+ memset(priv, 0, sizeof(&priv));
+}
+
+static void
+kiro_client_finalize (GObject *object)
+{
+ //PASS
+}
+
+static void
+kiro_client_class_init (KiroClientClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ gobject_class->finalize = kiro_client_finalize;
+}
+
+
+
+int kiro_client_connect (KiroClient *self, char *address, char* port, size_t timeout)
+{
+ KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE(self);
+
+ if(priv->conn)
+ {
+ printf("Already connected to server.\n");
+ return -1;
+ }
+
+ struct rdma_addrinfo hints, *res_addrinfo;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_port_space = RDMA_PS_IB;
+ if(rdma_getaddrinfo(address, port, &hints, &res_addrinfo))
+ {
+ printf("Failed to resolve Route to server %s:%s\n",address, port);
+ return -1;
+ }
+
+ struct ibv_qp_init_attr qp_attr;
+ memset(&qp_attr, 0, sizeof(qp_attr));
+ qp_attr.cap.max_send_wr = 10;
+ qp_attr.cap.max_recv_wr = 10;
+ qp_attr.cap.max_send_sge = 1;
+ qp_attr.cap.max_recv_sge = 1;
+ qp_attr.qp_context = priv->conn;
+ qp_attr.sq_sig_all = 1;
+
+
+ if(rdma_create_ep(&(priv->conn), res_addrinfo, NULL, &qp_attr))
+ {
+ printf("Endpoint creation failed.\n");
+ return -1;
+ }
+
+ struct kiro_connection_context *ctx = (struct kiro_connection_context *)calloc(1,sizeof(struct kiro_connection_context));
+ if(!ctx)
+ {
+ printf("Failed to create connection context.\n");
+ rdma_destroy_ep(priv->conn);
+ return -1;
+ }
+
+ ctx->cf_mr_send = (struct kiro_rdma_mem *)calloc(1, sizeof(struct kiro_rdma_mem));
+ ctx->cf_mr_recv = (struct kiro_rdma_mem *)calloc(1, sizeof(struct kiro_rdma_mem));
+ if(!ctx->cf_mr_recv || !ctx->cf_mr_send)
+ {
+ printf("Failed to allocate Control Flow Memory Container.\n");
+ kiro_destroy_connection_context(ctx);
+ rdma_destroy_ep(priv->conn);
+ return -1;
+ }
+
+ ctx->cf_mr_recv = kiro_create_rdma_memory(priv->conn->pd, sizeof(struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
+ ctx->cf_mr_send = kiro_create_rdma_memory(priv->conn->pd, sizeof(struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
+ if(!ctx->cf_mr_recv || !ctx->cf_mr_send)
+ {
+ printf("Failed to register control message memory.\n");
+ kiro_destroy_connection_context(ctx);
+ rdma_destroy_ep(priv->conn);
+ return -1;
+ }
+ ctx->cf_mr_recv->size = ctx->cf_mr_send->size = sizeof(struct kiro_ctrl_msg);
+ priv->conn->context = ctx;
+
+ if(!rdma_post_recv(priv->conn, priv->conn, ctx->cf_mr_recv->mem, ctx->cf_mr_recv->size, ctx->cf_mr_recv->mr))
+ {
+ printf("Posting preemtive receive for connection failed.\n");
+ kiro_destroy_connection_context(ctx);
+ rdma_destroy_ep(priv->conn);
+ return -1;
+ }
+
+ if(rdma_connect(priv->conn, NULL))
+ {
+ printf("Failed to establish connection to the server.\n");
+ kiro_destroy_connection_context(ctx);
+ rdma_destroy_ep(priv->conn);
+ return -1;
+ }
+
+ priv->ec = rdma_create_event_channel();
+ int oldflags = fcntl (priv->ec->fd, F_GETFL, 0);
+ /* Only change the FD Mode if we were able to get its flags */
+ if (oldflags >= 0) {
+ oldflags |= O_NONBLOCK;
+ /* Store modified flag word in the descriptor. */
+ fcntl (priv->ec->fd, F_SETFL, oldflags);
+ }
+ if(rdma_migrate_id(priv->conn, priv->ec))
+ {
+ printf("Was unable to migrate connection to new Event Channel.\n");
+ rdma_disconnect(priv->conn);
+ kiro_destroy_connection_context(ctx);
+ rdma_destroy_ep(priv->conn);
+ return -1;
+ }
+
+ //ToDo:
+ //Create TRB, request RDMA from Server, call kiro_client_sync, ???, Profit!
+
+
+ printf("Connect to server.\n");
+ return 0;
+
+}
+
+
+
+int kiro_client_sync (KiroClient *self)
+{
+ //PASS
+ return 0;
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/kiro-client.h b/kiro-client.h
new file mode 100644
index 0000000..fb1dccb
--- /dev/null
+++ b/kiro-client.h
@@ -0,0 +1,87 @@
+/* Copyright (C) 2014 Timo Dritschler <timo.dritschler@kit.edu>
+ (Karlsruhe Institute of Technology)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2.1 of the License, or (at your
+ option) any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License along
+ with this library; if not, write to the Free Software Foundation, Inc., 51
+ Franklin St, Fifth Floor, Boston, MA 02110, USA
+*/
+
+/**
+ * SECTION: kiro-client
+ * @Short_description: KIRO RDMA Client / Consumer
+ * @Title: KiroClient
+ *
+ * KiroClient implements the client / active / consumer side of the the RDMA
+ * Communication Channel. It uses a KIRO-CLIENT to manage data read from the Server.
+ */
+
+#ifndef __KIRO_CLIENT_H
+#define __KIRO_CLIENT_H
+
+#include <stdint.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define KIRO_TYPE_CLIENT (kiro_client_get_type())
+#define KIRO_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), KIRO_TYPE_CLIENT, KiroClient))
+#define KIRO_IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), KIRO_TYPE_CLIENT))
+#define KIRO_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), KIRO_TYPE_CLIENT, KiroClientClass))
+#define KIRO_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), KIRO_TYPE_CLIENT))
+#define KIRO_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), KIRO_TYPE_CLIENT, KiroClientClass))
+
+
+typedef struct _KiroClient KiroClient;
+typedef struct _KiroClientClass KiroClientClass;
+typedef struct _KiroClientPrivate KiroClientPrivate;
+
+
+struct _KiroClient {
+
+ GObject parent;
+
+ /*< private >*/
+ KiroClientPrivate *priv;
+};
+
+
+/**
+ * IbvConnectorInterface:
+ *
+ * Base interface for IbvConnectors.
+ */
+
+struct _KiroClientClass {
+
+ GObjectClass parent_class;
+
+};
+
+
+
+/* GObject and GType functions */
+GType kiro_client_get_type (void);
+
+GObject kiro_client_new (void);
+
+/* client functions */
+
+
+int kiro_client_connect (KiroClient *, char *, char*, size_t);
+
+int kiro_client_sync (KiroClient *);
+
+
+G_END_DECLS
+
+#endif //__KIRO_CLIENT_H \ No newline at end of file