-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite bgp.session plugin to use BGP neighbor generators
- Loading branch information
Showing
4 changed files
with
178 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# BGP neighbor traversal utilities | ||
# | ||
|
||
from box import Box | ||
import typing | ||
|
||
# Return all global and optionaly VRF neighbors | ||
# | ||
def neighbors(node: Box, vrf: bool = True) -> typing.Generator: | ||
for ngb in node.get('bgp.neighbors',[]): | ||
yield ngb | ||
|
||
if not vrf: | ||
return | ||
|
||
for vdata in node.get('vrfs',{}).values(): | ||
for ngb in vdata.get('bgp.neighbors',[]): | ||
yield ngb | ||
|
||
# Return all BGP neighbors associated with interfaces (usually EBGP neighbors) | ||
# | ||
def intf_neighbors(node: Box, vrf: bool = True) -> typing.Generator: | ||
for intf in node.interfaces: | ||
if 'vrf' in intf: | ||
if not vrf: | ||
continue | ||
for ngb in node.vrfs[intf.vrf].get('bgp.neighbors',[]): | ||
if ngb.get('ifindex',None) == intf.ifindex: | ||
yield (intf,ngb) | ||
else: | ||
for ngb in node.get('bgp.neighbors',[]): | ||
if ngb.get('ifindex',None) == intf.ifindex: | ||
yield (intf,ngb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters