Initial commit of Admission Control xAPP and E2AP/X2AP definitions
[ric-app/admin.git] / src / X2AP / sgnb_addition_request.cc
1 /*
2 ==================================================================================
3         Copyright (c) 2018-2019 AT&T Intellectual Property.
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================================
17 */
18 /*
19  * ric_indication.h
20  *
21  *  Created on: Aug 14, 2019
22  *      Author: Ashwin Sridharan
23  */
24
25 #include <sgnb_addition_request.hpp>
26
27   
28 sgnb_addition_request::sgnb_addition_request(void){
29   x2ap_pdu_obj = 0;
30   x2ap_pdu_obj = (X2AP_PDU_t * )calloc(1, sizeof(X2AP_PDU_t));
31   assert(x2ap_pdu_obj != 0);
32
33   initMsg = 0;
34   initMsg = (X2InitiatingMessage_t * )calloc(1, sizeof(X2InitiatingMessage_t));
35   assert(initMsg != 0);
36
37   IE_array = 0;
38   IE_array = (SgNBAdditionRequest_IEs_t *)calloc(NUM_SGNB_ADDITION_REQUEST_IES, sizeof(SgNBAdditionRequest_IEs_t));
39   assert(IE_array != 0);
40
41   erab_array = 0;
42   erab_array = (E_RABs_ToBeAdded_SgNBAddReq_ItemIEs_t * ) calloc(INITIAL_SIZE, sizeof(E_RABs_ToBeAdded_SgNBAddReq_ItemIEs_t));
43   assert(erab_array != 0);
44   erab_array_size = INITIAL_SIZE;
45
46   erab_sgnb_present_array = 0;
47   erab_sgnb_present_array = (E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPpresent_t *) calloc(INITIAL_SIZE, sizeof(E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPpresent_t));
48   assert(erab_sgnb_present_array != 0);
49   erab_sgnb_present_array_size = INITIAL_SIZE;
50   
51   erab_sgnb_notpresent_array = 0;
52   erab_sgnb_notpresent_array = (E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPnotpresent_t *) calloc(INITIAL_SIZE, sizeof(E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPnotpresent_t));
53   assert(erab_sgnb_notpresent_array != 0);
54   erab_sgnb_notpresent_array_size = INITIAL_SIZE;
55   
56   x2ap_pdu_obj->present = X2AP_PDU_PR_initiatingMessage;
57   x2ap_pdu_obj->choice.initiatingMessage = initMsg;
58
59   SgNBAdditionRequest_t * ric_indication = &(initMsg->value.choice.SgNBAdditionRequest);
60   for(int i = 0; i < NUM_SGNB_ADDITION_REQUEST_IES; i++){
61     ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[i]));
62   }
63
64   
65 };
66
67
68 sgnb_addition_request::~sgnb_addition_request(void){
69
70   mdclog_write(MDCLOG_INFO, "Freeing X2AP SgNB Addition Request object memory");
71
72   E_RABs_ToBeAdded_SgNBAddReqList_t  * erabs_toadd_list = &(IE_array[7].value.choice. E_RABs_ToBeAdded_SgNBAddReqList);
73   for(int i = 0; i < erabs_toadd_list->list.size; i++){
74     erabs_toadd_list->list.array[i] = 0;
75   }
76
77   
78   if (erabs_toadd_list->list.size > 0){
79     free(erabs_toadd_list->list.array);
80     erabs_toadd_list->list.array = 0;
81     erabs_toadd_list->list.size = 0;
82     erabs_toadd_list->list.count= 0;
83   }
84   
85   free(erab_sgnb_present_array);
86   
87   free(erab_sgnb_notpresent_array);
88   
89   free(erab_array);
90
91   // Free BitRate allocation if any
92   SgNBAdditionRequest_IEs_t *ies_sgnb_addition_req;
93   ies_sgnb_addition_req= &IE_array[3];
94   UEAggregateMaximumBitRate_t * ue_rates = &(ies_sgnb_addition_req->value.choice.UEAggregateMaximumBitRate);
95
96   // clear buffer if previously allocated
97   if (ue_rates->uEaggregateMaximumBitRateDownlink.size > 0){
98     ue_rates->uEaggregateMaximumBitRateDownlink.size = 0;
99     free(ue_rates->uEaggregateMaximumBitRateDownlink.buf);
100   }
101
102   
103   if (ue_rates->uEaggregateMaximumBitRateUplink.size > 0){
104     ue_rates->uEaggregateMaximumBitRateUplink.size = 0;
105     free(ue_rates->uEaggregateMaximumBitRateUplink.buf);
106   }
107   
108   SgNBAdditionRequest_t *sgnb_addition  = &(initMsg->value.choice.SgNBAdditionRequest);
109   for(int i = 0; i < sgnb_addition->protocolIEs.list.size; i++){
110     sgnb_addition->protocolIEs.list.array[i] = 0;
111   }
112
113
114   if (sgnb_addition->protocolIEs.list.size > 0){
115     free(sgnb_addition->protocolIEs.list.array);
116     sgnb_addition->protocolIEs.list.array = 0;
117     sgnb_addition->protocolIEs.list.size = 0;
118   }
119   free(IE_array);
120
121   free(initMsg);
122   
123   x2ap_pdu_obj->choice.initiatingMessage = 0;
124   ASN_STRUCT_FREE(asn_DEF_X2AP_PDU, x2ap_pdu_obj);
125   mdclog_write(MDCLOG_INFO, "Freed X2AP SgNB Addition Request object mempory");
126 }
127
128
129
130 bool sgnb_addition_request::encode_sgnb_addition_request(unsigned char *buf, size_t *size, sgnb_addition_helper & dinput){
131
132   initMsg->procedureCode = ProcedureCode_id_sgNBAdditionPreparation;
133   initMsg->criticality = Criticality_ignore;
134   initMsg->value.present = X2InitiatingMessage__value_PR_SgNBAdditionRequest;
135
136   bool res;
137   res = set_fields(initMsg, dinput);
138   if (!res){
139     return false;
140   }
141   
142   int ret_constr = asn_check_constraints(&asn_DEF_X2AP_PDU, x2ap_pdu_obj, errbuf, &errbuf_len);
143   if(ret_constr){
144     error_string.assign(&errbuf[0], errbuf_len);
145     error_string = "Error encoding X2AP Sgnb Addition Request  message. Reason = " + error_string;
146     return false;
147   }
148
149   //xer_fprint(stdout, &asn_DEF_X2AP_PDU, x2ap_pdu_obj);
150   
151   asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_X2AP_PDU, x2ap_pdu_obj, buf, *size);
152   if(retval.encoded == -1){
153     error_string.assign(strerror(errno));
154     return false;
155   }
156
157   else {
158     if(*size < retval.encoded){
159       std::stringstream ss;
160       ss  <<"Error encoding SgNB Addition Request definition. Reason =  encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl;
161       error_string = ss.str();
162       return false;
163     }
164   }
165
166   *size = retval.encoded;
167   return true;
168
169 }
170
171
172 bool sgnb_addition_request::set_fields(X2InitiatingMessage_t * init_msg, sgnb_addition_helper &dinput){
173
174   unsigned ie_index = 0;
175   
176   if (initMsg == 0){
177     error_string = "Invalid reference for X2AP Sgnb Addition Request message in set_fields";
178     return false;
179   }
180
181   
182   SgNBAdditionRequest_IEs_t *ies_sgnb_addition_req;
183
184   ie_index = 0;
185   ies_sgnb_addition_req= &IE_array[ie_index];
186   ies_sgnb_addition_req->criticality = Criticality_reject;
187   ies_sgnb_addition_req->id = ProtocolIE_ID_id_MeNB_UE_X2AP_ID;
188   ies_sgnb_addition_req->value.present = SgNBAdditionRequest_IEs__value_PR_UE_X2AP_ID;
189   ies_sgnb_addition_req->value.choice.UE_X2AP_ID = dinput.menb_ue_x2ap_id;
190   
191
192   ie_index = 1;
193   ies_sgnb_addition_req= &IE_array[ie_index];
194   ies_sgnb_addition_req->criticality = Criticality_reject;
195   ies_sgnb_addition_req->id = ProtocolIE_ID_id_NRUESecurityCapabilities;
196   ies_sgnb_addition_req->value.present = SgNBAdditionRequest_IEs__value_PR_NRUESecurityCapabilities;
197   NRUESecurityCapabilities_t * nrue_sec = &(ies_sgnb_addition_req->value.choice.NRUESecurityCapabilities);
198
199   nrue_sec->nRencryptionAlgorithms.buf =dinput.encryption_algs;
200   nrue_sec->nRencryptionAlgorithms.size = dinput.encryption_algs_size;
201   nrue_sec->nRencryptionAlgorithms.bits_unused = dinput.encryption_algs_unused;
202
203   nrue_sec->nRintegrityProtectionAlgorithms.buf = dinput.integrity_protection_algs;
204   nrue_sec->nRintegrityProtectionAlgorithms.size = dinput.integrity_protection_algs_size;
205   nrue_sec->nRintegrityProtectionAlgorithms.bits_unused = dinput.integrity_protection_algs_unused;
206
207   ie_index = 2;
208   ies_sgnb_addition_req= &IE_array[ie_index];
209   ies_sgnb_addition_req->criticality = Criticality_reject;
210   ies_sgnb_addition_req->id = ProtocolIE_ID_id_SgNBSecurityKey ;
211   ies_sgnb_addition_req->value.present = SgNBAdditionRequest_IEs__value_PR_SgNBSecurityKey;
212   SgNBSecurityKey_t * sgnb_sec = &(ies_sgnb_addition_req->value.choice.SgNBSecurityKey);
213
214   sgnb_sec->buf = dinput.sgnb_security_key;
215   sgnb_sec->size = dinput.sgnb_security_key_size;
216   sgnb_sec->bits_unused = dinput.sgnb_security_key_unused;
217
218   ie_index = 3;
219   ies_sgnb_addition_req= &IE_array[ie_index];
220   ies_sgnb_addition_req->criticality = Criticality_reject;
221   ies_sgnb_addition_req->id = ProtocolIE_ID_id_SgNBUEAggregateMaximumBitRate;
222   ies_sgnb_addition_req->value.present = SgNBAdditionRequest_IEs__value_PR_UEAggregateMaximumBitRate;
223   UEAggregateMaximumBitRate_t * ue_rates = &(ies_sgnb_addition_req->value.choice.UEAggregateMaximumBitRate);
224
225   // clear buffer if previously allocated
226   if (ue_rates->uEaggregateMaximumBitRateDownlink.size > 0){
227     ue_rates->uEaggregateMaximumBitRateDownlink.size = 0;
228     free(ue_rates->uEaggregateMaximumBitRateDownlink.buf);
229   }
230   
231   if (ue_rates->uEaggregateMaximumBitRateUplink.size > 0){
232     ue_rates->uEaggregateMaximumBitRateUplink.size = 0;
233     free(ue_rates->uEaggregateMaximumBitRateUplink.buf);
234   }
235   
236   /* To do : Fix malloc done by this operation */
237   asn_long2INTEGER(&(ue_rates->uEaggregateMaximumBitRateDownlink), dinput.bit_rate_max_dn);
238   asn_long2INTEGER(&(ue_rates->uEaggregateMaximumBitRateUplink),   dinput.bit_rate_max_up);
239
240   
241   ie_index = 4;
242   ies_sgnb_addition_req= &IE_array[ie_index];
243   ies_sgnb_addition_req->criticality = Criticality_reject;
244   ies_sgnb_addition_req->id =  ProtocolIE_ID_id_MeNBtoSgNBContainer  ;
245   ies_sgnb_addition_req->value.present =  SgNBAdditionRequest_IEs__value_PR_MeNBtoSgNBContainer;
246   MeNBtoSgNBContainer_t * metosg_container = &(ies_sgnb_addition_req->value.choice.MeNBtoSgNBContainer);
247
248   metosg_container->buf = dinput.menb_sgnb_container;
249   metosg_container->size = dinput.menb_sgnb_container_size;
250
251
252   ie_index = 5;
253   ies_sgnb_addition_req= &IE_array[ie_index];
254   ies_sgnb_addition_req->criticality = Criticality_reject;
255   ies_sgnb_addition_req->id = ProtocolIE_ID_id_MeNBCell_ID ;
256   ies_sgnb_addition_req->value.present = SgNBAdditionRequest_IEs__value_PR_ECGI;
257   ECGI_t * menb_ecgi = &(ies_sgnb_addition_req->value.choice.ECGI);
258   
259   menb_ecgi->pLMN_Identity.buf = dinput.plmn_identity;
260   menb_ecgi->pLMN_Identity.size = dinput.plmn_identity_size;
261   
262   menb_ecgi->eUTRANcellIdentifier.buf = dinput.eutran_identifier;
263   menb_ecgi->eUTRANcellIdentifier.size = dinput.eutran_identifier_size;
264   menb_ecgi->eUTRANcellIdentifier.bits_unused = 4;
265
266   ie_index = 6;
267   ies_sgnb_addition_req = &IE_array[ie_index];
268   ies_sgnb_addition_req->criticality = Criticality_reject;
269   ies_sgnb_addition_req->id =  ProtocolIE_ID_id_SubscriberProfileIDforRFP;
270   ies_sgnb_addition_req->value.present = SgNBAdditionRequest_IEs__value_PR_SubscriberProfileIDforRFP;
271   ies_sgnb_addition_req->value.choice.SubscriberProfileIDforRFP = dinput.subscriber_profile_id;
272   
273   // add erab-tobe-added list
274   ie_index = 7;
275   ies_sgnb_addition_req= &IE_array[ie_index];
276   ies_sgnb_addition_req->criticality = Criticality_reject;
277   ies_sgnb_addition_req->id =  ProtocolIE_ID_id_E_RABs_ToBeAdded_SgNBAddReqList;
278   ies_sgnb_addition_req->value.present = SgNBAdditionRequest_IEs__value_PR_E_RABs_ToBeAdded_SgNBAddReqList;
279   E_RABs_ToBeAdded_SgNBAddReqList_t  * erabs_toadd_list = &(ies_sgnb_addition_req->value.choice.E_RABs_ToBeAdded_SgNBAddReqList);
280   
281   std::vector<struct erab_item> * ref_erab_input  = &(dinput.erab_list);
282   erabs_toadd_list->list.count = 0;
283   
284   // resize ?
285   if (ref_erab_input->size() >= erab_array_size){
286     erab_array_size = 2 * ref_erab_input->size();
287
288     E_RABs_ToBeAdded_SgNBAddReq_ItemIEs_t * new_ref = 0;
289     new_ref = (E_RABs_ToBeAdded_SgNBAddReq_ItemIEs_t *)realloc(erab_array, erab_array_size * sizeof(E_RABs_ToBeAdded_SgNBAddReq_Item_t));
290     assert(new_ref != 0);
291     erab_array = new_ref;
292     
293     erab_sgnb_present_array_size = 2 * ref_erab_input->size();
294     E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPpresent_t  * new_present = 0;
295     new_present = (E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPpresent_t  *)realloc(erab_sgnb_present_array, erab_sgnb_present_array_size * sizeof(E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPpresent_t ));
296     assert(new_present != 0);
297     erab_sgnb_present_array = new_present;
298
299     erab_sgnb_notpresent_array_size = 2 * ref_erab_input->size();
300     E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPnotpresent_t  * new_notpresent = 0;
301     new_notpresent = (E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPnotpresent_t  *)realloc(erab_sgnb_notpresent_array, erab_sgnb_notpresent_array_size * sizeof(E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPnotpresent_t ));
302     assert(new_notpresent != 0);
303     erab_sgnb_notpresent_array = new_notpresent;
304
305     
306   }
307   
308   int sgnb_present_index = 0;
309   int sgnb_notpresent_index = 0;
310   
311   for(unsigned int i = 0; i < ref_erab_input->size(); i++){
312
313
314     erab_array[i].id = ProtocolIE_ID_id_E_RABs_ToBeAdded_SgNBAddReq_Item ;
315     erab_array[i].criticality = Criticality_reject;
316     erab_array[i].value.present =  E_RABs_ToBeAdded_SgNBAddReq_ItemIEs__value_PR_E_RABs_ToBeAdded_SgNBAddReq_Item;
317     E_RABs_ToBeAdded_SgNBAddReq_Item_t * erab_item = &(erab_array[i].value.choice.E_RABs_ToBeAdded_SgNBAddReq_Item);
318     
319     erab_item->e_RAB_ID = (*ref_erab_input)[i].erab_id;
320     erab_item->drb_ID = (*ref_erab_input)[i].drb_id;
321
322     erab_item->en_DC_ResourceConfiguration.pDCPatSgNB =  (*ref_erab_input)[i].pdcp_at_sgnb;
323     erab_item->en_DC_ResourceConfiguration.mCGresources =  (*ref_erab_input)[i].mcg_resources;
324     erab_item->en_DC_ResourceConfiguration.sCGresources =  (*ref_erab_input)[i].scg_resources;
325
326     erab_item->resource_configuration.present = (E_RABs_ToBeAdded_SgNBAddReq_Item__resource_configuration_PR)(*ref_erab_input)[i].sgnb_pdcp_present;
327     
328     
329     if( erab_item->resource_configuration.present == E_RABs_ToBeAdded_SgNBAddReq_Item__resource_configuration_PR_sgNBPDCPpresent){
330       erab_sgnb_present_array[sgnb_present_index].full_E_RAB_Level_QoS_Parameters.qCI = (*ref_erab_input)[i].sgnb_item.qci;
331       erab_sgnb_present_array[sgnb_present_index].full_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.priorityLevel = (*ref_erab_input)[i].sgnb_item.priority_level;
332       erab_sgnb_present_array[sgnb_present_index].full_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionCapability = (*ref_erab_input)[i].sgnb_item.pre_emption_capability;
333       erab_sgnb_present_array[sgnb_present_index].full_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionVulnerability = (*ref_erab_input)[i].sgnb_item.pre_emption_vulnerability;
334
335       erab_sgnb_present_array[sgnb_present_index].s1_UL_GTPtunnelEndpoint.transportLayerAddress.buf = (*ref_erab_input)[i].sgnb_item.transport_layer_addr;
336       erab_sgnb_present_array[sgnb_present_index].s1_UL_GTPtunnelEndpoint.transportLayerAddress.size = (*ref_erab_input)[i].sgnb_item.transport_layer_addr_size;
337       erab_sgnb_present_array[sgnb_present_index].s1_UL_GTPtunnelEndpoint.transportLayerAddress.bits_unused  = (*ref_erab_input)[i].sgnb_item.transport_layer_addr_unused;
338
339       erab_sgnb_present_array[sgnb_present_index].s1_UL_GTPtunnelEndpoint.gTP_TEID.buf = (*ref_erab_input)[i].sgnb_item.gtp_tei;
340       erab_sgnb_present_array[sgnb_present_index].s1_UL_GTPtunnelEndpoint.gTP_TEID.size = (*ref_erab_input)[i].sgnb_item.gtp_tei_size;
341
342       /* Force all optional parameters that are not set to NULL */
343       erab_sgnb_present_array[sgnb_present_index].max_MCG_admit_E_RAB_Level_QoS_Parameters = NULL;
344       erab_sgnb_present_array[sgnb_present_index].dL_Forwarding = NULL;
345       erab_sgnb_present_array[sgnb_present_index].meNB_DL_GTP_TEIDatMCG = NULL;
346
347
348       /* validate constraints ..*/      
349       int ret_constr;
350       
351       ret_constr = asn_check_constraints(&asn_DEF_AllocationAndRetentionPriority, &erab_sgnb_present_array[sgnb_present_index].full_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority, errbuf, &errbuf_len);
352       if(ret_constr){
353         error_string.assign(&errbuf[0], errbuf_len);
354         error_string = "Error in constraints for Allocation Priority.. Reason = " + error_string;
355         return false;
356       }
357
358       ret_constr = asn_check_constraints(&asn_DEF_E_RAB_Level_QoS_Parameters, &erab_sgnb_present_array[sgnb_present_index].full_E_RAB_Level_QoS_Parameters, errbuf, &errbuf_len);
359       if(ret_constr){
360         error_string.assign(&errbuf[0], errbuf_len);
361         error_string = "Error in constraints for ERAB QoS Parameters.. Reason = " + error_string;
362         return false;
363       }
364
365       
366       ret_constr = asn_check_constraints(&asn_DEF_GTP_TEI, &erab_sgnb_present_array[sgnb_present_index].s1_UL_GTPtunnelEndpoint.gTP_TEID, errbuf, &errbuf_len);
367       if(ret_constr){
368         error_string.assign(&errbuf[0], errbuf_len);
369         error_string = "Error in constraints for GTP TEID.. Reason = " + error_string;
370         return false;
371       }
372
373       ret_constr = asn_check_constraints(&asn_DEF_GTPtunnelEndpoint, &erab_sgnb_present_array[sgnb_present_index].s1_UL_GTPtunnelEndpoint, errbuf, &errbuf_len);
374       if(ret_constr){
375         error_string.assign(&errbuf[0], errbuf_len);
376         error_string = "Error in constraints for GTP tunnel endpoint .. Reason = " + error_string;
377         return false;
378       }
379
380       
381       ret_constr = asn_check_constraints(&asn_DEF_E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPpresent, &erab_sgnb_present_array[sgnb_present_index], errbuf, &errbuf_len);
382       if(ret_constr){
383         error_string.assign(&errbuf[0], errbuf_len);
384         error_string = "Error in constraints for E_RABS_ToBeAdded_SgNBAddReq_SgNBPDCPpresent.. Reason = " + error_string;
385         return false;
386       }
387
388       
389       erab_item->resource_configuration.choice.sgNBPDCPpresent = &erab_sgnb_present_array[sgnb_present_index];
390
391       sgnb_present_index ++;
392       
393     }
394     else if (erab_item->resource_configuration.present ==  E_RABs_ToBeAdded_SgNBAddReq_Item__resource_configuration_PR_sgNBPDCPnotpresent){
395
396       
397       erab_sgnb_notpresent_array[sgnb_notpresent_index].requested_SCG_E_RAB_Level_QoS_Parameters.qCI = (*ref_erab_input)[i].sgnb_item.qci;
398       erab_sgnb_notpresent_array[sgnb_notpresent_index].requested_SCG_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.priorityLevel = (*ref_erab_input)[i].sgnb_item.priority_level;
399       erab_sgnb_notpresent_array[sgnb_notpresent_index].requested_SCG_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionCapability = (*ref_erab_input)[i].sgnb_item.pre_emption_capability;
400       erab_sgnb_notpresent_array[sgnb_notpresent_index].requested_SCG_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionVulnerability = (*ref_erab_input)[i].sgnb_item.pre_emption_vulnerability;
401       erab_sgnb_notpresent_array[sgnb_notpresent_index].requested_SCG_E_RAB_Level_QoS_Parameters.gbrQosInformation = 0;
402       
403       erab_sgnb_notpresent_array[sgnb_notpresent_index].meNB_UL_GTP_TEIDatPDCP.transportLayerAddress.buf = (*ref_erab_input)[i].sgnb_item.transport_layer_addr;
404       erab_sgnb_notpresent_array[sgnb_notpresent_index].meNB_UL_GTP_TEIDatPDCP.transportLayerAddress.size = (*ref_erab_input)[i].sgnb_item.transport_layer_addr_size;
405       erab_sgnb_notpresent_array[sgnb_notpresent_index].meNB_UL_GTP_TEIDatPDCP.transportLayerAddress.bits_unused  = (*ref_erab_input)[i].sgnb_item.transport_layer_addr_unused;
406       
407       erab_sgnb_notpresent_array[sgnb_notpresent_index].meNB_UL_GTP_TEIDatPDCP.gTP_TEID.buf = (unsigned char *)(*ref_erab_input)[i].sgnb_item.gtp_tei;
408       erab_sgnb_notpresent_array[sgnb_notpresent_index].meNB_UL_GTP_TEIDatPDCP.gTP_TEID.size = (*ref_erab_input)[i].sgnb_item.gtp_tei_size;
409
410       erab_sgnb_notpresent_array[sgnb_notpresent_index].rlc_Mode = (*ref_erab_input)[i].sgnb_item.rlc_mode;
411
412       /* validate constraints ..*/      
413       int ret_constr;
414       
415       ret_constr = asn_check_constraints(&asn_DEF_AllocationAndRetentionPriority, &erab_sgnb_notpresent_array[sgnb_notpresent_index].requested_SCG_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority, errbuf, &errbuf_len);
416       if(ret_constr){
417         error_string.assign(&errbuf[0], errbuf_len);
418         error_string = "Error in constraints for Allocation Priority.. Reason = " + error_string;
419         return false;
420       }
421
422       ret_constr = asn_check_constraints(&asn_DEF_E_RAB_Level_QoS_Parameters, &erab_sgnb_notpresent_array[sgnb_notpresent_index].requested_SCG_E_RAB_Level_QoS_Parameters, errbuf, &errbuf_len);
423       if(ret_constr){
424         error_string.assign(&errbuf[0], errbuf_len);
425         error_string = "Error in constraints for ERAB QoS Parameters.. Reason = " + error_string;
426         return false;
427       }
428
429       
430       ret_constr = asn_check_constraints(&asn_DEF_GTP_TEI, &erab_sgnb_notpresent_array[sgnb_notpresent_index].meNB_UL_GTP_TEIDatPDCP.gTP_TEID, errbuf, &errbuf_len);
431       if(ret_constr){
432         error_string.assign(&errbuf[0], errbuf_len);
433         error_string = "Error in constraints for GTP TEID.. Reason = " + error_string;
434         return false;
435       }
436
437       ret_constr = asn_check_constraints(&asn_DEF_GTPtunnelEndpoint, &erab_sgnb_notpresent_array[sgnb_notpresent_index].meNB_UL_GTP_TEIDatPDCP, errbuf, &errbuf_len);
438       if(ret_constr){
439         error_string.assign(&errbuf[0], errbuf_len);
440         error_string = "Error in constraints for GTP tunnel endpoint .. Reason = " + error_string;
441         return false;
442       }
443
444       
445       ret_constr = asn_check_constraints(&asn_DEF_E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPnotpresent, &erab_sgnb_notpresent_array[sgnb_notpresent_index], errbuf, &errbuf_len);
446       if(ret_constr){
447         error_string.assign(&errbuf[0], errbuf_len);
448         error_string = "Error in constraints for E_RABS_ToBeAdded_SgNBAddReq_SgNBPDCPnotpresent.. Reason = " + error_string;
449         return false;
450       }
451
452
453       /* Force all optional parameters that are not set to NULL */
454       erab_sgnb_notpresent_array[sgnb_notpresent_index].uL_Configuration = 0;
455       erab_sgnb_notpresent_array[sgnb_notpresent_index].secondary_meNB_UL_GTP_TEIDatPDCP = 0;
456
457
458       erab_item->resource_configuration.choice.sgNBPDCPnotpresent = &erab_sgnb_notpresent_array[sgnb_notpresent_index]; ;
459       sgnb_notpresent_index ++;
460     }
461     else{
462       continue;
463     }
464     
465     // check constraint
466     int ret_constr = asn_check_constraints(&asn_DEF_E_RABs_ToBeAdded_SgNBAddReq_ItemIEs, &erab_array[i], errbuf, &errbuf_len);
467     if(ret_constr){
468       error_string.assign(&errbuf[0], errbuf_len);
469       error_string = "Error in constraints for E_RABS_ToBeAdded_SgNBAddReq_ItemIEs.. Reason = " + error_string;
470       return false;
471     }
472     
473     ASN_SEQUENCE_ADD(erabs_toadd_list, &erab_array[i]);
474     
475   }
476   
477   return true;
478
479 }
480
481
482 bool sgnb_addition_request::get_fields(X2InitiatingMessage_t * init_msg, sgnb_addition_helper & dout){
483     
484   if (init_msg == 0){
485     error_string = "Error ! Invalid reference for SgNB Addition Request get_fields";
486     return false;
487   }
488   
489   dout.clear();
490   int res = 0;
491   
492   struct erab_item * eitem;
493   std::vector<struct erab_item> *erab_list;
494   
495   SgNBAdditionRequest_IEs_t *memb_ptr;
496   for(int edx = 0; edx < init_msg->value.choice.SgNBAdditionRequest.protocolIEs.list.count; edx++){
497     memb_ptr = init_msg->value.choice.SgNBAdditionRequest.protocolIEs.list.array[edx];
498     
499     switch(memb_ptr->id){
500
501     case (ProtocolIE_ID_id_MeNB_UE_X2AP_ID):
502       dout.menb_ue_x2ap_id = memb_ptr->value.choice.UE_X2AP_ID;
503       break;
504
505     case (ProtocolIE_ID_id_SelectedPLMN):
506       dout.selected_plmn = memb_ptr->value.choice.PLMN_Identity.buf;
507       dout.selected_plmn_size = memb_ptr->value.choice.PLMN_Identity.size;
508       break;
509       
510     case (ProtocolIE_ID_id_NRUESecurityCapabilities):
511       dout.encryption_algs = memb_ptr->value.choice.NRUESecurityCapabilities.nRencryptionAlgorithms.buf;
512       dout.encryption_algs_size = memb_ptr->value.choice.NRUESecurityCapabilities.nRencryptionAlgorithms.size;
513       dout.encryption_algs_unused = memb_ptr->value.choice.NRUESecurityCapabilities.nRencryptionAlgorithms.bits_unused;
514
515       dout.integrity_protection_algs= memb_ptr->value.choice.NRUESecurityCapabilities.nRintegrityProtectionAlgorithms.buf;
516       dout.integrity_protection_algs_size = memb_ptr->value.choice.NRUESecurityCapabilities.nRintegrityProtectionAlgorithms.size;
517       dout.integrity_protection_algs_unused = memb_ptr->value.choice.NRUESecurityCapabilities.nRintegrityProtectionAlgorithms.bits_unused;
518
519       break;
520
521     case (ProtocolIE_ID_id_SgNBSecurityKey):
522       dout.sgnb_security_key = memb_ptr->value.choice.SgNBSecurityKey.buf;
523       dout.sgnb_security_key_size = memb_ptr->value.choice.SgNBSecurityKey.size;
524       dout.sgnb_security_key_unused = memb_ptr->value.choice.SgNBSecurityKey.bits_unused;
525
526       break;
527       
528     case (ProtocolIE_ID_id_SgNBUEAggregateMaximumBitRate):
529       res = asn_INTEGER2long(&(memb_ptr->value.choice.UEAggregateMaximumBitRate.uEaggregateMaximumBitRateDownlink), &dout.bit_rate_max_dn );
530       if (res == -1){
531         error_string = "Error converting uEaggregateMaximumBitRateDownlink ";
532         return false;
533       }
534       
535       res = asn_INTEGER2long(&(memb_ptr->value.choice.UEAggregateMaximumBitRate.uEaggregateMaximumBitRateUplink), &dout.bit_rate_max_up );
536       if (res == -1){
537         error_string = "Error converting uEaggregateMaximumBitRateUplink ";
538         return false;
539       }
540
541       
542       break;
543       
544     case (ProtocolIE_ID_id_MeNBtoSgNBContainer):
545       dout.menb_sgnb_container = memb_ptr->value.choice.MeNBtoSgNBContainer.buf;
546       dout.menb_sgnb_container_size = memb_ptr->value.choice.MeNBtoSgNBContainer.size;
547       break;
548       
549     case (ProtocolIE_ID_id_SgNB_UE_X2AP_ID):
550       dout.sgnb_ue_x2ap_id = memb_ptr->value.choice.SgNB_UE_X2AP_ID;
551       break;
552       
553     case (ProtocolIE_ID_id_SubscriberProfileIDforRFP):
554       //sgnb->subscriberprofileidforrfp = memb_ptr->value.choice.SubscriberProfileIDforRFP;
555       break;
556       
557     case (ProtocolIE_ID_id_MeNBCell_ID):
558
559       dout.eutran_identifier = memb_ptr->value.choice.ECGI.eUTRANcellIdentifier.buf;
560       dout.eutran_identifier_size = memb_ptr->value.choice.ECGI.eUTRANcellIdentifier.size;
561       dout.eutran_identifier_unused = memb_ptr->value.choice.ECGI.eUTRANcellIdentifier.bits_unused;
562
563       dout.plmn_identity = memb_ptr->value.choice.ECGI.pLMN_Identity.buf;
564       dout.plmn_identity_size = memb_ptr->value.choice.ECGI.pLMN_Identity.size;
565       break;
566       
567     case (ProtocolIE_ID_id_E_RABs_ToBeAdded_SgNBAddReqList):
568
569       erab_list = & dout.erab_list;
570       
571       for(int erabs=0; erabs < memb_ptr->value.choice.E_RABs_ToBeAdded_SgNBAddReqList.list.count;erabs++){
572         E_RABs_ToBeAdded_SgNBAddReq_ItemIEs_t * erab_item_ie = (E_RABs_ToBeAdded_SgNBAddReq_ItemIEs_t *)memb_ptr->value.choice.E_RABs_ToBeAdded_SgNBAddReqList.list.array[erabs];
573
574         erab_list->emplace_back();
575         eitem = &(*erab_list)[erabs];
576         
577         //erab_item *eitem = (erab_item*)calloc(1, sizeof(erab_item));
578         
579         eitem->drb_id = erab_item_ie->value.choice.E_RABs_ToBeAdded_SgNBAddReq_Item.drb_ID;
580         eitem->erab_id = erab_item_ie->value.choice.E_RABs_ToBeAdded_SgNBAddReq_Item.e_RAB_ID;
581
582         eitem->mcg_resources = erab_item_ie->value.choice.E_RABs_ToBeAdded_SgNBAddReq_Item.en_DC_ResourceConfiguration.mCGresources;
583         eitem->scg_resources = erab_item_ie->value.choice.E_RABs_ToBeAdded_SgNBAddReq_Item.en_DC_ResourceConfiguration.sCGresources;
584         eitem->pdcp_at_sgnb = erab_item_ie->value.choice.E_RABs_ToBeAdded_SgNBAddReq_Item.en_DC_ResourceConfiguration.pDCPatSgNB;
585         eitem->sgnb_pdcp_present = erab_item_ie->value.choice.E_RABs_ToBeAdded_SgNBAddReq_Item.resource_configuration.present;
586         
587         if(erab_item_ie->value.choice.E_RABs_ToBeAdded_SgNBAddReq_Item.resource_configuration.present == E_RABs_ToBeAdded_SgNBAddReq_Item__resource_configuration_PR_sgNBPDCPpresent){
588
589           E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPpresent_t *erab_sgnb_present_ie = erab_item_ie->value.choice.E_RABs_ToBeAdded_SgNBAddReq_Item.resource_configuration.choice.sgNBPDCPpresent;
590
591           eitem->sgnb_item.qci = erab_sgnb_present_ie->full_E_RAB_Level_QoS_Parameters.qCI;
592           eitem->sgnb_item.priority_level = erab_sgnb_present_ie->full_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.priorityLevel;
593           eitem->sgnb_item.pre_emption_capability = erab_sgnb_present_ie->full_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionCapability;
594           eitem->sgnb_item.pre_emption_vulnerability = erab_sgnb_present_ie->full_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionVulnerability;
595           
596           
597           eitem->sgnb_item.gtp_tei =  erab_sgnb_present_ie->s1_UL_GTPtunnelEndpoint.gTP_TEID.buf;
598           eitem->sgnb_item.gtp_tei_size = erab_sgnb_present_ie->s1_UL_GTPtunnelEndpoint.gTP_TEID.size;
599           
600           eitem->sgnb_item.transport_layer_addr = erab_sgnb_present_ie->s1_UL_GTPtunnelEndpoint.transportLayerAddress.buf;
601           eitem->sgnb_item.transport_layer_addr_size = erab_sgnb_present_ie->s1_UL_GTPtunnelEndpoint.transportLayerAddress.size;
602           eitem->sgnb_item.transport_layer_addr_unused = erab_sgnb_present_ie->s1_UL_GTPtunnelEndpoint.transportLayerAddress.bits_unused;
603           
604           
605         }
606         else if(erab_item_ie->value.choice.E_RABs_ToBeAdded_SgNBAddReq_Item.resource_configuration.present == E_RABs_ToBeAdded_SgNBAddReq_Item__resource_configuration_PR_sgNBPDCPnotpresent){
607           E_RABs_ToBeAdded_SgNBAddReq_Item_SgNBPDCPnotpresent_t *erab_sgnb_notpresent_ie = erab_item_ie->value.choice.E_RABs_ToBeAdded_SgNBAddReq_Item.resource_configuration.choice.sgNBPDCPnotpresent;
608           eitem->sgnb_item.rlc_mode = erab_sgnb_notpresent_ie->rlc_Mode;
609           eitem->sgnb_item.gtp_tei = erab_sgnb_notpresent_ie->meNB_UL_GTP_TEIDatPDCP.gTP_TEID.buf;
610           eitem->sgnb_item.gtp_tei_size = erab_sgnb_notpresent_ie->meNB_UL_GTP_TEIDatPDCP.gTP_TEID.size;
611           eitem->sgnb_item.transport_layer_addr = erab_sgnb_notpresent_ie->meNB_UL_GTP_TEIDatPDCP.transportLayerAddress.buf;
612           eitem->sgnb_item.transport_layer_addr_size = erab_sgnb_notpresent_ie->meNB_UL_GTP_TEIDatPDCP.transportLayerAddress.size;
613           eitem->sgnb_item.transport_layer_addr_unused = erab_sgnb_notpresent_ie->meNB_UL_GTP_TEIDatPDCP.transportLayerAddress.bits_unused;
614
615           eitem->sgnb_item.qci = erab_sgnb_notpresent_ie->requested_SCG_E_RAB_Level_QoS_Parameters.qCI;
616           eitem->sgnb_item.pre_emption_capability = erab_sgnb_notpresent_ie->requested_SCG_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionCapability;
617           eitem->sgnb_item.pre_emption_vulnerability = erab_sgnb_notpresent_ie->requested_SCG_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionVulnerability;
618           eitem->sgnb_item.priority_level = erab_sgnb_notpresent_ie->requested_SCG_E_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.priorityLevel;
619
620         }
621         else{
622           mdclog_write(MDCLOG_ERR, "Error :: %s, %d :: E-RAB does not have sgNBPDCP present/not present set flag", __FILE__, __LINE__);
623           return false;
624         }
625         
626       }
627       
628       break;
629       
630     default:
631       break;
632
633     }
634
635   }
636   return true;
637 }