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

implement SBFD #17336

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
32705fe
bfdd: add enum bfd_mode_type for different bfd types
forrestchu Nov 25, 2024
6648243
bfdd: add bfdname in bfd_key
forrestchu Nov 25, 2024
3796741
bfdd: modify frr-bfdd.yang for sbfd echo and sbfd init
forrestchu Nov 25, 2024
b4d2550
bfdd: add vtysh cmd for sbfd
forrestchu Nov 25, 2024
14cebb4
bfdd: implement sbfd Xpath callbacks
forrestchu Nov 25, 2024
7d06317
bfdd: refactor bfd_session_create
forrestchu Nov 25, 2024
f7e761c
bfdd: add sbfd cmds to bfdd cli
forrestchu Nov 25, 2024
074710b
bfdd: add show sbfd commands
forrestchu Nov 25, 2024
2bda257
bfdd: implement functions for sending sbfd pkts with SRv6 header
forrestchu Nov 25, 2024
1c46d9b
bfdd: add sbfd state machine functions
forrestchu Nov 25, 2024
f055db1
bfdd: create a hash table for local sbfd reflector info
forrestchu Nov 25, 2024
23a05ed
bfdd: enable sbfd session
forrestchu Nov 25, 2024
11a7582
bfdd: process sbfd in packets in bfd_recv_cb
forrestchu Nov 25, 2024
533940e
bfdd: add bfdname info when notify bfd status to PTM
forrestchu Nov 25, 2024
3da528e
bfdd: enable pathd to recv BFD state message
forrestchu Nov 25, 2024
07332d9
bfdd: add some code comments
forrestchu Nov 27, 2024
6daa1ee
bfdd: sbfd Initiator support multihop session
forrestchu Nov 28, 2024
35dc4a4
doc: add sbfd doc
forrestchu Nov 29, 2024
a6270ec
bfdd: Fix topo tests regression issue caused by SBFD code
forrestchu Dec 18, 2024
dbcdd72
tests: add basic topotest cases for sbfd Initiator and Reflector
forrestchu Jan 6, 2025
dbde9e9
bfdd: format code style
forrestchu Jan 7, 2025
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
564 changes: 537 additions & 27 deletions bfdd/bfd.c

Large diffs are not rendered by default.

95 changes: 89 additions & 6 deletions bfdd/bfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "lib/qobj.h"
#include "lib/queue.h"
#include "lib/vrf.h"
#include "lib/bfd.h"

#ifdef BFD_DEBUG
#define BFDD_JSON_CONV_OPTIONS (JSON_C_TO_STRING_PRETTY)
Expand All @@ -27,9 +28,11 @@
#endif

#ifndef MAXNAMELEN
#define MAXNAMELEN 32
#define MAXNAMELEN 128
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we keep 32 ? what is the limit on the configuration perspective?


#define MAXALIASNAMELEN 256

#define BPC_DEF_DETECTMULTIPLIER 3
#define BPC_DEF_RECEIVEINTERVAL 300 /* milliseconds */
#define BPC_DEF_TRANSMITINTERVAL 300 /* milliseconds */
Expand Down Expand Up @@ -86,6 +89,10 @@ struct bfd_peer_cfg {

bool bpc_has_profile;
char bpc_profile[64];

vrf_id_t vrf_id;
char bfd_name[BFD_NAME_SIZE +1];
uint8_t bfd_name_len;
};

/* bfd Authentication Type. */
Expand Down Expand Up @@ -147,6 +154,7 @@ struct bfd_echo_pkt {
uint64_t time_sent_usec;
};

#define BFD_XMTDEL_DELAY_TIMER 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless define. remove it.


