lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

June 2022

  • 3 participants
  • 1374 discussions
Change in osmo-upf[master]: install libosmo-gtlv, libosmo-pfcp
by pespin 08 Jun '22

08 Jun '22
Attention is currently required from: neels. pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-upf/+/28245 ) Change subject: install libosmo-gtlv, libosmo-pfcp ...................................................................... Patch Set 1: (1 comment) Patchset: PS1: I'm not really sure we should be installing those shared objects from within osmo-upf.git. Looks like those should be moved to libosmo-pfcp.git? -- To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/28245 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-upf Gerrit-Branch: master Gerrit-Change-Id: I9f4651b6bee457583aba99052dc82bbf675515e6 Gerrit-Change-Number: 28245 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-CC: pespin <pespin(a)sysmocom.de> Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de> Gerrit-Comment-Date: Wed, 08 Jun 2022 16:43:37 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
1 0
0 0
Change in osmo-upf[master]: add initial FSM design charts
by pespin 08 Jun '22

08 Jun '22
Attention is currently required from: neels. pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-upf/+/28243 ) Change subject: add initial FSM design charts ...................................................................... Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/28243 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-upf Gerrit-Branch: master Gerrit-Change-Id: I55474daa6bb204a0fe7da0a3bf888bb7d1c46677 Gerrit-Change-Number: 28243 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de> Gerrit-Comment-Date: Wed, 08 Jun 2022 16:40:40 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
Change in osmo-upf[master]: install libosmo-gtlv, libosmo-pfcp
by neels 08 Jun '22

08 Jun '22
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-upf/+/28245 ) Change subject: install libosmo-gtlv, libosmo-pfcp ...................................................................... install libosmo-gtlv, libosmo-pfcp The first user of this is osmo-hnbgw, to implement GTP mapping via a UPF. Related: SYS#5895 Change-Id: I9f4651b6bee457583aba99052dc82bbf675515e6 --- M Makefile.am M configure.ac A libosmo-gtlv.pc.in A libosmo-pfcp.pc.in M src/libosmo-gtlv/Makefile.am M src/libosmo-pfcp/Makefile.am M tests/libosmo-gtlv/Makefile.am M tests/libosmo-gtlv/test_gtlv_gen/Makefile.am M tests/libosmo-gtlv/test_tliv/Makefile.am M tests/libosmo-pfcp/Makefile.am 10 files changed, 43 insertions(+), 15 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/45/28245/1 diff --git a/Makefile.am b/Makefile.am index 4452f04..7bba342 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,6 +16,12 @@ contrib \ $(NULL) +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = \ + libosmo-gtlv.pc \ + libosmo-pfcp.pc \ + $(NULL) + BUILT_SOURCES = $(top_srcdir)/.version EXTRA_DIST = \ .version \ diff --git a/configure.ac b/configure.ac index 1b2cdea..3864cd2 100644 --- a/configure.ac +++ b/configure.ac @@ -195,6 +195,8 @@ AM_CONFIG_HEADER(config.h) AC_OUTPUT( + libosmo-gtlv.pc + libosmo-pfcp.pc include/Makefile include/osmocom/Makefile include/osmocom/gtlv/Makefile diff --git a/libosmo-gtlv.pc.in b/libosmo-gtlv.pc.in new file mode 100644 index 0000000..69de862 --- /dev/null +++ b/libosmo-gtlv.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Osmocom Generic TLV Library +Description: C Utility Library +Version: @VERSION@ +Libs: -L${libdir} -losmo-gtlv +Cflags: -I${includedir}/ diff --git a/libosmo-pfcp.pc.in b/libosmo-pfcp.pc.in new file mode 100644 index 0000000..c482751 --- /dev/null +++ b/libosmo-pfcp.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Osmocom PFCP library +Description: C Utility Library that implements the PFCP protocol and endpoint +Version: @VERSION@ +Libs: -L${libdir} -losmo-pfcp +Cflags: -I${includedir}/ diff --git a/src/libosmo-gtlv/Makefile.am b/src/libosmo-gtlv/Makefile.am index 248ff67..fb8d26f 100644 --- a/src/libosmo-gtlv/Makefile.am +++ b/src/libosmo-gtlv/Makefile.am @@ -16,11 +16,11 @@ $(COVERAGE_LDFLAGS) \ $(NULL) -noinst_LIBRARIES = \ - libosmo-gtlv.a \ +lib_LTLIBRARIES = \ + libosmo-gtlv.la \ $(NULL) -libosmo_gtlv_a_SOURCES = \ +libosmo_gtlv_la_SOURCES = \ gtlv.c \ gtlv_dec_enc.c \ gtlv_gen.c \ diff --git a/src/libosmo-pfcp/Makefile.am b/src/libosmo-pfcp/Makefile.am index db81648..6840648 100644 --- a/src/libosmo-pfcp/Makefile.am +++ b/src/libosmo-pfcp/Makefile.am @@ -19,11 +19,11 @@ $(COVERAGE_LDFLAGS) \ $(NULL) -noinst_LIBRARIES = \ - libosmo-pfcp.a \ +lib_LTLIBRARIES = \ + libosmo-pfcp.la \ $(NULL) -libosmo_pfcp_a_SOURCES = \ +libosmo_pfcp_la_SOURCES = \ pfcp_endpoint.c \ pfcp_ies_custom.c \ pfcp_msg.c \ @@ -56,7 +56,7 @@ $(NULL) gen__pfcp_ies_auto_LDADD = \ - $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.a \ + $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.la \ $(LIBOSMOCORE_LIBS) \ $(COVERAGE_LDFLAGS) \ $(NULL) diff --git a/tests/libosmo-gtlv/Makefile.am b/tests/libosmo-gtlv/Makefile.am index 45d6ec2..20721c0 100644 --- a/tests/libosmo-gtlv/Makefile.am +++ b/tests/libosmo-gtlv/Makefile.am @@ -28,7 +28,7 @@ $(NULL) gtlv_test_LDADD = \ - $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.a \ + $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.la \ $(LIBOSMOCORE_LIBS) \ $(NULL) @@ -37,7 +37,7 @@ $(NULL) gtlv_dec_enc_test_LDADD = \ - $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.a \ + $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.la \ $(LIBOSMOCORE_LIBS) \ $(NULL) diff --git a/tests/libosmo-gtlv/test_gtlv_gen/Makefile.am b/tests/libosmo-gtlv/test_gtlv_gen/Makefile.am index 0d27292..e13e7b5 100644 --- a/tests/libosmo-gtlv/test_gtlv_gen/Makefile.am +++ b/tests/libosmo-gtlv/test_gtlv_gen/Makefile.am @@ -35,7 +35,7 @@ $(NULL) gen__myproto_ies_auto_LDADD = \ - $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.a \ + $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.la \ $(LIBOSMOCORE_LIBS) \ $(NULL) @@ -51,7 +51,7 @@ $(NULL) gtlv_gen_test_LDADD = \ - $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.a \ + $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.la \ $(LIBOSMOCORE_LIBS) \ $(NULL) diff --git a/tests/libosmo-gtlv/test_tliv/Makefile.am b/tests/libosmo-gtlv/test_tliv/Makefile.am index eb95e12..458a410 100644 --- a/tests/libosmo-gtlv/test_tliv/Makefile.am +++ b/tests/libosmo-gtlv/test_tliv/Makefile.am @@ -35,7 +35,7 @@ $(NULL) gen__myproto_ies_auto_LDADD = \ - $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.a \ + $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.la \ $(LIBOSMOCORE_LIBS) \ $(NULL) @@ -51,7 +51,7 @@ $(NULL) tliv_test_LDADD = \ - $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.a \ + $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.la \ $(LIBOSMOCORE_LIBS) \ $(NULL) diff --git a/tests/libosmo-pfcp/Makefile.am b/tests/libosmo-pfcp/Makefile.am index fda143f..bd18d06 100644 --- a/tests/libosmo-pfcp/Makefile.am +++ b/tests/libosmo-pfcp/Makefile.am @@ -22,8 +22,8 @@ $(NULL) pfcp_test_LDADD = \ - $(top_builddir)/src/libosmo-pfcp/libosmo-pfcp.a \ - $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.a \ + $(top_builddir)/src/libosmo-pfcp/libosmo-pfcp.la \ + $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.la \ $(LIBOSMOCORE_LIBS) \ $(NULL) -- To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/28245 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-upf Gerrit-Branch: master Gerrit-Change-Id: I9f4651b6bee457583aba99052dc82bbf675515e6 Gerrit-Change-Number: 28245 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
Change in osmo-upf[master]: add initial FSM design charts
by neels 08 Jun '22

08 Jun '22
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-upf/+/28243 ) Change subject: add initial FSM design charts ...................................................................... add initial FSM design charts Related: SYS#5599 Change-Id: I55474daa6bb204a0fe7da0a3bf888bb7d1c46677 --- M configure.ac M doc/Makefile.am A doc/charts/Makefile.am A doc/charts/pfcp_and_gtp.dot A doc/charts/pfcp_cp_peer_fsm.dot A doc/charts/pfcp_cp_session_fsm.dot A doc/charts/pfcp_heartbeat_fsm.dot A doc/charts/pfcp_overview.dot A doc/charts/pfcp_up_peer_fsm.dot A doc/charts/pfcp_up_session_fsm.dot 10 files changed, 205 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/43/28243/1 diff --git a/configure.ac b/configure.ac index 9982028..1b2cdea 100644 --- a/configure.ac +++ b/configure.ac @@ -213,6 +213,7 @@ doc/Makefile doc/examples/Makefile doc/manuals/Makefile + doc/charts/Makefile contrib/Makefile contrib/systemd/Makefile Makefile) diff --git a/doc/Makefile.am b/doc/Makefile.am index 15f36b7..66103ba 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,4 +1,5 @@ SUBDIRS = \ examples \ manuals \ + charts \ $(NULL) diff --git a/doc/charts/Makefile.am b/doc/charts/Makefile.am new file mode 100644 index 0000000..af0736d --- /dev/null +++ b/doc/charts/Makefile.am @@ -0,0 +1,24 @@ +msc: \ + $(builddir)/pfcp_msgs.png \ + $(builddir)/pfcp_msgs_gtp.png \ + $(NULL) + +dot: \ + $(builddir)/pfcp_overview.png \ + $(builddir)/pfcp_cp_peer_fsm.png \ + $(builddir)/pfcp_up_peer_fsm.png \ + $(builddir)/pfcp_heartbeat_fsm.png \ + $(builddir)/pfcp_cp_session_fsm.png \ + $(builddir)/pfcp_up_session_fsm.png \ + $(builddir)/pfcp_and_gtp.png \ + $(NULL) + +$(builddir)/%.png: $(srcdir)/%.msc + mscgen -T png -o $@ $< + +$(builddir)/%.png: $(srcdir)/%.dot + dot -Tpng $< > $@ + +.PHONY: poll +poll: + while true; do $(MAKE) msc dot; sleep 1; done diff --git a/doc/charts/pfcp_and_gtp.dot b/doc/charts/pfcp_and_gtp.dot new file mode 100644 index 0000000..5c160b3 --- /dev/null +++ b/doc/charts/pfcp_and_gtp.dot @@ -0,0 +1,20 @@ +digraph G { +rankdir=LR +labelloc=t; label="PFCP and GTP" + +SGSN [label="SGSN\n123.44.0.9"] +SGWC [label="SGW-C\n123.44.05"] +subgraph cluster_UPF { + label="OsmoUPF"; + SGWU [label="SGW-U\n123.44.0.6"]; + GTPk [label="kernel GTP\n123.44.0.6"] +} + +SGSN -> SGWC [label="S4\nGTPv2-C"] +SGWC -> SGWU [label="Sxa\nPFCP\nSession Establishment:\n"] +SGSN -> GTPk [label="S4\nGTPv1-U",dir=both] + +MS [label="MS\n192.168.104.176"] +MS -> SGSN [dir=both] + +} diff --git a/doc/charts/pfcp_cp_peer_fsm.dot b/doc/charts/pfcp_cp_peer_fsm.dot new file mode 100644 index 0000000..101fe07 --- /dev/null +++ b/doc/charts/pfcp_cp_peer_fsm.dot @@ -0,0 +1,39 @@ +digraph G { +rankdir=TB +labelloc=t; label="PFCP CP peer FSM\nControl Plane side, managing association with remote UP peer" + +cp [label="CP function",shape="box"] + +cp -> WAIT_ASSOC_SETUP_RESP [label="cp_peer_associate()"] + +txrx [label="PFCP socket",shape="box"] +WAIT_ASSOC_SETUP_RESP -> txrx [label="tx_assoc_setup_req()",style=dotted] +txrx -> WAIT_ASSOC_SETUP_RESP [label="EV_RX_ASSOC_SETUP_RESP",style=dotted] +WAIT_ASSOC_SETUP_RESP -> ASSOCIATED [label="Assoc Setup Resp"] + +WAIT_ASSOC_SETUP_RESP -> WAIT_ASSOC_SETUP_RESP [label="retry"] + +heartbeat [label="PFCP heartbeat FSM",shape=box3d] +ASSOCIATED -> heartbeat [label="alloc()",style=dotted] +heartbeat -> ASSOCIATED [label="EV_HEARTBEAT_FAILURE",style=dotted] + +txrx2 [label="PFCP socket",shape="box"] +txrx2 -> ASSOCIATED [label="EV_RX_ASSOC_UPDATE_REQ\n3GPP TS 29.244 6.2.7.3.1",style=dotted] +GRACEFUL_RELEASE -> txrx2 [label="tx_assoc_update_resp()",style=dotted] + +cp_session [label="PFCP CP session FSM",shape=box3d] +cp -> ASSOCIATED [label="cp_peer_session_create()",style=dotted] +ASSOCIATED -> cp_session [label="cp_session_create()",style=dotted] +cp -> cp_session [style=invisible,arrowhead=none] + +ASSOCIATED -> GRACEFUL_RELEASE [label="Association Update\nindicating graceful release"] + +cp -> ASSOCIATED [label="cp_peer_release()",style=dotted] +ASSOCIATED -> term [label="cp_peer_release()\nHeartbeat failure"] + +ASSOCIATED -> WAIT_ASSOC_SETUP_RESP [label="Heartbeat failure"] + +GRACEFUL_RELEASE -> term +term [shape="octagon"] + +} diff --git a/doc/charts/pfcp_cp_session_fsm.dot b/doc/charts/pfcp_cp_session_fsm.dot new file mode 100644 index 0000000..0319608 --- /dev/null +++ b/doc/charts/pfcp_cp_session_fsm.dot @@ -0,0 +1,28 @@ +digraph G { +rankdir=TB +labelloc=t; label="PFCP CP session FSM" + +cp [label="CP function",shape=box] +cp -> WAIT_ESTABLISHMENT_RESP [label="cp_session_create(cp_peer)\niff cp_peer in state ASSOCIATED"] + +txrx [label="PFCP socket",shape=box] + +WAIT_ESTABLISHMENT_RESP -> txrx [label="tx_session_est_req()",style=dotted] +txrx -> WAIT_ESTABLISHMENT_RESP [label="EV_RX_SESSION_EST_RESP",style=dotted] + +WAIT_ESTABLISHMENT_RESP -> ESTABLISHED [label="Est Resp"] + +cp -> ESTABLISHED [label="cp_session_modify()",style=dotted] +ESTABLISHED -> WAIT_MODIFICATION_RESP [label="cp_session_modify()"] +WAIT_MODIFICATION_RESP -> txrx [label="tx_session_mod_req()",style=dotted] +txrx -> WAIT_MODIFICATION_RESP [label="EV_RX_SESSION_MOD_RESP",style=dotted,constraint=false] +WAIT_MODIFICATION_RESP -> ESTABLISHED [label="Mod Resp"] + +cp -> ESTABLISHED [label="cp_session_delete()",style=dotted] +ESTABLISHED -> WAIT_DELETION_RESP [label="cp_session_delete()"] +WAIT_DELETION_RESP -> txrx [label="tx_session_del_req()",style=dotted] +txrx -> WAIT_DELETION_RESP [label="EV_RX_SESSION_DEL_RESP",style=dotted,constraint=false] +WAIT_DELETION_RESP -> term +term [shape="octagon"] + +} diff --git a/doc/charts/pfcp_heartbeat_fsm.dot b/doc/charts/pfcp_heartbeat_fsm.dot new file mode 100644 index 0000000..b5b4584 --- /dev/null +++ b/doc/charts/pfcp_heartbeat_fsm.dot @@ -0,0 +1,21 @@ +digraph G { +rankdir=TB +labelloc=t; label="PFCP heartbeat FSM" + +peer [label="PFCP CP/UP peer FSM",shape=box3d] +txrx [label="PFCP socket",shape=box] + +peer -> IDLE [label="alloc()"] +IDLE -> WAIT_HEARTBEAT_RESP -> IDLE +WAIT_HEARTBEAT_RESP -> term +term [shape="octagon"] + +WAIT_HEARTBEAT_RESP -> txrx [label="tx_heartbeat_req()",style=dotted] +txrx -> WAIT_HEARTBEAT_RESP [label="HEARTBEAT_EV_RX_RESP",style=dotted] + +term -> peer [label="PEER_EV_HEARTBEAT_FAILURE",style=dotted] + +txrx2 [label="PFCP socket",shape=box] +txrx2 -> txrx2 [label="rx Heartbeat Req\ntx Heartbeat Resp",style=dotted] + +} diff --git a/doc/charts/pfcp_overview.dot b/doc/charts/pfcp_overview.dot new file mode 100644 index 0000000..33fa9a0 --- /dev/null +++ b/doc/charts/pfcp_overview.dot @@ -0,0 +1,23 @@ +digraph G { +rankdir=TB +labelloc=t; label="PFCP Overview\n3GPP TS 29.244 3.1, 5.8.1" + +subgraph cluster_N1_CP { + label="Node: Control Plane function";style=dotted + N1_E_CP [label="CP Entity"] +} + +subgraph cluster_N2_UP { + label="Node: User Plane function\nNode ID: my-userplane.com\n(FQDN may provide multiple PFCP Entities)";style=dotted + N2_E_UP [label="UP Entity\n8.7.6.1"] + N2_E_UP2 [label="UP Entity\n8.7.6.2"] +} + +subgraph cluster_N3_UP { + label="Node: User Plane function\nNode ID: 1.2.3.4\n(IP address means only one PFCP Entity)";style=dotted + N3_E_UP [label="UP Entity\n1.2.3.4\n(osmo-upf)"] +} + +N1_E_CP -> N3_E_UP [label="PFCP Request"] +N1_E_CP -> N2_E_UP +} diff --git a/doc/charts/pfcp_up_peer_fsm.dot b/doc/charts/pfcp_up_peer_fsm.dot new file mode 100644 index 0000000..60152f7 --- /dev/null +++ b/doc/charts/pfcp_up_peer_fsm.dot @@ -0,0 +1,27 @@ +digraph G { +rankdir=TB +labelloc=t; label="PFCP UP peer FSM\nUser Plane side, managing association with remote CP peer" + +txrx [label="PFCP socket",shape="box"] + +txrx -> NOT_ASSOCIATED [label="rx PFCP msg from\nnew remote IP"] +txrx -> NOT_ASSOCIATED [label="EV_RX_ASSOC_SETUP_REQ",style=dotted] + +NOT_ASSOCIATED -> ASSOCIATED [label="Assoc Setup Req",shape="box"] + +heartbeat [label="PFCP heartbeat FSM",shape=box3d] +ASSOCIATED -> heartbeat [label="alloc()",style=dotted] +heartbeat -> ASSOCIATED [label="EV_HEARTBEAT_FAILURE",style=dotted] + +txrx -> ASSOCIATED [label="EV_RX_SESSION_EST_REQ",style=dotted] +up_session [label="PFCP UP session FSM",shape=box3d] +ASSOCIATED -> up_session [label="up_session_create()",style=dotted] + +txrx -> ASSOCIATED [label="EV_RX_ASSOC_UPD_REQ",style=dotted] +ASSOCIATED -> GRACEFUL_RELEASE [label="Association Update\nindicating graceful release"] + +ASSOCIATED -> term [label="Heartbeat failure"] +GRACEFUL_RELEASE -> term +term [shape="octagon"] + +} diff --git a/doc/charts/pfcp_up_session_fsm.dot b/doc/charts/pfcp_up_session_fsm.dot new file mode 100644 index 0000000..b4a06f5 --- /dev/null +++ b/doc/charts/pfcp_up_session_fsm.dot @@ -0,0 +1,21 @@ +digraph G { +rankdir=TB +labelloc=t; label="PFCP UP session FSM" + +peer [label="PFCP UP peer FSM",shape=box3d] +peer -> ESTABLISHED [label="rx_session_est_req()"] + +txrx [label="PFCP socket",shape="box"] +txrx2 [label="PFCP socket",shape="box"] + +txrx -> ESTABLISHED [label="EV_RX_SESSION_MOD_REQ",style=dotted] +ESTABLISHED -> txrx [label="tx_session_mod_resp()",style=dotted,constraint=false] +ESTABLISHED -> ESTABLISHED [label="Mod"] + +txrx2 -> ESTABLISHED [label="EV_RX_SESSION_DEL_REQ",style=dotted] +ESTABLISHED -> txrx2 [label="tx_session_del_resp()",style=dotted,constraint=false] + +ESTABLISHED -> term [label="Deletion"] +term [shape="octagon"] + +} -- To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/28243 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-upf Gerrit-Branch: master Gerrit-Change-Id: I55474daa6bb204a0fe7da0a3bf888bb7d1c46677 Gerrit-Change-Number: 28243 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
Change in osmo-upf[master]: add pfcp_endpoint
by neels 08 Jun '22

