aligungr / UERANSIM

Open source 5G UE and RAN (gNodeB) implementation.
GNU General Public License v3.0
793 stars 323 forks source link

Name resolution of gNB IP address #245

Open raoufkh opened 3 years ago

raoufkh commented 3 years ago

As mentionned in this issue, I'm trying to deploy the UERANSIM on top of Kubernetes.

Pods are the deployment unit in Kubernetes and I'm trying to deploy the gNB and the UE in 2 different Pods.

Since Pods' IP addresses are highly variable, it is recommended to use a Kubernetes service to expose the Pods. Then, another applications can use the name of the service to access the Pod in the backend

In my case, I've created a service to expose the gNB Pod:

apiVersion: v1
kind: Service
metadata:
  name: gnb-service
  labels:
    app: ueransim
    component: gnb
spec:
  type: ClusterIP
  ports:
    - name: gnb-ue
      port: 4997
      protocol: UDP
  selector:
    app: ueransim
    component: gnb

And than I've passed its name to the UE:

    gnbSearchList:
      -gnb-service

Then, I realized that the UE expect only an IP address and not a name:

UERANSIM v3.0.1
[2021-01-30 05:31:55.116] [nas] [debug] NAS layer started
[2021-01-30 05:31:55.116] [rrc] [debug] RRC layer started
[2021-01-30 05:31:55.116] [nas] [info] UE switches to state: MM-DEREGISTERED/PLMN-SEARCH
terminate called after throwing an instance of 'LibError'
  what():  Bad Inet address: gnb-service No such file or directory

This can be solved by writing a script that replace the gNB service name by the corresponding IP address in the UE configuration, but I would like to want if you plan to add this functionality in the future releases (name resolution) as it is very important in environments like Kubernetes.

I want you to confirm also for the port number and the transmission protocol used by the gNB for this port (4997 and UDP).

Thank you in advance

aligungr commented 3 years ago

@raoufkh

Indeed, UE also accepts name instead of IP address in gnbSearchList field. And name resolution is performed by Linux kernel.

Could you try for example google.com in gnbSearchList instead of gnb-service to see if it works. I've just tried it and it seems working.

I don't know Kubernates pods mechanism, perhaps there is another problem about the environment.


By the way in gNB configurations, linkIp, ngapIp and gtpIp don't accept name but only accept IPv4 unlike UE config. We can fix this in the next release.


I want you to confirm also for the port number and the transmission protocol used by the gNB for this port (4997 and UDP).

Yes it's correct. UDP-4997 is used for radio link simulation between UE and gNB. (4997 is my birthday: 4.9.1997)

raoufkh commented 3 years ago

You are right! nslookup was not installed within the container. Now i works fine! thank you!

Will wait 04.09 to wish you a happy birthday :D

raoufkh commented 3 years ago

Hi again!

In the free5gc webui the default NSSSAI is (SST=1, SD=010203). In the UE config example tou have set the NSSAI to (SST=1, SD=1). I've set it to the good value (SST=1, SD=010203) in both UE and gNB configs but I'm having this error message in the AMF:

2021-02-01T01:17:49Z [INFO][AMF][Gmm] Handle UL NAS Transport (/go/src/free5gc/src/amf/gmm/handler.go:39 free5gc/src/amf/gmm.HandleULNASTransport)
2021-02-01T01:17:49Z [INFO][AMF][Gmm] [AMF] Handle PDU Session Establishment Request (/go/src/free5gc/src/amf/gmm/handler.go:140 free5gc/src/amf/gmm.HandlePDUSessionEstablishmentRequest)
2021-02-01T01:17:49Z [ERRO][AMF][Gmm] NSSelection Get Error[undefined response type] (/go/src/free5gc/src/amf/gmm/handler.go:345 free5gc/src/amf/gmm.selectSmf)
2021-02-01T01:17:49Z [ERRO][AMF][Gmm] [AMF] SMF Selection for Snssai[&{Sst:1 Sd:001083}] Failed[undefined response type] (/go/src/free5gc/src/amf/gmm/handler.go:187 free5gc/src/amf/gmm.HandlePDUSessionEstablishmentRequest)
2021-02-01T01:17:49Z [ERRO][AMF][Gmm] undefined response type (/go/src/free5gc/src/amf/gmm/sm.go:82 free5gc/src/amf/gmm.Registered)

