BGPv4neighborTable:
rpc: get-route-information
args:
bgp: True
extensive: True
table: inet.0
args_key: peer
item: route-table/rt
view: BGPview
BGPv6neighborTable:
rpc: get-route-information
args:
bgp: True
extensive: True
table: inet6.0
args_key: peer
item: route-table/rt
view: BGPview
BGPView:
groups:
rt: rt
fields_rt:
nh: nh/to
as-path: as-path
rt-destination: '..rt-destination' #This may be the wrong way to try to get this
rt-prefix-length: '..rt-prefix-length'#Here alsoshow route table inet.0 receive-protocol bgp 71.42.231.238 extensive | display xml rpc
Feb 19 17:03:10
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/11.4X12/junos">
<rpc>
<get-route-information>
<extensive/>
<table>inet.0</table>
<bgp/>
<peer>71.42.231.238</peer>
</get-route-information>
</rpc>
<cli>
<banner>{master}</banner>
</cli>
</rpc-reply>show route table inet.0 receive-protocol bgp 71.42.231.238 extensive | display xml
Feb 19 17:13:17
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/11.4X12/junos">
<route-information xmlns="http://xml.juniper.net/junos/11.4X12/junos-routing">
<!-- keepalive -->
<route-table>
<table-name>inet.0</table-name>
<destination-count>593260</destination-count>
<total-route-count>1180534</total-route-count>
<active-route-count>593194</active-route-count>
<holddown-route-count>64</holddown-route-count>
<hidden-route-count>4</hidden-route-count>
<rt junos:style="bgp-detail">
<rt-destination>107.178.8.0</rt-destination>
<rt-prefix-length>24</rt-prefix-length>
<rt-entry-count junos:format="1 entry">1</rt-entry-count>
<rt-announced-count>1</rt-announced-count>
<rt-entry>
<active-tag>*</active-tag>
<protocol-name>BGP</protocol-name>
<bgp-rt-flag>Accepted</bgp-rt-flag>
<nh>
<to>71.42.231.238</to>
</nh>
<as-path>AS path: 26077 I
AS path: Recorded
</as-path>
</rt-entry>
</rt>
<rt junos:style="bgp-detail">
<rt-destination>107.178.9.0</rt-destination>
<rt-prefix-length>24</rt-prefix-length>
<rt-entry-count junos:format="1 entry">1</rt-entry-count>
<rt-announced-count>1</rt-announced-count>
<rt-entry>
<active-tag>*</active-tag>
<protocol-name>BGP</protocol-name>
<bgp-rt-flag>Accepted</bgp-rt-flag>
<nh>
<to>71.42.231.238</to>
</nh>
<as-path>AS path: 26077 I
AS path: Recorded
</as-path>
</rt-entry>
</rt>
<rt junos:style="bgp-detail">
<rt-destination>107.178.12.0</rt-destination>
<rt-prefix-length>23</rt-prefix-length>
<rt-entry-count junos:format="1 entry">1</rt-entry-count>
<rt-announced-count>1</rt-announced-count>
<rt-entry>
<active-tag>*</active-tag>
<protocol-name>BGP</protocol-name>
<bgp-rt-flag>Accepted</bgp-rt-flag>
<nh>
<to>71.42.231.238</to>
</nh>
<as-path>AS path: 26077 I
AS path: Recorded
</as-path>
</rt-entry>
</rt>
</route-table>
</route-information>
<cli>
<banner>{master}</banner>
</cli>
</rpc-reply>...
<get-route-information> <table>PE10.inet.0</table> <protocol>bgp</protocol> <peer>172.16.1.24</peer></get-route-information>
>>> dev.rpc.get_route_information(table='PE10.inet.0', protocol='bgp', peer='172.16.1.24', extensive=True)<Element route-information at 0x2b89488>
import yaml
from jnpr.junos.factory.factory_loader import FactoryLoader
from jnpr.junos import Device
yml = '''
---
bgpNeighborTable:
rpc: get-route-information
args:
protocol: bgp
extensive: True
item: route-table/rt
key: rt-destination
view: bgpView
bgpView:
fields:
as-path: rt-entry/as-path
rt_destination: rt-destination
rt_prefix_length: rt-prefix-length
preference: rt-entry/preference
community: communities/community
'''
globals().update(FactoryLoader().load(yaml.load(yml)))
dev = Device(host)
dev.open()
bt = bgpNeighborTable(dev)
bt.get(table='PE10.inet.0', peer='172.16.1.24')
print bt.keys()
print bt.values()
dev.close()
$python test.py['1.1.1.1', '2.2.2.2'][[('preference', '170'), ('rt_prefix_length', '32'), ('rt_destination', '1.1.1.1'), ('community', None), ('as-path', '65001 I')], [('preference', '170'), ('rt_prefix_length', '32'), ('rt_destination', '2.2.2.2'), ('community', None), ('as-path', '65001 I')]]<user>$ python test.py
Test get_route_information - Elapsed time was 2.36913990974 seconds
Test bgpNeighborTable yml - Elapsed time was 1.14147186279 secondsif __name__=='__main__':
dev=Device(host='<ip>',user='<user>',password='<password>')
dev.open(gather_facts=False)
dev.timeout=6000
#test get_route_information
start_time = time.time()
xml = dev.rpc.get_route_information(table='inet.0',protocol='bgp',peer='<BGP peer IP>',extensive=True)
end_time = time.time()
print 'Test get_route_information - Elapsed time was {0} seconds'.format(end_time - start_time)
#test bgpNeighborTable yml
bgp = bgpNeighborTable(dev)
start_time = time.time()
bgp.get(table='inet.0',peer='<BGP peer IP>')
end_time = time.time()
print 'Test bgpNeighborTable yml - Elapsed time was {0} seconds'.format(end_time - start_time)
dev.close()---bgpNeighborTable: rpc: get-route-information args: protocol: bgp extensive: True item: route-table/rt key: rt-destination view: bgpView
bgpView: fields: as_path: rt-entry/as-path rt_destination: rt-destination rt_prefix_length: rt-prefix-length preference: rt-entry/preference community: rt-entry/communities/community<rt junos:style="bgp-detail">
<rt-destination>216.150.35.0</rt-destination>
<rt-prefix-length>24</rt-prefix-length>
<rt-entry-count junos:format="1 entry">1</rt-entry-count>
<rt-announced-count>1</rt-announced-count>
<rt-entry>
<active-tag>*</active-tag>
<protocol-name>BGP</protocol-name>
<bgp-rt-flag>Accepted</bgp-rt-flag>
<nh>
<to>50.84.34.214</to>
</nh>
<as-path>AS path: 13959 13959 13959 I
AS path: Recorded
</as-path>
<communities>
<community>11427:90</community>
</communities>
</rt-entry>
</rt>...