Skip to content

Commit 776a409

Browse files
committed
pfcp: pfcp-peer-list async broadcast
While launching schedule association setup request to remote pfcp peer list. Signed-off-by: Alexandre Cassen <acassen@gmail.com>
1 parent 31aad9f commit 776a409

File tree

5 files changed

+105
-15
lines changed

5 files changed

+105
-15
lines changed

src/pfcp/include/pfcp_proto_hdl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "pfcp_session.h"
2626

2727
/* Prototypes */
28+
void pfcp_assoc_setup_request_send(struct thread *t);
2829
int pfcp_proto_hdl(struct pfcp_server *srv, struct sockaddr_storage *addr);
2930
int gtpu_send_end_marker(struct gtp_server *srv, struct pfcp_teid *t);
3031
int pfcp_gtpu_hdl(struct gtp_server *s, struct sockaddr_storage *addr_from);

src/pfcp/include/pfcp_router.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,23 @@ enum pfcp_debug_flags {
4444
PFCP_DEBUG_FL_EGRESS_MSG,
4545
};
4646

47+
struct pfcp_peer_list {
48+
char name[GTP_NAME_MAX_LEN];
49+
char description[GTP_STR_MAX_LEN];
50+
union addr addr[PFCP_PEER_MAX];
51+
int nr_addr;
52+
53+
struct list_head next;
54+
};
55+
4756
struct pfcp_router {
4857
char name[GTP_NAME_MAX_LEN];
4958
char description[GTP_STR_MAX_LEN];
5059
uint8_t supported_features[4];
5160
struct gtp_bpf_prog *bpf_prog;
5261
struct pfcp_bpf_data *bpf_data;
5362
struct list_head bpf_list;
63+
struct pfcp_peer_list *peer_list;
5464
struct pfcp_server s;
5565
unsigned long debug;
5666

@@ -72,15 +82,6 @@ struct pfcp_router {
7282
struct list_head next;
7383
};
7484

75-
struct pfcp_peer_list {
76-
char name[GTP_NAME_MAX_LEN];
77-
char description[GTP_STR_MAX_LEN];
78-
union addr addr[PFCP_PEER_MAX];
79-
int nr_addr;
80-
81-
struct list_head next;
82-
};
83-
8485

8586
/* Prototypes */
8687
struct pfcp_peer_list *pfcp_peer_list_get(const char *name);

src/pfcp/pfcp_proto_hdl.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,53 @@ pfcp_assoc_setup_request(struct pfcp_msg *msg, struct pfcp_server *srv,
144144
return 0;
145145
}
146146

147+
static int
148+
pfcp_assoc_setup_response(struct pfcp_msg *msg, struct pfcp_server *srv,
149+
struct sockaddr_storage *addr)
150+
{
151+
152+
153+
return 0;
154+
}
155+
156+
void
157+
pfcp_assoc_setup_request_send(struct thread *t)
158+
{
159+
struct pfcp_router *ctx = THREAD_ARG(t);
160+
struct pfcp_peer_list *plist = ctx->peer_list;
161+
struct pkt_buffer *pbuff;
162+
struct pfcp_hdr *pfcph;
163+
int err = 0, i;
164+
165+
/* Prepare pkt */
166+
pbuff = pkt_buffer_alloc(INET_BUFFER_SIZE);
167+
pfcph = (struct pfcp_hdr *) pbuff->head;
168+
pfcph->version = 1;
169+
pfcph->type = PFCP_ASSOCIATION_SETUP_REQUEST;
170+
pfcph->sqn_only = htonl(1 << 8);
171+
172+
err = pfcp_ie_put_node_id(pbuff, ctx->node_id, ctx->node_id_len);
173+
err = (err) ? : pfcp_ie_put_recovery_ts(pbuff, ctx->recovery_ts);
174+
err = (err) ? : pfcp_ie_put_up_function_features(pbuff, ctx->supported_features);
175+
if (err) {
176+
log_message(LOG_INFO, "%s(): Error while Appending IEs"
177+
, __FUNCTION__);
178+
goto end;
179+
}
180+
181+
/* Broadcast pkt to peer list */
182+
for (i = 0; i < plist->nr_addr; i++) {
183+
/* TODO: only support IPv4 peer from now */
184+
if (plist->addr[i].family != AF_INET)
185+
continue;
186+
187+
inet_server_snd(&ctx->s.s, ctx->s.s.fd, pbuff, &plist->addr[i].sin);
188+
}
189+
190+
end:
191+
pkt_buffer_free(pbuff);
192+
}
193+
147194

148195
/* Session Establishment */
149196
static struct gtp_apn *
@@ -387,6 +434,7 @@ static const struct {
387434
[PFCP_HEARTBEAT_REQUEST] = { pfcp_heartbeat_request },
388435
[PFCP_PFD_MANAGEMENT_REQUEST] = { pfcp_pfd_management_request },
389436
[PFCP_ASSOCIATION_SETUP_REQUEST] = { pfcp_assoc_setup_request },
437+
[PFCP_ASSOCIATION_SETUP_RESPONSE] = { pfcp_assoc_setup_response },
390438
[PFCP_ASSOCIATION_UPDATE_REQUEST] = { NULL },
391439
[PFCP_ASSOCIATION_RELEASE_REQUEST] = { NULL },
392440
[PFCP_NODE_REPORT_REQUEST] = { NULL },

src/pfcp/pfcp_router.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extern struct thread_master *master;
3939

4040

4141
/*
42-
* PFCP Peer utilities
42+
* PFCP Peer list utilities
4343
*/
4444
struct pfcp_peer_list *
4545
pfcp_peer_list_get(const char *name)

src/pfcp/pfcp_router_vty.c

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "pfcp_router.h"
2929
#include "inet_server.h"
3030
#include "pfcp_assoc.h"
31+
#include "pfcp_proto_hdl.h"
3132
#include "pfcp.h"
3233
#include "inet_utils.h"
3334
#include "command.h"
@@ -162,6 +163,33 @@ DEFUN(pfcp_router_bpf_prog,
162163
return CMD_SUCCESS;
163164
}
164165

166+
DEFUN(pfcp_router_peer_list,
167+
pfcp_router_peer_list_cmd,
168+
"pfcp-peer-list STRING",
169+
"Use Specific PFCP Peer list\n"
170+
"PFCP Peer list name")
171+
{
172+
struct pfcp_router *c = vty->index;
173+
struct pfcp_peer_list *plist;
174+
175+
if (argc < 1) {
176+
vty_out(vty, "%% missing arguments%s", VTY_NEWLINE);
177+
return CMD_WARNING;
178+
}
179+
180+
plist = pfcp_peer_list_get(argv[0]);
181+
if (!plist) {
182+
vty_out(vty, "%% unknown pfcp-peer-list:'%s'%s"
183+
, argv[0], VTY_NEWLINE);
184+
return CMD_WARNING;
185+
}
186+
187+
c->peer_list = plist;
188+
thread_add_event(master, pfcp_assoc_setup_request_send, c, 0);
189+
190+
return CMD_SUCCESS;
191+
}
192+
165193
DEFUN(pfcp_listen,
166194
pfcp_listen_cmd,
167195
"listen (A.B.C.D|X:X::X:X) port <1024-65535>",
@@ -479,7 +507,7 @@ DEFUN(pfcp_peer_list,
479507
return CMD_WARNING;
480508
}
481509

482-
vty->node = PFCP_ROUTER_NODE;
510+
vty->node = PFCP_PEER_LIST_NODE;
483511
vty->index = new;
484512
return CMD_SUCCESS;
485513
}
@@ -524,9 +552,10 @@ DEFUN(pfcp_peer_list_desciption,
524552

525553
DEFUN(pfcp_peer,
526554
pfcp_peer_cmd,
527-
"peer STRING",
555+
"peer (A.B.C.D|X:X::X:X)",
528556
"Create a PFCP Peer\n"
529-
"PFCP Peer")
557+
"PFCP IPv4 Peer\n"
558+
"PFCP IPv6 Peer\n")
530559
{
531560
struct pfcp_peer_list *p = vty->index;
532561
int err;
@@ -542,6 +571,12 @@ DEFUN(pfcp_peer,
542571
return CMD_WARNING;
543572
}
544573

574+
if (p->nr_addr >= PFCP_PEER_MAX) {
575+
vty_out(vty, "%% Maximum peer per list reached:%d%s"
576+
, p->nr_addr, VTY_NEWLINE);
577+
return CMD_WARNING;
578+
}
579+
545580
switch (p->addr[p->nr_addr].family) {
546581
case AF_INET:
547582
if (!p->addr[p->nr_addr].sin.sin_port)
@@ -609,6 +644,9 @@ config_pfcp_router_write(struct vty *vty)
609644
if (c->bpf_prog)
610645
vty_out(vty, " bpf-program %s%s"
611646
, c->bpf_prog->name, VTY_NEWLINE);
647+
if (c->peer_list)
648+
vty_out(vty, " pfcp-peer-list %s%s"
649+
, c->peer_list->name, VTY_NEWLINE);
612650
srv = &c->s;
613651
if (srv->s.addr.ss_family)
614652
vty_out(vty, " listen %s port %d%s"
@@ -664,6 +702,7 @@ config_pfcp_peer_list_write(struct vty *vty)
664702
, VTY_NEWLINE);
665703
}
666704

705+
vty_out(vty, "!\n");
667706
}
668707

669708
return 0;
@@ -684,6 +723,7 @@ cmd_ext_pfcp_router_install(void)
684723
install_element(PFCP_ROUTER_NODE, &pfcp_router_description_cmd);
685724
install_element(PFCP_ROUTER_NODE, &pfcp_node_id_cmd);
686725
install_element(PFCP_ROUTER_NODE, &pfcp_router_bpf_prog_cmd);
726+
install_element(PFCP_ROUTER_NODE, &pfcp_router_peer_list_cmd);
687727
install_element(PFCP_ROUTER_NODE, &pfcp_listen_cmd);
688728
install_element(PFCP_ROUTER_NODE, &pfcp_debug_cmd);
689729
install_element(PFCP_ROUTER_NODE, &pfcp_debug_teid_cmd);
@@ -703,7 +743,7 @@ cmd_ext_pfcp_router_install(void)
703743
}
704744

705745
static int
706-
cmd_ext_pfcp_peer_install(void)
746+
cmd_ext_pfcp_peer_list_install(void)
707747
{
708748
/* Install PFCP Router commands. */
709749
install_element(CONFIG_NODE, &pfcp_peer_list_cmd);
@@ -738,7 +778,7 @@ struct cmd_node pfcp_peer_list_node = {
738778

739779
static struct cmd_ext cmd_ext_pfcp_peer_list = {
740780
.node = &pfcp_peer_list_node,
741-
.install = cmd_ext_pfcp_peer_install,
781+
.install = cmd_ext_pfcp_peer_list_install,
742782
};
743783

744784
static void __attribute__((constructor))

0 commit comments

Comments
 (0)