The AMF is saying [AMF] SMF Selection for Snssai[&{Sst:1 Sd:001083}] Failed So anything has changed in the interpretation of the NSSAI?

aligungr commented 3 years ago

I think in free5gc console it is written in hex format. So you should set 0x010203 in our config files instead of 010203.

raoufkh commented 3 years ago

In in the last version. It was like this:

sd:
  hex: 0x010203

Now I can set only this?

sd: 0x010203

I'll try and let you know

aligungr commented 3 years ago

Yes, it should be sd: 0x010203

raoufkh commented 3 years ago

Now PDU session is created successfully (no error message from the free5gc SMF and AMF) but the TUN interface is still not created automatically. Logs from UE:

vagrant@master2:~/docker$ kubectl -n edge logs ueransim-ue-57f79d5df5-7s846
UERANSIM v3.0.2
[2021-02-01 09:40:11.020] [nas] [debug] NAS layer started
[2021-02-01 09:40:11.020] [rrc] [debug] RRC layer started
[2021-02-01 09:40:11.114] [nas] [info] UE switches to state: MM-DEREGISTERED/PLMN-SEARCH
[2021-02-01 09:40:11.115] [nas] [info] UE connected to gNB
[2021-02-01 09:40:11.115] [nas] [info] UE switches to state: MM-DEREGISTERED/NORMAL-SERVICE
[2021-02-01 09:40:11.115] [nas] [info] UE switches to state: MM-REGISTERED-INITIATED/NA
[2021-02-01 09:40:11.116] [nas] [debug] T3519 is not running, new SUCI generated.
[2021-02-01 09:40:11.317] [nas] [debug] Received rand[335E9945CC6EB1287ECA01986A6DEE05] autn[0DD596108A8B800083FB20532E99724A]
[2021-02-01 09:40:11.317] [nas] [debug] Calculated res[6288C7E2D96A3C1C] ck[8D701712FFBB5D53188274E51A95C4A2] ik[1B5EE3AC47E2576BCFC3B3FB7F826A9E] ak[1B2625E78542] mac_a[83FB20532E99724A]
[2021-02-01 09:40:11.317] [nas] [debug] Used snn[5G:mnc093.mcc208.3gppnetwork.org] sqn[16F3B3F70FC9]
[2021-02-01 09:40:11.317] [nas] [debug] Derived kSeaf[6BA03039E35F378845598E604BB7FDCB3CDCF5D3C65099EA66232DE31C0818B8] kAusf[2BDA170D9356ADDBC1B416E1433640333E9EB0EF793E02CCFE767435FE30C347] kAmf[B5ACF9127B9D1EDE744EF57851D846871599B00E177FF8D8FA89F55EC2981E11]
[2021-02-01 09:40:11.339] [nas] [debug] Derived kNasEnc[72349FAF592C1E0437ABFBFBF38E2EDF] kNasInt[1580990123A33AA2DD806247B868DC56]
[2021-02-01 09:40:11.339] [nas] [debug] Selected integrity[2] ciphering[2]
[2021-02-01 09:40:11.955] [nas] [debug] T3512 started with int[3600]
[2021-02-01 09:40:11.955] [nas] [info] UE switches to state: MM-REGISTERED/NORMAL-SERVICE
[2021-02-01 09:40:11.955] [nas] [info] UE switches to state: RM-REGISTERED
[2021-02-01 09:40:11.955] [nas] [info] Initial Registration is successful
[2021-02-01 09:40:11.955] [nas] [info] Initial PDU sessions are establishing [1#]
[2021-02-01 09:40:11.955] [nas] [debug] Sending PDU session establishment request
[2021-02-01 09:40:11.955] [nas] [debug] PDU session allocated: 1
[2021-02-01 09:40:11.955] [nas] [debug] PTI[1] allocated

Logs from gNB:

vagrant@master2:~/docker$ kubectl -n edge logs ueransim-gnb-c746fd6bb-xfbtd
UERANSIM v3.0.2
[2021-02-01 09:40:07.714] [sctp] [info] Trying to establish SCTP connection... (10.100.50.249:38412)
[2021-02-01 09:40:07.721] [sctp] [info] SCTP connection established (10.100.50.249:38412)
[2021-02-01 09:40:07.722] [sctp] [debug] SCTP association setup ascId[87]
[2021-02-01 09:40:07.722] [ngap] [debug] SCTP association setup received ascId[87]
[2021-02-01 09:40:07.722] [ngap] [debug] Sending NG Setup Request
[2021-02-01 09:40:07.730] [ngap] [debug] NG Setup Response received
[2021-02-01 09:40:07.730] [ngap] [info] NG Setup procedure is successful
[2021-02-01 09:40:11.116] [mr] [info] New UE connected to gNB. Total number of UEs is now: 1
[2021-02-01 09:40:11.117] [ngap] [debug] Initial NAS message received from UE 3
[2021-02-01 09:40:11.954] [ngap] [debug] Initial Context Setup Request received

Sadly, The ./nr-cli ue-status command and the Creating TUN interface wiki page are no more here. So troubleshooting it is difficult (I cannot try to create a TUN interface manually).

aligungr commented 3 years ago

The issue is not about the TUN interface, no worries :)

