Checking Advertised BGP Routes To Peers – With PYEZ’S TABLE/VIEW

BGP doesn’t need any introduction because whenever we talk out highly scalable networks or Internet, we talk about BGP only. This is the best protocol to transport any number of routes. Whenever service provider or any customer runs BGP with its internal or external neighbors, they want to see what the BGP advertised routes to the neighbors are.

Every service provider or end customer wants to know what are the advertised routes towards the upstream peering so that during time of outages routes manipulation can be taken care. In this post, I have written a script by using the BGP Table View which can be used to dynamically create a view what is being advertised to peers by using different attributes mentioned in XML table.

Previous post “Display Static Routes With PyEZ Table and View” helps to understand how PYeZ framework can be used to display the static routes. I am using the same framework with different RPCs to show how dynamically we can display per peer neighbor advertised routes.

To achieve this, we need to know how many BGP neighbors we have and how many prefixes are advertised to each BGP neighbor.
Below is the python code which has been written to get the desired output of advertised route per neighbor.

from jnpr.junos import Device
from jnpr.junos.factory.factory_loader import FactoryLoader
import yaml
from jnpr.junos.op.xcvr import XcvrTable

yml = “””

rpc: get-route-information
advertising-protocol-name: bgp
extensive: True
item: route-table/rt
key: rt-destination
view: bgpAdvertiseView

rt_destination: rt-destination
rt_prefix_length: rt-prefix-length
rt_protocol_name: rt-entry/protocol-name
bgp_group_name: rt-entry/bgp-group-name
bgp_nh: rt-entry/nh/to
rt_med: rt-entry/med
rt_local_preference: rt-entry/local-preference
rt_as_path: rt-entry/as-path
rt_communities: rt-entry/communities/community

rpc: get-bgp-summary-information


with Device(‘your device ip address’, port=’7020′, user=’useryourname’,passwd=’yourpassword’) as dev:
op = dev.rpc.get_bgp_summary_information()
for i in op.xpath(‘bgp-peer/peer-address’):
load_bgp = bgpAdvertiseRoutes(dev).get(neighbor=i.text)
print(“n—————–BGP Advertising Routes For:”, i.text, “—————–“)
for item in load_bgp:
print(“Advertising_Route:”,item.rt_destination,”Prefix_Lengh:”,item.rt_prefix_length,”MED:”,item.rt_med,”LP:”,item.rt_local_preference,”AS_Path:”,item.rt_as_path, “Communities:”,item.rt_communities


Share on facebook
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Become a member

Full Access to 739 Lessons. New Lessons Added Every Week!

Awesome Deal! Get 2 Months for FREE!

No Obligations. Cancel At Any Time!