f1ap_du_task.c 7.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

22
/*! \file openair2/F1AP/f1ap_du_task.c
23 24 25 26 27 28 29 30 31 32 33 34
* \brief data structures for F1 interface modules
* \author EURECOM/NTUST
* \date 2018
* \version 0.1
* \company Eurecom
* \email: navid.nikaein@eurecom.fr, raymond.knopp@eurecom.fr, bing-kai.hong@eurecom.fr
* \note
* \warning
*/

#include "f1ap_common.h"
#include "f1ap_du_interface_management.h"
Robert Schmidt's avatar
Robert Schmidt committed
35
#include "f1ap_du_ue_context_management.h"
36
#include "f1ap_du_rrc_message_transfer.h"
37
#include "f1ap_du_task.h"
Laurent Thomas's avatar
Laurent Thomas committed
38
#include <openair3/ocp-gtpu/gtp_itf.h>
39

Laurent THOMAS's avatar
Laurent THOMAS committed
40 41 42
//Fixme: Uniq dirty DU instance, by global var, datamodel need better management
instance_t DUuniqInstance=0;

43 44 45 46
void du_task_send_sctp_association_req(instance_t instance, f1ap_setup_req_t *f1ap_setup_req) {
  DevAssert(f1ap_setup_req != NULL);
  MessageDef                 *message_p                   = NULL;
  sctp_new_association_req_t *sctp_new_association_req_p  = NULL;
47
  message_p = itti_alloc_new_message(TASK_DU_F1, 0, SCTP_NEW_ASSOCIATION_REQ);
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
  sctp_new_association_req_p = &message_p->ittiMsg.sctp_new_association_req;
  sctp_new_association_req_p->ulp_cnx_id = instance;
  sctp_new_association_req_p->port = F1AP_PORT_NUMBER;
  sctp_new_association_req_p->ppid = F1AP_SCTP_PPID;
  sctp_new_association_req_p->in_streams  = f1ap_setup_req->sctp_in_streams;
  sctp_new_association_req_p->out_streams = f1ap_setup_req->sctp_out_streams;
  // remote
  memcpy(&sctp_new_association_req_p->remote_address,
         &f1ap_setup_req->CU_f1_ip_address,
         sizeof(f1ap_setup_req->CU_f1_ip_address));
  // local
  memcpy(&sctp_new_association_req_p->local_address,
         &f1ap_setup_req->DU_f1_ip_address,
         sizeof(f1ap_setup_req->DU_f1_ip_address));
  //printf("sib itti message %s\n", f1ap_setup_req_t->sib1[0]);
Bing-Kai Hong's avatar
Bing-Kai Hong committed
63
  //printf("nr_cellid : %llx (%lld)",f1ap_setup_req->nr_cellid[0],f1ap_setup_req->nr_cellid[0]);
64 65 66 67 68 69 70 71
  //du_f1ap_register_to_sctp
  itti_send_msg_to_task(TASK_SCTP, instance, message_p);
}

void du_task_handle_sctp_association_resp(instance_t instance, sctp_new_association_resp_t *sctp_new_association_resp) {
  DevAssert(sctp_new_association_resp != NULL);

  if (sctp_new_association_resp->sctp_state != SCTP_STATE_ESTABLISHED) {
72
    LOG_W(F1AP, "Received unsuccessful result for SCTP association (%u), instance %ld, cnx_id %u\n",
73 74 75 76 77 78 79 80
          sctp_new_association_resp->sctp_state,
          instance,
          sctp_new_association_resp->ulp_cnx_id);
    //f1ap_handle_setup_message(instance, sctp_new_association_resp->sctp_state == SCTP_STATE_SHUTDOWN);
    return; // exit -1 for debugging
  }

  // save the assoc id
81
  f1ap_setup_req_t *f1ap_du_data=f1ap_req(false, instance);
82 83 84
  f1ap_du_data->assoc_id         = sctp_new_association_resp->assoc_id;
  f1ap_du_data->sctp_in_streams  = sctp_new_association_resp->in_streams;
  f1ap_du_data->sctp_out_streams = sctp_new_association_resp->out_streams;
85
  f1ap_du_data->default_sctp_stream_id = 0;
86
  /* setup parameters for F1U and start the server */
87 88 89
  DU_send_F1_SETUP_REQUEST(instance);
}

90
void du_task_handle_sctp_data_ind(instance_t instance, sctp_data_ind_t *sctp_data_ind) {
91 92
  int result;
  DevAssert(sctp_data_ind != NULL);
93
  f1ap_handle_message(instance, sctp_data_ind->assoc_id, sctp_data_ind->stream,
94
                      sctp_data_ind->buffer, sctp_data_ind->buffer_length);
95 96 97 98 99 100
  result = itti_free(TASK_UNKNOWN, sctp_data_ind->buffer);
  AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
}

