Device Simulator Code
diff --git a/device_simulator/device_simulator/Makefile.am b/device_simulator/device_simulator/Makefile.am
new file mode 100644
index 0000000..2708c69
--- /dev/null
+++ b/device_simulator/device_simulator/Makefile.am
@@ -0,0 +1,60 @@
+bin_PROGRAMS = bal_server
+
+.PHONY =
+
+HOSTPROG=yes
+
+DEFS += -DBAL_STUB
+
+bal_server_SOURCES = \
+ bal_server.c \
+ bal_stub.c \
+ grpc-c.h \
+ bal_errno.grpc-c.h bal_indications.grpc-c.h bal_model_types.grpc-c.h \
+ bal_obj.grpc-c.h bal.grpc-c.h bal_model_ids.grpc-c.h \
+ bal_msg_type.grpc-c.h bal_osmsg.grpc-c.h asfvolt16_driver.h \
+ bal.grpc-c.service.c \
+ bal_errno.grpc-c.c bal_indications.grpc-c.c \
+ bal_model_types.grpc-c.c bal_obj.grpc-c.c \
+ bal_errno.grpc-c.service.c bal_indications.grpc-c.service.c \
+ bal_model_types.grpc-c.service.c bal_obj.grpc-c.service.c \
+ bal.grpc-c.c bal_model_ids.grpc-c.c \
+ bal_msg_type.grpc-c.c bal_osmsg.grpc-c.c \
+ bal_model_ids.grpc-c.service.c \
+ bal_msg_type.grpc-c.service.c bal_osmsg.grpc-c.service.c
+
+replace:
+$(shell find . -type f \( -name '*.h' -o -name '*.c' \) -a -exec sed -i -e 's/bal_obj.proto.h/bal_obj.grpc-c.h/g' {} + )
+$(shell find . -type f \( -name '*.h' -o -name '*.c' \) -a -exec sed -i -e 's/bal_model_types.proto.h/bal_model_types.grpc-c.h/g' {} + )
+$(shell find . -type f \( -name '*.h' -o -name '*.c' \) -a -exec sed -i -e 's/bal_errno.proto.h/bal_errno.grpc-c.h/g' {} + )
+$(shell find . -type f \( -name '*.h' -o -name '*.c' \) -a -exec sed -i -e 's/bal_msg_type.proto.h/bal_msg_type.grpc-c.h/g' {} + )
+$(shell find . -type f \( -name '*.h' -o -name '*.c' \) -a -exec sed -i -e 's/bal_osmsg.proto.h/bal_osmsg.grpc-c.h/g' {} + )
+$(shell find . -type f \( -name '*.h' -o -name '*.c' \) -a -exec sed -i -e 's/bal_model_ids.proto.h/bal_model_ids.grpc-c.h/g' {} + )
+$(shell find . -type f \( -name '*.h' -o -name '*.c' \) -a -exec sed -i -e 's/bal.proto.h/bal.grpc-c.h/g' {} + )
+
+autoGenrate:
+ protoc -I ${srcdir} --grpc-c_out=. --plugin=protoc-gen-grpc-c=../compiler/protoc-gen-grpc-c ${srcdir}/bal_errno.proto ${srcdir}/bal_model_ids.proto ${srcdir}/bal_msg_type.proto ${srcdir}/bal_osmsg.proto ${srcdir}/bal_indications.proto ${srcdir}/bal_model_types.proto ${srcdir}/bal_obj.proto ${srcdir}/bal.proto $(replace)
+
+LDADD = \
+ ../lib/libgrpc-c.la \
+ /usr/local/lib/libgrpc.a \
+ /usr/local/lib/libgpr.a \
+ /usr/local/lib/libprotobuf-c.a \
+ -lssl \
+ -lcrypto \
+ -lz \
+ -lpthread
+
+EXTRA_bal_server_DEPENDENCIES=
+
+LIBS = -lrt -lm
+
+AM_CFLAGS = \
+ -I. \
+ -I${srcdir}/../lib/h/ \
+ -I${srcdir}/../third_party/protobuf-c \
+ -I${srcdir}/../third_party/grpc/include
+
+clean_all: clean
+
+all:bal_server$(EXEEXT)
diff --git a/device_simulator/device_simulator/README.md b/device_simulator/device_simulator/README.md
new file mode 100644
index 0000000..118c254
--- /dev/null
+++ b/device_simulator/device_simulator/README.md
@@ -0,0 +1,85 @@
+GRPC_C INTEGRATION WITH BAL
+
+ This is a executable(bal_server), which will recevie asfvolt16 adapter grpc-c messages and call respective device stub.
+ It will send recevied responses/asynchronous indications from Device stub to Adapter.
+
+GETTING STARTED
+
+prerequisites to install grpc
+ - sudo apt-get install build-essential libxml2-dev libgeos++-dev libpq-dev libbz2-dev libtool automake openssl libssl-dev golang-goprotobuf-dev
+
+
+INSTALLATION
+
+steps to install grpc
+ - Download as zip "grpc", "grpc-c", "protobuf" and "protobuf-c" from "https://github.com/opennetworkinglab/asfvolt16-driver/tree/master/third_party"
+ - place downloaded protobuf folder at grpc/thirdparty
+ - place downloaded protobuf-c folder at grpc-c/thirdparty
+ - cd grpc/thirdparty/protobuf
+ ./autogen.sh
+ ./configure
+ make
+ sudo make install
+ - cd grpc/
+ make
+ sudo make install
+
+steps to install grpc-c
+ - cd grpc-c/thirdparty/protobuf-c
+ ./autogen.sh
+ ./configure
+ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/protobuf
+ export LD_LIBRARY_PATH=/usr/local/lib
+ make
+ sudo make install
+
+Apply grpc-c patch
+ - cd grpc-c/
+ Patch 1:
+ Apply patch in following link for grpc-c/lib - "https://github.com/Juniper/grpc-c/commit/353b40cd920cd749ed6cf71f8df17f1d5cf2c89d"
+ Note:
+ (This patch is having very few changes in two files(grpc-c/lib/client.c, grpc-c/lib/service.c.
+ Download these two files from above link and replace at grpc-c/lib or merge these changes manually.)
+ Patch 2:
+ Apply patch in service.c.patch and client.c.patch
+ cp Makefile.am examples/
+ cp bal_server.c grpc-c/examples/
+ cp bal_stub.c grpc-c/examples/
+ cp bal_stub.h grpc-c/examples/
+ autoreconf --install
+ mkdir build && cd build
+ ../configure
+ make
+ sudo make install
+
+To obtain proto files - Have a repo sync of opencord code base
+ cp opencord/incubator/voltha/voltha/adapters/asfvolt16_olt/protos/* examples/
+
+To autogenerate code from proto files
+ make autoGenrate
+
+Build bal_server
+ make clean_all
+ make V=0
+
+The ultimate executable bal_server can be found under ~/grpc-c/build/examples/.libs/
+
+USAGE
+ ./bal_server test
+
+CONTRIBUTING
+ <TBD>
+
+VERSIONING
+ <TBD>
+
+AUTHORS
+ Radisys Adapter Team
+
+Licence
+ <TBD>
+
+Acknowledgments
+ <TBD>
+
+
diff --git a/device_simulator/device_simulator/bal_server.c b/device_simulator/device_simulator/bal_server.c
new file mode 100644
index 0000000..ede77e5
--- /dev/null
+++ b/device_simulator/device_simulator/bal_server.c
@@ -0,0 +1,274 @@
+/*
+ * Copyright (c) 2016, Juniper Networks, Inc.
+ * All rights reserved.
+ */
+
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include "bal_msg_type.grpc-c.h"
+#include "bal_osmsg.grpc-c.h"
+#include "bal_model_ids.grpc-c.h"
+#include "bal_obj.grpc-c.h"
+#include "bal_model_types.grpc-c.h"
+#include "bal_errno.grpc-c.h"
+#include "bal.grpc-c.h"
+
+#ifdef BAL_STUB
+#include "bal_stub.h"
+#endif
+
+static grpc_c_server_t *test_server;
+
+static void sigint_handler (int x) {
+ grpc_c_server_destroy(test_server);
+ exit(0);
+}
+
+/*
+ * This functions gets invoked whenever bal RPC gets called
+ */
+void bal__bal_cfg_get_cb(grpc_c_context_t *context)
+{
+ BalCfg *get_cfg;
+
+ /*
+ * Read incoming message into get_cfg
+ */
+ if (context->gcc_payload) {
+ context->gcc_stream->read(context, (void **)&get_cfg, 0);
+ }
+}
+
+/*
+ * This functions gets invoked whenever bal RPC gets called
+ */
+void bal__bal_cfg_set_cb(grpc_c_context_t *context)
+{
+ BalCfg *set_cfg;
+ BalErr bal_err;
+
+ /*
+ * Read incoming message into set_cfg
+ */
+ if (context->gcc_payload) {
+ context->gcc_stream->read(context, (void **)&set_cfg, 0);
+ }
+
+ /*
+ * send it to BAL
+ */
+
+ bal_err__init(&bal_err);
+
+ bal_err.err= 0;
+
+ /*
+ * Write reply back to the client
+ */
+ if (!context->gcc_stream->write(context, &bal_err, 0)) {
+ } else {
+ printf("Failed to write\n");
+ exit(1);
+ }
+
+ grpc_c_status_t status;
+ status.gcs_code = 0;
+
+ /*
+ * Finish response for RPC
+ */
+ if (context->gcc_stream->finish(context, &status)) {
+ printf("Failed to write status\n");
+ exit(1);
+ }
+
+#ifdef BAL_STUB
+ pthread_mutex_lock(&lock);
+ if(set_cfg->hdr->has_obj_type)
+ {
+ enQueue(set_cfg->hdr->obj_type, BAL_ERRNO__BAL_ERR_OK);
+ switch(set_cfg->hdr->obj_type)
+ {
+ case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL:
+ {
+ printf("\n***************************************************\n");
+ printf("Received Access Terminal Configuration msg\n");
+ printf("***************************************************\n");
+ }
+ break;
+ case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE:
+ {
+ printf("\n***************************************************\n");
+ printf("Received PON Interface Configuration msg\n");
+ printf("***************************************************\n");
+ }
+ break;
+ case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL:
+ {
+ printf("\n*****************************************************\n");
+ printf("Received ONU Activation msg\n");
+ printf("*****************************************************\n");
+ }
+ default:
+ break;
+ }
+ }
+ else
+ {
+ printf("BALSTUB:Cfg Set recevied without object type");
+ }
+ pthread_mutex_unlock(&lock);
+ sleep(2);
+ pthread_cond_signal(&cv);
+ if(BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE == set_cfg->hdr->obj_type)
+ {
+ sleep(5);
+ enQueue(BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL, BAL_ERRNO__BAL_ERR_OK);
+ pthread_cond_signal(&cv);
+ }
+#endif
+}
+
+
+/*
+ * This functions gets invoked whenever bal clear RPC gets called
+ */
+void bal__bal_cfg_clear_cb(grpc_c_context_t *context)
+{
+ BalKey *clear_key;
+
+ /*
+ * Read incoming message into clear_key
+ */
+ if (context->gcc_payload) {
+ context->gcc_stream->read(context, (void **)&clear_key, 0);
+ }
+
+}
+
+
+/*
+ * This functions gets invoked whenever bal Init RPC gets called
+ */
+void bal__bal_api_init_cb(grpc_c_context_t *context)
+{
+ BalInit *bal_init;
+
+ /*
+ * Read incoming message into set_cfg
+ */
+ if (context->gcc_payload) {
+ context->gcc_stream->read(context, (void **)&bal_init, 0);
+ }
+
+}
+
+
+/*
+ * This functions gets invoked whenever bal finish RPC gets called
+ */
+void bal__bal_api_finish_cb(grpc_c_context_t *context)
+{
+#if 0
+ void *finish_init;
+
+ /*
+ * Read incoming message into set_cfg
+ */
+ if (context->gcc_payload) {
+ context->gcc_stream->read(context, (void **)&finish_init);
+ }
+#endif
+}
+
+
+/*
+ * This functions gets invoked whenever bal finish RPC gets called
+ */
+void bal_ind__bal_ind_info_cb(grpc_c_context_t *context)
+{
+#if 0
+ void *finish_init;
+
+ /*
+ * Read incoming message into set_cfg
+ */
+ if (context->gcc_payload) {
+ context->gcc_stream->read(context, (void **)&finish_init);
+ }
+#endif
+}
+
+
+/*
+ * This functions gets invoked whenever bal RPC gets called
+ */
+void bal__bal_omci_msg_cb(grpc_c_context_t *context)
+{
+ char *omci_msg;
+
+ /*
+ * Read incoming message into omci_msg
+ */
+ if (context->gcc_payload) {
+ context->gcc_stream->read(context, (void **)&omci_msg, 0);
+ }
+}
+
+/*
+ * Takes socket path as argument
+ */
+int main (int argc, char **argv)
+{
+ int i = 0;
+ grpc_c_server_t *server = NULL;
+
+ printf("*************\n");
+ printf("BAL STUB\n");
+ printf("*************\n");
+ if (argc < 2) {
+ fprintf(stderr, "Missing socket path argument\n");
+ exit(1);
+ }
+
+ signal(SIGINT, sigint_handler);
+ /*
+ * Initialize grpc-c library to be used with vanilla gRPC
+ */
+ grpc_c_init(GRPC_THREADS, NULL);
+
+ /*
+ * Create server object
+ */
+ test_server = grpc_c_server_create("172.24.150.117:50060");
+ if (test_server == NULL) {
+ printf("Failed to create server\n");
+ exit(1);
+ }
+
+ /*
+ * Initialize greeter service
+ */
+ printf("\nCreating a test server\n");
+ bal__service_init(test_server);
+
+ /*
+ * Start server
+ */
+ grpc_c_server_start(test_server);
+
+#ifdef BAL_STUB
+ printf("\nCreating a stub thread\n");
+ create_stub_thread();
+#endif
+
+ /*
+ * Blocks server to wait to completion
+ */
+ grpc_c_server_wait(test_server);
+
+ bal__service_init(server);
+
+}
diff --git a/device_simulator/device_simulator/bal_stub.c b/device_simulator/device_simulator/bal_stub.c
new file mode 100644
index 0000000..adebd0a
--- /dev/null
+++ b/device_simulator/device_simulator/bal_stub.c
@@ -0,0 +1,194 @@
+#ifdef BAL_STUB
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include "bal_stub.h"
+#include "bal_msg_type.grpc-c.h"
+#include "bal_osmsg.grpc-c.h"
+#include "bal_model_ids.grpc-c.h"
+#include "bal_obj.grpc-c.h"
+#include "bal_model_types.grpc-c.h"
+#include "bal_errno.grpc-c.h"
+#include "bal_indications.grpc-c.h"
+#include "bal.grpc-c.h"
+
+void *stub_thread(void *v)
+{
+ int status;
+ grpc_c_client_t *client = grpc_c_client_init("172.24.150.114:60001", "bal_client", NULL);
+ pthread_mutex_lock(&lock);
+ pthread_cond_wait(&cv, &lock);
+ while(NULL != shared_queue->front)
+ {
+ BalObjId prevObjType;
+ struct QNode *front = deQueue(shared_queue);
+ /* prepare and send rpc response */
+ BalIndications balIndCfg;
+ memset(&balIndCfg, 0, sizeof(BalIndications));
+ bal_indications__init(&balIndCfg);
+ BalObjInd bal_obj_ind;
+ memset(&bal_obj_ind, 0, sizeof(BalObjInd));
+ bal_obj_ind__init(&bal_obj_ind);
+ balIndCfg.u_case = BAL_INDICATIONS__U_BAL_OBJ_INFO;
+ balIndCfg.balobjinfo = &bal_obj_ind;
+ balIndCfg.balobjinfo->has_objtype = 1;
+ balIndCfg.balobjinfo->objtype = front->obj_type;
+ balIndCfg.balobjinfo->has_status = 1;
+ balIndCfg.balobjinfo->status = front->status;
+ char keystr;
+ balIndCfg.balobjinfo->keystr = &keystr;
+ switch(front->obj_type)
+ {
+ case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL:
+ {
+ printf("***************************************************\n");
+ printf("Successful Indication sent for ACCESS_TERMINAL\n");
+ printf("***************************************************\n");
+ balIndCfg.balobjinfo->u_case = BAL_OBJ_IND__U__NOT_SET;
+ prevObjType = front->obj_type;
+ }
+ break;
+ case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE:
+ {
+ printf("***************************************************\n");
+ printf("Successful Indication sent for PON INTERFACE UP\n");
+ printf("***************************************************\n");
+ balIndCfg.balobjinfo->u_case = BAL_OBJ_IND__U__NOT_SET;
+ prevObjType = front->obj_type;
+ }
+ break;
+ case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL:
+ {
+ BalOnuDiscoveryInfo onuDiscoveryInfo;
+ memset(&onuDiscoveryInfo, 0, sizeof(BalOnuDiscoveryInfo));
+ bal_onu_discovery_info__init(&onuDiscoveryInfo);
+ balIndCfg.balobjinfo->onudiscoveryinfo = &onuDiscoveryInfo;
+ balIndCfg.balobjinfo->u_case = BAL_OBJ_IND__U_ONU_DISCOVERY_INFO;
+ BalSerialNumber serial_number;
+ memset(&serial_number, 0, sizeof(BalSerialNumber));
+ bal_serial_number__init(&serial_number);
+ balIndCfg.balobjinfo->onudiscoveryinfo->serial_number = &serial_number;
+ char vendor_id[20];
+ memset(&vendor_id, 0, 20);
+ strcpy(vendor_id,"4252434D");
+ balIndCfg.balobjinfo->onudiscoveryinfo->serial_number->vendor_id = vendor_id;
+ char vendor_specific[20];
+ memset(&vendor_specific, 0, 20);
+ strcpy(vendor_specific,"12345678");
+ balIndCfg.balobjinfo->onudiscoveryinfo->serial_number->vendor_specific = vendor_specific;
+ if(BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE == prevObjType)
+ {
+ balIndCfg.balobjinfo->onudiscoveryinfo->has_admin_state = 1;
+ balIndCfg.balobjinfo->onudiscoveryinfo->admin_state = BAL_STATE__BAL_STATE_DOWN;
+ balIndCfg.balobjinfo->onudiscoveryinfo->has_oper_status = 1;
+ balIndCfg.balobjinfo->onudiscoveryinfo->oper_status = BAL_STATUS__BAL_STATUS_DOWN;
+ printf("\n***************************************************\n");
+ printf("Sending ONU discovery message\n");
+ printf("***************************************************\n");
+ }
+ else
+ {
+ balIndCfg.balobjinfo->onudiscoveryinfo->has_admin_state = 1;
+ balIndCfg.balobjinfo->onudiscoveryinfo->admin_state = BAL_STATE__BAL_STATE_UP;
+ balIndCfg.balobjinfo->onudiscoveryinfo->has_oper_status = 1;
+ balIndCfg.balobjinfo->onudiscoveryinfo->oper_status = BAL_STATUS__BAL_STATUS_UP;
+ printf("***************************************************\n");
+ printf("ONU Activation Successful\n");
+ printf("***************************************************\n");
+ }
+ prevObjType = front->obj_type;
+ }
+ break;
+ case BAL_OBJ_ID__BAL_OBJ_ID_PACKET:
+ {
+ balIndCfg.balobjinfo->u_case = BAL_OBJ_IND__U_PKT_DATA;
+ }
+ break;
+ default:
+ {
+ balIndCfg.balobjinfo->u_case = BAL_OBJ_IND__U__NOT_SET;
+ prevObjType = front->obj_type;
+ }
+ break;
+ }
+ BalErr *output;
+ status = bal_ind__bal_ind_info(client, NULL, &balIndCfg, &output, NULL, 0);
+ free(front);
+ pthread_mutex_unlock(&lock);
+ pthread_mutex_lock(&lock);
+ pthread_cond_wait(&cv, &lock);
+ }
+ return NULL;
+}
+
+void create_stub_thread()
+{
+ pthread_t threadId = 0;
+
+ /* create shared queue */
+ shared_queue = createQueue();
+
+ pthread_create(&threadId, NULL, stub_thread, NULL);
+
+}
+
+/* A utility function to create an empty queue */
+bal_queue *createQueue()
+{
+ shared_queue = (struct Queue*)malloc(sizeof(struct Queue));
+ shared_queue->front = shared_queue->rear = NULL;
+ return shared_queue;
+}
+
+/* A utility function to create a new linked list node */
+struct QNode* newNode(int objKey, int status)
+{
+ struct QNode *temp = (struct QNode*)malloc(sizeof(struct QNode));
+ temp->obj_type = objKey;
+ temp->status = status;
+ temp->next = NULL;
+ return temp;
+}
+
+/* The function to add data to shared_queue - Add end of the queue */
+void enQueue(int objKey, int status)
+{
+ /* Create a new LL node */
+ struct QNode *temp = newNode(objKey, status);
+
+ /* If queue is empty, then new node is front and rear both */
+ if (shared_queue->rear == NULL)
+ {
+ shared_queue->front = shared_queue->rear = temp;
+ return;
+ }
+
+ /* Add the new node at the end of queue and change rear */
+ shared_queue->rear->next = temp;
+ shared_queue->rear = temp;
+}
+
+/* Function to remove data from shared_queue - FIFO */
+struct QNode *deQueue()
+{
+ /* If queue is empty, return NULL */
+ if (shared_queue->front == NULL)
+ {
+ return NULL;
+ }
+
+ /* Store previous front and move front one node ahead */
+ struct QNode *temp = shared_queue->front;
+ shared_queue->front = shared_queue->front->next;
+
+ /* If front becomes NULL, then change rear also as NULL */
+ if (shared_queue->front == NULL)
+ {
+ shared_queue->rear = NULL;
+ }
+
+ return temp;
+}
+
+#endif
diff --git a/device_simulator/device_simulator/bal_stub.h b/device_simulator/device_simulator/bal_stub.h
new file mode 100644
index 0000000..0bd30de
--- /dev/null
+++ b/device_simulator/device_simulator/bal_stub.h
@@ -0,0 +1,34 @@
+
+/* Global definations */
+pthread_cond_t cv;
+pthread_mutex_t lock;
+
+#define IND_USR_DAT_LEN 8
+#define IND_USR_DAT_VAL "brcmOLT"
+#define BALCLIENT "bal_client"
+#define BALSERVER "bal_server"
+
+/* A linked list (LL) node to store a queue entry */
+struct QNode
+{
+ int obj_type;
+ int status;
+ struct QNode *next;
+};
+
+
+/* The queue, front stores the front node of LL and rear stores ths
+ last node of LL */
+typedef struct Queue
+{
+ struct QNode *front, *rear;
+}bal_queue;
+
+/* shared queue */
+bal_queue *shared_queue;
+
+void create_stub_thread();
+bal_queue *createQueue();
+struct QNode* newNode(int objKey, int status);
+void enQueue(int objKey, int status);
+struct QNode *deQueue();
diff --git a/device_simulator/device_simulator/client.c.patch b/device_simulator/device_simulator/client.c.patch
new file mode 100644
index 0000000..7de4dd1
--- /dev/null
+++ b/device_simulator/device_simulator/client.c.patch
@@ -0,0 +1,37 @@
+*** grpc-c_orig/lib/client.c 2017-07-03 16:52:30.467488835 +0530
+--- grpc-c/lib/client.c 2017-07-12 15:34:28.904950001 +0530
+***************
+*** 134,141 ****
+ }
+
+ bzero(buf, BUFSIZ);
+! snprintf_safe(buf, sizeof(buf), "%s%s", PATH_GRPC_C_DAEMON_SOCK,
+! server_name);
+ if (buf[0] == '\0') {
+ return NULL;
+ }
+--- 134,141 ----
+ }
+
+ bzero(buf, BUFSIZ);
+! /*snprintf_safe(buf, sizeof(buf), "%s%s", PATH_GRPC_C_DAEMON_SOCK, server_name);*/
+! snprintf_safe(buf, sizeof(buf), "%s", server_name);
+ if (buf[0] == '\0') {
+ return NULL;
+ }
+***************
+*** 1039,1049 ****
+--- 1039,1051 ----
+ gpr_timespec tout;
+ grpc_c_context_t *context;
+
++ #if 0
+ if (context == NULL) {
+ gpr_log(GPR_ERROR, "Invalid context pointer provided");
+ rc = GRPC_C_FAIL;
+ goto cleanup;
+ }
++ #endif
+
+ context = gc_client_prepare_ops(client, mdarray, 1, input, NULL,
+ client_streaming, server_streaming, NULL,
diff --git a/device_simulator/device_simulator/service.c.patch b/device_simulator/device_simulator/service.c.patch
new file mode 100644
index 0000000..da8ebd8
--- /dev/null
+++ b/device_simulator/device_simulator/service.c.patch
@@ -0,0 +1,20 @@
+*** grpc-c_orig/lib/service.c 2017-07-03 16:52:38.239488835 +0530
+--- grpc-c/lib/service.c 2017-07-12 15:34:43.408198001 +0530
+***************
+*** 1224,1230 ****
+ return NULL;
+ }
+
+! snprintf_safe(buf, sizeof(buf), "%s%s", PATH_GRPC_C_DAEMON_SOCK, name);
+
+ if (buf[0] == '\0') {
+ return NULL;
+--- 1224,1231 ----
+ return NULL;
+ }
+
+! /*snprintf_safe(buf, sizeof(buf), "%s%s", PATH_GRPC_C_DAEMON_SOCK, name);*/
+! snprintf_safe(buf, sizeof(buf), "%s", name);
+
+ if (buf[0] == '\0') {
+ return NULL;