Lesson finished
Unlock all 29 lessons of 5G NR Radio Access NetworkFull course ₹40,000 · paid
NG Setup Procedure in srsRAN Code: Request and Response
A free lesson from Skill-Lync's 5G NR Radio Access Network course, on Grow by Skill-Lync · Last updated 16 Nov 2026 · Session: “Week 2 Session 1”
What will you learn in this free 5G NR Radio Access Network lesson?
The session reviews how the NG setup request and response are implemented in the srsRAN 5G code base. It follows the SCTP connection to the AMF, the request fields filled in code, and the handling of success and failure outcomes seen in Wireshark.
- Layout of the srsRAN 5G source tree
- Creating the SCTP connection to the AMF
- Fields filled in the NG setup request, including slice SST
- Run-then handling of success and failure responses
What comes after lesson 3?
Later in Skill-Lync's 5G NR Radio Access Network course (paid): lesson 4, Week 2 Session 2; lesson 5, Week 2 Session 3; lesson 6, Week 3 Session 1. The full course has 29 lessons (10 h 16 min of video); see the course overview or its price and syllabus.
Lesson transcript
Machine transcript of the lesson audio (lightly cleaned). Technical terms may contain errors; the video is the reference.
Hello and welcome back to the session, 5G NR Radio Access Network. This is our week two and today we'll discuss about the NG setup code review. In the last session, we learned about how this NG interface looks like, what is the mechanism of NG interface and what all functionalities it supports. Along with that, we also looked into the architecture of NG interface and the setup. As part of setup, we learned about what all messages are involved between RAN and core and from core to RAN. Also, we checked those messages in the live logs, what all information elements such as slice information, PLMN information which is being transferred from RAN to core and core to RAN.
Then we learned about various 5G identifiers in the 5G core, in the USM, in the UE. So, about the RAN identifiers like RNTI, we'll learn about it later. Now, today we're going to look into the code directly of the NG setup request. So, we already learned about the theory and we have already seen the logs. Now, we'll see much more about the implementation, how this NG setup and request has been implemented as part of code. Okay. So, in this session, we'll learn about the design and code of NG setup request and response in detail.
Before going directly into the NG setup request, I will just show you the code structure of SRS RAN which we'll be using for our course throughout and also we'll be doing our projects as part of that SRS RAN 5G code base. Okay. So, this is how the SRS RAN 5G code base looks like. Here, if you see, there are files which is having all the structure, the functions and everything at the right hand side. This is not just the NG setup RAN 5G code. This is having the complete RAN protocol stack starting from L1 to L3 and also it does the communication from the NGRAN.
As part of NGRAN, if you just type NG, right, if you see here, you can see all the codes like ngap.cc, ngap.h, ngap.h, ngap.pcap.h, bearer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer.barer are the functions which is having the macros and structures and every function is having pack and unpack functionalities which will be used to you know send and receive so when you receive a message it will do unpack the hex dump is unpacked and filled in the real structure similarly when you send any message out then the real structure is put into hex dump and then it will be sent out other functionality like if you open ngap ue.c you can see all the ue related function here for example initial ue message nas transport ue reconfiguration context setup response failure session response all the ue related handle ue context release and the pdv session resource setup request similarly if you open the file like ngap bearer.cc in the bearer.cc you can see all the bearer related information like add gtp bearer add pdv session reset pdv session remove gtp bearer then allocate the lc id the logical channel id which is also related to the bearer id now we'll jump on to the ngap code what is the focus of our today's session so let's get back to the slide first so ng setup code review this is our ng setup request so if you see and if you just look into the previous slides the previous session you will see that what is ng setup request and what is ng setup response request responses sent between what entities what all messages and what all information elements are involved so this is our rand session the whole course is about radio access networks so we'll be focusing mostly on the rand side so from the rand perspective we'll understand what all things are involved during the ngap setup so here we'll understand when the rand sends ngap setup how it creates what all functions are being involved and how the initialization process happen and then we'll send it the message towards the 5g core again we'll not see in the 5g core what is happening over there as we are rand we are working on the rand we'll simply wait for the response once the response will come from the 5g core then we'll see what all handlings are there in the rand how it will be handling how it will be managing okay so all the function and structure pointers have been given in the slides so for example here you can see start amf connection the first function so if you search in the code start amf connection you can see that how the rand is initiating the amf connection as the name suggests start amf connection so as we have already learned that rand does all the communication to amf for the control plane okay so first it will initiate the connection it will connect to the amf then it will start the ngap setup but before that it would have already set up its own layers it would have set up layer one layer two layer three everything will be up and now it is going to make a connection towards the 5g core network so let's get into this function start amf connection if you see this start amf connection function here in the file ngap.cc the first thing the rand checks whether ngap is running or not if it is not running then it will say ngap is not running anymore okay and it will just uh through an error then it will check whether amf connected okay amf connected then simply it will just return yes amf is connected okay and then if it is not connected okay if you'll see here if not amf connection then it will return an error so here in this function connect amf it will try to connect so first it is checking if ngap a pointer is not running it will simply throw an error then it will check if it is already connected then it will return success if it is not connected then it will trigger this connect amf okay so inside the connect amf if you see it will first create the socket sctp in its socket so uh the connection between the ran and core happens on the sctp uh transport mechanism okay so sctp is a protocol with which is similar to lte lte also having this ran and the core connection over sctp so this uh sctp connection will first initialized uh so inside this sctp connection you can see first the open socket ipv4 and the protocol type sctp so if you remember from your college days like when we make a socket connection it can be the tcp udp or sctp or any type so similarly we have to define the protocol so here we are defining the sctp protocol and it is an ipv4 mechanism then we'll go and bind the address so this all address will be received from the configuration file you need to configure those addresses in the configuration file and during the initialization of the ran it will first reads all the configuration file ip addresses port and everything and then it will just uh put it here somewhere in the structure like bind address structure bind port so if you see this would be an structure the character pointer this is a character pointer which is nothing but it will store the address then it will just do the bind just like a socket call if it is not success then it will just socket close and it will return false means your uh procedure was not success so if it is not sctp then just return false or else just go and now connect to amf so once you have created the socket at your ran side now you will use the amf address and it will just try to connect to the amf so this is how the amf connection is done so this is just the sctp still the ngap has not happened so if you go back now if you look at the slides just after the connect amf there is setup ng setup ng is nothing but it will be called from the same function start amf Connection. Once the ConnectAMF will succeed, then it will go for the SetupNG. SetupNG is nothing but the actual process. I mean, till now, till ConnectAMF, you have just created SCTP connection. So if you see in the log after this process, you can see the heartbeat between the 5G code, IP address and the RAN IP address for this SCTP connection. Now you will go on the SetupNG.
So just after ConnectAMF, if you see SetupNG, you just need to go inside this function SetupNG. In the SetupNG, you can see here there is a PLMN. So first, we are converting this MCC and MNC to the PLMN. So if you remember the logs, we send the PLMN, okay, where we have combination of MCC and MNC. Similarly, we have to implement it in the RAN, okay. Then set init message and we will give the object like ng-setup, okay, because we are initiating the ng-setup message. Then we will fill the container of ng-setup request.
Okay, so if you see this structure, okay, this is a container, okay, of this type. So if you see this container, it is a template class value T. This is a C++ code. Here you can see the RAN node name present, UE retention info, global RAN ID, supported TA list, default paging DRX, UE retention info, okay. All those information, whatever required in the ng-setup request will be filled here. Let's go back here and then you will fill the PLMN ID. You will do the GNB ID. And then there are some important part here.
If you see in the container, PLMN ID along with that, we also fill the NSSI ID, SST. SST is nothing but the slice ID. So if you remember the locks where we had filled this SST, the SD, the PLMN and everything. So this is where we are implementing that in the code. In the setup ng-message, we are implementing everything. And here we are setting some DRX value. And then we will just do the SSTP send ng-AP PDU. So as you know, this is the PDU. If you highlight it, you can see ng-AP PDU type C. This is the type, okay.
Whether it can be init message, successful outcome or unsuccessful outcome. And in this PDU, we will do the init message and everything will be filling in this PDU. And eventually this PDU will be sent out over the ng-AP interface. So to send out over this ng-AP interface, this PDU has to be used along with this name ng-setup request in this function. SSTP send ng-AP PDU. So if you click on this function, it's just behind this. You can see whatever message you are sending being used. And just over the SSTP mechanism, it will be just sent out. So you have already created this SSTP protocol between your RAN and core.
So this function will take care of sending that, okay. So till here, you should be able to, just after this function, you should be able to see that your ng-AP setup request would have been already sent to the 5G core. Now core will do the processing, okay. And the core will do the handling and whatever it has to do, the check mechanism and everything it will do. And it will just send the response to our message. So let's get back to the slide. Here you can see, just after setup the ng- message, we'll do the SSTP send ng-AP PDU. That is what we saw.
Till here, it should be able to send the ng-AP setup request. Now ng-AP setup response code review. So as we understood that just after receiving this ng-AP setup request, this 5G core will do its own processing and will just send. So now RAN will just do a wait. It will be waiting for the response to be received from the 5G code. Till that time, it will do nothing. Now here you can see ng-setup response. In the ng-setup response, you can see the first message is handle AMX RS message.
So this is an infinite message. We'll see this message first. Handle AMX RS message. Okay. So if you see, this message, this function keeps on running infinitely. Okay. So it will always keep on handling the messages. It will always open and it will see for any messages being coming from the AMF, okay, towards RAN. So you can see here handle AMF RX message. Now inside this handle AMF RX message, if you just look down, first it will see any kind of notification, message notification. If it would have received any message, it will just come here and it will call this handle ng-AP RX PDU.
If there is no any notification, it will just close the socket. It will just return from here. But once it will have some PDU, then it will just do the PDU.get. So this PDU has arrived from the 5G code. So you can see here, this is a unique byte buffer T. It is a buffer received from the 5G code. Okay. And then it will do the PDU.get. So PDU.get is passed in this function, handle ng-AP RX PDU. So if you see this function here, ng-AP handle RX PDU.
Here, as I mentioned that whenever you receive any message, you first do unpack. As you see here, this is a buffer. This buffer is nothing of, it's a class. And eventually, this will be a character type buffer. So you need to unpack this and put it in the actual structure. So if you see here, you can see here, this is U and 8 buffer. Now you have to unpack this. So first thing is to unpack here. You are doing this unpacking of the RX PDU. If it is success, then you will proceed.
Or if it is not success, then you will simply return false here. Here, this log ng-AP message, this is for the logging. So whatever you have received, you will just do and dump in the log file. And then here you have the handling, whether it is an initiate message or successful outcome or unsuccessful outcome. So this is a task for you to understand what is an init message successful and unsuccessful. I will just give a hint. If any message is being initiated, for example, this ng-AP setup request.
So this will be an init message from RAN. And RAN is waiting for a response. So this could be a successful outcome or unsuccessful outcome. So in this case, either it will go inside the successful or it can go inside the unsuccessful. But if there is any other message, for example, let's say some configuration update has to happen later on, core wants to do. Then core will initiate an init message. So that message will become an init message here in the handle ng-AP RX PDU. So you understood, right?
This is a successful outcome or unsuccessful outcome. Now let's get back to the slide. Now let's look into both. One is a handle unsuccessful outcome and handle successful outcome. So first, let's look into the unsuccessful case. So here you can see inside this, it can either go in the unsuccessful or in successful, not in the init. So in the unsuccessful first, if you see handle unsuccessful, it will just handle the setup failure. So if you see the response of ng-setup request, it can be either response success or a response failure.
So if it is an unsuccessful outcome, then must be a ng-setup failure. There may be some issue of the PLMN mismatch or slice ID mismatch or any other problem. So you will just go and call the handle ng-setup failure message. In the ng-setup failure message, you will just check the cause. You will just print and you will return true and you will do nothing. Mishandle the setup failure has happened. Now let's get back to the same function. Let's go inside the successful outcome. In the successful outcome, you see we are calling handle ng-setup response.
So you can see the difference here. In the unsuccessful, we were calling handle ng-setup failure. Here we are calling handle ng-setup response. Inside handle-setup response, you can see here, first thing is trigger. Okay. ng-setup-proc trigger. Let's get inside this trigger function. It will call handle outcome. Okay. So handle outcome. Inside handle outcome, if you see, it will just check if it's error or it is success. If it is success, then just update it with the outcome. Outcome equals to success and then call this function run then.
Run then is a virtual void function. So you just need to search it. You cannot directly go on the run then. So you just need to search and then you will see somewhere run then. Yeah. Here is the run then function. Inside the run then function, you will do rest of the things. I mean, whatever is required to do for the ng-setup response. I mean, whatever is required to do for the ng-setup response. For example, if it is a success, then you will extract the values, what you have received.
If you have received in the Boolean not success, then you will set the error message and you will proceed. So if you see all the pointers have been given in the slide, here you can see all the pointers. So unsuccessful, we saw the ng set of failure and in the successful, we saw the response, then trigger, then handle outcome and the run, then you are actually extracting the value and you are doing all the processing. So this is all about the RAN NGIP setup response handling.
So once you receive this NGIP successful outcome, then you should be able to see on the Wireshark that ng setup response has been received. It means the setup between core and the integration between core and RAN is successful. This is what you have to actually do during your first project. You have to integrate your Open 5GS code with the 5G RAN. So that is it from today's session. Let's quickly summarize whatever we learned today. So in this session, we learned about the design and code of ng setup request and response in detail.
We saw what all messages are involved when you see NGIP setup request going on Wireshark, when you see the response of that coming on the Wireshark, what happens when you get a failure, how you handle that, what happens when you get a success, I mean, NG setup response, how you handle that. That is what we learned. You can do a deep dive into the code. We also saw during the NG setup request what all things we fill in the structure and how we pass it over the interface.
So you can just deep dive into the code and understand each and every structure in detail because this is our first coding session and this is our first implementation and design session. You just need to deep dive into to understand further into much more detail. So that's it from today's session. Thank you very much.