void *F1AP_DU_task(void *arg) {
  //sctp_cu_init();
101
  LOG_I(F1AP, "Starting F1AP at DU\n");
102 103 104 105
  itti_mark_task_ready(TASK_DU_F1);

  // SCTP
  while (1) {
Laurent Thomas's avatar
Laurent Thomas committed
106 107 108
    MessageDef *msg = NULL;
    itti_receive_msg(TASK_DU_F1, &msg);
    instance_t myInstance=ITTI_MSG_DESTINATION_INSTANCE(msg);
109
    LOG_D(F1AP, "DU Task Received %s for instance %ld\n",
110
          ITTI_MSG_NAME(msg),myInstance);
Laurent Thomas's avatar
Laurent Thomas committed
111
    switch (ITTI_MSG_ID(msg)) {
112
      case F1AP_SETUP_REQ: {
laurent's avatar
laurent committed
113
        // this is not a true F1 message, but rather an ITTI message sent by gnb_app
114
        // 1. save the itti msg so that you can use it to sen f1ap_setup_req, fill the f1ap_setup_req message,
115 116
        // 2. store the message in f1ap context, that is also stored in RC
        // 2. send a sctp_association req
117
        f1ap_setup_req_t *msgSetup = &F1AP_SETUP_REQ(msg);
Laurent Thomas's avatar
Laurent Thomas committed
118
        createF1inst(false, myInstance, msgSetup);
119 120
        du_task_send_sctp_association_req(myInstance, msgSetup);
      } break;
121

122
      case F1AP_GNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE:
Laurent Thomas's avatar
Laurent Thomas committed
123 124
        DU_send_gNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE(ITTI_MSG_ORIGIN_INSTANCE(msg),
            &F1AP_GNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE(msg));
125 126
        break;

127
      case F1AP_GNB_CU_CONFIGURATION_UPDATE_FAILURE:
Laurent Thomas's avatar
Laurent Thomas committed
128 129
        DU_send_gNB_CU_CONFIGURATION_UPDATE_FAILURE(myInstance,
            &F1AP_GNB_CU_CONFIGURATION_UPDATE_FAILURE(msg));
130
        break;
131 132 133 134

      case SCTP_NEW_ASSOCIATION_RESP:
        // 1. store the respon
        // 2. send the f1setup_req
Laurent Thomas's avatar
Laurent Thomas committed
135 136
        du_task_handle_sctp_association_resp(myInstance,
                                             &msg->ittiMsg.sctp_new_association_resp);
137 138
        break;

139
      case SCTP_DATA_IND:
140
        // ex: any F1 incoming message for DU ends here
Laurent Thomas's avatar
Laurent Thomas committed
141 142
        du_task_handle_sctp_data_ind(myInstance,
                                     &msg->ittiMsg.sctp_data_ind);
143 144
        break;

145
      case F1AP_INITIAL_UL_RRC_MESSAGE: // from rrc
146
      {
Laurent Thomas's avatar
Laurent Thomas committed
147
        f1ap_initial_ul_rrc_message_t *msgRrc = &F1AP_INITIAL_UL_RRC_MESSAGE(msg);
148 149
        DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(0, 0, 0, msgRrc->crnti, msgRrc->rrc_container, msgRrc->rrc_container_length, msgRrc->du2cu_rrc_container, msgRrc->du2cu_rrc_container_length);
      } break;
150

151
      case F1AP_UL_RRC_MESSAGE: // to rrc
Robert Schmidt's avatar
Robert Schmidt committed
152
        DU_send_UL_NR_RRC_MESSAGE_TRANSFER(myInstance, &F1AP_UL_RRC_MESSAGE(msg));
153 154
        break;

155
      case F1AP_UE_CONTEXT_SETUP_RESP:
Laurent Thomas's avatar
Laurent Thomas committed
156
        DU_send_UE_CONTEXT_SETUP_RESPONSE(myInstance, &F1AP_UE_CONTEXT_SETUP_RESP(msg));
157 158
        break;

159
      case F1AP_UE_CONTEXT_MODIFICATION_RESP:
160
        DU_send_UE_CONTEXT_MODIFICATION_RESPONSE(myInstance, &F1AP_UE_CONTEXT_MODIFICATION_RESP(msg));
161 162
        break;

163
      case F1AP_UE_CONTEXT_RELEASE_REQ: // from MAC
Laurent Thomas's avatar
Laurent Thomas committed
164 165
        DU_send_UE_CONTEXT_RELEASE_REQUEST(myInstance,
                                           &F1AP_UE_CONTEXT_RELEASE_REQ(msg));
166 167
        break;

168 169 170 171
      case F1AP_UE_CONTEXT_RELEASE_COMPLETE:
        DU_send_UE_CONTEXT_RELEASE_COMPLETE(myInstance, &F1AP_UE_CONTEXT_RELEASE_COMPLETE(msg));
        break;

172
      case TERMINATE_MESSAGE:
173
        LOG_W(F1AP, " *** Exiting F1AP thread\n");
174 175 176 177
        itti_exit_task();
        break;

      default:
178
        LOG_E(F1AP, "DU Received unhandled message: %d:%s\n",
Laurent Thomas's avatar
Laurent Thomas committed
179
              ITTI_MSG_ID(msg), ITTI_MSG_NAME(msg));
180 181
        break;
    } // switch
182

Laurent Thomas's avatar
Laurent Thomas committed
183
    int result = itti_free (ITTI_MSG_ORIGIN_ID(msg), msg);
184 185 186 187
    AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
  } // while

  return NULL;
188
}