AS Class Code Example - jfuruness/bgpy_pkg GitHub Wiki
Routing Policy Code Example
Then there are extensions of the BGP Policy class. You can configure the routing policy to do basically whatever you want, but often the extensions are fairly simple. This is an example of an extension of BGP to perform ROV, where all we need to do is extend the function that checks the validity of the announcement to include a check to see if itโs invalid for ROV
You can see the code here, but I've also copied it into the documentation for ease of viewing
from bgpy.simulation_engine import BGP
from bgpy.simulation_engine import Announcement as Ann
from bgpy.shared.enums import Relationships
class ROV(BGP):
"""An Policy that deploys ROV"""
name: str = "TutorialROV"
def _valid_ann(self, ann: Ann, recv_rel: Relationships) -> bool:
"""Returns announcement validity
Returns false if invalid by roa,
otherwise uses standard BGP (such as no loops, etc)
to determine validity
"""
# Invalid by ROA is not valid by ROV
if ann.invalid_by_roa:
return False
# Use standard BGP to determine if the announcement is valid
else:
return super(ROV, self)._valid_ann(ann, recv_rel)
And here is the example for Peer ROV (which only filters announcements coming from peers:
from bgpy.shared.enums import Relationships
from bgpy.simulation_engine import BGP
from bgpy.simulation_engine import Announcement as Ann
class PeerROV(BGP):
"""An Policy that deploys PeerROV"""
name: str = "TutorialPeerROV"
def _valid_ann(self, ann: Ann, recv_rel: Relationships) -> bool:
"""Returns announcement validity
Returns false if invalid by roa and coming from a peer,
otherwise uses standard BGP (such as no loops, etc)
to determine validity
"""
# Invalid by ROA is not valid by ROV
# Since this type of real world ROV only does peer filtering, only peers here
if ann.invalid_by_roa and ann.recv_relationship == Relationships.PEERS:
return False
# Use standard BGP to determine if the announcement is valid
else:
return super(PeerROV, self)._valid_ann(ann, recv_rel)