77_config_name = 'bgp.confederation'
88_requires = [ 'bgp' ]
99
10+ CONFED_EBGP = 'confed_ebgp'
11+
12+ def init (topology : Box ) -> None :
13+ topology .defaults .attributes .bgp_session_type .valid_values [ CONFED_EBGP ] = None
14+ topology .defaults .bgp .attributes ._inherit_community [ CONFED_EBGP ] = 'ibgp'
15+
16+ for af in log .AF_LIST :
17+ if CONFED_EBGP in topology .get (f'bgp.sessions.{ af } ' ,{}):
18+ log .error ( f"Cannot use { CONFED_EBGP } in bgp.sessions" , category = Warning )
19+ if CONFED_EBGP in topology .get (f'bgp.activate.{ af } ' ,{}):
20+ log .error ( f"Cannot use { CONFED_EBGP } in bgp.activate" , category = Warning )
21+
1022def post_transform (topology : Box ) -> None :
1123 global _config_name
1224 confed = topology .get ('bgp.confederation' )
@@ -33,13 +45,15 @@ def post_transform(topology: Box) -> None:
3345 api .node_config (ndata ,_config_name ) # Remember that we have to do extra configuration
3446
3547 for nb in ndata .get ('bgp.neighbors' ,[]): # Update remote AS used by ebgp peers
48+ if nb .type != 'ebgp' : # Only applies to EBGP peers
49+ continue
3650 neighbor = topology .nodes [ nb .name ]
3751 if neighbor .get ('bgp.as' ) in members : # Skip members of the same confederation
3852 continue
53+ nb .type = CONFED_EBGP
3954 for nb2 in neighbor .get ('bgp.neighbors' ,[]):
4055 if nb2 .name == n and nb2 .type == 'ebgp' :
4156 nb2 ['as' ] = casn # Update peer to use the confederation AS instead
42-
43- # TODO: Apply ibgp type community exchange, confed is really a new type of ebgp peer
57+ # nb2.type = CONFED_EBGP # DO NOT update BGP session type - peer device may not support this plugin
4458
4559 break
0 commit comments