08 Jun '22
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-upf/+/28244 ) Change subject: add pfcp_endpoint ...................................................................... add pfcp_endpoint Related: SYS#5599 Change-Id: Ic8d42e201b63064a71b40ca45a5a40e29941e8ac --- M include/osmocom/pfcp/Makefile.am A include/osmocom/pfcp/pfcp_endpoint.h M include/osmocom/pfcp/pfcp_msg.h M src/libosmo-pfcp/Makefile.am A src/libosmo-pfcp/pfcp_endpoint.c 5 files changed, 580 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/44/28244/1 diff --git a/include/osmocom/pfcp/Makefile.am b/include/osmocom/pfcp/Makefile.am index 7bd5ea3..5d2db19 100644 --- a/include/osmocom/pfcp/Makefile.am +++ b/include/osmocom/pfcp/Makefile.am @@ -1,4 +1,5 @@ pfcp_HEADERS = \ + pfcp_endpoint.h \ pfcp_ies_custom.h \ pfcp_ies_auto.h \ pfcp_msg.h \ diff --git a/include/osmocom/pfcp/pfcp_endpoint.h b/include/osmocom/pfcp/pfcp_endpoint.h new file mode 100644 index 0000000..fa496dd --- /dev/null +++ b/include/osmocom/pfcp/pfcp_endpoint.h @@ -0,0 +1,103 @@ +/* + * (C) 2021-2022 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * All Rights Reserved. + * + * Author: Neels Janosch Hofmeyr <nhofmeyr(a)sysmocom.de> + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 <http://www.gnu.org/licenses/>. + * + */ + +#pragma once + +#include <osmocom/core/socket.h> +#include <osmocom/core/select.h> +#include <osmocom/core/tdef.h> + +#include <osmocom/pfcp/pfcp_msg.h> + +struct osmo_pfcp_endpoint; +struct osmo_fsm_inst; + +#define OSMO_PFCP_TIMER_T1 -22 +#define OSMO_PFCP_TIMER_N1 -23 +#define OSMO_PFCP_TIMER_KEEP_RESP -24 +#define OSMO_PFCP_TIMER_ASSOC_RETRY -26 +#define OSMO_PFCP_TIMER_GRACEFUL_REL -27 + +extern struct osmo_tdef osmo_pfcp_tdefs[]; + +/* Ownership of m remains with the caller / m will be deallocated by the caller. + * \param ep The PFCP endpoint that received and decoded the message. + * \param m The message that was received. + * \param req If m is a PFCP Response to an earlier Request, req is that request message. */ +typedef void (*osmo_pfcp_endpoint_cb)(struct osmo_pfcp_endpoint *ep, struct osmo_pfcp_msg *m, + struct osmo_pfcp_msg *req); + +/* Send/receive PFCP messages to/from remote PFCP endpoints. */ +struct osmo_pfcp_endpoint { + struct { + /* Local address */ + struct osmo_sockaddr local_addr; + /* Local PFCP Node ID, as sent in outgoing messages' Node ID IE */ + struct osmo_pfcp_ie_node_id local_node_id; + + /* Timer definitions to use, if any. See t1_ms, keep_resp_ms. Use osmo_pfcp_tdefs by default. It is + * convenient to add osmo_pfcp_tdefs as one of your program's osmo_tdef_group entries and call + * osmo_tdef_vty_init() to expose PFCP timers on the VTY. */ + const struct osmo_tdef *tdefs; + } cfg; + + /* PFCP socket */ + struct osmo_fd pfcp_fd; + + /* The time at which this endpoint last restarted, as seconds since unix epoch. */ + uint32_t recovery_time_stamp; + + /* State for determining the next sequence number for transmitting a request message */ + uint32_t seq_nr_state; + + /* This function is called just after decoding and before handling the message. + * This function may set ctx.peer_fi and ctx.session_fi, used for logging context during message decoding. + * The caller may also use these fi pointers to reduce lookup iterations in rx_msg(). + */ + osmo_pfcp_endpoint_cb set_msg_ctx; + + /* Callback to receive single incoming PFCP messages from a remote peer, already decoded. */ + osmo_pfcp_endpoint_cb rx_msg; + + /* application-private data */ + void *priv; + + /* All transmitted messages that are still pending, list of osmo_pfcp_queue_entry. + * For a transmitted Request message, wait for a matching Response from a remote peer; if none arrives, + * retransmit (see n1 and t1_ms). + * For a transmitted Response message, keep it in the queue for a fixed amount of time. If the peer retransmits + * the original Request, do not dispatch the Request, but respond with the queued message directly. + */ + struct llist_head retrans_queue; +}; + +struct osmo_pfcp_endpoint *osmo_pfcp_endpoint_create(void *ctx, void *priv); +int osmo_pfcp_endpoint_bind(struct osmo_pfcp_endpoint *ep); +void osmo_pfcp_endpoint_close(struct osmo_pfcp_endpoint *ep); +void osmo_pfcp_endpoint_free(struct osmo_pfcp_endpoint **ep); + +int osmo_pfcp_endpoint_tx(struct osmo_pfcp_endpoint *ep, struct osmo_pfcp_msg *m); +int osmo_pfcp_endpoint_tx_data(struct osmo_pfcp_endpoint *ep, struct osmo_pfcp_msg *m); +int osmo_pfcp_endpoint_tx_heartbeat_req(struct osmo_pfcp_endpoint *ep, const struct osmo_sockaddr *remote_addr); + +void osmo_pfcp_endpoint_invalidate_ctx(struct osmo_pfcp_endpoint *ep, struct osmo_fsm_inst *deleted_fi); diff --git a/include/osmocom/pfcp/pfcp_msg.h b/include/osmocom/pfcp/pfcp_msg.h index 949800e..2833408 100644 --- a/include/osmocom/pfcp/pfcp_msg.h +++ b/include/osmocom/pfcp/pfcp_msg.h @@ -147,6 +147,9 @@ osmo_pfcp_resp_cb resp_cb; void *priv; } ctx; + + /* When a message gets encoded, the encoded packet is cached here for possible retransmissions. */ + struct msgb *encoded; }; /* Given a &osmo_pfcp_msg->ies pointer, return the &osmo_pfcp_msg. diff --git a/src/libosmo-pfcp/Makefile.am b/src/libosmo-pfcp/Makefile.am index c8accb9..db81648 100644 --- a/src/libosmo-pfcp/Makefile.am +++ b/src/libosmo-pfcp/Makefile.am @@ -24,6 +24,7 @@ $(NULL) libosmo_pfcp_a_SOURCES = \ + pfcp_endpoint.c \ pfcp_ies_custom.c \ pfcp_msg.c \ pfcp_strs.c \ diff --git a/src/libosmo-pfcp/pfcp_endpoint.c b/src/libosmo-pfcp/pfcp_endpoint.c new file mode 100644 index 0000000..3be2aab --- /dev/null +++ b/src/libosmo-pfcp/pfcp_endpoint.c @@ -0,0 +1,472 @@ +/* + * (C) 2021-2022 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * All Rights Reserved. + * + * Author: Neels Janosch Hofmeyr <nhofmeyr(a)sysmocom.de> + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 <http://www.gnu.org/licenses/>. + * + */ + +#include <errno.h> +#include <unistd.h> +#include <time.h> + +#include <osmocom/core/talloc.h> +#include <osmocom/core/timer.h> +#include <osmocom/core/tdef.h> + +#include <osmocom/pfcp/pfcp_endpoint.h> +#include <osmocom/pfcp/pfcp_msg.h> + +/*! Entry of pfcp_endpoint message queue of PFCP messages, for re-transsions. */ +struct osmo_pfcp_queue_entry { + /* entry in per-peer list of messages waiting for a response */ + struct llist_head entry; + /* back-pointer */ + struct osmo_pfcp_endpoint *ep; + /* message we have transmitted */ + struct osmo_pfcp_msg *m; + /* T1 timer: How long to wait for response before retransmitting */ + struct osmo_timer_list t1; + /* N1: number of pending re-transmissions */ + unsigned int n1_remaining; +}; + +/* find a matching osmo_pfcp_queue_entry for given rx_hdr */ +static struct osmo_pfcp_queue_entry * +osmo_pfcp_queue_find(struct llist_head *queue, const struct osmo_pfcp_msg *rx) +{ + struct osmo_pfcp_queue_entry *qe; + /* It's important to match only a Request to a Response and vice versa, because the remote peer makes its own + * sequence_nr. There could be a collision of sequence_nr. But as long as all Requests look for a Response and + * vice versa, the sequence_nr scopes don't overlap. */ + llist_for_each_entry(qe, queue, entry) { + if (qe->m->is_response != rx->is_response + && qe->m->h.sequence_nr == rx->h.sequence_nr) + return qe; + } + return NULL; +} + +/* clean up and deallocate the given osmo_pfcp_queue_entry */ +static void osmo_pfcp_queue_del(struct osmo_pfcp_queue_entry *qe) +{ + /* see also the talloc destructor */ + talloc_free(qe); +} + +int osmo_pfcp_queue_destructor(struct osmo_pfcp_queue_entry *qe) +{ + osmo_timer_del(&qe->t1); + llist_del(&qe->entry); + return 0; +} + +struct osmo_tdef osmo_pfcp_tdefs[] = { + { .T = -19, .default_val = 15, .unit = OSMO_TDEF_S, + .desc = "PFCP Heartbeat Request period, how long to wait between issuing requests" + }, + { .T = -20, .default_val = 15, .unit = OSMO_TDEF_S, + .desc = "PFCP Heartbeat Response timeout, the time after which to regard a non-responding peer as disconnected" + }, + { .T = -21, .default_val = 15, .unit = OSMO_TDEF_S, + .desc = "PFCP peer graceful shutdown timeout, how long to keep the peer's state after a peer requested" + " graceful shutdown" + }, + { .T = OSMO_PFCP_TIMER_T1, .default_val = 3000, .unit = OSMO_TDEF_MS, + .desc = "PFCP request timeout, how long after a missing response to retransmit a PFCP request" + }, + { .T = OSMO_PFCP_TIMER_N1, .default_val = 3, .unit = OSMO_TDEF_CUSTOM, + .desc = "Number of PFCP request retransmission attempts" + }, + { .T = OSMO_PFCP_TIMER_KEEP_RESP, .default_val = 10000, .unit = OSMO_TDEF_MS, + .desc = "PFCP response timeout, how long to keep a response, in case its same request is retransmitted by the peer" + }, + { .T = OSMO_PFCP_TIMER_ASSOC_RETRY, .default_val = 15, .unit = OSMO_TDEF_S, + .desc = "Idle time between attempts of PFCP Association Setup (CPF)" + }, + { .T = OSMO_PFCP_TIMER_GRACEFUL_REL, .default_val = 15, .unit = OSMO_TDEF_S, + .desc = "PFCP graceful release timeout" + }, + {} +}; + +struct osmo_pfcp_endpoint *osmo_pfcp_endpoint_create(void *ctx, void *priv) +{ + struct osmo_pfcp_endpoint *ep = talloc_zero(ctx, struct osmo_pfcp_endpoint); + uint32_t unix_time; + if (!ep) + return NULL; + + INIT_LLIST_HEAD(&ep->retrans_queue); + + ep->cfg.tdefs = osmo_pfcp_tdefs; + ep->priv = priv; + ep->pfcp_fd.fd = -1; + + /* time() returns seconds since 1970 (UNIX epoch), but the recovery_time_stamp is coded in the NTP format, which is + * seconds since 1900, the NTP era 0. 2208988800L is the offset between UNIX epoch and NTP era 0. + * TODO: what happens when we enter NTP era 1? Is it sufficient to integer-wrap? */ + unix_time = time(NULL); + ep->recovery_time_stamp = unix_time + 2208988800L; + LOGP(DLPFCP, LOGL_NOTICE, "PFCP endpoint: recovery timestamp = 0x%08x (%u seconds since UNIX epoch," + " which is %u seconds since NTP era 0; IETF RFC 5905)\n", + ep->recovery_time_stamp, unix_time, ep->recovery_time_stamp); + + return ep; +} + +static unsigned int ep_n1(struct osmo_pfcp_endpoint *ep) +{ + return osmo_tdef_get(ep->cfg.tdefs, OSMO_PFCP_TIMER_N1, OSMO_TDEF_CUSTOM, -1); +} + +unsigned int ep_t1(struct osmo_pfcp_endpoint *ep) +{ + return osmo_tdef_get(ep->cfg.tdefs, OSMO_PFCP_TIMER_T1, OSMO_TDEF_MS, -1); +} + +unsigned int ep_keep_resp(struct osmo_pfcp_endpoint *ep) +{ + return osmo_tdef_get(ep->cfg.tdefs, OSMO_PFCP_TIMER_KEEP_RESP, OSMO_TDEF_MS, -1); +} + +static int osmo_pfcp_endpoint_tx_data_no_logging(struct osmo_pfcp_endpoint *ep, struct osmo_pfcp_msg *m); + +/* Return true to keep the message in the queue, false for dropping from the queue. */ +static bool pfcp_queue_retrans(struct osmo_pfcp_queue_entry *qe) +{ + struct osmo_pfcp_endpoint *endpoint = qe->ep; + unsigned int t1_ms = ep_t1(endpoint); + struct osmo_pfcp_msg *m = qe->m; + int rc; + + /* re-transmit */ + if (qe->n1_remaining) + qe->n1_remaining--; + OSMO_LOG_PFCP_MSG(m, LOGL_INFO, "re-sending (%u attempts remaining)\n", qe->n1_remaining); + + rc = osmo_pfcp_endpoint_tx_data_no_logging(endpoint, m); + /* If encoding failed, it cannot ever succeed. Drop the queue entry. */ + if (rc) + return false; + /* if no more attempts remaining, drop from queue */ + if (!qe->n1_remaining) + return false; + /* re-schedule timer, keep in queue */ + osmo_timer_schedule(&qe->t1, t1_ms/1000, t1_ms%1000); + return true; +} + +/* T1 for a given queue entry has expired */ +static void pfcp_queue_timer_cb(void *data) +{ + struct osmo_pfcp_queue_entry *qe = data; + bool keep; + + if (qe->m->is_response) { + /* The response has waited in the queue for any retransmissions of its initiating request. Now that time + * has passed and the response can be dropped from the queue. */ + keep = false; + } else { + /* The request is still here, which means it has not received a response from the remote side. + * Retransmit the request. */ + keep = pfcp_queue_retrans(qe); + } + + if (keep) + return; + /* Drop the queue entry. No more retransmissions. */ + if (!qe->m->is_response && qe->m->ctx.resp_cb) + qe->m->ctx.resp_cb(qe->m, NULL, "PFCP retransmissions elapsed, no response received"); + osmo_pfcp_queue_del(qe); +} + +/* Directly encode and transmit the message, without storing in the retrans_queue. */ +static int osmo_pfcp_endpoint_tx_data_no_logging(struct osmo_pfcp_endpoint *ep, struct osmo_pfcp_msg *m) +{ + int rc; + + if (!m->encoded) { + /* Allocate msgb as child of the message m, so that when m gets deallocated at the end of + * retransmission queueing, the msgb gets deallocated with it. */ + m->encoded = msgb_alloc_c(m, OSMO_PFCP_MSGB_ALLOC_SIZE, "PFCP-tx"); + OSMO_ASSERT(m->encoded); + rc = osmo_pfcp_msg_encode(m->encoded, m); + if (rc) { + msgb_free(m->encoded); + m->encoded = NULL; + return rc; + } + } + + rc = sendto(ep->pfcp_fd.fd, msgb_data(m->encoded), msgb_length(m->encoded), 0, + (struct sockaddr*)&m->remote_addr, sizeof(m->remote_addr)); + if (rc != msgb_length(m->encoded)) { + OSMO_LOG_PFCP_MSG(m, LOGL_ERROR, "sendto() failed: rc = %d != length %u\n", + rc, msgb_length(m->encoded)); + return -EIO; + } + return 0; +} + +int osmo_pfcp_endpoint_tx_data(struct osmo_pfcp_endpoint *ep, struct osmo_pfcp_msg *m) +{ + OSMO_LOG_PFCP_MSG(m, LOGL_INFO, "sending\n"); + return osmo_pfcp_endpoint_tx_data_no_logging(ep, m); +} + +int osmo_pfcp_endpoint_tx_heartbeat_req(struct osmo_pfcp_endpoint *ep, const struct osmo_sockaddr *remote_addr) +{ + struct osmo_pfcp_msg *tx = osmo_pfcp_msg_alloc_tx(OTC_SELECT, remote_addr, NULL, NULL, + OSMO_PFCP_MSGT_HEARTBEAT_REQ); + tx->ies.heartbeat_req.recovery_time_stamp = ep->recovery_time_stamp; + tx->h.sequence_nr = osmo_pfcp_next_seq_nr(&ep->seq_nr_state); + return osmo_pfcp_endpoint_tx_data(ep, tx); +} + +/* add a given msgb to the queue of per-peer messages waiting for a response */ +static int osmo_pfcp_endpoint_retrans_queue_add(struct osmo_pfcp_endpoint *endpoint, struct osmo_pfcp_msg *m) +{ + struct osmo_pfcp_queue_entry *qe; + unsigned int n1 = ep_n1(endpoint); + unsigned int t1_ms = ep_t1(endpoint); + unsigned int keep_resp_ms = ep_keep_resp(endpoint); + unsigned int timeout = m->is_response ? keep_resp_ms : t1_ms; + + LOGP(DLPFCP, LOGL_DEBUG, "retransmit unanswered Requests %u x %ums; keep sent Responses for %ums\n", + n1, t1_ms, keep_resp_ms); + /* If there are no retransmissions or no timeout, it makes no sense to add to the queue. */ + if (!n1 || !t1_ms) { + if (!m->is_response && m->ctx.resp_cb) + m->ctx.resp_cb(m, NULL, "PFCP timeout is zero, cannot wait for a response"); + return 0; + } + + qe = talloc(endpoint, struct osmo_pfcp_queue_entry); + OSMO_ASSERT(qe); + *qe = (struct osmo_pfcp_queue_entry){ + .ep = endpoint, + .m = m, + .n1_remaining = m->is_response ? 0 : n1, + }; + talloc_steal(qe, m); + llist_add_tail(&qe->entry, &endpoint->retrans_queue); + talloc_set_destructor(qe, osmo_pfcp_queue_destructor); + + osmo_timer_setup(&qe->t1, pfcp_queue_timer_cb, qe); + osmo_timer_schedule(&qe->t1, timeout/1000, timeout%1000); + return 0; +} + +/* Transmit a PFCP message. + * Store the message in the local message queue for possible retransmissions. + * On success, return zero, and pass ownership of m to ep. ep deallocates m when all retransmissions are done / a reply + * has been received. + * On error, return nonzero, and immediately deallocate m. */ +int osmo_pfcp_endpoint_tx(struct osmo_pfcp_endpoint *ep, struct osmo_pfcp_msg *m) +{ + struct osmo_pfcp_ie_node_id *node_id; + int rc; + if (!m->is_response) + m->h.sequence_nr = osmo_pfcp_next_seq_nr(&ep->seq_nr_state); + node_id = osmo_pfcp_msg_node_id(m); + if (node_id) + *node_id = ep->cfg.local_node_id; + + rc = osmo_pfcp_endpoint_tx_data(ep, m); + if (rc) { + if (!m->is_response && m->ctx.resp_cb) + m->ctx.resp_cb(m, NULL, "Failed to transmit request"); + osmo_pfcp_msg_free(m); + return rc; + } + osmo_pfcp_endpoint_retrans_queue_add(ep, m); + return 0; +} + +static void osmo_pfcp_endpoint_handle_rx(struct osmo_pfcp_endpoint *ep, struct osmo_pfcp_msg *m) +{ + bool dispatch_rx = true; + struct osmo_pfcp_queue_entry *prev_msg; + struct osmo_pfcp_msg *req; + + if (m->h.message_type == OSMO_PFCP_MSGT_HEARTBEAT_REQ) { + /* Directly answer with a Heartbeat Response. */ + struct osmo_pfcp_msg *resp = osmo_pfcp_msg_alloc_tx(OTC_SELECT, NULL, NULL, m, OSMO_PFCP_MSGT_HEARTBEAT_RESP); + resp->ies.heartbeat_resp.recovery_time_stamp = ep->recovery_time_stamp; + osmo_pfcp_endpoint_tx_data(ep, resp); + /* Still also dispatch the Rx event to the peer. */ + } + + /* If this is receiving a response, search for matching request that is now completed. + * If this is receiving a request, search for a matching response that can be retransmitted. + * Either way see if a matching sequence_nr is already in the queue. */ + prev_msg = osmo_pfcp_queue_find(&ep->retrans_queue, m); + req = NULL; + if (prev_msg) { + if (m->is_response && !prev_msg->m->is_response) { + /* Got a response, the original request is now ACKed and can be dropped from the retransmission + * queue: see if (req) below. */ + req = prev_msg->m; + + /* Populate message context to point at peer and session, if applicable */ + if (ep->set_msg_ctx) + ep->set_msg_ctx(ep, m, req); + + OSMO_LOG_PFCP_MSG(m, LOGL_INFO, "received response\n"); + + if (req->ctx.resp_cb) { + int rc = req->ctx.resp_cb(req, m, NULL); + /* Only dispatch the response to rx_msg() when resp_cb() asks for it with rc == 1 + * (or when there is no resp_cb()). */ + if (rc != 1) { + dispatch_rx = false; + OSMO_LOG_PFCP_MSG(m, LOGL_DEBUG, "response handled by m->resp_cb()," + " not dispatching to rx_msg()\n"); + } + } + } else if (!m->is_response && prev_msg->m->is_response) { + /* Got a request, but we have already sent a response to this same request earlier. Retransmit + * the same response, and don't dispatch the msg rx. Keep our response queued in case the + * request is retransmitted yet another time. */ + + /* Populate message context to point at peer and session, if applicable */ + if (ep->set_msg_ctx) + ep->set_msg_ctx(ep, m, NULL); + OSMO_LOG_PFCP_MSG(m, LOGL_INFO, "received retransmission of earlier request\n"); + + OSMO_LOG_PFCP_MSG(prev_msg->m, LOGL_INFO, "re-sending cached response\n"); + osmo_pfcp_endpoint_tx_data_no_logging(ep, prev_msg->m); + return; + } else { + /* Can't tell how prev_msg relates to m, shouldn't happen in a sane PFCP conversation. Handle as + * new, unrelated message. */ + prev_msg = NULL; + } + } + + if (!prev_msg) { + if (ep->set_msg_ctx) + ep->set_msg_ctx(ep, m, NULL); + OSMO_LOG_PFCP_MSG(m, LOGL_INFO, "received\n"); + } + + if (dispatch_rx) + ep->rx_msg(ep, m, req); + if (req) + osmo_pfcp_queue_del(prev_msg); +} + +/* call-back for PFCP socket file descriptor */ +static int osmo_pfcp_fd_cb(struct osmo_fd *ofd, unsigned int what) +{ + int rc; + struct osmo_pfcp_endpoint *ep = ofd->data; + + if (what & OSMO_FD_READ) { + struct osmo_sockaddr remote; + socklen_t remote_len = sizeof(remote); + struct msgb *msg = msgb_alloc_c(OTC_SELECT, OSMO_PFCP_MSGB_ALLOC_SIZE, "PFCP-rx"); + if (!msg) + return -ENOMEM; + + msg->l3h = msg->tail; + rc = recvfrom(ofd->fd, msg->tail, msgb_tailroom(msg), 0, (struct sockaddr *)&remote, &remote_len); + if (rc <= 0) + return -EIO; + msgb_put(msg, rc); + + OSMO_ASSERT(ep->rx_msg); + + /* This may be a bundle of PFCP messages. Parse and receive each message received, by shifting l4h + * through the message bundle. */ + msg->l4h = msg->l3h; + while (msgb_l4len(msg)) { + struct osmo_gtlv_load tlv; + struct osmo_pfcp_msg *m = osmo_pfcp_msg_alloc_rx(OTC_SELECT, &remote); + m->encoded = msg; + + rc = osmo_pfcp_msg_decode_header(&tlv, m, msg); + if (rc < 0) + break; + msg->l4h += rc; + + rc = osmo_pfcp_msg_decode_tlv(m, &tlv); + /* If errors occured, they have already been logged on DLPFCP. */ + if (rc == 0) + osmo_pfcp_endpoint_handle_rx(ep, m); + osmo_pfcp_msg_free(m); + } + msgb_free(msg); + } + return 0; +} + +/*! bind a PFCP endpoint to its configured address (ep->cfg.local_addr). + * \return 0 on success, negative on error. */ +int osmo_pfcp_endpoint_bind(struct osmo_pfcp_endpoint *ep) +{ + int rc; + /* close the existing socket, if any */ + osmo_pfcp_endpoint_close(ep); + + if (!ep->rx_msg) { + LOGP(DLPFCP, LOGL_ERROR, "missing rx_msg cb at osmo_pfcp_endpoint\n"); + return -EINVAL; + } + + /* create the new socket, binding to configured local address */ + ep->pfcp_fd.cb = osmo_pfcp_fd_cb; + ep->pfcp_fd.data = ep; + rc = osmo_sock_init_osa_ofd(&ep->pfcp_fd, SOCK_DGRAM, IPPROTO_UDP, &ep->cfg.local_addr, NULL, OSMO_SOCK_F_BIND); + if (rc < 0) + return rc; + return 0; +} + +void osmo_pfcp_endpoint_close(struct osmo_pfcp_endpoint *ep) +{ + struct osmo_pfcp_queue_entry *qe; + while ((qe = llist_first_entry_or_null(&ep->retrans_queue, struct osmo_pfcp_queue_entry, entry))) { + osmo_pfcp_queue_del(qe); + } + + if (ep->pfcp_fd.fd != -1) { + osmo_fd_unregister(&ep->pfcp_fd); + close(ep->pfcp_fd.fd); + ep->pfcp_fd.fd = -1; + } +} + +void osmo_pfcp_endpoint_free(struct osmo_pfcp_endpoint **ep) +{ + if (!*ep) + return; + osmo_pfcp_endpoint_close(*ep); + talloc_free(*ep); + *ep = NULL; +} + +/* Call osmo_pfcp_msg_invalidate_ctx(deleted_fi) on all queued osmo_pfcp_msg instances in the retrans_queue. */ +void osmo_pfcp_endpoint_invalidate_ctx(struct osmo_pfcp_endpoint *ep, struct osmo_fsm_inst *deleted_fi) +{ + struct osmo_pfcp_queue_entry *qe; + llist_for_each_entry(qe, &ep->retrans_queue, entry) { + osmo_pfcp_msg_invalidate_ctx(qe->m, deleted_fi); + } +} -- To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/28244 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-upf Gerrit-Branch: master Gerrit-Change-Id: Ic8d42e201b63064a71b40ca45a5a40e29941e8ac Gerrit-Change-Number: 28244 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
Change in osmo-upf[master]: add pfcp msg test
by neels 08 Jun '22

