[FRR] [BGP protocol analysis] 1-BGP initialization

FRR supports BGP-4, BGP-4+ protocol, knowledge points of BGP protocol itself, you can refer to a lot of information, TCP/IP routing technology is a good book, it is recommended to read it several times, as well as the blog and video of Brother Black Tea  http://blog.sina.com.cn/vinsoney

The initialization starts in the main function of bgp_main.c. Other protocols are similar. For example, the main function of ospf is in ospf_main.c.

The most important thing in main is initialization, including:

Event-driven initialization

Event-driven Each thread must have a struct thread_master to do event-driven (the specific operation mode, I will write an article to introduce it later, this is a big tome), and it also includes the initialization of the work queue and the initialization of the bgp label.

The bgp_master global variable governs all of this and takes the world over.

Initialization of VRF

Initialization of VRF, VRF in FRR is created on Linux, the processing of the entire process, subsequent analysis.

The most important thing is in the function void bgp_init(void)

contain:

  • Thread initialization

Thread initialization, as can be seen from the above, FRR also simulates the concept of threads, but it is different from linux threads. You can talk about it later. BGP threads include bgpd/bgpd_io/bgpd_ka:

From the name, I also know their main tasks:

bgpd_io --- Send and receive packets, then enqueue the message, wake up bgpd to continue processing, the entry function is fpt_run

bgpd --- Process all business logic of BGP, process function frr_run

bgpd_ka-handle BGP keeplive, bgp_keepalives_start

  • Initialization of Zebra

zclient_new creates a zclient client, fills in struct thread_master with the master of bgp, so that the client's callback function is executed in the context of the bgp process

After zclient_init initializes the client-related data, it will call zclient_event to add an event. The callback function is zclient_connect. After the initialization is completed, the subsequent connection with the zebra process will be established.

 

Then it will fill in the callback functions of various events that bgp cares about. In the bgp_zebra_connected callback function (which will be called after the client connects to zebra successfully), various events of BGP interest will be registered, such as router-id, interfaces, redistributed routes.

  • Initialization of the command line

Just register the CLI, nothing to say, the implementation of CLI is also quite complicated, and we will analyze it later

  • Attribute-related initialization

  • aspath_init

aspath_init initializes the hash storage of aspath, the hash header is ashash, all aspaths are stored in the global hash? ?

The relevant data structure is as follows:

  • attrhash_init

attrhash_init initializes the attribute hash storage, the hash header attrhash, all attributes are stored in the global hash? ?

The attr data structure is large and contains all the attributes of BGP, such as AS_PATH, community, med, origin, local_pref, med, etc.

 

  • community

community_init initializes the HASH of the community, the global comhash is stored, and why is it stored in the global? ?

 

  • ecommunity

ecommunity_init initializes the HASH of ecommunity, and stores the global ecomhash

  • lcommunity

lcommunity_init initializes the HASH of lcommunity, global lcomhash storage

  • cluster

cluster_init initializes the HASH of the cluster route reflector, the global variable cluster_hash

  • transit

transit_init initializes the HASH of the transmitted attributes, the global variable transit_hash

 

  • encap

encap_init initializes BGP Encap Hash, I don’t know much, follow-up supplement

  • Initialization of the routing table

 

afi network type (IPV4, IPV6)

safi Subnet type (SAFI_UNICAST, SAFI_MULTICAST, SAFI_RESERVED_3, SAFI_MPLS_VPN, SAFI_ENCAP)

lock reference count

route_table is a collection of routing table entries, which is the same data structure used by zebra to store routing table entries

  • route_map

Initialize the implementation of the route graph and add the callback function of the hook

route_map initialize the implementation of route_map strategy

The specific implementation will be analyzed later

  • mplsvpn

The initialization of MPLS VPN is all the initialization of CLI

  • EVPN

bgp_ethernetvpn_init CLI initialization

 

  • FLOWSPEC

bgp_flowspec_vty_init CLI initialization

  • Access list

 CLI initialization

Function analysis

  • Filter list

CLI initialization

Function analysis

 

  • Prefix list

CLI initialization

    

Function analysis

 

  • Community list

CLI initialization

/* Community list initialize. */

     bgp_clist = community_list_init();

  • BFD init

     

 

Main function continues to initialize

After analysis of frr_config_fork, I did not understand what to deal with

bgp_pthreads_run create thread

Bgp_pthread_run creates the corresponding thread and runs it.

Then frr_run bgpd starts an endless loop, processing various events

 

loading finished! ! ! ! ! ! ! ! !

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_39094034/article/details/115220101
BGP