/* Macros for manipulating control packets */
#define BFD_VERMASK 0x07
Expand Down Expand Up @@ -194,6 +202,8 @@ struct bfd_echo_pkt {
#define BFD_ECHO_VERSION 1
#define BFD_ECHO_PKT_LEN sizeof(struct bfd_echo_pkt)

#define RTH_BASE_HEADER_LEN 8
#define GET_RTH_HDR_LEN(size) (((size)>>3) - 1)
enum bfd_diagnosticis {
BD_OK = 0,
/* Control Detection Time Expired. */
Expand All @@ -212,6 +222,8 @@ enum bfd_diagnosticis {
BD_ADMIN_DOWN = 7,
/* Reverse Concatenated Path Down. */
BD_REVCONCATPATH_DOWN = 8,
/* Sbfd Detect Function Failed. */
BD_SBFD_DETECT_FAILED = 9,
/* 9..31: reserved. */
Copy link
Member

@pguibert6WIND pguibert6WIND Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment : RFC6428 to inform the user that this value is defined by this RFC.

};

Expand All @@ -233,6 +245,13 @@ enum bfd_session_flags {
BFD_SESS_FLAG_CBIT = 1 << 9, /* CBIT is set */
BFD_SESS_FLAG_PASSIVE = 1 << 10, /* Passive mode */
BFD_SESS_FLAG_MAC_SET = 1 << 11, /* MAC of peer known */
BFD_SESS_FLAG_REM_ADMIN_DOWN = 1 << 13, /* remote notify admindown */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nowhere in the code this value is set. is it really used?

};

enum bfd_mode_type {
BFD_MODE_TYPE_BFD = 0,
BFD_MODE_TYPE_SBFD_ECHO = 1,
BFD_MODE_TYPE_SBFD_INIT = 2,
};

/*
Expand All @@ -254,6 +273,7 @@ struct bfd_key {
struct in6_addr local;
char ifname[IFNAMSIZ];
char vrfname[VRF_NAMSIZ];
char bfdname[MAXNAMELEN];
} __attribute__((packed));

struct bfd_session_stats {
Expand All @@ -264,6 +284,7 @@ struct bfd_session_stats {
uint64_t session_up;
uint64_t session_down;
uint64_t znotification;
uint64_t tx_fail_pkt;
};

/**
Expand Down Expand Up @@ -375,6 +396,12 @@ struct bfd_session {
uint8_t rtt_valid; /* number of valid samples */
uint8_t rtt_index; /* last index added */
uint64_t rtt[BFD_RTT_SAMPLE]; /* RRT in usec for echo to be looped */
char bfd_name[BFD_NAME_SIZE +1];

uint32_t bfd_mode;
uint8_t segnum;
struct in6_addr out_sip6;
struct in6_addr seg_list[0];
};

struct bfd_diag_str_list {
Expand All @@ -396,12 +423,18 @@ struct bfd_session_observer {
};
TAILQ_HEAD(obslist, bfd_session_observer);

/*sbfd reflector struct*/
struct sbfd_reflector{
uint32_t discr;
struct in6_addr local;
};

/* States defined per 4.1 */
#define PTM_BFD_ADM_DOWN 0
#define PTM_BFD_DOWN 1
#define PTM_BFD_INIT 2
#define PTM_BFD_UP 3
#define PTM_BFD_DEL 4


/* Various constants */
Expand All @@ -413,6 +446,7 @@ TAILQ_HEAD(obslist, bfd_session_observer);
#define BFD_DEF_DES_MIN_ECHO_TX (50 * 1000) /* microseconds. */
#define BFD_DEF_REQ_MIN_ECHO_RX (50 * 1000) /* microseconds. */
#define BFD_DEF_SLOWTX (1000 * 1000) /* microseconds. */
#define SBFD_ECHO_DEF_SLOWTX (3000 * 1000) /* microseconds. */
/** Minimum multi hop TTL. */
#define BFD_DEF_MHOP_TTL 254
#define BFD_PKT_LEN 24 /* Length of control packet */
Expand All @@ -427,7 +461,11 @@ TAILQ_HEAD(obslist, bfd_session_observer);
#define BFD_DEFDESTPORT 3784
#define BFD_DEF_ECHO_PORT 3785
#define BFD_DEF_MHOP_DEST_PORT 4784
#define BFD_DEF_SBFD_DEST_PORT 7784

#define BFD_SBFD_INITIATOR_DEMAND 1
#define BFD_IPV6_UDP_DISABLE_CHECKSUM 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused define. please remove.

#define UDP_NO_CHECK6_RX 102
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused define. please remove.


/*
* bfdd.c
Expand All @@ -441,9 +479,10 @@ struct bfd_vrf_global {
int bg_mhop6;
int bg_echo;
int bg_echov6;
int bg_initv6;
struct vrf *vrf;

struct event *bg_ev[6];
struct event *bg_ev[7];
};

/* Forward declaration of data plane context struct. */
Expand Down Expand Up @@ -519,6 +558,7 @@ int bp_set_ttl(int sd, uint8_t value);
int bp_set_tosv6(int sd, uint8_t value);
int bp_set_tos(int sd, uint8_t value);
int bp_bind_dev(int sd, const char *dev);
void bp_set_prio(int sd, int value);

int bp_udp_shop(const struct vrf *vrf);
int bp_udp_mhop(const struct vrf *vrf);
Expand All @@ -528,10 +568,15 @@ int bp_peer_socket(const struct bfd_session *bs);
int bp_peer_socketv6(const struct bfd_session *bs);
int bp_echo_socket(const struct vrf *vrf);
int bp_echov6_socket(const struct vrf *vrf);
int bp_peer_srh_socketv6(struct bfd_session *bs);
int bp_sbfd_socket(const struct vrf *vrf);
int bp_initv6_socket(const struct vrf *vrf);

void ptm_bfd_snd(struct bfd_session *bfd, int fbit);
void ptm_bfd_echo_snd(struct bfd_session *bfd);
void ptm_bfd_echo_fp_snd(struct bfd_session *bfd);
void ptm_sbfd_echo_snd(struct bfd_session *bfd);
void ptm_sbfd_initiator_snd(struct bfd_session *bfd, int fbit);

void bfd_recv_cb(struct event *t);

Expand All @@ -545,13 +590,23 @@ typedef void (*bfd_ev_cb)(struct event *t);

void bfd_recvtimer_update(struct bfd_session *bs);
void bfd_echo_recvtimer_update(struct bfd_session *bs);
void sbfd_init_recvtimer_update(struct bfd_session *bs);
void sbfd_echo_recvtimer_update(struct bfd_session *bs);

void bfd_xmttimer_update(struct bfd_session *bs, uint64_t jitter);
void bfd_echo_xmttimer_update(struct bfd_session *bs, uint64_t jitter);
void sbfd_init_xmttimer_update(struct bfd_session *bs, uint64_t jitter);
void sbfd_echo_xmttimer_update(struct bfd_session *bs, uint64_t jitter);

void bfd_xmttimer_delete(struct bfd_session *bs);
void bfd_echo_xmttimer_delete(struct bfd_session *bs);
void sbfd_init_xmttimer_delete(struct bfd_session *bs);
void sbfd_echo_xmttimer_delete(struct bfd_session *bs);

void bfd_recvtimer_delete(struct bfd_session *bs);
void bfd_echo_recvtimer_delete(struct bfd_session *bs);
void sbfd_init_recvtimer_delete(struct bfd_session *bs);
void sbfd_echo_recvtimer_delete(struct bfd_session *bs);

void bfd_recvtimer_assign(struct bfd_session *bs, bfd_ev_cb cb, int sd);
void bfd_echo_recvtimer_assign(struct bfd_session *bs, bfd_ev_cb cb, int sd);
Expand All @@ -574,6 +629,9 @@ void ptm_bfd_echo_stop(struct bfd_session *bfd);
void ptm_bfd_echo_start(struct bfd_session *bfd);
void ptm_bfd_xmt_TO(struct bfd_session *bfd, int fbit);
void ptm_bfd_start_xmt_timer(struct bfd_session *bfd, bool is_echo);
void ptm_sbfd_init_xmt_TO(struct bfd_session *bfd, int fbit);
void ptm_sbfd_init_reset(struct bfd_session *bfd);
void ptm_sbfd_echo_reset(struct bfd_session *bfd);
struct bfd_session *ptm_bfd_sess_find(struct bfd_pkt *cp,
struct sockaddr_any *peer,
struct sockaddr_any *local,
Expand All @@ -600,14 +658,17 @@ void bs_to_bpc(struct bfd_session *bs, struct bfd_peer_cfg *bpc);

void gen_bfd_key(struct bfd_key *key, struct sockaddr_any *peer,
struct sockaddr_any *local, bool mhop, const char *ifname,
const char *vrfname);
struct bfd_session *bfd_session_new(void);
const char *vrfname, const char *bfdname);

struct bfd_session *bfd_session_new(enum bfd_mode_type mode, uint8_t segnum);

struct bfd_session *bs_registrate(struct bfd_session *bs);
void bfd_session_free(struct bfd_session *bs);
const struct bfd_session *bfd_session_next(const struct bfd_session *bs,
bool mhop);
bool mhop, uint32_t bfd_mode);
void bfd_sessions_remove_manual(void);
void bfd_profiles_remove(void);
void bs_sbfd_echo_timer_handler(struct bfd_session *bs);
void bfd_rtt_init(struct bfd_session *bfd);

extern void bfd_vrf_toggle_echo(struct bfd_vrf_global *bfd_vrf);
Expand Down Expand Up @@ -653,18 +714,22 @@ void bfd_vrf_terminate(void);
struct bfd_vrf_global *bfd_vrf_look_by_session(struct bfd_session *bfd);
struct bfd_session *bfd_id_lookup(uint32_t id);
struct bfd_session *bfd_key_lookup(struct bfd_key key);

struct sbfd_reflector *sbfd_discr_lookup(uint32_t discr);
struct bfd_session *bfd_id_delete(uint32_t id);
struct bfd_session *bfd_key_delete(struct bfd_key key);
struct sbfd_reflector *sbfd_discr_delete(uint32_t discr);

bool bfd_id_insert(struct bfd_session *bs);
bool bfd_key_insert(struct bfd_session *bs);
bool sbfd_discr_insert(struct sbfd_reflector *sr);

typedef void (*hash_iter_func)(struct hash_bucket *hb, void *arg);
void bfd_id_iterate(hash_iter_func hif, void *arg);
void bfd_key_iterate(hash_iter_func hif, void *arg);
void sbfd_discr_iterate(hash_iter_func hif, void *arg);

unsigned long bfd_get_session_count(void);
unsigned long sbfd_discr_get_count(void);

/* Export callback functions for `event.c`. */
extern struct event_loop *master;
Expand All @@ -674,6 +739,11 @@ void bfd_echo_recvtimer_cb(struct event *t);
void bfd_xmt_cb(struct event *t);
void bfd_echo_xmt_cb(struct event *t);

void sbfd_init_recvtimer_cb(struct event *t);
void sbfd_echo_recvtimer_cb(struct event *t);
void sbfd_init_xmt_cb(struct event *t);
void sbfd_echo_xmt_cb(struct event *t);

extern struct in6_addr zero_addr;

/**
Expand Down Expand Up @@ -809,4 +879,17 @@ int bfd_dplane_update_session_counters(struct bfd_session *bs);

void bfd_dplane_show_counters(struct vty *vty);

/*sbfd relfector*/
struct sbfd_reflector *sbfd_reflector_new(const uint32_t discr, struct in6_addr *sip);
void sbfd_reflector_free(const uint32_t discr);
void sbfd_reflector_flush(void);

/*sbfd*/
void ptm_sbfd_echo_sess_dn(struct bfd_session *bfd, uint8_t diag);
void ptm_sbfd_init_sess_dn(struct bfd_session *bfd, uint8_t diag);
void ptm_sbfd_sess_up(struct bfd_session *bfd);
void sbfd_echo_state_handler(struct bfd_session *bs, int nstate);
void sbfd_initiator_state_handler(struct bfd_session *bs, int nstate);

struct bfd_session * bfd_session_get_by_name(const char * name);
#endif /* _BFD_H_ */
Loading