blob: e6d7945a3b1e4eb5d10bea9debcab2f2bf23fe20 [file] [log] [blame]
suhasgrao76e8f8c2017-07-12 16:24:33 +05301#ifdef BAL_STUB
2#include <stdlib.h>
3#include <stdio.h>
4#include <string.h>
5#include <signal.h>
6#include "bal_stub.h"
7#include "bal_msg_type.grpc-c.h"
8#include "bal_osmsg.grpc-c.h"
9#include "bal_model_ids.grpc-c.h"
10#include "bal_obj.grpc-c.h"
11#include "bal_model_types.grpc-c.h"
12#include "bal_errno.grpc-c.h"
13#include "bal_indications.grpc-c.h"
14#include "bal.grpc-c.h"
15
16void *stub_thread(void *v)
17{
18 int status;
19 grpc_c_client_t *client = grpc_c_client_init("172.24.150.114:60001", "bal_client", NULL);
20 pthread_mutex_lock(&lock);
21 pthread_cond_wait(&cv, &lock);
22 while(NULL != shared_queue->front)
23 {
24 BalObjId prevObjType;
25 struct QNode *front = deQueue(shared_queue);
26 /* prepare and send rpc response */
27 BalIndications balIndCfg;
28 memset(&balIndCfg, 0, sizeof(BalIndications));
29 bal_indications__init(&balIndCfg);
30 BalObjInd bal_obj_ind;
31 memset(&bal_obj_ind, 0, sizeof(BalObjInd));
32 bal_obj_ind__init(&bal_obj_ind);
33 balIndCfg.u_case = BAL_INDICATIONS__U_BAL_OBJ_INFO;
34 balIndCfg.balobjinfo = &bal_obj_ind;
35 balIndCfg.balobjinfo->has_objtype = 1;
36 balIndCfg.balobjinfo->objtype = front->obj_type;
37 balIndCfg.balobjinfo->has_status = 1;
38 balIndCfg.balobjinfo->status = front->status;
39 char keystr;
40 balIndCfg.balobjinfo->keystr = &keystr;
41 switch(front->obj_type)
42 {
43 case BAL_OBJ_ID__BAL_OBJ_ID_ACCESS_TERMINAL:
44 {
45 printf("***************************************************\n");
46 printf("Successful Indication sent for ACCESS_TERMINAL\n");
47 printf("***************************************************\n");
48 balIndCfg.balobjinfo->u_case = BAL_OBJ_IND__U__NOT_SET;
49 prevObjType = front->obj_type;
50 }
51 break;
52 case BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE:
53 {
54 printf("***************************************************\n");
55 printf("Successful Indication sent for PON INTERFACE UP\n");
56 printf("***************************************************\n");
57 balIndCfg.balobjinfo->u_case = BAL_OBJ_IND__U__NOT_SET;
58 prevObjType = front->obj_type;
59 }
60 break;
61 case BAL_OBJ_ID__BAL_OBJ_ID_SUBSCRIBER_TERMINAL:
62 {
suhasgrao76e8f8c2017-07-12 16:24:33 +053063 balIndCfg.balobjinfo->u_case = BAL_OBJ_IND__U_ONU_DISCOVERY_INFO;
suhasgrao17d65922017-07-13 16:55:29 +053064 BalSubscriberTerminalCfg onudiscoveryinfo;
65 memset(&onudiscoveryinfo, 0, sizeof(BalSubscriberTerminalCfg));
66 bal_subscriber_terminal_cfg__init(&onudiscoveryinfo);
67 balIndCfg.balobjinfo->onudiscoveryinfo = &onudiscoveryinfo;
68
69 BalSubscriberTerminalKey subTermKey;
70 memset(&subTermKey, 0, sizeof(BalSubscriberTerminalKey));
71 bal_subscriber_terminal_key__init(&subTermKey);
72 balIndCfg.balobjinfo->onudiscoveryinfo->key = &subTermKey;
73 balIndCfg.balobjinfo->onudiscoveryinfo->key->has_sub_term_id = 1;
74 balIndCfg.balobjinfo->onudiscoveryinfo->key->sub_term_id = 65535;
75 balIndCfg.balobjinfo->onudiscoveryinfo->key->has_intf_id = 1;
76 balIndCfg.balobjinfo->onudiscoveryinfo->key->intf_id = 0;
77
78 BalSubscriberTerminalCfgData subTermCfgData;
79 memset(&subTermCfgData, 0, sizeof(BalSubscriberTerminalCfgData));
80 bal_subscriber_terminal_cfg_data__init(&subTermCfgData);
81 balIndCfg.balobjinfo->onudiscoveryinfo->data = &subTermCfgData;
suhasgrao76e8f8c2017-07-12 16:24:33 +053082 if(BAL_OBJ_ID__BAL_OBJ_ID_INTERFACE == prevObjType)
83 {
suhasgrao17d65922017-07-13 16:55:29 +053084 balIndCfg.balobjinfo->onudiscoveryinfo->data->has_admin_state = 1;
85 balIndCfg.balobjinfo->onudiscoveryinfo->data->admin_state = BAL_STATE__BAL_STATE_DOWN;
86 balIndCfg.balobjinfo->onudiscoveryinfo->data->has_oper_status = 1;
87 balIndCfg.balobjinfo->onudiscoveryinfo->data->oper_status = BAL_STATUS__BAL_STATUS_DOWN;
suhasgrao76e8f8c2017-07-12 16:24:33 +053088 printf("\n***************************************************\n");
89 printf("Sending ONU discovery message\n");
90 printf("***************************************************\n");
91 }
92 else
93 {
suhasgrao17d65922017-07-13 16:55:29 +053094 balIndCfg.balobjinfo->onudiscoveryinfo->data->has_admin_state = 1;
95 balIndCfg.balobjinfo->onudiscoveryinfo->data->admin_state = BAL_STATE__BAL_STATE_UP;
96 balIndCfg.balobjinfo->onudiscoveryinfo->data->has_oper_status = 1;
97 balIndCfg.balobjinfo->onudiscoveryinfo->data->oper_status = BAL_STATUS__BAL_STATUS_UP;
suhasgrao76e8f8c2017-07-12 16:24:33 +053098 printf("***************************************************\n");
99 printf("ONU Activation Successful\n");
100 printf("***************************************************\n");
101 }
suhasgrao17d65922017-07-13 16:55:29 +0530102 BalSerialNumber serial_number;
103 memset(&serial_number, 0, sizeof(BalSerialNumber));
104 bal_serial_number__init(&serial_number);
105 balIndCfg.balobjinfo->onudiscoveryinfo->data->serial_number = &serial_number;
106 char vendor_id[20];
107 memset(&vendor_id, 0, 20);
108 strcpy(vendor_id,"4252434D");
109 balIndCfg.balobjinfo->onudiscoveryinfo->data->serial_number->vendor_id = vendor_id;
110 char vendor_specific[20];
111 memset(&vendor_specific, 0, 20);
112 strcpy(vendor_specific,"12345678");
113 balIndCfg.balobjinfo->onudiscoveryinfo->data->serial_number->vendor_specific = vendor_specific;
114
suhasgrao76e8f8c2017-07-12 16:24:33 +0530115 prevObjType = front->obj_type;
116 }
117 break;
118 case BAL_OBJ_ID__BAL_OBJ_ID_PACKET:
119 {
120 balIndCfg.balobjinfo->u_case = BAL_OBJ_IND__U_PKT_DATA;
121 }
122 break;
123 default:
124 {
125 balIndCfg.balobjinfo->u_case = BAL_OBJ_IND__U__NOT_SET;
126 prevObjType = front->obj_type;
127 }
128 break;
129 }
130 BalErr *output;
131 status = bal_ind__bal_ind_info(client, NULL, &balIndCfg, &output, NULL, 0);
132 free(front);
133 pthread_mutex_unlock(&lock);
134 pthread_mutex_lock(&lock);
135 pthread_cond_wait(&cv, &lock);
136 }
137 return NULL;
138}
139
140void create_stub_thread()
141{
142 pthread_t threadId = 0;
143
144 /* create shared queue */
145 shared_queue = createQueue();
146
147 pthread_create(&threadId, NULL, stub_thread, NULL);
148
149}
150
151/* A utility function to create an empty queue */
152bal_queue *createQueue()
153{
154 shared_queue = (struct Queue*)malloc(sizeof(struct Queue));
155 shared_queue->front = shared_queue->rear = NULL;
156 return shared_queue;
157}
158
159/* A utility function to create a new linked list node */
160struct QNode* newNode(int objKey, int status)
161{
162 struct QNode *temp = (struct QNode*)malloc(sizeof(struct QNode));
163 temp->obj_type = objKey;
164 temp->status = status;
165 temp->next = NULL;
166 return temp;
167}
168
169/* The function to add data to shared_queue - Add end of the queue */
170void enQueue(int objKey, int status)
171{
172 /* Create a new LL node */
173 struct QNode *temp = newNode(objKey, status);
174
175 /* If queue is empty, then new node is front and rear both */
176 if (shared_queue->rear == NULL)
177 {
178 shared_queue->front = shared_queue->rear = temp;
179 return;
180 }
181
182 /* Add the new node at the end of queue and change rear */
183 shared_queue->rear->next = temp;
184 shared_queue->rear = temp;
185}
186
187/* Function to remove data from shared_queue - FIFO */
188struct QNode *deQueue()
189{
190 /* If queue is empty, return NULL */
191 if (shared_queue->front == NULL)
192 {
193 return NULL;
194 }
195
196 /* Store previous front and move front one node ahead */
197 struct QNode *temp = shared_queue->front;
198 shared_queue->front = shared_queue->front->next;
199
200 /* If front becomes NULL, then change rear also as NULL */
201 if (shared_queue->front == NULL)
202 {
203 shared_queue->rear = NULL;
204 }
205
206 return temp;
207}
208
209#endif