pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-pfcp/+/39456?usp=email )
Change subject: Use hashtable to look up req/resp by seq_nr
......................................................................
Use hashtable to look up req/resp by seq_nr
The list of requests/responses may grow quite a lot on busy instances.
Related: SYS#6398
Change-Id: I1b7138206ed035bed3d266f713ce1dd62cbe7286
---
M src/libosmo-pfcp/pfcp_endpoint.c
1 file changed, 39 insertions(+), 17 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-pfcp refs/changes/56/39456/1
diff --git a/src/libosmo-pfcp/pfcp_endpoint.c b/src/libosmo-pfcp/pfcp_endpoint.c
index 7e08d8e..e2b25d4 100644
--- a/src/libosmo-pfcp/pfcp_endpoint.c
+++ b/src/libosmo-pfcp/pfcp_endpoint.c
@@ -28,6 +28,8 @@
#include <osmocom/core/talloc.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/tdef.h>
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/hashtable.h>
#include <osmocom/pfcp/pfcp_endpoint.h>
#include <osmocom/pfcp/pfcp_msg.h>
@@ -49,16 +51,20 @@
* For a transmitted Request message, wait for a matching Response from a remote peer; if none arrives,
* retransmit (see n1 and t1_ms). */
struct llist_head sent_requests;
+ DECLARE_HASHTABLE(sent_requests_by_seq_nr, 10);
/* All transmitted PFCP Response messages, list of osmo_pfcp_queue_entry.
* 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 sent_responses;
+ DECLARE_HASHTABLE(sent_responses_by_seq_nr, 10);
};
/*! Entry of pfcp_endpoint message queue of PFCP messages, for re-transsions. */
struct osmo_pfcp_queue_entry {
/* entry in osmo_pfcp_endpoint.sent_requests or .sent_responses */
struct llist_head entry;
+ /* item in osmo_pfcp_endpoint's sent_responses_by_seq_nr or sent_responses_by_seq_nr */
+ struct hlist_node node_by_seq_nr;
/* back-pointer */
struct osmo_pfcp_endpoint *ep;
/* message we have transmitted */
@@ -70,22 +76,6 @@
unsigned int n1_remaining;
};
-/* Find a matching osmo_pfcp_queue_entry for given rx.
- * A returned osmo_pfcp_queue_entry is guaranteed to be a Response if rx is a Request, and vice versa. */
-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)
{
@@ -96,6 +86,7 @@
static int osmo_pfcp_queue_destructor(struct osmo_pfcp_queue_entry *qe)
{
osmo_timer_del(&qe->t1);
+ hash_del(&qe->node_by_seq_nr);
llist_del(&qe->entry);
return 0;
}
@@ -144,6 +135,8 @@
INIT_LLIST_HEAD(&ep->sent_requests);
INIT_LLIST_HEAD(&ep->sent_responses);
+ hash_init(ep->sent_requests_by_seq_nr);
+ hash_init(ep->sent_responses_by_seq_nr);
ep->pfcp_fd.fd = -1;
@@ -311,9 +304,11 @@
* Add sent responses to the end of the list: they will rarely be retransmitted at all. */
if (m->is_response) {
llist_add_tail(&qe->entry, &endpoint->sent_responses);
+ hash_add(endpoint->sent_responses_by_seq_nr, &qe->node_by_seq_nr, m->h.sequence_nr);
osmo_timer_setup(&qe->t1, pfcp_queue_sent_resp_timer_cb, qe);
} else {
llist_add(&qe->entry, &endpoint->sent_requests);
+ hash_add(endpoint->sent_requests_by_seq_nr, &qe->node_by_seq_nr, m->h.sequence_nr);
osmo_timer_setup(&qe->t1, pfcp_queue_sent_req_timer_cb, qe);
}
talloc_set_destructor(qe, osmo_pfcp_queue_destructor);
@@ -353,6 +348,30 @@
return 0;
}
+static struct osmo_pfcp_queue_entry *osmo_pfcp_enfpoint_find_sent_request(const struct osmo_pfcp_endpoint *ep, uint32_t seq_nr)
+{
+ struct osmo_pfcp_queue_entry *qe;
+ hash_for_each_possible(ep->sent_requests_by_seq_nr, qe, node_by_seq_nr, seq_nr) {
+ OSMO_ASSERT(qe->m);
+ if (qe->m->h.sequence_nr != seq_nr)
+ continue;
+ return qe;
+ }
+ return NULL;
+}
+
+static struct osmo_pfcp_queue_entry *osmo_pfcp_enfpoint_find_sent_response(const struct osmo_pfcp_endpoint *ep, uint32_t seq_nr)
+{
+ struct osmo_pfcp_queue_entry *qe;
+ hash_for_each_possible(ep->sent_responses_by_seq_nr, qe, node_by_seq_nr, seq_nr) {
+ OSMO_ASSERT(qe->m);
+ if (qe->m->h.sequence_nr != seq_nr)
+ continue;
+ return qe;
+ }
+ return NULL;
+}
+
static void osmo_pfcp_endpoint_handle_rx(struct osmo_pfcp_endpoint *ep, struct osmo_pfcp_msg *m)
{
bool dispatch_rx = true;
@@ -370,7 +389,10 @@
/* If this is receiving a response, search for matching sent request that is now completed.
* If this is receiving a request, search for a matching sent response that can be retransmitted.
* A match is found by sequence_nr. */
- prev_msg = osmo_pfcp_queue_find(m->is_response ? &ep->sent_requests : &ep->sent_responses, m);
+ if (m->is_response)
+ prev_msg = osmo_pfcp_enfpoint_find_sent_request(ep, m->h.sequence_nr);
+ else
+ prev_msg = osmo_pfcp_enfpoint_find_sent_response(ep, m->h.sequence_nr);
if (prev_msg && !m->is_response) {
/* m is a request, and we have already sent a response to this same request earlier. Retransmit the same
--
To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/39456?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-pfcp
Gerrit-Branch: master
Gerrit-Change-Id: I1b7138206ed035bed3d266f713ce1dd62cbe7286
Gerrit-Change-Number: 39456
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/39454?usp=email )
Change subject: utils: h2i(): use list() to convert bytes to integers
......................................................................
utils: h2i(): use list() to convert bytes to integers
Change-Id: Icb0d0803b7ae4e0b3a292ba96f58c26d0ca88abd
---
M src/osmocom/utils.py
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/python/pyosmocom refs/changes/54/39454/1
diff --git a/src/osmocom/utils.py b/src/osmocom/utils.py
index 6c823ec..347bb93 100644
--- a/src/osmocom/utils.py
+++ b/src/osmocom/utils.py
@@ -78,7 +78,7 @@
def h2i(s: Hexstr) -> List[int]:
"""convert from a string of hex nibbles to a list of integers"""
- return [(int(x, 16) << 4)+int(y, 16) for x, y in zip(s[0::2], s[1::2])]
+ return list(h2b(s))
def i2h(s: List[int]) -> hexstr:
--
To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/39454?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: python/pyosmocom
Gerrit-Branch: master
Gerrit-Change-Id: Icb0d0803b7ae4e0b3a292ba96f58c26d0ca88abd
Gerrit-Change-Number: 39454
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/39453?usp=email )
Change subject: utils: b2h()/i2h(): use bytes.hex() API
......................................................................
utils: b2h()/i2h(): use bytes.hex() API
Change-Id: Iaef25f614e7a4b1c3eb328e560bf9a300f70ae31
---
M src/osmocom/utils.py
1 file changed, 2 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/python/pyosmocom refs/changes/53/39453/1
diff --git a/src/osmocom/utils.py b/src/osmocom/utils.py
index 5947453..6c823ec 100644
--- a/src/osmocom/utils.py
+++ b/src/osmocom/utils.py
@@ -73,7 +73,7 @@
def b2h(b: bytearray) -> hexstr:
"""convert from a sequence of bytes to a string of hex nibbles"""
- return hexstr(''.join(['%02x' % (x) for x in b]))
+ return hexstr(b.hex())
def h2i(s: Hexstr) -> List[int]:
@@ -83,7 +83,7 @@
def i2h(s: List[int]) -> hexstr:
"""convert from a list of integers to a string of hex nibbles"""
- return hexstr(''.join(['%02x' % (x) for x in s]))
+ return hexstr(bytes(s).hex())
def h2s(s: Hexstr) -> str:
--
To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/39453?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: python/pyosmocom
Gerrit-Branch: master
Gerrit-Change-Id: Iaef25f614e7a4b1c3eb328e560bf9a300f70ae31
Gerrit-Change-Number: 39453
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Attention is currently required from: pespin.
fixeria has posted comments on this change by pespin. ( https://gerrit.osmocom.org/c/osmo-upf/+/39452?usp=email )
Change subject: Introduce hashtable to lookup chain_id
......................................................................
Patch Set 1: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/39452?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: I7df8fd945eedbda98bd08e9fb2f382e0f55c2983
Gerrit-Change-Number: 39452
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Mon, 03 Feb 2025 09:22:48 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Attention is currently required from: pespin.
fixeria has posted comments on this change by pespin. ( https://gerrit.osmocom.org/c/osmo-upf/+/39451?usp=email )
Change subject: Introduce hashtable to lookup session by F-TEID
......................................................................
Patch Set 1: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/39451?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: I90ecbb07b242c1de2298261019f24aa5f5810fda
Gerrit-Change-Number: 39451
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Mon, 03 Feb 2025 09:17:50 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Attention is currently required from: pespin.
fixeria has posted comments on this change by pespin. ( https://gerrit.osmocom.org/c/osmo-upf/+/39450?usp=email )
Change subject: Simplify up_session_choose_f_teid() with early returns
......................................................................
Patch Set 2: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/39450?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: I6e8c64d093588157c86bb3acaaeed458ff73132d
Gerrit-Change-Number: 39450
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Mon, 03 Feb 2025 09:15:39 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes