Support for service update E2 Message 13/4813/3
authorsubhash kumar singh <subh.singh@samsung.com>
Tue, 6 Oct 2020 19:58:58 +0000 (01:28 +0530)
committersubhash kumar singh <subh.singh@samsung.com>
Wed, 14 Oct 2020 13:43:53 +0000 (13:43 +0000)
Implement support for E2 service update message.

Issue-ID: SIM-43
Signed-off-by: subhash kumar singh <subh.singh@samsung.com>
Change-Id: Ifc3e3e0cf0638c36efc2edb98afc51e4392b3abc

e2sim/src/base/e2sim.cpp
e2sim/src/base/e2sim.hpp
e2sim/src/encoding/encode_e2apv1.cpp
e2sim/src/encoding/encode_e2apv1.hpp
e2sim/src/messagerouting/e2ap_message_handler.cpp
e2sim/src/messagerouting/e2ap_message_handler.hpp

index fa62bed..372cc9d 100644 (file)
@@ -1,6 +1,7 @@
 /*****************************************************************************
 #                                                                            *
 # Copyright 2020 AT&T Intellectual Property                                  *
 /*****************************************************************************
 #                                                                            *
 # Copyright 2020 AT&T Intellectual Property                                  *
+# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.      *
 #                                                                            *
 # Licensed under the Apache License, Version 2.0 (the "License");            *
 # you may not use this file except in compliance with the License.           *
 #                                                                            *
 # Licensed under the Apache License, Version 2.0 (the "License");            *
 # you may not use this file except in compliance with the License.           *
@@ -33,6 +34,10 @@ using namespace std;
 
 int client_fd = 0;
 
 
 int client_fd = 0;
 
+std::unordered_map<long, OCTET_STRING_t*> E2Sim::getRegistered_ran_functions() {
+  return ran_functions_registered;
+}
+
 void E2Sim::register_subscription_callback(long func_id, SubscriptionCallback cb) {
   fprintf(stderr,"%%%%about to register callback for subscription for func_id %d\n", func_id);
   subscription_callbacks[func_id] = cb;
 void E2Sim::register_subscription_callback(long func_id, SubscriptionCallback cb) {
   fprintf(stderr,"%%%%about to register callback for subscription for func_id %d\n", func_id);
   subscription_callbacks[func_id] = cb;
index 16015ea..eace5a8 100644 (file)
@@ -1,6 +1,7 @@
 /*****************************************************************************
 #                                                                            *
 # Copyright 2020 AT&T Intellectual Property                                  *
 /*****************************************************************************
 #                                                                            *
 # Copyright 2020 AT&T Intellectual Property                                  *
+# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.      *
 #                                                                            *
 # Licensed under the Apache License, Version 2.0 (the "License");            *
 # you may not use this file except in compliance with the License.           *
 #                                                                            *
 # Licensed under the Apache License, Version 2.0 (the "License");            *
 # you may not use this file except in compliance with the License.           *
@@ -40,6 +41,8 @@ private:
   
 public:
 
   
 public:
 
+  std::unordered_map<long, OCTET_STRING_t*> getRegistered_ran_functions();
+
   void generate_e2apv1_subscription_response_success(E2AP_PDU *e2ap_pdu, long reqActionIdsAccepted[], long reqActionIdsRejected[], int accept_size, int reject_size, long reqRequestorId, long reqInstanceId);
 
   void generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_pdu, long requestorId, long instanceId, long ranFunctionId, long actionId, long seqNum, uint8_t *ind_header_buf, int header_length, uint8_t *ind_message_buf, int message_length);  
   void generate_e2apv1_subscription_response_success(E2AP_PDU *e2ap_pdu, long reqActionIdsAccepted[], long reqActionIdsRejected[], int accept_size, int reject_size, long reqRequestorId, long reqInstanceId);
 
   void generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_pdu, long requestorId, long instanceId, long ranFunctionId, long actionId, long seqNum, uint8_t *ind_header_buf, int header_length, uint8_t *ind_message_buf, int message_length);  
index d1c2c06..6f8c589 100644 (file)
@@ -3,6 +3,7 @@
 /*****************************************************************************
 #                                                                            *
 # Copyright 2020 AT&T Intellectual Property                                  *
 /*****************************************************************************
 #                                                                            *
 # Copyright 2020 AT&T Intellectual Property                                  *
+# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.      *
 #                                                                            *
 # Licensed under the Apache License, Version 2.0 (the "License");            *
 # you may not use this file except in compliance with the License.           *
 #                                                                            *
 # Licensed under the Apache License, Version 2.0 (the "License");            *
 # you may not use this file except in compliance with the License.           *
@@ -95,6 +96,66 @@ long encoding::get_function_id_from_subscription(E2AP_PDU_t *e2ap_pdu) {
 
 }
 
 
 }
 
+void encoding::generate_e2apv1_service_update(E2AP_PDU_t *e2ap_pdu, std::vector<encoding::ran_func_info> all_funcs) {
+  char* ran_function_op_type = getenv("RAN_FUNCTION_OP_TYPE");
+  LOG_D("Ran funciton : %s", ran_function_op_type);
+  ProtocolIE_ID_t prID;
+  if (ran_function_op_type != NULL)
+  {
+    if (strcmp(ran_function_op_type, "ADD") == 0)
+    {
+      prID = ProtocolIE_ID_id_RANfunctionsAdded;
+    }
+    else if (strcmp(ran_function_op_type, "DELETE"))
+    {
+      prID = ProtocolIE_ID_id_RANfunctionsDeleted;
+    }
+  }
+  else
+  {
+    prID = ProtocolIE_ID_id_RANfunctionsModified;
+  }
+
+
+  RICserviceUpdate_IEs_t *e2serviceUpdateList = (RICserviceUpdate_IEs_t *)calloc(1, sizeof(RICserviceUpdate_IEs_t));
+  e2serviceUpdateList->id = prID;
+  e2serviceUpdateList->criticality = Criticality_reject;
+  e2serviceUpdateList->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
+
+
+  for (int i=0; i<all_funcs.size(); i++) {
+
+    encoding::ran_func_info nextRanFunc = all_funcs.at(i);
+    long nextRanFuncId = nextRanFunc.ranFunctionId;
+    OCTET_STRING_t *nextRanFuncDesc = nextRanFunc.ranFunctionDesc;
+    long nextRanFuncRev = nextRanFunc.ranFunctionRev;
+
+    auto *itemIes = (RANfunction_ItemIEs_t *)calloc(1, sizeof(RANfunction_ItemIEs_t));
+    itemIes->id = ProtocolIE_ID_id_RANfunction_Item;
+    itemIes->criticality = Criticality_reject;
+    itemIes->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
+    itemIes->value.choice.RANfunction_Item.ranFunctionID = 1;
+
+    itemIes->value.choice.RANfunction_Item.ranFunctionDefinition = *nextRanFuncDesc;
+    itemIes->value.choice.RANfunction_Item.ranFunctionRevision = nextRanFuncRev + 1;
+
+    ASN_SEQUENCE_ADD(&e2serviceUpdateList->value.choice.RANfunctions_List.list, itemIes);
+  }
+
+  RICserviceUpdate_t *ricServiceUpdate = (RICserviceUpdate_t *)calloc(1, sizeof(RICserviceUpdate_t));
+  ASN_SEQUENCE_ADD(&ricServiceUpdate->protocolIEs.list, e2serviceUpdateList);
+
+  InitiatingMessage_t *initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t));
+  initiatingMessage->criticality = Criticality_reject;
+  initiatingMessage->procedureCode = ProcedureCode_id_RICserviceUpdate;
+  initiatingMessage->value.present = InitiatingMessage__value_PR_RICserviceUpdate;
+  initiatingMessage->value.choice.RICserviceUpdate = *ricServiceUpdate;
+
+  E2AP_PDU_PR pres6 = E2AP_PDU_PR_initiatingMessage;
+  e2ap_pdu->present = pres6;
+  e2ap_pdu->choice.initiatingMessage = initiatingMessage;
+}
+
 void encoding::generate_e2apv1_setup_request_parameterized(E2AP_PDU_t *e2ap_pdu, std::vector<ran_func_info> all_funcs) {
   //                                            long ranFunctionId, uint8_t *ranFuncDescEncoded, int ranFuncLength) {
 
 void encoding::generate_e2apv1_setup_request_parameterized(E2AP_PDU_t *e2ap_pdu, std::vector<ran_func_info> all_funcs) {
   //                                            long ranFunctionId, uint8_t *ranFuncDescEncoded, int ranFuncLength) {
 
index b7747d4..6bbbe56 100644 (file)
@@ -2,6 +2,7 @@
 /*****************************************************************************
 #                                                                            *
 # Copyright 2020 AT&T Intellectual Property                                  *
 /*****************************************************************************
 #                                                                            *
 # Copyright 2020 AT&T Intellectual Property                                  *
+# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.      *
 #                                                                            *
 # Licensed under the Apache License, Version 2.0 (the "License");            *
 # you may not use this file except in compliance with the License.           *
 #                                                                            *
 # Licensed under the Apache License, Version 2.0 (the "License");            *
 # you may not use this file except in compliance with the License.           *
@@ -54,6 +55,7 @@ namespace encoding {
   
   void generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_pdu, long requestorId, long instanceId, long ranFunctionId, long actionId, long seqNum, uint8_t *ind_header_buf, int header_length, uint8_t *ind_message_buf, int message_length);
   
   
   void generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_pdu, long requestorId, long instanceId, long ranFunctionId, long actionId, long seqNum, uint8_t *ind_header_buf, int header_length, uint8_t *ind_message_buf, int message_length);
   
+  void generate_e2apv1_service_update(E2AP_PDU_t *e2ap_pdu, std::vector<ran_func_info> all_funcs);
 }
 
 #endif
 }
 
 #endif
index 0e23c8d..3ecc2f0 100644 (file)
@@ -3,6 +3,7 @@
 /*****************************************************************************\r
 #                                                                            *\r
 # Copyright 2020 AT&T Intellectual Property                                  *\r
 /*****************************************************************************\r
 #                                                                            *\r
 # Copyright 2020 AT&T Intellectual Property                                  *\r
+# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.      *\r
 #                                                                            *\r
 # Licensed under the Apache License, Version 2.0 (the "License");            *\r
 # you may not use this file except in compliance with the License.           *\r
 #                                                                            *\r
 # Licensed under the Apache License, Version 2.0 (the "License");            *\r
 # you may not use this file except in compliance with the License.           *\r
@@ -172,7 +173,40 @@ void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data, bool xmlenc, E2S
           break;\r
        }\r
       break;\r
           break;\r
        }\r
       break;\r
-      \r
+\r
+    case ProcedureCode_id_RICserviceQuery:\r
+      switch (index)\r
+        {\r
+          case E2AP_PDU_PR_initiatingMessage:\r
+          LOG_I("[E2AP] Received RIC-Service-Query")\r
+          e2ap_handle_E2SeviceRequest(pdu, socket_fd, e2sim);\r
+          break;\r
+\r
+          default:\r
+            LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU %d", index,\r
+                                    (int)ProcedureCode_id_RICserviceQuery);\r
+          break;\r
+        }\r
+      break;\r
+\r
+    case ProcedureCode_id_RICserviceUpdate:\r
+      switch (index)\r
+        {\r
+          case E2AP_PDU_PR_successfulOutcome:\r
+          LOG_I("[E2AP] Received RIC-SERVICE-UPDATE-SUCCESS")\r
+          break;\r
+\r
+          case E2AP_PDU_PR_unsuccessfulOutcome:\r
+          LOG_I("[E2AP] Received RIC-SERVICE-UPDATE-FAILURE")\r
+          break;\r
+\r
+          default:\r
+            LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU %d", index,\r
+                                    (int)ProcedureCode_id_RICserviceUpdate);\r
+          break;\r
+        }\r
+      break;\r
+    \r
     default:\r
       \r
       LOG_E("[E2AP] No available handler for procedureCode=%d", procedureCode);\r
     default:\r
       \r
       LOG_E("[E2AP] No available handler for procedureCode=%d", procedureCode);\r
@@ -181,6 +215,59 @@ void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data, bool xmlenc, E2S
     }\r
 }\r
 \r
     }\r
 }\r
 \r
+void e2ap_handle_E2SeviceRequest(E2AP_PDU_t* pdu, int &socket_fd, E2Sim *e2sim) {\r
+\r
+  auto buffer_size = MAX_SCTP_BUFFER;\r
+  unsigned char buffer[MAX_SCTP_BUFFER];\r
+  E2AP_PDU_t* res_pdu = (E2AP_PDU_t*)calloc(1,sizeof(E2AP_PDU));\r
+\r
+  // prepare ran function defination\r
+  std::vector<encoding::ran_func_info> all_funcs;\r
+\r
+  //Loop through RAN function definitions that are registered\r
+\r
+  for (std::pair<long, OCTET_STRING_t*> elem : e2sim->getRegistered_ran_functions()) {\r
+    printf("looping through ran func\n");\r
+    encoding::ran_func_info next_func;\r
+\r
+    next_func.ranFunctionId = elem.first;\r
+    next_func.ranFunctionDesc = elem.second;\r
+    next_func.ranFunctionRev = (long)3;\r
+    all_funcs.push_back(next_func);\r
+  }\r
+    \r
+  printf("about to call service update encode\n");\r
+\r
+  encoding::generate_e2apv1_service_update(res_pdu, all_funcs);\r
+\r
+  LOG_D("[E2AP] Created E2-SERVICE-UPDATE");\r
+\r
+  e2ap_asn1c_print_pdu(res_pdu);\r
+\r
+  sctp_buffer_t data;\r
+\r
+  char *error_buf = (char*)calloc(300, sizeof(char));\r
+  size_t errlen;\r
+\r
+  asn_check_constraints(&asn_DEF_E2AP_PDU, res_pdu, error_buf, &errlen);\r
+  printf("error length %d\n", errlen);\r
+  printf("error buf %s\n", error_buf);\r
+\r
+  auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, res_pdu, buffer, buffer_size);\r
+\r
+  data.len = er.encoded;\r
+  fprintf(stderr, "er encoded is %d\n", er.encoded);\r
+\r
+  memcpy(data.buffer, buffer, er.encoded);\r
+\r
+  //send response data over sctp\r
+  if(sctp_send_data(socket_fd, data) > 0) {\r
+    LOG_I("[SCTP] Sent E2-SERVICE-UPDATE");\r
+  } else {\r
+    LOG_E("[SCTP] Unable to send E2-SERVICE-UPDATE to peer");\r
+  }\r
+}\r
+\r
 void e2ap_handle_E2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd) {\r
 \r
   \r
 void e2ap_handle_E2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd) {\r
 \r
   \r
index 5ec288b..f937745 100644 (file)
@@ -2,6 +2,7 @@
 #                                                                            *\r
 # Copyright 2019 AT&T Intellectual Property                                  *\r
 # Copyright 2019 Nokia                                                       *\r
 #                                                                            *\r
 # Copyright 2019 AT&T Intellectual Property                                  *\r
 # Copyright 2019 Nokia                                                       *\r
+# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.      *\r
 #                                                                            *\r
 # Licensed under the Apache License, Version 2.0 (the "License");            *\r
 # you may not use this file except in compliance with the License.           *\r
 #                                                                            *\r
 # Licensed under the Apache License, Version 2.0 (the "License");            *\r
 # you may not use this file except in compliance with the License.           *\r
@@ -44,4 +45,6 @@ void e2ap_handle_RICSubscriptionRequest_securityDemo(E2AP_PDU_t* pdu, int &socke
 \r
 void e2ap_handle_ResourceStatusRequest(E2AP_PDU_t* pdu, int &socket_fd);\r
 \r
 \r
 void e2ap_handle_ResourceStatusRequest(E2AP_PDU_t* pdu, int &socket_fd);\r
 \r
+void e2ap_handle_E2SeviceRequest(E2AP_PDU_t* pdu, int &socket_fd, E2Sim *e2sim);\r
+\r
 #endif\r
 #endif\r