08 Jun '22
neels has submitted this change. ( https://gerrit.osmocom.org/c/osmo-upf/+/27638 ) Change subject: add pfcp msg test ...................................................................... add pfcp msg test Related: SYS#5599 Change-Id: I30bdfc66a8f96c0639513ef406e9b66525dced6d --- M configure.ac M tests/Makefile.am A tests/libosmo-pfcp/Makefile.am A tests/libosmo-pfcp/pfcp_test.c A tests/libosmo-pfcp/pfcp_test.ok M tests/testsuite.at 6 files changed, 706 insertions(+), 0 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve pespin: Looks good to me, but someone else must approve neels: Looks good to me, approved diff --git a/configure.ac b/configure.ac index 42e6e77..9982028 100644 --- a/configure.ac +++ b/configure.ac @@ -209,6 +209,7 @@ tests/libosmo-gtlv/Makefile tests/libosmo-gtlv/test_gtlv_gen/Makefile tests/libosmo-gtlv/test_tliv/Makefile + tests/libosmo-pfcp/Makefile doc/Makefile doc/examples/Makefile doc/manuals/Makefile diff --git a/tests/Makefile.am b/tests/Makefile.am index b20af16..01ef6b4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,6 @@ SUBDIRS = \ libosmo-gtlv \ + libosmo-pfcp \ $(NULL) # The `:;' works around a Bash 3.2 bug when the output is not writeable. diff --git a/tests/libosmo-pfcp/Makefile.am b/tests/libosmo-pfcp/Makefile.am new file mode 100644 index 0000000..fda143f --- /dev/null +++ b/tests/libosmo-pfcp/Makefile.am @@ -0,0 +1,32 @@ +AM_CPPFLAGS = \ + $(all_includes) \ + -I$(top_srcdir)/include \ + -I$(top_builddir)/include \ + $(NULL) + +AM_CFLAGS = \ + -Wall \ + $(LIBOSMOCORE_CFLAGS) \ + $(NULL) + +noinst_PROGRAMS = \ + pfcp_test \ + $(NULL) + +EXTRA_DIST = \ + pfcp_test.ok \ + $(NULL) + +pfcp_test_SOURCES = \ + pfcp_test.c \ + $(NULL) + +pfcp_test_LDADD = \ + $(top_builddir)/src/libosmo-pfcp/libosmo-pfcp.a \ + $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.a \ + $(LIBOSMOCORE_LIBS) \ + $(NULL) + +.PHONY: update_exp +update_exp: + $(builddir)/pfcp_test >$(srcdir)/pfcp_test.ok diff --git a/tests/libosmo-pfcp/pfcp_test.c b/tests/libosmo-pfcp/pfcp_test.c new file mode 100644 index 0000000..189622e --- /dev/null +++ b/tests/libosmo-pfcp/pfcp_test.c @@ -0,0 +1,512 @@ +/* + * (C) 2021-2022 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * All Rights Reserved. + * + * Author: Neels Janosch Hofmeyr <nhofmeyr(a)sysmocom.de> + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 <http://www.gnu.org/licenses/>. + * + */ + +#include <stdio.h> +#include <errno.h> + +#include <osmocom/core/application.h> +#include <osmocom/core/utils.h> +#include <osmocom/core/msgb.h> + +#include <osmocom/pfcp/pfcp_msg.h> + +void *ctx; + +/* struct osmo_sockaddr */ +#define v4_ue { \ + .u.sin = { \ + .sin_family = AF_INET, \ + .sin_addr = { 0x1700a8c0 }, \ + } \ +} + +/* struct osmo_sockaddr */ +#define v4_gtp { \ + .u.sin = { \ + .sin_family = AF_INET, \ + .sin_addr = { 0x0708090a }, \ + } \ +} + +/* struct osmo_pfcp_ie_f_teid */ +#define f_teid_access_local { \ + .choose_flag = true, \ + .choose = { \ + .ipv4_addr = true, \ + }, \ +} + +/* struct osmo_pfcp_ie_f_teid */ +#define f_teid_created { \ + .fixed = { \ + .teid = 1234, \ + .ip_addr = { \ + .v4_present = true, \ + .v4 = v4_gtp, \ + }, \ + }, \ +} + +/* struct osmo_pfcp_ie_outer_header_creation */ +#define ohc_access { \ + .desc_bits = { 0x01 }, \ + .teid_present = true, \ + .teid = 0xabcdef, \ + .ip_addr = { \ + .v4_present = true, \ + .v4 = v4_gtp, \ + }, \ +} + +/* struct osmo_pfcp_ie_apply_action */ +#define aa_forw { \ + .bits = { 0x02 }, \ +} + +/* struct osmo_pfcp_ie_f_seid */ +#define f_seid { \ + .seid = 0x1234567890abcdef, \ + .ip_addr = { \ + .v4_present = true, \ + .v4 = v4_gtp, \ + }, \ +} + +struct osmo_pfcp_msg tests[] = { + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_HEARTBEAT_REQ, + .sequence_nr = 1, + }, + .ies.heartbeat_req = { + .recovery_time_stamp = 1234, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_HEARTBEAT_RESP, + .sequence_nr = 2, + }, + .ies.heartbeat_resp = { + .recovery_time_stamp = 5678, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_ASSOC_SETUP_REQ, + .sequence_nr = 3, + }, + .ies.assoc_setup_req = { + .node_id = { + .type = OSMO_PFCP_NODE_ID_T_IPV4, + .ip.u.sin = { + .sin_family = AF_INET, + .sin_addr = { 0x01020304 }, + }, + }, + .recovery_time_stamp = 0x2b2b2b2b, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_ASSOC_SETUP_RESP, + .sequence_nr = 4, + }, + .ies.assoc_setup_resp = { + .node_id = { + .type = OSMO_PFCP_NODE_ID_T_FQDN, + .fqdn = "example.com", + }, + .cause = OSMO_PFCP_CAUSE_REQUEST_ACCEPTED, + .recovery_time_stamp = 0x2b2b2b2b, + .up_function_features_present = true, + .up_function_features.bits = { 1, 2 }, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_ASSOC_RELEASE_REQ, + .sequence_nr = 5, + }, + .ies.assoc_release_req = { + .node_id = { + .type = OSMO_PFCP_NODE_ID_T_IPV6, + .ip.u.sin6 = { + .sin6_family = AF_INET6, + .sin6_addr = {{{ 1, 2, 3, 4 }}}, + }, + }, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_ASSOC_RELEASE_RESP, + .sequence_nr = 6, + }, + .ies.assoc_release_resp = { + .node_id = { + .type = OSMO_PFCP_NODE_ID_T_IPV4, + .ip.u.sin = { + .sin_family = AF_INET, + .sin_addr = { 0x01020304 }, + }, + }, + .cause = OSMO_PFCP_CAUSE_REQUEST_REJECTED, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_SESSION_EST_REQ, + .sequence_nr = 7, + .seid_present = true, + .seid = 0, + }, + .ies.session_est_req = { + .node_id = { + .type = OSMO_PFCP_NODE_ID_T_IPV4, + .ip.u.sin = { + .sin_family = AF_INET, + .sin_addr = { 0x0100007f }, + }, + }, + .cp_f_seid_present = true, + .cp_f_seid = f_seid, + .create_pdr_count = 2, + .create_pdr = { + { + .pdr_id = 1, + .precedence = 255, + .pdi = { + .source_iface = OSMO_PFCP_SOURCE_IFACE_CORE, + .ue_ip_address_present = true, + .ue_ip_address = { + .ip_is_destination = true, + .ip_addr = { + .v4_present = true, + .v4 = v4_ue, + }, + }, + }, + .far_id_present = true, + .far_id = 1, + }, + { + .pdr_id = 2, + .precedence = 255, + .pdi = { + .source_iface = OSMO_PFCP_SOURCE_IFACE_ACCESS, + .local_f_teid_present = true, + .local_f_teid = f_teid_access_local, + }, + .outer_header_removal_present = true, + .outer_header_removal = { + .desc = OSMO_PFCP_OUTER_HEADER_REMOVAL_GTP_U_UDP_IPV4, + }, + .far_id_present = true, + .far_id = 2, + }, + }, + .create_far_count = 2, + .create_far = { + { + .far_id = 1, + .forw_params_present = true, + .forw_params = { + .destination_iface = OSMO_PFCP_DEST_IFACE_ACCESS, + .outer_header_creation_present = true, + .outer_header_creation = ohc_access, + }, + .apply_action = aa_forw, + }, + { + .far_id = 2, + .forw_params_present = true, + .forw_params = { + .destination_iface = OSMO_PFCP_DEST_IFACE_CORE, + }, + .apply_action = aa_forw, + }, + }, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_SESSION_EST_RESP, + .sequence_nr = 8, + .seid_present = true, + .seid = 0x0123456789abcdef, + }, + .ies.session_est_resp = { + .node_id = { + .type = OSMO_PFCP_NODE_ID_T_IPV4, + .ip.u.sin = { + .sin_family = AF_INET, + .sin_addr = { 0x0200007f }, + }, + }, + .cause = OSMO_PFCP_CAUSE_REQUEST_ACCEPTED, + .up_f_seid_present = true, + .up_f_seid = f_seid, + .created_pdr_count = 2, + .created_pdr = { + { + .pdr_id = 1, + }, + { + .pdr_id = 2, + .local_f_teid_present = true, + .local_f_teid = f_teid_created, + }, + }, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_SESSION_MOD_REQ, + .sequence_nr = 9, + .seid_present = true, + .seid = 0, + }, + .ies.session_mod_req = { + .remove_pdr_count = 1, + .remove_pdr = { + { + .pdr_id = 1, + }, + }, + .remove_far_count = 1, + .remove_far = { + { + .far_id = 1, + }, + }, + .create_pdr_count = 1, + .create_pdr = { + { + .pdr_id = 3, + .precedence = 255, + .pdi = { + .source_iface = OSMO_PFCP_SOURCE_IFACE_ACCESS, + .local_f_teid_present = true, + .local_f_teid = f_teid_access_local, + }, + .outer_header_removal_present = true, + .outer_header_removal = { + .desc = OSMO_PFCP_OUTER_HEADER_REMOVAL_GTP_U_UDP_IPV4, + }, + .far_id_present = true, + .far_id = 3, + }, + }, + .create_far_count = 1, + .create_far = { + { + .far_id = 3, + .forw_params_present = true, + .forw_params = { + .destination_iface = OSMO_PFCP_DEST_IFACE_ACCESS, + .outer_header_creation_present = true, + .outer_header_creation = ohc_access, + }, + .apply_action = aa_forw, + }, + }, + .upd_pdr_count = 1, + .upd_pdr = { + { + .pdr_id = 1, + .pdi = { + .source_iface = OSMO_PFCP_SOURCE_IFACE_ACCESS, + .local_f_teid_present = true, + .local_f_teid = f_teid_access_local, + }, + .outer_header_removal_present = true, + .outer_header_removal = { + .desc = OSMO_PFCP_OUTER_HEADER_REMOVAL_GTP_U_UDP_IPV4, + }, + .far_id_present = true, + .far_id = 1, + }, + }, + .upd_far_count = 1, + .upd_far = { + { + .far_id = 1, + .upd_forw_params_present = true, + .upd_forw_params = { + .destination_iface = OSMO_PFCP_DEST_IFACE_CORE, + .network_inst_present = true, + .network_inst = { + .str = "internet", + }, + }, + .apply_action = aa_forw, + }, + }, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_SESSION_MOD_RESP, + .sequence_nr = 10, + .seid_present = true, + .seid = 0x0123456789abcdef, + }, + .ies.session_mod_resp = { + .cause = OSMO_PFCP_CAUSE_REQUEST_ACCEPTED, + .created_pdr_count = 1, + .created_pdr = { + { + .pdr_id = 3, + .local_f_teid_present = true, + .local_f_teid = f_teid_created, + }, + }, + .updated_pdr_count = 1, + .updated_pdr = { + { + .pdr_id = 1, + .local_f_teid_present = true, + .local_f_teid = f_teid_created, + }, + }, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_SESSION_MOD_RESP, + .sequence_nr = 11, + .seid_present = true, + .seid = 0x0123456789abcdef, + }, + .ies.session_mod_resp = { + .cause = OSMO_PFCP_CAUSE_MANDATORY_IE_MISSING, + .offending_ie_present = true, + .offending_ie = OSMO_PFCP_IEI_APPLY_ACTION, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_SESSION_DEL_REQ, + .sequence_nr = 12, + .seid_present = true, + .seid = 0x0123456789abcdef, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_SESSION_DEL_RESP, + .sequence_nr = 13, + .seid_present = true, + .seid = 0x0123456789abcdef, + }, + .ies.session_del_resp = { + .cause = OSMO_PFCP_CAUSE_NO_ESTABLISHED_PFCP_ASSOC, + }, + }, + { + .h = { + .version = 1, + .message_type = OSMO_PFCP_MSGT_SESSION_DEL_RESP, + .sequence_nr = 13, + .seid_present = true, + .seid = 0x0123456789abcdef, + }, + .ies.session_del_resp = { + .cause = OSMO_PFCP_CAUSE_REQUEST_ACCEPTED, + }, + }, +}; + +void test_enc_dec() +{ + int i; + for (i = 0; i < ARRAY_SIZE(tests); i++) { + void *loop_ctx = talloc_named_const(ctx, 0, "loop"); + int rc; + const struct osmo_pfcp_msg *orig = &tests[i]; + struct osmo_pfcp_msg parsed = {}; + struct msgb *msg; + struct osmo_gtlv_load tlv; + + printf("\n=== start %s[%d]\n", __func__, i); + printf("encoding: %s\n", osmo_pfcp_message_type_str(orig->h.message_type)); + printf("%s\n", osmo_pfcp_msg_to_str_c(loop_ctx, orig)); + msg = msgb_alloc(1024, __func__); + rc = osmo_pfcp_msg_encode(msg, orig); + printf("osmo_pfcp_msg_encode() rc = %d\n", rc); + printf("%s.\n", osmo_hexdump(msg->data, msg->len)); + + rc = osmo_pfcp_msg_decode_header(&tlv, &parsed, msg); + printf("osmo_pfcp_msg_decode_header() rc = %d\n", rc); + if (rc != msgb_length(msg)) { + printf("ERROR: expected rc = %d\n", msgb_length(msg)); + exit(1); + } else { + printf("rc == msgb_length()\n"); + } + + rc = osmo_pfcp_msg_decode_tlv(&parsed, &tlv); + printf("osmo_pfcp_msg_decode_tlv() rc = %d\n", rc); + + if (strcmp(osmo_pfcp_msg_to_str_c(loop_ctx, orig), + osmo_pfcp_msg_to_str_c(loop_ctx, &parsed))) { + printf(" ERROR: parsed != orig\n"); + printf(" orig: %s\n", + osmo_pfcp_msg_to_str_c(loop_ctx, orig)); + printf(" parsed: %s\n", + osmo_pfcp_msg_to_str_c(loop_ctx, &parsed)); + exit(1); + } else { + printf("parsed == orig\n"); + } + + msgb_free(msg); + printf("=== end %s[%d]\n", __func__, i); + talloc_free(loop_ctx); + } +} + +int main() +{ + ctx = talloc_named_const(NULL, 0, "pfcp_test"); + msgb_talloc_ctx_init(ctx, 0); + + test_enc_dec(); + + talloc_free(ctx); + return 0; +} diff --git a/tests/libosmo-pfcp/pfcp_test.ok b/tests/libosmo-pfcp/pfcp_test.ok new file mode 100644 index 0000000..2b8cc1a --- /dev/null +++ b/tests/libosmo-pfcp/pfcp_test.ok @@ -0,0 +1,154 @@ + +=== start test_enc_dec[0] +encoding: HEARTBEAT_REQ +PFCPv1 HEARTBEAT_REQ hdr={seq=1} ies={ 'Recovery Time Stamp'=1234 } +osmo_pfcp_msg_encode() rc = 0 +20 01 00 0c 00 00 01 00 00 60 00 04 00 00 04 d2 . +osmo_pfcp_msg_decode_header() rc = 16 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[0] + +=== start test_enc_dec[1] +encoding: HEARTBEAT_RESP +PFCPv1 HEARTBEAT_RESP hdr={seq=2} ies={ 'Recovery Time Stamp'=5678 } +osmo_pfcp_msg_encode() rc = 0 +20 02 00 0c 00 00 02 00 00 60 00 04 00 00 16 2e . +osmo_pfcp_msg_decode_header() rc = 16 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[1] + +=== start test_enc_dec[2] +encoding: ASSOC_SETUP_REQ +PFCPv1 ASSOC_SETUP_REQ hdr={seq=3} ies={ 'Node ID'=v4:4.3.2.1 'Recovery Time Stamp'=724249387 } +osmo_pfcp_msg_encode() rc = 0 +20 05 00 15 00 00 03 00 00 3c 00 05 00 04 03 02 01 00 60 00 04 2b 2b 2b 2b . +osmo_pfcp_msg_decode_header() rc = 25 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[2] + +=== start test_enc_dec[3] +encoding: ASSOC_SETUP_RESP +PFCPv1 ASSOC_SETUP_RESP hdr={seq=4} ies={ 'Node ID'=fqdn:"example.com" 'Cause'=Request accepted (success) 'Recovery Time Stamp'=724249387 'UP Function Features'=( BUCP PDIU ) } +osmo_pfcp_msg_encode() rc = 0 +20 06 00 2b 00 00 04 00 00 3c 00 0c 02 65 78 61 6d 70 6c 65 2e 63 6f 6d 00 13 00 01 01 00 60 00 04 2b 2b 2b 2b 00 2b 00 06 01 02 00 00 00 00 . +osmo_pfcp_msg_decode_header() rc = 47 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[3] + +=== start test_enc_dec[4] +encoding: ASSOC_RELEASE_REQ +PFCPv1 ASSOC_RELEASE_REQ hdr={seq=5} ies={ 'Node ID'=v6:[102:304::] } +osmo_pfcp_msg_encode() rc = 0 +20 09 00 19 00 00 05 00 00 3c 00 11 01 01 02 03 04 00 00 00 00 00 00 00 00 00 00 00 00 . +osmo_pfcp_msg_decode_header() rc = 29 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[4] + +=== start test_enc_dec[5] +encoding: ASSOC_RELEASE_RESP +PFCPv1 ASSOC_RELEASE_RESP hdr={seq=6} ies={ 'Node ID'=v4:4.3.2.1 'Cause'=Request rejected (reason not specified) } +osmo_pfcp_msg_encode() rc = 0 +20 0a 00 12 00 00 06 00 00 3c 00 05 00 04 03 02 01 00 13 00 01 40 . +osmo_pfcp_msg_decode_header() rc = 22 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[5] + +=== start test_enc_dec[6] +encoding: SESSION_EST_REQ +PFCPv1 SESSION_EST_REQ hdr={seq=7 SEID=0x0} ies={ 'Node ID'=v4:127.0.0.1 'F-SEID'=0x1234567890abcdef,v4:10.9.8.7 'Create PDR'={ { 'PDR ID'=1 'Precedence'=255 'PDI'={ 'Source Interface'=Core 'UE IP Address'=,dst,v4:192.168.0.23 } 'FAR ID'=1 }, { 'PDR ID'=2 'Precedence'=255 'PDI'={ 'Source Interface'=Access 'F-TEID'=CHOOSE-v4 } 'Outer Header Removal'=GTP_U_UDP_IPV4 'FAR ID'=2 } } 'Create FAR'={ { 'FAR ID'=1 'Apply Action'=( FORW ) 'Forwarding Parameters'={ 'Destination Interface'=Access 'Outer Header Creation'=( GTP_U_UDP_IPV4 ),TEID:0xabcdef,v4:10.9.8.7 } }, { 'FAR ID'=2 'Apply Action'=( FORW ) 'Forwarding Parameters'={ 'Destination Interface'=Core } } } } +osmo_pfcp_msg_encode() rc = 0 +21 32 00 c3 00 00 00 00 00 00 00 00 00 00 07 00 00 3c 00 05 00 7f 00 00 01 00 39 00 0d 02 12 34 56 78 90 ab cd ef 0a 09 08 07 00 01 00 28 00 38 00 02 00 01 00 1d 00 04 00 00 00 ff 00 02 00 0e 00 14 00 01 01 00 5d 00 05 06 c0 a8 00 17 00 6c 00 04 00 00 00 01 00 01 00 29 00 38 00 02 00 02 00 1d 00 04 00 00 00 ff 00 02 00 0a 00 14 00 01 00 00 15 00 01 05 00 5f 00 01 00 00 6c 00 04 00 00 00 02 00 03 00 25 00 6c 00 04 00 00 00 01 00 2c 00 02 02 00 00 04 00 13 00 2a 00 01 00 00 54 00 0a 01 00 00 ab cd ef 0a 09 08 07 00 03 00 17 00 6c 00 04 00 00 00 02 00 2c 00 02 02 00 00 04 00 05 00 2a 00 01 01 . +osmo_pfcp_msg_decode_header() rc = 199 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[6] + +=== start test_enc_dec[7] +encoding: SESSION_EST_RESP +PFCPv1 SESSION_EST_RESP hdr={seq=8 SEID=0x123456789abcdef} ies={ 'Node ID'=v4:127.0.0.2 'Cause'=Request accepted (success) 'F-SEID'=0x1234567890abcdef,v4:10.9.8.7 'Created PDR'={ { 'PDR ID'=1 }, { 'PDR ID'=2 'F-TEID'=TEID-0x4d2,v4:10.9.8.7 } } } +osmo_pfcp_msg_encode() rc = 0 +21 33 00 4c 01 23 45 67 89 ab cd ef 00 00 08 00 00 3c 00 05 00 7f 00 00 02 00 13 00 01 01 00 39 00 0d 02 12 34 56 78 90 ab cd ef 0a 09 08 07 00 08 00 06 00 38 00 02 00 01 00 08 00 13 00 38 00 02 00 02 00 15 00 09 01 00 00 04 d2 0a 09 08 07 . +osmo_pfcp_msg_decode_header() rc = 80 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[7] + +=== start test_enc_dec[8] +encoding: SESSION_MOD_REQ +PFCPv1 SESSION_MOD_REQ hdr={seq=9 SEID=0x0} ies={ 'Remove PDR'={ { 'PDR ID'=1 } } 'Remove FAR'={ { 'FAR ID'=1 } } 'Create PDR'={ { 'PDR ID'=3 'Precedence'=255 'PDI'={ 'Source Interface'=Access 'F-TEID'=CHOOSE-v4 } 'Outer Header Removal'=GTP_U_UDP_IPV4 'FAR ID'=3 } } 'Create FAR'={ { 'FAR ID'=3 'Apply Action'=( FORW ) 'Forwarding Parameters'={ 'Destination Interface'=Access 'Outer Header Creation'=( GTP_U_UDP_IPV4 ),TEID:0xabcdef,v4:10.9.8.7 } } } 'Update PDR'={ { 'PDR ID'=1 'Outer Header Removal'=GTP_U_UDP_IPV4 'FAR ID'=1 } } 'Update FAR'={ { 'FAR ID'=1 'Update Forwarding Parameters'={ 'Network Instance'="internet" } } } } +osmo_pfcp_msg_encode() rc = 0 +21 34 00 ab 00 00 00 00 00 00 00 00 00 00 09 00 00 0f 00 06 00 38 00 02 00 01 00 10 00 08 00 6c 00 04 00 00 00 01 00 01 00 29 00 38 00 02 00 03 00 1d 00 04 00 00 00 ff 00 02 00 0a 00 14 00 01 00 00 15 00 01 05 00 5f 00 01 00 00 6c 00 04 00 00 00 03 00 03 00 25 00 6c 00 04 00 00 00 03 00 2c 00 02 02 00 00 04 00 13 00 2a 00 01 00 00 54 00 0a 01 00 00 ab cd ef 0a 09 08 07 00 09 00 13 00 38 00 02 00 01 00 5f 00 01 00 00 6c 00 04 00 00 00 01 00 0a 00 18 00 6c 00 04 00 00 00 01 00 0b 00 0c 00 16 00 08 69 6e 74 65 72 6e 65 74 . +osmo_pfcp_msg_decode_header() rc = 175 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[8] + +=== start test_enc_dec[9] +encoding: SESSION_MOD_RESP +PFCPv1 SESSION_MOD_RESP hdr={seq=10 SEID=0x123456789abcdef} ies={ 'Cause'=Request accepted (success) 'Created PDR'={ { 'PDR ID'=3 'F-TEID'=TEID-0x4d2,v4:10.9.8.7 } } 'Updated PDR'={ { 'PDR ID'=1 'F-TEID'=TEID-0x4d2,v4:10.9.8.7 } } } +osmo_pfcp_msg_encode() rc = 0 +21 35 00 3f 01 23 45 67 89 ab cd ef 00 00 0a 00 00 13 00 01 01 00 08 00 13 00 38 00 02 00 03 00 15 00 09 01 00 00 04 d2 0a 09 08 07 01 00 00 13 00 38 00 02 00 01 00 15 00 09 01 00 00 04 d2 0a 09 08 07 . +osmo_pfcp_msg_decode_header() rc = 67 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[9] + +=== start test_enc_dec[10] +encoding: SESSION_MOD_RESP +PFCPv1 SESSION_MOD_RESP hdr={seq=11 SEID=0x123456789abcdef} ies={ 'Cause'=Mandatory IE missing 'Offending IE'=Apply Action } +osmo_pfcp_msg_encode() rc = 0 +21 35 00 17 01 23 45 67 89 ab cd ef 00 00 0b 00 00 13 00 01 42 00 28 00 02 00 2c . +osmo_pfcp_msg_decode_header() rc = 27 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[10] + +=== start test_enc_dec[11] +encoding: SESSION_DEL_REQ +PFCPv1 SESSION_DEL_REQ hdr={seq=12 SEID=0x123456789abcdef} ies={ } +osmo_pfcp_msg_encode() rc = 0 +21 36 00 0c 01 23 45 67 89 ab cd ef 00 00 0c 00 . +osmo_pfcp_msg_decode_header() rc = 16 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[11] + +=== start test_enc_dec[12] +encoding: SESSION_DEL_RESP +PFCPv1 SESSION_DEL_RESP hdr={seq=13 SEID=0x123456789abcdef} ies={ 'Cause'=No established PFCP Association } +osmo_pfcp_msg_encode() rc = 0 +21 37 00 11 01 23 45 67 89 ab cd ef 00 00 0d 00 00 13 00 01 48 . +osmo_pfcp_msg_decode_header() rc = 21 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[12] + +=== start test_enc_dec[13] +encoding: SESSION_DEL_RESP +PFCPv1 SESSION_DEL_RESP hdr={seq=13 SEID=0x123456789abcdef} ies={ 'Cause'=Request accepted (success) } +osmo_pfcp_msg_encode() rc = 0 +21 37 00 11 01 23 45 67 89 ab cd ef 00 00 0d 00 00 13 00 01 01 . +osmo_pfcp_msg_decode_header() rc = 21 +rc == msgb_length() +osmo_pfcp_msg_decode_tlv() rc = 0 +parsed == orig +=== end test_enc_dec[13] diff --git a/tests/testsuite.at b/tests/testsuite.at index 0d17305..a365f0e 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -24,3 +24,9 @@ cat $abs_srcdir/libosmo-gtlv/test_tliv/tliv_test.ok > expout AT_CHECK([$abs_top_builddir/tests/libosmo-gtlv/test_tliv/tliv_test], [], [expout], [ignore]) AT_CLEANUP + +AT_SETUP([pfcp]) +AT_KEYWORDS([pfcp]) +cat $abs_srcdir/libosmo-pfcp/pfcp_test.ok > expout +AT_CHECK([$abs_top_builddir/tests/libosmo-pfcp/pfcp_test], [], [expout], [ignore]) +AT_CLEANUP 8 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. -- To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/27638 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-upf Gerrit-Branch: master Gerrit-Change-Id: I30bdfc66a8f96c0639513ef406e9b66525dced6d Gerrit-Change-Number: 27638 Gerrit-PatchSet: 9 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in osmo-upf[master]: add pfcp msg test
by neels 08 Jun '22

08 Jun '22
Hello Jenkins Builder, laforge, pespin, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/osmo-upf/+/27638 to look at the new patch set (#9). Change subject: add pfcp msg test ...................................................................... add pfcp msg test Related: SYS#5599 Change-Id: I30bdfc66a8f96c0639513ef406e9b66525dced6d --- M configure.ac M tests/Makefile.am A tests/libosmo-pfcp/Makefile.am A tests/libosmo-pfcp/pfcp_test.c A tests/libosmo-pfcp/pfcp_test.ok M tests/testsuite.at 6 files changed, 706 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/38/27638/9 -- To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/27638 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-upf Gerrit-Branch: master Gerrit-Change-Id: I30bdfc66a8f96c0639513ef406e9b66525dced6d Gerrit-Change-Number: 27638 Gerrit-PatchSet: 9 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: newpatchset
1 0
0 0
Change in osmo-upf[master]: libosmo-pfcp: implement PFCP header and msg handling
by neels 08 Jun '22

08 Jun '22
neels has submitted this change. ( https://gerrit.osmocom.org/c/osmo-upf/+/27631 ) Change subject: libosmo-pfcp: implement PFCP header and msg handling ...................................................................... libosmo-pfcp: implement PFCP header and msg handling Related: SYS#5599 Change-Id: I3f85ea052a6b7c064244a8093777e53a47c8c61e --- M include/osmocom/pfcp/Makefile.am A include/osmocom/pfcp/pfcp_msg.h M src/libosmo-pfcp/Makefile.am M src/libosmo-pfcp/pfcp_ies_custom.c A src/libosmo-pfcp/pfcp_msg.c 5 files changed, 741 insertions(+), 1 deletion(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve pespin: Looks good to me, but someone else must approve neels: Looks good to me, approved diff --git a/include/osmocom/pfcp/Makefile.am b/include/osmocom/pfcp/Makefile.am index 65b0102..7bd5ea3 100644 --- a/include/osmocom/pfcp/Makefile.am +++ b/include/osmocom/pfcp/Makefile.am @@ -1,6 +1,7 @@ pfcp_HEADERS = \ pfcp_ies_custom.h \ pfcp_ies_auto.h \ + pfcp_msg.h \ pfcp_proto.h \ pfcp_strs.h \ $(NULL) diff --git a/include/osmocom/pfcp/pfcp_msg.h b/include/osmocom/pfcp/pfcp_msg.h new file mode 100644 index 0000000..949800e --- /dev/null +++ b/include/osmocom/pfcp/pfcp_msg.h @@ -0,0 +1,197 @@ +/* PFCP message encoding and decoding */ +/* + * (C) 2021-2022 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * All Rights Reserved. + * + * Author: Neels Janosch Hofmeyr <nhofmeyr(a)sysmocom.de> + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 <http://www.gnu.org/licenses/>. + * + */ + +#pragma once + +#include <stdint.h> +#include <stdbool.h> +#include <inttypes.h> + +#include <osmocom/core/socket.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/fsm.h> + +#include <osmocom/pfcp/pfcp_proto.h> +#include <osmocom/pfcp/pfcp_ies_auto.h> +#include <osmocom/pfcp/pfcp_strs.h> + +struct msgb; +struct osmo_t16l16v_ie; +struct osmo_pfcp_msg; + +#define OSMO_PFCP_MSGB_ALLOC_SIZE 2048 + +#define OSMO_LOG_PFCP_MSG_SRC(M, LEVEL, file, line, FMT, ARGS...) do { \ + struct osmo_fsm_inst *_fi = (M) ? ((M)->ctx.session_fi ?: (M)->ctx.peer_fi) : NULL; \ + enum osmo_pfcp_cause *cause = osmo_pfcp_msg_cause(M); \ + if ((M)->h.seid_present) { \ + LOGPFSMSLSRC(_fi, DLPFCP, LEVEL, file, line, \ + "%s%s PFCP seq-%u SEID-0x%"PRIx64" %s%s%s: " FMT, \ + _fi ? "" : osmo_sockaddr_to_str_c(OTC_SELECT, &(M)->remote_addr), \ + (M)->rx ? "-rx->" : "<-tx-", (M)->h.sequence_nr, \ + (M)->h.seid, \ + osmo_pfcp_message_type_str((M)->h.message_type), cause ? ": " : "", \ + cause ? osmo_pfcp_cause_str(*cause) : "", ##ARGS); \ + } else { \ + LOGPFSMSLSRC(_fi, DLPFCP, LEVEL, file, line, \ + "%s%s PFCP seq-%u %s%s%s: " FMT, \ + _fi ? "" : osmo_sockaddr_to_str_c(OTC_SELECT, &(M)->remote_addr), \ + (M)->rx ? "-rx->" : "<-tx-", (M)->h.sequence_nr, \ + osmo_pfcp_message_type_str((M)->h.message_type), cause ? ": " : "", \ + cause ? osmo_pfcp_cause_str(*cause) : "", ##ARGS); \ + } \ + } while (0) + +#define OSMO_LOG_PFCP_MSG(M, LEVEL, FMT, ARGS...) \ + OSMO_LOG_PFCP_MSG_SRC(M, LEVEL, __FILE__, __LINE__, FMT, ##ARGS) + +struct osmo_pfcp_header_parsed { + uint8_t version; + enum osmo_pfcp_message_type message_type; + uint32_t sequence_nr; + bool priority_present; + uint8_t priority; + bool seid_present; + uint64_t seid; +}; + +/* For PFCP requests, notify when a PFCP response has arrived, or when the PFCP response timed out. + * When rx_resp == NULL, receiving a response timed out or the response could not be decoded. + * On error, errmsg may convey a human readable error message. + * Return 1 to also pass rx_resp to osmo_pfcp_endpoint->rx_msg(), return 0 to mark rx_resp handled and not pass it to + * rx_msg() (to save lookup iterations). Return negative on error, rx_resp is dropped. + * Find in req the original osmo_pfcp_msg instance; in req->ctx.priv, arbitrary user data may be passed. + * For example: + * + * static int on_foo_resp(struct osmo_pfcp_msg *req, struct osmo_pfcp_msg *rx_resp, const char *errmsg) + * { + * struct something *obj = req->ctx.priv; + * if (!rx_resp) { + * handle_error(); + * return 0; + * } + * handle_response(obj, rx_resp); + * return 0; + * } + * + * int do_request(struct something *obj) + * { + * struct osmo_pfcp_msg *req; + * req = osmo_pfcp_msg_alloc_tx(pfcp_ep, &upf_addr, &pfcp_ep->cfg.local_node_id, NULL, OSMO_PFCP_MSGT_FOO); + * req->h.seid_present = true; + * req->h.seid = remote_seid; + * req->ies.foo... = ...; + * req->ctx.on_resp = on_foo_resp; + * req->ctx.priv = obj; + * return osmo_pfcp_endpoint_tx(pfcp_ep, req); + * } + */ +typedef int (*osmo_pfcp_resp_cb)(struct osmo_pfcp_msg *req, struct osmo_pfcp_msg *rx_resp, const char *errmsg); + +struct osmo_pfcp_msg { + /* Peer's remote address. Received from this peer, or should be sent to this peer. */ + struct osmo_sockaddr remote_addr; + /* True when this message was received from a remote; false when this message is going to be sent. */ + bool rx; + /* True when this message is a Response message type; false if Request. This is set by + * osmo_pfcp_msg_decode() for received messages, and by osmo_pfcp_msg_alloc_tx */ + bool is_response; + + struct osmo_pfcp_header_parsed h; + + int ofs_cause; + int ofs_node_id; + + /* The union of decoded IEs from all supported PFCP message types. The union and its structure is defined in + * pfcp_ies_auto.h, which is generated by gen__pfcp_ies_auto.c. + */ + union osmo_pfcp_ies ies; + + /* Context information about this message, used for logging */ + struct { + /* Peer FSM instance that this message is received from / sent to. This can be set in the + * osmo_pfcp_endpoint->set_msg_ctx() implementation, up to the caller. If present, this is used for + * logging context, and can also be used by the caller to reduce lookup iterations. */ + struct osmo_fsm_inst *peer_fi; + struct osmo_use_count *peer_use_count; + const char *peer_use_token; + + /* Session FSM instance that this message is received from / sent to. This can be set in the + * osmo_pfcp_endpoint->set_msg_ctx() implementation, up to the caller. If present, this is used for + * logging context, and can also be used by the caller to reduce lookup iterations. */ + struct osmo_fsm_inst *session_fi; + struct osmo_use_count *session_use_count; + const char *session_use_token; + + osmo_pfcp_resp_cb resp_cb; + void *priv; + } ctx; +}; + +/* Given a &osmo_pfcp_msg->ies pointer, return the &osmo_pfcp_msg. + * In the TLV API, only the 'ies' union is passed around as argument. This macro is useful in error callbacks to obtain + * the related osmo_pfcp_msg and thus the logging context pointers (ctx.peer_fi and ctx.session_fi). */ +#define OSMO_PFCP_MSG_FOR_IES(IES_P) ((struct osmo_pfcp_msg *)((char *)IES_P - offsetof(struct osmo_pfcp_msg, ies))) + +bool osmo_pfcp_msgtype_is_response(enum osmo_pfcp_message_type message_type); + +int osmo_pfcp_ie_f_teid_to_str_buf(char *buf, size_t len, const struct osmo_pfcp_ie_f_teid *ft); +char *osmo_pfcp_ie_f_teid_to_str_c(void *ctx, const struct osmo_pfcp_ie_f_teid *ft); + +int osmo_pfcp_msg_encode(struct msgb *msg, const struct osmo_pfcp_msg *pfcp_msg); + +int osmo_pfcp_msg_decode_header(struct osmo_gtlv_load *tlv, struct osmo_pfcp_msg *m, + const struct msgb *msg); +int osmo_pfcp_msg_decode_tlv(struct osmo_pfcp_msg *m, struct osmo_gtlv_load *tlv); + +struct osmo_pfcp_msg *osmo_pfcp_msg_alloc_rx(void *ctx, const struct osmo_sockaddr *remote_addr); +struct osmo_pfcp_msg *osmo_pfcp_msg_alloc_tx(void *ctx, const struct osmo_sockaddr *remote_addr, + const struct osmo_pfcp_ie_node_id *local_node_id, + const struct osmo_pfcp_msg *in_reply_to, + enum osmo_pfcp_message_type msg_type); + +void osmo_pfcp_msg_invalidate_ctx(struct osmo_pfcp_msg *m, struct osmo_fsm_inst *deleted_fi); + +void osmo_pfcp_msg_free(struct osmo_pfcp_msg *m); + +uint32_t osmo_pfcp_next_seq_nr(uint32_t *next_seq_nr_state); +uint64_t osmo_pfcp_next_seid(uint64_t *next_seid_state); + +int osmo_pfcp_ie_node_id_from_osmo_sockaddr(struct osmo_pfcp_ie_node_id *node_id, const struct osmo_sockaddr *os); +int osmo_pfcp_ie_node_id_to_osmo_sockaddr(const struct osmo_pfcp_ie_node_id *node_id, struct osmo_sockaddr *os); + +#define OSMO_PFCP_MSG_MEMB(M, OFS) ((OFS) <= 0 ? NULL : (void *)((uint8_t *)(M) + OFS)) + +static inline enum osmo_pfcp_cause *osmo_pfcp_msg_cause(const struct osmo_pfcp_msg *m) +{ + return OSMO_PFCP_MSG_MEMB(m, m->ofs_cause); +} + +static inline struct osmo_pfcp_ie_node_id *osmo_pfcp_msg_node_id(const struct osmo_pfcp_msg *m) +{ + return OSMO_PFCP_MSG_MEMB(m, m->ofs_node_id); +} + +int osmo_pfcp_msg_to_str_buf(char *buf, size_t buflen, const struct osmo_pfcp_msg *m); +char *osmo_pfcp_msg_to_str_c(void *ctx, const struct osmo_pfcp_msg *m); diff --git a/src/libosmo-pfcp/Makefile.am b/src/libosmo-pfcp/Makefile.am index 0e249f9..c8accb9 100644 --- a/src/libosmo-pfcp/Makefile.am +++ b/src/libosmo-pfcp/Makefile.am @@ -25,6 +25,7 @@ libosmo_pfcp_a_SOURCES = \ pfcp_ies_custom.c \ + pfcp_msg.c \ pfcp_strs.c \ \ pfcp_ies_auto.c \ diff --git a/src/libosmo-pfcp/pfcp_ies_custom.c b/src/libosmo-pfcp/pfcp_ies_custom.c index 5975a29..3b3769a 100644 --- a/src/libosmo-pfcp/pfcp_ies_custom.c +++ b/src/libosmo-pfcp/pfcp_ies_custom.c @@ -34,12 +34,13 @@ #include <osmocom/pfcp/pfcp_ies_custom.h> #include <osmocom/pfcp/pfcp_strs.h> +#include <osmocom/pfcp/pfcp_msg.h> /* Assumes presence of local variable osmo_pfcp_msg *m. m->log_ctx may be NULL. */ #define RETURN_ERROR(RC, FMT, ARGS...) \ do {\ OSMO_ASSERT(decoded_struct); \ - LOGP(DLPFCP, LOGL_ERROR, FMT " (%d: %s)\n", ##ARGS, RC, \ + OSMO_LOG_PFCP_MSG(OSMO_PFCP_MSG_FOR_IES(decoded_struct), LOGL_ERROR, FMT " (%d: %s)\n", ##ARGS, RC, \ strerror((RC) > 0 ? (RC) : -(RC))); \ return RC; \ } while (0) diff --git a/src/libosmo-pfcp/pfcp_msg.c b/src/libosmo-pfcp/pfcp_msg.c new file mode 100644 index 0000000..9d65efc --- /dev/null +++ b/src/libosmo-pfcp/pfcp_msg.c @@ -0,0 +1,540 @@ +/* + * (C) 2021-2022 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * All Rights Reserved. + * + * Author: Neels Janosch Hofmeyr <nhofmeyr(a)sysmocom.de> + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 <http://www.gnu.org/licenses/>. + * + */ + +#include <errno.h> +#include <string.h> + +#include <osmocom/core/endian.h> +#include <osmocom/core/logging.h> +#include <osmocom/core/fsm.h> +#include <osmocom/core/use_count.h> +#include <osmocom/core/bitvec.h> + +#include <osmocom/pfcp/pfcp_msg.h> +#include <osmocom/gtlv/gtlv_dec_enc.h> + +/* Assumes presence of local variable osmo_pfcp_msg *m. m->log_ctx may be NULL. */ +#define RETURN_ERROR(RC, FMT, ARGS...) \ + do {\ + OSMO_ASSERT(m); \ + OSMO_LOG_PFCP_MSG(m, LOGL_ERROR, FMT " (%d: %s)\n", ##ARGS, RC, strerror((RC) > 0 ? (RC) : -(RC))); \ + return RC; \ + } while (0) + +bool osmo_pfcp_msgtype_is_response(enum osmo_pfcp_message_type message_type) +{ + switch (message_type) { + case OSMO_PFCP_MSGT_HEARTBEAT_RESP: + case OSMO_PFCP_MSGT_PFD_MGMT_RESP: + case OSMO_PFCP_MSGT_ASSOC_SETUP_RESP: + case OSMO_PFCP_MSGT_ASSOC_UPDATE_RESP: + case OSMO_PFCP_MSGT_ASSOC_RELEASE_RESP: + case OSMO_PFCP_MSGT_VERSION_NOT_SUPP_RESP: + case OSMO_PFCP_MSGT_NODE_REPORT_RESP: + case OSMO_PFCP_MSGT_SESSION_SET_DEL_RESP: + case OSMO_PFCP_MSGT_SESSION_EST_RESP: + case OSMO_PFCP_MSGT_SESSION_MOD_RESP: + case OSMO_PFCP_MSGT_SESSION_DEL_RESP: + case OSMO_PFCP_MSGT_SESSION_REP_RESP: + return true; + default: + return false; + } +} + +struct osmo_pfcp_header_common { +#if OSMO_IS_LITTLE_ENDIAN + uint8_t seid_present:1, + message_priority_present:1, + follow_on:1, + spare:2, + version:3; + uint8_t message_type; + uint16_t message_length; +#elif OSMO_IS_BIG_ENDIAN +/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ + uint8_t version:3, spare:2, follow_on:1, message_priority_present:1, seid_present:1; + uint8_t message_type; + uint16_t message_length; +#endif +} __attribute__ ((packed)); + +struct osmo_pfcp_header_no_seid { + struct osmo_pfcp_header_common c; + uint8_t sequence_nr[3]; + uint8_t spare; +} __attribute__ ((packed)); + +struct osmo_pfcp_header_seid { +#if OSMO_IS_LITTLE_ENDIAN + struct osmo_pfcp_header_common c; + uint64_t session_endpoint_identifier; + uint8_t sequence_nr[3]; + uint8_t message_priority:4, + spare:4; +#elif OSMO_IS_BIG_ENDIAN +/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */ + struct osmo_pfcp_header_common c; + uint64_t session_endpoint_identifier; + uint8_t sequence_nr[3]; + uint8_t spare:4, message_priority:4; +#endif +} __attribute__ ((packed)); + +int osmo_pfcp_ie_node_id_from_osmo_sockaddr(struct osmo_pfcp_ie_node_id *node_id, const struct osmo_sockaddr *os) +{ + switch (os->u.sa.sa_family) { + case AF_INET: + node_id->type = OSMO_PFCP_NODE_ID_T_IPV4; + break; + case AF_INET6: + node_id->type = OSMO_PFCP_NODE_ID_T_IPV6; + break; + default: + return -ENOTSUP; + } + node_id->ip = *os; + return 0; +} + +int osmo_pfcp_ie_node_id_to_osmo_sockaddr(const struct osmo_pfcp_ie_node_id *node_id, struct osmo_sockaddr *os) +{ + switch (node_id->type) { + case OSMO_PFCP_NODE_ID_T_IPV4: + if (os->u.sa.sa_family != AF_INET) + return -EINVAL; + break; + case OSMO_PFCP_NODE_ID_T_IPV6: + if (os->u.sa.sa_family != AF_INET6) + return -EINVAL; + break; + default: + return -ENOTSUP; + } + *os = node_id->ip; + return 0; +} + +static int pfcp_header_set_message_length(struct osmo_pfcp_header_common *c, unsigned int header_and_payload_len) +{ + if (header_and_payload_len < sizeof(struct osmo_pfcp_header_common)) + return -EINVAL; + if (header_and_payload_len - sizeof(struct osmo_pfcp_header_common) > UINT16_MAX) + return -EMSGSIZE; + osmo_store16be(header_and_payload_len - sizeof(struct osmo_pfcp_header_common), + &c->message_length); + return 0; +} + +static unsigned int pfcp_header_get_message_length(const struct osmo_pfcp_header_common *c) +{ + unsigned int len = osmo_load16be(&c->message_length); + return len + sizeof(struct osmo_pfcp_header_common); +} + +/*! Encode and append the given PFCP header to a msgb. + * \param[out] msg message buffer to which to push the header. + * \param[in] to-be-encoded representation of PFCP header. */ +static int enc_pfcp_header(struct msgb *msg, const struct osmo_pfcp_msg *m) +{ + const struct osmo_pfcp_header_parsed *parsed = &m->h; + struct osmo_pfcp_header_seid *h_seid; + struct osmo_pfcp_header_no_seid *h_no_seid; + struct osmo_pfcp_header_common *c; + int rc; + + if (!parsed->seid_present) { + h_no_seid = (struct osmo_pfcp_header_no_seid *)msgb_put(msg, sizeof(struct osmo_pfcp_header_no_seid)); + c = &h_no_seid->c; + } else { + h_seid = (struct osmo_pfcp_header_seid *)msgb_put(msg, sizeof(struct osmo_pfcp_header_seid)); + c = &h_seid->c; + } + + *c = (struct osmo_pfcp_header_common){ + .version = parsed->version, + .message_priority_present = (parsed->priority_present ? 1 : 0), + .seid_present = (parsed->seid_present ? 1 : 0), + .message_type = parsed->message_type, + }; + + /* Put a preliminary length reflecting only the header, until it is updated later in osmo_pfcp_msg_encode(). */ + rc = pfcp_header_set_message_length(c, parsed->seid_present ? sizeof(struct osmo_pfcp_header_seid) + : sizeof(struct osmo_pfcp_header_no_seid)); + if (rc) + RETURN_ERROR(rc, "Problem with PFCP message length"); + + if (!parsed->seid_present) { + osmo_store32be_ext(parsed->sequence_nr, h_no_seid->sequence_nr, 3); + if (parsed->priority_present) + RETURN_ERROR(-EINVAL, "Message Priority can only be present when the SEID is also present"); + } else { + osmo_store64be(parsed->seid, &h_seid->session_endpoint_identifier); + osmo_store32be_ext(parsed->sequence_nr, h_seid->sequence_nr, 3); + if (parsed->priority_present) + h_seid->message_priority = parsed->priority; + } + + return 0; +} + +static void osmo_pfcp_msg_set_memb_ofs(struct osmo_pfcp_msg *m) +{ + const struct osmo_gtlv_coding *mc = osmo_pfcp_get_msg_coding(m->h.message_type); + m->ofs_cause = 0; + m->ofs_node_id = 0; + if (!mc) + return; + for (; !osmo_gtlv_coding_end(mc) && (m->ofs_cause == 0 || m->ofs_node_id == 0); mc++) { + if (mc->ti.tag == OSMO_PFCP_IEI_CAUSE) + m->ofs_cause = offsetof(struct osmo_pfcp_msg, ies) + mc->memb_ofs; + if (mc->ti.tag == OSMO_PFCP_IEI_NODE_ID) + m->ofs_node_id = offsetof(struct osmo_pfcp_msg, ies) + mc->memb_ofs; + } +}; + +/*! Decode a single PFCP message's header. + * + * If msg->l4h is non-NULL, decode at msgb_l4(msg). If l4h is NULL, decode at msgb_l3(msg). + * In case of bundled PFCP messages, decode only one message and return the offset to the next message in the buffer. + * Hence, to decode a message bundle, increment msg->l4h until all messages are decoded: + * + * msg->l4h = msg->l3h; + * while (msgb_l4len(msg)) { + * struct osmo_pfcp_msg m; + * struct osmo_gtlv_load tlv; + * int rc; + * rc = osmo_pfcp_msg_decode_header(&tlv, &m, msg); + * if (rc < 0) + * error(); + * msg->l4h += rc; + * + * if (osmo_pfcp_msg_decode_tlv(&m, &tlv)) + * error(); + * handle(&m); + * } + * + * \param[out] tlv Return TLV start pointer and length in tlv->src.*. + * \param[inout] m Place the decoded data in m->h; use m->ctx.* as logging context. + * \param[in] msg PFCP data to parse, possibly containing a PFCP message bundle. + * \return total single PFCP message length (<= data_len) on success, negative on error. + */ +int osmo_pfcp_msg_decode_header(struct osmo_gtlv_load *tlv, struct osmo_pfcp_msg *m, + const struct msgb *msg) +{ + struct osmo_pfcp_header_parsed *parsed = &m->h; + const uint8_t *pfcp_msg_data; + unsigned int pfcp_msg_data_len; + unsigned int header_len; + unsigned int message_length; + const struct osmo_pfcp_header_common *c; + + if (msg->l4h) { + pfcp_msg_data = msgb_l4(msg); + pfcp_msg_data_len = msgb_l4len(msg); + } else { + pfcp_msg_data = msgb_l3(msg); + pfcp_msg_data_len = msgb_l3len(msg); + } + + if (!pfcp_msg_data || !pfcp_msg_data_len) + RETURN_ERROR(-EINVAL, "No Layer 3 data in this message buffer"); + + if (pfcp_msg_data_len < sizeof(struct osmo_pfcp_header_common)) + RETURN_ERROR(-EINVAL, "Message too short for PFCP header: %u", pfcp_msg_data_len); + + c = (void *)pfcp_msg_data; + + header_len = (c->seid_present ? sizeof(struct osmo_pfcp_header_seid) : sizeof(struct osmo_pfcp_header_no_seid)); + if (pfcp_msg_data_len < header_len) + RETURN_ERROR(-EINVAL, "Message too short for PFCP header: %u", pfcp_msg_data_len); + + *parsed = (struct osmo_pfcp_header_parsed){ + .version = c->version, + .priority_present = (bool)c->message_priority_present, + .seid_present = (bool)c->seid_present, + .message_type = c->message_type, + }; + + m->is_response = osmo_pfcp_msgtype_is_response(parsed->message_type); + osmo_pfcp_msg_set_memb_ofs(m); + + message_length = pfcp_header_get_message_length(c); + if (message_length > pfcp_msg_data_len) + RETURN_ERROR(-EMSGSIZE, + "The header's indicated total message length %u is larger than the received data %u", + message_length, pfcp_msg_data_len); + + /* T16L16V payload data and len */ + *tlv = (struct osmo_gtlv_load){ + .cfg = &osmo_t16l16v_cfg, + .src = { + .data = pfcp_msg_data + header_len, + .len = message_length - header_len, + }, + }; + + if (c->follow_on) { + /* Another PFCP message should follow */ + if (pfcp_msg_data_len - message_length < sizeof(struct osmo_pfcp_header_common)) + OSMO_LOG_PFCP_MSG(m, LOGL_INFO, + "PFCP message indicates more messages should follow in the bundle," + " but remaining size %u is too short", pfcp_msg_data_len - message_length); + } else { + /* No more PFCP message should follow in the bundle */ + if (pfcp_msg_data_len > message_length) + OSMO_LOG_PFCP_MSG(m, LOGL_INFO, "Surplus data after PFCP message: %u", + pfcp_msg_data_len - message_length); + } + + if (!parsed->seid_present) { + const struct osmo_pfcp_header_no_seid *h_no_seid = (void *)pfcp_msg_data; + parsed->sequence_nr = osmo_load32be_ext_2(h_no_seid->sequence_nr, 3); + if (parsed->priority_present) + RETURN_ERROR(-EINVAL, "Message Priority can only be present when the SEID is also present"); + } else { + const struct osmo_pfcp_header_seid *h_seid = (void *)pfcp_msg_data; + parsed->seid = osmo_load64be(&h_seid->session_endpoint_identifier); + parsed->sequence_nr = osmo_load32be_ext_2(h_seid->sequence_nr, 3); + if (parsed->priority_present) + parsed->priority = h_seid->message_priority; + } + + return message_length; +} + +void osmo_pfcp_msg_err_cb(void *data, void *decoded_struct, const char *file, int line, const char *fmt, ...) +{ + va_list ap; + if (log_check_level(DLPFCP, LOGL_ERROR)) { + char *errmsg; + + va_start(ap, fmt); + errmsg = talloc_vasprintf(OTC_SELECT, fmt, ap); + va_end(ap); + OSMO_LOG_PFCP_MSG_SRC((struct osmo_pfcp_msg *)data, LOGL_ERROR, file, line, "%s", errmsg); + } +} + +int osmo_pfcp_msg_decode_tlv(struct osmo_pfcp_msg *m, struct osmo_gtlv_load *tlv) +{ + return osmo_pfcp_ies_decode(&m->ies, tlv, false, m->h.message_type, osmo_pfcp_msg_err_cb, m, osmo_pfcp_iei_strs); +} + +static int osmo_pfcp_msg_encode_tlv(struct msgb *msg, const struct osmo_pfcp_msg *m) +{ + struct osmo_gtlv_put tlv = { + .cfg = &osmo_t16l16v_cfg, + .dst = msg, + }; + return osmo_pfcp_ies_encode(&tlv, &m->ies, m->h.message_type, osmo_pfcp_msg_err_cb, (void *)m, osmo_pfcp_iei_strs); +} + +/* Append the encoded PFCP message to the message buffer. + * + * If msg->l3h is NULL, point it at the start of the encoded message. + * Always point msg->l4h at the start of the newly encoded message. + * Hence, in a message bundle, msg->l3h always points at the first PFCP message, while msg->l4h always points at the + * last PFCP message. + * + * When adding a PFCP message to a bundle, set the Follow On (FO) flag of the previously last message to 1, and of the + * newly encoded, now last message as 0. + * + * To log errors to a specific osmo_fsm_inst, point m->log_ctx to that instance before calling this function. Otherwise + * set log_ctx = NULL. + * + * \return 0 on success, negative on error. */ +int osmo_pfcp_msg_encode(struct msgb *msg, const struct osmo_pfcp_msg *m) +{ + struct osmo_pfcp_header_common *c; + int rc; + + /* Forming a bundle? If yes, set the Follow On flag of the currently last message to 1 */ + if (msg->l4h && msgb_l4len(msg)) { + c = msgb_l4(msg); + c->follow_on = 1; + } + /* Make sure l3h points at the first PFCP message in a message bundle */ + if (!msg->l3h) + msg->l3h = msg->tail; + /* Make sure l4h points at the last PFCP message in a message bundle */ + msg->l4h = msg->tail; + c = (void *)msg->tail; + + rc = enc_pfcp_header(msg, m); + if (rc) + return rc; + + rc = osmo_pfcp_msg_encode_tlv(msg, m); + if (rc) + return rc; + + /* Update the header's message_length */ + rc = pfcp_header_set_message_length(c, msgb_l4len(msg)); + if (rc) + RETURN_ERROR(rc, "Problem with PFCP message length"); + return 0; +} + +static int osmo_pfcp_msg_destructor(struct osmo_pfcp_msg *m); + +static struct osmo_pfcp_msg *_osmo_pfcp_msg_alloc(void *ctx, const struct osmo_sockaddr *remote_addr) +{ + struct osmo_pfcp_msg *m = talloc(ctx, struct osmo_pfcp_msg); + *m = (struct osmo_pfcp_msg){ + .remote_addr = *remote_addr, + .h = { + .version = 1, + }, + }; + talloc_set_destructor(m, osmo_pfcp_msg_destructor); + return m; +} + +struct osmo_pfcp_msg *osmo_pfcp_msg_alloc_rx(void *ctx, const struct osmo_sockaddr *remote_addr) +{ + struct osmo_pfcp_msg *rx = _osmo_pfcp_msg_alloc(ctx, remote_addr); + rx->rx = true; + return rx; +} + +struct osmo_pfcp_msg *osmo_pfcp_msg_alloc_tx(void *ctx, const struct osmo_sockaddr *remote_addr, + const struct osmo_pfcp_ie_node_id *node_id, + const struct osmo_pfcp_msg *in_reply_to, + enum osmo_pfcp_message_type msg_type) +{ + struct osmo_pfcp_msg *tx; + if (!remote_addr && in_reply_to) + remote_addr = &in_reply_to->remote_addr; + OSMO_ASSERT(remote_addr); + tx = _osmo_pfcp_msg_alloc(ctx, remote_addr); + tx->is_response = osmo_pfcp_msgtype_is_response(msg_type); + tx->h.message_type = msg_type; + if (in_reply_to) + tx->h.sequence_nr = in_reply_to->h.sequence_nr; + osmo_pfcp_msg_set_memb_ofs(tx); + + /* Write the local node id data to the correct tx->ies.* member. */ + if (node_id) { + struct osmo_pfcp_ie_node_id *tx_node_id = osmo_pfcp_msg_node_id(tx); + if (tx_node_id) + *tx_node_id = *node_id; + } + return tx; +} + +static int osmo_pfcp_msg_destructor(struct osmo_pfcp_msg *m) +{ + OSMO_LOG_PFCP_MSG(m, LOGL_DEBUG, "discarding\n"); + if (m->ctx.session_use_count) + osmo_use_count_get_put(m->ctx.session_use_count, m->ctx.session_use_token, -1); + m->ctx.session_fi = NULL; + m->ctx.session_use_count = NULL; + m->ctx.session_use_token = NULL; + + if (m->ctx.peer_use_count) + osmo_use_count_get_put(m->ctx.peer_use_count, m->ctx.peer_use_token, -1); + m->ctx.peer_fi = NULL; + m->ctx.peer_use_count = NULL; + m->ctx.peer_use_token = NULL; + return 0; +} + +void osmo_pfcp_msg_free(struct osmo_pfcp_msg *m) +{ + if (!m) + return; + talloc_free(m); +} + +uint32_t osmo_pfcp_next_seq_nr(uint32_t *next_seq_nr_state) +{ + (*next_seq_nr_state)++; + (*next_seq_nr_state) &= 0xffffff; + /* Avoid seq == 0, so that it doesn't look like the value is missing. */ + if (!(*next_seq_nr_state)) + (*next_seq_nr_state)++; + return *next_seq_nr_state; +} + +uint64_t osmo_pfcp_next_seid(uint64_t *next_seid_state) +{ + (*next_seid_state)++; + /* Avoid SEID == 0, which is sent in Session Establishment Request before a remote SEID is known. */ + if (!*next_seid_state) + (*next_seid_state)++; + return *next_seid_state; +} + +int osmo_pfcp_ip_addrs_set(struct osmo_pfcp_ip_addrs *dst, const struct osmo_sockaddr *addr) +{ + switch (addr->u.sas.ss_family) { + case AF_INET: + dst->v4_present = true; + dst->v4 = *addr; + return 0; + case AF_INET6: + dst->v6_present = true; + dst->v6 = *addr; + return 0; + default: + return -ENOTSUP; + } +} + +/* If a osmo_fsm_inst placed in m->ctx deallocates before the osmo_pfcp_msg, call this function, to make sure to avoid + * use after free. Alternatively use m->ctx.*_use_count to make sure the FSM inst does not deallocate before the + * osmo_pfcp_msg is discarded from the resend queue. */ +void osmo_pfcp_msg_invalidate_ctx(struct osmo_pfcp_msg *m, struct osmo_fsm_inst *deleted_fi) +{ + if (m->ctx.session_fi == deleted_fi) { + m->ctx.session_fi = NULL; + m->ctx.session_use_count = NULL; + m->ctx.session_use_token = NULL; + } + if (m->ctx.peer_fi == deleted_fi) { + m->ctx.peer_fi = NULL; + m->ctx.peer_use_count = NULL; + m->ctx.peer_use_token = NULL; + } +} + +int osmo_pfcp_msg_to_str_buf(char *buf, size_t buflen, const struct osmo_pfcp_msg *m) +{ + struct osmo_strbuf sb = { .buf = buf, .len = buflen }; + OSMO_STRBUF_PRINTF(sb, "PFCPv%u %s hdr={seq=%u", m->h.version, osmo_pfcp_message_type_str(m->h.message_type), + m->h.sequence_nr); + if (m->h.priority_present) + OSMO_STRBUF_PRINTF(sb, " prio=%u", m->h.priority); + if (m->h.seid_present) + OSMO_STRBUF_PRINTF(sb, " SEID=0x%"PRIx64, m->h.seid); + OSMO_STRBUF_PRINTF(sb, "} ies={"); + OSMO_STRBUF_APPEND(sb, osmo_pfcp_ies_encode_to_str, &m->ies, m->h.message_type, osmo_pfcp_iei_strs); + OSMO_STRBUF_PRINTF(sb, " }"); + return sb.chars_needed; +} + +char *osmo_pfcp_msg_to_str_c(void *ctx, const struct osmo_pfcp_msg *m) +{ + OSMO_NAME_C_IMPL(ctx, 256, "ERROR", osmo_pfcp_msg_to_str_buf, m) +} -- To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/27631 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-upf Gerrit-Branch: master Gerrit-Change-Id: I3f85ea052a6b7c064244a8093777e53a47c8c61e Gerrit-Change-Number: 27631 Gerrit-PatchSet: 7 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
Change in osmo-upf[master]: libosmo-pfcp: implement PFCP header and msg handling
by neels 08 Jun '22

08 Jun '22
Attention is currently required from: laforge, fixeria. neels has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-upf/+/27631 ) Change subject: libosmo-pfcp: implement PFCP header and msg handling ...................................................................... Patch Set 7: Code-Review+2 (1 comment) Patchset: PS7: combine votes -- To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/27631 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-upf Gerrit-Branch: master Gerrit-Change-Id: I3f85ea052a6b7c064244a8093777e53a47c8c61e Gerrit-Change-Number: 27631 Gerrit-PatchSet: 7 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Comment-Date: Wed, 08 Jun 2022 16:06:32 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
Change in osmo-hnodeb[master]: hnb: move llsk fields inside substruct
by pespin 08 Jun '22

08 Jun '22
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnodeb/+/28242 ) Change subject: hnb: move llsk fields inside substruct ...................................................................... hnb: move llsk fields inside substruct More fields will be added, let's better organize them this way. Change-Id: Idfe644a7c2eccd94b602816a86e38b56264141af --- M include/osmocom/hnodeb/hnodeb.h M src/osmo-hnodeb/gtp.c M src/osmo-hnodeb/hnb.c M src/osmo-hnodeb/llsk.c M src/osmo-hnodeb/llsk_audio.c M src/osmo-hnodeb/llsk_gtp.c M src/osmo-hnodeb/llsk_iuh.c M src/osmo-hnodeb/main.c M src/osmo-hnodeb/rua.c M src/osmo-hnodeb/vty.c 10 files changed, 46 insertions(+), 44 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnodeb refs/changes/42/28242/1 diff --git a/include/osmocom/hnodeb/hnodeb.h b/include/osmocom/hnodeb/hnodeb.h index 924e1ac..5503020 100644 --- a/include/osmocom/hnodeb/hnodeb.h +++ b/include/osmocom/hnodeb/hnodeb.h @@ -88,10 +88,12 @@ } iuh; /* Lower Layer UD socket */ - struct osmo_prim_srv_link *llsk_link; - struct osmo_prim_srv *llsk; - uint8_t llsk_valid_sapi_mask; - struct osmo_timer_list llsk_defer_configure_ind_timer; + struct { + struct osmo_prim_srv_link *link; + struct osmo_prim_srv *srv; + uint8_t valid_sapi_mask; + struct osmo_timer_list defer_configure_ind_timer; + } llsk; struct { unsigned int jitter_buf_ms; diff --git a/src/osmo-hnodeb/gtp.c b/src/osmo-hnodeb/gtp.c index ef12cf6..58b28fe 100644 --- a/src/osmo-hnodeb/gtp.c +++ b/src/osmo-hnodeb/gtp.c @@ -189,7 +189,7 @@ LOGUE(ue, DGTP, LOGL_DEBUG, "Tx GTP-CONN_DATA.ind len=%u\n", msgb_l3len(msg)); gtp_prim = hnb_gtp_makeprim_conn_data_ind(conn->id, msgb_l3(msg), msgb_l3len(msg)); - if ((rc = osmo_prim_srv_send(hnb->llsk, gtp_prim->hdr.msg)) < 0) { + if ((rc = osmo_prim_srv_send(hnb->llsk.srv, gtp_prim->hdr.msg)) < 0) { LOGUE(ue, DGTP, LOGL_ERROR, "Failed Tx GTP-CONN_DATA.ind len=%u\n", msgb_l3len(msg)); } diff --git a/src/osmo-hnodeb/hnb.c b/src/osmo-hnodeb/hnb.c index 18f39b4..1d03826 100644 --- a/src/osmo-hnodeb/hnb.c +++ b/src/osmo-hnodeb/hnb.c @@ -88,9 +88,9 @@ } hnb_iuh_free(hnb); - osmo_timer_del(&hnb->llsk_defer_configure_ind_timer); - osmo_prim_srv_link_free(hnb->llsk_link); - hnb->llsk_link = NULL; + osmo_timer_del(&hnb->llsk.defer_configure_ind_timer); + osmo_prim_srv_link_free(hnb->llsk.link); + hnb->llsk.link = NULL; hnb_gtp_unbind(hnb); diff --git a/src/osmo-hnodeb/llsk.c b/src/osmo-hnodeb/llsk.c index 76d4c4a..89e8364 100644 --- a/src/osmo-hnodeb/llsk.c +++ b/src/osmo-hnodeb/llsk.c @@ -86,13 +86,13 @@ { struct hnb *hnb = (struct hnb *)osmo_prim_srv_get_priv(srv); - if (hnb->llsk) { + if (hnb->llsk.srv) { LOGP(DLLSK, LOGL_ERROR, "New connection opened while one is already active, dropping it\n"); osmo_prim_srv_close(srv); return 0; } LOGP(DLLSK, LOGL_NOTICE, "LLSK conn is UP\n"); - hnb->llsk = srv; + hnb->llsk.srv = srv; return 0; } @@ -100,37 +100,37 @@ { struct hnb *hnb = (struct hnb *)osmo_prim_srv_get_priv(srv); - if (!hnb->llsk) { + if (!hnb->llsk.srv) { LOGP(DLLSK, LOGL_ERROR, "closed_cb received but we have no active llsk conn!\n"); return 0; } /* If a later conn different than active one is dropped (because we closed it): */ - if (hnb->llsk != srv) + if (hnb->llsk.srv != srv) return 0; LOGP(DLLSK, LOGL_NOTICE, "LLSK conn is DOWN\n"); - hnb->llsk = NULL; - hnb->llsk_valid_sapi_mask = 0x0; - osmo_timer_del(&hnb->llsk_defer_configure_ind_timer); + hnb->llsk.srv = NULL; + hnb->llsk.valid_sapi_mask = 0x0; + osmo_timer_del(&hnb->llsk.defer_configure_ind_timer); hnb_shutdown(hnb, "LLSK conn dropped", false); return 0; } bool hnb_llsk_connected(const struct hnb *hnb) { - return !!hnb->llsk; + return !!hnb->llsk.srv; } bool hnb_llsk_can_be_configured(struct hnb *hnb) { if (!hnb->registered) return false; - if (!hnb->llsk) + if (!hnb->llsk.srv) return false; - if (hnb->llsk_valid_sapi_mask & (1 << HNB_PRIM_SAPI_IUH) && - hnb->llsk_valid_sapi_mask & (1 << HNB_PRIM_SAPI_AUDIO) && - hnb->llsk_valid_sapi_mask & (1 << HNB_PRIM_SAPI_GTP)) + if (hnb->llsk.valid_sapi_mask & (1 << HNB_PRIM_SAPI_IUH) && + hnb->llsk.valid_sapi_mask & (1 << HNB_PRIM_SAPI_AUDIO) && + hnb->llsk.valid_sapi_mask & (1 << HNB_PRIM_SAPI_GTP)) return true; return false; } @@ -144,13 +144,13 @@ static int llsk_rx_sapi_version_cb(struct osmo_prim_srv *prim_srv, uint32_t sapi, uint16_t rem_version) { struct hnb *hnb = (struct hnb *)osmo_prim_srv_get_priv(prim_srv); - if (sapi > sizeof(hnb->llsk_valid_sapi_mask)*8 - 1) + if (sapi > sizeof(hnb->llsk.valid_sapi_mask)*8 - 1) return -1; - hnb->llsk_valid_sapi_mask |= (1 << sapi); + hnb->llsk.valid_sapi_mask |= (1 << sapi); /* Defer CONFIGURE.req after we have confirmed the versions */ if (hnb_llsk_can_be_configured(hnb)) - osmo_timer_schedule(&hnb->llsk_defer_configure_ind_timer, 0, 0); + osmo_timer_schedule(&hnb->llsk.defer_configure_ind_timer, 0, 0); return rem_version; } @@ -177,14 +177,14 @@ int hnb_llsk_alloc(struct hnb *hnb) { - hnb->llsk_link = osmo_prim_srv_link_alloc(hnb); - osmo_prim_srv_link_set_priv(hnb->llsk_link, hnb); - osmo_prim_srv_link_set_log_category(hnb->llsk_link, DLLSK); - osmo_prim_srv_link_set_addr(hnb->llsk_link, HNB_PRIM_UD_SOCK_DEFAULT); - osmo_prim_srv_link_set_opened_conn_cb(hnb->llsk_link, llsk_opened_cb); - osmo_prim_srv_link_set_closed_conn_cb(hnb->llsk_link, llsk_closed_cb); - osmo_prim_srv_link_set_rx_sapi_version_cb(hnb->llsk_link, llsk_rx_sapi_version_cb); - osmo_prim_srv_link_set_rx_cb(hnb->llsk_link, llsk_rx_cb); - osmo_timer_setup(&hnb->llsk_defer_configure_ind_timer, llsk_defer_configure_ind_timer_cb, hnb); + hnb->llsk.link = osmo_prim_srv_link_alloc(hnb); + osmo_prim_srv_link_set_priv(hnb->llsk.link, hnb); + osmo_prim_srv_link_set_log_category(hnb->llsk.link, DLLSK); + osmo_prim_srv_link_set_addr(hnb->llsk.link, HNB_PRIM_UD_SOCK_DEFAULT); + osmo_prim_srv_link_set_opened_conn_cb(hnb->llsk.link, llsk_opened_cb); + osmo_prim_srv_link_set_closed_conn_cb(hnb->llsk.link, llsk_closed_cb); + osmo_prim_srv_link_set_rx_sapi_version_cb(hnb->llsk.link, llsk_rx_sapi_version_cb); + osmo_prim_srv_link_set_rx_cb(hnb->llsk.link, llsk_rx_cb); + osmo_timer_setup(&hnb->llsk.defer_configure_ind_timer, llsk_defer_configure_ind_timer_cb, hnb); return 0; } diff --git a/src/osmo-hnodeb/llsk_audio.c b/src/osmo-hnodeb/llsk_audio.c index da54d28..a9fe858 100644 --- a/src/osmo-hnodeb/llsk_audio.c +++ b/src/osmo-hnodeb/llsk_audio.c @@ -129,7 +129,7 @@ LOGUE(conn->ue, DLLSK, LOGL_DEBUG, "Tx AUDIO-CONN_DATA.ind conn_id=%u fn=%u fqc=%u rfci=%u data_len=%u\n", conn->id, frame_nr, fqc, rfci, len); audio_prim = hnb_audio_makeprim_conn_data_ind(conn->id, frame_nr, fqc, rfci, payload, len); - if ((rc = osmo_prim_srv_send(conn->ue->hnb->llsk, audio_prim->hdr.msg)) < 0) + if ((rc = osmo_prim_srv_send(conn->ue->hnb->llsk.srv, audio_prim->hdr.msg)) < 0) LOGUE(conn->ue, DLLSK, LOGL_ERROR, "Failed sending AUDIO-CONN_DATA.ind\n"); return rc; } @@ -141,7 +141,7 @@ LOGP(DLLSK, LOGL_ERROR, "Tx AUDIO-CONN_ESTABLISH.cnf: ctx=%u error_code=%u\n", context_id, error_code); audio_prim = hnb_audio_makeprim_conn_establish_cnf(context_id, 0, error_code, 0, HNB_PRIM_ADDR_TYPE_UNSPEC, NULL); - if ((rc = osmo_prim_srv_send(hnb->llsk, audio_prim->hdr.msg)) < 0) { + if ((rc = osmo_prim_srv_send(hnb->llsk.srv, audio_prim->hdr.msg)) < 0) { LOGP(DLLSK, LOGL_ERROR, "Failed sending AUDIO-CONN_ESTABLISH.cnf context_id=%u error_code=%u\n", context_id, error_code); } @@ -210,7 +210,7 @@ rem_addrstr, osmo_sockaddr_to_str(&conn->loc_addr)); audio_prim = hnb_audio_makeprim_conn_establish_cnf(ce_req->context_id, conn->id, 0, loc_port, ce_req->remote_rtp_address_type, &loc_uaddr); - if ((rc = osmo_prim_srv_send(hnb->llsk, audio_prim->hdr.msg)) < 0) { + if ((rc = osmo_prim_srv_send(hnb->llsk.srv, audio_prim->hdr.msg)) < 0) { LOGUE(ue, DLLSK, LOGL_ERROR, "Failed sending AUDIO-CONN_ESTABLISH.cnf error_code=0\n"); goto release_sock; } diff --git a/src/osmo-hnodeb/llsk_gtp.c b/src/osmo-hnodeb/llsk_gtp.c index 775df50..9882ecf 100644 --- a/src/osmo-hnodeb/llsk_gtp.c +++ b/src/osmo-hnodeb/llsk_gtp.c @@ -120,7 +120,7 @@ LOGP(DLLSK, LOGL_ERROR, "Tx GTP-CONN_ESTABLISH.cnf: ctx=%u error_code=%u\n", context_id, error_code); gtp_prim = hnb_gtp_makeprim_conn_establish_cnf(context_id, 0, error_code, 0, HNB_PRIM_ADDR_TYPE_UNSPEC, NULL); - if ((rc = osmo_prim_srv_send(hnb->llsk, gtp_prim->hdr.msg)) < 0) { + if ((rc = osmo_prim_srv_send(hnb->llsk.srv, gtp_prim->hdr.msg)) < 0) { LOGP(DLLSK, LOGL_ERROR, "Failed sending GTP-CONN_ESTABLISH.cnf context_id=%u error_code=%u\n", context_id, error_code); } @@ -191,7 +191,7 @@ rem_addrstr, ce_req->remote_tei, osmo_sockaddr_to_str(&conn->loc_addr), conn->loc_tei); gtp_prim = hnb_gtp_makeprim_conn_establish_cnf(ce_req->context_id, conn->id, 0, conn->loc_tei, ce_req->remote_gtpu_address_type, &loc_uaddr); - if ((rc = osmo_prim_srv_send(hnb->llsk, gtp_prim->hdr.msg)) < 0) { + if ((rc = osmo_prim_srv_send(hnb->llsk.srv, gtp_prim->hdr.msg)) < 0) { LOGUE(ue, DLLSK, LOGL_ERROR, "Failed sending GTP-CONN_ESTABLISH.cnf error_code=0\n"); goto release_sock; } diff --git a/src/osmo-hnodeb/llsk_iuh.c b/src/osmo-hnodeb/llsk_iuh.c index 00c399a..3cb9077 100644 --- a/src/osmo-hnodeb/llsk_iuh.c +++ b/src/osmo-hnodeb/llsk_iuh.c @@ -117,7 +117,7 @@ iuh_prim = hnb_iuh_makeprim_configure_ind(hnb->plmn.mcc, hnb->plmn.mnc, hnb->cell_identity, hnb->lac, hnb->rac, hnb->sac, hnb->rnc_id); - if ((rc = osmo_prim_srv_send(hnb->llsk, iuh_prim->hdr.msg)) < 0) + if ((rc = osmo_prim_srv_send(hnb->llsk.srv, iuh_prim->hdr.msg)) < 0) LOGP(DLLSK, LOGL_ERROR, "Failed sending IUH-CONFIGURE.ind\n"); return rc; } diff --git a/src/osmo-hnodeb/main.c b/src/osmo-hnodeb/main.c index 5d35c18..304ad1c 100644 --- a/src/osmo-hnodeb/main.c +++ b/src/osmo-hnodeb/main.c @@ -275,7 +275,7 @@ } /* Start listening on lower layer unix domain socket: */ - rc = osmo_prim_srv_link_open(g_hnb->llsk_link); + rc = osmo_prim_srv_link_open(g_hnb->llsk.link); if (rc < 0) { perror("Error opening lower layer socket"); exit(1); diff --git a/src/osmo-hnodeb/rua.c b/src/osmo-hnodeb/rua.c index 5b225de..e109ae0 100644 --- a/src/osmo-hnodeb/rua.c +++ b/src/osmo-hnodeb/rua.c @@ -77,7 +77,7 @@ LOGP(DLLSK, LOGL_INFO, "Tx IUH-CONN_ESTABLISH.cnf context_id=%u is_ps=%u\n", context_id, is_ps); iuh_prim = hnb_iuh_makeprim_conn_establish_cnf(context_id, is_ps, 0); - if ((rc = osmo_prim_srv_send(hnb->llsk, iuh_prim->hdr.msg)) < 0) { + if ((rc = osmo_prim_srv_send(hnb->llsk.srv, iuh_prim->hdr.msg)) < 0) { LOGP(DRUA, LOGL_ERROR, "Failed sending IUH-CONN_ESTABLISH.cnf context_id=%u is_ps=%u\n", context_id, is_ps); goto free_ret; @@ -87,7 +87,7 @@ LOGP(DLLSK, LOGL_DEBUG, "Tx IUH-CONN_DATA.ind context_id=%u is_ps=%u ranap_len=%zu\n", context_id, is_ps, ranap_buf_len); iuh_prim = hnb_iuh_makeprim_conn_data_ind(context_id, is_ps, ranap_buf, ranap_buf_len); - if ((rc = osmo_prim_srv_send(hnb->llsk, iuh_prim->hdr.msg)) < 0) { + if ((rc = osmo_prim_srv_send(hnb->llsk.srv, iuh_prim->hdr.msg)) < 0) { LOGP(DRUA, LOGL_ERROR, "Failed sending IUH-CONN_DATA.ind context_id=%u is_ps=%u ranap_len=%zu\n", context_id, is_ps, ranap_buf_len); goto free_ret; @@ -118,7 +118,7 @@ LOGP(DLLSK, LOGL_DEBUG, "Tx IUH-UNITDATA.ind ranap_len=%zu\n", ranap_buf_len); iuh_prim = hnb_iuh_makeprim_unitdata_ind(ranap_buf, ranap_buf_len); - if ((rc = osmo_prim_srv_send(hnb->llsk, iuh_prim->hdr.msg)) < 0) { + if ((rc = osmo_prim_srv_send(hnb->llsk.srv, iuh_prim->hdr.msg)) < 0) { LOGP(DRUA, LOGL_ERROR, "Failed sending IUH-CONN_DATA.ind ranap_len=%zu\n", ranap_buf_len); goto free_ret; diff --git a/src/osmo-hnodeb/vty.c b/src/osmo-hnodeb/vty.c index e84e330..f06e4cc 100644 --- a/src/osmo-hnodeb/vty.c +++ b/src/osmo-hnodeb/vty.c @@ -279,7 +279,7 @@ "Configure the Lower Layer Unix Domain Socket path\n" "UNIX socket path\n") { - osmo_prim_srv_link_set_addr(g_hnb->llsk_link, argv[0]); + osmo_prim_srv_link_set_addr(g_hnb->llsk.link, argv[0]); /* FIXME: re-open the interface? */ return CMD_SUCCESS; @@ -332,7 +332,7 @@ vty_out(vty, " remote-ip %s%s", g_hnb->iuh.remote_addr, VTY_NEWLINE); vty_out(vty, " remote-port %u%s", g_hnb->iuh.remote_port, VTY_NEWLINE); vty_out(vty, " ll-socket%s", VTY_NEWLINE); - vty_out(vty, " path %s%s", osmo_prim_srv_link_get_addr(g_hnb->llsk_link), VTY_NEWLINE); + vty_out(vty, " path %s%s", osmo_prim_srv_link_get_addr(g_hnb->llsk.link), VTY_NEWLINE); vty_out(vty, " gtp%s", VTY_NEWLINE); vty_out(vty, " local-ip %s%s", g_hnb->gtp.cfg_local_addr, VTY_NEWLINE); return CMD_SUCCESS; -- To view, visit https://gerrit.osmocom.org/c/osmo-hnodeb/+/28242 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-hnodeb Gerrit-Branch: master Gerrit-Change-Id: Idfe644a7c2eccd94b602816a86e38b56264141af Gerrit-Change-Number: 28242 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • ...
  • 138
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.