Change in libosmocore[master]: one step

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

lynxis lazus gerrit-no-reply at lists.osmocom.org
Fri Feb 26 17:06:26 UTC 2021


lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/23130 )


Change subject: one step
......................................................................

one step

Change-Id: I1e264633105c71ad8202c38bb05c6afd4f70e202
---
M src/gb/gprs_ns2_sns.c
1 file changed, 123 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/30/23130/1

diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index a82da95..5852e4e 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -102,6 +102,12 @@
 	{ 0, NULL }
 };
 
+enum sns_procedure {
+	SNS_ADD,
+	SNS_DEL,
+	SNS_UPDATE_WEIGHT,
+};
+
 struct sns_endpoint {
 	struct llist_head list;
 	struct osmo_sockaddr saddr;
@@ -112,6 +118,12 @@
 	struct gprs_ns2_vc_bind *bind;
 };
 
+struct ns2_sns_procedure {
+	struct llist_head list;
+	struct gprs_ns2_vc_bind *bind;
+	enum sns_procedure procedure;
+};
+
 struct ns2_sns_state {
 	struct gprs_ns2_nse *nse;
 
@@ -133,6 +145,12 @@
 	struct sns_endpoint *initial;
 	/* all SNS PDU will be sent over this nsvc */
 	struct gprs_ns2_vc *sns_nsvc;
+
+	/* all pending local procedures*/
+	struct llist_head *procedures;
+	/* all current procedure */
+	struct ns2_sns_procedure *current;
+
 	/* timer N */
 	int N;
 	/* true if at least one nsvc is alive */
@@ -167,6 +185,34 @@
 	return gss->nse;
 }
 
+static struct gprs_ns_ie_ip4_elem *ip4_elem_by_saddr(struct gprs_ns_ie_ip4_elem *ip4, size_t num, const struct osmo_sockaddr *saddr)
+{
+	if (saddr->u.sa.sa_family != AF_INET)
+		return NULL;
+
+	for (size_t i = 0; i < num; i++) {
+		if (ip4[i].ip_addr == saddr->u.sin.sin_addr.s_addr &&
+				ip4->udp_port == saddr->u.sin.sin_port)
+			return &ip4[i];
+	}
+
+	return NULL;
+}
+
+static struct gprs_ns_ie_ip6_elem *ip6_elem_by_saddr(struct gprs_ns_ie_ip6_elem *ip6, size_t num, const struct osmo_sockaddr *saddr)
+{
+	if (saddr->u.sa.sa_family != AF_INET6)
+		return NULL;
+
+	for (size_t i = 0; i < num; i++) {
+		if (memcmp(&ip6[i].ip_addr, &saddr->u.sin6.sin6_addr, sizeof(struct in6_addr)) == 0 &&
+				ip6->udp_port == saddr->u.sin6.sin6_port)
+			return &ip6[i];
+	}
+
+	return NULL;
+}
+
 /* helper function to compute the sum of all (data or signaling) weights */
 static int ip4_weight_sum(const struct gprs_ns_ie_ip4_elem *ip4, unsigned int num,
 			  bool data_weight)
@@ -1927,12 +1973,86 @@
 	return 0;
 }
 
-/* Update SNS weights
- * \param[in] nsvc the NSVC which should be updated
+/* Update SNS weights for a bind (local endpoint). */
+static void _ns2_sns_update_weights(struct ns2_sns_state *gss, struct ns2_sns_bind *sns_bind) {
+	// find the ip_local entry by using the initial connection for 0.0.0.0
+	struct osmo_sockaddr *local, *remote;
+	const struct osmo_sockaddr *sa;
+	struct gprs_ns_ie_ip4_elem *ip4;
+	struct gprs_ns_ie_ip6_elem *ip6;
+
+	sa = gprs_ns2_ip_bind_sockaddr(sns_bind->bind);
+	if (!sa)
+		return;
+
+	switch (sa->u.sa.sa_family) {
+	case AF_INET:
+		if (sa->u.sin.sin_addr.s_addr == 0) {
+			if (osmo_sockaddr_local_ip(local, &gss->initial->saddr))
+				return;
+			ip4 = ip4_elem_by_saddr(gss->ip4_local, gss->num_ip4_local, local);
+		} else {
+			ip4 = ip4_elem_by_saddr(gss->ip4_local, gss->num_ip4_local, sa);
+		}
+
+		/* TODO: check if this bind is about to be added */
+		if (!ip4)
+			return;
+
+		/* did something change? */
+		if (ip4->sig_weight == sns_bind->bind->sns_sig_weight &&
+				ip4->data_weight == sns_bind->bind->sns_data_weight)
+			return;
+
+		// TODO: create procedure
+		break;
+	case AF_INET6:
+		// in6addr_any
+		if (memcmp(&sa->u.sin6.sin6_addr, &in6addr_any, sizeof(struct in6_addr))) {
+			if (osmo_sockaddr_local_ip(local, remote))
+				return;
+			ip6 = ip6_elem_by_saddr(gss->ip6_local, gss->num_ip6_local, local);
+		} else {
+			ip6 = ip6_elem_by_saddr(gss->ip6_local, gss->num_ip6_local, sa);
+		}
+
+		/* TODO: check if this bind is about to be added */
+		if (!ip6)
+			return;
+
+		/* did something change? */
+		if (ip6->sig_weight == sns_bind->bind->sns_sig_weight &&
+				ip6->data_weight == sns_bind->bind->sns_data_weight)
+			return;
+
+		// TODO: create procedure
+		break;
+	default:
+		OSMO_ASSERT(false);
+		break;
+	}
+}
+
+/* Update SNS weights for a bind (local endpoint).
+ * \param[in] bind the bind which has been updated
  */
 void ns2_sns_update_weights(struct gprs_ns2_vc_bind *bind)
 {
-	/* TODO: implement weights after binds per sns implemented */
+	struct ns2_sns_bind *sns_bind;
+	struct gprs_ns2_nse *nse;
+	struct ns2_sns_state *gss;
+	llist_for_each_entry(nse, &bind->nsi->nse, list) {
+		if (!nse->bss_sns_fi)
+			continue;
+
+		gss = nse->bss_sns_fi->priv;
+		llist_for_each_entry(sns_bind, &gss->binds, list) {
+			if (sns_bind->bind == bind) {
+				_ns2_sns_update_weights(gss, sns_bind);
+				break;
+			}
+		}
+	}
 }
 
 /* initialize osmo_ctx on main tread */

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/23130
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I1e264633105c71ad8202c38bb05c6afd4f70e202
Gerrit-Change-Number: 23130
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210226/75e070b7/attachment.htm>


More information about the gerrit-log mailing list