前言:对于5G系列,在下主要在业余时间进行学习和总结,分享出来以供参考。为了便于理解5G协议,开始加入openairinterface(OAI)开源项目介绍,5G协议分析和5G代码分析不定期交替更新。OAI安装搭建已经在OAI 5G NR+USRP B210安装搭建一文中做过介绍,今天先大体看一下OAI的目录结构和主函数结构。
目录结构
openairinterface5g
├── ci-scripts : Meta-scripts used by the OSA CI process. Contains also configuration files used day-to-day by CI. 已忽略
├── cmake_targets : Build utilities to compile (simulation, emulation and real-time platforms), and generated build files. 存放编译脚本,以及编译生成的可执行程序,程序编译在这里面
├── common : Some common OAI utilities, other tools can be found at openair2/UTILS. OAI公共代码
├── doc : Contains an up-to-date feature set list and starting tutorials. 最新的功能集列表和入门教程
├── executables : Top-level executable source files. 已忽略
├── LICENSE : License file.
├── maketags : Script to generate emacs tags. 已忽略
├── nfapi : Contains the NFAPI code. A local Readme file provides more details. NFAPI接口代码
├── openair1 : 3GPP LTE Rel-10/12 PHY layer / 3GPP NR Rel-15 layer. A local Readme file provides more details. 物理层代码
│ ├── PHY 物理层
│ ├── SCHED LTE基站侧调度
│ ├── SCHED_NBIOT NBIOT调度
│ ├── SCHED_NR NR基站侧调度
│ ├── SCHED_NR_UE NR UE侧调度
│ ├── SCHED_UE LTE UE侧调度
│ └── SIMULATION : PHY RF simulation. 物理层RF仿真
├── openair2 : 3GPP LTE Rel-10 RLC/MAC/PDCP/RRC/X2AP + LTE Rel-14 M2AP implementation. Also 3GPP NR Rel-15 RLC/MAC/PDCP/RRC/X2AP. MAC, RLC, PDCP, RRC, NGAP全部在openair2目录下
│ ├── COMMON
│ ├── DOCS
│ ├── ENB_APP
│ ├── F1AP
│ ├── GNB_APP
│ ├── LAYER2/RLC/ : with the following subdirectories: UM_v9.3.0, TM_v9.3.0, and AM_v9.3.0.
│ ├── LAYER2/PDCP/PDCP_v10.1.0
│ ├── M2AP
│ ├── MCE_APP
│ ├── NETWORK_DRIVER
│ ├── NR_PHY_INTERFACE
│ ├── NR_UE_PHY_INTERFACE
│ ├── PHY_INTERFACE
│ ├── RRC
│ ├── UTIL
│ └── X2AP
├── openair3 : 3GPP LTE Rel10 for S1AP, NAS GTPV1-U for both ENB and UE. S1AP,NAS,SCTP,GTP-U在openair3下
│ ├── COMMON
│ ├── DOCS
│ ├── GTPV1-U
│ ├── M3AP
│ ├── MME_APP
│ ├── NAS
│ ├── S1AP
│ ├── SCTP
│ ├── SECU
│ ├── TEST
│ ├── UDP
│ └── UTILS
└── targets : Top-level wrappers for unitary simulation for PHY channels, system-level emulation (eNB-UE with and without S1), and realtime eNB and UE and RRH GW.
主函数结构
主函数main位于executables/nr-softmodem.c:
Main
├── load_configmodule(argc,argv,CONFIG_ENABLECMDLINEONLY) :读取nr-softmodem附带的启动参数。
├── logInit() : log初始化。
├── configure_linux() :锁定CPU状态,避免CPU因电源管理进入节能模式;设置CPU运行在超频状态。
├── itti_init(TASK_MAX, tasks_info) :为每个模块task创建数据队列。
├──init_opt():设置pcap,wireshark或tshark抓包。
├──netlink_init() :初始化网络套接字,addr,收发端口参数,最后会用于PDCP recvmsg。
├──pdcp_netlink_init()
│ └── threadCreate(&pdcp_netlink_thread, pdcp_netlink_thread_fct, (void*)NULL, "PDCP netlink", -1, OAI_PRIORITY_RT_LOW ):创建pdcp线程
│ ├──recvmsg(nas_sock_fd, &nas_msg_rx, 0):数据接收函数
│ └── lfds611_queue_guaranteed_enqueue(pdcp_netlink_queue_enb[module_id], new_data_p):将数据插入队列
├──create_gNB_tasks(1):创建gNB的一些线程
│ ├──itti_create_task(TASK_SCTP, sctp_eNB_task, NULL)
│ ├──sctp_eNB_init();
│ ├──sctp_eNB_process_itti_msg(NULL):创建socket,bind,listen
│ ├──itti_receive_msg(TASK_SCTP, &received_msg);
│ ├──sctp_create_new_listener();
│ └──sctp_send_data();
│ ├──itti_create_task(TASK_X2AP, x2ap_task, NULL)
│ ├──itti_create_task (TASK_NGAP, ngap_gNB_task, NULL) 创建NGAP线程
│ ├──ngap_gNB_init(); NGAP初始化
│ ├──ngap_gNB_process_itti_msg(NULL):NGAP编解码,UE上下文维护
│ ├── rrc_gNB_process_NGAP_DOWNLINK_NAS(msg_p, msg_name_p, instance, &rrc_gNB_mui);
│ ├──rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ(msg_p, msg_name_p, instance);
│ └──rrc_gNB_process_NGAP_PDUSESSION_RELEASE_COMMAND(msg_p, msg_name_p, instance);
│ ├──itti_create_task (TASK_UDP, udp_eNB_task, NULL)
│ ├──itti_create_task (TASK_GNB_APP, gNB_app_task, NULL)
│ ├──configure_nr_rrc(gnb_id):rrc配置
│ ├──init_pdcp():pdcp初始化
│ ├──itti_create_task(TASK_CU_F1, F1AP_CU_task, NULL)
│ └──itti_receive_msg (TASK_GNB_APP, &msg_p):从TASK_GNB_APP队列里面取数据进行处理
│ ├──itti_create_task (TASK_RRC_GNB, rrc_gnb_task, NULL):创建RRC实体
│ ├──itti_receive_msg(TASK_RRC_GNB, &msg_p):从TASK_RRC_APP队列里面取数据进行处理
│ ├──init_NR_SI(gNB_RRC_INST *rrc, gNB_RrcConfigurationReq *configuration):MIB和SIB1编码
│ ├──nr_rrc_gNB_decode_ccch(......):CCCH解码
│ └──rrc_gNB_decode_dcch(......):DCCH解码
├── init_gNB(single_thread_flag,wait_for_sync):为gNB实体分配资源以及初始化
├──init_NR_RU(get_softmodem_params()->rf_config_file):初始化RRU,内部将创建RRU相关线程
├──init_eNB_afterRU();
│ ├──phy_init_nr_gNB(gNB,0,0);phy初始化
│ └──init_gNB_Tpool(inst);
└──itti_wait_tasks_end():while死循环。