diff --git a/configs/00101.yaml.in b/configs/00101.yaml.in deleted file mode 100644 index 272aa67f7..000000000 --- a/configs/00101.yaml.in +++ /dev/null @@ -1,108 +0,0 @@ -db_uri: mongodb://localhost/open5gs - -logger: - -parameter: -# no_nrf: true -# no_amf: true -# no_smf: true -# no_upf: true -# no_ausf: true -# no_udm: true -# no_udr: true - -amf: - sbi: - - addr: 127.0.0.2 - port: 7777 - ngap: - - addr: 127.0.0.2 - guami: - - plmn_id: - mcc: 001 - mnc: 01 - amf_id: - region: 1 - set: 1 - pointer: 1 - tai: - - plmn_id: - mcc: 001 - mnc: 01 - tac: 81 - plmn: - - plmn_id: - mcc: 001 - mnc: 01 - s_nssai: - - sst: 1 - security: - integrity_order : [ NIA2, NIA1, NIA0 ] - ciphering_order : [ NEA0, NEA1, NEA2 ] - network_name: - full: Open5GS - amf_name: open5gs-amf0 - -smf: - sbi: - - addr: 127.0.0.3 - port: 7777 - gtpc: - - addr: 127.0.0.3 - - addr: ::1 - pfcp: - - addr: 127.0.0.3 - pdn: - - addr: 10.45.0.1/16 - - addr: cafe::1/64 - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 - mtu: 1400 - freeDiameter: - identity: pgw.open-ims.test - realm: open-ims.test - listen_on: 127.0.0.3 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: pcrf.open-ims.test - addr: 127.0.0.5 -upf: - pfcp: - - addr: 127.0.0.4 - gtpu: - - addr: - - 127.0.0.4 - - ::1 - pdn: - -ausf: - sbi: - - addr: 127.0.0.5 - port: 7777 - -udm: - sbi: - - addr: 127.0.0.6 - port: 7777 - -udr: - sbi: - - addr: 127.0.0.7 - port: 7777 -nrf: - sbi: - - addr: - - 127.0.0.1 - - ::1 - port: 7777 diff --git a/configs/23504.yaml.in b/configs/310014.yaml.in similarity index 74% rename from configs/23504.yaml.in rename to configs/310014.yaml.in index 630f25354..8dd7cbd36 100644 --- a/configs/23504.yaml.in +++ b/configs/310014.yaml.in @@ -3,7 +3,6 @@ db_uri: mongodb://localhost/open5gs logger: parameter: - no_ipv6: true # no_nrf: true # no_amf: true # no_smf: true @@ -11,13 +10,11 @@ parameter: # no_ausf: true # no_udm: true # no_udr: true - -nrf: - sbi: - addr: - - 127.0.0.1 - - ::1 - port: 7777 +# no_mme: true +# no_sgwc: true +# no_sgwu: true +# no_pcrf: true +# no_hss: true mme: freeDiameter: @@ -35,25 +32,25 @@ mme: - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - identity: hss.localdomain - addr: 127.0.0.4 + addr: 127.0.0.8 s1ap: - addr: 127.0.0.1 + addr: 127.0.0.2 gtpc: - addr: 127.0.0.1 - gummei: + addr: 127.0.0.2 + gummei: plmn_id: - mcc: 235 - mnc: 04 - mme_gid: 32769 + mcc: 310 + mnc: 014 + mme_gid: 2 mme_code: 1 tai: plmn_id: - mcc: 235 - mnc: 04 + mcc: 310 + mnc: 014 tac: 1 security: - integrity_order : [ EIA2, EIA1, EIA0 ] + integrity_order : [ EIA1, EIA2, EIA0 ] ciphering_order : [ EEA0, EEA1, EEA2 ] network_name: @@ -61,25 +58,19 @@ mme: sgwc: gtpc: - addr: 127.0.0.6 + addr: 127.0.0.3 pfcp: - addr: 127.0.0.6 - -sgwu: - gtpu: - addr: 127.0.0.7 - pfcp: - addr: 127.0.0.7 + addr: 127.0.0.3 smf: sbi: - - addr: 127.0.0.3 + - addr: 127.0.0.4 port: 7777 gtpc: - - addr: 127.0.0.3 + - addr: 127.0.0.4 - addr: ::1 pfcp: - - addr: 127.0.0.3 + - addr: 127.0.0.4 pdn: - addr: 10.45.0.1/16 - addr: cafe::1/64 @@ -92,7 +83,7 @@ smf: freeDiameter: identity: smf.localdomain realm: localdomain - listen_on: 127.0.0.3 + listen_on: 127.0.0.4 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -104,13 +95,50 @@ smf: - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - identity: pcrf.localdomain - addr: 127.0.0.5 + addr: 127.0.0.9 +amf: + sbi: + - addr: 127.0.0.5 + port: 7777 + ngap: + - addr: 127.0.0.5 + guami: + - plmn_id: + mcc: 310 + mnc: 014 + amf_id: + region: 2 + set: 1 + tai: + - plmn_id: + mcc: 310 + mnc: 014 + tac: 1 + plmn: + - plmn_id: + mcc: 310 + mnc: 014 + s_nssai: + - sst: 1 + security: + integrity_order : [ NIA1, NIA2, NIA0 ] + ciphering_order : [ NEA0, NEA1, NEA2 ] + network_name: + full: Open5GS + amf_name: open5gs-amf0 + +sgwu: + gtpu: + addr: 127.0.0.6 + pfcp: + addr: 127.0.0.6 + upf: pfcp: - - addr: 127.0.0.4 + - addr: 127.0.0.7 gtpu: - addr: - - 127.0.0.4 + - 127.0.0.7 - ::1 pdn: - addr: 10.45.0.1/16 @@ -120,7 +148,7 @@ hss: freeDiameter: identity: hss.localdomain realm: localdomain - listen_on: 127.0.0.4 + listen_on: 127.0.0.8 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -133,12 +161,11 @@ hss: connect: - identity: mme.localdomain addr: 127.0.0.2 - pcrf: freeDiameter: identity: pcrf.localdomain realm: localdomain - listen_on: 127.0.0.5 + listen_on: 127.0.0.9 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -150,4 +177,26 @@ pcrf: - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - identity: smf.localdomain - addr: 127.0.0.3 + addr: 127.0.0.4 + +nrf: + sbi: + addr: + - 127.0.0.10 + - ::1 + port: 7777 + +ausf: + sbi: + - addr: 127.0.0.11 + port: 7777 + +udm: + sbi: + - addr: 127.0.0.12 + port: 7777 + +udr: + sbi: + - addr: 127.0.0.13 + port: 7777 diff --git a/configs/5gc-sample.yaml.in b/configs/5gc-sample.yaml.in deleted file mode 100644 index cbd147fc6..000000000 --- a/configs/5gc-sample.yaml.in +++ /dev/null @@ -1,107 +0,0 @@ -db_uri: mongodb://localhost/open5gs - -logger: - -parameter: -# no_nrf: true -# no_amf: true -# no_smf: true -# no_upf: true -# no_ausf: true -# no_udm: true -# no_udr: true - -amf: - sbi: - - addr: 127.0.0.2 - port: 7777 - ngap: - - addr: 127.0.0.2 - guami: - - plmn_id: - mcc: 901 - mnc: 70 - amf_id: - region: 2 - set: 1 - tai: - - plmn_id: - mcc: 901 - mnc: 70 - tac: 1 - plmn: - - plmn_id: - mcc: 901 - mnc: 70 - s_nssai: - - sst: 1 - security: - integrity_order : [ NIA1, NIA2, NIA0 ] - ciphering_order : [ NEA0, NEA1, NEA2 ] - network_name: - full: Open5GS - amf_name: open5gs-amf0 - -smf: - sbi: - - addr: 127.0.0.3 - port: 7777 - gtpc: - - addr: 127.0.0.3 - - addr: ::1 - pfcp: - - addr: 127.0.0.3 - pdn: - - addr: 10.45.0.1/16 - - addr: cafe::1/64 - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 - mtu: 1400 - freeDiameter: - identity: pgw.open-ims.test - realm: open-ims.test - listen_on: 127.0.0.3 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: pcrf.open-ims.test - addr: 127.0.0.5 -upf: - pfcp: - - addr: 127.0.0.4 - gtpu: - - addr: - - 127.0.0.4 - - ::1 - pdn: - -ausf: - sbi: - - addr: 127.0.0.5 - port: 7777 - -udm: - sbi: - - addr: 127.0.0.6 - port: 7777 - -udr: - sbi: - - addr: 127.0.0.7 - port: 7777 -nrf: - sbi: - - addr: - - 127.0.0.1 - - ::1 - port: 7777 diff --git a/configs/5gc.yaml.in b/configs/5gc.yaml.in deleted file mode 100644 index 5bd8bbc63..000000000 --- a/configs/5gc.yaml.in +++ /dev/null @@ -1,96 +0,0 @@ -db_uri: mongodb://localhost/open5gs - -logger: - -parameter: - -amf: - sbi: - - addr: 127.0.0.2 - port: 7777 - ngap: - guami: - - plmn_id: - mcc: 901 - mnc: 70 - amf_id: - region: 2 - set: 1 - tai: - - plmn_id: - mcc: 901 - mnc: 70 - tac: 1 - plmn: - - plmn_id: - mcc: 901 - mnc: 70 - s_nssai: - - sst: 1 - security: - integrity_order : [ NIA1, NIA2, NIA0 ] - ciphering_order : [ NEA0, NEA1, NEA2 ] - network_name: - full: Open5GS - amf_name: open5gs-amf0 - -smf: - sbi: - - addr: 127.0.0.3 - port: 7777 - gtpc: - - addr: 127.0.0.3 - - addr: ::1 - pfcp: - - addr: 127.0.0.3 - pdn: - - addr: 10.45.0.1/16 - - addr: cafe::1/64 - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 - mtu: 1400 - freeDiameter: - identity: pgw.open-ims.test - realm: open-ims.test - listen_on: 127.0.0.3 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: pcrf.open-ims.test - addr: 127.0.0.5 -upf: - pfcp: - addr: 127.0.0.4 - gtpu: - pdn: - -ausf: - sbi: - - addr: 127.0.0.5 - port: 7777 - -udm: - sbi: - - addr: 127.0.0.6 - port: 7777 - -udr: - sbi: - - addr: 127.0.0.7 - port: 7777 -nrf: - sbi: - - addr: - - 127.0.0.1 - - ::1 - port: 7777 diff --git a/configs/csfb.yaml.in b/configs/csfb.yaml.in index 914d81bcf..4f24ebdd5 100644 --- a/configs/csfb.yaml.in +++ b/configs/csfb.yaml.in @@ -3,14 +3,18 @@ db_uri: mongodb://localhost/open5gs logger: parameter: - no_ipv6: true - -nrf: - sbi: - addr: - - 127.0.0.1 - - ::1 - port: 7777 +# no_nrf: true +# no_amf: true +# no_smf: true +# no_upf: true +# no_ausf: true +# no_udm: true +# no_udr: true +# no_mme: true +# no_sgwc: true +# no_sgwu: true +# no_pcrf: true +# no_hss: true mme: freeDiameter: @@ -28,12 +32,12 @@ mme: - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - identity: hss.localdomain - addr: 127.0.0.4 + addr: 127.0.0.8 s1ap: - addr: 127.0.0.1 + addr: 127.0.0.2 gtpc: - addr: 127.0.0.1 + addr: 127.0.0.2 sgsap: - addr: 127.0.0.2 map: @@ -58,7 +62,7 @@ mme: mcc: 724 mnc: 21 lac: 51544 - gummei: + gummei: - plmn_id: mcc: 901 mnc: 70 @@ -88,25 +92,19 @@ mme: sgwc: gtpc: - addr: 127.0.0.6 + addr: 127.0.0.3 pfcp: - addr: 127.0.0.6 - -sgwu: - gtpu: - addr: 127.0.0.7 - pfcp: - addr: 127.0.0.7 + addr: 127.0.0.3 smf: sbi: - - addr: 127.0.0.3 + - addr: 127.0.0.4 port: 7777 gtpc: - - addr: 127.0.0.3 + - addr: 127.0.0.4 - addr: ::1 pfcp: - - addr: 127.0.0.3 + - addr: 127.0.0.4 pdn: - addr: 10.45.0.1/16 - addr: cafe::1/64 @@ -119,7 +117,7 @@ smf: freeDiameter: identity: smf.localdomain realm: localdomain - listen_on: 127.0.0.3 + listen_on: 127.0.0.4 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -131,13 +129,50 @@ smf: - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - identity: pcrf.localdomain - addr: 127.0.0.5 + addr: 127.0.0.9 +amf: + sbi: + - addr: 127.0.0.5 + port: 7777 + ngap: + - addr: 127.0.0.5 + guami: + - plmn_id: + mcc: 901 + mnc: 70 + amf_id: + region: 2 + set: 1 + tai: + - plmn_id: + mcc: 901 + mnc: 70 + tac: 1 + plmn: + - plmn_id: + mcc: 901 + mnc: 70 + s_nssai: + - sst: 1 + security: + integrity_order : [ NIA1, NIA2, NIA0 ] + ciphering_order : [ NEA0, NEA1, NEA2 ] + network_name: + full: Open5GS + amf_name: open5gs-amf0 + +sgwu: + gtpu: + addr: 127.0.0.6 + pfcp: + addr: 127.0.0.6 + upf: pfcp: - - addr: 127.0.0.4 + - addr: 127.0.0.7 gtpu: - addr: - - 127.0.0.4 + - 127.0.0.7 - ::1 pdn: - addr: 10.45.0.1/16 @@ -147,7 +182,7 @@ hss: freeDiameter: identity: hss.localdomain realm: localdomain - listen_on: 127.0.0.4 + listen_on: 127.0.0.8 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -160,12 +195,11 @@ hss: connect: - identity: mme.localdomain addr: 127.0.0.2 - pcrf: freeDiameter: identity: pcrf.localdomain realm: localdomain - listen_on: 127.0.0.5 + listen_on: 127.0.0.9 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -177,4 +211,26 @@ pcrf: - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - identity: smf.localdomain - addr: 127.0.0.3 + addr: 127.0.0.4 + +nrf: + sbi: + addr: + - 127.0.0.10 + - ::1 + port: 7777 + +ausf: + sbi: + - addr: 127.0.0.11 + port: 7777 + +udm: + sbi: + - addr: 127.0.0.12 + port: 7777 + +udr: + sbi: + - addr: 127.0.0.13 + port: 7777 diff --git a/configs/cups.yaml.in b/configs/cups.yaml.in deleted file mode 100644 index 7ee72afa4..000000000 --- a/configs/cups.yaml.in +++ /dev/null @@ -1,158 +0,0 @@ -db_uri: mongodb://localhost/open5gs - -logger: - -parameter: -# no_nrf: true -# no_amf: true -# no_smf: true -# no_upf: true -# no_ausf: true -# no_udm: true -# no_udr: true - -nrf: - sbi: - addr: - - 127.0.0.1 - - ::1 - port: 7777 - -mme: - freeDiameter: - identity: mme.open-ims.test - realm: open-ims.test -# port: 3868 -# sec_port: 5868 - listen_on: 127.0.0.2 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: hss.open-ims.test - addr: 127.0.0.4 -# port: 3868 - - s1ap: - addr: 127.0.0.1 - gtpc: - addr: 127.0.0.1 - gummei: - plmn_id: - mcc: 001 - mnc: 01 - mme_gid: 2 - mme_code: 1 - tai: - plmn_id: - mcc: 001 - mnc: 01 - tac: 12345 - security: - integrity_order : [ EIA1, EIA2, EIA0 ] - ciphering_order : [ EEA0, EEA1, EEA2 ] - -sgwc: - gtpc: - addr: 127.0.0.6 - pfcp: - addr: 127.0.0.6 - -sgwu: - gtpu: - addr: 127.0.0.7 - pfcp: - addr: 127.0.0.7 - -smf: - sbi: - - addr: 127.0.0.3 - port: 7777 - gtpc: - - addr: 127.0.0.3 - - addr: ::1 - pfcp: - - addr: 127.0.0.3 - pdn: - - addr: 10.45.0.1/16 - - addr: cafe::1/64 - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 - mtu: 1400 - freeDiameter: - identity: smf.open-ims.test - realm: open-ims.test -# port: 3868 -# sec_port: 5868 - listen_on: 127.0.0.3 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: pcrf.open-ims.test - addr: 127.0.0.5 -# port: 3868 - -upf: - pfcp: - - addr: 127.0.0.4 - gtpu: - - addr: - - 127.0.0.4 - - ::1 - pdn: - - addr: 10.45.0.1/16 - - addr: cafe::1/64 - -hss: - freeDiameter: - identity: hss.open-ims.test - realm: open-ims.test - listen_on: 127.0.0.4 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: mme.open-ims.test - addr: 127.0.0.2 - -pcrf: - freeDiameter: - identity: pcrf.open-ims.test - realm: open-ims.test - listen_on: 127.0.0.5 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: smf.open-ims.test - addr: 127.0.0.3 - - identity: pcscf.open-ims.test - addr: 127.0.0.1 diff --git a/configs/epc-custom.yaml.in b/configs/epc-custom.yaml.in deleted file mode 100644 index a0ee41cc4..000000000 --- a/configs/epc-custom.yaml.in +++ /dev/null @@ -1,121 +0,0 @@ -db_uri: mongodb://localhost/open5gs - -logger: - -parameter: - no_ipv6: true - -mme: - freeDiameter: - identity: mme.localdomain - realm: localdomain - listen_on: 127.0.0.2 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: hss.localdomain - addr: 127.0.0.4 - - s1ap: - gtpc: - addr: 127.0.0.1 - gummei: - plmn_id: - mcc: 901 - mnc: 70 - mme_gid: 2 - mme_code: 1 - tai: - plmn_id: - mcc: 901 - mnc: 70 - tac: 7 - security: - integrity_order : [ EIA1, EIA2, EIA0 ] - ciphering_order : [ EEA0, EEA1, EEA2 ] - - network_name: - full: Open5GS - -hss: - freeDiameter: - identity: hss.localdomain - realm: localdomain - listen_on: 127.0.0.4 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: mme.localdomain - addr: 127.0.0.2 - -sgw: - gtpc: - addr: 127.0.0.2 - gtpu: - -pgw: - freeDiameter: - identity: pgw.localdomain - realm: localdomain - listen_on: 127.0.0.3 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: pcrf.localdomain - addr: 127.0.0.5 - - gtpc: - addr: - - 127.0.0.3 - - ::1 - gtpu: - - addr: 127.0.0.3 - - addr: ::1 - pdn: - - addr: 10.45.0.1/16 - - addr: cafe::1/64 - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 - mtu: 1400 - -pcrf: - freeDiameter: - identity: pcrf.localdomain - realm: localdomain - listen_on: 127.0.0.5 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: pgw.localdomain - addr: 127.0.0.3 diff --git a/configs/epc-fdconf.yaml.in b/configs/epc-fdconf.yaml.in deleted file mode 100644 index 103627a0f..000000000 --- a/configs/epc-fdconf.yaml.in +++ /dev/null @@ -1,64 +0,0 @@ -db_uri: mongodb://localhost/open5gs - -logger: - file: @localstatedir@/log/open5gs/open5gs.log - -parameter: - no_ipv6: true - -mme: - freeDiameter: @sysconfdir@/freeDiameter/mme.conf - s1ap: - addr: 127.0.0.1 - gtpc: - addr: 127.0.0.1 - sgsap: - gummei: - plmn_id: - mcc: 901 - mnc: 70 - mme_gid: 2 - mme_code: 1 - tai: - plmn_id: - mcc: 901 - mnc: 70 - tac: 1 - - security: - integrity_order : [ EIA1, EIA2, EIA0 ] - ciphering_order : [ EEA0, EEA1, EEA2 ] - network_name: - full: Open5GS - -hss: - freeDiameter: @sysconfdir@/freeDiameter/hss.conf - -sgw: - gtpc: - addr: 127.0.0.2 - gtpu: - addr: 127.0.0.2 - -pgw: - freeDiameter: @sysconfdir@/freeDiameter/pgw.conf - gtpc: - addr: - - 127.0.0.3 - - ::1 - gtpu: - - addr: 127.0.0.3 - - addr: ::1 - pdn: - - addr: 10.45.0.1/16 - - addr: cafe::1/64 - - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 - mtu: 1400 - -pcrf: - freeDiameter: @sysconfdir@/freeDiameter/pcrf.conf diff --git a/configs/epc.yaml.in b/configs/epc.yaml.in deleted file mode 100644 index ee8d1abff..000000000 --- a/configs/epc.yaml.in +++ /dev/null @@ -1,146 +0,0 @@ -db_uri: mongodb://localhost/open5gs - -logger: - -parameter: - no_ipv6: true - -nrf: - sbi: - addr: - - 127.0.0.1 - - ::1 - port: 7777 - -mme: - freeDiameter: - identity: mme.localdomain - realm: localdomain - listen_on: 127.0.0.2 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: hss.localdomain - addr: 127.0.0.4 - - s1ap: - addr: 127.0.0.1 - gtpc: - addr: 127.0.0.1 - gummei: - plmn_id: - mcc: 001 - mnc: 01 - mme_gid: 2 - mme_code: 1 - tai: - plmn_id: - mcc: 001 - mnc: 01 - tac: 12345 - security: - integrity_order : [ EIA1, EIA2, EIA0 ] - ciphering_order : [ EEA0, EEA1, EEA2 ] - - network_name: - full: Open5GS - -sgwc: - gtpc: - addr: 127.0.0.6 - pfcp: - addr: 127.0.0.6 - -sgwu: - gtpu: - addr: 127.0.0.7 - pfcp: - addr: 127.0.0.7 - -smf: - sbi: - - addr: 127.0.0.3 - port: 7777 - gtpc: - - addr: 127.0.0.3 - - addr: ::1 - pfcp: - - addr: 127.0.0.3 - pdn: - - addr: 10.45.0.1/16 - - addr: cafe::1/64 - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 - mtu: 1400 - freeDiameter: - identity: smf.localdomain - realm: localdomain - listen_on: 127.0.0.3 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: pcrf.localdomain - addr: 127.0.0.5 -upf: - pfcp: - - addr: 127.0.0.4 - gtpu: - - addr: - - 127.0.0.4 - - ::1 - pdn: - - addr: 10.45.0.1/16 - - addr: cafe::1/64 - -hss: - freeDiameter: - identity: hss.localdomain - realm: localdomain - listen_on: 127.0.0.4 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: mme.localdomain - addr: 127.0.0.2 - -pcrf: - freeDiameter: - identity: pcrf.localdomain - realm: localdomain - listen_on: 127.0.0.5 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: smf.localdomain - addr: 127.0.0.3 diff --git a/configs/freeDiameter/cacert.pem b/configs/freeDiameter/cacert.pem index 5536d8663..5a73c99ef 100644 --- a/configs/freeDiameter/cacert.pem +++ b/configs/freeDiameter/cacert.pem @@ -1,17 +1,17 @@ -----BEGIN CERTIFICATE----- -MIICrDCCAhWgAwIBAgIUPoUbKXRTWQbrJYUIvyHdacCzw9cwDQYJKoZIhvcNAQEL +MIICrDCCAhWgAwIBAgIUX3u0zTLhQTa3lsR92/GelxTGQacwDQYJKoZIhvcNAQEL BQAwaDEXMBUGA1UEAwwOY2EubG9jYWxkb21haW4xCzAJBgNVBAYTAktPMQ4wDAYD VQQIDAVTZW91bDEOMAwGA1UEBwwFTm93b24xEDAOBgNVBAoMB09wZW41R1MxDjAM -BgNVBAsMBVRlc3RzMB4XDTE5MTAyMDA2NDM1OFoXDTI5MTAxNzA2NDM1OFowaDEX +BgNVBAsMBVRlc3RzMB4XDTIwMDgyMjAwMzkxNloXDTMwMDgyMDAwMzkxNlowaDEX MBUGA1UEAwwOY2EubG9jYWxkb21haW4xCzAJBgNVBAYTAktPMQ4wDAYDVQQIDAVT ZW91bDEOMAwGA1UEBwwFTm93b24xEDAOBgNVBAoMB09wZW41R1MxDjAMBgNVBAsM -BVRlc3RzMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2sDnWMj9oXpIw+vcm -9k/WidMyhSbImINLe9YgibFfozoxZt51Hvi/aAxlqyq7akGtvpL8yVZD6j7o74z7 -6dlnUFDGC4M0WGEkcxqf5NIWe0QplCsXkEOMYHrXLQisAuUk81DNcsXlZr74bmDI -B0dUM0xJ2JrA5mx1LzTFHSesIwIDAQABo1MwUTAdBgNVHQ4EFgQUxTjcug/DKW49 -mQeW0IcS/bhIzDcwHwYDVR0jBBgwFoAUxTjcug/DKW49mQeW0IcS/bhIzDcwDwYD -VR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQB533IwIPOEE1w2RLBF9EKX -UxaDnUYW05t9eZFLsUtOLFiR84xhCawGEWNtaLvoJE42E17qEjnX4+KGOc6/sa6q -bLskf7BK7496dQrVY5DO9vdSpN1ep3j+1QKae23wYpjqt2UEU3QtIZpsDjUreYri -YLVacMQydGgizNQrY3iCvQ== +BVRlc3RzMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCuPWKllQ1+hM/wQE08 +xjDBiSx9GQOCEF5dkLK126u4joIhNFig6wfn/Ui0nq88ApUlEREUXB3D33ZEsAkt +cbwz1UHX2THOeTYX8XdDbkwkbxNOOH902duiQ2UUbf8ve1hsV7+Dr7ue2Fmz4gsR +lHBv1EsIyPZJQlb4qxET+2++2QIDAQABo1MwUTAdBgNVHQ4EFgQUZPvI16MgF9yo +OqpLK4XNvT5TSwkwHwYDVR0jBBgwFoAUZPvI16MgF9yoOqpLK4XNvT5TSwkwDwYD +VR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQAwGvKdevLJNDuSXsFpIkTE +ZRsNnKrprNgbZC4/HkrzpvR1aDQgcSqF12DzSUmoTqzESuMtKvkaLv2IqYko9g4p +iKVu2jBDKrJq4q63Cy71fxwbtXLrqGaWgbXkepzqyJYjn4Nf/ya0shK7l2rIIDyL +crvs5/rXN6enLFUQ3n955w== -----END CERTIFICATE----- diff --git a/configs/freeDiameter/hss.cert.pem b/configs/freeDiameter/hss.cert.pem index 629f150a6..4d9ce3953 100644 --- a/configs/freeDiameter/hss.cert.pem +++ b/configs/freeDiameter/hss.cert.pem @@ -5,22 +5,22 @@ Certificate: Signature Algorithm: sha256WithRSAEncryption Issuer: CN=ca.localdomain, C=KO, ST=Seoul, L=Nowon, O=Open5GS, OU=Tests Validity - Not Before: Oct 20 06:43:58 2019 GMT - Not After : Oct 17 06:43:58 2029 GMT + Not Before: Aug 22 00:39:17 2020 GMT + Not After : Aug 20 00:39:17 2030 GMT Subject: C=KO, ST=Seoul, O=Open5GS, OU=Tests, CN=hss.localdomain Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (1024 bit) Modulus: - 00:d3:e7:ba:6d:14:65:af:df:90:e5:4a:53:56:a1: - f6:89:2e:cb:ee:ce:d6:73:9f:48:b6:96:78:67:a7: - 87:18:b8:ab:c3:0b:31:b3:02:92:48:ed:49:ac:40: - c1:13:3b:13:58:50:cc:2e:59:44:e9:7e:31:02:14: - f0:18:82:95:10:e4:37:b2:5d:14:19:1d:4b:8f:e9: - 1f:45:75:cf:0a:e0:8f:7b:e1:70:7b:ab:e4:af:2b: - 7c:4d:7f:00:d8:eb:cf:f3:96:ab:fc:04:4f:21:ad: - d8:c4:94:05:02:ff:f3:12:48:88:9e:ce:cf:37:29: - e0:28:39:37:62:05:ed:6d:5d + 00:e8:b3:82:96:bd:4a:f6:30:2c:03:60:aa:82:65: + b0:15:32:5f:d3:90:0d:c0:1d:06:62:52:51:c7:12: + 36:d7:5c:34:21:ac:4a:44:4d:9b:a5:22:9c:3e:86: + a8:ba:df:02:64:b6:74:f5:95:c4:71:e8:e0:28:1d: + 2b:ea:06:94:fa:3c:f1:07:d3:23:55:b6:84:d4:00: + f4:28:08:18:be:c7:38:e1:b7:d9:b4:bf:d3:e1:d3: + d8:13:60:72:e1:e4:d3:31:37:b1:cf:b9:e1:c9:8d: + 5e:e2:1c:54:a3:90:b1:69:6f:07:90:ff:68:86:69: + 7d:ef:50:69:0d:9d:47:18:39 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: @@ -28,33 +28,33 @@ Certificate: Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: - AB:0F:C4:B8:B7:6B:56:12:F5:D4:A3:29:B7:D9:5E:3C:DD:8B:79:DD + 74:20:F9:E9:BD:E1:37:8A:9C:A9:AD:B4:B2:28:7D:44:22:0B:BD:0B X509v3 Authority Key Identifier: - keyid:C5:38:DC:BA:0F:C3:29:6E:3D:99:07:96:D0:87:12:FD:B8:48:CC:37 + keyid:64:FB:C8:D7:A3:20:17:DC:A8:3A:AA:4B:2B:85:CD:BD:3E:53:4B:09 Signature Algorithm: sha256WithRSAEncryption - 43:95:ee:57:3f:4d:ad:bf:42:6c:48:ae:f8:2f:db:f6:cf:2e: - 53:a2:3d:48:0a:48:a4:2c:2a:7c:fa:ec:b1:bd:06:a1:21:a5: - 38:d8:00:05:81:25:91:51:e2:e6:a8:67:a8:c2:f6:5d:2a:f0: - 40:fe:20:d3:82:2d:d9:8c:4c:61:b7:43:87:7f:fe:e4:a1:b6: - fd:54:35:13:4f:63:a5:6b:4a:01:aa:25:e9:80:27:eb:2e:a2: - 18:e0:36:37:a5:57:09:67:ed:8f:1e:13:fd:b8:b2:d7:4e:cf: - 93:d4:bf:75:02:38:4e:d4:4a:9c:35:fb:a8:0b:3a:ba:03:1a: - e6:9e + ac:aa:85:5a:57:61:6d:7d:f3:c4:2a:b7:73:3f:e9:bc:b9:6d: + 0a:8f:35:24:13:66:46:14:5e:60:90:3e:32:95:72:5a:21:55: + 15:fe:ef:30:44:fb:fe:3e:cb:bf:f3:30:ce:3b:bb:4f:c1:64: + 41:ea:db:99:f2:ca:db:78:03:95:81:91:3c:fa:1d:9c:8a:55: + eb:9d:6a:c1:b6:de:44:38:0f:99:b4:66:d5:4e:dd:e7:d5:ba: + ff:f2:4b:f6:9a:94:53:55:36:4e:73:2d:da:d1:bb:0f:8f:fb: + 1a:22:43:28:6a:b4:5d:a3:40:2c:cf:7e:0d:3e:fb:60:ef:92: + f3:0e -----BEGIN CERTIFICATE----- MIICsjCCAhugAwIBAgIBAjANBgkqhkiG9w0BAQsFADBoMRcwFQYDVQQDDA5jYS5s b2NhbGRvbWFpbjELMAkGA1UEBhMCS08xDjAMBgNVBAgMBVNlb3VsMQ4wDAYDVQQH -DAVOb3dvbjEQMA4GA1UECgwHT3BlbjVHUzEOMAwGA1UECwwFVGVzdHMwHhcNMTkx -MDIwMDY0MzU4WhcNMjkxMDE3MDY0MzU4WjBZMQswCQYDVQQGEwJLTzEOMAwGA1UE +DAVOb3dvbjEQMA4GA1UECgwHT3BlbjVHUzEOMAwGA1UECwwFVGVzdHMwHhcNMjAw +ODIyMDAzOTE3WhcNMzAwODIwMDAzOTE3WjBZMQswCQYDVQQGEwJLTzEOMAwGA1UE CAwFU2VvdWwxEDAOBgNVBAoMB09wZW41R1MxDjAMBgNVBAsMBVRlc3RzMRgwFgYD VQQDDA9oc3MubG9jYWxkb21haW4wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB -ANPnum0UZa/fkOVKU1ah9okuy+7O1nOfSLaWeGenhxi4q8MLMbMCkkjtSaxAwRM7 -E1hQzC5ZROl+MQIU8BiClRDkN7JdFBkdS4/pH0V1zwrgj3vhcHur5K8rfE1/ANjr -z/OWq/wETyGt2MSUBQL/8xJIiJ7Ozzcp4Cg5N2IF7W1dAgMBAAGjezB5MAkGA1Ud +AOizgpa9SvYwLANgqoJlsBUyX9OQDcAdBmJSUccSNtdcNCGsSkRNm6UinD6GqLrf +AmS2dPWVxHHo4CgdK+oGlPo88QfTI1W2hNQA9CgIGL7HOOG32bS/0+HT2BNgcuHk +0zE3sc+54cmNXuIcVKOQsWlvB5D/aIZpfe9QaQ2dRxg5AgMBAAGjezB5MAkGA1Ud EwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmlj -YXRlMB0GA1UdDgQWBBSrD8S4t2tWEvXUoym32V483Yt53TAfBgNVHSMEGDAWgBTF -ONy6D8Mpbj2ZB5bQhxL9uEjMNzANBgkqhkiG9w0BAQsFAAOBgQBDle5XP02tv0Js -SK74L9v2zy5Toj1ICkikLCp8+uyxvQahIaU42AAFgSWRUeLmqGeowvZdKvBA/iDT -gi3ZjExht0OHf/7kobb9VDUTT2Ola0oBqiXpgCfrLqIY4DY3pVcJZ+2PHhP9uLLX -Ts+T1L91AjhO1EqcNfuoCzq6Axrmng== +YXRlMB0GA1UdDgQWBBR0IPnpveE3ipyprbSyKH1EIgu9CzAfBgNVHSMEGDAWgBRk ++8jXoyAX3Kg6qksrhc29PlNLCTANBgkqhkiG9w0BAQsFAAOBgQCsqoVaV2FtffPE +KrdzP+m8uW0KjzUkE2ZGFF5gkD4ylXJaIVUV/u8wRPv+Psu/8zDOO7tPwWRB6tuZ +8srbeAOVgZE8+h2cilXrnWrBtt5EOA+ZtGbVTt3n1br/8kv2mpRTVTZOcy3a0bsP +j/saIkMoarRdo0Asz34NPvtg75LzDg== -----END CERTIFICATE----- diff --git a/configs/freeDiameter/hss.conf.in b/configs/freeDiameter/hss.conf.in index c0feb322d..619d98f89 100644 --- a/configs/freeDiameter/hss.conf.in +++ b/configs/freeDiameter/hss.conf.in @@ -79,7 +79,7 @@ Realm = "localdomain"; #ListenOn = "202.249.37.5"; #ListenOn = "2001:200:903:2::202:1"; #ListenOn = "fe80::21c:5ff:fe98:7d62%eth0"; -ListenOn = "127.0.0.4"; +ListenOn = "127.0.0.8"; ############################################################## diff --git a/configs/freeDiameter/hss.key.pem b/configs/freeDiameter/hss.key.pem index fcf33a1c3..b6362d4d4 100644 --- a/configs/freeDiameter/hss.key.pem +++ b/configs/freeDiameter/hss.key.pem @@ -1,15 +1,15 @@ -----BEGIN RSA PRIVATE KEY----- -MIICXQIBAAKBgQDT57ptFGWv35DlSlNWofaJLsvuztZzn0i2lnhnp4cYuKvDCzGz -ApJI7UmsQMETOxNYUMwuWUTpfjECFPAYgpUQ5DeyXRQZHUuP6R9Fdc8K4I974XB7 -q+SvK3xNfwDY68/zlqv8BE8hrdjElAUC//MSSIiezs83KeAoOTdiBe1tXQIDAQAB -AoGBAM7ShI2Ec/9lSInSsmaC7BpW12p87KirFZBIarpYs634SIS0v0xFvTt6hgae -qRO4/BedvLucG3t91B2BDBoQEaZELCjJ9kCUtzphW+u8/SUvPUCfb5xiLLeDQCVR -oU45JuqlF+ro9XM0x7f1REuTza1Xr20O5n5TzaCzQkdTlMdtAkEA+Yk9aS589D2c -TAj7H5nQMFai/z0JKM7kuBmXaqbsPtnYjdNvVYsCRPcjbhyfIjN88o/QGuUuInpb -PyzUZh3x2wJBANlk8d5ZVco+UE1NX0KzpEXHMY+z8kE4f8IMy0KN1V+An0ZbdxJE -X0aUMz9/K0+V6n0rlpY4QdOnTnbIEg2hTycCQDXBUM9lylk7JH5kuORX2Ddxkm91 -kJGP8EmQicPZ7a6kczgqQiOlbHm625EO7WEKwnHmdSg2Ergur5VubNsKvF0CQQCc -sbv8rpu9qOisr2ZIZ7+yY/9/Ow8Un6rGrf4cPKtdqRIk3myXCB08fDnsPLd1J/Pa -wP5LzMT10BQoXdFVbb3lAkBpNXUkts8O1YxSG5zTruvygjU2n4Lova31icJ8HFaG -pfKHJpqDGPooupFxeCsPVPBZIRtxW70CZcr77eW/XKXv +MIICXQIBAAKBgQDos4KWvUr2MCwDYKqCZbAVMl/TkA3AHQZiUlHHEjbXXDQhrEpE +TZulIpw+hqi63wJktnT1lcRx6OAoHSvqBpT6PPEH0yNVtoTUAPQoCBi+xzjht9m0 +v9Ph09gTYHLh5NMxN7HPueHJjV7iHFSjkLFpbweQ/2iGaX3vUGkNnUcYOQIDAQAB +AoGAdxNkv74dnd0IqLHOjut6L16XqqsMXkJ8AdQeBMBNT+bexlxjpJASFW6ghV5i ++T0k/GRhdUouPBvumJhU4Gx9zpVYUMzAxZDgWQfoknQ11fs6bi1aH8Fn9NhC3UeB +ZaSmkAyeTMpJMzVAiVLND3iN/83OcijqSq2MZ4kkdsQngAECQQD/AOBiwlh6AVtZ +bJMbVSVPLdtQRtGuP29gaC64vROE60qfxUcW7H2rHdMq4AWrlaZ3hXxSLU+TuCDt +Z7khtHexAkEA6ZxSJfw1SO0qqu/uHBcQTOzoTKPi28fRt2ilEIOhIzuHbJPpjFEp +snhGfX+XgD4EtXH1ebdmh+rGZ8yRPcjTCQJBAJ170xfq4m1mzR2q+ibVLNd7gIhR +VEmCj6xAaypYSue50DpfwYmcv/ef0bwW4imXoFkMLT0rEowuGNfFSQZRx+ECQETG +TrD8JTvJBsy4QiNm7teWz3TwsrL9itIyLpZECkZzGhVvHky/AEWYfzgnPhT1LTG1 +0Qz6X2cYSTz5zrCf1PECQQCPZIkkOUsgq6kGDK5MTzAoTjPxzIDgLX/YdMelwHUA +pK+nv/gxO9Pjd+wcU4GmaD0KXdLtu+dsKT3bx/7RzGjj -----END RSA PRIVATE KEY----- diff --git a/configs/freeDiameter/meson.build b/configs/freeDiameter/meson.build index 923e96180..09887f276 100644 --- a/configs/freeDiameter/meson.build +++ b/configs/freeDiameter/meson.build @@ -23,6 +23,7 @@ freediameter_conf = ''' mme.conf hss.conf pgw.conf + smf.conf pcrf.conf '''.split() @@ -43,6 +44,8 @@ freediameter_pem = ''' hss.key.pem pgw.cert.pem pgw.key.pem + smf.cert.pem + smf.key.pem pcrf.cert.pem pcrf.key.pem '''.split() diff --git a/configs/freeDiameter/mme.cert.pem b/configs/freeDiameter/mme.cert.pem index 2e84db4ce..cca1c9792 100644 --- a/configs/freeDiameter/mme.cert.pem +++ b/configs/freeDiameter/mme.cert.pem @@ -5,22 +5,22 @@ Certificate: Signature Algorithm: sha256WithRSAEncryption Issuer: CN=ca.localdomain, C=KO, ST=Seoul, L=Nowon, O=Open5GS, OU=Tests Validity - Not Before: Oct 20 06:43:58 2019 GMT - Not After : Oct 17 06:43:58 2029 GMT + Not Before: Aug 22 00:39:17 2020 GMT + Not After : Aug 20 00:39:17 2030 GMT Subject: C=KO, ST=Seoul, O=Open5GS, OU=Tests, CN=mme.localdomain Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (1024 bit) Modulus: - 00:b5:3a:31:ed:bf:fe:cd:e7:50:cc:94:ba:3d:fd: - 2f:e6:cb:83:25:3d:82:93:26:57:b4:2f:6b:29:d9: - fd:80:c8:c5:82:9c:09:17:14:38:91:57:ac:72:b0: - 86:d4:6f:bd:6b:fa:b9:60:51:9b:ab:6b:68:37:15: - c7:de:8b:bd:e8:da:5a:49:75:03:33:09:8e:49:e4: - d9:5b:3c:2f:ca:47:9b:95:d5:6f:16:e4:8d:39:b4: - 39:dd:51:1a:55:27:68:b9:a0:24:ad:1c:18:48:bb: - 49:54:ae:03:a3:0b:b8:e5:da:b4:c2:7f:09:a4:12: - 8e:97:08:58:24:6a:4b:f4:87 + 00:9c:69:25:fc:ee:7f:11:e0:81:f7:b5:51:8f:01: + b8:9e:01:74:03:3e:a5:25:de:6f:28:66:05:6f:7b: + ab:86:0f:09:fc:94:7b:e8:aa:9f:0b:5f:32:27:46: + f0:ca:e2:12:f3:5d:03:80:e9:9a:1d:f0:20:d6:5c: + 1b:4b:65:d4:66:e3:b7:63:19:6e:b1:e8:db:6c:24: + df:24:2c:50:f2:1c:8a:33:c1:f7:27:b8:3c:6e:c6: + 90:98:ac:43:67:00:6b:3d:ab:39:49:3d:d5:74:77: + 6a:0e:38:4e:41:cd:e4:15:63:27:76:b5:9c:75:f8: + cb:6f:cc:5e:f3:a7:68:ef:a5 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: @@ -28,33 +28,33 @@ Certificate: Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: - 20:74:06:F0:AF:F6:2D:90:D1:CB:8C:5C:AB:73:D7:45:99:31:DD:AA + 92:69:1E:3F:9F:E2:40:2F:81:24:05:B4:13:AA:8A:65:5C:7C:71:1D X509v3 Authority Key Identifier: - keyid:C5:38:DC:BA:0F:C3:29:6E:3D:99:07:96:D0:87:12:FD:B8:48:CC:37 + keyid:64:FB:C8:D7:A3:20:17:DC:A8:3A:AA:4B:2B:85:CD:BD:3E:53:4B:09 Signature Algorithm: sha256WithRSAEncryption - 0a:f5:fd:1f:19:52:9a:99:ec:34:67:e8:57:dc:61:73:c0:05: - b0:53:e3:8f:66:86:c9:99:af:28:5a:2a:06:a8:53:b1:80:ea: - 5c:c9:ad:93:ec:b8:b4:b0:e4:04:8b:85:1b:08:93:f2:71:b1: - 21:ab:80:40:e4:27:c6:c5:7a:56:f2:d2:33:6c:f0:1d:f4:99: - 85:55:60:9c:eb:d3:b8:e3:4b:e5:be:1e:d2:39:d5:55:6f:4c: - 20:07:c8:24:1c:21:70:e4:54:17:0b:a5:66:17:be:8b:5c:73: - ca:5e:42:6e:27:15:18:69:dc:c6:49:97:d7:66:e0:a8:ad:9c: - f1:b7 + 74:fc:32:ee:e6:2b:a5:f5:a4:71:64:49:ff:eb:6f:01:30:32: + b7:61:62:97:e1:2c:0f:50:62:a8:71:9a:bd:8b:d8:0d:4b:28: + ea:b4:5f:1c:30:3e:4c:23:2f:c5:5b:77:ed:48:c2:bb:b7:0c: + d9:50:4d:7f:7f:a3:b9:1e:2c:19:33:1e:41:94:e1:14:1b:45: + e8:ae:27:aa:5e:78:8e:67:67:19:69:48:e3:e4:c0:c3:a7:85: + fd:fd:d6:62:6e:dd:1f:31:2f:bc:9a:d2:fa:82:eb:4b:3e:35: + e0:90:db:ed:de:1a:68:33:6f:e6:90:9f:08:64:60:46:91:09: + 74:15 -----BEGIN CERTIFICATE----- MIICsjCCAhugAwIBAgIBATANBgkqhkiG9w0BAQsFADBoMRcwFQYDVQQDDA5jYS5s b2NhbGRvbWFpbjELMAkGA1UEBhMCS08xDjAMBgNVBAgMBVNlb3VsMQ4wDAYDVQQH -DAVOb3dvbjEQMA4GA1UECgwHT3BlbjVHUzEOMAwGA1UECwwFVGVzdHMwHhcNMTkx -MDIwMDY0MzU4WhcNMjkxMDE3MDY0MzU4WjBZMQswCQYDVQQGEwJLTzEOMAwGA1UE +DAVOb3dvbjEQMA4GA1UECgwHT3BlbjVHUzEOMAwGA1UECwwFVGVzdHMwHhcNMjAw +ODIyMDAzOTE3WhcNMzAwODIwMDAzOTE3WjBZMQswCQYDVQQGEwJLTzEOMAwGA1UE CAwFU2VvdWwxEDAOBgNVBAoMB09wZW41R1MxDjAMBgNVBAsMBVRlc3RzMRgwFgYD VQQDDA9tbWUubG9jYWxkb21haW4wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB -ALU6Me2//s3nUMyUuj39L+bLgyU9gpMmV7QvaynZ/YDIxYKcCRcUOJFXrHKwhtRv -vWv6uWBRm6traDcVx96LvejaWkl1AzMJjknk2Vs8L8pHm5XVbxbkjTm0Od1RGlUn -aLmgJK0cGEi7SVSuA6MLuOXatMJ/CaQSjpcIWCRqS/SHAgMBAAGjezB5MAkGA1Ud +AJxpJfzufxHggfe1UY8BuJ4BdAM+pSXebyhmBW97q4YPCfyUe+iqnwtfMidG8Mri +EvNdA4Dpmh3wINZcG0tl1Gbjt2MZbrHo22wk3yQsUPIcijPB9ye4PG7GkJisQ2cA +az2rOUk91XR3ag44TkHN5BVjJ3a1nHX4y2/MXvOnaO+lAgMBAAGjezB5MAkGA1Ud EwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmlj -YXRlMB0GA1UdDgQWBBQgdAbwr/YtkNHLjFyrc9dFmTHdqjAfBgNVHSMEGDAWgBTF -ONy6D8Mpbj2ZB5bQhxL9uEjMNzANBgkqhkiG9w0BAQsFAAOBgQAK9f0fGVKamew0 -Z+hX3GFzwAWwU+OPZobJma8oWioGqFOxgOpcya2T7Li0sOQEi4UbCJPycbEhq4BA -5CfGxXpW8tIzbPAd9JmFVWCc69O440vlvh7SOdVVb0wgB8gkHCFw5FQXC6VmF76L -XHPKXkJuJxUYadzGSZfXZuCorZzxtw== +YXRlMB0GA1UdDgQWBBSSaR4/n+JAL4EkBbQTqoplXHxxHTAfBgNVHSMEGDAWgBRk ++8jXoyAX3Kg6qksrhc29PlNLCTANBgkqhkiG9w0BAQsFAAOBgQB0/DLu5iul9aRx +ZEn/628BMDK3YWKX4SwPUGKocZq9i9gNSyjqtF8cMD5MIy/FW3ftSMK7twzZUE1/ +f6O5HiwZMx5BlOEUG0XorieqXniOZ2cZaUjj5MDDp4X9/dZibt0fMS+8mtL6gutL +PjXgkNvt3hpoM2/mkJ8IZGBGkQl0FQ== -----END CERTIFICATE----- diff --git a/configs/freeDiameter/mme.conf.in b/configs/freeDiameter/mme.conf.in index 0bc380770..56158501c 100644 --- a/configs/freeDiameter/mme.conf.in +++ b/configs/freeDiameter/mme.conf.in @@ -260,7 +260,7 @@ LoadExtension = "@libdir@/freeDiameter/dict_dcca_3gpp.fdx"; # Examples: #ConnectPeer = "aaa.wide.ad.jp"; #ConnectPeer = "old.diameter.serv" { TcTimer = 60; TLS_old_method; No_SCTP; Port=3868; } ; -ConnectPeer = "hss.localdomain" { ConnectTo = "127.0.0.4"; No_TLS; }; +ConnectPeer = "hss.localdomain" { ConnectTo = "127.0.0.8"; No_TLS; }; ############################################################## diff --git a/configs/freeDiameter/mme.key.pem b/configs/freeDiameter/mme.key.pem index 21b81a428..cc9c42c92 100644 --- a/configs/freeDiameter/mme.key.pem +++ b/configs/freeDiameter/mme.key.pem @@ -1,15 +1,15 @@ -----BEGIN RSA PRIVATE KEY----- -MIICXQIBAAKBgQC1OjHtv/7N51DMlLo9/S/my4MlPYKTJle0L2sp2f2AyMWCnAkX -FDiRV6xysIbUb71r+rlgUZura2g3Fcfei73o2lpJdQMzCY5J5NlbPC/KR5uV1W8W -5I05tDndURpVJ2i5oCStHBhIu0lUrgOjC7jl2rTCfwmkEo6XCFgkakv0hwIDAQAB -AoGBALL3ID1H/8m4Z9tP+EelEzvYt8772kmUcMHYnfw7cJNQMXQUwQlQh7hIG107 -JDr/idDrTUtn69GxhL35PWJxH3z7b9nPQCcPZQ3PZWW8lDXNqNCjV5j+2zDAXqkc -IyxLQuPnTyn9kcB/OIjNGrr86/6JKS1ipbT9AIllV+br5OMhAkEA7KMLbiAI03JH -wBhtnHdtj7NETXDnZd0Plj3ATpa7SOtxmBtqVVOH/1ghAqJ0YScrqa9+eEqcn6mv -sHoJ10wVVwJBAMQOdR6b6H3Swy5dZNYzSKDsWRf4cNK5Kz8HJ8UOLbHTjzcDHNsD -n09McdcnWgNAxV6J0YJzu4LWQjT4b1e77FECQAd+8rG+Wgk4qYUwQOif79yJdTRu -yyWy5vd/ZUQYCj65FpQW6jthtgEkrYcD1mPtdbieUodE9cko+uPAOeeUBWkCQQCt -lL9NImxtOjVkz3t/ylf7YkZfWq9JYnhPjV5AsZTzZIPgCPl7T3G1G9GO1GB1kNsu -IIdGIIFcDacAjxTFcLSBAkA1Bl7gARE2XZR9iVVJ/On2hWFZhtG9RId+k0pVUxKs -KXYnYSiD/WIeVZ6IBswqL2AnEV+kBBuZ7D9aEiDYbXQ/ +MIICXQIBAAKBgQCcaSX87n8R4IH3tVGPAbieAXQDPqUl3m8oZgVve6uGDwn8lHvo +qp8LXzInRvDK4hLzXQOA6Zod8CDWXBtLZdRm47djGW6x6NtsJN8kLFDyHIozwfcn +uDxuxpCYrENnAGs9qzlJPdV0d2oOOE5BzeQVYyd2tZx1+MtvzF7zp2jvpQIDAQAB +AoGARr3D4a7Yp/Q7tBY86gokPsp3dxQ5S3RcIBBseuybOknJAYUCucuZnWIT4/HQ +7GHtokY6VG7TNqEpqOoFqkdHFgDZQlJPG+N2B63JEGxAL0RedHsTbnYQ8MFqrixb +U59yDfwudrlEYAQNML51pEp7D06Add+CPubcFLO8Tnh/z20CQQDQCWRPP0ZdfYk1 +NZFS82fWxWE0jhxEu8nFXCh4uawlSOyyl8RFKyvwFhs+u8DAS+ntSA5nBIkglLW5 +aM+WbJerAkEAwHi5BIojXNmqjrfDDDaD3jM5/Ug2SOuReVz/7JDoPC/w9rob37RM +pz0bWrtOVCud+mD0WeOjsxfsb6ixpjMF7wJBAI9zmnbG0/eNo/pL6NzBOP4w9rlt +sPJ4Z0avKL0ukxTWt1jjLBTiExcntzvH7b7r2e+ju0KwLvqHcNPcASDh2qcCQBQ4 +Wo+ch4yInX9y1L3iuEXOsefm/zT38oeCeqx6qLsx+imhca41vdvP8qC8jsUO9ADK +0MDkxlzZRZCRc2BXeecCQQCl+Ac9n+gtpIUFNmwvgtOnnjDAEDhGgi4lR45frT75 +t57D+YTERbn2pygttzhZ6imWMEUnSQJQSGpDAUnVsIUg -----END RSA PRIVATE KEY----- diff --git a/configs/freeDiameter/pcrf.cert.pem b/configs/freeDiameter/pcrf.cert.pem index acbd4adfc..ffe7a97f4 100644 --- a/configs/freeDiameter/pcrf.cert.pem +++ b/configs/freeDiameter/pcrf.cert.pem @@ -5,22 +5,22 @@ Certificate: Signature Algorithm: sha256WithRSAEncryption Issuer: CN=ca.localdomain, C=KO, ST=Seoul, L=Nowon, O=Open5GS, OU=Tests Validity - Not Before: Oct 20 06:43:58 2019 GMT - Not After : Oct 17 06:43:58 2029 GMT + Not Before: Aug 22 00:39:17 2020 GMT + Not After : Aug 20 00:39:17 2030 GMT Subject: C=KO, ST=Seoul, O=Open5GS, OU=Tests, CN=pcrf.localdomain Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (1024 bit) Modulus: - 00:c4:63:95:b8:b2:99:ca:4d:dd:ac:b8:e2:78:29: - 43:03:8a:de:6b:05:99:97:b7:90:39:f8:f6:b8:20: - 77:44:4b:1b:95:6c:ad:e1:5f:2c:48:a2:8a:d2:95: - 72:0e:f9:e1:cf:70:4e:45:6e:71:7e:2a:41:29:93: - 7a:12:01:73:0b:10:20:7a:38:66:9f:75:76:21:d6: - 7d:0c:ea:35:47:16:d6:c3:9f:41:ec:e9:98:36:16: - 84:9f:43:38:2b:b2:c8:d9:f3:6c:07:82:e4:ce:c8: - a3:f3:c3:60:13:f3:46:44:fa:f0:ee:a9:48:40:8f: - 80:3e:60:73:ff:6d:59:03:2f + 00:b9:1f:b3:a5:74:de:31:97:ac:fa:86:1d:65:86: + c7:be:b1:25:07:01:f3:69:21:7a:6d:ec:d7:c8:ec: + e2:c9:e8:71:a1:07:ce:0e:68:e5:0f:a9:ec:f3:5e: + 5e:3e:a4:ea:27:f3:fa:65:36:2d:7c:ce:a8:70:cc: + 34:db:51:b2:28:7b:03:bf:78:06:61:7c:44:81:17: + 88:f9:c9:16:cb:2e:9f:21:4a:24:28:0a:0f:76:ef: + 63:0f:05:a4:ee:52:64:1f:4f:0b:ec:4e:6c:1b:12: + 40:43:75:ed:62:16:ec:6a:ba:15:dd:c4:b9:fa:a9: + de:2c:80:f5:84:c5:97:ec:7b Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Basic Constraints: @@ -28,33 +28,33 @@ Certificate: Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: - 53:A8:0E:78:45:FB:38:A6:CF:30:E5:FF:BB:CA:E6:CF:A3:4A:DC:53 + CD:C4:C9:C1:7F:D9:34:1F:DB:08:61:27:FC:59:A2:C2:CC:19:9A:7B X509v3 Authority Key Identifier: - keyid:C5:38:DC:BA:0F:C3:29:6E:3D:99:07:96:D0:87:12:FD:B8:48:CC:37 + keyid:64:FB:C8:D7:A3:20:17:DC:A8:3A:AA:4B:2B:85:CD:BD:3E:53:4B:09 Signature Algorithm: sha256WithRSAEncryption - 47:6b:2b:f9:03:8d:c1:fd:84:21:fe:3c:5b:8c:9d:c1:48:bc: - ae:90:67:c5:ad:1a:80:e9:97:9c:c2:d4:31:1b:7d:4e:1a:72: - 09:fb:92:32:b3:82:79:59:cd:92:21:27:c7:34:c3:76:27:a8: - 11:33:cd:4a:ec:10:cb:44:89:da:47:1a:a4:6a:06:10:fb:f1: - 6a:de:d5:1a:15:de:4a:54:6f:29:b8:de:ec:20:f2:d1:c3:0c: - 9a:8e:97:46:8c:21:c3:63:7f:41:52:41:7e:73:47:43:0a:d1: - 86:0b:f0:fb:9a:1f:6d:b5:93:88:95:88:84:6d:28:8e:29:2e: - 66:9d + 24:3a:da:a7:50:b3:42:ab:e9:87:21:b2:d9:2b:a1:44:0b:5f: + bd:ad:c9:8b:b1:ca:d5:2e:65:46:55:80:11:00:33:03:f9:04: + b1:31:a2:c9:d2:41:e0:ec:73:bc:9a:3c:31:06:cc:d0:2d:73: + 1f:b4:93:1c:b0:99:dd:14:27:64:39:7e:c5:ab:53:48:c5:25: + e8:88:fd:4e:b8:dd:64:88:b5:b4:89:8b:15:97:8b:e7:c9:fb: + 23:6c:ed:60:9b:2f:f0:99:7a:75:6c:8e:ea:09:c6:ba:ff:e9: + 81:3f:97:96:8b:00:58:5b:88:13:e8:8a:39:4c:f6:c9:06:d3: + 24:66 -----BEGIN CERTIFICATE----- MIICszCCAhygAwIBAgIBBDANBgkqhkiG9w0BAQsFADBoMRcwFQYDVQQDDA5jYS5s b2NhbGRvbWFpbjELMAkGA1UEBhMCS08xDjAMBgNVBAgMBVNlb3VsMQ4wDAYDVQQH -DAVOb3dvbjEQMA4GA1UECgwHT3BlbjVHUzEOMAwGA1UECwwFVGVzdHMwHhcNMTkx -MDIwMDY0MzU4WhcNMjkxMDE3MDY0MzU4WjBaMQswCQYDVQQGEwJLTzEOMAwGA1UE +DAVOb3dvbjEQMA4GA1UECgwHT3BlbjVHUzEOMAwGA1UECwwFVGVzdHMwHhcNMjAw +ODIyMDAzOTE3WhcNMzAwODIwMDAzOTE3WjBaMQswCQYDVQQGEwJLTzEOMAwGA1UE CAwFU2VvdWwxEDAOBgNVBAoMB09wZW41R1MxDjAMBgNVBAsMBVRlc3RzMRkwFwYD VQQDDBBwY3JmLmxvY2FsZG9tYWluMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB -gQDEY5W4spnKTd2suOJ4KUMDit5rBZmXt5A5+Pa4IHdESxuVbK3hXyxIoorSlXIO -+eHPcE5FbnF+KkEpk3oSAXMLECB6OGafdXYh1n0M6jVHFtbDn0Hs6Zg2FoSfQzgr -ssjZ82wHguTOyKPzw2AT80ZE+vDuqUhAj4A+YHP/bVkDLwIDAQABo3sweTAJBgNV +gQC5H7OldN4xl6z6hh1lhse+sSUHAfNpIXpt7NfI7OLJ6HGhB84OaOUPqezzXl4+ +pOon8/plNi18zqhwzDTbUbIoewO/eAZhfESBF4j5yRbLLp8hSiQoCg9272MPBaTu +UmQfTwvsTmwbEkBDde1iFuxquhXdxLn6qd4sgPWExZfsewIDAQABo3sweTAJBgNV HRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZp -Y2F0ZTAdBgNVHQ4EFgQUU6gOeEX7OKbPMOX/u8rmz6NK3FMwHwYDVR0jBBgwFoAU -xTjcug/DKW49mQeW0IcS/bhIzDcwDQYJKoZIhvcNAQELBQADgYEAR2sr+QONwf2E -If48W4ydwUi8rpBnxa0agOmXnMLUMRt9ThpyCfuSMrOCeVnNkiEnxzTDdieoETPN -SuwQy0SJ2kcapGoGEPvxat7VGhXeSlRvKbje7CDy0cMMmo6XRowhw2N/QVJBfnNH -QwrRhgvw+5ofbbWTiJWIhG0ojikuZp0= +Y2F0ZTAdBgNVHQ4EFgQUzcTJwX/ZNB/bCGEn/FmiwswZmnswHwYDVR0jBBgwFoAU +ZPvI16MgF9yoOqpLK4XNvT5TSwkwDQYJKoZIhvcNAQELBQADgYEAJDrap1CzQqvp +hyGy2SuhRAtfva3Ji7HK1S5lRlWAEQAzA/kEsTGiydJB4OxzvJo8MQbM0C1zH7ST +HLCZ3RQnZDl+xatTSMUl6Ij9TrjdZIi1tImLFZeL58n7I2ztYJsv8Jl6dWyO6gnG +uv/pgT+XlosAWFuIE+iKOUz2yQbTJGY= -----END CERTIFICATE----- diff --git a/configs/freeDiameter/pcrf.conf.in b/configs/freeDiameter/pcrf.conf.in index 75524f8cb..7d6322c4b 100644 --- a/configs/freeDiameter/pcrf.conf.in +++ b/configs/freeDiameter/pcrf.conf.in @@ -79,7 +79,7 @@ Realm = "localdomain"; #ListenOn = "202.249.37.5"; #ListenOn = "2001:200:903:2::202:1"; #ListenOn = "fe80::21c:5ff:fe98:7d62%eth0"; -ListenOn = "127.0.0.5"; +ListenOn = "127.0.0.9"; ############################################################## @@ -260,6 +260,6 @@ LoadExtension = "@libdir@/freeDiameter/dict_dcca_3gpp.fdx"; # Examples: #ConnectPeer = "aaa.wide.ad.jp"; #ConnectPeer = "old.diameter.serv" { TcTimer = 60; TLS_old_method; No_SCTP; Port=3868; } ; -ConnectPeer = "pgw.localdomain" { ConnectTo = "127.0.0.3"; No_TLS; }; +ConnectPeer = "smf.localdomain" { ConnectTo = "127.0.0.4"; No_TLS; }; ############################################################## diff --git a/configs/freeDiameter/pcrf.key.pem b/configs/freeDiameter/pcrf.key.pem index aefcc45a1..bed6dbee3 100644 --- a/configs/freeDiameter/pcrf.key.pem +++ b/configs/freeDiameter/pcrf.key.pem @@ -1,15 +1,15 @@ -----BEGIN RSA PRIVATE KEY----- -MIICXQIBAAKBgQDEY5W4spnKTd2suOJ4KUMDit5rBZmXt5A5+Pa4IHdESxuVbK3h -XyxIoorSlXIO+eHPcE5FbnF+KkEpk3oSAXMLECB6OGafdXYh1n0M6jVHFtbDn0Hs -6Zg2FoSfQzgrssjZ82wHguTOyKPzw2AT80ZE+vDuqUhAj4A+YHP/bVkDLwIDAQAB -AoGBAJG6b+RhK3uSMjcz7mFKBP9A8fCqdCG/xdcu5i0VcksMDMjhn1mIXPz9GFRR -LxTr2eMrK/mbjb4YLshiNgfcaXdzpZGauK15PNEHemygI4et9b0iE3ZfGM3dGEGi -UmWzXgO347S8CNmm6JX/gtAaCafeapmyms6E4teYFp1UMRIBAkEA7zrq9HZT1CZu -fWN9DraOUVrgMdV8Q/qdKzAqMsTf95r43aRxxe8ZkXpQuf1X0kBDH8cIeOAVu96/ -hmfxCcVZAQJBANIn3YU7xCnUbdK29tYuxAzEw7j4pdfjHEPgkvjV1xsGVwM+DQkF -/yrSgAujxR70uGfBcUF/M9XRniBWg+FRrC8CQBXJ5vZnBJGRAoU3F3/Mjr/IKB1B -1XSXkdMKKv2+wqtZmQsO3DHr6gc+/bVC5snGgpaVWScxOamHyyfhtalvKQECQG+w -PCyo3NIWUd+g2YJvDEZ09EgD7a/UxZrVaYbRryZvsiLJAYiAJWKOyPpmqUaQbMjH -p/dVMSk75Dvvfttq2oUCQQDuEO0xY0gHxzFYH1K82Yw5aDdRsryEQYpb5e+jduH1 -EHACfc2H4Oc3/a39q7On+HnZgxK7gFMpGW+D0MdDDoL6 +MIICWgIBAAKBgQC5H7OldN4xl6z6hh1lhse+sSUHAfNpIXpt7NfI7OLJ6HGhB84O +aOUPqezzXl4+pOon8/plNi18zqhwzDTbUbIoewO/eAZhfESBF4j5yRbLLp8hSiQo +Cg9272MPBaTuUmQfTwvsTmwbEkBDde1iFuxquhXdxLn6qd4sgPWExZfsewIDAQAB +An8UP2NmtWGYCv7gZ8rPT+6I7Ncf7RayaPb7DuyLDV3At6u18SSYbuCe1fcUpz2n +nGH//K9mYoaXIANMUwl083qIwxT0VbarpTCgiHT8afdISe6Bm8B8Xs0ITEikRHiG +vmI/oCbCA1DkXZlf4jpQbGdet2DyxnJTXv+W9vDkqHOhAkEA74Y+MQgf3eaz/on9 +2I5S0kvFJxBYjkAcbkzHmytA5cT45KoCIF+6oPAnBoDkLq3fUotOgWzX2pnWHzMu ++VLtrwJBAMXbhpxQflZ/4eqDYbD49ggVO8VJzl3Ch1B7ZvKW/b+6plRwsdHx0RFk +xbwz02GuJbwf6UjVW1VyaQF6fgkdzPUCQQCYhK+nQxgfkV69zxpvwbilJhBFHph1 +BAfWiFd1y+YIKROfb03pVWuePS1sa7hgrOCOTBxSN39/OAPrXAkmQ5MLAkBbNSZp +eoWy1ELNe4EWNr4b3cXu3WYfPKRqCmjbnZUdxCoWtNiUAlgxH3YzmuRvm/rTLRa6 +N3hh/FrBjrj49N7dAkA5SaCw2WFulgLRPA6QwfObrQEYkHgtF2++r9jhane5nfq3 +/kcrlFnfDfT7ITc32Hmvgj7wJud7w8ANukPXG7DU -----END RSA PRIVATE KEY----- diff --git a/configs/freeDiameter/pgw.conf.in b/configs/freeDiameter/pgw.conf.in index e5ee14ba9..ad4e15009 100644 --- a/configs/freeDiameter/pgw.conf.in +++ b/configs/freeDiameter/pgw.conf.in @@ -79,7 +79,7 @@ Realm = "localdomain"; #ListenOn = "202.249.37.5"; #ListenOn = "2001:200:903:2::202:1"; #ListenOn = "fe80::21c:5ff:fe98:7d62%eth0"; -ListenOn = "127.0.0.3"; +ListenOn = "127.0.0.4"; ############################################################## @@ -260,7 +260,7 @@ LoadExtension = "@libdir@/freeDiameter/dict_dcca_3gpp.fdx"; # Examples: #ConnectPeer = "aaa.wide.ad.jp"; #ConnectPeer = "old.diameter.serv" { TcTimer = 60; TLS_old_method; No_SCTP; Port=3868; } ; -ConnectPeer = "pcrf.localdomain" { ConnectTo = "127.0.0.5"; No_TLS; }; +ConnectPeer = "pcrf.localdomain" { ConnectTo = "127.0.0.9"; No_TLS; }; ############################################################## diff --git a/configs/freeDiameter/smf.cert.pem b/configs/freeDiameter/smf.cert.pem new file mode 100644 index 000000000..610168e4a --- /dev/null +++ b/configs/freeDiameter/smf.cert.pem @@ -0,0 +1,60 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 3 (0x3) + Signature Algorithm: sha256WithRSAEncryption + Issuer: CN=ca.localdomain, C=KO, ST=Seoul, L=Nowon, O=Open5GS, OU=Tests + Validity + Not Before: Aug 22 00:39:17 2020 GMT + Not After : Aug 20 00:39:17 2030 GMT + Subject: C=KO, ST=Seoul, O=Open5GS, OU=Tests, CN=smf.localdomain + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public-Key: (1024 bit) + Modulus: + 00:ad:d6:cb:88:33:51:23:72:f1:16:29:2a:df:b7: + 75:d7:38:9e:da:18:b6:27:73:a8:60:ec:04:8f:d0: + cd:c6:2e:10:ff:bd:c3:c2:a3:d7:53:e7:9e:73:07: + 07:a9:59:16:b1:7f:92:79:4d:d8:ee:5a:c7:ed:ef: + 37:83:8a:7d:94:08:41:0b:34:68:27:a5:4b:7d:cb: + 29:fb:85:c0:21:6e:17:72:32:29:7a:28:be:94:31: + 56:d2:85:9f:4b:b1:33:6f:f9:eb:01:9c:e7:2f:68: + 94:6b:91:58:a7:80:04:94:3c:b3:19:96:91:31:f7: + c4:81:98:2b:85:8f:5c:f0:fd + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Basic Constraints: + CA:FALSE + Netscape Comment: + OpenSSL Generated Certificate + X509v3 Subject Key Identifier: + 91:4B:EF:65:02:0D:C8:85:FA:4A:3F:29:C0:10:3C:1B:AE:E4:AD:A4 + X509v3 Authority Key Identifier: + keyid:64:FB:C8:D7:A3:20:17:DC:A8:3A:AA:4B:2B:85:CD:BD:3E:53:4B:09 + + Signature Algorithm: sha256WithRSAEncryption + a3:6e:4f:00:bd:1a:62:b9:86:0f:35:f6:18:8d:15:61:a2:bc: + 05:07:f1:73:8d:70:6f:e1:34:f1:ae:87:26:87:13:0b:c8:d8: + 29:16:70:02:12:73:36:f9:de:43:26:12:7d:9f:d2:20:7c:e2: + 76:47:0b:14:ba:67:e5:5a:0d:22:3b:00:c8:35:ab:dd:b1:9a: + e5:75:b0:86:89:02:15:32:b3:e9:48:c3:e0:38:e1:56:4c:fd: + aa:12:96:00:6d:a6:c3:ab:b0:8c:4b:ab:b2:4c:c2:08:26:ab: + d6:3f:26:95:4a:da:b8:dd:9a:f8:fe:b9:c2:e3:7a:a3:2f:2c: + 7f:df +-----BEGIN CERTIFICATE----- +MIICsjCCAhugAwIBAgIBAzANBgkqhkiG9w0BAQsFADBoMRcwFQYDVQQDDA5jYS5s +b2NhbGRvbWFpbjELMAkGA1UEBhMCS08xDjAMBgNVBAgMBVNlb3VsMQ4wDAYDVQQH +DAVOb3dvbjEQMA4GA1UECgwHT3BlbjVHUzEOMAwGA1UECwwFVGVzdHMwHhcNMjAw +ODIyMDAzOTE3WhcNMzAwODIwMDAzOTE3WjBZMQswCQYDVQQGEwJLTzEOMAwGA1UE +CAwFU2VvdWwxEDAOBgNVBAoMB09wZW41R1MxDjAMBgNVBAsMBVRlc3RzMRgwFgYD +VQQDDA9zbWYubG9jYWxkb21haW4wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB +AK3Wy4gzUSNy8RYpKt+3ddc4ntoYtidzqGDsBI/QzcYuEP+9w8Kj11PnnnMHB6lZ +FrF/knlN2O5ax+3vN4OKfZQIQQs0aCelS33LKfuFwCFuF3IyKXoovpQxVtKFn0ux +M2/56wGc5y9olGuRWKeABJQ8sxmWkTH3xIGYK4WPXPD9AgMBAAGjezB5MAkGA1Ud +EwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmlj +YXRlMB0GA1UdDgQWBBSRS+9lAg3IhfpKPynAEDwbruStpDAfBgNVHSMEGDAWgBRk ++8jXoyAX3Kg6qksrhc29PlNLCTANBgkqhkiG9w0BAQsFAAOBgQCjbk8AvRpiuYYP +NfYYjRVhorwFB/FzjXBv4TTxrocmhxMLyNgpFnACEnM2+d5DJhJ9n9IgfOJ2RwsU +umflWg0iOwDINavdsZrldbCGiQIVMrPpSMPgOOFWTP2qEpYAbabDq7CMS6uyTMII +JqvWPyaVStq43Zr4/rnC43qjLyx/3w== +-----END CERTIFICATE----- diff --git a/configs/freeDiameter/smf.conf.in b/configs/freeDiameter/smf.conf.in new file mode 100644 index 000000000..02e1695c0 --- /dev/null +++ b/configs/freeDiameter/smf.conf.in @@ -0,0 +1,266 @@ +# This is a sample configuration file for freeDiameter daemon. + +# Most of the options can be omitted, as they default to reasonable values. +# Only TLS-related options must be configured properly in usual setups. + +# It is possible to use "include" keyword to import additional files +# e.g.: include "/etc/freeDiameter.d/*.conf" +# This is exactly equivalent as copy & paste the content of the included file(s) +# where the "include" keyword is found. + + +############################################################## +## Peer identity and realm + +# The Diameter Identity of this daemon. +# This must be a valid FQDN that resolves to the local host. +# Default: hostname's FQDN +#Identity = "aaa.koganei.freediameter.net"; +Identity = "smf.localdomain"; + +# The Diameter Realm of this daemon. +# Default: the domain part of Identity (after the first dot). +#Realm = "koganei.freediameter.net"; +Realm = "localdomain"; + +############################################################## +## Transport protocol configuration + +# The port this peer is listening on for incoming connections (TCP and SCTP). +# Default: 3868. Use 0 to disable. +#Port = 3868; + +# The port this peer is listening on for incoming TLS-protected connections (TCP and SCTP). +# See TLS_old_method for more information about TLS flavours. +# Note: we use TLS/SCTP instead of DTLS/SCTP at the moment. This will change in future version of freeDiameter. +# Default: 5868. Use 0 to disable. +#SecPort = 5868; + +# Use RFC3588 method for TLS protection, where TLS is negociated after CER/CEA exchange is completed +# on the unsecure connection. The alternative is RFC6733 mechanism, where TLS protects also the +# CER/CEA exchange on a dedicated secure port. +# This parameter only affects outgoing connections. +# The setting can be also defined per-peer (see Peers configuration section). +# Default: use RFC6733 method with separate port for TLS. +#TLS_old_method; + +# Disable use of TCP protocol (only listen and connect over SCTP) +# Default : TCP enabled +#No_TCP; + +# Disable use of SCTP protocol (only listen and connect over TCP) +# Default : SCTP enabled +#No_SCTP; +# This option is ignored if freeDiameter is compiled with DISABLE_SCTP option. + +# Prefer TCP instead of SCTP for establishing new connections. +# This setting may be overwritten per peer in peer configuration blocs. +# Default : SCTP is attempted first. +#Prefer_TCP; + +# Default number of streams per SCTP associations. +# This setting may be overwritten per peer basis. +# Default : 30 streams +#SCTP_streams = 30; + +############################################################## +## Endpoint configuration + +# Disable use of IP addresses (only IPv6) +# Default : IP enabled +#No_IP; + +# Disable use of IPv6 addresses (only IP) +# Default : IPv6 enabled +#No_IPv6; + +# Specify local addresses the server must bind to +# Default : listen on all addresses available. +#ListenOn = "202.249.37.5"; +#ListenOn = "2001:200:903:2::202:1"; +#ListenOn = "fe80::21c:5ff:fe98:7d62%eth0"; +ListenOn = "127.0.0.4"; + + +############################################################## +## Server configuration + +# How many Diameter peers are allowed to be connecting at the same time ? +# This parameter limits the number of incoming connections from the time +# the connection is accepted until the first CER is received. +# Default: 5 unidentified clients in paralel. +#ThreadsPerServer = 5; + +############################################################## +## TLS Configuration + +# TLS is managed by the GNUTLS library in the freeDiameter daemon. +# You may find more information about parameters and special behaviors +# in the relevant documentation. +# http://www.gnu.org/software/gnutls/manual/ + +# Credentials of the local peer +# The X509 certificate and private key file to use for the local peer. +# The files must contain PKCS-1 encoded RSA key, in PEM format. +# (These parameters are passed to gnutls_certificate_set_x509_key_file function) +# Default : NO DEFAULT +#TLS_Cred = "" , ""; +#TLS_Cred = "/etc/ssl/certs/freeDiameter.pem", "/etc/ssl/private/freeDiameter.key"; +TLS_Cred = "@sysconfdir@/freeDiameter/smf.cert.pem", "@sysconfdir@/freeDiameter/smf.key.pem"; + +# Certificate authority / trust anchors +# The file containing the list of trusted Certificate Authorities (PEM list) +# (This parameter is passed to gnutls_certificate_set_x509_trust_file function) +# The directive can appear several times to specify several files. +# Default : GNUTLS default behavior +#TLS_CA = ""; +TLS_CA = "@sysconfdir@/freeDiameter/cacert.pem"; + +# Certificate Revocation List file +# The information about revoked certificates. +# The file contains a list of trusted CRLs in PEM format. They should have been verified before. +# (This parameter is passed to gnutls_certificate_set_x509_crl_file function) +# Note: openssl CRL format might have interoperability issue with GNUTLS format. +# Default : GNUTLS default behavior +#TLS_CRL = ""; + +# GNU TLS Priority string +# This string allows to configure the behavior of GNUTLS key exchanges +# algorithms. See gnutls_priority_init function documentation for information. +# You should also refer to the Diameter required TLS support here: +# http://tools.ietf.org/html/rfc6733#section-13.1 +# Default : "NORMAL" +# Example: TLS_Prio = "NONE:+VERS-TLS1.1:+AES-128-CBC:+RSA:+SHA1:+COMP-NULL"; +#TLS_Prio = "NORMAL"; + +# Diffie-Hellman parameters size +# Set the number of bits for generated DH parameters +# Valid value should be 768, 1024, 2048, 3072 or 4096. +# (This parameter is passed to gnutls_dh_params_generate2 function, +# it usually should match RSA key size) +# Default : 1024 +#TLS_DH_Bits = 1024; + +# Alternatively, you can specify a file to load the PKCS#3 encoded +# DH parameters directly from. This accelerates the daemon start +# but is slightly less secure. If this file is provided, the +# TLS_DH_Bits parameters has no effect. +# Default : no default. +#TLS_DH_File = ""; + + +############################################################## +## Timers configuration + +# The Tc timer of this peer. +# It is the delay before a new attempt is made to reconnect a disconnected peer. +# The value is expressed in seconds. The recommended value is 30 seconds. +# Default: 30 +#TcTimer = 30; + +# The Tw timer of this peer. +# It is the delay before a watchdog message is sent, as described in RFC 3539. +# The value is expressed in seconds. The default value is 30 seconds. Value must +# be greater or equal to 6 seconds. See details in the RFC. +# Default: 30 +#TwTimer = 30; + +############################################################## +## Applications configuration + +# Disable the relaying of Diameter messages? +# For messages not handled locally, the default behavior is to forward the +# message to another peer if any is available, according to the routing +# algorithms. In addition the "0xffffff" application is advertised in CER/CEA +# exchanges. +# Default: Relaying is enabled. +#NoRelay; + +# Number of server threads that can handle incoming messages at the same time. +# Default: 4 +#AppServThreads = 4; + +# Other applications are configured by loaded extensions. + +############################################################## +## Extensions configuration + +# The freeDiameter framework merely provides support for +# Diameter Base Protocol. The specific application behaviors, +# as well as advanced functions, are provided +# by loadable extensions (plug-ins). +# These extensions may in addition receive the name of a +# configuration file, the format of which is extension-specific. +# +# Format: +#LoadExtension = "/path/to/extension" [ : "/optional/configuration/file" ] ; +# +# Examples: +#LoadExtension = "extensions/sample.fdx"; +#LoadExtension = "extensions/sample.fdx":"conf/sample.conf"; + +# Extensions are named as follow: +# dict_* for extensions that add content to the dictionary definitions. +# dbg_* for extensions useful only to retrieve more information on the framework execution. +# acl_* : Access control list, to control which peers are allowed to connect. +# rt_* : routing extensions that impact how messages are forwarded to other peers. +# app_* : applications, these extensions usually register callbacks to handle specific messages. +# test_* : dummy extensions that are useful only in testing environments. + + +# The dbg_msg_dump.fdx extension allows you to tweak the way freeDiameter displays some +# information about some events. This extension does not actually use a configuration file +# but receives directly a parameter in the string passed to the extension. Here are some examples: +## LoadExtension = "dbg_msg_dumps.fdx" : "0x1111"; # Removes all default hooks, very quiet even in case of errors. +## LoadExtension = "dbg_msg_dumps.fdx" : "0x2222"; # Display all events with few details. +## LoadExtension = "dbg_msg_dumps.fdx" : "0x0080"; # Dump complete information about sent and received messages. +# The four digits respectively control: connections, routing decisions, sent/received messages, errors. +# The values for each digit are: +# 0 - default - keep the default behavior +# 1 - quiet - remove any specific log +# 2 - compact - display only a summary of the information +# 4 - full - display the complete information on a single long line +# 8 - tree - display the complete information in an easier to read format spanning several lines. + +LoadExtension = "@libdir@/freeDiameter/dbg_msg_dumps.fdx" : "0x8888"; +LoadExtension = "@libdir@/freeDiameter/dict_rfc5777.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_mip6i.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_nasreq.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_nas_mipv6.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_dcca.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_dcca_3gpp.fdx"; + + +############################################################## +## Peers configuration + +# The local server listens for incoming connections. By default, +# all unknown connecting peers are rejected. Extensions can override this behavior (e.g., acl_wl). +# +# In addition to incoming connections, the local peer can +# be configured to establish and maintain connections to some +# Diameter nodes and allow connections from these nodes. +# This is achieved with the ConnectPeer directive described below. +# +# Note that the configured Diameter Identity MUST match +# the information received inside CEA, or the connection will be aborted. +# +# Format: +#ConnectPeer = "diameterid" [ { parameter1; parameter2; ...} ] ; +# Parameters that can be specified in the peer's parameter list: +# No_TCP; No_SCTP; No_IP; No_IPv6; Prefer_TCP; TLS_old_method; +# No_TLS; # assume transparent security instead of TLS. DTLS is not supported yet (will change in future versions). +# Port = 5868; # The port to connect to +# TcTimer = 30; +# TwTimer = 30; +# ConnectTo = "202.249.37.5"; +# ConnectTo = "2001:200:903:2::202:1"; +# TLS_Prio = "NORMAL"; +# Realm = "realm.net"; # Reject the peer if it does not advertise this realm. +# Examples: +#ConnectPeer = "aaa.wide.ad.jp"; +#ConnectPeer = "old.diameter.serv" { TcTimer = 60; TLS_old_method; No_SCTP; Port=3868; } ; +ConnectPeer = "pcrf.localdomain" { ConnectTo = "127.0.0.9"; No_TLS; }; + + +############################################################## diff --git a/configs/freeDiameter/smf.key.pem b/configs/freeDiameter/smf.key.pem new file mode 100644 index 000000000..f0581961f --- /dev/null +++ b/configs/freeDiameter/smf.key.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQCt1suIM1EjcvEWKSrft3XXOJ7aGLYnc6hg7ASP0M3GLhD/vcPC +o9dT555zBwepWRaxf5J5TdjuWsft7zeDin2UCEELNGgnpUt9yyn7hcAhbhdyMil6 +KL6UMVbShZ9LsTNv+esBnOcvaJRrkVingASUPLMZlpEx98SBmCuFj1zw/QIDAQAB +AoGAV1x1hmn7oav22mMv56PD9be/pOz8RZFLEgIqPLf7YVfvNQaBpYQ/ByyEJVxo +DkP2Mpdg3dMwbIB0ru8j39guSO0evsCG95u5L3lUMLFh/+WTt4W0g4+9y0qD1dUy +y7kk+gKLlbPvyRNr+CiEnpz/rxdWC3J+tVBsWJGNjBGtZWECQQDdn5q7FUrF6HHQ +O5iJYCbeL+Xn4Ajwrr4M9OeGhMz4pTTtE45jjGi2ykFa9TJFMqjLuClBXw5FkIOe +S4unTO7JAkEAyM268Z558xHHnRl6uEN1NrqqpdXtZYnK9lm4/kZRs2mKm/98fjf0 +GiHwiKqONP7si4ARE2Ws1wKmXmCe0nNGlQJBAMw8KFCd95FYe4IlWZXHySnaxCki +WbrLnhK8opxhx66gOJz996sfmuRQkVfsPE5uuAU9Cq/WlIVg/xoijmk3yZkCQEFu +YCsZM62TrpKvWcCvIoOZ4b817Sw38S3C4LfiW/71NhhM8NkEDINzabhusvXr11JB +gc7rQ52wHFwGadoze90CQF9qOBatpIFlEDkhzKofRILCWIzSrfhFdcCZqe6K8G10 +ngbk3Xg3I0I+qWViDivOm689SC9xniF7wJ1XH0BRBKE= +-----END RSA PRIVATE KEY----- diff --git a/configs/meson.build b/configs/meson.build index abc7d708f..9ab40fa23 100644 --- a/configs/meson.build +++ b/configs/meson.build @@ -34,20 +34,13 @@ else endif example_conf = ''' - 5gc.yaml - 5gc-sample.yaml - 00101.yaml - 23504.yaml - minimal.yaml - epc.yaml - epc-fdconf.yaml - epc-custom.yaml - mnc3.yaml + sample.yaml + 310014.yaml csfb.yaml volte.yaml + minimal.yaml srslte.yaml - cups.yaml - app.yaml + sample.yaml '''.split() foreach file : example_conf diff --git a/configs/minimal.yaml.in b/configs/minimal.yaml.in index d39e01f98..4822a5bb3 100644 --- a/configs/minimal.yaml.in +++ b/configs/minimal.yaml.in @@ -3,13 +3,105 @@ db_uri: mongodb://localhost/open5gs logger: parameter: +# no_nrf: true +# no_amf: true +# no_smf: true +# no_upf: true +# no_ausf: true +# no_udm: true +# no_udr: true +# no_mme: true +# no_sgwc: true +# no_sgwu: true +# no_pcrf: true +# no_hss: true +mme: + freeDiameter: + identity: mme.localdomain + realm: localdomain + listen_on: 127.0.0.2 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: hss.localdomain + addr: 127.0.0.8 + + s1ap: + addr: 127.0.0.2 + gtpc: + addr: 127.0.0.2 + gummei: + plmn_id: + mcc: 901 + mnc: 70 + mme_gid: 2 + mme_code: 1 + tai: + plmn_id: + mcc: 901 + mnc: 70 + tac: 1 + security: + integrity_order : [ EIA1, EIA2, EIA0 ] + ciphering_order : [ EEA0, EEA1, EEA2 ] + + network_name: + full: Open5GS + +sgwc: + gtpc: + addr: 127.0.0.3 + pfcp: + addr: 127.0.0.3 + +smf: + sbi: + - addr: 127.0.0.4 + port: 7777 + gtpc: + - addr: 127.0.0.4 + - addr: ::1 + pfcp: + - addr: 127.0.0.4 + pdn: + - addr: 10.45.0.1/16 + - addr: cafe::1/64 + dns: + - 8.8.8.8 + - 8.8.4.4 + - 2001:4860:4860::8888 + - 2001:4860:4860::8844 + mtu: 1400 + freeDiameter: + identity: smf.localdomain + realm: localdomain + listen_on: 127.0.0.4 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: pcrf.localdomain + addr: 127.0.0.9 amf: sbi: - - addr: 127.0.0.2 + - addr: 127.0.0.5 port: 7777 ngap: - - addr: 127.0.0.2 + - addr: 127.0.0.5 guami: - plmn_id: mcc: 208 @@ -38,28 +130,28 @@ amf: full: Open5GS amf_name: open5gs-amf0 -smf: - sbi: - - addr: 127.0.0.3 - port: 7777 - gtpc: - - addr: 127.0.0.3 - - addr: ::1 +sgwu: + gtpu: + addr: 127.0.0.6 pfcp: - - addr: 127.0.0.3 + addr: 127.0.0.6 + +upf: + pfcp: + - addr: 127.0.0.7 + gtpu: + - addr: + - 127.0.0.7 + - ::1 pdn: - addr: 10.45.0.1/16 - addr: cafe::1/64 - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 - mtu: 1400 + +hss: freeDiameter: - identity: pgw.open-ims.test - realm: open-ims.test - listen_on: 127.0.0.3 + identity: hss.localdomain + realm: localdomain + listen_on: 127.0.0.8 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -70,34 +162,44 @@ smf: - module: @freediameter_extensions_builddir@/dict_dcca.fdx - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - - identity: pcrf.open-ims.test - addr: 127.0.0.5 -upf: - pfcp: - - addr: 127.0.0.4 - gtpu: - - addr: - - 127.0.0.4 + - identity: mme.localdomain + addr: 127.0.0.2 +pcrf: + freeDiameter: + identity: pcrf.localdomain + realm: localdomain + listen_on: 127.0.0.9 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: smf.localdomain + addr: 127.0.0.4 + +nrf: + sbi: + addr: + - 127.0.0.10 - ::1 - pdn: + port: 7777 ausf: sbi: - - addr: 127.0.0.5 + - addr: 127.0.0.11 port: 7777 udm: sbi: - - addr: 127.0.0.6 + - addr: 127.0.0.12 port: 7777 udr: sbi: - - addr: 127.0.0.7 - port: 7777 -nrf: - sbi: - - addr: - - 127.0.0.1 - - ::1 + - addr: 127.0.0.13 port: 7777 diff --git a/configs/mnc3.yaml.in b/configs/mnc3.yaml.in deleted file mode 100644 index 4d5a84c47..000000000 --- a/configs/mnc3.yaml.in +++ /dev/null @@ -1,144 +0,0 @@ -db_uri: mongodb://localhost/open5gs - -logger: - -parameter: - -nrf: - sbi: - addr: - - 127.0.0.1 - - ::1 - port: 7777 - -mme: - freeDiameter: - identity: mme.localdomain - realm: localdomain - listen_on: 127.0.0.2 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: hss.localdomain - addr: 127.0.0.4 - - s1ap: - addr: 127.0.0.1 - gtpc: - addr: 127.0.0.1 - gummei: - plmn_id: - mcc: 310 - mnc: 014 - mme_gid: 32798 - mme_code: 100 - tai: - plmn_id: - mcc: 310 - mnc: 014 - tac: [50, 51, 52, 53] - security: - integrity_order : [ EIA1, EIA2, EIA0 ] - ciphering_order : [ EEA0, EEA1, EEA2 ] - - network_name: - full: Open5GS - -sgwc: - gtpc: - addr: 127.0.0.6 - pfcp: - addr: 127.0.0.6 - -sgwu: - gtpu: - addr: 127.0.0.7 - pfcp: - addr: 127.0.0.7 - -smf: - sbi: - - addr: 127.0.0.3 - port: 7777 - gtpc: - - addr: 127.0.0.3 - - addr: ::1 - pfcp: - - addr: 127.0.0.3 - pdn: - - addr: 10.45.0.1/16 - - addr: cafe::1/64 - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 - mtu: 1400 - freeDiameter: - identity: smf.localdomain - realm: localdomain - listen_on: 127.0.0.3 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: pcrf.localdomain - addr: 127.0.0.5 -upf: - pfcp: - - addr: 127.0.0.4 - gtpu: - - addr: - - 127.0.0.4 - - ::1 - pdn: - - addr: 10.45.0.1/16 - - addr: cafe::1/64 - -hss: - freeDiameter: - identity: hss.localdomain - realm: localdomain - listen_on: 127.0.0.4 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: mme.localdomain - addr: 127.0.0.2 -pcrf: - freeDiameter: - identity: pcrf.localdomain - realm: localdomain - listen_on: 127.0.0.5 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: smf.localdomain - addr: 127.0.0.3 diff --git a/configs/open5gs/amf.yaml.in b/configs/open5gs/amf.yaml.in index fa79af2a1..98138f909 100644 --- a/configs/open5gs/amf.yaml.in +++ b/configs/open5gs/amf.yaml.in @@ -16,7 +16,7 @@ # # o Set OGS_LOG_TRACE to all domain level # level: trace -# domain: core,pfcp,fd,gtp,amf,event,tlv,mem,sock +# domain: core,ngap,nas,gmm,sbi,amf,event,tlv,mem,sock # logger: file: @localstatedir@/log/open5gs/amf.log @@ -41,9 +41,9 @@ logger: # key: amf.key # pem: amf.pem # -# o SBI Server(https://127.0.0.2:443, http://[::1]:80) +# o SBI Server(https://127.0.0.5:443, http://[::1]:80) # sbi: -# - addr: 127.0.0.2 +# - addr: 127.0.0.5 # tls: # key: amf.key # pem: amf.pem @@ -53,9 +53,9 @@ logger: # sbi: # name: amf.open5gs.org # -# o SBI Server(http://127.0.0.2:7777) +# o SBI Server(http://127.0.0.5:7777) # sbi: -# - addr: 127.0.0.2 +# - addr: 127.0.0.5 # port: 7777 # # o SBI Server(http://:80) @@ -71,14 +71,14 @@ logger: # ngap: # addr: 0.0.0.0 # -# o NGAP Server(127.0.0.1:38412, [::1]:38412) +# o NGAP Server(127.0.0.5:38412, [::1]:38412) # ngap: -# - addr: 127.0.0.1 +# - addr: 127.0.0.5 # - addr: ::1 # # o NGAP Server(different port) # ngap: -# - addr: 127.0.0.1 +# - addr: 127.0.0.5 # port: 38413 # # o NGAP Server(address avaiable in `eth0` interface) @@ -162,10 +162,10 @@ logger: # amf: sbi: - - addr: 127.0.0.2 + - addr: 127.0.0.5 port: 7777 ngap: - - addr: 127.0.0.2 + - addr: 127.0.0.5 guami: - plmn_id: mcc: 901 @@ -196,31 +196,31 @@ amf: # # > # -# o SBI Client(http://127.0.0.1:7777) +# o SBI Client(http://127.0.0.10:7777) # sbi: -# addr: 127.0.0.1 +# addr: 127.0.0.10 # port: 7777 # -# o SBI Client(https://127.0.0.1:443, http://nrf.open5gs.org:80) +# o SBI Client(https://127.0.0.10:443, http://nrf.open5gs.org:80) # sbi: -# - addr: 127.0.0.1 +# - addr: 127.0.0.10 # tls: # key: nrf.key # pem: nrf.pem # - name: nrf.open5gs.org # # o SBI Client(http://[fe80::1%@loopback_devname@]:80) -# If prefer_ipv4 is true, http://127.0.0.1:80 is selected. +# If prefer_ipv4 is true, http://127.0.0.10:80 is selected. # # sbi: # addr: -# - 127.0.0.1 +# - 127.0.0.10 # - fe80::1%@loopback_devname@ # nrf: sbi: - addr: - - 127.0.0.1 + - 127.0.0.10 - ::1 port: 7777 diff --git a/configs/open5gs/ausf.yaml.in b/configs/open5gs/ausf.yaml.in index 104880a70..3d5834894 100644 --- a/configs/open5gs/ausf.yaml.in +++ b/configs/open5gs/ausf.yaml.in @@ -16,7 +16,7 @@ # # o Set OGS_LOG_TRACE to all domain level # level: trace -# domain: core,pfcp,fd,gtp,ausf,event,tlv,mem,sock +# domain: core,sbi,ausf,event,tlv,mem,sock # logger: file: @localstatedir@/log/open5gs/ausf.log @@ -41,9 +41,9 @@ logger: # key: ausf.key # pem: ausf.pem # -# o SBI Server(https://127.0.0.5:443, http://[::1]:80) +# o SBI Server(https://127.0.0.11:443, http://[::1]:80) # sbi: -# - addr: 127.0.0.5 +# - addr: 127.0.0.11 # tls: # key: ausf.key # pem: ausf.pem @@ -53,9 +53,9 @@ logger: # sbi: # name: ausf.open5gs.org # -# o SBI Server(http://127.0.0.5:7777) +# o SBI Server(http://127.0.0.11:7777) # sbi: -# - addr: 127.0.0.5 +# - addr: 127.0.0.11 # port: 7777 # # o SBI Server(http://:80) @@ -64,7 +64,7 @@ logger: # ausf: sbi: - - addr: 127.0.0.5 + - addr: 127.0.0.11 port: 7777 # @@ -72,31 +72,31 @@ ausf: # # > # -# o SBI Client(http://127.0.0.1:7777) +# o SBI Client(http://127.0.0.10:7777) # sbi: -# addr: 127.0.0.1 +# addr: 127.0.0.10 # port: 7777 # -# o SBI Client(https://127.0.0.1:443, http://nrf.open5gs.org:80) +# o SBI Client(https://127.0.0.10:443, http://nrf.open5gs.org:80) # sbi: -# - addr: 127.0.0.1 +# - addr: 127.0.0.10 # tls: # key: nrf.key # pem: nrf.pem # - name: nrf.open5gs.org # # o SBI Client(http://[fe80::1%@loopback_devname@]:80) -# If prefer_ipv4 is true, http://127.0.0.1:80 is selected. +# If prefer_ipv4 is true, http://127.0.0.10:80 is selected. # # sbi: # addr: -# - 127.0.0.1 +# - 127.0.0.10 # - fe80::1%@loopback_devname@ # nrf: sbi: - addr: - - 127.0.0.1 + - 127.0.0.10 - ::1 port: 7777 diff --git a/configs/open5gs/mme.yaml.in b/configs/open5gs/mme.yaml.in index 2d934537d..1ac7de7df 100644 --- a/configs/open5gs/mme.yaml.in +++ b/configs/open5gs/mme.yaml.in @@ -33,14 +33,14 @@ logger: # s1ap: # addr: 0.0.0.0 # -# o S1AP Server(127.0.0.1:36412, [::1]:36412) +# o S1AP Server(127.0.0.2:36412, [::1]:36412) # s1ap: -# - addr: 127.0.0.1 +# - addr: 127.0.0.2 # - addr: ::1 # # o S1AP Server(different port) # s1ap: -# - addr: 127.0.0.1 +# - addr: 127.0.0.2 # port: 36413 # # o S1AP Server(address avaiable in `eth0` interface) @@ -52,9 +52,9 @@ logger: # o GTP-C Server(all address avaiable) # gtpc: # -# o GTP-C Server(127.0.0.1:2123, [::1]:2123) +# o GTP-C Server(127.0.0.2:2123, [::1]:2123) # gtpc: -# - addr: 127.0.0.1 +# - addr: 127.0.0.2 # - addr: ::1 # # @@ -112,7 +112,7 @@ logger: # mnc: 02 # lac: 43692 # - addr -# - 127.0.0.3 +# - 127.0.0.4 # - fe80::2%@loopback_devname@ # map: # tai: @@ -204,9 +204,9 @@ logger: mme: freeDiameter: @sysconfdir@/freeDiameter/mme.conf s1ap: - addr: 127.0.0.1 + addr: 127.0.0.2 gtpc: - addr: 127.0.0.1 + addr: 127.0.0.2 gummei: plmn_id: mcc: 901 @@ -236,21 +236,21 @@ mme: # If prefer_ipv4 is not true, [fe80::2%@loopback_devname@] is selected. # gtpc: # addr: -# - 127.0.0.6 +# - 127.0.0.3 # - fe80::2%@loopback_devname@ # # o Two SGW are defined. MME selects SGW with round-robin manner per UE # gtpc: -# - addr: 127.0.0.6 +# - addr: 127.0.0.3 # - addr: fe80::2%@loopback_devname@ # # o Three SGW are defined. MME selects SGW with round-robin manner per UE # gtpc: # - addr -# - 127.0.0.6 +# - 127.0.0.3 # - fe80::2%@loopback_devname@ # - addr -# - 127.0.0.12 +# - 127.0.0.22 # - fe80::12%@loopback_devname@ # - name: sgw3.open5gs.org # @@ -259,7 +259,7 @@ mme: # o Round-Robin # # gtpc: -# addr: 127.0.0.6 +# addr: 127.0.0.3 # addr: 127.0.2.2 # addr: 127.0.4.2 # @@ -267,7 +267,7 @@ mme: # (either single TAC or multiple TACs, DECIMAL representation) # # gtpc: -# - addr: 127.0.0.6 +# - addr: 127.0.0.3 # tac: 26000 # - addr: 127.0.2.2 # tac: [25000, 27000, 28000] @@ -276,14 +276,14 @@ mme: # (either single or multiple e_cell_id, HEX representation) # # gtpc: -# - addr: 127.0.0.6 +# - addr: 127.0.0.3 # e_cell_id: abcde01 # - addr: 127.0.2.2 # e_cell_id: [12345, a9413, 98765] # sgwc: gtpc: - addr: 127.0.0.6 + addr: 127.0.0.3 # # smf: @@ -295,37 +295,37 @@ sgwc: # - If the HSS uses WebUI to set the SMF IP for each UE, # you can use a specific SMF node for each UE. # -# o Two SMF are defined. 127.0.0.3:2123 is used. +# o Two SMF are defined. 127.0.0.4:2123 is used. # [fe80::3%@loopback_devname@]:2123 is ignored. # gtpc: -# - addr: 127.0.0.3 +# - addr: 127.0.0.4 # - addr: fe80::3%@loopback_devname@ # # o One SMF is defined. if prefer_ipv4 is not true, # [fe80::3%@loopback_devname@] is selected. # gtpc: # - addr: -# - 127.0.0.3 +# - 127.0.0.4 # - fe80::3%@loopback_devname@ # # o Two SMF are defined with a different APN. # - Note that if SMF IP for UE is configured in HSS, # the following configurion for this UE is ignored. # gtpc: -# - addr: 127.0.0.3 +# - addr: 127.0.0.4 # apn: internet # - addr: 127.0.0.5 # apn: volte # # o If APN is omitted, the default APN uses the first SMF node. # gtpc: -# - addr: 127.0.0.3 +# - addr: 127.0.0.4 # - addr: 127.0.0.5 # apn: volte smf: gtpc: addr: - - 127.0.0.3 + - 127.0.0.4 - ::1 # diff --git a/configs/open5gs/nrf.yaml.in b/configs/open5gs/nrf.yaml.in index 1c2bc7b5d..fd696b376 100644 --- a/configs/open5gs/nrf.yaml.in +++ b/configs/open5gs/nrf.yaml.in @@ -16,7 +16,7 @@ # # o Set OGS_LOG_TRACE to all domain level # level: trace -# domain: core,fd,nrf,event,mem,sock +# domain: core,sbi,nrf,event,mem,sock # logger: file: @localstatedir@/log/open5gs/nrf.log @@ -42,9 +42,9 @@ logger: # key: nrf.key # pem: nrf.pem # -# o SBI Server(https://127.0.0.1:443, http://[::1]:80) +# o SBI Server(https://127.0.0.10:443, http://[::1]:80) # sbi: -# - addr: 127.0.0.1 +# - addr: 127.0.0.10 # tls: # key: nrf.key # pem: nrf.pem @@ -54,9 +54,9 @@ logger: # sbi: # name: nrf.open5gs.org # -# o SBI Server(http://127.0.0.1:7777) +# o SBI Server(http://127.0.0.10:7777) # sbi: -# - addr: 127.0.0.1 +# - addr: 127.0.0.10 # port: 7777 # # o SBI Server(http://:80) @@ -66,7 +66,7 @@ logger: nrf: sbi: addr: - - 127.0.0.1 + - 127.0.0.10 - ::1 port: 7777 diff --git a/configs/open5gs/sgwc.yaml.in b/configs/open5gs/sgwc.yaml.in index 97e437f9e..72c521127 100644 --- a/configs/open5gs/sgwc.yaml.in +++ b/configs/open5gs/sgwc.yaml.in @@ -16,7 +16,7 @@ # # o Set OGS_LOG_TRACE to all domain level # level: trace -# domain: core,gtp,sgw,event,tlv,mem,sock +# domain: core,pfcp,gtp,sgwc,event,tlv,mem,sock # logger: file: @localstatedir@/log/open5gs/sgwc.log @@ -26,47 +26,47 @@ logger: # # # -# o GTP-C Server(127.0.0.6:2123, [fe80::2%@loopback_devname@]:2123) +# o GTP-C Server(127.0.0.3:2123, [fe80::2%@loopback_devname@]:2123) # gtpc: # addr: -# - 127.0.0.6 +# - 127.0.0.3 # - fe80::2%@loopback_devname@ # -# o On SGW, Same Configuration(127.0.0.6:2123, +# o On SGW, Same Configuration(127.0.0.3:2123, # [fe80::2%@loopback_devname@]:2123) as below. # gtpc: -# - addr: 127.0.0.6 +# - addr: 127.0.0.3 # - addr: fe80::2%@loopback_devname@ # # # -# o PFCP Server(127.0.0.6:8805, ::1:8805) +# o PFCP Server(127.0.0.3:8805, ::1:8805) # pfcp: -# - addr: 127.0.0.6 +# - addr: 127.0.0.3 # - addr: ::1 # sgwc: gtpc: - addr: 127.0.0.6 + addr: 127.0.0.3 pfcp: - addr: 127.0.0.6 + addr: 127.0.0.3 # # sgwu: # # > # -# o PFCP Client(127.0.0.7:8805) +# o PFCP Client(127.0.0.6:8805) # # pfcp: -# addr: 127.0.0.7 +# addr: 127.0.0.6 # # # # o Round-Robin # sgwu: # pfcp: -# - addr: 127.0.0.7 +# - addr: 127.0.0.6 # - addr: 127.0.0.12 # # o UPF selection by eNodeB TAC @@ -74,7 +74,7 @@ sgwc: # # sgwu: # pfcp: -# - addr: 127.0.0.7 +# - addr: 127.0.0.6 # tac: 1 # - addr: 127.0.0.12 # tac: [3,5,8] @@ -83,7 +83,7 @@ sgwc: # # sgwu: # pfcp: -# - addr: 127.0.0.7 +# - addr: 127.0.0.6 # dnn: ims # - addr: 127.0.0.12 # apn: [internet, web] @@ -93,14 +93,14 @@ sgwc: # # sgwu: # pfcp: -# - addr: 127.0.0.7 +# - addr: 127.0.0.6 # e_cell_id: 463 # - addr: 127.0.0.12 # nr_cell_id: [123456789, 9413] # sgwu: pfcp: - addr: 127.0.0.7 + addr: 127.0.0.6 # # parameter: @@ -124,7 +124,6 @@ sgwu: # no_slaac: true # parameter: - no_ipv6: true # # max: diff --git a/configs/open5gs/sgwu.yaml.in b/configs/open5gs/sgwu.yaml.in index ffb0452a6..dbe36ac68 100644 --- a/configs/open5gs/sgwu.yaml.in +++ b/configs/open5gs/sgwu.yaml.in @@ -16,10 +16,10 @@ # # o Set OGS_LOG_TRACE to all domain level # level: trace -# domain: core,gtp,sgw,event,tlv,mem,sock +# domain: core,pfcp,gtp,sgwu,event,tlv,mem,sock # logger: - file: @localstatedir@/log/open5gs/sgwc.log + file: @localstatedir@/log/open5gs/sgwu.log # # sgwu: @@ -44,16 +44,16 @@ logger: # # # -# o PFCP Server(127.0.0.7:8805, ::1:8805) +# o PFCP Server(127.0.0.6:8805, ::1:8805) # pfcp: -# - addr: 127.0.0.7 +# - addr: 127.0.0.6 # - addr: ::1 # sgwu: gtpu: - addr: 127.0.0.7 + addr: 127.0.0.6 pfcp: - addr: 127.0.0.7 + addr: 127.0.0.6 # # sgwc: @@ -89,7 +89,6 @@ sgwc: # no_slaac: true # parameter: - no_ipv6: true # # max: diff --git a/configs/open5gs/smf.yaml.in b/configs/open5gs/smf.yaml.in index 4fb74187f..06405d8dd 100644 --- a/configs/open5gs/smf.yaml.in +++ b/configs/open5gs/smf.yaml.in @@ -16,7 +16,7 @@ # # o Set OGS_LOG_TRACE to all domain level # level: trace -# domain: core,pfcp,fd,gtp,smf,event,tlv,mem,sock +# domain: core,pfcp,fd,pfcp,gtp,smf,event,tlv,mem,sock # logger: file: @localstatedir@/log/open5gs/smf.log @@ -41,9 +41,9 @@ logger: # key: smf.key # pem: smf.pem # -# o SBI Server(https://127.0.0.3:443, http://[::1]:80) +# o SBI Server(https://127.0.0.4:443, http://[::1]:80) # sbi: -# - addr: 127.0.0.3 +# - addr: 127.0.0.4 # tls: # key: smf.key # pem: smf.pem @@ -53,9 +53,9 @@ logger: # sbi: # name: smf.open5gs.org # -# o SBI Server(http://127.0.0.3:7777) +# o SBI Server(http://127.0.0.4:7777) # sbi: -# - addr: 127.0.0.3 +# - addr: 127.0.0.4 # port: 7777 # # o SBI Server(http://:80) @@ -64,23 +64,23 @@ logger: # # # -# o PFCP Server(127.0.0.3:8805, ::1:8805) +# o PFCP Server(127.0.0.4:8805, ::1:8805) # pfcp: -# - addr: 127.0.0.3 +# - addr: 127.0.0.4 # - addr: ::1 # # # -# o GTP-C Server(127.0.0.3:2123, [fe80::3%@loopback_devname@]:2123) +# o GTP-C Server(127.0.0.4:2123, [fe80::3%@loopback_devname@]:2123) # gtpc: # addr: -# - 127.0.0.3 +# - 127.0.0.4 # - fe80::3%@loopback_devname@ # # o On SMF, Same configuration -# (127.0.0.3:2123, [fe80::3%@loopback_devname@]:2123). +# (127.0.0.4:2123, [fe80::3%@loopback_devname@]:2123). # gtpc: -# - addr: 127.0.0.3 +# - addr: 127.0.0.4 # - addr: fe80::3%@loopback_devname@ # # @@ -181,13 +181,13 @@ logger: # smf: sbi: - - addr: 127.0.0.3 + - addr: 127.0.0.4 port: 7777 gtpc: - - addr: 127.0.0.3 + - addr: 127.0.0.4 - addr: ::1 pfcp: - - addr: 127.0.0.3 + - addr: 127.0.0.4 - addr: ::1 pdn: - addr: 10.45.0.1/16 @@ -198,7 +198,7 @@ smf: - 2001:4860:4860::8888 - 2001:4860:4860::8844 mtu: 1400 - freeDiameter: @sysconfdir@/freeDiameter/pgw.conf + freeDiameter: @sysconfdir@/freeDiameter/smf.conf # # nrf: @@ -207,29 +207,29 @@ smf: # # o SBI Client(http://127.0.0.1:7777) # sbi: -# addr: 127.0.0.1 +# addr: 127.0.0.10 # port: 7777 # -# o SBI Client(https://127.0.0.1:443, http://nrf.open5gs.org:80) +# o SBI Client(https://127.0.0.10:443, http://nrf.open5gs.org:80) # sbi: -# - addr: 127.0.0.1 +# - addr: 127.0.0.10 # tls: # key: nrf.key # pem: nrf.pem # - name: nrf.open5gs.org # # o SBI Client(http://[fe80::1%@loopback_devname@]:80) -# If prefer_ipv4 is true, http://127.0.0.1:80 is selected. +# If prefer_ipv4 is true, http://127.0.0.10:80 is selected. # # sbi: # addr: -# - 127.0.0.1 +# - 127.0.0.10 # - fe80::1%@loopback_devname@ # nrf: sbi: - addr: - - 127.0.0.1 + - 127.0.0.10 - ::1 port: 7777 @@ -238,17 +238,17 @@ nrf: # # > # -# o PFCP Client(127.0.0.4:8805) +# o PFCP Client(127.0.0.7:8805) # # pfcp: -# addr: 127.0.0.4 +# addr: 127.0.0.7 # # # # o Round-Robin # upf: # pfcp: -# - addr: 127.0.0.4 +# - addr: 127.0.0.7 # - addr: 127.0.0.12 # # o UPF selection by eNodeB TAC @@ -256,7 +256,7 @@ nrf: # # upf: # pfcp: -# - addr: 127.0.0.4 +# - addr: 127.0.0.7 # tac: 1 # - addr: 127.0.0.12 # tac: [3,5,8] @@ -265,7 +265,7 @@ nrf: # # upf: # pfcp: -# - addr: 127.0.0.4 +# - addr: 127.0.0.7 # dnn: ims # - addr: 127.0.0.12 # apn: [internet, web] @@ -275,14 +275,14 @@ nrf: # # upf: # pfcp: -# - addr: 127.0.0.4 +# - addr: 127.0.0.7 # e_cell_id: 463 # - addr: 127.0.0.12 # nr_cell_id: [123456789, 9413] # upf: pfcp: - - addr: 127.0.0.4 + - addr: 127.0.0.7 # # parameter: diff --git a/configs/open5gs/udm.yaml.in b/configs/open5gs/udm.yaml.in index 2cb9362cc..4e5bab617 100644 --- a/configs/open5gs/udm.yaml.in +++ b/configs/open5gs/udm.yaml.in @@ -16,7 +16,7 @@ # # o Set OGS_LOG_TRACE to all domain level # level: trace -# domain: core,pfcp,fd,gtp,udm,event,tlv,mem,sock +# domain: core,sbi,udm,event,tlv,mem,sock # logger: file: @localstatedir@/log/open5gs/udm.log @@ -41,9 +41,9 @@ logger: # key: udm.key # pem: udm.pem # -# o SBI Server(https://127.0.0.6:443, http://[::1]:80) +# o SBI Server(https://127.0.0.12:443, http://[::1]:80) # sbi: -# - addr: 127.0.0.6 +# - addr: 127.0.0.12 # tls: # key: udm.key # pem: udm.pem @@ -53,9 +53,9 @@ logger: # sbi: # name: udm.open5gs.org # -# o SBI Server(http://127.0.0.6:7777) +# o SBI Server(http://127.0.0.12:7777) # sbi: -# - addr: 127.0.0.6 +# - addr: 127.0.0.12 # port: 7777 # # o SBI Server(http://:80) @@ -64,7 +64,7 @@ logger: # udm: sbi: - - addr: 127.0.0.6 + - addr: 127.0.0.12 port: 7777 # @@ -72,31 +72,31 @@ udm: # # > # -# o SBI Client(http://127.0.0.1:7777) +# o SBI Client(http://127.0.0.10:7777) # sbi: -# addr: 127.0.0.1 +# addr: 127.0.0.10 # port: 7777 # -# o SBI Client(https://127.0.0.1:443, http://nrf.open5gs.org:80) +# o SBI Client(https://127.0.0.10:443, http://nrf.open5gs.org:80) # sbi: -# - addr: 127.0.0.1 +# - addr: 127.0.0.10 # tls: # key: nrf.key # pem: nrf.pem # - name: nrf.open5gs.org # # o SBI Client(http://[fe80::1%@loopback_devname@]:80) -# If prefer_ipv4 is true, http://127.0.0.1:80 is selected. +# If prefer_ipv4 is true, http://127.0.0.10:80 is selected. # # sbi: # addr: -# - 127.0.0.1 +# - 127.0.0.10 # - fe80::1%@loopback_devname@ # nrf: sbi: - addr: - - 127.0.0.1 + - 127.0.0.10 - ::1 port: 7777 diff --git a/configs/open5gs/udr.yaml.in b/configs/open5gs/udr.yaml.in index e7292bd32..9396627dc 100644 --- a/configs/open5gs/udr.yaml.in +++ b/configs/open5gs/udr.yaml.in @@ -18,7 +18,7 @@ db_uri: mongodb://localhost/open5gs # # o Set OGS_LOG_TRACE to all domain level # level: trace -# domain: core,pfcp,fd,gtp,udr,event,tlv,mem,sock +# domain: core,sbi,udr,event,tlv,mem,sock # logger: file: @localstatedir@/log/open5gs/udr.log @@ -43,9 +43,9 @@ logger: # key: udr.key # pem: udr.pem # -# o SBI Server(https://127.0.0.7:443, http://[::1]:80) +# o SBI Server(https://127.0.0.13:443, http://[::1]:80) # sbi: -# - addr: 127.0.0.7 +# - addr: 127.0.0.13 # tls: # key: udr.key # pem: udr.pem @@ -55,9 +55,9 @@ logger: # sbi: # name: udr.open5gs.org # -# o SBI Server(http://127.0.0.7:7777) +# o SBI Server(http://127.0.0.13:7777) # sbi: -# - addr: 127.0.0.7 +# - addr: 127.0.0.13 # port: 7777 # # o SBI Server(http://:80) @@ -66,7 +66,7 @@ logger: # udr: sbi: - - addr: 127.0.0.7 + - addr: 127.0.0.13 port: 7777 # @@ -74,31 +74,31 @@ udr: # # > # -# o SBI Client(http://127.0.0.1:7777) +# o SBI Client(http://127.0.0.10:7777) # sbi: -# addr: 127.0.0.1 +# addr: 127.0.0.10 # port: 7777 # -# o SBI Client(https://127.0.0.1:443, http://nrf.open5gs.org:80) +# o SBI Client(https://127.0.0.10:443, http://nrf.open5gs.org:80) # sbi: -# - addr: 127.0.0.1 +# - addr: 127.0.0.10 # tls: # key: nrf.key # pem: nrf.pem # - name: nrf.open5gs.org # # o SBI Client(http://[fe80::1%@loopback_devname@]:80) -# If prefer_ipv4 is true, http://127.0.0.1:80 is selected. +# If prefer_ipv4 is true, http://127.0.0.10:80 is selected. # # sbi: # addr: -# - 127.0.0.1 +# - 127.0.0.10 # - fe80::1%@loopback_devname@ # nrf: sbi: - addr: - - 127.0.0.1 + - 127.0.0.10 - ::1 port: 7777 diff --git a/configs/open5gs/upf.yaml.in b/configs/open5gs/upf.yaml.in index d54b09900..c270ad36a 100644 --- a/configs/open5gs/upf.yaml.in +++ b/configs/open5gs/upf.yaml.in @@ -26,26 +26,26 @@ logger: # # # -# o PFCP Server(127.0.0.4:8805) +# o PFCP Server(127.0.0.7:8805) # pfcp: -# addr: 127.0.0.4 +# addr: 127.0.0.7 # # > # -# o GTP-U Server(127.0.0.4:2152, [::1]:2152) +# o GTP-U Server(127.0.0.7:2152, [::1]:2152) # gtpu: # - addr: -# - 127.0.0.4 +# - 127.0.0.7 # - ::1 # -# o Same configuration(127.0.0.4:2152, [::1]:2152) as below. +# o Same configuration(127.0.0.7:2152, [::1]:2152) as below. # gtpu: # name: localhost # # o User Plane IP Resource information # gtpu: # - addr: -# - 127.0.0.4 +# - 127.0.0.7 # - ::1 # teid_range_indication: 4 # teid_range: 10 @@ -59,12 +59,14 @@ logger: # upf: pfcp: - - addr: 127.0.0.4 + - addr: 127.0.0.7 gtpu: - addr: - - 127.0.0.4 + - 127.0.0.7 - ::1 pdn: + - addr: 10.45.0.1/16 + - addr: cafe::1/64 # # smf: diff --git a/configs/app.yaml.in b/configs/sample.yaml.in similarity index 74% rename from configs/app.yaml.in rename to configs/sample.yaml.in index fe04fff6d..9da878e8e 100644 --- a/configs/app.yaml.in +++ b/configs/sample.yaml.in @@ -3,14 +3,18 @@ db_uri: mongodb://localhost/open5gs logger: parameter: - no_ipv6: true - -nrf: - sbi: - addr: - - 127.0.0.1 - - ::1 - port: 7777 +# no_nrf: true +# no_amf: true +# no_smf: true +# no_upf: true +# no_ausf: true +# no_udm: true +# no_udr: true +# no_mme: true +# no_sgwc: true +# no_sgwu: true +# no_pcrf: true +# no_hss: true mme: freeDiameter: @@ -28,13 +32,13 @@ mme: - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - identity: hss.localdomain - addr: 127.0.0.4 + addr: 127.0.0.8 s1ap: - addr: 127.0.0.1 + addr: 127.0.0.2 gtpc: - addr: 127.0.0.1 - gummei: + addr: 127.0.0.2 + gummei: plmn_id: mcc: 901 mnc: 70 @@ -54,25 +58,19 @@ mme: sgwc: gtpc: - addr: 127.0.0.6 + addr: 127.0.0.3 pfcp: - addr: 127.0.0.6 - -sgwu: - gtpu: - addr: 127.0.0.7 - pfcp: - addr: 127.0.0.7 + addr: 127.0.0.3 smf: sbi: - - addr: 127.0.0.3 + - addr: 127.0.0.4 port: 7777 gtpc: - - addr: 127.0.0.3 + - addr: 127.0.0.4 - addr: ::1 pfcp: - - addr: 127.0.0.3 + - addr: 127.0.0.4 pdn: - addr: 10.45.0.1/16 - addr: cafe::1/64 @@ -85,7 +83,7 @@ smf: freeDiameter: identity: smf.localdomain realm: localdomain - listen_on: 127.0.0.3 + listen_on: 127.0.0.4 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -97,13 +95,50 @@ smf: - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - identity: pcrf.localdomain - addr: 127.0.0.5 + addr: 127.0.0.9 +amf: + sbi: + - addr: 127.0.0.5 + port: 7777 + ngap: + - addr: 127.0.0.5 + guami: + - plmn_id: + mcc: 901 + mnc: 70 + amf_id: + region: 2 + set: 1 + tai: + - plmn_id: + mcc: 901 + mnc: 70 + tac: 1 + plmn: + - plmn_id: + mcc: 901 + mnc: 70 + s_nssai: + - sst: 1 + security: + integrity_order : [ NIA1, NIA2, NIA0 ] + ciphering_order : [ NEA0, NEA1, NEA2 ] + network_name: + full: Open5GS + amf_name: open5gs-amf0 + +sgwu: + gtpu: + addr: 127.0.0.6 + pfcp: + addr: 127.0.0.6 + upf: pfcp: - - addr: 127.0.0.4 + - addr: 127.0.0.7 gtpu: - addr: - - 127.0.0.4 + - 127.0.0.7 - ::1 pdn: - addr: 10.45.0.1/16 @@ -113,7 +148,7 @@ hss: freeDiameter: identity: hss.localdomain realm: localdomain - listen_on: 127.0.0.4 + listen_on: 127.0.0.8 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -130,7 +165,7 @@ pcrf: freeDiameter: identity: pcrf.localdomain realm: localdomain - listen_on: 127.0.0.5 + listen_on: 127.0.0.9 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -142,4 +177,26 @@ pcrf: - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - identity: smf.localdomain - addr: 127.0.0.3 + addr: 127.0.0.4 + +nrf: + sbi: + addr: + - 127.0.0.10 + - ::1 + port: 7777 + +ausf: + sbi: + - addr: 127.0.0.11 + port: 7777 + +udm: + sbi: + - addr: 127.0.0.12 + port: 7777 + +udr: + sbi: + - addr: 127.0.0.13 + port: 7777 diff --git a/configs/srslte.yaml.in b/configs/srslte.yaml.in index 4f0253cf0..d83b6eefa 100644 --- a/configs/srslte.yaml.in +++ b/configs/srslte.yaml.in @@ -3,14 +3,18 @@ db_uri: mongodb://localhost/open5gs logger: parameter: - no_ipv6: true - -nrf: - sbi: - addr: - - 127.0.0.1 - - ::1 - port: 7777 +# no_nrf: true +# no_amf: true +# no_smf: true +# no_upf: true +# no_ausf: true +# no_udm: true +# no_udr: true +# no_mme: true +# no_sgwc: true +# no_sgwu: true +# no_pcrf: true +# no_hss: true mme: freeDiameter: @@ -28,13 +32,13 @@ mme: - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - identity: hss.localdomain - addr: 127.0.0.4 + addr: 127.0.0.8 s1ap: addr: 127.0.1.100 gtpc: addr: 127.0.1.100 - gummei: + gummei: plmn_id: mcc: 901 mnc: 70 @@ -54,25 +58,19 @@ mme: sgwc: gtpc: - addr: 127.0.0.6 + addr: 127.0.0.3 pfcp: - addr: 127.0.0.6 - -sgwu: - gtpu: - addr: 127.0.0.7 - pfcp: - addr: 127.0.0.7 + addr: 127.0.0.3 smf: sbi: - - addr: 127.0.0.3 + - addr: 127.0.0.4 port: 7777 gtpc: - - addr: 127.0.0.3 + - addr: 127.0.0.4 - addr: ::1 pfcp: - - addr: 127.0.0.3 + - addr: 127.0.0.4 pdn: - addr: 10.45.0.1/16 - addr: cafe::1/64 @@ -85,7 +83,7 @@ smf: freeDiameter: identity: smf.localdomain realm: localdomain - listen_on: 127.0.0.3 + listen_on: 127.0.0.4 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -97,24 +95,60 @@ smf: - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - identity: pcrf.localdomain - addr: 127.0.0.5 + addr: 127.0.0.9 +amf: + sbi: + - addr: 127.0.0.5 + port: 7777 + ngap: + - addr: 127.0.0.5 + guami: + - plmn_id: + mcc: 901 + mnc: 70 + amf_id: + region: 2 + set: 1 + tai: + - plmn_id: + mcc: 901 + mnc: 70 + tac: 1 + plmn: + - plmn_id: + mcc: 901 + mnc: 70 + s_nssai: + - sst: 1 + security: + integrity_order : [ NIA1, NIA2, NIA0 ] + ciphering_order : [ NEA0, NEA1, NEA2 ] + network_name: + full: Open5GS + amf_name: open5gs-amf0 + +sgwu: + gtpu: + addr: 127.0.0.6 + pfcp: + addr: 127.0.0.6 + upf: pfcp: - - addr: 127.0.0.4 + - addr: 127.0.0.7 gtpu: - addr: - - 127.0.0.4 + - 127.0.0.7 - ::1 pdn: - addr: 10.45.0.1/16 - addr: cafe::1/64 - hss: freeDiameter: identity: hss.localdomain realm: localdomain - listen_on: 127.0.0.4 + listen_on: 127.0.0.8 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -127,12 +161,11 @@ hss: connect: - identity: mme.localdomain addr: 127.0.0.2 - pcrf: freeDiameter: identity: pcrf.localdomain realm: localdomain - listen_on: 127.0.0.5 + listen_on: 127.0.0.9 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -144,4 +177,26 @@ pcrf: - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - identity: smf.localdomain - addr: 127.0.0.3 + addr: 127.0.0.4 + +nrf: + sbi: + addr: + - 127.0.0.10 + - ::1 + port: 7777 + +ausf: + sbi: + - addr: 127.0.0.11 + port: 7777 + +udm: + sbi: + - addr: 127.0.0.12 + port: 7777 + +udr: + sbi: + - addr: 127.0.0.13 + port: 7777 diff --git a/configs/systemd/meson.build b/configs/systemd/meson.build index 2cba508f1..e228b601e 100644 --- a/configs/systemd/meson.build +++ b/configs/systemd/meson.build @@ -16,11 +16,18 @@ # along with this program. If not, see . systemd_conf_in = ''' - open5gs-hssd.service - open5gs-pgwd.service open5gs-mmed.service - open5gs-sgwd.service + open5gs-sgwcd.service + open5gs-smfd.service + open5gs-amfd.service + open5gs-sgwud.service + open5gs-upfd.service + open5gs-hssd.service open5gs-pcrfd.service + open5gs-nrfd.service + open5gs-ausfd.service + open5gs-udmd.service + open5gs-udrd.service '''.split() foreach file : systemd_conf_in diff --git a/configs/systemd/open5gs-sgwd.service.in b/configs/systemd/open5gs-amfd.service.in similarity index 68% rename from configs/systemd/open5gs-sgwd.service.in rename to configs/systemd/open5gs-amfd.service.in index 12b705880..d9280bc9c 100644 --- a/configs/systemd/open5gs-sgwd.service.in +++ b/configs/systemd/open5gs-amfd.service.in @@ -1,5 +1,5 @@ [Unit] -Description=Open5GS S-GW Daemon +Description=Open5GS AMF Daemon After=networking.service [Service] @@ -9,7 +9,7 @@ User=open5gs Group=open5gs Restart=always -ExecStart=@bindir@/open5gs-sgwd -c @sysconfdir@/open5gs/sgw.yaml +ExecStart=@bindir@/open5gs-amfd -c @sysconfdir@/open5gs/amf.yaml RestartSec=2 RestartPreventExitStatus=1 ExecReload=/bin/kill -HUP $MAINPID diff --git a/configs/systemd/open5gs-ausfd.service.in b/configs/systemd/open5gs-ausfd.service.in new file mode 100644 index 000000000..f633eb2ef --- /dev/null +++ b/configs/systemd/open5gs-ausfd.service.in @@ -0,0 +1,18 @@ +[Unit] +Description=Open5GS AUSF Daemon +After=networking.service + +[Service] +Type=simple + +User=open5gs +Group=open5gs + +Restart=always +ExecStart=@bindir@/open5gs-ausfd -c @sysconfdir@/open5gs/ausf.yaml +RestartSec=2 +RestartPreventExitStatus=1 +ExecReload=/bin/kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/configs/systemd/open5gs-nrfd.service.in b/configs/systemd/open5gs-nrfd.service.in new file mode 100644 index 000000000..5bdc0a41c --- /dev/null +++ b/configs/systemd/open5gs-nrfd.service.in @@ -0,0 +1,18 @@ +[Unit] +Description=Open5GS NRF Daemon +After=networking.service + +[Service] +Type=simple + +User=open5gs +Group=open5gs + +Restart=always +ExecStart=@bindir@/open5gs-nrfd -c @sysconfdir@/open5gs/nrf.yaml +RestartSec=2 +RestartPreventExitStatus=1 +ExecReload=/bin/kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/configs/systemd/open5gs-sgwcd.service.in b/configs/systemd/open5gs-sgwcd.service.in new file mode 100644 index 000000000..75f03819b --- /dev/null +++ b/configs/systemd/open5gs-sgwcd.service.in @@ -0,0 +1,18 @@ +[Unit] +Description=Open5GS SGW-C Daemon +After=networking.service + +[Service] +Type=simple + +User=open5gs +Group=open5gs + +Restart=always +ExecStart=@bindir@/open5gs-sgwcd -c @sysconfdir@/open5gs/sgwc.yaml +RestartSec=2 +RestartPreventExitStatus=1 +ExecReload=/bin/kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/configs/systemd/open5gs-sgwud.service.in b/configs/systemd/open5gs-sgwud.service.in new file mode 100644 index 000000000..c4cc78f45 --- /dev/null +++ b/configs/systemd/open5gs-sgwud.service.in @@ -0,0 +1,18 @@ +[Unit] +Description=Open5GS SGW-U Daemon +After=networking.service + +[Service] +Type=simple + +User=open5gs +Group=open5gs + +Restart=always +ExecStart=@bindir@/open5gs-sgwud -c @sysconfdir@/open5gs/sgwu.yaml +RestartSec=2 +RestartPreventExitStatus=1 +ExecReload=/bin/kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/configs/systemd/open5gs-pgwd.service.in b/configs/systemd/open5gs-smfd.service.in similarity index 72% rename from configs/systemd/open5gs-pgwd.service.in rename to configs/systemd/open5gs-smfd.service.in index 05e2dfa40..94322acd9 100644 --- a/configs/systemd/open5gs-pgwd.service.in +++ b/configs/systemd/open5gs-smfd.service.in @@ -1,5 +1,5 @@ [Unit] -Description=Open5GS P-GW Daemon +Description=Open5GS SMF Daemon After=networking.service Requires=systemd-networkd.service @@ -10,7 +10,7 @@ User=open5gs Group=open5gs Restart=always -ExecStart=@bindir@/open5gs-pgwd -c @sysconfdir@/open5gs/pgw.yaml +ExecStart=@bindir@/open5gs-smfd -c @sysconfdir@/open5gs/smf.yaml RestartSec=2 RestartPreventExitStatus=1 ExecReload=/bin/kill -HUP $MAINPID diff --git a/configs/systemd/open5gs-udmd.service.in b/configs/systemd/open5gs-udmd.service.in new file mode 100644 index 000000000..ce5b87541 --- /dev/null +++ b/configs/systemd/open5gs-udmd.service.in @@ -0,0 +1,18 @@ +[Unit] +Description=Open5GS UDM Daemon +After=networking.service + +[Service] +Type=simple + +User=open5gs +Group=open5gs + +Restart=always +ExecStart=@bindir@/open5gs-udmd -c @sysconfdir@/open5gs/udm.yaml +RestartSec=2 +RestartPreventExitStatus=1 +ExecReload=/bin/kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/configs/systemd/open5gs-udrd.service.in b/configs/systemd/open5gs-udrd.service.in new file mode 100644 index 000000000..ee2686096 --- /dev/null +++ b/configs/systemd/open5gs-udrd.service.in @@ -0,0 +1,18 @@ +[Unit] +Description=Open5GS UDR Daemon +After=networking.service + +[Service] +Type=simple + +User=open5gs +Group=open5gs + +Restart=always +ExecStart=@bindir@/open5gs-udrd -c @sysconfdir@/open5gs/udr.yaml +RestartSec=2 +RestartPreventExitStatus=1 +ExecReload=/bin/kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/configs/systemd/open5gs-upfd.service.in b/configs/systemd/open5gs-upfd.service.in new file mode 100644 index 000000000..7a9f5faba --- /dev/null +++ b/configs/systemd/open5gs-upfd.service.in @@ -0,0 +1,19 @@ +[Unit] +Description=Open5GS UPF Daemon +After=networking.service +Requires=systemd-networkd.service + +[Service] +Type=simple + +User=open5gs +Group=open5gs + +Restart=always +ExecStart=@bindir@/open5gs-upfd -c @sysconfdir@/open5gs/upf.yaml +RestartSec=2 +RestartPreventExitStatus=1 +ExecReload=/bin/kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/configs/volte.yaml.in b/configs/volte.yaml.in index db0b8f378..ca7178979 100644 --- a/configs/volte.yaml.in +++ b/configs/volte.yaml.in @@ -10,19 +10,16 @@ parameter: # no_ausf: true # no_udm: true # no_udr: true +# no_mme: true +# no_sgwc: true +# no_sgwu: true +# no_pcrf: true +# no_hss: true -nrf: - sbi: - addr: - - 127.0.0.1 - - ::1 - port: 7777 mme: freeDiameter: - identity: mme.open-ims.test - realm: open-ims.test -# port: 3868 -# sec_port: 5868 + identity: mme.localdomain + realm: localdomain listen_on: 127.0.0.2 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx @@ -34,15 +31,14 @@ mme: - module: @freediameter_extensions_builddir@/dict_dcca.fdx - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - - identity: hss.open-ims.test - addr: 127.0.0.4 -# port: 3868 + - identity: hss.localdomain + addr: 127.0.0.8 s1ap: - addr: 127.0.0.1 + addr: 127.0.0.2 gtpc: - addr: 127.0.0.1 - gummei: + addr: 127.0.0.2 + gummei: plmn_id: mcc: 001 mnc: 01 @@ -57,27 +53,24 @@ mme: integrity_order : [ EIA1, EIA2, EIA0 ] ciphering_order : [ EEA0, EEA1, EEA2 ] + network_name: + full: Open5GS + sgwc: gtpc: - addr: 127.0.0.6 + addr: 127.0.0.3 pfcp: - addr: 127.0.0.6 - -sgwu: - gtpu: - addr: 127.0.0.7 - pfcp: - addr: 127.0.0.7 + addr: 127.0.0.3 smf: sbi: - - addr: 127.0.0.3 + - addr: 127.0.0.4 port: 7777 gtpc: - - addr: 127.0.0.3 + - addr: 127.0.0.4 - addr: ::1 pfcp: - - addr: 127.0.0.3 + - addr: 127.0.0.4 pdn: - addr: 10.45.0.1/16 - addr: cafe::1/64 @@ -88,42 +81,8 @@ smf: - 2001:4860:4860::8844 mtu: 1400 freeDiameter: - identity: smf.open-ims.test - realm: open-ims.test -# port: 3868 -# sec_port: 5868 - listen_on: 127.0.0.3 - load_extension: - - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx - conf: 0x8888 - - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx - - module: @freediameter_extensions_builddir@/dict_mip6i.fdx - - module: @freediameter_extensions_builddir@/dict_nasreq.fdx - - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx - - module: @freediameter_extensions_builddir@/dict_dcca.fdx - - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx - connect: - - identity: pcrf.open-ims.test - addr: 127.0.0.5 -# port: 3868 - -upf: - pfcp: - - addr: 127.0.0.4 - gtpu: - - addr: - - 127.0.0.4 - - ::1 - pdn: - - addr: 10.45.0.1/16 - - addr: cafe::1/64 - -hss: - freeDiameter: - identity: hss.open-ims.test - realm: open-ims.test -# port: 3868 -# sec_port: 5868 + identity: smf.localdomain + realm: localdomain listen_on: 127.0.0.4 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx @@ -135,17 +94,61 @@ hss: - module: @freediameter_extensions_builddir@/dict_dcca.fdx - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - - identity: mme.open-ims.test - addr: 127.0.0.2 -# port: 3868 + - identity: pcrf.localdomain + addr: 127.0.0.9 +amf: + sbi: + - addr: 127.0.0.5 + port: 7777 + ngap: + - addr: 127.0.0.5 + guami: + - plmn_id: + mcc: 001 + mnc: 01 + amf_id: + region: 2 + set: 1 + tai: + - plmn_id: + mcc: 001 + mnc: 01 + tac: 1 + plmn: + - plmn_id: + mcc: 001 + mnc: 01 + s_nssai: + - sst: 1 + security: + integrity_order : [ NIA1, NIA2, NIA0 ] + ciphering_order : [ NEA0, NEA1, NEA2 ] + network_name: + full: Open5GS + amf_name: open5gs-amf0 -pcrf: +sgwu: + gtpu: + addr: 127.0.0.6 + pfcp: + addr: 127.0.0.6 + +upf: + pfcp: + - addr: 127.0.0.7 + gtpu: + - addr: + - 127.0.0.7 + - ::1 + pdn: + - addr: 10.45.0.1/16 + - addr: cafe::1/64 + +hss: freeDiameter: - identity: pcrf.open-ims.test - realm: open-ims.test -# port: 3868 -# sec_port: 5868 - listen_on: 127.0.0.5 + identity: hss.localdomain + realm: localdomain + listen_on: 127.0.0.8 load_extension: - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx conf: 0x8888 @@ -156,7 +159,46 @@ pcrf: - module: @freediameter_extensions_builddir@/dict_dcca.fdx - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx connect: - - identity: smf.open-ims.test - addr: 127.0.0.3 - - identity: pcscf.open-ims.test + - identity: mme.localdomain + addr: 127.0.0.2 +pcrf: + freeDiameter: + identity: pcrf.localdomain + realm: localdomain + listen_on: 127.0.0.9 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: smf.localdomain + addr: 127.0.0.4 + - identity: pcscf.localdomain addr: 127.0.0.1 + +nrf: + sbi: + addr: + - 127.0.0.10 + - ::1 + port: 7777 + +ausf: + sbi: + - addr: 127.0.0.11 + port: 7777 + +udm: + sbi: + - addr: 127.0.0.12 + port: 7777 + +udr: + sbi: + - addr: 127.0.0.13 + port: 7777 diff --git a/debian/changelog b/debian/changelog index c2f89cd7a..85def1dd4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +open5gs (2.0.0) unstable; urgency=medium + + * 5G Core and EPC (Hybrid) + + -- Sukchan Lee Fri, 21 Aug 2020 22:18:53 -0400 + open5gs (1.3.0) unstable; urgency=medium * Release-16 diff --git a/debian/control b/debian/control index dc63ccf41..5c1747f9b 100644 --- a/debian/control +++ b/debian/control @@ -30,12 +30,12 @@ Architecture: any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends} -Description: Open Source based 3GPP EPC (Shared Files) - Open5GS is a C-language Open Source implementation of the 3GPP Evolved - Packet Core, i.e. the core network of an LTE network. +Description: 5G Core and EPC (Shared Files) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) . This package contains some core libraries/plugins required by the other - binary packages such as open5gs-{mme,sgw,pgw,pcrf,hss}. + binary packages such as open5gs-{mme,sgwc,sgwu,amf,smf,upf,...}. Package: open5gs-mme Architecture: any @@ -43,61 +43,79 @@ Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends}, open5gs-common (= ${binary:Version}) -Description: Open Source based 3GPP EPC MME (Mobility Management Entity) - Open5GS is a C-language Open Source implementation of the 3GPP Evolved - Packet Core, i.e. the core network of an LTE network. +Description: MME (Mobility Management Entity) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) . This package provides the MME (Mobility Management Engine), which terminates the S1 interfaces from the eNodeBs cells in the cellular - network, and interfaces via S11 to the SGW as well as via S6a to the + network, and interfaces via S11 to the SGW-C as well as via S6a to the HSS. -Package: open5gs-sgw +Package: open5gs-sgwc Architecture: any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends}, open5gs-common (= ${binary:Version}) -Description: Open Source based 3GPP EPC SGW (Serving Gateway) - Open5GS is a C-language Open Source implementation of the 3GPP Evolved - Packet Core, i.e. the core network of an LTE network. +Description: SGW-C (Serving Gateway - Control Plane) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) . - This package provides the SGW (Serving Gateway) which is situated - between the MME and PGW. It implements the S11 interface to the MME, - and the S5 interface to the PGW. + This package provides the SGW-C (Serving Gateway - Control Plane) + which is situated between the MME and PGW. It implements the S11 interface + to the MME, and the S5 interface to the SMF-C. -Package: open5gs-pgw +Package: open5gs-smf +Architecture: any +Multi-Arch: same +Depends: ${shlibs:Depends}, + ${misc:Depends}, + open5gs-common (= ${binary:Version}) +Description: SMF (Session Management Function) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) + . + This package provides the SMF (Session Management Function) + +Package: open5gs-amf +Architecture: any +Multi-Arch: same +Depends: ${shlibs:Depends}, + ${misc:Depends}, + open5gs-common (= ${binary:Version}) +Description: AMF (Access and Mobility Management Function) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) + . + This package provides the AMF (Access and Mobility Management Function) + +Package: open5gs-sgwu +Architecture: any +Multi-Arch: same +Depends: ${shlibs:Depends}, + ${misc:Depends}, + open5gs-common (= ${binary:Version}) +Description: SGW-U (Serving Gateway - User Plane) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) + . + This package provides the SGW-U (Serving Gateway - User Plane) + which is situated between the eNB and UPF. It implements the S1U interface + to the eNB, and the S5U interface to the SMF-U. + +Package: open5gs-upf Architecture: any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends}, udev, open5gs-common (= ${binary:Version}) -Description: Open Source based 3GPP EPC PGW (Packet Data Network Gateway) - Open5GS is a C-language Open Source implementation of the 3GPP Evolved - Packet Core, i.e. the core network of an LTE network. +Description: UPF (User Plane Function) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) . - This package provides the PGW or PDN-GW (Packet Data Network Gateway) - element of the EPC, i.e. the gateway between the EPC and the external - packet data network, such as the public Internet. It implements the S5 - interface towards the S-GW, the SGi interface towards the Internet, - and the S7 interface towards the PCRF. - -Package: open5gs-pcrf -Architecture: any -Multi-Arch: same -Depends: ${shlibs:Depends}, - ${misc:Depends}, - mongodb-org | mongodb, - open5gs-common (= ${binary:Version}) -Description: Open Source based 3GPP EPC PCRF (Policy and Charging Rules Function) - Open5GS is a C-language Open Source implementation of the 3GPP Evolved - Packet Core, i.e. the core network of an LTE network. - . - This package contains the PCRF (Policy and Charging Rules Function), - which controls the service quality (QoS) of individual connections and - how to account/charge related traffic. It implements the Gx interface - towards the PGW using the DIAMETER protocol. + This package provides the UPF (User Plane Function) Package: open5gs-hss Architecture: any @@ -106,9 +124,9 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, mongodb-org | mongodb, open5gs-common (= ${binary:Version}) -Description: Open Source based 3GPP EPC HSS (Home Subscriber Server) - Open5GS is a C-language Open Source implementation of the 3GPP Evolved - Packet Core, i.e. the core network of an LTE network. +Description: HSS (Home Subscriber Server) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) . This package provides the HSS (Home Subscriber Server) element of the EPC, i.e. the central database of mobile network subscribers, with @@ -116,22 +134,92 @@ Description: Open Source based 3GPP EPC HSS (Home Subscriber Server) information, etc. It implements the S6a interface towards the MME using the DIAMETER protocol. +Package: open5gs-pcrf +Architecture: any +Multi-Arch: same +Depends: ${shlibs:Depends}, + ${misc:Depends}, + mongodb-org | mongodb, + open5gs-common (= ${binary:Version}) +Description: PCRF (Policy and Charging Rules Function) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) + . + This package contains the PCRF (Policy and Charging Rules Function), + which controls the service quality (QoS) of individual connections and + how to account/charge related traffic. It implements the Gx interface + towards the SMF-C using the DIAMETER protocol. + +Package: open5gs-nrf +Architecture: any +Multi-Arch: same +Depends: ${shlibs:Depends}, + ${misc:Depends}, + open5gs-common (= ${binary:Version}) +Description: NRF (Network Repository Function) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) + . + This package provides the NRF (Network Repository Function) + +Package: open5gs-ausf +Architecture: any +Multi-Arch: same +Depends: ${shlibs:Depends}, + ${misc:Depends}, + open5gs-common (= ${binary:Version}) +Description: AUSF (Authentication Server Function) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) + . + This package provides the AUSF (Authentication Server Function) + +Package: open5gs-udm +Architecture: any +Multi-Arch: same +Depends: ${shlibs:Depends}, + ${misc:Depends}, + open5gs-common (= ${binary:Version}) +Description: UDM (Unified Data Management) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) + . + This package provides the UDM (Unified Data Managemement) + +Package: open5gs-udr +Architecture: any +Multi-Arch: same +Depends: ${shlibs:Depends}, + ${misc:Depends}, + open5gs-common (= ${binary:Version}) +Description: UDR (Unified Data Repository) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) + . + This package provides the UDR (Unified Data Repository) + Package: open5gs Architecture: any Multi-Arch: same Depends: ${misc:Depends}, open5gs-common (= ${binary:Version}), open5gs-mme (= ${binary:Version}), - open5gs-sgw (= ${binary:Version}), - open5gs-pgw (= ${binary:Version}), + open5gs-sgwc (= ${binary:Version}), + open5gs-smf (= ${binary:Version}), + open5gs-amf (= ${binary:Version}), + open5gs-sgwu (= ${binary:Version}), + open5gs-upf (= ${binary:Version}), open5gs-hss (= ${binary:Version}), - open5gs-pcrf (= ${binary:Version}) -Description: Open Source based 3GPP EPC (metapackage) - Open5GS is a C-language Open Source implementation of the 3GPP Evolved - Packet Core, i.e. the core network of an LTE network. + open5gs-pcrf (= ${binary:Version}), + open5gs-nrf (= ${binary:Version}), + open5gs-ausf (= ${binary:Version}), + open5gs-udm (= ${binary:Version}), + open5gs-udr (= ${binary:Version}) +Description: 5G Core and EPC (metapackage) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) . This is a metapackage that depends on all the open5gs parts. - (MME, SGW, PGW, HSS, PCRF) Package: open5gs-dbg Architecture: any @@ -139,7 +227,7 @@ Multi-Arch: same Depends: ${misc:Depends}, open5gs (= ${binary:Version}) Description: Debug symbols for Open5GS - Open5GS is a C-language Open Source implementation of the 3GPP Evolved - Packet Core, i.e. the core network of an LTE network. + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) . This package contains debug symbols for Open5GS. diff --git a/debian/open5gs-amf.install b/debian/open5gs-amf.install new file mode 100644 index 000000000..34795b1b8 --- /dev/null +++ b/debian/open5gs-amf.install @@ -0,0 +1,3 @@ +usr/bin/open5gs-amfd +configs/open5gs/amf.yaml etc/open5gs +configs/systemd/open5gs-amfd.service lib/systemd/system diff --git a/debian/open5gs-ausf.install b/debian/open5gs-ausf.install new file mode 100644 index 000000000..e8a401dee --- /dev/null +++ b/debian/open5gs-ausf.install @@ -0,0 +1,3 @@ +usr/bin/open5gs-ausfd +configs/open5gs/ausf.yaml etc/open5gs +configs/systemd/open5gs-ausfd.service lib/systemd/system diff --git a/debian/open5gs-nrf.install b/debian/open5gs-nrf.install new file mode 100644 index 000000000..3e9f6b80f --- /dev/null +++ b/debian/open5gs-nrf.install @@ -0,0 +1,3 @@ +usr/bin/open5gs-nrfd +configs/open5gs/nrf.yaml etc/open5gs +configs/systemd/open5gs-nrfd.service lib/systemd/system diff --git a/debian/open5gs-pgw.install b/debian/open5gs-pgw.install deleted file mode 100644 index 817448545..000000000 --- a/debian/open5gs-pgw.install +++ /dev/null @@ -1,5 +0,0 @@ -usr/bin/open5gs-pgwd -configs/freeDiameter/pgw.* etc/freeDiameter -configs/open5gs/pgw.yaml etc/open5gs -configs/systemd/99-open5gs.net* etc/systemd/network -configs/systemd/open5gs-pgwd.service lib/systemd/system diff --git a/debian/open5gs-sgw.install b/debian/open5gs-sgw.install deleted file mode 100644 index 1c1c5e27e..000000000 --- a/debian/open5gs-sgw.install +++ /dev/null @@ -1,3 +0,0 @@ -usr/bin/open5gs-sgwd -configs/open5gs/sgw.yaml etc/open5gs -configs/systemd/open5gs-sgwd.service lib/systemd/system diff --git a/debian/open5gs-sgwc.install b/debian/open5gs-sgwc.install new file mode 100644 index 000000000..23ffdd394 --- /dev/null +++ b/debian/open5gs-sgwc.install @@ -0,0 +1,3 @@ +usr/bin/open5gs-sgwcd +configs/open5gs/sgwc.yaml etc/open5gs +configs/systemd/open5gs-sgwcd.service lib/systemd/system diff --git a/debian/open5gs-sgwu.install b/debian/open5gs-sgwu.install new file mode 100644 index 000000000..1ef6b769f --- /dev/null +++ b/debian/open5gs-sgwu.install @@ -0,0 +1,3 @@ +usr/bin/open5gs-sgwud +configs/open5gs/sgwu.yaml etc/open5gs +configs/systemd/open5gs-sgwud.service lib/systemd/system diff --git a/debian/open5gs-smf.install b/debian/open5gs-smf.install new file mode 100644 index 000000000..fb5d2d66a --- /dev/null +++ b/debian/open5gs-smf.install @@ -0,0 +1,4 @@ +usr/bin/open5gs-smfd +configs/freeDiameter/smf.* etc/freeDiameter +configs/open5gs/smf.yaml etc/open5gs +configs/systemd/open5gs-smfd.service lib/systemd/system diff --git a/debian/open5gs-udm.install b/debian/open5gs-udm.install new file mode 100644 index 000000000..aa15fce4a --- /dev/null +++ b/debian/open5gs-udm.install @@ -0,0 +1,3 @@ +usr/bin/open5gs-udmd +configs/open5gs/udm.yaml etc/open5gs +configs/systemd/open5gs-udmd.service lib/systemd/system diff --git a/debian/open5gs-udr.install b/debian/open5gs-udr.install new file mode 100644 index 000000000..488d48c96 --- /dev/null +++ b/debian/open5gs-udr.install @@ -0,0 +1,3 @@ +usr/bin/open5gs-udrd +configs/open5gs/udr.yaml etc/open5gs +configs/systemd/open5gs-udrd.service lib/systemd/system diff --git a/debian/open5gs-upf.install b/debian/open5gs-upf.install new file mode 100644 index 000000000..7fc5a6ebc --- /dev/null +++ b/debian/open5gs-upf.install @@ -0,0 +1,4 @@ +usr/bin/open5gs-upfd +configs/open5gs/upf.yaml etc/open5gs +configs/systemd/99-open5gs.net* etc/systemd/network +configs/systemd/open5gs-upfd.service lib/systemd/system diff --git a/debian/open5gs-pgw.postinst b/debian/open5gs-upf.postinst similarity index 100% rename from debian/open5gs-pgw.postinst rename to debian/open5gs-upf.postinst diff --git a/debian/open5gs-pgw.postrm b/debian/open5gs-upf.postrm similarity index 100% rename from debian/open5gs-pgw.postrm rename to debian/open5gs-upf.postrm diff --git a/docs/_docs/guide/01-quickstart.md b/docs/_docs/guide/01-quickstart.md index 1e6115f2b..e709af60f 100644 --- a/docs/_docs/guide/01-quickstart.md +++ b/docs/_docs/guide/01-quickstart.md @@ -76,20 +76,101 @@ $ sudo zypper install open5gs ### Configure Open5GS --- -Modify [/etc/open5gs/mme.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/mme.yaml.in) to set the S1AP/GTP-C IP address, PLMN ID, and TAC +#### 5G Core + +Modify [install/etc/open5gs/amf.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/amf.yaml.in) to set the NGAP IP address, PLMN ID, TAC and NSSAI. + +In the below example we + +- use MCC-MNC of 901-70, as this is the home network of the default IMSIs of the sysmoUSIM-SJS1 cards. +- use 10.10.0.5 for the NGAP connection of AMF to the gNB +- use 10.11.0.7 for the GTP-U connection of UPF to the gNB + +```diff +diff -u amf.yaml.old amf.yaml +--- amf.yaml.old 2020-06-21 23:34:14.643114779 -0400 ++++ amf.yaml 2020-06-21 23:34:28.718482095 -0400 +@@ -67,25 +67,25 @@ + - addr: 127.0.0.5 + port: 7777 + ngap: +- - addr: 127.0.0.5 ++ - addr: 10.10.0.5 + guami: + - plmn_id: +- mcc: 001 +- mnc: 01 ++ mcc: 901 ++ mnc: 70 + amf_id: + region: 2 + set: 1 + tai: + - plmn_id: +- mcc: 001 +- mnc: 01 +- tac: 7 ++ mcc: 901 ++ mnc: 70 ++ tac: 1 + plmn: + - plmn_id: +- mcc: 001 +- mnc: 01 ++ mcc: 901 ++ mnc: 70 + s_nssai: + - sst: 1 +- - sd: 2 + security: + integrity_order : [ NIA1, NIA2, NIA0 ] + ciphering_order : [ NEA0, NEA1, NEA2 ] +``` + +Modify [install/etc/open5gs/upf.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/upf.yaml.in) to set the GTP-U IP address. +```diff +diff -u upf.yaml.old upf.yaml +--- upf.yaml.old 2020-06-21 23:35:54.378631781 -0400 ++++ upf.yaml 2020-06-21 23:36:02.978245251 -0400 +@@ -61,6 +61,7 @@ + pfcp: + - addr: 127.0.0.7 + gtpu: +- - addr: 127.0.0.7 ++ - addr: 10.11.0.7 + pdn: +``` + +After changing conf files, please restart Open5GS daemons. + +```bash +$ sudo systemctl restart open5gs-amfd +$ sudo systemctl restart open5gs-upfd +``` + +#### EPC + +Modify [install/etc/open5gs/mme.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/mme.yaml.in) to set the S1AP IP address, PLMN ID, and TAC. + +In the below example we + +- use MCC-MNC of 901-70, as this is the home network of the default IMSIs of the sysmoUSIM-SJS1 cards. +- use 10.10.0.2 for the S1AP connection of MME to the eNB +- use 10.11.0.6 for the GTP-U connection of SGW-U to the eNB ```diff diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml --- mme.yaml.old 2018-04-15 18:28:31.000000000 +0900 +++ mme.yaml 2018-04-15 19:53:10.000000000 +0900 -@@ -8,18 +8,20 @@ parameter: +@@ -204,20 +204,20 @@ logger: mme: - freeDiameter: /etc/freeDiameter/mme.conf + freeDiameter: @sysconfdir@/freeDiameter/mme.conf s1ap: -+ addr: 192.168.0.100 +- addr: 127.0.0.2 ++ addr: 10.10.0.2 gtpc: -+ addr: 192.168.0.100 - gummei: + addr: 127.0.0.2 + gummei: plmn_id: - mcc: 001 - mnc: 01 @@ -101,32 +182,37 @@ diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml plmn_id: - mcc: 001 - mnc: 01 -- tac: 12345 +- tac: 7 + mcc: 901 + mnc: 70 -+ tac: 7 ++ tac: 1 security: integrity_order : [ EIA1, EIA2, EIA0 ] ciphering_order : [ EEA0, EEA1, EEA2 ] + ``` -Modify [/etc/open5gs/sgw.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/sgw.yaml.in) to set the GTP-U IP address. +Modify [install/etc/open5gs/sgwu.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/sgwu.yaml.in) to set the GTP-U IP address. ```diff -diff -u /etc/open5gs/sgw.yaml.old /etc/open5gs/sgw.yaml ---- sgw.yaml.old 2018-04-15 18:30:25.000000000 +0900 -+++ sgw.yaml 2018-04-15 18:30:30.000000000 +0900 -@@ -14,3 +14,4 @@ - gtpc: - addr: 127.0.0.2 +diff -u /etc/open5gs/sgwu.yaml.old /etc/open5gs/sgwu.yaml +--- sgwu.yaml.old 2018-04-15 18:30:25.000000000 +0900 ++++ sgwu.yaml 2018-04-15 18:30:30.000000000 +0900 +@@ -51,7 +51,7 @@ logger: + # + sgwu: gtpu: -+ addr: 192.168.0.100 +- addr: 127.0.0.6 ++ addr: 10.11.0.6 + pfcp: + addr: 127.0.0.6 ``` + After changing conf files, please restart Open5GS daemons. ```bash $ sudo systemctl restart open5gs-mmed -$ sudo systemctl restart open5gs-sgwd +$ sudo systemctl restart open5gs-sgwud ``` ### Install WebUI of Open5GS diff --git a/docs/_docs/guide/02-building-open5gs-from-sources.md b/docs/_docs/guide/02-building-open5gs-from-sources.md index 81cbb8a72..1808c21ec 100644 --- a/docs/_docs/guide/02-building-open5gs-from-sources.md +++ b/docs/_docs/guide/02-building-open5gs-from-sources.md @@ -62,7 +62,7 @@ Check whether the compilation is correct. $ ninja -C build test ``` -**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 || diameter || gtp`. You can see the virtually created packets. [[testsimple.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testsimple.pcapng) +**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`. You can see the virtually created packets. [[testsimple.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testsimple.pcapng) {: .notice--info} You need to perform the **installation process**. @@ -75,25 +75,96 @@ $ cd ../ ### Configure Open5GS --- -Modify [install/etc/open5gs/mme.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/mme.yaml.in) to set the S1AP/GTP-C IP address, PLMN ID, and TAC. +#### 5G Core + +Modify [install/etc/open5gs/amf.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/amf.yaml.in) to set the NGAP IP address, PLMN ID, TAC and NSSAI. In the below example we - use MCC-MNC of 901-70, as this is the home network of the default IMSIs of the sysmoUSIM-SJS1 cards. -- use 192.168.0.100 for the S1AP +GTP-U connection of MME/SGW to the eNB +- use 10.10.0.5 for the NGAP connection of AMF to the gNB +- use 10.11.0.7 for the GTP-U connection of UPF to the gNB + +```diff +diff -u amf.yaml.old amf.yaml +--- amf.yaml.old 2020-06-21 23:34:14.643114779 -0400 ++++ amf.yaml 2020-06-21 23:34:28.718482095 -0400 +@@ -67,25 +67,25 @@ + - addr: 127.0.0.5 + port: 7777 + ngap: +- - addr: 127.0.0.5 ++ - addr: 10.10.0.5 + guami: + - plmn_id: +- mcc: 001 +- mnc: 01 ++ mcc: 901 ++ mnc: 70 + amf_id: + region: 2 + set: 1 + tai: + - plmn_id: +- mcc: 001 +- mnc: 01 +- tac: 7 ++ mcc: 901 ++ mnc: 70 ++ tac: 1 + plmn: + - plmn_id: +- mcc: 001 +- mnc: 01 ++ mcc: 901 ++ mnc: 70 + s_nssai: + - sst: 1 +- - sd: 2 + security: + integrity_order : [ NIA1, NIA2, NIA0 ] + ciphering_order : [ NEA0, NEA1, NEA2 ] +``` + +Modify [install/etc/open5gs/upf.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/upf.yaml.in) to set the GTP-U IP address. +```diff +diff -u upf.yaml.old upf.yaml +--- upf.yaml.old 2020-06-21 23:35:54.378631781 -0400 ++++ upf.yaml 2020-06-21 23:36:02.978245251 -0400 +@@ -61,6 +61,7 @@ + pfcp: + - addr: 127.0.0.7 + gtpu: +- - addr: 127.0.0.7 ++ - addr: 10.11.0.7 + pdn: +``` + +If you modify the config files while Open5GS daemons are running, please restart them + +#### EPC + +Modify [install/etc/open5gs/mme.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/mme.yaml.in) to set the S1AP IP address, PLMN ID, and TAC. + +In the below example we + +- use MCC-MNC of 901-70, as this is the home network of the default IMSIs of the sysmoUSIM-SJS1 cards. +- use 10.10.0.2 for the S1AP connection of MME to the eNB +- use 10.11.0.6 for the GTP-U connection of SGW-U to the eNB ```diff diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml --- mme.yaml.old 2018-04-15 18:28:31.000000000 +0900 +++ mme.yaml 2018-04-15 19:53:10.000000000 +0900 -@@ -8,18 +8,20 @@ parameter: +@@ -204,20 +204,20 @@ logger: mme: - freeDiameter: /etc/freeDiameter/mme.conf + freeDiameter: @sysconfdir@/freeDiameter/mme.conf s1ap: -+ addr: 192.168.0.100 +- addr: 127.0.0.2 ++ addr: 10.10.0.2 gtpc: -+ addr: 192.168.0.100 - gummei: + addr: 127.0.0.2 + gummei: plmn_id: - mcc: 001 - mnc: 01 @@ -105,25 +176,29 @@ diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml plmn_id: - mcc: 001 - mnc: 01 -- tac: 12345 +- tac: 7 + mcc: 901 + mnc: 70 -+ tac: 7 ++ tac: 1 security: integrity_order : [ EIA1, EIA2, EIA0 ] ciphering_order : [ EEA0, EEA1, EEA2 ] + ``` -Modify [install/etc/open5gs/sgw.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/sgw.yaml.in) to set the GTP-U IP address. +Modify [install/etc/open5gs/sgwu.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/sgwu.yaml.in) to set the GTP-U IP address. ```diff -diff -u /etc/open5gs/sgw.yaml.old /etc/open5gs/sgw.yaml ---- sgw.yaml.old 2018-04-15 18:30:25.000000000 +0900 -+++ sgw.yaml 2018-04-15 18:30:30.000000000 +0900 -@@ -14,3 +14,4 @@ - gtpc: - addr: 127.0.0.2 +diff -u /etc/open5gs/sgwu.yaml.old /etc/open5gs/sgwu.yaml +--- sgwu.yaml.old 2018-04-15 18:30:25.000000000 +0900 ++++ sgwu.yaml 2018-04-15 18:30:30.000000000 +0900 +@@ -51,7 +51,7 @@ logger: + # + sgwu: gtpu: -+ addr: 192.168.0.100 +- addr: 127.0.0.6 ++ addr: 10.11.0.6 + pfcp: + addr: 127.0.0.6 ``` If you modify the config files while Open5GS daemons are running, please restart them @@ -138,7 +213,7 @@ Specify the absolute path to the sharead library as follows. $ echo $(cd $(dirname ./install/lib/x86_64-linux-gnu/) && pwd -P)/$(basename ./install/lib/x86_64-linux-gnu/) /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu $ export LD_LIBRARY_PATH=/home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu -$ ldd ./install/bin/open5gs-mmed +$ ldd ./install/bin/open5gs-amfd ... libogsapp.so.1 => /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu/libogsapp.so.1 (0x00007f161ab51000) libogscore.so.1 => /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu/libogscore.so.1 (0x00007f161a922000) @@ -157,58 +232,123 @@ Now let's get started. ```bash $ cd install/bin/ -$ ./open5gs-pcrfd -Open5GS daemon v1.0.0 +$ ./install/bin/open5gs-mmed +Open5GS daemon v1.3.0-213-gd190548+ -10/27 15:47:55.821: [app] INFO: Configuration: '/Users/acetcom/Documents/git/open5gs/install/etc/open5gs/pcrf.yaml' (../src/main.c:54) -10/27 15:47:55.822: [app] INFO: File Logging: '/Users/acetcom/Documents/git/open5gs/install/var/log/open5gs/pcrf.log' (../src/main.c:57) -10/27 15:47:55.868: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) -10/27 15:47:55.965: [app] INFO: PCRF initialize...done (../src/pcrf/app-init.c:31) +08/21 22:53:47.328: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/mme.yaml' (../src/main.c:54) +08/21 22:53:47.328: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/mme.log' (../src/main.c:57) +08/21 22:53:47.365: [app] INFO: MME initialize...done (../src/mme/app-init.c:33) +08/21 22:53:47.365: [gtp] INFO: gtp_server() [127.0.0.2]:2123 (../lib/gtp/path.c:32) +08/21 22:53:47.365: [gtp] INFO: gtp_connect() [127.0.0.3]:2123 (../lib/gtp/path.c:59) +08/21 22:53:47.366: [mme] INFO: s1ap_server() [127.0.0.2]:36412 (../src/mme/s1ap-sctp.c:57) -$ ./open5gs-pgwd -Open5GS daemon v1.0.0 +$ ./install/bin/open5gs-sgwcd +Open5GS daemon v1.3.0-213-gd190548+ -10/27 15:48:11.198: [app] INFO: Configuration: '/Users/acetcom/Documents/git/open5gs/install/etc/open5gs/pgw.yaml' (../src/main.c:54) -10/27 15:48:11.199: [app] INFO: File Logging: '/Users/acetcom/Documents/git/open5gs/install/var/log/open5gs/pgw.log' (../src/main.c:57) -10/27 15:48:11.292: [app] INFO: PGW initialize...done (../src/pgw/app-init.c:31) -10/27 15:48:11.293: [gtp] INFO: gtp_server() [127.0.0.3]:2123 (../lib/gtp/path.c:32) -10/27 15:48:11.293: [gtp] INFO: gtp_server() [::1]:2123 (../lib/gtp/path.c:32) -10/27 15:48:11.293: [gtp] INFO: gtp_server() [127.0.0.3]:2152 (../lib/gtp/path.c:32) -10/27 15:48:11.293: [gtp] INFO: gtp_server() [::1]:2152 (../lib/gtp/path.c:32) +08/21 22:54:43.059: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/sgwc.yaml' (../src/main.c:54) +08/21 22:54:43.059: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/sgwc.log' (../src/main.c:57) +08/21 22:54:43.065: [app] INFO: SGW-C initialize...done (../src/sgwc/app.c:31) +08/21 22:54:43.066: [gtp] INFO: gtp_server() [127.0.0.3]:2123 (../lib/gtp/path.c:32) +08/21 22:54:43.066: [pfcp] INFO: pfcp_server() [127.0.0.3]:8805 (../lib/pfcp/path.c:32) +08/21 22:54:43.066: [pfcp] INFO: ogs_pfcp_connect() [127.0.0.6]:8805 (../lib/pfcp/path.c:60) -$ ./open5gs-sgwd -Open5GS daemon v1.0.0 +$ ./install/bin/open5gs-smfd +Open5GS daemon v1.3.0-213-gd190548+ -10/27 15:48:21.526: [app] INFO: Configuration: '/Users/acetcom/Documents/git/open5gs/install/etc/open5gs/sgw.yaml' (../src/main.c:54) -10/27 15:48:21.527: [app] INFO: File Logging: '/Users/acetcom/Documents/git/open5gs/install/var/log/open5gs/sgw.log' (../src/main.c:57) -10/27 15:48:21.533: [app] INFO: SGW initialize...done (../src/sgw/app-init.c:31) -10/27 15:48:21.537: [gtp] INFO: gtp_server() [127.0.0.2]:2123 (../lib/gtp/path.c:32) -10/27 15:48:21.537: [gtp] INFO: gtp_server() [192.168.0.3]:2152 (../lib/gtp/path.c:32) +08/21 22:54:56.000: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/smf.yaml' (../src/main.c:54) +08/21 22:54:56.000: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/smf.log' (../src/main.c:57) +08/21 22:54:56.050: [gtp] INFO: gtp_server() [127.0.0.4]:2123 (../lib/gtp/path.c:32) +08/21 22:54:56.050: [app] INFO: SMF initialize...done (../src/smf/app.c:31) +08/21 22:54:56.050: [gtp] INFO: gtp_server() [::1]:2123 (../lib/gtp/path.c:32) +08/21 22:54:56.050: [pfcp] INFO: pfcp_server() [127.0.0.4]:8805 (../lib/pfcp/path.c:32) +08/21 22:54:56.050: [pfcp] INFO: pfcp_server() [::1]:8805 (../lib/pfcp/path.c:32) +08/21 22:54:56.050: [pfcp] INFO: ogs_pfcp_connect() [127.0.0.7]:8805 (../lib/pfcp/path.c:60) +08/21 22:54:56.051: [sbi] INFO: sbi_server() [127.0.0.4]:7777 (../lib/sbi/server.c:298) -$ ./open5gs-hssd -Open5GS daemon v1.0.0 +$ ./install/bin/open5gs-amfd +Open5GS daemon v1.3.0-213-gd190548+ -10/27 15:48:32.802: [app] INFO: Configuration: '/Users/acetcom/Documents/git/open5gs/install/etc/open5gs/hss.yaml' (../src/main.c:54) -10/27 15:48:32.803: [app] INFO: File Logging: '/Users/acetcom/Documents/git/open5gs/install/var/log/open5gs/hss.log' (../src/main.c:57) -10/27 15:48:32.815: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) -10/27 15:48:32.861: [app] INFO: HSS initialize...done (../src/hss/app-init.c:31) +08/21 22:55:14.015: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/amf.yaml' (../src/main.c:54) +08/21 22:55:14.015: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/amf.log' (../src/main.c:57) +08/21 22:55:14.039: [app] INFO: AMF initialize...done (../src/amf/app.c:33) +08/21 22:55:14.040: [sbi] INFO: sbi_server() [127.0.0.5]:7777 (../lib/sbi/server.c:298) +08/21 22:55:14.040: [amf] INFO: ngap_server() [127.0.0.5]:38412 (../src/amf/ngap-sctp.c:56) -$ ./open5gs-mmed -Open5GS daemon v1.0.0 +$ ./install/bin/open5gs-sgwud +Open5GS daemon v1.3.0-213-gd190548+ -10/27 15:46:23.539: [app] INFO: Configuration: '/Users/acetcom/Documents/git/open5gs/install/etc/open5gs/mme.yaml' (../src/main.c:54) -10/27 15:46:23.540: [app] INFO: File Logging: '/Users/acetcom/Documents/git/open5gs/install/var/log/open5gs/mme.log' (../src/main.c:57) -10/27 15:46:23.682: [app] INFO: MME initialize...done (../src/mme/app-init.c:33) -10/27 15:46:23.682: [gtp] INFO: gtp_server() [192.168.0.3]:2123 (../lib/gtp/path.c:32) -10/27 15:46:23.683: [gtp] INFO: gtp_connect() [127.0.0.2]:2123 (../lib/gtp/path.c:57) -10/27 15:46:23.683: [mme] INFO: s1ap_server() [192.168.0.3]:36412 (../src/mme/s1ap-usrpath.c:46) +08/21 22:54:10.357: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/sgwu.yaml' (../src/main.c:54) +08/21 22:54:10.357: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/sgwu.log' (../src/main.c:57) +08/21 22:54:10.360: [pfcp] INFO: pfcp_server() [127.0.0.6]:8805 (../lib/pfcp/path.c:32) +08/21 22:54:10.360: [app] INFO: SGW-U initialize...done (../src/sgwu/app.c:31) +08/21 22:54:10.361: [gtp] INFO: gtp_server() [127.0.0.6]:2152 (../lib/gtp/path.c:32) + +$ ./install/bin/open5gs-upfd +Open5GS daemon v1.3.0-213-gd190548+ + +08/21 22:54:21.596: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/upf.yaml' (../src/main.c:54) +08/21 22:54:21.596: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/upf.log' (../src/main.c:57) +08/21 22:54:21.601: [pfcp] INFO: pfcp_server() [127.0.0.7]:8805 (../lib/pfcp/path.c:32) +08/21 22:54:21.601: [app] INFO: UPF initialize...done (../src/upf/app.c:31) +08/21 22:54:21.601: [gtp] INFO: gtp_server() [127.0.0.7]:2152 (../lib/gtp/path.c:32) +08/21 22:54:21.601: [gtp] INFO: gtp_server() [::1]:2152 (../lib/gtp/path.c:32) + +$ ./install/bin/open5gs-hssd +Open5GS daemon v1.3.0-213-gd190548+ + +08/21 22:57:17.450: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/hss.yaml' (../src/main.c:54) +08/21 22:57:17.450: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/hss.log' (../src/main.c:57) +08/21 22:57:17.451: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) +08/21 22:57:17.519: [app] INFO: HSS initialize...done (../src/hss/app-init.c:31) + +$ ./install/bin/open5gs-pcrfd +Open5GS daemon v1.3.0-213-gd190548+ + +08/21 22:57:45.894: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/pcrf.yaml' (../src/main.c:54) +08/21 22:57:45.894: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/pcrf.log' (../src/main.c:57) +08/21 22:57:45.896: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) +08/21 22:57:45.997: [app] INFO: PCRF initialize...done (../src/pcrf/app-init.c:31) + +$ ./install/bin/open5gs-nrfd +Open5GS daemon v1.3.0-213-gd190548+ + +08/21 22:56:35.472: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/nrf.yaml' (../src/main.c:54) +08/21 22:56:35.472: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/nrf.log' (../src/main.c:57) +08/21 22:56:35.472: [app] INFO: NRF initialize...done (../src/nrf/app.c:31) +08/21 22:56:35.473: [sbi] INFO: sbi_server() [127.0.0.10]:7777 (../lib/sbi/server.c:298) +08/21 22:56:35.473: [sbi] INFO: sbi_server() [::1]:7777 (../lib/sbi/server.c:298 + +$ ./install/bin/open5gs-ausfd +Open5GS daemon v1.3.0-213-gd190548+ + +08/21 22:55:41.899: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/ausf.yaml' (../src/main.c:54) +08/21 22:55:41.899: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/ausf.log' (../src/main.c:57) +08/21 22:55:41.900: [app] INFO: AUSF initialize...done (../src/ausf/app.c:31) +08/21 22:55:41.900: [sbi] INFO: sbi_server() [127.0.0.11]:7777 (../lib/sbi/server.c:298) + +$ ./install/bin/open5gs-udmd +Open5GS daemon v1.3.0-213-gd190548+ + +08/21 22:56:02.154: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/udm.yaml' (../src/main.c:54) +08/21 22:56:02.154: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/udm.log' (../src/main.c:57) +08/21 22:56:02.155: [app] INFO: UDM initialize...done (../src/udm/app.c:31) +08/21 22:56:02.155: [sbi] INFO: sbi_server() [127.0.0.12]:7777 (../lib/sbi/server.c:298) + +$ ./install/bin/open5gs-udrd +Open5GS daemon v1.3.0-213-gd190548+ + +08/21 22:56:15.810: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/udr.yaml' (../src/main.c:54) +08/21 22:56:15.810: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/udr.log' (../src/main.c:57) +08/21 22:56:15.813: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) +08/21 22:56:15.813: [app] INFO: UDR initialize...done (../src/udr/app.c:31) +08/21 22:56:15.813: [sbi] INFO: sbi_server() [127.0.0.13]:7777 (../lib/sbi/server.c:298) ``` Several command line options are provided. ```bash -$ ./open5gs-mmed -h -Usage: ./open5gs-mmed [options] +$ ./install/bin/open5gs-amfd -h +Usage: ./install/bin/open5gs-amfd [options] Options: -c filename : set configuration file -l filename : set logging file @@ -226,6 +366,18 @@ You can also copy the binaries to /usr/bin to be able to run them from anywhere $ cp open5gs* /usr/bin/ ``` +For convenience, you can execute all NFs at once by using the following command. +```bash +$ cd build +$ cat configs/sample.yaml ## check the configuration + +$ ./test/app/5gc ## 5G Core Only with sample.yaml +OR +$ ./test/app/epc -c ./config/srslte.yaml ## EPC Only with srslte.yaml +OR +$ ./test/app/app ## Both 5G Core and EPC with sample.yaml +``` + ### Building the WebUI of Open5GS --- @@ -327,38 +479,45 @@ Debugging tools can help you troubleshoot problems. - [GDB](https://www.gnu.org/software/gdb/) can be used as below: ```bash - $ gdb ./open5gs-mmed + $ gdb ./open5gs-amfd ``` - On *Mac OS X*, you can use the [LLDB](https://lldb.llvm.org/). ```bash - $ lldb ./open5gs-mmed + $ lldb ./open5gs-amfd ``` You can use the command line option[`-d`] to record more logs. ```bash -Open5GS daemon v1.0.0 +$ ./test/app/app -d +Open5GS daemon v1.3.0-213-gd190548+ + +08/21 23:01:54.246: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/sample.yaml' (../src/main.c:54) +08/21 23:01:54.246: [thread] DEBUG: [0x7f8de4d25018] worker signal (../lib/core/ogs-thread.c:66) +08/21 23:01:54.246: [thread] DEBUG: [0x7f8de4d25018] thread started (../lib/core/ogs-thread.c:101) +Open5GS daemon v1.3.0-213-gd190548+ + +08/21 23:01:54.254: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/sample.yaml' (../src/main.c:54) +08/21 23:01:54.254: [thread] DEBUG: [0x7ff8d13be818] worker signal (../lib/core/ogs-thread.c:66) +08/21 23:01:54.254: [nrf] DEBUG: nrf_state_initial(): INIT (../src/nrf/nrf-sm.c:25) +08/21 23:01:54.254: [nrf] DEBUG: nrf_state_operational(): ENTRY (../src/nrf/nrf-sm.c:50) +08/21 23:01:54.254: [thread] DEBUG: [0x7ff8d13be818] thread started (../lib/core/ogs-thread.c:101) +08/21 23:01:54.254: [app] INFO: NRF initialize...done (../src/nrf/app.c:31) +08/21 23:01:54.255: [sbi] INFO: sbi_server() [127.0.0.10]:7777 (../lib/sbi/server.c:298) +08/21 23:01:54.255: [sbi] INFO: sbi_server() [::1]:7777 (../lib/sbi/server.c:298) +08/21 23:01:54.296: [thread] DEBUG: [0x7f8de4d25098] worker signal (../lib/core/ogs-thread.c:66) +08/21 23:01:54.296: [thread] DEBUG: [0x7f8de4d25098] thread started (../lib/core/ogs-thread.c:101) +Open5GS daemon v1.3.0-213-gd190548+ + +08/21 23:01:54.315: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/sample.yaml' (../src/main.c:54) +08/21 23:01:54.319: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) +08/21 23:01:54.332: [app] INFO: PCRF initialize...done (../src/pcrf/app-init.c:31) +08/21 23:01:54.347: [thread] DEBUG: [0x7f8de4d25118] worker signal (../lib/core/ogs-thread.c:66) +08/21 23:01:54.347: [thread] DEBUG: [0x7f8de4d25118] thread started (../lib/core/ogs-thread.c:101) +Open5GS daemon v1.3.0-213-gd190548+ + +... -10/27 15:50:45.170: [app] INFO: Configuration: '/Users/acetcom/Documents/git/open5gs/install/etc/open5gs/mme.yaml' (../src/main.c:54) -10/27 15:50:45.171: [app] INFO: File Logging: '/Users/acetcom/Documents/git/open5gs/install/var/log/open5gs/mme.log' (../src/main.c:57) -10/27 15:50:45.171: [app] INFO: LOG-LEVEL: 'debug' (../src/main.c:60) -10/27 15:50:45.267: [thread] DEBUG: [0x10b52ed08] thread started (../lib/core/ogs-thread.c:101) -10/27 15:50:45.267: [thread] DEBUG: [0x10b52ed08] worker signal (../lib/core/ogs-thread.c:66) -10/27 15:50:45.268: [app] INFO: MME initialize...done (../src/mme/app-init.c:33) -10/27 15:50:45.268: [mme] DEBUG: mme_state_initial(): INIT - (../src/mme/mme-sm.c:38) -10/27 15:50:45.268: [mme] DEBUG: mme_state_operational(): ENTRY - (../src/mme/mme-sm.c:83) -10/27 15:50:45.269: [sock] DEBUG: socket create(2:2:17) (../lib/core/ogs-socket.c:92) -10/27 15:50:45.269: [sock] DEBUG: udp_socket() family:2 (../lib/core/ogs-udp.c:31) -10/27 15:50:45.269: [sock] DEBUG: socket bind 192.168.0.3:2123 (../lib/core/ogs-socket.c:117) -10/27 15:50:45.269: [sock] DEBUG: udp_server() [192.168.0.3]:2123 (../lib/core/ogs-udp.c:55) -10/27 15:50:45.269: [gtp] INFO: gtp_server() [192.168.0.3]:2123 (../lib/gtp/path.c:32) -10/27 15:50:45.269: [gtp] INFO: gtp_connect() [127.0.0.2]:2123 (../lib/gtp/path.c:57) -10/27 15:50:45.270: [sctp] DEBUG: Old INITMSG (numout:10 maxin:2048 maxattempt:8 maxinit_to:60000) (../lib/sctp/ogs-usrsctp.c:132) -10/27 15:50:45.271: [sctp] DEBUG: New INITMSG (numout:30 maxin:65535 maxattempt:4 maxinit_to:8000) (../lib/sctp/ogs-usrsctp.c:152) -10/27 15:50:45.271: [sctp] DEBUG: sctp_bind() [192.168.0.3]:36412 (../lib/sctp/ogs-usrsctp.c:261) -10/27 15:50:45.271: [mme] INFO: s1ap_server() [192.168.0.3]:36412 (../src/mme/s1ap-usrpath.c:46) ``` diff --git a/docs/_docs/guide/03-splitting-network-elements.md b/docs/_docs/guide/03-splitting-network-elements.md index b62bcacce..dd948c967 100644 --- a/docs/_docs/guide/03-splitting-network-elements.md +++ b/docs/_docs/guide/03-splitting-network-elements.md @@ -3,50 +3,47 @@ title: Open5GS Splitting Network Elements head_inline: "" --- -In a production network network elements would typically not all be on the same machine, as is the default example that ships with Open5GS. +In a production network, NFs would typically not all be on the same machine, as is the default example that ships with Open5GS. -Open5GS is designed to be standards compliant, so in theory you can connect any core network element (MME, PGW, SGW, PCRF, HSS) from Open5GS or any other vendor to form a functioning network, so long as they are 3GPP compliant. +Open5GS is designed to be standards compliant, so in theory you can connect any core network function from Open5GS or any other vendor to form a functioning network, so long as they are 3GPP compliant. To demonstrate this we will cover isolating each network element onto it's on machine and connect each network element to the other. For some interfaces specifying multiple interfaces is supported to allow connection to multiple -In these examples we'll be connecting Open5GS elements together, but it could just as easily be EPC elements from a different vendor in the place of any Open5GS network element. +In these examples we'll be connecting Open5GS NFs together, but it could just as easily be NFs from a different vendor in the place of any Open5GS network functions. | Service | IP | Identity | | ------------- |:-------------:|:-------------:| -| P-GW | 10.0.1.121 | pgw.localdomain | -| S-GW | 10.0.1.122 | | +| SMF | 10.0.1.121 | smf.localdomain | +| SGW-C | 10.0.1.122 | | | PCRF | 10.0.1.123 | pcrf.localdomain | | MME | 10.0.1.124 | mme.localdomain | | HSS | 10.0.1.118 | hss.localdomain | -# External P-GW -In it's simplest from the P-GW has 3 interfaces: - * S5 - Connection to home network S-GW (GTP-C) +# External SMF +In it's simplest from the SMF has 3 interfaces: + * S5 - Connection to home network SGW-C (GTP-C) * Gx - Connection to PCRF (Diameter) * Sgi - Connection to external network (Generally the Internet via standard TCP/IP) ### S5 Interface Configuration -Edit ```/etc/open5gs/pgw.yaml``` and change the address to IP of the server running the P-GW for the listener on GTP-C and GTP-U interfaces. +Edit ```/etc/open5gs/smf.yaml``` and change the address to IP of the server running the SMF for the listener on GTP-C interfaces. ``` -pgw: - freeDiameter: /etc/freeDiameter/pgw.conf +smf: + freeDiameter: /etc/freeDiameter/smf.conf gtpc: addr: - 10.0.1.121 - gtpu: - addr: - - 10.0.1.121 ``` ### Gx Interface Configuration -Edit ```/etc/freeDiameter/pgw.conf``` +Edit ```/etc/freeDiameter/smf.conf``` -Update ```ListenOn``` address to IP of the server running the P-GW: +Update ```ListenOn``` address to IP of the server running the SMF: ``` ListenOn = "10.0.1.121"; ``` @@ -56,38 +53,37 @@ Update ConnectPeer to connect to the PCRF on it's IP. ### Restart Services -Restart Open5GS PGW Daemon: +Restart Open5GS SMF Daemon: -``` $ sudo systemctl restart open5gs-pgwd ``` +``` $ sudo systemctl restart open5gs-smfd ``` -# External S-GW -In it's simplest form the S-GW has 2 interfaces: +# External SGW-C +In it's simplest form the SGW-C has 2 interfaces: * S11 - Connection to MME (GTP-C) - * S5 - Connection to the home network P-GW (GTP-C) + * S5 - Connection to the home network SMF (GTP-C) ### S5 Interface Configuration -Edit ```/etc/open5gs/sgw.yaml``` and change the address to IP of the server running the S-GW for the listener on GTP-C interface. +Edit ```/etc/open5gs/sgwc.yaml``` and change the address to IP of the server running the SGW-C for the listener on GTP-C interface. ``` -sgw: - freeDiameter: /etc/freeDiameter/pgw.conf +sgwc: gtpc: addr: - 10.0.1.122 ``` - Restart Open5GS SGW Daemon: + Restart Open5GS SGW-C Daemon: -``` $ sudo systemctl restart open5gs-sgwd ``` +``` $ sudo systemctl restart open5gs-sgwcd ``` # External PCRF In it's simplest from the PCRF has 1 network interface: - * Gx - Connection to P-GW (Diameter) + * Gx - Connection to SMF (Diameter) ### Gx Interface Configuration -Edit ```/etc/freeDiameter/hss.conf``` +Edit ```/etc/freeDiameter/pcrf.conf``` Update ```ListenOn``` address to IP of the server running the HSS on it's IP: @@ -95,10 +91,10 @@ Update ```ListenOn``` address to IP of the server running the HSS on it's IP: Update ConnectPeer to connect to the MME. -```ConnectPeer = "pgw.localdomain" { ConnectTo = "10.0.1.121"; No_TLS; };``` +```ConnectPeer = "smf.localdomain" { ConnectTo = "10.0.1.121"; No_TLS; };``` -### MongoDB Interface Configuration (Open5GS HSS only) -Edit ```/etc/freeDiameter/hss.conf``` and change the ```db_uri:``` to point at the HSS: ```db_uri: mongodb://10.0.1.118/open5gs``` +### MongoDB Interface Configuration +Edit the ```db_uri:``` to point at the Open5GS: ```db_uri: mongodb://10.0.1.118/open5gs``` Restart Open5GS PCRF Daemon: @@ -135,16 +131,16 @@ Restart MongoDB for changes to take effect. In it's simplest form the MME has 3 interfaces: * S1AP - Connections from eNodeBs * S6a - Connection to HSS (Diameter) - * S11 - Connection to S-GW (GTP-C) + * S11 - Connection to SGW-C (GTP-C) ### S11 Interface Configuration -Edit ```/etc/open5gs/mme.yaml``` and filling the IP address of the S-GW and P-GW servers. +Edit ```/etc/open5gs/mme.yaml``` and filling the IP address of the SGW-C and SMF servers. ``` -sgw: +sgwc: gtpc: addr: 10.0.1.122 -pgw: +smf: gtpc: addr: - 10.0.1.121 diff --git a/docs/_docs/new/02-installing-5g-core.md b/docs/_docs/new/02-installing-5g-core.md deleted file mode 100644 index 96739c713..000000000 --- a/docs/_docs/new/02-installing-5g-core.md +++ /dev/null @@ -1,426 +0,0 @@ ---- -title: Installing 5G Core from Sources -head_inline: "" ---- - -This post explains how to compile and install the source code on **Debian/Ubuntu** based Linux Distribution. -{: .blue} - -### Getting MongoDB ---- - -Install MongoDB with package manager. It is used as database for the UDR. - -```bash -$ sudo apt update -$ sudo apt install mongodb -$ sudo systemctl start mongodb (if '/usr/bin/mongod' is not running) -$ sudo systemctl enable mongodb (ensure to automatically start it on system boot) -``` - -### Setting up TUN device (not persistent after rebooting) ---- - -Create the TUN device with the interface name `ogstun`. - -```bash -$ sudo ip tuntap add name ogstun mode tun -$ sudo ip addr add 10.45.0.1/16 dev ogstun -$ sudo ip addr add cafe::1/64 dev ogstun -$ sudo ip link set ogstun up -``` - -**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/misc/netconf.sh) makes it easy to configure the TUN device as follows: -`$ sudo ./misc/netconf.sh` -{: .notice--info} - -### Building Open5GS ---- - -Install the dependencies for building the source code. - -```bash -$ sudo apt install python3-pip python3-setuptools python3-wheel ninja-build build-essential flex bison git libsctp-dev libgnutls28-dev libgcrypt-dev libssl-dev libidn11-dev libmongoc-dev libbson-dev libyaml-dev libmicrohttpd-dev libcurl4-gnutls-dev meson -``` - -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 -``` - -Check whether the compilation is correct in your environment. -```bash -$ cd build -$ ./tests/registration/registration -``` - -**Tip:** You can also check the result of `./test/registration/registration` with a tool that captures packets. If you are running `wireshark`, select the `any` interface and set FILTER to `ngap || http || pfcp || gtp`. -{: .notice--info} - -You need to perform the **installation process**. -```bash -$ cd build -$ ninja install -$ cd ../ -``` - -### Configure Open5GS ---- - -Modify [install/etc/open5gs/amf.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/amf.yaml.in) to set the NGAP IP address, PLMN ID, TAC and NSSAI. - -In the below example we - -- use MCC-MNC of 901-70, as this is the home network of the default IMSIs of the sysmoUSIM-SJS1 cards. -- use 192.168.0.100 for the NGAP connection of AMF to the gNB - -```diff -diff -u amf.yaml.old amf.yaml ---- amf.yaml.old 2020-06-21 23:34:14.643114779 -0400 -+++ amf.yaml 2020-06-21 23:34:28.718482095 -0400 -@@ -67,25 +67,25 @@ - - addr: 127.0.0.2 - port: 7777 - ngap: -+ - addr: 192.168.0.100 - guami: - - plmn_id: -- mcc: 001 -- mnc: 01 -+ mcc: 901 -+ mnc: 70 - amf_id: - region: 2 - set: 1 - tai: - - plmn_id: -- mcc: 001 -- mnc: 01 -- tac: 1 -+ mcc: 901 -+ mnc: 70 -+ tac: 7 - plmn: - - plmn_id: -- mcc: 001 -- mnc: 01 -+ mcc: 901 -+ mnc: 70 - s_nssai: - - sst: 1 -- - sd: 2 - security: - integrity_order : [ NIA1, NIA2, NIA0 ] - ciphering_order : [ NEA0, NEA1, NEA2 ] -``` - -Modify [install/etc/open5gs/upf.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/upf.yaml.in) to set the GTP-U IP address. -```diff -diff -u upf.yaml.old upf.yaml ---- upf.yaml.old 2020-06-21 23:35:54.378631781 -0400 -+++ upf.yaml 2020-06-21 23:36:02.978245251 -0400 -@@ -61,6 +61,7 @@ - pfcp: - - addr: 127.0.0.4 - gtpu: -+ - addr: 192.168.0.100 - pdn: -``` - -If you modify the config files while Open5GS daemons are running, please restart them - - -### Running Open5GS ---- - -Specify the absolute path to the sharead library as follows. - -```bash -$ echo $(cd $(dirname ./install/lib/x86_64-linux-gnu/) && pwd -P)/$(basename ./install/lib/x86_64-linux-gnu/) -/home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu -$ export LD_LIBRARY_PATH=/home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu -$ ldd ./install/bin/open5gs-amfd -... - libogsapp.so.1 => /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu/libogsapp.so.1 (0x00007f161ab51000) - libogscore.so.1 => /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu/libogscore.so.1 (0x00007f161a922000) - libogssctp.so.1 => /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu/libogssctp.so.1 (0x00007f161a71d000) - libogss1ap.so.1 => /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu/libogss1ap.so.1 (0x00007f161a519000) -... -``` - -If you want to set the shared library path permanently, you can use ldconfig. -```bash -$ sudo sh -c "echo /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu > /etc/ld.so.conf.d/open5gs.conf" -$ sudo ldconfig -``` - -Now let's get started. - -```bash -$ cd install/bin/ -$ ./install/bin/open5gs-nrfd -Open5GS daemon v1.3.0 - -06/21 23:37:46.749: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/nrf.yaml' (../src/main.c:54) -06/21 23:37:46.749: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/nrf.log' (../src/main.c:57) -06/21 23:37:46.749: [app] INFO: NRF initialize...done (../src/nrf/app.c:31) -06/21 23:37:46.749: [sbi] INFO: sbi_server() [127.0.0.1]:7777 (../lib/sbi/server.c:291) -06/21 23:37:46.749: [sbi] INFO: sbi_server() [::1]:7777 (../lib/sbi/server.c:291 - - -$ ./install/bin/open5gs-amfd -Open5GS daemon v1.3.0 - -06/21 23:38:15.834: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/amf.yaml' (../src/main.c:54) -06/21 23:38:15.834: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/amf.log' (../src/main.c:57) -06/21 23:38:15.876: [app] INFO: AMF initialize...done (../src/amf/app.c:33) -06/21 23:38:15.876: [sbi] INFO: sbi_server() [127.0.0.2]:7777 (../lib/sbi/server.c:291) -06/21 23:38:15.877: [amf] INFO: ngap_server() [192.168.0.11]:38412 (../src/amf/ngap-sctp.c:56) -06/21 23:38:15.877: [amf] INFO: ngap_server() [172.19.0.1]:38412 (../src/amf/ngap-sctp.c:56) -06/21 23:38:15.877: [amf] INFO: ngap_server() [172.17.0.1]:38412 (../src/amf/ngap-sctp.c:56) -06/21 23:38:15.877: [amf] INFO: ngap_server() [2601:144:4100:a220:ee:f149:8f28:9572]:38412 (../src/amf/ngap-sctp.c:56) -06/21 23:38:15.877: [amf] INFO: ngap_server() [2601:144:4100:a220:c643:4b3a:b0ee:c446]:38412 (../src/amf/ngap-sctp.c:56) -06/21 23:38:15.877: [amf] INFO: [ce785804-b439-41ea-9c93-399fce5a75a5] NF registered (../src/amf/nf-sm.c:209) - -$ ./install/bin/open5gs-smfd -Open5GS daemon v1.3.0 - -06/21 23:38:35.313: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/smf.yaml' (../src/main.c:54) -06/21 23:38:35.313: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/smf.log' (../src/main.c:57) -06/21 23:38:35.350: [gtp] INFO: gtp_server() [127.0.0.3]:2123 (../lib/gtp/path.c:32) -06/21 23:38:35.350: [gtp] INFO: gtp_server() [::1]:2123 (../lib/gtp/path.c:32) -06/21 23:38:35.350: [app] INFO: SMF initialize...done (../src/smf/app.c:31) -06/21 23:38:35.350: [pfcp] INFO: pfcp_server() [127.0.0.3]:8805 (../lib/pfcp/path.c:32) -06/21 23:38:35.350: [pfcp] INFO: pfcp_server() [::1]:8805 (../lib/pfcp/path.c:32) -06/21 23:38:35.350: [pfcp] INFO: ogs_pfcp_connect() [127.0.0.4]:8805 (../lib/pfcp/path.c:60) -06/21 23:38:35.351: [sbi] INFO: sbi_server() [127.0.0.3]:7777 (../lib/sbi/server.c:291) -06/21 23:38:35.352: [smf] INFO: [da15f3e2-b439-41ea-bd58-c3fe61467c94] NF registered (../src/smf/nf-sm.c:210) - -$ ./install/bin/open5gs-upfd -Open5GS daemon v1.3.0 - -06/21 23:38:52.832: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/upf.yaml' (../src/main.c:54) -06/21 23:38:52.832: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/upf.log' (../src/main.c:57) -06/21 23:38:52.844: [app] INFO: UPF initialize...done (../src/upf/app.c:31) -06/21 23:38:52.844: [pfcp] INFO: pfcp_server() [127.0.0.4]:8805 (../lib/pfcp/path.c:32) -06/21 23:38:52.844: [pfcp] INFO: ogs_pfcp_connect() [127.0.0.3]:8805 (../lib/pfcp/path.c:60) -06/21 23:38:52.846: [gtp] INFO: gtp_server() [192.168.0.11]:2152 (../lib/gtp/path.c:32) -06/21 23:38:52.846: [gtp] INFO: gtp_server() [172.19.0.1]:2152 (../lib/gtp/path.c:32) -06/21 23:38:52.846: [gtp] INFO: gtp_server() [172.17.0.1]:2152 (../lib/gtp/path.c:32) -06/21 23:38:52.846: [gtp] INFO: gtp_server() [2601:144:4100:a220:ee:f149:8f28:9572]:2152 (../lib/gtp/path.c:32) -06/21 23:38:52.846: [gtp] INFO: gtp_server() [2601:144:4100:a220:c643:4b3a:b0ee:c446]:2152 (../lib/gtp/path.c:32) -06/21 23:38:52.848: [upf] INFO: PFCP associated (../src/upf/pfcp-sm.c:171) -06/21 23:38:53.358: [upf] WARNING: PFCP[REQ] has already been associated (../src/upf/pfcp-sm.c:201) - -$ ./install/bin/open5gs-ausfd -Open5GS daemon v1.3.0 - -06/21 23:39:11.641: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/ausf.yaml' (../src/main.c:54) -06/21 23:39:11.641: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/ausf.log' (../src/main.c:57) -06/21 23:39:11.641: [app] INFO: AUSF initialize...done (../src/ausf/app.c:31) -06/21 23:39:11.642: [sbi] INFO: sbi_server() [127.0.0.5]:7777 (../lib/sbi/server.c:291) -06/21 23:39:11.643: [ausf] INFO: [efbbbe5c-b439-41ea-b95c-039d7a609671] NF registered (../src/ausf/nf-sm.c:209) - -$ ./install/bin/open5gs-udmd -Open5GS daemon v1.3.0 - -06/21 23:39:28.792: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/udm.yaml' (../src/main.c:54) -06/21 23:39:28.792: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/udm.log' (../src/main.c:57) -06/21 23:39:28.792: [app] INFO: UDM initialize...done (../src/udm/app.c:31) -06/21 23:39:28.793: [sbi] INFO: sbi_server() [127.0.0.6]:7777 (../lib/sbi/server.c:291) -06/21 23:39:29.390: [udm] INFO: [f9f4ce22-b439-41ea-bf29-c309f36c787f] NF registered (../src/udm/nf-sm.c:209) - -$ ./install/bin/open5gs-udrd -Open5GS daemon v1.3.0 - -06/21 23:39:41.763: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/udr.yaml' (../src/main.c:54) -06/21 23:39:41.763: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/udr.log' (../src/main.c:57) -06/21 23:39:41.765: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) -06/21 23:39:41.765: [app] INFO: UDR initialize...done (../src/udr/app.c:31) -06/21 23:39:41.765: [sbi] INFO: sbi_server() [127.0.0.7]:7777 (../lib/sbi/server.c:291) -06/21 23:39:41.767: [udr] INFO: [01b0191e-b43a-41ea-9abb-df3b42196e0a] NF registered (../src/udr/nf-sm.c:209) - -``` - -Several command line options are provided. - -```bash -$ ./install/bin/open5gs-amfd -h -Usage: ./install/bin/open5gs-amfd [options] -Options: - -c filename : set configuration file - -l filename : set logging file - -e level : set global log-level (default:info) - -m domain : set log-domain (e.g. mme:sgw:gtp) - -d : print lots of debugging information - -t : print tracing information for developer - -D : start as a daemon - -v : show version number and exit - -h : show this message and exit -``` - -You can also copy the binaries to /usr/bin to be able to run them from anywhere on the system. -```bash -$ cp open5gs* /usr/bin/ -``` - -For convenience, you can execute all NFs at once by using the following command. -```bash -$ cd build -$ vi configs/5gc.yaml ## check the configuration -$ ./test/app/5gc ## run all NFs -``` - -### Building the WebUI of Open5GS ---- - -[Node.js](https://nodejs.org/) is required to build WebUI of Open5GS - -```bash -$ sudo apt install curl -$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - -$ sudo apt install nodejs -``` - -Install the dependencies to run WebUI - -```bash -$ cd webui -$ npm install -``` - -The WebUI runs as an [npm](https://www.npmjs.com/) script. - -```bash -$ npm run dev -``` - -### Register Subscriber Information ---- - -Connect to `http://localhost:3000` and login with **admin** account. - -> Username : admin -> Password : 1423 - -**Note:** -You can change the password in _Account_ Menu. -{: .notice--info} - -To add subscriber information, you can do WebUI operations in the following order: - - 1. Go to `Subscriber` Menu. - 2. Click `+` Button to add a new subscriber. - 3. Fill the IMSI, security context(K, OPc, AMF), and APN of the subscriber. - 4. Click `SAVE` Button - -**Tip:** This addition immediately affects Open5GS without restarting any daemon. -{: .notice--warning} - -### IP routing + NAT for UE internet connectivity ---- - -To allow your phones to connect to the internet, you must run the following command on the host running Open5GS-PGW: - -```bash -### Check IP Table 'forward' -$ sudo iptables -L -Chain INPUT (policy ACCEPT) -target prot opt source destination - -Chain FORWARD (policy ACCEPT) -target prot opt source destination - -Chain OUTPUT (policy ACCEPT) -target prot opt source destination - -### Check IP Table 'nat' -$ sudo iptables -L -t nat -Chain PREROUTING (policy ACCEPT) -target prot opt source destination - -Chain INPUT (policy ACCEPT) -target prot opt source destination - -Chain OUTPUT (policy ACCEPT) -target prot opt source destination - -Chain POSTROUTING (policy ACCEPT) -target prot opt source destination - -### Enable IPv4 Forwarding -$ sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" - -### Add NAT Rule -$ sudo iptables -t nat -A POSTROUTING -s 10.45.0.0/16 ! -o ogstun -j MASQUERADE -``` - -**Note:** The above assumes you do not have any existing rules in the filter and nat tables. If a program such as docker has already set up rules, you may need to add the Open5GS related rules differently. -{: .notice--danger} - -### Turn on your gNB and Phone ---- - -- You can view the log at `$INSTALL_PREFIX/var/log/open5gs/*.log`. - -### Troubleshooting ---- - -If you run into any problems, please post the github issue. Providing packets using wireshark can help a lot. -{: .blue} - -To fix the problem yourself, debugging tools can help you troubleshoot problems. - -- [GDB](https://www.gnu.org/software/gdb/) can be used as below: - - ```bash - $ gdb ./open5gs-amfd - ``` - -- On *Mac OS X*, you can use the [LLDB](https://lldb.llvm.org/). - - ```bash - $ lldb ./open5gs-amfd - ``` - -You can use the command line option[`-d`] to record more logs. - -```bash -$ ./test/app/5gc -d -Open5GS daemon v1.3.0 - -06/21 23:44:54.500: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/5gc.yaml' (../src/main.c:54) -06/21 23:44:54.500: [thread] DEBUG: [0x7f3342a7d018] worker signal (../lib/core/ogs-thread.c:66) -06/21 23:44:54.500: [thread] DEBUG: [0x7f3342a7d018] thread started (../lib/core/ogs-thread.c:101) -Open5GS daemon v1.3.0 - -06/21 23:44:54.508: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/5gc.yaml' (../src/main.c:54) -06/21 23:44:54.508: [thread] DEBUG: [0x7f31d3620818] worker signal (../lib/core/ogs-thread.c:66) -06/21 23:44:54.508: [nrf] DEBUG: nrf_state_initial(): INIT (../src/nrf/nrf-sm.c:25) -06/21 23:44:54.508: [nrf] DEBUG: nrf_state_operational(): ENTRY (../src/nrf/nrf-sm.c:50) -06/21 23:44:54.508: [thread] DEBUG: [0x7f31d3620818] thread started (../lib/core/ogs-thread.c:101) -06/21 23:44:54.508: [app] INFO: NRF initialize...done (../src/nrf/app.c:31) -06/21 23:44:54.509: [sbi] INFO: sbi_server() [127.0.0.1]:7777 (../lib/sbi/server.c:291) -06/21 23:44:54.509: [sbi] INFO: sbi_server() [::1]:7777 (../lib/sbi/server.c:291) -06/21 23:44:54.551: [thread] DEBUG: [0x7f3342a7d098] worker signal (../lib/core/ogs-thread.c:66) -06/21 23:44:54.551: [thread] DEBUG: [0x7f3342a7d098] thread started (../lib/core/ogs-thread.c:101) -Open5GS daemon v1.3.0 - -06/21 23:44:54.575: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/5gc.yaml' (../src/main.c:54) -06/21 23:44:54.601: [thread] DEBUG: [0x7f3342a7d118] worker signal (../lib/core/ogs-thread.c:66) -06/21 23:44:54.601: [thread] DEBUG: [0x7f3342a7d118] thread started (../lib/core/ogs-thread.c:101) -Open5GS daemon v1.3.0 - -06/21 23:44:54.607: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/5gc.yaml' (../src/main.c:54) -06/21 23:44:54.608: [thread] DEBUG: [0x7f996e1b2918] worker signal (../lib/core/ogs-thread.c:66) -06/21 23:44:54.608: [ausf] DEBUG: ausf_state_initial(): INIT (../src/ausf/ausf-sm.c:25) -``` diff --git a/docs/_docs/new/03-moving-4g-epc-to-cups.md b/docs/_docs/new/03-moving-4g-epc-to-cups.md deleted file mode 100644 index d6182f3fb..000000000 --- a/docs/_docs/new/03-moving-4g-epc-to-cups.md +++ /dev/null @@ -1,407 +0,0 @@ ---- -title: Moving 4G EPC to the CUPS -head_inline: "" ---- - -This post explains how to compile and install the source code on **Debian/Ubuntu** based Linux Distribution. -{: .blue} - -### Getting MongoDB ---- - -Install MongoDB with package manager. It is used as database for the HSS and PCRF. - -```bash -$ sudo apt update -$ sudo apt install mongodb -$ sudo systemctl start mongodb (if '/usr/bin/mongod' is not running) -$ sudo systemctl enable mongodb (ensure to automatically start it on system boot) -``` - -### Setting up TUN device (not persistent after rebooting) ---- - -Create the TUN device with the interface name `ogstun`. - -```bash -$ sudo ip tuntap add name ogstun mode tun -$ sudo ip addr add 10.45.0.1/16 dev ogstun -$ sudo ip addr add cafe::1/64 dev ogstun -$ sudo ip link set ogstun up -``` - -**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/misc/netconf.sh) makes it easy to configure the TUN device as follows: -`$ sudo ./misc/netconf.sh` -{: .notice--info} - -### Building Open5GS ---- - -Install the dependencies for building the source code. - -```bash -$ sudo apt install python3-pip python3-setuptools python3-wheel ninja-build build-essential flex bison git libsctp-dev libgnutls28-dev libgcrypt-dev libssl-dev libidn11-dev libmongoc-dev libbson-dev libyaml-dev libmicrohttpd-dev libcurl4-gnutls-dev meson -``` - -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 -``` - -Check whether the compilation is correct. -```bash -$ meson test -``` - -**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 || diameter || pfcp || gtp`. You can see the virtually created packets. [[testcups.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testcups.pcapng) -{: .notice--info} - -You need to perform the **installation process**. -```bash -$ cd build -$ ninja install -$ cd ../ -``` - -### Configure Open5GS ---- - -Modify [install/etc/open5gs/mme.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/mme.yaml.in) to set the S1AP IP address, PLMN ID, and TAC. - -In the below example we - -- use MCC-MNC of 901-70, as this is the home network of the default IMSIs of the sysmoUSIM-SJS1 cards. -- use 192.168.0.100 for the S1AP/GTP-U connection of MME/SGW-U to the eNB - -```diff -diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml ---- mme.yaml.old 2018-04-15 18:28:31.000000000 +0900 -+++ mme.yaml 2018-04-15 19:53:10.000000000 +0900 -@@ -204,20 +204,20 @@ logger: - mme: - freeDiameter: @sysconfdir@/freeDiameter/mme.conf - s1ap: -- addr: 127.0.0.1 -+ addr: 192.168.0.100 - gtpc: - addr: 127.0.0.1 - gummei: - plmn_id: -- mcc: 001 -- mnc: 01 -+ mcc: 901 -+ mnc: 70 - mme_gid: 2 - mme_code: 1 - tai: - plmn_id: -- mcc: 001 -- mnc: 01 -- tac: 1 -+ mcc: 901 -+ mnc: 70 -+ tac: 7 - security: - integrity_order : [ EIA1, EIA2, EIA0 ] - ciphering_order : [ EEA0, EEA1, EEA2 ] - -``` - -Modify [install/etc/open5gs/sgwu.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/sgwu.yaml.in) to set the GTP-U IP address. -```diff -diff -u /etc/open5gs/sgwu.yaml.old /etc/open5gs/sgwu.yaml ---- sgwu.yaml.old 2018-04-15 18:30:25.000000000 +0900 -+++ sgwu.yaml 2018-04-15 18:30:30.000000000 +0900 -@@ -51,7 +51,7 @@ logger: - # - sgwu: - gtpu: -- addr: 127.0.0.7 -+ addr: 192.168.0.100 - pfcp: - addr: 127.0.0.7 -``` - -If you modify the config files while Open5GS daemons are running, please restart them - - -### Running Open5GS ---- - -Specify the absolute path to the sharead library as follows. - -```bash -$ echo $(cd $(dirname ./install/lib/x86_64-linux-gnu/) && pwd -P)/$(basename ./install/lib/x86_64-linux-gnu/) -/home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu -$ export LD_LIBRARY_PATH=/home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu -$ ldd ./install/bin/open5gs-mmed -... - libogsapp.so.1 => /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu/libogsapp.so.1 (0x00007f161ab51000) - libogscore.so.1 => /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu/libogscore.so.1 (0x00007f161a922000) - libogssctp.so.1 => /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu/libogssctp.so.1 (0x00007f161a71d000) - libogss1ap.so.1 => /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu/libogss1ap.so.1 (0x00007f161a519000) -... -``` - -If you want to set the shared library path permanently, you can use ldconfig. -```bash -$ sudo sh -c "echo /home/acetcom/Documents/git/open5gs/install/lib/x86_64-linux-gnu > /etc/ld.so.conf.d/open5gs.conf" -$ sudo ldconfig -``` - -Now let's get started. - -```bash -$ ./install/bin/open5gs-nrfd -Open5GS daemon v1.3.0-194-gc674984+ - -08/12 19:34:39.277: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/nrf.yaml' (../src/main.c:54) -08/12 19:34:39.277: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/nrf.log' (../src/main.c:57) -08/12 19:34:39.278: [app] INFO: NRF initialize...done (../src/nrf/app.c:31) -08/12 19:34:39.278: [sbi] INFO: sbi_server() [127.0.0.1]:7777 (../lib/sbi/server.c:298) -08/12 19:34:39.278: [sbi] INFO: sbi_server() [::1]:7777 (../lib/sbi/server.c:298 - -$ ./install/bin/open5gs-mmed -Open5GS daemon v1.3.0-194-gc674984+ - -08/12 19:35:00.505: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/mme.yaml' (../src/main.c:54) -08/12 19:35:00.506: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/mme.log' (../src/main.c:57) -08/12 19:35:00.560: [gtp] INFO: gtp_server() [127.0.0.1]:2123 (../lib/gtp/path.c:32) -08/12 19:35:00.560: [app] INFO: MME initialize...done (../src/mme/app-init.c:33) -08/12 19:35:00.560: [gtp] INFO: gtp_connect() [127.0.0.6]:2123 (../lib/gtp/path.c:59) -08/12 19:35:00.560: [mme] INFO: s1ap_server() [127.0.0.1]:36412 (../src/mme/s1ap-sctp.c:57) - -$ ./install/bin/open5gs-sgwcd -Open5GS daemon v1.3.0-194-gc674984+ - -08/12 19:35:15.866: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/sgwc.yaml' (../src/main.c:54) -08/12 19:35:15.866: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/sgwc.log' (../src/main.c:57) -08/12 19:35:15.872: [app] INFO: SGW-C initialize...done (../src/sgwc/app.c:31) -08/12 19:35:15.873: [gtp] INFO: gtp_server() [127.0.0.6]:2123 (../lib/gtp/path.c:32) -08/12 19:35:15.873: [pfcp] INFO: pfcp_server() [127.0.0.6]:8805 (../lib/pfcp/path.c:32) -08/12 19:35:15.873: [pfcp] INFO: ogs_pfcp_connect() [127.0.0.7]:8805 (../lib/pfcp/path.c:60) - -$ ./install/bin/open5gs-sgwud -Open5GS daemon v1.3.0-194-gc674984+ - -08/12 19:35:37.768: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/sgwu.yaml' (../src/main.c:54) -08/12 19:35:37.768: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/sgwc.log' (../src/main.c:57) -08/12 19:35:37.771: [pfcp] INFO: pfcp_server() [127.0.0.7]:8805 (../lib/pfcp/path.c:32) -08/12 19:35:37.771: [app] INFO: SGW-U initialize...done (../src/sgwu/app.c:31) -08/12 19:35:37.773: [gtp] INFO: gtp_server() [127.0.0.7]:2152 (../lib/gtp/path.c:32) - -$ ./install/bin/open5gs-smfd -Open5GS daemon v1.3.0-194-gc674984+ - -08/12 19:35:50.948: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/smf.yaml' (../src/main.c:54) -08/12 19:35:50.948: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/smf.log' (../src/main.c:57) -08/12 19:35:50.999: [gtp] INFO: gtp_server() [127.0.0.3]:2123 (../lib/gtp/path.c:32) -08/12 19:35:50.999: [app] INFO: SMF initialize...done (../src/smf/app.c:31) -08/12 19:35:50.999: [gtp] INFO: gtp_server() [::1]:2123 (../lib/gtp/path.c:32) -08/12 19:35:50.999: [pfcp] INFO: pfcp_server() [127.0.0.3]:8805 (../lib/pfcp/path.c:32) -08/12 19:35:50.999: [pfcp] INFO: pfcp_server() [::1]:8805 (../lib/pfcp/path.c:32) -08/12 19:35:50.999: [pfcp] INFO: ogs_pfcp_connect() [127.0.0.4]:8805 (../lib/pfcp/path.c:60) -08/12 19:35:50.999: [sbi] INFO: sbi_server() [127.0.0.3]:7777 (../lib/sbi/server.c:298) - -$ ./install/bin/open5gs-upfd -Open5GS daemon v1.3.0-194-gc674984+ - -08/12 19:36:03.980: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/upf.yaml' (../src/main.c:54) -08/12 19:36:03.981: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/upf.log' (../src/main.c:57) -08/12 19:36:03.984: [pfcp] INFO: pfcp_server() [127.0.0.4]:8805 (../lib/pfcp/path.c:32) -08/12 19:36:03.984: [app] INFO: UPF initialize...done (../src/upf/app.c:31) -08/12 19:36:03.984: [gtp] INFO: gtp_server() [127.0.0.4]:2152 (../lib/gtp/path.c:32) -08/12 19:36:03.984: [gtp] INFO: gtp_server() [::1]:2152 (../lib/gtp/path.c:32) - -$ ./install/bin/open5gs-hssd -Open5GS daemon v1.3.0-194-gc674984+ - -08/12 19:36:15.670: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/hss.yaml' (../src/main.c:54) -08/12 19:36:15.670: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/hss.log' (../src/main.c:57) -08/12 19:36:15.671: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) -08/12 19:36:15.693: [app] INFO: HSS initialize...done (../src/hss/app-init.c:31) - -$ ./install/bin/open5gs-pcrfd -Open5GS daemon v1.3.0-194-gc674984+ - -08/12 19:36:30.356: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/pcrf.yaml' (../src/main.c:54) -08/12 19:36:30.356: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/pcrf.log' (../src/main.c:57) -08/12 19:36:30.358: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) -08/12 19:36:30.387: [app] INFO: PCRF initialize...done (../src/pcrf/app-init.c:31) -``` - -Several command line options are provided. - -```bash -$ ./install/bin/open5gs-mmed -h -Usage: ./install/bin/open5gs-mmed [options] -Options: - -c filename : set configuration file - -l filename : set logging file - -e level : set global log-level (default:info) - -m domain : set log-domain (e.g. mme:sgw:gtp) - -d : print lots of debugging information - -t : print tracing information for developer - -D : start as a daemon - -v : show version number and exit - -h : show this message and exit -``` - -You can also copy the binaries to /usr/bin to be able to run them from anywhere on the system. -```bash -$ cp open5gs* /usr/bin/ -``` - -For convenience, you can execute all network elements at once by using the following command. -```bash -$ cd build -$ vi configs/app.yaml ## check the configuration -$ ./test/app/app ## run all network elements -``` - -### Building the WebUI of Open5GS ---- - -[Node.js](https://nodejs.org/) is required to build WebUI of Open5GS - -```bash -$ sudo apt install curl -$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - -$ sudo apt install nodejs -``` - -Install the dependencies to run WebUI - -```bash -$ cd webui -$ npm install -``` - -The WebUI runs as an [npm](https://www.npmjs.com/) script. - -```bash -$ npm run dev -``` - -### Register Subscriber Information ---- - -Connect to `http://localhost:3000` and login with **admin** account. - -> Username : admin -> Password : 1423 - -**Note:** -You can change the password in _Account_ Menu. -{: .notice--info} - -To add subscriber information, you can do WebUI operations in the following order: - - 1. Go to `Subscriber` Menu. - 2. Click `+` Button to add a new subscriber. - 3. Fill the IMSI, security context(K, OPc, AMF), and APN of the subscriber. - 4. Click `SAVE` Button - -**Tip:** This addition immediately affects Open5GS without restarting any daemon. -{: .notice--warning} - -### IP routing + NAT for UE internet connectivity ---- - -To allow your phones to connect to the internet, you must run the following command on the host running Open5GS-PGW: - -```bash -### Check IP Table 'forward' -$ sudo iptables -L -Chain INPUT (policy ACCEPT) -target prot opt source destination - -Chain FORWARD (policy ACCEPT) -target prot opt source destination - -Chain OUTPUT (policy ACCEPT) -target prot opt source destination - -### Check IP Table 'nat' -$ sudo iptables -L -t nat -Chain PREROUTING (policy ACCEPT) -target prot opt source destination - -Chain INPUT (policy ACCEPT) -target prot opt source destination - -Chain OUTPUT (policy ACCEPT) -target prot opt source destination - -Chain POSTROUTING (policy ACCEPT) -target prot opt source destination - -### Enable IPv4 Forwarding -$ sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" - -### Add NAT Rule -$ sudo iptables -t nat -A POSTROUTING -s 10.45.0.0/16 ! -o ogstun -j MASQUERADE -``` - -**Note:** The above assumes you do not have any existing rules in the filter and nat tables. If a program such as docker has already set up rules, you may need to add the Open5GS related rules differently. -{: .notice--danger} - -### Turn on your eNodeB and Phone ---- - -- You can see actual traffic through wireshark -- [[srsenb.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/srsenb.pcapng). -- You can view the log at `$INSTALL_PREFIX/var/log/open5gs/*.log`. - -### Troubleshooting ---- - -Debugging tools can help you troubleshoot problems. - -- [GDB](https://www.gnu.org/software/gdb/) can be used as below: - - ```bash - $ gdb ./open5gs-mmed - ``` - -- On *Mac OS X*, you can use the [LLDB](https://lldb.llvm.org/). - - ```bash - $ lldb ./open5gs-mmed - ``` - -You can use the command line option[`-d`] to record more logs. - -```bash -$ ./install/bin/open5gs-mmed -d -Open5GS daemon v1.3.0-194-gc674984+ - -08/12 19:38:40.968: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/mme.yaml' (../src/main.c:54) -08/12 19:38:40.968: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/mme.log' (../src/main.c:57) -08/12 19:38:40.968: [app] INFO: LOG-LEVEL: 'debug' (../src/main.c:60) -08/12 19:38:41.076: [thread] DEBUG: [0x7ff5d26adb18] worker signal (../lib/core/ogs-thread.c:66) -08/12 19:38:41.076: [mme] DEBUG: mme_state_initial(): INIT - (../src/mme/mme-sm.c:82) -08/12 19:38:41.076: [thread] DEBUG: [0x7ff5d26adb18] thread started (../lib/core/ogs-thread.c:101) -08/12 19:38:41.076: [mme] DEBUG: mme_state_operational(): ENTRY - (../src/mme/mme-sm.c:128) -08/12 19:38:41.076: [app] INFO: MME initialize...done (../src/mme/app-init.c:33) -08/12 19:38:41.076: [sock] DEBUG: socket create(2:2:17) (../lib/core/ogs-socket.c:92) -08/12 19:38:41.076: [sock] DEBUG: udp_socket() family:2 (../lib/core/ogs-udp.c:31) -08/12 19:38:41.076: [sock] DEBUG: socket bind 127.0.0.1:2123 (../lib/core/ogs-socket.c:117) -08/12 19:38:41.076: [sock] DEBUG: udp_server() [127.0.0.1]:2123 (../lib/core/ogs-udp.c:55) -08/12 19:38:41.076: [gtp] INFO: gtp_server() [127.0.0.1]:2123 (../lib/gtp/path.c:32) -08/12 19:38:41.076: [gtp] INFO: gtp_connect() [127.0.0.6]:2123 (../lib/gtp/path.c:59) -08/12 19:38:41.076: [sock] DEBUG: socket create(2:1:132) (../lib/core/ogs-socket.c:92) -08/12 19:38:41.076: [sock] DEBUG: socket bind 127.0.0.1:36412 (../lib/core/ogs-socket.c:117) -08/12 19:38:41.076: [sock] DEBUG: sctp_server() [127.0.0.1]:36412 (../lib/sctp/ogs-lksctp.c:100) -08/12 19:38:41.076: [mme] INFO: s1ap_server() [127.0.0.1]:36412 (../src/mme/s1ap-sctp.c:57) -``` diff --git a/docs/_docs/troubleshoot/02-now-in-github-issues.md b/docs/_docs/troubleshoot/02-now-in-github-issues.md index e4b5fc592..0dfaaea79 100644 --- a/docs/_docs/troubleshoot/02-now-in-github-issues.md +++ b/docs/_docs/troubleshoot/02-now-in-github-issues.md @@ -107,11 +107,18 @@ switched to db open5gs Kill all processes. ```bash $ ps -ef | grep open5gs +$ sudo pkill -9 open5gs-mmed +$ sudo pkill -9 open5gs-sgwcd +$ sudo pkill -9 open5gs-smfd +$ sudo pkill -9 open5gs-amfd +$ sudo pkill -9 open5gs-sgwud +$ sudo pkill -9 open5gs-upfd $ sudo pkill -9 open5gs-hssd $ sudo pkill -9 open5gs-pcrfd -$ sudo pkill -9 open5gs-pgwd -$ sudo pkill -9 open5gs-sgwd -$ sudo pkill -9 open5gs-mmed +$ sudo pkill -9 open5gs-nrfd +$ sudo pkill -9 open5gs-ausfd +$ sudo pkill -9 open5gs-udmd +$ sudo pkill -9 open5gs-udrd ``` Run `meson test` again @@ -385,9 +392,9 @@ You can start MongoDB using systemctl. $ sudo systemctl start mongodb ``` -#### I have some error when running `./build/test/epc/simple` +#### I have some error when running `./build/test/attach/attach` -Did you see the following error after executing `./build/test/epc/simple`? +Did you see the following error after executing `./build/test/attach/attach`? ```bash $ ./build/test/epc/simple s1setup_test : SUCCESS @@ -420,18 +427,18 @@ Execute `./build/test/epc/simple` $ ./build/test/epc/simple ``` -#### My eNB does not support IPv6. +#### My gNB/eNB does not support IPv6. Your eNodeB don't have to support IPv6. -If the sgw.gtpu configuration does not have an IPv6 address, the eNodeB can use IPv4 to connect to the MME and SGW. If the sgw.gtpu setting has an IPv6 address, you can disable the IPv6 address as shown below. +If the sgwu.gtpu configuration does not have an IPv6 address, the gNB/eNB can use IPv4 to connect to the MME and SGW-U. If the sgwu.gtpu setting has an IPv6 address, you can disable the IPv6 address as shown below. ```yaml parameter: no_ipv6: true ``` -**Note:** This parameter `no_ipv6` is only applied to EPC Elements such as MME, SGW, and so on. The parameter `no_ipv6` does not affect to UE. So, IPv6-enabled UE can connect to Open5GS LTE network. +**Note:** This parameter `no_ipv6` is only applied to NFs such as AMF, MME, SGW-C, and so on. The parameter `no_ipv6` does not affect to UE. So, IPv6-enabled UE can connect to Open5GS LTE network. {: .notice--warning} #### Unable to add new user by WebUI @@ -470,45 +477,55 @@ Currently, the number of UE is limited to `128*128`. - Network ``` -* MME - S1AP: listen on all address avaiable in system - GTP-C: listen on the first IP address in system - DIAMETER: 127.0.0.2 (No TLS) +* MongoDB : 127.0.0.1 +* MME : 127.0.0.2 +* SGW-C : 127.0.0.3 +* SMF : 127.0.0.4 +* AMF : 127.0.0.5 +* SGW-U : 127.0.0.6 +* UPF : 127.0.0.7 +* HSS : 127.0.0.8 +* PCRF : 127.0.0.9 +* NRF : 127.0.0.10 +* AUSF : 127.0.0.11 +* UDM : 127.0.0.12 +* UDR : 127.0.0.13 +``` -* SGW - GTP-C: 127.0.0.2 - GTP-U: listen on the first IP address in system +- AMF_ID, TAC and S_NSSAI -* PGW - GTP-C: Both 127.0.0.3 and [::1] - GTP-U: Both 127.0.0.3 and [::1] - DIAMETER: 127.0.0.3 (No TLS) +``` +* AMF_ID + PLMN ID - MNC: 901, MCC: 70 + Region : 2 + Set : 1 -* HSS - DIAMETER: 127.0.0.4 (No TLS) +* TAI + PLMN ID - MNC: 901, MCC: 70 + TAC : 1 -* PCRF - DIAMETER: 127.0.0.5 (No TLS) +* S_NSSASI + SST : 1 ``` - GUMMEI, PLMN and TAC ``` * GUMMEI - PLMN ID - MNC: 001, MCC: 01 + PLMN ID - MNC: 901, MCC: 70 MME Group : 2 MME Code : 1 * TAI - PLMN ID - MNC: 001, MCC: 01 - TAC : 12345 + PLMN ID - MNC: 901, MCC: 70 + TAC : 1 ``` - Security ``` -* Integrity : EIA1 - Snow 3G -* Ciphering : EEA0 - Nothing +* Integrity : NIA1/EIA1 - Snow 3G +* Ciphering : NEA0/EEA0 - Nothing ``` - UE Network @@ -547,7 +564,7 @@ By default, Open5GS is designed to support the Embedding System. To do so, we in - We'll use Debian Docker Environment. ```bash -$ git clone https://github.com/acetcom/open5gs +$ git clone https://github.com/open5gs/open5gs $ cd open5gs/docker $ DIST=debian TAG=stretch docker-compose run dev ``` diff --git a/docs/_docs/tutorial/01-your-first-lte.md b/docs/_docs/tutorial/01-your-first-lte.md index 927d91c57..96bc9e856 100644 --- a/docs/_docs/tutorial/01-your-first-lte.md +++ b/docs/_docs/tutorial/01-your-first-lte.md @@ -222,68 +222,73 @@ Then proceed as follows: 3. Fill the IMSI, security context(K, OPc, AMF), and APN of the subscriber. 4. Click `SAVE` Button -Modify [/etc/open5gs/mme.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/mme.yaml.in) to set the S1AP/GTP-C IP address, PLMN ID, and TAC +Modify [/etc/open5gs/mme.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/mme.yaml.in) to set the S1AP IP address, PLMN ID, and TAC ```diff -diff -u mme.yaml.old mme.yaml +diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml --- mme.yaml.old 2018-04-15 18:28:31.000000000 +0900 +++ mme.yaml 2018-04-15 19:53:10.000000000 +0900 -@@ -14,18 +14,20 @@ +@@ -204,20 +204,20 @@ logger: mme: - freeDiameter: mme.conf + freeDiameter: @sysconfdir@/freeDiameter/mme.conf s1ap: +- addr: 127.0.0.2 + addr: 127.0.1.100 gtpc: -+ addr: 127.0.1.100 - gummei: + addr: 127.0.0.2 + gummei: plmn_id: -- mcc: 001 -- mnc: 01 +- mcc: 901 +- mnc: 70 + mcc: 310 + mnc: 789 mme_gid: 2 mme_code: 1 tai: plmn_id: -- mcc: 001 -- mnc: 01 -- tac: 12345 +- mcc: 901 +- mnc: 70 +- tac: 1 + mcc: 310 + mnc: 789 + tac: 7 security: integrity_order : [ EIA1, EIA2, EIA0 ] ciphering_order : [ EEA0, EEA1, EEA2 ] + ``` S1AP/GTP-C IP address, PLMN ID, TAC are changed as follows. ``` S1AP address : 127.0.1.100 - srsENB default value -GTP-C address : 127.0.1.100 - Use loopback interface PLMN ID : MNC(310), MCC(789) - Programmed USIM with a card reader TAC : 7 - srsENB default value ``` -The GTP-U IP address will be set to 127.0.0.2. To do this, modify [/etc/open5gs/sgw.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/sgw.yaml.in) to set the GTP-U IP address. +The GTP-U IP address will be set to 127.0.0.6. To do this, modify [/etc/open5gs/sgwu.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/sgwu.yaml.in) to set the GTP-U IP address. ```diff -diff -u /etc/open5gs/sgw.yaml.old /etc/open5gs/sgw.yaml ---- sgw.yaml.old 2018-04-15 18:30:25.000000000 +0900 -+++ sgw.yaml 2018-04-15 18:30:30.000000000 +0900 -@@ -14,3 +14,4 @@ - gtpc: - addr: 127.0.0.2 +diff -u /etc/open5gs/sgwu.yaml.old /etc/open5gs/sgwu.yaml +--- sgwu.yaml.old 2018-04-15 18:30:25.000000000 +0900 ++++ sgwu.yaml 2018-04-15 18:30:30.000000000 +0900 +@@ -51,7 +51,7 @@ logger: + # + sgwu: gtpu: -+ addr: 127.0.0.2 +- addr: 10.11.0.6 ++ addr: 127.0.0.6 + pfcp: + addr: 127.0.0.6 ``` + After changing conf files, please restart Open5GS daemons. ```bash $ sudo systemctl restart open5gs-mmed -$ sudo systemctl restart open5gs-sgwd +$ sudo systemctl restart open5gs-sgwud ``` If your phone can connect to internet, you must run the following command in Open5GS-PGW installed host. diff --git a/docs/_docs/tutorial/02-VoLTE-setup.md b/docs/_docs/tutorial/02-VoLTE-setup.md index 3f40b63e5..8c1dee59e 100644 --- a/docs/_docs/tutorial/02-VoLTE-setup.md +++ b/docs/_docs/tutorial/02-VoLTE-setup.md @@ -1204,7 +1204,7 @@ Assuming IMSI of the user1 as 001010123456791 and MSISDN is 0198765432100 and IM Debug using wireshark at Open5GS machine and following wireshark display filter ``` -s1ap || gtpv2 || diameter || diameter.3gpp || sip +s1ap || gtpv2 || pfcp || diameter || diameter.3gpp || sip ``` Also, diff --git a/docs/_pages/docs.md b/docs/_pages/docs.md index cc2992c1c..d62d58cbd 100644 --- a/docs/_pages/docs.md +++ b/docs/_pages/docs.md @@ -5,10 +5,6 @@ permalink: /docs/ head_inline: "" --- -- What's New? - - [Installing 5G Core](new/02-installing-5g-core) - - [Moving 4G EPC to the CUPS](new/03-moving-4g-epc-to-cups) - - User's Guide - [Quickstart](guide/01-quickstart) - [Building Open5GS from Sources](guide/02-building-open5gs-from-sources) diff --git a/docs/assets/webui/install b/docs/assets/webui/install index 13e1c3cd2..b44686ca8 100644 --- a/docs/assets/webui/install +++ b/docs/assets/webui/install @@ -10,7 +10,7 @@ # PACKAGE="open5gs" -VERSION="1.3.0" +VERSION="2.0.0" print_status() { echo diff --git a/lib/core/ogs-log.c b/lib/core/ogs-log.c index a89baa869..5baf385fb 100644 --- a/lib/core/ogs-log.c +++ b/lib/core/ogs-log.c @@ -390,7 +390,10 @@ void ogs_log_vprintf(ogs_log_level_e level, int id, ogs_list_for_each(&log_list, log) { domain = ogs_pool_find(&domain_pool, id); - ogs_assert(domain); + if (!domain) { + fprintf(stderr, "No LogDomain[id:%d] in %s:%d", id, file, line); + ogs_assert_if_reached(); + } if (domain->level < level) return; diff --git a/lib/crypt/ogs-kdf.c b/lib/crypt/ogs-kdf.c index bbbcfeead..b741908cc 100644 --- a/lib/crypt/ogs-kdf.c +++ b/lib/crypt/ogs-kdf.c @@ -30,6 +30,7 @@ #define FC_FOR_KGNB_KN3IWF_DERIVATION 0x6E #define FC_FOR_NH_GNB_DERIVATION 0x6F +#define FC_FOR_KASME 0x10 #define FC_FOR_KENB_DERIVATION 0x11 #define FC_FOR_NH_ENB_DERIVATION 0x12 #define FC_FOR_EPS_ALGORITHM_KEY_DERIVATION 0x15 @@ -261,6 +262,39 @@ void ogs_kdf_nh_gnb(uint8_t *kamf, uint8_t *sync_input, uint8_t *kgnb) FC_FOR_NH_GNB_DERIVATION, param, kgnb); } +/* TS33.401 Annex A.2 KASME derivation function */ +void ogs_auc_kasme(const uint8_t *ck, const uint8_t *ik, + const uint8_t *plmn_id, const uint8_t *sqn, const uint8_t *ak, + uint8_t *kasme) +{ + kdf_param_t param; + int i; + + uint8_t key[OGS_KEY_LEN*2]; + uint8_t sqn_xor_ak[OGS_SQN_XOR_AK_LEN]; + + ogs_assert(ck); + ogs_assert(ik); + ogs_assert(plmn_id); + ogs_assert(sqn); + ogs_assert(ak); + + memcpy(key, ck, OGS_KEY_LEN); + memcpy(key + OGS_KEY_LEN, ik, OGS_KEY_LEN); + + memset(param, 0, sizeof(param)); + param[0].buf = (uint8_t *)plmn_id; + param[0].len = OGS_PLMN_ID_LEN; + + for (i = 0; i < 6; i++) + sqn_xor_ak[i] = sqn[i] ^ ak[i]; + + param[1].buf = sqn_xor_ak; + param[1].len = OGS_SQN_XOR_AK_LEN; + + ogs_kdf_common(key, OGS_SHA256_DIGEST_SIZE, FC_FOR_KASME, param, kasme); +} + /* TS33.401 Annex A.3 KeNB derivation function */ void ogs_kdf_kenb(uint8_t *kasme, uint32_t ul_count, uint8_t *kenb) { diff --git a/lib/crypt/ogs-kdf.h b/lib/crypt/ogs-kdf.h index 8b6f6e344..c6ed7b5c9 100644 --- a/lib/crypt/ogs-kdf.h +++ b/lib/crypt/ogs-kdf.h @@ -77,6 +77,11 @@ void ogs_kdf_kgnb_and_kn3iwf(uint8_t *kamf, uint32_t ul_count, /* TS33.501 Annex A.10 NH derivation function */ void ogs_kdf_nh_gnb(uint8_t *kamf, uint8_t *sync_input, uint8_t *kgnb); +/* TS33.401 Annex A.2 KASME derivation function */ +void ogs_auc_kasme(const uint8_t *ck, const uint8_t *ik, + const uint8_t *plmn_id, const uint8_t *sqn, const uint8_t *ak, + uint8_t *kasme); + /* TS33.401 Annex A.3 KeNB derivation function */ void ogs_kdf_kenb(uint8_t *kasme, uint32_t ul_count, uint8_t *kenb); diff --git a/lib/nas/eps/decoder.c b/lib/nas/eps/decoder.c index bcf4f8461..2453847c3 100644 --- a/lib/nas/eps/decoder.c +++ b/lib/nas/eps/decoder.c @@ -28,7 +28,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2020-06-30 16:47:16.506642 by acetcom + * Created on: 2020-08-16 17:47:29.429097 by acetcom * from 24301-g40.docx ******************************************************************************/ @@ -153,6 +153,8 @@ int ogs_nas_eps_decode_attach_request(ogs_nas_eps_message_t *message, ogs_pkbuf_ decoded += size; break; case OGS_NAS_EPS_ATTACH_REQUEST_TMSI_STATUS_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_tmsi_status(&attach_request->tmsi_status, pkbuf); ogs_assert(size >= 0); attach_request->presencemask |= OGS_NAS_EPS_ATTACH_REQUEST_TMSI_STATUS_PRESENT; @@ -177,6 +179,8 @@ int ogs_nas_eps_decode_attach_request(ogs_nas_eps_message_t *message, ogs_pkbuf_ decoded += size; break; case OGS_NAS_EPS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_additional_update_type(&attach_request->additional_update_type, pkbuf); ogs_assert(size >= 0); attach_request->presencemask |= OGS_NAS_EPS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_PRESENT; @@ -189,18 +193,24 @@ int ogs_nas_eps_decode_attach_request(ogs_nas_eps_message_t *message, ogs_pkbuf_ decoded += size; break; case OGS_NAS_EPS_ATTACH_REQUEST_DEVICE_PROPERTIES_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_device_properties(&attach_request->device_properties, pkbuf); ogs_assert(size >= 0); attach_request->presencemask |= OGS_NAS_EPS_ATTACH_REQUEST_DEVICE_PROPERTIES_PRESENT; decoded += size; break; case OGS_NAS_EPS_ATTACH_REQUEST_OLD_GUTI_TYPE_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_guti_type(&attach_request->old_guti_type, pkbuf); ogs_assert(size >= 0); attach_request->presencemask |= OGS_NAS_EPS_ATTACH_REQUEST_OLD_GUTI_TYPE_PRESENT; decoded += size; break; case OGS_NAS_EPS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_ms_network_feature_support(&attach_request->ms_network_feature_support, pkbuf); ogs_assert(size >= 0); attach_request->presencemask |= OGS_NAS_EPS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_PRESENT; @@ -351,6 +361,8 @@ int ogs_nas_eps_decode_attach_accept(ogs_nas_eps_message_t *message, ogs_pkbuf_t decoded += size; break; case OGS_NAS_EPS_ATTACH_ACCEPT_ADDITIONAL_UPDATE_RESULT_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_additional_update_result(&attach_accept->additional_update_result, pkbuf); ogs_assert(size >= 0); attach_accept->presencemask |= OGS_NAS_EPS_ATTACH_ACCEPT_ADDITIONAL_UPDATE_RESULT_PRESENT; @@ -381,12 +393,16 @@ int ogs_nas_eps_decode_attach_accept(ogs_nas_eps_message_t *message, ogs_pkbuf_t decoded += size; break; case OGS_NAS_EPS_ATTACH_ACCEPT_SMS_SERVICES_STATUS_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_sms_services_status(&attach_accept->sms_services_status, pkbuf); ogs_assert(size >= 0); attach_accept->presencemask |= OGS_NAS_EPS_ATTACH_ACCEPT_SMS_SERVICES_STATUS_PRESENT; decoded += size; break; case OGS_NAS_EPS_ATTACH_ACCEPT_NON__NW_PROVIDED_POLICIES_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_non__nw_provided_policies(&attach_accept->non__nw_provided_policies, pkbuf); ogs_assert(size >= 0); attach_accept->presencemask |= OGS_NAS_EPS_ATTACH_ACCEPT_NON__NW_PROVIDED_POLICIES_PRESENT; @@ -399,6 +415,8 @@ int ogs_nas_eps_decode_attach_accept(ogs_nas_eps_message_t *message, ogs_pkbuf_t decoded += size; break; case OGS_NAS_EPS_ATTACH_ACCEPT_NETWORK_POLICY_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_network_policy(&attach_accept->network_policy, pkbuf); ogs_assert(size >= 0); attach_accept->presencemask |= OGS_NAS_EPS_ATTACH_ACCEPT_NETWORK_POLICY_PRESENT; @@ -429,6 +447,8 @@ int ogs_nas_eps_decode_attach_accept(ogs_nas_eps_message_t *message, ogs_pkbuf_t decoded += size; break; case OGS_NAS_EPS_ATTACH_ACCEPT_UE_RADIO_CAPABILITY_ID_DELETION_INDICATION_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_ue_radio_capability_id_deletion_indication(&attach_accept->ue_radio_capability_id_deletion_indication, pkbuf); ogs_assert(size >= 0); attach_accept->presencemask |= OGS_NAS_EPS_ATTACH_ACCEPT_UE_RADIO_CAPABILITY_ID_DELETION_INDICATION_PRESENT; @@ -498,6 +518,8 @@ int ogs_nas_eps_decode_attach_reject(ogs_nas_eps_message_t *message, ogs_pkbuf_t decoded += size; break; case OGS_NAS_EPS_ATTACH_REJECT_EXTENDED_EMM_CAUSE_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_extended_emm_cause(&attach_reject->extended_emm_cause, pkbuf); ogs_assert(size >= 0); attach_reject->presencemask |= OGS_NAS_EPS_ATTACH_REJECT_EXTENDED_EMM_CAUSE_PRESENT; @@ -593,12 +615,16 @@ int ogs_nas_eps_decode_tracking_area_update_request(ogs_nas_eps_message_t *messa switch (type) { case OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_NON_CURRENT_NATIVE_NAS_KEY_SET_IDENTIFIER_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_key_set_identifier(&tracking_area_update_request->non_current_native_nas_key_set_identifier, pkbuf); ogs_assert(size >= 0); tracking_area_update_request->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_NON_CURRENT_NATIVE_NAS_KEY_SET_IDENTIFIER_PRESENT; decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_GPRS_CIPHERING_KEY_SEQUENCE_NUMBER_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_ciphering_key_sequence_number(&tracking_area_update_request->gprs_ciphering_key_sequence_number, pkbuf); ogs_assert(size >= 0); tracking_area_update_request->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_GPRS_CIPHERING_KEY_SEQUENCE_NUMBER_PRESENT; @@ -641,6 +667,8 @@ int ogs_nas_eps_decode_tracking_area_update_request(ogs_nas_eps_message_t *messa decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_UE_RADIO_CAPABILITY_INFORMATION_UPDATE_NEEDED_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_ue_radio_capability_information_update_needed(&tracking_area_update_request->ue_radio_capability_information_update_needed, pkbuf); ogs_assert(size >= 0); tracking_area_update_request->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_UE_RADIO_CAPABILITY_INFORMATION_UPDATE_NEEDED_PRESENT; @@ -665,6 +693,8 @@ int ogs_nas_eps_decode_tracking_area_update_request(ogs_nas_eps_message_t *messa decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_TMSI_STATUS_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_tmsi_status(&tracking_area_update_request->tmsi_status, pkbuf); ogs_assert(size >= 0); tracking_area_update_request->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_TMSI_STATUS_PRESENT; @@ -689,6 +719,8 @@ int ogs_nas_eps_decode_tracking_area_update_request(ogs_nas_eps_message_t *messa decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_ADDITIONAL_UPDATE_TYPE_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_additional_update_type(&tracking_area_update_request->additional_update_type, pkbuf); ogs_assert(size >= 0); tracking_area_update_request->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_ADDITIONAL_UPDATE_TYPE_PRESENT; @@ -701,18 +733,24 @@ int ogs_nas_eps_decode_tracking_area_update_request(ogs_nas_eps_message_t *messa decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_OLD_GUTI_TYPE_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_guti_type(&tracking_area_update_request->old_guti_type, pkbuf); ogs_assert(size >= 0); tracking_area_update_request->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_OLD_GUTI_TYPE_PRESENT; decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_DEVICE_PROPERTIES_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_device_properties(&tracking_area_update_request->device_properties, pkbuf); ogs_assert(size >= 0); tracking_area_update_request->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_DEVICE_PROPERTIES_PRESENT; decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_MS_NETWORK_FEATURE_SUPPORT_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_ms_network_feature_support(&tracking_area_update_request->ms_network_feature_support, pkbuf); ogs_assert(size >= 0); tracking_area_update_request->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_MS_NETWORK_FEATURE_SUPPORT_PRESENT; @@ -869,6 +907,8 @@ int ogs_nas_eps_decode_tracking_area_update_accept(ogs_nas_eps_message_t *messag decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_ACCEPT_ADDITIONAL_UPDATE_RESULT_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_additional_update_result(&tracking_area_update_accept->additional_update_result, pkbuf); ogs_assert(size >= 0); tracking_area_update_accept->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_ACCEPT_ADDITIONAL_UPDATE_RESULT_PRESENT; @@ -905,12 +945,16 @@ int ogs_nas_eps_decode_tracking_area_update_accept(ogs_nas_eps_message_t *messag decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_ACCEPT_SMS_SERVICES_STATUS_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_sms_services_status(&tracking_area_update_accept->sms_services_status, pkbuf); ogs_assert(size >= 0); tracking_area_update_accept->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_ACCEPT_SMS_SERVICES_STATUS_PRESENT; decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_ACCEPT_NON__NW_POLICIES_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_non__nw_provided_policies(&tracking_area_update_accept->non__nw_policies, pkbuf); ogs_assert(size >= 0); tracking_area_update_accept->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_ACCEPT_NON__NW_POLICIES_PRESENT; @@ -923,6 +967,8 @@ int ogs_nas_eps_decode_tracking_area_update_accept(ogs_nas_eps_message_t *messag decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_ACCEPT_NETWORK_POLICY_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_network_policy(&tracking_area_update_accept->network_policy, pkbuf); ogs_assert(size >= 0); tracking_area_update_accept->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_ACCEPT_NETWORK_POLICY_PRESENT; @@ -953,6 +999,8 @@ int ogs_nas_eps_decode_tracking_area_update_accept(ogs_nas_eps_message_t *messag decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_ACCEPT_UE_RADIO_CAPABILITY_ID_DELETION_INDICATION_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_ue_radio_capability_id_deletion_indication(&tracking_area_update_accept->ue_radio_capability_id_deletion_indication, pkbuf); ogs_assert(size >= 0); tracking_area_update_accept->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_ACCEPT_UE_RADIO_CAPABILITY_ID_DELETION_INDICATION_PRESENT; @@ -995,6 +1043,8 @@ int ogs_nas_eps_decode_tracking_area_update_reject(ogs_nas_eps_message_t *messag decoded += size; break; case OGS_NAS_EPS_TRACKING_AREA_UPDATE_REJECT_EXTENDED_EMM_CAUSE_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_extended_emm_cause(&tracking_area_update_reject->extended_emm_cause, pkbuf); ogs_assert(size >= 0); tracking_area_update_reject->presencemask |= OGS_NAS_EPS_TRACKING_AREA_UPDATE_REJECT_EXTENDED_EMM_CAUSE_PRESENT; @@ -1035,6 +1085,8 @@ int ogs_nas_eps_decode_extended_service_request(ogs_nas_eps_message_t *message, switch (type) { case OGS_NAS_EPS_EXTENDED_SERVICE_REQUEST_CSFB_RESPONSE_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_csfb_response(&extended_service_request->csfb_response, pkbuf); ogs_assert(size >= 0); extended_service_request->presencemask |= OGS_NAS_EPS_EXTENDED_SERVICE_REQUEST_CSFB_RESPONSE_PRESENT; @@ -1047,6 +1099,8 @@ int ogs_nas_eps_decode_extended_service_request(ogs_nas_eps_message_t *message, decoded += size; break; case OGS_NAS_EPS_EXTENDED_SERVICE_REQUEST_DEVICE_PROPERTIES_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_device_properties(&extended_service_request->device_properties, pkbuf); ogs_assert(size >= 0); extended_service_request->presencemask |= OGS_NAS_EPS_EXTENDED_SERVICE_REQUEST_DEVICE_PROPERTIES_PRESENT; @@ -1162,6 +1216,8 @@ int ogs_nas_eps_decode_guti_reallocation_command(ogs_nas_eps_message_t *message, decoded += size; break; case OGS_NAS_EPS_GUTI_REALLOCATION_COMMAND_UE_RADIO_CAPABILITY_ID_DELETION_INDICATION_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_ue_radio_capability_id_deletion_indication(&guti_reallocation_command->ue_radio_capability_id_deletion_indication, pkbuf); ogs_assert(size >= 0); guti_reallocation_command->presencemask |= OGS_NAS_EPS_GUTI_REALLOCATION_COMMAND_UE_RADIO_CAPABILITY_ID_DELETION_INDICATION_PRESENT; @@ -1310,6 +1366,8 @@ int ogs_nas_eps_decode_security_mode_command(ogs_nas_eps_message_t *message, ogs switch (type) { case OGS_NAS_EPS_SECURITY_MODE_COMMAND_IMEISV_REQUEST_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_imeisv_request(&security_mode_command->imeisv_request, pkbuf); ogs_assert(size >= 0); security_mode_command->presencemask |= OGS_NAS_EPS_SECURITY_MODE_COMMAND_IMEISV_REQUEST_PRESENT; @@ -1340,6 +1398,8 @@ int ogs_nas_eps_decode_security_mode_command(ogs_nas_eps_message_t *message, ogs decoded += size; break; case OGS_NAS_EPS_SECURITY_MODE_COMMAND_UE_RADIO_CAPABILITY_ID_REQUEST_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_ue_radio_capability_id_request(&security_mode_command->ue_radio_capability_id_request, pkbuf); ogs_assert(size >= 0); security_mode_command->presencemask |= OGS_NAS_EPS_SECURITY_MODE_COMMAND_UE_RADIO_CAPABILITY_ID_REQUEST_PRESENT; @@ -1696,6 +1756,8 @@ int ogs_nas_eps_decode_activate_default_eps_bearer_context_request(ogs_nas_eps_m decoded += size; break; case OGS_NAS_EPS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_RADIO_PRIORITY_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_radio_priority(&activate_default_eps_bearer_context_request->radio_priority, pkbuf); ogs_assert(size >= 0); activate_default_eps_bearer_context_request->presencemask |= OGS_NAS_EPS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_RADIO_PRIORITY_PRESENT; @@ -1726,12 +1788,16 @@ int ogs_nas_eps_decode_activate_default_eps_bearer_context_request(ogs_nas_eps_m decoded += size; break; case OGS_NAS_EPS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_CONNECTIVITY_TYPE_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_connectivity_type(&activate_default_eps_bearer_context_request->connectivity_type, pkbuf); ogs_assert(size >= 0); activate_default_eps_bearer_context_request->presencemask |= OGS_NAS_EPS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_CONNECTIVITY_TYPE_PRESENT; decoded += size; break; case OGS_NAS_EPS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_WLAN_OFFLOAD_INDICATION_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_wlan_offload_acceptability(&activate_default_eps_bearer_context_request->wlan_offload_indication, pkbuf); ogs_assert(size >= 0); activate_default_eps_bearer_context_request->presencemask |= OGS_NAS_EPS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_WLAN_OFFLOAD_INDICATION_PRESENT; @@ -1750,6 +1816,8 @@ int ogs_nas_eps_decode_activate_default_eps_bearer_context_request(ogs_nas_eps_m decoded += size; break; case OGS_NAS_EPS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_CONTROL_PLANE_ONLY_INDICATION_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_control_plane_only_indication(&activate_default_eps_bearer_context_request->control_plane_only_indication, pkbuf); ogs_assert(size >= 0); activate_default_eps_bearer_context_request->presencemask |= OGS_NAS_EPS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST_CONTROL_PLANE_ONLY_INDICATION_PRESENT; @@ -1910,6 +1978,8 @@ int ogs_nas_eps_decode_activate_dedicated_eps_bearer_context_request(ogs_nas_eps decoded += size; break; case OGS_NAS_EPS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST_RADIO_PRIORITY_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_radio_priority(&activate_dedicated_eps_bearer_context_request->radio_priority, pkbuf); ogs_assert(size >= 0); activate_dedicated_eps_bearer_context_request->presencemask |= OGS_NAS_EPS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST_RADIO_PRIORITY_PRESENT; @@ -1928,6 +1998,8 @@ int ogs_nas_eps_decode_activate_dedicated_eps_bearer_context_request(ogs_nas_eps decoded += size; break; case OGS_NAS_EPS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST_WLAN_OFFLOAD_INDICATION_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_wlan_offload_acceptability(&activate_dedicated_eps_bearer_context_request->wlan_offload_indication, pkbuf); ogs_assert(size >= 0); activate_dedicated_eps_bearer_context_request->presencemask |= OGS_NAS_EPS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST_WLAN_OFFLOAD_INDICATION_PRESENT; @@ -2094,6 +2166,8 @@ int ogs_nas_eps_decode_modify_eps_bearer_context_request(ogs_nas_eps_message_t * decoded += size; break; case OGS_NAS_EPS_MODIFY_EPS_BEARER_CONTEXT_REQUEST_RADIO_PRIORITY_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_radio_priority(&modify_eps_bearer_context_request->radio_priority, pkbuf); ogs_assert(size >= 0); modify_eps_bearer_context_request->presencemask |= OGS_NAS_EPS_MODIFY_EPS_BEARER_CONTEXT_REQUEST_RADIO_PRIORITY_PRESENT; @@ -2118,6 +2192,8 @@ int ogs_nas_eps_decode_modify_eps_bearer_context_request(ogs_nas_eps_message_t * decoded += size; break; case OGS_NAS_EPS_MODIFY_EPS_BEARER_CONTEXT_REQUEST_WLAN_OFFLOAD_INDICATION_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_wlan_offload_acceptability(&modify_eps_bearer_context_request->wlan_offload_indication, pkbuf); ogs_assert(size >= 0); modify_eps_bearer_context_request->presencemask |= OGS_NAS_EPS_MODIFY_EPS_BEARER_CONTEXT_REQUEST_WLAN_OFFLOAD_INDICATION_PRESENT; @@ -2288,6 +2364,8 @@ int ogs_nas_eps_decode_deactivate_eps_bearer_context_request(ogs_nas_eps_message decoded += size; break; case OGS_NAS_EPS_DEACTIVATE_EPS_BEARER_CONTEXT_REQUEST_WLAN_OFFLOAD_INDICATION_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_wlan_offload_acceptability(&deactivate_eps_bearer_context_request->wlan_offload_indication, pkbuf); ogs_assert(size >= 0); deactivate_eps_bearer_context_request->presencemask |= OGS_NAS_EPS_DEACTIVATE_EPS_BEARER_CONTEXT_REQUEST_WLAN_OFFLOAD_INDICATION_PRESENT; @@ -2374,6 +2452,8 @@ int ogs_nas_eps_decode_pdn_connectivity_request(ogs_nas_eps_message_t *message, switch (type) { case OGS_NAS_EPS_PDN_CONNECTIVITY_REQUEST_ESM_INFORMATION_TRANSFER_FLAG_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_esm_information_transfer_flag(&pdn_connectivity_request->esm_information_transfer_flag, pkbuf); ogs_assert(size >= 0); pdn_connectivity_request->presencemask |= OGS_NAS_EPS_PDN_CONNECTIVITY_REQUEST_ESM_INFORMATION_TRANSFER_FLAG_PRESENT; @@ -2392,6 +2472,8 @@ int ogs_nas_eps_decode_pdn_connectivity_request(ogs_nas_eps_message_t *message, decoded += size; break; case OGS_NAS_EPS_PDN_CONNECTIVITY_REQUEST_DEVICE_PROPERTIES_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_device_properties(&pdn_connectivity_request->device_properties, pkbuf); ogs_assert(size >= 0); pdn_connectivity_request->presencemask |= OGS_NAS_EPS_PDN_CONNECTIVITY_REQUEST_DEVICE_PROPERTIES_PRESENT; @@ -2604,6 +2686,8 @@ int ogs_nas_eps_decode_bearer_resource_allocation_request(ogs_nas_eps_message_t decoded += size; break; case OGS_NAS_EPS_BEARER_RESOURCE_ALLOCATION_REQUEST_DEVICE_PROPERTIES_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_device_properties(&bearer_resource_allocation_request->device_properties, pkbuf); ogs_assert(size >= 0); bearer_resource_allocation_request->presencemask |= OGS_NAS_EPS_BEARER_RESOURCE_ALLOCATION_REQUEST_DEVICE_PROPERTIES_PRESENT; @@ -2740,6 +2824,8 @@ int ogs_nas_eps_decode_bearer_resource_modification_request(ogs_nas_eps_message_ decoded += size; break; case OGS_NAS_EPS_BEARER_RESOURCE_MODIFICATION_REQUEST_DEVICE_PROPERTIES_TYPE: + decoded--; + ogs_assert(ogs_pkbuf_push(pkbuf, 1)); size = ogs_nas_eps_decode_device_properties(&bearer_resource_modification_request->device_properties, pkbuf); ogs_assert(size >= 0); bearer_resource_modification_request->presencemask |= OGS_NAS_EPS_BEARER_RESOURCE_MODIFICATION_REQUEST_DEVICE_PROPERTIES_PRESENT; diff --git a/lib/nas/eps/encoder.c b/lib/nas/eps/encoder.c index db0fcfb09..a5aa135a4 100644 --- a/lib/nas/eps/encoder.c +++ b/lib/nas/eps/encoder.c @@ -28,7 +28,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2020-06-30 16:47:16.518250 by acetcom + * Created on: 2020-08-16 17:47:29.440664 by acetcom * from 24301-g40.docx ******************************************************************************/ diff --git a/lib/nas/eps/ies.c b/lib/nas/eps/ies.c index 35f2a7610..59a798b71 100644 --- a/lib/nas/eps/ies.c +++ b/lib/nas/eps/ies.c @@ -28,7 +28,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2020-06-30 16:47:16.490433 by acetcom + * Created on: 2020-08-16 17:47:29.412678 by acetcom * from 24301-g40.docx ******************************************************************************/ @@ -81,12 +81,15 @@ int ogs_nas_eps_encode_additional_information(ogs_pkbuf_t *pkbuf, ogs_nas_additi * O TV 1 */ int ogs_nas_eps_decode_device_properties(ogs_nas_device_properties_t *device_properties, ogs_pkbuf_t *pkbuf) { - memcpy(device_properties, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_device_properties_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(device_properties, pkbuf->data - size, size); ogs_trace(" DEVICE_PROPERTIES - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_device_properties(ogs_pkbuf_t *pkbuf, ogs_nas_device_properties_t *device_properties) @@ -353,12 +356,15 @@ int ogs_nas_eps_encode_plmn_list(ogs_pkbuf_t *pkbuf, ogs_nas_plmn_list_t *plmn_l * O TV 1 */ int ogs_nas_eps_decode_additional_update_result(ogs_nas_additional_update_result_t *additional_update_result, ogs_pkbuf_t *pkbuf) { - memcpy(additional_update_result, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_additional_update_result_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(additional_update_result, pkbuf->data - size, size); ogs_trace(" ADDITIONAL_UPDATE_RESULT - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_additional_update_result(ogs_pkbuf_t *pkbuf, ogs_nas_additional_update_result_t *additional_update_result) @@ -378,12 +384,15 @@ int ogs_nas_eps_encode_additional_update_result(ogs_pkbuf_t *pkbuf, ogs_nas_addi * O TV 1 */ int ogs_nas_eps_decode_additional_update_type(ogs_nas_additional_update_type_t *additional_update_type, ogs_pkbuf_t *pkbuf) { - memcpy(additional_update_type, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_additional_update_type_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(additional_update_type, pkbuf->data - size, size); ogs_trace(" ADDITIONAL_UPDATE_TYPE - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_additional_update_type(ogs_pkbuf_t *pkbuf, ogs_nas_additional_update_type_t *additional_update_type) @@ -806,12 +815,15 @@ int ogs_nas_eps_encode_identity_type_2(ogs_pkbuf_t *pkbuf, ogs_nas_identity_type * O TV 1 */ int ogs_nas_eps_decode_imeisv_request(ogs_nas_imeisv_request_t *imeisv_request, ogs_pkbuf_t *pkbuf) { - memcpy(imeisv_request, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_imeisv_request_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(imeisv_request, pkbuf->data - size, size); ogs_trace(" IMEISV_REQUEST - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_imeisv_request(ogs_pkbuf_t *pkbuf, ogs_nas_imeisv_request_t *imeisv_request) @@ -929,12 +941,15 @@ int ogs_nas_eps_encode_ms_network_capability(ogs_pkbuf_t *pkbuf, ogs_nas_ms_netw * O TV 1 */ int ogs_nas_eps_decode_ms_network_feature_support(ogs_nas_ms_network_feature_support_t *ms_network_feature_support, ogs_pkbuf_t *pkbuf) { - memcpy(ms_network_feature_support, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_ms_network_feature_support_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(ms_network_feature_support, pkbuf->data - size, size); ogs_trace(" MS_NETWORK_FEATURE_SUPPORT - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_ms_network_feature_support(ogs_pkbuf_t *pkbuf, ogs_nas_ms_network_feature_support_t *ms_network_feature_support) @@ -954,12 +969,15 @@ int ogs_nas_eps_encode_ms_network_feature_support(ogs_pkbuf_t *pkbuf, ogs_nas_ms * O TV 1 */ int ogs_nas_eps_decode_key_set_identifier(ogs_nas_key_set_identifier_t *key_set_identifier, ogs_pkbuf_t *pkbuf) { - memcpy(key_set_identifier, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_key_set_identifier_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(key_set_identifier, pkbuf->data - size, size); ogs_trace(" KEY_SET_IDENTIFIER - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_key_set_identifier(ogs_pkbuf_t *pkbuf, ogs_nas_key_set_identifier_t *key_set_identifier) @@ -1209,12 +1227,15 @@ int ogs_nas_eps_encode_p_tmsi_signature(ogs_pkbuf_t *pkbuf, ogs_nas_p_tmsi_signa * O TV 1 */ int ogs_nas_eps_decode_extended_emm_cause(ogs_nas_extended_emm_cause_t *extended_emm_cause, ogs_pkbuf_t *pkbuf) { - memcpy(extended_emm_cause, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_extended_emm_cause_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(extended_emm_cause, pkbuf->data - size, size); ogs_trace(" EXTENDED_EMM_CAUSE - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_extended_emm_cause(ogs_pkbuf_t *pkbuf, ogs_nas_extended_emm_cause_t *extended_emm_cause) @@ -1388,12 +1409,15 @@ int ogs_nas_eps_encode_time_zone_and_time(ogs_pkbuf_t *pkbuf, ogs_nas_time_zone_ * O TV 1 */ int ogs_nas_eps_decode_tmsi_status(ogs_nas_tmsi_status_t *tmsi_status, ogs_pkbuf_t *pkbuf) { - memcpy(tmsi_status, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_tmsi_status_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(tmsi_status, pkbuf->data - size, size); ogs_trace(" TMSI_STATUS - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_tmsi_status(ogs_pkbuf_t *pkbuf, ogs_nas_tmsi_status_t *tmsi_status) @@ -1515,12 +1539,15 @@ int ogs_nas_eps_encode_ue_network_capability(ogs_pkbuf_t *pkbuf, ogs_nas_ue_netw * O TV 1 */ int ogs_nas_eps_decode_ue_radio_capability_information_update_needed(ogs_nas_ue_radio_capability_information_update_needed_t *ue_radio_capability_information_update_needed, ogs_pkbuf_t *pkbuf) { - memcpy(ue_radio_capability_information_update_needed, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_ue_radio_capability_information_update_needed_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(ue_radio_capability_information_update_needed, pkbuf->data - size, size); ogs_trace(" UE_RADIO_CAPABILITY_INFORMATION_UPDATE_NEEDED - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_ue_radio_capability_information_update_needed(ogs_pkbuf_t *pkbuf, ogs_nas_ue_radio_capability_information_update_needed_t *ue_radio_capability_information_update_needed) @@ -1918,12 +1945,15 @@ int ogs_nas_eps_encode_voice_domain_preference_and_ue_usage_setting(ogs_pkbuf_t * O TV 1 */ int ogs_nas_eps_decode_guti_type(ogs_nas_guti_type_t *guti_type, ogs_pkbuf_t *pkbuf) { - memcpy(guti_type, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_guti_type_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(guti_type, pkbuf->data - size, size); ogs_trace(" GUTI_TYPE - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_guti_type(ogs_pkbuf_t *pkbuf, ogs_nas_guti_type_t *guti_type) @@ -2011,12 +2041,15 @@ int ogs_nas_eps_encode_dcn_id(ogs_pkbuf_t *pkbuf, ogs_nas_dcn_id_t *dcn_id) * O TV 1 */ int ogs_nas_eps_decode_non__nw_provided_policies(ogs_nas_non__nw_provided_policies_t *non__nw_provided_policies, ogs_pkbuf_t *pkbuf) { - memcpy(non__nw_provided_policies, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_non__nw_provided_policies_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(non__nw_provided_policies, pkbuf->data - size, size); ogs_trace(" NON__NW_PROVIDED_POLICIES - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_non__nw_provided_policies(ogs_pkbuf_t *pkbuf, ogs_nas_non__nw_provided_policies_t *non__nw_provided_policies) @@ -2036,12 +2069,15 @@ int ogs_nas_eps_encode_non__nw_provided_policies(ogs_pkbuf_t *pkbuf, ogs_nas_non * O TV 1 */ int ogs_nas_eps_decode_sms_services_status(ogs_nas_sms_services_status_t *sms_services_status, ogs_pkbuf_t *pkbuf) { - memcpy(sms_services_status, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_sms_services_status_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(sms_services_status, pkbuf->data - size, size); ogs_trace(" SMS_SERVICES_STATUS - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_sms_services_status(ogs_pkbuf_t *pkbuf, ogs_nas_sms_services_status_t *sms_services_status) @@ -2061,12 +2097,15 @@ int ogs_nas_eps_encode_sms_services_status(ogs_pkbuf_t *pkbuf, ogs_nas_sms_servi * O TV 1 */ int ogs_nas_eps_decode_ciphering_key_sequence_number(ogs_nas_ciphering_key_sequence_number_t *ciphering_key_sequence_number, ogs_pkbuf_t *pkbuf) { - memcpy(ciphering_key_sequence_number, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_ciphering_key_sequence_number_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(ciphering_key_sequence_number, pkbuf->data - size, size); ogs_trace(" CIPHERING_KEY_SEQUENCE_NUMBER - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_ciphering_key_sequence_number(ogs_pkbuf_t *pkbuf, ogs_nas_ciphering_key_sequence_number_t *ciphering_key_sequence_number) @@ -2086,12 +2125,15 @@ int ogs_nas_eps_encode_ciphering_key_sequence_number(ogs_pkbuf_t *pkbuf, ogs_nas * O TV 1 */ int ogs_nas_eps_decode_csfb_response(ogs_nas_csfb_response_t *csfb_response, ogs_pkbuf_t *pkbuf) { - memcpy(csfb_response, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_csfb_response_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(csfb_response, pkbuf->data - size, size); ogs_trace(" CSFB_RESPONSE - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_csfb_response(ogs_pkbuf_t *pkbuf, ogs_nas_csfb_response_t *csfb_response) @@ -2187,12 +2229,15 @@ int ogs_nas_eps_encode_replayed_nas_message_container(ogs_pkbuf_t *pkbuf, ogs_na * O TV 1 */ int ogs_nas_eps_decode_network_policy(ogs_nas_network_policy_t *network_policy, ogs_pkbuf_t *pkbuf) { - memcpy(network_policy, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_network_policy_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(network_policy, pkbuf->data - size, size); ogs_trace(" NETWORK_POLICY - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_network_policy(ogs_pkbuf_t *pkbuf, ogs_nas_network_policy_t *network_policy) @@ -2386,12 +2431,15 @@ int ogs_nas_eps_encode_n1_ue_network_capability(ogs_pkbuf_t *pkbuf, ogs_nas_n1_u * O TV 1 */ int ogs_nas_eps_decode_ue_radio_capability_id_request(ogs_nas_ue_radio_capability_id_request_t *ue_radio_capability_id_request, ogs_pkbuf_t *pkbuf) { - memcpy(ue_radio_capability_id_request, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_ue_radio_capability_id_request_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(ue_radio_capability_id_request, pkbuf->data - size, size); ogs_trace(" UE_RADIO_CAPABILITY_ID_REQUEST - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_ue_radio_capability_id_request(ogs_pkbuf_t *pkbuf, ogs_nas_ue_radio_capability_id_request_t *ue_radio_capability_id_request) @@ -2479,12 +2527,15 @@ int ogs_nas_eps_encode_ue_radio_capability_id(ogs_pkbuf_t *pkbuf, ogs_nas_ue_rad * O TV 1 */ int ogs_nas_eps_decode_ue_radio_capability_id_deletion_indication(ogs_nas_ue_radio_capability_id_deletion_indication_t *ue_radio_capability_id_deletion_indication, ogs_pkbuf_t *pkbuf) { - memcpy(ue_radio_capability_id_deletion_indication, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_ue_radio_capability_id_deletion_indication_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(ue_radio_capability_id_deletion_indication, pkbuf->data - size, size); ogs_trace(" UE_RADIO_CAPABILITY_ID_DELETION_INDICATION - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_ue_radio_capability_id_deletion_indication(ogs_pkbuf_t *pkbuf, ogs_nas_ue_radio_capability_id_deletion_indication_t *ue_radio_capability_id_deletion_indication) @@ -2705,12 +2756,15 @@ int ogs_nas_eps_encode_quality_of_service(ogs_pkbuf_t *pkbuf, ogs_nas_quality_of * O TV 1 */ int ogs_nas_eps_decode_radio_priority(ogs_nas_radio_priority_t *radio_priority, ogs_pkbuf_t *pkbuf) { - memcpy(radio_priority, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_radio_priority_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(radio_priority, pkbuf->data - size, size); ogs_trace(" RADIO_PRIORITY - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_radio_priority(ogs_pkbuf_t *pkbuf, ogs_nas_radio_priority_t *radio_priority) @@ -2896,12 +2950,15 @@ int ogs_nas_eps_encode_transaction_identifier(ogs_pkbuf_t *pkbuf, ogs_nas_transa * O TV 1 */ int ogs_nas_eps_decode_wlan_offload_acceptability(ogs_nas_wlan_offload_acceptability_t *wlan_offload_acceptability, ogs_pkbuf_t *pkbuf) { - memcpy(wlan_offload_acceptability, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_wlan_offload_acceptability_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(wlan_offload_acceptability, pkbuf->data - size, size); ogs_trace(" WLAN_OFFLOAD_ACCEPTABILITY - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_wlan_offload_acceptability(ogs_pkbuf_t *pkbuf, ogs_nas_wlan_offload_acceptability_t *wlan_offload_acceptability) @@ -3027,12 +3084,15 @@ int ogs_nas_eps_encode_header_compression_configuration(ogs_pkbuf_t *pkbuf, ogs_ * O TV 1 */ int ogs_nas_eps_decode_control_plane_only_indication(ogs_nas_control_plane_only_indication_t *control_plane_only_indication, ogs_pkbuf_t *pkbuf) { - memcpy(control_plane_only_indication, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_control_plane_only_indication_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(control_plane_only_indication, pkbuf->data - size, size); ogs_trace(" CONTROL_PLANE_ONLY_INDICATION - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_control_plane_only_indication(ogs_pkbuf_t *pkbuf, ogs_nas_control_plane_only_indication_t *control_plane_only_indication) @@ -3196,12 +3256,15 @@ int ogs_nas_eps_encode_extended_apn_aggregate_maximum_bit_rate(ogs_pkbuf_t *pkbu * O TV 1 */ int ogs_nas_eps_decode_connectivity_type(ogs_nas_connectivity_type_t *connectivity_type, ogs_pkbuf_t *pkbuf) { - memcpy(connectivity_type, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_connectivity_type_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(connectivity_type, pkbuf->data - size, size); ogs_trace(" CONNECTIVITY_TYPE - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_connectivity_type(ogs_pkbuf_t *pkbuf, ogs_nas_connectivity_type_t *connectivity_type) @@ -3319,12 +3382,15 @@ int ogs_nas_eps_encode_esm_cause(ogs_pkbuf_t *pkbuf, ogs_nas_esm_cause_t *esm_ca * O TV 1 */ int ogs_nas_eps_decode_esm_information_transfer_flag(ogs_nas_esm_information_transfer_flag_t *esm_information_transfer_flag, ogs_pkbuf_t *pkbuf) { - memcpy(esm_information_transfer_flag, pkbuf->data - 1, 1); + uint16_t size = sizeof(ogs_nas_esm_information_transfer_flag_t); + + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + memcpy(esm_information_transfer_flag, pkbuf->data - size, size); ogs_trace(" ESM_INFORMATION_TRANSFER_FLAG - "); - ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1); + ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size); - return 0; + return size; } int ogs_nas_eps_encode_esm_information_transfer_flag(ogs_pkbuf_t *pkbuf, ogs_nas_esm_information_transfer_flag_t *esm_information_transfer_flag) diff --git a/lib/nas/eps/ies.h b/lib/nas/eps/ies.h index 9e7e43597..ee66b2ed1 100644 --- a/lib/nas/eps/ies.h +++ b/lib/nas/eps/ies.h @@ -28,7 +28,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2020-06-30 16:47:16.487897 by acetcom + * Created on: 2020-08-16 17:47:29.410200 by acetcom * from 24301-g40.docx ******************************************************************************/ diff --git a/lib/nas/eps/message.h b/lib/nas/eps/message.h index 392807c94..7dff31b72 100644 --- a/lib/nas/eps/message.h +++ b/lib/nas/eps/message.h @@ -28,7 +28,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2020-06-30 16:47:16.497641 by acetcom + * Created on: 2020-08-16 17:47:29.419910 by acetcom * from 24301-g40.docx ******************************************************************************/ diff --git a/lib/nas/eps/support/nas-message.py b/lib/nas/eps/support/nas-message.py index b01a743af..b2146d52a 100644 --- a/lib/nas/eps/support/nas-message.py +++ b/lib/nas/eps/support/nas-message.py @@ -403,10 +403,12 @@ for (k, v) in sorted_type_list: if (type_list[k]["format"] == "TV" or type_list[k]["format"] == "T") and type_list[k]["length"] == "1": f.write("int ogs_nas_eps_decode_%s(ogs_nas_%s_t *%s, ogs_pkbuf_t *pkbuf)\n" % (v_lower(k), v_lower(k), v_lower(k))) f.write("{\n") - f.write(" memcpy(%s, pkbuf->data - 1, 1);\n\n" % v_lower(k)) + f.write(" uint16_t size = sizeof(ogs_nas_%s_t);\n\n" % v_lower(k)) + f.write(" ogs_assert(ogs_pkbuf_pull(pkbuf, size));\n") + f.write(" memcpy(%s, pkbuf->data - size, size);\n\n" % v_lower(k)) f.write(" ogs_trace(\" %s - \");\n" % v_upper(k)) - f.write(" ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - 1, 1);\n\n"); - f.write(" return 0;\n") + f.write(" ogs_log_hexdump(OGS_LOG_TRACE, pkbuf->data - size, size);\n\n"); + f.write(" return size;\n") f.write("}\n\n") f.write("int ogs_nas_eps_encode_%s(ogs_pkbuf_t *pkbuf, ogs_nas_%s_t *%s)\n" % (v_lower(k), v_lower(k), v_lower(k))) f.write("{\n") @@ -693,6 +695,9 @@ for (k, v) in sorted_msg_list: optional_fields = True; f.write(" case OGS_NAS_EPS_%s_%s_TYPE:\n" % (v_upper(k), v_upper(ie["value"]))) + if (ie["format"] == "TV" or ie["format"] == "T") and ie["length"] == "1": + f.write(" decoded--;\n") + f.write(" ogs_assert(ogs_pkbuf_push(pkbuf, 1));\n") f.write(" size = ogs_nas_eps_decode_%s(&%s->%s, pkbuf);\n" % (v_lower(ie["type"]), v_lower(k), v_lower(ie["value"]))) f.write(" ogs_assert(size >= 0);\n") f.write(" %s->presencemask |= OGS_NAS_EPS_%s_%s_PRESENT;\n" % (v_lower(k), v_upper(k), v_upper(ie["value"]))) diff --git a/lib/nas/eps/types.h b/lib/nas/eps/types.h index 1b417561d..1b70bc438 100644 --- a/lib/nas/eps/types.h +++ b/lib/nas/eps/types.h @@ -287,8 +287,8 @@ ED2(uint8_t spare:5;, #define OGS_NAS_KEY_SET_IDENTIFIER_NOT_AVAILABLE 0x111 #define OGS_NAS_ATTACH_TYPE_EPS_ATTACH 1 -#define OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTAACH 2 -#define OGS_NAS_ATTACH_TYPE_EPS_ERMERGENCY_ATTCH 3 +#define OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH 2 +#define OGS_NAS_ATTACH_TYPE_EPS_ERMERGENCY_ATTACH 3 #define OGS_NAS_ATTACH_TYPE_RESERVED 4 typedef struct ogs_nas_eps_attach_type_s { ED4(uint8_t tsc:1;, diff --git a/lib/ngap/conv.c b/lib/ngap/conv.c index 436e91a93..8a331453c 100644 --- a/lib/ngap/conv.c +++ b/lib/ngap/conv.c @@ -124,7 +124,7 @@ void ogs_ngap_nr_cgi_to_ASN(ogs_nr_cgi_t *nr_cgi, NGAP_NR_CGI_t *nR_CGI) /* CellIdentity : 36bit */ ogs_uint64_to_buffer((nr_cgi->cell_id << 4), 5, buf); - ogs_asn_buffer_to_BIT_STRING(buf, 5, 4, &nR_CGI->nRCellIdentity); + ogs_asn_buffer_to_BIT_STRING(buf, 5, 4, &nR_CGI->nRCellIdentity); } void ogs_ngap_ASN_to_nr_cgi(NGAP_NR_CGI_t *nR_CGI, ogs_nr_cgi_t *nr_cgi) diff --git a/lib/ngap/message.c b/lib/ngap/message.c index cd223bc89..b9eb7c849 100644 --- a/lib/ngap/message.c +++ b/lib/ngap/message.c @@ -21,7 +21,7 @@ int __ogs_ngap_domain; -ogs_pkbuf_t *nga_ngap_encode(ogs_ngap_message_t *message) +ogs_pkbuf_t *ogs_ngap_encode(ogs_ngap_message_t *message) { ogs_pkbuf_t *pkbuf = NULL; @@ -39,7 +39,7 @@ ogs_pkbuf_t *nga_ngap_encode(ogs_ngap_message_t *message) return pkbuf; } -int nga_ngap_decode(ogs_ngap_message_t *message, ogs_pkbuf_t *pkbuf) +int ogs_ngap_decode(ogs_ngap_message_t *message, ogs_pkbuf_t *pkbuf) { int rv; ogs_assert(message); @@ -60,7 +60,7 @@ int nga_ngap_decode(ogs_ngap_message_t *message, ogs_pkbuf_t *pkbuf) return OGS_OK; } -void nga_ngap_free(ogs_ngap_message_t *message) +void ogs_ngap_free(ogs_ngap_message_t *message) { ogs_assert(message); ogs_asn_free(&asn_DEF_NGAP_NGAP_PDU, message); diff --git a/lib/ngap/message.h b/lib/ngap/message.h index eb4a91e58..2e2c7cf32 100644 --- a/lib/ngap/message.h +++ b/lib/ngap/message.h @@ -30,9 +30,9 @@ extern "C" { typedef struct NGAP_NGAP_PDU ogs_ngap_message_t; -int nga_ngap_decode(ogs_ngap_message_t *message, ogs_pkbuf_t *pkbuf); -ogs_pkbuf_t *nga_ngap_encode(ogs_ngap_message_t *message); -void nga_ngap_free(ogs_ngap_message_t *message); +int ogs_ngap_decode(ogs_ngap_message_t *message, ogs_pkbuf_t *pkbuf); +ogs_pkbuf_t *ogs_ngap_encode(ogs_ngap_message_t *message); +void ogs_ngap_free(ogs_ngap_message_t *message); #ifdef __cplusplus } diff --git a/lib/s1ap/build.c b/lib/s1ap/build.c new file mode 100644 index 000000000..57bbfe35b --- /dev/null +++ b/lib/s1ap/build.c @@ -0,0 +1,279 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-s1ap.h" + +ogs_pkbuf_t *ogs_s1ap_build_error_indication( + S1AP_MME_UE_S1AP_ID_t *mme_ue_s1ap_id, + S1AP_ENB_UE_S1AP_ID_t *enb_ue_s1ap_id, + S1AP_Cause_PR group, long cause) +{ + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_ErrorIndication_t *ErrorIndication = NULL; + + S1AP_ErrorIndicationIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_Cause_t *Cause = NULL; + + ogs_debug("[MME] Error Indication"); + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = + CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); + + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = S1AP_ProcedureCode_id_ErrorIndication; + initiatingMessage->criticality = S1AP_Criticality_ignore; + initiatingMessage->value.present = + S1AP_InitiatingMessage__value_PR_ErrorIndication; + + ErrorIndication = &initiatingMessage->value.choice.ErrorIndication; + + if (mme_ue_s1ap_id) { + ie = CALLOC(1, sizeof(S1AP_ErrorIndicationIEs_t)); + ASN_SEQUENCE_ADD(&ErrorIndication->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_ErrorIndicationIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = *mme_ue_s1ap_id; + ogs_debug(" MME_UE_S1AP_ID[%d]", (int)*mme_ue_s1ap_id); + } + + if (enb_ue_s1ap_id) { + ie = CALLOC(1, sizeof(S1AP_ErrorIndicationIEs_t)); + ASN_SEQUENCE_ADD(&ErrorIndication->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_ErrorIndicationIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = *enb_ue_s1ap_id; + ogs_debug(" ENB_UE_S1AP_ID[%d]", (int)*enb_ue_s1ap_id); + } + + ie = CALLOC(1, sizeof(S1AP_ErrorIndicationIEs_t)); + ASN_SEQUENCE_ADD(&ErrorIndication->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_Cause; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_ErrorIndicationIEs__value_PR_Cause; + + Cause = &ie->value.choice.Cause; + + Cause->present = group; + Cause->choice.radioNetwork = cause; + + ogs_debug(" Group[%d] Cause[%d]", + Cause->present, (int)Cause->choice.radioNetwork); + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *ogs_s1ap_build_s1_reset( + S1AP_Cause_PR group, long cause, + S1AP_UE_associatedLogicalS1_ConnectionListRes_t *partOfS1_Interface) +{ + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_Reset_t *Reset = NULL; + + S1AP_ResetIEs_t *ie = NULL; + S1AP_Cause_t *Cause = NULL; + S1AP_ResetType_t *ResetType = NULL; + + ogs_debug("[MME] Reset"); + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = + CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); + + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = S1AP_ProcedureCode_id_Reset; + initiatingMessage->criticality = S1AP_Criticality_ignore; + initiatingMessage->value.present = + S1AP_InitiatingMessage__value_PR_Reset; + + Reset = &initiatingMessage->value.choice.Reset; + + ie = CALLOC(1, sizeof(S1AP_ResetIEs_t)); + ASN_SEQUENCE_ADD(&Reset->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_Cause; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_ResetIEs__value_PR_Cause; + + Cause = &ie->value.choice.Cause; + + ie = CALLOC(1, sizeof(S1AP_ResetIEs_t)); + ASN_SEQUENCE_ADD(&Reset->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_ResetType; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_ResetIEs__value_PR_ResetType; + + ResetType = &ie->value.choice.ResetType; + + Cause->present = group; + Cause->choice.radioNetwork = cause; + + ogs_debug(" Group[%d] Cause[%d] partOfS1_Interface[%p]", + Cause->present, (int)Cause->choice.radioNetwork, partOfS1_Interface); + + if (partOfS1_Interface) { + ResetType->present = S1AP_ResetType_PR_partOfS1_Interface; + ResetType->choice.partOfS1_Interface = partOfS1_Interface; + } else { + ResetType->present = S1AP_ResetType_PR_s1_Interface; + ResetType->choice.s1_Interface = S1AP_ResetAll_reset_all; + } + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *ogs_s1ap_build_s1_reset_partial( + S1AP_Cause_PR group, long cause, + S1AP_MME_UE_S1AP_ID_t *mme_ue_s1ap_id, + S1AP_ENB_UE_S1AP_ID_t *enb_ue_s1ap_id) +{ + S1AP_UE_associatedLogicalS1_ConnectionListRes_t *partOfS1_Interface = NULL; + S1AP_UE_associatedLogicalS1_ConnectionItemRes_t *ie2 = NULL; + S1AP_UE_associatedLogicalS1_ConnectionItem_t *item = NULL; + + partOfS1_Interface = CALLOC(1, + sizeof(S1AP_UE_associatedLogicalS1_ConnectionListRes_t)); + ogs_assert(partOfS1_Interface); + + ie2 = CALLOC(1, + sizeof(S1AP_UE_associatedLogicalS1_ConnectionItemRes_t)); + ASN_SEQUENCE_ADD(&partOfS1_Interface->list, ie2); + + ie2->id = S1AP_ProtocolIE_ID_id_UE_associatedLogicalS1_ConnectionItem; + ie2->criticality = S1AP_Criticality_reject; + ie2->value.present = S1AP_UE_associatedLogicalS1_ConnectionItemRes__value_PR_UE_associatedLogicalS1_ConnectionItem; + + item = &ie2->value.choice.UE_associatedLogicalS1_ConnectionItem; + item->mME_UE_S1AP_ID = mme_ue_s1ap_id; + item->eNB_UE_S1AP_ID = enb_ue_s1ap_id; + + return ogs_s1ap_build_s1_reset(group, cause, partOfS1_Interface); +} + +ogs_pkbuf_t *ogs_s1ap_build_s1_reset_ack( + S1AP_UE_associatedLogicalS1_ConnectionListRes_t *partOfS1_Interface) +{ + S1AP_S1AP_PDU_t pdu; + S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; + S1AP_ResetAcknowledge_t *ResetAcknowledge = NULL; + + S1AP_ResetAcknowledgeIEs_t *ie = NULL; + + ogs_debug("[MME] Reset acknowledge"); + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome = + CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); + + successfulOutcome = pdu.choice.successfulOutcome; + successfulOutcome->procedureCode = S1AP_ProcedureCode_id_Reset; + successfulOutcome->criticality = S1AP_Criticality_reject; + successfulOutcome->value.present = + S1AP_SuccessfulOutcome__value_PR_ResetAcknowledge; + + ResetAcknowledge = &successfulOutcome->value.choice.ResetAcknowledge; + + if (partOfS1_Interface && partOfS1_Interface->list.count) { + int i = 0; + S1AP_UE_associatedLogicalS1_ConnectionListResAck_t *list = NULL; + + ie = CALLOC(1, sizeof(S1AP_ResetAcknowledgeIEs_t)); + ASN_SEQUENCE_ADD(&ResetAcknowledge->protocolIEs, ie); + + ie->id = + S1AP_ProtocolIE_ID_id_UE_associatedLogicalS1_ConnectionListResAck; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_ResetAcknowledgeIEs__value_PR_UE_associatedLogicalS1_ConnectionListResAck; + + list = &ie->value.choice.UE_associatedLogicalS1_ConnectionListResAck; + + for (i = 0; i < partOfS1_Interface->list.count; i++) { + S1AP_UE_associatedLogicalS1_ConnectionItemRes_t *ie1 = NULL; + S1AP_UE_associatedLogicalS1_ConnectionItem_t *item1 = NULL; + + S1AP_UE_associatedLogicalS1_ConnectionItemResAck_t *ie2 = NULL; + S1AP_UE_associatedLogicalS1_ConnectionItem_t *item2 = NULL; + + ie1 = (S1AP_UE_associatedLogicalS1_ConnectionItemRes_t *) + partOfS1_Interface->list.array[i]; + ogs_assert(ie1); + + item1 = &ie1->value.choice.UE_associatedLogicalS1_ConnectionItem; + ogs_assert(item1); + + if (item1->mME_UE_S1AP_ID == NULL && + item1->eNB_UE_S1AP_ID == NULL) { + ogs_warn("No MME_UE_S1AP_ID & ENB_UE_S1AP_ID"); + continue; + } + + ie2 = CALLOC(1, + sizeof(S1AP_UE_associatedLogicalS1_ConnectionItemResAck_t)); + ogs_assert(ie2); + ASN_SEQUENCE_ADD(&list->list, ie2); + + ie2->id = + S1AP_ProtocolIE_ID_id_UE_associatedLogicalS1_ConnectionItem; + ie2->criticality = S1AP_Criticality_ignore; + ie2->value.present = S1AP_UE_associatedLogicalS1_ConnectionItemResAck__value_PR_UE_associatedLogicalS1_ConnectionItem; + + item2 = &ie2->value.choice.UE_associatedLogicalS1_ConnectionItem; + ogs_assert(item2); + + if (item1->mME_UE_S1AP_ID) { + item2->mME_UE_S1AP_ID = CALLOC(1, + sizeof(S1AP_MME_UE_S1AP_ID_t)); + ogs_assert(item2->mME_UE_S1AP_ID); + *item2->mME_UE_S1AP_ID = *item1->mME_UE_S1AP_ID; + } + + if (item1->eNB_UE_S1AP_ID) { + item2->eNB_UE_S1AP_ID = CALLOC(1, + sizeof(S1AP_ENB_UE_S1AP_ID_t)); + ogs_assert(item2->eNB_UE_S1AP_ID); + *item2->eNB_UE_S1AP_ID = *item1->eNB_UE_S1AP_ID; + } + + ogs_debug(" MME_UE_S1AP_ID[%d] ENB_UE_S1AP_ID[%d]", + item2->mME_UE_S1AP_ID ? (int)*item2->mME_UE_S1AP_ID : -1, + item2->eNB_UE_S1AP_ID ? (int)*item2->eNB_UE_S1AP_ID : -1); + } + } + + return ogs_s1ap_encode(&pdu); +} diff --git a/tests/cups/pcscf-fd-path.h b/lib/s1ap/build.h similarity index 50% rename from tests/cups/pcscf-fd-path.h rename to lib/s1ap/build.h index 2a42a2fad..60c1875c6 100644 --- a/tests/cups/pcscf-fd-path.h +++ b/lib/s1ap/build.h @@ -17,23 +17,36 @@ * along with this program. If not, see . */ -#ifndef PCSCF_FD_PATH_H -#define PCSCF_FD_PATH_H +#if !defined(OGS_S1AP_INSIDE) && !defined(OGS_S1AP_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_S1AP_BUILD_H +#define OGS_S1AP_BUILD_H #ifdef __cplusplus extern "C" { #endif -int pcscf_fd_init(void); -void pcscf_fd_final(void); +ogs_pkbuf_t *ogs_s1ap_build_error_indication( + S1AP_MME_UE_S1AP_ID_t *mme_ue_s1ap_id, + S1AP_ENB_UE_S1AP_ID_t *enb_ue_s1ap_id, + S1AP_Cause_PR group, long cause); -void pcscf_rx_send_aar(uint8_t **rx_sid, const char *ip, - int qos_type, int flow_presence); -void pcscf_rx_send_str(uint8_t *rx_sid); +ogs_pkbuf_t *ogs_s1ap_build_s1_reset( + S1AP_Cause_PR group, long cause, + S1AP_UE_associatedLogicalS1_ConnectionListRes_t *partOfS1_Interface); + +ogs_pkbuf_t *ogs_s1ap_build_s1_reset_partial( + S1AP_Cause_PR group, long cause, + S1AP_MME_UE_S1AP_ID_t *mme_ue_s1ap_id, + S1AP_ENB_UE_S1AP_ID_t *enb_ue_s1ap_id); + +ogs_pkbuf_t *ogs_s1ap_build_s1_reset_ack( + S1AP_UE_associatedLogicalS1_ConnectionListRes_t *partOfS1_Interface); #ifdef __cplusplus } #endif -#endif /* PCSCF_FD_PATH_H */ - +#endif /* OGS_S1AP_BUILD_H */ diff --git a/lib/s1ap/meson.build b/lib/s1ap/meson.build index b54361939..128fefc60 100644 --- a/lib/s1ap/meson.build +++ b/lib/s1ap/meson.build @@ -20,9 +20,11 @@ libs1ap_sources = files(''' conv.h message.h + build.h conv.c message.c + build.c '''.split()) libs1ap_inc = include_directories('.') diff --git a/lib/s1ap/ogs-s1ap.h b/lib/s1ap/ogs-s1ap.h index a743eb8d6..3a2d0ecee 100644 --- a/lib/s1ap/ogs-s1ap.h +++ b/lib/s1ap/ogs-s1ap.h @@ -549,6 +549,7 @@ #include "s1ap/conv.h" #include "s1ap/message.h" +#include "s1ap/build.h" #undef OGS_S1AP_INSIDE diff --git a/meson.build b/meson.build index f658e49a3..235390c47 100644 --- a/meson.build +++ b/meson.build @@ -16,7 +16,7 @@ # along with this program. If not, see . project('open5gs', 'c', - version : '1.3.0', + version : '2.0.0', license : 'AGPL-3.0-or-later', meson_version : '>= 0.43.0', default_options : [ @@ -24,7 +24,7 @@ project('open5gs', 'c', ], ) -libogslib_version = '1.3.0' +libogslib_version = '2.0.0' prefix = get_option('prefix') bindir = join_paths(prefix, get_option('bindir')) diff --git a/misc/make_certs.sh b/misc/make_certs.sh index b11a90812..0f1642b6f 100755 --- a/misc/make_certs.sh +++ b/misc/make_certs.sh @@ -25,10 +25,10 @@ openssl genrsa -out $1/hss.key.pem 1024 openssl req -new -batch -out hss.csr.pem -key $1/hss.key.pem -subj /CN=hss.localdomain/C=KO/ST=Seoul/L=Nowon/O=Open5GS/OU=Tests openssl ca -cert $1/cacert.pem -days 3650 -keyfile cakey.pem -in hss.csr.pem -out $1/hss.cert.pem -outdir . -batch -#pgw -openssl genrsa -out $1/pgw.key.pem 1024 -openssl req -new -batch -out pgw.csr.pem -key $1/pgw.key.pem -subj /CN=pgw.localdomain/C=KO/ST=Seoul/L=Nowon/O=Open5GS/OU=Tests -openssl ca -cert $1/cacert.pem -days 3650 -keyfile cakey.pem -in pgw.csr.pem -out $1/pgw.cert.pem -outdir . -batch +#smf +openssl genrsa -out $1/smf.key.pem 1024 +openssl req -new -batch -out smf.csr.pem -key $1/smf.key.pem -subj /CN=smf.localdomain/C=KO/ST=Seoul/L=Nowon/O=Open5GS/OU=Tests +openssl ca -cert $1/cacert.pem -days 3650 -keyfile cakey.pem -in smf.csr.pem -out $1/smf.cert.pem -outdir . -batch #pcrf openssl genrsa -out $1/pcrf.key.pem 1024 @@ -38,4 +38,4 @@ openssl ca -cert $1/cacert.pem -days 3650 -keyfile cakey.pem -in pcrf.csr.pem -o rm -rf demoCA rm -f 01.pem 02.pem 03.pem 04.pem rm -f cakey.pem -rm -f mme.csr.pem hss.csr.pem pgw.csr.pem pcrf.csr.pem +rm -f mme.csr.pem hss.csr.pem smf.csr.pem pcrf.csr.pem diff --git a/misc/netconf.sh b/misc/netconf.sh index 5af9389f5..952c2c50b 100755 --- a/misc/netconf.sh +++ b/misc/netconf.sh @@ -23,6 +23,19 @@ else ifconfig lo0 alias 127.0.0.5 netmask 255.255.255.255 ifconfig lo0 alias 127.0.0.6 netmask 255.255.255.255 ifconfig lo0 alias 127.0.0.7 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.8 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.9 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.10 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.11 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.12 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.13 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.14 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.15 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.16 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.17 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.18 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.19 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.20 netmask 255.255.255.255 if [ "$SYSTEM" = "Darwin" ]; then if ! test -f /etc/pf.anchors/org.open5gs; then sudo sh -c "echo 'nat on {en0} from 10.45.0.0/16 to any -> {en0}' > /etc/pf.anchors/org.open5gs" diff --git a/src/amf/amf-sm.c b/src/amf/amf-sm.c index f9b4324f7..b6add90e5 100644 --- a/src/amf/amf-sm.c +++ b/src/amf/amf-sm.c @@ -624,7 +624,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_assert(gnb); ogs_assert(OGS_FSM_STATE(&gnb->sm)); - rc = nga_ngap_decode(&ngap_message, pkbuf); + rc = ogs_ngap_decode(&ngap_message, pkbuf); if (rc == OGS_OK) { e->gnb = gnb; e->ngap.message = &ngap_message; @@ -636,7 +636,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) NGAP_CauseProtocol_abstract_syntax_error_falsely_constructed_message); } - nga_ngap_free(&ngap_message); + ogs_ngap_free(&ngap_message); ogs_pkbuf_free(pkbuf); break; diff --git a/src/amf/context.c b/src/amf/context.c index b5c328b3d..ba54e89f0 100644 --- a/src/amf/context.c +++ b/src/amf/context.c @@ -229,7 +229,7 @@ int amf_context_parse_config(void) family != AF_INET && family != AF_INET6) { ogs_warn("Ignore family(%d) : " "AF_UNSPEC(%d), " - "AF_INET(%d), AF_INET6(%d) ", + "AF_INET(%d), AF_INET6(%d) ", family, AF_UNSPEC, AF_INET, AF_INET6); family = AF_UNSPEC; } @@ -249,7 +249,7 @@ int amf_context_parse_config(void) } ogs_assert(num <= OGS_MAX_NUM_OF_HOSTNAME); - hostname[num++] = + hostname[num++] = ogs_yaml_iter_value(&hostname_iter); } while ( ogs_yaml_iter_type(&hostname_iter) == diff --git a/src/amf/ngap-build.c b/src/amf/ngap-build.c index c8b48e347..17ecccd9d 100644 --- a/src/amf/ngap-build.c +++ b/src/amf/ngap-build.c @@ -157,7 +157,7 @@ ogs_pkbuf_t *ngap_build_ng_setup_response(void) ASN_SEQUENCE_ADD(&PLMNSupportList->list, NGAP_PLMNSupportItem); } - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_ng_setup_failure( @@ -212,7 +212,7 @@ ogs_pkbuf_t *ngap_build_ng_setup_failure( if (TimeToWait) *TimeToWait = time_to_wait; - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_downlink_nas_transport( @@ -285,7 +285,7 @@ ogs_pkbuf_t *ngap_build_downlink_nas_transport( memcpy(NAS_PDU->buf, gmmbuf->data, NAS_PDU->size); ogs_pkbuf_free(gmmbuf); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_initial_context_setup_request( @@ -589,7 +589,7 @@ ogs_pkbuf_t *ngap_build_initial_context_setup_request( ogs_pkbuf_free(gmmbuf); } - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } #if 0 @@ -732,7 +732,7 @@ ogs_pkbuf_t *ngap_build_ue_context_modification_request(amf_ue_t *amf_ue) memcpy(SecurityKey->buf, amf_ue->kgnb, SecurityKey->size); } - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } #endif @@ -799,7 +799,7 @@ ogs_pkbuf_t *ngap_build_ue_context_release_command( Cause->present = group; Cause->choice.radioNetwork = cause; - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_pdu_session_resource_setup_request( @@ -908,7 +908,7 @@ ogs_pkbuf_t *ngap_build_pdu_session_resource_setup_request( memcpy(transfer->buf, n2smbuf->data, transfer->size); ogs_pkbuf_free(n2smbuf); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_pdu_session_resource_release_command( @@ -1015,7 +1015,7 @@ ogs_pkbuf_t *ngap_build_pdu_session_resource_release_command( memcpy(transfer->buf, n2smbuf->data, transfer->size); ogs_pkbuf_free(n2smbuf); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } #if 0 @@ -1139,7 +1139,7 @@ ogs_pkbuf_t *ngap_build_paging( &tai_item->tAI.pLMNidentity); ogs_asn_uint16_to_OCTET_STRING(amf_ue->tai.tac, &tai_item->tAI.tAC); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_amf_configuration_transfer( @@ -1187,7 +1187,7 @@ ogs_pkbuf_t *ngap_build_amf_configuration_transfer( son_configuration_transfer, SONConfigurationTransfer); ogs_assert(rv == OGS_OK); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_path_switch_ack(amf_ue_t *amf_ue) @@ -1268,7 +1268,7 @@ ogs_pkbuf_t *ngap_build_path_switch_ack(amf_ue_t *amf_ue) memcpy(SecurityContext->nextHopParameter.buf, amf_ue->nh, SecurityContext->nextHopParameter.size); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_path_switch_failure( @@ -1339,7 +1339,7 @@ ogs_pkbuf_t *ngap_build_path_switch_failure( Cause->present = group; Cause->choice.radioNetwork = cause; - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_handover_command(ran_ue_t *source_ue) @@ -1510,7 +1510,7 @@ ogs_pkbuf_t *ngap_build_handover_command(ran_ue_t *source_ue) ogs_asn_buffer_to_OCTET_STRING(amf_ue->container.buf, amf_ue->container.size, Target_ToSource_TransparentContainer); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_handover_preparation_failure( @@ -1584,7 +1584,7 @@ ogs_pkbuf_t *ngap_build_handover_preparation_failure( Cause->present = cause->present; Cause->choice.radioNetwork = cause->choice.radioNetwork; - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_handover_request( @@ -1829,7 +1829,7 @@ ogs_pkbuf_t *ngap_build_handover_request( memcpy(SecurityContext->nextHopParameter.buf, amf_ue->nh, SecurityContext->nextHopParameter.size); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_handover_cancel_ack(ran_ue_t *source_ue) @@ -1886,7 +1886,7 @@ ogs_pkbuf_t *ngap_build_handover_cancel_ack(ran_ue_t *source_ue) ogs_debug(" Source : RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%d]", source_ue->ran_ue_ngap_id, source_ue->amf_ue_ngap_id); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_amf_status_transfer( @@ -1965,7 +1965,7 @@ ogs_pkbuf_t *ngap_build_amf_status_transfer( RAN_StatusTransfer_TransparentContainer); ogs_assert(rv == OGS_OK); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } #endif @@ -2041,7 +2041,7 @@ ogs_pkbuf_t *ngap_build_error_indication( ogs_debug(" Group[%d] Cause[%d]", Cause->present, (int)Cause->choice.radioNetwork); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } #if 0 @@ -2104,7 +2104,7 @@ ogs_pkbuf_t *ngap_build_s1_reset( ResetType->choice.s1_Interface = NGAP_ResetAll_reset_all; } - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *ngap_build_s1_reset_partial( @@ -2226,6 +2226,6 @@ ogs_pkbuf_t *ngap_build_s1_reset_ack( } } - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } #endif diff --git a/src/hss/hss-auc.c b/src/hss/hss-auc.c deleted file mode 100644 index 28433c432..000000000 --- a/src/hss/hss-auc.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "ogs-crypt.h" -#include "ogs-core.h" - -#include "hss-auc.h" - -#define FC_VALUE 0x10 - -void hss_auc_kasme(const uint8_t *ck, const uint8_t *ik, - const uint8_t plmn_id[3], const uint8_t *sqn, const uint8_t *ak, - uint8_t *kasme) -{ - uint8_t s[14]; - uint8_t k[32]; - int i; - - memcpy(&k[0], ck, 16); - memcpy(&k[16], ik, 16); - - s[0] = FC_VALUE; - memcpy(&s[1], plmn_id, 3); - s[4] = 0x00; - s[5] = 0x03; - - for (i = 0; i < 6; i++) - s[6+i] = sqn[i] ^ ak[i]; - s[12] = 0x00; - s[13] = 0x06; - - ogs_hmac_sha256(k, 32, s, 14, kasme, 32); -} diff --git a/src/hss/hss-fd-path.c b/src/hss/hss-fd-path.c index f605c44f3..5146b80ce 100644 --- a/src/hss/hss-fd-path.c +++ b/src/hss/hss-fd-path.c @@ -20,7 +20,6 @@ #include "ogs-crypt.h" #include "hss-context.h" -#include "hss-auc.h" #include "hss-fd-path.h" /* handler for fallback cb */ @@ -163,7 +162,7 @@ static int hss_ogs_diam_s6a_air_cb( struct msg **msg, struct avp *avp, milenage_generate(opc, auth_info.amf, auth_info.k, ogs_uint64_to_buffer(auth_info.sqn, OGS_SQN_LEN, sqn), auth_info.rand, autn, ik, ck, ak, xres, &xres_len); - hss_auc_kasme(ck, ik, hdr->avp_value->os.data, sqn, ak, kasme); + ogs_auc_kasme(ck, ik, hdr->avp_value->os.data, sqn, ak, kasme); /* Set the Authentication-Info */ ret = fd_msg_avp_new(ogs_diam_s6a_authentication_info, 0, &avp); diff --git a/src/hss/meson.build b/src/hss/meson.build index 9051adc24..57c31ebad 100644 --- a/src/hss/meson.build +++ b/src/hss/meson.build @@ -16,10 +16,8 @@ # along with this program. If not, see . libhss_sources = files(''' - hss-auc.h hss-context.h hss-fd-path.h - hss-auc.c hss-init.c hss-context.c hss-fd-path.c diff --git a/src/mme/emm-build.c b/src/mme/emm-build.c index eecbc6b5d..0dde516db 100644 --- a/src/mme/emm-build.c +++ b/src/mme/emm-build.c @@ -240,30 +240,6 @@ ogs_pkbuf_t *emm_build_security_mode_command(mme_ue_t *mme_ue) *replayed_ue_additional_security_capability = &security_mode_command->replayed_ue_additional_security_capability; -#if 0 - char *_reg = (char *) - "0741720bf632f540 800101dde9c6cf07 f0f0c04001001000 230201d031271d80" - "8021100101001081 0600000000830600 000000000300000a 00000d005232f540" - "00015c20001332f5 40000111034f1880 5d0105e010028dc0 6f04f000f000"; - uint8_t tmp[OGS_MAX_SDU_LEN]; - uint8_t s[OGS_MAX_SDU_LEN]; - uint16_t len; - uint8_t key[32]; - uint8_t output[OGS_SHA256_DIGEST_SIZE]; - - OGS_HEX(_reg, strlen(_reg), tmp); - - memcpy(s, tmp, 94); - - len = htobe16(94); - memcpy(&s[94], &len, sizeof(len)); - memset(key, 0, 32); - - ogs_hmac_sha256(key, 32, s, 94, output, OGS_SHA256_DIGEST_SIZE); - ogs_fatal("output"); - ogs_log_hexdump(OGS_LOG_FATAL, output, 32); -#endif - ogs_assert(mme_ue); memset(&message, 0, sizeof(message)); diff --git a/src/mme/emm-sm.c b/src/mme/emm-sm.c index 8ba14e75e..99f8ea20c 100644 --- a/src/mme/emm-sm.c +++ b/src/mme/emm-sm.c @@ -96,6 +96,7 @@ static void common_register_state(ogs_fsm_t *s, mme_event_t *e) mme_ue_t *mme_ue = NULL; enb_ue_t *enb_ue = NULL; ogs_nas_eps_message_t *message = NULL; + ogs_nas_security_header_type_t h; ogs_assert(e); @@ -114,6 +115,8 @@ static void common_register_state(ogs_fsm_t *s, mme_event_t *e) enb_ue = mme_ue->enb_ue; ogs_assert(enb_ue); + h.type = e->nas_type; + if (message->emm.h.security_header_type == OGS_NAS_SECURITY_HEADER_FOR_SERVICE_REQUEST_MESSAGE) { ogs_debug("[EMM] Service request"); @@ -198,7 +201,7 @@ static void common_register_state(ogs_fsm_t *s, mme_event_t *e) break; } - if (SECURITY_CONTEXT_IS_VALID(mme_ue)) { + if (h.integrity_protected && SECURITY_CONTEXT_IS_VALID(mme_ue)) { rv = nas_eps_send_emm_to_esm(mme_ue, &mme_ue->pdn_connectivity_request); if (rv != OGS_OK) { diff --git a/src/mme/mme-context.c b/src/mme/mme-context.c index a8bd3705f..131b24d07 100644 --- a/src/mme/mme-context.c +++ b/src/mme/mme-context.c @@ -592,7 +592,7 @@ int mme_context_parse_config() family != AF_INET && family != AF_INET6) { ogs_warn("Ignore family(%d) : " "AF_UNSPEC(%d), " - "AF_INET(%d), AF_INET6(%d) ", + "AF_INET(%d), AF_INET6(%d) ", family, AF_UNSPEC, AF_INET, AF_INET6); family = AF_UNSPEC; } @@ -1153,7 +1153,7 @@ int mme_context_parse_config() ogs_assert(hostname_num <= OGS_MAX_NUM_OF_HOSTNAME); - hostname[hostname_num++] = + hostname[hostname_num++] = ogs_yaml_iter_value(&hostname_iter); } while ( ogs_yaml_iter_type(&hostname_iter) == diff --git a/src/mme/s1ap-build.c b/src/mme/s1ap-build.c index 84cedfc1d..9881f0c56 100644 --- a/src/mme/s1ap-build.c +++ b/src/mme/s1ap-build.c @@ -2148,265 +2148,6 @@ ogs_pkbuf_t *s1ap_build_mme_status_transfer( return ogs_s1ap_encode(&pdu); } -ogs_pkbuf_t *s1ap_build_error_indication( - S1AP_MME_UE_S1AP_ID_t *mme_ue_s1ap_id, - S1AP_ENB_UE_S1AP_ID_t *enb_ue_s1ap_id, - S1AP_Cause_PR group, long cause) -{ - S1AP_S1AP_PDU_t pdu; - S1AP_InitiatingMessage_t *initiatingMessage = NULL; - S1AP_ErrorIndication_t *ErrorIndication = NULL; - - S1AP_ErrorIndicationIEs_t *ie = NULL; - S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; - S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; - S1AP_Cause_t *Cause = NULL; - - ogs_debug("[MME] Error Indication"); - - memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage = - CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); - - initiatingMessage = pdu.choice.initiatingMessage; - initiatingMessage->procedureCode = S1AP_ProcedureCode_id_ErrorIndication; - initiatingMessage->criticality = S1AP_Criticality_ignore; - initiatingMessage->value.present = - S1AP_InitiatingMessage__value_PR_ErrorIndication; - - ErrorIndication = &initiatingMessage->value.choice.ErrorIndication; - - if (mme_ue_s1ap_id) { - ie = CALLOC(1, sizeof(S1AP_ErrorIndicationIEs_t)); - ASN_SEQUENCE_ADD(&ErrorIndication->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_ErrorIndicationIEs__value_PR_MME_UE_S1AP_ID; - - MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; - - *MME_UE_S1AP_ID = *mme_ue_s1ap_id; - ogs_debug(" MME_UE_S1AP_ID[%d]", (int)*mme_ue_s1ap_id); - } - - if (enb_ue_s1ap_id) { - ie = CALLOC(1, sizeof(S1AP_ErrorIndicationIEs_t)); - ASN_SEQUENCE_ADD(&ErrorIndication->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_ErrorIndicationIEs__value_PR_ENB_UE_S1AP_ID; - - ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; - - *ENB_UE_S1AP_ID = *enb_ue_s1ap_id; - ogs_debug(" ENB_UE_S1AP_ID[%d]", (int)*enb_ue_s1ap_id); - } - - ie = CALLOC(1, sizeof(S1AP_ErrorIndicationIEs_t)); - ASN_SEQUENCE_ADD(&ErrorIndication->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_Cause; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_ErrorIndicationIEs__value_PR_Cause; - - Cause = &ie->value.choice.Cause; - - Cause->present = group; - Cause->choice.radioNetwork = cause; - - ogs_debug(" Group[%d] Cause[%d]", - Cause->present, (int)Cause->choice.radioNetwork); - - return ogs_s1ap_encode(&pdu); -} - -ogs_pkbuf_t *s1ap_build_s1_reset( - S1AP_Cause_PR group, long cause, - S1AP_UE_associatedLogicalS1_ConnectionListRes_t *partOfS1_Interface) -{ - S1AP_S1AP_PDU_t pdu; - S1AP_InitiatingMessage_t *initiatingMessage = NULL; - S1AP_Reset_t *Reset = NULL; - - S1AP_ResetIEs_t *ie = NULL; - S1AP_Cause_t *Cause = NULL; - S1AP_ResetType_t *ResetType = NULL; - - ogs_debug("[MME] Reset"); - - memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage = - CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); - - initiatingMessage = pdu.choice.initiatingMessage; - initiatingMessage->procedureCode = S1AP_ProcedureCode_id_Reset; - initiatingMessage->criticality = S1AP_Criticality_ignore; - initiatingMessage->value.present = - S1AP_InitiatingMessage__value_PR_Reset; - - Reset = &initiatingMessage->value.choice.Reset; - - ie = CALLOC(1, sizeof(S1AP_ResetIEs_t)); - ASN_SEQUENCE_ADD(&Reset->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_Cause; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_ResetIEs__value_PR_Cause; - - Cause = &ie->value.choice.Cause; - - ie = CALLOC(1, sizeof(S1AP_ResetIEs_t)); - ASN_SEQUENCE_ADD(&Reset->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_ResetType; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_ResetIEs__value_PR_ResetType; - - ResetType = &ie->value.choice.ResetType; - - Cause->present = group; - Cause->choice.radioNetwork = cause; - - ogs_debug(" Group[%d] Cause[%d] partOfS1_Interface[%p]", - Cause->present, (int)Cause->choice.radioNetwork, partOfS1_Interface); - - if (partOfS1_Interface) { - ResetType->present = S1AP_ResetType_PR_partOfS1_Interface; - ResetType->choice.partOfS1_Interface = partOfS1_Interface; - } else { - ResetType->present = S1AP_ResetType_PR_s1_Interface; - ResetType->choice.s1_Interface = S1AP_ResetAll_reset_all; - } - - return ogs_s1ap_encode(&pdu); -} - -ogs_pkbuf_t *s1ap_build_s1_reset_partial( - S1AP_Cause_PR group, long cause, - S1AP_MME_UE_S1AP_ID_t *mme_ue_s1ap_id, - S1AP_ENB_UE_S1AP_ID_t *enb_ue_s1ap_id) -{ - S1AP_UE_associatedLogicalS1_ConnectionListRes_t *partOfS1_Interface = NULL; - S1AP_UE_associatedLogicalS1_ConnectionItemRes_t *ie2 = NULL; - S1AP_UE_associatedLogicalS1_ConnectionItem_t *item = NULL; - - partOfS1_Interface = CALLOC(1, - sizeof(S1AP_UE_associatedLogicalS1_ConnectionListRes_t)); - ogs_assert(partOfS1_Interface); - - ie2 = CALLOC(1, - sizeof(S1AP_UE_associatedLogicalS1_ConnectionItemRes_t)); - ASN_SEQUENCE_ADD(&partOfS1_Interface->list, ie2); - - ie2->id = S1AP_ProtocolIE_ID_id_UE_associatedLogicalS1_ConnectionItem; - ie2->criticality = S1AP_Criticality_reject; - ie2->value.present = S1AP_UE_associatedLogicalS1_ConnectionItemRes__value_PR_UE_associatedLogicalS1_ConnectionItem; - - item = &ie2->value.choice.UE_associatedLogicalS1_ConnectionItem; - item->mME_UE_S1AP_ID = mme_ue_s1ap_id; - item->eNB_UE_S1AP_ID = enb_ue_s1ap_id; - - return s1ap_build_s1_reset(group, cause, partOfS1_Interface); -} - -ogs_pkbuf_t *s1ap_build_s1_reset_ack( - S1AP_UE_associatedLogicalS1_ConnectionListRes_t *partOfS1_Interface) -{ - S1AP_S1AP_PDU_t pdu; - S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; - S1AP_ResetAcknowledge_t *ResetAcknowledge = NULL; - - S1AP_ResetAcknowledgeIEs_t *ie = NULL; - - ogs_debug("[MME] Reset acknowledge"); - - memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome = - CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); - - successfulOutcome = pdu.choice.successfulOutcome; - successfulOutcome->procedureCode = S1AP_ProcedureCode_id_Reset; - successfulOutcome->criticality = S1AP_Criticality_reject; - successfulOutcome->value.present = - S1AP_SuccessfulOutcome__value_PR_ResetAcknowledge; - - ResetAcknowledge = &successfulOutcome->value.choice.ResetAcknowledge; - - if (partOfS1_Interface && partOfS1_Interface->list.count) { - int i = 0; - S1AP_UE_associatedLogicalS1_ConnectionListResAck_t *list = NULL; - - ie = CALLOC(1, sizeof(S1AP_ResetAcknowledgeIEs_t)); - ASN_SEQUENCE_ADD(&ResetAcknowledge->protocolIEs, ie); - - ie->id = - S1AP_ProtocolIE_ID_id_UE_associatedLogicalS1_ConnectionListResAck; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_ResetAcknowledgeIEs__value_PR_UE_associatedLogicalS1_ConnectionListResAck; - - list = &ie->value.choice.UE_associatedLogicalS1_ConnectionListResAck; - - for (i = 0; i < partOfS1_Interface->list.count; i++) { - S1AP_UE_associatedLogicalS1_ConnectionItemRes_t *ie1 = NULL; - S1AP_UE_associatedLogicalS1_ConnectionItem_t *item1 = NULL; - - S1AP_UE_associatedLogicalS1_ConnectionItemResAck_t *ie2 = NULL; - S1AP_UE_associatedLogicalS1_ConnectionItem_t *item2 = NULL; - - ie1 = (S1AP_UE_associatedLogicalS1_ConnectionItemRes_t *) - partOfS1_Interface->list.array[i]; - ogs_assert(ie1); - - item1 = &ie1->value.choice.UE_associatedLogicalS1_ConnectionItem; - ogs_assert(item1); - - if (item1->mME_UE_S1AP_ID == NULL && - item1->eNB_UE_S1AP_ID == NULL) { - ogs_warn("No MME_UE_S1AP_ID & ENB_UE_S1AP_ID"); - continue; - } - - ie2 = CALLOC(1, - sizeof(S1AP_UE_associatedLogicalS1_ConnectionItemResAck_t)); - ogs_assert(ie2); - ASN_SEQUENCE_ADD(&list->list, ie2); - - ie2->id = - S1AP_ProtocolIE_ID_id_UE_associatedLogicalS1_ConnectionItem; - ie2->criticality = S1AP_Criticality_ignore; - ie2->value.present = S1AP_UE_associatedLogicalS1_ConnectionItemResAck__value_PR_UE_associatedLogicalS1_ConnectionItem; - - item2 = &ie2->value.choice.UE_associatedLogicalS1_ConnectionItem; - ogs_assert(item2); - - if (item1->mME_UE_S1AP_ID) { - item2->mME_UE_S1AP_ID = CALLOC(1, - sizeof(S1AP_MME_UE_S1AP_ID_t)); - ogs_assert(item2->mME_UE_S1AP_ID); - *item2->mME_UE_S1AP_ID = *item1->mME_UE_S1AP_ID; - } - - if (item1->eNB_UE_S1AP_ID) { - item2->eNB_UE_S1AP_ID = CALLOC(1, - sizeof(S1AP_ENB_UE_S1AP_ID_t)); - ogs_assert(item2->eNB_UE_S1AP_ID); - *item2->eNB_UE_S1AP_ID = *item1->eNB_UE_S1AP_ID; - } - - ogs_debug(" MME_UE_S1AP_ID[%d] ENB_UE_S1AP_ID[%d]", - item2->mME_UE_S1AP_ID ? (int)*item2->mME_UE_S1AP_ID : -1, - item2->eNB_UE_S1AP_ID ? (int)*item2->eNB_UE_S1AP_ID : -1); - } - } - - return ogs_s1ap_encode(&pdu); -} - ogs_pkbuf_t *s1ap_build_write_replace_warning_request(sbc_pws_data_t *sbc_pws) { S1AP_S1AP_PDU_t pdu; diff --git a/src/mme/s1ap-build.h b/src/mme/s1ap-build.h index 62c5317f2..28c81273a 100644 --- a/src/mme/s1ap-build.h +++ b/src/mme/s1ap-build.h @@ -80,23 +80,6 @@ ogs_pkbuf_t *s1ap_build_mme_status_transfer( S1AP_ENB_StatusTransfer_TransparentContainer_t *enb_statustransfer_transparentContainer); -ogs_pkbuf_t *s1ap_build_error_indication( - S1AP_MME_UE_S1AP_ID_t *mme_ue_s1ap_id, - S1AP_ENB_UE_S1AP_ID_t *enb_ue_s1ap_id, - S1AP_Cause_PR group, long cause); - -ogs_pkbuf_t *s1ap_build_s1_reset( - S1AP_Cause_PR group, long cause, - S1AP_UE_associatedLogicalS1_ConnectionListRes_t *partOfS1_Interface); - -ogs_pkbuf_t *s1ap_build_s1_reset_partial( - S1AP_Cause_PR group, long cause, - S1AP_MME_UE_S1AP_ID_t *mme_ue_s1ap_id, - S1AP_ENB_UE_S1AP_ID_t *enb_ue_s1ap_id); - -ogs_pkbuf_t *s1ap_build_s1_reset_ack( - S1AP_UE_associatedLogicalS1_ConnectionListRes_t *partOfS1_Interface); - ogs_pkbuf_t *s1ap_build_write_replace_warning_request( sbc_pws_data_t *sbc_pws); diff --git a/src/mme/s1ap-handler.c b/src/mme/s1ap-handler.c index 7a7d2fc13..dae0580b0 100644 --- a/src/mme/s1ap-handler.c +++ b/src/mme/s1ap-handler.c @@ -1287,8 +1287,8 @@ void s1ap_handle_enb_configuration_transfer( target_enb = mme_enb_find_by_enb_id(target_enb_id); if (target_enb == NULL) { - ogs_warn("eNB configuration transfer : cannot find target eNB-id[%d]", - target_enb_id); + ogs_warn("eNB configuration transfer : " + "cannot find target eNB-id[0x%x]", target_enb_id); return; } diff --git a/src/mme/s1ap-path.c b/src/mme/s1ap-path.c index 05ad4cfa1..5c5a7e599 100644 --- a/src/mme/s1ap-path.c +++ b/src/mme/s1ap-path.c @@ -521,7 +521,7 @@ void s1ap_send_error_indication( ogs_assert(enb); - s1apbuf = s1ap_build_error_indication( + s1apbuf = ogs_s1ap_build_error_indication( mme_ue_s1ap_id, enb_ue_s1ap_id, group, cause); ogs_expect_or_return(s1apbuf); @@ -538,7 +538,7 @@ void s1ap_send_s1_reset_ack( ogs_assert(enb); - s1apbuf = s1ap_build_s1_reset_ack(partOfS1_Interface); + s1apbuf = ogs_s1ap_build_s1_reset_ack(partOfS1_Interface); ogs_expect_or_return(s1apbuf); rv = s1ap_send_to_enb(enb, s1apbuf, S1AP_NON_UE_SIGNALLING); diff --git a/tests/00101/abts-main.c b/tests/00101/abts-main.c deleted file mode 100644 index b72e05f50..000000000 --- a/tests/00101/abts-main.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "test-5gc.h" - -abts_suite *test_issues_482(abts_suite *suite); -abts_suite *test_issues_508(abts_suite *suite); - -const struct testlist { - abts_suite *(*func)(abts_suite *suite); -} alltests[] = { - {test_issues_482}, - {test_issues_508}, - {NULL}, -}; - -static void terminate(void) -{ - ogs_msleep(50); - - test_child_terminate(); - app_terminate(); - - test_5gc_final(); - ogs_app_terminate(); -} - -static void initialize(const char *const argv[]) -{ - int rv; - - rv = ogs_app_initialize(NULL, argv); - ogs_assert(rv == OGS_OK); - test_5gc_init(); - - rv = app_initialize(argv); - ogs_assert(rv == OGS_OK); -} - -int main(int argc, const char *const argv[]) -{ - int i; - abts_suite *suite = NULL; - - atexit(terminate); - test_5gc_run(argc, argv, "00101.yaml", initialize); - - for (i = 0; alltests[i].func; i++) - suite = alltests[i].func(suite); - - return abts_report(suite); -} diff --git a/tests/00101/issues-482-test.c b/tests/00101/issues-482-test.c deleted file mode 100644 index ecfab1a0e..000000000 --- a/tests/00101/issues-482-test.c +++ /dev/null @@ -1,406 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "test-5gc.h" - -static void test1_func(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *ngap; - ogs_socknode_t *gtpu; - ogs_pkbuf_t *gmmbuf; - ogs_pkbuf_t *gsmbuf; - ogs_pkbuf_t *nasbuf; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_ngap_message_t message; - int i; - int msgindex = 0; - - ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; - - const char *_k_string = "00112233445566778899aabbccddeeff"; - uint8_t k[OGS_KEY_LEN]; - const char *_opc_string = "279eb54971771559879284fddde3ee0c"; - uint8_t opc[OGS_KEY_LEN]; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " - "\"imsi\" : \"001010000000001\"," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"security\" : { " - "\"k\" : \"00112233445566778899aabbccddeeff\", " - "\"opc\" : \"279eb54971771559879284fddde3ee0c\", " - "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"32\" } " - "}, " - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"__v\" : 0 " - "}"; - - /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); - - mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; - mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); - mobile_identity_suci.routing_indicator1 = 0; - mobile_identity_suci.routing_indicator2 = 0xf; - mobile_identity_suci.routing_indicator3 = 0xf; - mobile_identity_suci.routing_indicator4 = 0xf; - mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; - mobile_identity_suci.home_network_pki_value = 0; - mobile_identity_suci.scheme_output[0] = 0; - mobile_identity_suci.scheme_output[1] = 0; - mobile_identity_suci.scheme_output[2] = 0; - mobile_identity_suci.scheme_output[3] = 0; - mobile_identity_suci.scheme_output[4] = 0x10; - - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); - - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; - - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; - - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); - - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 0; - - /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); - ABTS_PTR_NOTNULL(tc, ngap); - - /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); - ABTS_PTR_NOTNULL(tc, gtpu); - - /* Send NG-Setup Reqeust */ - sendbuf = testngap_build_ng_setup_request(0xce, 31); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive NG-Setup Response */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /********** Insert Subscriber in Database */ - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - if (count) { - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - } - bson_destroy(doc); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /* To start RAN-UE-NGAP-ID : 0 */ - test_ue.ran_ue_ngap_id = -1; - test_self()->nr_cgi.cell_id = 0x000000ce7; - - /* Send Registration request */ - test_ue.registration_request_param.guti = 1; - test_ue.registration_request_param.gmm_capability = 1; - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); - ABTS_PTR_NOTNULL(tc, gmmbuf); - - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); - ABTS_PTR_NOTNULL(tc, nasbuf); - - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Indentity request */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send Identity response */ - gmmbuf = testgmm_build_identity_response(&test_ue); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication request */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send Authentication failure - SYNCH failure */ - gmmbuf = testgmm_build_authentication_failure( - &test_ue, OGS_5GMM_CAUSE_SYNCH_FAILURE, 0x1f60); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication request */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode command */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial context setup request */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Configuration update command */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = - OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; - - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); - ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, - OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive PDU session establishment accept */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive GTP-U ICMP Packet */ - recvbuf = testgnb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive GTP-U ICMP Packet */ - recvbuf = testgnb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send De-registration request */ - gmmbuf = testgmm_build_de_registration_request(&test_ue, 1); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive UE context release command */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* gNB disonncect from UPF */ - testgnb_gtpu_close(gtpu); - - /* gNB disonncect from AMF */ - testgnb_ngap_close(ngap); - - /* Clear Test UE Context */ - test_ue_remove(&test_ue); -} - -abts_suite *test_issues_482(abts_suite *suite) -{ - suite = ADD_SUITE(suite) - - abts_run_test(suite, test1_func, NULL); - - return suite; -} diff --git a/tests/00101/issues-508-test.c b/tests/00101/issues-508-test.c deleted file mode 100644 index d9b4452a0..000000000 --- a/tests/00101/issues-508-test.c +++ /dev/null @@ -1,467 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "test-5gc.h" - -static void test1_func(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *ngap; - ogs_socknode_t *gtpu; - ogs_pkbuf_t *gmmbuf; - ogs_pkbuf_t *gsmbuf; - ogs_pkbuf_t *nasbuf; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_ngap_message_t message; - int i; - int msgindex = 0; - - ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; - - const char *_k_string = "00112233445566778899aabbccddeeff"; - uint8_t k[OGS_KEY_LEN]; - const char *_opc_string = "279eb54971771559879284fddde3ee0c"; - uint8_t opc[OGS_KEY_LEN]; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " - "\"imsi\" : \"001010000000001\"," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"security\" : { " - "\"k\" : \"00112233445566778899aabbccddeeff\", " - "\"opc\" : \"279eb54971771559879284fddde3ee0c\", " - "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"32\" } " - "}, " - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"__v\" : 0 " - "}"; - - /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); - - mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; - mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); - mobile_identity_suci.routing_indicator1 = 0; - mobile_identity_suci.routing_indicator2 = 0xf; - mobile_identity_suci.routing_indicator3 = 0xf; - mobile_identity_suci.routing_indicator4 = 0xf; - mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; - mobile_identity_suci.home_network_pki_value = 0; - mobile_identity_suci.scheme_output[0] = 0; - mobile_identity_suci.scheme_output[1] = 0; - mobile_identity_suci.scheme_output[2] = 0; - mobile_identity_suci.scheme_output[3] = 0; - mobile_identity_suci.scheme_output[4] = 0x10; - - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); - - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; - - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; - - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); - - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 0; - - /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); - ABTS_PTR_NOTNULL(tc, ngap); - - /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); - ABTS_PTR_NOTNULL(tc, gtpu); - - /* Send NG-Setup Reqeust */ - sendbuf = testngap_build_ng_setup_request(0xce, 31); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive NG-Setup Response */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /********** Insert Subscriber in Database */ - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - if (count) { - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - } - bson_destroy(doc); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /* To start RAN-UE-NGAP-ID : 0 */ - test_ue.ran_ue_ngap_id = -1; - test_self()->nr_cgi.cell_id = 0x000000ce7; - - /* Send Registration request */ - test_ue.registration_request_param.guti = 1; - test_ue.registration_request_param.gmm_capability = 1; - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); - ABTS_PTR_NOTNULL(tc, gmmbuf); - - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); - ABTS_PTR_NOTNULL(tc, nasbuf); - - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Indentity request */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send Identity response */ - gmmbuf = testgmm_build_identity_response(&test_ue); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication request */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send Authentication failure - SYNCH failure */ - gmmbuf = testgmm_build_authentication_failure( - &test_ue, OGS_5GMM_CAUSE_SYNCH_FAILURE, 0x1f60); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication request */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode command */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial context setup request */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Configuration update command */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = - OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; - - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); - ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, - OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); - ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive PDU session establishment accept */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive GTP-U ICMP Packet */ - recvbuf = testgnb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive GTP-U ICMP Packet */ - recvbuf = testgnb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE context release request */ - sendbuf = testngap_build_ue_context_release_request(&test_ue, - NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_user_inactivity, - true); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive UE context release command */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - - /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* - * Send Service request Using InitialUEMessage - * - Uplink Data Status - */ - test_ue.service_request_param.integrity_protected = 0; - test_ue.service_request_param.uplink_data_status = 1; - test_ue.service_request_param. - psimask.uplink_data_status = 1 << test_sess.psi; - test_ue.service_request_param.pdu_session_status = 0; - nasbuf = testgmm_build_service_request(&test_ue, NULL); - ABTS_PTR_NOTNULL(tc, nasbuf); - - test_ue.service_request_param.integrity_protected = 1; - test_ue.service_request_param.uplink_data_status = 0; - test_ue.service_request_param.pdu_session_status = 0; - gmmbuf = testgmm_build_service_request(&test_ue, nasbuf); - ABTS_PTR_NOTNULL(tc, gmmbuf); - - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Service accept */ - recvbuf = testgnb_ngap_read(ngap); - ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_status); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_reactivation_result); - - test_sess.gnb_n3_teid = 5; - - /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response( - &test_ue, &test_sess); - ABTS_PTR_NOTNULL(tc, sendbuf); - rv = testgnb_ngap_send(ngap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive GTP-U ICMP Packet */ - recvbuf = testgnb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive GTP-U ICMP Packet */ - recvbuf = testgnb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* gNB disonncect from UPF */ - testgnb_gtpu_close(gtpu); - - /* gNB disonncect from AMF */ - testgnb_ngap_close(ngap); - - /* Clear Test UE Context */ - test_ue_remove(&test_ue); -} - -abts_suite *test_issues_508(abts_suite *suite) -{ - suite = ADD_SUITE(suite) - - abts_run_test(suite, test1_func, NULL); - - return suite; -} diff --git a/tests/00101/meson.build b/tests/00101/meson.build deleted file mode 100644 index 5b05ff594..000000000 --- a/tests/00101/meson.build +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (C) 2019,2020 by Sukchan Lee - -# This file is part of Open5GS. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -test5gc_00101_sources = files(''' - abts-main.c - issues-482-test.c - issues-508-test.c -'''.split()) - -test5gc_00101_exe = executable('00101', - sources : test5gc_00101_sources, - c_args : testunit_core_cc_flags, - dependencies : libtest5gc_dep) diff --git a/tests/23504/r16-test.c b/tests/23504/r16-test.c deleted file mode 100644 index 6e9891e6b..000000000 --- a/tests/23504/r16-test.c +++ /dev/null @@ -1,627 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "test-epc.h" - -static void test1_func(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_socknode_t *gtpu; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 24; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; - - test_ue_t test_ue; - - const char *_k_string = "4d060eab0a7743bc8eede608a94b63de"; - uint8_t k[OGS_KEY_LEN]; - const char *_opc_string = "7c0f7d5a427048a86fb429cc003c117c"; - uint8_t opc[OGS_KEY_LEN]; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"235047364000060\", " - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1000000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 15," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1000000\" } " - "}," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"security\" : { " - "\"k\" : \"4d060eab0a7743bc8eede608a94b63de\", " - "\"opc\" : \"7c0f7d5a427048a86fb429cc003c117c\", " - "\"amf\" : \"9001\", " - "\"sqn\" : { \"$numberLong\" : \"7085\" }, " - "\"rand\" : \"198e06800ea7a4c61e9e424f2558a774\" " - "}, " - "\"__v\" : 0 " - "}"; - - /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - test_ue.imsi = (char *)"235047364000060"; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* eNB connects to SGW */ - gtpu = testenb_gtpu_server("127.0.0.5"); - ABTS_PTR_NOTNULL(tc, gtpu); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x2000, 1, 235, 4, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - /********** Insert Subscriber in Database */ - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - if (count) { - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - } - bson_destroy(doc); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - /* Send Attach Request */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Identity Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 16777373, 1, 5, 1, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); - - /* eNB disonncect from SGW */ - testenb_gtpu_close(gtpu); -} - -static void test2_func(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_socknode_t *gtpu; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 25; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; - - test_ue_t test_ue; - - const char *_k_string = "4d060eab0a7743bc8eede608a94b63de"; - uint8_t k[OGS_KEY_LEN]; - const char *_opc_string = "7c0f7d5a427048a86fb429cc003c117c"; - uint8_t opc[OGS_KEY_LEN]; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"235047364000060\", " - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1000000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 15," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1000000\" } " - "}," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"security\" : { " - "\"k\" : \"4d060eab0a7743bc8eede608a94b63de\", " - "\"opc\" : \"7c0f7d5a427048a86fb429cc003c117c\", " - "\"amf\" : \"9001\", " - "\"sqn\" : { \"$numberLong\" : \"9034\" }, " - "\"rand\" : \"bb17c5f251e2ff6a528a9e9f70248ed9\" " - "}, " - "\"__v\" : 0 " - "}"; - - /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - test_ue.imsi = (char *)"235047364000060"; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* eNB connects to SGW */ - gtpu = testenb_gtpu_server("127.0.0.5"); - ABTS_PTR_NOTNULL(tc, gtpu); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x2000, 1, 235, 4, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - /********** Insert Subscriber in Database */ - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - if (count) { - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - } - bson_destroy(doc); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - /* Send Attach Request */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 1, 1, 5, 0x10783d92, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); - - /* eNB disonncect from SGW */ - testenb_gtpu_close(gtpu); -} - -static void test3_func(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_socknode_t *gtpu; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 26; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; - - test_ue_t test_ue; - - const char *_k_string = "4d060eab0a7743bc8eede608a94b63de"; - uint8_t k[OGS_KEY_LEN]; - const char *_opc_string = "7c0f7d5a427048a86fb429cc003c117c"; - uint8_t opc[OGS_KEY_LEN]; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"235047364000060\", " - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1000000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 15," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1000000\" } " - "}," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"security\" : { " - "\"k\" : \"4d060eab0a7743bc8eede608a94b63de\", " - "\"opc\" : \"7c0f7d5a427048a86fb429cc003c117c\", " - "\"amf\" : \"9001\", " - "\"sqn\" : { \"$numberLong\" : \"8968\" }, " - "\"rand\" : \"5616d4deb87e39be6259ef8e5c753c0b\" " - "}, " - "\"__v\" : 0 " - "}"; - - /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - test_ue.imsi = (char *)"235047364000060"; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* eNB connects to SGW */ - gtpu = testenb_gtpu_server("127.0.0.5"); - ABTS_PTR_NOTNULL(tc, gtpu); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x2000, 1, 235, 4, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - /********** Insert Subscriber in Database */ - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - if (count) { - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - } - bson_destroy(doc); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - /* Send Attach Request */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 1, 1, 5, 0x1654c84e, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); - - /* eNB disonncect from SGW */ - testenb_gtpu_close(gtpu); -} - -abts_suite *test_r16(abts_suite *suite) -{ - suite = ADD_SUITE(suite) - - abts_run_test(suite, test1_func, NULL); - abts_run_test(suite, test2_func, NULL); - abts_run_test(suite, test3_func, NULL); - - return suite; -} diff --git a/tests/mnc3/abts-main.c b/tests/310014/abts-main.c similarity index 92% rename from tests/mnc3/abts-main.c rename to tests/310014/abts-main.c index fd481e7bf..f4d4987c7 100644 --- a/tests/mnc3/abts-main.c +++ b/tests/310014/abts-main.c @@ -19,12 +19,12 @@ #include "test-app.h" -abts_suite *test_mnc3(abts_suite *suite); +abts_suite *test_epc(abts_suite *suite); const struct testlist { abts_suite *(*func)(abts_suite *suite); } alltests[] = { - {test_mnc3}, + {test_epc}, {NULL}, }; @@ -57,7 +57,7 @@ int main(int argc, const char *const argv[]) abts_suite *suite = NULL; atexit(terminate); - test_5gc_run(argc, argv, "mnc3.yaml", initialize); + test_app_run(argc, argv, "310014.yaml", initialize); for (i = 0; alltests[i].func; i++) suite = alltests[i].func(suite); diff --git a/tests/mnc3/mnc3-test.c b/tests/310014/epc-test.c similarity index 53% rename from tests/mnc3/mnc3-test.c rename to tests/310014/epc-test.c index 49c0abb0b..6b39e8a8a 100644 --- a/tests/mnc3/mnc3-test.c +++ b/tests/310014/epc-test.c @@ -17,50 +17,27 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-common.h" static void test1_func(abts_case *tc, void *data) { int rv; ogs_socknode_t *s1ap; ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; ogs_pkbuf_t *sendbuf; ogs_pkbuf_t *recvbuf; ogs_s1ap_message_t message; - int i; - int msgindex = 15; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; - uint8_t tmp[OGS_MAX_SDU_LEN]; - const char *_authentication_request = - "000b403800000300 0000020001000800 020018001a002524 075200906d231ff5" - "7ef278c7191d1703 03deb610d07c4def a47480001f2b5350 926bdb3a"; - const char *_security_mode_command = - "000b402c00000300 0000020001000800 020018001a001918 37b4fe6e2700075d" - "010002e0e0c14f08 d14b7a88d1d1d02e"; - const char *_esm_information_request = - "000b401d00000300 0000020001000800 020018001a000a09 27846a01a8010201" - "d9"; - const char *_initial_context_setup_request = - "00090080bf000006 0000000200010008 000200180042000a 183d090000603d09" - "0000001800710000 34006c4500093d0f 807f000007000000 025d2722ab599e02" - "074201490c031340 1000320033003400 3500315201c10109 0c0773746172656e" - "7403636f6d05010a 2d00025e06fefee2 e20303270f80000d 0408080808000d04" - "08080404500bf613 4010801e64e400ae b859496402010800 6b000518000c0000" - "0049002046c789cb a93e9b97758335c0 97e6c386c872e4b8 2434a48037c30601" - "590edd8e"; - const char *_emm_information = - "000b403800000300 0000020001000800 020018001a002524 27e211a94a030761" - "430f10004f007000 65006e0035004700 5347028040325204 69490100"; + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; - test_ue_t test_ue; - test_sess_t test_sess; - - const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + const char *_k_string = "4d060eab0a7743bc8eede608a94b63de"; uint8_t k[OGS_KEY_LEN]; - const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + const char *_opc_string = "7c0f7d5a427048a86fb429cc003c117c"; uint8_t opc[OGS_KEY_LEN]; mongoc_collection_t *collection = NULL; @@ -77,7 +54,7 @@ static void test1_func(abts_case *tc, void *data) #endif "\"pdn\" : [" "{" - "\"apn\" : \"starent.com\", " + "\"apn\" : \"internet\", " "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " "\"ambr\" : {" "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " @@ -90,7 +67,7 @@ static void test1_func(abts_case *tc, void *data) "\"qci\" : 9, " "\"arp\" : { " "\"priority_level\" : 15," - "\"pre_emption_vulnerability\" : 0, " + "\"pre_emption_vulnerability\" : 1, " "\"pre_emption_capability\" : 1" "} " "}, " @@ -106,58 +83,69 @@ static void test1_func(abts_case *tc, void *data) "\"subscriber_status\" : 0, " "\"access_restriction_data\" : 32, " "\"security\" : { " - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " - "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"k\" : \"4d060eab0a7743bc8eede608a94b63de\", " + "\"opc\" : \"7c0f7d5a427048a86fb429cc003c117c\", " "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"906d231f f57ef278 c7191d17 0303deb6\" " + "\"sqn\" : { \"$numberLong\" : \"64\" } " "}, " "\"__v\" : 0 " "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); - test_ue.imsi = (char *)"310014987654004"; + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x89; + mobile_identity_suci.scheme_output[1] = 0x67; + mobile_identity_suci.scheme_output[2] = 0x45; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0xf4; - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr(TEST_GNB_IPV4); - test_sess.gnb_n3_teid = 0; + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - test_sess.upf_n3_ip.ipv4 = true; - test_sess.upf_n3_ip.addr = inet_addr(TEST_SGWU_IPV4); + test_ue->e_cgi.cell_id = 0x8d01b780; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_EPS_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); /* eNB connects to MME */ - s1ap = testenb_s1ap_client(TEST_MME_IPV4); + s1ap = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, s1ap); /* eNB connects to SGW */ - gtpu = testenb_gtpu_server(TEST_ENB_IPV4); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 51, 310, 14, 3); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1-Setup Response */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(NULL, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -174,7 +162,7 @@ static void test1_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -182,8 +170,22 @@ static void test1_func(abts_case *tc, void *data) } while (count == 0); bson_destroy(doc); + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + /* Send Attach Request */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -191,101 +193,94 @@ static void test1_func(abts_case *tc, void *data) /* Receive Authentication Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_authentication_request, strlen(_authentication_request), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Security mode Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_security_mode_command, strlen(_security_mode_command), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive ESM Information Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_esm_information_request, - strlen(_esm_information_request), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Initial Context Setup Request + - * Attach Accept + + /* Receive Initial Context Setup Request + + * Attach Accept + * Activate Default Bearer Context Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - OGS_HEX(_initial_context_setup_request, - strlen(_initial_context_setup_request), tmp); - ABTS_TRUE(tc, memcmp(recvbuf->data, tmp, 59) == 0); - ABTS_TRUE(tc, memcmp(recvbuf->data+63, tmp+63, 78) == 0); - ABTS_TRUE(tc, memcmp(recvbuf->data+145, tmp+145, 50) == 0); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 1, 24, 5, 1, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive EMM information */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - OGS_HEX(_emm_information, strlen(_emm_information), tmp); - ABTS_TRUE(tc, memcmp(recvbuf->data, tmp, 25) == 0); - ABTS_TRUE(tc, memcmp(recvbuf->data+29, tmp+29, 20) == 0); ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - test_sess.upf_n3_teid = 2; - test_sess.ue_ip.addr = inet_addr("10.45.0.2"); - - rv = test_gtpu_build_ping(&sendbuf, &test_sess, TEST_PING_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_sendto(gtpu, sendbuf, TEST_SGWU_IPV4); + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu, bearer, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ - recvbuf = testenb_gtpu_read(gtpu); + recvbuf = test_gtpu_read(gtpu); ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -297,10 +292,12 @@ static void test1_func(abts_case *tc, void *data) testenb_s1ap_close(s1ap); /* eNB disonncect from SGW */ - testenb_gtpu_close(gtpu); + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); } -abts_suite *test_mnc3(abts_suite *suite) +abts_suite *test_epc(abts_suite *suite) { suite = ADD_SUITE(suite) diff --git a/tests/mnc3/meson.build b/tests/310014/meson.build similarity index 80% rename from tests/mnc3/meson.build rename to tests/310014/meson.build index d2b25dc9e..7a9261862 100644 --- a/tests/mnc3/meson.build +++ b/tests/310014/meson.build @@ -15,14 +15,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -testapp_mnc3_sources = files(''' +testapp_310014_sources = files(''' abts-main.c - mnc3-test.c + epc-test.c '''.split()) -testapp_mnc3_exe = executable('mnc3', - sources : testapp_mnc3_sources, +testapp_310014_exe = executable('310014', + sources : testapp_310014_sources, c_args : testunit_core_cc_flags, dependencies : libtestapp_dep) -test('mnc3', testapp_mnc3_exe, is_parallel : false, suite: 'app') +test('310014', testapp_310014_exe, is_parallel : false, suite: 'app') diff --git a/tests/app/5gc-init.c b/tests/app/5gc-init.c index 1594c1e44..914297903 100644 --- a/tests/app/5gc-init.c +++ b/tests/app/5gc-init.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-5gc.h" +#include "test-app.h" static ogs_thread_t *nrf_thread = NULL; static ogs_thread_t *ausf_thread = NULL; @@ -91,4 +91,6 @@ void test_5gc_final(void) { ogs_dbi_final(); ogs_sctp_final(); + + test_context_final(); } diff --git a/tests/app/app-init.c b/tests/app/app-init.c index 387d18c5b..3053acdd1 100644 --- a/tests/app/app-init.c +++ b/tests/app/app-init.c @@ -21,11 +21,14 @@ static ogs_thread_t *nrf_thread = NULL; static ogs_thread_t *pcrf_thread = NULL; +static ogs_thread_t *hss_thread = NULL; +static ogs_thread_t *ausf_thread = NULL; +static ogs_thread_t *udm_thread = NULL; +static ogs_thread_t *udr_thread = NULL; static ogs_thread_t *upf_thread = NULL; -static ogs_thread_t *smf_thread = NULL; static ogs_thread_t *sgwc_thread = NULL; static ogs_thread_t *sgwu_thread = NULL; -static ogs_thread_t *hss_thread = NULL; +static ogs_thread_t *smf_thread = NULL; static ogs_thread_t *mme_thread = NULL; int app_initialize(const char *const argv[]) @@ -83,16 +86,29 @@ int app_initialize(const char *const argv[]) if (ogs_config()->parameter.no_mme == 0) mme_thread = test_child_create("mme", argv_out); + if (ogs_config()->parameter.no_ausf == 0) + ausf_thread = test_child_create("ausf", argv_out); + if (ogs_config()->parameter.no_udm == 0) + udm_thread = test_child_create("udm", argv_out); + if (ogs_config()->parameter.no_udr == 0) + udr_thread = test_child_create("udr", argv_out); + return OGS_OK;; } void app_terminate(void) { + if (udr_thread) ogs_thread_destroy(udr_thread); + if (udm_thread) ogs_thread_destroy(udm_thread); + if (ausf_thread) ogs_thread_destroy(ausf_thread); + if (mme_thread) ogs_thread_destroy(mme_thread); - if (sgwc_thread) ogs_thread_destroy(sgwc_thread); if (smf_thread) ogs_thread_destroy(smf_thread); + + if (sgwc_thread) ogs_thread_destroy(sgwc_thread); if (sgwu_thread) ogs_thread_destroy(sgwu_thread); if (upf_thread) ogs_thread_destroy(upf_thread); + if (hss_thread) ogs_thread_destroy(hss_thread); if (pcrf_thread) ogs_thread_destroy(pcrf_thread); if (nrf_thread) ogs_thread_destroy(nrf_thread); @@ -102,6 +118,7 @@ void test_app_init(void) { ogs_log_install_domain(&__ogs_sctp_domain, "sctp", OGS_LOG_ERROR); ogs_log_install_domain(&__ogs_s1ap_domain, "s1ap", OGS_LOG_ERROR); + ogs_log_install_domain(&__ogs_s1ap_domain, "ngap", OGS_LOG_ERROR); ogs_log_install_domain(&__ogs_diam_domain, "diam", OGS_LOG_ERROR); ogs_log_install_domain(&__ogs_dbi_domain, "dbi", OGS_LOG_ERROR); ogs_log_install_domain(&__ogs_nas_domain, "nas", OGS_LOG_ERROR); @@ -114,4 +131,6 @@ void test_app_final(void) { ogs_dbi_final(); ogs_sctp_final(); + + test_context_final(); } diff --git a/tests/app/epc-init.c b/tests/app/epc-init.c index 911af7db5..2a1d0ac4d 100644 --- a/tests/app/epc-init.c +++ b/tests/app/epc-init.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-app.h" static ogs_thread_t *nrf_thread = NULL; static ogs_thread_t *pcrf_thread = NULL; @@ -26,11 +26,10 @@ static ogs_thread_t *smf_thread = NULL; static ogs_thread_t *sgwc_thread = NULL; static ogs_thread_t *sgwu_thread = NULL; static ogs_thread_t *hss_thread = NULL; +static ogs_thread_t *mme_thread = NULL; int app_initialize(const char *const argv[]) { - int rv; - const char *argv_out[OGS_ARG_MAX]; bool user_config = false; int i = 0; @@ -81,23 +80,15 @@ int app_initialize(const char *const argv[]) if (ogs_config()->parameter.no_smf == 0) smf_thread = test_child_create("smf", argv_out); - - ogs_sctp_init(ogs_config()->usrsctp.udp_port); - - rv = mme_initialize(); - ogs_assert(rv == OGS_OK); - ogs_info("MME initialize...done"); + if (ogs_config()->parameter.no_mme == 0) + mme_thread = test_child_create("mme", argv_out); return OGS_OK;; } void app_terminate(void) { - mme_terminate(); - - ogs_sctp_final(); - ogs_info("MME terminate...done"); - + if (mme_thread) ogs_thread_destroy(mme_thread); if (sgwc_thread) ogs_thread_destroy(sgwc_thread); if (smf_thread) ogs_thread_destroy(smf_thread); if (sgwu_thread) ogs_thread_destroy(sgwu_thread); @@ -115,5 +106,14 @@ void test_epc_init(void) ogs_log_install_domain(&__ogs_dbi_domain, "dbi", OGS_LOG_ERROR); ogs_log_install_domain(&__ogs_nas_domain, "nas", OGS_LOG_ERROR); + ogs_sctp_init(ogs_config()->usrsctp.udp_port); ogs_assert(ogs_dbi_init(ogs_config()->db_uri) == OGS_OK); } + +void test_epc_final(void) +{ + ogs_dbi_final(); + ogs_sctp_final(); + + test_context_final(); +} diff --git a/tests/app/meson.build b/tests/app/meson.build index 47b9267db..aa7f96ab3 100644 --- a/tests/app/meson.build +++ b/tests/app/meson.build @@ -18,10 +18,9 @@ libtestapp_inc = include_directories('.') -libtestepc_cc_args = '-DDEFAULT_CONFIG_FILENAME="@0@/configs/epc.yaml"'.format(meson.build_root()) +libtestepc_cc_args = '-DDEFAULT_CONFIG_FILENAME="@0@/configs/sample.yaml"'.format(meson.build_root()) libtestepc_sources = files(''' - test-packet.c epc-init.c '''.split()) @@ -58,7 +57,7 @@ executable('epc', include_directories : srcinc, dependencies : libtestepc_dep) -libtest5gc_cc_args = '-DDEFAULT_CONFIG_FILENAME="@0@/configs/5gc.yaml"'.format(meson.build_root()) +libtest5gc_cc_args = '-DDEFAULT_CONFIG_FILENAME="@0@/configs/sample.yaml"'.format(meson.build_root()) libtest5gc_sources = files(''' 5gc-init.c @@ -87,10 +86,9 @@ executable('5gc', include_directories : srcinc, dependencies : libtest5gc_dep) -libtestapp_cc_args = '-DDEFAULT_CONFIG_FILENAME="@0@/configs/app.yaml"'.format(meson.build_root()) +libtestapp_cc_args = '-DDEFAULT_CONFIG_FILENAME="@0@/configs/sample.yaml"'.format(meson.build_root()) libtestapp_sources = files(''' - test-packet.c app-init.c '''.split()) diff --git a/tests/app/test-app.h b/tests/app/test-app.h index 3f0c235dd..fc271448d 100644 --- a/tests/app/test-app.h +++ b/tests/app/test-app.h @@ -20,9 +20,7 @@ #ifndef TEST_APP_H #define TEST_APP_H -#include "test-packet.h" - -#include "mme/mme-context.h" +#include "test-common.h" #ifdef __cplusplus extern "C" { @@ -31,6 +29,12 @@ extern "C" { void test_app_init(void); void test_app_final(void); +void test_5gc_init(void); +void test_5gc_final(void); + +void test_epc_init(void); +void test_epc_final(void); + #ifdef __cplusplus } #endif diff --git a/tests/app/test-packet.c b/tests/app/test-packet.c deleted file mode 100644 index 91c1ec7f5..000000000 --- a/tests/app/test-packet.c +++ /dev/null @@ -1,3777 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "ogs-gtp.h" -#include "ogs-sctp.h" -#include "ogs-app.h" - -#include "pgw/pgw-config.h" - -#if HAVE_NETINET_IP_H -#include -#endif - -#if HAVE_NETINET_IP6_H -#include -#endif - -#if HAVE_NETINET_IP_ICMP_H -#include -#endif - -#if HAVE_NETINET_ICMP6_H -#include -#endif - -#include "mme/s1ap-build.h" -#include "mme/s1ap-path.h" - -#include "mme/sgsap-path.h" - -#include "test-packet.h" - -bool test_no_mme_self = 0; - -int testenb_gtpu_send(ogs_socknode_t *node, ogs_pkbuf_t *sendbuf) -{ - int rv; - mme_ue_t *mme_ue = NULL; - mme_sess_t *sess = NULL; - mme_bearer_t *bearer = NULL; - - ogs_sockaddr_t sgw; - ssize_t sent; - - ogs_assert(node); - ogs_assert(node->sock); - - memset(&sgw, 0, sizeof(ogs_sockaddr_t)); - sgw.ogs_sin_port = htons(OGS_GTPV1_U_UDP_PORT); - if (test_no_mme_self) { - sgw.ogs_sa_family = AF_INET; - sgw.sin.sin_addr.s_addr = inet_addr("127.0.0.2"); - } else { - mme_ue = ogs_list_first(&mme_self()->mme_ue_list); - ogs_assert(mme_ue); - sess = mme_sess_first(mme_ue); - ogs_assert(sess); - bearer = mme_bearer_first(sess); - ogs_assert(bearer); - - if (bearer->sgw_s1u_ip.ipv6) { - sgw.ogs_sa_family = AF_INET6; - memcpy(sgw.sin6.sin6_addr.s6_addr, - bearer->sgw_s1u_ip.addr6, OGS_IPV6_LEN); - rv = ogs_socknode_fill_scope_id_in_local(&sgw); - ogs_assert(rv == OGS_OK); - } else { - sgw.ogs_sa_family = AF_INET; - sgw.sin.sin_addr.s_addr = bearer->sgw_s1u_ip.addr; - } - } - - sent = ogs_sendto(node->sock->fd, sendbuf->data, sendbuf->len, 0, &sgw); - ogs_pkbuf_free(sendbuf); - if (sent < 0 || sent != sendbuf->len) - return OGS_ERROR; - - return OGS_OK; -} - -int tests1ap_build_setup_req( - ogs_pkbuf_t **pkbuf, S1AP_ENB_ID_PR present, uint32_t enb_id, - int tac, uint16_t mcc, uint16_t mnc, uint16_t mnc_len) -{ - ogs_plmn_id_t plmn_id; - - S1AP_S1AP_PDU_t pdu; - S1AP_InitiatingMessage_t *initiatingMessage = NULL; - S1AP_S1SetupRequest_t *S1SetupRequest = NULL; - - S1AP_S1SetupRequestIEs_t *ie = NULL; - S1AP_Global_ENB_ID_t *Global_ENB_ID = NULL; - S1AP_SupportedTAs_t *SupportedTAs = NULL; - S1AP_SupportedTAs_Item_t *SupportedTAs_Item = NULL; - S1AP_PLMNidentity_t *PLMNidentity = NULL; - S1AP_PagingDRX_t *PagingDRX = NULL; - - memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage = - CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); - - initiatingMessage = pdu.choice.initiatingMessage; - initiatingMessage->procedureCode = S1AP_ProcedureCode_id_S1Setup; - initiatingMessage->criticality = S1AP_Criticality_reject; - initiatingMessage->value.present = - S1AP_InitiatingMessage__value_PR_S1SetupRequest; - - S1SetupRequest = &initiatingMessage->value.choice.S1SetupRequest; - - ie = CALLOC(1, sizeof(S1AP_S1SetupRequestIEs_t)); - ASN_SEQUENCE_ADD(&S1SetupRequest->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_Global_ENB_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_S1SetupRequestIEs__value_PR_Global_ENB_ID; - - Global_ENB_ID = &ie->value.choice.Global_ENB_ID; - - ie = CALLOC(1, sizeof(S1AP_S1SetupRequestIEs_t)); - ASN_SEQUENCE_ADD(&S1SetupRequest->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_SupportedTAs; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_S1SetupRequestIEs__value_PR_SupportedTAs; - - SupportedTAs = &ie->value.choice.SupportedTAs; - - ie = CALLOC(1, sizeof(S1AP_S1SetupRequestIEs_t)); - ASN_SEQUENCE_ADD(&S1SetupRequest->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_DefaultPagingDRX; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_S1SetupRequestIEs__value_PR_PagingDRX; - - PagingDRX = &ie->value.choice.PagingDRX; - - ogs_plmn_id_build(&plmn_id, mcc, mnc, mnc_len); - - ogs_s1ap_uint32_to_ENB_ID(present, enb_id, &Global_ENB_ID->eNB_ID); - ogs_s1ap_buffer_to_OCTET_STRING( - &plmn_id, OGS_PLMN_ID_LEN, &Global_ENB_ID->pLMNidentity); - - SupportedTAs_Item = (S1AP_SupportedTAs_Item_t *) - CALLOC(1, sizeof(S1AP_SupportedTAs_Item_t)); - ogs_asn_uint16_to_OCTET_STRING(tac, &SupportedTAs_Item->tAC); - PLMNidentity = (S1AP_PLMNidentity_t *) - CALLOC(1, sizeof(S1AP_PLMNidentity_t)); - ogs_s1ap_buffer_to_OCTET_STRING( - &plmn_id, OGS_PLMN_ID_LEN, PLMNidentity); - ASN_SEQUENCE_ADD(&SupportedTAs_Item->broadcastPLMNs.list, PLMNidentity); - - ASN_SEQUENCE_ADD(&SupportedTAs->list, SupportedTAs_Item); - - *PagingDRX = S1AP_PagingDRX_v64; - - *pkbuf = ogs_s1ap_encode(&pdu); - if (*pkbuf == NULL) { - ogs_error("ogs_s1ap_encode() failed"); - return OGS_ERROR; - } - return OGS_OK; -} - -#define TESTS1AP_MAX_MESSAGE 64 - -int tests1ap_build_invalid_packet(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "0011002100000300 3b40080062f22400 0001700040000700 00004062f224002c" - "00030a0100", - "", - }; - - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 37, - 0, - }; - - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_initial_ue_msg(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000c405800000500 0800020001001a00 302f177ca0b38802 0741020809101010" - "3254869104e060c0 4000050221d031d1 5c0a003103e5e034 9011035758a65d01" - "00004300060000f1 1030390064400800 00f1101079baf000 86400130", - - "000c40809b000005 000800020002001a 00737217400466af 070741020bf600f1" - "10000201fd001710 05e060c040010021 0221d011d1271a80 8021100100001081" - "0600000000830600 000000000d00000a 005255f50110225c 0a003103e5c03e13" - "55f501aaaa110357 58a6200b601404ef 65233b8878d29040 080402600400021f" - "025d0107e0004300 060000f110303900 6440080055f50100 19d0100086400130", - - "000c40809b00" - "0005000800020003 001a007372178c 3e3cff070741020b f600f11000020100" - "00000905e060c040 0100210204d011d1 271a808021100100 0010810600000000" - "830600000000000d 00000a005255f501 10225c0a003103e5 c03e1355f501aaaa" - "11035758a6200b60 1404ef65233b8878 d290400804026004 00021f025d0107e0" - "004300060000f110 3039006440080055 f5010019d0100086 400130", - - - /* 3 */ - "000c406800000500 080002001f001a00 403f074172080910 10103254866202e0" - "600021023cd011d1 271a808021100100 0010810600000000 830600000000000d" - "00000a005c0a0090 11034f18a6f15d01 00004300060000f1 1030390064400800" - "00f110002343d000 86400130", - - "000c405200000500 0800020011001a 002a2917acba67c4 8207410108091010" - "103254866205f0f0 000000000e023cd0 11d1270780000a00 000d00c100430006" - "0000f11030390064 40080000f1109d67 aa500086400130", - - "000c405200000500 0800020021001a 002a2917bcba67c4 8207410108091010" - "000000003005f0f0 000000000e023cd0 11d1270780000a00 000d00c100430006" - "0000f11030390064 40080000f1109d67 aa500086400130", - - - /* 6 */ - "000c" - "404c000005000800 020002001a002423 0741710809101010 3254767905f0f000" - "0000000e0201d011 d1270780000a0000 0d00c10043000600 00f1103039006440" - "080000f11054f640 100086400130", - "", - "000c" - "4070000005000800 020001001a004847 0741720809101000 0000002004f07000" - "000023020ed03127 1d80802110010000 1081060000000083 0600000000000d00" - "000300000a005c0a 003103e5e0349011 035758a65d010000 4300060000f11030" - "39006440080000f1 100019b010008640 0130", - - - /* 9 */ - "000c" - "4068000005000800 020001001a00403f 0741720809101010 3254861002e06000" - "210207d011d1271a 8080211001000010 8106000000008306 00000000000d0000" - "0a005c0a00901103 4f18a6f15d010000 4300060000f11030 39006440080000f1" - "1004615380008640 0130", - - "000c" - "4080830000060008 0002000c001a0050 4f1744b524490507 41020bf600f11000" - "0201010003e802e0 6000210204d011d1 271a808021100100 0010810600000000" - "830600000000000d 00000a005200f110 30395c0a00901103 4f18a6f15d0100e0" - "004300060000f110 3039006440080000 f110001f20a00086 400130004b000700" - "00f110000201", - "", - - /* 12 */ - "000c" - "4080810000050008 000340072d001a00 5857074172080910 10103254967305e0" - "60c0401100270209 d031d12720808021 1001000010810600 0000008306000000" - "00000d0000030000 0a000010005c0a00 3103e5e02e901103 5758a64008040260" - "0000021f005d0103 c1004300060000f1 1030390064400800 00f1100787b80000" - "86400130", - "", - "", - - /* 15 */ - "000c" - "404c000005000800 020018001a002423 0741710839011094 7856044005e0e000" - "0000000e0201d011 d1270780000a0000 0d00c10043000600 1300410033006440" - "08001300418d01b7 800086400130", - "", - "", - - /* 18 */ - "000c408096000005 000800020001001a 006e6d177d3278f5 090741020bf609f1" - "07000201ca001310 05f0f0c040090021 0234d011d1271a80 8021100101001081" - "0600000000830600 000000000d000010 005209f10700075c 08033103e5e07e90" - "1103571882200a60 140462918100127e 00400800021f0004 0240045d0100e0c1" - "004300060009f107 0007006440080009 f1070019b0100086 400130", - "000c4080b1000005 000800048003e993 001a008086808417 6e2da9da06074102" - "0bf627f412000201 f700571805f070c0 4011002d026ed031 d127268080211001" - "0000108106000000 0083060000000000 0d00000300000a00 0005000010000011" - "005227f41230395c 0a003103e5e03e13 27f412c958110357 58a6200c601404ef" - "65233b8878d2f280 4008040260040002 1f025d0103e0c110 0203800043000600" - "27f4123039006440 080027f412000640 200086400130", - "", - - /* 21 */ - "000c407400000700 08000200d0001a00 3c3b17c000c55201 0741010bf600f110" - "000201c5001d9005 f0f0000000001702 01d011d027108000 0a00000d00001000" - "ff00031301845264 f0130002e0004300 060000f110303900 6440080000f11000" - "0640100086400130 004b00070000f110 02000100aa400100", - "000c407400000700 08000200d1001a00 3c3b17f1f96e4a02 0741010bf600f110" - "000201c5001d9005 f0f0000000001702 01d011d027108000 0a00000d00001000" - "ff00031301845264 f0130002e0004300 060000f110303900 6440080000f11000" - "0640100086400130 004b00070000f110 02000100aa400100", - "", - - /* 24 */ - "000c" - "4080870000050008 00020001001a005f 5e0741720bf632f5 40800101dde9c6cf" - "07f0f0c040010010 00230201d031271d 8080211001010010 8106000000008306" - "0000000000030000 0a00000d005232f5 4000015c20001332 f540000111034f18" - "805d0105e010028d c06f04f000f00000 4300060032f54000 01006440080032f5" - "4000200010008640 0130", - "000c" - "4074000005000800 020001001a004c4b 0741720829534037 4600000607f0f0c0" - "4001001000230201 d031271d80802110 0101001081060000 0000830600000000" - "000300000a00000d 005c20009011034f 18805d01056f04f0 00f0000043000600" - "32f5400001006440 080032f540002000 100086400130", - "000c" - "4080870000050008 00020001001a005f 5e07417208295340 374600000607f0f0" - "c040018030002702 01d0312721808021 1001010010810600 0000008306000000" - "00000300000a0000 0d00001a010f5232 f54000015c200013 32f540000111034f" - "18805d0105100245 c06f04f000f00000 4300060032f54000 01006440080032f5" - "4000200010008640 0130", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 92, - 160, - 160, - - 108, - 86, - 86, - - 80, - 0, - 116, - - 108, - 136, - 0, - - 134, - 0, - 0, - - 80, - 0, - 0, - - 155, - 182, - 0, - - /* 21 */ - 120, - 120, - 0, - - /* 24 */ - 140, - 120, - 140, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_identity_response(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "", - "", - "000d" - "403e000005000000 05c00100009f0008 00020003001a00 121117d7e3248b57" - "0756080910101032 5486510064400800 00f11054f6401000 4340060000f1105b" - "a0", - - /* 3 */ - "", - "", - "", - - "", - "", - "", - - /* 9 */ - "", - "000d" - "403e000005000000 05c0020000c40008 0002000c001a0012 1117c07eb5f50607" - "5608091010103254 8651006440080000 f110001f20a00043 40060000f1103039", - "", - - "", - "", - "", - - "", - "", - "", - - /* 18 */ - "000d403b00000500 0000020001000800 020001001a001211 177b973f4c0a0756" - "0829262400001118 93006440080009f1 070019b010004340 060009f1070007", - "000d403d00000500 00000200f8000800 048003e993001a00 121117c651b5f907" - "0756087942120000 0000300064400800 27f4120006402000 4340060027f41230" - "39", - "", - - /* 21 */ - "000d403b00000500 00000200d0000800 0200d0001a001211 17d2074692020756" - "0839118900000070 52006440080064f0 1300064010004340 060064f0130002", - "000d403b00000500 00000200d1000800 0200d1001a001211 170baa6c40030756" - "0839118900000070 52006440080064f0 1300064010004340 060064f0130002", - "", - - /* 24 */ - "000d" - "4035000005000000 0200640008000200 01001a000c0b0756 0829534037460000" - "06006440080032f5 4000200010004340 060032f5400001", - "", - "", - }; - - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 0, - 0, - 66, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 0, - 66, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 63, - 65, - 0, - - /* 21 */ - 63, - 63, - 0, - - /* 24 */ - 57, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_authentication_response(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - /* 0 */ - "000d403e00000500 000005c00100009d 000800020001001a 001211177c0bca9d" - "030753086a91970e 838fd07900644008 0000f1101079baf0 004340060000f110" - "5ba0", - "", - "", - - /* 3 */ - "000d403500000500 0000020001000800 02001f001a000c0b 07530831c964f076" - "1378760064400800 00f110002343d000 4340060000f11030 39", - "", - "", - - /* 6 */ - "000d" - "4038000005000000 05c0020000c80008 00020002001a000c 0b0753087dc78e7c" - "421f9eb900644008 0000f11054f64010 004340060000f110 2b67", - "", - "000d" - "4035000005000000 0200010008000200 01001a000c0b0753 08d8b388ddacaa1f" - "36006440080000f1 100019b010004340 060000f1100001", - - /* 9 */ - "000d" - "4038000005000000 05c0010001da0008 00020001001a000c 0b0753084ce11ef1" - "24b1854500644008 0000f11004615380 004340060000f110 5ba0", - "000d" - "403e000005000000 05c0020000c40008 0002000c001a0012 1117deff957c0707" - "5308e3b925330735 7093006440080000 f110001f20a00043 40060000f1103039", - "", - - /* 12 */ - "000d" - "4036000005000000 0200020008000340 072d001a000c0b07 5308e2b7921bc6fe" - "b4c9006440080000 f1100787b8000043 40060000f1103039", - "", - "", - - /* 15 */ - "000d" - "4038000005000000 05c001a001020008 00020018001a000c 0b0753082a080419" - "d7becfdb00644008 001300418d01b780 0043400600130041 0033", - "", - "", - - /* 18 */ - "000d403b00000500 0000020001000800 020001001a001211 17fda45fe50b0753" - "086f7ff4fc4be85f d1006440080009f1 070019b010004340 060009f1070007", - "000d403d00000500 00000200f8000800 048003e993001a00 121117e6e4dd6508" - "0753086f7ff4fc4b e85fd10064400800 27f4120006402000 4340060027f41230" - "39", - "", - - /* 21 */ - "000d403b00000500 00000200d0000800 0200d0001a001211 17c3cf6653030753" - "0831c964f0761378 76006440080064f0 1300064010004340 060064f0130002", - "000d403b00000500 00000200d1000800 0200d1001a001211 17e41759f6040753" - "0831c964f0761378 76006440080064f0 1300064010004340 060064f0130002", - "", - - /* 24 */ - "000d" - "4035000005000000 0200640008000200 01001a000c0b0753 08db8af07f4b815c" - "9a006440080032f5 4000200010004340 060032f5400001", - "000d" - "4035000005000000 0200640008000200 01001a000c0b0753 0886f726fd424fa5" - "ab006440080032f5 4000200010004340 060032f5400001", - "000d" - "4035000005000000 0200640008000200 01001a000c0b0753 08d4150f5e02472e" - "8f006440080032f5 4000200010004340 060032f5400001", - }; - - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 66, - 0, - 0, - - 57, - 0, - 0, - - 60, - 0, - 57, - - 60, - 66, - 0, - - 58, - 0, - 0, - - 60, - 0, - 0, - - 63, - 65, - 0, - - /* 21 */ - 63, - 63, - 63, - - /* 24 */ - 57, - 57, - 57, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - - -int tests1ap_build_authentication_failure(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "", - "", - "", - - "000d" - "403d000005000000 0200030008000200 21001a001413075c 15300e61640edcfb" - "605d25911423ee1f 9e006440080000f1 100019b010004340 060000f1100001", - "000d" - "402d000005000000 0200030008000200 21001a00040307 5c14006440080000" - "f1101a2d10100043 40060000f1100001", - "", - - "", - "", - "", - - "", - "", - "", - - }; - - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 0, - 0, - 0, - - 65, - 49, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_security_mode_complete(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000d403500000500 000005c00100009d 000800020001001a 000908476b8f5f64" - "00075e0064400800 00f1101079baf000 4340060000f1105b a0", - "", - "", - - /* 3 */ - "000d403200000500 0000020001000800 02001f001a000908 473c0c819e00075e" - "006440080000f110 002343d000434006 0000f1103039", - "", - "", - - /* 6 */ - "000d" - "4035000005000000 05c0020000c80008 00020002001a0009 0847c0eb1eb80007" - "5e006440080000f1 1054f64010004340 060000f1102b67", - "", - "000d" - "4032000005000000 0200010008000200 01001a00090847c8 38f8d700075e0064" - "40080000f1100019 b010004340060000 f1100001", - - /* 9 */ - "000d" - "4035000005000000 05c0010001da0008 00020001001a0009 0847d3b0ef030007" - "5e006440080000f1 1004615380004340 060000f1105ba0", - - "000d" - "4035000005000000 05c0020000c40008 0002000c001a0009 084790282df90007" - "5e006440080000f1 10001f20a0004340 060000f1103039", - "", - - /* 12 */ - "000d" - "4033000005000000 0200020008000340 072d001a00090847 aaaf94cf00075e00" - "6440080000f11007 87b8000043400600 00f1103039", - "", - "", - - /* 15 */ - "000d" - "4035000005000000 05c001a001020008 00020018001a0009 084785cfd7fa0007" - "5e00644008001300 418d01b780004340 06001300410033", - "", - "", - - /* 18 */ - "000d403d00000500 0000020001000800 020001001a001413 471647b75200075e" - "2309337522002954 3118f40064400800 09f1070019b01000 4340060009f10700" - "07", - - "000d403400000500 00000200f8000800 048003e993001a00 090847592cf09600" - "075e006440080027 f412000640200043 40060027f4123039", - "", - - /* 21 */ - "000d403200000500 00000200d0000800 0200d0001a000908 473c0c819e00075e" - "006440080064f013 0006401000434006 0064f0130002", - "000d403200000500 00000200d1000800 0200d1001a000908 47e68241c900075e" - "006440080064f013 0006401000434006 0064f0130002", - "", - - /* 24 */ - "000d" - "403d000005000000 0200640008000200 01001a0014134725 f0f17d00075e2309" - "8306370004448009 f1006440080032f5 4000200010004340 060032f5400001", - "000d" - "403d000005000000 0200640008000200 01001a0014134716 baaf8800075e2309" - "8306370004448009 f1006440080032f5 4000200010004340 060032f5400001", - "000d" - "403d000005000000 0200640008000200 01001a0014134793 728e4000075e2309" - "8306370004448009 f1006440080032f5 4000200010004340 060032f5400001", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 57, - 0, - 0, - - 54, - 0, - 0, - - 57, - 0, - 54, - - 57, - 57, - 0, - - 55, - 0, - 0, - - 57, - 0, - 0, - - 65, - 56, - 0, - - /* 21 */ - 54, - 54, - 0, - - /* 24 */ - 65, - 65, - 65, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_esm_information_response(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000d40808d000005 00000005c0010000 9d00080002000100 1a006160275c0667" - "58010221da280908 696e7465726e6574 274a80c223150100 001510c09a2626c0" - "9a2626c09a2626c0 9a2626c223150200 0015103d3dda5c72 4cc497354ae64653" - "45a8088021100100 0010810600000000 830600000000000d 00000a0000644008" - "0000f1101079baf0 004340060000f110 5ba0", - "000d40808d000005 00000005c0010000 9e00080002000200 1a00616027c963b5" - "1b010221da280908 696e7465726e6574 274a80c223150100 001510c09a2626c0" - "9a2626c09a2626c0 9a2626c223150200 0015103d3dda5c72 4cc497354ae64653" - "45a8088021100100 0010810600000000 830600000000000d 00000a0000644008" - "0000f1101079baf0 004340060000f110 5ba0", - "", - - /* 3 */ - "000d403e00000500 0000020001000800 02001f001a001514 27505a0b5301023c" - "da280908696e7465 726e657400644008 0000f110002343d0 004340060000f110" - "3039", - "000d403e00000500 0000020002000800 020011001a001514 27b531c64f01023c" - "da280908696e7465 726e657400644008 0000f110002343d0 004340060000f110" - "3039", - "", - - /* 6 */ - "000d" - "4041000005000000 05c0020000c80008 00020002001a0015 142793b2bedc0102" - "01da280908696e74 65726e6574006440 080000f11054f640 10004340060000f1" - "102b67", - "", - "", - - /* 9 */ - "000d" - "4041000005000000 05c0010001da0008 00020001001a0015 14279a2476c80102" - "07da280908696e74 65726e6574006440 080000f110046153 80004340060000f1" - "105ba0", - "000d" - "4041000005000000 05c0020000c40008 0002000c001a0015 14274f280bff0102" - "04da280908696e74 65726e6574006440 080000f110001f20 a0004340060000f1" - "103039", - "", - - /* 12 */ - "000d" - "403f000005000000 0200020008000340 072d001a00151427 c4a524d8010209da" - "280908696e746572 6e65740064400800 00f1100787b80000 4340060000f11030" - "39", - "", - "", - - /* 15 */ - "000d" - "4044000005000000 05c001a001020008 00020018001a0018 1727675df9c50102" - "01da280c07737461 72656e7403636f6d 0064400800130041 8d01b78000434006" - "001300410033", - "", - "", - - /* 18 */ - "000d405a00000500 0000020001000800 020001001a003130 27ebeeb5d4010234" - "da280908696e7465 726e6574271a8080 2110010100108106 0000000083060000" - "0000000d00001000 006440080009f107 0019b01000434006 0009f1070007", - "000d404000000500 00000200f8000800 048003e993001a00 151427f9e0e95c01" - "026eda280908696e 7465726e65740064 40080027f4120006 4020004340060027" - "f4123039", - "", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 146, - 146, - 0, - - 66, - 66, - 0, - - 69, - 0, - 0, - - /* 9 */ - 69, - 69, - 0, - - 67, - 0, - 0, - - 72, - 0, - 0, - - /* 18 */ - 94, - 68, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_ue_capability_info_indication(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "0016" - "40809c0000030000 0005c00100009d00 0800020001004a40 8085808304040003" - "04ec598007000820 81839b4e1e3ff8ff f1ffc7ff8ffe3ffc 7ff1ffe3ff8fff1f" - "fc7ff8ffe3ffc7ff 1ffdfd3ffa7a2060 090e194e9525c8c2 fd80000000e03fe7" - "ff5f60000000384f e9ffd3d800000002 1033035758a66014 042f6513b8800d2f" - "0831c1a53432b259 ef989007000cdd9c 6331200e0019a332 c662401c003200", - "", - "", - - /* 3 */ - "0016402d00000300 0000020001000800 02001f004a401a19 00b801014c598080" - "9c000bf06ec4d001 40302c0000000000 000000", - "", - "", - - /* 6 */ - "0016" - "403f000003000000 05c0020000c80008 00020002004a4029 28013001023cd980" - "00bc000ff06ec4d0 0141b82c00000000 07d404000ef08020 00012a0300008800" - "00", - "0016" - "403f000003000000 05c0020000c70008 00020004004a4029 28013001023cd980" - "00bc000ff06ec4d0 0141b82c00000000 07d404000ef08020 00012a0300008800" - "00", - "", - - /* 9 */ - "0016" - "4030000003000000 05c0010001da0008 00020001004a401a 1900b801014c5980" - "809c000bf06ec4d0 0140302c00000000 0000", - "0016" - "4030000003000000 05c0020000c40008 0002000c004a401a 1900b801014c5980" - "0018000bf06ec4d0 0100302c00000000 0000", - "", - - /* 12 */ - "0016" - "4080800000030000 0002000200080003 40072d004a406c6b 034803042c998001" - "08201838bfc1c5fd bd3ffa8a20400902 3a54930382c60000 00001c4083840008" - "0881001c40004042 080060e2ff0717f0 0040000203fa0000 0007e8000000020f" - "33035758a6601404 e09c100125600031 218d3432b2386200 40008d17960c4008" - "001100", - "", - "", - - /* 15 */ - "0016" - "403f000003000000 05c001a001020008 00020018004a4029 28013001023cd980" - "00bc000ff06ec4d0 0141b82c00000000 07d404000ef08020 00016a0300008800" - "00", - "", - "", - - "", - "00164081f7000003 0000000200f80008 00048003e993004a 4081e181df040ee2" - "03081a4cd9800818 1004e103a54ca044 8ff91ff91ff23ff2 3fe47fe47fc8ffc8" - "ff91ff91ff23ff23 fe47fe47fc8ffc8f f91ff7fcffebe882 002429c329d2a4b8" - "fc37f00000000010 254b7000000003ea 83234a801c600040 4608006300024018" - "c000880e10002021 0400708001010020 028410300001000c 200048039c001200" - "e50004807a000101 982002d010398001 000e60004807a000 101a02001d000090" - "0738082401ca0209 00730082401d0020 900e100024200400 50824600002001ce" - "020980738002603d 002090cc1001e800 048660800b4048e6 0004007a00010198" - "2402d01039804120 168081cc000900f4 008243404007a000 121a02002d0123a0" - "001000e80104c03a 000131048ff91ff9 1ff23ff23fe47fe4 7fc8ffc8ff91ff91" - "ff23ff23fe47fe47 fc8ffc8ff91ff91f f23ff23fe47fe47f c8ffc8ff91ff91ff" - "23ff23fe47fe47fc 8ffc8ff91ff91ff2 3ff23fe47fe47fc8 ffc8ff91ff91ff23" - "ff23fe47fe47fc8f fc8ff91ff91ff23f f23fe47fe47fc8ff c8ff91ff91ff23ff" - "23fe47fe47fc8ffc 8ff91ff402c00004 d043c5c10e10f1fc 391f8000648803c6" - "5a600923ffffcd02 1133035758a66014 04ef65233b8878d2 f2803201bb3432b2" - "59ef9891e7000d80 1bbe8c662479c003 60068f8b19891e70 00d80100", - "", - - /* 21 */ - "00164080b6000003 0000000200d00008 000200d0004a4080 a280a00404e80108" - "099cd98002a552f0 40b82e0bff06ec4d 00141b8748000000 02a5647400c00c00" - "80007d404380e900 04103a8001040ef0 004107a400101a82 003d200080de1001" - "ea00040690800f50 00203784007bc001 01a42003de00080d 41000e90004807a4" - "00101a42001d4000 900f500020350400 3bc001201ef00040 6f080381705c1705" - "c1705c1705c1705c 1705c1705c172a32 0000887003fc0000 000000", - "00164080b6000003 0000000200d10008 000200d1004a4080 a280a00404e80108" - "099cd98002a552f0 40b82e0bff06ec4d 00141b8748000000 02a5647400c00c00" - "80007d404380e900 04103a8001040ef0 004107a400101a82 003d200080de1001" - "ea00040690800f50 00203784007bc001 01a42003de00080d 41000e90004807a4" - "00101a42001d4000 900f500020350400 3bc001201ef00040 6f080381705c1705" - "c1705c1705c1705c 1705c1705c172a32 0000887003fc0000 000000", - "", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 161, - 0, - 0, - - 51, - 0, - 0, - - 67, - 67, - 0, - - 52, - 52, - 0, - - 133, - 0, - 0, - - 67, - 0, - 0, - - 0, - 508, - 0, - - /* 21 */ - 187, - 187, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_initial_context_setup_response( - ogs_pkbuf_t **pkbuf, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, - uint8_t ebi, uint32_t teid, const char *ipstr) -{ - int rv; - - S1AP_S1AP_PDU_t pdu; - S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; - S1AP_InitialContextSetupResponse_t *InitialContextSetupResponse = NULL; - ogs_sockaddr_t *addr = NULL; - - S1AP_InitialContextSetupResponseIEs_t *ie = NULL; - S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; - S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; - S1AP_E_RABSetupListCtxtSURes_t *E_RABSetupListCtxtSURes = NULL; - - S1AP_E_RABSetupItemCtxtSUResIEs_t *item = NULL; - S1AP_E_RABSetupItemCtxtSURes_t *e_rab = NULL; - - ogs_gtp_f_teid_t f_teid; - ogs_ip_t ip; - int len; - - memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome = - CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); - - successfulOutcome = pdu.choice.successfulOutcome; - successfulOutcome->procedureCode = - S1AP_ProcedureCode_id_InitialContextSetup; - successfulOutcome->criticality = S1AP_Criticality_reject; - successfulOutcome->value.present = - S1AP_SuccessfulOutcome__value_PR_InitialContextSetupResponse; - - InitialContextSetupResponse = - &successfulOutcome->value.choice.InitialContextSetupResponse; - - ie = CALLOC(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ASN_SEQUENCE_ADD(&InitialContextSetupResponse->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = - S1AP_InitialContextSetupResponseIEs__value_PR_MME_UE_S1AP_ID; - - MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; - - ie = CALLOC(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ASN_SEQUENCE_ADD(&InitialContextSetupResponse->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = - S1AP_InitialContextSetupResponseIEs__value_PR_ENB_UE_S1AP_ID; - - ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; - - ie = CALLOC(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ASN_SEQUENCE_ADD(&InitialContextSetupResponse->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListCtxtSURes; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = - S1AP_InitialContextSetupResponseIEs__value_PR_E_RABSetupListCtxtSURes; - - E_RABSetupListCtxtSURes = &ie->value.choice.E_RABSetupListCtxtSURes; - - *MME_UE_S1AP_ID = mme_ue_s1ap_id; - *ENB_UE_S1AP_ID = enb_ue_s1ap_id; - - item = CALLOC(1, sizeof(S1AP_E_RABSetupItemCtxtSUResIEs_t)); - ASN_SEQUENCE_ADD(&E_RABSetupListCtxtSURes->list, item); - - item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemCtxtSURes; - item->criticality = S1AP_Criticality_ignore; - item->value.present = - S1AP_E_RABSetupItemCtxtSUResIEs__value_PR_E_RABSetupItemCtxtSURes; - - e_rab = &item->value.choice.E_RABSetupItemCtxtSURes; - - e_rab->e_RAB_ID = ebi; - - rv = ogs_getaddrinfo(&addr, AF_INET, ipstr, OGS_GTPV1_U_UDP_PORT, 0); - ogs_assert(rv == OGS_OK); - rv = ogs_gtp_sockaddr_to_f_teid(addr, NULL, &f_teid, &len); - ogs_assert(rv == OGS_OK); - ogs_freeaddrinfo(addr); - - rv = ogs_gtp_f_teid_to_ip(&f_teid, &ip); - ogs_assert(rv == OGS_OK); - - rv = ogs_asn_ip_to_BIT_STRING(&ip, &e_rab->transportLayerAddress); - ogs_assert(rv == OGS_OK); - ogs_asn_uint32_to_OCTET_STRING(teid, &e_rab->gTP_TEID); - - *pkbuf = ogs_s1ap_encode(&pdu); - if (*pkbuf == NULL) { - ogs_error("ogs_s1ap_encode() failed"); - return OGS_ERROR; - } - return OGS_OK; -} - -int tests1ap_build_ue_context_modification_response( - ogs_pkbuf_t **pkbuf, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id) -{ - S1AP_S1AP_PDU_t pdu; - S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; - S1AP_UEContextModificationResponse_t *UEContextModificationResponse = NULL; - - S1AP_UEContextModificationResponseIEs_t *ie = NULL; - S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; - S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; - - memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome = - CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); - - successfulOutcome = pdu.choice.successfulOutcome; - successfulOutcome->procedureCode = - S1AP_ProcedureCode_id_UEContextModification; - successfulOutcome->criticality = S1AP_Criticality_reject; - successfulOutcome->value.present = - S1AP_SuccessfulOutcome__value_PR_UEContextModificationResponse; - - UEContextModificationResponse = - &successfulOutcome->value.choice.UEContextModificationResponse; - - ie = CALLOC(1, sizeof(S1AP_UEContextModificationResponseIEs_t)); - ASN_SEQUENCE_ADD(&UEContextModificationResponse->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = - S1AP_UEContextModificationResponseIEs__value_PR_MME_UE_S1AP_ID; - - MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; - - ie = CALLOC(1, sizeof(S1AP_UEContextModificationResponseIEs_t)); - ASN_SEQUENCE_ADD(&UEContextModificationResponse->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = - S1AP_UEContextModificationResponseIEs__value_PR_ENB_UE_S1AP_ID; - - ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; - - *MME_UE_S1AP_ID = mme_ue_s1ap_id; - *ENB_UE_S1AP_ID = enb_ue_s1ap_id; - - *pkbuf = ogs_s1ap_encode(&pdu); - if (*pkbuf == NULL) { - ogs_error("ogs_s1ap_encode() failed"); - return OGS_ERROR; - } - return OGS_OK; -} - -int tests1ap_build_initial_context_setup_failure(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "4009 0015000003000040 0200020008400200 01000240020000", - "", - "", - - /* 3 */ - "", - "", - "", - - /* 6 */ - "", - "", - "4009001500000300 0040020001000840 0200010002400202 a0", - - /* 9 */ - "", - "", - "", - - /* 12 */ - "", - "", - "", - - /* 15 */ - "", - "", - "", - - /* 18 */ - "", - "", - "", - - /* 21 */ - "4009001500000300 00400200d0000840 0200d00002400203 40", - "4009001500000300 00400200d2000840 0200d20002400203 40", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 25, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 25, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - /* 21 */ - 25, - 25, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_attach_complete(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000d" - "403a000005000000 05c00100009d0008 00020001001a000e 0d27c183eb950207" - "4300035200c20064 40080000f1101079 baf0004340060000 f1105ba0", - "000d" - "403a000005000000 05c00100009e0008 00020002001a000e 0d27e8a2a3f10207" - "4300035200c20064 40080000f1101079 baf0004340060000 f1105ba0", - "", - - /* 3 */ - "000d" - "403a000005000000 05c0000000010008 0002001f001a000e 0d27127c47860207" - "4300035200c20064 40080000f1101079 baf0004340060000 f1105ba0", - "000d" - "403a000005000000 05c0010000020008 00020011001a000e 0d27225d92bb0207" - "4300035200c20064 40080000f1101079 baf0004340060000 f1105ba0", - "", - - /* 6 */ - "000d" - "403a000005000000 05c0020000c80008 00020002001a000e 0d27f190fc2b0207" - "4300035200c20064 40080000f11054f6 4010004340060000 f1102b67", - "", - "", - - /* 9 */ - "000d" - "403a000005000000 05c0010001da0008 00020001001a000e 0d272e3456f70207" - "4300035200c20064 40080000f1100461 5380004340060000 f1105ba0", - "000d" - "403a000005000000 05c0020000c40008 0002000c001a000e 0d276a543e560207" - "4300035200c20064 40080000f110001f 20a0004340060000 f1103039", - "", - - /* 12 */ - "000d" - "4038000005000000 0200020008000340 072d001a000e0d27 600bbd3802074300" - "035200c200644008 0000f1100787b800 004340060000f110 3039", - "", - "", - - /* 15 */ - "000d" - "403a000005000000 05c001a001020008 00020018001a000e 0d27be5dbbc90207" - "4300035200c20064 4008001300418d01 b780004340060013 00410033", - "", - "", - - /* 18 */ - "000d403700000500 0000020001000800 020001001a000e0d 27ffe827a8020743" - "00035200c2006440 080009f1070019b0 10004340060009f1 070007", - "000d403900000500 00000200f8000800 048003e993001a00 0e0d27b1f1539802" - "074300035200c200 6440080027f41200 0640200043400600 27f4123039", - "", - - /* 21 */ - "", - "000d403700000500 00000200d1000800 0200d1001a000e0d 27f6962d51010743" - "00035200c2006440 080064f013000640 10004340060064f0 130002", - "", - - /* 24 */ - "000d" - "4037000005000000 0200640008000200 01001a000e0d277a 6f1f5b0107430003" - "5200c20064400800 32f5400020001000 4340060032f54000 01", - "000d" - "4044000006000000 0200640008000200 01001a000e0d2728 e58e6d0107430003" - "5200c20064400800 32f5400020001000 4340060032f54000 01012040090032f5" - "400012345020", - "000d" - "4037000005000000 0200640008000200 01001a000e0d27e3 11971d0107430003" - "5200c20064400800 32f5400020001000 4340060032f54000 01", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 62, - 62, - 0, - - 62, - 62, - 0, - - 62, - 0, - 0, - - 62, - 62, - 0, - - 60, - 0, - 0, - - 62, - 0, - 0, - - 59, - 61, - 0, - - /* 21 */ - 0, - 59, - 0, - - /* 24 */ - 59, - 72, - 59, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_emm_status(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "", - "", - "", - - "", - "", - "", - - "", - "", - "000d403300000500 0000020001000800 020001001a000a09 276941dec8020760" - "65006440080000f1 10002343d0004340 060000f1103039", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 0, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 55, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_detach_request(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000c404800000600 0800020002001a 001615172ba435db 040745090bf600f1" - "10000201020003e6 004300060000f110 2b67006440080000 f1109d67aa500086" - "4001300060000600 40020003e6", - "000c404800000600 0800020001001a 00161517ba258500 040745090bf600f1" - "10000201020003e6 004300060000f110 2b67006440080000 f1109d67aa500086" - "4001300060000600 40020003e6", - "", - - /* 3 */ - "", - "", - "", - - /* 6 */ - "", - "", - "", - - /* 9 */ - "", - "", - "", - - /* 12 */ - "", - "", - "", - - /* 15 */ - "", - "", - "", - - /* 18 */ - "000d403f00000500 0000020002000800 020002001a001615 2754d17d69040745" - "0b0bf609f1070002 01f500075e006440 080009f1070019b0 10004340060009f1" - "070007", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 76, - 76, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 67, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_ue_context_release_request(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "0012" - "4018000003000000 05c00100009d0008 0002000100024002 0280", - "", - "", - - /* 3 */ - "", - "", - "", - - /* 6 */ - "0012" - "4018000003000000 05c0020000c80008 0002000200024002 0280", - "", - "0012401500000300 0000020001000800 0200010002400202 a0", - - /* 9 */ - "", - "", - "", - - /* 12 */ - "", - "", - "", - - /* 15 */ - "", - "", - "", - - /* 18 */ - "0012401500000300 0000020001000800 0200010002400202 80", - "0012401500000300 0000020002000800 0200020002400202 e0", - "0012401700000300 00000200f8000800 048003e993000240 0202e0", - - /* 21 */ - "0012401500000300 00000200d1000800 0200d10002400202 80", - "0012401500000300 00000200d2000800 0200d20002400202 80", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 28, - 0, - 0, - - 0, - 0, - 0, - - 28, - 0, - 25, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 25, - 25, - 27, - - 25, - 25, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_ue_context_release_complete(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "2017001300000200 004005c00100009e 00084003400002", - "2017001300000200 004005c000000001 00084003400001", - "2017001200000200 004005c00100009f 000840020003", - - /* 3 */ - "2017001300000200 004005c00100009d 00084003400001", - "", - "2017001300000200 004005c000000003 00084003400021", - - /* 6 */ - "2017" - "0012000002000040 05c0020000c80008 40020002", - "2017" - "0012000002000040 05c0020000cb0008 40020026", - "2017001200000200 004005c000000001 00084002001f", - - /* 9 */ - "2017" - "0012000002000040 05c0020000c40008 4002000c", - "2017" - "0012000002000040 05c0020000c50008 40020008", - "2017" - "0012000002000040 05c0020000c70008 40020008", - - /* 12 */ - "2017" - "0010000002000040 0200010008400340 072c", - "2017" - "0010000002000040 0200030008400340 072e", - "", - - /* 15 */ - "", - "", - "", - - /* 18 */ - "2017000f00000200 0040020001000840 020001", - "2017000f00000200 0040020002000840 020002", - "2017001100000200 00400200f8000840 048003e993", - - /* 21 */ - "2017000f00000200 00400200d0000840 0200d0", - "2017000f00000200 00400200d1000840 0200d1", - "2017000f00000200 00400200d3000840 0200d3", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 23, - 23, - 22, - - 23, - 0, - 23, - - 22, - 22, - 22, - - 22, - 22, - 22, - - 20, - 20, - 0, - - 0, - 0, - 0, - - 19, - 19, - 21, - - /* 21 */ - 19, - 19, - 19, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_service_request(ogs_pkbuf_t **pkbuf, - uint32_t enb_ue_s1ap_id, uint8_t seq, - uint16_t mac, uint32_t m_tmsi) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000c" - "4037000006000800 020004001a0005 04c7049551004300 060000f110303900" - "6440080000f11007 87b8000086400140 0060000600400000 0001", - - "000c" - "4038000006000800 03400700001a0005 04c7049551004300 060000f110303900" - "6440080000f11007 87b8000086400140 0060000600400000 0001", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 59, - 60, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - int i = 0; - - if (enb_ue_s1ap_id & 0x400000) i = 1; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - enb_ue_s1ap_id = htonl(enb_ue_s1ap_id << 8); - memcpy((*pkbuf)->data + 11, &enb_ue_s1ap_id, 2+i); - mac = htons(mac); - memcpy((*pkbuf)->data + 19+i, &seq, 1); - memcpy((*pkbuf)->data + 20+i, &mac, 2); - m_tmsi = htonl(m_tmsi); - memcpy((*pkbuf)->data + 55+i, &m_tmsi, 4); - - return OGS_OK; -} - -int tests1ap_build_tau_request(ogs_pkbuf_t **pkbuf, int i, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, uint8_t active_flag, - uint32_t m_tmsi, uint8_t seq, uint32_t mac, uint8_t *knas_int) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - /* Initial UE Message */ - "000c" - "406d000006000800 020035001a003b3a 1797c955d80a0748 010bf600f1100002" - "01d900a79e5805f0 f0c040005200f110 30395c1004570220 003103e561249011" - "033358a25d0103d0 e0c1004300060000 f110303900644008 0000f11054f64010" - "0086400130006000 060040d900a79e", - /* Uplink NAS Transport */ - "000d" - "4063000005000000 0200030008000200 01001a003a39178a c93785030748010b" - "f600f110000201d6 004ae05805f070c0 40185200f110303a 5c0a005702200031" - "03e5e03490110357 58a65d0100e0c100 6440080000f11000 02cf900043400600" - "00f1103039", - "", - - /* Crash : 3 */ - - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 113, - 103, - 0, - - 77, - 68, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - if (i == 0) { - enb_ue_s1ap_id = htonl(enb_ue_s1ap_id << 8); - memcpy((*pkbuf)->data + 11, &enb_ue_s1ap_id, 3); - if (active_flag) { - unsigned char *active_buf = (*pkbuf)->data + 26; - *active_buf |= 0x08; - } - mac = htonl(mac); - memcpy((*pkbuf)->data + 19, &mac, 4); - memcpy((*pkbuf)->data + 23, &seq, 1); - m_tmsi = htonl(m_tmsi); - memcpy((*pkbuf)->data + 109, &m_tmsi, 4); - } else if (i == 1) { - ogs_assert(knas_int); - - mme_ue_s1ap_id = htonl(mme_ue_s1ap_id << 8); - memcpy((*pkbuf)->data + 11, &mme_ue_s1ap_id, 3); - enb_ue_s1ap_id = htonl(enb_ue_s1ap_id << 8); - memcpy((*pkbuf)->data + 17, &enb_ue_s1ap_id, 3); - - memcpy((*pkbuf)->data + 29, &seq, 1); - - m_tmsi = htonl(m_tmsi); - memcpy((*pkbuf)->data + 41, &m_tmsi, 4); - - snow_3g_f9(knas_int, seq, (0 << 27), 0, - (*pkbuf)->data + 29, (52 << 3), - (*pkbuf)->data + 25); - } else - ogs_assert_if_reached(); - - return OGS_OK; -} - -int tests1ap_build_extended_service_request(ogs_pkbuf_t **pkbuf, int i, - uint8_t service_type, uint32_t m_tmsi, uint8_t seq, uint8_t *knas_int) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "", - "", - "", - - /* 3 */ - "", - "", - "", - - /* 6 */ - "", - "", - "", - - /* 9 */ - "", - "", - "", - - /* 12 */ - "", - "", - "", - - /* 15 */ - "", - "", - "", - - /* 18 */ - "000c" - "4038000005000800 020002001a00100f 17b51a57a504074c 000504e900a25200" - "4300060009f10700 07006440080009f1 0707080140008640 0130", - - "000d403900000500 0000020001000800 020001001a00100f 17b51a57a504074c" - "000504e900a25200 6440080009f10700 19b0100043400600 09f1070007", - - "", - - /* 21 */ - "000c404900000600 0800048004141300 1a001514172cf294 2e04074c0105f4e6" - "004551b157022000 004300060027f412 3039006440080027 f412000640300086" - "4001200060000600 40e6004551", - "000d404000000500 00000200f8000800 048003e993001a00 151427b426655c03" - "074c0105f4e60045 51b1570220000064 40080027f4120006 4020004340060027" - "f4123039", - "", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 0, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 60, - 61, - 0, - - /* 21 */ - 77, - 68, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - if (i == 18) { - memcpy((*pkbuf)->data + 26, &service_type, sizeof service_type); - m_tmsi = htonl(m_tmsi); - memcpy((*pkbuf)->data + 29, &m_tmsi, sizeof m_tmsi); - - snow_3g_f9(knas_int, seq, (0 << 27), 0, - (*pkbuf)->data + 23, (10 << 3), - (*pkbuf)->data + 19); - } else if (i == 19) { - memcpy((*pkbuf)->data + 32, &service_type, sizeof service_type); - m_tmsi = htonl(m_tmsi); - memcpy((*pkbuf)->data + 35, &m_tmsi, sizeof m_tmsi); - snow_3g_f9(knas_int, seq, (0 << 27), 0, - (*pkbuf)->data + 29, (10 << 3), - (*pkbuf)->data + 25); - } else if (i == 21) { - memcpy((*pkbuf)->data + 28, &service_type, sizeof service_type); - m_tmsi = htonl(m_tmsi); - memcpy((*pkbuf)->data + 31, &m_tmsi, sizeof m_tmsi); - snow_3g_f9(knas_int, seq, (0 << 27), 0, - (*pkbuf)->data + 25, (15 << 3), - (*pkbuf)->data + 21); - } else if (i == 22) { - memcpy((*pkbuf)->data + 34, &service_type, sizeof service_type); - m_tmsi = htonl(m_tmsi); - memcpy((*pkbuf)->data + 37, &m_tmsi, sizeof m_tmsi); - snow_3g_f9(knas_int, seq, (0 << 27), 0, - (*pkbuf)->data + 31, (15 << 3), - (*pkbuf)->data + 27); - } - - return OGS_OK; -} - -int tests1ap_build_pdn_connectivity_request( - ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000d40640000" - "0500000002 0001000800020001 001a003b3a277c 81dab50a0205d011" - "281208696e746572 6e6574036e673204 6d6e6574271a8080 2110010000108106" - "0000000083060000 0000000d00000a00 006440080055f501 0019d01000434006" - "0055f5011022", - "000d40640000" - "0500000002 0001000800020001 001a003b3a2710 3fdafa0a0209d011" - "281208706e746572 6e6574036e673204 6d6e6574271a8080 2110010000108106" - "0000000083060000 0000000d00000a00 006440080055f501 0019d01000434006" - "0055f5011022", - "", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 108, - 108, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_pdn_disconnectivity_request( - ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000d40370000" - "0500000005c08000 0108000800020001 001a000b0a2732 423c53040206d206" - "006440080055f501 0019d01000434006 0055f5011022", - "000d40370000" - "0500000005c08000 0108000800020001 001a000b0a2777 693066040206d206" - "006440080055f501 0019d01000434006 0055f5011022", - "", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 59, - 59, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_e_rab_setup_response( - ogs_pkbuf_t **pkbuf, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, - uint8_t ebi, uint32_t teid, const char *ipstr) -{ - int rv; - ogs_sockaddr_t *addr = NULL; - - S1AP_S1AP_PDU_t pdu; - S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; - S1AP_E_RABSetupResponse_t *E_RABSetupResponse = NULL; - - S1AP_E_RABSetupResponseIEs_t *ie = NULL; - S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; - S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; - S1AP_E_RABSetupListBearerSURes_t *E_RABSetupListBearerSURes = NULL; - - S1AP_E_RABSetupItemBearerSUResIEs_t *item = NULL; - S1AP_E_RABSetupItemBearerSURes_t *e_rab = NULL; - - ogs_gtp_f_teid_t f_teid; - ogs_ip_t ip; - int len; - - memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome = - CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); - - successfulOutcome = pdu.choice.successfulOutcome; - successfulOutcome->procedureCode = S1AP_ProcedureCode_id_E_RABSetup; - successfulOutcome->criticality = S1AP_Criticality_reject; - successfulOutcome->value.present = - S1AP_SuccessfulOutcome__value_PR_E_RABSetupResponse; - - E_RABSetupResponse = &successfulOutcome->value.choice.E_RABSetupResponse; - - ie = CALLOC(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ASN_SEQUENCE_ADD(&E_RABSetupResponse->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_MME_UE_S1AP_ID; - - MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; - - ie = CALLOC(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ASN_SEQUENCE_ADD(&E_RABSetupResponse->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_ENB_UE_S1AP_ID; - - ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; - - ie = CALLOC(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ASN_SEQUENCE_ADD(&E_RABSetupResponse->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListBearerSURes; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = - S1AP_E_RABSetupResponseIEs__value_PR_E_RABSetupListBearerSURes; - - E_RABSetupListBearerSURes = &ie->value.choice.E_RABSetupListBearerSURes; - - *MME_UE_S1AP_ID = mme_ue_s1ap_id; - *ENB_UE_S1AP_ID = enb_ue_s1ap_id; - - item = CALLOC(1, sizeof(S1AP_E_RABSetupItemBearerSUResIEs_t)); - ASN_SEQUENCE_ADD(&E_RABSetupListBearerSURes->list, item); - - item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemBearerSURes; - item->criticality = S1AP_Criticality_ignore; - item->value.present = - S1AP_E_RABSetupItemBearerSUResIEs__value_PR_E_RABSetupItemBearerSURes; - - e_rab = &item->value.choice.E_RABSetupItemBearerSURes; - e_rab->e_RAB_ID = ebi; - - rv = ogs_getaddrinfo(&addr, AF_INET, ipstr, OGS_GTPV1_U_UDP_PORT, 0); - ogs_assert(rv == OGS_OK); - rv = ogs_gtp_sockaddr_to_f_teid(addr, NULL, &f_teid, &len); - ogs_assert(rv == OGS_OK); - ogs_freeaddrinfo(addr); - rv = ogs_gtp_f_teid_to_ip(&f_teid, &ip); - ogs_assert(rv == OGS_OK); - - rv = ogs_asn_ip_to_BIT_STRING(&ip, &e_rab->transportLayerAddress); - ogs_assert(rv == OGS_OK); - ogs_asn_uint32_to_OCTET_STRING(teid, &e_rab->gTP_TEID); - - *pkbuf = ogs_s1ap_encode(&pdu); - if (*pkbuf == NULL) { - ogs_error("ogs_s1ap_encode() failed"); - return OGS_ERROR; - } - return OGS_OK; -} - -int tests1ap_build_e_rab_modify_response(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "2006" - "001b000003000040 0480000001000840 020001001f400600 002500010e", - "2006" - "001b000003000040 0480000001000840 020001001f400600 002500010e", - "", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 31, - 31, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_e_rab_release_response(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "200700190000" - "0300004002 0001000840020001 0045400600000f 40010c", - "200700190000" - "0300004002 0001000840020001 0045400600000f 40010e", - "", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 29, - 29, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_activate_default_bearer_accept( - ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000d40360000" - "0500000005c08000 0107000800020001 001a000a0927e7 f5bb400b6200c200" - "6440080055f50100 19d0100043400600 55f5011022", - "", - "", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 58, - 0, - 0, - - 0, - 0, - 0, - - 59, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_activate_dedicated_bearer_accept( - ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000d403600000500" - "000005c000000001 00080002000100 1a000a0927078a5f 34037200c6006440" - "080000f1109d67aa 50004340060000f1 102b67", - "000d403600000500" - "000005c000000001 00080002000100 1a000a0927c035da 96036200c6006440" - "080000f1109d67aa 50004340060000f1 102b67", - "", - - "", - "", - "", - - "", - "", - "", - - "000d403600000500" - "000005c00200003c 00080002000100 1a000a0927a27f49 d6036200c6006440" - "080000f1109d67aa 50004340060000f1 102b67", - - "000d" - "4036000005000000 05c0020000c40008 0002000c001a000a 0927e3c77e000362" - "00c6006440080000 f110001f20a00043 40060000f1103039", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 58, - 58, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - - 58, - 58, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_modify_bearer_accept( - ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000d" - "4035000005000000 0480000001000800 020001001a000a09 27a5c0d564067200" - "ca006440080064f0 430020a000004340 060064f043020a", - "000d" - "4035000005000000 0480000001000800 020001001a000a09 27a6746cea097204" - "ca006440080064f0 430020a000004340 060064f043020a", - "000d" - "4035000005000000 0480000001000800 020001001a000a09 2726b727fe0a7205" - "ca006440080064f0 430020a000004340 060064f043020a", - - "000d" - "4035000005000000 0480000001000800 020001001a000a09 271070e13b0d7203" - "ca006440080064f0 430020a000004340 060064f043020a", - "", - "", - - "", - "", - "", - - "", - "", - "", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 57, - 57, - 57, - - 57, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_deactivate_bearer_accept( - ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000d40330000" - "0500000002 0001000800020001 001a000a09274c b2ebbd056200ce00" - "6440080055f50100 19d0100043400600 55f5011022", - "000d40330000" - "0500000002 0001000800020001 001a000a0927a9 a1b2bd057200ce00" - "6440080055f50100 19d0100043400600 55f5011022", - "000d40330000" - "0500000002 0001000800020001 001a000a09277d 7f1f80056200ce00" - "6440080055f50100 19d0100043400600 55f5011022", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 59, - 59, - 59, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_bearer_resource_allocation_request( - ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000d" - "403f000005000000 0200010008000200 01001a00161517fe b2b150070203d406" - "04212001000501ff ffffff0064400800 2143650003039000 4340060021436509" - "29", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 67, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -static void build_bearer_resource_modification_request(ogs_pkbuf_t **pkbuf, - uint8_t pti, uint32_t mac, uint8_t seq, uint8_t ebi, - uint8_t tft_code, uint8_t qci, - uint8_t ul_mbr, uint8_t dl_mbr, uint8_t ul_gbr, uint8_t dl_gbr) -{ - int rv; - ogs_pkbuf_t *emmbuf = NULL; - - ogs_nas_eps_message_t message; - ogs_nas_eps_bearer_resource_modification_request_t - *req = &message.esm.bearer_resource_modification_request; - ogs_nas_traffic_flow_aggregate_description_t *tad = - &req->traffic_flow_aggregate; - ogs_nas_eps_quality_of_service_t *qos = &req->required_traffic_flow_qos; - - ogs_gtp_tft_t tft; - ogs_tlv_octet_t octet; - ogs_ipsubnet_t ipsubnet; - - memset(&message, 0, sizeof(message)); - message.esm.h.eps_bearer_identity = 0; - message.esm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_ESM; - message.esm.h.procedure_transaction_identity = pti; - message.esm.h.message_type = - OGS_NAS_EPS_BEARER_RESOURCE_MODIFICATION_REQUEST; - - req->eps_bearer_identity_for_packet_filter.eps_bearer_identity = ebi; - - memset(&tft, 0, sizeof tft); - tft.code = tft_code; - if (tft.code == OGS_GTP_TFT_CODE_REPLACE_PACKET_FILTERS_IN_EXISTING) { - tft.num_of_packet_filter = 1; - tft.pf[0].direction = 1; - tft.pf[0].identifier = 0; - tft.pf[0].precedence = 0x0f; - tft.pf[0].length = 9; - tft.pf[0].component[0].type = - GTP_PACKET_FILTER_IPV4_REMOTE_ADDRESS_TYPE; - rv = ogs_ipsubnet(&ipsubnet, "201.20.2.5", NULL); - ogs_assert(rv == OGS_OK); - tft.pf[0].component[0].ipv4.addr = ipsubnet.sub[0]; - tft.pf[0].component[0].ipv4.mask = ipsubnet.mask[0]; - tft.pf[0].num_of_component = 1; - } else if (tft.code == - OGS_GTP_TFT_CODE_ADD_PACKET_FILTERS_TO_EXISTING_TFT) { - tft.num_of_packet_filter = 1; - tft.pf[0].direction = 1; - tft.pf[0].identifier = 4; - tft.pf[0].precedence = 0x0f; - - rv = ogs_ipsubnet(&ipsubnet, "cafe::9", "120"); - ogs_assert(rv == OGS_OK); -#if 1 - tft.pf[0].length = 18; - tft.pf[0].component[0].type = - GTP_PACKET_FILTER_IPV6_REMOTE_ADDRESS_PREFIX_LENGTH_TYPE; - memcpy(tft.pf[0].component[0].ipv6.addr, ipsubnet.sub, - sizeof(tft.pf[0].component[0].ipv6.addr)); - tft.pf[0].component[0].ipv6.prefixlen = 120; -#else - tft.pf[0].length = 33; - tft.pf[0].component[0].type = - GTP_PACKET_FILTER_IPV6_REMOTE_ADDRESS_TYPE; - memcpy(tft.pf[0].component[0].ipv6_mask.addr, ipsubnet.sub, - sizeof(tft.pf[0].component[0].ipv6_mask.addr)); - memcpy(tft.pf[0].component[0].ipv6_mask.mask, ipsubnet.mask, - sizeof(tft.pf[0].component[0].ipv6_mask.mask)); -#endif - tft.pf[0].num_of_component = 1; - - } else if (tft.code == OGS_GTP_TFT_CODE_CREATE_NEW_TFT) { - tft.num_of_packet_filter = 4; - - tft.pf[0].direction = 1; - tft.pf[0].identifier = 0; - tft.pf[0].precedence = 0x01; - tft.pf[0].length = 0x17; - tft.pf[0].component[0].type = - GTP_PACKET_FILTER_PROTOCOL_IDENTIFIER_NEXT_HEADER_TYPE; - tft.pf[0].component[0].proto = 0x11; /* UDP */ - tft.pf[0].component[1].type = - GTP_PACKET_FILTER_IPV4_LOCAL_ADDRESS_TYPE; - rv = ogs_ipsubnet(&ipsubnet, "172.20.166.84", NULL); - ogs_assert(rv == OGS_OK); - tft.pf[0].component[1].ipv4.addr = ipsubnet.sub[0]; - tft.pf[0].component[1].ipv4.mask = ipsubnet.mask[0]; - tft.pf[0].component[2].type = - GTP_PACKET_FILTER_IPV4_REMOTE_ADDRESS_TYPE; - rv = ogs_ipsubnet(&ipsubnet, "172.18.128.20", NULL); - ogs_assert(rv == OGS_OK); - tft.pf[0].component[2].ipv4.addr = ipsubnet.sub[0]; - tft.pf[0].component[2].ipv4.mask = ipsubnet.mask[0]; - tft.pf[0].component[3].type = - GTP_PACKET_FILTER_SINGLE_REMOTE_PORT_TYPE; - tft.pf[0].component[3].port.low = 20001; - tft.pf[0].num_of_component = 4; - - tft.pf[1].direction = 2; - tft.pf[1].identifier = 1; - tft.pf[1].precedence = 0x02; - tft.pf[1].length = 0x17; - tft.pf[1].component[0].type = - GTP_PACKET_FILTER_PROTOCOL_IDENTIFIER_NEXT_HEADER_TYPE; - tft.pf[1].component[0].proto = 0x11; /* UDP */ - tft.pf[1].component[1].type = - GTP_PACKET_FILTER_IPV4_LOCAL_ADDRESS_TYPE; - rv = ogs_ipsubnet(&ipsubnet, "172.20.166.84", NULL); - ogs_assert(rv == OGS_OK); - tft.pf[1].component[1].ipv4.addr = ipsubnet.sub[0]; - tft.pf[1].component[1].ipv4.mask = ipsubnet.mask[0]; - tft.pf[1].component[2].type = - GTP_PACKET_FILTER_IPV4_REMOTE_ADDRESS_TYPE; - rv = ogs_ipsubnet(&ipsubnet, "172.18.128.20", NULL); - ogs_assert(rv == OGS_OK); - tft.pf[1].component[2].ipv4.addr = ipsubnet.sub[0]; - tft.pf[1].component[2].ipv4.mask = ipsubnet.mask[0]; - tft.pf[1].component[3].type = - GTP_PACKET_FILTER_SINGLE_LOCAL_PORT_TYPE; - tft.pf[1].component[3].port.low = 20360; - tft.pf[1].num_of_component = 4; - - tft.pf[2].direction = 1; - tft.pf[2].identifier = 2; - tft.pf[2].precedence = 0x03; - tft.pf[2].length = 0x17; - tft.pf[2].component[0].type = - GTP_PACKET_FILTER_PROTOCOL_IDENTIFIER_NEXT_HEADER_TYPE; - tft.pf[2].component[0].proto = 0x11; /* UDP */ - tft.pf[2].component[1].type = - GTP_PACKET_FILTER_IPV4_LOCAL_ADDRESS_TYPE; - rv = ogs_ipsubnet(&ipsubnet, "172.20.166.84", NULL); - ogs_assert(rv == OGS_OK); - tft.pf[2].component[1].ipv4.addr = ipsubnet.sub[0]; - tft.pf[2].component[1].ipv4.mask = ipsubnet.mask[0]; - tft.pf[2].component[2].type = - GTP_PACKET_FILTER_IPV4_REMOTE_ADDRESS_TYPE; - rv = ogs_ipsubnet(&ipsubnet, "172.18.128.20", NULL); - ogs_assert(rv == OGS_OK); - tft.pf[2].component[2].ipv4.addr = ipsubnet.sub[0]; - tft.pf[2].component[2].ipv4.mask = ipsubnet.mask[0]; - tft.pf[2].component[3].type = - GTP_PACKET_FILTER_SINGLE_REMOTE_PORT_TYPE; - tft.pf[2].component[3].port.low = 20002; - tft.pf[2].num_of_component = 4; - - tft.pf[3].direction = 2; - tft.pf[3].identifier = 3; - tft.pf[3].precedence = 0x04; - tft.pf[3].length = 0x17; - tft.pf[3].component[0].type = - GTP_PACKET_FILTER_PROTOCOL_IDENTIFIER_NEXT_HEADER_TYPE; - tft.pf[3].component[0].proto = 0x11; /* UDP */ - tft.pf[3].component[1].type = - GTP_PACKET_FILTER_IPV4_LOCAL_ADDRESS_TYPE; - rv = ogs_ipsubnet(&ipsubnet, "172.20.166.84", NULL); - ogs_assert(rv == OGS_OK); - tft.pf[3].component[1].ipv4.addr = ipsubnet.sub[0]; - tft.pf[3].component[1].ipv4.mask = ipsubnet.mask[0]; - tft.pf[3].component[2].type = - GTP_PACKET_FILTER_IPV4_REMOTE_ADDRESS_TYPE; - rv = ogs_ipsubnet(&ipsubnet, "172.18.128.20", NULL); - ogs_assert(rv == OGS_OK); - tft.pf[3].component[2].ipv4.addr = ipsubnet.sub[0]; - tft.pf[3].component[2].ipv4.mask = ipsubnet.mask[0]; - tft.pf[3].component[3].type = - GTP_PACKET_FILTER_SINGLE_LOCAL_PORT_TYPE; - tft.pf[3].component[3].port.low = 20361; - tft.pf[3].num_of_component = 4; - } - tad->length = ogs_gtp_build_tft(&octet, - &tft, tad->buffer, OGS_GTP_MAX_TRAFFIC_FLOW_TEMPLATE); - - if (ul_mbr || dl_mbr || ul_gbr || dl_gbr) { - req->presencemask |= - OGS_NAS_EPS_BEARER_RESOURCE_MODIFICATION_REQUEST_REQUIRED_TRAFFIC_FLOW_QOS_PRESENT; - qos->length = 5; - qos->qci = qci; - qos->ul_mbr = ul_mbr; - qos->dl_mbr = dl_mbr; - qos->ul_gbr = ul_gbr; - qos->dl_gbr = dl_gbr; - } - - emmbuf = ogs_nas_eps_plain_encode(&message); - - message.h.security_header_type = - OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED; - message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; - message.h.message_authentication_code = htobe32(mac); - message.h.sequence_number = seq; - - ogs_assert(ogs_pkbuf_push(emmbuf, sizeof(ogs_nas_eps_security_header_t))); - memcpy(emmbuf->data, &message.h, sizeof(ogs_nas_eps_security_header_t)); - - *pkbuf = emmbuf; -} - -int tests1ap_build_bearer_resource_modification_request( - ogs_pkbuf_t **pkbuf, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, - uint8_t pti, uint32_t mac, uint8_t seq, uint8_t ebi, - uint8_t tft_code, uint8_t qci, - uint8_t ul_mbr, uint8_t dl_mbr, uint8_t ul_gbr, uint8_t dl_gbr) -{ - ogs_pkbuf_t *emmbuf = NULL; - - S1AP_S1AP_PDU_t pdu; - S1AP_InitiatingMessage_t *initiatingMessage = NULL; - S1AP_UplinkNASTransport_t *UplinkNASTransport = NULL; - - S1AP_UplinkNASTransport_IEs_t *ie = NULL; - S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; - S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; - S1AP_NAS_PDU_t *NAS_PDU = NULL; - - memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage = - CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); - - initiatingMessage = pdu.choice.initiatingMessage; - initiatingMessage->procedureCode = - S1AP_ProcedureCode_id_uplinkNASTransport; - initiatingMessage->criticality = S1AP_Criticality_ignore; - initiatingMessage->value.present = - S1AP_InitiatingMessage__value_PR_UplinkNASTransport; - - UplinkNASTransport = &initiatingMessage->value.choice.UplinkNASTransport; - - ie = CALLOC(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ASN_SEQUENCE_ADD(&UplinkNASTransport->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = - S1AP_UplinkNASTransport_IEs__value_PR_MME_UE_S1AP_ID; - - MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; - - ie = CALLOC(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ASN_SEQUENCE_ADD(&UplinkNASTransport->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = - S1AP_UplinkNASTransport_IEs__value_PR_ENB_UE_S1AP_ID; - - ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; - - ie = CALLOC(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ASN_SEQUENCE_ADD(&UplinkNASTransport->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_NAS_PDU; - - NAS_PDU = &ie->value.choice.NAS_PDU; - - build_bearer_resource_modification_request( - &emmbuf, pti, mac, seq, ebi, - tft_code, qci, ul_mbr, dl_mbr, ul_gbr, dl_gbr); - ogs_assert(emmbuf); - NAS_PDU->size = emmbuf->len; - NAS_PDU->buf = CALLOC(NAS_PDU->size, sizeof(uint8_t)); - memcpy(NAS_PDU->buf, emmbuf->data, NAS_PDU->size); - ogs_pkbuf_free(emmbuf); - - *MME_UE_S1AP_ID = mme_ue_s1ap_id; - *ENB_UE_S1AP_ID = enb_ue_s1ap_id; - - *pkbuf = ogs_s1ap_encode(&pdu); - if (*pkbuf == NULL) { - ogs_error("ogs_s1ap_encode() failed"); - return OGS_ERROR; - } - return OGS_OK; -} - -int tests1ap_build_bearer_resource_modification_request2( - ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000d403c00000500 0000020001000800 020001001a001312 279d165c7b0c0203" - "d60705a400010203 5824006440080000 f110000019c00043 40060000f1100001", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 64, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_path_switch_request( - ogs_pkbuf_t **pkbuf, int target, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, - int num_of_bearer, uint8_t ebi, uint32_t teid, - const char *ipstr1, const char *ipstr2) -{ - int rv; - int i; - - S1AP_S1AP_PDU_t pdu; - S1AP_InitiatingMessage_t *initiatingMessage = NULL; - S1AP_PathSwitchRequest_t *PathSwitchRequest = NULL; - - S1AP_PathSwitchRequestIEs_t *ie = NULL; - S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; - S1AP_E_RABToBeSwitchedDLList_t *E_RABToBeSwitchedDLList = NULL; - S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; - S1AP_EUTRAN_CGI_t *EUTRAN_CGI = NULL; - S1AP_TAI_t *TAI = NULL; - S1AP_UESecurityCapabilities_t *UESecurityCapabilities = NULL; - - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - - memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage = - CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); - - initiatingMessage = pdu.choice.initiatingMessage; - initiatingMessage->procedureCode = S1AP_ProcedureCode_id_PathSwitchRequest; - initiatingMessage->criticality = S1AP_Criticality_reject; - initiatingMessage->value.present = - S1AP_InitiatingMessage__value_PR_PathSwitchRequest; - - PathSwitchRequest = &initiatingMessage->value.choice.PathSwitchRequest; - - ie = CALLOC(1, sizeof(S1AP_PathSwitchRequestIEs_t)); - ASN_SEQUENCE_ADD(&PathSwitchRequest->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_ENB_UE_S1AP_ID; - - ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; - - ie = CALLOC(1, sizeof(S1AP_PathSwitchRequestIEs_t)); - ASN_SEQUENCE_ADD(&PathSwitchRequest->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_E_RABToBeSwitchedDLList; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = - S1AP_PathSwitchRequestIEs__value_PR_E_RABToBeSwitchedDLList; - - E_RABToBeSwitchedDLList = &ie->value.choice.E_RABToBeSwitchedDLList; - - ie = CALLOC(1, sizeof(S1AP_PathSwitchRequestIEs_t)); - ASN_SEQUENCE_ADD(&PathSwitchRequest->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_SourceMME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_MME_UE_S1AP_ID; - - MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; - - ie = CALLOC(1, sizeof(S1AP_PathSwitchRequestIEs_t)); - ASN_SEQUENCE_ADD(&PathSwitchRequest->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_EUTRAN_CGI; - - EUTRAN_CGI = &ie->value.choice.EUTRAN_CGI; - - ie = CALLOC(1, sizeof(S1AP_PathSwitchRequestIEs_t)); - ASN_SEQUENCE_ADD(&PathSwitchRequest->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_TAI; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_TAI; - - TAI = &ie->value.choice.TAI; - - ie = CALLOC(1, sizeof(S1AP_PathSwitchRequestIEs_t)); - ASN_SEQUENCE_ADD(&PathSwitchRequest->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_UESecurityCapabilities; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = - S1AP_PathSwitchRequestIEs__value_PR_UESecurityCapabilities; - - UESecurityCapabilities = &ie->value.choice.UESecurityCapabilities; - - *ENB_UE_S1AP_ID = enb_ue_s1ap_id; - *MME_UE_S1AP_ID = mme_ue_s1ap_id; - - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(mme_ue_s1ap_id); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - - for (i = 0; i < num_of_bearer; i++) { - S1AP_E_RABToBeSwitchedDLItemIEs_t *item = NULL; - S1AP_E_RABToBeSwitchedDLItem_t *e_rab = NULL; - - ogs_sockaddr_t *addr = NULL; - ogs_gtp_f_teid_t f_teid; - ogs_ip_t ip; - int len; - - item = CALLOC(1, sizeof(S1AP_E_RABToBeSwitchedDLItemIEs_t)); - ASN_SEQUENCE_ADD(&E_RABToBeSwitchedDLList->list, item); - - item->id = S1AP_ProtocolIE_ID_id_E_RABToBeSwitchedDLItem; - item->criticality = S1AP_Criticality_reject; - item->value.present = - S1AP_E_RABToBeSwitchedDLItemIEs__value_PR_E_RABToBeSwitchedDLItem; - - e_rab = &item->value.choice.E_RABToBeSwitchedDLItem; - - e_rab->e_RAB_ID = ebi+i; - - if (target == 0) { - rv = ogs_getaddrinfo(&addr, AF_INET, ipstr1, - OGS_GTPV1_U_UDP_PORT, 0); - rv = ogs_gtp_sockaddr_to_f_teid( - addr, NULL, &f_teid, &len); - ogs_freeaddrinfo(addr); - } else { - rv = ogs_getaddrinfo(&addr, AF_INET, ipstr2, - OGS_GTPV1_U_UDP_PORT, 0); - rv = ogs_gtp_sockaddr_to_f_teid( - addr, NULL, &f_teid, &len); - ogs_freeaddrinfo(addr); - } - ogs_assert(rv == OGS_OK); - rv = ogs_gtp_f_teid_to_ip(&f_teid, &ip); - ogs_assert(rv == OGS_OK); - - rv = ogs_asn_ip_to_BIT_STRING(&ip, &e_rab->transportLayerAddress); - ogs_assert(rv == OGS_OK); - ogs_asn_uint32_to_OCTET_STRING(teid+i, &e_rab->gTP_TEID); - } - - ogs_s1ap_buffer_to_OCTET_STRING( - &mme_ue->e_cgi.plmn_id, OGS_PLMN_ID_LEN, &EUTRAN_CGI->pLMNidentity); - EUTRAN_CGI->cell_ID.size = 4; - EUTRAN_CGI->cell_ID.buf = CALLOC( - EUTRAN_CGI->cell_ID.size, sizeof(uint8_t)); - ogs_assert(EUTRAN_CGI->cell_ID.buf); - EUTRAN_CGI->cell_ID.buf[0] = (mme_ue->e_cgi.cell_id >> 24); - EUTRAN_CGI->cell_ID.buf[1] = (mme_ue->e_cgi.cell_id >> 16); - EUTRAN_CGI->cell_ID.buf[2] = (mme_ue->e_cgi.cell_id >> 8); - EUTRAN_CGI->cell_ID.buf[3] = (mme_ue->e_cgi.cell_id); - EUTRAN_CGI->cell_ID.bits_unused = 4; - - ogs_asn_uint16_to_OCTET_STRING( - mme_ue->tai.tac, &TAI->tAC); - ogs_s1ap_buffer_to_OCTET_STRING( - &mme_ue->tai.plmn_id, OGS_PLMN_ID_LEN, &TAI->pLMNidentity); - - UESecurityCapabilities->encryptionAlgorithms.size = 2; - UESecurityCapabilities->encryptionAlgorithms.buf = - CALLOC(UESecurityCapabilities->encryptionAlgorithms.size, - sizeof(uint8_t)); - UESecurityCapabilities->encryptionAlgorithms.bits_unused = 0; - UESecurityCapabilities->encryptionAlgorithms.buf[0] = - (mme_ue->ue_network_capability.eea << 1); - - UESecurityCapabilities->integrityProtectionAlgorithms.size = 2; - UESecurityCapabilities->integrityProtectionAlgorithms.buf = - CALLOC(UESecurityCapabilities-> - integrityProtectionAlgorithms.size, sizeof(uint8_t)); - UESecurityCapabilities->integrityProtectionAlgorithms.bits_unused = 0; - UESecurityCapabilities->integrityProtectionAlgorithms.buf[0] = - (mme_ue->ue_network_capability.eia << 1); - - *pkbuf = ogs_s1ap_encode(&pdu); - if (*pkbuf == NULL) { - ogs_error("ogs_s1ap_encode() failed"); - return OGS_ERROR; - } - return OGS_OK; -} - -int tests1ap_build_handover_required( - ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "0000" - "0081030000060000 0005c0020000c400 080002000c000100 0100000240020220" - "0004000d0000f110 0000043000f11030 3900680080d080ce 4080ab0f1014c598" - "00018000bf06ec4d 00100302c0000000 000015a800140672 0af00348f10013d0" - "3bc58414903bc588 09401de2c2100440 13f212249010127d ad808fd50398381c" - "08fd503983805f50 37868baa010c846f b057874162d62e82 1f42f2e159f821d0" - "9c0009e28aa1a001 2d888026d0600040 8008066072003e41 5250d46210208184" - "3423c135002214d6 dfb0a0b06502c402 000004008177faab 4677235334a0e867" - "213e804030000100 4e40024500004e40 0246000000f11000 043a000000f11000" - "1f20a0000022", - - "0000" - "00810e0000060000 0005c0020000c500 0800020008000100 0100000240020220" - "0004000d0000f110 00001f2000f11030 3900680080db80d9 4080ab0f1014c598" - "00018000bf06ec4d 00100302c0000000 000015a800140672 0af003e8f10013d0" - "3bc58414903bc588 09401de2c2100440 13f212249010127d ad808fd50398381c" - "08fd503983805f50 37868baa010c846f b057874162d62e82 1f42f2e159f821d0" - "9c0009e28aa1a001 2d888050d1bc0040 8008066072000874 1250d46210208184" - "3423c135002214d6 dfb0a0b06502c402 000004008177faab 4677235334a0e867" - "2134804030000100 4e40024500004e40 0246000000f11000 1f20a10000f11000" - "043a000000350000 f110001f20a00000 22", - - "0000" - "0081190000060000 0005c0020000c600 080002000d000100 0100000240020220" - "0004000d0000f110 0000043000f11030 3900680080e680e4 4080ab0f1014c598" - "00018000bf06ec4d 00100302c0000000 000015a800140672 0af00348f10013d0" - "3bc58414903bc588 09401de2c2100440 13f212249010127d ad808fd50398381c" - "08fd503983805f50 37868baa010c846f b057874162d62e82 1f42f2e159f821d0" - "9c0009e28aa1a001 2d888050514c0040 8008066072003e41 5250d46210208184" - "3423c135002214d6 dfb0a0b06502c402 000004008177faab 4677235334a0e867" - "213e804030000100 4e40024500004e40 0246000000f11000 043a020000f11000" - "1f20a00000340000 f11000043a000000 350000f110001f20 a0000022", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 264, - 275, - 286, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_handover_failure(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "4001 0012000002000040 05c0020000c5 000240020000", - - "", - "", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 22, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_handover_request_ack( - ogs_pkbuf_t **pkbuf, int target, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, - int num_of_bearer, uint8_t ebi, uint32_t teid, - const char *ipstr1, const char *ipstr2) -{ - int rv; - int i; - - S1AP_S1AP_PDU_t pdu; - S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; - S1AP_HandoverRequestAcknowledge_t *HandoverRequestAcknowledge = NULL; - - S1AP_HandoverRequestAcknowledgeIEs_t *ie = NULL; - S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; - S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; - S1AP_E_RABAdmittedList_t *E_RABAdmittedList = NULL; - S1AP_Target_ToSource_TransparentContainer_t - *Target_ToSource_TransparentContainer = NULL; - - char hexbuf[OGS_MAX_SDU_LEN]; - const char *payload = - "00 80810bf900d8af40 00a0339057801f47 88009e81de2c20a4" - "81de2c404a00ef16 2000010044013f21 2249008093efd243 3914cd2aa0a0142f" - "f2214d6dfb82c194 0b10080000020040 bbfd55aeab41ad80 8fd50398381c08fd" - "503983804d037868 baa016423342bc3a 18b58fa084ca833f a17970acfc10e84e" - "0004f14550d00096 c88900"; - - memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome = - CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); - - successfulOutcome = pdu.choice.successfulOutcome; - successfulOutcome->procedureCode = S1AP_ProcedureCode_id_HandoverResourceAllocation; - successfulOutcome->criticality = S1AP_Criticality_reject; - successfulOutcome->value.present = - S1AP_SuccessfulOutcome__value_PR_HandoverRequestAcknowledge; - - HandoverRequestAcknowledge = - &successfulOutcome->value.choice.HandoverRequestAcknowledge; - - ie = CALLOC(1, sizeof(S1AP_HandoverRequestAcknowledgeIEs_t)); - ASN_SEQUENCE_ADD(&HandoverRequestAcknowledge->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = - S1AP_HandoverRequestAcknowledgeIEs__value_PR_MME_UE_S1AP_ID; - - MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; - - ie = CALLOC(1, sizeof(S1AP_HandoverRequestAcknowledgeIEs_t)); - ASN_SEQUENCE_ADD(&HandoverRequestAcknowledge->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = - S1AP_HandoverRequestAcknowledgeIEs__value_PR_ENB_UE_S1AP_ID; - - ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; - - ie = CALLOC(1, sizeof(S1AP_HandoverRequestAcknowledgeIEs_t)); - ASN_SEQUENCE_ADD(&HandoverRequestAcknowledge->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_E_RABAdmittedList; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = - S1AP_HandoverRequestAcknowledgeIEs__value_PR_E_RABAdmittedList; - - E_RABAdmittedList = &ie->value.choice.E_RABAdmittedList; - - ie = CALLOC(1, sizeof(S1AP_HandoverRequestAcknowledgeIEs_t)); - ASN_SEQUENCE_ADD(&HandoverRequestAcknowledge->protocolIEs, ie); - - ie->id = S1AP_ProtocolIE_ID_id_Target_ToSource_TransparentContainer; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_HandoverRequestAcknowledgeIEs__value_PR_Target_ToSource_TransparentContainer; - - Target_ToSource_TransparentContainer = - &ie->value.choice.Target_ToSource_TransparentContainer; - - *MME_UE_S1AP_ID = mme_ue_s1ap_id; - *ENB_UE_S1AP_ID = enb_ue_s1ap_id; - - for (i = 0; i < num_of_bearer; i++) { - S1AP_E_RABAdmittedItemIEs_t *item = NULL; - S1AP_E_RABAdmittedItem_t *e_rab = NULL; - - ogs_sockaddr_t *addr = NULL; - ogs_gtp_f_teid_t f_teid; - ogs_ip_t ip; - int len; - - item = CALLOC(1, sizeof(S1AP_E_RABAdmittedItemIEs_t)); - ASN_SEQUENCE_ADD(&E_RABAdmittedList->list, item); - - item->id = S1AP_ProtocolIE_ID_id_E_RABAdmittedItem; - item->criticality = S1AP_Criticality_ignore; - item->value.present = - S1AP_E_RABAdmittedItemIEs__value_PR_E_RABAdmittedItem; - - e_rab = &item->value.choice.E_RABAdmittedItem; - - e_rab->e_RAB_ID = ebi+i; - - if (target == 0) { - rv = ogs_getaddrinfo(&addr, AF_INET, ipstr1, - OGS_GTPV1_U_UDP_PORT, 0); - rv = ogs_gtp_sockaddr_to_f_teid( - addr, NULL, &f_teid, &len); - ogs_freeaddrinfo(addr); - } else { - rv = ogs_getaddrinfo(&addr, AF_INET, ipstr2, - OGS_GTPV1_U_UDP_PORT, 0); - rv = ogs_gtp_sockaddr_to_f_teid( - addr, NULL, &f_teid, &len); - ogs_freeaddrinfo(addr); - } - ogs_assert(rv == OGS_OK); - rv = ogs_gtp_f_teid_to_ip(&f_teid, &ip); - ogs_assert(rv == OGS_OK); - - rv = ogs_asn_ip_to_BIT_STRING(&ip, &e_rab->transportLayerAddress); - ogs_assert(rv == OGS_OK); - ogs_asn_uint32_to_OCTET_STRING(teid+i, &e_rab->gTP_TEID); - - e_rab->dL_transportLayerAddress = - (S1AP_TransportLayerAddress_t *) - CALLOC(1, sizeof(S1AP_TransportLayerAddress_t)); - rv = ogs_asn_ip_to_BIT_STRING(&ip, e_rab->dL_transportLayerAddress); - ogs_assert(rv == OGS_OK); - e_rab->dL_gTP_TEID = (S1AP_GTP_TEID_t *) - CALLOC(1, sizeof(S1AP_GTP_TEID_t)); - ogs_asn_uint32_to_OCTET_STRING(teid+i+10, e_rab->dL_gTP_TEID); - - e_rab->uL_TransportLayerAddress = - (S1AP_TransportLayerAddress_t *) - CALLOC(1, sizeof(S1AP_TransportLayerAddress_t)); - rv = ogs_asn_ip_to_BIT_STRING(&ip, e_rab->uL_TransportLayerAddress); - ogs_assert(rv == OGS_OK); - e_rab->uL_GTP_TEID = (S1AP_GTP_TEID_t *) - CALLOC(1, sizeof(S1AP_GTP_TEID_t)); - ogs_asn_uint32_to_OCTET_STRING(teid+i+20, e_rab->uL_GTP_TEID); - } - - ogs_s1ap_buffer_to_OCTET_STRING( - OGS_HEX(payload, strlen(payload), hexbuf), 132, - Target_ToSource_TransparentContainer); - - *pkbuf = ogs_s1ap_encode(&pdu); - if (*pkbuf == NULL) { - ogs_error("ogs_s1ap_encode() failed"); - return OGS_ERROR; - } - return OGS_OK; -} - -int tests1ap_build_handover_request_ack_static( - ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "2001" - "0080e80000040000 4005c0020000c500 0840020008001240 47010014401f78a1" - "f07f000001010007 080f807f00000101 0007090f807f0000 010100070a001440" - "1f78c1f07f000001 010007100f807f00 0001010007110f80 7f00000101000712" - "007b008086808400 80810bf900d8af40 00a0339057801f47 88009e81de2c20a4" - "81de2c404a00ef16 2000010044013f21 2249008093efd243 3914cd2aa0a0142f" - "f2214d6dfb82c194 0b10080000020040 bbfd55aeab41ad80 8fd50398381c08fd" - "503983804d037868 baa016423342bc3a 18b58fa084ca833f a17970acfc10e84e" - "0004f14550d00096 c88900", - - "2001" - "0080e80000040000 4005c0020000c600 084002000d001240 47010014401f78a1" - "f00a01237b010009 080f800a01237b01 0009090f800a0123 7b0100090a001440" - "1f78c1f00a01237b 010009100f800a01 237b010009110f80 0a01237b01000912" - "007b008086808400 80810bf900d8af40 00a0339057801a47 88009e81de2c20a4" - "81de2c404a00ef16 2000010044013f21 2249008093effa43 3914cd2aa0a0140f" - "f2214d6dfb82c194 0b10080000020040 bbfd55aeab01ad80 8fd50398381c08fd" - "503983804d037868 baa016423342bc3a 18b58fa084ca833f a17970acfc10e84e" - "0004f14550d00096 c88980", - - "2001" - "0080e80000040000 4005c0020000c700 0840020009001240 47010014401f78a1" - "f00a01237c010008 080f800a01237c01 0008090f800a0123 7c0100080a001440" - "1f78c1f00a01237c 010008100f800a01 237c010008110f80 0a01237c01000812" - "007b008086808400 80810bf900d8af40 00a0339057801f47 88009e81de2c20a4" - "81de2c404a00ef16 2000010044013f21 2249008093efd243 3914cd2aa0a0144f" - "f2214d6dfb82c194 0b10080000020040 bbfd55aeab81ad80 8fd50398381c08fd" - "503983804d037868 baa016423342bc3a 18b58fa084ca833f a17970acfc10e84e" - "0004f14550d00096 c88a00", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 237, - 237, - 237, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_enb_status_transfer( - ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "0018" - "4027000003000000 05c0020000c40008 0002000c005a0011 00000059400b0500" - "004b000000001100 00", - "0018" - "4027000003000000 05c0020000c50008 00020008005a0011 00000059400b0500" - "00a8000000004100 00", - "", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 43, - 43, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_enb_configuration_transfer( - ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "0028" - "403b000001008140 3440049699000004 3004969900020004 969900001f200496" - "9900020000000098 401341f0ac110e02 0000009940070200 f8ac110e02", - "0028" - "403b000001008140 344004969900001f 2004969900020004 9699000004300496" - "9900020000000098 401341f0ac110e02 0000009940070200 f8ac110e02", - "", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 63, - 63, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_handover_notify(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "0002" - "4028000004000000 05c0020000c50008 0002000800644008 0000f11000043a00" - "004340060000f110 3039", - "0002" - "4028000004000000 05c0020000c60008 0002000d00644008 0000f110001f20a0" - "004340060000f110 3039", - "", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 44, - 44, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_handover_cancel(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "0004" - "0018000003000000 05c0020000c60008 0002000d00024002 0120", - "", - "", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 28, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_s1_reset(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000e001500000200 0240020060005c00 084000005b000220 04", - "", - "", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 25, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int tests1ap_build_uplink_nas_transport(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "000d40809d000005 0000000200010008 00020001001a0074 7327f908d4bd0307" - "636a390167000300 0581005155f55d11 030c914477680205 490000055ad2e2b1" - "252d467ff6de6c47 efd568375b303613 166fb51c6d160cc2 8ab462b006a3d98a" - "31da90060b0673c5 9c512684158bb119 2c88b3058b37e1ad 081bca84c1582d07" - "93ede4bddc6d2693 e566371b00644008 0009f1070019b010 004340060009f107" - "0007", - "", - "", - - "", - "", - "", - - "", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 162, - 0, - 0, - - 0, - 0, - 0, - - 0, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int testgtpu_build_ping(ogs_pkbuf_t **sendbuf, - const uint32_t teid, const char *src_ip, const char *dst_ip) -{ - int rv; - ogs_pkbuf_t *pkbuf = NULL; - ogs_gtp_header_t *gtp_h = NULL; - ogs_ipsubnet_t src_ipsub, dst_ipsub; - - ogs_assert(src_ip); - ogs_assert(dst_ip); - rv = ogs_ipsubnet(&src_ipsub, src_ip, NULL); - ogs_assert(rv == OGS_OK); - rv = ogs_ipsubnet(&dst_ipsub, dst_ip, NULL); - ogs_assert(rv == OGS_OK); - - pkbuf = ogs_pkbuf_alloc(NULL, - 200 /* enough for ICMP; use smaller buffer */); - ogs_pkbuf_put(pkbuf, 200); - memset(pkbuf->data, 0, pkbuf->len); - - gtp_h = (ogs_gtp_header_t *)pkbuf->data; - gtp_h->flags = 0x30; - gtp_h->type = OGS_GTPU_MSGTYPE_GPDU; - gtp_h->teid = htonl(teid); - - if (dst_ipsub.family == AF_INET) { - struct ip *ip_h = NULL; - struct icmp *icmp_h = NULL; - - gtp_h->length = htons(sizeof *ip_h + ICMP_MINLEN); - - ip_h = (struct ip *)(pkbuf->data + OGS_GTPV1U_HEADER_LEN); - icmp_h = (struct icmp *)((uint8_t *)ip_h + sizeof *ip_h); - - ip_h->ip_v = 4; - ip_h->ip_hl = 5; - ip_h->ip_tos = 0; - ip_h->ip_id = rand(); - ip_h->ip_off = 0; - ip_h->ip_ttl = 255; - ip_h->ip_p = IPPROTO_ICMP; - ip_h->ip_len = gtp_h->length; - ip_h->ip_src.s_addr = src_ipsub.sub[0]; - ip_h->ip_dst.s_addr = dst_ipsub.sub[0]; - ip_h->ip_sum = ogs_in_cksum((uint16_t *)ip_h, sizeof *ip_h); - - icmp_h->icmp_type = 8; - icmp_h->icmp_seq = rand(); - icmp_h->icmp_id = rand(); - icmp_h->icmp_cksum = ogs_in_cksum((uint16_t *)icmp_h, ICMP_MINLEN); - } else if (dst_ipsub.family == AF_INET6) { - struct ip6_hdr *ip6_h = NULL; - struct icmp6_hdr *icmp6_h = NULL; - uint16_t plen = 0; - uint8_t nxt = 0; - uint8_t *p = NULL; - - gtp_h->length = htons(sizeof *ip6_h + sizeof *icmp6_h); - plen = htons(sizeof *icmp6_h); - nxt = IPPROTO_ICMPV6; - - p = (uint8_t *)pkbuf->data + OGS_GTPV1U_HEADER_LEN; - ip6_h = (struct ip6_hdr *)p; - icmp6_h = (struct icmp6_hdr *)((uint8_t *)ip6_h + sizeof *ip6_h); - - memcpy(p, src_ipsub.sub, sizeof src_ipsub.sub); - p += sizeof src_ipsub.sub; - memcpy(p, dst_ipsub.sub, sizeof dst_ipsub.sub); - p += sizeof dst_ipsub.sub; - p += 2; memcpy(p, &plen, 2); p += 2; - p += 3; *p = nxt; p += 1; - - icmp6_h->icmp6_type = ICMP6_ECHO_REQUEST; - icmp6_h->icmp6_seq = rand(); - icmp6_h->icmp6_id = rand(); - - icmp6_h->icmp6_cksum = ogs_in_cksum( - (uint16_t *)ip6_h, sizeof *ip6_h + sizeof *icmp6_h); - - ip6_h->ip6_flow = htonl(0x60000001); - ip6_h->ip6_plen = plen; - ip6_h->ip6_nxt = nxt;; - ip6_h->ip6_hlim = 0xff; - memcpy(ip6_h->ip6_src.s6_addr, src_ipsub.sub, sizeof src_ipsub.sub); - memcpy(ip6_h->ip6_dst.s6_addr, dst_ipsub.sub, sizeof dst_ipsub.sub); - } else - ogs_assert_if_reached(); - - *sendbuf = pkbuf; - - return OGS_OK; -} - -int testgtpu_build_slacc_rs(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "32ff003400000001 00000000 6000000000083aff fe80000000000000 0000000000000002" - "ff02000000000000 0000000000000002 85007d3500000000", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 60, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int testsgsap_location_update_accept(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "0a01082926240000 111893040509f107 09260e05f49ee88e 64", - "0a01087942120000 000030040527f412 c9580e05f437ab9c c5", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 25, - 25, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int testsgsap_location_update_reject(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "0b01082926240000 1118930f01030405 09f1070926", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 21, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int testsgsap_imsi_detach_ack(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "1401082926240000 111893" - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 11, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int testsgsap_paging_request(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "0101082926240000 111893021003766c 72076578616d706c 65036e6574200101" - "040509f1070926", - "0101082926240000 111892021003766c 72076578616d706c 65036e6574200101" - "040509f1070926", /* Paging-Reject */ - "0101082926240000 111893021003766c 72076578616d706c 65036e6574200102" - "040509f1070926", /* Paging-Request with SMS */ - - /* Paging-Request for crash-test */ - "0101087942120000 000030021003766c 72076578616d706c 65036e6574200101" - "040527f412c958", - "", - "", - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 39, - 39, - 39, - - 39, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int testsgsap_reset_indication(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "15021003766c7207 6578616d706c6503 6e6574", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 19, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int testsgsap_release_request(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "1b01082926240000 111893", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 11, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int testsgsap_downlink_unitdata(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "0701082926240000 1118931626090123 0100079144775810 0650001700048032" - "2400009160404044 150009c8329bfd06 4d9b53", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 51, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} - -int testsgsap_mm_information_request(ogs_pkbuf_t **pkbuf, int i) -{ - const char *payload[TESTS1AP_MAX_MESSAGE] = { - "1a01087942120000 0000301714430483 d46413450483d464 1347917071028401" - "29", - "", - "", - - }; - uint16_t len[TESTS1AP_MAX_MESSAGE] = { - 33, - 0, - 0, - }; - char hexbuf[OGS_MAX_SDU_LEN]; - - *pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); - ogs_pkbuf_put_data(*pkbuf, - OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); - - return OGS_OK; -} diff --git a/tests/app/test-packet.h b/tests/app/test-packet.h deleted file mode 100644 index 9d5b0b58f..000000000 --- a/tests/app/test-packet.h +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef TEST_PACKET_H -#define TEST_PACKET_H - -#include "ogs-s1ap.h" -#include "mme/s1ap-build.h" - -#include "test-common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern bool test_no_mme_self; - -#define testenb_gtpu_server(x) test_gtpu_server(x, OGS_GTPV1_U_UDP_PORT) -#define testenb_gtpu_read(x) test_gtpu_read(x) -int testenb_gtpu_send(ogs_socknode_t *node, ogs_pkbuf_t *sendbuf); -#define testenb_gtpu_close(x) test_gtpu_close(x) - -int tests1ap_build_invalid_packet(ogs_pkbuf_t **pkbuf, int i); - -int tests1ap_build_setup_req( - ogs_pkbuf_t **pkbuf, S1AP_ENB_ID_PR present, uint32_t enb_id, - int tac, uint16_t mcc, uint16_t mnc, uint16_t mnc_len); -int tests1ap_build_initial_ue_msg(ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_identity_response(ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_authentication_response( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_authentication_failure( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_security_mode_complete( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_esm_information_response( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_ue_capability_info_indication( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_initial_context_setup_response( - ogs_pkbuf_t **pkbuf, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, - uint8_t ebi, uint32_t teid, const char *ipstr); -int tests1ap_build_ue_context_modification_response( - ogs_pkbuf_t **pkbuf, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id); -int tests1ap_build_initial_context_setup_failure( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_attach_complete(ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_emm_status(ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_detach_request(ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_ue_context_release_request( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_ue_context_release_complete( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_service_request(ogs_pkbuf_t **pkbuf, - uint32_t enb_ue_s1ap_id, uint8_t seq, - uint16_t mac, uint32_t m_tmsi); -int tests1ap_build_tau_request(ogs_pkbuf_t **pkbuf, int i, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, uint8_t active_flag, - uint32_t m_tmsi, uint8_t seq, uint32_t mac, uint8_t *knas_int); -int tests1ap_build_extended_service_request(ogs_pkbuf_t **pkbuf, int i, - uint8_t service_type, uint32_t m_tmsi, uint8_t seq, uint8_t *knas_int); -int tests1ap_build_pdn_connectivity_request( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_pdn_disconnectivity_request( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_e_rab_setup_response( - ogs_pkbuf_t **pkbuf, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, - uint8_t ebi, uint32_t teid, const char *ipstr); -int tests1ap_build_e_rab_modify_response( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_e_rab_release_response( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_activate_default_bearer_accept( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_activate_dedicated_bearer_accept( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_modify_bearer_accept( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_deactivate_bearer_accept( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_bearer_resource_allocation_request( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_bearer_resource_modification_request( - ogs_pkbuf_t **pkbuf, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, - uint8_t pti, uint32_t mac, uint8_t seq, uint8_t ebi, - uint8_t tft_code, uint8_t qci, - uint8_t ul_mbr, uint8_t dl_mbr, uint8_t ul_gbr, uint8_t dl_gbr); -int tests1ap_build_bearer_resource_modification_request2( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_path_switch_request( - ogs_pkbuf_t **pkbuf, int target, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, - int num_of_bearer, uint8_t ebi, uint32_t teid, - const char *ipstr1, const char *ipstr2); -int tests1ap_build_handover_required(ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_handover_failure(ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_handover_request_ack( - ogs_pkbuf_t **pkbuf, int target, - uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, - int num_of_bearer, uint8_t ebi, uint32_t teid, - const char *ipstr1, const char *ipstr2); -int tests1ap_build_handover_request_ack_static( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_enb_status_transfer( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_enb_configuration_transfer( - ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_handover_notify(ogs_pkbuf_t **pkbuf, int i); -int tests1ap_build_handover_cancel(ogs_pkbuf_t **pkbuf, int i); - -int tests1ap_build_s1_reset(ogs_pkbuf_t **pkbuf, int i); - -int tests1ap_build_uplink_nas_transport(ogs_pkbuf_t **pkbuf, int i); - -int testgtpu_build_ping(ogs_pkbuf_t **sendbuf, - const uint32_t teid, const char *src_ip, const char *dst_ip); -int testgtpu_build_slacc_rs(ogs_pkbuf_t **sendbuf, int i); - -int testsgsap_location_update_accept(ogs_pkbuf_t **pkbuf, int i); -int testsgsap_location_update_reject(ogs_pkbuf_t **pkbuf, int i); -int testsgsap_imsi_detach_ack(ogs_pkbuf_t **pkbuf, int i); -int testsgsap_paging_request(ogs_pkbuf_t **pkbuf, int i); -int testsgsap_reset_indication(ogs_pkbuf_t **pkbuf, int i); -int testsgsap_release_request(ogs_pkbuf_t **pkbuf, int i); -int testsgsap_downlink_unitdata(ogs_pkbuf_t **pkbuf, int i); -int testsgsap_mm_information_request(ogs_pkbuf_t **pkbuf, int i); - -#ifdef __cplusplus -} -#endif - -#endif /* TEST_PACKET_H */ diff --git a/tests/epc/abts-main.c b/tests/attach/abts-main.c similarity index 76% rename from tests/epc/abts-main.c rename to tests/attach/abts-main.c index e0bd632c1..baece1606 100644 --- a/tests/epc/abts-main.c +++ b/tests/attach/abts-main.c @@ -17,22 +17,26 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-app.h" abts_suite *test_s1setup(abts_suite *suite); -abts_suite *test_attach(abts_suite *suite); -abts_suite *test_volte(abts_suite *suite); -abts_suite *test_handover(abts_suite *suite); -abts_suite *test_crash(abts_suite *suite); +abts_suite *test_guti(abts_suite *suite); +abts_suite *test_auth(abts_suite *suite); +abts_suite *test_idle(abts_suite *suite); +abts_suite *test_emm_status(abts_suite *suite); +abts_suite *test_reset(abts_suite *suite); +abts_suite *test_ue_context(abts_suite *suite); const struct testlist { abts_suite *(*func)(abts_suite *suite); } alltests[] = { {test_s1setup}, - {test_attach}, - {test_volte}, - {test_handover}, - {test_crash}, + {test_guti}, + {test_auth}, + {test_idle}, + {test_emm_status}, + {test_reset}, + {test_ue_context}, {NULL}, }; @@ -65,7 +69,7 @@ int main(int argc, const char *const argv[]) abts_suite *suite = NULL; atexit(terminate); - test_epc_run(argc, argv, "epc.yaml", initialize); + test_app_run(argc, argv, "sample.yaml", initialize); for (i = 0; alltests[i].func; i++) suite = alltests[i].func(suite); diff --git a/tests/attach/auth-test.c b/tests/attach/auth-test.c new file mode 100644 index 000000000..646371d91 --- /dev/null +++ b/tests/attach/auth-test.c @@ -0,0 +1,419 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"901707364000060\", " + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x1079baf0; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* eNB connects to MME */ + s1ap = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap); + + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send S1-Setup Reqeust */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Setup Response */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.additional_update_type = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Attach Request */ + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Attach Request - No Integrity */ + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication failure - SYNCH failure */ + emmbuf = testemm_build_authentication_failure( + test_ue, EMM_CAUSE_SYNCH_FAILURE, 0x11223344); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication failure - MAC failure */ + emmbuf = testemm_build_authentication_failure( + test_ue, EMM_CAUSE_MAC_FAILURE, 0); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication reject */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from MME */ + testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} + +abts_suite *test_auth(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/attach/emm-status-test.c b/tests/attach/emm-status-test.c new file mode 100644 index 000000000..3ec0636b4 --- /dev/null +++ b/tests/attach/emm-status-test.c @@ -0,0 +1,272 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"901707364000060\", " + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x1079baf0; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* eNB connects to MME */ + s1ap = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap); + + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send S1-Setup Reqeust */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Setup Response */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send EMM Status */ + emmbuf = testemm_build_emm_status( + test_ue, ESM_CAUSE_MESSAGE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from MME */ + testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} + +abts_suite *test_emm_status(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/attach/guti-test.c b/tests/attach/guti-test.c new file mode 100644 index 000000000..a724d7fb9 --- /dev/null +++ b/tests/attach/guti-test.c @@ -0,0 +1,504 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + uint32_t enb_ue_s1ap_id; + uint64_t mme_ue_s1ap_id; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"901707364000060\", " + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x1079baf0; + test_ue->nas.ksi = 0; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* eNB connects to MME */ + s1ap = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap); + + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send S1-Setup Reqeust */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Setup Response */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + sess->esm_information_param.pco = 1; + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send GTP-U Router Solicitation */ + rv = test_gtpu_send_slacc_rs(gtpu, bearer); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U Router Solicitation */ + recvbuf = test_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + +#if __linux__ + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, bearer, TEST_PING_IPV6); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); +#endif + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.location_area_identication = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.mobile_station_classmark_3 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Request */ + mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id--; + enb_ue_s1ap_id = test_ue->enb_ue_s1ap_id--; + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Error Indicaation */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + test_ue->mme_ue_s1ap_id = mme_ue_s1ap_id; + test_ue->enb_ue_s1ap_id = enb_ue_s1ap_id; + + /* Send ESM Information Response */ + sess->esm_information_param.pco = 1; + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Detach Request */ + emmbuf = testemm_build_detach_request(test_ue, 1); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Request - INVALID GUTI */ + test_ue->nas_eps_guti.m_tmsi = 0x1234; + + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.location_area_identication = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.mobile_station_classmark_3 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Identity Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Identity response - INVALID IMSI */ + test_ue->mobile_identity_imsi.digit15 = 5; + + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Attach Reject */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from MME */ + testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} + +abts_suite *test_guti(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/attach/idle-test.c b/tests/attach/idle-test.c new file mode 100644 index 000000000..86abbed93 --- /dev/null +++ b/tests/attach/idle-test.c @@ -0,0 +1,407 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"901707364000060\", " + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x54f6401; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_EPS_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* eNB connects to MME */ + s1ap = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap); + + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send S1-Setup Reqeust */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Setup Response */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Request */ + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Service Request */ + emmbuf = testemm_build_service_request(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Data, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send TAU Request */ + memset(&test_ue->tau_request_param, 0, sizeof(test_ue->tau_request_param)); + test_ue->tau_request_param.ciphered = 1; + test_ue->tau_request_param.ue_network_capability = 1; + test_ue->tau_request_param.last_visited_registered_tai = 1; + test_ue->tau_request_param.drx_parameter = 1; + test_ue->tau_request_param.eps_bearer_context_status = 1; + test_ue->tau_request_param.ms_network_capability = 1; + test_ue->tau_request_param.tmsi_status = 1; + test_ue->tau_request_param.mobile_station_classmark_2 = 1; + test_ue->tau_request_param.ue_usage_setting = 1; + test_ue->tau_request_param.device_properties = 1; + emmbuf = testemm_build_tau_request(test_ue, true); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive TAU Accept */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send TAU Request */ + memset(&test_ue->tau_request_param, 0, sizeof(test_ue->tau_request_param)); + test_ue->tau_request_param.ciphered = 1; + test_ue->tau_request_param.ue_network_capability = 1; + test_ue->tau_request_param.last_visited_registered_tai = 1; + test_ue->tau_request_param.drx_parameter = 1; + test_ue->tau_request_param.eps_bearer_context_status = 1; + test_ue->tau_request_param.ms_network_capability = 1; + test_ue->tau_request_param.tmsi_status = 1; + test_ue->tau_request_param.mobile_station_classmark_2 = 1; + test_ue->tau_request_param.ue_usage_setting = 1; + test_ue->tau_request_param.device_properties = 1; + emmbuf = testemm_build_tau_request(test_ue, false); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive TAU Accept */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from MME */ + testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} + +abts_suite *test_idle(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/epc/meson.build b/tests/attach/meson.build similarity index 74% rename from tests/epc/meson.build rename to tests/attach/meson.build index 345cb365f..e50be0f0b 100644 --- a/tests/epc/meson.build +++ b/tests/attach/meson.build @@ -15,19 +15,20 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -testepc_simple_sources = files(''' +testapp_attach_sources = files(''' abts-main.c s1setup-test.c - attach-test.c - volte-test.c - handover-test.c - crash-test.c - + guti-test.c + auth-test.c + idle-test.c + emm-status-test.c + reset-test.c + ue-context-test.c '''.split()) -testepc_simple_exe = executable('simple', - sources : testepc_simple_sources, +testapp_attach_exe = executable('attach', + sources : testapp_attach_sources, c_args : testunit_core_cc_flags, dependencies : libtestepc_dep) -test('simple', testepc_simple_exe, is_parallel : false, suite: 'epc') +test('attach', testapp_attach_exe, is_parallel : false, suite: 'epc') diff --git a/tests/attach/reset-test.c b/tests/attach/reset-test.c new file mode 100644 index 000000000..67e94ea3f --- /dev/null +++ b/tests/attach/reset-test.c @@ -0,0 +1,372 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + S1AP_MME_UE_S1AP_ID_t *mme_ue_s1ap_id = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"901707364000060\", " + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x54f6401; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* eNB connects to MME */ + s1ap = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap); + + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send S1-Setup Reqeust */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Setup Response */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Service Request */ + emmbuf = testemm_build_service_request(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Data, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Service reject */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send S1-Reset */ + mme_ue_s1ap_id = CALLOC(1, sizeof(S1AP_MME_UE_S1AP_ID_t)); + ogs_assert(mme_ue_s1ap_id); + *mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id; + sendbuf = ogs_s1ap_build_s1_reset_partial( + S1AP_Cause_PR_radioNetwork, + S1AP_CauseRadioNetwork_release_due_to_eutran_generated_reason, + mme_ue_s1ap_id, NULL); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Reset Acknowledge */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Service Request - INVALID M-TMSI */ + test_ue->nas_eps_guti.m_tmsi = 0x1234; + + emmbuf = testemm_build_service_request(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Data, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Service reject */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from MME */ + testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} + +abts_suite *test_reset(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/epc/s1setup-test.c b/tests/attach/s1setup-test.c similarity index 84% rename from tests/epc/s1setup-test.c rename to tests/attach/s1setup-test.c index 463c04663..3dfa7bb5b 100644 --- a/tests/epc/s1setup-test.c +++ b/tests/attach/s1setup-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-packet.h" +#include "test-common.h" #define NUM_OF_TEST_DUPLICATED_ENB 4 @@ -31,14 +31,14 @@ static void s1setup_test1(abts_case *tc, void *data) int i; for (i = 0; i < NUM_OF_TEST_DUPLICATED_ENB; i++) { - node[i] = testenb_s1ap_client("127.0.0.1"); + node[i] = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, node[i]); } for (i = 0; i < NUM_OF_TEST_DUPLICATED_ENB; i++) { - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(node[i], sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -72,14 +72,14 @@ static void s1setup_test2(abts_case *tc, void *data) int i; for (i = 0; i < NUM_OF_TEST_ENB; i++) { - node[i] = testenb_s1ap_client("127.0.0.1"); + node[i] = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, node[i]); } for (i = 0; i < NUM_OF_TEST_ENB; i++) { - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64+i, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64+i); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(node[i], sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -108,11 +108,11 @@ static void s1setup_test3(abts_case *tc, void *data) ogs_pkbuf_t *sendbuf; ogs_pkbuf_t *recvbuf; - s1ap = testenb_s1ap_client("127.0.0.1"); + s1ap = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, s1ap); - rv = tests1ap_build_invalid_packet(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_invalid_packet(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); diff --git a/tests/attach/ue-context-test.c b/tests/attach/ue-context-test.c new file mode 100644 index 000000000..05c335306 --- /dev/null +++ b/tests/attach/ue-context-test.c @@ -0,0 +1,1064 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"901707364000060\", " + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x1079baf0; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* eNB connects to MME */ + s1ap = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap); + + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send S1-Setup Reqeust */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Setup Response */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Initial context setup failure */ + sendbuf = test_s1ap_build_initial_context_setup_failure(test_ue, + S1AP_Cause_PR_radioNetwork, + S1AP_CauseRadioNetwork_radio_connection_with_ue_lost); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + + /* Send UE Context Release Request */ + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, + S1AP_CauseRadioNetwork_radio_connection_with_ue_lost); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from MME */ + testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} + +static void test2_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"901707364000060\", " + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x64010; + test_ue->nas.ksi = 0; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_EPS_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* eNB connects to MME */ + s1ap = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap); + + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send S1-Setup Reqeust */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x2343d); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Setup Response */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit_no_required = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.old_guti_type = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + test_ue->initial_ue_param.gummei_id = 1; + test_ue->initial_ue_param.gummei.mme_gid = 512; + test_ue->initial_ue_param.gummei.mme_code = 1; + test_ue->initial_ue_param.gummei_type = 1; + test_ue->initial_ue_param.gummei.type = S1AP_GUMMEIType_native; + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Identity Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit_no_required = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.old_guti_type = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + test_ue->initial_ue_param.gummei_id = 1; + test_ue->initial_ue_param.gummei.mme_gid = 512; + test_ue->initial_ue_param.gummei.mme_code = 1; + test_ue->initial_ue_param.gummei_type = 1; + test_ue->initial_ue_param.gummei.type = S1AP_GUMMEIType_native; + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Initial context setup failure */ + sendbuf = test_s1ap_build_initial_context_setup_failure(test_ue, + S1AP_Cause_PR_radioNetwork, + S1AP_CauseRadioNetwork_radio_connection_with_ue_lost); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(100); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from MME */ + testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} + +static void test3_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"901707364000060\", " + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x64010; + test_ue->nas.ksi = 0; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_EPS_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* eNB connects to MME */ + s1ap = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap); + + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send S1-Setup Reqeust */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x2343d); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Setup Response */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit_no_required = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.old_guti_type = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + test_ue->initial_ue_param.gummei_id = 1; + test_ue->initial_ue_param.gummei.mme_gid = 512; + test_ue->initial_ue_param.gummei.mme_code = 1; + test_ue->initial_ue_param.gummei_type = 1; + test_ue->initial_ue_param.gummei.type = S1AP_GUMMEIType_native; + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Identity Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit_no_required = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.old_guti_type = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + test_ue->initial_ue_param.gummei_id = 1; + test_ue->initial_ue_param.gummei.mme_gid = 512; + test_ue->initial_ue_param.gummei.mme_code = 1; + test_ue->initial_ue_param.gummei_type = 1; + test_ue->initial_ue_param.gummei.type = S1AP_GUMMEIType_native; + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Request */ + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Service Request */ + emmbuf = testemm_build_service_request(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Data, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Initial context setup failure */ + sendbuf = test_s1ap_build_initial_context_setup_failure(test_ue, + S1AP_Cause_PR_radioNetwork, + S1AP_CauseRadioNetwork_radio_connection_with_ue_lost); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + + /* Send UE Context Release Request */ + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Service Request */ + emmbuf = testemm_build_service_request(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Data, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Service Reject */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(100); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from MME */ + testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} +abts_suite *test_ue_context(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + abts_run_test(suite, test2_func, NULL); + abts_run_test(suite, test3_func, NULL); + + return suite; +} diff --git a/tests/common/application.c b/tests/common/application.c index f4d0113bb..a8c29c326 100644 --- a/tests/common/application.c +++ b/tests/common/application.c @@ -20,17 +20,7 @@ #include "test-config-private.h" #include "test-common.h" -static int connected_count = 0; -static void test_diam_logger_handler(enum fd_hook_type type, struct msg * msg, - struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, - void * regdata) -{ - if (type == HOOK_PEER_CONNECT_SUCCESS) { - connected_count++; - } -} - -static void test_app_run(int argc, const char *const argv[], +static void run(int argc, const char *const argv[], const char *name, void (*init)(const char * const argv[])) { int rv; @@ -71,29 +61,12 @@ static void test_app_run(int argc, const char *const argv[], (*init)(new_argv); } -void test_epc_run(int argc, const char *const argv[], - const char *name, void (*init)(const char * const argv[])) -{ - ogs_diam_logger_register(test_diam_logger_handler); - - test_app_run(argc, argv, name, init); - -#if 0 /* We will not use this */ - while(1) { - if (connected_count == 1) break; - ogs_msleep(50); - } -#endif - - ogs_msleep(500); /* Wait for listening all sockets */ -} - -void test_5gc_run(int argc, const char *const argv[], +void test_app_run(int argc, const char *const argv[], const char *name, void (*init)(const char * const argv[])) { int rv; - test_app_run(argc, argv, name, init); + run(argc, argv, name, init); test_context_init(); @@ -103,7 +76,7 @@ void test_5gc_run(int argc, const char *const argv[], ogs_msleep(500); /* Wait for listening all sockets */ } -#define MAX_CHILD_PROCESS 8 +#define MAX_CHILD_PROCESS 16 #define OGS_ARG_MAX 256 static ogs_proc_t process[MAX_CHILD_PROCESS]; diff --git a/tests/common/application.h b/tests/common/application.h index 3ed0dc6e4..2d8502ea6 100644 --- a/tests/common/application.h +++ b/tests/common/application.h @@ -28,9 +28,7 @@ extern "C" { #endif -void test_epc_run(int argc, const char *const argv[], - const char *name, void (*init)(const char * const argv[])); -void test_5gc_run(int argc, const char *const argv[], +void test_app_run(int argc, const char *const argv[], const char *name, void (*init)(const char * const argv[])); void test_child_terminate(void); ogs_thread_t *test_child_create(const char *name, const char *const argv[]); diff --git a/tests/common/context.c b/tests/common/context.c index b65a891f9..37e1f9064 100644 --- a/tests/common/context.c +++ b/tests/common/context.c @@ -22,15 +22,33 @@ static test_context_t self; +static OGS_POOL(test_ue_pool, test_ue_t); +static OGS_POOL(test_sess_pool, test_sess_t); +static OGS_POOL(test_bearer_pool, test_bearer_t); + static int context_initialized = 0; void test_context_init(void) { + int rv; + ogs_assert(context_initialized == 0); /* Initialize AMF context */ memset(&self, 0, sizeof(test_context_t)); + ogs_pool_init(&test_ue_pool, ogs_config()->pool.ue); + ogs_pool_init(&test_sess_pool, ogs_config()->pool.sess); + ogs_pool_init(&test_bearer_pool, ogs_config()->pool.bearer); + + rv = ogs_getaddrinfo(&test_self()->gnb1_addr, AF_UNSPEC, + "127.0.0.2", OGS_GTPV1_U_UDP_PORT, 0); + ogs_assert(rv == OGS_OK); + + rv = ogs_getaddrinfo(&test_self()->gnb2_addr, AF_UNSPEC, + "127.0.0.3", OGS_GTPV1_U_UDP_PORT, 0); + ogs_assert(rv == OGS_OK); + context_initialized = 1; } @@ -38,6 +56,19 @@ void test_context_final(void) { ogs_assert(context_initialized == 1); + ogs_socknode_remove_all(&self.ngap_list); + ogs_socknode_remove_all(&self.ngap_list6); + + ogs_socknode_remove_all(&self.s1ap_list); + ogs_socknode_remove_all(&self.s1ap_list6); + + ogs_freeaddrinfo(test_self()->gnb1_addr); + ogs_freeaddrinfo(test_self()->gnb2_addr); + + ogs_pool_final(&test_ue_pool); + ogs_pool_final(&test_bearer_pool); + ogs_pool_final(&test_sess_pool); + context_initialized = 0; } @@ -48,22 +79,49 @@ test_context_t *test_self(void) static int test_context_prepare(void) { + self.s1ap_port = OGS_S1AP_SCTP_PORT; + self.ngap_port = OGS_NGAP_SCTP_PORT; + return OGS_OK; } static int test_context_validation(void) { - if (test_self()->served_tai[0].list2.num) { - memcpy(&test_self()->tai, - &test_self()->served_tai[0].list2.tai[0], sizeof(ogs_5gs_tai_t)); - } else if (test_self()->served_tai[0].list0.tai[0].num) { - test_self()->tai.tac = test_self()->served_tai[0].list0.tai[0].tac[0]; - memcpy(&test_self()->tai.plmn_id, - &test_self()->served_tai[0].list0.tai[0].plmn_id, + ogs_socknode_t *snode = NULL; + + snode = ogs_list_first(&test_self()->s1ap_list); + if (snode) test_self()->s1ap_addr = snode->addr; + snode = ogs_list_first(&test_self()->s1ap_list6); + if (snode) test_self()->s1ap_addr6 = snode->addr; + + snode = ogs_list_first(&test_self()->ngap_list); + if (snode) test_self()->ngap_addr = snode->addr; + snode = ogs_list_first(&test_self()->ngap_list6); + if (snode) test_self()->ngap_addr6 = snode->addr; + + if (test_self()->e_served_tai[0].list2.num) { + memcpy(&test_self()->e_tai, + &test_self()->e_served_tai[0].list2.tai[0], sizeof(ogs_5gs_tai_t)); + } else if (test_self()->e_served_tai[0].list0.tai[0].num) { + test_self()->e_tai.tac = + test_self()->e_served_tai[0].list0.tai[0].tac[0]; + memcpy(&test_self()->e_tai.plmn_id, + &test_self()->e_served_tai[0].list0.tai[0].plmn_id, OGS_PLMN_ID_LEN); } - memcpy(&test_self()->nr_cgi.plmn_id, &test_self()->tai.plmn_id, + if (test_self()->nr_served_tai[0].list2.num) { + memcpy(&test_self()->nr_tai, + &test_self()->nr_served_tai[0].list2.tai[0], sizeof(ogs_5gs_tai_t)); + } else if (test_self()->nr_served_tai[0].list0.tai[0].num) { + test_self()->nr_tai.tac = + test_self()->nr_served_tai[0].list0.tai[0].tac[0]; + memcpy(&test_self()->nr_tai.plmn_id, + &test_self()->nr_served_tai[0].list0.tai[0].plmn_id, + OGS_PLMN_ID_LEN); + } + + memcpy(&test_self()->nr_cgi.plmn_id, &test_self()->nr_tai.plmn_id, OGS_PLMN_ID_LEN); test_self()->nr_cgi.cell_id = 0x40001; @@ -92,113 +150,129 @@ int test_context_parse_config(void) while (ogs_yaml_iter_next(&amf_iter)) { const char *amf_key = ogs_yaml_iter_key(&amf_iter); ogs_assert(amf_key); - if (!strcmp(amf_key, "guami")) { - ogs_yaml_iter_t guami_array, guami_iter; - ogs_yaml_iter_recurse(&amf_iter, &guami_array); + if (!strcmp(amf_key, "ngap")) { + ogs_yaml_iter_t ngap_array, ngap_iter; + ogs_yaml_iter_recurse(&amf_iter, &ngap_array); do { - const char *mcc = NULL, *mnc = NULL; - const char *region = NULL, *set = NULL; - const char *pointer = NULL; - ogs_assert(self.num_of_served_guami <= - MAX_NUM_OF_SERVED_GUAMI); + int family = AF_UNSPEC; + int i, num = 0; + const char *hostname[OGS_MAX_NUM_OF_HOSTNAME]; + uint16_t port = self.ngap_port; + const char *dev = NULL; + ogs_sockaddr_t *addr = NULL; - if (ogs_yaml_iter_type(&guami_array) == + if (ogs_yaml_iter_type(&ngap_array) == YAML_MAPPING_NODE) { - memcpy(&guami_iter, &guami_array, + memcpy(&ngap_iter, &ngap_array, sizeof(ogs_yaml_iter_t)); - } else if (ogs_yaml_iter_type(&guami_array) == + } else if (ogs_yaml_iter_type(&ngap_array) == YAML_SEQUENCE_NODE) { - if (!ogs_yaml_iter_next(&guami_array)) + if (!ogs_yaml_iter_next(&ngap_array)) break; - ogs_yaml_iter_recurse(&guami_array, - &guami_iter); - } else if (ogs_yaml_iter_type(&guami_array) == + ogs_yaml_iter_recurse(&ngap_array, &ngap_iter); + } else if (ogs_yaml_iter_type(&ngap_array) == YAML_SCALAR_NODE) { break; } else ogs_assert_if_reached(); - while (ogs_yaml_iter_next(&guami_iter)) { - const char *guami_key = - ogs_yaml_iter_key(&guami_iter); - ogs_assert(guami_key); - if (!strcmp(guami_key, "plmn_id")) { - ogs_yaml_iter_t plmn_id_iter; + while (ogs_yaml_iter_next(&ngap_iter)) { + const char *ngap_key = + ogs_yaml_iter_key(&ngap_iter); + ogs_assert(ngap_key); + if (!strcmp(ngap_key, "family")) { + const char *v = ogs_yaml_iter_value(&ngap_iter); + if (v) family = atoi(v); + if (family != AF_UNSPEC && + family != AF_INET && family != AF_INET6) { + ogs_warn("Ignore family(%d) : " + "AF_UNSPEC(%d), " + "AF_INET(%d), AF_INET6(%d) ", + family, AF_UNSPEC, AF_INET, AF_INET6); + family = AF_UNSPEC; + } + } else if (!strcmp(ngap_key, "addr") || + !strcmp(ngap_key, "name")) { + ogs_yaml_iter_t hostname_iter; + ogs_yaml_iter_recurse( + &ngap_iter, &hostname_iter); + ogs_assert(ogs_yaml_iter_type(&hostname_iter) != + YAML_MAPPING_NODE); - ogs_yaml_iter_recurse(&guami_iter, - &plmn_id_iter); - while (ogs_yaml_iter_next(&plmn_id_iter)) { - const char *plmn_id_key = - ogs_yaml_iter_key(&plmn_id_iter); - ogs_assert(plmn_id_key); - if (!strcmp(plmn_id_key, "mcc")) { - mcc = ogs_yaml_iter_value( - &plmn_id_iter); - } else if (!strcmp(plmn_id_key, "mnc")) { - mnc = ogs_yaml_iter_value( - &plmn_id_iter); + do { + if (ogs_yaml_iter_type(&hostname_iter) == + YAML_SEQUENCE_NODE) { + if (!ogs_yaml_iter_next(&hostname_iter)) + break; } - } - if (mcc && mnc) { - ogs_plmn_id_build( - &self.served_guami[ - self.num_of_served_guami]. - plmn_id, - atoi(mcc), atoi(mnc), strlen(mnc)); - } - } else if (!strcmp(guami_key, "amf_id")) { - ogs_yaml_iter_t amf_id_iter; - - ogs_yaml_iter_recurse(&guami_iter, - &amf_id_iter); - while (ogs_yaml_iter_next(&amf_id_iter)) { - const char *amf_id_key = - ogs_yaml_iter_key(&amf_id_iter); - ogs_assert(amf_id_key); - if (!strcmp(amf_id_key, "region")) { - region = ogs_yaml_iter_value( - &amf_id_iter); - } else if (!strcmp(amf_id_key, "set")) { - set = ogs_yaml_iter_value( - &amf_id_iter); - } else if (!strcmp(amf_id_key, "pointer")) { - pointer = ogs_yaml_iter_value( - &amf_id_iter); - } - } - - if (region && set) { - ogs_amf_id_build( - &self.served_guami[ - self.num_of_served_guami]. - amf_id, - atoi(region), atoi(set), - pointer ? atoi(pointer) : 0); - } + ogs_assert(num <= OGS_MAX_NUM_OF_HOSTNAME); + hostname[num++] = + ogs_yaml_iter_value(&hostname_iter); + } while ( + ogs_yaml_iter_type(&hostname_iter) == + YAML_SEQUENCE_NODE); + } else if (!strcmp(ngap_key, "port")) { + const char *v = ogs_yaml_iter_value(&ngap_iter); + if (v) port = atoi(v); + } else if (!strcmp(ngap_key, "dev")) { + dev = ogs_yaml_iter_value(&ngap_iter); } else - ogs_warn("unknown key `%s`", guami_key); + ogs_warn("unknown key `%s`", ngap_key); } - if (mnc && mcc && region && set) { - self.num_of_served_guami++; - } else { - ogs_warn("Ignore guami : " - "mcc(%s), mnc(%s), region(%s), set(%s)", - mcc, mnc, region, set); + addr = NULL; + for (i = 0; i < num; i++) { + rv = ogs_addaddrinfo(&addr, + family, hostname[i], port, 0); + ogs_assert(rv == OGS_OK); } - } while (ogs_yaml_iter_type(&guami_array) == + + if (addr) { + if (ogs_config()->parameter.no_ipv4 == 0) + ogs_socknode_add( + &self.ngap_list, AF_INET, addr); + if (ogs_config()->parameter.no_ipv6 == 0) + ogs_socknode_add( + &self.ngap_list6, AF_INET6, addr); + ogs_freeaddrinfo(addr); + } + + if (dev) { + rv = ogs_socknode_probe( + ogs_config()->parameter.no_ipv4 ? + NULL : &self.ngap_list, + ogs_config()->parameter.no_ipv6 ? + NULL : &self.ngap_list6, + dev, port); + ogs_assert(rv == OGS_OK); + } + + } while (ogs_yaml_iter_type(&ngap_array) == YAML_SEQUENCE_NODE); - } else if (!strcmp(amf_key, "tai")) { + + if (ogs_list_first(&self.ngap_list) == NULL && + ogs_list_first(&self.ngap_list6) == NULL) { + rv = ogs_socknode_probe( + ogs_config()->parameter.no_ipv4 ? + NULL : &self.ngap_list, + ogs_config()->parameter.no_ipv6 ? + NULL : &self.ngap_list6, + NULL, self.ngap_port); + ogs_assert(rv == OGS_OK); + } + } if (!strcmp(amf_key, "tai")) { int num_of_list0 = 0; ogs_5gs_tai0_list_t *list0 = NULL; ogs_5gs_tai2_list_t *list2 = NULL; - ogs_assert(self.num_of_served_tai <= + ogs_assert(self.num_of_nr_served_tai <= OGS_MAX_NUM_OF_SERVED_TAI); - list0 = &self.served_tai[self.num_of_served_tai].list0; + list0 = + &self.nr_served_tai[self.num_of_nr_served_tai].list0; ogs_assert(list0); - list2 = &self.served_tai[self.num_of_served_tai].list2; + list2 = + &self.nr_served_tai[self.num_of_nr_served_tai].list2; ogs_assert(list2); ogs_yaml_iter_t tai_array, tai_iter; @@ -307,7 +381,7 @@ int test_context_parse_config(void) YAML_SEQUENCE_NODE); if (list2->num || num_of_list0) { - self.num_of_served_tai++; + self.num_of_nr_served_tai++; } } else if (!strcmp(amf_key, "plmn")) { ogs_yaml_iter_t plmn_array, plmn_iter; @@ -458,6 +532,244 @@ int test_context_parse_config(void) } else ogs_warn("unknown key `%s`", amf_key); } + } else if (!strcmp(root_key, "mme")) { + ogs_yaml_iter_t mme_iter; + ogs_yaml_iter_recurse(&root_iter, &mme_iter); + while (ogs_yaml_iter_next(&mme_iter)) { + const char *mme_key = ogs_yaml_iter_key(&mme_iter); + ogs_assert(mme_key); + if (!strcmp(mme_key, "s1ap")) { + ogs_yaml_iter_t s1ap_array, s1ap_iter; + ogs_yaml_iter_recurse(&mme_iter, &s1ap_array); + do { + int family = AF_UNSPEC; + int i, num = 0; + const char *hostname[OGS_MAX_NUM_OF_HOSTNAME]; + uint16_t port = self.s1ap_port; + const char *dev = NULL; + ogs_sockaddr_t *addr = NULL; + + if (ogs_yaml_iter_type(&s1ap_array) == + YAML_MAPPING_NODE) { + memcpy(&s1ap_iter, &s1ap_array, + sizeof(ogs_yaml_iter_t)); + } else if (ogs_yaml_iter_type(&s1ap_array) == + YAML_SEQUENCE_NODE) { + if (!ogs_yaml_iter_next(&s1ap_array)) + break; + ogs_yaml_iter_recurse(&s1ap_array, &s1ap_iter); + } else if (ogs_yaml_iter_type(&s1ap_array) == + YAML_SCALAR_NODE) { + break; + } else + ogs_assert_if_reached(); + + while (ogs_yaml_iter_next(&s1ap_iter)) { + const char *s1ap_key = + ogs_yaml_iter_key(&s1ap_iter); + ogs_assert(s1ap_key); + if (!strcmp(s1ap_key, "family")) { + const char *v = ogs_yaml_iter_value(&s1ap_iter); + if (v) family = atoi(v); + if (family != AF_UNSPEC && + family != AF_INET && family != AF_INET6) { + ogs_warn("Ignore family(%d) : " + "AF_UNSPEC(%d), " + "AF_INET(%d), AF_INET6(%d) ", + family, AF_UNSPEC, AF_INET, AF_INET6); + family = AF_UNSPEC; + } + } else if (!strcmp(s1ap_key, "addr") || + !strcmp(s1ap_key, "name")) { + ogs_yaml_iter_t hostname_iter; + ogs_yaml_iter_recurse( + &s1ap_iter, &hostname_iter); + ogs_assert(ogs_yaml_iter_type(&hostname_iter) != + YAML_MAPPING_NODE); + + do { + if (ogs_yaml_iter_type(&hostname_iter) == + YAML_SEQUENCE_NODE) { + if (!ogs_yaml_iter_next(&hostname_iter)) + break; + } + + ogs_assert(num <= OGS_MAX_NUM_OF_HOSTNAME); + hostname[num++] = + ogs_yaml_iter_value(&hostname_iter); + } while ( + ogs_yaml_iter_type(&hostname_iter) == + YAML_SEQUENCE_NODE); + } else if (!strcmp(s1ap_key, "port")) { + const char *v = ogs_yaml_iter_value(&s1ap_iter); + if (v) port = atoi(v); + } else if (!strcmp(s1ap_key, "dev")) { + dev = ogs_yaml_iter_value(&s1ap_iter); + } else + ogs_warn("unknown key `%s`", s1ap_key); + } + + addr = NULL; + for (i = 0; i < num; i++) { + rv = ogs_addaddrinfo(&addr, + family, hostname[i], port, 0); + ogs_assert(rv == OGS_OK); + } + + if (addr) { + if (ogs_config()->parameter.no_ipv4 == 0) + ogs_socknode_add( + &self.s1ap_list, AF_INET, addr); + if (ogs_config()->parameter.no_ipv6 == 0) + ogs_socknode_add( + &self.s1ap_list6, AF_INET6, addr); + ogs_freeaddrinfo(addr); + } + + if (dev) { + rv = ogs_socknode_probe( + ogs_config()->parameter.no_ipv4 ? + NULL : &self.s1ap_list, + ogs_config()->parameter.no_ipv6 ? + NULL : &self.s1ap_list6, + dev, port); + ogs_assert(rv == OGS_OK); + } + + } while (ogs_yaml_iter_type(&s1ap_array) == + YAML_SEQUENCE_NODE); + + if (ogs_list_first(&self.s1ap_list) == NULL && + ogs_list_first(&self.s1ap_list6) == NULL) { + rv = ogs_socknode_probe( + ogs_config()->parameter.no_ipv4 ? + NULL : &self.s1ap_list, + ogs_config()->parameter.no_ipv6 ? + NULL : &self.s1ap_list6, + NULL, self.s1ap_port); + ogs_assert(rv == OGS_OK); + } + } else if (!strcmp(mme_key, "tai")) { + int num_of_list0 = 0; + ogs_eps_tai0_list_t *list0 = NULL; + ogs_eps_tai2_list_t *list2 = NULL; + + ogs_assert(self.num_of_e_served_tai <= + OGS_MAX_NUM_OF_SERVED_TAI); + list0 = &self.e_served_tai[self.num_of_e_served_tai].list0; + ogs_assert(list0); + list2 = &self.e_served_tai[self.num_of_e_served_tai].list2; + ogs_assert(list2); + + ogs_yaml_iter_t tai_array, tai_iter; + ogs_yaml_iter_recurse(&mme_iter, &tai_array); + do { + const char *mcc = NULL, *mnc = NULL; + uint16_t tac[OGS_MAX_NUM_OF_TAI]; + int num_of_tac = 0; + + if (ogs_yaml_iter_type(&tai_array) == + YAML_MAPPING_NODE) { + memcpy(&tai_iter, &tai_array, + sizeof(ogs_yaml_iter_t)); + } else if (ogs_yaml_iter_type(&tai_array) == + YAML_SEQUENCE_NODE) { + if (!ogs_yaml_iter_next(&tai_array)) + break; + ogs_yaml_iter_recurse(&tai_array, + &tai_iter); + } else if (ogs_yaml_iter_type(&tai_array) == + YAML_SCALAR_NODE) { + break; + } else + ogs_assert_if_reached(); + + while (ogs_yaml_iter_next(&tai_iter)) { + const char *tai_key = ogs_yaml_iter_key(&tai_iter); + ogs_assert(tai_key); + if (!strcmp(tai_key, "plmn_id")) { + ogs_yaml_iter_t plmn_id_iter; + + ogs_yaml_iter_recurse(&tai_iter, &plmn_id_iter); + while (ogs_yaml_iter_next(&plmn_id_iter)) { + const char *plmn_id_key = + ogs_yaml_iter_key(&plmn_id_iter); + ogs_assert(plmn_id_key); + if (!strcmp(plmn_id_key, "mcc")) { + mcc = ogs_yaml_iter_value( + &plmn_id_iter); + } else if (!strcmp(plmn_id_key, "mnc")) { + mnc = ogs_yaml_iter_value( + &plmn_id_iter); + } + } + } else if (!strcmp(tai_key, "tac")) { + ogs_yaml_iter_t tac_iter; + ogs_yaml_iter_recurse(&tai_iter, &tac_iter); + ogs_assert(ogs_yaml_iter_type(&tac_iter) != + YAML_MAPPING_NODE); + + do { + const char *v = NULL; + + ogs_assert(num_of_tac <= + OGS_MAX_NUM_OF_TAI); + if (ogs_yaml_iter_type(&tac_iter) == + YAML_SEQUENCE_NODE) { + if (!ogs_yaml_iter_next(&tac_iter)) + break; + } + + v = ogs_yaml_iter_value(&tac_iter); + if (v) { + tac[num_of_tac] = atoi(v); + num_of_tac++; + } + } while ( + ogs_yaml_iter_type(&tac_iter) == + YAML_SEQUENCE_NODE); + } else + ogs_warn("unknown key `%s`", tai_key); + } + + if (mcc && mnc && num_of_tac) { + if (num_of_tac == 1) { + ogs_plmn_id_build( + &list2->tai[list2->num].plmn_id, + atoi(mcc), atoi(mnc), strlen(mnc)); + list2->tai[list2->num].tac = tac[0]; + + list2->num++; + if (list2->num > 1) + list2->type = OGS_TAI2_TYPE; + else + list2->type = OGS_TAI1_TYPE; + } else if (num_of_tac > 1) { + int i; + ogs_plmn_id_build( + &list0->tai[num_of_list0].plmn_id, + atoi(mcc), atoi(mnc), strlen(mnc)); + for (i = 0; i < num_of_tac; i++) { + list0->tai[num_of_list0].tac[i] = tac[i]; + } + + list0->tai[num_of_list0].num = num_of_tac; + list0->tai[num_of_list0].type = OGS_TAI0_TYPE; + + num_of_list0++; + } + } else { + ogs_warn("Ignore tai : mcc(%p), mnc(%p), " + "num_of_tac(%d)", mcc, mnc, num_of_tac); + } + } while (ogs_yaml_iter_type(&tai_array) == + YAML_SEQUENCE_NODE); + + if (list2->num || num_of_list0) { + self.num_of_e_served_tai++; + } + } + } } } @@ -467,23 +779,6 @@ int test_context_parse_config(void) return OGS_OK; } -void test_ue_set_mobile_identity(test_ue_t *test_ue, - ogs_nas_5gs_mobile_identity_t *mobile_identity) -{ - ogs_assert(test_ue); - ogs_assert(mobile_identity); - - if (test_ue->suci) - ogs_free(test_ue->suci); - test_ue->suci = ogs_nas_5gs_suci_from_mobile_identity(mobile_identity); - if (test_ue->supi) - ogs_free(test_ue->supi); - test_ue->supi = ogs_supi_from_suci(test_ue->suci); - if (test_ue->imsi) - ogs_free(test_ue->imsi); - test_ue->imsi = ogs_id_get_value(test_ue->supi); -} - void test_ue_set_mobile_identity_suci(test_ue_t *test_ue, ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci, uint16_t mobile_identity_suci_length) @@ -512,12 +807,346 @@ void test_ue_set_mobile_identity_suci(test_ue_t *test_ue, test_ue->imsi = ogs_id_get_value(test_ue->supi); } +static void test_ue_set_mobile_identity_imsi(test_ue_t *test_ue) +{ + ogs_assert(test_ue); + ogs_assert(test_ue->imsi); + + test_ue->mobile_identity_imsi.odd_even = OGS_NAS_MOBILE_IDENTITY_ODD; + test_ue->mobile_identity_imsi.type = OGS_NAS_MOBILE_IDENTITY_IMSI; + test_ue->mobile_identity_imsi.digit1 = test_ue->imsi[0] - '0'; + test_ue->mobile_identity_imsi.digit2 = test_ue->imsi[1] - '0'; + test_ue->mobile_identity_imsi.digit3 = test_ue->imsi[2] - '0'; + test_ue->mobile_identity_imsi.digit4 = test_ue->imsi[3] - '0'; + test_ue->mobile_identity_imsi.digit5 = test_ue->imsi[4] - '0'; + test_ue->mobile_identity_imsi.digit6 = test_ue->imsi[5] - '0'; + test_ue->mobile_identity_imsi.digit7 = test_ue->imsi[6] - '0'; + test_ue->mobile_identity_imsi.digit8 = test_ue->imsi[7] - '0'; + test_ue->mobile_identity_imsi.digit9 = test_ue->imsi[8] - '0'; + test_ue->mobile_identity_imsi.digit10 = test_ue->imsi[9] - '0'; + test_ue->mobile_identity_imsi.digit11 = test_ue->imsi[10] - '0'; + test_ue->mobile_identity_imsi.digit12 = test_ue->imsi[11] - '0'; + test_ue->mobile_identity_imsi.digit13 = test_ue->imsi[12] - '0'; + test_ue->mobile_identity_imsi.digit14 = test_ue->imsi[13] - '0'; + test_ue->mobile_identity_imsi.digit15 = test_ue->imsi[14] - '0'; +} + +static void test_ue_set_mobile_identity_imsisv(test_ue_t *test_ue) +{ + ogs_assert(test_ue); + + memset(&test_ue->mobile_identity_imeisv, 0, + sizeof(ogs_nas_mobile_identity_imeisv_t)); + test_ue->mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; + test_ue->mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; + test_ue->mobile_identity_imeisv.digit1 = 8; + test_ue->mobile_identity_imeisv.digit2 = 6; + test_ue->mobile_identity_imeisv.digit3 = 6; + test_ue->mobile_identity_imeisv.digit4 = 5; + test_ue->mobile_identity_imeisv.digit5 = 0; + test_ue->mobile_identity_imeisv.digit6 = 7; + test_ue->mobile_identity_imeisv.digit7 = 0; + test_ue->mobile_identity_imeisv.digit8 = 4; + test_ue->mobile_identity_imeisv.digit9 = 0; + test_ue->mobile_identity_imeisv.digit10 = 0; + test_ue->mobile_identity_imeisv.digit11 = 4; + test_ue->mobile_identity_imeisv.digit12 = 0; + test_ue->mobile_identity_imeisv.digit13 = 5; + test_ue->mobile_identity_imeisv.digit14 = 3; + test_ue->mobile_identity_imeisv.digit15 = 0; + test_ue->mobile_identity_imeisv.digit16 = 1; + test_ue->mobile_identity_imeisv.digit17 = 0xf; +} + +test_ue_t *test_ue_add_by_suci( + ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci, + uint16_t mobile_identity_suci_length) +{ + test_ue_t *test_ue = NULL; + + ogs_assert(mobile_identity_suci); + ogs_assert(mobile_identity_suci_length); + + ogs_pool_alloc(&test_ue_pool, &test_ue); + ogs_assert(test_ue); + memset(test_ue, 0, sizeof *test_ue); + + test_ue->nas.access_type = OGS_ACCESS_TYPE_3GPP; + test_ue->abba_len = 2; + + memcpy(&test_ue->e_tai, &test_self()->e_tai, sizeof(ogs_eps_tai_t)); + memcpy(&test_ue->e_cgi.plmn_id, &test_ue->e_tai.plmn_id, OGS_PLMN_ID_LEN); + + memcpy(&test_ue->nr_tai, &test_self()->nr_tai, sizeof(ogs_5gs_tai_t)); + memcpy(&test_ue->nr_cgi.plmn_id, &test_ue->nr_tai.plmn_id, OGS_PLMN_ID_LEN); + + if (test_self()->nr_tai.tac.v) + ogs_nas_from_plmn_id( + &mobile_identity_suci->nas_plmn_id, &test_ue->nr_tai.plmn_id); + else + ogs_nas_from_plmn_id( + &mobile_identity_suci->nas_plmn_id, &test_ue->e_tai.plmn_id); + + test_ue_set_mobile_identity_suci( + test_ue, mobile_identity_suci, mobile_identity_suci_length); + + test_ue_set_mobile_identity_imsi(test_ue); + test_ue_set_mobile_identity_imsisv(test_ue); + + ogs_list_add(&self.test_ue_list, test_ue); + + return test_ue; +} + void test_ue_remove(test_ue_t *test_ue) { + ogs_assert(test_ue); + + ogs_list_remove(&self.test_ue_list, test_ue); + if (test_ue->suci) ogs_free(test_ue->suci); if (test_ue->supi) ogs_free(test_ue->supi); if (test_ue->imsi) ogs_free(test_ue->imsi); + + test_sess_remove_all(test_ue); + + ogs_pool_free(&test_ue_pool, test_ue); +} + +void test_ue_remove_all(void) +{ + test_ue_t *test_ue = NULL, *next = NULL;; + + ogs_list_for_each_safe(&self.test_ue_list, next, test_ue) + test_ue_remove(test_ue); +} + +test_sess_t *test_sess_add_by_apn(test_ue_t *test_ue, char *apn) +{ + test_sess_t *sess = NULL; + + ogs_assert(test_ue); + ogs_assert(apn); + + ogs_pool_alloc(&test_sess_pool, &sess); + ogs_assert(sess); + memset(sess, 0, sizeof *sess); + + sess->apn = ogs_strdup(apn); + ogs_assert(sess->apn); + sess->pti = 1; /* Default PTI : 1 */ + + sess->test_ue = test_ue; + + ogs_list_add(&test_ue->sess_list, sess); + + return sess; +} + +test_sess_t *test_sess_add_by_dnn_and_psi( + test_ue_t *test_ue, char *dnn, uint8_t psi) +{ + test_sess_t *sess = NULL; + + ogs_assert(test_ue); + ogs_assert(dnn); + + ogs_pool_alloc(&test_sess_pool, &sess); + ogs_assert(sess); + memset(sess, 0, sizeof *sess); + + sess->index = ogs_pool_index(&test_sess_pool, sess); + + sess->dnn = ogs_strdup(dnn); + ogs_assert(sess->dnn); + sess->psi = psi; + sess->pti = 1; /* Default PTI : 1 */ + + sess->gnb_n3_addr = test_self()->gnb1_addr; + sess->gnb_n3_addr6 = test_self()->gnb1_addr6; + sess->gnb_n3_teid = sess->index; + + sess->pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; + + sess->test_ue = test_ue; + + ogs_list_add(&test_ue->sess_list, sess); + + return sess; +} + +void test_sess_remove(test_sess_t *sess) +{ + test_ue_t *test_ue = NULL; + + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + ogs_list_remove(&test_ue->sess_list, sess); + + if (sess->dnn) + ogs_free(sess->dnn); + + test_bearer_remove_all(sess); + + ogs_pool_free(&test_sess_pool, sess); +} + +void test_sess_remove_all(test_ue_t *test_ue) +{ + test_sess_t *sess = NULL, *next = NULL;; + + ogs_assert(test_ue); + + ogs_list_for_each_safe(&test_ue->sess_list, next, sess) + test_sess_remove(sess); +} + +test_sess_t *test_sess_find_by_apn(test_ue_t *test_ue, char *apn) +{ + test_sess_t *sess = NULL; + + ogs_assert(test_ue); + ogs_assert(apn); + + ogs_list_for_each(&test_ue->sess_list, sess) + if (strcmp(sess->apn, apn) == 0) return sess; + + return NULL; +} + +test_sess_t *test_sess_find_by_psi(test_ue_t *test_ue, uint8_t psi) +{ + test_sess_t *sess = NULL; + + ogs_assert(test_ue); + + ogs_list_for_each(&test_ue->sess_list, sess) + if (sess->psi == psi) return sess; + + return NULL; +} + +test_bearer_t *test_bearer_add(test_sess_t *sess, uint8_t ebi) +{ + test_bearer_t *bearer = NULL; + + ogs_assert(sess); + ogs_assert(ebi); + + ogs_pool_alloc(&test_bearer_pool, &bearer); + ogs_assert(bearer); + memset(bearer, 0, sizeof *bearer); + + bearer->index = ogs_pool_index(&test_bearer_pool, bearer); + + bearer->ebi = ebi; + + bearer->enb_s1u_addr = test_self()->gnb1_addr; + bearer->enb_s1u_addr6 = test_self()->gnb1_addr6; + bearer->enb_s1u_teid = bearer->index; + + bearer->sess = sess; + + ogs_list_add(&sess->bearer_list, bearer); + + return bearer; +} + +test_bearer_t *test_qos_flow_add(test_sess_t *sess) +{ + test_bearer_t *qos_flow = NULL; + + ogs_assert(sess); + + ogs_pool_alloc(&test_bearer_pool, &qos_flow); + ogs_assert(qos_flow); + memset(qos_flow, 0, sizeof *qos_flow); + + qos_flow->index = ogs_pool_index(&test_bearer_pool, qos_flow); + + qos_flow->sess = sess; + + ogs_list_add(&sess->bearer_list, qos_flow); + + return qos_flow; +} + +void test_bearer_remove(test_bearer_t *bearer) +{ + ogs_assert(bearer); + ogs_assert(bearer->sess); + + ogs_list_remove(&bearer->sess->bearer_list, bearer); + + ogs_pool_free(&test_bearer_pool, bearer); +} + +void test_bearer_remove_all(test_sess_t *sess) +{ + test_bearer_t *bearer = NULL, *next_bearer = NULL; + + ogs_assert(sess); + ogs_list_for_each_safe(&sess->bearer_list, next_bearer, bearer) + test_bearer_remove(bearer); +} + +test_bearer_t *test_bearer_find_by_sess_ebi(test_sess_t *sess, uint8_t ebi) +{ + test_bearer_t *bearer = NULL; + + ogs_assert(sess); + + ogs_list_for_each(&sess->bearer_list, bearer) + if (ebi == bearer->ebi) return bearer; + + return NULL; +} + +test_bearer_t *test_bearer_find_by_ue_ebi(test_ue_t *test_ue, uint8_t ebi) +{ + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + ogs_assert(test_ue); + + ogs_list_for_each(&test_ue->sess_list, sess) { + bearer = test_bearer_find_by_sess_ebi(sess, ebi); + if (bearer) return bearer; + + } + + return NULL; +} + +test_bearer_t *test_qos_flow_find_by_sess_qfi(test_sess_t *sess, uint8_t qfi) +{ + test_bearer_t *qos_flow = NULL; + + ogs_assert(sess); + + ogs_list_for_each(&sess->bearer_list, qos_flow) + if (qfi == qos_flow->qfi) return qos_flow; + + return NULL; +} + +test_bearer_t *test_qos_flow_find_by_ue_qfi(test_ue_t *test_ue, uint8_t qfi) +{ + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; + + ogs_assert(test_ue); + + ogs_list_for_each(&test_ue->sess_list, sess) { + qos_flow = test_qos_flow_find_by_sess_qfi(sess, qfi); + if (qos_flow) return qos_flow; + + } + + return NULL; } diff --git a/tests/common/context.h b/tests/common/context.h index c5c1af99e..ab5620b79 100644 --- a/tests/common/context.h +++ b/tests/common/context.h @@ -36,25 +36,29 @@ extern "C" { #define TEST_SGWU_IPV4 "127.0.0.7" #define TEST_PING_IPV4 "10.45.0.1" +#define TEST_PING_IPV6 "cafe::1" #define MAX_NUM_OF_SERVED_GUAMI 8 typedef struct test_context_s { - /* Served GUMME */ - uint8_t num_of_served_guami; - struct { - ogs_plmn_id_t plmn_id; - ogs_amf_id_t amf_id; - } served_guami[MAX_NUM_OF_SERVED_GUAMI]; + uint16_t ngap_port; /* Default NGAP Port */ + ogs_list_t ngap_list; /* AMF NGAP IPv4 Server List */ + ogs_list_t ngap_list6; /* AMF NGAP IPv6 Server List */ + ogs_sockaddr_t *ngap_addr; /* AMF NGAP IPv4 Address */ + ogs_sockaddr_t *ngap_addr6; /* AMF NGAP IPv6 Address */ - /* Served TAI */ - uint8_t num_of_served_tai; - struct { - ogs_5gs_tai0_list_t list0; - ogs_5gs_tai2_list_t list2; - } served_tai[OGS_MAX_NUM_OF_SERVED_TAI]; + uint16_t s1ap_port; /* Default S1AP Port */ + ogs_list_t s1ap_list; /* MME S1AP IPv4 Server List */ + ogs_list_t s1ap_list6; /* MME S1AP IPv6 Server List */ + ogs_sockaddr_t *s1ap_addr; /* MME GTPC IPv4 Address */ + ogs_sockaddr_t *s1ap_addr6; /* MME GTPC IPv6 Address */ - /* PLMN Support */ + ogs_sockaddr_t *gnb1_addr; + ogs_sockaddr_t *gnb1_addr6; + ogs_sockaddr_t *gnb2_addr; + ogs_sockaddr_t *gnb2_addr6; + + /* 5G PLMN Support */ uint8_t num_of_plmn_support; struct { ogs_plmn_id_t plmn_id; @@ -62,12 +66,48 @@ typedef struct test_context_s { ogs_s_nssai_t s_nssai[OGS_MAX_NUM_OF_S_NSSAI]; } plmn_support[OGS_MAX_NUM_OF_PLMN]; - ogs_5gs_tai_t tai; + /* Served EPC TAI */ + uint8_t num_of_e_served_tai; + struct { + ogs_eps_tai0_list_t list0; + ogs_eps_tai2_list_t list2; + } e_served_tai[OGS_MAX_NUM_OF_SERVED_TAI]; + + ogs_eps_tai_t e_tai; + + /* Served 5GC TAI */ + uint8_t num_of_nr_served_tai; + struct { + ogs_5gs_tai0_list_t list0; + ogs_5gs_tai2_list_t list2; + } nr_served_tai[OGS_MAX_NUM_OF_SERVED_TAI]; + + ogs_5gs_tai_t nr_tai; ogs_nr_cgi_t nr_cgi; + + ogs_list_t test_ue_list; } test_context_t; typedef struct test_sess_s test_sess_t; +typedef struct test_initial_ue_param_s { + struct { + ED8(uint8_t gummei_id:1;, + uint8_t gummei_type:1;, + uint8_t spare1:1;, + uint8_t spare2:1;, + uint8_t spare3:1;, + uint8_t spare4:1;, + uint8_t spare5:1;, + uint8_t spare6:1;) + }; + struct { + uint16_t mme_gid; + uint8_t mme_code; + uint8_t type; + } gummei; +} __attribute__ ((packed)) test_initial_ue_param_t; + typedef struct test_registration_request_param_s { struct { ED8(uint8_t integrity_protected:1;, @@ -92,6 +132,72 @@ typedef struct test_registration_request_param_s { } psimask; } __attribute__ ((packed)) test_registration_request_param_t; +typedef struct test_attach_request_param_s { + struct { + ED8(uint8_t integrity_protected:1;, + uint8_t ciphered:1;, + uint8_t guti:1;, + uint8_t last_visited_registered_tai:1;, + uint8_t drx_parameter:1;, + uint8_t location_area_identication:1;, + uint8_t mobile_station_classmark_2:1;, + uint8_t ue_usage_setting:1;) + }; + struct { + ED8(uint8_t old_guti_type:1;, + uint8_t nri_container:1;, + uint8_t ue_additional_security_capability:1;, + uint8_t tmsi_status:1;, + uint8_t ms_network_feature_support:1;, + uint8_t ms_network_capability:1;, + uint8_t mobile_station_classmark_3:1;, + uint8_t supported_codecs:1;) + }; + struct { + ED8(uint8_t additional_update_type:1;, + uint8_t spare2:1;, + uint8_t spare3:1;, + uint8_t spare4:1;, + uint8_t spare5:1;, + uint8_t spare6:1;, + uint8_t spare7:1;, + uint8_t spare8:1;) + }; +} __attribute__ ((packed)) test_attach_request_param_t; + +typedef struct test_tau_request_param_s { + struct { + ED8(uint8_t ue_network_capability:1;, + uint8_t eps_bearer_context_status:1;, + uint8_t guti:1;, + uint8_t last_visited_registered_tai:1;, + uint8_t drx_parameter:1;, + uint8_t location_area_identication:1;, + uint8_t mobile_station_classmark_2:1;, + uint8_t ue_usage_setting:1;) + }; + struct { + ED8(uint8_t old_guti_type:1;, + uint8_t nri_container:1;, + uint8_t ue_additional_security_capability:1;, + uint8_t tmsi_status:1;, + uint8_t ms_network_feature_support:1;, + uint8_t ms_network_capability:1;, + uint8_t mobile_station_classmark_3:1;, + uint8_t supported_codecs:1;) + }; + struct { + ED8(uint8_t additional_update_type:1;, + uint8_t device_properties:1;, + uint8_t ciphered:1;, + uint8_t spare4:1;, + uint8_t spare5:1;, + uint8_t spare6:1;, + uint8_t spare7:1;, + uint8_t spare8:1;) + }; +} __attribute__ ((packed)) test_tau_request_param_t; + typedef struct test_service_request_param_s { union { struct { @@ -112,6 +218,23 @@ typedef struct test_service_request_param_s { } psimask; } __attribute__ ((packed)) test_service_request_param_t; +typedef struct test_extended_service_request_param_s { + union { + struct { + ED6(uint8_t ciphered:1;, + uint8_t csfb_response:1;, + uint8_t eps_bearer_context_status:1;, + uint8_t spare1:1;, + uint8_t spare2:1;, + uint8_t spare3:3;) + }; + uint8_t value; + }; + struct { + uint8_t response; + } csfb; +} __attribute__ ((packed)) test_extended_service_request_param_t; + typedef struct test_ul_nas_transport_param_s { union { struct { @@ -124,9 +247,45 @@ typedef struct test_ul_nas_transport_param_s { }; } __attribute__ ((packed)) test_ul_nas_transport_param_t; +typedef struct test_pdn_connectivity_param_s { + union { + struct { + ED8(uint8_t eit:1;, + uint8_t eit_no_required:1;, + uint8_t apn:1;, + uint8_t pco:1;, + uint8_t integrity_protected:1;, + uint8_t ciphered:1;, + uint8_t spare6:1;, + uint8_t spare7:1;) + }; + uint8_t value; + }; +} __attribute__ ((packed)) test_pdn_connectivity_param_t; + +typedef struct test_esm_information_param_s { + union { + struct { + ED8(uint8_t pco:1;, + uint8_t spare1:1;, + uint8_t spare2:1;, + uint8_t spare3:1;, + uint8_t spare4:1;, + uint8_t spare5:1;, + uint8_t spare6:1;, + uint8_t spare7:1;) + }; + uint8_t value; + }; +} __attribute__ ((packed)) test_esm_information_param_t; + typedef struct test_ue_s { - uint32_t ran_ue_ngap_id; /* eNB-UE-NGAP-ID received from eNB */ + ogs_lnode_t lnode; /**< A node of list_t */ + + uint32_t ran_ue_ngap_id; /* gNB-UE-NGAP-ID received from gNB */ uint64_t amf_ue_ngap_id; /* AMF-UE-NGAP-ID received from AMF */ + uint32_t enb_ue_s1ap_id; /* eNB-UE-S1AP-ID received from eNB */ + uint32_t mme_ue_s1ap_id; /* MME-UE-S1AP-ID received from MME */ char *imsi; char *suci; /* TS33.501 : SUCI */ @@ -134,8 +293,16 @@ typedef struct test_ue_s { ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; ogs_nas_mobile_identity_imeisv_t mobile_identity_imeisv; + bool mobile_identity_imeisv_presence; uint16_t mobile_identity_suci_length; - ogs_nas_5gs_guti_t nas_guti; + ogs_nas_5gs_guti_t nas_5gs_guti; + ogs_nas_eps_guti_t nas_eps_guti; + ogs_nas_mobile_identity_imsi_t mobile_identity_imsi; + + ogs_eps_tai_t e_tai; + ogs_e_cgi_t e_cgi; + ogs_5gs_tai_t nr_tai; + ogs_nr_cgi_t nr_cgi; uint8_t k[OGS_KEY_LEN]; uint8_t opc[OGS_KEY_LEN]; @@ -145,6 +312,7 @@ typedef struct test_ue_s { uint8_t abba[OGS_NAS_MAX_ABBA_LEN]; uint8_t abba_len; uint8_t kamf[OGS_SHA256_DIGEST_SIZE]; + uint8_t kasme[OGS_SHA256_DIGEST_SIZE]; struct { int access_type; /* 3GPP or Non-3GPP */ @@ -157,6 +325,7 @@ typedef struct test_ue_s { }; ogs_nas_5gs_registration_type_t registration; ogs_nas_de_registration_type_t de_registration; + ogs_nas_eps_attach_type_t attach; uint8_t data; }; @@ -194,48 +363,108 @@ typedef struct test_ue_s { int security_context_available; int mac_failed; + test_initial_ue_param_t initial_ue_param; + test_registration_request_param_t registration_request_param; test_service_request_param_t service_request_param; + test_extended_service_request_param_t extended_service_request_param; uint8_t gmm_message_type; /* Last received 5GMM message type */ uint16_t pdu_session_status; uint16_t pdu_session_reactivation_result; + test_attach_request_param_t attach_request_param; + test_tau_request_param_t tau_request_param; + uint8_t emm_message_type; /* Last received EMM message type */ + test_sess_t *sess; + + ogs_list_t sess_list; } test_ue_t; typedef struct test_sess_s { + ogs_lnode_t lnode; /**< A node of list_t */ + uint32_t index; + uint8_t psi; uint8_t pti; uint8_t pdu_session_type; - char *dnn; + union { + char *dnn; + char *apn; + }; ogs_ip_t ue_ip; - ogs_ip_t upf_n3_ip; - uint32_t upf_n3_teid; - ogs_ip_t gnb_n3_ip; - uint32_t gnb_n3_teid; - uint8_t qfi; + ogs_ip_t upf_n3_ip; /* UPF-N3 IPv4/IPv6 */ + uint32_t upf_n3_teid; /* UPF-N3 TEID */ + + uint32_t gnb_n3_teid; /* gNB-N3 TEID */ + ogs_sockaddr_t *gnb_n3_addr; /* gNB-N3 IPv4 */ + ogs_sockaddr_t *gnb_n3_addr6; /* gNB-N3 IPv6 */ test_ul_nas_transport_param_t ul_nas_transport_param; + test_pdn_connectivity_param_t pdn_connectivity_param; + test_esm_information_param_t esm_information_param; + + ogs_list_t bearer_list; test_ue_t *test_ue; } test_sess_t; +typedef struct test_bearer_s { + ogs_lnode_t lnode; /**< A node of list_t */ + uint32_t index; + + uint8_t qfi; /* 5GC */ + uint8_t ebi; /* EPC */ + + uint32_t sgw_s1u_teid; /* SGW-S1U TEID */ + ogs_ip_t sgw_s1u_ip; /* SGW-S1U IPv4/IPv6 */ + + uint32_t enb_s1u_teid; /* eNB-S1U TEID */ + ogs_sockaddr_t *enb_s1u_addr; /* eNB-S1U IPv4 */ + ogs_sockaddr_t *enb_s1u_addr6; /* eNB-S1U IPv6 */ + + test_sess_t *sess; +} test_bearer_t; + void test_context_init(void); void test_context_final(void); test_context_t *test_self(void); int test_context_parse_config(void); -void test_ue_set_mobile_identity(test_ue_t *test_ue, - ogs_nas_5gs_mobile_identity_t *mobile_identity); void test_ue_set_mobile_identity_suci(test_ue_t *test_ue, ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci, uint16_t mobile_identity_suci_length); + +test_ue_t *test_ue_add_by_suci( + ogs_nas_5gs_mobile_identity_suci_t *mobile_identity_suci, + uint16_t mobile_identity_suci_length); void test_ue_remove(test_ue_t *test_ue); +void test_ue_remove_all(void); + +test_sess_t *test_sess_add_by_dnn_and_psi( + test_ue_t *test_ue, char *dnn, uint8_t psi); +test_sess_t *test_sess_add_by_apn(test_ue_t *test_ue, char *apn); +void test_sess_remove(test_sess_t *sess); +void test_sess_remove_all(test_ue_t *test_ue); + +test_sess_t *test_sess_find_by_apn(test_ue_t *test_ue, char *apn); +test_sess_t *test_sess_find_by_psi(test_ue_t *test_ue, uint8_t psi); + +test_bearer_t *test_bearer_add(test_sess_t *sess, uint8_t ebi); +test_bearer_t *test_qos_flow_add(test_sess_t *sess); +void test_bearer_remove(test_bearer_t *bearer); +void test_bearer_remove_all(test_sess_t *sess); + +test_bearer_t *test_bearer_find_by_sess_ebi(test_sess_t *sess, uint8_t ebi); +test_bearer_t *test_bearer_find_by_ue_ebi(test_ue_t *test_ue, uint8_t ebi); + +test_bearer_t *test_qos_flow_find_by_sess_qfi(test_sess_t *sess, uint8_t qfi); +test_bearer_t *test_qos_flow_find_by_ue_qfi(test_ue_t *test_ue, uint8_t qfi); #ifdef __cplusplus } diff --git a/tests/common/emm-build.c b/tests/common/emm-build.c new file mode 100644 index 000000000..71bea99dc --- /dev/null +++ b/tests/common/emm-build.c @@ -0,0 +1,852 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of OpenEPS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +ogs_pkbuf_t *testemm_build_attach_request( + test_ue_t *test_ue, ogs_pkbuf_t *esmbuf) +{ + int i; + uint16_t psimask = 0; + + ogs_nas_eps_message_t message; + ogs_nas_eps_attach_request_t *attach_request = &message.emm.attach_request; + + ogs_nas_eps_attach_type_t *eps_attach_type = + &attach_request->eps_attach_type; + ogs_nas_eps_mobile_identity_t *eps_mobile_identity = + &attach_request->eps_mobile_identity; + ogs_nas_ue_network_capability_t *ue_network_capability = + &attach_request->ue_network_capability; + ogs_nas_esm_message_container_t *esm_message_container = + &attach_request->esm_message_container; + + ogs_nas_tracking_area_identity_t *last_visited_registered_tai = + &attach_request->last_visited_registered_tai; + ogs_nas_drx_parameter_t *drx_parameter = &attach_request->drx_parameter; + ogs_nas_ms_network_capability_t *ms_network_capability = + &attach_request->ms_network_capability; + ogs_nas_location_area_identification_t *old_location_area_identification = + &attach_request->old_location_area_identification; + ogs_nas_tmsi_status_t *tmsi_status = &attach_request->tmsi_status; + ogs_nas_mobile_station_classmark_2_t *mobile_station_classmark_2 = + &attach_request->mobile_station_classmark_2; + ogs_nas_mobile_station_classmark_3_t *mobile_station_classmark_3 = + &attach_request->mobile_station_classmark_3; + ogs_nas_supported_codec_list_t *supported_codecs = + &attach_request->supported_codecs; + ogs_nas_additional_update_type_t *additional_update_type = + &attach_request->additional_update_type; + ogs_nas_voice_domain_preference_and_ue_usage_setting_t + *voice_domain_preference_and_ue_usage_setting = + &attach_request->voice_domain_preference_and_ue_usage_setting; + ogs_nas_guti_type_t *old_guti_type = &attach_request->old_guti_type; + ogs_nas_ms_network_feature_support_t *ms_network_feature_support = + &attach_request->ms_network_feature_support; + ogs_nas_network_resource_identifier_container_t *tmsi_based_nri_container = + &attach_request->tmsi_based_nri_container; + ogs_nas_ue_additional_security_capability_t + *ue_additional_security_capability = + &attach_request->ue_additional_security_capability; + + uint8_t classmark_3[11] = "\x60\x14\x04\xef\x65\x23\x3b\x88\x78\xd2\x90"; + + ogs_assert(test_ue); + ogs_assert(esmbuf); + + memset(&message, 0, sizeof(message)); + if (test_ue->attach_request_param.integrity_protected) { + if (test_ue->attach_request_param.ciphered) + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + else + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + } + message.emm.h.protocol_discriminator = + OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + message.emm.h.message_type = OGS_NAS_EPS_ATTACH_REQUEST; + + esm_message_container->length = esmbuf->len; + esm_message_container->buffer = esmbuf->data; + ogs_pkbuf_free(esmbuf); + + memcpy(eps_attach_type, &test_ue->nas.data, sizeof(*eps_attach_type)); + + if (test_ue->attach_request_param.guti) { + eps_mobile_identity->length = + sizeof(ogs_nas_eps_mobile_identity_guti_t); + eps_mobile_identity->guti.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; + eps_mobile_identity->guti.type = OGS_NAS_EPS_MOBILE_IDENTITY_GUTI; + eps_mobile_identity->guti.nas_plmn_id = + test_ue->nas_eps_guti.nas_plmn_id; + eps_mobile_identity->guti.mme_gid = test_ue->nas_eps_guti.mme_gid; + eps_mobile_identity->guti.mme_code = test_ue->nas_eps_guti.mme_code; + eps_mobile_identity->guti.m_tmsi = test_ue->nas_eps_guti.m_tmsi; + } else { + eps_mobile_identity->length = + sizeof(ogs_nas_mobile_identity_imsi_t); + memcpy(&eps_mobile_identity->imsi, + &test_ue->mobile_identity_imsi, eps_mobile_identity->length); + } + + ue_network_capability->length = 7; + ue_network_capability->eea = 0xf0; + ue_network_capability->eia = 0xf0; + ue_network_capability->uea = 0xc0; + ue_network_capability->uia = 0x40; + ue_network_capability->notification_procedure = 1; + ue_network_capability->dual_connectivity_with_nr = 1; + + if (test_ue->attach_request_param.last_visited_registered_tai) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_LAST_VISITED_REGISTERED_TAI_PRESENT; + ogs_nas_from_plmn_id(&last_visited_registered_tai->nas_plmn_id, + &test_ue->e_tai.plmn_id); + last_visited_registered_tai->tac = test_ue->e_tai.tac; + } + + if (test_ue->attach_request_param.drx_parameter) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_DRX_PARAMETER_PRESENT; + drx_parameter->split_pg_cycle_code = 32; + } + + if (test_ue->attach_request_param.ms_network_capability) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_MS_NETWORK_CAPABILITY_PRESENT; + ms_network_capability->length = 3; + ms_network_capability->gea1 = 1; + ms_network_capability->sm_capabilities_via_dedicated_channels = 1; + ms_network_capability->sm_capabilities_via_gprs_channels = 1; + ms_network_capability->ss_screening_indicator = 1; + ms_network_capability->revision_level_indicator = 1; + ms_network_capability->pfc_feature_mode = 1; + ms_network_capability->extended_gea = 0x30; + ms_network_capability->emm_combined_procedures_capability = 1; + ms_network_capability->isr_support = 1; + ms_network_capability->epc_capability = 1; + } + + if (test_ue->attach_request_param.location_area_identication) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_OLD_LOCATION_AREA_IDENTIFICATION_PRESENT; + ogs_nas_from_plmn_id(&old_location_area_identification->nas_plmn_id, + &test_ue->e_tai.plmn_id); + old_location_area_identification->lac = 1; + } + + if (test_ue->attach_request_param.tmsi_status) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_TMSI_STATUS_PRESENT; + } + + if (test_ue->attach_request_param.mobile_station_classmark_2) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_2_PRESENT; + mobile_station_classmark_2->length = 3; + mobile_station_classmark_2->revision_level = 2; + mobile_station_classmark_2->es_ind = 1; + mobile_station_classmark_2->a5_1 = 1; + mobile_station_classmark_2->rf_power_capability = 7; + mobile_station_classmark_2->ps_capa = 1; + mobile_station_classmark_2->ss_screen_indicator = 1; + mobile_station_classmark_2->sm_capabi = 1; + mobile_station_classmark_2->cm3 = 1; + mobile_station_classmark_2->lcsva_cap = 1; + mobile_station_classmark_2->cmsp = 1; + mobile_station_classmark_2->a5_3 = 1; + } + + if (test_ue->attach_request_param.mobile_station_classmark_3) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_MOBILE_STATION_CLASSMARK_3_PRESENT; + mobile_station_classmark_3->length = 11; + memcpy(mobile_station_classmark_3->buffer, + classmark_3, mobile_station_classmark_3->length); + } + + if (test_ue->attach_request_param.supported_codecs) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_SUPPORTED_CODECS_PRESENT; + supported_codecs->length = 8; + supported_codecs->item[0].system_identification = 0x04; + supported_codecs->item[0].length_of_bitmap = 2; + supported_codecs->item[0].codec_bitmap = htobe16(0x6004); + supported_codecs->item[1].system_identification = 0; + supported_codecs->item[1].length_of_bitmap = 2; + supported_codecs->item[1].codec_bitmap = htobe16(0x1f02); + } + + if (test_ue->attach_request_param.additional_update_type) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_ADDITIONAL_UPDATE_TYPE_PRESENT; + additional_update_type->autv = 1; + } + + if (test_ue->attach_request_param.ue_usage_setting) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING_PRESENT; + voice_domain_preference_and_ue_usage_setting->length = 1; + voice_domain_preference_and_ue_usage_setting->ue_usage_setting = 1; + voice_domain_preference_and_ue_usage_setting-> + voice_domain_preference_for_e_utran = 1; + } + + if (test_ue->attach_request_param.old_guti_type) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_OLD_GUTI_TYPE_PRESENT; + } + + if (test_ue->attach_request_param.ms_network_feature_support) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_MS_NETWORK_FEATURE_SUPPORT_PRESENT; + ms_network_feature_support->extended_periodic_timers = 1; + } + + if (test_ue->attach_request_param.nri_container) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_TMSI_BASED_NRI_CONTAINER_PRESENT; + tmsi_based_nri_container->length = 2; + tmsi_based_nri_container->nri_container_value1 = 0x8d; + tmsi_based_nri_container->nri_container_value2 = 0x3; + } + + if (test_ue->attach_request_param.ue_additional_security_capability) { + attach_request->presencemask |= + OGS_NAS_EPS_ATTACH_REQUEST_UE_ADDITIONAL_SECURITY_CAPABILITY_PRESENT; + ue_additional_security_capability->length = 4; + ue_additional_security_capability->nea = 0xf0; + ue_additional_security_capability->nia = 0xf0; + } + + if (test_ue->attach_request_param.integrity_protected) + return test_nas_eps_security_encode(test_ue, &message); + else + return ogs_nas_eps_plain_encode(&message); +} + +ogs_pkbuf_t *testemm_build_identity_response(test_ue_t *test_ue) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_identity_response_t *identity_response = + &message.emm.identity_response; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + message.emm.h.protocol_discriminator = + OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + message.emm.h.message_type = OGS_NAS_EPS_IDENTITY_RESPONSE; + + identity_response->mobile_identity.length = + sizeof(ogs_nas_mobile_identity_imsi_t); + memcpy(&identity_response->mobile_identity.imsi, + &test_ue->mobile_identity_imsi, + identity_response->mobile_identity.length); + + return ogs_nas_eps_plain_encode(&message); +} + +ogs_pkbuf_t *testemm_build_authentication_response(test_ue_t *test_ue) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_authentication_response_t *authentication_response = + &message.emm.authentication_response; + ogs_nas_authentication_response_parameter_t + *authentication_response_parameter = + &authentication_response->authentication_response_parameter; + + uint8_t ik[OGS_KEY_LEN]; + uint8_t ck[OGS_KEY_LEN]; + uint8_t ak[OGS_AK_LEN]; + uint8_t sqn[OGS_SQN_LEN]; + uint8_t res[OGS_MAX_RES_LEN]; + + ogs_nas_plmn_id_t nas_plmn_id; + uint8_t kasme[32]; + + int i; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + message.emm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + message.emm.h.message_type = OGS_NAS_EPS_AUTHENTICATION_RESPONSE; + + milenage_f2345(test_ue->opc, test_ue->k, test_ue->rand, + res, ck, ik, ak, NULL); + + for (i = 0; i < 6; i++) + sqn[i] = test_ue->autn[i] ^ ak[i]; + + ogs_nas_from_plmn_id(&nas_plmn_id, &test_ue->e_tai.plmn_id); + ogs_auc_kasme(ck, ik, &nas_plmn_id, sqn, ak, test_ue->kasme); + + authentication_response_parameter->length = 8; + memcpy(authentication_response_parameter->res, res, 8); + + return ogs_nas_eps_plain_encode(&message); +} + +ogs_pkbuf_t *testemm_build_authentication_failure( + test_ue_t *test_ue, ogs_nas_emm_cause_t emm_cause, uint64_t sqn_ms) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_authentication_failure_t *authentication_failure = + &message.emm.authentication_failure; + ogs_nas_authentication_failure_parameter_t + *authentication_failure_parameter = + &authentication_failure->authentication_failure_parameter; + + uint8_t ak[OGS_AK_LEN]; +#if 0 + uint8_t sqn_ms[OGS_SQN_LEN] = "\x00\x00\x11\x22\x33\x44"; + uint8_t sqn_ms[OGS_SQN_LEN] = "\x00\x00\x00\x00\x1f\x60"; /* Issues 482 */ +#endif + uint8_t sqn[OGS_SQN_LEN]; + uint8_t mac_s[OGS_MAC_S_LEN]; + uint8_t amf[2] = { 0, 0 }; + uint8_t auts[OGS_AUTS_LEN]; + int i = 0; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + message.emm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + message.emm.h.message_type = OGS_NAS_EPS_AUTHENTICATION_FAILURE; + + authentication_failure->emm_cause = emm_cause; + + if (emm_cause == EMM_CAUSE_SYNCH_FAILURE) { + authentication_failure->presencemask |= + OGS_NAS_EPS_AUTHENTICATION_FAILURE_AUTHENTICATION_FAILURE_PARAMETER_PRESENT; + + milenage_f2345(test_ue->opc, test_ue->k, test_ue->rand, + NULL, NULL, NULL, NULL, ak); + + ogs_uint64_to_buffer(sqn_ms, 6, sqn); + milenage_f1(test_ue->opc, test_ue->k, test_ue->rand, + sqn, amf, NULL, auts + OGS_SQN_LEN); + for (i = 0; i < OGS_SQN_LEN; i++) + auts[i] = sqn[i] ^ ak[i]; + + authentication_failure_parameter->length = OGS_AUTS_LEN; + memcpy(authentication_failure_parameter->auts, auts, + authentication_failure_parameter->length); + } + + return ogs_nas_eps_plain_encode(&message); +} + +ogs_pkbuf_t *testemm_build_security_mode_complete(test_ue_t *test_ue) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_security_mode_complete_t *security_mode_complete = + &message.emm.security_mode_complete; + ogs_nas_mobile_identity_t *imeisv = &security_mode_complete->imeisv; + + ogs_nas_mobile_identity_imeisv_t mobile_identity_imeisv; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.emm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + message.emm.h.message_type = OGS_NAS_EPS_SECURITY_MODE_COMPLETE; + + if (test_ue->mobile_identity_imeisv_presence) { + security_mode_complete->presencemask |= + OGS_NAS_EPS_SECURITY_MODE_COMPLETE_IMEISV_PRESENT; + memset(&mobile_identity_imeisv, 0, sizeof(mobile_identity_imeisv)); + imeisv->length = sizeof(test_ue->mobile_identity_imeisv); + memcpy(&imeisv->imeisv, + &test_ue->mobile_identity_imeisv, imeisv->length); + imeisv->imeisv.type = OGS_NAS_MOBILE_IDENTITY_IMEISV; + } + + return test_nas_eps_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testemm_build_attach_complete( + test_ue_t *test_ue, ogs_pkbuf_t *esmbuf) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_attach_complete_t *attach_complete = + &message.emm.attach_complete; + + ogs_nas_esm_message_container_t *esm_message_container = + &attach_complete->esm_message_container; + + ogs_assert(test_ue); + ogs_assert(esmbuf); + + memset(&message, 0, sizeof(message)); + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.emm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + message.emm.h.message_type = OGS_NAS_EPS_ATTACH_COMPLETE; + + esm_message_container->length = esmbuf->len; + esm_message_container->buffer = esmbuf->data; + ogs_pkbuf_free(esmbuf); + + return test_nas_eps_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testemm_build_detach_request(test_ue_t *test_ue, bool switch_off) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_detach_request_from_ue_t *detach_request = + &message.emm.detach_request_from_ue; + + ogs_nas_detach_type_t *detach_type = &detach_request->detach_type; + ogs_nas_eps_mobile_identity_t *eps_mobile_identity = + &detach_request->eps_mobile_identity; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.emm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + message.emm.h.message_type = OGS_NAS_EPS_DETACH_REQUEST; + + detach_type->nas_key_set_identifier = test_ue->nas.ksi; + detach_type->switch_off = switch_off; + detach_type->value = OGS_NAS_DETACH_TYPE_FROM_UE_EPS_DETACH; + + if (test_ue->nas_eps_guti.m_tmsi) { + eps_mobile_identity->length = + sizeof(ogs_nas_eps_mobile_identity_guti_t); + eps_mobile_identity->guti.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; + eps_mobile_identity->guti.type = OGS_NAS_EPS_MOBILE_IDENTITY_GUTI; + eps_mobile_identity->guti.nas_plmn_id = + test_ue->nas_eps_guti.nas_plmn_id; + eps_mobile_identity->guti.mme_gid = test_ue->nas_eps_guti.mme_gid; + eps_mobile_identity->guti.mme_code = test_ue->nas_eps_guti.mme_code; + eps_mobile_identity->guti.m_tmsi = test_ue->nas_eps_guti.m_tmsi; + } else { + eps_mobile_identity->length = + sizeof(ogs_nas_mobile_identity_imsi_t); + memcpy(&eps_mobile_identity->imsi, + &test_ue->mobile_identity_imsi, eps_mobile_identity->length); + } + + return test_nas_eps_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testemm_build_service_request(test_ue_t *test_ue) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_service_request_t *service_request = + &message.emm.service_request; + + ogs_pkbuf_t *pkbuf = NULL; + ogs_pkbuf_t *new = NULL; + uint8_t mac[4]; + + ogs_nas_ksi_and_sequence_number_t *ksi_and_sequence_number = + &service_request->ksi_and_sequence_number; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + message.emm.h.security_header_type = + OGS_NAS_SECURITY_HEADER_FOR_SERVICE_REQUEST_MESSAGE; + message.emm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + ksi_and_sequence_number->sequence_number = test_ue->ul_count; + + pkbuf = ogs_nas_eps_plain_encode(&message); + ogs_assert(pkbuf); + + new = ogs_pkbuf_copy(pkbuf); + ogs_assert(new); + ogs_pkbuf_trim(new, 2); + + /* To prevent error message in ogs_nas_mac_calculate() */ + if (test_ue->selected_int_algorithm == OGS_NAS_SECURITY_ALGORITHMS_EIA0) + test_ue->selected_int_algorithm = OGS_NAS_SECURITY_ALGORITHMS_128_EIA1; + + ogs_nas_mac_calculate(test_ue->selected_int_algorithm, + test_ue->knas_int, test_ue->ul_count, 0, 0, new, mac); + test_ue->ul_count = (test_ue->ul_count + 1) & 0xffffff; /* Use 24bit */ + + memcpy(pkbuf->data + 2, mac + 2, 2); + ogs_pkbuf_free(new); + + return pkbuf; +} + +ogs_pkbuf_t *testemm_build_tau_request(test_ue_t *test_ue, bool active_flag) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_tracking_area_update_request_t *tau_request = + &message.emm.tracking_area_update_request; + + ogs_nas_eps_update_type_t *eps_update_type = &tau_request->eps_update_type; + ogs_nas_eps_mobile_identity_t *old_guti = &tau_request->old_guti; + + ogs_nas_ue_network_capability_t *ue_network_capability = + &tau_request->ue_network_capability; + ogs_nas_tracking_area_identity_t *last_visited_registered_tai = + &tau_request->last_visited_registered_tai; + ogs_nas_drx_parameter_t *drx_parameter = &tau_request->drx_parameter; + ogs_nas_eps_bearer_context_status_t *eps_bearer_context_status = + &tau_request->eps_bearer_context_status; + ogs_nas_ms_network_capability_t *ms_network_capability = + &tau_request->ms_network_capability; + ogs_nas_location_area_identification_t *old_location_area_identification = + &tau_request->old_location_area_identification; + ogs_nas_tmsi_status_t *tmsi_status = &tau_request->tmsi_status; + ogs_nas_mobile_station_classmark_2_t *mobile_station_classmark_2 = + &tau_request->mobile_station_classmark_2; + ogs_nas_mobile_station_classmark_3_t *mobile_station_classmark_3 = + &tau_request->mobile_station_classmark_3; + ogs_nas_supported_codec_list_t *supported_codecs = + &tau_request->supported_codecs; + ogs_nas_additional_update_type_t *additional_update_type = + &tau_request->additional_update_type; + ogs_nas_voice_domain_preference_and_ue_usage_setting_t + *voice_domain_preference_and_ue_usage_setting = + &tau_request->voice_domain_preference_and_ue_usage_setting; + ogs_nas_guti_type_t *old_guti_type = &tau_request->old_guti_type; + ogs_nas_ms_network_feature_support_t *ms_network_feature_support = + &tau_request->ms_network_feature_support; + ogs_nas_network_resource_identifier_container_t *tmsi_based_nri_container = + &tau_request->tmsi_based_nri_container; + ogs_nas_ue_additional_security_capability_t + *ue_additional_security_capability = + &tau_request->ue_additional_security_capability; + + uint8_t classmark_3[11] = "\x60\x14\x04\xef\x65\x23\x3b\x88\x78\xd2\x90"; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + if (test_ue->tau_request_param.ciphered) { + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + } else { + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED; + } + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.emm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + message.emm.h.message_type = OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST; + + eps_update_type->nas_key_set_identifier = test_ue->nas.ksi; + eps_update_type->active_flag = active_flag; + eps_update_type->value = OGS_NAS_EPS_UPDATE_TYPE_COMBINED_TA_LA_UPDATING; + + old_guti->length = sizeof(ogs_nas_eps_mobile_identity_guti_t); + old_guti->guti.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; + old_guti->guti.type = OGS_NAS_EPS_MOBILE_IDENTITY_GUTI; + old_guti->guti.nas_plmn_id = test_ue->nas_eps_guti.nas_plmn_id; + old_guti->guti.mme_gid = test_ue->nas_eps_guti.mme_gid; + old_guti->guti.mme_code = test_ue->nas_eps_guti.mme_code; + old_guti->guti.m_tmsi = test_ue->nas_eps_guti.m_tmsi; + + if (test_ue->tau_request_param.ue_network_capability) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_UE_NETWORK_CAPABILITY_PRESENT; + ue_network_capability->length = 7; + ue_network_capability->eea = 0xf0; + ue_network_capability->eia = 0xf0; + ue_network_capability->uea = 0xc0; + ue_network_capability->uia = 0x40; + ue_network_capability->notification_procedure = 1; + ue_network_capability->dual_connectivity_with_nr = 1; + } + + if (test_ue->tau_request_param.last_visited_registered_tai) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_LAST_VISITED_REGISTERED_TAI_PRESENT; + ogs_nas_from_plmn_id(&last_visited_registered_tai->nas_plmn_id, + &test_ue->e_tai.plmn_id); + last_visited_registered_tai->tac = test_ue->e_tai.tac; + } + + if (test_ue->tau_request_param.drx_parameter) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_DRX_PARAMETER_PRESENT; + drx_parameter->split_pg_cycle_code = 32; + } + + if (test_ue->tau_request_param.eps_bearer_context_status) { + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_EPS_BEARER_CONTEXT_STATUS_PRESENT; + eps_bearer_context_status->length = 2; + + ogs_list_for_each(&test_ue->sess_list, sess) { + ogs_list_for_each(&sess->bearer_list, bearer) { + if (bearer->ebi == 5) eps_bearer_context_status->ebi5 = 1; + else if (bearer->ebi == 6) eps_bearer_context_status->ebi6 = 1; + else if (bearer->ebi == 7) eps_bearer_context_status->ebi7 = 1; + } + } + } + + if (test_ue->tau_request_param.ms_network_capability) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_MS_NETWORK_CAPABILITY_PRESENT; + ms_network_capability->length = 3; + ms_network_capability->gea1 = 1; + ms_network_capability->sm_capabilities_via_dedicated_channels = 1; + ms_network_capability->sm_capabilities_via_gprs_channels = 1; + ms_network_capability->ss_screening_indicator = 1; + ms_network_capability->revision_level_indicator = 1; + ms_network_capability->pfc_feature_mode = 1; + ms_network_capability->extended_gea = 0x30; + ms_network_capability->emm_combined_procedures_capability = 1; + ms_network_capability->isr_support = 1; + ms_network_capability->epc_capability = 1; + } + + if (test_ue->tau_request_param.location_area_identication) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_OLD_LOCATION_AREA_IDENTIFICATION_PRESENT; + ogs_nas_from_plmn_id(&old_location_area_identification->nas_plmn_id, + &test_ue->e_tai.plmn_id); + old_location_area_identification->lac = 1; + } + + if (test_ue->tau_request_param.tmsi_status) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_TMSI_STATUS_PRESENT; + } + + if (test_ue->tau_request_param.mobile_station_classmark_2) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_MOBILE_STATION_CLASSMARK_2_PRESENT; + mobile_station_classmark_2->length = 3; + mobile_station_classmark_2->revision_level = 2; + mobile_station_classmark_2->es_ind = 1; + mobile_station_classmark_2->a5_1 = 1; + mobile_station_classmark_2->rf_power_capability = 7; + mobile_station_classmark_2->ps_capa = 1; + mobile_station_classmark_2->ss_screen_indicator = 1; + mobile_station_classmark_2->sm_capabi = 1; + mobile_station_classmark_2->cm3 = 1; + mobile_station_classmark_2->lcsva_cap = 1; + mobile_station_classmark_2->cmsp = 1; + mobile_station_classmark_2->a5_3 = 1; + } + + if (test_ue->tau_request_param.mobile_station_classmark_3) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_MOBILE_STATION_CLASSMARK_3_PRESENT; + mobile_station_classmark_3->length = 11; + memcpy(mobile_station_classmark_3->buffer, + classmark_3, mobile_station_classmark_3->length); + } + + if (test_ue->tau_request_param.supported_codecs) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_SUPPORTED_CODECS_PRESENT; + supported_codecs->length = 8; + supported_codecs->item[0].system_identification = 0x04; + supported_codecs->item[0].length_of_bitmap = 2; + supported_codecs->item[0].codec_bitmap = htobe16(0x6004); + supported_codecs->item[1].system_identification = 0; + supported_codecs->item[1].length_of_bitmap = 2; + supported_codecs->item[1].codec_bitmap = htobe16(0x1f02); + } + + if (test_ue->tau_request_param.additional_update_type) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_ADDITIONAL_UPDATE_TYPE_PRESENT; + additional_update_type->autv = 1; + } + + if (test_ue->tau_request_param.ue_usage_setting) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_VOICE_DOMAIN_PREFERENCE_AND_UE_USAGE_SETTING_PRESENT; + voice_domain_preference_and_ue_usage_setting->length = 1; + voice_domain_preference_and_ue_usage_setting->ue_usage_setting = 1; + voice_domain_preference_and_ue_usage_setting-> + voice_domain_preference_for_e_utran = 1; + } + + if (test_ue->tau_request_param.old_guti_type) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_OLD_GUTI_TYPE_PRESENT; + } + + if (test_ue->tau_request_param.ms_network_feature_support) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_MS_NETWORK_FEATURE_SUPPORT_PRESENT; + ms_network_feature_support->extended_periodic_timers = 1; + } + + if (test_ue->tau_request_param.nri_container) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_TMSI_BASED_NRI_CONTAINER_PRESENT; + tmsi_based_nri_container->length = 2; + tmsi_based_nri_container->nri_container_value1 = 0x8d; + tmsi_based_nri_container->nri_container_value2 = 0x3; + } + + if (test_ue->tau_request_param.ue_additional_security_capability) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_UE_ADDITIONAL_SECURITY_CAPABILITY_PRESENT; + ue_additional_security_capability->length = 4; + ue_additional_security_capability->nea = 0xf0; + ue_additional_security_capability->nia = 0xf0; + } + + if (test_ue->tau_request_param.device_properties) { + tau_request->presencemask |= + OGS_NAS_EPS_TRACKING_AREA_UPDATE_REQUEST_DEVICE_PROPERTIES_PRESENT; + } + + return test_nas_eps_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testemm_build_emm_status( + test_ue_t *test_ue, ogs_nas_emm_cause_t emm_cause) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_emm_status_t *emm_status = &message.emm.emm_status; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.emm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + message.emm.h.message_type = OGS_NAS_EPS_EMM_STATUS; + + emm_status->emm_cause = emm_cause; + + return test_nas_eps_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testemm_build_extended_service_request( + test_ue_t *test_ue, uint8_t type) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_extended_service_request_t *extended_service_request = + &message.emm.extended_service_request; + + ogs_nas_service_type_t *service_type = + &extended_service_request->service_type; + ogs_nas_mobile_identity_t *mobile_identity = + &extended_service_request->m_tmsi; + ogs_nas_csfb_response_t *csfb_response = + &extended_service_request->csfb_response; + ogs_nas_eps_bearer_context_status_t *eps_bearer_context_status = + &extended_service_request->eps_bearer_context_status; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + if (test_ue->extended_service_request_param.ciphered) + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + else + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED; + + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.emm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + message.emm.h.message_type = OGS_NAS_EPS_EXTENDED_SERVICE_REQUEST; + + service_type->value = type; + + mobile_identity->length = 5; + mobile_identity->tmsi.type = OGS_NAS_MOBILE_IDENTITY_TMSI; + mobile_identity->tmsi.tmsi = test_ue->nas_eps_guti.m_tmsi; + + if (test_ue->extended_service_request_param.csfb_response) { + extended_service_request->presencemask |= + OGS_NAS_EPS_EXTENDED_SERVICE_REQUEST_CSFB_RESPONSE_PRESENT; + csfb_response->response = + test_ue->extended_service_request_param.csfb.response; + } + + if (test_ue->extended_service_request_param.eps_bearer_context_status) { + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + extended_service_request->presencemask |= OGS_NAS_EPS_EXTENDED_SERVICE_REQUEST_EPS_BEARER_CONTEXT_STATUS_PRESENT; + eps_bearer_context_status->length = 2; + + ogs_list_for_each(&test_ue->sess_list, sess) { + ogs_list_for_each(&sess->bearer_list, bearer) { + if (bearer->ebi == 5) eps_bearer_context_status->ebi5 = 1; + else if (bearer->ebi == 6) eps_bearer_context_status->ebi6 = 1; + else if (bearer->ebi == 7) eps_bearer_context_status->ebi7 = 1; + } + } + } + + return test_nas_eps_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testemm_build_uplink_nas_transport(test_ue_t *test_ue) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_uplink_nas_transport_t *uplink_nas_transport = + &message.emm.uplink_nas_transport; + + ogs_nas_eps_message_container_t *nas_message_container = + &uplink_nas_transport->nas_message_container; + + char hexbuf[OGS_MAX_SDU_LEN]; + const char *payload = + "390167000300" + "0581005155f55d11 030c914477680205 490000055ad2e2b1 252d467ff6de6c47" + "efd568375b303613 166fb51c6d160cc2 8ab462b006a3d98a 31da90060b0673c5" + "9c512684158bb119 2c88b3058b37e1ad 081bca84c1582d07 93ede4bddc6d2693" + "e566371b"; + + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.emm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + message.emm.h.message_type = OGS_NAS_EPS_UPLINK_NAS_TRANSPORT; + + OGS_HEX(payload, strlen(payload), hexbuf); + nas_message_container->length = 106; + memcpy(nas_message_container->buffer, + hexbuf, nas_message_container->length); + + return test_nas_eps_security_encode(test_ue, &message); +} diff --git a/tests/common/emm-build.h b/tests/common/emm-build.h new file mode 100644 index 000000000..993695bb7 --- /dev/null +++ b/tests/common/emm-build.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TEST_EMM_BUILD_H +#define TEST_EMM_BUILD_H + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_pkbuf_t *testemm_build_attach_request( + test_ue_t *test_ue, ogs_pkbuf_t *esmbuf); +ogs_pkbuf_t *testemm_build_identity_response(test_ue_t *test_ue); +ogs_pkbuf_t *testemm_build_authentication_response(test_ue_t *test_ue); +ogs_pkbuf_t *testemm_build_authentication_failure( + test_ue_t *test_ue, ogs_nas_emm_cause_t emm_cause, uint64_t sqn_ms); +ogs_pkbuf_t *testemm_build_security_mode_complete(test_ue_t *test_ue); +ogs_pkbuf_t *testemm_build_attach_complete( + test_ue_t *test_ue, ogs_pkbuf_t *esmbuf); + +ogs_pkbuf_t *testemm_build_detach_request(test_ue_t *test_ue, bool switch_off); + +ogs_pkbuf_t *testemm_build_service_request(test_ue_t *test_ue); +ogs_pkbuf_t *testemm_build_tau_request(test_ue_t *test_ue, bool active_flag); +ogs_pkbuf_t *testemm_build_emm_status( + test_ue_t *test_ue, ogs_nas_emm_cause_t emm_cause); + +ogs_pkbuf_t *testemm_build_extended_service_request( + test_ue_t *test_ue, uint8_t type); + +ogs_pkbuf_t *testemm_build_uplink_nas_transport(test_ue_t *test_ue); + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_EMM_BUILD_H */ diff --git a/tests/common/emm-handler.c b/tests/common/emm-handler.c new file mode 100644 index 000000000..d2956f571 --- /dev/null +++ b/tests/common/emm-handler.c @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +void testemm_handle_identity_request(test_ue_t *test_ue, + ogs_nas_eps_identity_request_t *identity_request) +{ + ogs_assert(test_ue); + ogs_assert(identity_request); + + switch (identity_request->identity_type.type) { + case OGS_NAS_IDENTITY_TYPE_2_IMSI: + break; + default: + ogs_error("Not implemented [%d]", + identity_request->identity_type.type); + break; + } +} + +void testemm_handle_authentication_request(test_ue_t *test_ue, + ogs_nas_eps_authentication_request_t *authentication_request) +{ + ogs_nas_authentication_parameter_rand_t *authentication_parameter_rand = + NULL; + ogs_nas_authentication_parameter_autn_t *authentication_parameter_autn = + NULL; + ogs_nas_key_set_identifier_t *ksi = NULL; + + ogs_assert(test_ue); + ogs_assert(authentication_request); + + authentication_parameter_rand = &authentication_request-> + authentication_parameter_rand; + authentication_parameter_autn = &authentication_request-> + authentication_parameter_autn; + ksi = &authentication_request->nas_key_set_identifierasme; + + test_ue->nas.ksi = ksi->value; + + memcpy(test_ue->rand, authentication_parameter_rand->rand, OGS_RAND_LEN); + memcpy(test_ue->autn, authentication_parameter_autn->autn, OGS_AUTN_LEN); +} + +void testemm_handle_security_mode_command(test_ue_t *test_ue, + ogs_nas_eps_security_mode_command_t *security_mode_command) +{ + ogs_nas_security_algorithms_t *selected_nas_security_algorithms = NULL; + ogs_nas_key_set_identifier_t *ksi = NULL; + + ogs_assert(test_ue); + ogs_assert(security_mode_command); + + selected_nas_security_algorithms = + &security_mode_command->selected_nas_security_algorithms; + ksi = &security_mode_command->nas_key_set_identifier; + + test_ue->selected_enc_algorithm = + selected_nas_security_algorithms->type_of_ciphering_algorithm; + test_ue->selected_int_algorithm = + selected_nas_security_algorithms-> + type_of_integrity_protection_algorithm; + + ogs_kdf_nas_eps(OGS_KDF_NAS_INT_ALG, test_ue->selected_int_algorithm, + test_ue->kasme, test_ue->knas_int); + ogs_kdf_nas_eps(OGS_KDF_NAS_ENC_ALG, test_ue->selected_enc_algorithm, + test_ue->kasme, test_ue->knas_enc); + + test_ue->nas.ksi = ksi->value; + + test_ue->security_context_available = 1; +} + +void testemm_handle_attach_accept(test_ue_t *test_ue, + ogs_nas_eps_attach_accept_t *attach_accept) +{ + ogs_nas_eps_mobile_identity_t *guti = NULL; + + ogs_assert(test_ue); + ogs_assert(attach_accept); + + guti = &attach_accept->guti; + + if (attach_accept->presencemask & OGS_NAS_EPS_ATTACH_ACCEPT_GUTI_PRESENT) { + memcpy(&test_ue->nas_eps_guti.nas_plmn_id, + &guti->guti.nas_plmn_id, OGS_PLMN_ID_LEN); + test_ue->nas_eps_guti.mme_gid = guti->guti.mme_gid; + test_ue->nas_eps_guti.mme_code = guti->guti.mme_code; + test_ue->nas_eps_guti.m_tmsi = guti->guti.m_tmsi; + } + + testemm_send_to_esm(test_ue, &attach_accept->esm_message_container); +} diff --git a/src/hss/hss-auc.h b/tests/common/emm-handler.h similarity index 54% rename from src/hss/hss-auc.h rename to tests/common/emm-handler.h index 10a344b4f..7232d4cf4 100644 --- a/src/hss/hss-auc.h +++ b/tests/common/emm-handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019,2020 by Sukchan Lee * * This file is part of Open5GS. * @@ -17,21 +17,24 @@ * along with this program. If not, see . */ -#ifndef HSS_KDF_H -#define HSS_KDF_H - -#include "ogs-core.h" +#ifndef TEST_EMM_HANDLE_H +#define TEST_EMM_HANDLE_H #ifdef __cplusplus extern "C" { #endif -void hss_auc_kasme(const uint8_t *ck, const uint8_t *ik, - const uint8_t plmn_id[3], const uint8_t *sqn, const uint8_t *ak, - uint8_t *kasme); +void testemm_handle_identity_request(test_ue_t *test_ue, + ogs_nas_eps_identity_request_t *identity_request); +void testemm_handle_authentication_request(test_ue_t *test_ue, + ogs_nas_eps_authentication_request_t *authentication_request); +void testemm_handle_security_mode_command(test_ue_t *test_ue, + ogs_nas_eps_security_mode_command_t *security_mode_command); +void testemm_handle_attach_accept(test_ue_t *test_ue, + ogs_nas_eps_attach_accept_t *attach_accept); #ifdef __cplusplus } #endif -#endif /* HSS_KDF_H */ +#endif /* TEST_EMM_HANDLE_H */ diff --git a/tests/common/esm-build.c b/tests/common/esm-build.c new file mode 100644 index 000000000..024ebc36e --- /dev/null +++ b/tests/common/esm-build.c @@ -0,0 +1,567 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +ogs_pkbuf_t *testesm_build_pdn_connectivity_request(test_sess_t *sess) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_pdn_connectivity_request_t *pdn_connectivity_request = + &message.esm.pdn_connectivity_request; + ogs_nas_request_type_t *request_type = + &pdn_connectivity_request->request_type; + + ogs_nas_access_point_name_t *access_point_name = + &pdn_connectivity_request->access_point_name; + ogs_nas_esm_information_transfer_flag_t *esm_information_transfer_flag = + &pdn_connectivity_request->esm_information_transfer_flag; + ogs_nas_protocol_configuration_options_t *protocol_configuration_options = + &pdn_connectivity_request->protocol_configuration_options; + uint8_t ue_pco[29] = + "\x80\x80\x21\x10\x01\x01\x00\x10\x81\x06\x00\x00\x00\x00" + "\x83\x06\x00\x00\x00\x00\x00\x03\x00\x00\x0a\x00\x00\x0d\x00"; +#if 0 + uint8_t ue_pco[7] = "\x80\x00\x0a\x00\x00\x0d\x00"; +#endif + + test_ue_t *test_ue = NULL; + ogs_pkbuf_t *pkbuf = NULL; + + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + + if (sess->pdn_connectivity_param.integrity_protected) { + if (sess->pdn_connectivity_param.ciphered) + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + else + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + } + + message.esm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_ESM; + message.esm.h.procedure_transaction_identity = sess->pti; + message.esm.h.message_type = OGS_NAS_EPS_PDN_CONNECTIVITY_REQUEST; + + request_type->type = OGS_NAS_EPS_PDN_TYPE_IPV4V6; + request_type->value = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; + + if (sess->pdn_connectivity_param.apn) { + pdn_connectivity_request->presencemask |= + OGS_NAS_EPS_PDN_CONNECTIVITY_REQUEST_ACCESS_POINT_NAME_PRESENT; + ogs_cpystrn(access_point_name->apn, sess->apn, + ogs_min(strlen(sess->apn), OGS_MAX_APN_LEN) + 1); + access_point_name->length = strlen(sess->apn); + } + + if (sess->pdn_connectivity_param.eit || + sess->pdn_connectivity_param.eit_no_required) { + pdn_connectivity_request->presencemask |= OGS_NAS_EPS_PDN_CONNECTIVITY_REQUEST_ESM_INFORMATION_TRANSFER_FLAG_PRESENT; + esm_information_transfer_flag->security_protected_required = + sess->pdn_connectivity_param.eit; + } + + if (sess->pdn_connectivity_param.pco) { + pdn_connectivity_request->presencemask |= OGS_NAS_EPS_PDN_CONNECTIVITY_REQUEST_PROTOCOL_CONFIGURATION_OPTIONS_PRESENT; + protocol_configuration_options->length = sizeof(ue_pco); + memcpy(protocol_configuration_options->buffer, ue_pco, sizeof(ue_pco)); + } + + if (sess->pdn_connectivity_param.integrity_protected) + return test_nas_eps_security_encode(test_ue, &message); + else + return ogs_nas_eps_plain_encode(&message); +} + +ogs_pkbuf_t *testesm_build_pdn_disconnect_request(test_sess_t *sess) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_pdn_disconnect_request_t *pdn_disconnect_request = + &message.esm.pdn_disconnect_request; + ogs_nas_linked_eps_bearer_identity_t *linked_eps_bearer_identity = + &pdn_disconnect_request->linked_eps_bearer_identity; + + test_ue_t *test_ue = NULL; + test_bearer_t *bearer = NULL; + ogs_pkbuf_t *pkbuf = NULL; + + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + bearer = ogs_list_first(&sess->bearer_list); + ogs_assert(bearer); + + memset(&message, 0, sizeof(message)); + + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.esm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_ESM; + message.esm.h.procedure_transaction_identity = sess->pti; + message.esm.h.message_type = OGS_NAS_EPS_PDN_DISCONNECT_REQUEST; + + linked_eps_bearer_identity->eps_bearer_identity = bearer->ebi; + + return test_nas_eps_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testesm_build_esm_information_response(test_sess_t *sess) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_esm_information_response_t *esm_information_response = + &message.esm.esm_information_response; + + ogs_nas_access_point_name_t *access_point_name = + &esm_information_response->access_point_name; + ogs_nas_protocol_configuration_options_t *protocol_configuration_options = + &esm_information_response->protocol_configuration_options; + + uint8_t ue_pco[29] = + "\x80\x80\x21\x10\x01\x01\x00\x10\x81\x06\x00\x00\x00\x00" + "\x83\x06\x00\x00\x00\x00\x00\x03\x00\x00\x0a\x00\x00\x0d\x00"; + + test_ue_t *test_ue = NULL; + ogs_pkbuf_t *pkbuf = NULL; + + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.esm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_ESM; + message.esm.h.procedure_transaction_identity = sess->pti; + message.esm.h.message_type = OGS_NAS_EPS_ESM_INFORMATION_RESPONSE; + + esm_information_response->presencemask |= OGS_NAS_EPS_ESM_INFORMATION_RESPONSE_ACCESS_POINT_NAME_PRESENT; + + ogs_assert(sess->apn); + ogs_cpystrn(access_point_name->apn, sess->apn, + ogs_min(strlen(sess->apn), OGS_MAX_APN_LEN) + 1); + access_point_name->length = strlen(sess->apn); + + if (sess->esm_information_param.pco) { + esm_information_response->presencemask |= OGS_NAS_EPS_ESM_INFORMATION_RESPONSE_PROTOCOL_CONFIGURATION_OPTIONS_PRESENT; + protocol_configuration_options->length = sizeof(ue_pco); + memcpy(protocol_configuration_options->buffer, ue_pco, sizeof(ue_pco)); + } + + return test_nas_eps_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testesm_build_activate_default_eps_bearer_context_accept( + test_bearer_t *bearer, bool integrity_protected_and_ciphered) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_activate_default_eps_bearer_context_accept_t + *activate_default_eps_bearer_context_accept = + &message.esm.activate_default_eps_bearer_context_accept; + + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + ogs_pkbuf_t *pkbuf = NULL; + + ogs_assert(bearer); + sess = bearer->sess; + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + + if (integrity_protected_and_ciphered) { + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + } + + + message.esm.h.eps_bearer_identity = bearer->ebi; + message.esm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_ESM; + message.esm.h.message_type = + OGS_NAS_EPS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_ACCEPT; + + if (integrity_protected_and_ciphered) + return test_nas_eps_security_encode(test_ue, &message); + else + return ogs_nas_eps_plain_encode(&message); +} + +ogs_pkbuf_t *testesm_build_activate_dedicated_eps_bearer_context_accept( + test_bearer_t *bearer) +{ + ogs_nas_eps_message_t message; + ogs_nas_eps_activate_dedicated_eps_bearer_context_accept_t + *activate_dedicated_eps_bearer_context_accept = + &message.esm.activate_dedicated_eps_bearer_context_accept; + + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + ogs_pkbuf_t *pkbuf = NULL; + + ogs_assert(bearer); + sess = bearer->sess; + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.esm.h.eps_bearer_identity = bearer->ebi; + message.esm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_ESM; + message.esm.h.message_type = + OGS_NAS_EPS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT; + + return test_nas_eps_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testesm_build_modify_eps_bearer_context_accept( + test_bearer_t *bearer) +{ + ogs_nas_eps_message_t message; + + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + ogs_pkbuf_t *pkbuf = NULL; + + ogs_assert(bearer); + sess = bearer->sess; + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.esm.h.eps_bearer_identity = bearer->ebi; + message.esm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_ESM; + message.esm.h.procedure_transaction_identity = sess->pti; + message.esm.h.message_type = OGS_NAS_EPS_MODIFY_EPS_BEARER_CONTEXT_ACCEPT; + + return test_nas_eps_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testesm_build_deactivate_eps_bearer_context_accept( + test_bearer_t *bearer) +{ + ogs_nas_eps_message_t message; + + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + ogs_pkbuf_t *pkbuf = NULL; + + ogs_assert(bearer); + sess = bearer->sess; + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.esm.h.eps_bearer_identity = bearer->ebi; + message.esm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_ESM; + message.esm.h.message_type = + OGS_NAS_EPS_DEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT; + + return test_nas_eps_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testesm_build_bearer_resource_allocation_request( + test_bearer_t *bearer) +{ + ogs_nas_eps_message_t message; + + ogs_nas_eps_bearer_resource_allocation_request_t + *bearer_resource_allocation_request = + &message.esm.bearer_resource_allocation_request; + + ogs_nas_linked_eps_bearer_identity_t *linked_eps_bearer_identity = + &bearer_resource_allocation_request->linked_eps_bearer_identity; + ogs_nas_traffic_flow_aggregate_description_t *traffic_flow_aggregate = + &bearer_resource_allocation_request->traffic_flow_aggregate; + ogs_nas_eps_quality_of_service_t *required_traffic_flow_qos = + &bearer_resource_allocation_request->required_traffic_flow_qos; + + uint8_t tft[4] = "\x21\x20\x01\x00"; + + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + ogs_pkbuf_t *pkbuf = NULL; + + ogs_assert(bearer); + sess = bearer->sess; + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.esm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_ESM; + message.esm.h.procedure_transaction_identity = sess->pti; + message.esm.h.message_type = OGS_NAS_EPS_BEARER_RESOURCE_ALLOCATION_REQUEST; + + linked_eps_bearer_identity->eps_bearer_identity = bearer->ebi; + + traffic_flow_aggregate->length = sizeof(tft); + memcpy(traffic_flow_aggregate->buffer, tft, traffic_flow_aggregate->length); + + required_traffic_flow_qos->length = 5; + required_traffic_flow_qos->qci = 1; + + return test_nas_eps_security_encode(test_ue, &message); +} + +ogs_pkbuf_t *testesm_build_bearer_resource_modification_request( + test_bearer_t *bearer, uint8_t tft_code, uint8_t qci, uint8_t esm_cause) +{ + int rv; + ogs_nas_eps_message_t message; + + ogs_nas_eps_bearer_resource_modification_request_t *req = + &message.esm.bearer_resource_modification_request; + + ogs_nas_linked_eps_bearer_identity_t + *eps_bearer_identity_for_packet_filter = + &req->eps_bearer_identity_for_packet_filter; + ogs_nas_traffic_flow_aggregate_description_t *tad = + &req->traffic_flow_aggregate; + ogs_nas_eps_quality_of_service_t *qos = &req->required_traffic_flow_qos; + + ogs_gtp_tft_t tft; + ogs_tlv_octet_t octet; + ogs_ipsubnet_t ipsubnet; + + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + ogs_pkbuf_t *pkbuf = NULL; + + ogs_assert(bearer); + sess = bearer->sess; + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + memset(&message, 0, sizeof(message)); + + message.h.security_header_type = + OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED; + message.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM; + + message.esm.h.protocol_discriminator = OGS_NAS_PROTOCOL_DISCRIMINATOR_ESM; + message.esm.h.procedure_transaction_identity = sess->pti; + message.esm.h.message_type = + OGS_NAS_EPS_BEARER_RESOURCE_MODIFICATION_REQUEST; + + eps_bearer_identity_for_packet_filter->eps_bearer_identity = bearer->ebi; + + memset(&tft, 0, sizeof tft); + tft.code = tft_code; + if (tft.code == OGS_GTP_TFT_CODE_REPLACE_PACKET_FILTERS_IN_EXISTING) { + tft.num_of_packet_filter = 1; + tft.pf[0].direction = 1; + tft.pf[0].identifier = 0; + tft.pf[0].precedence = 0x0f; + tft.pf[0].length = 9; + tft.pf[0].component[0].type = + GTP_PACKET_FILTER_IPV4_REMOTE_ADDRESS_TYPE; + rv = ogs_ipsubnet(&ipsubnet, "201.20.2.5", NULL); + ogs_assert(rv == OGS_OK); + tft.pf[0].component[0].ipv4.addr = ipsubnet.sub[0]; + tft.pf[0].component[0].ipv4.mask = ipsubnet.mask[0]; + tft.pf[0].num_of_component = 1; + } else if (tft.code == + OGS_GTP_TFT_CODE_ADD_PACKET_FILTERS_TO_EXISTING_TFT) { + tft.num_of_packet_filter = 1; + tft.pf[0].direction = 1; + tft.pf[0].identifier = 4; + tft.pf[0].precedence = 0x0f; + + rv = ogs_ipsubnet(&ipsubnet, "cafe::9", "120"); + ogs_assert(rv == OGS_OK); +#if 1 + tft.pf[0].length = 18; + tft.pf[0].component[0].type = + GTP_PACKET_FILTER_IPV6_REMOTE_ADDRESS_PREFIX_LENGTH_TYPE; + memcpy(tft.pf[0].component[0].ipv6.addr, ipsubnet.sub, + sizeof(tft.pf[0].component[0].ipv6.addr)); + tft.pf[0].component[0].ipv6.prefixlen = 120; +#else + tft.pf[0].length = 33; + tft.pf[0].component[0].type = + GTP_PACKET_FILTER_IPV6_REMOTE_ADDRESS_TYPE; + memcpy(tft.pf[0].component[0].ipv6_mask.addr, ipsubnet.sub, + sizeof(tft.pf[0].component[0].ipv6_mask.addr)); + memcpy(tft.pf[0].component[0].ipv6_mask.mask, ipsubnet.mask, + sizeof(tft.pf[0].component[0].ipv6_mask.mask)); +#endif + tft.pf[0].num_of_component = 1; + + } else if (tft.code == OGS_GTP_TFT_CODE_CREATE_NEW_TFT) { + tft.num_of_packet_filter = 4; + + tft.pf[0].direction = 1; + tft.pf[0].identifier = 0; + tft.pf[0].precedence = 0x01; + tft.pf[0].length = 0x17; + tft.pf[0].component[0].type = + GTP_PACKET_FILTER_PROTOCOL_IDENTIFIER_NEXT_HEADER_TYPE; + tft.pf[0].component[0].proto = 0x11; /* UDP */ + tft.pf[0].component[1].type = + GTP_PACKET_FILTER_IPV4_LOCAL_ADDRESS_TYPE; + rv = ogs_ipsubnet(&ipsubnet, "172.20.166.84", NULL); + ogs_assert(rv == OGS_OK); + tft.pf[0].component[1].ipv4.addr = ipsubnet.sub[0]; + tft.pf[0].component[1].ipv4.mask = ipsubnet.mask[0]; + tft.pf[0].component[2].type = + GTP_PACKET_FILTER_IPV4_REMOTE_ADDRESS_TYPE; + rv = ogs_ipsubnet(&ipsubnet, "172.18.128.20", NULL); + ogs_assert(rv == OGS_OK); + tft.pf[0].component[2].ipv4.addr = ipsubnet.sub[0]; + tft.pf[0].component[2].ipv4.mask = ipsubnet.mask[0]; + tft.pf[0].component[3].type = + GTP_PACKET_FILTER_SINGLE_REMOTE_PORT_TYPE; + tft.pf[0].component[3].port.low = 20001; + tft.pf[0].num_of_component = 4; + + tft.pf[1].direction = 2; + tft.pf[1].identifier = 1; + tft.pf[1].precedence = 0x02; + tft.pf[1].length = 0x17; + tft.pf[1].component[0].type = + GTP_PACKET_FILTER_PROTOCOL_IDENTIFIER_NEXT_HEADER_TYPE; + tft.pf[1].component[0].proto = 0x11; /* UDP */ + tft.pf[1].component[1].type = + GTP_PACKET_FILTER_IPV4_LOCAL_ADDRESS_TYPE; + rv = ogs_ipsubnet(&ipsubnet, "172.20.166.84", NULL); + ogs_assert(rv == OGS_OK); + tft.pf[1].component[1].ipv4.addr = ipsubnet.sub[0]; + tft.pf[1].component[1].ipv4.mask = ipsubnet.mask[0]; + tft.pf[1].component[2].type = + GTP_PACKET_FILTER_IPV4_REMOTE_ADDRESS_TYPE; + rv = ogs_ipsubnet(&ipsubnet, "172.18.128.20", NULL); + ogs_assert(rv == OGS_OK); + tft.pf[1].component[2].ipv4.addr = ipsubnet.sub[0]; + tft.pf[1].component[2].ipv4.mask = ipsubnet.mask[0]; + tft.pf[1].component[3].type = + GTP_PACKET_FILTER_SINGLE_LOCAL_PORT_TYPE; + tft.pf[1].component[3].port.low = 20360; + tft.pf[1].num_of_component = 4; + + tft.pf[2].direction = 1; + tft.pf[2].identifier = 2; + tft.pf[2].precedence = 0x03; + tft.pf[2].length = 0x17; + tft.pf[2].component[0].type = + GTP_PACKET_FILTER_PROTOCOL_IDENTIFIER_NEXT_HEADER_TYPE; + tft.pf[2].component[0].proto = 0x11; /* UDP */ + tft.pf[2].component[1].type = + GTP_PACKET_FILTER_IPV4_LOCAL_ADDRESS_TYPE; + rv = ogs_ipsubnet(&ipsubnet, "172.20.166.84", NULL); + ogs_assert(rv == OGS_OK); + tft.pf[2].component[1].ipv4.addr = ipsubnet.sub[0]; + tft.pf[2].component[1].ipv4.mask = ipsubnet.mask[0]; + tft.pf[2].component[2].type = + GTP_PACKET_FILTER_IPV4_REMOTE_ADDRESS_TYPE; + rv = ogs_ipsubnet(&ipsubnet, "172.18.128.20", NULL); + ogs_assert(rv == OGS_OK); + tft.pf[2].component[2].ipv4.addr = ipsubnet.sub[0]; + tft.pf[2].component[2].ipv4.mask = ipsubnet.mask[0]; + tft.pf[2].component[3].type = + GTP_PACKET_FILTER_SINGLE_REMOTE_PORT_TYPE; + tft.pf[2].component[3].port.low = 20002; + tft.pf[2].num_of_component = 4; + + tft.pf[3].direction = 2; + tft.pf[3].identifier = 3; + tft.pf[3].precedence = 0x04; + tft.pf[3].length = 0x17; + tft.pf[3].component[0].type = + GTP_PACKET_FILTER_PROTOCOL_IDENTIFIER_NEXT_HEADER_TYPE; + tft.pf[3].component[0].proto = 0x11; /* UDP */ + tft.pf[3].component[1].type = + GTP_PACKET_FILTER_IPV4_LOCAL_ADDRESS_TYPE; + rv = ogs_ipsubnet(&ipsubnet, "172.20.166.84", NULL); + ogs_assert(rv == OGS_OK); + tft.pf[3].component[1].ipv4.addr = ipsubnet.sub[0]; + tft.pf[3].component[1].ipv4.mask = ipsubnet.mask[0]; + tft.pf[3].component[2].type = + GTP_PACKET_FILTER_IPV4_REMOTE_ADDRESS_TYPE; + rv = ogs_ipsubnet(&ipsubnet, "172.18.128.20", NULL); + ogs_assert(rv == OGS_OK); + tft.pf[3].component[2].ipv4.addr = ipsubnet.sub[0]; + tft.pf[3].component[2].ipv4.mask = ipsubnet.mask[0]; + tft.pf[3].component[3].type = + GTP_PACKET_FILTER_SINGLE_LOCAL_PORT_TYPE; + tft.pf[3].component[3].port.low = 20361; + tft.pf[3].num_of_component = 4; + } else if (tft.code == + OGS_GTP_TFT_CODE_DELETE_PACKET_FILTERS_FROM_EXISTING) { + tft.num_of_packet_filter = 4; + tft.pf[0].identifier = 0; + tft.pf[1].identifier = 1; + tft.pf[2].identifier = 2; + tft.pf[3].identifier = 3; + } + tad->length = ogs_gtp_build_tft(&octet, + &tft, tad->buffer, OGS_GTP_MAX_TRAFFIC_FLOW_TEMPLATE); + + if (qci) { + req->presencemask |= + OGS_NAS_EPS_BEARER_RESOURCE_MODIFICATION_REQUEST_REQUIRED_TRAFFIC_FLOW_QOS_PRESENT; + qos->length = 5; + qos->qci = qci; + qos->ul_mbr = 44; + qos->dl_mbr = 55; + qos->ul_gbr = 22; + qos->dl_gbr = 33; + } + + if (esm_cause) { + req->presencemask |= + OGS_NAS_EPS_BEARER_RESOURCE_MODIFICATION_REQUEST_ESM_CAUSE_PRESENT; + req->esm_cause = esm_cause; + } + + return test_nas_eps_security_encode(test_ue, &message); +} diff --git a/tests/common/esm-build.h b/tests/common/esm-build.h new file mode 100644 index 000000000..2b27e6567 --- /dev/null +++ b/tests/common/esm-build.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TEST_ESM_BUILD_H +#define TEST_ESM_BUILD_H + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_pkbuf_t *testesm_build_pdn_connectivity_request(test_sess_t *sess); +ogs_pkbuf_t *testesm_build_pdn_disconnect_request(test_sess_t *sess); +ogs_pkbuf_t *testesm_build_esm_information_response(test_sess_t *sess); +ogs_pkbuf_t *testesm_build_activate_default_eps_bearer_context_accept( + test_bearer_t *bearer, bool integrity_protected_and_ciphered); +ogs_pkbuf_t *testesm_build_activate_dedicated_eps_bearer_context_accept( + test_bearer_t *bearer); +ogs_pkbuf_t *testesm_build_modify_eps_bearer_context_accept( + test_bearer_t *bearer); +ogs_pkbuf_t *testesm_build_deactivate_eps_bearer_context_accept( + test_bearer_t *bearer); + +ogs_pkbuf_t *testesm_build_bearer_resource_allocation_request( + test_bearer_t *bearer); +ogs_pkbuf_t *testesm_build_bearer_resource_modification_request( + test_bearer_t *bearer, uint8_t tft_code, uint8_t qci, uint8_t esm_cause); + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_ESM_BUILD_H */ diff --git a/tests/common/esm-handler.c b/tests/common/esm-handler.c new file mode 100644 index 000000000..ff307edc2 --- /dev/null +++ b/tests/common/esm-handler.c @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +void testesm_handle_activate_default_eps_bearer_context_request( + test_ue_t *test_ue, ogs_nas_eps_message_t *message) +{ + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + ogs_nas_eps_activate_default_eps_bearer_context_request_t + *activate_default_eps_bearer_context_request = NULL; + + ogs_nas_pdn_address_t *pdn_address = NULL; + ogs_nas_access_point_name_t *access_point_name = NULL; + + ogs_assert(message); + + activate_default_eps_bearer_context_request = + &message->esm.activate_default_eps_bearer_context_request; + + pdn_address = &activate_default_eps_bearer_context_request->pdn_address; + access_point_name = + &activate_default_eps_bearer_context_request->access_point_name; + + sess = test_sess_find_by_apn(test_ue, access_point_name->apn); + ogs_assert(sess); + bearer = test_bearer_find_by_sess_ebi( + sess, message->esm.h.eps_bearer_identity); + if (!bearer) + bearer = test_bearer_add(sess, message->esm.h.eps_bearer_identity); + ogs_assert(bearer); + + switch (pdn_address->pdn_type) { + case OGS_PDU_SESSION_TYPE_IPV4: + sess->ue_ip.ipv4 = 1; + sess->ue_ip.addr = pdn_address->addr; + break; + case OGS_PDU_SESSION_TYPE_IPV6: + sess->ue_ip.ipv6 = 1; + memcpy(sess->ue_ip.addr6, "\xca\xfe\x00\x00\x00\x00\x00\x00", 8); + memcpy(sess->ue_ip.addr6+8, pdn_address->addr6, 8); + break; + case OGS_PDU_SESSION_TYPE_IPV4V6: + sess->ue_ip.ipv4 = 1; + sess->ue_ip.addr = pdn_address->both.addr; + sess->ue_ip.ipv6 = 1; + memcpy(sess->ue_ip.addr6, "\xca\xfe\x00\x00\x00\x00\x00\x00", 8); + memcpy(sess->ue_ip.addr6+8, pdn_address->both.addr6, 8); + break; + default: + ogs_fatal("Invalid PDU Address Type [%d]", pdn_address->pdn_type); + ogs_assert_if_reached(); + } +} + +void testesm_handle_activate_dedicated_eps_bearer_context_request( + test_ue_t *test_ue, ogs_nas_eps_message_t *message) +{ + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + ogs_nas_eps_activate_dedicated_eps_bearer_context_request_t + *activate_dedicated_eps_bearer_context_request = NULL; + + ogs_nas_linked_eps_bearer_identity_t *linked_eps_bearer_identity = NULL; + + ogs_assert(message); + + activate_dedicated_eps_bearer_context_request = + &message->esm.activate_dedicated_eps_bearer_context_request; + linked_eps_bearer_identity = + &activate_dedicated_eps_bearer_context_request->linked_eps_bearer_identity; + + bearer = test_bearer_find_by_ue_ebi( + test_ue, linked_eps_bearer_identity->eps_bearer_identity); + ogs_assert(bearer); + sess = bearer->sess; + ogs_assert(sess); + + bearer = test_bearer_find_by_sess_ebi( + sess, message->esm.h.eps_bearer_identity); + if (!bearer) + bearer = test_bearer_add(sess, message->esm.h.eps_bearer_identity); + ogs_assert(bearer); +} diff --git a/tests/common/test-ngap.h b/tests/common/esm-handler.h similarity index 71% rename from tests/common/test-ngap.h rename to tests/common/esm-handler.h index b942a96ae..8e1b9fccc 100644 --- a/tests/common/test-ngap.h +++ b/tests/common/esm-handler.h @@ -17,27 +17,20 @@ * along with this program. If not, see . */ -#ifndef TEST_NGAP_H -#define TEST_NGAP_H - -#include "ogs-ngap.h" +#ifndef TEST_ESM_HANDLE_H +#define TEST_ESM_HANDLE_H #ifdef __cplusplus extern "C" { #endif -#include "test-common.h" - -#define OGS_TEST_INSIDE - -#include "common/ngap-build.h" -#include "common/ngap-handler.h" -#include "common/ngap-path.h" - -#undef OGS_TEST_INSIDE +void testesm_handle_activate_default_eps_bearer_context_request( + test_ue_t *test_ue, ogs_nas_eps_message_t *message); +void testesm_handle_activate_dedicated_eps_bearer_context_request( + test_ue_t *test_ue, ogs_nas_eps_message_t *message); #ifdef __cplusplus } #endif -#endif /* TEST_NGAP_H */ +#endif /* TEST_ESM_HANDLE_H */ diff --git a/tests/common/gmm-build.c b/tests/common/gmm-build.c index b4dc1ccdf..d8818cce1 100644 --- a/tests/common/gmm-build.c +++ b/tests/common/gmm-build.c @@ -23,7 +23,6 @@ ogs_pkbuf_t *testgmm_build_registration_request( test_ue_t *test_ue, ogs_pkbuf_t *nasbuf) { int i; - test_sess_t *sess = NULL; uint16_t psimask = 0; ogs_s_nssai_t *s_nssai = NULL; @@ -59,8 +58,6 @@ ogs_pkbuf_t *testgmm_build_registration_request( ogs_nas_5gs_mobile_identity_guti_t mobile_identity_guti; ogs_assert(test_ue); - sess = test_ue->sess; - ogs_assert(sess); memset(&message, 0, sizeof(message)); if (test_ue->registration_request_param.integrity_protected) { @@ -81,7 +78,7 @@ ogs_pkbuf_t *testgmm_build_registration_request( if (test_ue->registration_request_param.guti) { ogs_nas_5gs_nas_guti_to_mobilty_identity_guti( - &test_ue->nas_guti, &mobile_identity_guti); + &test_ue->nas_5gs_guti, &mobile_identity_guti); registration_request->mobile_identity.length = sizeof(ogs_nas_5gs_mobile_identity_guti_t); registration_request->mobile_identity.buffer = @@ -169,8 +166,8 @@ ogs_pkbuf_t *testgmm_build_registration_request( registration_request->presencemask |= OGS_NAS_5GS_REGISTRATION_REQUEST_LAST_VISITED_REGISTERED_TAI_PRESENT; ogs_nas_from_plmn_id(&last_visited_registered_tai->nas_plmn_id, - &test_self()->tai.plmn_id); - last_visited_registered_tai->tac.v = test_self()->tai.tac.v; + &test_self()->nr_tai.plmn_id); + last_visited_registered_tai->tac.v = test_self()->nr_tai.tac.v; } if (test_ue->registration_request_param.ue_usage_setting) { @@ -267,7 +264,7 @@ ogs_pkbuf_t *testgmm_build_service_request( service_request->ngksi.tsc = test_ue->nas.tsc; service_request->ngksi.value = test_ue->nas.ksi; - ogs_assert(test_ue->nas_guti.m_tmsi); + ogs_assert(test_ue->nas_5gs_guti.m_tmsi); memset(&mobile_identity_s_tmsi, 0, sizeof(mobile_identity_s_tmsi)); /* @@ -286,10 +283,10 @@ ogs_pkbuf_t *testgmm_build_service_request( */ mobile_identity_s_tmsi.h.supi_format = 0xf; mobile_identity_s_tmsi.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_S_TMSI; - mobile_identity_s_tmsi.m_tmsi = htobe32(test_ue->nas_guti.m_tmsi); - mobile_identity_s_tmsi.set1 = test_ue->nas_guti.amf_id.set1; - mobile_identity_s_tmsi.set2 = test_ue->nas_guti.amf_id.set2; - mobile_identity_s_tmsi.pointer = test_ue->nas_guti.amf_id.pointer; + mobile_identity_s_tmsi.m_tmsi = htobe32(test_ue->nas_5gs_guti.m_tmsi); + mobile_identity_s_tmsi.set1 = test_ue->nas_5gs_guti.amf_id.set1; + mobile_identity_s_tmsi.set2 = test_ue->nas_5gs_guti.amf_id.set2; + mobile_identity_s_tmsi.pointer = test_ue->nas_5gs_guti.amf_id.pointer; service_request->s_tmsi.length = sizeof(mobile_identity_s_tmsi); service_request->s_tmsi.buffer = &mobile_identity_s_tmsi; @@ -365,9 +362,9 @@ ogs_pkbuf_t *testgmm_build_de_registration_request( de_registration_type->switch_off = switch_off; de_registration_type->access_type = test_ue->nas.access_type; - if (test_ue->nas_guti.m_tmsi) { + if (test_ue->nas_5gs_guti.m_tmsi) { ogs_nas_5gs_nas_guti_to_mobilty_identity_guti( - &test_ue->nas_guti, &mobile_identity_guti); + &test_ue->nas_5gs_guti, &mobile_identity_guti); deregistration_request_from_ue->mobile_identity.length = sizeof(ogs_nas_5gs_mobile_identity_guti_t); deregistration_request_from_ue->mobile_identity.buffer = @@ -436,7 +433,7 @@ ogs_pkbuf_t *testgmm_build_authentication_response(test_ue_t *test_ue) milenage_f2345(test_ue->opc, test_ue->k, test_ue->rand, res, ck, ik, ak, NULL); serving_network_name = - ogs_serving_network_name_from_plmn_id(&test_self()->tai.plmn_id); + ogs_serving_network_name_from_plmn_id(&test_self()->nr_tai.plmn_id); ogs_kdf_xres_star( ck, ik, serving_network_name, test_ue->rand, res, 8, diff --git a/tests/common/gmm-handler.c b/tests/common/gmm-handler.c index 4617c801f..d1b7f90a9 100644 --- a/tests/common/gmm-handler.c +++ b/tests/common/gmm-handler.c @@ -40,11 +40,11 @@ void testgmm_handle_registration_accept(test_ue_t *test_ue, mobile_identity = ®istration_accept->guti; mobile_identity_guti = mobile_identity->buffer; - memcpy(&test_ue->nas_guti.nas_plmn_id, + memcpy(&test_ue->nas_5gs_guti.nas_plmn_id, &mobile_identity_guti->nas_plmn_id, OGS_PLMN_ID_LEN); - memcpy(&test_ue->nas_guti.amf_id, + memcpy(&test_ue->nas_5gs_guti.amf_id, &mobile_identity_guti->amf_id, sizeof(ogs_amf_id_t)); - test_ue->nas_guti.m_tmsi = be32toh(mobile_identity_guti->m_tmsi); + test_ue->nas_5gs_guti.m_tmsi = be32toh(mobile_identity_guti->m_tmsi); } test_ue->pdu_session_status = 0; @@ -174,7 +174,7 @@ void testgmm_handle_dl_nas_transport(test_ue_t *test_ue, ogs_assert(test_ue); ogs_assert(dl_nas_transport); - sess = test_ue->sess; + sess = test_sess_find_by_psi(test_ue, dl_nas_transport->pdu_session_id); ogs_assert(sess); testgmm_send_to_gsm(sess, &dl_nas_transport->payload_container); diff --git a/tests/common/gsm-handler.c b/tests/common/gsm-handler.c index 7b1aac3c7..5f60ac3d9 100644 --- a/tests/common/gsm-handler.c +++ b/tests/common/gsm-handler.c @@ -38,10 +38,16 @@ void testgsm_handle_pdu_session_establishment_accept(test_sess_t *sess, sess->ue_ip.addr = pdu_address->addr; break; case OGS_PDU_SESSION_TYPE_IPV6: + sess->ue_ip.ipv6 = 1; + memcpy(sess->ue_ip.addr6, "\xca\xfe\x00\x00\x00\x00\x00\x00", 8); + memcpy(sess->ue_ip.addr6+8, pdu_address->addr6, 8); break; case OGS_PDU_SESSION_TYPE_IPV4V6: sess->ue_ip.ipv4 = 1; sess->ue_ip.addr = pdu_address->both.addr; + sess->ue_ip.ipv6 = 1; + memcpy(sess->ue_ip.addr6, "\xca\xfe\x00\x00\x00\x00\x00\x00", 8); + memcpy(sess->ue_ip.addr6+8, pdu_address->both.addr6, 8); break; default: ogs_fatal("Invalid PDU Address Type [%d]", pdu_address->pdn_type); diff --git a/tests/common/gtpu.c b/tests/common/gtpu.c index 755a4c694..9adfedd37 100644 --- a/tests/common/gtpu.c +++ b/tests/common/gtpu.c @@ -19,15 +19,25 @@ #include "test-common.h" -ogs_socknode_t *test_gtpu_server(const char *ipstr, int port) +ogs_socknode_t *test_gtpu_server(int index, int family) { int rv; ogs_sockaddr_t *addr = NULL; ogs_socknode_t *node = NULL; ogs_sock_t *sock = NULL; - rv = ogs_getaddrinfo(&addr, AF_UNSPEC, ipstr, port, 0); - ogs_assert(rv == OGS_OK); + if (index == 1) { + if (family == AF_INET6) + ogs_copyaddrinfo(&addr, test_self()->gnb1_addr6); + else + ogs_copyaddrinfo(&addr, test_self()->gnb1_addr); + } else if (index == 2) { + if (family == AF_INET6) + ogs_copyaddrinfo(&addr, test_self()->gnb2_addr6); + else + ogs_copyaddrinfo(&addr, test_self()->gnb2_addr); + } else + ogs_assert_if_reached(); node = ogs_socknode_new(addr); ogs_assert(node); @@ -63,56 +73,6 @@ ogs_pkbuf_t *test_gtpu_read(ogs_socknode_t *node) return recvbuf; } -int testgnb_gtpu_send(ogs_socknode_t *node, ogs_pkbuf_t *sendbuf) -{ - int rv; - - ogs_sockaddr_t upf; - ssize_t sent; - - ogs_assert(node); - ogs_assert(node->sock); - - memset(&upf, 0, sizeof(ogs_sockaddr_t)); - upf.ogs_sin_port = htons(OGS_GTPV1_U_UDP_PORT); - upf.ogs_sa_family = AF_INET; - upf.sin.sin_addr.s_addr = inet_addr("127.0.0.4"); - - sent = ogs_sendto(node->sock->fd, sendbuf->data, sendbuf->len, 0, &upf); - ogs_pkbuf_free(sendbuf); - if (sent < 0 || sent != sendbuf->len) - return OGS_ERROR; - - return OGS_OK; -} - -int testgnb_gtpu_sendto( - ogs_socknode_t *node, ogs_pkbuf_t *sendbuf, const char *ipstr) -{ - int rv; - - ogs_sockaddr_t *addr; - int port = OGS_GTPV1_U_UDP_PORT; - ssize_t sent; - - ogs_assert(node); - ogs_assert(node->sock); - ogs_assert(ipstr); - - rv = ogs_getaddrinfo(&addr, AF_UNSPEC, ipstr, port, 0); - ogs_assert(rv == OGS_OK); - - sent = ogs_sendto(node->sock->fd, sendbuf->data, sendbuf->len, 0, addr); - - ogs_pkbuf_free(sendbuf); - ogs_freeaddrinfo(addr); - - if (sent < 0 || sent != sendbuf->len) - return OGS_ERROR; - - return OGS_OK; -} - void test_gtpu_close(ogs_socknode_t *node) { ogs_socknode_free(node); @@ -136,41 +96,77 @@ void test_gtpu_close(ogs_socknode_t *node) #include #endif -int test_gtpu_build_ping(ogs_pkbuf_t **sendbuf, - test_sess_t *sess, const char *dst_ip) +int test_gtpu_send_ping( + ogs_socknode_t *node, test_bearer_t *bearer, const char *dst_ip) { int rv; + ssize_t sent; + + test_sess_t *sess = NULL; + ogs_sockaddr_t upf; + ogs_pkbuf_t *pkbuf = NULL; ogs_gtp_header_t *gtp_h = NULL; ogs_gtp_extension_header_t *ext_h = NULL; ogs_ipsubnet_t dst_ipsub; + ogs_assert(bearer); + sess = bearer->sess; ogs_assert(sess); ogs_assert(dst_ip); + rv = ogs_ipsubnet(&dst_ipsub, dst_ip, NULL); ogs_assert(rv == OGS_OK); - pkbuf = ogs_pkbuf_alloc(NULL, - 200 /* enough for ICMP; use smaller buffer */); + memset(&upf, 0, sizeof(ogs_sockaddr_t)); + upf.ogs_sin_port = htobe16(OGS_GTPV1_U_UDP_PORT); + + pkbuf = ogs_pkbuf_alloc( + NULL, 200 /* enough for ICMP; use smaller buffer */); ogs_pkbuf_put(pkbuf, 200); memset(pkbuf->data, 0, pkbuf->len); gtp_h = (ogs_gtp_header_t *)pkbuf->data; - if (sess->qfi) + if (bearer->qfi) { + /* 5G Core */ gtp_h->flags = 0x34; - else - gtp_h->flags = 0x30; - gtp_h->type = OGS_GTPU_MSGTYPE_GPDU; - gtp_h->teid = htobe32(sess->upf_n3_teid); + gtp_h->teid = htobe32(sess->upf_n3_teid); - if (sess->qfi) { + if (sess->upf_n3_ip.ipv4) { + upf.ogs_sa_family = AF_INET; + upf.sin.sin_addr.s_addr = sess->upf_n3_ip.addr; + } else { + ogs_fatal("Not implemented"); + ogs_assert_if_reached(); + } + + } else if (bearer->ebi) { + /* EPC */ + gtp_h->flags = 0x30; + gtp_h->teid = htobe32(bearer->sgw_s1u_teid); + + if (bearer->sgw_s1u_ip.ipv4) { + upf.ogs_sa_family = AF_INET; + upf.sin.sin_addr.s_addr = bearer->sgw_s1u_ip.addr; + } else { + ogs_fatal("Not implemented"); + ogs_assert_if_reached(); + } + } else { + ogs_fatal("No QFI[%d] and EBI[%d]", bearer->qfi, bearer->ebi); + ogs_assert_if_reached(); + } + + gtp_h->type = OGS_GTPU_MSGTYPE_GPDU; + + if (bearer->qfi) { ext_h = (ogs_gtp_extension_header_t *) (pkbuf->data + OGS_GTPV1U_HEADER_LEN); ext_h->type = OGS_GTP_EXTENSION_HEADER_TYPE_PDU_SESSION_CONTAINER; ext_h->len = 1; ext_h->pdu_type = OGS_GTP_EXTENSION_HEADER_PDU_TYPE_UL_PDU_SESSION_INFORMATION; - ext_h->qos_flow_identifier = sess->qfi; + ext_h->qos_flow_identifier = bearer->qfi; ext_h->next_type = OGS_GTP_EXTENSION_HEADER_TYPE_NO_MORE_EXTENSION_HEADERS; } @@ -179,7 +175,7 @@ int test_gtpu_build_ping(ogs_pkbuf_t **sendbuf, struct ip *ip_h = NULL; struct icmp *icmp_h = NULL; - if (sess->qfi) { + if (bearer->qfi) { gtp_h->length = htobe16( sizeof *ip_h + ICMP_MINLEN + OGS_GTPV1U_EXTENSION_HEADER_LEN + ext_h->len * 4); @@ -211,24 +207,31 @@ int test_gtpu_build_ping(ogs_pkbuf_t **sendbuf, icmp_h->icmp_seq = rand(); icmp_h->icmp_id = rand(); icmp_h->icmp_cksum = ogs_in_cksum((uint16_t *)icmp_h, ICMP_MINLEN); + } else if (dst_ipsub.family == AF_INET6) { -#if 0 struct ip6_hdr *ip6_h = NULL; struct icmp6_hdr *icmp6_h = NULL; uint16_t plen = 0; uint8_t nxt = 0; uint8_t *p = NULL; - gtp_h->length = htons(sizeof *ip6_h + sizeof *icmp6_h); - plen = htons(sizeof *icmp6_h); + if (bearer->qfi) { + gtp_h->length = htobe16(sizeof *ip6_h + sizeof *icmp6_h) + + OGS_GTPV1U_EXTENSION_HEADER_LEN + ext_h->len * 4; + p = (uint8_t *)pkbuf->data + OGS_GTPV1U_HEADER_LEN + + OGS_GTPV1U_EXTENSION_HEADER_LEN + ext_h->len * 4; + } else { + gtp_h->length = htobe16(sizeof *ip6_h + sizeof *icmp6_h); + p = (uint8_t *)pkbuf->data + OGS_GTPV1U_HEADER_LEN; + } + plen = htobe16(sizeof *icmp6_h); nxt = IPPROTO_ICMPV6; - p = (uint8_t *)pkbuf->data + OGS_5GS_GTP_HEADER_LEN; ip6_h = (struct ip6_hdr *)p; icmp6_h = (struct icmp6_hdr *)((uint8_t *)ip6_h + sizeof *ip6_h); - memcpy(p, src_ipsub.sub, sizeof src_ipsub.sub); - p += sizeof src_ipsub.sub; + memcpy(p, sess->ue_ip.addr6, sizeof sess->ue_ip.addr6); + p += sizeof sess->ue_ip.addr6; memcpy(p, dst_ipsub.sub, sizeof dst_ipsub.sub); p += sizeof dst_ipsub.sub; p += 2; memcpy(p, &plen, 2); p += 2; @@ -245,13 +248,124 @@ int test_gtpu_build_ping(ogs_pkbuf_t **sendbuf, ip6_h->ip6_plen = plen; ip6_h->ip6_nxt = nxt;; ip6_h->ip6_hlim = 0xff; - memcpy(ip6_h->ip6_src.s6_addr, src_ipsub.sub, sizeof src_ipsub.sub); + memcpy(ip6_h->ip6_src.s6_addr, + sess->ue_ip.addr6, sizeof sess->ue_ip.addr6); memcpy(ip6_h->ip6_dst.s6_addr, dst_ipsub.sub, sizeof dst_ipsub.sub); -#endif - } else + } else { + ogs_fatal("Invalid family[%d]", dst_ipsub.family); ogs_assert_if_reached(); + } - *sendbuf = pkbuf; + ogs_assert(node); + ogs_assert(node->sock); + + sent = ogs_sendto(node->sock->fd, pkbuf->data, pkbuf->len, 0, &upf); + ogs_pkbuf_free(pkbuf); + if (sent < 0 || sent != pkbuf->len) + return OGS_ERROR; + + return OGS_OK; +} + +int test_gtpu_send_slacc_rs(ogs_socknode_t *node, test_bearer_t *bearer) +{ + int rv; + ssize_t sent; + + test_sess_t *sess = NULL; + ogs_sockaddr_t upf; + + ogs_pkbuf_t *pkbuf = NULL; + ogs_gtp_header_t *gtp_h = NULL; + ogs_gtp_extension_header_t *ext_h = NULL; + + unsigned char *ip_h = NULL; + + const char *payload = + "6000000000083aff fe80000000000000 0000000000000002" + "ff02000000000000 0000000000000002 85007d3500000000"; + unsigned char tmp[OGS_MAX_SDU_LEN]; + + ogs_assert(bearer); + sess = bearer->sess; + ogs_assert(sess); + + memset(&upf, 0, sizeof(ogs_sockaddr_t)); + upf.ogs_sin_port = htobe16(OGS_GTPV1_U_UDP_PORT); + + pkbuf = ogs_pkbuf_alloc( + NULL, 200 /* enough for ICMP; use smaller buffer */); + ogs_pkbuf_put(pkbuf, 200); + memset(pkbuf->data, 0, pkbuf->len); + + gtp_h = (ogs_gtp_header_t *)pkbuf->data; + if (bearer->qfi) { + /* 5G Core */ + gtp_h->flags = 0x36; + gtp_h->teid = htobe32(sess->upf_n3_teid); + + if (sess->upf_n3_ip.ipv4) { + upf.ogs_sa_family = AF_INET; + upf.sin.sin_addr.s_addr = sess->upf_n3_ip.addr; + } else { + ogs_fatal("Not implemented"); + ogs_assert_if_reached(); + } + + } else if (bearer->ebi) { + /* EPC */ + gtp_h->flags = 0x32; + gtp_h->teid = htobe32(bearer->sgw_s1u_teid); + + if (bearer->sgw_s1u_ip.ipv4) { + upf.ogs_sa_family = AF_INET; + upf.sin.sin_addr.s_addr = bearer->sgw_s1u_ip.addr; + } else { + ogs_fatal("Not implemented"); + ogs_assert_if_reached(); + } + } else { + ogs_fatal("No QFI[%d] and EBI[%d]", bearer->qfi, bearer->ebi); + ogs_assert_if_reached(); + } + + gtp_h->type = OGS_GTPU_MSGTYPE_GPDU; + + if (bearer->qfi) { + ext_h = (ogs_gtp_extension_header_t *) + (pkbuf->data + OGS_GTPV1U_HEADER_LEN); + ext_h->type = OGS_GTP_EXTENSION_HEADER_TYPE_PDU_SESSION_CONTAINER; + ext_h->len = 1; + ext_h->pdu_type = + OGS_GTP_EXTENSION_HEADER_PDU_TYPE_UL_PDU_SESSION_INFORMATION; + ext_h->qos_flow_identifier = bearer->qfi; + ext_h->next_type = + OGS_GTP_EXTENSION_HEADER_TYPE_NO_MORE_EXTENSION_HEADERS; + } + + if (bearer->qfi) { + gtp_h->length = htobe16(52 + + OGS_GTPV1U_EXTENSION_HEADER_LEN + ext_h->len * 4); + + ip_h = (pkbuf->data + + OGS_GTPV1U_HEADER_LEN + 4 + + OGS_GTPV1U_EXTENSION_HEADER_LEN + ext_h->len * 4); + } else { + gtp_h->length = htobe16(52); + + ip_h = (pkbuf->data + OGS_GTPV1U_HEADER_LEN + 4); + } + + ogs_assert(node); + ogs_assert(node->sock); + + OGS_HEX(payload, strlen(payload), tmp); + memcpy(ip_h, tmp, 48); + + sent = ogs_sendto(node->sock->fd, pkbuf->data, pkbuf->len, 0, &upf); + ogs_pkbuf_free(pkbuf); + if (sent < 0 || sent != pkbuf->len) + return OGS_ERROR; return OGS_OK; } diff --git a/tests/common/gtpu.h b/tests/common/gtpu.h index 15785d880..bf11da6af 100644 --- a/tests/common/gtpu.h +++ b/tests/common/gtpu.h @@ -24,19 +24,16 @@ extern "C" { #endif -#define testgnb_gtpu_server(x) test_gtpu_server(x, OGS_GTPV1_U_UDP_PORT) #define testgnb_gtpu_read(x) test_gtpu_read(x) #define testgnb_gtpu_close(x) test_gtpu_close(x) -ogs_socknode_t *test_gtpu_server(const char *ipstr, int port); +ogs_socknode_t *test_gtpu_server(int index, int family); ogs_pkbuf_t *test_gtpu_read(ogs_socknode_t *node); -int testgnb_gtpu_send(ogs_socknode_t *node, ogs_pkbuf_t *sendbuf); -int testgnb_gtpu_sendto( - ogs_socknode_t *node, ogs_pkbuf_t *sendbuf, const char *ipstr); void test_gtpu_close(ogs_socknode_t *node); -int test_gtpu_build_ping(ogs_pkbuf_t **sendbuf, - test_sess_t *sess, const char *dst_ip); +int test_gtpu_send_ping( + ogs_socknode_t *node, test_bearer_t *bearer, const char *dst_ip); +int test_gtpu_send_slacc_rs(ogs_socknode_t *node, test_bearer_t *bearer); #ifdef __cplusplus } diff --git a/tests/common/meson.build b/tests/common/meson.build index 417e06d4a..4392182ef 100644 --- a/tests/common/meson.build +++ b/tests/common/meson.build @@ -34,9 +34,21 @@ libtestcommon_sources = files(''' gmm-handler.c gsm-build.c gsm-handler.c + + s1ap-build.c + s1ap-handler.c + s1ap-path.c + + emm-build.c + emm-handler.c + esm-build.c + esm-handler.c + nas-path.c nas-encoder.c nas-security.c + + sgsap-build.c '''.split()) libtestcommon_inc = include_directories('.') @@ -50,6 +62,7 @@ libtestcommon = static_library('testcomon', libdbi_dep, libsctp_dep, libgtp_dep, + libs1ap_dep, libngap_dep, libnas_eps_dep, libnas_5gs_dep, @@ -64,6 +77,7 @@ libtestcommon_dep = declare_dependency( libdbi_dep, libsctp_dep, libgtp_dep, + libs1ap_dep, libngap_dep, libnas_eps_dep, libnas_5gs_dep, diff --git a/tests/common/nas-encoder.c b/tests/common/nas-encoder.c index 7017d64a8..9f91d90f0 100644 --- a/tests/common/nas-encoder.c +++ b/tests/common/nas-encoder.c @@ -30,7 +30,7 @@ ogs_pkbuf_t *test_nas_5gmm_encode(ogs_nas_5gs_message_t *message) ogs_assert(message); - /* The Packet Buffer(ogs_pkbuf_t) for NAS message MUST make a HEADROOM. + /* The Packet Buffer(ogs_pkbuf_t) for NAS message MUST make a HEADROOM. * When calculating AES_CMAC, we need to use the headroom of the packet. */ pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); ogs_assert(pkbuf); @@ -51,7 +51,7 @@ ogs_pkbuf_t *test_nas_5gmm_encode(ogs_nas_5gs_message_t *message) encoded += size; break; default: - ogs_error("Unknown message type (0x%x) or not implemented", + ogs_error("Unknown message type (0x%x) or not implemented", message->gmm.h.message_type); ogs_pkbuf_free(pkbuf); return NULL; @@ -71,12 +71,73 @@ ogs_pkbuf_t *test_nas_5gs_plain_encode(ogs_nas_5gs_message_t *message) ogs_assert(message->gmm.h.extended_protocol_discriminator == message->gsm.h.extended_protocol_discriminator); - if (message->gmm.h.extended_protocol_discriminator == + if (message->gmm.h.extended_protocol_discriminator == OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM) return test_nas_5gmm_encode(message); - ogs_error("Unknown discriminator [%d]", + ogs_error("Unknown discriminator [%d]", message->gmm.h.extended_protocol_discriminator); return NULL; } + +int ogs_nas_eps_encode_detach_request_from_ue( + ogs_pkbuf_t *pkbuf, ogs_nas_eps_message_t *message); + +ogs_pkbuf_t *test_nas_emm_encode(ogs_nas_eps_message_t *message) +{ + ogs_pkbuf_t *pkbuf = NULL; + int size = 0; + int encoded = 0; + + ogs_assert(message); + + /* The Packet Buffer(ogs_pkbuf_t) for NAS message MUST make a HEADROOM. + * When calculating AES_CMAC, we need to use the headroom of the packet. */ + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_assert(pkbuf); + ogs_pkbuf_reserve(pkbuf, OGS_NAS_HEADROOM); + ogs_pkbuf_put(pkbuf, OGS_MAX_SDU_LEN-OGS_NAS_HEADROOM); + + size = sizeof(ogs_nas_emm_header_t); + ogs_assert(ogs_pkbuf_pull(pkbuf, size)); + + memcpy(pkbuf->data - size, &message->emm.h, size); + encoded += size; + + switch(message->emm.h.message_type) { + case OGS_NAS_EPS_DETACH_REQUEST: + size = ogs_nas_eps_encode_detach_request_from_ue(pkbuf, message); + ogs_assert(size >= 0); + encoded += size; + break; + default: + ogs_error("Unknown message type (0x%x) or not implemented", + message->emm.h.message_type); + ogs_pkbuf_free(pkbuf); + return NULL; + } + + ogs_assert(ogs_pkbuf_push(pkbuf, encoded)); + + pkbuf->len = encoded; + + return pkbuf; +} + +ogs_pkbuf_t *test_nas_eps_plain_encode(ogs_nas_eps_message_t *message) +{ + ogs_assert(message); + + ogs_assert(message->emm.h.protocol_discriminator == + message->emm.h.protocol_discriminator); + + if (message->emm.h.protocol_discriminator == + OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM) + return test_nas_emm_encode(message); + + ogs_error("Unknown discriminator [%d]", + message->emm.h.protocol_discriminator); + + return NULL; +} diff --git a/tests/common/nas-encoder.h b/tests/common/nas-encoder.h index 9852f49f3..f8b8a84b1 100644 --- a/tests/common/nas-encoder.h +++ b/tests/common/nas-encoder.h @@ -27,6 +27,9 @@ extern "C" { ogs_pkbuf_t *test_nas_5gmm_encode(ogs_nas_5gs_message_t *message); ogs_pkbuf_t *test_nas_5gs_plain_encode(ogs_nas_5gs_message_t *message); +ogs_pkbuf_t *test_nas_emm_encode(ogs_nas_eps_message_t *message); +ogs_pkbuf_t *test_nas_eps_plain_encode(ogs_nas_eps_message_t *message); + #ifdef __cplusplus } #endif diff --git a/tests/common/nas-path.c b/tests/common/nas-path.c index 8af75b86e..151151ad2 100644 --- a/tests/common/nas-path.c +++ b/tests/common/nas-path.c @@ -110,3 +110,107 @@ void testgmm_send_to_gsm(test_sess_t *sess, testgsm_recv(sess, gsmbuf); } + +void testemm_recv(test_ue_t *test_ue, ogs_pkbuf_t *pkbuf) +{ + int rv; + ogs_nas_eps_message_t message; + + ogs_assert(test_ue); + ogs_assert(pkbuf); + + rv = ogs_nas_emm_decode(&message, pkbuf); + ogs_assert(rv == OGS_OK); + + test_ue->emm_message_type = message.emm.h.message_type; + switch (message.emm.h.message_type) { + case OGS_NAS_EPS_IDENTITY_REQUEST: + testemm_handle_identity_request(test_ue, &message.emm.identity_request); + break; + case OGS_NAS_EPS_AUTHENTICATION_REQUEST: + testemm_handle_authentication_request(test_ue, + &message.emm.authentication_request); + break; + case OGS_NAS_EPS_AUTHENTICATION_REJECT: + break; + case OGS_NAS_EPS_SECURITY_MODE_COMMAND: + break; + case OGS_NAS_EPS_ATTACH_ACCEPT: + testemm_handle_attach_accept(test_ue, &message.emm.attach_accept); + break; + case OGS_NAS_EPS_ATTACH_REJECT: + break; + case OGS_NAS_EPS_SERVICE_REJECT: + break; + case OGS_NAS_EPS_TRACKING_AREA_UPDATE_ACCEPT: + break; + case OGS_NAS_EPS_EMM_INFORMATION: + break; + case OGS_NAS_EPS_CS_SERVICE_NOTIFICATION: + break; + case OGS_NAS_EPS_DOWNLINK_NAS_TRANSPORT: + break; + default: + ogs_error("Unknown message[%d]", message.emm.h.message_type); + break; + } + + ogs_pkbuf_free(pkbuf); +} + +void testesm_recv(test_ue_t *test_ue, ogs_pkbuf_t *pkbuf) +{ + int rv; + test_bearer_t *bearer = NULL; + ogs_nas_eps_message_t message; + + ogs_assert(test_ue); + ogs_assert(pkbuf); + + rv = ogs_nas_esm_decode(&message, pkbuf); + ogs_assert(rv == OGS_OK); + + switch (message.esm.h.message_type) { + case OGS_NAS_EPS_ESM_INFORMATION_REQUEST: + break; + case OGS_NAS_EPS_PDN_CONNECTIVITY_REJECT: + break; + case OGS_NAS_EPS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST: + testesm_handle_activate_default_eps_bearer_context_request( + test_ue, &message); + break; + case OGS_NAS_EPS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST: + testesm_handle_activate_dedicated_eps_bearer_context_request( + test_ue, &message); + break; + case OGS_NAS_EPS_MODIFY_EPS_BEARER_CONTEXT_REQUEST: + break; + case OGS_NAS_EPS_DEACTIVATE_EPS_BEARER_CONTEXT_REQUEST: + break; + case OGS_NAS_EPS_BEARER_RESOURCE_ALLOCATION_REJECT: + break; + case OGS_NAS_EPS_BEARER_RESOURCE_MODIFICATION_REJECT: + break; + default: + ogs_error("Unknown message[%d]", message.esm.h.message_type); + break; + } + + ogs_pkbuf_free(pkbuf); +} + +void testemm_send_to_esm(test_ue_t *test_ue, + ogs_nas_esm_message_container_t *esm_message_container) +{ + ogs_pkbuf_t *esmbuf = NULL; + + ogs_assert(test_ue); + ogs_assert(esm_message_container); + ogs_assert(esm_message_container->buffer); + + esmbuf = ogs_pkbuf_alloc(NULL, esm_message_container->length); + ogs_pkbuf_put_data(esmbuf, + esm_message_container->buffer, esm_message_container->length); + + testesm_recv(test_ue, esmbuf); +} diff --git a/tests/common/nas-path.h b/tests/common/nas-path.h index 165e67482..8b40e8df7 100644 --- a/tests/common/nas-path.h +++ b/tests/common/nas-path.h @@ -30,6 +30,12 @@ void testgsm_recv(test_sess_t *sess, ogs_pkbuf_t *pkbuf); void testgmm_send_to_gsm(test_sess_t *sess, ogs_nas_payload_container_t *payload_container); +void testemm_recv(test_ue_t *test_ue, ogs_pkbuf_t *pkbuf); +void testesm_recv(test_ue_t *test_ue, ogs_pkbuf_t *pkbuf); + +void testemm_send_to_esm(test_ue_t *test_ue, + ogs_nas_esm_message_container_t *esm_message_container); + #ifdef __cplusplus } #endif diff --git a/tests/common/nas-security.c b/tests/common/nas-security.c index eab152528..3e0bc3f0a 100644 --- a/tests/common/nas-security.c +++ b/tests/common/nas-security.c @@ -19,6 +19,7 @@ #include "test-common.h" +#define NAS_SECURITY_BEARER 0 #define NAS_SECURITY_DOWNLINK_DIRECTION 1 #define NAS_SECURITY_UPLINK_DIRECTION 0 @@ -56,7 +57,7 @@ ogs_pkbuf_t *test_nas_5gs_security_encode( ciphered = 1; break; default: - ogs_error("Not implemented(securiry header type:0x%x)", + ogs_error("Not implemented(securiry header type:0x%x)", message->h.security_header_type); return NULL; } @@ -119,7 +120,7 @@ ogs_pkbuf_t *test_nas_5gs_security_encode( return new; } -int test_nas_5gs_security_decode(test_ue_t *test_ue, +int test_nas_5gs_security_decode(test_ue_t *test_ue, ogs_nas_security_header_type_t security_header_type, ogs_pkbuf_t *pkbuf) { ogs_assert(test_ue); @@ -141,7 +142,7 @@ int test_nas_5gs_security_decode(test_ue_t *test_ue, if (test_ue->selected_int_algorithm == 0) security_header_type.integrity_protected = 0; - if (security_header_type.ciphered || + if (security_header_type.ciphered || security_header_type.integrity_protected) { ogs_nas_5gs_security_header_t *h = NULL; @@ -191,3 +192,169 @@ int test_nas_5gs_security_decode(test_ue_t *test_ue, return OGS_OK; } + +ogs_pkbuf_t *test_nas_eps_security_encode( + test_ue_t *test_ue, ogs_nas_eps_message_t *message) +{ + int integrity_protected = 0; + int new_security_context = 0; + int ciphered = 0; + ogs_nas_eps_security_header_t h; + ogs_pkbuf_t *new = NULL; + + ogs_assert(test_ue); + ogs_assert(message); + + switch (message->h.security_header_type) { + case OGS_NAS_SECURITY_HEADER_PLAIN_NAS_MESSAGE: + return ogs_nas_eps_plain_encode(message); + case OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED: + integrity_protected = 1; + break; + case OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED: + integrity_protected = 1; + ciphered = 1; + break; + case OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_NEW_SECURITY_CONTEXT: + integrity_protected = 1; + new_security_context = 1; + break; + case OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHTERD_WITH_NEW_INTEGRITY_CONTEXT: + integrity_protected = 1; + new_security_context = 1; + ciphered = 1; + break; + default: + ogs_error("Not implemented(securiry header type:0x%x)", + message->h.security_header_type); + return NULL; + } + + if (new_security_context) { + test_ue->ul_count = 0; + test_ue->dl_count.i32 = 0; + } + + if (test_ue->selected_enc_algorithm == 0) + ciphered = 0; + if (test_ue->selected_int_algorithm == 0) + integrity_protected = 0; + + memset(&h, 0, sizeof(h)); + h.security_header_type = message->h.security_header_type; + h.protocol_discriminator = message->h.protocol_discriminator; + h.sequence_number = (test_ue->ul_count & 0xff); + + if (message->emm.h.message_type == OGS_NAS_EPS_DETACH_REQUEST) + new = test_nas_eps_plain_encode(message); + else + new = ogs_nas_eps_plain_encode(message); + if (!new) { + ogs_error("ogs_nas_eps_plain_encode() failed"); + return NULL; + } + + if (ciphered) { + /* encrypt NAS message */ + ogs_nas_encrypt(test_ue->selected_enc_algorithm, + test_ue->knas_enc, test_ue->ul_count, + test_ue->nas.access_type, + NAS_SECURITY_UPLINK_DIRECTION, new); + } + + /* encode sequence number */ + ogs_assert(ogs_pkbuf_push(new, 1)); + *(uint8_t *)(new->data) = h.sequence_number; + + if (integrity_protected) { + uint8_t mac[NAS_SECURITY_MAC_SIZE]; + + /* calculate NAS MAC(message authentication code) */ + ogs_nas_mac_calculate(test_ue->selected_int_algorithm, + test_ue->knas_int, test_ue->ul_count, + NAS_SECURITY_BEARER, NAS_SECURITY_UPLINK_DIRECTION, new, mac); + memcpy(&h.message_authentication_code, mac, sizeof(mac)); + } + + /* increase ul_count */ + test_ue->ul_count = (test_ue->ul_count + 1) & 0xffffff; /* Use 24bit */ + + /* encode all security header */ + ogs_assert(ogs_pkbuf_push(new, 5)); + memcpy(new->data, &h, sizeof(ogs_nas_eps_security_header_t)); + + return new; +} + +int test_nas_eps_security_decode(test_ue_t *test_ue, + ogs_nas_security_header_type_t security_header_type, ogs_pkbuf_t *pkbuf) +{ + ogs_assert(test_ue); + ogs_assert(pkbuf); + ogs_assert(pkbuf->data); + + if (!test_ue->security_context_available) { + security_header_type.integrity_protected = 0; + security_header_type.new_security_context = 0; + security_header_type.ciphered = 0; + } + + if (security_header_type.new_security_context) { + test_ue->dl_count.i32 = 0; + } + + if (test_ue->selected_enc_algorithm == 0) + security_header_type.ciphered = 0; + if (test_ue->selected_int_algorithm == 0) + security_header_type.integrity_protected = 0; + + if (security_header_type.ciphered || + security_header_type.integrity_protected) { + ogs_nas_eps_security_header_t *h = NULL; + + /* NAS Security Header */ + ogs_assert(ogs_pkbuf_push(pkbuf, 6)); + h = (ogs_nas_eps_security_header_t *)pkbuf->data; + + /* NAS Security Header.Sequence_Number */ + ogs_assert(ogs_pkbuf_pull(pkbuf, 5)); + + /* calculate dl_count */ + if (test_ue->dl_count.sqn > h->sequence_number) + test_ue->dl_count.overflow++; + test_ue->dl_count.sqn = h->sequence_number; + + if (security_header_type.integrity_protected) { + uint8_t mac[NAS_SECURITY_MAC_SIZE]; + uint32_t mac32; + uint32_t original_mac = h->message_authentication_code; + + /* calculate NAS MAC(message authentication code) */ + ogs_nas_mac_calculate(test_ue->selected_int_algorithm, + test_ue->knas_int, test_ue->dl_count.i32, + NAS_SECURITY_BEARER, + NAS_SECURITY_DOWNLINK_DIRECTION, pkbuf, mac); + h->message_authentication_code = original_mac; + + memcpy(&mac32, mac, NAS_SECURITY_MAC_SIZE); + if (h->message_authentication_code != mac32) { + ogs_error("NAS MAC verification failed(0x%x != 0x%x)", + ntohl(h->message_authentication_code), ntohl(mac32)); + test_ue->mac_failed = 1; + } + } + + /* NAS EMM Header or ESM Header */ + ogs_assert(ogs_pkbuf_pull(pkbuf, 1)); + + if (security_header_type.ciphered) { + /* decrypt NAS message */ + ogs_nas_encrypt(test_ue->selected_enc_algorithm, + test_ue->knas_enc, test_ue->dl_count.i32, + test_ue->nas.access_type, + NAS_SECURITY_DOWNLINK_DIRECTION, pkbuf); + } + } + + return OGS_OK; +} diff --git a/tests/common/nas-security.h b/tests/common/nas-security.h index e378f1d11..9342b5847 100644 --- a/tests/common/nas-security.h +++ b/tests/common/nas-security.h @@ -26,7 +26,12 @@ extern "C" { ogs_pkbuf_t *test_nas_5gs_security_encode( test_ue_t *test_ue, ogs_nas_5gs_message_t *message); -int test_nas_5gs_security_decode(test_ue_t *test_ue, +int test_nas_5gs_security_decode(test_ue_t *test_ue, + ogs_nas_security_header_type_t security_header_type, ogs_pkbuf_t *pkbuf); + +ogs_pkbuf_t *test_nas_eps_security_encode( + test_ue_t *test_ue, ogs_nas_eps_message_t *message); +int test_nas_eps_security_decode(test_ue_t *test_ue, ogs_nas_security_header_type_t security_header_type, ogs_pkbuf_t *pkbuf); #ifdef __cplusplus diff --git a/tests/common/ngap-build.c b/tests/common/ngap-build.c index 2acf73baf..79b4e78ce 100644 --- a/tests/common/ngap-build.c +++ b/tests/common/ngap-build.c @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -#include "test-ngap.h" +#include "test-common.h" static ogs_pkbuf_t *testngap_build_pdu_session_resource_setup_response_trasfer( - test_sess_t *sess); + test_bearer_t *qos_flow); ogs_pkbuf_t *testngap_build_ng_setup_request(uint32_t gnb_id, uint8_t bitsize) { @@ -108,13 +108,13 @@ ogs_pkbuf_t *testngap_build_ng_setup_request(uint32_t gnb_id, uint8_t bitsize) strlen(ran_node_name), RANNodeName); SupportedTAItem = CALLOC(1, sizeof(NGAP_SupportedTAItem_t)); - if (test_self()->served_tai[0].list2.num) + if (test_self()->nr_served_tai[0].list2.num) ogs_asn_uint24_to_OCTET_STRING( - test_self()->served_tai[0].list2.tai[0].tac, + test_self()->nr_served_tai[0].list2.tai[0].tac, &SupportedTAItem->tAC); - else if (test_self()->served_tai[0].list0.tai[0].num) + else if (test_self()->nr_served_tai[0].list0.tai[0].num) ogs_asn_uint24_to_OCTET_STRING( - test_self()->served_tai[0].list0.tai[0].tac[0], + test_self()->nr_served_tai[0].list0.tai[0].tac[0], &SupportedTAItem->tAC); else ogs_assert_if_reached(); @@ -152,7 +152,7 @@ ogs_pkbuf_t *testngap_build_ng_setup_request(uint32_t gnb_id, uint8_t bitsize) *PagingDRX = NGAP_PagingDRX_v32; - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *testngap_build_initial_ue_message( @@ -245,7 +245,7 @@ ogs_pkbuf_t *testngap_build_initial_ue_message( ogs_ngap_nr_cgi_to_ASN(&test_self()->nr_cgi, nR_CGI); tAI = &userLocationInformationNR->tAI; - ogs_ngap_5gs_tai_to_ASN(&test_self()->tai, tAI); + ogs_ngap_5gs_tai_to_ASN(&test_self()->nr_tai, tAI); UserLocationInformation->present = NGAP_UserLocationInformation_PR_userLocationInformationNR; @@ -274,10 +274,11 @@ ogs_pkbuf_t *testngap_build_initial_ue_message( fiveG_TMSI = &FiveG_S_TMSI->fiveG_TMSI; ogs_ngap_uint16_to_AMFSetID( - ogs_amf_set_id(&test_ue->nas_guti.amf_id), aMFSetID); + ogs_amf_set_id(&test_ue->nas_5gs_guti.amf_id), aMFSetID); ogs_ngap_uint8_to_AMFPointer( - ogs_amf_pointer(&test_ue->nas_guti.amf_id), aMFPointer); - ogs_asn_uint32_to_OCTET_STRING(test_ue->nas_guti.m_tmsi, fiveG_TMSI); + ogs_amf_pointer(&test_ue->nas_5gs_guti.amf_id), aMFPointer); + ogs_asn_uint32_to_OCTET_STRING( + test_ue->nas_5gs_guti.m_tmsi, fiveG_TMSI); } ie = CALLOC(1, sizeof(NGAP_InitialUEMessage_IEs_t)); @@ -292,7 +293,7 @@ ogs_pkbuf_t *testngap_build_initial_ue_message( *UEContextRequest = NGAP_UEContextRequest_requested; - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *testngap_build_uplink_nas_transport( @@ -381,14 +382,14 @@ ogs_pkbuf_t *testngap_build_uplink_nas_transport( ogs_ngap_nr_cgi_to_ASN(&test_self()->nr_cgi, nR_CGI); tAI = &userLocationInformationNR->tAI; - ogs_ngap_5gs_tai_to_ASN(&test_self()->tai, tAI); + ogs_ngap_5gs_tai_to_ASN(&test_self()->nr_tai, tAI); UserLocationInformation->present = NGAP_UserLocationInformation_PR_userLocationInformationNR; UserLocationInformation->choice.userLocationInformationNR = userLocationInformationNR; - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *testngap_build_initial_context_setup_response( @@ -447,6 +448,8 @@ ogs_pkbuf_t *testngap_build_initial_context_setup_response( OCTET_STRING_t *transfer = NULL; ogs_pkbuf_t *n2smbuf = NULL; + test_bearer_t *bearer = NULL; + ie = CALLOC(1, sizeof(NGAP_InitialContextSetupResponseIEs_t)); ASN_SEQUENCE_ADD(&InitialContextSetupResponse->protocolIEs, ie); @@ -462,8 +465,11 @@ ogs_pkbuf_t *testngap_build_initial_context_setup_response( PDUSessionItem->pDUSessionID = sess->psi; + bearer = ogs_list_first(&sess->bearer_list); + ogs_assert(bearer); + n2smbuf = testngap_build_pdu_session_resource_setup_response_trasfer( - sess); + bearer); ogs_assert(n2smbuf); transfer = &PDUSessionItem->pDUSessionResourceSetupResponseTransfer; @@ -473,7 +479,7 @@ ogs_pkbuf_t *testngap_build_initial_context_setup_response( ogs_pkbuf_free(n2smbuf); } - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *testngap_build_initial_context_setup_failure(test_ue_t *test_ue, @@ -530,8 +536,7 @@ ogs_pkbuf_t *testngap_build_initial_context_setup_failure(test_ue_t *test_ue, ie->id = NGAP_ProtocolIE_ID_id_Cause; ie->criticality = NGAP_Criticality_ignore; - ie->value.present = - NGAP_InitialContextSetupFailureIEs__value_PR_Cause; + ie->value.present = NGAP_InitialContextSetupFailureIEs__value_PR_Cause; Cause = &ie->value.choice.Cause; @@ -541,7 +546,7 @@ ogs_pkbuf_t *testngap_build_initial_context_setup_failure(test_ue_t *test_ue, Cause->present = group; Cause->choice.radioNetwork = cause; - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *testngap_build_ue_radio_capability_info_indication( @@ -629,7 +634,7 @@ ogs_pkbuf_t *testngap_build_ue_radio_capability_info_indication( UERadioCapability->buf = CALLOC(UERadioCapability->size, sizeof(uint8_t)); memcpy(UERadioCapability->buf, tmp, UERadioCapability->size); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *testngap_build_ue_context_release_request(test_ue_t *test_ue, @@ -700,7 +705,7 @@ ogs_pkbuf_t *testngap_build_ue_context_release_request(test_ue_t *test_ue, CALLOC(1, sizeof(struct NGAP_PDUSessionResourceItemCxtRelReq)); ASN_SEQUENCE_ADD(&PDUSessionList->list, PDUSessionItem); - sess = test_ue->sess; + sess = ogs_list_first(&test_ue->sess_list); ogs_assert(sess); PDUSessionItem->pDUSessionID = sess->psi; @@ -718,7 +723,7 @@ ogs_pkbuf_t *testngap_build_ue_context_release_request(test_ue_t *test_ue, Cause->present = group; Cause->choice.radioNetwork = cause; - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *testngap_build_ue_context_release_complete(test_ue_t *test_ue) @@ -770,14 +775,17 @@ ogs_pkbuf_t *testngap_build_ue_context_release_complete(test_ue_t *test_ue) asn_uint642INTEGER(AMF_UE_NGAP_ID, test_ue->amf_ue_ngap_id); *RAN_UE_NGAP_ID = test_ue->ran_ue_ngap_id; - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *testngap_build_pdu_session_resource_setup_response( test_sess_t *sess) { int rv; - test_ue_t *test_ue; + + test_ue_t *test_ue = NULL; + test_bearer_t *qos_flow = NULL; + ogs_pkbuf_t *n2smbuf = NULL; ogs_pkbuf_t *ngapbuf = NULL; @@ -848,7 +856,11 @@ ogs_pkbuf_t *testngap_build_pdu_session_resource_setup_response( PDUSessionItem->pDUSessionID = sess->psi; - n2smbuf = testngap_build_pdu_session_resource_setup_response_trasfer(sess); + qos_flow = ogs_list_first(&sess->bearer_list); + ogs_assert(qos_flow); + + n2smbuf = testngap_build_pdu_session_resource_setup_response_trasfer( + qos_flow); ogs_assert(n2smbuf); transfer = &PDUSessionItem->pDUSessionResourceSetupResponseTransfer; @@ -857,7 +869,7 @@ ogs_pkbuf_t *testngap_build_pdu_session_resource_setup_response( memcpy(transfer->buf, n2smbuf->data, transfer->size); ogs_pkbuf_free(n2smbuf); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } ogs_pkbuf_t *testngap_build_pdu_session_resource_release_response( @@ -939,13 +951,23 @@ ogs_pkbuf_t *testngap_build_pdu_session_resource_release_response( transfer->size = 1; transfer->buf = CALLOC(transfer->size, sizeof(uint8_t)); - return nga_ngap_encode(&pdu); + return ogs_ngap_encode(&pdu); } static ogs_pkbuf_t *testngap_build_pdu_session_resource_setup_response_trasfer( - test_sess_t *sess) + test_bearer_t *qos_flow) { - ogs_ip_t gnb_n3_ip; + int rv; + + test_sess_t *sess = NULL; + + ogs_gtp_f_teid_t f_teid; + ogs_ip_t ip; + int len; + + ogs_assert(qos_flow); + sess = qos_flow->sess; + ogs_assert(sess); NGAP_PDUSessionResourceSetupResponseTransfer_t message; @@ -968,8 +990,15 @@ static ogs_pkbuf_t *testngap_build_pdu_session_resource_setup_response_trasfer( NGAP_UPTransportLayerInformation_PR_gTPTunnel; uPTransportLayerInformation->choice.gTPTunnel = gTPTunnel; - ogs_asn_ip_to_BIT_STRING(&sess->gnb_n3_ip, - &gTPTunnel->transportLayerAddress); + ogs_assert(sess->gnb_n3_addr || sess->gnb_n3_addr6); + rv = ogs_gtp_sockaddr_to_f_teid( + sess->gnb_n3_addr, sess->gnb_n3_addr6, &f_teid, &len); + ogs_assert(rv == OGS_OK); + + rv = ogs_gtp_f_teid_to_ip(&f_teid, &ip); + ogs_assert(rv == OGS_OK); + + ogs_asn_ip_to_BIT_STRING(&ip, &gTPTunnel->transportLayerAddress); ogs_asn_uint32_to_OCTET_STRING(sess->gnb_n3_teid, &gTPTunnel->gTP_TEID); associatedQosFlowList = &dLQosFlowPerTNLInformation->associatedQosFlowList; @@ -977,7 +1006,7 @@ static ogs_pkbuf_t *testngap_build_pdu_session_resource_setup_response_trasfer( CALLOC(1, sizeof(struct NGAP_AssociatedQosFlowItem)); ASN_SEQUENCE_ADD(&associatedQosFlowList->list, associatedQosFlowItem); - associatedQosFlowItem->qosFlowIdentifier = sess->qfi; + associatedQosFlowItem->qosFlowIdentifier = qos_flow->qfi; return ogs_asn_encode( &asn_DEF_NGAP_PDUSessionResourceSetupResponseTransfer, &message); diff --git a/tests/common/ngap-handler.c b/tests/common/ngap-handler.c index b8c23bdde..6097ddfd1 100644 --- a/tests/common/ngap-handler.c +++ b/tests/common/ngap-handler.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-ngap.h" +#include "test-common.h" void testngap_handle_ng_setup_response( test_ue_t *test_ue, ogs_ngap_message_t *message) @@ -72,9 +72,9 @@ void testngap_handle_downlink_nas_transport( NGAP_NGAP_PDU_t pdu; NGAP_InitiatingMessage_t *initiatingMessage = NULL; - NGAP_InitialContextSetupRequest_t *InitialContextSetupRequest = NULL; + NGAP_DownlinkNASTransport_t *DownlinkNASTransport = NULL; - NGAP_InitialContextSetupRequestIEs_t *ie = NULL; + NGAP_DownlinkNASTransport_IEs_t *ie = NULL; NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; NGAP_NAS_PDU_t *NAS_PDU = NULL; @@ -83,12 +83,12 @@ void testngap_handle_downlink_nas_transport( initiatingMessage = message->choice.initiatingMessage; ogs_assert(initiatingMessage); - InitialContextSetupRequest = - &initiatingMessage->value.choice.InitialContextSetupRequest; - ogs_assert(InitialContextSetupRequest); + DownlinkNASTransport = + &initiatingMessage->value.choice.DownlinkNASTransport; + ogs_assert(DownlinkNASTransport); - for (i = 0; i < InitialContextSetupRequest->protocolIEs.list.count; i++) { - ie = InitialContextSetupRequest->protocolIEs.list.array[i]; + for (i = 0; i < DownlinkNASTransport->protocolIEs.list.count; i++) { + ie = DownlinkNASTransport->protocolIEs.list.array[i]; switch (ie->id) { case NGAP_ProtocolIE_ID_id_AMF_UE_NGAP_ID: AMF_UE_NGAP_ID = &ie->value.choice.AMF_UE_NGAP_ID; @@ -101,6 +101,7 @@ void testngap_handle_downlink_nas_transport( } } + ogs_assert(AMF_UE_NGAP_ID); asn_INTEGER2ulong(AMF_UE_NGAP_ID, &test_ue->amf_ue_ngap_id); if (NAS_PDU) @@ -154,10 +155,55 @@ void testngap_handle_initial_context_setup_request( testngap_send_to_nas(test_ue, NAS_PDU); } +void testngap_handle_ue_release_context_command( + test_ue_t *test_ue, ogs_ngap_message_t *message) +{ + int i, rv; + test_bearer_t *bearer = NULL; + + NGAP_NGAP_PDU_t pdu; + NGAP_InitiatingMessage_t *initiatingMessage = NULL; + NGAP_UEContextReleaseCommand_t *UEContextReleaseCommand = NULL; + + NGAP_UEContextReleaseCommand_IEs_t *ie = NULL; + NGAP_UE_NGAP_IDs_t *UE_NGAP_IDs = NULL; + + ogs_assert(test_ue); + ogs_assert(message); + + initiatingMessage = message->choice.initiatingMessage; + ogs_assert(initiatingMessage); + UEContextReleaseCommand = + &initiatingMessage->value.choice.UEContextReleaseCommand; + ogs_assert(UEContextReleaseCommand); + + for (i = 0; i < UEContextReleaseCommand->protocolIEs.list.count; i++) { + ie = UEContextReleaseCommand->protocolIEs.list.array[i]; + switch (ie->id) { + case NGAP_ProtocolIE_ID_id_UE_NGAP_IDs: + UE_NGAP_IDs = &ie->value.choice.UE_NGAP_IDs; + break; + default: + break; + } + } + + if (UE_NGAP_IDs) { + if (UE_NGAP_IDs->present == NGAP_UE_NGAP_IDs_PR_uE_NGAP_ID_pair) { + uint64_t amf_ue_ngap_id; + asn_INTEGER2ulong( + &UE_NGAP_IDs->choice.uE_NGAP_ID_pair->aMF_UE_NGAP_ID, + (unsigned long *)&amf_ue_ngap_id); + test_ue->amf_ue_ngap_id = (uint64_t)amf_ue_ngap_id; + } + } +} + void testngap_handle_pdu_session_resource_setup_request( test_ue_t *test_ue, ogs_ngap_message_t *message) { test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; int rv, i, j, k, l; char buf[OGS_ADDRSTRLEN]; @@ -182,8 +228,6 @@ void testngap_handle_pdu_session_resource_setup_request( ogs_pkbuf_t *n2smbuf = NULL; ogs_assert(test_ue); - sess = test_ue->sess; - ogs_assert(sess); ogs_assert(message); initiatingMessage = message->choice.initiatingMessage; @@ -203,6 +247,11 @@ void testngap_handle_pdu_session_resource_setup_request( PDUSessionItem = (NGAP_PDUSessionResourceSetupItemSUReq_t *) PDUSessionList->list.array[j]; ogs_assert(PDUSessionItem); + + sess = test_sess_find_by_psi( + test_ue, PDUSessionItem->pDUSessionID); + ogs_assert(sess); + if (PDUSessionItem->pDUSessionNAS_PDU) testngap_send_to_nas( test_ue, PDUSessionItem->pDUSessionNAS_PDU); @@ -231,8 +280,13 @@ void testngap_handle_pdu_session_resource_setup_request( (struct NGAP_QosFlowSetupRequestItem *) QosFlowSetupRequestList->list.array[l]; ogs_assert(QosFlowSetupRequestItem); - sess->qfi = - QosFlowSetupRequestItem->qosFlowIdentifier; + qos_flow = test_qos_flow_find_by_sess_qfi(sess, + QosFlowSetupRequestItem->qosFlowIdentifier); + if (!qos_flow) + qos_flow = test_qos_flow_add(sess); + + qos_flow->qfi = + QosFlowSetupRequestItem->qosFlowIdentifier; } break; case NGAP_ProtocolIE_ID_id_UL_NGU_UP_TNLInformation: @@ -269,7 +323,6 @@ void testngap_handle_pdu_session_resource_setup_request( void testngap_handle_pdu_session_resource_release_command( test_ue_t *test_ue, ogs_ngap_message_t *message) { - test_sess_t *sess = NULL; int rv, i, j, k; char buf[OGS_ADDRSTRLEN]; @@ -281,8 +334,6 @@ void testngap_handle_pdu_session_resource_release_command( NGAP_NAS_PDU_t *NAS_PDU = NULL; ogs_assert(test_ue); - sess = test_ue->sess; - ogs_assert(sess); ogs_assert(message); initiatingMessage = message->choice.initiatingMessage; diff --git a/tests/common/ngap-handler.h b/tests/common/ngap-handler.h index 51512bca2..a34db3ed6 100644 --- a/tests/common/ngap-handler.h +++ b/tests/common/ngap-handler.h @@ -31,6 +31,8 @@ void testngap_handle_downlink_nas_transport( test_ue_t *test_ue, ogs_ngap_message_t *message); void testngap_handle_initial_context_setup_request( test_ue_t *test_ue, ogs_ngap_message_t *message); +void testngap_handle_ue_release_context_command( + test_ue_t *test_ue, ogs_ngap_message_t *message); void testngap_handle_pdu_session_resource_setup_request( test_ue_t *test_ue, ogs_ngap_message_t *message); void testngap_handle_pdu_session_resource_release_command( diff --git a/tests/common/ngap-path.c b/tests/common/ngap-path.c index 68293e0a3..a28bc2792 100644 --- a/tests/common/ngap-path.c +++ b/tests/common/ngap-path.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-ngap.h" +#include "test-common.h" void testngap_recv(test_ue_t *test_ue, ogs_pkbuf_t *pkbuf) { @@ -32,7 +32,7 @@ void testngap_recv(test_ue_t *test_ue, ogs_pkbuf_t *pkbuf) ogs_assert(test_ue); ogs_assert(pkbuf); - rv = nga_ngap_decode(&message, pkbuf); + rv = ogs_ngap_decode(&message, pkbuf); ogs_assert(rv == OGS_OK); pdu = &message; @@ -50,15 +50,15 @@ void testngap_recv(test_ue_t *test_ue, ogs_pkbuf_t *pkbuf) case NGAP_ProcedureCode_id_InitialContextSetup: testngap_handle_initial_context_setup_request(test_ue, pdu); break; + case NGAP_ProcedureCode_id_UEContextRelease: + testngap_handle_ue_release_context_command(test_ue, pdu); + break; case NGAP_ProcedureCode_id_PDUSessionResourceSetup: testngap_handle_pdu_session_resource_setup_request(test_ue, pdu); break; case NGAP_ProcedureCode_id_PDUSessionResourceRelease: testngap_handle_pdu_session_resource_release_command(test_ue, pdu); break; - case NGAP_ProcedureCode_id_UEContextRelease: - /* Nothing */ - break; case NGAP_ProcedureCode_id_ErrorIndication: /* Nothing */ break; @@ -100,7 +100,7 @@ void testngap_recv(test_ue_t *test_ue, ogs_pkbuf_t *pkbuf) break; } - nga_ngap_free(&message); + ogs_ngap_free(&message); ogs_pkbuf_free(pkbuf); } diff --git a/tests/common/s1ap-build.c b/tests/common/s1ap-build.c new file mode 100644 index 000000000..81257b081 --- /dev/null +++ b/tests/common/s1ap-build.c @@ -0,0 +1,1882 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +ogs_pkbuf_t *test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR present, uint32_t enb_id) +{ + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_S1SetupRequest_t *S1SetupRequest = NULL; + + S1AP_S1SetupRequestIEs_t *ie = NULL; + S1AP_Global_ENB_ID_t *Global_ENB_ID = NULL; + S1AP_SupportedTAs_t *SupportedTAs = NULL; + S1AP_SupportedTAs_Item_t *SupportedTAs_Item = NULL; + S1AP_PLMNidentity_t *PLMNidentity = NULL; + S1AP_PagingDRX_t *PagingDRX = NULL; + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); + + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = S1AP_ProcedureCode_id_S1Setup; + initiatingMessage->criticality = S1AP_Criticality_reject; + initiatingMessage->value.present = + S1AP_InitiatingMessage__value_PR_S1SetupRequest; + + S1SetupRequest = &initiatingMessage->value.choice.S1SetupRequest; + + ie = CALLOC(1, sizeof(S1AP_S1SetupRequestIEs_t)); + ASN_SEQUENCE_ADD(&S1SetupRequest->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_Global_ENB_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_S1SetupRequestIEs__value_PR_Global_ENB_ID; + + Global_ENB_ID = &ie->value.choice.Global_ENB_ID; + + ie = CALLOC(1, sizeof(S1AP_S1SetupRequestIEs_t)); + ASN_SEQUENCE_ADD(&S1SetupRequest->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_SupportedTAs; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_S1SetupRequestIEs__value_PR_SupportedTAs; + + SupportedTAs = &ie->value.choice.SupportedTAs; + + ie = CALLOC(1, sizeof(S1AP_S1SetupRequestIEs_t)); + ASN_SEQUENCE_ADD(&S1SetupRequest->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_DefaultPagingDRX; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_S1SetupRequestIEs__value_PR_PagingDRX; + + PagingDRX = &ie->value.choice.PagingDRX; + + ogs_s1ap_uint32_to_ENB_ID(present, enb_id, &Global_ENB_ID->eNB_ID); + ogs_s1ap_buffer_to_OCTET_STRING( + &test_self()->e_tai.plmn_id, OGS_PLMN_ID_LEN, + &Global_ENB_ID->pLMNidentity); + + SupportedTAs_Item = (S1AP_SupportedTAs_Item_t *) + CALLOC(1, sizeof(S1AP_SupportedTAs_Item_t)); + ogs_asn_uint16_to_OCTET_STRING( + test_self()->e_tai.tac, &SupportedTAs_Item->tAC); + PLMNidentity = (S1AP_PLMNidentity_t *) + CALLOC(1, sizeof(S1AP_PLMNidentity_t)); + ogs_s1ap_buffer_to_OCTET_STRING( + &test_self()->e_tai.plmn_id, OGS_PLMN_ID_LEN, PLMNidentity); + ASN_SEQUENCE_ADD(&SupportedTAs_Item->broadcastPLMNs.list, PLMNidentity); + + ASN_SEQUENCE_ADD(&SupportedTAs->list, SupportedTAs_Item); + + *PagingDRX = S1AP_PagingDRX_v64; + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_initial_ue_message( + test_ue_t *test_ue, ogs_pkbuf_t *emmbuf, uint8_t cause, bool s_tmsi) +{ + ogs_pkbuf_t *pkbuf = NULL; + int i, j; + char buf[5]; + + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_InitialUEMessage_t *InitialUEMessage = NULL; + + S1AP_InitialUEMessage_IEs_t *ie = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_NAS_PDU_t *NAS_PDU = NULL; + S1AP_TAI_t *TAI = NULL; + S1AP_EUTRAN_CGI_t *EUTRAN_CGI = NULL; + S1AP_RRC_Establishment_Cause_t *RRC_Establishment_Cause = NULL; + S1AP_GUMMEI_t *GUMMEI = NULL; + S1AP_GUMMEIType_t *GUMMEIType = NULL; + + ogs_assert(test_ue); + ogs_assert(emmbuf); + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); + + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = S1AP_ProcedureCode_id_initialUEMessage; + initiatingMessage->criticality = S1AP_Criticality_reject; + initiatingMessage->value.present = + S1AP_InitiatingMessage__value_PR_InitialUEMessage; + + InitialUEMessage = &initiatingMessage->value.choice.InitialUEMessage; + + ie = CALLOC(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ASN_SEQUENCE_ADD(&InitialUEMessage->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + test_ue->enb_ue_s1ap_id++; + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ASN_SEQUENCE_ADD(&InitialUEMessage->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_NAS_PDU; + + NAS_PDU = &ie->value.choice.NAS_PDU; + + NAS_PDU->size = emmbuf->len; + NAS_PDU->buf = CALLOC(NAS_PDU->size, sizeof(uint8_t)); + memcpy(NAS_PDU->buf, emmbuf->data, NAS_PDU->size); + ogs_pkbuf_free(emmbuf); + + ie = CALLOC(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ASN_SEQUENCE_ADD(&InitialUEMessage->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_TAI; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TAI; + + TAI = &ie->value.choice.TAI; + + ogs_asn_uint16_to_OCTET_STRING(test_ue->e_tai.tac, &TAI->tAC); + ogs_s1ap_buffer_to_OCTET_STRING( + &test_ue->e_tai.plmn_id, OGS_PLMN_ID_LEN, &TAI->pLMNidentity); + + ie = CALLOC(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ASN_SEQUENCE_ADD(&InitialUEMessage->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_EUTRAN_CGI; + + EUTRAN_CGI = &ie->value.choice.EUTRAN_CGI; + + ogs_s1ap_buffer_to_OCTET_STRING( + &test_ue->e_cgi.plmn_id, + OGS_PLMN_ID_LEN, &EUTRAN_CGI->pLMNidentity); + EUTRAN_CGI->cell_ID.size = 4; + EUTRAN_CGI->cell_ID.buf = CALLOC( + EUTRAN_CGI->cell_ID.size, sizeof(uint8_t)); + ogs_assert(EUTRAN_CGI->cell_ID.buf); + EUTRAN_CGI->cell_ID.buf[0] = (test_ue->e_cgi.cell_id >> 24); + EUTRAN_CGI->cell_ID.buf[1] = (test_ue->e_cgi.cell_id >> 16); + EUTRAN_CGI->cell_ID.buf[2] = (test_ue->e_cgi.cell_id >> 8); + EUTRAN_CGI->cell_ID.buf[3] = (test_ue->e_cgi.cell_id); + EUTRAN_CGI->cell_ID.bits_unused = 4; + + ie = CALLOC(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ASN_SEQUENCE_ADD(&InitialUEMessage->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_RRC_Establishment_Cause; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_InitialUEMessage_IEs__value_PR_RRC_Establishment_Cause; + + RRC_Establishment_Cause = &ie->value.choice.RRC_Establishment_Cause; + + *RRC_Establishment_Cause = cause; + + if (s_tmsi) { + S1AP_MME_Code_t *mMEC = NULL; + S1AP_M_TMSI_t *m_TMSI = NULL; + S1AP_S_TMSI_t *S_TMSI = NULL; + + ie = CALLOC(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ASN_SEQUENCE_ADD(&InitialUEMessage->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_S_TMSI; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_S_TMSI; + + S_TMSI = &ie->value.choice.S_TMSI; + + mMEC = &S_TMSI->mMEC; + m_TMSI = &S_TMSI->m_TMSI; + + ogs_asn_uint8_to_OCTET_STRING(test_ue->nas_eps_guti.mme_code, mMEC); + ogs_asn_uint32_to_OCTET_STRING(test_ue->nas_eps_guti.m_tmsi, m_TMSI); + } + + if (test_ue->initial_ue_param.gummei_id) { + ie = CALLOC(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ASN_SEQUENCE_ADD(&InitialUEMessage->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_GUMMEI_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEI; + + GUMMEI = &ie->value.choice.GUMMEI; + ogs_s1ap_buffer_to_OCTET_STRING( + &test_ue->e_cgi.plmn_id, + OGS_PLMN_ID_LEN, &GUMMEI->pLMN_Identity); + ogs_asn_uint16_to_OCTET_STRING( + test_ue->initial_ue_param.gummei.mme_gid, + &GUMMEI->mME_Group_ID); + ogs_asn_uint8_to_OCTET_STRING( + test_ue->initial_ue_param.gummei.mme_code, + &GUMMEI->mME_Code); + } + + if (test_ue->initial_ue_param.gummei_type) { + ie = CALLOC(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ASN_SEQUENCE_ADD(&InitialUEMessage->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_GUMMEIType; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEIType; + + GUMMEIType = &ie->value.choice.GUMMEIType; + + *GUMMEIType = test_ue->initial_ue_param.gummei.type; + } + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_uplink_nas_transport( + test_ue_t *test_ue, ogs_pkbuf_t *nasbuf) +{ + char buf[5]; + + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_UplinkNASTransport_t *UplinkNASTransport = NULL; + + S1AP_UplinkNASTransport_IEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_NAS_PDU_t *NAS_PDU = NULL; + S1AP_TAI_t *TAI = NULL; + S1AP_EUTRAN_CGI_t *EUTRAN_CGI = NULL; + S1AP_PSCellInformation_t *PSCellInformation = NULL; + S1AP_NR_CGI_t *nCGI = NULL; + + ogs_assert(test_ue); + ogs_assert(nasbuf); + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); + + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = + S1AP_ProcedureCode_id_uplinkNASTransport; + initiatingMessage->criticality = S1AP_Criticality_ignore; + initiatingMessage->value.present = + S1AP_InitiatingMessage__value_PR_UplinkNASTransport; + + UplinkNASTransport = &initiatingMessage->value.choice.UplinkNASTransport; + + ie = CALLOC(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ASN_SEQUENCE_ADD(&UplinkNASTransport->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = + S1AP_UplinkNASTransport_IEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ASN_SEQUENCE_ADD(&UplinkNASTransport->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = + S1AP_UplinkNASTransport_IEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ASN_SEQUENCE_ADD(&UplinkNASTransport->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_NAS_PDU; + + NAS_PDU = &ie->value.choice.NAS_PDU; + + NAS_PDU->size = nasbuf->len; + NAS_PDU->buf = CALLOC(NAS_PDU->size, sizeof(uint8_t)); + memcpy(NAS_PDU->buf, nasbuf->data, NAS_PDU->size); + ogs_pkbuf_free(nasbuf); + + ie = CALLOC(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ASN_SEQUENCE_ADD(&UplinkNASTransport->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_EUTRAN_CGI; + + EUTRAN_CGI = &ie->value.choice.EUTRAN_CGI; + + ogs_s1ap_buffer_to_OCTET_STRING( + &test_ue->e_cgi.plmn_id, + OGS_PLMN_ID_LEN, &EUTRAN_CGI->pLMNidentity); + EUTRAN_CGI->cell_ID.size = 4; + EUTRAN_CGI->cell_ID.buf = CALLOC( + EUTRAN_CGI->cell_ID.size, sizeof(uint8_t)); + ogs_assert(EUTRAN_CGI->cell_ID.buf); + EUTRAN_CGI->cell_ID.buf[0] = (test_ue->e_cgi.cell_id >> 24); + EUTRAN_CGI->cell_ID.buf[1] = (test_ue->e_cgi.cell_id >> 16); + EUTRAN_CGI->cell_ID.buf[2] = (test_ue->e_cgi.cell_id >> 8); + EUTRAN_CGI->cell_ID.buf[3] = (test_ue->e_cgi.cell_id); + EUTRAN_CGI->cell_ID.bits_unused = 4; + + ie = CALLOC(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ASN_SEQUENCE_ADD(&UplinkNASTransport->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_TAI; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TAI; + + TAI = &ie->value.choice.TAI; + + ogs_asn_uint16_to_OCTET_STRING(test_ue->e_tai.tac, &TAI->tAC); + ogs_s1ap_buffer_to_OCTET_STRING( + &test_ue->e_tai.plmn_id, OGS_PLMN_ID_LEN, &TAI->pLMNidentity); + + if (test_ue->nr_cgi.cell_id) { + ie = CALLOC(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ASN_SEQUENCE_ADD(&UplinkNASTransport->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_PSCellInformation; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_UplinkNASTransport_IEs__value_PR_PSCellInformation; + + PSCellInformation = &ie->value.choice.PSCellInformation; + nCGI = &PSCellInformation->nCGI; + ogs_s1ap_buffer_to_OCTET_STRING( + &test_ue->e_cgi.plmn_id, OGS_PLMN_ID_LEN, &nCGI->pLMNIdentity); + + ogs_uint64_to_buffer((test_ue->nr_cgi.cell_id << 4), 5, buf); + ogs_asn_buffer_to_BIT_STRING(buf, 5, 4, &nCGI->nRCellIdentity); + } + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *tests1ap_build_ue_radio_capability_info_indication( + test_ue_t *test_ue) +{ + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_UECapabilityInfoIndication_t *UECapabilityInfoIndication = + NULL; + + S1AP_UECapabilityInfoIndicationIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_UERadioCapability_t *UERadioCapability = NULL; + + uint8_t tmp[OGS_MAX_SDU_LEN]; + char *_capability_captured = + "013001023c" + "d98000bc000ff06e c4d00141b82c0000 000007d404000ef0 802000016a030000" + "880000"; + + ogs_assert(test_ue); + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); + + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = + S1AP_ProcedureCode_id_UECapabilityInfoIndication; + initiatingMessage->criticality = S1AP_Criticality_ignore; + initiatingMessage->value.present = + S1AP_InitiatingMessage__value_PR_UECapabilityInfoIndication; + + UECapabilityInfoIndication = + &initiatingMessage->value.choice.UECapabilityInfoIndication; + + ie = CALLOC(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); + ASN_SEQUENCE_ADD(&UECapabilityInfoIndication->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = + S1AP_UECapabilityInfoIndicationIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); + ASN_SEQUENCE_ADD(&UECapabilityInfoIndication->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = + S1AP_UECapabilityInfoIndicationIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); + ASN_SEQUENCE_ADD(&UECapabilityInfoIndication->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_UERadioCapability; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapability; + + UERadioCapability = &ie->value.choice.UERadioCapability; + + OGS_HEX(_capability_captured, strlen(_capability_captured), tmp), + + UERadioCapability->size = 40; + UERadioCapability->buf = CALLOC(UERadioCapability->size, sizeof(uint8_t)); + memcpy(UERadioCapability->buf, tmp, UERadioCapability->size); + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_initial_context_setup_response(test_ue_t *test_ue) +{ + int rv; + + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + ogs_gtp_f_teid_t f_teid; + ogs_ip_t ip; + int len; + + S1AP_S1AP_PDU_t pdu; + S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; + S1AP_InitialContextSetupResponse_t *InitialContextSetupResponse = NULL; + + S1AP_InitialContextSetupResponseIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_E_RABSetupListCtxtSURes_t *E_RABSetupListCtxtSURes = NULL; + + S1AP_E_RABSetupItemCtxtSUResIEs_t *item = NULL; + S1AP_E_RABSetupItemCtxtSURes_t *e_rab = NULL; + + ogs_assert(test_ue); + sess = ogs_list_first(&test_ue->sess_list); + ogs_assert(sess); + bearer = ogs_list_first(&sess->bearer_list); + ogs_assert(bearer); + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome = + CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); + + successfulOutcome = pdu.choice.successfulOutcome; + successfulOutcome->procedureCode = + S1AP_ProcedureCode_id_InitialContextSetup; + successfulOutcome->criticality = S1AP_Criticality_reject; + successfulOutcome->value.present = + S1AP_SuccessfulOutcome__value_PR_InitialContextSetupResponse; + + InitialContextSetupResponse = + &successfulOutcome->value.choice.InitialContextSetupResponse; + + ie = CALLOC(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); + ASN_SEQUENCE_ADD(&InitialContextSetupResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_InitialContextSetupResponseIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); + ASN_SEQUENCE_ADD(&InitialContextSetupResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_InitialContextSetupResponseIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); + ASN_SEQUENCE_ADD(&InitialContextSetupResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListCtxtSURes; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_InitialContextSetupResponseIEs__value_PR_E_RABSetupListCtxtSURes; + + E_RABSetupListCtxtSURes = &ie->value.choice.E_RABSetupListCtxtSURes; + + item = CALLOC(1, sizeof(S1AP_E_RABSetupItemCtxtSUResIEs_t)); + ASN_SEQUENCE_ADD(&E_RABSetupListCtxtSURes->list, item); + + item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemCtxtSURes; + item->criticality = S1AP_Criticality_ignore; + item->value.present = + S1AP_E_RABSetupItemCtxtSUResIEs__value_PR_E_RABSetupItemCtxtSURes; + + e_rab = &item->value.choice.E_RABSetupItemCtxtSURes; + + e_rab->e_RAB_ID = bearer->ebi; + + rv = ogs_gtp_sockaddr_to_f_teid( + bearer->enb_s1u_addr, bearer->enb_s1u_addr6, &f_teid, &len); + ogs_assert(rv == OGS_OK); + + rv = ogs_gtp_f_teid_to_ip(&f_teid, &ip); + ogs_assert(rv == OGS_OK); + + rv = ogs_asn_ip_to_BIT_STRING(&ip, &e_rab->transportLayerAddress); + ogs_assert(rv == OGS_OK); + ogs_asn_uint32_to_OCTET_STRING(bearer->enb_s1u_teid, &e_rab->gTP_TEID); + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_initial_context_setup_failure(test_ue_t *test_ue, + S1AP_Cause_PR group, long cause) +{ + int rv; + + S1AP_S1AP_PDU_t pdu; + S1AP_UnsuccessfulOutcome_t *unsuccessfulOutcome = NULL; + S1AP_InitialContextSetupFailure_t *InitialContextSetupFailure = NULL; + + S1AP_InitialContextSetupFailureIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_Cause_t *Cause = NULL; + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_unsuccessfulOutcome; + pdu.choice.unsuccessfulOutcome = + CALLOC(1, sizeof(S1AP_UnsuccessfulOutcome_t)); + + unsuccessfulOutcome = pdu.choice.unsuccessfulOutcome; + unsuccessfulOutcome->procedureCode = + S1AP_ProcedureCode_id_InitialContextSetup; + unsuccessfulOutcome->criticality = S1AP_Criticality_reject; + unsuccessfulOutcome->value.present = + S1AP_UnsuccessfulOutcome__value_PR_InitialContextSetupFailure; + + InitialContextSetupFailure = + &unsuccessfulOutcome->value.choice.InitialContextSetupFailure; + + ie = CALLOC(1, sizeof(S1AP_InitialContextSetupFailureIEs_t)); + ASN_SEQUENCE_ADD(&InitialContextSetupFailure->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_InitialContextSetupFailureIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_InitialContextSetupFailureIEs_t)); + ASN_SEQUENCE_ADD(&InitialContextSetupFailure->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_InitialContextSetupFailureIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_InitialContextSetupFailureIEs_t)); + ASN_SEQUENCE_ADD(&InitialContextSetupFailure->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_Cause; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialContextSetupFailureIEs__value_PR_Cause; + + Cause = &ie->value.choice.Cause; + + Cause->present = group; + Cause->choice.radioNetwork = cause; + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_ue_context_modification_response( + test_ue_t *test_ue) +{ + S1AP_S1AP_PDU_t pdu; + S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; + S1AP_UEContextModificationResponse_t *UEContextModificationResponse = NULL; + + S1AP_UEContextModificationResponseIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome = + CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); + + successfulOutcome = pdu.choice.successfulOutcome; + successfulOutcome->procedureCode = + S1AP_ProcedureCode_id_UEContextModification; + successfulOutcome->criticality = S1AP_Criticality_reject; + successfulOutcome->value.present = + S1AP_SuccessfulOutcome__value_PR_UEContextModificationResponse; + + UEContextModificationResponse = + &successfulOutcome->value.choice.UEContextModificationResponse; + + ie = CALLOC(1, sizeof(S1AP_UEContextModificationResponseIEs_t)); + ASN_SEQUENCE_ADD(&UEContextModificationResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_UEContextModificationResponseIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_UEContextModificationResponseIEs_t)); + ASN_SEQUENCE_ADD(&UEContextModificationResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_UEContextModificationResponseIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_ue_context_release_request(test_ue_t *test_ue, + S1AP_Cause_PR group, long cause) +{ + int rv; + + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_UEContextReleaseRequest_t *UEContextReleaseRequest = NULL; + + S1AP_UEContextReleaseRequest_IEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_Cause_t *Cause = NULL; + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); + + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = + S1AP_ProcedureCode_id_UEContextReleaseRequest; + initiatingMessage->criticality = S1AP_Criticality_ignore; + initiatingMessage->value.present = + S1AP_InitiatingMessage__value_PR_UEContextReleaseRequest; + + UEContextReleaseRequest = + &initiatingMessage->value.choice.UEContextReleaseRequest; + + ie = CALLOC(1, sizeof(S1AP_UEContextReleaseRequest_IEs_t)); + ASN_SEQUENCE_ADD(&UEContextReleaseRequest->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = + S1AP_UEContextReleaseRequest_IEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_UEContextReleaseRequest_IEs_t)); + ASN_SEQUENCE_ADD(&UEContextReleaseRequest->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = + S1AP_UEContextReleaseRequest_IEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_UEContextReleaseRequest_IEs_t)); + ASN_SEQUENCE_ADD(&UEContextReleaseRequest->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_Cause; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_UEContextReleaseRequest_IEs__value_PR_Cause; + + Cause = &ie->value.choice.Cause; + + Cause->present = group; + Cause->choice.radioNetwork = cause; + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_ue_context_release_complete(test_ue_t *test_ue) +{ + int rv; + + S1AP_S1AP_PDU_t pdu; + S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; + S1AP_UEContextReleaseComplete_t *UEContextReleaseComplete = NULL; + + S1AP_UEContextReleaseComplete_IEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome = CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); + + successfulOutcome = pdu.choice.successfulOutcome; + successfulOutcome->procedureCode = + S1AP_ProcedureCode_id_UEContextRelease; + successfulOutcome->criticality = S1AP_Criticality_reject; + successfulOutcome->value.present = + S1AP_SuccessfulOutcome__value_PR_UEContextReleaseComplete; + + UEContextReleaseComplete = + &successfulOutcome->value.choice.UEContextReleaseComplete; + + ie = CALLOC(1, sizeof(S1AP_UEContextReleaseComplete_IEs_t)); + ASN_SEQUENCE_ADD(&UEContextReleaseComplete->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_UEContextReleaseComplete_IEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_UEContextReleaseComplete_IEs_t)); + ASN_SEQUENCE_ADD(&UEContextReleaseComplete->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_UEContextReleaseComplete_IEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_e_rab_setup_response(test_bearer_t *bearer) +{ + int rv; + ogs_sockaddr_t *addr = NULL; + + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + + S1AP_S1AP_PDU_t pdu; + S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; + S1AP_E_RABSetupResponse_t *E_RABSetupResponse = NULL; + + S1AP_E_RABSetupResponseIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_E_RABSetupListBearerSURes_t *E_RABSetupListBearerSURes = NULL; + + S1AP_E_RABSetupItemBearerSUResIEs_t *item = NULL; + S1AP_E_RABSetupItemBearerSURes_t *e_rab = NULL; + + ogs_gtp_f_teid_t f_teid; + ogs_ip_t ip; + int len; + + ogs_assert(bearer); + sess = bearer->sess; + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome = CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); + + successfulOutcome = pdu.choice.successfulOutcome; + successfulOutcome->procedureCode = S1AP_ProcedureCode_id_E_RABSetup; + successfulOutcome->criticality = S1AP_Criticality_reject; + successfulOutcome->value.present = + S1AP_SuccessfulOutcome__value_PR_E_RABSetupResponse; + + E_RABSetupResponse = &successfulOutcome->value.choice.E_RABSetupResponse; + + ie = CALLOC(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); + ASN_SEQUENCE_ADD(&E_RABSetupResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); + ASN_SEQUENCE_ADD(&E_RABSetupResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); + ASN_SEQUENCE_ADD(&E_RABSetupResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListBearerSURes; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_E_RABSetupResponseIEs__value_PR_E_RABSetupListBearerSURes; + + E_RABSetupListBearerSURes = &ie->value.choice.E_RABSetupListBearerSURes; + + item = CALLOC(1, sizeof(S1AP_E_RABSetupItemBearerSUResIEs_t)); + ASN_SEQUENCE_ADD(&E_RABSetupListBearerSURes->list, item); + + item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemBearerSURes; + item->criticality = S1AP_Criticality_ignore; + item->value.present = + S1AP_E_RABSetupItemBearerSUResIEs__value_PR_E_RABSetupItemBearerSURes; + + e_rab = &item->value.choice.E_RABSetupItemBearerSURes; + + e_rab->e_RAB_ID = bearer->ebi; + + rv = ogs_gtp_sockaddr_to_f_teid( + bearer->enb_s1u_addr, bearer->enb_s1u_addr6, &f_teid, &len); + ogs_assert(rv == OGS_OK); + + rv = ogs_gtp_f_teid_to_ip(&f_teid, &ip); + ogs_assert(rv == OGS_OK); + + rv = ogs_asn_ip_to_BIT_STRING(&ip, &e_rab->transportLayerAddress); + ogs_assert(rv == OGS_OK); + ogs_asn_uint32_to_OCTET_STRING(bearer->enb_s1u_teid, &e_rab->gTP_TEID); + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_e_rab_modify_response(test_bearer_t *bearer) +{ + int rv; + ogs_sockaddr_t *addr = NULL; + + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + + S1AP_S1AP_PDU_t pdu; + S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; + S1AP_E_RABModifyResponse_t *E_RABModifyResponse = NULL; + + S1AP_E_RABModifyResponseIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_E_RABModifyListBearerModRes_t *E_RABModifyListBearerModRes = NULL; + + S1AP_E_RABModifyItemBearerModResIEs_t *item = NULL; + S1AP_E_RABModifyItemBearerModRes_t *e_rab = NULL; + + ogs_assert(bearer); + sess = bearer->sess; + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome = CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); + + successfulOutcome = pdu.choice.successfulOutcome; + successfulOutcome->procedureCode = S1AP_ProcedureCode_id_E_RABModify; + successfulOutcome->criticality = S1AP_Criticality_reject; + successfulOutcome->value.present = + S1AP_SuccessfulOutcome__value_PR_E_RABModifyResponse; + + E_RABModifyResponse = &successfulOutcome->value.choice.E_RABModifyResponse; + + ie = CALLOC(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); + ASN_SEQUENCE_ADD(&E_RABModifyResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); + ASN_SEQUENCE_ADD(&E_RABModifyResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); + ASN_SEQUENCE_ADD(&E_RABModifyResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_E_RABModifyListBearerModRes; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_E_RABModifyResponseIEs__value_PR_E_RABModifyListBearerModRes; + + E_RABModifyListBearerModRes = &ie->value.choice.E_RABModifyListBearerModRes; + + item = CALLOC(1, sizeof(S1AP_E_RABModifyItemBearerModResIEs_t)); + ASN_SEQUENCE_ADD(&E_RABModifyListBearerModRes->list, item); + + item->id = S1AP_ProtocolIE_ID_id_E_RABModifyItemBearerModRes; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABModifyItemBearerModResIEs__value_PR_E_RABModifyItemBearerModRes; + + e_rab = &item->value.choice.E_RABModifyItemBearerModRes; + + e_rab->e_RAB_ID = bearer->ebi; + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_e_rab_release_response(test_bearer_t *bearer) +{ + int rv; + ogs_sockaddr_t *addr = NULL; + + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + + S1AP_S1AP_PDU_t pdu; + S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; + S1AP_E_RABReleaseResponse_t *E_RABReleaseResponse = NULL; + + S1AP_E_RABReleaseResponseIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_E_RABReleaseListBearerRelComp_t *E_RABReleaseListBearerRelComp = NULL; + + S1AP_E_RABReleaseItemBearerRelCompIEs_t *item = NULL; + S1AP_E_RABReleaseItemBearerRelComp_t *e_rab = NULL; + + ogs_assert(bearer); + sess = bearer->sess; + ogs_assert(sess); + test_ue = sess->test_ue; + ogs_assert(test_ue); + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome = CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); + + successfulOutcome = pdu.choice.successfulOutcome; + successfulOutcome->procedureCode = S1AP_ProcedureCode_id_E_RABRelease; + successfulOutcome->criticality = S1AP_Criticality_reject; + successfulOutcome->value.present = + S1AP_SuccessfulOutcome__value_PR_E_RABReleaseResponse; + + E_RABReleaseResponse = + &successfulOutcome->value.choice.E_RABReleaseResponse; + + ie = CALLOC(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ASN_SEQUENCE_ADD(&E_RABReleaseResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ASN_SEQUENCE_ADD(&E_RABReleaseResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ASN_SEQUENCE_ADD(&E_RABReleaseResponse->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_E_RABReleaseListBearerRelComp; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_E_RABReleaseResponseIEs__value_PR_E_RABReleaseListBearerRelComp; + + E_RABReleaseListBearerRelComp = + &ie->value.choice.E_RABReleaseListBearerRelComp; + + item = CALLOC(1, sizeof(S1AP_E_RABReleaseItemBearerRelCompIEs_t)); + ASN_SEQUENCE_ADD(&E_RABReleaseListBearerRelComp->list, item); + + item->id = S1AP_ProtocolIE_ID_id_E_RABReleaseItemBearerRelComp; + item->criticality = S1AP_Criticality_ignore; + item->value.present = + S1AP_E_RABReleaseItemBearerRelCompIEs__value_PR_E_RABReleaseItemBearerRelComp; + + e_rab = &item->value.choice.E_RABReleaseItemBearerRelComp; + + e_rab->e_RAB_ID = bearer->ebi; + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_path_switch_request(test_ue_t *test_ue) +{ + int rv; + + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_PathSwitchRequest_t *PathSwitchRequest = NULL; + + S1AP_PathSwitchRequestIEs_t *ie = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_E_RABToBeSwitchedDLList_t *E_RABToBeSwitchedDLList = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_EUTRAN_CGI_t *EUTRAN_CGI = NULL; + S1AP_TAI_t *TAI = NULL; + S1AP_UESecurityCapabilities_t *UESecurityCapabilities = NULL; + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); + + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = S1AP_ProcedureCode_id_PathSwitchRequest; + initiatingMessage->criticality = S1AP_Criticality_reject; + initiatingMessage->value.present = + S1AP_InitiatingMessage__value_PR_PathSwitchRequest; + + PathSwitchRequest = &initiatingMessage->value.choice.PathSwitchRequest; + + ie = CALLOC(1, sizeof(S1AP_PathSwitchRequestIEs_t)); + ASN_SEQUENCE_ADD(&PathSwitchRequest->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + ie = CALLOC(1, sizeof(S1AP_PathSwitchRequestIEs_t)); + ASN_SEQUENCE_ADD(&PathSwitchRequest->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_E_RABToBeSwitchedDLList; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = + S1AP_PathSwitchRequestIEs__value_PR_E_RABToBeSwitchedDLList; + + E_RABToBeSwitchedDLList = &ie->value.choice.E_RABToBeSwitchedDLList; + + ie = CALLOC(1, sizeof(S1AP_PathSwitchRequestIEs_t)); + ASN_SEQUENCE_ADD(&PathSwitchRequest->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_SourceMME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + ie = CALLOC(1, sizeof(S1AP_PathSwitchRequestIEs_t)); + ASN_SEQUENCE_ADD(&PathSwitchRequest->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_EUTRAN_CGI; + + EUTRAN_CGI = &ie->value.choice.EUTRAN_CGI; + + ie = CALLOC(1, sizeof(S1AP_PathSwitchRequestIEs_t)); + ASN_SEQUENCE_ADD(&PathSwitchRequest->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_TAI; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_TAI; + + TAI = &ie->value.choice.TAI; + + ie = CALLOC(1, sizeof(S1AP_PathSwitchRequestIEs_t)); + ASN_SEQUENCE_ADD(&PathSwitchRequest->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_UESecurityCapabilities; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_PathSwitchRequestIEs__value_PR_UESecurityCapabilities; + + UESecurityCapabilities = &ie->value.choice.UESecurityCapabilities; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ogs_list_for_each(&test_ue->sess_list, sess) { + ogs_list_for_each(&sess->bearer_list, bearer) { + S1AP_E_RABToBeSwitchedDLItemIEs_t *item = NULL; + S1AP_E_RABToBeSwitchedDLItem_t *e_rab = NULL; + + ogs_sockaddr_t *addr = NULL; + ogs_gtp_f_teid_t f_teid; + ogs_ip_t ip; + int len; + + item = CALLOC(1, sizeof(S1AP_E_RABToBeSwitchedDLItemIEs_t)); + ASN_SEQUENCE_ADD(&E_RABToBeSwitchedDLList->list, item); + + item->id = S1AP_ProtocolIE_ID_id_E_RABToBeSwitchedDLItem; + item->criticality = S1AP_Criticality_reject; + item->value.present = S1AP_E_RABToBeSwitchedDLItemIEs__value_PR_E_RABToBeSwitchedDLItem; + + e_rab = &item->value.choice.E_RABToBeSwitchedDLItem; + + e_rab->e_RAB_ID = bearer->ebi; + + rv = ogs_gtp_sockaddr_to_f_teid( + bearer->enb_s1u_addr, bearer->enb_s1u_addr6, &f_teid, &len); + ogs_assert(rv == OGS_OK); + + rv = ogs_gtp_f_teid_to_ip(&f_teid, &ip); + ogs_assert(rv == OGS_OK); + + rv = ogs_asn_ip_to_BIT_STRING(&ip, &e_rab->transportLayerAddress); + ogs_assert(rv == OGS_OK); + ogs_asn_uint32_to_OCTET_STRING( + bearer->enb_s1u_teid, &e_rab->gTP_TEID); + } + } + + ogs_s1ap_buffer_to_OCTET_STRING( + &test_ue->e_cgi.plmn_id, + OGS_PLMN_ID_LEN, &EUTRAN_CGI->pLMNidentity); + EUTRAN_CGI->cell_ID.size = 4; + EUTRAN_CGI->cell_ID.buf = CALLOC( + EUTRAN_CGI->cell_ID.size, sizeof(uint8_t)); + ogs_assert(EUTRAN_CGI->cell_ID.buf); + EUTRAN_CGI->cell_ID.buf[0] = (test_ue->e_cgi.cell_id >> 24); + EUTRAN_CGI->cell_ID.buf[1] = (test_ue->e_cgi.cell_id >> 16); + EUTRAN_CGI->cell_ID.buf[2] = (test_ue->e_cgi.cell_id >> 8); + EUTRAN_CGI->cell_ID.buf[3] = (test_ue->e_cgi.cell_id); + EUTRAN_CGI->cell_ID.bits_unused = 4; + + ogs_asn_uint16_to_OCTET_STRING(test_ue->e_tai.tac, &TAI->tAC); + ogs_s1ap_buffer_to_OCTET_STRING( + &test_ue->e_tai.plmn_id, OGS_PLMN_ID_LEN, &TAI->pLMNidentity); + + UESecurityCapabilities->encryptionAlgorithms.size = 2; + UESecurityCapabilities->encryptionAlgorithms.buf = + CALLOC(UESecurityCapabilities->encryptionAlgorithms.size, + sizeof(uint8_t)); + UESecurityCapabilities->encryptionAlgorithms.bits_unused = 0; + UESecurityCapabilities->encryptionAlgorithms.buf[0] = (0x70 << 1); + + UESecurityCapabilities->integrityProtectionAlgorithms.size = 2; + UESecurityCapabilities->integrityProtectionAlgorithms.buf = + CALLOC(UESecurityCapabilities-> + integrityProtectionAlgorithms.size, sizeof(uint8_t)); + UESecurityCapabilities->integrityProtectionAlgorithms.bits_unused = 0; + UESecurityCapabilities->integrityProtectionAlgorithms.buf[0] = (0x70 << 1); + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_handover_required( + test_ue_t *test_ue, S1AP_HandoverType_t handover_type, + S1AP_ENB_ID_PR present, uint32_t enb_id, + S1AP_Cause_PR group, long cause) +{ + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_HandoverRequired_t *HandoverRequired = NULL; + + S1AP_HandoverRequiredIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_HandoverType_t *HandoverType = NULL; + S1AP_Cause_t *Cause = NULL; + S1AP_TargetID_t *TargetID = NULL; + S1AP_TargeteNB_ID_t *targeteNB_ID = NULL; + S1AP_Global_ENB_ID_t *global_ENB_ID = NULL; + S1AP_TAI_t *selected_TAI = NULL; + S1AP_Source_ToTarget_TransparentContainer_t + *Source_ToTarget_TransparentContainer = NULL; + + uint8_t tmp[OGS_MAX_SDU_LEN]; + char *_container = + "4080ab0f1014" + "c59800018000bf06 ec4d00100302c000 0000000015a80014 06720af00348f100" + "13d03bc58414903b c58809401de2c210 044013f212249010 127dad808fd50398" + "381c08fd50398380 5f5037868baa010c 846fb057874162d6 2e821f42f2e159f8" + "21d09c0009e28aa1 a0012d888026d060 0040800806607200 3e415250d4621020" + "81843423c1350022 14d6dfb0a0b06502 c402000004008177 faab4677235334a0" + "e867213e80403000 01004e4002450000 4e400246000000f1 1000043a000000f1" + "10001f20a0000022"; + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); + + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = + S1AP_ProcedureCode_id_HandoverPreparation; + initiatingMessage->criticality = S1AP_Criticality_reject; + initiatingMessage->value.present = + S1AP_InitiatingMessage__value_PR_HandoverRequired; + + HandoverRequired = &initiatingMessage->value.choice.HandoverRequired; + + ie = CALLOC(1, sizeof(S1AP_HandoverRequiredIEs_t)); + ASN_SEQUENCE_ADD(&HandoverRequired->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_HandoverRequiredIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_HandoverRequiredIEs_t)); + ASN_SEQUENCE_ADD(&HandoverRequired->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_HandoverRequiredIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_HandoverRequiredIEs_t)); + ASN_SEQUENCE_ADD(&HandoverRequired->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_HandoverType; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_HandoverRequiredIEs__value_PR_HandoverType; + + HandoverType = &ie->value.choice.HandoverType; + + *HandoverType = handover_type; + + ie = CALLOC(1, sizeof(S1AP_HandoverRequiredIEs_t)); + ASN_SEQUENCE_ADD(&HandoverRequired->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_Cause; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_HandoverRequiredIEs__value_PR_Cause; + + Cause = &ie->value.choice.Cause; + + Cause->present = group; + Cause->choice.radioNetwork = cause; + + ie = CALLOC(1, sizeof(S1AP_HandoverRequiredIEs_t)); + ASN_SEQUENCE_ADD(&HandoverRequired->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_TargetID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_HandoverRequiredIEs__value_PR_TargetID; + + TargetID = &ie->value.choice.TargetID; + + TargetID->present = S1AP_TargetID_PR_targeteNB_ID; + targeteNB_ID = CALLOC(1, sizeof(S1AP_TargeteNB_ID_t)); + TargetID->choice.targeteNB_ID = targeteNB_ID; + + global_ENB_ID = &targeteNB_ID->global_ENB_ID; + ogs_s1ap_buffer_to_OCTET_STRING( + &test_ue->e_tai.plmn_id, OGS_PLMN_ID_LEN, + &global_ENB_ID->pLMNidentity); + ogs_s1ap_uint32_to_ENB_ID(present, enb_id, &global_ENB_ID->eNB_ID); + + selected_TAI = &targeteNB_ID->selected_TAI; + ogs_asn_uint16_to_OCTET_STRING(test_ue->e_tai.tac, &selected_TAI->tAC); + ogs_s1ap_buffer_to_OCTET_STRING( + &test_ue->e_tai.plmn_id, + OGS_PLMN_ID_LEN, &selected_TAI->pLMNidentity); + + ie = CALLOC(1, sizeof(S1AP_HandoverRequiredIEs_t)); + ASN_SEQUENCE_ADD(&HandoverRequired->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_Source_ToTarget_TransparentContainer; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_HandoverRequiredIEs__value_PR_Source_ToTarget_TransparentContainer; + + Source_ToTarget_TransparentContainer = + &ie->value.choice.Source_ToTarget_TransparentContainer; + + OGS_HEX(_container, strlen(_container), tmp), + + Source_ToTarget_TransparentContainer->size = 206; + Source_ToTarget_TransparentContainer->buf = + CALLOC(Source_ToTarget_TransparentContainer->size, sizeof(uint8_t)); + memcpy(Source_ToTarget_TransparentContainer->buf, + tmp, Source_ToTarget_TransparentContainer->size); + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_handover_request_ack(test_ue_t *test_ue) +{ + int rv; + + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + S1AP_S1AP_PDU_t pdu; + S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; + S1AP_HandoverRequestAcknowledge_t *HandoverRequestAcknowledge = NULL; + + S1AP_HandoverRequestAcknowledgeIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_E_RABAdmittedList_t *E_RABAdmittedList = NULL; + S1AP_Target_ToSource_TransparentContainer_t + *Target_ToSource_TransparentContainer = NULL; + + char hexbuf[OGS_MAX_SDU_LEN]; + const char *payload = + "00 80810bf900d8af40 00a0339057801f47 88009e81de2c20a4" + "81de2c404a00ef16 2000010044013f21 2249008093efd243 3914cd2aa0a0142f" + "f2214d6dfb82c194 0b10080000020040 bbfd55aeab41ad80 8fd50398381c08fd" + "503983804d037868 baa016423342bc3a 18b58fa084ca833f a17970acfc10e84e" + "0004f14550d00096 c88900"; + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome = + CALLOC(1, sizeof(S1AP_SuccessfulOutcome_t)); + + successfulOutcome = pdu.choice.successfulOutcome; + successfulOutcome->procedureCode = S1AP_ProcedureCode_id_HandoverResourceAllocation; + successfulOutcome->criticality = S1AP_Criticality_reject; + successfulOutcome->value.present = + S1AP_SuccessfulOutcome__value_PR_HandoverRequestAcknowledge; + + HandoverRequestAcknowledge = + &successfulOutcome->value.choice.HandoverRequestAcknowledge; + + ie = CALLOC(1, sizeof(S1AP_HandoverRequestAcknowledgeIEs_t)); + ASN_SEQUENCE_ADD(&HandoverRequestAcknowledge->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_HandoverRequestAcknowledgeIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_HandoverRequestAcknowledgeIEs_t)); + ASN_SEQUENCE_ADD(&HandoverRequestAcknowledge->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_HandoverRequestAcknowledgeIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + test_ue->enb_ue_s1ap_id++; + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_HandoverRequestAcknowledgeIEs_t)); + ASN_SEQUENCE_ADD(&HandoverRequestAcknowledge->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_E_RABAdmittedList; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_HandoverRequestAcknowledgeIEs__value_PR_E_RABAdmittedList; + + E_RABAdmittedList = &ie->value.choice.E_RABAdmittedList; + ogs_list_for_each(&test_ue->sess_list, sess) { + ogs_list_for_each(&sess->bearer_list, bearer) { + S1AP_E_RABAdmittedItemIEs_t *item = NULL; + S1AP_E_RABAdmittedItem_t *e_rab = NULL; + + ogs_gtp_f_teid_t f_teid; + ogs_ip_t ip; + int len; + + item = CALLOC(1, sizeof(S1AP_E_RABAdmittedItemIEs_t)); + ASN_SEQUENCE_ADD(&E_RABAdmittedList->list, item); + + item->id = S1AP_ProtocolIE_ID_id_E_RABAdmittedItem; + item->criticality = S1AP_Criticality_ignore; + item->value.present = + S1AP_E_RABAdmittedItemIEs__value_PR_E_RABAdmittedItem; + + e_rab = &item->value.choice.E_RABAdmittedItem; + + e_rab->e_RAB_ID = bearer->ebi; + + rv = ogs_gtp_sockaddr_to_f_teid( + bearer->enb_s1u_addr, bearer->enb_s1u_addr6, &f_teid, &len); + ogs_assert(rv == OGS_OK); + + rv = ogs_gtp_f_teid_to_ip(&f_teid, &ip); + ogs_assert(rv == OGS_OK); + + rv = ogs_asn_ip_to_BIT_STRING(&ip, &e_rab->transportLayerAddress); + ogs_assert(rv == OGS_OK); + ogs_asn_uint32_to_OCTET_STRING( + bearer->enb_s1u_teid, &e_rab->gTP_TEID); + + e_rab->dL_transportLayerAddress = + (S1AP_TransportLayerAddress_t *) + CALLOC(1, sizeof(S1AP_TransportLayerAddress_t)); + rv = ogs_asn_ip_to_BIT_STRING(&ip, e_rab->dL_transportLayerAddress); + ogs_assert(rv == OGS_OK); + e_rab->dL_gTP_TEID = (S1AP_GTP_TEID_t *) + CALLOC(1, sizeof(S1AP_GTP_TEID_t)); + ogs_asn_uint32_to_OCTET_STRING( + bearer->enb_s1u_teid+10, e_rab->dL_gTP_TEID); + + e_rab->uL_TransportLayerAddress = + (S1AP_TransportLayerAddress_t *) + CALLOC(1, sizeof(S1AP_TransportLayerAddress_t)); + rv = ogs_asn_ip_to_BIT_STRING(&ip, e_rab->uL_TransportLayerAddress); + ogs_assert(rv == OGS_OK); + e_rab->uL_GTP_TEID = (S1AP_GTP_TEID_t *) + CALLOC(1, sizeof(S1AP_GTP_TEID_t)); + ogs_asn_uint32_to_OCTET_STRING( + bearer->enb_s1u_teid+20, e_rab->uL_GTP_TEID); + } + } + + ie = CALLOC(1, sizeof(S1AP_HandoverRequestAcknowledgeIEs_t)); + ASN_SEQUENCE_ADD(&HandoverRequestAcknowledge->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_Target_ToSource_TransparentContainer; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_HandoverRequestAcknowledgeIEs__value_PR_Target_ToSource_TransparentContainer; + + Target_ToSource_TransparentContainer = + &ie->value.choice.Target_ToSource_TransparentContainer; + + ogs_s1ap_buffer_to_OCTET_STRING( + OGS_HEX(payload, strlen(payload), hexbuf), 132, + Target_ToSource_TransparentContainer); + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_enb_status_transfer(test_ue_t *test_ue) +{ + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_ENBStatusTransfer_t *ENBStatusTransfer = + NULL; + + S1AP_ENBStatusTransferIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_ENB_StatusTransfer_TransparentContainer_t + *ENB_StatusTransfer_TransparentContainer = NULL; + S1AP_Bearers_SubjectToStatusTransferList_t + *Bearers_SubjectToStatusTransferList = NULL; + S1AP_Bearers_SubjectToStatusTransfer_ItemIEs_t *ie2 = NULL; + S1AP_Bearers_SubjectToStatusTransfer_Item_t *item = NULL; + + ogs_assert(test_ue); + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); + + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = + S1AP_ProcedureCode_id_eNBStatusTransfer; + initiatingMessage->criticality = S1AP_Criticality_ignore; + initiatingMessage->value.present = + S1AP_InitiatingMessage__value_PR_ENBStatusTransfer; + + ENBStatusTransfer = &initiatingMessage->value.choice.ENBStatusTransfer; + + ie = CALLOC(1, sizeof(S1AP_ENBStatusTransferIEs_t)); + ASN_SEQUENCE_ADD(&ENBStatusTransfer->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_ENBStatusTransferIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_ENBStatusTransferIEs_t)); + ASN_SEQUENCE_ADD(&ENBStatusTransfer->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_ENBStatusTransferIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_ENBStatusTransferIEs_t)); + ASN_SEQUENCE_ADD(&ENBStatusTransfer->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_StatusTransfer_TransparentContainer; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_ENBStatusTransferIEs__value_PR_ENB_StatusTransfer_TransparentContainer; + + ENB_StatusTransfer_TransparentContainer = + &ie->value.choice.ENB_StatusTransfer_TransparentContainer; + + Bearers_SubjectToStatusTransferList = + &ENB_StatusTransfer_TransparentContainer-> + bearers_SubjectToStatusTransferList; + + ogs_list_for_each(&test_ue->sess_list, sess) { + ogs_list_for_each(&sess->bearer_list, bearer) { + ie2 = CALLOC( + 1, sizeof(S1AP_Bearers_SubjectToStatusTransfer_ItemIEs_t)); + ASN_SEQUENCE_ADD(&Bearers_SubjectToStatusTransferList->list, ie2); + + ie2->id = + S1AP_ProtocolIE_ID_id_Bearers_SubjectToStatusTransfer_Item; + ie2->criticality = S1AP_Criticality_ignore; + ie2->value.present = S1AP_Bearers_SubjectToStatusTransfer_ItemIEs__value_PR_Bearers_SubjectToStatusTransfer_Item; + + item = &ie2->value.choice.Bearers_SubjectToStatusTransfer_Item; + item->e_RAB_ID = bearer->ebi; + item->uL_COUNTvalue.pDCP_SN = 75; + item->dL_COUNTvalue.pDCP_SN = 17; + } + } + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_handover_notify(test_ue_t *test_ue) +{ + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_HandoverNotify_t *HandoverNotify = NULL; + + S1AP_HandoverNotifyIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_EUTRAN_CGI_t *EUTRAN_CGI = NULL; + S1AP_TAI_t *TAI = NULL; + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); + + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = + S1AP_ProcedureCode_id_HandoverNotification; + initiatingMessage->criticality = S1AP_Criticality_ignore; + initiatingMessage->value.present = + S1AP_InitiatingMessage__value_PR_HandoverNotify; + + HandoverNotify = &initiatingMessage->value.choice.HandoverNotify; + + ie = CALLOC(1, sizeof(S1AP_HandoverNotifyIEs_t)); + ASN_SEQUENCE_ADD(&HandoverNotify->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_HandoverNotifyIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_HandoverNotifyIEs_t)); + ASN_SEQUENCE_ADD(&HandoverNotify->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_HandoverNotifyIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_HandoverNotifyIEs_t)); + ASN_SEQUENCE_ADD(&HandoverNotify->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_HandoverNotifyIEs__value_PR_EUTRAN_CGI; + + EUTRAN_CGI = &ie->value.choice.EUTRAN_CGI; + + ogs_s1ap_buffer_to_OCTET_STRING( + &test_ue->e_cgi.plmn_id, + OGS_PLMN_ID_LEN, &EUTRAN_CGI->pLMNidentity); + EUTRAN_CGI->cell_ID.size = 4; + EUTRAN_CGI->cell_ID.buf = CALLOC( + EUTRAN_CGI->cell_ID.size, sizeof(uint8_t)); + ogs_assert(EUTRAN_CGI->cell_ID.buf); + EUTRAN_CGI->cell_ID.buf[0] = (test_ue->e_cgi.cell_id >> 24); + EUTRAN_CGI->cell_ID.buf[1] = (test_ue->e_cgi.cell_id >> 16); + EUTRAN_CGI->cell_ID.buf[2] = (test_ue->e_cgi.cell_id >> 8); + EUTRAN_CGI->cell_ID.buf[3] = (test_ue->e_cgi.cell_id); + EUTRAN_CGI->cell_ID.bits_unused = 4; + + ie = CALLOC(1, sizeof(S1AP_HandoverNotifyIEs_t)); + ASN_SEQUENCE_ADD(&HandoverNotify->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_TAI; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_HandoverNotifyIEs__value_PR_TAI; + + TAI = &ie->value.choice.TAI; + + ogs_asn_uint16_to_OCTET_STRING(test_ue->e_tai.tac, &TAI->tAC); + ogs_s1ap_buffer_to_OCTET_STRING( + &test_ue->e_tai.plmn_id, OGS_PLMN_ID_LEN, &TAI->pLMNidentity); + + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_handover_cancel(test_ue_t *test_ue, + S1AP_Cause_PR group, long cause) +{ + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_HandoverCancel_t *HandoverCancel = NULL; + + S1AP_HandoverCancelIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_ENB_UE_S1AP_ID_t *ENB_UE_S1AP_ID = NULL; + S1AP_Cause_t *Cause = NULL; + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage = CALLOC(1, sizeof(S1AP_InitiatingMessage_t)); + + initiatingMessage = pdu.choice.initiatingMessage; + initiatingMessage->procedureCode = S1AP_ProcedureCode_id_HandoverCancel; + initiatingMessage->criticality = S1AP_Criticality_reject; + initiatingMessage->value.present = + S1AP_InitiatingMessage__value_PR_HandoverCancel; + + HandoverCancel = &initiatingMessage->value.choice.HandoverCancel; + + ie = CALLOC(1, sizeof(S1AP_HandoverCancelIEs_t)); + ASN_SEQUENCE_ADD(&HandoverCancel->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_HandoverCancelIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_HandoverCancelIEs_t)); + ASN_SEQUENCE_ADD(&HandoverCancel->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_HandoverCancelIEs__value_PR_ENB_UE_S1AP_ID; + + ENB_UE_S1AP_ID = &ie->value.choice.ENB_UE_S1AP_ID; + + *ENB_UE_S1AP_ID = test_ue->enb_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_HandoverCancelIEs_t)); + ASN_SEQUENCE_ADD(&HandoverCancel->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_Cause; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_HandoverCancelIEs__value_PR_Cause; + + Cause = &ie->value.choice.Cause; + + Cause->present = group; + Cause->choice.radioNetwork = cause; + + return ogs_s1ap_encode(&pdu); +} + +ogs_pkbuf_t *test_s1ap_build_handover_failure(test_ue_t *test_ue, + S1AP_Cause_PR group, long cause) +{ + int rv; + + S1AP_S1AP_PDU_t pdu; + S1AP_UnsuccessfulOutcome_t *unsuccessfulOutcome = NULL; + S1AP_HandoverFailure_t *HandoverFailure = NULL; + + S1AP_HandoverFailureIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_Cause_t *Cause = NULL; + + memset(&pdu, 0, sizeof (S1AP_S1AP_PDU_t)); + pdu.present = S1AP_S1AP_PDU_PR_unsuccessfulOutcome; + pdu.choice.unsuccessfulOutcome = + CALLOC(1, sizeof(S1AP_UnsuccessfulOutcome_t)); + + unsuccessfulOutcome = pdu.choice.unsuccessfulOutcome; + unsuccessfulOutcome->procedureCode = + S1AP_ProcedureCode_id_HandoverResourceAllocation; + unsuccessfulOutcome->criticality = S1AP_Criticality_reject; + unsuccessfulOutcome->value.present = + S1AP_UnsuccessfulOutcome__value_PR_HandoverFailure; + + HandoverFailure = &unsuccessfulOutcome->value.choice.HandoverFailure; + + ie = CALLOC(1, sizeof(S1AP_HandoverFailureIEs_t)); + ASN_SEQUENCE_ADD(&HandoverFailure->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = + S1AP_HandoverFailureIEs__value_PR_MME_UE_S1AP_ID; + + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + + *MME_UE_S1AP_ID = test_ue->mme_ue_s1ap_id; + + ie = CALLOC(1, sizeof(S1AP_HandoverFailureIEs_t)); + ASN_SEQUENCE_ADD(&HandoverFailure->protocolIEs, ie); + + ie->id = S1AP_ProtocolIE_ID_id_Cause; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_HandoverFailureIEs__value_PR_Cause; + + Cause = &ie->value.choice.Cause; + + Cause->present = group; + Cause->choice.radioNetwork = cause; + + return ogs_s1ap_encode(&pdu); +} + +#define TEST_S1AP_MAX_MESSAGE 64 + +ogs_pkbuf_t *test_s1ap_build_invalid_packet(int i) +{ + ogs_pkbuf_t *pkbuf = NULL; + const char *payload[TEST_S1AP_MAX_MESSAGE] = { + "0011002100000300 3b40080062f22400 0001700040000700 00004062f224002c" + "00030a0100", + "", + }; + + uint16_t len[TEST_S1AP_MAX_MESSAGE] = { + 37, + 0, + }; + + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); + + return pkbuf; +} + +ogs_pkbuf_t *test_s1ap_build_enb_configuration_transfer(int i) +{ + ogs_pkbuf_t *pkbuf = NULL; + const char *payload[TEST_S1AP_MAX_MESSAGE] = { + "0028" + "403b000001008140 3440049699000004 3004969900020004 969900001f200496" + "9900020000000098 401341f0ac110e02 0000009940070200 f8ac110e02", + "0028" + "403b000001008140 344004969900001f 2004969900020004 9699000004300496" + "9900020000000098 401341f0ac110e02 0000009940070200 f8ac110e02", + "", + + "", + "", + "", + + "", + "", + "", + + }; + uint16_t len[TEST_S1AP_MAX_MESSAGE] = { + 63, + 63, + 0, + + 0, + 0, + 0, + + 0, + 0, + 0, + }; + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); + + return pkbuf; +} diff --git a/tests/common/s1ap-build.h b/tests/common/s1ap-build.h new file mode 100644 index 000000000..63f251872 --- /dev/null +++ b/tests/common/s1ap-build.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TEST_S1AP_BUILD_H +#define TEST_S1AP_BUILD_H + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_pkbuf_t *test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR present, uint32_t enb_id); + +ogs_pkbuf_t *test_s1ap_build_initial_ue_message( + test_ue_t *test_ue, ogs_pkbuf_t *emmbuf, uint8_t cause, bool s_tmsi); +ogs_pkbuf_t *test_s1ap_build_uplink_nas_transport( + test_ue_t *test_ue, ogs_pkbuf_t *nasbuf); +ogs_pkbuf_t *tests1ap_build_ue_radio_capability_info_indication( + test_ue_t *test_ue); +ogs_pkbuf_t *test_s1ap_build_initial_context_setup_response(test_ue_t *test_ue); +ogs_pkbuf_t *test_s1ap_build_initial_context_setup_failure(test_ue_t *test_ue, + S1AP_Cause_PR group, long cause); + +ogs_pkbuf_t *test_s1ap_build_ue_context_modification_response( + test_ue_t *test_ue); +ogs_pkbuf_t *test_s1ap_build_ue_context_release_request(test_ue_t *test_ue, + S1AP_Cause_PR group, long cause); + +ogs_pkbuf_t *test_s1ap_build_ue_context_release_complete(test_ue_t *test_ue); +ogs_pkbuf_t *test_s1ap_build_e_rab_setup_response(test_bearer_t *bearer); +ogs_pkbuf_t *test_s1ap_build_e_rab_modify_response(test_bearer_t *bearer); +ogs_pkbuf_t *test_s1ap_build_e_rab_release_response(test_bearer_t *bearer); + +ogs_pkbuf_t *test_s1ap_build_path_switch_request(test_ue_t *test_ue); + +ogs_pkbuf_t *test_s1ap_build_handover_required( + test_ue_t *test_ue, S1AP_HandoverType_t handover_type, + S1AP_ENB_ID_PR present, uint32_t enb_id, + S1AP_Cause_PR group, long cause); +ogs_pkbuf_t *test_s1ap_build_handover_request_ack(test_ue_t *test_ue); +ogs_pkbuf_t *test_s1ap_build_enb_status_transfer(test_ue_t *test_ue); +ogs_pkbuf_t *test_s1ap_build_handover_notify(test_ue_t *test_ue); + +ogs_pkbuf_t *test_s1ap_build_handover_cancel(test_ue_t *test_ue, + S1AP_Cause_PR group, long cause); +ogs_pkbuf_t *test_s1ap_build_handover_failure(test_ue_t *test_ue, + S1AP_Cause_PR group, long cause); + +ogs_pkbuf_t *test_s1ap_build_invalid_packet(int i); +ogs_pkbuf_t *test_s1ap_build_enb_configuration_transfer(int i); + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_S1AP_BUILD_H */ diff --git a/tests/common/s1ap-handler.c b/tests/common/s1ap-handler.c new file mode 100644 index 000000000..812596569 --- /dev/null +++ b/tests/common/s1ap-handler.c @@ -0,0 +1,401 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * alos1 with this program. If not, see . + */ + +#include "test-common.h" + +void tests1ap_handle_s1_setup_response(ogs_s1ap_message_t *message) +{ + S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; + S1AP_S1SetupResponse_t *S1SetupResponse = NULL; + + S1AP_S1SetupResponseIEs_t *ie = NULL; + + ogs_assert(message); + + successfulOutcome = message->choice.successfulOutcome; + ogs_assert(successfulOutcome); + S1SetupResponse = &successfulOutcome->value.choice.S1SetupResponse; + ogs_assert(S1SetupResponse); + + ogs_debug("S1 setup response"); +} + +void tests1ap_handle_downlink_nas_transport( + test_ue_t *test_ue, ogs_s1ap_message_t *message) +{ + int i; + + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_DownlinkNASTransport_t *DownlinkNASTransport = NULL; + + S1AP_DownlinkNASTransport_IEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_NAS_PDU_t *NAS_PDU = NULL; + + ogs_assert(test_ue); + ogs_assert(message); + + initiatingMessage = message->choice.initiatingMessage; + ogs_assert(initiatingMessage); + DownlinkNASTransport = + &initiatingMessage->value.choice.DownlinkNASTransport; + ogs_assert(DownlinkNASTransport); + + for (i = 0; i < DownlinkNASTransport->protocolIEs.list.count; i++) { + ie = DownlinkNASTransport->protocolIEs.list.array[i]; + switch (ie->id) { + case S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID: + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + break; + case S1AP_ProtocolIE_ID_id_NAS_PDU: + NAS_PDU = &ie->value.choice.NAS_PDU; + break; + default: + break; + } + } + + if (MME_UE_S1AP_ID) + test_ue->mme_ue_s1ap_id = *MME_UE_S1AP_ID; + + if (NAS_PDU) + tests1ap_send_to_nas(test_ue, NAS_PDU); +} + +void tests1ap_handle_initial_context_setup_request( + test_ue_t *test_ue, ogs_s1ap_message_t *message) +{ + int i, rv; + test_bearer_t *bearer = NULL; + + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_InitialContextSetupRequest_t *InitialContextSetupRequest = NULL; + + S1AP_InitialContextSetupRequestIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_NAS_PDU_t *NAS_PDU = NULL; + S1AP_E_RABToBeSetupListCtxtSUReq_t *E_RABToBeSetupListCtxtSUReq = NULL; + + ogs_assert(test_ue); + ogs_assert(message); + + initiatingMessage = message->choice.initiatingMessage; + ogs_assert(initiatingMessage); + InitialContextSetupRequest = + &initiatingMessage->value.choice.InitialContextSetupRequest; + ogs_assert(InitialContextSetupRequest); + + for (i = 0; i < InitialContextSetupRequest->protocolIEs.list.count; i++) { + ie = InitialContextSetupRequest->protocolIEs.list.array[i]; + switch (ie->id) { + case S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID: + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + break; + case S1AP_ProtocolIE_ID_id_E_RABToBeSetupListCtxtSUReq: + E_RABToBeSetupListCtxtSUReq = + &ie->value.choice.E_RABToBeSetupListCtxtSUReq; + break; + default: + break; + } + } + + if (MME_UE_S1AP_ID) + test_ue->mme_ue_s1ap_id = *MME_UE_S1AP_ID; + + for (i = 0; i < E_RABToBeSetupListCtxtSUReq->list.count; i++) { + S1AP_E_RABToBeSetupItemCtxtSUReqIEs_t *ie2 = NULL; + S1AP_E_RABToBeSetupItemCtxtSUReq_t *e_rab = NULL; + + ie2 = (S1AP_E_RABToBeSetupItemCtxtSUReqIEs_t *) + E_RABToBeSetupListCtxtSUReq->list.array[i]; + ogs_assert(ie2); + e_rab = &ie2->value.choice.E_RABToBeSetupItemCtxtSUReq; + + if (e_rab->nAS_PDU) + tests1ap_send_to_nas(test_ue, e_rab->nAS_PDU); + + bearer = test_bearer_find_by_ue_ebi(test_ue, e_rab->e_RAB_ID); + ogs_assert(bearer); + + memcpy(&bearer->sgw_s1u_teid, e_rab->gTP_TEID.buf, + sizeof(bearer->sgw_s1u_teid)); + bearer->sgw_s1u_teid = be32toh(bearer->sgw_s1u_teid); + rv = ogs_asn_BIT_STRING_to_ip( + &e_rab->transportLayerAddress, &bearer->sgw_s1u_ip); + ogs_assert(rv == OGS_OK); + } +} + +void tests1ap_handle_ue_release_context_command( + test_ue_t *test_ue, ogs_s1ap_message_t *message) +{ + int i, rv; + test_bearer_t *bearer = NULL; + + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_UEContextReleaseCommand_t *UEContextReleaseCommand = NULL; + + S1AP_UEContextReleaseCommand_IEs_t *ie = NULL; + S1AP_UE_S1AP_IDs_t *UE_S1AP_IDs = NULL; + + ogs_assert(test_ue); + ogs_assert(message); + + initiatingMessage = message->choice.initiatingMessage; + ogs_assert(initiatingMessage); + UEContextReleaseCommand = + &initiatingMessage->value.choice.UEContextReleaseCommand; + ogs_assert(UEContextReleaseCommand); + + for (i = 0; i < UEContextReleaseCommand->protocolIEs.list.count; i++) { + ie = UEContextReleaseCommand->protocolIEs.list.array[i]; + switch (ie->id) { + case S1AP_ProtocolIE_ID_id_UE_S1AP_IDs: + UE_S1AP_IDs = &ie->value.choice.UE_S1AP_IDs; + break; + default: + break; + } + } + + if (UE_S1AP_IDs) { + if (UE_S1AP_IDs->present == S1AP_UE_S1AP_IDs_PR_uE_S1AP_ID_pair) { + test_ue->mme_ue_s1ap_id = + UE_S1AP_IDs->choice.uE_S1AP_ID_pair->mME_UE_S1AP_ID; + test_ue->enb_ue_s1ap_id = + UE_S1AP_IDs->choice.uE_S1AP_ID_pair->eNB_UE_S1AP_ID; + } + } +} + +void tests1ap_handle_e_rab_setup_request( + test_ue_t *test_ue, ogs_s1ap_message_t *message) +{ + int i, rv; + test_bearer_t *bearer = NULL; + + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_E_RABSetupRequest_t *E_RABSetupRequest = NULL; + + S1AP_E_RABSetupRequestIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_NAS_PDU_t *NAS_PDU = NULL; + S1AP_E_RABToBeSetupListBearerSUReq_t *E_RABToBeSetupListBearerSUReq = NULL; + + ogs_assert(test_ue); + ogs_assert(message); + + initiatingMessage = message->choice.initiatingMessage; + ogs_assert(initiatingMessage); + E_RABSetupRequest = + &initiatingMessage->value.choice.E_RABSetupRequest; + ogs_assert(E_RABSetupRequest); + + for (i = 0; i < E_RABSetupRequest->protocolIEs.list.count; i++) { + ie = E_RABSetupRequest->protocolIEs.list.array[i]; + switch (ie->id) { + case S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID: + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + break; + case S1AP_ProtocolIE_ID_id_E_RABToBeSetupListBearerSUReq: + E_RABToBeSetupListBearerSUReq = + &ie->value.choice.E_RABToBeSetupListBearerSUReq; + break; + default: + break; + } + } + + if (MME_UE_S1AP_ID) + test_ue->mme_ue_s1ap_id = *MME_UE_S1AP_ID; + + for (i = 0; i < E_RABToBeSetupListBearerSUReq->list.count; i++) { + S1AP_E_RABToBeSetupItemBearerSUReqIEs_t *ie2 = NULL; + S1AP_E_RABToBeSetupItemBearerSUReq_t *e_rab = NULL; + + ie2 = (S1AP_E_RABToBeSetupItemBearerSUReqIEs_t *) + E_RABToBeSetupListBearerSUReq->list.array[i]; + ogs_assert(ie2); + e_rab = &ie2->value.choice.E_RABToBeSetupItemBearerSUReq; + + tests1ap_send_to_nas(test_ue, &e_rab->nAS_PDU); + + bearer = test_bearer_find_by_ue_ebi(test_ue, e_rab->e_RAB_ID); + ogs_assert(bearer); + + memcpy(&bearer->sgw_s1u_teid, e_rab->gTP_TEID.buf, + sizeof(bearer->sgw_s1u_teid)); + bearer->sgw_s1u_teid = be32toh(bearer->sgw_s1u_teid); + rv = ogs_asn_BIT_STRING_to_ip( + &e_rab->transportLayerAddress, &bearer->sgw_s1u_ip); + ogs_assert(rv == OGS_OK); + } +} + +void tests1ap_handle_e_rab_modify_request( + test_ue_t *test_ue, ogs_s1ap_message_t *message) +{ + int i, rv; + test_bearer_t *bearer = NULL; + + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_E_RABModifyRequest_t *E_RABModifyRequest = NULL; + + S1AP_E_RABModifyRequestIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_NAS_PDU_t *NAS_PDU = NULL; + S1AP_E_RABToBeModifiedListBearerModReq_t *E_RABToBeModifiedListBearerModReq; + + ogs_assert(test_ue); + ogs_assert(message); + + initiatingMessage = message->choice.initiatingMessage; + ogs_assert(initiatingMessage); + E_RABModifyRequest = &initiatingMessage->value.choice.E_RABModifyRequest; + ogs_assert(E_RABModifyRequest); + + for (i = 0; i < E_RABModifyRequest->protocolIEs.list.count; i++) { + ie = E_RABModifyRequest->protocolIEs.list.array[i]; + switch (ie->id) { + case S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID: + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + break; + case S1AP_ProtocolIE_ID_id_E_RABToBeModifiedListBearerModReq: + E_RABToBeModifiedListBearerModReq = + &ie->value.choice.E_RABToBeModifiedListBearerModReq; + break; + default: + break; + } + } + + if (MME_UE_S1AP_ID) + test_ue->mme_ue_s1ap_id = *MME_UE_S1AP_ID; + + for (i = 0; i < E_RABToBeModifiedListBearerModReq->list.count; i++) { + S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *ie2 = NULL; + S1AP_E_RABToBeModifiedItemBearerModReq_t *e_rab = NULL; + + ie2 = (S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *) + E_RABToBeModifiedListBearerModReq->list.array[i]; + ogs_assert(ie2); + e_rab = &ie2->value.choice.E_RABToBeModifiedItemBearerModReq; + + tests1ap_send_to_nas(test_ue, &e_rab->nAS_PDU); + } +} + +void tests1ap_handle_e_rab_release_command( + test_ue_t *test_ue, ogs_s1ap_message_t *message) +{ + int i, rv; + test_bearer_t *bearer = NULL; + + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_E_RABReleaseCommand_t *E_RABReleaseCommand = NULL; + + S1AP_E_RABReleaseCommandIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + S1AP_NAS_PDU_t *NAS_PDU = NULL; + S1AP_E_RABList_t *E_RABList = NULL; + + ogs_assert(test_ue); + ogs_assert(message); + + initiatingMessage = message->choice.initiatingMessage; + ogs_assert(initiatingMessage); + E_RABReleaseCommand = + &initiatingMessage->value.choice.E_RABReleaseCommand; + ogs_assert(E_RABReleaseCommand); + + for (i = 0; i < E_RABReleaseCommand->protocolIEs.list.count; i++) { + ie = E_RABReleaseCommand->protocolIEs.list.array[i]; + switch (ie->id) { + case S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID: + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + break; + case S1AP_ProtocolIE_ID_id_E_RABToBeReleasedList: + E_RABList = &ie->value.choice.E_RABList; + break; + case S1AP_ProtocolIE_ID_id_NAS_PDU: + NAS_PDU = &ie->value.choice.NAS_PDU; + break; + default: + break; + } + } + + if (MME_UE_S1AP_ID) + test_ue->mme_ue_s1ap_id = *MME_UE_S1AP_ID; + + for (i = 0; i < E_RABList->list.count; i++) { + S1AP_E_RABItemIEs_t *ie2 = NULL; + S1AP_E_RABItem_t *e_rab = NULL; + + ie2 = (S1AP_E_RABItemIEs_t *)E_RABList->list.array[i]; + ogs_assert(ie2); + e_rab = &ie2->value.choice.E_RABItem; + ogs_assert(e_rab); + } + + if (NAS_PDU) + tests1ap_send_to_nas(test_ue, NAS_PDU); +} + +void tests1ap_handle_handover_request( + test_ue_t *test_ue, ogs_s1ap_message_t *message) +{ + int i, rv; + + S1AP_S1AP_PDU_t pdu; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_HandoverRequest_t *HandoverRequest = NULL; + + S1AP_HandoverRequestIEs_t *ie = NULL; + S1AP_MME_UE_S1AP_ID_t *MME_UE_S1AP_ID = NULL; + + ogs_assert(test_ue); + ogs_assert(message); + + initiatingMessage = message->choice.initiatingMessage; + ogs_assert(initiatingMessage); + HandoverRequest = &initiatingMessage->value.choice.HandoverRequest; + ogs_assert(HandoverRequest); + + for (i = 0; i < HandoverRequest->protocolIEs.list.count; i++) { + ie = HandoverRequest->protocolIEs.list.array[i]; + switch (ie->id) { + case S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID: + MME_UE_S1AP_ID = &ie->value.choice.MME_UE_S1AP_ID; + break; + default: + break; + } + } + + if (MME_UE_S1AP_ID) + test_ue->mme_ue_s1ap_id = *MME_UE_S1AP_ID; +} diff --git a/tests/common/s1ap-handler.h b/tests/common/s1ap-handler.h new file mode 100644 index 000000000..667a3a397 --- /dev/null +++ b/tests/common/s1ap-handler.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TEST_S1AP_HANDLE_H +#define TEST_S1AP_HANDLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +void tests1ap_handle_s1_setup_response(ogs_s1ap_message_t *message); +void tests1ap_handle_downlink_nas_transport( + test_ue_t *test_ue, ogs_s1ap_message_t *message); +void tests1ap_handle_initial_context_setup_request( + test_ue_t *test_ue, ogs_s1ap_message_t *message); +void tests1ap_handle_ue_release_context_command( + test_ue_t *test_ue, ogs_s1ap_message_t *message); +void tests1ap_handle_e_rab_setup_request( + test_ue_t *test_ue, ogs_s1ap_message_t *message); +void tests1ap_handle_e_rab_modify_request( + test_ue_t *test_ue, ogs_s1ap_message_t *message); +void tests1ap_handle_e_rab_release_command( + test_ue_t *test_ue, ogs_s1ap_message_t *message); + +void tests1ap_handle_handover_request( + test_ue_t *test_ue, ogs_s1ap_message_t *message); + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_S1AP_HANDLE_H */ diff --git a/tests/common/s1ap-path.c b/tests/common/s1ap-path.c new file mode 100644 index 000000000..80a179725 --- /dev/null +++ b/tests/common/s1ap-path.c @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +void tests1ap_recv(test_ue_t *test_ue, ogs_pkbuf_t *pkbuf) +{ + int rv; + ogs_s1ap_message_t message; + + S1AP_S1AP_PDU_t *pdu = NULL; + S1AP_InitiatingMessage_t *initiatingMessage = NULL; + S1AP_SuccessfulOutcome_t *successfulOutcome = NULL; + S1AP_UnsuccessfulOutcome_t *unsuccessfulOutcome = NULL; + + ogs_assert(pkbuf); + + rv = ogs_s1ap_decode(&message, pkbuf); + ogs_assert(rv == OGS_OK); + + pdu = &message; + ogs_assert(pdu); + + switch (pdu->present) { + case S1AP_S1AP_PDU_PR_initiatingMessage: + initiatingMessage = pdu->choice.initiatingMessage; + ogs_assert(initiatingMessage); + + switch (initiatingMessage->procedureCode) { + case S1AP_ProcedureCode_id_downlinkNASTransport: + tests1ap_handle_downlink_nas_transport(test_ue, pdu); + break; + case S1AP_ProcedureCode_id_InitialContextSetup: + tests1ap_handle_initial_context_setup_request(test_ue, pdu); + break; + case S1AP_ProcedureCode_id_UEContextModification: + tests1ap_handle_ue_release_context_command(test_ue, pdu); + break; + case S1AP_ProcedureCode_id_UEContextRelease: + tests1ap_handle_ue_release_context_command(test_ue, pdu); + break; + case S1AP_ProcedureCode_id_E_RABSetup: + tests1ap_handle_e_rab_setup_request(test_ue, pdu); + break; + case S1AP_ProcedureCode_id_E_RABModify: + tests1ap_handle_e_rab_modify_request(test_ue, pdu); + break; + case S1AP_ProcedureCode_id_E_RABRelease: + tests1ap_handle_e_rab_release_command(test_ue, pdu); + break; + case S1AP_ProcedureCode_id_MMEConfigurationTransfer: + break; + case S1AP_ProcedureCode_id_HandoverResourceAllocation: + tests1ap_handle_handover_request(test_ue, pdu); + break; + case S1AP_ProcedureCode_id_MMEStatusTransfer: + break; + case S1AP_ProcedureCode_id_Paging: + break; + case S1AP_ProcedureCode_id_ErrorIndication: + break; + default: + ogs_error("Not implemented(choice:%d, proc:%d)", + pdu->present, (int)initiatingMessage->procedureCode); + break; + } + break; + case S1AP_S1AP_PDU_PR_successfulOutcome : + successfulOutcome = pdu->choice.successfulOutcome; + ogs_assert(successfulOutcome); + + switch (successfulOutcome->procedureCode) { + case S1AP_ProcedureCode_id_S1Setup: + tests1ap_handle_s1_setup_response(pdu); + break; + case S1AP_ProcedureCode_id_PathSwitchRequest: + break; + case S1AP_ProcedureCode_id_HandoverPreparation: + break; + case S1AP_ProcedureCode_id_HandoverCancel: + break; + case S1AP_ProcedureCode_id_Reset: + break; + default: + ogs_error("Not implemented(choice:%d, proc:%d)", + pdu->present, (int)successfulOutcome->procedureCode); + break; + } + break; + case S1AP_S1AP_PDU_PR_unsuccessfulOutcome : + unsuccessfulOutcome = pdu->choice.unsuccessfulOutcome; + ogs_assert(unsuccessfulOutcome); + + switch (unsuccessfulOutcome->procedureCode) { + case S1AP_ProcedureCode_id_S1Setup: + break; + case S1AP_ProcedureCode_id_HandoverPreparation: + break; + default: + ogs_error("Not implemented(choice:%d, proc:%d)", + pdu->present, (int)unsuccessfulOutcome->procedureCode); + break; + } + break; + default: + ogs_error("Not implemented(choice:%d)", pdu->present); + break; + } + + ogs_s1ap_free(&message); + ogs_pkbuf_free(pkbuf); +} + +void tests1ap_send_to_nas(test_ue_t *test_ue, S1AP_NAS_PDU_t *nasPdu) +{ + ogs_nas_eps_security_header_t *sh = NULL; + ogs_nas_security_header_type_t security_header_type; + + ogs_nas_emm_header_t *h = NULL; + ogs_pkbuf_t *nasbuf = NULL; + + ogs_assert(test_ue); + ogs_assert(nasPdu); + + /* The Packet Buffer(pkbuf_t) for NAS message MUST make a HEADROOM. + * When calculating AES_CMAC, we need to use the headroom of the packet. */ + nasbuf = ogs_pkbuf_alloc(NULL, OGS_NAS_HEADROOM+nasPdu->size); + ogs_pkbuf_reserve(nasbuf, OGS_NAS_HEADROOM); + ogs_pkbuf_put_data(nasbuf, nasPdu->buf, nasPdu->size); + + sh = (ogs_nas_eps_security_header_t *)nasbuf->data; + ogs_assert(sh); + + memset(&security_header_type, 0, sizeof(ogs_nas_security_header_type_t)); + switch(sh->security_header_type) { + case OGS_NAS_SECURITY_HEADER_PLAIN_NAS_MESSAGE: + break; + case OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED: + security_header_type.integrity_protected = 1; + ogs_pkbuf_pull(nasbuf, 6); + break; + case OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHERED: + security_header_type.integrity_protected = 1; + security_header_type.ciphered = 1; + ogs_pkbuf_pull(nasbuf, 6); + break; + case OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_NEW_SECURITY_CONTEXT: + security_header_type.integrity_protected = 1; + security_header_type.new_security_context = 1; + ogs_pkbuf_pull(nasbuf, 6); + break; + case OGS_NAS_SECURITY_HEADER_INTEGRITY_PROTECTED_AND_CIPHTERD_WITH_NEW_INTEGRITY_CONTEXT: + security_header_type.integrity_protected = 1; + security_header_type.ciphered = 1; + security_header_type.new_security_context = 1; + ogs_pkbuf_pull(nasbuf, 6); + break; + default: + ogs_error("Not implemented(security header type:0x%x)", + sh->security_header_type); + ogs_assert_if_reached(); + } + + h = (ogs_nas_emm_header_t *)nasbuf->data; + ogs_assert(h); + + if (h->message_type == OGS_NAS_EPS_SECURITY_MODE_COMMAND) { + ogs_nas_eps_message_t message; + int rv; + + rv = ogs_nas_emm_decode(&message, nasbuf); + ogs_assert(rv == OGS_OK); + + testemm_handle_security_mode_command(test_ue, + &message.emm.security_mode_command); + } + + if (test_nas_eps_security_decode(test_ue, + security_header_type, nasbuf) != OGS_OK) { + ogs_error("nas_eps_security_decode failed()"); + ogs_assert_if_reached(); + } + + if (h->protocol_discriminator == OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM) { + testemm_recv(test_ue, nasbuf); + } else if (h->protocol_discriminator == + OGS_NAS_PROTOCOL_DISCRIMINATOR_ESM) { + testesm_recv(test_ue, nasbuf); + } else { + ogs_error("Unknown NAS Protocol discriminator 0x%02x", + h->protocol_discriminator); + ogs_assert_if_reached(); + } +} diff --git a/tests/app/test-5gc.h b/tests/common/s1ap-path.h similarity index 79% rename from tests/app/test-5gc.h rename to tests/common/s1ap-path.h index ed1813cfe..51b31a9ad 100644 --- a/tests/app/test-5gc.h +++ b/tests/common/s1ap-path.h @@ -17,21 +17,18 @@ * along with this program. If not, see . */ -#ifndef TEST_5GC_H -#define TEST_5GC_H - -#include "test-common.h" -#include "test-ngap.h" +#ifndef TEST_S1AP_PATH_H +#define TEST_S1AP_PATH_H #ifdef __cplusplus extern "C" { #endif -void test_5gc_init(void); -void test_5gc_final(void); +void tests1ap_recv(test_ue_t *test_ue, ogs_pkbuf_t *pkbuf); +void tests1ap_send_to_nas(test_ue_t *test_ue, S1AP_NAS_PDU_t *nasPdu); #ifdef __cplusplus } #endif -#endif /* TEST_5GC_H */ +#endif /* TEST_S1AP_PATH_H */ diff --git a/tests/common/sctp.c b/tests/common/sctp.c index 1f86c1404..83c971e9d 100644 --- a/tests/common/sctp.c +++ b/tests/common/sctp.c @@ -100,3 +100,49 @@ int testsctp_send(ogs_socknode_t *node, ogs_pkbuf_t *pkbuf, return OGS_OK; } + +ogs_socknode_t *tests1ap_client(int family) +{ + int rv; + ogs_sockaddr_t *addr = NULL; + ogs_socknode_t *node = NULL; + + if (family == AF_INET6) + ogs_copyaddrinfo(&addr, test_self()->s1ap_addr6); + else + ogs_copyaddrinfo(&addr, test_self()->s1ap_addr); + + ogs_assert(addr); + + node = ogs_socknode_new(addr); + ogs_assert(node); + ogs_socknode_nodelay(node, true); + + ogs_sctp_client(SOCK_STREAM, node); + ogs_assert(node->sock); + + return node; +} + +ogs_socknode_t *testngap_client(int family) +{ + int rv; + ogs_sockaddr_t *addr = NULL; + ogs_socknode_t *node = NULL; + + if (family == AF_INET6) + ogs_copyaddrinfo(&addr, test_self()->ngap_addr6); + else + ogs_copyaddrinfo(&addr, test_self()->ngap_addr); + + ogs_assert(addr); + + node = ogs_socknode_new(addr); + ogs_assert(node); + ogs_socknode_nodelay(node, true); + + ogs_sctp_client(SOCK_STREAM, node); + ogs_assert(node->sock); + + return node; +} diff --git a/tests/common/sctp.h b/tests/common/sctp.h index 20ecbba64..9cb65797e 100644 --- a/tests/common/sctp.h +++ b/tests/common/sctp.h @@ -32,6 +32,9 @@ int testsctp_send(ogs_socknode_t *node, ogs_pkbuf_t *pkbuf, int ppid, uint16_t stream_no, int type); ogs_pkbuf_t *testsctp_read(ogs_socknode_t *node, int type); +ogs_socknode_t *tests1ap_client(int family); +ogs_socknode_t *testngap_client(int family); + #define testenb_s1ap_client(x) testsctp_client(x, OGS_S1AP_SCTP_PORT) #define testenb_s1ap_read(x) testsctp_read(x, 0); #define testenb_s1ap_send(x, y) \ @@ -44,7 +47,6 @@ ogs_pkbuf_t *testsctp_read(ogs_socknode_t *node, int type); testsctp_send(x, y, OGS_SCTP_SGSAP_PPID, 0, 1) #define testvlr_sgsap_close ogs_socknode_free -#define testgnb_ngap_client(x) testsctp_client(x, OGS_NGAP_SCTP_PORT) #define testgnb_ngap_read(x) testsctp_read(x, 0); #define testgnb_ngap_send(x, y) \ testsctp_send(x, y, OGS_SCTP_NGAP_PPID, 0, 0) diff --git a/tests/common/sgsap-build.c b/tests/common/sgsap-build.c new file mode 100644 index 000000000..a08d6b57a --- /dev/null +++ b/tests/common/sgsap-build.c @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +#define TEST_SGSAP_MAX_MESSAGE 64 + +ogs_pkbuf_t *test_sgsap_location_update_accept(int i) +{ + ogs_pkbuf_t *pkbuf = NULL; + const char *payload[TEST_SGSAP_MAX_MESSAGE] = { + "0a01089910073746 000006040509f107 09260e05f49ee88e 64", + "0a01087942120000 000030040527f412 c9580e05f437ab9c c5", + "", + + }; + uint16_t len[TEST_SGSAP_MAX_MESSAGE] = { + 25, + 25, + 0, + }; + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); + + return pkbuf; +} + +ogs_pkbuf_t *test_sgsap_location_update_reject(int i) +{ + ogs_pkbuf_t *pkbuf = NULL; + const char *payload[TEST_SGSAP_MAX_MESSAGE] = { + "0b01089910073746 0000060f01030405 09f1070926", + "", + "", + + }; + uint16_t len[TEST_SGSAP_MAX_MESSAGE] = { + 21, + 0, + 0, + }; + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); + + return pkbuf; +} + +ogs_pkbuf_t *test_sgsap_imsi_detach_ack(int i) +{ + ogs_pkbuf_t *pkbuf = NULL; + const char *payload[TEST_SGSAP_MAX_MESSAGE] = { + "1401089910073746 000006", + "", + "", + + }; + uint16_t len[TEST_SGSAP_MAX_MESSAGE] = { + 11, + 0, + 0, + }; + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); + + return pkbuf; +} + +ogs_pkbuf_t *test_sgsap_paging_request(int i) +{ + ogs_pkbuf_t *pkbuf = NULL; + const char *payload[TEST_SGSAP_MAX_MESSAGE] = { + "0101089910073746 000006021003766c 72076578616d706c 65036e6574200101" + "040509f1070926", + "0101089910073746 000005021003766c 72076578616d706c 65036e6574200101" + "040509f1070926", /* Paging-Reject */ + "0101089910073746 000006021003766c 72076578616d706c 65036e6574200102" + "040509f1070926", /* Paging-Request with SMS */ + + /* Paging-Request for crash-test */ + "0101089910073746 000006021003766c 72076578616d706c 65036e6574200101" + "040527f412c958", + "", + "", + }; + uint16_t len[TEST_SGSAP_MAX_MESSAGE] = { + 39, + 39, + 39, + + 39, + 0, + 0, + }; + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); + + return pkbuf; +} + +ogs_pkbuf_t *test_sgsap_reset_indication(int i) +{ + ogs_pkbuf_t *pkbuf = NULL; + const char *payload[TEST_SGSAP_MAX_MESSAGE] = { + "15021003766c7207 6578616d706c6503 6e6574", + "", + "", + + }; + uint16_t len[TEST_SGSAP_MAX_MESSAGE] = { + 19, + 0, + 0, + }; + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); + + return pkbuf; +} + +ogs_pkbuf_t *test_sgsap_release_request(int i) +{ + ogs_pkbuf_t *pkbuf = NULL; + const char *payload[TEST_SGSAP_MAX_MESSAGE] = { + "1b01089910073746 000006", + "", + "", + + }; + uint16_t len[TEST_SGSAP_MAX_MESSAGE] = { + 11, + 0, + 0, + }; + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); + + return pkbuf; +} + +ogs_pkbuf_t *test_sgsap_downlink_unitdata(int i) +{ + ogs_pkbuf_t *pkbuf = NULL; + const char *payload[TEST_SGSAP_MAX_MESSAGE] = { + "0701089910073746 0000061626090123 0100079144775810 0650001700048032" + "2400009160404044 150009c8329bfd06 4d9b53", + "", + "", + + }; + uint16_t len[TEST_SGSAP_MAX_MESSAGE] = { + 51, + 0, + 0, + }; + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); + + return pkbuf; +} + +ogs_pkbuf_t *test_sgsap_mm_information_request(int i) +{ + ogs_pkbuf_t *pkbuf = NULL; + const char *payload[TEST_SGSAP_MAX_MESSAGE] = { + "1a01087942120000 0000301714430483 d46413450483d464 1347917071028401" + "29", + "", + "", + + }; + uint16_t len[TEST_SGSAP_MAX_MESSAGE] = { + 33, + 0, + 0, + }; + char hexbuf[OGS_MAX_SDU_LEN]; + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_pkbuf_put_data(pkbuf, + OGS_HEX(payload[i], strlen(payload[i]), hexbuf), len[i]); + + return pkbuf; +} diff --git a/tests/app/test-epc.h b/tests/common/sgsap-build.h similarity index 62% rename from tests/app/test-epc.h rename to tests/common/sgsap-build.h index b229cc357..ffb809a1d 100644 --- a/tests/app/test-epc.h +++ b/tests/common/sgsap-build.h @@ -17,22 +17,24 @@ * along with this program. If not, see . */ -#ifndef TEST_EPC_H -#define TEST_EPC_H - -#include "test-packet.h" - -#include "mme/mme-context.h" +#ifndef TEST_SGSAP_BUILD_H +#define TEST_SGSAP_BUILD_H #ifdef __cplusplus extern "C" { #endif -void test_epc_init(void); -#define test_epc_final ogs_dbi_final +ogs_pkbuf_t *test_sgsap_location_update_accept(int i); +ogs_pkbuf_t *test_sgsap_location_update_reject(int i); +ogs_pkbuf_t *test_sgsap_imsi_detach_ack(int i); +ogs_pkbuf_t *test_sgsap_paging_request(int i); +ogs_pkbuf_t *test_sgsap_reset_indication(int i); +ogs_pkbuf_t *test_sgsap_release_request(int i); +ogs_pkbuf_t *test_sgsap_downlink_unitdata(int i); +ogs_pkbuf_t *test_sgsap_mm_information_request(int i); #ifdef __cplusplus } #endif -#endif /* TEST_EPC_H */ +#endif /* TEST_SGSAP_BUILD_H */ diff --git a/tests/common/test-common.h b/tests/common/test-common.h index 5398bb11a..4df3ff075 100644 --- a/tests/common/test-common.h +++ b/tests/common/test-common.h @@ -32,6 +32,12 @@ extern "C" { #include "ogs-nas-eps.h" #include "ogs-nas-5gs.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wredundant-decls" +#include "ogs-ngap.h" +#include "ogs-s1ap.h" +#pragma GCC diagnostic pop + #include "core/abts.h" #define OGS_TEST_INSIDE @@ -48,6 +54,24 @@ extern "C" { #include "common/nas-encoder.h" #include "common/nas-security.h" +#include "common/ngap-build.h" +#include "common/ngap-handler.h" +#include "common/ngap-path.h" + +#include "common/s1ap-build.h" +#include "common/s1ap-handler.h" +#include "common/s1ap-path.h" + +#include "common/emm-build.h" +#include "common/emm-handler.h" +#include "common/esm-build.h" +#include "common/esm-handler.h" + +#include "common/sgsap-build.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN 1 + #undef OGS_TEST_INSIDE #ifdef __cplusplus diff --git a/tests/csfb/abts-main.c b/tests/csfb/abts-main.c index 5bd4484d0..f0cded7ec 100644 --- a/tests/csfb/abts-main.c +++ b/tests/csfb/abts-main.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-app.h" abts_suite *test_mo_idle(abts_suite *suite); abts_suite *test_mt_idle(abts_suite *suite); @@ -40,13 +40,6 @@ const struct testlist { {NULL}, }; -static ogs_thread_t *nrf_thread = NULL; -static ogs_thread_t *pcrf_thread = NULL; -static ogs_thread_t *upf_thread = NULL; -static ogs_thread_t *smf_thread = NULL; -static ogs_thread_t *sgwc_thread = NULL; -static ogs_thread_t *sgwu_thread = NULL; -static ogs_thread_t *hss_thread = NULL; ogs_socknode_t *sgsap = NULL; static void terminate(void) @@ -54,24 +47,11 @@ static void terminate(void) ogs_msleep(50); test_child_terminate(); - - ogs_info("MME try to terminate"); - mme_terminate(); + app_terminate(); testvlr_sgsap_close(sgsap); - ogs_sctp_final(); test_epc_final(); - ogs_info("MME terminate...done"); - - if (sgwc_thread) ogs_thread_destroy(sgwc_thread); - if (smf_thread) ogs_thread_destroy(smf_thread); - if (sgwu_thread) ogs_thread_destroy(sgwu_thread); - if (upf_thread) ogs_thread_destroy(upf_thread); - if (hss_thread) ogs_thread_destroy(hss_thread); - if (pcrf_thread) ogs_thread_destroy(pcrf_thread); - if (nrf_thread) ogs_thread_destroy(nrf_thread); - ogs_app_terminate(); } @@ -81,50 +61,21 @@ static void initialize(const char *const argv[]) rv = ogs_app_initialize(NULL, argv); ogs_assert(rv == OGS_OK); - - if (ogs_config()->parameter.no_nrf == 0) - nrf_thread = test_child_create("nrf", argv); - if (ogs_config()->parameter.no_pcrf == 0) - pcrf_thread = test_child_create("pcrf", argv); - if (ogs_config()->parameter.no_hss == 0) - hss_thread = test_child_create("hss", argv); - - /* - * To avoid freeDiameter error - * - * ROUTING ERROR - * 'No remaining suitable candidate to route the message to' for: - */ - ogs_msleep(500); - - if (ogs_config()->parameter.no_upf == 0) - upf_thread = test_child_create("upf", argv); - if (ogs_config()->parameter.no_sgwu == 0) - sgwu_thread = test_child_create("sgwu", argv); - if (ogs_config()->parameter.no_sgwc == 0) - sgwc_thread = test_child_create("sgwc", argv); - - - /* - * To avoid freeDiameter error - * - * ROUTING ERROR - * 'No remaining suitable candidate to route the message to' for: - */ - ogs_msleep(500); - - if (ogs_config()->parameter.no_smf == 0) - smf_thread = test_child_create("smf", argv); - test_epc_init(); - ogs_sctp_init(ogs_config()->usrsctp.udp_port); sgsap = testvlr_sgsap_server("127.0.0.2"); ogs_assert(sgsap); - rv = mme_initialize(); + rv = app_initialize(argv); ogs_assert(rv == OGS_OK); - ogs_info("MME initialize...done"); + + /* + * To avoid freeDiameter error + * + * ROUTING ERROR + * 'No remaining suitable candidate to route the message to' for: + */ + ogs_msleep(500); } int main(int argc, const char *const argv[]) @@ -133,7 +84,7 @@ int main(int argc, const char *const argv[]) abts_suite *suite = NULL; atexit(terminate); - test_epc_run(argc, argv, "csfb.yaml", initialize); + test_app_run(argc, argv, "csfb.yaml", initialize); for (i = 0; alltests[i].func; i++) suite = alltests[i].func(suite); diff --git a/tests/csfb/crash-test.c b/tests/csfb/crash-test.c index f75e58b10..039c2a826 100644 --- a/tests/csfb/crash-test.c +++ b/tests/csfb/crash-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-common.h" extern ogs_socknode_t *sgsap; @@ -25,14 +25,22 @@ static void test1_func(abts_case *tc, void *data) { int rv; ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; ogs_pkbuf_t *sendbuf; ogs_pkbuf_t *recvbuf; ogs_s1ap_message_t message; - int i; - int msgindex = 19; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; mongoc_collection_t *collection = NULL; bson_t *doc = NULL; @@ -41,7 +49,7 @@ static void test1_func(abts_case *tc, void *data) const char *json = "{" "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"724210000000003\", " + "\"imsi\" : \"901707364000060\", " "\"pdn\" : [" "{" "\"apn\" : \"internet\", " @@ -53,9 +61,9 @@ static void test1_func(abts_case *tc, void *data) "\"qos\" : { " "\"qci\" : 9, " "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 0, " - "\"pre_emption_capability\" : 0" + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" "} " "}, " "\"type\" : 2" @@ -70,46 +78,86 @@ static void test1_func(abts_case *tc, void *data) "\"subscriber_status\" : 0, " "\"access_restriction_data\" : 32, " "\"security\" : { " - "\"k\" : \"70D49A71DD1A2B806A25ABE0EF749F1E\", " - "\"opc\" : \"6F1BF53D624B3A43AF6592854E2444C7\", " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"2374\" }, " - "\"rand\" : \"aa266700bc2887354e9f87368d5d0ae7\" " + "\"sqn\" : { \"$numberLong\" : \"64\" } " "}, " "\"__v\" : 0 " "}"; + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x19b010; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); + s1ap = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, s1ap); + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x0019b0, 12345, 724, 21, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x19b0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1-Setup Response */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(NULL, recvbuf); + /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); - /********** Insert Subscriber in Database */ doc = bson_new_from_json((const uint8_t *)json, -1, &error);; ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, + ABTS_TRUE(tc, mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8("724210000000003")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -117,54 +165,92 @@ static void test1_func(abts_case *tc, void *data) } while (count == 0); bson_destroy(doc); + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + /* Send Attach Request */ - mme_self()->mme_ue_s1ap_id = 247; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.mobile_station_classmark_3 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Identity-Request */ + /* Receive Identity Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Authentication Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Security mode Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive ESM Information Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -174,42 +260,42 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-Location-Update-Accept */ - rv = testsgsap_location_update_accept(&sendbuf, 1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_location_update_accept(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Initial Context Setup Request + - * Attach Accept + + /* Receive Initial Context Setup Request + + * Attach Accept + * Activate Default Bearer Context Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + tests1ap_recv(test_ue, recvbuf); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 248, 256403, 5, 0x00000615, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Attach Complete + Activate default EPS bearer cotext accept */ - /* Receive EMM information */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive EMM Information */ + /* Receive EMM information */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Receive SGsAP TMSI-REALLOCATION-COMPLETE */ recvbuf = testvlr_sgsap_read(sgsap); @@ -217,33 +303,34 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-MM-INFORMATION-REQUEST */ - rv = testsgsap_mm_information_request(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_mm_information_request(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Retreive M-TMSI */ - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(248); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - m_tmsi = mme_ue->guti.m_tmsi; - /* Send SGsAP-Paging-Request */ - rv = testsgsap_paging_request(&sendbuf, 3); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_paging_request(3); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive S1AP Paging */ + /* Receive CS service notification */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Extended Service Request */ - rv = tests1ap_build_extended_service_request(&sendbuf, 22, - 1, m_tmsi, 3, mme_ue->knas_int); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + memset(&test_ue->extended_service_request_param, + 0, sizeof(test_ue->extended_service_request_param)); + test_ue->extended_service_request_param.ciphered = 1; + test_ue->extended_service_request_param.csfb_response = 1; + test_ue->extended_service_request_param.csfb.response = + OGS_NAS_CS_FALLBACK_RESPONSE_ACCEPTED_BY_THE_UE; + test_ue->extended_service_request_param.eps_bearer_context_status = 1; + emmbuf = testemm_build_extended_service_request(test_ue, 1); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -251,50 +338,62 @@ static void test1_func(abts_case *tc, void *data) recvbuf = testvlr_sgsap_read(sgsap); ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); - + /* Receive UE Context Modification Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send UE Context Modification Response */ - rv = tests1ap_build_ue_context_modification_response(&sendbuf, 248, 256403); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send UE Context Release Request */ + sendbuf = test_s1ap_build_ue_context_modification_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, 20); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, 20); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send SGsAP-Paging-Request */ - rv = testsgsap_paging_request(&sendbuf, 3); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_paging_request(3); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1AP Paging */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Extended Service Request */ - rv = tests1ap_build_extended_service_request(&sendbuf, 21, - 1, m_tmsi, 4, mme_ue->knas_int); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + memset(&test_ue->extended_service_request_param, + 0, sizeof(test_ue->extended_service_request_param)); + test_ue->extended_service_request_param.ciphered = 1; + test_ue->extended_service_request_param.csfb_response = 1; + test_ue->extended_service_request_param.csfb.response = + OGS_NAS_CS_FALLBACK_RESPONSE_ACCEPTED_BY_THE_UE; + test_ue->extended_service_request_param.eps_bearer_context_status = 1; + emmbuf = testemm_build_extended_service_request(test_ue, 1); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -306,21 +405,32 @@ static void test1_func(abts_case *tc, void *data) /* Receive Initial Context Setup Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - ogs_msleep(300); + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(100); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("724210000000003")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) bson_destroy(doc); mongoc_collection_destroy(collection); /* eNB disonncect from MME */ testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); } abts_suite *test_crash(abts_suite *suite) diff --git a/tests/csfb/meson.build b/tests/csfb/meson.build index 67e98ac7f..30ba9d959 100644 --- a/tests/csfb/meson.build +++ b/tests/csfb/meson.build @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -testepc_csfb_sources = files(''' +testapp_csfb_sources = files(''' abts-main.c mo-idle-test.c mt-idle-test.c @@ -26,9 +26,9 @@ testepc_csfb_sources = files(''' crash-test.c '''.split()) -testepc_csfb_exe = executable('csfb', - sources : testepc_csfb_sources, +testapp_csfb_exe = executable('csfb', + sources : testapp_csfb_sources, c_args : testunit_core_cc_flags, dependencies : libtestepc_dep) -test('csfb', testepc_csfb_exe, is_parallel : false, suite: 'epc') +test('csfb', testapp_csfb_exe, is_parallel : false, suite: 'epc') diff --git a/tests/csfb/mo-active-test.c b/tests/csfb/mo-active-test.c index 74864f3b2..95ca57dd5 100644 --- a/tests/csfb/mo-active-test.c +++ b/tests/csfb/mo-active-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-common.h" extern ogs_socknode_t *sgsap; @@ -25,14 +25,22 @@ static void test1_func(abts_case *tc, void *data) { int rv; ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; ogs_pkbuf_t *sendbuf; ogs_pkbuf_t *recvbuf; ogs_s1ap_message_t message; - int i; - int msgindex = 18; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; mongoc_collection_t *collection = NULL; bson_t *doc = NULL; @@ -41,7 +49,7 @@ static void test1_func(abts_case *tc, void *data) const char *json = "{" "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"262420000118139\", " + "\"imsi\" : \"901707364000060\", " "\"pdn\" : [" "{" "\"apn\" : \"internet\", " @@ -53,9 +61,9 @@ static void test1_func(abts_case *tc, void *data) "\"qos\" : { " "\"qci\" : 9, " "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 0, " - "\"pre_emption_capability\" : 0" + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" "} " "}, " "\"type\" : 2" @@ -70,46 +78,86 @@ static void test1_func(abts_case *tc, void *data) "\"subscriber_status\" : 0, " "\"access_restriction_data\" : 32, " "\"security\" : { " - "\"k\" : \"70D49A71DD1A2B806A25ABE0EF749F1E\", " - "\"opc\" : \"6F1BF53D624B3A43AF6592854E2444C7\", " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"2374\" }, " - "\"rand\" : \"aa266700bc2887354e9f87368d5d0ae7\" " + "\"sqn\" : { \"$numberLong\" : \"64\" } " "}, " "\"__v\" : 0 " "}"; + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x19b010; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); + s1ap = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, s1ap); + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x0019b0, 7, 901, 70, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x19b0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1-Setup Response */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(NULL, recvbuf); + /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); - /********** Insert Subscriber in Database */ doc = bson_new_from_json((const uint8_t *)json, -1, &error);; ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, + ABTS_TRUE(tc, mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -117,54 +165,92 @@ static void test1_func(abts_case *tc, void *data) } while (count == 0); bson_destroy(doc); + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + /* Send Attach Request */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.mobile_station_classmark_3 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Identity-Request */ + /* Receive Identity Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Authentication Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Security mode Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive ESM Information Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -174,52 +260,55 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-Location-Update-Accept */ - rv = testsgsap_location_update_accept(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_location_update_accept(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Initial Context Setup Request + - * Attach Accept + + /* Receive Initial Context Setup Request + + * Attach Accept + * Activate Default Bearer Context Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 1, 1, 5, 0x00460003, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive EMM information */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Receive SGsAP TMSI-REALLOCATION-COMPLETE */ recvbuf = testvlr_sgsap_read(sgsap); ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); - /* Retreive M-TMSI */ - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(1); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - m_tmsi = mme_ue->guti.m_tmsi; - /* Send Extended Service Request */ - rv = tests1ap_build_extended_service_request(&sendbuf, msgindex+1, - 0, m_tmsi, 4, mme_ue->knas_int); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + memset(&test_ue->extended_service_request_param, + 0, sizeof(test_ue->extended_service_request_param)); + emmbuf = testemm_build_extended_service_request(test_ue, 0); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -231,44 +320,50 @@ static void test1_func(abts_case *tc, void *data) /* Receive UE Context Modification Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Modification Response */ - rv = tests1ap_build_ue_context_modification_response(&sendbuf, 1, 1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_modification_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_msleep(300); + ogs_msleep(100); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) bson_destroy(doc); mongoc_collection_destroy(collection); /* eNB disonncect from MME */ testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); } abts_suite *test_mo_active(abts_suite *suite) diff --git a/tests/csfb/mo-idle-test.c b/tests/csfb/mo-idle-test.c index 583820ae4..b75cf872f 100644 --- a/tests/csfb/mo-idle-test.c +++ b/tests/csfb/mo-idle-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-common.h" extern ogs_socknode_t *sgsap; @@ -25,45 +25,22 @@ static void test1_func(abts_case *tc, void *data) { int rv; ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; ogs_pkbuf_t *sendbuf; ogs_pkbuf_t *recvbuf; ogs_s1ap_message_t message; - int i; - int msgindex = 18; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; - uint8_t tmp[OGS_MAX_SDU_LEN]; - const char *_identity_request = - "000b401700000300 0000020001000800 020001001a000403 075501"; - const char *_authentication_request = - "000b403800000300 0000020001000800 020001001a002524 075200aa266700bc" - "2887354e9f87368d 5d0ae710ab857af5 5f1a8000d71e5537 4ee176e9"; - const char *_security_mode_command = - "000b402f00000300 0000020001000800 020001001a001c1b 37654673a700075d" - "010005f0f0c04070 c14f08e56478c08b 01fb65"; - const char *_esm_information_request = - "000b401d00000300 0000020001000800 020001001a000a09 27d1237969010234" - "d9"; - const char *_sgsap_location_update_request = - "0901082926240000 1118930937066d6d 65633031096d6d65 676930303032036d" - "6d6503657063066d 6e63303730066d63 633930310b336770 706e6574776f726b" - "036f72670a010104 0509f1070926"; - const char *_initial_context_setup_request = - "00090080e9000007 0000000200010008 000200010042000a 183d090000603d09" - "0000001800808e00 0034008088450009 230f807f00000700 000002792758bf47" - "8002074202490620 09f1070007004652 34c101090908696e 7465726e65740501" - "0a2d00025e06fefe e2e2030327278080 2110020000108106 0808080883060808" - "0404000d04080808 08000d0408080404 0010020578500bf6 09f107000201ea00" - "8e461309f1070926 2305f49ee88e6459 4964020108006b00 051c000e00000049" - "0020f9f4f80b206c 33ae286c6daff4c2 53585174c3a0a12a 661967f5e1ba0a68" - "6c8c00c040083572 200924ffff14"; - const char *_emm_information = - "000b403800000300 0000020001000800 020001001a002524 2751034124030761" - "430f10004f007000 65006e0035004700 5347916051216124 63490100"; - const char *_sgsap_tmsi_reallocation_complete = - "0c01082926240000 111893"; + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; mongoc_collection_t *collection = NULL; bson_t *doc = NULL; @@ -72,7 +49,7 @@ static void test1_func(abts_case *tc, void *data) const char *json = "{" "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"262420000118139\", " + "\"imsi\" : \"901707364000060\", " "\"pdn\" : [" "{" "\"apn\" : \"internet\", " @@ -84,9 +61,9 @@ static void test1_func(abts_case *tc, void *data) "\"qos\" : { " "\"qci\" : 9, " "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 0, " - "\"pre_emption_capability\" : 0" + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" "} " "}, " "\"type\" : 2" @@ -101,46 +78,86 @@ static void test1_func(abts_case *tc, void *data) "\"subscriber_status\" : 0, " "\"access_restriction_data\" : 32, " "\"security\" : { " - "\"k\" : \"70D49A71DD1A2B806A25ABE0EF749F1E\", " - "\"opc\" : \"6F1BF53D624B3A43AF6592854E2444C7\", " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"2374\" }, " - "\"rand\" : \"aa266700bc2887354e9f87368d5d0ae7\" " + "\"sqn\" : { \"$numberLong\" : \"64\" } " "}, " "\"__v\" : 0 " "}"; + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x19b010; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); + s1ap = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, s1ap); + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x0019b0, 7, 901, 70, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x19b0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1-Setup Response */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(NULL, recvbuf); + /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); - /********** Insert Subscriber in Database */ doc = bson_new_from_json((const uint8_t *)json, -1, &error);; ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, + ABTS_TRUE(tc, mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -148,171 +165,186 @@ static void test1_func(abts_case *tc, void *data) } while (count == 0); bson_destroy(doc); + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + /* Send Attach Request */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.mobile_station_classmark_3 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Identity-Request */ + /* Receive Identity Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_identity_request, strlen(_identity_request), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Authentication Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_authentication_request, strlen(_authentication_request), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Security mode Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_security_mode_command, strlen(_security_mode_command), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive ESM Information Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_esm_information_request, strlen(_security_mode_command), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive SGsAP-Location-Update-Request */ recvbuf = testvlr_sgsap_read(sgsap); ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_sgsap_location_update_request, - strlen(_sgsap_location_update_request), tmp), - recvbuf->len) == 0); ogs_pkbuf_free(recvbuf); /* Send SGsAP-Location-Update-Accept */ - rv = testsgsap_location_update_accept(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_location_update_accept(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Initial Context Setup Request + - * Attach Accept + + /* Receive Initial Context Setup Request + + * Attach Accept + * Activate Default Bearer Context Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - OGS_HEX(_initial_context_setup_request, - strlen(_initial_context_setup_request), tmp); - ABTS_TRUE(tc, memcmp(recvbuf->data, tmp, 61) == 0); - ABTS_TRUE(tc, memcmp(recvbuf->data+65, tmp+65, 93) == 0); - ABTS_TRUE(tc, memcmp(recvbuf->data+162, tmp+162, 63) == 0); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 1, 1, 5, 0x00460003, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive EMM information */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - OGS_HEX(_emm_information, strlen(_emm_information), tmp); - ABTS_TRUE(tc, memcmp(recvbuf->data, tmp, 25) == 0); - ABTS_TRUE(tc, memcmp(recvbuf->data+29, tmp+29, 21) == 0); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Receive SGsAP TMSI-REALLOCATION-COMPLETE */ recvbuf = testvlr_sgsap_read(sgsap); ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_sgsap_tmsi_reallocation_complete, - strlen(_sgsap_tmsi_reallocation_complete), tmp), - recvbuf->len) == 0); ogs_pkbuf_free(recvbuf); - /* Retreive M-TMSI */ - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(1); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - m_tmsi = mme_ue->guti.m_tmsi; - /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Service Request */ - rv = tests1ap_build_service_request(&sendbuf, 0x000200, 3, 0xc340, m_tmsi); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + emmbuf = testemm_build_service_request(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Data, true); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Initial Context Setup Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 2, 2, 5, 0x00470003, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Detach Request */ - rv = tests1ap_build_detach_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + emmbuf = testemm_build_detach_request(test_ue, 1); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -322,49 +354,62 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP IMSI-DETACH-ACK */ - rv = testsgsap_imsi_detach_ack(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_imsi_detach_ack(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_msleep(300); + ogs_msleep(100); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) bson_destroy(doc); mongoc_collection_destroy(collection); /* eNB disonncect from MME */ testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); } static void test2_func(abts_case *tc, void *data) { int rv; ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; ogs_pkbuf_t *sendbuf; ogs_pkbuf_t *recvbuf; ogs_s1ap_message_t message; - int i; - int msgindex = 18; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; mongoc_collection_t *collection = NULL; bson_t *doc = NULL; @@ -373,7 +418,7 @@ static void test2_func(abts_case *tc, void *data) const char *json = "{" "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"262420000118139\", " + "\"imsi\" : \"901707364000060\", " "\"pdn\" : [" "{" "\"apn\" : \"internet\", " @@ -385,9 +430,9 @@ static void test2_func(abts_case *tc, void *data) "\"qos\" : { " "\"qci\" : 9, " "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 0, " - "\"pre_emption_capability\" : 0" + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" "} " "}, " "\"type\" : 2" @@ -402,46 +447,86 @@ static void test2_func(abts_case *tc, void *data) "\"subscriber_status\" : 0, " "\"access_restriction_data\" : 32, " "\"security\" : { " - "\"k\" : \"70D49A71DD1A2B806A25ABE0EF749F1E\", " - "\"opc\" : \"6F1BF53D624B3A43AF6592854E2444C7\", " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"2374\" }, " - "\"rand\" : \"aa266700bc2887354e9f87368d5d0ae7\" " + "\"sqn\" : { \"$numberLong\" : \"64\" } " "}, " "\"__v\" : 0 " "}"; + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x19b010; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); + s1ap = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, s1ap); + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x0019b0, 7, 901, 70, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x19b0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1-Setup Response */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(NULL, recvbuf); + /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); - /********** Insert Subscriber in Database */ doc = bson_new_from_json((const uint8_t *)json, -1, &error);; ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, + ABTS_TRUE(tc, mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -449,54 +534,92 @@ static void test2_func(abts_case *tc, void *data) } while (count == 0); bson_destroy(doc); + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + /* Send Attach Request */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.mobile_station_classmark_3 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Identity-Request */ + /* Receive Identity Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Authentication Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Security mode Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive ESM Information Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -506,54 +629,67 @@ static void test2_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-Location-Update-Reject */ - rv = testsgsap_location_update_reject(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_location_update_reject(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Attach Reject */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Receive UE Release Command */ + /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_msleep(300); + ogs_msleep(100); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) bson_destroy(doc); mongoc_collection_destroy(collection); /* eNB disonncect from MME */ testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); } static void test3_func(abts_case *tc, void *data) { int rv; ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; ogs_pkbuf_t *sendbuf; ogs_pkbuf_t *recvbuf; ogs_s1ap_message_t message; - int i; - int msgindex = 18; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; mongoc_collection_t *collection = NULL; bson_t *doc = NULL; @@ -562,7 +698,7 @@ static void test3_func(abts_case *tc, void *data) const char *json = "{" "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"262420000118139\", " + "\"imsi\" : \"901707364000060\", " "\"pdn\" : [" "{" "\"apn\" : \"internet\", " @@ -574,9 +710,9 @@ static void test3_func(abts_case *tc, void *data) "\"qos\" : { " "\"qci\" : 9, " "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 0, " - "\"pre_emption_capability\" : 0" + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" "} " "}, " "\"type\" : 2" @@ -591,46 +727,86 @@ static void test3_func(abts_case *tc, void *data) "\"subscriber_status\" : 0, " "\"access_restriction_data\" : 32, " "\"security\" : { " - "\"k\" : \"70D49A71DD1A2B806A25ABE0EF749F1E\", " - "\"opc\" : \"6F1BF53D624B3A43AF6592854E2444C7\", " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"2374\" }, " - "\"rand\" : \"aa266700bc2887354e9f87368d5d0ae7\" " + "\"sqn\" : { \"$numberLong\" : \"64\" } " "}, " "\"__v\" : 0 " "}"; + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x19b010; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); + s1ap = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, s1ap); + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x0019b0, 7, 901, 70, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x19b0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1-Setup Response */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(NULL, recvbuf); + /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); - /********** Insert Subscriber in Database */ doc = bson_new_from_json((const uint8_t *)json, -1, &error);; ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, + ABTS_TRUE(tc, mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -638,54 +814,92 @@ static void test3_func(abts_case *tc, void *data) } while (count == 0); bson_destroy(doc); + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + /* Send Attach Request */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.mobile_station_classmark_3 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Identity-Request */ + /* Receive Identity Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Authentication Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Security mode Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive ESM Information Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -695,68 +909,75 @@ static void test3_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-Location-Update-Accept */ - rv = testsgsap_location_update_accept(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_location_update_accept(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Initial Context Setup Request + - * Attach Accept + + /* Receive Initial Context Setup Request + + * Attach Accept + * Activate Default Bearer Context Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 1, 1, 5, 0x00460003, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive EMM information */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Receive SGsAP TMSI-REALLOCATION-COMPLETE */ recvbuf = testvlr_sgsap_read(sgsap); ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); - /* Retreive M-TMSI */ - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(1); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - m_tmsi = mme_ue->guti.m_tmsi; - /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Extended Service Request */ - rv = tests1ap_build_extended_service_request(&sendbuf, msgindex, - 0, m_tmsi, 4, mme_ue->knas_int); + memset(&test_ue->extended_service_request_param, + 0, sizeof(test_ue->extended_service_request_param)); + emmbuf = testemm_build_extended_service_request(test_ue, 0); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -769,59 +990,72 @@ static void test3_func(abts_case *tc, void *data) /* Receive Initial Context Setup Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 2, 2, 5, 0x00470003, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_msleep(300); + ogs_msleep(100); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) bson_destroy(doc); mongoc_collection_destroy(collection); /* eNB disonncect from MME */ testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); } static void test4_func(abts_case *tc, void *data) { int rv; ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; ogs_pkbuf_t *sendbuf; ogs_pkbuf_t *recvbuf; ogs_s1ap_message_t message; - int i; - int msgindex = 18; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; mongoc_collection_t *collection = NULL; bson_t *doc = NULL; @@ -830,7 +1064,7 @@ static void test4_func(abts_case *tc, void *data) const char *json = "{" "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"262420000118139\", " + "\"imsi\" : \"901707364000060\", " "\"pdn\" : [" "{" "\"apn\" : \"internet\", " @@ -842,9 +1076,9 @@ static void test4_func(abts_case *tc, void *data) "\"qos\" : { " "\"qci\" : 9, " "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 0, " - "\"pre_emption_capability\" : 0" + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" "} " "}, " "\"type\" : 2" @@ -859,46 +1093,86 @@ static void test4_func(abts_case *tc, void *data) "\"subscriber_status\" : 0, " "\"access_restriction_data\" : 32, " "\"security\" : { " - "\"k\" : \"70D49A71DD1A2B806A25ABE0EF749F1E\", " - "\"opc\" : \"6F1BF53D624B3A43AF6592854E2444C7\", " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"2374\" }, " - "\"rand\" : \"aa266700bc2887354e9f87368d5d0ae7\" " + "\"sqn\" : { \"$numberLong\" : \"64\" } " "}, " "\"__v\" : 0 " "}"; + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x19b010; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); + s1ap = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, s1ap); + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x0019b0, 7, 901, 70, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x19b0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1-Setup Response */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(NULL, recvbuf); + /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); - /********** Insert Subscriber in Database */ doc = bson_new_from_json((const uint8_t *)json, -1, &error);; ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, + ABTS_TRUE(tc, mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -906,54 +1180,92 @@ static void test4_func(abts_case *tc, void *data) } while (count == 0); bson_destroy(doc); + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + /* Send Attach Request */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.mobile_station_classmark_3 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Identity-Request */ + /* Receive Identity Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Authentication Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Security mode Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive ESM Information Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -963,8 +1275,8 @@ static void test4_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-Reset-Indication */ - rv = testsgsap_reset_indication(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_reset_indication(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -973,21 +1285,23 @@ static void test4_func(abts_case *tc, void *data) ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); - ogs_msleep(300); - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) bson_destroy(doc); mongoc_collection_destroy(collection); /* eNB disonncect from MME */ testenb_s1ap_close(s1ap); -} + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} abts_suite *test_mo_idle(abts_suite *suite) { diff --git a/tests/csfb/mo-sms-test.c b/tests/csfb/mo-sms-test.c index 99c57b6c6..f4c415ddf 100644 --- a/tests/csfb/mo-sms-test.c +++ b/tests/csfb/mo-sms-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-common.h" extern ogs_socknode_t *sgsap; @@ -25,14 +25,22 @@ static void test1_func(abts_case *tc, void *data) { int rv; ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; ogs_pkbuf_t *sendbuf; ogs_pkbuf_t *recvbuf; ogs_s1ap_message_t message; - int i; - int msgindex = 18; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; mongoc_collection_t *collection = NULL; bson_t *doc = NULL; @@ -41,7 +49,7 @@ static void test1_func(abts_case *tc, void *data) const char *json = "{" "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"262420000118139\", " + "\"imsi\" : \"901707364000060\", " "\"pdn\" : [" "{" "\"apn\" : \"internet\", " @@ -53,9 +61,9 @@ static void test1_func(abts_case *tc, void *data) "\"qos\" : { " "\"qci\" : 9, " "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 0, " - "\"pre_emption_capability\" : 0" + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" "} " "}, " "\"type\" : 2" @@ -70,46 +78,86 @@ static void test1_func(abts_case *tc, void *data) "\"subscriber_status\" : 0, " "\"access_restriction_data\" : 32, " "\"security\" : { " - "\"k\" : \"70D49A71DD1A2B806A25ABE0EF749F1E\", " - "\"opc\" : \"6F1BF53D624B3A43AF6592854E2444C7\", " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"2374\" }, " - "\"rand\" : \"aa266700bc2887354e9f87368d5d0ae7\" " + "\"sqn\" : { \"$numberLong\" : \"64\" } " "}, " "\"__v\" : 0 " "}"; + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x19b010; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); + s1ap = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, s1ap); + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x0019b0, 7, 901, 70, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x19b0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1-Setup Response */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(NULL, recvbuf); + /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); - /********** Insert Subscriber in Database */ doc = bson_new_from_json((const uint8_t *)json, -1, &error);; ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, + ABTS_TRUE(tc, mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -117,54 +165,92 @@ static void test1_func(abts_case *tc, void *data) } while (count == 0); bson_destroy(doc); + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + /* Send Attach Request */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.mobile_station_classmark_3 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Identity-Request */ + /* Receive Identity Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Authentication Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Security mode Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive ESM Information Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -174,35 +260,42 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-Location-Update-Accept */ - rv = testsgsap_location_update_accept(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_location_update_accept(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Initial Context Setup Request + - * Attach Accept + + /* Receive Initial Context Setup Request + + * Attach Accept + * Activate Default Bearer Context Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 1, 1, 5, 0x00460003, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive EMM information */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Receive SGsAP TMSI-REALLOCATION-COMPLETE */ recvbuf = testvlr_sgsap_read(sgsap); @@ -210,8 +303,10 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send Uplink NAS Transport */ - rv = tests1ap_build_uplink_nas_transport(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + emmbuf = testemm_build_uplink_nas_transport(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -221,41 +316,47 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-RELEASE-REQUEST */ - rv = testsgsap_release_request(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_release_request(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_msleep(300); + ogs_msleep(100); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) bson_destroy(doc); mongoc_collection_destroy(collection); /* eNB disonncect from MME */ testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); } abts_suite *test_mo_sms(abts_suite *suite) diff --git a/tests/csfb/mt-active-test.c b/tests/csfb/mt-active-test.c index e04607855..de18d2640 100644 --- a/tests/csfb/mt-active-test.c +++ b/tests/csfb/mt-active-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-common.h" extern ogs_socknode_t *sgsap; @@ -25,14 +25,22 @@ static void test1_func(abts_case *tc, void *data) { int rv; ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; ogs_pkbuf_t *sendbuf; ogs_pkbuf_t *recvbuf; ogs_s1ap_message_t message; - int i; - int msgindex = 18; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; mongoc_collection_t *collection = NULL; bson_t *doc = NULL; @@ -41,7 +49,7 @@ static void test1_func(abts_case *tc, void *data) const char *json = "{" "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"262420000118139\", " + "\"imsi\" : \"901707364000060\", " "\"pdn\" : [" "{" "\"apn\" : \"internet\", " @@ -53,9 +61,9 @@ static void test1_func(abts_case *tc, void *data) "\"qos\" : { " "\"qci\" : 9, " "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 0, " - "\"pre_emption_capability\" : 0" + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" "} " "}, " "\"type\" : 2" @@ -70,46 +78,86 @@ static void test1_func(abts_case *tc, void *data) "\"subscriber_status\" : 0, " "\"access_restriction_data\" : 32, " "\"security\" : { " - "\"k\" : \"70D49A71DD1A2B806A25ABE0EF749F1E\", " - "\"opc\" : \"6F1BF53D624B3A43AF6592854E2444C7\", " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"2374\" }, " - "\"rand\" : \"aa266700bc2887354e9f87368d5d0ae7\" " + "\"sqn\" : { \"$numberLong\" : \"64\" } " "}, " "\"__v\" : 0 " "}"; + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x19b010; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); + s1ap = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, s1ap); + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x0019b0, 7, 901, 70, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x19b0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1-Setup Response */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(NULL, recvbuf); + /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); - /********** Insert Subscriber in Database */ doc = bson_new_from_json((const uint8_t *)json, -1, &error);; ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, + ABTS_TRUE(tc, mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -117,54 +165,92 @@ static void test1_func(abts_case *tc, void *data) } while (count == 0); bson_destroy(doc); + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + /* Send Attach Request */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.mobile_station_classmark_3 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Identity-Request */ + /* Receive Identity Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Authentication Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Security mode Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive ESM Information Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -174,63 +260,66 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-Location-Update-Accept */ - rv = testsgsap_location_update_accept(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_location_update_accept(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Initial Context Setup Request + - * Attach Accept + + /* Receive Initial Context Setup Request + + * Attach Accept + * Activate Default Bearer Context Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 1, 1, 5, 0x00460003, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive EMM information */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Receive SGsAP TMSI-REALLOCATION-COMPLETE */ recvbuf = testvlr_sgsap_read(sgsap); ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); - /* Retreive M-TMSI */ - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(1); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - m_tmsi = mme_ue->guti.m_tmsi; - /* Send SGsAP-Paging-Request */ - rv = testsgsap_paging_request(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_paging_request(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1AP Paging */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Extended Service Request */ - rv = tests1ap_build_extended_service_request(&sendbuf, msgindex+1, - 1, m_tmsi, 4, mme_ue->knas_int); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + memset(&test_ue->extended_service_request_param, + 0, sizeof(test_ue->extended_service_request_param)); + emmbuf = testemm_build_extended_service_request(test_ue, 1); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -238,48 +327,54 @@ static void test1_func(abts_case *tc, void *data) recvbuf = testvlr_sgsap_read(sgsap); ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); - + /* Receive UE Context Modification Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Modification Response */ - rv = tests1ap_build_ue_context_modification_response(&sendbuf, 1, 1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_modification_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_msleep(300); + ogs_msleep(100); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) bson_destroy(doc); mongoc_collection_destroy(collection); /* eNB disonncect from MME */ testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); } abts_suite *test_mt_active(abts_suite *suite) diff --git a/tests/csfb/mt-idle-test.c b/tests/csfb/mt-idle-test.c index 7a93ae2eb..0f19cc37d 100644 --- a/tests/csfb/mt-idle-test.c +++ b/tests/csfb/mt-idle-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-common.h" extern ogs_socknode_t *sgsap; @@ -25,14 +25,22 @@ static void test1_func(abts_case *tc, void *data) { int rv; ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; ogs_pkbuf_t *sendbuf; ogs_pkbuf_t *recvbuf; ogs_s1ap_message_t message; - int i; - int msgindex = 18; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; mongoc_collection_t *collection = NULL; bson_t *doc = NULL; @@ -41,7 +49,7 @@ static void test1_func(abts_case *tc, void *data) const char *json = "{" "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"262420000118139\", " + "\"imsi\" : \"901707364000060\", " "\"pdn\" : [" "{" "\"apn\" : \"internet\", " @@ -53,9 +61,9 @@ static void test1_func(abts_case *tc, void *data) "\"qos\" : { " "\"qci\" : 9, " "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 0, " - "\"pre_emption_capability\" : 0" + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" "} " "}, " "\"type\" : 2" @@ -70,46 +78,86 @@ static void test1_func(abts_case *tc, void *data) "\"subscriber_status\" : 0, " "\"access_restriction_data\" : 32, " "\"security\" : { " - "\"k\" : \"70D49A71DD1A2B806A25ABE0EF749F1E\", " - "\"opc\" : \"6F1BF53D624B3A43AF6592854E2444C7\", " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"2374\" }, " - "\"rand\" : \"aa266700bc2887354e9f87368d5d0ae7\" " + "\"sqn\" : { \"$numberLong\" : \"64\" } " "}, " "\"__v\" : 0 " "}"; + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x19b010; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); + s1ap = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, s1ap); + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x0019b0, 7, 901, 70, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x19b0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1-Setup Response */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(NULL, recvbuf); + /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); - /********** Insert Subscriber in Database */ doc = bson_new_from_json((const uint8_t *)json, -1, &error);; ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, + ABTS_TRUE(tc, mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -117,54 +165,92 @@ static void test1_func(abts_case *tc, void *data) } while (count == 0); bson_destroy(doc); + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + /* Send Attach Request */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.mobile_station_classmark_3 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Identity-Request */ + /* Receive Identity Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Authentication Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Security mode Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive ESM Information Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -174,68 +260,69 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-Location-Update-Accept */ - rv = testsgsap_location_update_accept(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_location_update_accept(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Initial Context Setup Request + - * Attach Accept + + /* Receive Initial Context Setup Request + + * Attach Accept + * Activate Default Bearer Context Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 1, 1, 5, 0x00460003, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive EMM information */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Receive SGsAP TMSI-REALLOCATION-COMPLETE */ recvbuf = testvlr_sgsap_read(sgsap); ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); - /* Retreive M-TMSI */ - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(1); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - m_tmsi = mme_ue->guti.m_tmsi; - /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send SGsAP-Paging-Request */ - rv = testsgsap_paging_request(&sendbuf, 1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_paging_request(1); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -245,19 +332,25 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-Paging-Request */ - rv = testsgsap_paging_request(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_paging_request(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1AP Paging */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Extended Service Request */ - rv = tests1ap_build_extended_service_request(&sendbuf, msgindex, - 1, m_tmsi, 4, mme_ue->knas_int); + memset(&test_ue->extended_service_request_param, + 0, sizeof(test_ue->extended_service_request_param)); + emmbuf = testemm_build_extended_service_request(test_ue, 1); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -270,45 +363,50 @@ static void test1_func(abts_case *tc, void *data) /* Receive Initial Context Setup Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 2, 2, 5, 0x00470003, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_msleep(300); + ogs_msleep(100); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) bson_destroy(doc); mongoc_collection_destroy(collection); /* eNB disonncect from MME */ testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); } abts_suite *test_mt_idle(abts_suite *suite) diff --git a/tests/csfb/mt-sms-test.c b/tests/csfb/mt-sms-test.c index 413998c4e..000714d1f 100644 --- a/tests/csfb/mt-sms-test.c +++ b/tests/csfb/mt-sms-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-common.h" extern ogs_socknode_t *sgsap; @@ -25,14 +25,22 @@ static void test1_func(abts_case *tc, void *data) { int rv; ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; ogs_pkbuf_t *sendbuf; ogs_pkbuf_t *recvbuf; ogs_s1ap_message_t message; - int i; - int msgindex = 18; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; mongoc_collection_t *collection = NULL; bson_t *doc = NULL; @@ -41,7 +49,7 @@ static void test1_func(abts_case *tc, void *data) const char *json = "{" "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " - "\"imsi\" : \"262420000118139\", " + "\"imsi\" : \"901707364000060\", " "\"pdn\" : [" "{" "\"apn\" : \"internet\", " @@ -53,9 +61,9 @@ static void test1_func(abts_case *tc, void *data) "\"qos\" : { " "\"qci\" : 9, " "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 0, " - "\"pre_emption_capability\" : 0" + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" "} " "}, " "\"type\" : 2" @@ -70,46 +78,86 @@ static void test1_func(abts_case *tc, void *data) "\"subscriber_status\" : 0, " "\"access_restriction_data\" : 32, " "\"security\" : { " - "\"k\" : \"70D49A71DD1A2B806A25ABE0EF749F1E\", " - "\"opc\" : \"6F1BF53D624B3A43AF6592854E2444C7\", " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"2374\" }, " - "\"rand\" : \"aa266700bc2887354e9f87368d5d0ae7\" " + "\"sqn\" : { \"$numberLong\" : \"64\" } " "}, " "\"__v\" : 0 " "}"; + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x19b010; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); + s1ap = tests1ap_client(AF_INET); ABTS_PTR_NOTNULL(tc, s1ap); + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x0019b0, 7, 901, 70, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x19b0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1-Setup Response */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(NULL, recvbuf); + /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); - /********** Insert Subscriber in Database */ doc = bson_new_from_json((const uint8_t *)json, -1, &error);; ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, + ABTS_TRUE(tc, mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -117,54 +165,92 @@ static void test1_func(abts_case *tc, void *data) } while (count == 0); bson_destroy(doc); + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + /* Send Attach Request */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.mobile_station_classmark_3 = 1; + test_ue->attach_request_param.supported_codecs = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + test_ue->attach_request_param.ms_network_feature_support = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); ABTS_INT_EQUAL(tc, OGS_OK, rv); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Identity-Request */ + /* Receive Identity Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Authentication Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Security mode Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive ESM Information Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -174,93 +260,94 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-Location-Update-Accept */ - rv = testsgsap_location_update_accept(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_location_update_accept(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - /* Receive Initial Context Setup Request + - * Attach Accept + + /* Receive Initial Context Setup Request + + * Attach Accept + * Activate Default Bearer Context Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 1, 1, 5, 0x00460003, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive EMM information */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Receive SGsAP TMSI-REALLOCATION-COMPLETE */ recvbuf = testvlr_sgsap_read(sgsap); ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); - /* Retreive M-TMSI */ - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(1); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - m_tmsi = mme_ue->guti.m_tmsi; - /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_msleep(50); - /* Send SGsAP-Paging-Request */ - rv = testsgsap_paging_request(&sendbuf, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_paging_request(2); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive S1AP Paging */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Service Request */ - rv = tests1ap_build_service_request(&sendbuf, 0x000200, 4, 0x6033, m_tmsi); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + emmbuf = testemm_build_service_request(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Data, true); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Initial Context Setup Request */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 2, 2, 5, 0x00470003, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -270,52 +357,58 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send SGsAP-Downlink-Unitdata */ - rv = testsgsap_downlink_unitdata(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_downlink_unitdata(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive Downlink NAS Transport */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send SGsAP-RELEASE-REQUEST */ - rv = testsgsap_release_request(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_sgsap_release_request(0); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testvlr_sgsap_send(sgsap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_request(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive UE Context Release Command */ recvbuf = testenb_s1ap_read(s1ap); ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); + tests1ap_recv(test_ue, recvbuf); /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); rv = testenb_s1ap_send(s1ap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_msleep(300); + ogs_msleep(100); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("262420000118139")); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) bson_destroy(doc); mongoc_collection_destroy(collection); /* eNB disonncect from MME */ testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); } abts_suite *test_mt_sms(abts_suite *suite) diff --git a/tests/cups/abts-main.c b/tests/cups/abts-main.c deleted file mode 100644 index a05b38a3a..000000000 --- a/tests/cups/abts-main.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "test-app.h" - -#include "pcscf-fd-path.h" - -abts_suite *test_cups(abts_suite *suite); - -const struct testlist { - abts_suite *(*func)(abts_suite *suite); -} alltests[] = { - {test_cups}, - {NULL}, -}; - -static void terminate(void) -{ - ogs_msleep(50); - - test_child_terminate(); - app_terminate(); - - pcscf_fd_final(); - - test_app_final(); - ogs_app_terminate(); -} - -static void initialize(const char *const argv[]) -{ - int rv; - - rv = ogs_app_initialize(NULL, argv); - ogs_assert(rv == OGS_OK); - test_app_init(); - - rv = app_initialize(argv); - ogs_assert(rv == OGS_OK); - - /* - * To avoid freeDiameter error - * - * ROUTING ERROR - * 'No remaining suitable candidate to route the message to' for: - */ - ogs_msleep(500); - - rv = pcscf_fd_init(); - ogs_assert(rv == OGS_OK); -} - -int main(int argc, const char *const argv[]) -{ - int i; - abts_suite *suite = NULL; - - atexit(terminate); - test_5gc_run(argc, argv, "cups.yaml", initialize); - - for (i = 0; alltests[i].func; i++) - suite = alltests[i].func(suite); - - return abts_report(suite); -} diff --git a/tests/cups/cups-test.c b/tests/cups/cups-test.c deleted file mode 100644 index 4ca6f769a..000000000 --- a/tests/cups/cups-test.c +++ /dev/null @@ -1,1450 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "test-epc.h" -#include "pcscf-fd-path.h" - -#define TEST3_ONLY_PING 0 - -static void cups_test1(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_socknode_t *gtpu; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 0; - uint8_t *rx_sid = NULL; - - test_ue_t test_ue; - test_sess_t test_sess; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2b\" }," - "\"imsi\" : \"001010123456819\"," - "\"pdn\" : [" - "{ \"apn\" : \"internet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," - "\"qos\" : {" - "\"qci\" : 9," - "\"arp\" : {" - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }," - "{ \"apn\" : \"internet.ng2.mnet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2c\" }," - "\"pcc_rule\" : [" - "{ \"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," - "\"qos\" : {" - "\"qci\" : 1," - "\"gbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"mbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"arp\" : {" - "\"priority_level\" : 3," - "\"pre_emption_vulnerability\" : 0," - "\"pre_emption_capability\" : 0 } }" - "} ]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"35840\" }," - "\"uplink\" : { \"$numberLong\" : \"15360\" } }," - "\"qos\" : {" - "\"qci\" : 6," - "\"arp\" : {" - "\"priority_level\" : 6," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }" - "]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"1024000\" }," - "\"uplink\" : { \"$numberLong\" : \"1024000\" } }," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2," - "\"subscriber_status\" : 0," - "\"access_restriction_data\" : 32," - "\"security\" : {" - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\"," - "\"op\" : \"5F1D289C 5D354D0A 140C2548 F5F3E3BA\"," - "\"amf\" : \"8000\"," - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"20080C38 18183B52 2614162C 07601D0D\" }, " - "\"__v\" : 0" - "}"; - - /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.imsi = (char *)"001010123456819"; - - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr(TEST_GNB_IPV4); - test_sess.gnb_n3_teid = 0; - - test_sess.upf_n3_ip.ipv4 = true; - test_sess.upf_n3_ip.addr = inet_addr(TEST_SGWU_IPV4); - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client(TEST_MME_IPV4); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* eNB connects to SGW */ - gtpu = testenb_gtpu_server(TEST_ENB_IPV4); - ABTS_PTR_NOTNULL(tc, gtpu); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - /********** Insert Subscriber in Database */ - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - if (count) { - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - } - bson_destroy(doc); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, No Security Context - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response( - &sendbuf, 1, 1, 5, 1, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send GTP-U ICMP Packet */ - test_sess.upf_n3_teid = 2; - test_sess.ue_ip.addr = inet_addr("10.45.0.2"); - - rv = test_gtpu_build_ping(&sendbuf, &test_sess, TEST_PING_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_sendto(gtpu, sendbuf, TEST_SGWU_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive GTP-U ICMP Packet */ - recvbuf = testenb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send PDN Connectivity Request */ - rv = tests1ap_build_pdn_connectivity_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Setup Request + - * Activate default EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response( - &sendbuf, 1, 1, 6, 2, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Activate default EPS bearer context accept */ - rv = tests1ap_build_activate_default_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send GTP-U ICMP Packet */ - test_sess.upf_n3_teid = 4; - test_sess.ue_ip.addr = inet_addr("10.45.0.3"); - - rv = test_gtpu_build_ping(&sendbuf, &test_sess, TEST_PING_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_sendto(gtpu, sendbuf, TEST_SGWU_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive GTP-U ICMP Packet */ - recvbuf = testenb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send AA-Request */ - ogs_msleep(300); - pcscf_rx_send_aar(&rx_sid, "10.45.0.3", 1, 1); - - /* Receive E-RAB Setup Request + - * Activate dedicated EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response(&sendbuf, - 1, 1, 7, 3, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Activate dedicated EPS bearer context accept */ - rv = tests1ap_build_activate_dedicated_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send AA-Request without Flow */ - ogs_msleep(300); - pcscf_rx_send_aar(&rx_sid, "10.45.0.3", 2, 1); - - /* Receive E-RAB Modify Request + - * Modify EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Modify Response */ - rv = tests1ap_build_e_rab_modify_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Modify EPS bearer context accept */ - rv = tests1ap_build_modify_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(50); - - /* Send Bearer resource allocation request */ - rv = tests1ap_build_bearer_resource_allocation_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Bearer resource allocation reject */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Bearer resource modification request */ - rv = tests1ap_build_bearer_resource_modification_request(&sendbuf, - 1, 1, 3, 0x3f426e62, 7, 7, - OGS_GTP_TFT_CODE_NO_TFT_OPERATION, - 1, 0, 0, 0, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Bearer resource modification reject */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Bearer resource modification request */ - rv = tests1ap_build_bearer_resource_modification_request(&sendbuf, - 1, 1, 4, 0xdc64fbbc, 8, 7, - OGS_GTP_TFT_CODE_ADD_PACKET_FILTERS_TO_EXISTING_TFT, - 1, 44, 55, 22, 33); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Modify Request + - * Modify EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Modify EPS bearer context accept */ - rv = tests1ap_build_modify_bearer_accept(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send E-RAB Modify Response */ - rv = tests1ap_build_e_rab_modify_response(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Bearer resource modification request */ - rv = tests1ap_build_bearer_resource_modification_request(&sendbuf, - 1, 1, 5, 0x87a44610, 9, 7, - OGS_GTP_TFT_CODE_REPLACE_PACKET_FILTERS_IN_EXISTING, - 1, 0, 0, 0, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Modify Request + - * Modify EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Modify Response */ - rv = tests1ap_build_e_rab_modify_response(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Modify EPS bearer context accept */ - rv = tests1ap_build_modify_bearer_accept(&sendbuf, msgindex+2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Session-Termination-Request */ - ogs_msleep(50); - pcscf_rx_send_str(rx_sid); - - /* Receive E-RAB Release Command + - * Dectivate EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Release Response */ - rv = tests1ap_build_e_rab_release_response(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(50); - - /* Send Deactivate EPS bearer context accept */ - rv = tests1ap_build_deactivate_bearer_accept(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(50); - - /* Send Detach Request */ - rv = tests1ap_build_detach_request(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); - - /* eNB disonncect from SGW */ - testenb_gtpu_close(gtpu); -} - -static void cups_test2(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 0; - uint8_t *rx_sid = NULL; - - test_ue_t test_ue; - test_sess_t test_sess; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2b\" }," - "\"imsi\" : \"001010123456819\"," - "\"pdn\" : [" - "{ \"apn\" : \"internet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," - "\"qos\" : {" - "\"qci\" : 9," - "\"arp\" : {" - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }," - "{ \"apn\" : \"internet.ng2.mnet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2c\" }," - "\"pcc_rule\" : [" - "{ \"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," - "\"qos\" : {" - "\"qci\" : 1," - "\"gbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"mbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"arp\" : {" - "\"priority_level\" : 3," - "\"pre_emption_vulnerability\" : 0," - "\"pre_emption_capability\" : 0 } }," - "\"flow\" : [" - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } } ]" - "} ]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"35840\" }," - "\"uplink\" : { \"$numberLong\" : \"15360\" } }," - "\"qos\" : {" - "\"qci\" : 6," - "\"arp\" : {" - "\"priority_level\" : 6," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }" - "]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"1024000\" }," - "\"uplink\" : { \"$numberLong\" : \"1024000\" } }," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2," - "\"subscriber_status\" : 0," - "\"access_restriction_data\" : 32," - "\"security\" : {" - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\"," - "\"op\" : \"5F1D289C 5D354D0A 140C2548 F5F3E3BA\"," - "\"amf\" : \"8000\"," - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"20080C38 18183B52 2614162C 07601D0D\" }, " - "\"__v\" : 0" - "}"; - - /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.imsi = (char *)"001010123456819"; - - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr(TEST_GNB_IPV4); - test_sess.gnb_n3_teid = 0; - - test_sess.upf_n3_ip.ipv4 = true; - test_sess.upf_n3_ip.addr = inet_addr(TEST_SGWU_IPV4); - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client(TEST_MME_IPV4); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - /********** Insert Subscriber in Database */ - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - if (count) { - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - } - bson_destroy(doc); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, No Security Context - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response( - &sendbuf, 1, 1, 5, 1, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send PDN Connectivity Request */ - rv = tests1ap_build_pdn_connectivity_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Setup Request + - * Activate default EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response( - &sendbuf, 1, 1, 6, 2, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Activate default EPS bearer context accept */ - rv = tests1ap_build_activate_default_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Setup Request + - * Activate dedicated EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Activate dedicated EPS bearer context accept */ - rv = tests1ap_build_activate_dedicated_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response( - &sendbuf, 1, 1, 7, 3, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send AA-Request */ - ogs_msleep(300); - pcscf_rx_send_aar(&rx_sid, "10.45.0.5", 0, 1); - - /* Receive downlink NAS transport + - * Modify EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Modify EPS bearer context accept */ - rv = tests1ap_build_modify_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send PDN disconnectivity request */ - rv = tests1ap_build_pdn_disconnectivity_request(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Release Command + - * Deactivate EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Release Response */ - rv = tests1ap_build_e_rab_release_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Deactivate EPS bearer context accept */ - rv = tests1ap_build_deactivate_bearer_accept(&sendbuf, msgindex+2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); -} - -static void cups_test3(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_socknode_t *gtpu; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 0; - - test_ue_t test_ue; - test_sess_t test_sess; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2b\" }," - "\"imsi\" : \"001010123456819\"," - "\"pdn\" : [" - "{ \"apn\" : \"internet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," - "\"qos\" : {" - "\"qci\" : 9," - "\"arp\" : {" - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }," - "{ \"apn\" : \"internet.ng2.mnet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2c\" }," - "\"pcc_rule\" : [" - "{ \"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," - "\"qos\" : {" - "\"qci\" : 1," - "\"gbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"mbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"arp\" : {" - "\"priority_level\" : 3," - "\"pre_emption_vulnerability\" : 0," - "\"pre_emption_capability\" : 0 } }," - "\"flow\" : [" - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } } ]" - "} ]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"35840\" }," - "\"uplink\" : { \"$numberLong\" : \"15360\" } }," - "\"qos\" : {" - "\"qci\" : 6," - "\"arp\" : {" - "\"priority_level\" : 6," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }" - "]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"1024000\" }," - "\"uplink\" : { \"$numberLong\" : \"1024000\" } }," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2," - "\"subscriber_status\" : 0," - "\"access_restriction_data\" : 32," - "\"security\" : {" - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\"," - "\"op\" : \"5F1D289C 5D354D0A 140C2548 F5F3E3BA\"," - "\"amf\" : \"8000\"," - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"20080C38 18183B52 2614162C 07601D0D\" }, " - "\"__v\" : 0" - "}"; - - /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.imsi = (char *)"001010123456819"; - - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr(TEST_GNB_IPV4); - test_sess.gnb_n3_teid = 0; - - test_sess.upf_n3_ip.ipv4 = true; - test_sess.upf_n3_ip.addr = inet_addr(TEST_SGWU_IPV4); - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client(TEST_MME_IPV4); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* eNB connects to SGW */ - gtpu = testenb_gtpu_server(TEST_ENB_IPV4); - ABTS_PTR_NOTNULL(tc, gtpu); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - /********** Insert Subscriber in Database */ - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - if (count) { - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - } - bson_destroy(doc); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, No Security Context - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response( - &sendbuf, 1, 1, 5, 1, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send GTP-U ICMP Packet */ -#if TEST3_ONLY_PING - test_sess.upf_n3_teid = 2; - test_sess.ue_ip.addr = inet_addr("10.45.0.2"); -#else - test_sess.upf_n3_teid = 0xe; - test_sess.ue_ip.addr = inet_addr("10.45.0.6"); -#endif - - rv = test_gtpu_build_ping(&sendbuf, &test_sess, TEST_PING_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_sendto(gtpu, sendbuf, TEST_SGWU_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive GTP-U ICMP Packet */ - recvbuf = testenb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send PDN Connectivity Request */ - rv = tests1ap_build_pdn_connectivity_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Setup Request + - * Activate default EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response( - &sendbuf, 1, 1, 6, 2, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Activate default EPS bearer context accept */ - rv = tests1ap_build_activate_default_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Setup Request + - * Activate dedicated EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Activate dedicated EPS bearer context accept */ - rv = tests1ap_build_activate_dedicated_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response( - &sendbuf, 1, 1, 7, 3, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send GTP-U ICMP Packet */ - ogs_msleep(50); - - /* Send GTP-U ICMP Packet */ -#if TEST3_ONLY_PING - test_sess.upf_n3_teid = 4; - test_sess.ue_ip.addr = inet_addr("10.45.0.3"); -#else - test_sess.upf_n3_teid = 0x12; - test_sess.ue_ip.addr = inet_addr("10.45.0.7"); -#endif - - rv = test_gtpu_build_ping(&sendbuf, &test_sess, TEST_PING_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_sendto(gtpu, sendbuf, TEST_SGWU_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive GTP-U ICMP Packet */ - recvbuf = testenb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - ogs_msleep(300); - - /* Send PDN disconnectivity request */ - rv = tests1ap_build_pdn_disconnectivity_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Release Command + - * Deactivate EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Release Response */ - rv = tests1ap_build_e_rab_release_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Deactivate EPS bearer context accept */ - rv = tests1ap_build_deactivate_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send INVALID PDN Connectivity Request */ - rv = tests1ap_build_pdn_connectivity_request(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive PDN Connectivity Reject */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); - - /* eNB disonncect from SGW */ - testenb_gtpu_close(gtpu); -} - -static void cups_test4(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 0; - - test_ue_t test_ue; - test_sess_t test_sess; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2b\" }," - "\"imsi\" : \"001010123456819\"," - "\"pdn\" : [" - "{ \"apn\" : \"internet.ng2.mnet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," - "\"qos\" : {" - "\"qci\" : 9," - "\"arp\" : {" - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }," - "{ \"apn\" : \"internet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2c\" }," - "\"pcc_rule\" : [" - "{ \"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," - "\"qos\" : {" - "\"qci\" : 1," - "\"gbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"mbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"arp\" : {" - "\"priority_level\" : 3," - "\"pre_emption_vulnerability\" : 0," - "\"pre_emption_capability\" : 0 } }," - "\"flow\" : [" - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out ip from 10.45.0.1 to any\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/24 23455\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out ip from cafe::1 to any\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } } ]" - "} ]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"35840\" }," - "\"uplink\" : { \"$numberLong\" : \"15360\" } }," - "\"qos\" : {" - "\"qci\" : 6," - "\"arp\" : {" - "\"priority_level\" : 6," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }" - "]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"1024000\" }," - "\"uplink\" : { \"$numberLong\" : \"1024000\" } }," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2," - "\"subscriber_status\" : 0," - "\"access_restriction_data\" : 32," - "\"security\" : {" - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\"," - "\"op\" : \"5F1D289C 5D354D0A 140C2548 F5F3E3BA\"," - "\"amf\" : \"8000\"," - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"20080C38 18183B52 2614162C 07601D0D\" }, " - "\"__v\" : 0" - "}"; - - /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.imsi = (char *)"001010123456819"; - - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr(TEST_GNB_IPV4); - test_sess.gnb_n3_teid = 0; - - test_sess.upf_n3_ip.ipv4 = true; - test_sess.upf_n3_ip.addr = inet_addr(TEST_SGWU_IPV4); - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client(TEST_MME_IPV4); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - /********** Insert Subscriber in Database */ - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - if (count) { - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - } - bson_destroy(doc); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, MAC failed - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response( - &sendbuf, 16777373, 1, 5, 1, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive E-RAB Setup Request + - * Activate dedicated EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response( - &sendbuf, 33554492, 1, 6, 2, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Activate dedicated EPS bearer context accept */ - rv = tests1ap_build_activate_dedicated_bearer_accept(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); -} - -abts_suite *test_cups(abts_suite *suite) -{ - suite = ADD_SUITE(suite) - - abts_run_test(suite, cups_test1, NULL); - abts_run_test(suite, cups_test2, NULL); - abts_run_test(suite, cups_test3, NULL); - abts_run_test(suite, cups_test4, NULL); - - return suite; -} diff --git a/tests/cups/meson.build b/tests/cups/meson.build deleted file mode 100644 index e9da736c9..000000000 --- a/tests/cups/meson.build +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright (C) 2019 by Sukchan Lee - -# This file is part of Open5GS. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -testapp_cups_sources = files(''' - pcscf-fd-path.h - pcscf-fd-path.c - - abts-main.c - cups-test.c -'''.split()) - -testapp_cups_exe = executable('cups', - sources : testapp_cups_sources, - c_args : [testunit_core_cc_flags, - '-DFD_EXT_DIR="@0@"'.format(freediameter_extensions_builddir)], - dependencies : libtestapp_dep) - -test('cups', testapp_cups_exe, is_parallel : false, suite: 'app') diff --git a/tests/cups/pcscf-fd-path.c b/tests/cups/pcscf-fd-path.c deleted file mode 100644 index 24c099cbe..000000000 --- a/tests/cups/pcscf-fd-path.c +++ /dev/null @@ -1,948 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "ogs-gtp.h" -#include "ogs-diameter-rx.h" - -#include "pcscf-fd-path.h" - -#define MAX_NUM_SESSION_STATE 32 - -static struct session_handler *pcscf_rx_reg = NULL; -static struct disp_hdl *hdl_rx_fb = NULL; -static struct disp_hdl *hdl_rx_asr = NULL; -static ogs_diam_config_t diam_config; - -struct sess_state { - os0_t sid; /* Rx Session-Id */ - - struct timespec ts; /* Time of sending the message */ -}; - -static void pcscf_rx_aaa_cb(void *data, struct msg **msg); -static void pcscf_rx_sta_cb(void *data, struct msg **msg); - -static __inline__ struct sess_state *new_state(os0_t sid) -{ - struct sess_state *new = NULL; - - new = ogs_calloc(1, sizeof(*new)); - new->sid = (os0_t)ogs_strdup((char *)sid); - ogs_assert(new->sid); - - return new; -} - -static void state_cleanup(struct sess_state *sess_data, os0_t sid, void *opaque) -{ - if (sess_data->sid) - ogs_free(sess_data->sid); - - ogs_free(sess_data); -} - -static int pcscf_rx_fb_cb(struct msg **msg, struct avp *avp, - struct session *sess, void *opaque, enum disp_action *act) -{ - /* This CB should never be called */ - ogs_warn("Unexpected message received!"); - - return ENOTSUP; -} - -void pcscf_rx_send_aar(uint8_t **rx_sid, const char *ip, - int qos_type, int flow_presence) -{ - int rv; - int ret; - - struct msg *req = NULL; - struct avp *avp; - struct avp *avpch1, *avpch2; - union avp_value val; - struct sess_state *sess_data = NULL, *svg; - struct session *session = NULL; - int new; - - ogs_paa_t paa; - ogs_ipsubnet_t ipsub; - - ogs_assert(rx_sid); - - ogs_assert(ip); - rv = ogs_ipsubnet(&ipsub, ip, NULL); - ogs_assert(rv == OGS_OK); - - /* Create the request */ - ret = fd_msg_new(ogs_diam_rx_cmd_aar, MSGFL_ALLOC_ETEID, &req); - ogs_assert(ret == 0); - { - struct msg_hdr * h; - ret = fd_msg_hdr( req, &h ); - ogs_assert(ret == 0); - h->msg_appl = OGS_DIAM_RX_APPLICATION_ID; - } - - /* Find Diameter Rx Session */ - if (*rx_sid) { - /* Retrieve session by Session-Id */ - size_t sidlen = strlen((char *)*rx_sid); - ret = fd_sess_fromsid_msg(*rx_sid, sidlen, &session, &new); - ogs_assert(ret == 0); - ogs_assert(new == 0); - - /* Add Session-Id to the message */ - ret = ogs_diam_message_session_id_set(req, *rx_sid, sidlen); - ogs_assert(ret == 0); - /* Save the session associated with the message */ - ret = fd_msg_sess_set(req, session); - } else { - /* Create a new session */ - #define OGS_DIAM_RX_APP_SID_OPT "app_rx" - ret = fd_msg_new_session(req, (os0_t)OGS_DIAM_RX_APP_SID_OPT, - CONSTSTRLEN(OGS_DIAM_RX_APP_SID_OPT)); - ogs_assert(ret == 0); - ret = fd_msg_sess_get(fd_g_config->cnf_dict, req, &session, NULL); - ogs_assert(ret == 0); - } - - /* Retrieve session state in this session */ - ret = fd_sess_state_retrieve(pcscf_rx_reg, session, &sess_data); - if (!sess_data) { - os0_t sid; - size_t sidlen; - - ret = fd_sess_getsid(session, &sid, &sidlen); - ogs_assert(ret == 0); - - /* Allocate new session state memory */ - sess_data = new_state(sid); - ogs_assert(sess_data); - - /* Save Session-Id to PGW Session Context */ - *rx_sid = sess_data->sid; - } - - /* Set Origin-Host & Origin-Realm */ - ret = fd_msg_add_origin(req, 0); - ogs_assert(ret == 0); - - /* Set the Destination-Realm AVP */ - ret = fd_msg_avp_new(ogs_diam_destination_realm, 0, &avp); - ogs_assert(ret == 0); - val.os.data = (unsigned char *)(fd_g_config->cnf_diamrlm); - val.os.len = strlen(fd_g_config->cnf_diamrlm); - ret = fd_msg_avp_setvalue(avp, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); - ogs_assert(ret == 0); - - /* Set the Auth-Application-Id AVP */ - ret = fd_msg_avp_new(ogs_diam_auth_application_id, 0, &avp); - ogs_assert(ret == 0); - val.i32 = OGS_DIAM_RX_APPLICATION_ID; - ret = fd_msg_avp_setvalue(avp, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); - ogs_assert(ret == 0); - - /* Set Subscription-Id */ - ret = fd_msg_avp_new(ogs_diam_rx_subscription_id, 0, &avp); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new(ogs_diam_rx_subscription_id_type, 0, &avpch1); - ogs_assert(ret == 0); - val.i32 = OGS_DIAM_RX_SUBSCRIPTION_ID_TYPE_END_USER_IMSI; - ret = fd_msg_avp_setvalue (avpch1, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - - #define OGS_DIAM_RX_APP_IMSI_BCD "001010123456789" - ret = fd_msg_avp_new(ogs_diam_rx_subscription_id_data, 0, &avpch1); - ogs_assert(ret == 0); - val.os.data = (uint8_t *)OGS_DIAM_RX_APP_IMSI_BCD; - val.os.len = strlen(OGS_DIAM_RX_APP_IMSI_BCD); - ret = fd_msg_avp_setvalue (avpch1, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - - ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); - ogs_assert(ret == 0); - - if (ipsub.family == AF_INET) { - /* Set Framed-IP-Address */ - ret = fd_msg_avp_new(ogs_diam_rx_framed_ip_address, 0, &avp); - ogs_assert(ret == 0); - val.os.data = (uint8_t*)ipsub.sub; - val.os.len = OGS_IPV4_LEN; - ret = fd_msg_avp_setvalue(avp, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); - ogs_assert(ret == 0); - } else if (ipsub.family == AF_INET6) { - /* Set Framed-IPv6-Prefix */ - ret = fd_msg_avp_new(ogs_diam_rx_framed_ipv6_prefix, 0, &avp); - ogs_assert(ret == 0); - memset(&paa, 0, sizeof(ogs_paa_t)); - - memcpy(paa.addr6, ipsub.sub, OGS_IPV6_LEN); - paa.pdn_type = 0x03; -#define FRAMED_IPV6_PREFIX_LENGTH 128 /* from spec document */ - paa.len = FRAMED_IPV6_PREFIX_LENGTH; - val.os.data = (uint8_t*)&paa; - val.os.len = OGS_PAA_IPV6_LEN; - ret = fd_msg_avp_setvalue(avp, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); - ogs_assert(ret == 0); - } - - /* Set Media-Component-Description */ - ret = fd_msg_avp_new(ogs_diam_rx_media_component_description, 0, &avp); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new(ogs_diam_rx_media_component_number, 0, &avpch1); - ogs_assert(ret == 0); - val.i32 = 1; - ret = fd_msg_avp_setvalue (avpch1, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new(ogs_diam_rx_media_type, 0, &avpch1); - ogs_assert(ret == 0); - val.i32 = OGS_DIAM_RX_MEDIA_TYPE_AUDIO; - ret = fd_msg_avp_setvalue (avpch1, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - - if (qos_type == 1) { - ret = fd_msg_avp_new( - ogs_diam_rx_max_requested_bandwidth_dl, 0, &avpch1); - ogs_assert(ret == 0); - val.i32 = 96000; - ret = fd_msg_avp_setvalue (avpch1, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new( - ogs_diam_rx_max_requested_bandwidth_ul, 0, &avpch1); - ogs_assert(ret == 0); - val.i32 = 96000; - ret = fd_msg_avp_setvalue (avpch1, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new(ogs_diam_rx_rr_bandwidth, 0, &avpch1); - ogs_assert(ret == 0); - val.i32 = 2400; - ret = fd_msg_avp_setvalue (avpch1, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new(ogs_diam_rx_rs_bandwidth, 0, &avpch1); - ogs_assert(ret == 0); - val.i32 = 2400; - ret = fd_msg_avp_setvalue (avpch1, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - } else if (qos_type == 2) { - ret = fd_msg_avp_new( - ogs_diam_rx_max_requested_bandwidth_dl, 0, &avpch1); - ogs_assert(ret == 0); - val.i32 = 96000; - ret = fd_msg_avp_setvalue (avpch1, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new( - ogs_diam_rx_max_requested_bandwidth_ul, 0, &avpch1); - ogs_assert(ret == 0); - val.i32 = 96000; - ret = fd_msg_avp_setvalue (avpch1, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new( - ogs_diam_rx_min_requested_bandwidth_dl, 0, &avpch1); - ogs_assert(ret == 0); - val.i32 = 88000; - ret = fd_msg_avp_setvalue (avpch1, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new( - ogs_diam_rx_min_requested_bandwidth_ul, 0, &avpch1); - ogs_assert(ret == 0); - val.i32 = 88000; - ret = fd_msg_avp_setvalue (avpch1, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - } - - if (flow_presence) { - /* Set Media-Sub-Component #1 */ - ret = fd_msg_avp_new(ogs_diam_rx_media_sub_component, 0, &avpch1); - - ret = fd_msg_avp_new(ogs_diam_rx_flow_number, 0, &avpch2); - ogs_assert(ret == 0); - val.i32 = 1; - ret = fd_msg_avp_setvalue (avpch2, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new(ogs_diam_rx_flow_description, 0, &avpch2); - ogs_assert(ret == 0); - #define TEST_OGS_DIAM_RX_FLOW_DESC1 \ - "permit out 17 from 172.20.166.84 to 172.18.128.20 20001" - val.os.data = (uint8_t *)TEST_OGS_DIAM_RX_FLOW_DESC1; - val.os.len = strlen(TEST_OGS_DIAM_RX_FLOW_DESC1); - ret = fd_msg_avp_setvalue (avpch2, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new(ogs_diam_rx_flow_description, 0, &avpch2); - ogs_assert(ret == 0); - #define TEST_OGS_DIAM_RX_FLOW_DESC2 \ - "permit in 17 from 172.18.128.20 to 172.20.166.84 20360" - val.os.data = (uint8_t *)TEST_OGS_DIAM_RX_FLOW_DESC2; - val.os.len = strlen(TEST_OGS_DIAM_RX_FLOW_DESC2); - ret = fd_msg_avp_setvalue (avpch2, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2); - ogs_assert(ret == 0); - - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - - /* Set Media-Sub-Component #2 */ - ret = fd_msg_avp_new(ogs_diam_rx_media_sub_component, 0, &avpch1); - - ret = fd_msg_avp_new(ogs_diam_rx_flow_number, 0, &avpch2); - ogs_assert(ret == 0); - val.i32 = 2; - ret = fd_msg_avp_setvalue (avpch2, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new(ogs_diam_rx_flow_usage, 0, &avpch2); - ogs_assert(ret == 0); - val.i32 = OGS_DIAM_RX_FLOW_USAGE_RTCP; - ret = fd_msg_avp_setvalue (avpch2, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new(ogs_diam_rx_flow_description, 0, &avpch2); - ogs_assert(ret == 0); - #define TEST_OGS_DIAM_RX_FLOW_DESC3 \ - "permit out 17 from 172.20.166.84 to 172.18.128.20 20002" - val.os.data = (uint8_t *)TEST_OGS_DIAM_RX_FLOW_DESC3; - val.os.len = strlen(TEST_OGS_DIAM_RX_FLOW_DESC3); - ret = fd_msg_avp_setvalue (avpch2, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2); - ogs_assert(ret == 0); - - ret = fd_msg_avp_new(ogs_diam_rx_flow_description, 0, &avpch2); - ogs_assert(ret == 0); - #define TEST_OGS_DIAM_RX_FLOW_DESC4 \ - "permit in 17 from 172.18.128.20 to 172.20.166.84 20361" - val.os.data = (uint8_t *)TEST_OGS_DIAM_RX_FLOW_DESC4; - val.os.len = strlen(TEST_OGS_DIAM_RX_FLOW_DESC4); - ret = fd_msg_avp_setvalue (avpch2, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2); - ogs_assert(ret == 0); - - ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); - ogs_assert(ret == 0); - } - - ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); - ogs_assert(ret == 0); - - ret = clock_gettime(CLOCK_REALTIME, &sess_data->ts); - ogs_assert(ret == 0); - - /* Keep a pointer to the session data for debug purpose, - * in real life we would not need it */ - svg = sess_data; - - /* Store this value in the session */ - ret = fd_sess_state_store(pcscf_rx_reg, session, &sess_data); - ogs_assert(ret == 0); - ogs_assert(sess_data == NULL); - - /* Send the request */ - ret = fd_msg_send(&req, pcscf_rx_aaa_cb, svg); - ogs_assert(ret == 0); - - /* Increment the counter */ - ogs_assert(pthread_mutex_lock(&ogs_diam_logger_self()->stats_lock) == 0); - ogs_diam_logger_self()->stats.nb_sent++; - ogs_assert(pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0); -} - -static void pcscf_rx_aaa_cb(void *data, struct msg **msg) -{ - int ret; - - struct sess_state *sess_data = NULL; - struct timespec ts; - struct session *session; - struct avp *avp, *avpch1; - struct avp_hdr *hdr; - unsigned long dur; - int error = 0; - int new; - int result_code = 0; - - ret = clock_gettime(CLOCK_REALTIME, &ts); - ogs_assert(ret == 0); - - /* Search the session, retrieve its data */ - ret = fd_msg_sess_get(fd_g_config->cnf_dict, *msg, &session, &new); - ogs_assert(ret == 0); - ogs_assert(new == 0); - - ret = fd_sess_state_retrieve(pcscf_rx_reg, session, &sess_data); - ogs_assert(ret == 0); - ogs_assert(sess_data); - ogs_assert((void *)sess_data == data); - - /* Value of Result Code */ - ret = fd_msg_search_avp(*msg, ogs_diam_result_code, &avp); - ogs_assert(ret == 0); - if (avp) { - ret = fd_msg_avp_hdr(avp, &hdr); - ogs_assert(ret == 0); - result_code = hdr->avp_value->i32; - ogs_debug("Result Code: %d\n", hdr->avp_value->i32); - } else { - ret = fd_msg_search_avp(*msg, ogs_diam_experimental_result, &avp); - ogs_assert(ret == 0); - if (avp) { - ret = fd_avp_search_avp( - avp, ogs_diam_experimental_result_code, &avpch1); - ogs_assert(ret == 0); - if (avpch1) { - ret = fd_msg_avp_hdr(avpch1, &hdr); - ogs_assert(ret == 0); - result_code = hdr->avp_value->i32; - ogs_debug("Experimental Result Code: %d\n", - result_code); - } - } else { - ogs_error("no Result-Code"); - error++; - } - } - - /* Value of Origin-Host */ - ret = fd_msg_search_avp(*msg, ogs_diam_origin_host, &avp); - ogs_assert(ret == 0); - if (avp) { - ret = fd_msg_avp_hdr(avp, &hdr); - ogs_assert(ret == 0); - ogs_debug("From '%.*s' ", - (int)hdr->avp_value->os.len, hdr->avp_value->os.data); - } else { - ogs_error("no_Origin-Host "); - error++; - } - - /* Value of Origin-Realm */ - ret = fd_msg_search_avp(*msg, ogs_diam_origin_realm, &avp); - ogs_assert(ret == 0); - if (avp) { - ret = fd_msg_avp_hdr(avp, &hdr); - ogs_assert(ret == 0); - ogs_debug("('%.*s') ", - (int)hdr->avp_value->os.len, hdr->avp_value->os.data); - } else { - ogs_error("no_Origin-Realm "); - error++; - } - - if (result_code != ER_DIAMETER_SUCCESS) { - ogs_warn("ERROR DIAMETER Result Code(%d)", result_code); - error++; - goto out; - } - -out: - /* Free the message */ - ogs_assert(pthread_mutex_lock(&ogs_diam_logger_self()->stats_lock) == 0); - dur = ((ts.tv_sec - sess_data->ts.tv_sec) * 1000000) + - ((ts.tv_nsec - sess_data->ts.tv_nsec) / 1000); - if (ogs_diam_logger_self()->stats.nb_recv) { - /* Ponderate in the avg */ - ogs_diam_logger_self()->stats.avg = (ogs_diam_logger_self()->stats.avg * - ogs_diam_logger_self()->stats.nb_recv + dur) / - (ogs_diam_logger_self()->stats.nb_recv + 1); - /* Min, max */ - if (dur < ogs_diam_logger_self()->stats.shortest) - ogs_diam_logger_self()->stats.shortest = dur; - if (dur > ogs_diam_logger_self()->stats.longest) - ogs_diam_logger_self()->stats.longest = dur; - } else { - ogs_diam_logger_self()->stats.shortest = dur; - ogs_diam_logger_self()->stats.longest = dur; - ogs_diam_logger_self()->stats.avg = dur; - } - if (error) - ogs_diam_logger_self()->stats.nb_errs++; - else - ogs_diam_logger_self()->stats.nb_recv++; - - ogs_assert(pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0); - - /* Display how long it took */ - if (ts.tv_nsec > sess_data->ts.tv_nsec) - ogs_debug("in %d.%06ld sec\n", - (int)(ts.tv_sec - sess_data->ts.tv_sec), - (long)(ts.tv_nsec - sess_data->ts.tv_nsec) / 1000); - else - ogs_debug("in %d.%06ld sec\n", - (int)(ts.tv_sec + 1 - sess_data->ts.tv_sec), - (long)(1000000000 + ts.tv_nsec - sess_data->ts.tv_nsec) / 1000); - - ret = fd_sess_state_store(pcscf_rx_reg, session, &sess_data); - ogs_assert(ret == 0); - ogs_assert(sess_data == NULL); - - ret = fd_msg_free(*msg); - ogs_assert(ret == 0); - *msg = NULL; - - return; -} - -static int pcscf_rx_asr_cb( struct msg **msg, struct avp *avp, - struct session *sess, void *opaque, enum disp_action *act) -{ - int rv; - int ret; - - struct msg *ans, *qry; - struct avp *avpch1, *avpch2, *avpch3; - struct avp_hdr *hdr; - union avp_value val; - struct sess_state *sess_data = NULL; - os0_t sid; - size_t sidlen; - - ogs_assert(msg); - ogs_assert(sess); - - ret = fd_sess_state_retrieve(pcscf_rx_reg, sess, &sess_data); - ogs_assert(ret == 0); - ogs_assert(sess_data); - - /* Create answer header */ - qry = *msg; - ret = fd_msg_new_answer_from_req(fd_g_config->cnf_dict, msg, 0); - ogs_assert(ret == 0); - ans = *msg; - - /* Set the Auth-Application-Id AVP */ - ret = fd_msg_avp_new(ogs_diam_auth_application_id, 0, &avp); - ogs_assert(ret == 0); - val.i32 = OGS_DIAM_RX_APPLICATION_ID; - ret = fd_msg_avp_setvalue(avp, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp); - ogs_assert(ret == 0); - - /* Set the Auth-Request-Type AVP */ - ret = fd_msg_avp_new(ogs_diam_auth_request_type, 0, &avp); - ogs_assert(ret == 0); - val.i32 = 1; - ret = fd_msg_avp_setvalue(avp, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp); - ogs_assert(ret == 0); - - /* Get Abort-Cause */ - ret = fd_msg_search_avp(qry, ogs_diam_rx_abort_cause, &avp); - ogs_assert(ret == 0); - if (avp) { - ret = fd_msg_avp_hdr(avp, &hdr); - ogs_assert(ret == 0); - } else { - ogs_error("no_Abort-Cause "); - } - - /* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */ - ret = fd_msg_rescode_set(ans, (char*)"DIAMETER_SUCCESS", NULL, NULL, 1); - ogs_assert(ret == 0); - - /* Store this value in the session */ - sid = sess_data->sid; - ogs_assert(sid); - - ret = fd_sess_state_store(pcscf_rx_reg, sess, &sess_data); - ogs_assert(ret == 0); - ogs_assert(sess_data == NULL); - - /* Send the answer */ - ret = fd_msg_send(msg, NULL, NULL); - ogs_assert(ret == 0); - - /* Add this value to the stats */ - ogs_assert(pthread_mutex_lock(&ogs_diam_logger_self()->stats_lock) == 0); - ogs_diam_logger_self()->stats.nb_echoed++; - ogs_assert(pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0); - - pcscf_rx_send_str(sid); - - return 0; -} - -void pcscf_rx_send_str(uint8_t *rx_sid) -{ - int rv; - int ret; - - struct msg *req = NULL; - struct avp *avp; - struct avp *avpch1, *avpch2; - union avp_value val; - struct sess_state *sess_data = NULL, *svg; - struct session *session = NULL; - int new; - - ogs_assert(rx_sid); - - /* Create the request */ - ret = fd_msg_new(ogs_diam_rx_cmd_str, MSGFL_ALLOC_ETEID, &req); - ogs_assert(ret == 0); - { - struct msg_hdr * h; - ret = fd_msg_hdr( req, &h ); - ogs_assert(ret == 0); - h->msg_appl = OGS_DIAM_RX_APPLICATION_ID; - } - - /* Retrieve session by Session-Id */ - size_t sidlen = strlen((char*)rx_sid); - ret = fd_sess_fromsid_msg(rx_sid, sidlen, &session, &new); - ogs_assert(ret == 0); - ogs_assert(new == 0); - - /* Add Session-Id to the message */ - ret = ogs_diam_message_session_id_set(req, rx_sid, sidlen); - ogs_assert(ret == 0); - /* Save the session associated with the message */ - ret = fd_msg_sess_set(req, session); - - /* Retrieve session state in this session */ - ret = fd_sess_state_retrieve(pcscf_rx_reg, session, &sess_data); - ogs_assert(ret == 0); - ogs_assert(sess_data); - - /* Set Origin-Host & Origin-Realm */ - ret = fd_msg_add_origin(req, 0); - ogs_assert(ret == 0); - - /* Set the Destination-Realm AVP */ - ret = fd_msg_avp_new(ogs_diam_destination_realm, 0, &avp); - ogs_assert(ret == 0); - val.os.data = (unsigned char *)(fd_g_config->cnf_diamrlm); - val.os.len = strlen(fd_g_config->cnf_diamrlm); - ret = fd_msg_avp_setvalue(avp, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); - ogs_assert(ret == 0); - - /* Set the Auth-Application-Id AVP */ - ret = fd_msg_avp_new(ogs_diam_auth_application_id, 0, &avp); - ogs_assert(ret == 0); - val.i32 = OGS_DIAM_RX_APPLICATION_ID; - ret = fd_msg_avp_setvalue(avp, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); - ogs_assert(ret == 0); - - /* Set the Termination-Cause AVP */ - ret = fd_msg_avp_new(ogs_diam_rx_termination_cause, 0, &avp); - ogs_assert(ret == 0); - val.i32 = OGS_DIAM_RX_TERMINATION_CAUSE_DIAMETER_LOGOUT; - ret = fd_msg_avp_setvalue(avp, &val); - ogs_assert(ret == 0); - ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); - ogs_assert(ret == 0); - - /* Keep a pointer to the session data for debug purpose, - * in real life we would not need it */ - svg = sess_data; - - /* Store this value in the session */ - ret = fd_sess_state_store(pcscf_rx_reg, session, &sess_data); - ogs_assert(ret == 0); - ogs_assert(sess_data == NULL); - - /* Send the request */ - ret = fd_msg_send(&req, pcscf_rx_sta_cb, svg); - ogs_assert(ret == 0); - - /* Increment the counter */ - ogs_assert(pthread_mutex_lock(&ogs_diam_logger_self()->stats_lock) == 0); - ogs_diam_logger_self()->stats.nb_sent++; - ogs_assert(pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0); -} - -static void pcscf_rx_sta_cb(void *data, struct msg **msg) -{ - int ret; - - struct sess_state *sess_data = NULL; - struct timespec ts; - struct session *session; - struct avp *avp, *avpch1; - struct avp_hdr *hdr; - unsigned long dur; - int error = 0; - int new; - int result_code = 0; - - ret = clock_gettime(CLOCK_REALTIME, &ts); - ogs_assert(ret == 0); - - /* Search the session, retrieve its data */ - ret = fd_msg_sess_get(fd_g_config->cnf_dict, *msg, &session, &new); - ogs_assert(ret == 0); - ogs_assert(new == 0); - - ret = fd_sess_state_retrieve(pcscf_rx_reg, session, &sess_data); - ogs_assert(ret == 0); - ogs_assert(sess_data && (void *)sess_data == data); - - /* Value of Result Code */ - ret = fd_msg_search_avp(*msg, ogs_diam_result_code, &avp); - ogs_assert(ret == 0); - if (avp) { - ret = fd_msg_avp_hdr(avp, &hdr); - ogs_assert(ret == 0); - result_code = hdr->avp_value->i32; - ogs_debug("Result Code: %d\n", hdr->avp_value->i32); - } else { - ret = fd_msg_search_avp(*msg, ogs_diam_experimental_result, &avp); - ogs_assert(ret == 0); - if (avp) { - ret = fd_avp_search_avp( - avp, ogs_diam_experimental_result_code, &avpch1); - ogs_assert(ret == 0); - if (avpch1) { - ret = fd_msg_avp_hdr(avpch1, &hdr); - ogs_assert(ret == 0); - result_code = hdr->avp_value->i32; - ogs_debug("Experimental Result Code: %d\n", - result_code); - } - } else { - ogs_error("no Result-Code"); - error++; - } - } - - /* Value of Origin-Host */ - ret = fd_msg_search_avp(*msg, ogs_diam_origin_host, &avp); - ogs_assert(ret == 0); - if (avp) { - ret = fd_msg_avp_hdr(avp, &hdr); - ogs_assert(ret == 0); - ogs_debug("From '%.*s' ", - (int)hdr->avp_value->os.len, hdr->avp_value->os.data); - } else { - ogs_error("no_Origin-Host "); - error++; - } - - /* Value of Origin-Realm */ - ret = fd_msg_search_avp(*msg, ogs_diam_origin_realm, &avp); - ogs_assert(ret == 0); - if (avp) { - ret = fd_msg_avp_hdr(avp, &hdr); - ogs_assert(ret == 0); - ogs_debug("('%.*s') ", - (int)hdr->avp_value->os.len, hdr->avp_value->os.data); - } else { - ogs_error("no_Origin-Realm "); - error++; - } - - if (result_code != ER_DIAMETER_SUCCESS) { - ogs_warn("ERROR DIAMETER Result Code(%d)", result_code); - error++; - goto out; - } - -out: - /* Free the message */ - ogs_assert(pthread_mutex_lock(&ogs_diam_logger_self()->stats_lock) == 0); - dur = ((ts.tv_sec - sess_data->ts.tv_sec) * 1000000) + - ((ts.tv_nsec - sess_data->ts.tv_nsec) / 1000); - if (ogs_diam_logger_self()->stats.nb_recv) { - /* Ponderate in the avg */ - ogs_diam_logger_self()->stats.avg = (ogs_diam_logger_self()->stats.avg * - ogs_diam_logger_self()->stats.nb_recv + dur) / - (ogs_diam_logger_self()->stats.nb_recv + 1); - /* Min, max */ - if (dur < ogs_diam_logger_self()->stats.shortest) - ogs_diam_logger_self()->stats.shortest = dur; - if (dur > ogs_diam_logger_self()->stats.longest) - ogs_diam_logger_self()->stats.longest = dur; - } else { - ogs_diam_logger_self()->stats.shortest = dur; - ogs_diam_logger_self()->stats.longest = dur; - ogs_diam_logger_self()->stats.avg = dur; - } - if (error) - ogs_diam_logger_self()->stats.nb_errs++; - else - ogs_diam_logger_self()->stats.nb_recv++; - - ogs_assert(pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0); - - /* Display how long it took */ - if (ts.tv_nsec > sess_data->ts.tv_nsec) - ogs_trace("in %d.%06ld sec\n", - (int)(ts.tv_sec - sess_data->ts.tv_sec), - (long)(ts.tv_nsec - sess_data->ts.tv_nsec) / 1000); - else - ogs_trace("in %d.%06ld sec\n", - (int)(ts.tv_sec + 1 - sess_data->ts.tv_sec), - (long)(1000000000 + ts.tv_nsec - sess_data->ts.tv_nsec) / 1000); - - state_cleanup(sess_data, NULL, NULL); - - ret = fd_msg_free(*msg); - ogs_assert(ret == 0); - *msg = NULL; - - return; -} - -void pcscf_diam_config(void) -{ - memset(&diam_config, 0, sizeof(ogs_diam_config_t)); - - diam_config.cnf_diamid = "pcscf.open-ims.test"; - diam_config.cnf_diamrlm = "open-ims.test"; - diam_config.cnf_port = DIAMETER_PORT; - diam_config.cnf_port_tls = DIAMETER_SECURE_PORT; - diam_config.cnf_flags.no_sctp = 1; - diam_config.cnf_addr = "127.0.0.1"; - - diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR OGS_DIR_SEPARATOR_S "dbg_msg_dumps.fdx"; - diam_config.ext[diam_config.num_of_ext].conf = "0x8888"; - diam_config.num_of_ext++; - diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_rfc5777.fdx"; - diam_config.num_of_ext++; - diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_mip6i.fdx"; - diam_config.num_of_ext++; - diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_nasreq.fdx"; - diam_config.num_of_ext++; - diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_nas_mipv6.fdx"; - diam_config.num_of_ext++; - diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_dcca.fdx"; - diam_config.num_of_ext++; - diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_dcca_3gpp.fdx"; - diam_config.num_of_ext++; - - diam_config.conn[diam_config.num_of_conn].identity = "pcrf.open-ims.test"; - diam_config.conn[diam_config.num_of_conn].addr = "127.0.0.5"; - diam_config.num_of_conn++; -} - -int pcscf_fd_init(void) -{ - int ret; - struct disp_when data; - - pcscf_diam_config(); - - ret = ogs_diam_init(FD_MODE_CLIENT, NULL, &diam_config); - ogs_assert(ret == 0); - - /* Install objects definitions for this application */ - ret = ogs_diam_rx_init(); - ogs_assert(ret == 0); - - /* Create handler for sessions */ - ret = fd_sess_handler_create(&pcscf_rx_reg, state_cleanup, NULL, NULL); - ogs_assert(ret == 0); - - /* Fallback CB if command != unexpected message received */ - memset(&data, 0, sizeof(data)); - data.app = ogs_diam_rx_application; - - ret = fd_disp_register(pcscf_rx_fb_cb, DISP_HOW_APPID, &data, NULL, - &hdl_rx_fb); - ogs_assert(ret == 0); - - /* Specific handler for Abort-Session-Request */ - data.command = ogs_diam_rx_cmd_asr; - ret = fd_disp_register(pcscf_rx_asr_cb, DISP_HOW_CC, &data, NULL, - &hdl_rx_asr); - ogs_assert(ret == 0); - - /* Advertise the support for the application in the peer */ - ret = fd_disp_app_support(ogs_diam_rx_application, ogs_diam_vendor, 1, 0); - ogs_assert(ret == 0); - - return 0; -} - -void pcscf_fd_final(void) -{ - int ret; - ret = fd_sess_handler_destroy(&pcscf_rx_reg, NULL); - ogs_assert(ret == 0); - - if (hdl_rx_fb) - (void) fd_disp_unregister(&hdl_rx_fb, NULL); - if (hdl_rx_asr) - (void) fd_disp_unregister(&hdl_rx_asr, NULL); - - ogs_diam_final(); -} diff --git a/tests/epc/attach-test.c b/tests/epc/attach-test.c deleted file mode 100644 index ef28662ec..000000000 --- a/tests/epc/attach-test.c +++ /dev/null @@ -1,1777 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "test-epc.h" - -/************************************************************** - * eNB : MACRO - * UE : IMSI - * Protocol Configuration Options in ESM information response */ -static void attach_test1(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_socknode_t *gtpu; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 0; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; - - uint8_t tmp[OGS_MAX_SDU_LEN]; - const char *_authentication_request = - "000b403b00000300 000005c00100009d 000800020001001a 0025240752002008" - "0c3818183b522614 162c07601d0d10f1 1b89a2a8de8000ad 0ccf7f55e8b20d"; - const char *_security_mode_command = - "000b403200000300 000005c00100009d 000800020001001a 001c1b3708deab59" - "00075d010005e060 c04070c14f08116b f77412f7d151"; - const char *_esm_information_request = - "000b402000000300 000005c00100009d 000800020001001a 000a092779012320" - "010221d9"; - const char *_initial_context_setup_request = - "00090080d8000006 00000005c0010000 9d00080002000100 42000a183e800000" - "603e800000001800 8086000034008080 450009200f807f00 0002000000017127" - "4db5d98302074202 49064000f1105ba0 00485221c1010909 08696e7465726e65" - "7405010a2d00025e 06fefeeeee030327 2980c22304030000 0480211002000010" - "8106080808088306 08080404000d0408 080808000d040808 0404500bf600f110" - "0002010000000153 12172c5949640125 006b000518000c00 00004900203311c6" - "03c6a6d67f695e5a c02bb75b381b693c 3893a6d932fd9182 3544e3e79b"; - const char *_emm_information = - "000b403b00000300 000005c00100009d 000800020001001a 002524271f9b491e" - "030761430f10004f 00700065006e0035 0047005347812072 11240563490100"; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " - "\"imsi\" : \"001010123456819\", " - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"security\" : { " - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " - "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " - "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"20080C38 18183B52 2614162C 07601D0D\" " - "}, " - "\"__v\" : 0 " - "}"; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* eNB connects to SGW */ - gtpu = testenb_gtpu_server("127.0.0.5"); - ABTS_PTR_NOTNULL(tc, gtpu); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - /********** Insert Subscriber in Database */ - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("001010123456819")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, No Security Context - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - mme_self()->mme_ue_s1ap_id = 16777372; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_authentication_request, strlen(_authentication_request), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_security_mode_command, strlen(_security_mode_command), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_esm_information_request, strlen(_security_mode_command), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - /* - * We cannot check it since SGW S1U ADDR is changed - * from configuration file - */ -#if 0 - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_initial_context_setup_request, - strlen(_initial_context_setup_request), tmp), - recvbuf->len) == 0); -#endif - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(50); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 16777373, 1, 5, 1, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(50); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - OGS_HEX(_emm_information, strlen(_emm_information), tmp); - ABTS_TRUE(tc, memcmp(recvbuf->data, tmp, 28) == 0); - ABTS_TRUE(tc, memcmp(recvbuf->data+32, tmp+32, 20) == 0); - ogs_pkbuf_free(recvbuf); - - rv = testgtpu_build_slacc_rs(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_gtpu_send(gtpu, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - recvbuf = testenb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send GTP-U ICMP Packet */ - rv = testgtpu_build_ping(&sendbuf, 1, "10.45.0.2", "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_gtpu_send(gtpu, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive GTP-U ICMP Packet */ - recvbuf = testenb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - -#if __linux__ - rv = testgtpu_build_ping(&sendbuf, 1, "cafe::2", "cafe::1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_gtpu_send(gtpu, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive GTP-U ICMP Packet */ - recvbuf = testenb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); -#endif - - /* Retreive M-TMSI */ - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(16777373); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - m_tmsi = mme_ue->guti.m_tmsi; - - /***************************************************************** - * Attach Request : Known GUTI, Integrity Protected, MAC Matched - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex+1); - /* Update M-TMSI */ - m_tmsi = htonl(m_tmsi); - memcpy(sendbuf->data + 36, &m_tmsi, 4); - /* Update NAS MAC */ - snow_3g_f9(mme_ue->knas_int, 7, 0, 0, - sendbuf->data + 24, (109 << 3), sendbuf->data+20); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Error Indicaation */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Attach Complete + - * Activate Default EPS Bearer Context Accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Detach Request */ - rv = tests1ap_build_detach_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /***************************************************************** - * Attach Request : Unknown GUTI, Integrity Protected - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex+2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Identity Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("001010123456819")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex+2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Attach Reject */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive UE Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); - - /* eNB disonncect from SGW */ - testenb_gtpu_close(gtpu); -} - -/************************************************************** - * eNB : HOME - * UE : IMSI - * Protocol Configuration Options in PDN Connectivity Request */ -static void attach_test2(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 3; - - mongoc_collection_t *collection = NULL; - int64_t count = 0; - bson_t *doc = NULL; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " - "\"imsi\" : \"001010123456826\", " - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"security\" : { " - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " - "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " - "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"2AE4FC02 1DD4D1C2 E0A277C2 317C2E67\" " - "}, " - "\"__v\" : 0 " - "}"; - const char *json2 = - "{" - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " - "\"imsi\" : \"001010000000003\", " - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c8\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"security\" : { " - "\"k\" : \"00112233 44556677 8899AABB CCDDEEFF\", " - "\"opc\" : \"00010203 04050607 08090A0B 0C0D0E0F\", " - "\"amf\" : \"9001\", " - "\"sqn\" : { \"$numberLong\" : \"96\" }, " - "\"rand\" : \"1c92dd6e dcd676e8 7b590ba2 20c1874e\" " - "}, " - "\"__v\" : 0 " - "}"; - - uint8_t tmp[OGS_MAX_SDU_LEN]; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x002343d, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - /********** Insert Subscriber in Database */ - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("001010123456826")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - doc = bson_new_from_json((const uint8_t *)json2, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("001010000000003")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /***************************************************************** - * Attach Request : Known IMSI, Plain NAS message - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 1, 31, 5, 1, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /***************************************************************** - * Attach Request : IMSI, Integrity Protected, MAC Matched - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Attach Complete + - * Activate Default EPS Bearer Context Accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /***************************************************************** - * Attach Request : Unknown IMSI, Integrity Protected - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex+2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Authentication Failure */ - rv = tests1ap_build_authentication_failure(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Authentication Failure */ - rv = tests1ap_build_authentication_failure(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Reject */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - doc = BCON_NEW("imsi", BCON_UTF8("001010123456826")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("001010000000003")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); -} - -/************************************************************** - * Attach -> Release -> Service Request -> TAU Request */ -static void attach_test3(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_socknode_t *gtpu; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 6; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; - - uint8_t tmp[OGS_MAX_SDU_LEN]; - const char *_authentication_request = - "000b" - "403b000003000000 05c0020000c80008 00020002001a0025 2407520042200639" - "1c0021554d444928 4a1a062e10e543cb 257f1f800021f4f9 2d522a5b87"; - const char *_security_mode_command = - "000b402f00000300 000005c0020000c8 000800020002001a 001918371fb7de55" - "00075d010002f0f0 c14f088f4677974b faed1e"; - const char *_esm_information_request = - "000b" - "4020000003000000 05c0020000c80008 00020002001a000a 09277330e06c0102" - "01d9"; - const char *_initial_context_setup_request = - "00090080c8000006 00000005c0020000 c800080002000200 42000a183e800000" - "603e800000001800 7700003400724540 0920000000000000 00000f800a0123d8" - "000000035b27a23a 27b4020742024906 4000f1102b670032 5201c10509ffffff" - "ff0908696e746572 6e657405010a2d2d 035e060000000004 04270f80000d0408" - "080808000d040404 0404500bf600f110 0002010000000353 12172c5949640125" - "006b00051e000e00 000049002040964d eb63a0afb5d0d374 c1da505f6252d1f9" - "05ff9c6791b8503a 032c6effa7"; - - const char *_emm_information = - "000b403b00000300 000005c0020000c8 000800020002001a 002524276782702a" - "030761430f10004f 00700065006e0035 0047005347812072 11941563490100"; - - const char *_ue_context_release_command = - "0017" - "0013000002006300 070c020000c80002 0002400120"; - - mongoc_collection_t *collection = NULL; - int64_t count = 0; - bson_t *doc = NULL; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " - "\"imsi\" : \"001010123456797\", " - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"security\" : { " - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " - "\"op\" : \"5F1D289C 5D354D0A 140C2548 F5F3E3BA\", " - "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"42200639 1c002155 4d444928 4a1a062e\" " - "}, " - "\"__v\" : 0 " - "}"; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* eNB connects to SGW */ - gtpu = testenb_gtpu_server("127.0.0.5"); - ABTS_PTR_NOTNULL(tc, gtpu); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - /********** Insert Subscriber in Database */ - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("001010123456797")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /***************************************************************** - * Attach Request : Known IMSI, Plain NAS message - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - mme_self()->mme_ue_s1ap_id = 33554631; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_authentication_request, strlen(_authentication_request), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_security_mode_command, strlen(_security_mode_command), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_esm_information_request, strlen(_security_mode_command), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 33554632, 2, 5, 1, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - OGS_HEX(_emm_information, strlen(_emm_information), tmp); - ABTS_TRUE(tc, memcmp(recvbuf->data, tmp, 28) == 0); - ABTS_TRUE(tc, memcmp(recvbuf->data+32, tmp+32, 20) == 0); - ogs_pkbuf_free(recvbuf); - - /* Retreive M-TMSI */ - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(33554632); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - m_tmsi = mme_ue->guti.m_tmsi; - - /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data, - OGS_HEX(_ue_context_release_command, - strlen(_ue_context_release_command), tmp), - recvbuf->len) == 0); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Service Request */ - rv = tests1ap_build_service_request(&sendbuf, 0x000400, 4, 0xd4b8, m_tmsi); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 33554633, 4, 5, 1, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send TAU Request */ - rv = tests1ap_build_tau_request(&sendbuf, 0, - 0, 0x003600, 1, m_tmsi, 7, 0xe73ce7c, mme_ue->knas_int); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive TAU Accept */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 33554634, 54, 5, 1, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send TAU Request */ - rv = tests1ap_build_tau_request(&sendbuf, 0, - 0, 0x002600, 0, m_tmsi, 8, 0x972dc6f8, mme_ue->knas_int); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive TAU Accept */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - doc = BCON_NEW("imsi", BCON_UTF8("001010123456797")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); - - /* eNB disonncect from SGW */ - testenb_gtpu_close(gtpu); -} - -/************************************************************** - * eNB : MACRO - * UE : IMSI - * Protocol Configuration Options without default APN */ -static void attach_test4(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_socknode_t *gtpu; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 8; - - uint8_t tmp[OGS_MAX_SDU_LEN]; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"597223258b8861d7605378c7\" }, " - "\"imsi\" : \"001010000000002\", " - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"598223158b8861d7605378c8\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"security\" : { " - "\"k\" : \"00112233 44556677 8899AABB CCDDEEFF\", " - "\"opc\" : \"00010203 04050607 08090A0B 0C0D0E0F\", " - "\"amf\" : \"9001\", " - "\"sqn\" : { \"$numberLong\" : \"96\" }, " - "\"rand\" : \"9bdbfb93 16be4d52 80153094 38326671\" " - "}, " - "\"__v\" : 0 " - "}"; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* eNB connects to SGW */ - gtpu = testenb_gtpu_server("127.0.0.5"); - ABTS_PTR_NOTNULL(tc, gtpu); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - /********** Insert Subscriber in Database */ - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("001010000000002")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, No Security Context - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - -#if 0 - rv = testgtpu_build_slacc_rs(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_gtpu_send(gtpu, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - recvbuf = testenb_gtpu_read(gtpu); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); -#endif - - /* Send EMM Status */ - rv = tests1ap_build_emm_status(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - doc = BCON_NEW("imsi", BCON_UTF8("001010000000002")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); - - /* eNB disonncect from SGW */ - testenb_gtpu_close(gtpu); -} - -static void attach_test5(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 12; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " - "\"imsi\" : \"001010123456937\", " - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"security\" : { " - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " - "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " - "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"768\" }, " - "\"rand\" : \"2e815f03 cc54b55f 00933008 5cab5ca3\" " - "}, " - "\"__v\" : 0 " - "}"; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x787b0, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - /********** Insert Subscriber in Database */ - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("001010123456937")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /* Send Service request */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_service_request(&sendbuf, - 0x40072c, 17, 0x9551, 0x12345678); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Service reject */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive Initial Context Setup Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, No Security Context - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 2, 1837, 5, 0x1000908, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Retreive M-TMSI */ - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(2); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - m_tmsi = mme_ue->guti.m_tmsi; - -#if 0 - rv = tests1ap_build_s1_reset(&sendbuf, 0); -#elif 0 - rv = s1ap_build_s1_reset(&sendbuf, - S1AP_Cause_PR_radioNetwork, - S1AP_CauseRadioNetwork_release_due_to_eutran_generated_reason, - NULL); -#elif 0 - { - S1AP_UE_associatedLogicalS1_ConnectionListRes_t - *partOfS1_Interface = NULL; - S1AP_UE_associatedLogicalS1_ConnectionItemRes_t *ie = NULL; - S1AP_UE_associatedLogicalS1_ConnectionItem_t *item = NULL; - - partOfS1_Interface = CALLOC(1, - sizeof(S1AP_UE_associatedLogicalS1_ConnectionListRes_t)); - ogs_assert(partOfS1_Interface); - - ie = CALLOC(1, - sizeof(S1AP_UE_associatedLogicalS1_ConnectionItemRes_t)); - ASN_SEQUENCE_ADD(&partOfS1_Interface->list, ie); - - ie->id = S1AP_ProtocolIE_ID_id_UE_associatedLogicalS1_ConnectionItem; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UE_associatedLogicalS1_ConnectionItemRes__value_PR_UE_associatedLogicalS1_ConnectionItem; - - item = &ie->value.choice.UE_associatedLogicalS1_ConnectionItem; - - item->mME_UE_S1AP_ID = CALLOC(1, sizeof(S1AP_MME_UE_S1AP_ID_t)); - ogs_assert(item->mME_UE_S1AP_ID); - *item->mME_UE_S1AP_ID = 100; - item->eNB_UE_S1AP_ID = CALLOC(1, sizeof(S1AP_ENB_UE_S1AP_ID_t)); - ogs_assert(item->eNB_UE_S1AP_ID); - *item->eNB_UE_S1AP_ID = 4; - - ie = CALLOC(1, - sizeof(S1AP_UE_associatedLogicalS1_ConnectionItemRes_t)); - ASN_SEQUENCE_ADD(&partOfS1_Interface->list, ie); - - ie->id = S1AP_ProtocolIE_ID_id_UE_associatedLogicalS1_ConnectionItem; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UE_associatedLogicalS1_ConnectionItemRes__value_PR_UE_associatedLogicalS1_ConnectionItem; - - item = &ie->value.choice.UE_associatedLogicalS1_ConnectionItem; - - item->mME_UE_S1AP_ID = CALLOC(1, sizeof(S1AP_MME_UE_S1AP_ID_t)); - ogs_assert(item->mME_UE_S1AP_ID); - *item->mME_UE_S1AP_ID = 2; - item->eNB_UE_S1AP_ID = CALLOC(1, sizeof(S1AP_ENB_UE_S1AP_ID_t)); - ogs_assert(item->eNB_UE_S1AP_ID); - *item->eNB_UE_S1AP_ID = 3; - - ie = CALLOC(1, - sizeof(S1AP_UE_associatedLogicalS1_ConnectionItemRes_t)); - ASN_SEQUENCE_ADD(&partOfS1_Interface->list, ie); - - ie->id = S1AP_ProtocolIE_ID_id_UE_associatedLogicalS1_ConnectionItem; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UE_associatedLogicalS1_ConnectionItemRes__value_PR_UE_associatedLogicalS1_ConnectionItem; - - item = &ie->value.choice.UE_associatedLogicalS1_ConnectionItem; - - item->mME_UE_S1AP_ID = CALLOC(1, sizeof(S1AP_MME_UE_S1AP_ID_t)); - ogs_assert(item->mME_UE_S1AP_ID); - *item->mME_UE_S1AP_ID = 44; - - rv = s1ap_build_s1_reset(&sendbuf, - S1AP_Cause_PR_radioNetwork, - S1AP_CauseRadioNetwork_release_due_to_eutran_generated_reason, - partOfS1_Interface); - } -#else - { - S1AP_MME_UE_S1AP_ID_t *mme_ue_s1ap_id = NULL; - - mme_ue_s1ap_id = CALLOC(1, sizeof(S1AP_MME_UE_S1AP_ID_t)); - ogs_assert(mme_ue_s1ap_id); - *mme_ue_s1ap_id = 2; - sendbuf = s1ap_build_s1_reset_partial( - S1AP_Cause_PR_radioNetwork, - S1AP_CauseRadioNetwork_release_due_to_eutran_generated_reason, - mme_ue_s1ap_id, NULL); - } -#endif - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1 Reset Acknowledge */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Service request */ - rv = tests1ap_build_service_request(&sendbuf, - 0x40072e, 4, 0xda67, m_tmsi); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Service Reject */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("001010123456937")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); -} - -/************************************************************** - * eNB : MACRO - * UE : IMSI - * Protocol Configuration Options without default APN */ -static void attach_test6(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_socknode_t *gtpu; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 8; - - uint8_t tmp[OGS_MAX_SDU_LEN]; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"597223258b8861d7605378c7\" }, " - "\"imsi\" : \"001010000000002\", " - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"598223158b8861d7605378c8\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"security\" : { " - "\"k\" : \"00112233 44556677 8899AABB CCDDEEFF\", " - "\"opc\" : \"00010203 04050607 08090A0B 0C0D0E0F\", " - "\"amf\" : \"9001\", " - "\"sqn\" : { \"$numberLong\" : \"96\" }, " - "\"rand\" : \"9bdbfb93 16be4d52 80153094 38326671\" " - "}, " - "\"__v\" : 0 " - "}"; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* eNB connects to SGW */ - gtpu = testenb_gtpu_server("127.0.0.5"); - ABTS_PTR_NOTNULL(tc, gtpu); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - /********** Insert Subscriber in Database */ - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("001010000000002")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, No Security Context - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - mme_self()->mme_ue_s1ap_id = 0; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Initial Context Setup Failure */ - rv = tests1ap_build_initial_context_setup_failure(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - doc = BCON_NEW("imsi", BCON_UTF8("001010000000002")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); - - /* eNB disonncect from SGW */ - testenb_gtpu_close(gtpu); -} - -abts_suite *test_attach(abts_suite *suite) -{ - suite = ADD_SUITE(suite) - - abts_run_test(suite, attach_test1, NULL); - abts_run_test(suite, attach_test2, NULL); - abts_run_test(suite, attach_test3, NULL); - abts_run_test(suite, attach_test4, NULL); - abts_run_test(suite, attach_test5, NULL); - abts_run_test(suite, attach_test6, NULL); - - return suite; -} diff --git a/tests/epc/crash-test.c b/tests/epc/crash-test.c deleted file mode 100644 index 942f52390..000000000 --- a/tests/epc/crash-test.c +++ /dev/null @@ -1,594 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "test-epc.h" - -static void crash_test1(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 21; - - mongoc_collection_t *collection = NULL; - int64_t count = 0; - bson_t *doc = NULL; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " - "\"imsi\" : \"311980000000725\", " - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"security\" : { " - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " - "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " - "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"2AE4FC02 1DD4D1C2 E0A277C2 317C2E67\" " - "}, " - "\"__v\" : 0 " - "}"; - uint8_t tmp[OGS_MAX_SDU_LEN]; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x002343d, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - /********** Insert Subscriber in Database */ - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("311980000000725")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /* Send Attach Request */ - mme_self()->mme_ue_s1ap_id = 207; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Identity Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - msgindex = 22; - - /* Send Attach Request */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Identity Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 209, 209, 5, 0x01001908, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - msgindex = 21; - - /* Send Initial Context Setup Failure */ - rv = tests1ap_build_initial_context_setup_failure(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - doc = BCON_NEW("imsi", BCON_UTF8("311980000000725")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); -} - -static void crash_test2(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 21; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; - - mongoc_collection_t *collection = NULL; - int64_t count = 0; - bson_t *doc = NULL; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " - "\"imsi\" : \"311980000000725\", " - "\"pdn\" : [" - "{" - "\"apn\" : \"internet\", " - "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " - "\"ambr\" : {" - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"qos\" : { " - "\"qci\" : 9, " - "\"arp\" : { " - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1, " - "\"pre_emption_capability\" : 1" - "} " - "}, " - "\"type\" : 2" - "}" - "]," - "\"ambr\" : { " - "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " - "\"downlink\" : { \"$numberLong\" : \"1024000\" } " - "}," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2, " - "\"subscriber_status\" : 0, " - "\"access_restriction_data\" : 32, " - "\"security\" : { " - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " - "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " - "\"amf\" : \"8000\", " - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"2AE4FC02 1DD4D1C2 E0A277C2 317C2E67\" " - "}, " - "\"__v\" : 0 " - "}"; - uint8_t tmp[OGS_MAX_SDU_LEN]; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x002343d, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - /********** Insert Subscriber in Database */ - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("311980000000725")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /* Send Attach Request */ - mme_self()->mme_ue_s1ap_id = 207; - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Identity Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - msgindex = 22; - - /* Send Attach Request */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Identity Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 209, 209, 5, 0x01001908, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Retreive M-TMSI */ - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(209); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - m_tmsi = mme_ue->guti.m_tmsi; - - /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex-1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Service Request */ - rv = tests1ap_build_service_request(&sendbuf, 0x00d200, 4, 0xef95, m_tmsi); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Initial Context Setup Failure */ - rv = tests1ap_build_initial_context_setup_failure(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send UE Context Release Request */ - rv = tests1ap_build_ue_context_release_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Service Request */ - rv = tests1ap_build_service_request(&sendbuf, 0x00d300, 4, 0xef95, m_tmsi); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Service Reject */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - doc = BCON_NEW("imsi", BCON_UTF8("311980000000725")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); -} - -abts_suite *test_crash(abts_suite *suite) -{ - suite = ADD_SUITE(suite) - - abts_run_test(suite, crash_test1, NULL); - abts_run_test(suite, crash_test2, NULL); - - return suite; -} diff --git a/tests/epc/handover-test.c b/tests/epc/handover-test.c deleted file mode 100644 index be8542586..000000000 --- a/tests/epc/handover-test.c +++ /dev/null @@ -1,820 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "test-epc.h" - -static void handover_test1(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap1, *s1ap2; - ogs_socknode_t *gtpu1, *gtpu2; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 9; - - uint8_t tmp[OGS_MAX_SDU_LEN]; - const char *_nh1 = "10" - "3715a966536b75b4 d46e99774dcdb344 5ce5e893fbbf28f4 9f58508c36f827cc"; - const char *_nh2 = "18" - "a29ed36339514717 481992f77f47a9af 934a7b763afcec39 edf5071461db6ae8"; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2b\" }," - "\"imsi\" : \"001010123456801\"," - "\"pdn\" : [" - "{ \"apn\" : \"internet.ng2.mnet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," - "\"qos\" : {" - "\"qci\" : 9," - "\"arp\" : {" - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }," - "{ \"apn\" : \"internet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2c\" }," - "\"pcc_rule\" : [" - "{ \"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," - "\"qos\" : {" - "\"qci\" : 1," - "\"gbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"mbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"arp\" : {" - "\"priority_level\" : 3," - "\"pre_emption_vulnerability\" : 0," - "\"pre_emption_capability\" : 0 } }," - "\"flow\" : [" - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } } ]" - "} ]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"35840\" }," - "\"uplink\" : { \"$numberLong\" : \"15360\" } }," - "\"qos\" : {" - "\"qci\" : 7," - "\"arp\" : {" - "\"priority_level\" : 1," - "\"pre_emption_vulnerability\" : 0," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }" - "]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"1024000\" }," - "\"uplink\" : { \"$numberLong\" : \"1024000\" } }," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2," - "\"subscriber_status\" : 0," - "\"access_restriction_data\" : 32," - "\"security\" : {" - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\"," - "\"op\" : \"5F1D289C 5D354D0A 140C2548 F5F3E3BA\"," - "\"amf\" : \"8000\"," - "\"sqn\" : { \"$numberLong\" : \"32\" }, " - "\"rand\" : \"0a303a1e 63603f61 404c1241 30320f39\" }, " - "\"__v\" : 0" - "}"; - - mme_self()->mme_ue_s1ap_id = 16777689; - - /* Two eNB connects to MME */ - s1ap1 = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap1); - - s1ap2 = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap2); - - /* eNB connects to SGW */ - gtpu1 = testenb_gtpu_server("127.0.0.5"); - ABTS_PTR_NOTNULL(tc, gtpu1); - - gtpu2 = testenb_gtpu_server("127.0.0.6"); - ABTS_PTR_NOTNULL(tc, gtpu2); - - /* S1-Setup Reqeust/Response for Source eNB */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* S1-Setup Reqeust/Response for Target eNB */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f65, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap2, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - recvbuf = testenb_s1ap_read(s1ap2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("001010123456801")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, No Security Context - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 16777690, 1, 5, 1, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive E-RAB Setup Request + - * Activate dedicated EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response(&sendbuf, - 33554492, 1, 6, 2, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Activate dedicated EPS bearer context accept */ - rv = tests1ap_build_activate_dedicated_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(50); - - /* Send Path Switch Request */ - rv = tests1ap_build_path_switch_request(&sendbuf, - 1, 16777690, 1, 2, 5, 1, "127.0.0.5", "127.0.0.6"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap2, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Path Switch Ack */ - recvbuf = testenb_s1ap_read(s1ap2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data + 26, - OGS_HEX(_nh1, strlen(_nh1), tmp), 33) == 0); - ogs_pkbuf_free(recvbuf); - - /* Receive End Mark */ - recvbuf = testenb_gtpu_read(gtpu1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive End Mark */ - recvbuf = testenb_gtpu_read(gtpu1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Path Switch Request */ - rv = tests1ap_build_path_switch_request(&sendbuf, 0, 16777690, 2, 2, 5, 1, - "127.0.0.5", "127.0.0.6"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive End Mark */ - recvbuf = testenb_gtpu_read(gtpu2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive End Mark */ - recvbuf = testenb_gtpu_read(gtpu2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive Path Switch Ack */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ABTS_TRUE(tc, memcmp(recvbuf->data + 26, - OGS_HEX(_nh2, strlen(_nh2), tmp), 33) == 0); - ogs_pkbuf_free(recvbuf); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("001010123456801")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from SGW */ - testenb_gtpu_close(gtpu2); - testenb_gtpu_close(gtpu1); - - /* Two eNB disonncect from MME */ - testenb_s1ap_close(s1ap1); - testenb_s1ap_close(s1ap2); -} - -static void handover_test2(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap1, *s1ap2; - ogs_socknode_t *gtpu1, *gtpu2; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 10; - enb_ue_t *enb_ue = NULL; - mme_ue_t *mme_ue = NULL; - uint32_t m_tmsi = 0; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2b\" }," - "\"imsi\" : \"001010123456815\"," - "\"pdn\" : [" - "{ \"apn\" : \"internet.ng2.mnet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," - "\"qos\" : {" - "\"qci\" : 9," - "\"arp\" : {" - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }," - "{ \"apn\" : \"internet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2c\" }," - "\"pcc_rule\" : [" - "{ \"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," - "\"qos\" : {" - "\"qci\" : 1," - "\"gbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"976\" }," - "\"uplink\" : { \"$numberLong\" : \"976\" } }," - "\"mbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"976\" }," - "\"uplink\" : { \"$numberLong\" : \"976\" } }," - "\"arp\" : {" - "\"priority_level\" : 1," - "\"pre_emption_vulnerability\" : 0," - "\"pre_emption_capability\" : 0 } }," - "\"flow\" : [" - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } } ]" - "} ]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"35840\" }," - "\"uplink\" : { \"$numberLong\" : \"15360\" } }," - "\"qos\" : {" - "\"qci\" : 7," - "\"arp\" : {" - "\"priority_level\" : 1," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 0 } }," - "\"type\" : 2 }" - "]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"202400\" }," - "\"uplink\" : { \"$numberLong\" : \"202400\" } }," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2," - "\"subscriber_status\" : 0," - "\"access_restriction_data\" : 32," - "\"security\" : {" - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\"," - "\"op\" : \"5F1D289C 5D354D0A 140C2548 F5F3E3BA\"," - "\"amf\" : \"8000\"," - "\"sqn\" : { \"$numberLong\" : \"161\" }, " - "\"rand\" : \"160b4726 39115e14 075f4731 50355216\" }, " - "\"__v\" : 0" - "}"; - - mme_self()->mme_ue_s1ap_id = 33554627; - - /* Two eNB connects to MME */ - s1ap1 = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap1); - - s1ap2 = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap2); - - /* eNB connects to SGW */ - gtpu1 = testenb_gtpu_server("127.0.0.5"); - ABTS_PTR_NOTNULL(tc, gtpu1); - - gtpu2 = testenb_gtpu_server("127.0.0.6"); - ABTS_PTR_NOTNULL(tc, gtpu2); - - /* S1-Setup Reqeust/Response for Source eNB */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x001f2, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* S1-Setup Reqeust/Response for Target eNB */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x00043, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap2, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - recvbuf = testenb_s1ap_read(s1ap2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("001010123456815")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /*********************************************************************** - * Attach Request : Known IMSI, No Security Context - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Identity Request */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Identity Response */ - rv = tests1ap_build_identity_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response(&sendbuf, - 33554628, 12, 5, 1, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Retreive M-TMSI */ - enb_ue = enb_ue_find_by_mme_ue_s1ap_id(33554628); - ogs_assert(enb_ue); - mme_ue = enb_ue->mme_ue; - ogs_assert(mme_ue); - m_tmsi = mme_ue->guti.m_tmsi; - - /* Receive E-RAB Setup Request + - * Activate dedicated EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response(&sendbuf, - 33554628, 12, 6, 2, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Activate dedicated EPS bearer context accept */ - rv = tests1ap_build_activate_dedicated_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send ENB configuration transfer */ - rv = tests1ap_build_enb_configuration_transfer(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive MME configuration transfer */ - recvbuf = testenb_s1ap_read(s1ap2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ENB configuration transfer */ - rv = tests1ap_build_enb_configuration_transfer(&sendbuf, 1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap2, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive MME configuration transfer */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Handover Required */ - rv = tests1ap_build_handover_required(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Handover Request */ - recvbuf = testenb_s1ap_read(s1ap2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - -#if TEST_HANDOVER_FAILURE - /* Send Handover Failure */ - rv = tests1ap_build_handover_failure(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); -#endif - - /* Send Handover Request Ack */ - rv = tests1ap_build_handover_request_ack(&sendbuf, - 1, 33554629, 8, 2, 5, 1, "127.0.0.5", "127.0.0.6"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap2, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Handover Command */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send eNB Status Transfer */ - rv = tests1ap_build_enb_status_transfer(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive MME Status Transfer */ - recvbuf = testenb_s1ap_read(s1ap2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Handover Notify */ - rv = tests1ap_build_handover_notify(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap2, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive End Mark */ - recvbuf = testenb_gtpu_read(gtpu1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive End Mark */ - recvbuf = testenb_gtpu_read(gtpu1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Tracking Area Update Request */ - rv = tests1ap_build_tau_request(&sendbuf, 1, - 0x000300, 0x000800, 0, m_tmsi, 4, 0, mme_ue->knas_int); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap2, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Tracking Area Update Accept */ - recvbuf = testenb_s1ap_read(s1ap2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex-1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Handover Required */ - rv = tests1ap_build_handover_required(&sendbuf, 1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap2, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Handover Request */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Handover Request Ack */ - rv = tests1ap_build_handover_request_ack(&sendbuf, - 0, 33554630, 13, 2, 5, 1, "127.0.0.5", "127.0.0.6"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Handover Command */ - recvbuf = testenb_s1ap_read(s1ap2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send eNB Status Transfer */ - rv = tests1ap_build_enb_status_transfer(&sendbuf, 1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap2, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive MME Status Transfer */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Handover Notify */ - rv = tests1ap_build_handover_notify(&sendbuf, 1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive End Mark */ - recvbuf = testenb_gtpu_read(gtpu2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive End Mark */ - recvbuf = testenb_gtpu_read(gtpu2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap2, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Handover Required */ - rv = tests1ap_build_handover_required(&sendbuf, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Handover Request */ - recvbuf = testenb_s1ap_read(s1ap2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Handover Request Ack */ - rv = tests1ap_build_handover_request_ack(&sendbuf, - 0, 33554631, 9, 2, 5, 1, "127.0.0.5", "127.0.0.6"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap2, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Handover Command */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Handover Cancel */ - rv = tests1ap_build_handover_cancel(&sendbuf, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap1, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Recv Handover Cancel Ack */ - recvbuf = testenb_s1ap_read(s1ap1); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Recv UE Context Relase Command */ - recvbuf = testenb_s1ap_read(s1ap2); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap2, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("001010123456815")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* Two eNB disonncect from MME */ - testenb_s1ap_close(s1ap1); - testenb_s1ap_close(s1ap2); - - /* eNB disonncect from SGW */ - testenb_gtpu_close(gtpu1); - testenb_gtpu_close(gtpu2); -} - -abts_suite *test_handover(abts_suite *suite) -{ - suite = ADD_SUITE(suite) - - abts_run_test(suite, handover_test1, NULL); - abts_run_test(suite, handover_test2, NULL); - - return suite; -} diff --git a/tests/epc/volte-test.c b/tests/epc/volte-test.c deleted file mode 100644 index afc794a14..000000000 --- a/tests/epc/volte-test.c +++ /dev/null @@ -1,565 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "test-epc.h" - -static void volte_test1(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 0; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2b\" }," - "\"imsi\" : \"001010123456819\"," - "\"pdn\" : [" - "{ \"apn\" : \"internet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," - "\"qos\" : {" - "\"qci\" : 9," - "\"arp\" : {" - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }," - "{ \"apn\" : \"internet.ng2.mnet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2c\" }," - "\"pcc_rule\" : [" - "{ \"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," - "\"qos\" : {" - "\"qci\" : 1," - "\"gbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"mbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"arp\" : {" - "\"priority_level\" : 3," - "\"pre_emption_vulnerability\" : 0," - "\"pre_emption_capability\" : 0 } }," - "\"flow\" : [" - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } } ]" - "} ]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"35840\" }," - "\"uplink\" : { \"$numberLong\" : \"15360\" } }," - "\"qos\" : {" - "\"qci\" : 6," - "\"arp\" : {" - "\"priority_level\" : 6," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }" - "]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"1024000\" }," - "\"uplink\" : { \"$numberLong\" : \"1024000\" } }," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2," - "\"subscriber_status\" : 0," - "\"access_restriction_data\" : 32," - "\"security\" : {" - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\"," - "\"op\" : \"5F1D289C 5D354D0A 140C2548 F5F3E3BA\"," - "\"amf\" : \"8000\"," - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"20080C38 18183B52 2614162C 07601D0D\" }, " - "\"__v\" : 0" - "}"; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("001010123456819")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, No Security Context - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response( - &sendbuf, 1, 1, 5, 1, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send PDN Connectivity Request */ - rv = tests1ap_build_pdn_connectivity_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Setup Request + - * Activate default EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response(&sendbuf, 1, 1, 6, 2, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Activate default EPS bearer context accept */ - rv = tests1ap_build_activate_default_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Setup Request + - * Activate dedicated EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Activate dedicated EPS bearer context accept */ - rv = tests1ap_build_activate_dedicated_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response(&sendbuf, 1, 1, 7, 3, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send PDN disconnectivity request */ - rv = tests1ap_build_pdn_disconnectivity_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Release Command + - * Deactivate EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Release Response */ - rv = tests1ap_build_e_rab_release_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Deactivate EPS bearer context accept */ - rv = tests1ap_build_deactivate_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send INVALID PDN Connectivity Request */ - rv = tests1ap_build_pdn_connectivity_request(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive PDN Connectivity Reject */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("001010123456819")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); -} - -static void volte_test2(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 0; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2b\" }," - "\"imsi\" : \"001010123456819\"," - "\"pdn\" : [" - "{ \"apn\" : \"internet.ng2.mnet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," - "\"qos\" : {" - "\"qci\" : 9," - "\"arp\" : {" - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }," - "{ \"apn\" : \"internet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2c\" }," - "\"pcc_rule\" : [" - "{ \"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," - "\"qos\" : {" - "\"qci\" : 1," - "\"gbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"mbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"arp\" : {" - "\"priority_level\" : 3," - "\"pre_emption_vulnerability\" : 0," - "\"pre_emption_capability\" : 0 } }," - "\"flow\" : [" - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out ip from 10.45.0.1 to any\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/24 23455\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out ip from cafe::1 to any\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } } ]" - "} ]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"35840\" }," - "\"uplink\" : { \"$numberLong\" : \"15360\" } }," - "\"qos\" : {" - "\"qci\" : 6," - "\"arp\" : {" - "\"priority_level\" : 6," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }" - "]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"1024000\" }," - "\"uplink\" : { \"$numberLong\" : \"1024000\" } }," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2," - "\"subscriber_status\" : 0," - "\"access_restriction_data\" : 32," - "\"security\" : {" - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\"," - "\"op\" : \"5F1D289C 5D354D0A 140C2548 F5F3E3BA\"," - "\"amf\" : \"8000\"," - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"20080C38 18183B52 2614162C 07601D0D\" }, " - "\"__v\" : 0" - "}"; - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client("127.0.0.1"); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8("001010123456819")); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, MAC failed - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response( - &sendbuf, 16777373, 1, 5, 1, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Receive E-RAB Setup Request + - * Activate dedicated EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response( - &sendbuf, 33554492, 1, 6, 2, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Activate dedicated EPS bearer context accept */ - rv = tests1ap_build_activate_dedicated_bearer_accept(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - -#if 0 /* TFT Rule Tester */ - /* Send GTP-U ICMP Packet */ -#if 1 - rv = testgtpu_build_ping(&sendbuf, 1, "10.45.0.2", "10.45.0.1"); -#else - rv = testgtpu_build_ping(&sendbuf, 1, "cafe::2", "cafe::1"); -#endif - rv = testgtpu_enb_send(gtpu, sendbuf); -#endif - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8("001010123456819")); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); -} - -abts_suite *test_volte(abts_suite *suite) -{ - suite = ADD_SUITE(suite) - - abts_run_test(suite, volte_test1, NULL); - abts_run_test(suite, volte_test2, NULL); - - return suite; -} diff --git a/tests/23504/abts-main.c b/tests/handover/abts-main.c similarity index 89% rename from tests/23504/abts-main.c rename to tests/handover/abts-main.c index 43ba11f8a..5595cffa7 100644 --- a/tests/23504/abts-main.c +++ b/tests/handover/abts-main.c @@ -19,12 +19,14 @@ #include "test-app.h" -abts_suite *test_r16(abts_suite *suite); +abts_suite *test_epc_x2(abts_suite *suite); +abts_suite *test_epc_s1(abts_suite *suite); const struct testlist { abts_suite *(*func)(abts_suite *suite); } alltests[] = { - {test_r16}, + {test_epc_x2}, + {test_epc_s1}, {NULL}, }; @@ -57,7 +59,7 @@ int main(int argc, const char *const argv[]) abts_suite *suite = NULL; atexit(terminate); - test_5gc_run(argc, argv, "23504.yaml", initialize); + test_app_run(argc, argv, "sample.yaml", initialize); for (i = 0; alltests[i].func; i++) suite = alltests[i].func(suite); diff --git a/tests/handover/epc-s1-test.c b/tests/handover/epc-s1-test.c new file mode 100644 index 000000000..aeb234eec --- /dev/null +++ b/tests/handover/epc-s1-test.c @@ -0,0 +1,1620 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap1, *s1ap2; + ogs_socknode_t *gtpu1, *gtpu2; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + uint32_t enb_ue_s1ap_id; + uint64_t mme_ue_s1ap_id; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"901707364000060\", " + "\"pdn\" : [" + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"apn\" : \"internet\", " + "\"pcc_rule\" : [" + "{" + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," + "\"qos\" : {" + "\"qci\" : 1," + "\"gbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"mbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"arp\" : {" + "\"priority_level\" : 3," + "\"pre_emption_vulnerability\" : 0," + "\"pre_emption_capability\" : 0 }" + "}," + "\"flow\" : [" + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } }" + "]" + "}" + "]," + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x4615380; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* Two eNB connects to MME */ + s1ap1 = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap1); + + s1ap2 = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap2); + + /* eNB connects to SGW */ + gtpu1 = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu1); + + gtpu2 = test_gtpu_server(2, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu2); + + /* S1-Setup Reqeust/Response for Source eNB */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x1f2); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /* S1-Setup Reqeust/Response for Target eNB */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x43); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.additional_update_type = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + test_ue->initial_ue_param.gummei_id = 1; + test_ue->initial_ue_param.gummei.mme_gid = 2; + test_ue->initial_ue_param.gummei.mme_code = 1; + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Identity Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive E-RAB Setup Request + + * Activate dedicated EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Setup Response */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + sendbuf = test_s1ap_build_e_rab_setup_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Activate dedicated EPS bearer context accept */ + esmbuf = testesm_build_activate_dedicated_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send ENB configuration transfer */ + sendbuf = test_s1ap_build_enb_configuration_transfer(0); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive MME configuration transfer */ + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ENB configuration transfer */ + sendbuf = test_s1ap_build_enb_configuration_transfer(1); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive MME configuration transfer */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu1, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu1); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu1, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu1); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send Handover Required */ + sendbuf = test_s1ap_build_handover_required( + test_ue, S1AP_HandoverType_intralte, + S1AP_ENB_ID_PR_macroENB_ID, 0x43, + S1AP_Cause_PR_radioNetwork, + S1AP_CauseRadioNetwork_time_critical_handover); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Handover Request */ + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Handover Request Ack */ + ogs_list_for_each(&sess->bearer_list, bearer) { + bearer->enb_s1u_addr = test_self()->gnb2_addr; + bearer->enb_s1u_addr6 = test_self()->gnb2_addr6; + } + sendbuf = test_s1ap_build_handover_request_ack(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Handover Command */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send eNB Status Transfer */ + mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id--; + enb_ue_s1ap_id = test_ue->enb_ue_s1ap_id--; + + sendbuf = test_s1ap_build_enb_status_transfer(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + test_ue->mme_ue_s1ap_id = mme_ue_s1ap_id; + test_ue->enb_ue_s1ap_id = enb_ue_s1ap_id; + + /* Receive MME Status Transfer */ + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Handover Notify */ + test_ue->e_cgi.cell_id = 0x43a00; + sendbuf = test_s1ap_build_handover_notify(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive End Mark */ + recvbuf = test_gtpu_read(gtpu1); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Receive End Mark */ + recvbuf = test_gtpu_read(gtpu1); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send TAU Request */ + memset(&test_ue->tau_request_param, 0, sizeof(test_ue->tau_request_param)); + test_ue->tau_request_param.ue_network_capability = 1; + test_ue->tau_request_param.last_visited_registered_tai = 1; + test_ue->tau_request_param.drx_parameter = 1; + test_ue->tau_request_param.eps_bearer_context_status = 1; + test_ue->tau_request_param.ms_network_capability = 1; + test_ue->tau_request_param.tmsi_status = 1; + test_ue->tau_request_param.mobile_station_classmark_2 = 1; + test_ue->tau_request_param.ue_usage_setting = 1; + emmbuf = testemm_build_tau_request(test_ue, false); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive TAU Accept */ + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive UE Context Release Command */ + mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id; + enb_ue_s1ap_id = test_ue->enb_ue_s1ap_id; + + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + test_ue->mme_ue_s1ap_id = mme_ue_s1ap_id; + test_ue->enb_ue_s1ap_id = enb_ue_s1ap_id; + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu2, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu2); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu2, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu2); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send Handover Required */ + sendbuf = test_s1ap_build_handover_required( + test_ue, S1AP_HandoverType_intralte, + S1AP_ENB_ID_PR_macroENB_ID, 0x1f2, + S1AP_Cause_PR_radioNetwork, + S1AP_CauseRadioNetwork_time_critical_handover); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Handover Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Handover Request Ack */ + ogs_list_for_each(&sess->bearer_list, bearer) { + bearer->enb_s1u_addr = test_self()->gnb1_addr; + bearer->enb_s1u_addr6 = test_self()->gnb1_addr6; + } + sendbuf = test_s1ap_build_handover_request_ack(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Handover Command */ + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send eNB Status Transfer */ + mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id--; + enb_ue_s1ap_id = test_ue->enb_ue_s1ap_id--; + + sendbuf = test_s1ap_build_enb_status_transfer(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + test_ue->mme_ue_s1ap_id = mme_ue_s1ap_id; + test_ue->enb_ue_s1ap_id = enb_ue_s1ap_id; + + /* Receive MME Status Transfer */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Handover Notify */ + test_ue->e_cgi.cell_id = 0x1f20a0; + sendbuf = test_s1ap_build_handover_notify(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive End Mark */ + recvbuf = test_gtpu_read(gtpu2); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Receive End Mark */ + recvbuf = test_gtpu_read(gtpu2); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Receive UE Context Release Command */ + mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id; + enb_ue_s1ap_id = test_ue->enb_ue_s1ap_id; + + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + test_ue->mme_ue_s1ap_id = mme_ue_s1ap_id; + test_ue->enb_ue_s1ap_id = enb_ue_s1ap_id; + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu1, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu1); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu1, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu1); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send Handover Required */ + sendbuf = test_s1ap_build_handover_required( + test_ue, S1AP_HandoverType_intralte, + S1AP_ENB_ID_PR_macroENB_ID, 0x43, + S1AP_Cause_PR_radioNetwork, + S1AP_CauseRadioNetwork_time_critical_handover); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Handover Request */ + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Handover Request Ack */ + ogs_list_for_each(&sess->bearer_list, bearer) { + bearer->enb_s1u_addr = test_self()->gnb1_addr; + bearer->enb_s1u_addr6 = test_self()->gnb1_addr6; + } + sendbuf = test_s1ap_build_handover_request_ack(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Handover Command */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Handover Cancel */ + mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id--; + enb_ue_s1ap_id = test_ue->enb_ue_s1ap_id--; + + sendbuf = test_s1ap_build_handover_cancel(test_ue, + S1AP_Cause_PR_radioNetwork, + S1AP_CauseRadioNetwork_tS1relocprep_expiry); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Recv Handover Cancel Ack */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive UE Context Release Command */ + mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id; + enb_ue_s1ap_id = test_ue->enb_ue_s1ap_id; + + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + test_ue->mme_ue_s1ap_id = mme_ue_s1ap_id; + test_ue->enb_ue_s1ap_id = enb_ue_s1ap_id; + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from SGW */ + testgnb_gtpu_close(gtpu2); + testgnb_gtpu_close(gtpu1); + + /* Two eNB disonncect from MME */ + testenb_s1ap_close(s1ap1); + testenb_s1ap_close(s1ap2); + + test_ue_remove(test_ue); +} + +static void test2_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap1, *s1ap2; + ogs_socknode_t *gtpu1, *gtpu2; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + uint32_t enb_ue_s1ap_id; + uint64_t mme_ue_s1ap_id; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"901707364000060\", " + "\"pdn\" : [" + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"apn\" : \"internet\", " + "\"pcc_rule\" : [" + "{" + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," + "\"qos\" : {" + "\"qci\" : 1," + "\"gbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"mbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"arp\" : {" + "\"priority_level\" : 3," + "\"pre_emption_vulnerability\" : 0," + "\"pre_emption_capability\" : 0 }" + "}," + "\"flow\" : [" + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } }" + "]" + "}" + "]," + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x4615380; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* Two eNB connects to MME */ + s1ap1 = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap1); + + s1ap2 = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap2); + + /* eNB connects to SGW */ + gtpu1 = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu1); + + gtpu2 = test_gtpu_server(2, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu2); + + /* S1-Setup Reqeust/Response for Source eNB */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x1f2); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /* S1-Setup Reqeust/Response for Target eNB */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x43); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.additional_update_type = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + test_ue->initial_ue_param.gummei_id = 1; + test_ue->initial_ue_param.gummei.mme_gid = 2; + test_ue->initial_ue_param.gummei.mme_code = 1; + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Identity Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive E-RAB Setup Request + + * Activate dedicated EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Setup Response */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + sendbuf = test_s1ap_build_e_rab_setup_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Activate dedicated EPS bearer context accept */ + esmbuf = testesm_build_activate_dedicated_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send ENB configuration transfer */ + sendbuf = test_s1ap_build_enb_configuration_transfer(0); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive MME configuration transfer */ + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ENB configuration transfer */ + sendbuf = test_s1ap_build_enb_configuration_transfer(1); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive MME configuration transfer */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Handover Required */ + sendbuf = test_s1ap_build_handover_required( + test_ue, S1AP_HandoverType_intralte, + S1AP_ENB_ID_PR_macroENB_ID, 0x43, + S1AP_Cause_PR_radioNetwork, + S1AP_CauseRadioNetwork_time_critical_handover); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Handover Request */ + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Handover Request Ack */ + ogs_list_for_each(&sess->bearer_list, bearer) { + bearer->enb_s1u_addr = test_self()->gnb1_addr; + bearer->enb_s1u_addr6 = test_self()->gnb1_addr6; + } + sendbuf = test_s1ap_build_handover_request_ack(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Handover Command */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Handover Cancel */ + mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id--; + enb_ue_s1ap_id = test_ue->enb_ue_s1ap_id--; + + sendbuf = test_s1ap_build_handover_cancel(test_ue, + S1AP_Cause_PR_radioNetwork, + S1AP_CauseRadioNetwork_tS1relocprep_expiry); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Recv Handover Cancel Ack */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive UE Context Release Command */ + mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id; + enb_ue_s1ap_id = test_ue->enb_ue_s1ap_id; + + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + test_ue->mme_ue_s1ap_id = mme_ue_s1ap_id; + test_ue->enb_ue_s1ap_id = enb_ue_s1ap_id; + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from SGW */ + testgnb_gtpu_close(gtpu2); + testgnb_gtpu_close(gtpu1); + + /* Two eNB disonncect from MME */ + testenb_s1ap_close(s1ap1); + testenb_s1ap_close(s1ap2); + + test_ue_remove(test_ue); +} + +static void test3_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap1, *s1ap2; + ogs_socknode_t *gtpu1, *gtpu2; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + uint32_t enb_ue_s1ap_id; + uint64_t mme_ue_s1ap_id; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"901707364000060\", " + "\"pdn\" : [" + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"apn\" : \"internet\", " + "\"pcc_rule\" : [" + "{" + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," + "\"qos\" : {" + "\"qci\" : 1," + "\"gbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"mbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"arp\" : {" + "\"priority_level\" : 3," + "\"pre_emption_vulnerability\" : 0," + "\"pre_emption_capability\" : 0 }" + "}," + "\"flow\" : [" + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } }" + "]" + "}" + "]," + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x4615380; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* Two eNB connects to MME */ + s1ap1 = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap1); + + s1ap2 = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap2); + + /* eNB connects to SGW */ + gtpu1 = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu1); + + gtpu2 = test_gtpu_server(2, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu2); + + /* S1-Setup Reqeust/Response for Source eNB */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x1f2); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /* S1-Setup Reqeust/Response for Target eNB */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x43); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.guti = 1; + test_ue->attach_request_param.last_visited_registered_tai = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.additional_update_type = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + test_ue->attach_request_param.old_guti_type = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + test_ue->initial_ue_param.gummei_id = 1; + test_ue->initial_ue_param.gummei.mme_gid = 2; + test_ue->initial_ue_param.gummei.mme_code = 1; + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Identity Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Identity response */ + emmbuf = testemm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive E-RAB Setup Request + + * Activate dedicated EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Setup Response */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + sendbuf = test_s1ap_build_e_rab_setup_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Activate dedicated EPS bearer context accept */ + esmbuf = testesm_build_activate_dedicated_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send ENB configuration transfer */ + sendbuf = test_s1ap_build_enb_configuration_transfer(0); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive MME configuration transfer */ + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ENB configuration transfer */ + sendbuf = test_s1ap_build_enb_configuration_transfer(1); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive MME configuration transfer */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Handover Required */ + sendbuf = test_s1ap_build_handover_required( + test_ue, S1AP_HandoverType_intralte, + S1AP_ENB_ID_PR_macroENB_ID, 0x43, + S1AP_Cause_PR_radioNetwork, + S1AP_CauseRadioNetwork_time_critical_handover); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Handover Request */ + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Handover Failure */ + sendbuf = test_s1ap_build_handover_failure(test_ue, + S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_unspecified); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Handover Preparation Failure */ + mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id--; + + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + test_ue->mme_ue_s1ap_id = mme_ue_s1ap_id; + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + test_ue->enb_ue_s1ap_id++; + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from SGW */ + testgnb_gtpu_close(gtpu2); + testgnb_gtpu_close(gtpu1); + + /* Two eNB disonncect from MME */ + testenb_s1ap_close(s1ap1); + testenb_s1ap_close(s1ap2); + + test_ue_remove(test_ue); +} + +abts_suite *test_epc_s1(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + abts_run_test(suite, test2_func, NULL); + abts_run_test(suite, test3_func, NULL); + + return suite; +} diff --git a/tests/handover/epc-x2-test.c b/tests/handover/epc-x2-test.c new file mode 100644 index 000000000..3fb8eab4c --- /dev/null +++ b/tests/handover/epc-x2-test.c @@ -0,0 +1,485 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap1, *s1ap2; + ogs_socknode_t *gtpu1, *gtpu2; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"901707364000060\", " + "\"pdn\" : [" + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"apn\" : \"internet\", " + "\"pcc_rule\" : [" + "{" + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," + "\"qos\" : {" + "\"qci\" : 1," + "\"gbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"mbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"arp\" : {" + "\"priority_level\" : 3," + "\"pre_emption_vulnerability\" : 0," + "\"pre_emption_capability\" : 0 }" + "}," + "\"flow\" : [" + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } }" + "]" + "}" + "]," + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x37; + mobile_identity_suci.scheme_output[1] = 0x46; + mobile_identity_suci.scheme_output[2] = 0; + mobile_identity_suci.scheme_output[3] = 0; + mobile_identity_suci.scheme_output[4] = 0x06; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x4615380; + test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* Two eNB connects to MME */ + s1ap1 = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap1); + + s1ap2 = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap2); + + /* eNB connects to SGW */ + gtpu1 = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu1); + + gtpu2 = test_gtpu_server(2, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu2); + + /* S1-Setup Reqeust/Response for Source eNB */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /* S1-Setup Reqeust/Response for Target eNB */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f65); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap2, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + recvbuf = testenb_s1ap_read(s1ap2); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.additional_update_type = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive E-RAB Setup Request + + * Activate dedicated EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Setup Response */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + sendbuf = test_s1ap_build_e_rab_setup_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Activate dedicated EPS bearer context accept */ + esmbuf = testesm_build_activate_dedicated_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(100); + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu1, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu1); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu1, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu1); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send Path Switch Request */ + test_ue->e_cgi.cell_id = 0x461530; + ogs_list_for_each(&sess->bearer_list, bearer) { + bearer->enb_s1u_addr = test_self()->gnb2_addr; + bearer->enb_s1u_addr6 = test_self()->gnb2_addr6; + } + + sendbuf = test_s1ap_build_path_switch_request(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Path Switch Ack */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive End Mark */ + recvbuf = test_gtpu_read(gtpu1); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Receive End Mark */ + recvbuf = test_gtpu_read(gtpu1); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu2, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu2); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu2, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu2); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send Path Switch Request */ + test_ue->e_cgi.cell_id = 0x46150; + test_ue->enb_ue_s1ap_id++; + ogs_list_for_each(&sess->bearer_list, bearer) { + bearer->enb_s1u_addr = test_self()->gnb1_addr; + bearer->enb_s1u_addr6 = test_self()->gnb1_addr6; + } + + sendbuf = test_s1ap_build_path_switch_request(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap1, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Path Switch Ack */ + recvbuf = testenb_s1ap_read(s1ap1); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu1, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu1); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu1, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu1); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from SGW */ + testgnb_gtpu_close(gtpu2); + testgnb_gtpu_close(gtpu1); + + /* Two eNB disonncect from MME */ + testenb_s1ap_close(s1ap1); + testenb_s1ap_close(s1ap2); + + test_ue_remove(test_ue); +} + +abts_suite *test_epc_x2(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/23504/meson.build b/tests/handover/meson.build similarity index 78% rename from tests/23504/meson.build rename to tests/handover/meson.build index 9b0189616..a1056441b 100644 --- a/tests/23504/meson.build +++ b/tests/handover/meson.build @@ -15,12 +15,15 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -testapp_23504_sources = files(''' +testapp_handover_sources = files(''' abts-main.c - r16-test.c + epc-x2-test.c + epc-s1-test.c '''.split()) -testapp_23504_exe = executable('23504', - sources : testapp_23504_sources, +testapp_handover_exe = executable('handover', + sources : testapp_handover_sources, c_args : testunit_core_cc_flags, dependencies : libtestapp_dep) + +test('handover', testapp_handover_exe, is_parallel : false, suite: 'app') diff --git a/tests/meson.build b/tests/meson.build index e1777fbf1..520fa08bf 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -23,12 +23,10 @@ subdir('sctp') subdir('common') subdir('app') subdir('unit') -subdir('epc') -subdir('mnc3') +subdir('registration') +subdir('minimal') +subdir('attach') subdir('volte') subdir('csfb') -subdir('cups') -subdir('minimal') -subdir('registration') -subdir('00101') -subdir('23504') +subdir('310014') +subdir('handover') diff --git a/tests/minimal/abts-main.c b/tests/minimal/abts-main.c index 345262318..110b278ee 100644 --- a/tests/minimal/abts-main.c +++ b/tests/minimal/abts-main.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-5gc.h" +#include "test-app.h" abts_suite *test_minimal(abts_suite *suite); @@ -57,7 +57,7 @@ int main(int argc, const char *const argv[]) abts_suite *suite = NULL; atexit(terminate); - test_5gc_run(argc, argv, "minimal.yaml", initialize); + test_app_run(argc, argv, "minimal.yaml", initialize); for (i = 0; alltests[i].func; i++) suite = alltests[i].func(suite); diff --git a/tests/minimal/minimal-test.c b/tests/minimal/minimal-test.c index 810ae3313..ffb9f52d4 100644 --- a/tests/minimal/minimal-test.c +++ b/tests/minimal/minimal-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-5gc.h" +#include "test-common.h" static void test1_func(abts_case *tc, void *data) { @@ -31,13 +31,11 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "5122250214c33e723a5dd523fc145fc0"; uint8_t k[OGS_KEY_LEN]; @@ -90,21 +88,10 @@ static void test1_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = 1; /* TSC[0], KSI[1] */ - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = 1; /* Initial Registration */ - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -116,38 +103,30 @@ static void test1_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[2] = 0x47; mobile_identity_suci.scheme_output[3] = 0x78; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 12); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 12); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 1; - test_ue.mobile_identity_imeisv.digit2 = 1; - test_ue.mobile_identity_imeisv.digit3 = 1; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = 1; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 10; - test_sess.pti = 0; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4; - test_sess.dnn = (char *)"internet"; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 10); + ogs_assert(sess); - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 3; + sess->pti = 0; + sess->pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4; /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -159,13 +138,13 @@ static void test1_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -182,7 +161,7 @@ static void test1_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -191,10 +170,10 @@ static void test1_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - test_ue.registration_request_param.gmm_capability = 1; - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -202,12 +181,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -215,14 +194,14 @@ static void test1_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -230,24 +209,24 @@ static void test1_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -255,20 +234,20 @@ static void test1_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -276,16 +255,16 @@ static void test1_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -296,9 +275,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -307,7 +284,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -316,7 +293,7 @@ static void test1_func(abts_case *tc, void *data) mongoc_collection_destroy(collection); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); /* gNB disonncect from UPF */ testgnb_gtpu_close(gtpu); diff --git a/tests/registration/abts-main.c b/tests/registration/abts-main.c index 453d9bf5a..da37e3a3c 100644 --- a/tests/registration/abts-main.c +++ b/tests/registration/abts-main.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-5gc.h" +#include "test-app.h" abts_suite *test_guti(abts_suite *suite); abts_suite *test_auth(abts_suite *suite); @@ -69,7 +69,7 @@ int main(int argc, const char *const argv[]) abts_suite *suite = NULL; atexit(terminate); - test_5gc_run(argc, argv, "5gc-sample.yaml", initialize); + test_app_run(argc, argv, "sample.yaml", initialize); for (i = 0; alltests[i].func; i++) suite = alltests[i].func(suite); diff --git a/tests/registration/auth-test.c b/tests/registration/auth-test.c index 1cba797bc..18edfd592 100644 --- a/tests/registration/auth-test.c +++ b/tests/registration/auth-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-5gc.h" +#include "test-common.h" static void test1_func(abts_case *tc, void *data) { @@ -31,13 +31,11 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -89,21 +87,10 @@ static void test1_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -116,52 +103,27 @@ static void test1_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 0; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -173,13 +135,13 @@ static void test1_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -196,7 +158,7 @@ static void test1_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -205,10 +167,10 @@ static void test1_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - test_ue.registration_request_param.gmm_capability = 1; - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -216,13 +178,13 @@ static void test1_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication failure - SYNCH failure */ gmmbuf = testgmm_build_authentication_failure( - &test_ue, OGS_5GMM_CAUSE_SYNCH_FAILURE, 0x11223344); + test_ue, OGS_5GMM_CAUSE_SYNCH_FAILURE, 0x11223344); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -230,13 +192,13 @@ static void test1_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication failure - MAC failure */ gmmbuf = testgmm_build_authentication_failure( - &test_ue, OGS_5GMM_CAUSE_MAC_FAILURE, 0); + test_ue, OGS_5GMM_CAUSE_MAC_FAILURE, 0); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -244,21 +206,21 @@ static void test1_func(abts_case *tc, void *data) /* Receive Authentication reject */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -273,7 +235,7 @@ static void test1_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } abts_suite *test_auth(abts_suite *suite) diff --git a/tests/registration/dereg-test.c b/tests/registration/dereg-test.c index 864a02528..640175b6c 100644 --- a/tests/registration/dereg-test.c +++ b/tests/registration/dereg-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-5gc.h" +#include "test-common.h" static void test1_func(abts_case *tc, void *data) { @@ -31,13 +31,11 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -93,21 +91,10 @@ static void test1_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -120,52 +107,27 @@ static void test1_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 0; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -177,13 +139,13 @@ static void test1_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -200,7 +162,7 @@ static void test1_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -209,17 +171,17 @@ static void test1_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -227,12 +189,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -240,12 +202,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -253,24 +215,24 @@ static void test1_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -278,30 +240,30 @@ static void test1_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); #if 0 /* Send Configuration update complete */ - gmmbuf = testgmm_build_configuration_update_complete(&test_ue); + gmmbuf = testgmm_build_configuration_update_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); #endif /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -309,16 +271,16 @@ static void test1_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -329,9 +291,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -340,9 +300,9 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send De-registration request */ - gmmbuf = testgmm_build_de_registration_request(&test_ue, 1); + gmmbuf = testgmm_build_de_registration_request(test_ue, 1); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -350,16 +310,16 @@ static void test1_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -374,7 +334,7 @@ static void test1_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } static void test2_func(abts_case *tc, void *data) @@ -389,13 +349,11 @@ static void test2_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -451,21 +409,10 @@ static void test2_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -478,52 +425,27 @@ static void test2_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 0; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -535,13 +457,13 @@ static void test2_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -558,7 +480,7 @@ static void test2_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -567,17 +489,17 @@ static void test2_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -585,12 +507,12 @@ static void test2_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -598,12 +520,12 @@ static void test2_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -611,24 +533,24 @@ static void test2_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -636,12 +558,12 @@ static void test2_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send De-registration request */ - gmmbuf = testgmm_build_de_registration_request(&test_ue, 1); + gmmbuf = testgmm_build_de_registration_request(test_ue, 1); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -649,16 +571,16 @@ static void test2_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -673,7 +595,7 @@ static void test2_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } static void test3_func(abts_case *tc, void *data) @@ -688,13 +610,11 @@ static void test3_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -746,21 +666,10 @@ static void test3_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -773,52 +682,27 @@ static void test3_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 0; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -830,13 +714,13 @@ static void test3_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -853,7 +737,7 @@ static void test3_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -862,18 +746,18 @@ static void test3_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - test_ue.registration_request_param.gmm_capability = 0; - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 0; + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -881,12 +765,12 @@ static void test3_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -894,12 +778,12 @@ static void test3_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -907,24 +791,24 @@ static void test3_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -932,20 +816,20 @@ static void test3_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -953,16 +837,16 @@ static void test3_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -973,9 +857,7 @@ static void test3_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -984,16 +866,16 @@ static void test3_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send PDU Session release request */ - test_sess.ul_nas_transport_param.request_type = 0; - test_sess.ul_nas_transport_param.dnn = 0; - test_sess.ul_nas_transport_param.s_nssai = 0; + sess->ul_nas_transport_param.request_type = 0; + sess->ul_nas_transport_param.dnn = 0; + sess->ul_nas_transport_param.s_nssai = 0; - gsmbuf = testgsm_build_pdu_session_release_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_release_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1001,33 +883,33 @@ static void test3_func(abts_case *tc, void *data) /* Receive PDU session release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session resource release response */ - sendbuf = testngap_build_pdu_session_resource_release_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_release_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session resource release complete */ - test_sess.ul_nas_transport_param.request_type = 0; - test_sess.ul_nas_transport_param.dnn = 0; - test_sess.ul_nas_transport_param.s_nssai = 0; + sess->ul_nas_transport_param.request_type = 0; + sess->ul_nas_transport_param.dnn = 0; + sess->ul_nas_transport_param.s_nssai = 0; - gsmbuf = testgsm_build_pdu_session_release_complete(&test_sess); + gsmbuf = testgsm_build_pdu_session_release_complete(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send De-registration request */ - gmmbuf = testgmm_build_de_registration_request(&test_ue, 1); + gmmbuf = testgmm_build_de_registration_request(test_ue, 1); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1035,36 +917,36 @@ static void test3_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration request : Uplink Data Status */ - test_ue.registration_request_param.integrity_protected = 0; - test_ue.registration_request_param.guti = 1; - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - test_ue.registration_request_param.update_type = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.integrity_protected = 0; + test_ue->registration_request_param.guti = 1; + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + test_ue->registration_request_param.update_type = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - test_ue.registration_request_param.integrity_protected = 1; - test_ue.registration_request_param.guti = 1; - test_ue.registration_request_param.gmm_capability = 0; - test_ue.registration_request_param.requested_nssai = 0; - test_ue.registration_request_param.last_visited_registered_tai = 0; - test_ue.registration_request_param.ue_usage_setting = 0; - test_ue.registration_request_param.update_type = 0; - gmmbuf = testgmm_build_registration_request(&test_ue, nasbuf); + test_ue->registration_request_param.integrity_protected = 1; + test_ue->registration_request_param.guti = 1; + test_ue->registration_request_param.gmm_capability = 0; + test_ue->registration_request_param.requested_nssai = 0; + test_ue->registration_request_param.last_visited_registered_tai = 0; + test_ue->registration_request_param.ue_usage_setting = 0; + test_ue->registration_request_param.update_type = 0; + gmmbuf = testgmm_build_registration_request(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1072,27 +954,27 @@ static void test3_func(abts_case *tc, void *data) /* Receive Registration accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_reactivation_result); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1100,16 +982,16 @@ static void test3_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1120,9 +1002,7 @@ static void test3_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -1131,7 +1011,7 @@ static void test3_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -1146,7 +1026,7 @@ static void test3_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } static void test4_func(abts_case *tc, void *data) @@ -1161,13 +1041,11 @@ static void test4_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -1219,21 +1097,10 @@ static void test4_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -1246,52 +1113,27 @@ static void test4_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 0; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -1303,13 +1145,13 @@ static void test4_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -1326,7 +1168,7 @@ static void test4_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -1336,18 +1178,18 @@ static void test4_func(abts_case *tc, void *data) for (i = 0; i < 10; i++) { /* Send Registration request */ - test_ue.registration_request_param.gmm_capability = 0; - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 0; + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1355,12 +1197,12 @@ static void test4_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1368,12 +1210,12 @@ static void test4_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1381,24 +1223,24 @@ static void test4_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1406,20 +1248,20 @@ static void test4_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1427,11 +1269,11 @@ static void test4_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session resource setup response */ sendbuf = - testngap_build_pdu_session_resource_setup_response(&test_sess); + testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1439,16 +1281,16 @@ static void test4_func(abts_case *tc, void *data) ogs_msleep(100); /* Send PDU Session release request */ - test_sess.ul_nas_transport_param.request_type = 0; - test_sess.ul_nas_transport_param.dnn = 0; - test_sess.ul_nas_transport_param.s_nssai = 0; + sess->ul_nas_transport_param.request_type = 0; + sess->ul_nas_transport_param.dnn = 0; + sess->ul_nas_transport_param.s_nssai = 0; - gsmbuf = testgsm_build_pdu_session_release_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_release_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1456,34 +1298,34 @@ static void test4_func(abts_case *tc, void *data) /* Receive PDU session release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session resource release response */ sendbuf = - testngap_build_pdu_session_resource_release_response(&test_sess); + testngap_build_pdu_session_resource_release_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session resource release complete */ - test_sess.ul_nas_transport_param.request_type = 0; - test_sess.ul_nas_transport_param.dnn = 0; - test_sess.ul_nas_transport_param.s_nssai = 0; + sess->ul_nas_transport_param.request_type = 0; + sess->ul_nas_transport_param.dnn = 0; + sess->ul_nas_transport_param.s_nssai = 0; - gsmbuf = testgsm_build_pdu_session_release_complete(&test_sess); + gsmbuf = testgsm_build_pdu_session_release_complete(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send De-registration request */ - gmmbuf = testgmm_build_de_registration_request(&test_ue, 1); + gmmbuf = testgmm_build_de_registration_request(test_ue, 1); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1491,17 +1333,17 @@ static void test4_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); } /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -1516,7 +1358,7 @@ static void test4_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } abts_suite *test_dereg(abts_suite *suite) diff --git a/tests/registration/gmm-status-test.c b/tests/registration/gmm-status-test.c index dd23a7b31..3fcc11f41 100644 --- a/tests/registration/gmm-status-test.c +++ b/tests/registration/gmm-status-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-5gc.h" +#include "test-common.h" static void test1_func(abts_case *tc, void *data) { @@ -31,13 +31,11 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -89,21 +87,10 @@ static void test1_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -116,52 +103,27 @@ static void test1_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 0; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -173,13 +135,13 @@ static void test1_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -196,7 +158,7 @@ static void test1_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -205,17 +167,17 @@ static void test1_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -223,12 +185,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -236,12 +198,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -249,18 +211,18 @@ static void test1_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -268,20 +230,20 @@ static void test1_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -289,13 +251,13 @@ static void test1_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send GMM Status */ - gmmbuf = testgmm_build_gmm_status(&test_ue, + gmmbuf = testgmm_build_gmm_status(test_ue, OGS_5GMM_CAUSE_MESSAGE_NOT_COMPATIBLE_WITH_THE_PROTOCOL_STATE); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -303,16 +265,16 @@ static void test1_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -327,7 +289,7 @@ static void test1_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } abts_suite *test_gmm_status(abts_suite *suite) diff --git a/tests/registration/guti-test.c b/tests/registration/guti-test.c index d87a436ce..aae7400fa 100644 --- a/tests/registration/guti-test.c +++ b/tests/registration/guti-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-5gc.h" +#include "test-common.h" static void test1_func(abts_case *tc, void *data) { @@ -31,13 +31,11 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -89,21 +87,10 @@ static void test1_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -116,52 +103,27 @@ static void test1_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 0; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -173,13 +135,13 @@ static void test1_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -196,7 +158,7 @@ static void test1_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -205,18 +167,18 @@ static void test1_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - test_ue.registration_request_param.guti = 1; - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.guti = 1; + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -224,12 +186,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Identity request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Identity response */ - gmmbuf = testgmm_build_identity_response(&test_ue); + gmmbuf = testgmm_build_identity_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -237,12 +199,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -250,12 +212,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -263,24 +225,24 @@ static void test1_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -288,20 +250,20 @@ static void test1_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -309,16 +271,16 @@ static void test1_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -329,9 +291,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -339,24 +299,35 @@ static void test1_func(abts_case *tc, void *data) ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); +#if __linux__ + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV6); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); +#endif + /* Update Registration request type */ - test_ue.nas.registration.value = + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_MOBILITY_UPDATING; /* Send Registration request : Uplink Data Status */ - test_ue.registration_request_param.integrity_protected = 0; - test_ue.registration_request_param.uplink_data_status = 1; - test_ue.registration_request_param.psimask.uplink_data_status = - 1 << test_sess.psi; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.integrity_protected = 0; + test_ue->registration_request_param.uplink_data_status = 1; + test_ue->registration_request_param.psimask.uplink_data_status = + 1 << sess->psi; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - test_ue.registration_request_param.integrity_protected = 1; - test_ue.registration_request_param.uplink_data_status = 0; - gmmbuf = testgmm_build_registration_request(&test_ue, nasbuf); + test_ue->registration_request_param.integrity_protected = 1; + test_ue->registration_request_param.uplink_data_status = 0; + gmmbuf = testgmm_build_registration_request(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -364,20 +335,20 @@ static void test1_func(abts_case *tc, void *data) /* Receive Registration accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_reactivation_result); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ sendbuf = testngap_build_initial_context_setup_response( - &test_ue, &test_sess); + test_ue, sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -386,20 +357,20 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Update Registration request type */ - test_ue.nas.registration.value = + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_PERIODIC_UPDATING; /* Send Registration request - INVALID_GUTI */ - test_ue.nas_guti.m_tmsi = 0x1234; - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->nas_5gs_guti.m_tmsi = 0x1234; + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.integrity_protected = 0; - test_ue.registration_request_param.uplink_data_status = 0; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.integrity_protected = 0; + test_ue->registration_request_param.uplink_data_status = 0; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -407,14 +378,14 @@ static void test1_func(abts_case *tc, void *data) /* Receive Identity request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); ogs_msleep(100); /* Send Identity response */ - gmmbuf = testgmm_build_identity_response(&test_ue); + gmmbuf = testgmm_build_identity_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -422,12 +393,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -435,12 +406,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -448,18 +419,18 @@ static void test1_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -467,20 +438,20 @@ static void test1_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -488,18 +459,18 @@ static void test1_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -508,7 +479,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -523,7 +494,7 @@ static void test1_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } abts_suite *test_guti(abts_suite *suite) diff --git a/tests/registration/identity-test.c b/tests/registration/identity-test.c index a99fbd590..7f5618235 100644 --- a/tests/registration/identity-test.c +++ b/tests/registration/identity-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-5gc.h" +#include "test-common.h" static void test1_func(abts_case *tc, void *data) { @@ -31,13 +31,11 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -89,21 +87,10 @@ static void test1_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -116,52 +103,27 @@ static void test1_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 0; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -173,13 +135,13 @@ static void test1_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -196,7 +158,7 @@ static void test1_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -205,17 +167,17 @@ static void test1_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -223,12 +185,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -236,12 +198,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -249,24 +211,24 @@ static void test1_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -274,20 +236,20 @@ static void test1_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -295,26 +257,26 @@ static void test1_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Update Registration request type */ - test_ue.nas.registration.value = + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_MOBILITY_UPDATING; /* Send Registration request */ - test_ue.registration_request_param.integrity_protected = 1; - test_ue.registration_request_param.guti = 1; - test_ue.registration_request_param.uplink_data_status = 1; - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.integrity_protected = 1; + test_ue->registration_request_param.guti = 1; + test_ue->registration_request_param.uplink_data_status = 1; + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -322,11 +284,11 @@ static void test1_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Initial context setup response */ sendbuf = testngap_build_initial_context_setup_response( - &test_ue, &test_sess); + test_ue, sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -334,9 +296,9 @@ static void test1_func(abts_case *tc, void *data) ogs_msleep(100); /* Send De-registration request */ - gmmbuf = testgmm_build_de_registration_request(&test_ue, 1); + gmmbuf = testgmm_build_de_registration_request(test_ue, 1); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -344,26 +306,26 @@ static void test1_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Update Registration request type */ - test_ue.nas.registration.value = + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_PERIODIC_UPDATING; /* INVALID GUTI */ - test_ue.nas_guti.m_tmsi = 0x1234; + test_ue->nas_5gs_guti.m_tmsi = 0x1234; /* Send Registration request */ - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -371,17 +333,17 @@ static void test1_func(abts_case *tc, void *data) /* Receive Identity request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); ogs_msleep(100); /* INVALID SUCI */ - test_ue.mobile_identity_suci.scheme_output[0] = 0x99; + test_ue->mobile_identity_suci.scheme_output[0] = 0x99; /* Send Identity response */ - gmmbuf = testgmm_build_identity_response(&test_ue); + gmmbuf = testgmm_build_identity_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -389,21 +351,21 @@ static void test1_func(abts_case *tc, void *data) /* Receive Registration reject */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -418,7 +380,7 @@ static void test1_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } abts_suite *test_identity(abts_suite *suite) diff --git a/tests/registration/idle-test.c b/tests/registration/idle-test.c index 4f9d84091..ae1e55ec7 100644 --- a/tests/registration/idle-test.c +++ b/tests/registration/idle-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-5gc.h" +#include "test-common.h" static void test1_func(abts_case *tc, void *data) { @@ -31,13 +31,11 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -89,21 +87,10 @@ static void test1_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -116,52 +103,27 @@ static void test1_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 3; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -173,13 +135,13 @@ static void test1_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -196,7 +158,7 @@ static void test1_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -205,17 +167,17 @@ static void test1_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -223,12 +185,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -236,12 +198,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -249,24 +211,24 @@ static void test1_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -274,20 +236,20 @@ static void test1_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -295,16 +257,16 @@ static void test1_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -315,9 +277,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -326,7 +286,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send UE context release request */ - sendbuf = testngap_build_ue_context_release_request(&test_ue, + sendbuf = testngap_build_ue_context_release_request(test_ue, NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_user_inactivity, true); ABTS_PTR_NOTNULL(tc, sendbuf); @@ -336,37 +296,35 @@ static void test1_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* * Send Service request Using InitialUEMessage * - PDU Session Status */ - test_ue.service_request_param.integrity_protected = 0; - test_ue.service_request_param.pdu_session_status = 1; - test_ue.service_request_param.psimask.pdu_session_status = - 1 << test_sess.psi; - nasbuf = testgmm_build_service_request(&test_ue, NULL); + test_ue->service_request_param.integrity_protected = 0; + test_ue->service_request_param.pdu_session_status = 1; + test_ue->service_request_param.psimask.pdu_session_status = + 1 << sess->psi; + nasbuf = testgmm_build_service_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - test_ue.service_request_param.integrity_protected = 1; - test_ue.service_request_param.pdu_session_status = 0; - gmmbuf = testgmm_build_service_request(&test_ue, nasbuf); + test_ue->service_request_param.integrity_protected = 1; + test_ue->service_request_param.pdu_session_status = 0; + gmmbuf = testgmm_build_service_request(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -374,13 +332,13 @@ static void test1_func(abts_case *tc, void *data) /* Receive Service accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x2000, test_ue.pdu_session_status); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_reactivation_result); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x2000, test_ue->pdu_session_status); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ sendbuf = testngap_build_initial_context_setup_response( - &test_ue, &test_sess); + test_ue, sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -391,9 +349,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -402,7 +358,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send UE context release request */ - sendbuf = testngap_build_ue_context_release_request(&test_ue, + sendbuf = testngap_build_ue_context_release_request(test_ue, NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_user_inactivity, true); ABTS_PTR_NOTNULL(tc, sendbuf); @@ -412,16 +368,14 @@ static void test1_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -430,21 +384,21 @@ static void test1_func(abts_case *tc, void *data) * Send Service request Using InitialUEMessage * - Uplink Data Status */ - test_ue.service_request_param.integrity_protected = 0; - test_ue.service_request_param.uplink_data_status = 1; - test_ue.service_request_param. - psimask.uplink_data_status = 1 << test_sess.psi; - test_ue.service_request_param.pdu_session_status = 0; - nasbuf = testgmm_build_service_request(&test_ue, NULL); + test_ue->service_request_param.integrity_protected = 0; + test_ue->service_request_param.uplink_data_status = 1; + test_ue->service_request_param. + psimask.uplink_data_status = 1 << sess->psi; + test_ue->service_request_param.pdu_session_status = 0; + nasbuf = testgmm_build_service_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - test_ue.service_request_param.integrity_protected = 1; - test_ue.service_request_param.uplink_data_status = 0; - test_ue.service_request_param.pdu_session_status = 0; - gmmbuf = testgmm_build_service_request(&test_ue, nasbuf); + test_ue->service_request_param.integrity_protected = 1; + test_ue->service_request_param.uplink_data_status = 0; + test_ue->service_request_param.pdu_session_status = 0; + gmmbuf = testgmm_build_service_request(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -452,15 +406,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Service accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_status); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_reactivation_result); - - test_sess.gnb_n3_teid = 5; + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_status); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response( - &test_ue, &test_sess); + sendbuf = testngap_build_initial_context_setup_response(test_ue, sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -471,9 +422,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -482,7 +431,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -497,7 +446,7 @@ static void test1_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } static void test2_func(abts_case *tc, void *data) @@ -512,13 +461,11 @@ static void test2_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -570,21 +517,10 @@ static void test2_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -597,52 +533,27 @@ static void test2_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 3; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -654,13 +565,13 @@ static void test2_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -677,7 +588,7 @@ static void test2_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -686,17 +597,17 @@ static void test2_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -704,12 +615,12 @@ static void test2_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -717,12 +628,12 @@ static void test2_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -730,24 +641,24 @@ static void test2_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -755,10 +666,10 @@ static void test2_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release request */ - sendbuf = testngap_build_ue_context_release_request(&test_ue, + sendbuf = testngap_build_ue_context_release_request(test_ue, NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_user_inactivity, true); ABTS_PTR_NOTNULL(tc, sendbuf); @@ -768,10 +679,10 @@ static void test2_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -780,16 +691,16 @@ static void test2_func(abts_case *tc, void *data) * Send Service request Using InitialUEMessage * - PDU Session Status */ - test_ue.service_request_param.integrity_protected = 0; - test_ue.service_request_param.pdu_session_status = 1; - nasbuf = testgmm_build_service_request(&test_ue, NULL); + test_ue->service_request_param.integrity_protected = 0; + test_ue->service_request_param.pdu_session_status = 1; + nasbuf = testgmm_build_service_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - test_ue.service_request_param.integrity_protected = 1; - test_ue.service_request_param.pdu_session_status = 0; - gmmbuf = testgmm_build_service_request(&test_ue, nasbuf); + test_ue->service_request_param.integrity_protected = 1; + test_ue->service_request_param.pdu_session_status = 0; + gmmbuf = testgmm_build_service_request(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -797,18 +708,18 @@ static void test2_func(abts_case *tc, void *data) /* Receive Service accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_status); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_reactivation_result); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_status); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -823,7 +734,7 @@ static void test2_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } static void test3_func(abts_case *tc, void *data) @@ -838,13 +749,11 @@ static void test3_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -896,21 +805,10 @@ static void test3_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -923,52 +821,27 @@ static void test3_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 3; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -980,13 +853,13 @@ static void test3_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -1003,7 +876,7 @@ static void test3_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -1012,17 +885,17 @@ static void test3_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1030,12 +903,12 @@ static void test3_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1043,12 +916,12 @@ static void test3_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1056,24 +929,24 @@ static void test3_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1081,20 +954,20 @@ static void test3_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1102,16 +975,16 @@ static void test3_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1122,9 +995,7 @@ static void test3_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -1137,23 +1008,23 @@ static void test3_func(abts_case *tc, void *data) * - Uplink Data Status * - PDU Session Status */ - test_ue.service_request_param.integrity_protected = 0; - test_ue.service_request_param.uplink_data_status = 1; - test_ue.service_request_param.psimask.uplink_data_status = - 1 << test_sess.psi; - test_ue.service_request_param.pdu_session_status = 1; - test_ue.service_request_param.psimask.pdu_session_status = - 1 << test_sess.psi; - nasbuf = testgmm_build_service_request(&test_ue, NULL); + test_ue->service_request_param.integrity_protected = 0; + test_ue->service_request_param.uplink_data_status = 1; + test_ue->service_request_param.psimask.uplink_data_status = + 1 << sess->psi; + test_ue->service_request_param.pdu_session_status = 1; + test_ue->service_request_param.psimask.pdu_session_status = + 1 << sess->psi; + nasbuf = testgmm_build_service_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - test_ue.service_request_param.integrity_protected = 1; - test_ue.service_request_param.uplink_data_status = 0; - test_ue.service_request_param.pdu_session_status = 0; - gmmbuf = testgmm_build_service_request(&test_ue, nasbuf); + test_ue->service_request_param.integrity_protected = 1; + test_ue->service_request_param.uplink_data_status = 0; + test_ue->service_request_param.pdu_session_status = 0; + gmmbuf = testgmm_build_service_request(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1161,21 +1032,19 @@ static void test3_func(abts_case *tc, void *data) /* Receive Service accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x2000, test_ue.pdu_session_status); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_reactivation_result); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x2000, test_ue->pdu_session_status); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ sendbuf = testngap_build_initial_context_setup_response( - &test_ue, NULL); + test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -1187,15 +1056,15 @@ static void test3_func(abts_case *tc, void *data) * Send Service request Using UplinkNASTransport * - Uplink Data Status */ - test_ue.service_request_param.integrity_protected = 1; - test_ue.service_request_param.ciphered = 1; - test_ue.service_request_param.uplink_data_status = 1; - test_ue.service_request_param.psimask.uplink_data_status = - 1 << test_sess.psi; - gmmbuf = testgmm_build_service_request(&test_ue, NULL); + test_ue->service_request_param.integrity_protected = 1; + test_ue->service_request_param.ciphered = 1; + test_ue->service_request_param.uplink_data_status = 1; + test_ue->service_request_param.psimask.uplink_data_status = + 1 << sess->psi; + gmmbuf = testgmm_build_service_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1203,13 +1072,11 @@ static void test3_func(abts_case *tc, void *data) /* Receive Service accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_reactivation_result); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -1218,7 +1085,7 @@ static void test3_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -1233,7 +1100,7 @@ static void test3_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } static void test4_func(abts_case *tc, void *data) @@ -1248,17 +1115,15 @@ static void test4_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; /* for backup */ uint32_t ran_ue_ngap_id; uint64_t amf_ue_ngap_id; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -1310,21 +1175,10 @@ static void test4_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -1337,52 +1191,27 @@ static void test4_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 3; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -1394,13 +1223,13 @@ static void test4_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -1417,7 +1246,7 @@ static void test4_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -1426,18 +1255,18 @@ static void test4_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - test_ue.registration_request_param.guti = 1; - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.guti = 1; + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1445,12 +1274,12 @@ static void test4_func(abts_case *tc, void *data) /* Receive Identity request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Identity response */ - gmmbuf = testgmm_build_identity_response(&test_ue); + gmmbuf = testgmm_build_identity_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1458,12 +1287,12 @@ static void test4_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1471,12 +1300,12 @@ static void test4_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1484,24 +1313,24 @@ static void test4_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1509,10 +1338,10 @@ static void test4_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release request */ - sendbuf = testngap_build_ue_context_release_request(&test_ue, + sendbuf = testngap_build_ue_context_release_request(test_ue, NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_user_inactivity, false); ABTS_PTR_NOTNULL(tc, sendbuf); @@ -1522,10 +1351,10 @@ static void test4_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1534,17 +1363,17 @@ static void test4_func(abts_case *tc, void *data) * Send Service request Using InitialUEMessage * - PDU Session Status */ - test_ue.service_request_param.integrity_protected = 0; - test_ue.service_request_param.pdu_session_status = 1; - nasbuf = testgmm_build_service_request(&test_ue, NULL); + test_ue->service_request_param.integrity_protected = 0; + test_ue->service_request_param.pdu_session_status = 1; + nasbuf = testgmm_build_service_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - test_ue.service_request_param.integrity_protected = 1; - test_ue.service_request_param.pdu_session_status = 0; - gmmbuf = testgmm_build_service_request(&test_ue, nasbuf); + test_ue->service_request_param.integrity_protected = 1; + test_ue->service_request_param.pdu_session_status = 0; + gmmbuf = testgmm_build_service_request(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1552,27 +1381,27 @@ static void test4_func(abts_case *tc, void *data) /* Receive Service accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_status); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_status); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1580,18 +1409,18 @@ static void test4_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -1604,23 +1433,23 @@ static void test4_func(abts_case *tc, void *data) * - Uplink Data Status * - PDU Session Status */ - test_ue.service_request_param.integrity_protected = 0; - test_ue.service_request_param.uplink_data_status = 1; - test_ue.service_request_param.psimask.uplink_data_status = - 1 << test_sess.psi; - test_ue.service_request_param.pdu_session_status = 1; - test_ue.service_request_param.psimask.pdu_session_status = - 1 << test_sess.psi; - nasbuf = testgmm_build_service_request(&test_ue, NULL); + test_ue->service_request_param.integrity_protected = 0; + test_ue->service_request_param.uplink_data_status = 1; + test_ue->service_request_param.psimask.uplink_data_status = + 1 << sess->psi; + test_ue->service_request_param.pdu_session_status = 1; + test_ue->service_request_param.psimask.pdu_session_status = + 1 << sess->psi; + nasbuf = testgmm_build_service_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - test_ue.service_request_param.integrity_protected = 1; - test_ue.service_request_param.uplink_data_status = 0; - test_ue.service_request_param.pdu_session_status = 0; - gmmbuf = testgmm_build_service_request(&test_ue, nasbuf); + test_ue->service_request_param.integrity_protected = 1; + test_ue->service_request_param.uplink_data_status = 0; + test_ue->service_request_param.pdu_session_status = 0; + gmmbuf = testgmm_build_service_request(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1628,21 +1457,19 @@ static void test4_func(abts_case *tc, void *data) /* Receive Service accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x2000, test_ue.pdu_session_status); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_reactivation_result); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x2000, test_ue->pdu_session_status); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ sendbuf = testngap_build_initial_context_setup_response( - &test_ue, NULL); + test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -1655,15 +1482,15 @@ static void test4_func(abts_case *tc, void *data) * Send Service request Using UplinkNASTransport * - Uplink Data Status */ - test_ue.service_request_param.integrity_protected = 1; - test_ue.service_request_param.ciphered = 1; - test_ue.service_request_param.uplink_data_status = 1; - test_ue.service_request_param.psimask.uplink_data_status = - 1 << test_sess.psi; - gmmbuf = testgmm_build_service_request(&test_ue, NULL); + test_ue->service_request_param.integrity_protected = 1; + test_ue->service_request_param.ciphered = 1; + test_ue->service_request_param.uplink_data_status = 1; + test_ue->service_request_param.psimask.uplink_data_status = + 1 << sess->psi; + gmmbuf = testgmm_build_service_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1671,17 +1498,17 @@ static void test4_func(abts_case *tc, void *data) /* Receive Service accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_reactivation_result); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); } /* Send UE context release request */ - ran_ue_ngap_id = test_ue.ran_ue_ngap_id; - amf_ue_ngap_id = test_ue.amf_ue_ngap_id; + ran_ue_ngap_id = test_ue->ran_ue_ngap_id; + amf_ue_ngap_id = test_ue->amf_ue_ngap_id; - test_ue.ran_ue_ngap_id = 2; - test_ue.amf_ue_ngap_id = 2; - sendbuf = testngap_build_ue_context_release_request(&test_ue, + test_ue->ran_ue_ngap_id = 2; + test_ue->amf_ue_ngap_id = 2; + sendbuf = testngap_build_ue_context_release_request(test_ue, NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_user_inactivity, false); ABTS_PTR_NOTNULL(tc, sendbuf); @@ -1691,25 +1518,25 @@ static void test4_func(abts_case *tc, void *data) /* Error Indication */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); - test_ue.ran_ue_ngap_id = ran_ue_ngap_id; - test_ue.amf_ue_ngap_id = amf_ue_ngap_id; + test_ue->ran_ue_ngap_id = ran_ue_ngap_id; + test_ue->amf_ue_ngap_id = amf_ue_ngap_id; for (i = 0; i < 200; i++) { /* * Send Service request Using UplinkNASTransport * - Uplink Data Status */ - test_ue.service_request_param.integrity_protected = 1; - test_ue.service_request_param.ciphered = 1; - test_ue.service_request_param.uplink_data_status = 1; - test_ue.service_request_param.psimask.uplink_data_status = - 1 << test_sess.psi; - gmmbuf = testgmm_build_service_request(&test_ue, NULL); + test_ue->service_request_param.integrity_protected = 1; + test_ue->service_request_param.ciphered = 1; + test_ue->service_request_param.uplink_data_status = 1; + test_ue->service_request_param.psimask.uplink_data_status = + 1 << sess->psi; + gmmbuf = testgmm_build_service_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1717,14 +1544,14 @@ static void test4_func(abts_case *tc, void *data) /* Receive Service accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_reactivation_result); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); } /* Send De-registration request */ - gmmbuf = testgmm_build_de_registration_request(&test_ue, 1); + gmmbuf = testgmm_build_de_registration_request(test_ue, 1); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1732,16 +1559,16 @@ static void test4_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -1756,7 +1583,7 @@ static void test4_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } static void test5_func(abts_case *tc, void *data) @@ -1771,13 +1598,11 @@ static void test5_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -1829,21 +1654,10 @@ static void test5_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -1856,52 +1670,27 @@ static void test5_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 3; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -1913,13 +1702,13 @@ static void test5_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -1936,7 +1725,7 @@ static void test5_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -1945,17 +1734,17 @@ static void test5_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1963,12 +1752,12 @@ static void test5_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1976,12 +1765,12 @@ static void test5_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1989,24 +1778,24 @@ static void test5_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE radio capability info indication */ - sendbuf = testngap_build_ue_radio_capability_info_indication(&test_ue); + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Registration complete */ - gmmbuf = testgmm_build_registration_complete(&test_ue); + gmmbuf = testgmm_build_registration_complete(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -2014,20 +1803,20 @@ static void test5_func(abts_case *tc, void *data) /* Receive Configuration update command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; - test_sess.ul_nas_transport_param.s_nssai = 1; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -2035,16 +1824,16 @@ static void test5_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -2055,9 +1844,7 @@ static void test5_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -2066,7 +1853,7 @@ static void test5_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send UE context release request */ - sendbuf = testngap_build_ue_context_release_request(&test_ue, + sendbuf = testngap_build_ue_context_release_request(test_ue, NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_user_inactivity, true); ABTS_PTR_NOTNULL(tc, sendbuf); @@ -2076,10 +1863,10 @@ static void test5_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -2088,17 +1875,17 @@ static void test5_func(abts_case *tc, void *data) * Send Service request Using InitialUEMessage * - PDU Session Status */ - test_ue.service_request_param.integrity_protected = 0; - test_ue.service_request_param.pdu_session_status = 1; - nasbuf = testgmm_build_service_request(&test_ue, NULL); + test_ue->service_request_param.integrity_protected = 0; + test_ue->service_request_param.pdu_session_status = 1; + nasbuf = testgmm_build_service_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - test_ue.service_request_param.integrity_protected = 1; - test_ue.service_request_param.pdu_session_status = 0; - gmmbuf = testgmm_build_service_request(&test_ue, nasbuf); + test_ue->service_request_param.integrity_protected = 1; + test_ue->service_request_param.pdu_session_status = 0; + gmmbuf = testgmm_build_service_request(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, true); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -2106,27 +1893,27 @@ static void test5_func(abts_case *tc, void *data) /* Receive Service accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_status); - ABTS_INT_EQUAL(tc, 0x0000, test_ue.pdu_session_reactivation_result); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_status); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(&test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session establishment request */ - test_sess.ul_nas_transport_param.request_type = + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; - test_sess.ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.dnn = 1; - gsmbuf = testgsm_build_pdu_session_establishment_request(&test_sess); + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); ABTS_PTR_NOTNULL(tc, gsmbuf); - gmmbuf = testgmm_build_ul_nas_transport(&test_sess, + gmmbuf = testgmm_build_ul_nas_transport(sess, OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -2134,16 +1921,14 @@ static void test5_func(abts_case *tc, void *data) /* Receive PDU session establishment accept */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session resource setup response */ - sendbuf = testngap_build_pdu_session_resource_setup_response(&test_sess); + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -2154,9 +1939,7 @@ static void test5_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - rv = test_gtpu_build_ping(&sendbuf, &test_sess, "10.45.0.1"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testgnb_gtpu_send(gtpu, sendbuf); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Receive GTP-U ICMP Packet */ @@ -2165,7 +1948,7 @@ static void test5_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -2180,7 +1963,398 @@ static void test5_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); +} + +static void test6_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *ngap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *gmmbuf; + ogs_pkbuf_t *gsmbuf; + ogs_pkbuf_t *nasbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_ngap_message_t message; + int i; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; + + const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "6f1bf53d624b3a43af6592854e2444c7"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " + "\"imsi\" : \"901700000021309\"," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 8," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"security\" : { " + "\"k\" : \"70d49a71dd1a2b806a25abe0ef749f1e\", " + "\"opc\" : \"6f1bf53d624b3a43af6592854e2444c7\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"25235952177090\" } " + "}, " + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0; + mobile_identity_suci.scheme_output[1] = 0; + mobile_identity_suci.scheme_output[2] = 0x20; + mobile_identity_suci.scheme_output[3] = 0x31; + mobile_identity_suci.scheme_output[4] = 0x90; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->nr_cgi.cell_id = 0x40001; + + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + + /* gNB connects to AMF */ + ngap = testngap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, ngap); + + /* gNB connects to UPF */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send NG-Setup Reqeust */ + sendbuf = testngap_build_ng_setup_request(0x4000, 23); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive NG-Setup Response */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + /* To start RAN-UE-NGAP-ID : 0 */ + test_ue->ran_ue_ngap_id = -1; + test_self()->nr_cgi.cell_id = 0x000000ce7; + + /* Send Registration request */ + test_ue->registration_request_param.guti = 1; + test_ue->registration_request_param.gmm_capability = 1; + gmmbuf = testgmm_build_registration_request(test_ue, NULL); + ABTS_PTR_NOTNULL(tc, gmmbuf); + + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); + ABTS_PTR_NOTNULL(tc, nasbuf); + + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Indentity request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send Identity response */ + gmmbuf = testgmm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send Authentication failure - SYNCH failure */ + gmmbuf = testgmm_build_authentication_failure( + test_ue, OGS_5GMM_CAUSE_SYNCH_FAILURE, 0x1f60); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + gmmbuf = testgmm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial context setup request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send UE radio capability info indication */ + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Registration complete */ + gmmbuf = testgmm_build_registration_complete(test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Configuration update command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send PDU session establishment request */ + sess->ul_nas_transport_param.request_type = + OGS_NAS_5GS_REQUEST_TYPE_INITIAL; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; + + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDU session establishment accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send GTP-U ICMP Packet */ + qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send PDU session resource setup response */ + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send UE context release request */ + sendbuf = testngap_build_ue_context_release_request(test_ue, + NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_user_inactivity, + true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE context release command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send UE context release complete */ + sendbuf = testngap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* + * Send Service request Using InitialUEMessage + * - Uplink Data Status + */ + test_ue->service_request_param.integrity_protected = 0; + test_ue->service_request_param.uplink_data_status = 1; + test_ue->service_request_param. + psimask.uplink_data_status = 1 << sess->psi; + test_ue->service_request_param.pdu_session_status = 0; + nasbuf = testgmm_build_service_request(test_ue, NULL); + ABTS_PTR_NOTNULL(tc, nasbuf); + + test_ue->service_request_param.integrity_protected = 1; + test_ue->service_request_param.uplink_data_status = 0; + test_ue->service_request_param.pdu_session_status = 0; + gmmbuf = testgmm_build_service_request(test_ue, nasbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Service accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_status); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response( + test_ue, sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* gNB disonncect from UPF */ + testgnb_gtpu_close(gtpu); + + /* gNB disonncect from AMF */ + testgnb_ngap_close(ngap); + + /* Clear Test UE Context */ + test_ue_remove(test_ue); } abts_suite *test_idle(abts_suite *suite) @@ -2192,6 +2366,7 @@ abts_suite *test_idle(abts_suite *suite) abts_run_test(suite, test3_func, NULL); abts_run_test(suite, test4_func, NULL); abts_run_test(suite, test5_func, NULL); + abts_run_test(suite, test6_func, NULL); return suite; } diff --git a/tests/registration/meson.build b/tests/registration/meson.build index 571182577..50252ac48 100644 --- a/tests/registration/meson.build +++ b/tests/registration/meson.build @@ -30,3 +30,8 @@ test5gc_registration_exe = executable('registration', sources : test5gc_registration_sources, c_args : testunit_core_cc_flags, dependencies : libtest5gc_dep) + +test('registration', + test5gc_registration_exe, + is_parallel : false, + suite: '5gc') diff --git a/tests/registration/ue-context-test.c b/tests/registration/ue-context-test.c index 6c749d09d..f23c3f532 100644 --- a/tests/registration/ue-context-test.c +++ b/tests/registration/ue-context-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-5gc.h" +#include "test-common.h" static void test1_func(abts_case *tc, void *data) { @@ -31,13 +31,11 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_t *recvbuf; ogs_ngap_message_t message; int i; - int msgindex = 0; ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; - test_ue_t test_ue; - test_sess_t test_sess; - - uint8_t tmp[OGS_MAX_SDU_LEN]; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; uint8_t k[OGS_KEY_LEN]; @@ -89,21 +87,10 @@ static void test1_func(abts_case *tc, void *data) "}"; /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; - test_ue.nas.registration.follow_on_request = 1; - test_ue.nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; - ogs_nas_from_plmn_id(&mobile_identity_suci.nas_plmn_id, - &test_self()->tai.plmn_id); mobile_identity_suci.routing_indicator1 = 0; mobile_identity_suci.routing_indicator2 = 0xf; mobile_identity_suci.routing_indicator3 = 0xf; @@ -116,52 +103,27 @@ static void test1_func(abts_case *tc, void *data) mobile_identity_suci.scheme_output[3] = 0x31; mobile_identity_suci.scheme_output[4] = 0x90; - test_ue_set_mobile_identity_suci(&test_ue, &mobile_identity_suci, 13); + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); - memset(&test_ue.mobile_identity_imeisv, 0, - sizeof(ogs_nas_mobile_identity_imeisv_t)); - test_ue.mobile_identity_imeisv.type = OGS_NAS_5GS_MOBILE_IDENTITY_IMEISV; - test_ue.mobile_identity_imeisv.odd_even = OGS_NAS_MOBILE_IDENTITY_EVEN; - test_ue.mobile_identity_imeisv.digit1 = 8; - test_ue.mobile_identity_imeisv.digit2 = 6; - test_ue.mobile_identity_imeisv.digit3 = 6; - test_ue.mobile_identity_imeisv.digit4 = 5; - test_ue.mobile_identity_imeisv.digit5 = 0; - test_ue.mobile_identity_imeisv.digit6 = 7; - test_ue.mobile_identity_imeisv.digit7 = 0; - test_ue.mobile_identity_imeisv.digit8 = 4; - test_ue.mobile_identity_imeisv.digit9 = 0; - test_ue.mobile_identity_imeisv.digit10 = 0; - test_ue.mobile_identity_imeisv.digit11 = 4; - test_ue.mobile_identity_imeisv.digit12 = 0; - test_ue.mobile_identity_imeisv.digit13 = 5; - test_ue.mobile_identity_imeisv.digit14 = 3; - test_ue.mobile_identity_imeisv.digit15 = 0; - test_ue.mobile_identity_imeisv.digit16 = 1; - test_ue.mobile_identity_imeisv.digit17 = 0xf; + test_ue->nr_cgi.cell_id = 0x40001; - test_ue.nas.access_type = OGS_ACCESS_TYPE_3GPP; - test_ue.abba_len = 2; + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; - OGS_HEX(_k_string, strlen(_k_string), test_ue.k); - OGS_HEX(_opc_string, strlen(_opc_string), test_ue.opc); + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - test_sess.psi = 5; - test_sess.pti = 1; - test_sess.pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4V6; - test_sess.dnn = (char *)"internet"; - - memset(&test_sess.gnb_n3_ip, 0, sizeof(test_sess.gnb_n3_ip)); - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr("127.0.0.5"); - test_sess.gnb_n3_teid = 0; + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); /* gNB connects to AMF */ - ngap = testgnb_ngap_client("127.0.0.2"); + ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); /* gNB connects to UPF */ - gtpu = testgnb_gtpu_server("127.0.0.5"); + gtpu = test_gtpu_server(1, AF_INET); ABTS_PTR_NOTNULL(tc, gtpu); /* Send NG-Setup Reqeust */ @@ -173,13 +135,13 @@ static void test1_func(abts_case *tc, void *data) /* Receive NG-Setup Response */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /********** Insert Subscriber in Database */ collection = mongoc_client_get_collection( ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); count = mongoc_collection_count ( @@ -196,7 +158,7 @@ static void test1_func(abts_case *tc, void *data) MONGOC_INSERT_NONE, doc, NULL, &error)); bson_destroy(doc); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); do { count = mongoc_collection_count ( @@ -205,17 +167,17 @@ static void test1_func(abts_case *tc, void *data) bson_destroy(doc); /* Send Registration request */ - gmmbuf = testgmm_build_registration_request(&test_ue, NULL); + gmmbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, gmmbuf); - test_ue.registration_request_param.gmm_capability = 1; - test_ue.registration_request_param.requested_nssai = 1; - test_ue.registration_request_param.last_visited_registered_tai = 1; - test_ue.registration_request_param.ue_usage_setting = 1; - nasbuf = testgmm_build_registration_request(&test_ue, NULL); + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); ABTS_PTR_NOTNULL(tc, nasbuf); - sendbuf = testngap_build_initial_ue_message(&test_ue, gmmbuf, false); + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -223,12 +185,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Authentication request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Authentication response */ - gmmbuf = testgmm_build_authentication_response(&test_ue); + gmmbuf = testgmm_build_authentication_response(test_ue); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -236,12 +198,12 @@ static void test1_func(abts_case *tc, void *data) /* Receive Security mode command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Security mode complete */ - gmmbuf = testgmm_build_security_mode_complete(&test_ue, nasbuf); + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); ABTS_PTR_NOTNULL(tc, gmmbuf); - sendbuf = testngap_build_uplink_nas_transport(&test_ue, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -249,10 +211,10 @@ static void test1_func(abts_case *tc, void *data) /* Receive Initial context setup request */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send Initial context setup failure */ - sendbuf = testngap_build_initial_context_setup_failure(&test_ue, + sendbuf = testngap_build_initial_context_setup_failure(test_ue, NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_radio_connection_with_ue_lost); ABTS_PTR_NOTNULL(tc, sendbuf); @@ -261,16 +223,16 @@ static void test1_func(abts_case *tc, void *data) /* Receive UE context release command */ recvbuf = testgnb_ngap_read(ngap); ABTS_PTR_NOTNULL(tc, recvbuf); - testngap_recv(&test_ue, recvbuf); + testngap_recv(test_ue, recvbuf); /* Send UE context release complete */ - sendbuf = testngap_build_ue_context_release_complete(&test_ue); + sendbuf = testngap_build_ue_context_release_complete(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); ABTS_PTR_NOTNULL(tc, doc); ABTS_TRUE(tc, mongoc_collection_remove(collection, MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) @@ -285,7 +247,7 @@ static void test1_func(abts_case *tc, void *data) testgnb_ngap_close(ngap); /* Clear Test UE Context */ - test_ue_remove(&test_ue); + test_ue_remove(test_ue); } abts_suite *test_ue_context(abts_suite *suite) diff --git a/tests/sctp/meson.build b/tests/sctp/meson.build index 3789b8596..a7963df15 100644 --- a/tests/sctp/meson.build +++ b/tests/sctp/meson.build @@ -25,4 +25,4 @@ testsystem_sctp_exe = executable('sctp', c_args : testunit_core_cc_flags, dependencies : libsctp_dep) -test('sctp', testsystem_sctp_exe, is_parallel : false, suite: 'system') +test('sctp', testsystem_sctp_exe, is_parallel : false, suite: 'app') diff --git a/tests/unit/abts-main.c b/tests/unit/abts-main.c index 42e01749d..ef1f7e5ef 100644 --- a/tests/unit/abts-main.c +++ b/tests/unit/abts-main.c @@ -17,7 +17,8 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-app.h" +#include "mme/mme-context.h" abts_suite *test_s1ap_message(abts_suite *suite); abts_suite *test_nas_message(abts_suite *suite); diff --git a/tests/unit/crash-test.c b/tests/unit/crash-test.c index b6d176e44..4fed04299 100644 --- a/tests/unit/crash-test.c +++ b/tests/unit/crash-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-packet.h" +#include "test-common.h" static void test1_func(abts_case *tc, void *data) { diff --git a/tests/unit/gtp-message-test.c b/tests/unit/gtp-message-test.c index ea63223de..82fd1a1cb 100644 --- a/tests/unit/gtp-message-test.c +++ b/tests/unit/gtp-message-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-common.h" static void gtp_message_test1(abts_case *tc, void *data) { diff --git a/tests/unit/s1ap-message-test.c b/tests/unit/s1ap-message-test.c index d164df8e5..b120074c2 100644 --- a/tests/unit/s1ap-message-test.c +++ b/tests/unit/s1ap-message-test.c @@ -2,8 +2,6 @@ #include "mme/s1ap-build.h" -#include "test-packet.h" - static void s1ap_message_test1(abts_case *tc, void *data) { /* S1SetupRequest */ @@ -112,13 +110,14 @@ static void s1ap_message_test4(abts_case *tc, void *data) static void s1ap_message_test5(abts_case *tc, void *data) { +#if 0 ogs_s1ap_message_t message; int rv; ogs_pkbuf_t *pkbuf; int result; - rv = tests1ap_build_setup_req(&pkbuf, S1AP_ENB_ID_PR_macroENB_ID, - 0x54f64, 12345, 1, 1, 2); + pkbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); ABTS_INT_EQUAL(tc, OGS_OK, rv); ABTS_PTR_NOTNULL(tc, pkbuf); @@ -130,6 +129,7 @@ static void s1ap_message_test5(abts_case *tc, void *data) ogs_s1ap_free(&message); ogs_pkbuf_free(pkbuf); +#endif } static void s1ap_message_test6(abts_case *tc, void *data) diff --git a/tests/unit/sbi-message-test.c b/tests/unit/sbi-message-test.c index 002970b9d..98025819f 100644 --- a/tests/unit/sbi-message-test.c +++ b/tests/unit/sbi-message-test.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "test-epc.h" +#include "test-common.h" #include "ogs-sbi.h" diff --git a/tests/unit/security-test.c b/tests/unit/security-test.c index 17e7742ca..231df0e96 100644 --- a/tests/unit/security-test.c +++ b/tests/unit/security-test.c @@ -19,7 +19,6 @@ #include "ogs-crypt.h" -#include "hss/hss-auc.h" #include "mme/nas-security.h" #include "core/abts.h" @@ -114,7 +113,7 @@ static void security_test3(abts_case *tc, void *data) uint8_t kasme[32]; uint8_t tmp[32]; - hss_auc_kasme( + ogs_auc_kasme( OGS_HEX(_ck, strlen(_ck), ck), OGS_HEX(_ik, strlen(_ik), ik), OGS_HEX(_plmn_id, strlen(_plmn_id), plmn_id), diff --git a/tests/volte/abts-main.c b/tests/volte/abts-main.c index 679337759..427037da0 100644 --- a/tests/volte/abts-main.c +++ b/tests/volte/abts-main.c @@ -21,12 +21,16 @@ #include "pcscf-fd-path.h" -abts_suite *test_volte(abts_suite *suite); +abts_suite *test_bearer(abts_suite *suite); +abts_suite *test_session(abts_suite *suite); +abts_suite *test_rx(abts_suite *suite); const struct testlist { abts_suite *(*func)(abts_suite *suite); } alltests[] = { - {test_volte}, + {test_bearer}, + {test_session}, + {test_rx}, {NULL}, }; @@ -39,7 +43,7 @@ static void terminate(void) pcscf_fd_final(); - test_app_final(); + test_epc_final(); ogs_app_terminate(); } @@ -49,7 +53,7 @@ static void initialize(const char *const argv[]) rv = ogs_app_initialize(NULL, argv); ogs_assert(rv == OGS_OK); - test_app_init(); + test_epc_init(); rv = app_initialize(argv); ogs_assert(rv == OGS_OK); @@ -72,7 +76,7 @@ int main(int argc, const char *const argv[]) abts_suite *suite = NULL; atexit(terminate); - test_5gc_run(argc, argv, "volte.yaml", initialize); + test_app_run(argc, argv, "volte.yaml", initialize); for (i = 0; alltests[i].func; i++) suite = alltests[i].func(suite); diff --git a/tests/volte/bearer-test.c b/tests/volte/bearer-test.c new file mode 100644 index 000000000..d29a73c69 --- /dev/null +++ b/tests/volte/bearer-test.c @@ -0,0 +1,367 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"001010123456819\", " + "\"pdn\" : [" + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"apn\" : \"internet\", " + "\"pcc_rule\" : [" + "{" + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," + "\"qos\" : {" + "\"qci\" : 1," + "\"gbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"mbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"arp\" : {" + "\"priority_level\" : 3," + "\"pre_emption_vulnerability\" : 0," + "\"pre_emption_capability\" : 0 }" + "}," + "\"flow\" : [" + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } }" + "]" + "}" + "]," + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 15," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x10; + mobile_identity_suci.scheme_output[1] = 0x32; + mobile_identity_suci.scheme_output[2] = 0x54; + mobile_identity_suci.scheme_output[3] = 0x86; + mobile_identity_suci.scheme_output[4] = 0x91; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x1079baf; + test_ue->nas.ksi = 0; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* eNB connects to MME */ + s1ap = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap); + + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send S1-Setup Reqeust */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Setup Response */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + sess->esm_information_param.pco = 1; + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive E-RAB Setup Request + + * Activate dedicated EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Setup Response */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + sendbuf = test_s1ap_build_e_rab_setup_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Activate dedicated EPS bearer context accept */ + esmbuf = testesm_build_activate_dedicated_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(100); + + /* Send GTP-U ICMP Packet */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + rv = test_gtpu_send_ping(gtpu, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from MME */ + testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} + +abts_suite *test_bearer(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/volte/meson.build b/tests/volte/meson.build index 7eb2a2557..11c497173 100644 --- a/tests/volte/meson.build +++ b/tests/volte/meson.build @@ -20,13 +20,15 @@ testapp_volte_sources = files(''' pcscf-fd-path.c abts-main.c - volte-test.c + bearer-test.c + session-test.c + rx-test.c '''.split()) testapp_volte_exe = executable('volte', sources : testapp_volte_sources, c_args : [testunit_core_cc_flags, '-DFD_EXT_DIR="@0@"'.format(freediameter_extensions_builddir)], - dependencies : libtestapp_dep) + dependencies : libtestepc_dep) -test('volte', testapp_volte_exe, is_parallel : false, suite: 'app') +test('volte', testapp_volte_exe, is_parallel : false, suite: 'epc') diff --git a/tests/volte/pcscf-fd-path.c b/tests/volte/pcscf-fd-path.c index 02f6103fa..a15f84fdb 100644 --- a/tests/volte/pcscf-fd-path.c +++ b/tests/volte/pcscf-fd-path.c @@ -851,8 +851,8 @@ void pcscf_diam_config(void) { memset(&diam_config, 0, sizeof(ogs_diam_config_t)); - diam_config.cnf_diamid = "pcscf.open-ims.test"; - diam_config.cnf_diamrlm = "open-ims.test"; + diam_config.cnf_diamid = "pcscf.localdomain"; + diam_config.cnf_diamrlm = "localdomain"; diam_config.cnf_port = DIAMETER_PORT; diam_config.cnf_port_tls = DIAMETER_SECURE_PORT; diam_config.cnf_flags.no_sctp = 1; @@ -881,8 +881,8 @@ void pcscf_diam_config(void) FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_dcca_3gpp.fdx"; diam_config.num_of_ext++; - diam_config.conn[diam_config.num_of_conn].identity = "pcrf.open-ims.test"; - diam_config.conn[diam_config.num_of_conn].addr = "127.0.0.5"; + diam_config.conn[diam_config.num_of_conn].identity = "pcrf.localdomain"; + diam_config.conn[diam_config.num_of_conn].addr = "127.0.0.9"; diam_config.num_of_conn++; } diff --git a/tests/volte/rx-test.c b/tests/volte/rx-test.c new file mode 100644 index 000000000..9d0ea466b --- /dev/null +++ b/tests/volte/rx-test.c @@ -0,0 +1,1064 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" +#include "pcscf-fd-path.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + char *ipstr = NULL; + uint8_t *rx_sid = NULL; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"001010123456819\", " + "\"pdn\" : [" + "{" + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," + "\"apn\" : \"internet\"," + "\"qos\" : {" + "\"qci\" : 9," + "\"arp\" : {" + "\"priority_level\" : 8," + "\"pre_emption_vulnerability\" : 1," + "\"pre_emption_capability\" : 1" + "}" + "}," + "\"type\" : 2" + "}," + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"apn\" : \"ims\", " + "\"pcc_rule\" : [" + "{" + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," + "\"qos\" : {" + "\"qci\" : 1," + "\"gbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"mbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"arp\" : {" + "\"priority_level\" : 3," + "\"pre_emption_vulnerability\" : 0," + "\"pre_emption_capability\" : 0 }" + "}" + "}" + "]," + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 6, " + "\"arp\" : { " + "\"priority_level\" : 6," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x10; + mobile_identity_suci.scheme_output[1] = 0x32; + mobile_identity_suci.scheme_output[2] = 0x54; + mobile_identity_suci.scheme_output[3] = 0x86; + mobile_identity_suci.scheme_output[4] = 0x91; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x1079baf; + test_ue->nas.ksi = 0; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* eNB connects to MME */ + s1ap = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap); + + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send S1-Setup Reqeust */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Setup Response */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + sess->esm_information_param.pco = 1; + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send PDN Connectivity Request */ + sess = test_sess_add_by_apn(test_ue, "ims"); + ogs_assert(sess); + sess->pti = 5; + + sess->pdn_connectivity_param.integrity_protected = 1; + sess->pdn_connectivity_param.ciphered = 1; + sess->pdn_connectivity_param.apn = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive E-RAB Setup Request + + * Activate default EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Setup Response */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + sendbuf = test_s1ap_build_e_rab_setup_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Activate default EPS bearer context accept */ + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, true); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send AA-Request */ + ogs_assert(sess->ue_ip.ipv4); + ipstr = ogs_ipv4_to_string(sess->ue_ip.addr); + ogs_assert(ipstr); + pcscf_rx_send_aar(&rx_sid, ipstr, 1, 1); + ogs_free(ipstr); + + /* Receive E-RAB Setup Request + + * Activate dedicated EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Setup Response */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 7); + ogs_assert(bearer); + sendbuf = test_s1ap_build_e_rab_setup_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Activate dedicated EPS bearer context accept */ + esmbuf = testesm_build_activate_dedicated_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* DELAY is needed in dedicated EPS bearer */ + ogs_msleep(100); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send AA-Request without Flow */ + pcscf_rx_send_aar(&rx_sid, ipstr, 2, 1); + + /* Receive E-RAB Modify Request + + * Modify EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Modify Response */ + sendbuf = test_s1ap_build_e_rab_modify_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Modify EPS bearer context accept */ + esmbuf = testesm_build_modify_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Bearer resource allocation request */ + sess->pti = 6; + esmbuf = testesm_build_bearer_resource_allocation_request(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Bearer resource allocation reject */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Bearer resource modification request */ + sess->pti = 7; + esmbuf = testesm_build_bearer_resource_modification_request( + bearer, OGS_GTP_TFT_CODE_NO_TFT_OPERATION, 0, 0); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Bearer resource modification reject */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Bearer resource modification request */ + sess->pti = 8; + esmbuf = testesm_build_bearer_resource_modification_request( + bearer, OGS_GTP_TFT_CODE_ADD_PACKET_FILTERS_TO_EXISTING_TFT, 1, 0); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive E-RAB Modify Request + + * Modify EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Modify EPS bearer context accept */ + esmbuf = testesm_build_modify_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send E-RAB Modify Response */ + sendbuf = test_s1ap_build_e_rab_modify_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Bearer resource modification request */ + sess->pti = 9; + esmbuf = testesm_build_bearer_resource_modification_request( + bearer, OGS_GTP_TFT_CODE_REPLACE_PACKET_FILTERS_IN_EXISTING, 0, 0); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive E-RAB Modify Request + + * Modify EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Modify Response */ + sendbuf = test_s1ap_build_e_rab_modify_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Modify EPS bearer context accept */ + esmbuf = testesm_build_modify_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Bearer resource modification request */ + sess->pti = 10; + esmbuf = testesm_build_bearer_resource_modification_request( + bearer, OGS_GTP_TFT_CODE_DELETE_PACKET_FILTERS_FROM_EXISTING, 0, + ESM_CAUSE_REGULAR_DEACTIVATION); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive E-RAB Modify Request + + * Modify EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Modify Response */ + sendbuf = test_s1ap_build_e_rab_modify_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Modify EPS bearer context accept */ + esmbuf = testesm_build_modify_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Session-Termination-Request */ + pcscf_rx_send_str(rx_sid); + + /* Receive E-RAB Release Command + + * Dectivate EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Release Response */ + sendbuf = test_s1ap_build_e_rab_release_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Deactivate EPS bearer context accept */ + esmbuf = testesm_build_deactivate_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Detach Request */ + emmbuf = testemm_build_detach_request(test_ue, 1); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from MME */ + testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} + +static void test2_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + char *ipstr = NULL; + uint8_t *rx_sid = NULL; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"001010123456819\", " + "\"pdn\" : [" + "{" + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," + "\"apn\" : \"internet\"," + "\"qos\" : {" + "\"qci\" : 9," + "\"arp\" : {" + "\"priority_level\" : 8," + "\"pre_emption_vulnerability\" : 1," + "\"pre_emption_capability\" : 1" + "}" + "}," + "\"type\" : 2" + "}," + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"apn\" : \"ims\", " + "\"pcc_rule\" : [" + "{" + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," + "\"qos\" : {" + "\"qci\" : 1," + "\"gbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"mbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"arp\" : {" + "\"priority_level\" : 3," + "\"pre_emption_vulnerability\" : 0," + "\"pre_emption_capability\" : 0 }" + "}," + "\"flow\" : [" + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } }" + "]" + "}" + "]," + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 6, " + "\"arp\" : { " + "\"priority_level\" : 6," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x10; + mobile_identity_suci.scheme_output[1] = 0x32; + mobile_identity_suci.scheme_output[2] = 0x54; + mobile_identity_suci.scheme_output[3] = 0x86; + mobile_identity_suci.scheme_output[4] = 0x91; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x1079baf; + test_ue->nas.ksi = 0; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* eNB connects to MME */ + s1ap = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap); + + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send S1-Setup Reqeust */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Setup Response */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + sess->esm_information_param.pco = 1; + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send PDN Connectivity Request */ + sess = test_sess_add_by_apn(test_ue, "ims"); + ogs_assert(sess); + sess->pti = 5; + + sess->pdn_connectivity_param.integrity_protected = 1; + sess->pdn_connectivity_param.ciphered = 1; + sess->pdn_connectivity_param.apn = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive E-RAB Setup Request + + * Activate default EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Setup Response */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + sendbuf = test_s1ap_build_e_rab_setup_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Activate default EPS bearer context accept */ + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, true); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive E-RAB Setup Request + + * Activate dedicated EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Setup Response */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 7); + ogs_assert(bearer); + sendbuf = test_s1ap_build_e_rab_setup_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Activate dedicated EPS bearer context accept */ + esmbuf = testesm_build_activate_dedicated_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send AA-Request */ + ogs_assert(sess->ue_ip.ipv4); + ipstr = ogs_ipv4_to_string(sess->ue_ip.addr); + ogs_assert(ipstr); + pcscf_rx_send_aar(&rx_sid, ipstr, 0, 1); + ogs_free(ipstr); + + /* Receive downlink NAS transport + + * Modify EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Modify Response */ + sendbuf = test_s1ap_build_e_rab_modify_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Modify EPS bearer context accept */ + esmbuf = testesm_build_modify_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send PDN disconnectivity request */ + sess->pti = 6; + esmbuf = testesm_build_pdn_disconnect_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive E-RAB Release Command + + * Deactivate EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Release Response */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + sendbuf = test_s1ap_build_e_rab_release_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Deactivate EPS bearer context accept */ + esmbuf = testesm_build_deactivate_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from MME */ + testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} + +abts_suite *test_rx(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + abts_run_test(suite, test2_func, NULL); + + return suite; +} diff --git a/tests/volte/session-test.c b/tests/volte/session-test.c new file mode 100644 index 000000000..ed819d68d --- /dev/null +++ b/tests/volte/session-test.c @@ -0,0 +1,484 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *s1ap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *emmbuf; + ogs_pkbuf_t *esmbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_s1ap_message_t message; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *bearer = NULL; + + const char *_k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "e8ed289deba952e4283b54e88e6183ca"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c6\" }, " + "\"imsi\" : \"001010123456819\", " + "\"pdn\" : [" + "{" + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," + "\"apn\" : \"internet\"," + "\"qos\" : {" + "\"qci\" : 9," + "\"arp\" : {" + "\"priority_level\" : 8," + "\"pre_emption_vulnerability\" : 1," + "\"pre_emption_capability\" : 1" + "}" + "}," + "\"type\" : 2" + "}," + "{" + "\"_id\" : { \"$oid\" : \"310014158b8861d7605378c7\" }, " + "\"apn\" : \"ims\", " + "\"pcc_rule\" : [" + "{" + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," + "\"qos\" : {" + "\"qci\" : 1," + "\"gbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"mbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"arp\" : {" + "\"priority_level\" : 3," + "\"pre_emption_vulnerability\" : 0," + "\"pre_emption_capability\" : 0 }" + "}," + "\"flow\" : [" + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } }" + "]" + "}" + "]," + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 6, " + "\"arp\" : { " + "\"priority_level\" : 6," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}" + "]," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1000000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1000000\" } " + "}," + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"security\" : { " + "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\", " + "\"opc\" : \"E8ED289D EBA952E4 283B54E8 8E6183CA\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"64\" } " + "}, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0x10; + mobile_identity_suci.scheme_output[1] = 0x32; + mobile_identity_suci.scheme_output[2] = 0x54; + mobile_identity_suci.scheme_output[3] = 0x86; + mobile_identity_suci.scheme_output[4] = 0x91; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->e_cgi.cell_id = 0x1079baf; + test_ue->nas.ksi = 0; + test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + sess = test_sess_add_by_apn(test_ue, "internet"); + ogs_assert(sess); + + /* eNB connects to MME */ + s1ap = tests1ap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, s1ap); + + /* eNB connects to SGW */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send S1-Setup Reqeust */ + sendbuf = test_s1ap_build_s1_setup_request( + S1AP_ENB_ID_PR_macroENB_ID, 0x54f64); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive S1-Setup Response */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(NULL, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + + /* Send Attach Request */ + memset(&sess->pdn_connectivity_param, + 0, sizeof(sess->pdn_connectivity_param)); + sess->pdn_connectivity_param.eit = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + + memset(&test_ue->attach_request_param, + 0, sizeof(test_ue->attach_request_param)); + test_ue->attach_request_param.integrity_protected = 1; + test_ue->attach_request_param.drx_parameter = 1; + test_ue->attach_request_param.ms_network_capability = 1; + test_ue->attach_request_param.tmsi_status = 1; + test_ue->attach_request_param.mobile_station_classmark_2 = 1; + test_ue->attach_request_param.ue_usage_setting = 1; + emmbuf = testemm_build_attach_request(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + + memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param)); + sendbuf = test_s1ap_build_initial_ue_message( + test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + emmbuf = testemm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + test_ue->mobile_identity_imeisv_presence = true; + emmbuf = testemm_build_security_mode_complete(test_ue); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive ESM Information Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send ESM Information Response */ + sess->esm_information_param.pco = 1; + esmbuf = testesm_build_esm_information_response(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial Context Setup Request + + * Attach Accept + + * Activate Default Bearer Context Request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Capability Info Indication */ + sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial Context Setup Response */ + sendbuf = test_s1ap_build_initial_context_setup_response(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Attach Complete + Activate default EPS bearer cotext accept */ + test_ue->nr_cgi.cell_id = 0x1234502; + bearer = test_bearer_find_by_ue_ebi(test_ue, 5); + ogs_assert(bearer); + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, false); + ABTS_PTR_NOTNULL(tc, esmbuf); + emmbuf = testemm_build_attach_complete(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, emmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive EMM information */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send PDN Connectivity Request */ + sess = test_sess_add_by_apn(test_ue, "ims"); + ogs_assert(sess); + sess->pti = 5; + + sess->pdn_connectivity_param.integrity_protected = 1; + sess->pdn_connectivity_param.ciphered = 1; + sess->pdn_connectivity_param.apn = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive E-RAB Setup Request + + * Activate default EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Setup Response */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + sendbuf = test_s1ap_build_e_rab_setup_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Activate default EPS bearer context accept */ + esmbuf = testesm_build_activate_default_eps_bearer_context_accept( + bearer, true); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive E-RAB Setup Request + + * Activate dedicated EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send Activate dedicated EPS bearer context accept */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 7); + ogs_assert(bearer); + esmbuf = testesm_build_activate_dedicated_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send E-RAB Setup Response */ + sendbuf = test_s1ap_build_e_rab_setup_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* DELAY is needed in dedicated EPS bearer */ + ogs_msleep(100); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, bearer, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = test_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send PDN disconnectivity request */ + sess->pti = 6; + esmbuf = testesm_build_pdn_disconnect_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive E-RAB Release Command + + * Deactivate EPS bearer context request */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send E-RAB Release Response */ + bearer = test_bearer_find_by_ue_ebi(test_ue, 6); + ogs_assert(bearer); + sendbuf = test_s1ap_build_e_rab_release_response(bearer); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Deactivate EPS bearer context accept */ + esmbuf = testesm_build_deactivate_eps_bearer_context_accept(bearer); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send INVALID PDN Connectivity Request */ + sess = test_sess_add_by_apn(test_ue, "ims2"); + ogs_assert(sess); + sess->pti = 9; + + sess->pdn_connectivity_param.integrity_protected = 1; + sess->pdn_connectivity_param.ciphered = 1; + sess->pdn_connectivity_param.apn = 1; + sess->pdn_connectivity_param.pco = 1; + esmbuf = testesm_build_pdn_connectivity_request(sess); + ABTS_PTR_NOTNULL(tc, esmbuf); + sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDN Connectivity Reject */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Receive UE Context Release Command */ + recvbuf = testenb_s1ap_read(s1ap); + ABTS_PTR_NOTNULL(tc, recvbuf); + tests1ap_recv(test_ue, recvbuf); + + /* Send UE Context Release Complete */ + sendbuf = test_s1ap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testenb_s1ap_send(s1ap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* eNB disonncect from MME */ + testenb_s1ap_close(s1ap); + + /* eNB disonncect from SGW */ + test_gtpu_close(gtpu); + + test_ue_remove(test_ue); +} + +abts_suite *test_session(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/volte/volte-test.c b/tests/volte/volte-test.c deleted file mode 100644 index dfc7b0a08..000000000 --- a/tests/volte/volte-test.c +++ /dev/null @@ -1,797 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "test-epc.h" -#include "pcscf-fd-path.h" - -static void volte_test1(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 0; - uint8_t *rx_sid = NULL; - - test_ue_t test_ue; - test_sess_t test_sess; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2b\" }," - "\"imsi\" : \"001010123456819\"," - "\"pdn\" : [" - "{ \"apn\" : \"internet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," - "\"qos\" : {" - "\"qci\" : 9," - "\"arp\" : {" - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }," - "{ \"apn\" : \"internet.ng2.mnet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2c\" }," - "\"pcc_rule\" : [" - "{ \"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," - "\"qos\" : {" - "\"qci\" : 1," - "\"gbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"mbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"arp\" : {" - "\"priority_level\" : 3," - "\"pre_emption_vulnerability\" : 0," - "\"pre_emption_capability\" : 0 } }" - "} ]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"35840\" }," - "\"uplink\" : { \"$numberLong\" : \"15360\" } }," - "\"qos\" : {" - "\"qci\" : 6," - "\"arp\" : {" - "\"priority_level\" : 6," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }" - "]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"1024000\" }," - "\"uplink\" : { \"$numberLong\" : \"1024000\" } }," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2," - "\"subscriber_status\" : 0," - "\"access_restriction_data\" : 32," - "\"security\" : {" - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\"," - "\"op\" : \"5F1D289C 5D354D0A 140C2548 F5F3E3BA\"," - "\"amf\" : \"8000\"," - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"20080C38 18183B52 2614162C 07601D0D\" }, " - "\"__v\" : 0" - "}"; - - /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.imsi = (char *)"001010123456819"; - - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr(TEST_GNB_IPV4); - test_sess.gnb_n3_teid = 0; - - test_sess.upf_n3_ip.ipv4 = true; - test_sess.upf_n3_ip.addr = inet_addr(TEST_SGWU_IPV4); - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client(TEST_MME_IPV4); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - /********** Insert Subscriber in Database */ - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - if (count) { - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - } - bson_destroy(doc); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, No Security Context - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response( - &sendbuf, 1, 1, 5, 1, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send PDN Connectivity Request */ - rv = tests1ap_build_pdn_connectivity_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Setup Request + - * Activate default EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response( - &sendbuf, 1, 1, 6, 2, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Activate default EPS bearer context accept */ - rv = tests1ap_build_activate_default_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send AA-Request */ - ogs_msleep(300); - pcscf_rx_send_aar(&rx_sid, "10.45.0.3", 1, 1); - - /* Receive E-RAB Setup Request + - * Activate dedicated EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response(&sendbuf, 1, 1, 7, 3, "127.0.0.5"); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Activate dedicated EPS bearer context accept */ - rv = tests1ap_build_activate_dedicated_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send AA-Request without Flow */ - ogs_msleep(300); - pcscf_rx_send_aar(&rx_sid, "10.45.0.3", 2, 1); - - /* Receive E-RAB Modify Request + - * Modify EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Modify Response */ - rv = tests1ap_build_e_rab_modify_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Modify EPS bearer context accept */ - rv = tests1ap_build_modify_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(50); - - /* Send Bearer resource allocation request */ - rv = tests1ap_build_bearer_resource_allocation_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Bearer resource allocation reject */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Bearer resource modification request */ - rv = tests1ap_build_bearer_resource_modification_request(&sendbuf, - 1, 1, 3, 0x3f426e62, 7, 7, - OGS_GTP_TFT_CODE_NO_TFT_OPERATION, - 1, 0, 0, 0, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Bearer resource modification reject */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Bearer resource modification request */ - rv = tests1ap_build_bearer_resource_modification_request(&sendbuf, - 1, 1, 4, 0xdc64fbbc, 8, 7, - OGS_GTP_TFT_CODE_ADD_PACKET_FILTERS_TO_EXISTING_TFT, - 1, 44, 55, 22, 33); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Modify Request + - * Modify EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Modify EPS bearer context accept */ - rv = tests1ap_build_modify_bearer_accept(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send E-RAB Modify Response */ - rv = tests1ap_build_e_rab_modify_response(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Bearer resource modification request */ - rv = tests1ap_build_bearer_resource_modification_request(&sendbuf, - 1, 1, 5, 0x87a44610, 9, 7, - OGS_GTP_TFT_CODE_REPLACE_PACKET_FILTERS_IN_EXISTING, - 1, 0, 0, 0, 0); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Modify Request + - * Modify EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Modify Response */ - rv = tests1ap_build_e_rab_modify_response(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Modify EPS bearer context accept */ - rv = tests1ap_build_modify_bearer_accept(&sendbuf, msgindex+2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Bearer resource modification request */ - rv = tests1ap_build_bearer_resource_modification_request2( - &sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Modify Request + - * Modify EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Modify Response */ - rv = tests1ap_build_e_rab_modify_response(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Modify EPS bearer context accept */ - rv = tests1ap_build_modify_bearer_accept(&sendbuf, msgindex+3); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Session-Termination-Request */ - ogs_msleep(50); - pcscf_rx_send_str(rx_sid); - - /* Receive E-RAB Release Command + - * Dectivate EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Release Response */ - rv = tests1ap_build_e_rab_release_response(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(50); - - /* Send Deactivate EPS bearer context accept */ - rv = tests1ap_build_deactivate_bearer_accept(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Detach Request */ - rv = tests1ap_build_detach_request(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive UE Context Release Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Context Release Complete */ - rv = tests1ap_build_ue_context_release_complete(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); -} - -static void volte_test2(abts_case *tc, void *data) -{ - int rv; - ogs_socknode_t *s1ap; - ogs_pkbuf_t *sendbuf; - ogs_pkbuf_t *recvbuf; - ogs_s1ap_message_t message; - int i; - int msgindex = 0; - uint8_t *rx_sid = NULL; - - test_ue_t test_ue; - test_sess_t test_sess; - - mongoc_collection_t *collection = NULL; - bson_t *doc = NULL; - int64_t count = 0; - bson_error_t error; - const char *json = - "{" - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2b\" }," - "\"imsi\" : \"001010123456819\"," - "\"pdn\" : [" - "{ \"apn\" : \"internet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd32\" }," - "\"qos\" : {" - "\"qci\" : 9," - "\"arp\" : {" - "\"priority_level\" : 8," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }," - "{ \"apn\" : \"internet.ng2.mnet\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2c\" }," - "\"pcc_rule\" : [" - "{ \"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," - "\"qos\" : {" - "\"qci\" : 1," - "\"gbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"mbr\" : {" - "\"downlink\" : { \"$numberLong\" : \"64\" }," - "\"uplink\" : { \"$numberLong\" : \"44\" } }," - "\"arp\" : {" - "\"priority_level\" : 3," - "\"pre_emption_vulnerability\" : 0," - "\"pre_emption_capability\" : 0 } }," - "\"flow\" : [" - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23454\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out udp from any 50020 to 10.200.136.98/32 1-65535\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," - "{ \"direction\" : 2," - "\"description\" : \"permit out udp from any 1-65535 to 10.200.136.98/32 23455\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," - "{ \"direction\" : 1," - "\"description\" : \"permit out udp from any 50021 to 10.200.136.98/32 1-65535\"," - "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } } ]" - "} ]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"35840\" }," - "\"uplink\" : { \"$numberLong\" : \"15360\" } }," - "\"qos\" : {" - "\"qci\" : 6," - "\"arp\" : {" - "\"priority_level\" : 6," - "\"pre_emption_vulnerability\" : 1," - "\"pre_emption_capability\" : 1 } }," - "\"type\" : 2 }" - "]," - "\"ambr\" : {" - "\"downlink\" : { \"$numberLong\" : \"1024000\" }," - "\"uplink\" : { \"$numberLong\" : \"1024000\" } }," - "\"subscribed_rau_tau_timer\" : 12," - "\"network_access_mode\" : 2," - "\"subscriber_status\" : 0," - "\"access_restriction_data\" : 32," - "\"security\" : {" - "\"k\" : \"465B5CE8 B199B49F AA5F0A2E E238A6BC\"," - "\"op\" : \"5F1D289C 5D354D0A 140C2548 F5F3E3BA\"," - "\"amf\" : \"8000\"," - "\"sqn\" : { \"$numberLong\" : \"64\" }, " - "\"rand\" : \"20080C38 18183B52 2614162C 07601D0D\" }, " - "\"__v\" : 0" - "}"; - - /* Setup Test UE & Session Context */ - memset(&test_ue, 0, sizeof(test_ue)); - memset(&test_sess, 0, sizeof(test_sess)); - test_sess.test_ue = &test_ue; - test_ue.sess = &test_sess; - - test_ue.imsi = (char *)"001010123456819"; - - test_sess.gnb_n3_ip.ipv4 = true; - test_sess.gnb_n3_ip.addr = inet_addr(TEST_GNB_IPV4); - test_sess.gnb_n3_teid = 0; - - test_sess.upf_n3_ip.ipv4 = true; - test_sess.upf_n3_ip.addr = inet_addr(TEST_SGWU_IPV4); - - /* eNB connects to MME */ - s1ap = testenb_s1ap_client(TEST_MME_IPV4); - ABTS_PTR_NOTNULL(tc, s1ap); - - /* Send S1-Setup Reqeust */ - rv = tests1ap_build_setup_req( - &sendbuf, S1AP_ENB_ID_PR_macroENB_ID, 0x54f64, 12345, 1, 1, 2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive S1-Setup Response */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - rv = ogs_s1ap_decode(&message, recvbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - ogs_s1ap_free(&message); - ogs_pkbuf_free(recvbuf); - - /********** Insert Subscriber in Database */ - collection = mongoc_client_get_collection( - ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); - ABTS_PTR_NOTNULL(tc, collection); - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - if (count) { - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - } - bson_destroy(doc); - - doc = bson_new_from_json((const uint8_t *)json, -1, &error);; - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_insert(collection, - MONGOC_INSERT_NONE, doc, NULL, &error)); - bson_destroy(doc); - - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - do { - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); - } while (count == 0); - bson_destroy(doc); - - /*********************************************************************** - * Attach Request : Known IMSI, Integrity Protected, No Security Context - * Send Initial-UE Message + Attach Request + PDN Connectivity */ - rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Authentication Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Authentication Response */ - rv = tests1ap_build_authentication_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Security mode Command */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Security mode Complete */ - rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive ESM Information Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send ESM Information Response */ - rv = tests1ap_build_esm_information_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive Initial Context Setup Request + - * Attach Accept + - * Activate Default Bearer Context Request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send UE Capability Info Indication */ - rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Initial Context Setup Response */ - rv = tests1ap_build_initial_context_setup_response( - &sendbuf, 1, 1, 5, 1, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Attach Complete + Activate default EPS bearer cotext accept */ - rv = tests1ap_build_attach_complete(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive EMM information */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send PDN Connectivity Request */ - rv = tests1ap_build_pdn_connectivity_request(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Setup Request + - * Activate default EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response( - &sendbuf, 1, 1, 6, 2, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Activate default EPS bearer context accept */ - rv = tests1ap_build_activate_default_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Setup Request + - * Activate dedicated EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Activate dedicated EPS bearer context accept */ - rv = tests1ap_build_activate_dedicated_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send E-RAB Setup Response */ - rv = tests1ap_build_e_rab_setup_response( - &sendbuf, 1, 1, 7, 3, TEST_ENB_IPV4); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send AA-Request */ - ogs_msleep(300); - pcscf_rx_send_aar(&rx_sid, "10.45.0.5", 0, 1); - - /* Receive downlink NAS transport + - * Modify EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send Modify EPS bearer context accept */ - rv = tests1ap_build_modify_bearer_accept(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send PDN disconnectivity request */ - rv = tests1ap_build_pdn_disconnectivity_request(&sendbuf, msgindex+1); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Receive E-RAB Release Command + - * Deactivate EPS bearer context request */ - recvbuf = testenb_s1ap_read(s1ap); - ABTS_PTR_NOTNULL(tc, recvbuf); - ogs_pkbuf_free(recvbuf); - - /* Send E-RAB Release Response */ - rv = tests1ap_build_e_rab_release_response(&sendbuf, msgindex); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - /* Send Deactivate EPS bearer context accept */ - rv = tests1ap_build_deactivate_bearer_accept(&sendbuf, msgindex+2); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - rv = testenb_s1ap_send(s1ap, sendbuf); - ABTS_INT_EQUAL(tc, OGS_OK, rv); - - ogs_msleep(300); - - /********** Remove Subscriber in Database */ - doc = BCON_NEW("imsi", BCON_UTF8(test_ue.imsi)); - ABTS_PTR_NOTNULL(tc, doc); - ABTS_TRUE(tc, mongoc_collection_remove(collection, - MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) - bson_destroy(doc); - - mongoc_collection_destroy(collection); - - /* eNB disonncect from MME */ - testenb_s1ap_close(s1ap); -} - -abts_suite *test_volte(abts_suite *suite) -{ - suite = ADD_SUITE(suite) - - abts_run_test(suite, volte_test1, NULL); - abts_run_test(suite, volte_test2, NULL); - - return suite; -} diff --git a/webui/package-lock.json b/webui/package-lock.json index 0c87c8df0..02b927308 100644 --- a/webui/package-lock.json +++ b/webui/package-lock.json @@ -1,6 +1,6 @@ { "name": "open5gs", - "version": "1.3.0", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/webui/package.json b/webui/package.json index 6c1b3cac8..2c3637fd2 100644 --- a/webui/package.json +++ b/webui/package.json @@ -1,6 +1,6 @@ { "name": "open5gs", - "version": "1.3.0", + "version": "2.0.0", "description": "Open5gs", "main": "index.js", "repository": "https://github.com/open5gs/open5gs/webui",