Skip to content

Commit

Permalink
implement SBFD
Browse files Browse the repository at this point in the history
Signed-off-by: wumu.zsl <wumu.zsl@alibaba-inc.com>
  • Loading branch information
forrestchu committed Nov 4, 2024
1 parent dfcb75a commit d96c7fd
Show file tree
Hide file tree
Showing 17 changed files with 3,890 additions and 136 deletions.
576 changes: 546 additions & 30 deletions bfdd/bfd.c

Large diffs are not rendered by default.

98 changes: 91 additions & 7 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

#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

/* 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. */
};

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 */
};

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,6 +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
#define UDP_NO_CHECK6_RX 102


/*
Expand All @@ -441,9 +480,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 +559,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 +569,14 @@ 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,24 @@ 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 +630,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 +659,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);

/**
Expand Down Expand Up @@ -651,18 +713,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 @@ -672,6 +738,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 @@ -807,4 +878,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

0 comments on commit d96c7fd

Please sign in to comment.