ns2: Count transmitted/dropped in each layer implementation

This allows better control on how the counters are ticked.
For instance, since nowadays the writing in ns2_udp is done
asyncrhonously, most probable failures occur at a later point and not
when returning to the caller.

Change-Id: I8109cee07f157ebf1806f82a071f58de3a2dcc9c
This commit is contained in:
Pau Espin 2023-04-27 16:00:01 +02:00 committed by daniel
parent fa3a9ce9fd
commit 8f026bf3b7
3 changed files with 23 additions and 17 deletions

View File

@ -332,9 +332,19 @@ int gprs_ns2_is_fr_bind(struct gprs_ns2_vc_bind *bind)
static int fr_vc_sendmsg(struct gprs_ns2_vc *nsvc, struct msgb *msg)
{
struct priv_vc *vcpriv = nsvc->priv;
unsigned int vc_len = msgb_length(msg);
int rc;
msg->dst = vcpriv->dlc;
return osmo_fr_tx_dlc(msg);
rc = osmo_fr_tx_dlc(msg);
if (OSMO_LIKELY(rc >= 0)) {
RATE_CTR_INC_NS(nsvc, NS_CTR_PKTS_OUT);
RATE_CTR_ADD_NS(nsvc, NS_CTR_BYTES_OUT, vc_len);
} else {
RATE_CTR_INC_NS(nsvc, NS_CTR_PKTS_OUT_DROP);
RATE_CTR_ADD_NS(nsvc, NS_CTR_BYTES_OUT_DROP, vc_len);
}
return rc;
}
static void enqueue_at_head(struct gprs_ns2_vc_bind *bind, struct msgb *msg)

View File

@ -503,6 +503,8 @@ static int frgre_vc_sendmsg(struct gprs_ns2_vc *nsvc, struct msgb *msg)
uint16_t dlci = osmo_htons(bindpriv->dlci);
uint8_t *frh;
struct gre_hdr *greh;
unsigned int vc_len = msgb_length(msg);
int rc;
/* Prepend the FR header */
frh = msgb_push(msg, 2);
@ -514,7 +516,15 @@ static int frgre_vc_sendmsg(struct gprs_ns2_vc *nsvc, struct msgb *msg)
greh->flags = 0;
greh->ptype = osmo_htons(GRE_PTYPE_FR);
return frgre_sendmsg(bind, msg, &vcpriv->remote);
rc = frgre_sendmsg(bind, msg, &vcpriv->remote);
if (OSMO_LIKELY(rc >= 0)) {
RATE_CTR_INC_NS(nsvc, NS_CTR_PKTS_OUT);
RATE_CTR_ADD_NS(nsvc, NS_CTR_BYTES_OUT, rc);
} else {
RATE_CTR_INC_NS(nsvc, NS_CTR_PKTS_OUT_DROP);
RATE_CTR_ADD_NS(nsvc, NS_CTR_BYTES_OUT_DROP, vc_len);
}
return rc;
}
static int frgre_fd_cb(struct osmo_fd *bfd, unsigned int what)

View File

@ -169,23 +169,9 @@ int ns2_validate(struct gprs_ns2_vc *nsvc,
return 0;
}
static int ns_vc_tx(struct gprs_ns2_vc *nsvc, struct msgb *msg)
{
unsigned int bytes = msgb_length(msg);
int rc;
rc = nsvc->bind->send_vc(nsvc, msg);
if (rc < 0) {
RATE_CTR_INC_NS(nsvc, NS_CTR_PKTS_OUT_DROP);
RATE_CTR_ADD_NS(nsvc, NS_CTR_BYTES_OUT_DROP, bytes);
} else {
RATE_CTR_INC_NS(nsvc, NS_CTR_PKTS_OUT);
RATE_CTR_ADD_NS(nsvc, NS_CTR_BYTES_OUT, bytes);
}
return rc;
return nsvc->bind->send_vc(nsvc, msg);
}
/* transmit functions */