Setting up environment - mariotlemes/non3GPP-WiFi GitHub Wiki

Y1 Interface - Conection between UE and AP

On your host, install the necessary packages:

sudo apt-get update && sudo apt-get install dnsmasq hostapd wget -y

To create wlan0 and wlan1 wireless cards with mac80211_hwsim:

sudo modprobe mac80211_hwsim radios=2

The argument radios=2 defines how many virtual interfaces will be created and defaults to two devices. After successfully loading the kernel module, wlan0 and wlan1 are showing up, as shown in figure below (execute iwconfig). The third interface that pops up is hwsim0 that is a virtual interface for debugging purposes, where you could listen to all radio frames on all channels. We won’t need it for this guide.

iwconfig

We are going to create network namespaces: i) APns for interface wlan0 and ii) UEns for interface wlan1.

To create a network namespace for UEns and APns:

sudo ip netns add APns
sudo ip netns add UEns

In other terminal, type:

# Run this in a separate shell.
sudo ip netns exec APns bash
echo $BASHPID

The resulted expected is like below. In this tutorial, the bash pid is 3065 (in your case, it will be another number)

bash pid

At the first terminal, type:

# Run this command with your bash pid instead of 3065
sudo iw phy phy0 set netns 3065 # you must have to change the bash pid (APns)

In other terminal, type:

# Run this in a separate shell.
sudo ip netns exec UEns bash
echo $BASHPID

At the first terminal, type:

# Run this command with your bash pid instead of 3065
sudo iw phy phy1 set netns 3065 # you must have to change the bash pid (UEns)

At this point, wlan0 interface is in APns namespace and wlan1 at UEns namespace. Note in the figure that wlan0 is isolated.

second terminal

Apply the settings for wlan0:

sudo ip netns exec APns ip addr add 192.168.1.10/24 dev wlan0

To create the dnsmasq.conf file:

sudo killall dnsmasq
sudo touch ~/dnsmasq.conf && sudo chmod 666 ~/dnsmasq.conf
echo -e "interface=wlan0\ndhcp-range=192.168.1.2,192.168.1.254,255.255.255.0,12h\nserver=8.8.8.8\nlog-queries\nlog-dhcp\nlisten-address=127.0.0.1\ndhcp-host=02:00:00:00:01:00,192.168.1.1" > ~/dnsmasq.conf

Initializing dnsmasq.conf:

sudo ip netns exec APns dnsmasq -C ~/dnsmasq.conf -D

To create the hostapd.conf file:

sudo touch ~/hostapd.conf && sudo chmod 666 ~/hostapd.conf
echo -e "interface=wlan0\ndriver=nl80211\nssid=my5gcore\nchannel=0\nhw_mode=b\nwpa=3\nwpa_key_mgmt=WPA-PSK\nwpa_pairwise=TKIP CCMP\nwpa_passphrase=my5gcore\nauth_algs=3\nbeacon_int=100" > ~/hostapd.conf

Initializing hostapd.conf to wlan0. At the end of this process, wlan0 will become an access point:

sudo ip netns exec APns hostapd ~/hostapd.conf -B

The expected result is like below:

hostapd background

To create the wpa_supplicant.conf file:

  sudo touch ~/wpa_supplicant.conf && sudo chmod 666 ~/wpa_supplicant.conf
  echo -e 'network={\nssid="my5gcore"\nkey_mgmt=WPA-PSK\npsk="my5gcore"\n}' > ~/wpa_supplicant.conf

Apply the settings for wlan1:

sudo killall wpa_supplicant
sudo ip netns exec UEns wpa_supplicant -i wlan1 -c ~/wpa_supplicant.conf -B 
sudo ip netns exec UEns dhclient wlan1

To remove the default route from UE:

sudo ip netns exec UEns route del -net 0.0.0.0 gw 192.168.1.10 netmask 0.0.0.0 dev wlan1

Check connection between UE and AP

At this point, the virtual interface wlan1 (ip address 192.168.1.1/24) is connected to wlan0 (ip address 192.168.1.10/24) which acts as a WiFi access point.

sudo ip netns exec UEns iwconfig

If success, the output of the command above will be like below:

success y1 interface

You can also check the IP address configuration of wlan1 interface.

sudo ip netns exec UEns ip addr show wlan1

The ip add address of the wlan1 interface must be 192.168.1.1/24.

ip address wlan1

Y2 Interface - Conection between AP and N3IWF

The connection between AP and N3IWF will be made by veth (virtual ethernet) and the AP will be able to able to route messages between UE and N3IWF. The ip addressing for the logical interface Y2 and the virtual interfaces are shown in the figure below:

y2 interface

Setting-up environment

# Clone the repository
cd ~
git clone https://github.com/mariotlemes/non-3GPP-WiFi.git

# Enable forwarding, stop ufw, install module gtp5g and add rule on iptables 
cd ~/non-3GPP-WiFi
sudo ./utils/fix_core.sh
 
# Backup of the config folder
cd ~/my5G-core
mv -f config config.orig

# Using sample1 folder for configuration
cp -R sample/sample1/ config

# Backup of upf config
mv -f src/upf/build/config/upfcfg.yaml src/upf/build/config/upfcfg.yaml.orig

# New configuration for upf
cp src/upf/config/upfcfg.sample1.yaml src/upf/build/config/upfcfg.yaml

# set UE http bind address 
sed -i 's/HttpIPv4Address: .*/HttpIPv4Address: 192.168.1.1/' config/uecfg.conf

# Remove database due to previews tests
mongo free5gc --eval "db.dropDatabase()"

# Run webconsole
go build -o bin/webconsole -x webconsole/server.go
./bin/webconsole &

# Add the UE that will be used in the test
~/my5G-core/sample/sample1/utils/add_test_ue.sh

Setting namespaces, interfaces and routes

# Backup env_manager.sh file
cd ~/my5G-core/sample/sample1/utils
mv env_manager.sh env_manager.sh-ori

# Copy the env_manager.sh file from the repository
sudo cp ~/non-3GPP-WiFi/utils/env_manager.sh ~/my5G-core/sample/sample1/utils/

# Setup network interfaces and namespaces
./env_manager.sh up $(ip route | grep default | cut -d' ' -f5)

Starting monitoring tools

# Wireshark for global namespace
wireshark -kni any --display-filter "isakmp or nas-5gs or ngap or pfcp or gtp or esp or gre" &

Starting UPF

# Use a new terminal so we can easily see the logs
cd ~/my5G-core/sample/sample1/utils
./run_upf.sh 

Running the other NFs in my5G-core network

Run the components of core in this order: NFR->AMF->SMF->UDR->PCF->UDM->NSSF->AUSF->N3IWF.

For example, to run NRF:

cd ~/my5G-core
./bin/nrf &

Repeat the process to AMF, SMF, UDR, PCF, UDM, NSSF and AUSF.

Finally, to run N3IWF:

cd ~/my5G-core
sudo ./bin/n3iwf 

Starting UE

# Use a new terminal or split
cd ~/my5G-core/

# Starting UE
sudo ip netns exec UEns ./bin/ue

Triggering initial registration procedure

# New ike_bind_addr 
sed -i 's/ike_bind_addr=.*/ike_bind_addr=${ike_bind_addr:-"192.168.1.1"}/' ~/my5G-core/src/ue/trigger_initial_registration.sh 

# Starting the initial registration procedure
sudo ip netns exec UEns ~/my5G-core/src/ue/trigger_initial_registration.sh --ue_addr 192.168.1.1 --ue_port 10000 --scheme http