open5gs/docs/_docs/platform/07-freebsd.md

243 lines
6.9 KiB
Markdown
Raw Normal View History

2021-02-08 19:25:40 +00:00
---
title: FreeBSD
head_inline: "<style> .blue { color: blue; } </style>"
---
2022-11-21 13:06:29 +00:00
This guide is based on **FreeBSD-13.1-STABLE**.
2021-02-08 19:25:40 +00:00
{: .blue}
2022-11-21 13:06:29 +00:00
## Install **FreeBSD-13.1-STABLE** from Vagrant box (optional)
2021-02-08 19:25:40 +00:00
---
Vagrant provides a simple way to create and deploy Virtual Machines from
pre-built images using VirtualBox, libvirt, or VMWare as a hypervisor engine.
This allows the user to quickly create a virtual machine without the hassle
of installing the operating system by hand.
### Install Vagrant
---
The instructions to install Vagrant are provided at
[vagrantup.com](https://www.vagrantup.com/).
2022-11-21 13:06:29 +00:00
### Create a FreeBSD-13.1-STABLE Virtual Machine using Vagrant
2021-02-08 19:25:40 +00:00
---
Use the supplied `Vagrantfile` in the `vagrant` directory to create the
virtual machine.
2022-11-21 13:06:29 +00:00
Note that this Vagrantfile is identical to the base FreeBSD 13 box, with
2021-02-08 19:25:40 +00:00
the exception that the amount of virtual memory has been increased to 1GB:
```bash
cd vagrant/freebsd
vagrant up --provider virtualbox
```
### Log into the newly created FreeBSD VM
---
2022-11-21 13:06:29 +00:00
Use SSH to log into the FreeBSD 13 VM:
2021-02-08 19:25:40 +00:00
```bash
vagrant ssh
```
Note that the Open5GS source is *not* copied into the VM. The instructions
below provide the step by step instructions for setting up Open5GS for
2022-11-21 13:06:29 +00:00
either a bare metal or virtual FreeBSD 13 system.
2021-02-08 19:25:40 +00:00
The rest of the commands below are performed inside the FreeBSD VM as the
2022-11-21 13:06:29 +00:00
user 'vagrant', or on your bare metal FreeBSD 13 system as any normal user.
2021-02-08 19:25:40 +00:00
### Getting MongoDB
---
Install MongoDB with package manager.
```bash
2022-11-21 13:06:29 +00:00
$ sudo pkg install mongodb50
2021-02-08 19:25:40 +00:00
```
Run MongoDB server.
```bash
$ mkdir -p ./data/db
$ mongod --dbpath ./data/db
```
### Setting up network (No persistent after rebooting)
---
Configure the loopback interface.
```bash
$ sudo ifconfig lo0 alias 127.0.0.2 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.3 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.4 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.5 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.5 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.6 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.7 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.8 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.9 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.10 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.11 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.12 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.13 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.14 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.15 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.16 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.17 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.18 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.19 netmask 255.255.255.255
$ sudo ifconfig lo0 alias 127.0.0.20 netmask 255.255.255.255
2022-09-24 12:58:18 +00:00
$ sudo ifconfig lo0 alias 127.0.1.10 netmask 255.255.255.255
2021-02-08 19:25:40 +00:00
```
Enable IP forwarding
```bash
$ sudo sysctl -w net.inet.ip.forwarding=1
$ sudo sysctl -w net.inet6.ip6.forwarding=1
```
**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/main/misc/netconf.sh) makes it easy to configure the TUN device as follows:
2021-02-08 19:25:40 +00:00
`$ sudo ./misc/netconf.sh`
{: .notice--info}
2022-11-21 13:06:29 +00:00
### Load the SCTP kernel module
---
Update `/etc/rc.conf` to load the SCTP kernel module.
```diff
$ diff -u /etc/rc.conf.old /etc/rc.conf.new
--- /etc/rc.conf.old 2022-11-19 12:35:07.718151000 +0000
+++ /etc/rc.conf.new 2022-11-19 12:34:59.160560000 +0000
@@ -11,3 +11,4 @@
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
+kld_list="sctp"
```
This is important that you must reboot as shown below.
```bash
[host] $ vagrant halt
[host] $ vagrant up --provider virtualbox
[host] $ # ssh back into the VM after it reboots...
[host] $ vagrant ssh
```
2021-02-08 19:25:40 +00:00
### Building Open5GS
---
Install the depedencies for building the source code.
```bash
2022-11-21 13:06:29 +00:00
$ sudo pkg install meson cmake ninja gcc bison gsed pkgconf git cmake mongo-c-driver gnutls libgcrypt libidn libyaml libmicrohttpd nghttp2 talloc
2021-02-08 19:25:40 +00:00
```
Configure gcc PATH
```bash
$ setenv LIBRARY_PATH /usr/local/lib
$ setenv C_INCLUDE_PATH /usr/local/include
```
If you are using BASH instead of default CSH,
```bash
$ export LIBRARY_PATH=/usr/local/lib
$ export C_INCLUDE_PATH=/usr/local/include
```
Git clone.
```bash
$ git clone https://github.com/{{ site.github_username }}/open5gs
```
To compile with meson:
```bash
$ cd open5gs
$ meson build --prefix=`pwd`/install
$ ninja -C build
```
2022-11-21 13:06:29 +00:00
**Note:** No source code changes are required for FreeBSD 11.x version. However, in FreeBSD 12.x/13.x version, we'll getting a crash with segmentation fault when calling basename(3). To avoid this, you need to change the freeDiameter source code as below.
2021-02-08 19:25:40 +00:00
{: .blue}
```diff
$ cd open5gs/subprojects/freeDiameter
$ diff --git a/include/freeDiameter/libfdproto.h b/include/freeDiameter/libfdproto.h
index 52c11ef..cd7f383 100644
--- a/include/freeDiameter/libfdproto.h
+++ b/include/freeDiameter/libfdproto.h
@@ -293,7 +293,7 @@ extern int fd_g_debug_lvl;
/* A version of __FILE__ without the full path. This is specific to each C file being compiled */
static char * file_bname = NULL;
-static char * file_bname_init(char * full) { file_bname = basename(full); return file_bname; }
+static char * file_bname_init(char * full) { file_bname = __old_basename(full); return file_bname; }
#define __STRIPPED_FILE__ (file_bname ?: file_bname_init((char *)__FILE__))
```
Now, compile again:
{: .blue}
```bash
$ cd open5gs
$ ninja -C build
```
Check whether the compilation is correct.
**Note:** This should require *sudo* due to access `/dev/tun0`.
{: .notice--danger}
```bash
$ sudo ./build/tests/attach/attach ## EPC Only
$ sudo ./build/tests/registration/registration ## 5G Core Only
```
Run all test programs as below.
**Note:** This should require *sudo* due to access `/dev/tun0`.
{: .notice--danger}
```bash
$ cd build
$ sudo meson test -v
```
**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || pfcp || diameter || gtp || ngap || http2.data.data || http2.headers`. You can see the virtually created packets. [testattach.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testattach.pcapng)/[testregistration.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testregistration.pcapng)
{: .notice--info}
You need to perform the **installation process**.
```bash
$ cd build
$ ninja install
$ cd ../
```
### Building WebUI of Open5GS
---
[Node.js](https://nodejs.org/) is required to build WebUI of Open5GS
```bash
2022-11-21 13:06:29 +00:00
$ sudo pkg install npm
2021-02-08 19:25:40 +00:00
```
Install the dependencies to run WebUI
```bash
$ cd webui
$ npm ci
2021-02-08 19:25:40 +00:00
```
The WebUI runs as an [npm](https://www.npmjs.com/) script.
```bash
$ npm run dev
```