---
# System prepended metadata

title: Project documentation template
tags: [Documentation, Templates]

---

---
title: 'Installation free5gc and UERANSIM'
disqus: hackmd
---

Installation Free5gc and UERANSIM
===

[TOC]
## Installing Free 5GC 

First we need to:
A. Prerequisites
* Install Golang 
a. As noted above, free5gc is built and tested with Go 1.17.8
b. To check the version of Go on your system, from a command prompt:

`go version`
  
![image](https://hackmd.io/_uploads/HJZeq_Wta.png)
Figure 1. Result go version
    
c. If another version of Go is installed, remove the existing version and install Go 1.17.8, this assumes your current version of Go is in the default location: 
    
```
sudo rm -rf /usr/local/go 
wget https://dl.google.com/go/go1.17.8.linux-amd64.tar.gz
sudo tar -C /usr/local -zxvf go1.17.8.linux-amd64.tar.gz
```

   ![image](https://hackmd.io/_uploads/ByJjj_WF6.png)

d. If Go is not installed on your system:
```
wget https://dl.google.com/go/go1.17.8.linux-amd64.tar.gz
sudo tar -C /usr/local -zxvf go1.17.8.linux-amd64.tar.gz mkdir -p ~/go/{bin,pkg,src}
```
##### The following assume that your shell is bash 
    echo 'export GOPATH=$HOME/go' >> ~/.bashrc 
    echo 'export GOROOT=/usr/local/go' >> ~/.bashrc 
    echo 'export PATH=$PATH:$GOPATH/bin:$GOROOT/bin' >> ~/.bashrc 
    echo 'export GO111MODULE=auto' >> ~/.bashrc 
    source ~/.bashrc

![image](https://hackmd.io/_uploads/rJyI9tWYa.png)


![image](https://hackmd.io/_uploads/SJc_auZtT.png)
Figure 3. Result installing go last version

    
e. Further information and installation instructions for golang are available at the [official golang site](https://go.dev/doc/install). 

##### Control-plane Supporting Packages
    
    sudo apt -y update 
    sudo apt -y install mongodb wget git 
    sudo systemctl start mongodb 

![image](https://hackmd.io/_uploads/ryM5R_-tT.png)

![image](https://hackmd.io/_uploads/Hy590dWFa.png)

Figure 4. Result update and install monggo wget

##### User-plane Supporting Packages 

    sudo apt -y update 
    sudo apt -y install git gcc g++ cmake autoconf
    libtool pkg-config libmnl-dev libyaml-dev 

![image](https://hackmd.io/_uploads/r1O9JYbFp.png)
Figure 5. Result update and install user-plane Supporting Packages

#### Linux Host Network Settings
```
sudo sysctl -w net.ipv4.ip_forward=1 
sudo iptables -t nat -A POSTROUTING -o <dn_interface> -j MASQUERADE 
sudo iptables -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1400 
sudo systemctl stop ufw 
```

#### A.	Install Control Plane Elements
Clone the free5GC repository

a. To Install the latest stable build (v3.2.1)
```
cd ~ 
git clone --recursive -b v3.2.1 -j `nproc` https://github.com/free5gc/free5gc.git 
cd free5gc
```

b. Alternatively to Install the latest nightly build:
```
cd ~/free5gc 
    git checkout main 
    git submodule sync 
    git submodule update --init --jobs `nproc` 
    git submodule foreach git checkout main 
    git submodule foreach git pull --jobs `nproc`
```

Compile network function services in free5gc

a. To do so individually (e.g., AMF only):
```
cd ~/free5gc 
    make amf
```
b. To build all network functions: 
```
cd ~/free5gc 
    make 
```

#### B. Install User Plane Function (UPF)

As noted above, the GTP kernel module used by the UPF requires that you use Linux kernel version 5.0.0-23-generic or 5.4.x. To verify your version: 

`uname -r`

![image](https://hackmd.io/_uploads/H1ZWftWKa.png)
Figure 7. result Linux version 

Retrieve the 5G GTP-U kernel module using git and build it

```
git clone -b v0.6.8 https://github.com/free5gc/gtp5g.git 
cd gtp5g 
make 
sudo make install
```
![image](https://hackmd.io/_uploads/r1NzVFWYp.png)
Figure 8. result GTP-U install


## Installing UERANSIM

* download UERANSIM 
```
cd ~ 
git clone https://github.com/aligungr/UERANSIM 
cd UERANSIM 
git checkout v3.1.0 
```

* Update and upgrade ueransim VM first:
```
sudo apt update 
sudo apt upgrade
``` 

* Install required tools:
```
sudo apt install make 
sudo apt install g++ 
sudo apt install libsctp-dev lksctp-tools 
sudo apt install iproute2 
sudo snap install cmake --classic 
```

* Build UERANSIM 
```
cd ~/UERANSIM 
make 
```
 
if UERANSIM successful it look like this 

* If you are a total beginner to thhvkvgcct
> - [ ] 1. * ![Uploading file..._krz3c7r4o]()


1. Visit hackmd.io
2. Click "Sign in"
3. Choose a way to sign in
4. Start writing note!

Configuring free5GC and UERANSIM 
---

```gherkin=
Feature: Guess the word

  # The first example has two steps
  Scenario: Maker starts a game
    When the Maker starts a game
    Then the Maker waits for a Breaker to join

  # The second example has three steps
  Scenario: Breaker joins a game
    Given the Maker has started a game with the word "silky"
    When the Breaker joins the Maker's game
    Then the Breaker must guess a word with 5 characters
```
> I choose a lazy person to do a hard job. Because a lazy person will find an easy way to do it. [name=Bill Gates]


```gherkin=
Feature: Shopping Cart
  As a Shopper
  I want to put items in my shopping cart
  Because I want to manage items before I check out

  Scenario: User adds item to cart
    Given I'm a logged-in User
    When I go to the Item page
    And I click "Add item to cart"
    Then the quantity of items in my cart should go up
    And my subtotal should increment
    And the warehouse inventory should decrement
```

> Read more about Gherkin here: https://docs.cucumber.io/gherkin/reference/

Running UERANSIM against free5GC 
---
```sequence
Alice->Bob: Hello Bob, how are you?
Note right of Bob: Bob thinks
Bob-->Alice: I am good thanks!
Note left of Alice: Alice responds
Alice->Bob: Where have you been?
```

> Read more about sequence-diagrams here: http://bramp.github.io/js-sequence-diagrams/

Call Flow 5GC  
---


---


# **5G Network Elements & Function**

**AMF (Access and Mobility Management Function)**

The AMF will take rol in knowing the subscriber mobility, registration and security.
It will know the location of the subscriber, or at least the default location of the subscriber when it is required
The AMF will also be communication with other NE for subscriber-related informations
Take part in the authentication of the subscriber and also providing GUTI which is a temporarty identifier for the UE, after the device send a SUCI key and have been decrypted by the UDM.

**SMF (Session Management Function)**
The SMF will be taking the role session management related task such as PCF (Policy Control Function) interaction for the data network profile, UPF (User Plane Function) and IP allocation.

The SMF will communicate with the PCF for QoS and Policy related information
Assigning IP to UE for IP required task
Selection of UPF(Because there are usually multiple upf in the 5G Core)

**UDM (Unified Data Management)**
The UDM will be taking the role in access authorization, registration and mobility management and data network profile. It contains the registry of the subscriber information and data network profile.

**NRF (Network Repository Function)**
The NRF will be responsible for managing the network functions in the 5G Core for registration and the discovering of new NF

**UPF (User Plane Function)**
The UPF is where all the user data will go through after the PDU session is established. It will also become an anchor point for the GnodeB, because the UE will probably change GnodeB over time but could have the same UPF. Other than that the UPF will also implement the QoS and Policy that is set by the PCF.

**NSSF (Network Slice Selection Function)**
The NSSF will be responsible to decide which UE will use which slice of the network

**AUSF (Authentication Service Function)**
The AUSF will basically responsible for the authentication of the UE

**AF (Application Function)**
The AF is basically an application and is connected to the PCF for related charging-task.

**NEF (Network Exposure Function)**
The NEF will be responsible for internet and third party related task. So the NEF will provide an API to those services.

**NSSAAF (Network Slice Specific Authorization and Authentication Function)**
The NSSAF will be responsible when a specific Network Slice is required to have Authorization and Authentication services.

**PCF (Policy Control Function)**
The PCF will be responsible for the dynamic policy decision based on the resources in the present time. It will also enforce policy base on the subscriber level of subscription to ensure the level of QoS that the UE will be given.

**Personal Notes on 5G Core**
The target is to make PDU sessions with customized QoS Flow based on the UE user subscription

First the UE will connect to the amf which the AMF will be taking the role of Access point of the 5G Core. In this session building process the UE will send a SUCI key that will be sent to the UDM to be Decrypted. Then the UE will get a GUTI which is a temporary key for the identifier of the UE. After that and the session is built by the SMF where it will applies also policies from UDM and PCF to the UPF. Then the UE will have the session through the GnodeB (Next Generation) UPF and Data Network Sequencially.

**Additional Notes**
In case of changing GNode B the UPF will remain the same but the GNode B changes

The smf will also assign upf to the UE. SMF will also responsible for assigning IP address if the traffic requires it.

Network elements in the 5g core is registered in the NRF in case of registration and deregistration.

PCF applies dynamic policies on its network condition even if the subscriber have high subscription level

AMF knows the location, atleast the default location of the UE in the network.







gantt
    title A Gantt Diagram

    section Section
    A task           :a1, 2014-01-01, 30d
    Another task     :after a1  , 20d
    section Another
    Task in sec      :2014-01-12  , 12d
    anther task      : 24d
```

> Read more about mermaid here: http://mermaid-js.github.io/mermaid/

## Appendix and FAQ

:::info
**Find this document incomplete?** Leave a comment!
:::

###### tags: `Templates` `Documentation`
