Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update statistic calculation #114

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ extern const struct net_device_ops gtp5g_netdev_ops;
struct gtp5g_dev *gtp5g_find_dev(struct net *, int, int);
int dev_hashtable_new(struct gtp5g_dev *, int);
void gtp5g_hashtable_free(struct gtp5g_dev *);
void update_usage_statistic(struct gtp5g_dev *, u64, int, uint);
void update_usage_statistic(struct gtp5g_dev *, u64, u64, int, uint);

#endif // __GTP5G_DEV_H__
14 changes: 8 additions & 6 deletions src/gtpu/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,23 @@ struct gtp5g_dev *gtp5g_find_dev(struct net *src_net, int ifindex, int netnsfd)
return gtp;
}

void update_usage_statistic(struct gtp5g_dev *gtp, u64 vol, int pkt_action, uint srcIntf)
void update_usage_statistic(struct gtp5g_dev *gtp, u64 rxVol, u64 txVol,
int pkt_action, uint srcIntf)
{
switch (srcIntf) {
case SRC_INTF_ACCESS: // uplink
atomic_add(vol, &gtp->rx.ul_byte);
atomic_add(rxVol, &gtp->rx.ul_byte);
atomic_inc(&gtp->rx.ul_pkt);
if (pkt_action != PKT_DROPPED) {
atomic_add(vol, &gtp->tx.ul_byte);
atomic_add(txVol, &gtp->tx.ul_byte);
atomic_inc(&gtp->tx.ul_pkt);
}
break;
case SRC_INTF_CORE: // downlink
atomic_add(vol, &gtp->rx.dl_byte);
atomic_add(rxVol, &gtp->rx.dl_byte);
atomic_inc(&gtp->rx.dl_pkt);
if (pkt_action != PKT_DROPPED) {
atomic_add(vol, &gtp->tx.dl_byte);
atomic_add(txVol, &gtp->tx.dl_byte);
atomic_inc(&gtp->tx.dl_pkt);
}
break;
Expand Down Expand Up @@ -98,6 +99,7 @@ static netdev_tx_t gtp5g_dev_xmit(struct sk_buff *skb, struct net_device *dev)
unsigned int proto = ntohs(skb->protocol);
struct gtp5g_pktinfo pktinfo;
int ret = 0;
u64 rxVol = skb->len;

/* Ensure there is sufficient headroom */
if (skb_cow_head(skb, dev->needed_headroom)) {
Expand All @@ -112,7 +114,7 @@ static netdev_tx_t gtp5g_dev_xmit(struct sk_buff *skb, struct net_device *dev)
switch (proto) {
case ETH_P_IP:
ret = gtp5g_handle_skb_ipv4(skb, dev, &pktinfo);
update_usage_statistic(gtp, skb->len, ret, SRC_INTF_CORE); // DL
update_usage_statistic(gtp, rxVol, skb->len, ret, SRC_INTF_CORE); // DL
break;
default:
ret = -EOPNOTSUPP;
Expand Down
5 changes: 3 additions & 2 deletions src/gtpu/encap.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ static int gtp1u_udp_encap_recv(struct gtp5g_dev *gtp, struct sk_buff *skb)
u8 gtp_type;
u32 teid;
int rt = 0;
u64 rxVol = skb->len - sizeof(struct udphdr); // exclude UDP header of GTP packet

if (!pskb_may_pull(skb, pull_len)) {
GTP5G_ERR(gtp->dev, "Failed to pull skb length %#x\n", pull_len);
Expand Down Expand Up @@ -346,9 +347,9 @@ static int gtp1u_udp_encap_recv(struct gtp5g_dev *gtp, struct sk_buff *skb)

end:
if (pdr && pdr->pdi) {
update_usage_statistic(gtp, skb->len, rt, pdr->pdi->srcIntf);
update_usage_statistic(gtp, rxVol, skb->len, rt, pdr->pdi->srcIntf);
} else {
update_usage_statistic(gtp, skb->len, rt, SRC_INTF_ACCESS);
update_usage_statistic(gtp, rxVol, skb->len, rt, SRC_INTF_ACCESS);
}

return rt;
Expand Down