Open5GS 5GCとUERANSIM UE/RANによるFramed Routingの設定

本記事は、Open5GSとUERANSIMを使用して、Framed Routing機能を試すための簡単な設定について説明します。5GのFramed Routingについては、`3GPP TS 23.501 5.6.14 Support of Framed Routing`を参照して下さい。この機能により、UEの背後のネットワークにroutingすることができます。
なお、5GCのコア網に登場する各NF(Network Function)の役割やインターフェースについて概ね知っていることを期待して書いており、これらの説明は省略します。

---

## 目次

- [Open5GS 5GCのシミュレーション携帯網の概要](#open5gs-5gcのシミュレーション携帯網の概要)
- [Open5GS 5GCとUERANSIM UE/RANの設定ファイルの変更点](#open5gs-5gcとueransim-ueranの設定ファイルの変更点)
    - [Open5GS 5GC C-Planeの設定ファイルの変更点](#open5gs-5gc-c-planeの設定ファイルの変更点)
    - [Open5GS 5GC U-Planeの設定ファイルの変更点](#open5gs-5gc-u-planeの設定ファイルの変更点)
    - [UERANSIM UE/RANの設定ファイルの変更点](#ueransim-ueranの設定ファイルの変更点)
        - [RANの設定ファイルの変更点](#ranの設定ファイルの変更点)
        - [UE0(IMSI-001010000000000)の設定ファイルの変更点](#ue0imsi-001010000000000の設定ファイルの変更点)
        - [UE1(IMSI-001010000000001)の設定ファイルの変更点](#ue1imsi-001010000000001の設定ファイルの変更点)
- [Open5GS 5GCとUERANSIM UE/RANのネットワーク設定](#open5gs-5gcとueransim-ueranのネットワーク設定)
    - [Open5GS 5GC U-Planeのネットワーク設定](#open5gs-5gc-u-planeのネットワーク設定)
    - [UERANSIM UE0のネットワーク設定](#ueransim-ue0のネットワーク設定)
    - [UERANSIM UE1のネットワーク設定](#ueransim-ue1のネットワーク設定)
- [加入者情報にFramed Routesを追加](#加入者情報にframed-routesを追加)
    - [UE0のFramed Routesを追加](#ue0のframed-routesを追加)
    - [UE1のFramed Routesを追加](#ue1のframed-routesを追加)
- [Open5GSとUERANSIMのビルド](#open5gsとueransimのビルド)
- [Open5GS 5GCとUERANSIM UE/RANを実行](#open5gs-5gcとueransim-ueranを実行)
    - [Open5GS 5GC C-Planeを実行](#open5gs-5gc-c-planeを実行)
    - [Open5GS 5GC U-Planeを実行](#open5gs-5gc-u-planeを実行)
    - [UERANSIMを実行](#ueransimを実行)
        - [gNodeBを起動](#gnodebを起動)
        - [UE0を起動](#ue0を起動)
        - [UE1を起動](#ue1を起動)
- [Framed Routesにpingする](#framed-routesにpingする)
    - [UE0のFramed Routesに属するIPアドレス(192.168.20.100/24)にping](#ue0のframed-routesに属するipアドレス1921682010024にping)
    - [UE1のFramed Routesに属するIPアドレス(192.168.21.100/24)にping](#ue1のframed-routesに属するipアドレス1921682110024にping)
    - [UE1のFramed Routesに属するIPアドレス(192.168.22.100/24)にping](#ue1のframed-routesに属するipアドレス1921682210024にping)
    - [存在しないFramed Routesに属するIPアドレス(192.168.23.100/24)にping](#存在しないframed-routesに属するipアドレス1921682310024にping)
- [最後に](#最後に)
- [主な変更履歴](#主な変更履歴)

---

## Open5GS 5GCのシミュレーション携帯網の概要

ここでは、UEの背後にあるIP routes (Framed Routes)にroutingする設定を確認することを目的に、簡易的な5GC携帯網をシミュレーション用に構築しました。
このシミュレーション環境は以下の条件を満たす最小構成になります。

- 二つのUEは同じDNNを持ち、同じDNに接続する。
- 二つのUEは異なるFramed Routesを持ち、5GCからUEに割り当てられたIPアドレス(Tunnel GW/uesimtun0)を経由して、UPFが稼働するVMから、UEの背後にあるFramed RoutesのIPアドレスにpingが届く。

構築したシミュレーション環境は以下の通りです。
<img width="800" alt="network-overview.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/457466/e53c4518-058b-5688-7d72-78df29eb33bf.png">

5GCとUE/RANに使用しているOSSは以下の通りです。

- 5GC - Open5GS v2.6.0 (2023.01.28) - https://github.com/open5gs/open5gs  
- UE/RAN - UERANSIM v3.2.6 - https://github.com/aligungr/UERANSIM

各VMは以下の通りです。

| VM# | SW & Role | IP address | OS | Memory (Min) | HDD (Min) |
| --- | --- | --- | --- | --- | --- |
| VM1 | Open5GS 5GC C-Plane | 192.168.0.111/24 | Ubuntu 20.04 | 1GB | 20GB |
| VM2 | Open5GS 5GC U-Plane  | 192.168.0.112/24 | Ubuntu 20.04 | 1GB | 20GB |
| VM3 | UERANSIM RAN (gNodeB) | 192.168.0.131/24 | Ubuntu 20.04 | 1GB | 10GB |
| VM4 | UERANSIM UE0 | 192.168.0.132/24 | Ubuntu 20.04 | 1GB | 10GB |
| VM5 | UERANSIM UE1 | 192.168.0.133/24 | Ubuntu 20.04 | 1GB | 10GB |

加入者情報は以下の通りです。(その他の項目はデフォルト値)
**注意。UERANSIMのUEの設定に合わせて、OPあるいはOPcを選択してください。また、2023.01.29の時点で、Open5GS WebUIにはFramed Routesを設定する項目はありません。なお、`open5gs-dbctl`スクリプトを変更することで設定できるようですが、わたしは設定できませんでした。**

| UE# | IMSI | DNN | OP/OPc | Framed Routes |
| --- | --- | --- | --- | -- |
| UE0 | 001010000000000 | internet | OPc | 192.168.20.0/24 |
| UE1 | 001010000000001 | internet | OPc | 192.168.21.0/24<br>192.168.22.0/24 |

これらの情報の登録には、Open5GSが提供するWebUIを使用しました。なお、3GPP認証とキー生成機能(MILENAGE)の試験データとして、[3GPP TS 35.208](https://www.3gpp.org/DynaReport/35208.htm) "4.3 Test Sets"が公開されています。

DNは以下の通りです。

| DN | TUNnel interface of DN | DNN | TUNnel interface of UE |
| --- | --- | --- | --- |
| 10.45.0.0/16 | ogstun | internet | uesimtun0 |

## Open5GS 5GCとUERANSIM UE/RANの設定ファイルの変更点

Open5GSとUERANSIMのビルド方法は以下を参照して下さい。

- Open5GS v2.6.0 (2023.01.28) - https://open5gs.org/open5gs/docs/guide/02-building-open5gs-from-sources/
- UERANSIM v3.2.6 - https://github.com/aligungr/UERANSIM/wiki/Installation

### Open5GS 5GC C-Planeの設定ファイルの変更点

- `open5gs/install/etc/open5gs/amf.yaml`

```diff
--- amf.yaml.orig       2023-01-12 20:33:18.000000000 +0900
+++ amf.yaml    2023-01-12 21:17:46.000000000 +0900
@@ -342,26 +342,26 @@
       - addr: 127.0.0.5
         port: 7777
     ngap:
-      - addr: 127.0.0.5
+      - addr: 192.168.0.111
     metrics:
       - addr: 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
     security:
```

- `open5gs/install/etc/open5gs/smf.yaml`

```diff
--- smf.yaml.orig       2023-01-12 20:33:18.000000000 +0900
+++ smf.yaml    2023-01-29 09:47:21.876573900 +0900
@@ -508,20 +508,17 @@
       - addr: 127.0.0.4
         port: 7777
     pfcp:
-      - addr: 127.0.0.4
-      - addr: ::1
+      - addr: 192.168.0.111
     gtpc:
       - addr: 127.0.0.4
-      - addr: ::1
     gtpu:
-      - addr: 127.0.0.4
-      - addr: ::1
+      - addr: 192.168.0.111
     metrics:
       - addr: 127.0.0.4
         port: 9090
     subnet:
       - addr: 10.45.0.1/16
-      - addr: 2001:db8:cafe::1/48
+        dnn: internet
     dns:
       - 8.8.8.8
       - 8.8.4.4
@@ -695,7 +692,8 @@
 #
 upf:
     pfcp:
-      - addr: 127.0.0.7
+      - addr: 192.168.0.112
+        dnn: internet
 
 #
 # parameter:
```

### Open5GS 5GC U-Planeの設定ファイルの変更点

- `open5gs/install/etc/open5gs/upf.yaml`

```diff
--- upf.yaml.orig       2023-01-12 20:44:34.000000000 +0900
+++ upf.yaml    2023-01-29 09:47:52.262159150 +0900
@@ -173,12 +173,13 @@
 #
 upf:
     pfcp:
-      - addr: 127.0.0.7
+      - addr: 192.168.0.112
     gtpu:
-      - addr: 127.0.0.7
+      - addr: 192.168.0.112
     subnet:
       - addr: 10.45.0.1/16
-      - addr: 2001:db8:cafe::1/48
+        dnn: internet
+        dev: ogstun
     metrics:
       - addr: 127.0.0.7
         port: 9090
```

### UERANSIM UE/RANの設定ファイルの変更点

#### RANの設定ファイルの変更点

- `UERANSIM/config/open5gs-gnb.yaml`

```diff
--- open5gs-gnb.yaml.orig       2022-07-03 13:06:44.000000000 +0900
+++ open5gs-gnb.yaml    2023-01-12 21:26:20.000000000 +0900
@@ -1,17 +1,17 @@
-mcc: '999'          # Mobile Country Code value
-mnc: '70'           # Mobile Network Code value (2 or 3 digits)
+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)
+linkIp: 192.168.0.131   # gNB's local IP address for Radio Link Simulation (Usually same with local IP)
+ngapIp: 192.168.0.131   # gNB's local IP address for N2 Interface (Usually same with local IP)
+gtpIp: 192.168.0.131    # gNB's local IP address for N3 Interface (Usually same with local IP)
 
 # List of AMF address information
 amfConfigs:
-  - address: 127.0.0.5
+  - address: 192.168.0.111
     port: 38412
 
 # List of supported S-NSSAIs by this gNB
```

#### UE0(IMSI-001010000000000)の設定ファイルの変更点

最初に、`open5gs-ue.yaml`から`open5gs-ue0.yaml`にコピーを作成します。

```
# cd UERANSIM/config
# cp open5gs-ue.yaml open5gs-ue0.yaml
```

次に、`open5gs-ue0.yaml`を編集します。

- `UERANSIM/config/open5gs-ue0.yaml`

```diff
--- open5gs-ue.yaml.orig        2022-07-03 13:06:44.000000000 +0900
+++ open5gs-ue0.yaml    2023-01-12 21:28:10.000000000 +0900
@@ -1,9 +1,9 @@
 # IMSI number of the UE. IMSI = [MCC|MNC|MSISDN] (In total 15 digits)
-supi: 'imsi-999700000000001'
+supi: 'imsi-001010000000000'
 # Mobile Country Code value of HPLMN
-mcc: '999'
+mcc: '001'
 # Mobile Network Code value of HPLMN (2 or 3 digits)
-mnc: '70'
+mnc: '01'
 
 # Permanent subscription key
 key: '465B5CE8B199B49FAA5F0A2EE238A6BC'
@@ -20,7 +20,7 @@
 
 # List of gNB IP addresses for Radio Link Simulation
 gnbSearchList:
-  - 127.0.0.1
+  - 192.168.0.131
 
 # UAC Access Identities Configuration
 uacAic:
```

#### UE1(IMSI-001010000000001)の設定ファイルの変更点

最初に、`open5gs-ue.yaml`から`open5gs-ue1.yaml`にコピーを作成します。

```
# cd UERANSIM/config
# cp open5gs-ue.yaml open5gs-ue1.yaml
```

次に、`open5gs-ue1.yaml`を編集します。

- `UERANSIM/config/open5gs-ue1.yaml`

```diff
--- open5gs-ue.yaml.orig        2022-07-03 13:06:44.000000000 +0900
+++ open5gs-ue1.yaml    2023-01-29 13:36:52.157598766 +0900
@@ -1,9 +1,9 @@
 # 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'
 
 # Permanent subscription key
 key: '465B5CE8B199B49FAA5F0A2EE238A6BC'
@@ -20,7 +20,7 @@
 
 # List of gNB IP addresses for Radio Link Simulation
 gnbSearchList:
-  - 127.0.0.1
+  - 192.168.0.131
 
 # UAC Access Identities Configuration
 uacAic:
```

## Open5GS 5GCとUERANSIM UE/RANのネットワーク設定

### Open5GS 5GC U-Planeのネットワーク設定

最初に、`/etc/sysctl.conf`ファイルの以下の行のコメントを外し、OSに反映します。

```
net.ipv4.ip_forward=1
```
```
# sysctl -p
```

次に、TUNインターフェースとNAPTを設定します。

```sh
ip tuntap add name ogstun mode tun
ip addr add 10.45.0.1/16 dev ogstun
ip link set ogstun up

iptables -t nat -A POSTROUTING -s 10.45.0.0/16 ! -o ogstun -j MASQUERADE
```

### UERANSIM UE0のネットワーク設定

VM4のUE0を起動後、VM4において、`uesimtun0`インターフェースに、Framed Routesに属するIPアドレス(例、`192.168.20.100/24`)とDN(`10.45.0.0/16`)のroutingを以下のように設定します。

```
ip addr add 192.168.20.100/24 dev uesimtun0
ip route add 10.45.0.0/16 dev uesimtun0
```

### UERANSIM UE1のネットワーク設定

VM5のUE1を起動後、VM5において、`uesimtun0`インターフェースに、Framed Routesに属するIPアドレス(例、`192.168.21.100/24`、`192.168.22.100/24`)とDN(`10.45.0.0/16`)のroutingを以下のように設定します。

```
ip addr add 192.168.21.100/24 dev uesimtun0
ip addr add 192.168.22.100/24 dev uesimtun0
ip route add 10.45.0.0/16 dev uesimtun0
```

## 加入者情報にFramed Routesを追加

[MongoDB Compass](https://www.mongodb.com/products/compass)は、MongoDBのデータを簡単に操作できるGUIツールです。今回、本ツールを使用して、MongoDBに作成した加入者情報に直接、Framed Routesを追加しました。

### UE0のFramed Routesを追加

MongoDBに登録されたUE0の加入者情報(サンプル)をJSON形式で表示すると以下の通りです。これに、矢印の通りにFramed Routesの情報を追加します。

```json
{
  "_id": {
    "$oid": "63d51ff360e6c465ca52edbb"
  },
  "schema_version": 1,
  "imsi": "001010000000000",
  "msisdn": [],
  "imeisv": "4370816125816151",
  "mme_host": [],
  "mme_realm": [],
  "purge_flag": [],
  "security": {
    "k": "465B5CE8 B199B49F AA5F0A2E E238A6BC",
    "op": null,
    "opc": "E8ED289D EBA952E4 283B54E8 8E6183CA",
    "amf": "8000",
    "sqn": {
      "$numberLong": "129"
    }
  },
  "ambr": {
    "downlink": {
      "value": 1,
      "unit": 3
    },
    "uplink": {
      "value": 1,
      "unit": 3
    }
  },
  "slice": [
    {
      "sst": 1,
      "default_indicator": true,
      "session": [
        {
          "name": "internet",
          "type": 3,
          "qos": {
            "index": 9,
            "arp": {
              "priority_level": 8,
              "pre_emption_capability": 1,
              "pre_emption_vulnerability": 1
            }
          },
          "ambr": {
            "downlink": {
              "value": 1,
              "unit": 3
            },
            "uplink": {
              "value": 1,
              "unit": 3
            }
          },
          "_id": {
            "$oid": "63d51ff360e6c465ca52edbd"
          },
-->       "ipv4_framed_routes": [
-->         "192.168.20.0/24"
-->       ],
          "pcc_rule": []
        }
      ],
      "_id": {
        "$oid": "63d51ff360e6c465ca52edbc"
      }
    }
  ],
  "access_restriction_data": 32,
  "subscriber_status": 0,
  "network_access_mode": 0,
  "subscribed_rau_tau_timer": 12,
  "__v": 0
}
```

### UE1のFramed Routesを追加

MongoDBに登録されたUE1の加入者情報(サンプル)をJSON形式で表示すると以下の通りです。これに、矢印の通りにFramed Routesの情報を追加します。

```json
{
  "_id": {
    "$oid": "63d53f7360e6c465ca52edcf"
  },
  "schema_version": 1,
  "imsi": "001010000000001",
  "msisdn": [],
  "imeisv": "4370816125816151",
  "mme_host": [],
  "mme_realm": [],
  "purge_flag": [],
  "security": {
    "k": "465B5CE8 B199B49F AA5F0A2E E238A6BC",
    "op": null,
    "opc": "E8ED289D EBA952E4 283B54E8 8E6183CA",
    "amf": "8000",
    "sqn": {
      "$numberLong": "161"
    }
  },
  "ambr": {
    "downlink": {
      "value": 1,
      "unit": 3
    },
    "uplink": {
      "value": 1,
      "unit": 3
    }
  },
  "slice": [
    {
      "sst": 1,
      "default_indicator": true,
      "session": [
        {
          "name": "internet",
          "type": 3,
          "qos": {
            "index": 9,
            "arp": {
              "priority_level": 8,
              "pre_emption_capability": 1,
              "pre_emption_vulnerability": 1
            }
          },
          "ambr": {
            "downlink": {
              "value": 1,
              "unit": 3
            },
            "uplink": {
              "value": 1,
              "unit": 3
            }
          },
          "_id": {
            "$oid": "63d53f7360e6c465ca52edd1"
          },
-->       "ipv4_framed_routes": [
-->         "192.168.21.0/24",
-->         "192.168.22.0/24"
-->       ],
          "pcc_rule": []
        }
      ],
      "_id": {
        "$oid": "63d53f7360e6c465ca52edd0"
      }
    }
  ],
  "access_restriction_data": 32,
  "subscriber_status": 0,
  "network_access_mode": 0,
  "subscribed_rau_tau_timer": 12,
  "__v": 0
}
```

## Open5GSとUERANSIMのビルド

Open5GSとUERANSIMのビルド方法は以下を参照して下さい。

- Open5GS v2.6.0 (2023.01.28) - https://open5gs.org/open5gs/docs/guide/02-building-open5gs-from-sources/
- UERANSIM v3.2.6 - https://github.com/aligungr/UERANSIM/wiki/Installation

注意。Open5GS 5GC C-PlaneマシンにMongoDBをインストールして下さい。U-Planeマシンにインストールする必要はありません。

## Open5GS 5GCとUERANSIM UE/RANを実行

最初に5GCを起動し、次にUERANSIM(UEとRANのシミュレータ)を起動します。

### Open5GS 5GC C-Planeを実行

- Open5GS 5GC C-Plane

```sh
./install/bin/open5gs-nrfd &
sleep 2
./install/bin/open5gs-scpd &
sleep 2
./install/bin/open5gs-amfd &
sleep 2
./install/bin/open5gs-smfd &
./install/bin/open5gs-ausfd &
./install/bin/open5gs-udmd &
./install/bin/open5gs-udrd &
./install/bin/open5gs-pcfd &
./install/bin/open5gs-nssfd &
./install/bin/open5gs-bsfd &
```

### Open5GS 5GC U-Planeを実行

次に、Open5GS 5GC U-Planeを起動します。

- Open5GS 5GC U-Plane

```
./install/bin/open5gs-upfd &
```

### UERANSIMを実行

まず、gNodeBと5GCの間でNG-Setupし、5GCにUEを登録し、PDUセッションを確立します。
UERANSIMの使い方は以下を参照して下さい。

- https://github.com/aligungr/UERANSIM/wiki/Usage

#### gNodeBを起動

次のようにgNodeBを起動します。

```
# ./nr-gnb -c ../config/open5gs-gnb.yaml
UERANSIM v3.2.6
[2023-01-29 19:02:58.457] [sctp] [info] Trying to establish SCTP connection... (192.168.0.111:38412)
[2023-01-29 19:02:58.459] [sctp] [info] SCTP connection established (192.168.0.111:38412)
[2023-01-29 19:02:58.459] [sctp] [debug] SCTP association setup ascId[7]
[2023-01-29 19:02:58.460] [ngap] [debug] Sending NG Setup Request
[2023-01-29 19:02:58.460] [ngap] [debug] NG Setup Response received
[2023-01-29 19:02:58.460] [ngap] [info] NG Setup procedure is successful
```

Open5GS C-Planeのログは以下の通りです。

```
01/29 19:02:58.357: [amf] INFO: gNB-N2 accepted[192.168.0.131]:33848 in ng-path module (../src/amf/ngap-sctp.c:113)
01/29 19:02:58.357: [amf] INFO: gNB-N2 accepted[192.168.0.131] in master_sm module (../src/amf/amf-sm.c:676)
01/29 19:02:58.357: [amf] INFO: [Added] Number of gNBs is now 1 (../src/amf/context.c:1034)
01/29 19:02:58.357: [amf] INFO: gNB-N2[192.168.0.131] max_num_of_ostreams : 10 (../src/amf/amf-sm.c:715)
```

#### UE0を起動

次のようにUE0を起動します。これにより、5GCにUEが登録され、PDUセッションが確立します。

```
# ./nr-ue -c ../config/open5gs-ue0.yaml
UERANSIM v3.2.6
[2023-01-29 19:05:19.689] [nas] [info] UE switches to state [MM-DEREGISTERED/PLMN-SEARCH]
[2023-01-29 19:05:19.689] [rrc] [debug] New signal detected for cell[1], total [1] cells in coverage
[2023-01-29 19:05:19.690] [nas] [info] Selected plmn[001/01]
[2023-01-29 19:05:19.690] [rrc] [info] Selected cell plmn[001/01] tac[1] category[SUITABLE]
[2023-01-29 19:05:19.690] [nas] [info] UE switches to state [MM-DEREGISTERED/PS]
[2023-01-29 19:05:19.690] [nas] [info] UE switches to state [MM-DEREGISTERED/NORMAL-SERVICE]
[2023-01-29 19:05:19.690] [nas] [debug] Initial registration required due to [MM-DEREG-NORMAL-SERVICE]
[2023-01-29 19:05:19.690] [nas] [debug] UAC access attempt is allowed for identity[0], category[MO_sig]
[2023-01-29 19:05:19.690] [nas] [debug] Sending Initial Registration
[2023-01-29 19:05:19.691] [nas] [info] UE switches to state [MM-REGISTER-INITIATED]
[2023-01-29 19:05:19.691] [rrc] [debug] Sending RRC Setup Request
[2023-01-29 19:05:19.691] [rrc] [info] RRC connection established
[2023-01-29 19:05:19.691] [rrc] [info] UE switches to state [RRC-CONNECTED]
[2023-01-29 19:05:19.692] [nas] [info] UE switches to state [CM-CONNECTED]
[2023-01-29 19:05:19.700] [nas] [debug] Authentication Request received
[2023-01-29 19:05:19.707] [nas] [debug] Security Mode Command received
[2023-01-29 19:05:19.707] [nas] [debug] Selected integrity[2] ciphering[0]
[2023-01-29 19:05:19.725] [nas] [debug] Registration accept received
[2023-01-29 19:05:19.725] [nas] [info] UE switches to state [MM-REGISTERED/NORMAL-SERVICE]
[2023-01-29 19:05:19.725] [nas] [debug] Sending Registration Complete
[2023-01-29 19:05:19.725] [nas] [info] Initial Registration is successful
[2023-01-29 19:05:19.725] [nas] [debug] Sending PDU Session Establishment Request
[2023-01-29 19:05:19.725] [nas] [debug] UAC access attempt is allowed for identity[0], category[MO_sig]
[2023-01-29 19:05:19.930] [nas] [debug] Configuration Update Command received
[2023-01-29 19:05:19.954] [nas] [debug] PDU Session Establishment Accept received
[2023-01-29 19:05:19.957] [nas] [info] PDU Session establishment is successful PSI[1]
[2023-01-29 19:05:19.980] [app] [info] Connection setup for PDU session[1] is successful, TUN interface[uesimtun0, 10.45.0.2] is up.
```

Open5GS C-Planeのログは以下の通りです。

```
01/29 19:05:19.574: [amf] INFO: InitialUEMessage (../src/amf/ngap-handler.c:372)
01/29 19:05:19.574: [amf] INFO: [Added] Number of gNB-UEs is now 1 (../src/amf/context.c:2327)
01/29 19:05:19.574: [amf] INFO:     RAN_UE_NGAP_ID[1] AMF_UE_NGAP_ID[1] TAC[1] CellID[0x10] (../src/amf/ngap-handler.c:533)
01/29 19:05:19.574: [amf] INFO: [suci-0-001-01-0000-0-0-0000000000] Unknown UE by SUCI (../src/amf/context.c:1634)
01/29 19:05:19.574: [amf] INFO: [Added] Number of AMF-UEs is now 1 (../src/amf/context.c:1419)
01/29 19:05:19.574: [gmm] INFO: Registration request (../src/amf/gmm-sm.c:552)
01/29 19:05:19.574: [gmm] INFO: [suci-0-001-01-0000-0-0-0000000000]    SUCI (../src/amf/gmm-handler.c:149)
01/29 19:05:19.575: [sbi] WARNING: [0c621c5c-9fbc-41ed-aaa0-e9add7f343b7] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:05:19.575: [sbi] WARNING: NF EndPoint updated [127.0.0.11:80] (../lib/sbi/context.c:1711)
01/29 19:05:19.575: [sbi] WARNING: NF EndPoint updated [127.0.0.11:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.575: [sbi] INFO: [0c621c5c-9fbc-41ed-aaa0-e9add7f343b7] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:05:19.577: [sbi] WARNING: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:05:19.577: [sbi] WARNING: NF EndPoint updated [127.0.0.12:80] (../lib/sbi/context.c:1711)
01/29 19:05:19.577: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.577: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.577: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.578: [sbi] INFO: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:05:19.590: [sbi] WARNING: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:05:19.591: [sbi] WARNING: NF EndPoint updated [127.0.0.12:80] (../lib/sbi/context.c:1711)
01/29 19:05:19.591: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.591: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.591: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.591: [sbi] INFO: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:05:19.594: [sbi] WARNING: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:05:19.594: [sbi] WARNING: NF EndPoint updated [127.0.0.12:80] (../lib/sbi/context.c:1711)
01/29 19:05:19.594: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.594: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.594: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.594: [sbi] INFO: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:05:19.600: [sbi] WARNING: [0c6845e6-9fbc-41ed-8fa9-a9977941d33a] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:05:19.600: [sbi] WARNING: NF EndPoint updated [127.0.0.13:80] (../lib/sbi/context.c:1711)
01/29 19:05:19.600: [sbi] WARNING: NF EndPoint updated [127.0.0.13:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.600: [sbi] WARNING: NF EndPoint updated [127.0.0.13:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.600: [sbi] WARNING: NF EndPoint updated [127.0.0.13:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.601: [sbi] INFO: [0c6845e6-9fbc-41ed-8fa9-a9977941d33a] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:05:19.603: [sbi] WARNING: [0c67f9c4-9fbc-41ed-8765-5713aaa088ab] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:05:19.603: [sbi] WARNING: NF EndPoint updated [127.0.0.20:80] (../lib/sbi/context.c:1711)
01/29 19:05:19.603: [sbi] WARNING: NF EndPoint updated [127.0.0.20:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.603: [sbi] INFO: [0c67f9c4-9fbc-41ed-8765-5713aaa088ab] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:05:19.808: [gmm] INFO: [imsi-001010000000000] Registration complete (../src/amf/gmm-sm.c:1435)
01/29 19:05:19.809: [amf] INFO: [imsi-001010000000000] Configuration update command (../src/amf/nas-path.c:522)
01/29 19:05:19.809: [gmm] INFO:     UTC [2023-01-29T10:05:19] Timezone[0]/DST[0] (../src/amf/gmm-build.c:543)
01/29 19:05:19.810: [gmm] INFO:     LOCAL [2023-01-29T19:05:19] Timezone[32400]/DST[0] (../src/amf/gmm-build.c:548)
01/29 19:05:19.811: [amf] INFO: [Added] Number of AMF-Sessions is now 1 (../src/amf/context.c:2348)
01/29 19:05:19.812: [gmm] INFO: UE SUPI[imsi-001010000000000] DNN[internet] S_NSSAI[SST:1 SD:0xffffff] (../src/amf/gmm-handler.c:1098)
01/29 19:05:19.815: [smf] INFO: [Added] Number of SMF-UEs is now 1 (../src/smf/context.c:1012)
01/29 19:05:19.815: [smf] INFO: [Added] Number of SMF-Sessions is now 1 (../src/smf/context.c:3108)
01/29 19:05:19.817: [sbi] WARNING: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:05:19.817: [sbi] WARNING: NF EndPoint updated [127.0.0.12:80] (../lib/sbi/context.c:1711)
01/29 19:05:19.817: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.817: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.818: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.818: [sbi] INFO: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:05:19.823: [sbi] WARNING: [0c6845e6-9fbc-41ed-8fa9-a9977941d33a] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:05:19.823: [sbi] WARNING: NF EndPoint updated [127.0.0.13:80] (../lib/sbi/context.c:1711)
01/29 19:05:19.823: [sbi] WARNING: NF EndPoint updated [127.0.0.13:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.823: [sbi] WARNING: NF EndPoint updated [127.0.0.13:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.823: [sbi] WARNING: NF EndPoint updated [127.0.0.13:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.824: [sbi] INFO: [0c6845e6-9fbc-41ed-8fa9-a9977941d33a] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:05:19.825: [sbi] WARNING: [0c67f9c4-9fbc-41ed-8765-5713aaa088ab] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:05:19.826: [sbi] WARNING: NF EndPoint updated [127.0.0.20:80] (../lib/sbi/context.c:1711)
01/29 19:05:19.826: [sbi] WARNING: NF EndPoint updated [127.0.0.20:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.826: [sbi] INFO: [0c67f9c4-9fbc-41ed-8765-5713aaa088ab] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:05:19.828: [sbi] WARNING: [0c612e5a-9fbc-41ed-b508-fddde7864725] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:05:19.828: [sbi] WARNING: NF EndPoint updated [127.0.0.15:80] (../lib/sbi/context.c:1711)
01/29 19:05:19.828: [sbi] WARNING: NF EndPoint updated [127.0.0.15:7777] (../lib/sbi/context.c:1623)
01/29 19:05:19.828: [sbi] INFO: [0c612e5a-9fbc-41ed-b508-fddde7864725] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:05:19.830: [smf] INFO: UE SUPI[imsi-001010000000000] DNN[internet] IPv4[10.45.0.2] IPv6[] (../src/smf/npcf-handler.c:527)
01/29 19:05:19.831: [gtp] INFO: gtp_connect() [192.168.0.112]:2152 (../lib/gtp/path.c:60)
```

Open5GS U-Planeのログは以下の通りです。

```
01/29 19:05:19.832: [upf] INFO: [Added] Number of UPF-Sessions is now 1 (../src/upf/context.c:194)
01/29 19:05:19.832: [gtp] INFO: gtp_connect() [192.168.0.111]:2152 (../lib/gtp/path.c:60)
01/29 19:05:19.832: [upf] INFO: UE F-SEID[UP:0x1 CP:0x1] APN[internet] PDN-Type[1] IPv4[10.45.0.2] IPv6[] (../src/upf/context.c:467)
01/29 19:05:19.832: [upf] INFO: UE F-SEID[UP:0x1 CP:0x1] APN[internet] PDN-Type[1] IPv4[10.45.0.2] IPv6[] (../src/upf/context.c:467)
01/29 19:05:19.837: [gtp] INFO: gtp_connect() [192.168.0.131]:2152 (../lib/gtp/path.c:60)
```

`nr-ue`コマンドのコンソールログから、Open5GS 5GCからIPアドレス`10.45.0.2`がUE0に割り当てられたことが分かります。

```
[2023-01-29 19:05:19.980] [app] [info] Connection setup for PDU session[1] is successful, TUN interface[uesimtun0, 10.45.0.2] is up.
```

念のため、UE0のTUNインターフェースに割り当てられたIPアドレスと一致していることを確認して下さい。

```
# ip addr show
...
12: uesimtun0: <POINTOPOINT,PROMISC,NOTRAILERS,UP,LOWER_UP> mtu 1400 qdisc fq_codel state UNKNOWN group default qlen 500
    link/none 
    inet 10.45.0.2/32 scope global uesimtun0
       valid_lft forever preferred_lft forever
    inet6 fe80::676e:648e:99af:cd6e/64 scope link stable-privacy 
       valid_lft forever preferred_lft forever
...
```

- UE0のFramed Routingを確認するために、VM4で`tcpdump`を走らせます。

```
# tcpdump -i uesimtun0 -n
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on uesimtun0, link-type RAW (Raw IP), capture size 262144 bytes
```

**[UERANSIM UE0のネットワーク設定](#ueransim-ue0のネットワーク設定)を忘れずに実施して下さい。**

#### UE1を起動

次のようにUE1を起動します。これにより、5GCにUEが登録され、PDUセッションが確立します。

```
# ./nr-ue -c ../config/open5gs-ue1.yaml 
UERANSIM v3.2.6
[2023-01-29 19:25:37.965] [nas] [info] UE switches to state [MM-DEREGISTERED/PLMN-SEARCH]
[2023-01-29 19:25:37.966] [rrc] [debug] New signal detected for cell[1], total [1] cells in coverage
[2023-01-29 19:25:38.432] [nas] [info] Selected plmn[001/01]
[2023-01-29 19:25:38.432] [rrc] [info] Selected cell plmn[001/01] tac[1] category[SUITABLE]
[2023-01-29 19:25:38.433] [nas] [info] UE switches to state [MM-DEREGISTERED/PS]
[2023-01-29 19:25:38.433] [nas] [info] UE switches to state [MM-DEREGISTERED/NORMAL-SERVICE]
[2023-01-29 19:25:38.434] [nas] [debug] Initial registration required due to [MM-DEREG-NORMAL-SERVICE]
[2023-01-29 19:25:38.435] [nas] [debug] UAC access attempt is allowed for identity[0], category[MO_sig]
[2023-01-29 19:25:38.435] [nas] [debug] Sending Initial Registration
[2023-01-29 19:25:38.435] [rrc] [debug] Sending RRC Setup Request
[2023-01-29 19:25:38.436] [nas] [info] UE switches to state [MM-REGISTER-INITIATED]
[2023-01-29 19:25:38.437] [rrc] [info] RRC connection established
[2023-01-29 19:25:38.437] [rrc] [info] UE switches to state [RRC-CONNECTED]
[2023-01-29 19:25:38.437] [nas] [info] UE switches to state [CM-CONNECTED]
[2023-01-29 19:25:38.452] [nas] [debug] Authentication Request received
[2023-01-29 19:25:38.456] [nas] [debug] Security Mode Command received
[2023-01-29 19:25:38.456] [nas] [debug] Selected integrity[2] ciphering[0]
[2023-01-29 19:25:38.478] [nas] [debug] Registration accept received
[2023-01-29 19:25:38.479] [nas] [info] UE switches to state [MM-REGISTERED/NORMAL-SERVICE]
[2023-01-29 19:25:38.479] [nas] [debug] Sending Registration Complete
[2023-01-29 19:25:38.479] [nas] [info] Initial Registration is successful
[2023-01-29 19:25:38.479] [nas] [debug] Sending PDU Session Establishment Request
[2023-01-29 19:25:38.479] [nas] [debug] UAC access attempt is allowed for identity[0], category[MO_sig]
[2023-01-29 19:25:38.688] [nas] [debug] Configuration Update Command received
[2023-01-29 19:25:38.709] [nas] [debug] PDU Session Establishment Accept received
[2023-01-29 19:25:38.715] [nas] [info] PDU Session establishment is successful PSI[1]
[2023-01-29 19:25:38.737] [app] [info] Connection setup for PDU session[1] is successful, TUN interface[uesimtun0, 10.45.0.3] is up.
```

Open5GS C-Planeのログは以下の通りです。

```
01/29 19:25:38.434: [amf] INFO: InitialUEMessage (../src/amf/ngap-handler.c:372)
01/29 19:25:38.434: [amf] INFO: [Added] Number of gNB-UEs is now 2 (../src/amf/context.c:2327)
01/29 19:25:38.435: [amf] INFO:     RAN_UE_NGAP_ID[2] AMF_UE_NGAP_ID[2] TAC[1] CellID[0x10] (../src/amf/ngap-handler.c:533)
01/29 19:25:38.435: [amf] INFO: [suci-0-001-01-0000-0-0-0000000001] Unknown UE by SUCI (../src/amf/context.c:1634)
01/29 19:25:38.436: [amf] INFO: [Added] Number of AMF-UEs is now 2 (../src/amf/context.c:1419)
01/29 19:25:38.436: [gmm] INFO: Registration request (../src/amf/gmm-sm.c:552)
01/29 19:25:38.436: [gmm] INFO: [suci-0-001-01-0000-0-0-0000000001]    SUCI (../src/amf/gmm-handler.c:149)
01/29 19:25:38.438: [sbi] WARNING: [0c621c5c-9fbc-41ed-aaa0-e9add7f343b7] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:25:38.439: [sbi] WARNING: NF EndPoint updated [127.0.0.11:80] (../lib/sbi/context.c:1711)
01/29 19:25:38.439: [sbi] WARNING: NF EndPoint updated [127.0.0.11:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.439: [sbi] INFO: [0c621c5c-9fbc-41ed-aaa0-e9add7f343b7] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:25:38.442: [sbi] WARNING: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:25:38.443: [sbi] WARNING: NF EndPoint updated [127.0.0.12:80] (../lib/sbi/context.c:1711)
01/29 19:25:38.443: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.444: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.444: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.444: [sbi] INFO: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:25:38.454: [sbi] WARNING: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:25:38.454: [sbi] WARNING: NF EndPoint updated [127.0.0.12:80] (../lib/sbi/context.c:1711)
01/29 19:25:38.455: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.455: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.455: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.455: [sbi] INFO: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:25:38.459: [sbi] WARNING: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:25:38.459: [sbi] WARNING: NF EndPoint updated [127.0.0.12:80] (../lib/sbi/context.c:1711)
01/29 19:25:38.459: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.460: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.460: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.460: [sbi] INFO: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:25:38.468: [sbi] WARNING: [0c6845e6-9fbc-41ed-8fa9-a9977941d33a] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:25:38.469: [sbi] WARNING: NF EndPoint updated [127.0.0.13:80] (../lib/sbi/context.c:1711)
01/29 19:25:38.469: [sbi] WARNING: NF EndPoint updated [127.0.0.13:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.469: [sbi] WARNING: NF EndPoint updated [127.0.0.13:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.469: [sbi] WARNING: NF EndPoint updated [127.0.0.13:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.469: [sbi] INFO: [0c6845e6-9fbc-41ed-8fa9-a9977941d33a] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:25:38.471: [sbi] WARNING: [0c67f9c4-9fbc-41ed-8765-5713aaa088ab] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:25:38.472: [sbi] WARNING: NF EndPoint updated [127.0.0.20:80] (../lib/sbi/context.c:1711)
01/29 19:25:38.472: [sbi] WARNING: NF EndPoint updated [127.0.0.20:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.472: [sbi] INFO: [0c67f9c4-9fbc-41ed-8765-5713aaa088ab] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:25:38.680: [gmm] INFO: [imsi-001010000000001] Registration complete (../src/amf/gmm-sm.c:1435)
01/29 19:25:38.681: [amf] INFO: [imsi-001010000000001] Configuration update command (../src/amf/nas-path.c:522)
01/29 19:25:38.681: [gmm] INFO:     UTC [2023-01-29T10:25:38] Timezone[0]/DST[0] (../src/amf/gmm-build.c:543)
01/29 19:25:38.682: [gmm] INFO:     LOCAL [2023-01-29T19:25:38] Timezone[32400]/DST[0] (../src/amf/gmm-build.c:548)
01/29 19:25:38.683: [amf] INFO: [Added] Number of AMF-Sessions is now 2 (../src/amf/context.c:2348)
01/29 19:25:38.684: [gmm] INFO: UE SUPI[imsi-001010000000001] DNN[internet] S_NSSAI[SST:1 SD:0xffffff] (../src/amf/gmm-handler.c:1098)
01/29 19:25:38.686: [smf] INFO: [Added] Number of SMF-UEs is now 2 (../src/smf/context.c:1012)
01/29 19:25:38.686: [smf] INFO: [Added] Number of SMF-Sessions is now 2 (../src/smf/context.c:3108)
01/29 19:25:38.688: [sbi] WARNING: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:25:38.688: [sbi] WARNING: NF EndPoint updated [127.0.0.12:80] (../lib/sbi/context.c:1711)
01/29 19:25:38.688: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.688: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.689: [sbi] WARNING: NF EndPoint updated [127.0.0.12:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.689: [sbi] INFO: [0c61db2a-9fbc-41ed-bb82-7fbd44cc75b1] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:25:38.693: [sbi] WARNING: [0c6845e6-9fbc-41ed-8fa9-a9977941d33a] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:25:38.694: [sbi] WARNING: NF EndPoint updated [127.0.0.13:80] (../lib/sbi/context.c:1711)
01/29 19:25:38.694: [sbi] WARNING: NF EndPoint updated [127.0.0.13:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.694: [sbi] WARNING: NF EndPoint updated [127.0.0.13:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.694: [sbi] WARNING: NF EndPoint updated [127.0.0.13:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.694: [sbi] INFO: [0c6845e6-9fbc-41ed-8fa9-a9977941d33a] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:25:38.696: [sbi] WARNING: [0c67f9c4-9fbc-41ed-8765-5713aaa088ab] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:25:38.696: [sbi] WARNING: NF EndPoint updated [127.0.0.20:80] (../lib/sbi/context.c:1711)
01/29 19:25:38.696: [sbi] WARNING: NF EndPoint updated [127.0.0.20:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.697: [sbi] INFO: [0c67f9c4-9fbc-41ed-8765-5713aaa088ab] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:25:38.698: [sbi] WARNING: [0c612e5a-9fbc-41ed-b508-fddde7864725] (NF-discover) NF has already been added (../lib/sbi/nnrf-handler.c:739)
01/29 19:25:38.698: [sbi] WARNING: NF EndPoint updated [127.0.0.15:80] (../lib/sbi/context.c:1711)
01/29 19:25:38.699: [sbi] WARNING: NF EndPoint updated [127.0.0.15:7777] (../lib/sbi/context.c:1623)
01/29 19:25:38.699: [sbi] INFO: [0c612e5a-9fbc-41ed-b508-fddde7864725] (NF-discover) NF Profile updated (../lib/sbi/nnrf-handler.c:762)
01/29 19:25:38.701: [smf] INFO: UE SUPI[imsi-001010000000001] DNN[internet] IPv4[10.45.0.3] IPv6[] (../src/smf/npcf-handler.c:527)
```

Open5GS U-Planeのログは以下の通りです。

```
01/29 19:25:38.704: [upf] INFO: [Added] Number of UPF-Sessions is now 2 (../src/upf/context.c:194)
01/29 19:25:38.704: [upf] INFO: UE F-SEID[UP:0x2 CP:0x2] APN[internet] PDN-Type[1] IPv4[10.45.0.3] IPv6[] (../src/upf/context.c:467)
01/29 19:25:38.704: [upf] INFO: UE F-SEID[UP:0x2 CP:0x2] APN[internet] PDN-Type[1] IPv4[10.45.0.3] IPv6[] (../src/upf/context.c:467)
```

`nr-ue`コマンドのコンソールログから、Open5GS 5GCからIPアドレス`10.45.0.3`がUE1に割り当てられたことが分かります。

```
[2023-01-29 19:25:38.737] [app] [info] Connection setup for PDU session[1] is successful, TUN interface[uesimtun0, 10.45.0.3] is up.
```

念のため、UE1のTUNインターフェースに割り当てられたIPアドレスと一致していることを確認して下さい。

```
# ip addr show
...
6: uesimtun0: <POINTOPOINT,PROMISC,NOTRAILERS,UP,LOWER_UP> mtu 1400 qdisc fq_codel state UNKNOWN group default qlen 500
    link/none 
    inet 10.45.0.3/32 scope global uesimtun0
       valid_lft forever preferred_lft forever
    inet6 fe80::68a2:d78b:6f4e:f884/64 scope link stable-privacy 
       valid_lft forever preferred_lft forever
...
```

- UE1のFramed Routingを確認するために、VM5で`tcpdump`を走らせます。

```
# tcpdump -i uesimtun0 -n
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on uesimtun0, link-type RAW (Raw IP), capture size 262144 bytes
```

**[UERANSIM UE1のネットワーク設定](#ueransim-ue1のネットワーク設定)を忘れずに実施して下さい。**

## Framed Routesにpingする

### UE0のFramed Routesに属するIPアドレス(`192.168.20.100/24`)にping

UPFが稼働するVM2から、UE0(VM4)のFramed Routesに属するIPアドレス(`192.168.20.100/24`)にpingが通ることを、VM4の`tcpdump`で確認します。

```
# ping 192.168.20.100 -I ogstun 
PING 192.168.20.100 (192.168.20.100) from 10.45.0.1 ogstun: 56(84) bytes of data.
64 bytes from 192.168.20.100: icmp_seq=1 ttl=64 time=2.63 ms
64 bytes from 192.168.20.100: icmp_seq=2 ttl=64 time=3.46 ms
64 bytes from 192.168.20.100: icmp_seq=3 ttl=64 time=2.31 ms
```

UE0(VM4)の`tcpdump`のログは以下の通りです。

```
20:01:37.269683 IP 10.45.0.1 > 192.168.20.100: ICMP echo request, id 49, seq 1, length 64
20:01:37.269716 IP 192.168.20.100 > 10.45.0.1: ICMP echo reply, id 49, seq 1, length 64
20:01:38.272187 IP 10.45.0.1 > 192.168.20.100: ICMP echo request, id 49, seq 2, length 64
20:01:38.272231 IP 192.168.20.100 > 10.45.0.1: ICMP echo reply, id 49, seq 2, length 64
20:01:39.273160 IP 10.45.0.1 > 192.168.20.100: ICMP echo request, id 49, seq 3, length 64
20:01:39.273199 IP 192.168.20.100 > 10.45.0.1: ICMP echo reply, id 49, seq 3, length 64
```

**UE1(VM5)にパケットが届いていないことを確認して下さい。**

### UE1のFramed Routesに属するIPアドレス(`192.168.21.100/24`)にping

UPFが稼働するVM2から、UE1(VM5)のFramed Routesに属するIPアドレス(`192.168.21.100/24`)にpingが通ることを、VM5の`tcpdump`で確認します。

```
# ping 192.168.21.100 -I ogstun 
PING 192.168.21.100 (192.168.21.100) from 10.45.0.1 ogstun: 56(84) bytes of data.
64 bytes from 192.168.21.100: icmp_seq=1 ttl=64 time=2.71 ms
64 bytes from 192.168.21.100: icmp_seq=2 ttl=64 time=2.92 ms
64 bytes from 192.168.21.100: icmp_seq=3 ttl=64 time=3.42 ms
```

UE1(VM5)の`tcpdump`のログは以下の通りです。

```
20:12:39.167367 IP 10.45.0.1 > 192.168.21.100: ICMP echo request, id 50, seq 1, length 64
20:12:39.167488 IP 192.168.21.100 > 10.45.0.1: ICMP echo reply, id 50, seq 1, length 64
20:12:40.168897 IP 10.45.0.1 > 192.168.21.100: ICMP echo request, id 50, seq 2, length 64
20:12:40.168937 IP 192.168.21.100 > 10.45.0.1: ICMP echo reply, id 50, seq 2, length 64
20:12:41.171274 IP 10.45.0.1 > 192.168.21.100: ICMP echo request, id 50, seq 3, length 64
20:12:41.171311 IP 192.168.21.100 > 10.45.0.1: ICMP echo reply, id 50, seq 3, length 64
```

**UE0(VM4)にパケットが届いていないことを確認して下さい。**

### UE1のFramed Routesに属するIPアドレス(`192.168.22.100/24`)にping

UPFが稼働するVM2から、UE1(VM5)のFramed Routesに属するIPアドレス(`192.168.22.100/24`)にpingが通ることを、VM5の`tcpdump`で確認します。

```
# ping 192.168.22.100 -I ogstun 
PING 192.168.22.100 (192.168.22.100) from 10.45.0.1 ogstun: 56(84) bytes of data.
64 bytes from 192.168.22.100: icmp_seq=1 ttl=64 time=2.72 ms
64 bytes from 192.168.22.100: icmp_seq=2 ttl=64 time=3.70 ms
64 bytes from 192.168.22.100: icmp_seq=3 ttl=64 time=3.89 ms
```

UE1(VM5)の`tcpdump`のログは以下の通りです。

```
20:16:13.218204 IP 10.45.0.1 > 192.168.22.100: ICMP echo request, id 51, seq 1, length 64
20:16:13.218246 IP 192.168.22.100 > 10.45.0.1: ICMP echo reply, id 51, seq 1, length 64
20:16:14.219303 IP 10.45.0.1 > 192.168.22.100: ICMP echo request, id 51, seq 2, length 64
20:16:14.219337 IP 192.168.22.100 > 10.45.0.1: ICMP echo reply, id 51, seq 2, length 64
20:16:15.220465 IP 10.45.0.1 > 192.168.22.100: ICMP echo request, id 51, seq 3, length 64
20:16:15.220552 IP 192.168.22.100 > 10.45.0.1: ICMP echo reply, id 51, seq 3, length 64
```

**UE0(VM4)にパケットが届いていないことを確認して下さい。**

### 存在しないFramed Routesに属するIPアドレス(`192.168.23.100/24`)にping

UPFが稼働するVM2から、UE0とUE1のどちらのFramed Routesにも属さないIPアドレス(`192.168.23.100/24`)にpingが通らないことを、VM4とVM5の`tcpdump`で確認します。

```
# ping 192.168.23.100 -I ogstun 
PING 192.168.23.100 (192.168.23.100) from 10.45.0.1 ogstun: 56(84) bytes of data.
```

**UE0(VM4)とUE1(VM5)のどちらにもパケットが届いていないことを確認して下さい。**

これで、Open5GSのFramed Routing機能を簡単に試すことができました。 実際の構成では、PSA-UPFとUEには、より複雑なネットワーク設定が必要になると思います。本記事では、Framed Routingを確認するための最小限の設定を説明しました。

## 最後に

有線ネットワークでは、AAAサーバ(通常、RADIUS)から返され、ユーザにroutingされる一つまたは複数のIP routesとして、Framed Routingは知られていると思います。
5Gはエンタープライズな接続用にFramed Routingを規定しており、2023年1月、Open5GSにこの機能が入りました。Framed Routesの情報はSMFによってPSA-UPFに提供されますが、そのSMFには今回のOpen5GSの実装では、UDMによって送信されたDNNおよびS-NSSAIに関連付けられたセッション管理情報から提供されます。(DN-AAAサーバからではなく)
これにより、UEの背後のネットワークを含めて、N6(PSA-UPF)とのネットワーク構成が柔軟になると思います。
また、参考までに、UE0とUE1の間のping、ならびに異なるUEに属するFramed routes間のpingについては、[こちら](https://github.com/s5uishida/open5gs_5gc_ueransim_framed_routing_sample_config/issues/2#issuecomment-1464891842)を参照して下さい。

最後に、元記事は[Github](https://github.com/s5uishida/open5gs_5gc_ueransim_framed_routing_sample_config)に書いたものです。Open5GSの[チュートリアル](https://open5gs.org/open5gs/docs/)からもリンクして頂きました。

## 主な変更履歴

- [2023.03.11] UE0とUE1の間のping、ならびに異なるUEに属するFramed routes間のpingについての説明を追加。
- [2023.02.02] 初版。