:::warning
# <center><i class="fa fa-edit"></i> Initialization of E2 agents</center>
:::
[TOC]
### Source code
```c
sleep(2);
const gNB_RRC_INST* rrc = RC.nrrrc[mod_id];
assert(rrc != NULL && "rrc cannot be NULL");
const int mcc = rrc->configuration.mcc[0]; // 208;
const int mnc = rrc->configuration.mnc[0]; // 94;
const int mnc_digit_len = rrc->configuration.mnc_digit_length[0]; // 2;
const int nb_id = rrc->configuration.cell_identity; //42;
sm_io_ag_t io = {.read = read_RAN, .write = write_RAN};
printf("[E2 NODE]: mcc = %d mnc = %d mnc_digit = %d nd_id = %d \n", mcc, mnc, mnc_digit_len, nb_id);
init_agent_api( mcc, mnc, mnc_digit_len, nb_id, io);
```
### Explanation of functions and variables
| Variable/function | explanation |
| ----------------- | ---------------------- |
| gNB_RRC_INST | security configuration |
| rrc | radio resource control |
| RC | condition variable fo signaling setup completion of an RU |
| nrrrc |NR RRC context variables|
| mcc |mobile country code |
| mnc |mobile network code |
| sm_io_ag_t |The SM agent uses read_RAN and write_RAN functions to communicate with the RAN and with the server|
| cell_identity | identifier for a Base Transceiver Station in mobile phone networks. It consists of four parts: Mobile Country Code (MCC), Mobile Network Code (MNC), Location Area Code (LAC) and Cell Identification (CI).|
### read_RAN
```c
void read_RAN(sm_ag_if_rd_t* data)
{
assert(data != NULL);
assert(data->type == MAC_STATS_V0
|| data->type == RLC_STATS_V0
|| data->type == PDCP_STATS_V0
);
if(data->type == MAC_STATS_V0 ){
read_mac_sm(&data->mac_stats.msg);
}else if(data->type == RLC_STATS_V0) {
read_rlc_sm(&data->rlc_stats.msg);
} else if(data->type == PDCP_STATS_V0){
read_pdcp_sm(&data->pdcp_stats.msg);
} else {
assert(0!=0 && "Unknown data type!");
}
}
```
This function is reading MAC, PDCP and RLC
| Variable/functions | explanation |
| ------------------ | ----------- |
| MAC_STATS_V0 | variable reading a data of MAC|
| RLC_STATS_V0 | variable reading a data of RLC|
| PDCP_STATS_V0 | variable reading a data of PDCP|
### write_RAN
```c
sm_ag_if_ans_t write_RAN(sm_ag_if_wr_t const* data)
{
assert(data != NULL);
assert(0!=0 && "Not implemented");
sm_ag_if_ans_t ans = {.type = MAC_AGENT_IF_CTRL_ANS_V0 };
return ans;
}
```