# 5G Core - The Installation of 5G Core(free5gc)
## Prerequisites
### Linux Kernel Version
Kernel mus version 5.0.0-23-generic or 5.4.x version of the Linux kernel. free5gc uses the gtp5g kernel module, which has been tested and compiled against that kernel versions only.
```
uname -r
```

### Install Golang
Install Golang with compatible version :
````
wget https://dl.google.com/go/go1.18.10.linux-amd64.tar.gz
sudo tar -C /usr/local -zxvf go1.18.10.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
````






### Control-plane Supporting Packages
Install Mongodb for Supporting Control-Plane :
```
sudo apt -y update
sudo apt -y install mongodb wget git
sudo systemctl start mongodb
```


### User-plane Supporting Packages
Install Many Depedencies for Supporting User-Plane :
```
sudo apt -y update
sudo apt -y install git gcc g++ cmake autoconf libtool pkg-config libmnl-dev libyaml-dev
```

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



## Install Control Plane Elements
### Clone the free5GC repository (stable version)
install the latest stable build (v3.3.0):
```
cd ~
git clone --recursive -b v3.3.0 -j `nproc` https://github.com/free5gc/free5gc.git
cd free5gc
```

### Compile network function services in free5gc
Compile network function services in free5gc. This command invokes the make tool to build the free5gc project. The Makefile in the root of the project directory specifies the build process, which may involve compiling source code, linking object files, and producing executable files.
```
cd ~/free5gc
make
```


## Install User Plane Function (UPF)
### Retrieve the 5G GTP-U kerne
Retrieve the 5G GTP-U kernel module using git and build it
```
git clone -b v0.8.3 https://github.com/free5gc/gtp5g.git
cd gtp5g
make
sudo make install
```



### Build the UPF
Build the UPF using
```
cd ~/free5gc
make upf
```

## Install WebConsole
### Install nodejs and yarn packages
```
sudo apt remove cmdtest
sudo apt remove yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install -y nodejs yarn
```


### Build WebConsole
The command ‘cd ~/free5gc’ changes the current directory to the free5gc directory in the user’s home directory. The next command make webconsole builds the web console module of the free5gc project.
```
cd ~/free5gc
make webconsole
```

The command go run server.go runs a Go program called server.go.
```
go run server.go
```



## Test free5GC
### Execute Run.sh
```
sudo ./run.sh
```

### Run the tests
```
cd ~/free5gc
make upf
chmod +x ./test.sh
```

#### Test Registration
The TestRegistration function is employed for enrolling a user into the 5G Core Network through the submission of a registration request to both the Authentication and Authorization Server (AUSF) and the Home Subscriber Server (HSS). This function oversees the registration procedure by validating the user's identity and authentication details, creating and storing session keys, and furnishing essential information to other network functions for subsequent communication.
```
./test.sh TestRegistration
```


#### Test GUTI Registration
The TestGUTIRegistration function is employed to enroll a user utilizing their GUTI. It forwards a registration request to the MME, where the GUTI is verified, and essential authentication and authorization procedures are conducted in collaboration with the AUSF and HSS. Upon successful registration, the MME assigns a permanent identity to the user, referred to as the Subscriber Permanent Identifier (SUPI), which is utilized for subsequent communication with the user.
```
./test.sh TestGUTIRegistration
```


#### Test Service Request
TestServiceRequest is a testing function designed to simulate service requests initiated by users within the 5G Core Network. This function creates a service request message and transmits it to the SEAF (Service Authorization Function) to assess user authorization and evaluate network conditions. Upon authorization, the SEAF dispatches a response message to TestServiceRequest, which then proceeds to configure the essential resources for the requested service.
```
./test.sh TestServiceRequest
```


#### Test PDU Session Release Request
The TestPDUSessionReleaseRequest is a testing function designed to simulate the release of a PDU (Packet Data Unit) session. It accomplishes this by generating a release request message and transmitting it to the SMF (Session Management Function). This process facilitates the termination of the PDU session and involves releasing the allocated resources for the session through communication with other network functions.
```
./test.sh TestPDUSessionReleaseRequest
```


#### Test Paging
The TestPaging function is a testing procedure that simulates the paging process. It does so by triggering a paging request, facilitating the exchange of messages among the network functions participating in the procedure, and establishing the essential resources for the requested service.
```
./test.sh TestPaging
```


#### Test N2Handover
The TestN2Handover function serves as a testing mechanism that emulates the N2 handover procedure. This simulation involves the exchange of messages among the source gNB, target gNB, and other network functions engaged in the handover process. The primary objective is to enable the seamless transfer of both the control plane and user plane connections from the source gNB to the target gNB. Throughout this process, the session and routing information for the user are preserved.
```
./test.sh TestN2Handover
```


#### Test ReSynchronization
The TestReSynchronization function is a testing utility that emulates the Re-Synchronization procedure within the network. This involves initiating the procedure, facilitating the exchange of messages among the network functions participating in the process, and validating the re-establishment of synchronization between these network functions. This simulation is particularly relevant after experiencing a temporary loss of synchronization.
```
./test.sh TestReSynchronization
```


#### Test ULCL
The TestULCL function is a testing feature designed to simulate the ULI Consolidation List (ULCL) procedure. This simulation involves triggering the consolidation of ULI (User Location Information) from multiple sources into a unified list. The process includes validating the successful consolidation and generating a response based on the outcome of the consolidation.
```
./test_ulcl.sh TestRequestTwoPDUSessions
```


#### Test Deregistration
The TestDeregistration function serves as a testing mechanism for simulating user deregistration within the network. This involves generating a deregistration request message and transmitting it to the AMF (Access and Mobility Management Function). The purpose is to facilitate the discontinuation of the user's connection with the network and subsequently release the resources allocated to the user through communication with other network functions.
```
./test.sh TestDeregistration
```


## Install Ueranism
### Install Ubuntu Server
#### Update Ubuntu Server
```
sudo apt update
```

#### Change Hostname with 'ueranism'
```
sudo adduser ueranism
```

Change IP Local to specifiec hostname :
```
sudo nano /etc/hosts
```

Make user ueranism have permission sudo :
```
sudo usermod -aG sudo ueranism
```

### Change Static IP Address
Change IP in NAT for IP Static like installation guide :

### Clone Repo Ueransim
```
cd ~
git clone https://github.com/aligungr/UERANSIM
cd UERANSIM
git checkout v3.1.0
```

### Update and Upgrade UERANSIM
```
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
```


### Add Subscriber in Web Console

### Change IP Address Free5gc












THANK YOU