[TOC]
# Things to know
>[!Note] Check if anything is running
>```
>sudo systemctl status <proccess name>
>```
>ex: mongod, open5gs-amfd, etc...
>
>also `sudo systemctl restart <proccess name>` for restart
>[!Note] If **(99:Cannot assign requested address)**
>just throw this in (lazy tho, but gets the job done)
>```
>sudo ip addr add <ip addr>/32 dev lo
>```
>[!Note] Search for a running proccess
>```
>ps x | grep <name>
>```
>[!Note] Kill all Open5GS NFs
>```
>pkill -f open5gs-
>```
# Download
## Open5GS
### MongoDB
```
sudo apt install gnupg
```
```
curl -fsSL https://pgp.mongodb.com/server-8.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor
```
```
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
```
```
sudo apt install -y mongodb-org
```
```
sudo systemctl start mongod
```
```
sudo systemctl enable mongod
```
### TUN
```
sudo ip tuntap add name ogstun mode tun
```
>[!Warning] ioctl(TUNSETIFF): Device or resource busy
>```
>sudo ip link delete ogstun
>```
>```
>sudo ip tuntap add name ogstun mode tun
>```
```
sudo ip addr add 10.45.0.1/16 dev ogstun
```
```
sudo ip addr add 2001:db8:cafe::1/48 dev ogstun
```
```
sudo ip link set ogstun up
```
### Open5GS
```
sudo apt install python3-pip python3-setuptools python3-wheel ninja-build build-essential flex bison git cmake libsctp-dev libgnutls28-dev libgcrypt-dev libssl-dev libmongoc-dev libbson-dev libyaml-dev libnghttp2-dev libmicrohttpd-dev libcurl4-gnutls-dev libnghttp2-dev libtins-dev libtalloc-dev meson
```
```
git clone https://github.com/open5gs/open5gs
```
```
cd open5gs
```
```
meson build --prefix=`pwd`/install
```
```
ninja -C build
```
>[!Note] Test
>```
>./build/tests/registration/registration
>```
## WebUI
### NodeJS
```
cd ~
```
```
sudo apt install -y ca-certificates curl gnupg
```
```
sudo mkdir -p /etc/apt/keyrings
```
```
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
```
```
NODE_MAJOR=20
```
```
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
```
```
sudo apt install nodejs -y
```
### WebUI
```
cd ./open5gs/webui
```
```
npm ci
```
```
npm run dev
```
>[!Note] go to http://localhost:9999
>Username: `admin`
>Password: `1423`
>Add a new subscriber
>==*IMSI = <MCC><MNC><MSIN>*==
>==*The first 5 numbers depend on how you config your MCC/MNC, in this case 00101.*==
>IMSI: `001010000000001`
>K: `465B5CE8B199B49FAA5F0A2EE238A6BC`
>AMF: `8000`
>OPc: `E8ED289DEBA952E4283B54E88E6183CA`
## UERANSIM
```
sudo apt install -y make gcc g++ libsctp-dev lksctp-tools iproute2
```
```
sudo snap install cmake --classic
```
```
cd ~
```
```
git clone https://github.com/aligungr/UERANSIM.git
```
```
cd UERANSIM
```
```
make
```
---
# Configuration
## Open5GS
- nrf
```
vim ~/open5gs/configs/open5gs/nrf.yaml.in
```
```diff=11
nrf:
serving: # 5G roaming requires PLMN in NRF
- plmn_id:
- mcc: 999
- mnc: 70
+ mcc: 001
+ mnc: 01
sbi:
server:
- address: 127.0.0.10
port: 7777
```
- amf
```
vim ~/open5gs/configs/open5gs/amf.yaml.in
```
```diff=11
amf:
sbi:
server:
- address: 127.0.0.5
port: 7777
client:
# nrf:
# - uri: http://127.0.0.10:7777
scp:
- uri: http://127.0.0.200:7777
ngap:
server:
- address: 127.0.0.5
+ port: 38412
metrics:
server:
- address: 127.0.0.5
port: 9090
guami:
- plmn_id:
- mcc: 999
- mnc: 70
+ mcc: 001
+ mnc: 01
amf_id:
region: 2
set: 1
tai:
- plmn_id:
- mcc: 999
- mnc: 70
+ mcc: 001
+ mnc: 01
tac: 1
plmn_support:
- plmn_id:
- mcc: 999
- mnc: 70
+ mcc: 001
+ mnc: 01
s_nssai:
- sst: 1
```
- upf
```
vim ~/open5gs/configs/open5gs/upf.yaml.in
```
```diff=18
gtpu:
server:
- - address: 127.0.0.7
+ - address: 10.11.0.7
session:
- subnet: 10.45.0.0/16
gateway: 10.45.0.1
- subnet: 2001:db8:cafe::/48
gateway: 2001:db8:cafe::1
metrics:
server:
- address: 127.0.0.7
port: 9090
```
## UERANSIM
- gNB
```
vim ~/UERANSIM/config/open5gs-gnb.yaml
```
```
mcc: '001' # Mobile Country Code value
mnc: '01' # Mobile Network Code value (2 or 3 digits)
nci: '0x000000010' # NR Cell Identity (36-bit)
idLength: 32 # NR gNB ID length in bits [22...32]
tac: 1 # Tracking Area Code
linkIp: 127.0.0.1 # gNB's local IP address for Radio Link Simulation (Usually same with local IP)
ngapIp: 127.0.0.1 # gNB's local IP address for N2 Interface (Usually same with local IP)
gtpIp: 127.0.0.1 # gNB's local IP address for N3 Interface (Usually same with local IP)
# List of AMF address information
amfConfigs:
- address: 127.0.0.5
port: 38412
# List of supported S-NSSAIs by this gNB
slices:
- sst: 1
# Indicates whether or not SCTP stream number errors should be ignored.
ignoreStreamIds: true
```
- UE
```
vim ~/UERANSIM/config/open5gs-ue.yaml
```
```diff=
# IMSI number of the UE. IMSI = [MCC|MNC|MSISDN] (In total 15 digits)
-supi: 'imsi-999700000000001'
+supi: 'imsi-001010000000001'
# Mobile Country Code value of HPLMN
-mcc: '999'
+mcc: '001'
# Mobile Network Code value of HPLMN (2 or 3 digits)
-mnc: '70'
+mnc: '01'
# SUCI Protection Scheme : 0 for Null-scheme, 1 for Profile A and 2 for Profile B
protectionScheme: 0
# Home Network Public Key for protecting with SUCI Profile A
homeNetworkPublicKey: '5a8d38864820197c3394b92613b20b91633cbd897119273bf8e4a6f4eec0a650'
# Home Network Public Key ID for protecting with SUCI Profile A
homeNetworkPublicKeyId: 1
# Routing Indicator
routingIndicator: '0000'
# Permanent subscription key
key: '465B5CE8B199B49FAA5F0A2EE238A6BC'
# Operator code (OP or OPC) of the UE
op: 'E8ED289DEBA952E4283B54E88E6183CA'
# This value specifies the OP type and it can be either 'OP' or 'OPC'
opType: 'OPC'
# Authentication Management Field (AMF) value
amf: '8000'
# IMEI number of the device. It is used if no SUPI is provided
imei: '356938035643803'
# IMEISV number of the device. It is used if no SUPI and IMEI is provided
imeiSv: '4370816125816151'
# Network mask used for the UE's TUN interface to define the subnet size
tunNetmask: '255.255.255.0'
# List of gNB IP addresses for Radio Link Simulation
gnbSearchList:
- 127.0.0.1
```
:arrow_up: make sure the IMSI, K, AMF and OPc matches your subscriber
---
# Execution
## Open5GS
```
cd ~/open5gs/
```
```
sudo ./install/bin/open5gs-nrfd
```
```
sudo ./install/bin/open5gs-scpd
```
```
sudo ./install/bin/open5gs-amfd
```
```
sudo ./install/bin/open5gs-smfd
```
```
sudo ./install/bin/open5gs-ausfd
```
```
sudo ./install/bin/open5gs-udmd
```
```
sudo ./install/bin/open5gs-udrd
```
```
sudo ./install/bin/open5gs-pcfd
```
```
sudo ./install/bin/open5gs-nssfd
```
```
sudo ./install/bin/open5gs-bsfd
```
```
sudo ./install/bin/open5gs-upfd
```
or just run
```
sudo ./install/bin/open5gs-nrfd & sudo ./install/bin/open5gs-scpd & sudo ./install/bin/open5gs-amfd & sudo ./install/bin/open5gs-smfd & sudo ./install/bin/open5gs-ausfd & sudo ./install/bin/open5gs-udmd & sudo ./install/bin/open5gs-udrd & sudo ./install/bin/open5gs-pcfd & sudo ./install/bin/open5gs-nssfd & sudo ./install/bin/open5gs-bsfd & sudo ./install/bin/open5gs-upfd &
```
if you know for sure that all of them above are running with no issue
## UERANSIM
```
cd ~/UERANSIM
```
- gNB
```
sudo ./build/nr-gnb -c config/open5gs-gnb.yaml
```
- UE
```
sudo ./build/nr-ue -c config/open5gs-ue.yaml
```
# Execute using tmux script
>[!Note]
>These scripts will open each service in a new window in the session, go through each windows by clicking
>==Ctrl+B== ++*release keys*++ and click:
>==N== to the next window
>==P== to the previous window
>==number== to the specific window
```
sudo apt install tmux
```
## Open5GS
### make script
```
cd ~/open5gs
```
```
touch ./runOpen5GS.sh
```
```
vim ./runOpen5GS.sh
```
```bash=
#!/bin/bash
session="open5gs"
services=(nrfd scpd amfd smfd ausfd udmd udrd pcfd nssfd bsfd upfd)
tmux new-session -d -s "$session"
first="${services[0]}"
tmux rename-window -t "$session:0" "$first"
tmux send-keys -t "$session:0" "sudo ./install/bin/open5gs-$first" C-m
for i in $(seq 1 $((${#services[@]}-1))); do
NewSvc="${services[$i]}"
tmux new-window -t "$session:$i" -n "$NewSvc"
tmux send-keys -t "$session:$i" "sudo ./install/bin/open5gs-$NewSvc" C-m
done
tmux select-window -t "$session:0"
tmux attach-session -t "$session"
```
```
chmod +x runOpen5GS.sh
```
### run script
```
~/open5gs/runOpen5GS.sh
```
>[!Note] Still needs to type in password for each services
## UERANSIM
### make script
```
cd ~/UERANSIM
```
```
touch ./runUERANSIM.sh
```
```
vim ./runUERANSIM.sh
```
```bash=
#!/bin/bash
session="UERANSIM"
tmux new-session -d -s "$session"
tmux rename-window -t "$session:0" "gnb"
tmux send-keys -t "$session:0" "sudo ./build/nr-gnb -c config/open5gs-gnb.yaml" C-m
tmux new-window -t "$session:1" -n "ue"
tmux send-keys -t "$SESSION:1" "sudo ./build/nr-ue -c config/open5gs-ue.yaml" C-m
tmux select-window -t "$session:0"
tmux attach-session -t "$session"
```
```
chmod +x runUERANSIM.sh
```
### run script
```
~/UERANSIM/runUERANSIM.sh
```
>[!Note] Still needs to type in password for each services
## To kill the sessions and processes
```
sudo pkill -f 'open5gs-'
```
```
tmux kill-session -t open5gs
```
```
tmux kill-session -t UERANSIM
```