Skip to content

Commit

Permalink
Upgrade gtp5g to a58fb426a79997fcb234be56c2ab105d9dfaf7ce
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin <[email protected]>
  • Loading branch information
linouxis9 committed Mar 27, 2024
1 parent 284c7a4 commit 8b8aa72
Show file tree
Hide file tree
Showing 21 changed files with 508 additions and 86 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ PacketRusher borrows libraries and data structures from the [free5gc project](ht
The following is a quick start guide, for more details on the installation, configuration or usage, you may refer to the [wiki](https://github.com/HewlettPackard/PacketRusher/wiki).

### Requirements
- Ubuntu 20.04-22.04
- /!\ gtp5g kernel module does not work on Ubuntu 22.04 HWE kernel (or any distro with kernel later than 5.15.X)
- Ubuntu 20.04-23.04, Debian 12 Bookworm
- All Linux distibutions with kernel >= 5.4 should work, but untested.
- There might be issues with frankenstein kernel from RHEL/CentOS/Rocky, feel free to open a bug if you encounter one!
- Windows is not supported (Windows does not support SCTP)
- Go 1.21.0 or more recent
- Root privilege
Expand Down Expand Up @@ -108,6 +109,7 @@ If you use this software, you may cite it as below:

## License
© Copyright 2023 Hewlett Packard Enterprise Development LP

© Copyright 2024 Valentin D'Emmanuele

This project is under the [Apache 2.0 License](LICENSE) license.
Expand Down
3 changes: 2 additions & 1 deletion lib/gtp5g/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ EXTRA_CFLAGS += -I $(MAKEFILE_DIR)/include
src/gtpu/hash.o \
src/gtpu/link.o \
src/gtpu/net.o \
src/gtpu/pktinfo.o
src/gtpu/pktinfo.o \
src/gtpu/trTCM.o

5G_GENL := src/genl/genl.o \
src/genl/genl_version.o \
Expand Down
59 changes: 38 additions & 21 deletions lib/gtp5g/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ For detailed information, please reference to 3GPP specification TS 29.281 and T
Due to the evolution of Linux kernel, this module would not work with every kernel version.
Please run this module with kernel version `5.0.0-23-generic`, upper than `5.4` (Ubuntu 20.04) or RHEL8.

Please check the [libgtp5gnl](https://github.com/free5gc/libgtp5gnl) version is the same as gtp5g,
because the type translating between libgtp5gnl and gtp5g had been changed.

## Usage
### Compile
```
Expand All @@ -27,27 +24,47 @@ Remove the kernel module from the system
```
sudo make uninstall
```
### Create a gtp5g interface and update Rules
The gtp5g interface will be created by using libgtp5gnl scripts
1) Checkout the latest or compatible source of libgtp5gnl
2) cd libgtp5gnl
3) Create an interface and update rules
+ sudo ./run.sh UPF_PDR_FAR_QER
4) Troubleshoot
### Checkout Rules
Get PDR/FAR/QER information by "/proc"
```
# if UPF used legacy netlink struct without SEID, need use #SEID=0 to query related info as below:
echo #interfaceName #SEID #PDRID > /proc/gtp5g/pdr
echo #interfaceName #SEID #FARID > /proc/gtp5g/far
echo #interfaceName #SEID #QERID > /proc/gtp5g/qer
```
```
cat /proc/gtp5g/pdr
cat /proc/gtp5g/far
cat /proc/gtp5g/qer
```

### QoS Enable
Support Session AMBR and MFBR

1) Check whether QoS is enabled or disabled. (1 means enabled, 0 means disabled)
```
dmesg
cat /proc/gtp5g/qos
```
2) Enable or disable QoS
+ enable
```
echo 1 > /proc/gtp5g/qos
```
+ disable
```
echo 0 > /proc/gtp5g/qos
```
### Log Related
1) check log
```
# if UPF used legacy netlink struct without SEID, need use #SEID=0 to query related info as below:
echo #interfaceName #SEID #PDRID > /proc/gtp5g/pdr
echo #interfaceName #SEID #FARID > /proc/gtp5g/far
echo #interfaceName #SEID #QERID > /proc/gtp5g/qer
dmesg
```
1) update log level
```
cat /proc/gtp5g/pdr
cat /proc/gtp5g/far
cat /proc/gtp5g/qer
# [number] is 0~4
# e.g. echo 4 > /proc/gtp5g/dbg
echo [number] > /proc/gtp5g/dbg
```
5) Delete an interface
+ sudo ./run.sh Clean
+ Note: It will delete list of rules and interface
### Tools
+ [go-gtp5gnl](https://github.com/free5gc/go-gtp5gnl)
4 changes: 4 additions & 0 deletions lib/gtp5g/include/encap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "dev.h"
#include "pktinfo.h"

#define PKT_TO_APP 1
#define PKT_FORWARDED 0
#define PKT_DROPPED -1

enum gtp5g_msg_type_attrs {
GTP5G_BUFFER = 1,
GTP5G_REPORT,
Expand Down
1 change: 1 addition & 0 deletions lib/gtp5g/include/far.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct far {
u64 seid;
u32 id;
u16 action;
u16 seq_number;
struct forwarding_parameter __rcu *fwd_param;
u8 *bar_id;
struct bar *bar;
Expand Down
2 changes: 1 addition & 1 deletion lib/gtp5g/include/genl_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "genl.h"

#define DRV_VERSION "0.8.2"
#define DRV_VERSION "0.8.6"

enum gtp5g_version {
GTP5G_VERSION
Expand Down
9 changes: 8 additions & 1 deletion lib/gtp5g/include/pdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <net/ip.h>

#include "urr.h"
#include "trTCM.h"

#define SEID_U32ID_HEX_STR_LEN 24

Expand Down Expand Up @@ -69,9 +70,9 @@ struct pdr {
u32 *qer_ids;
u32 qer_num;
u8 qfi;
struct qer __rcu *qer_with_rate;
u32 *urr_ids;
u32 urr_num;
struct urr *urr;

/* deprecated: AF_UNIX socket for buffer */
struct sockaddr_un addr_unix;
Expand Down Expand Up @@ -110,6 +111,12 @@ extern void unix_sock_client_delete(struct pdr *);
extern int unix_sock_client_new(struct pdr *);
extern int unix_sock_client_update(struct pdr *, struct far *);

extern int get_qos_enable(void);
extern void set_qos_enable(int);

extern int get_seq_enable(void);
extern void set_seq_enable(int);

static inline bool pdr_addr_is_netlink(struct pdr *pdr)
{
return (pdr->addr_unix.sun_path[0] == '/' && pdr->addr_unix.sun_path[1] == 0);
Expand Down
3 changes: 2 additions & 1 deletion lib/gtp5g/include/pktinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct gtp5g_pktinfo {
struct rtable *rt;
struct outer_header_creation *hdr_creation;
u8 qfi;
u16 seq_number;
struct net_device *dev;
__be16 gtph_port;
};
Expand Down Expand Up @@ -42,7 +43,7 @@ extern void gtp5g_xmit_skb_ipv4(struct sk_buff *, struct gtp5g_pktinfo *);
extern void gtp5g_set_pktinfo_ipv4(struct gtp5g_pktinfo *,
struct sock *, struct iphdr *,
struct outer_header_creation *,
u8, struct rtable *, struct flowi4 *,
u8, u16, struct rtable *, struct flowi4 *,
struct net_device *);
extern void gtp5g_push_header(struct sk_buff *, struct gtp5g_pktinfo *);

Expand Down
6 changes: 6 additions & 0 deletions lib/gtp5g/include/qer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ struct qer {
uint32_t dl_high;
uint8_t dl_low;
} mbr;
u64 ul_mbr;
u64 dl_mbr;

struct {
uint32_t ul_high;
uint8_t ul_low;
Expand All @@ -32,6 +35,8 @@ struct qer {
uint8_t rcsr;
struct net_device *dev;
struct rcu_head rcu_head;

TrafficPolicer *ul_policer, *dl_policer;
};

extern void qer_context_delete(struct qer *);
Expand All @@ -41,5 +46,6 @@ extern void qer_append(u64, u32, struct qer *, struct gtp5g_dev *);
extern int qer_get_pdr_ids(u16 *, int, struct qer *, struct gtp5g_dev *);
extern int qer_set_pdr(struct pdr *, struct gtp5g_dev *);
extern void del_related_qer_hash(struct gtp5g_dev *, struct pdr *);
extern void set_pdr_qer_with_rate_null(struct qer *, struct gtp5g_dev *);

#endif // __QER_H__
24 changes: 24 additions & 0 deletions lib/gtp5g/include/trTCM.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <linux/ktime.h>

typedef enum {
Green,
Yellow,
Red
} Color;

typedef struct {
u64 cbs;
u64 ebs;

u64 tc;
u64 te;

u64 tokenRate;
u64 lastUpdate;

spinlock_t lock;
} TrafficPolicer;

extern TrafficPolicer* newTrafficPolicer(u64);
extern void refillTokens(TrafficPolicer*);
extern Color policePacket(TrafficPolicer*, int);
4 changes: 4 additions & 0 deletions lib/gtp5g/src/genl/genl.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <linux/module.h>
#include <linux/version.h>
#include <net/genetlink.h>

#include "genl.h"
Expand Down Expand Up @@ -179,4 +180,7 @@ struct genl_family gtp5g_genl_family __ro_after_init = {
.n_ops = ARRAY_SIZE(gtp5g_genl_ops),
.mcgrps = gtp5g_genl_mcgrps,
.n_mcgrps = ARRAY_SIZE(gtp5g_genl_mcgrps),
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0)
.resv_start_op = GTP5G_ATTR_MAX,
#endif
};
1 change: 1 addition & 0 deletions lib/gtp5g/src/genl/genl_far.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ static int far_fill(struct far *far, struct gtp5g_dev *gtp, struct genl_info *in
return -EINVAL;

far->id = nla_get_u32(info->attrs[GTP5G_FAR_ID]);
far->seq_number = 0;

if (info->attrs[GTP5G_FAR_SEID])
far->seid = nla_get_u64(info->attrs[GTP5G_FAR_SEID]);
Expand Down
11 changes: 11 additions & 0 deletions lib/gtp5g/src/genl/genl_pdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ static int pdr_fill(struct pdr *pdr, struct gtp5g_dev *gtp, struct genl_info *in
struct nlattr *hdr = nlmsg_attrdata(info->nlhdr, 0);
int remaining = nlmsg_attrlen(info->nlhdr, 0);
struct far *far;
struct qer *qer;
int i;

pdr->seid = 0;

Expand Down Expand Up @@ -486,6 +488,15 @@ static int pdr_fill(struct pdr *pdr, struct gtp5g_dev *gtp, struct genl_info *in

set_pdr_qfi(pdr, gtp);

// set qer with bit rate to pdr structure
for (i = 0; i < pdr->qer_num; i++) {
qer = find_qer_by_id(gtp, pdr->seid, pdr->qer_ids[i]);
if (qer && qer->ul_policer!= NULL && qer->dl_policer!= NULL) {
rcu_assign_pointer(pdr->qer_with_rate, qer);
break;
}
}

if (unix_sock_client_update(pdr, far) < 0)
return -EINVAL;

Expand Down
17 changes: 17 additions & 0 deletions lib/gtp5g/src/genl/genl_qer.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "genl.h"
#include "genl_qer.h"
#include "qer.h"
#include "hash.h"

#include <linux/rculist.h>
#include <net/netns/generic.h>
Expand Down Expand Up @@ -158,6 +159,14 @@ int gtp5g_genl_del_qer(struct sk_buff *skb, struct genl_info *info)
return -ENOENT;
}

// free QoS traffic policer
kfree(qer->ul_policer);
qer->ul_policer = NULL;
kfree(qer->dl_policer);
qer->dl_policer = NULL;
// set related PDR qer_with_rate to NULL
set_pdr_qer_with_rate_null(qer, gtp);

qer_context_delete(qer);
rcu_read_unlock();

Expand Down Expand Up @@ -284,6 +293,9 @@ int gtp5g_genl_dump_qer(struct sk_buff *skb, struct netlink_callback *cb)
return skb->len;
}

u64 concat_bit_rate(u32 highbit, u8 lowbit) {
return (highbit << 8) | lowbit;
}

static int qer_fill(struct qer *qer, struct gtp5g_dev *gtp, struct genl_info *info)
{
Expand All @@ -307,6 +319,11 @@ static int qer_fill(struct qer *qer, struct gtp5g_dev *gtp, struct genl_info *in
qer->mbr.ul_low = nla_get_u8(mbr_param_attrs[GTP5G_QER_MBR_UL_LOW8]);
qer->mbr.dl_high = nla_get_u32(mbr_param_attrs[GTP5G_QER_MBR_DL_HIGH32]);
qer->mbr.dl_low = nla_get_u8(mbr_param_attrs[GTP5G_QER_MBR_DL_LOW8]);

qer->ul_mbr = concat_bit_rate(qer->mbr.ul_high, qer->mbr.ul_low);
qer->dl_mbr = concat_bit_rate(qer->mbr.dl_high, qer->mbr.dl_low);
qer->ul_policer = newTrafficPolicer(qer->ul_mbr);
qer->dl_policer = newTrafficPolicer(qer->dl_mbr);
}

/* GBR */
Expand Down
Loading

0 comments on commit 8b8aa72

Please sign in to comment.