Indeed PDU session establishment isn't successfull, because core network didn't send a response to pdu session establishment request. (PDU session allocated line in the log may be confusing but it means PDU session resources are reserved for use and waiting success indication from the core network)

Do you have some logs in free5gc side? Let me check the files.

By the way, did you set S-NSSAI as well in sessions in UE config file?

raoufkh commented 3 years ago

Yes I've modified S-NSSAI in sessions field.

Logs from free5gc: SMF: smf.txt

AMF: amf.txt

Note that errors about encoding IMEI in the AMF are friendly (I had them when I was using UERANSIM v2.2.x and there was no problem).

Here is the config of the UE:

# Initial PDU sessions to be established
sessions:
  - type: 'IPv4'
    apn: 'internet'
    slice:
      sst: 1
      sd: 0x010203

# List of requested S-NSSAIs by this UE
slices:
  - sst: 1
    sd: 0x010203

# Supported encryption and integrity algorithms by this UE
integrity:
  IA1: true
  IA2: true
  IA3: true
ciphering:
  EA1: true
  EA2: true
  EA3: true

and the config of gNB:

mcc: '208'          # Mobile Country Code value
mnc: '93'           # Mobile Network Code value (2 or 3 digits)

nci: '0x0000000100' # NR Cell Identity (36-bit)
idLength: 32        # NR gNB ID length in bits [22...32]
tac: 1              # Tracking Area Code

linkIp: 0.0.0.0   # gNB's local IP address for Radio Link Simulation (Usually same with local IP)
ngapIp: 10.100.50.250
gtpIp: 10.100.50.236    # gNB's local IP address for N3 Interface (Usually same with local IP)

# List of AMF address information
amfConfigs:
  - address: 10.100.50.249
    port: 38412

# List of supported S-NSSAIs by this gNB
slices:
  - sst: 1
    sd: 0x010203

# Indicates whether or not SCTP stream number errors should be ignored.
ignoreStreamIds: true

I'll try to clean all and retry

aligungr commented 3 years ago

@raoufkh I've just checked with free5gc 3.0.5 and it worked. I pinged google over free5gc.

Perhaps the issue is about free5gs' gtp module. Did you apply the following configurations:

I'm copy-pasting from free5gc wiki

sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o <dn_interface> -j MASQUERADE
sudo systemctl stop ufw

and

git clone https://github.com/PrinzOwO/gtp5g.git
cd gtp5g
make
sudo make install
raoufkh commented 3 years ago

All works fine right now. This was due to an error in the UPF (context does exist) because I had already tried to create an UE before.

Thank you for your support!

raoufkh commented 3 years ago

I will also update the free5gc Helm charts to v3.0.5 but there is more work to do because all configuration files have changed :( but I'll do it.