Creating Route Table showing BGP Neighbor Info

683 views
Skip to first unread message

Ansel Gaddy

unread,
Feb 19, 2015, 7:03:54 PM2/19/15
to junos-p...@googlegroups.com
I am wanting to create a YML for the following style of route table.

all will be receive-protocol bgp
Input Variables: table, peer
Output Variables: rt-destination, rt-prefix-length, as-path, preference,  and community (not sure of the variable for community)

This is my attempt so far. I am thinking there should be two different tables because of inet.0 and inet6.0

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 also


show 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>



Thanks!

Ansel Gaddy

unread,
Feb 19, 2015, 7:33:21 PM2/19/15
to junos-p...@googlegroups.com
Also, curiously enough it seems that this command will take extensive=True but not bgp=True 

works
resultXML = tmp.rpc.get_route_information(table='inet6.0',peer=bgp['neighbor'],extensive=True)
doesn't work
resultXML = tmp.rpc.get_route_information(table='inet6.0',peer=bgp['neighbor'],extensive=True,bgp=True)
...

Rick Sherman

unread,
Feb 20, 2015, 6:36:23 PM2/20/15
to junos-p...@googlegroups.com
Hi Ansel,

It looks like you hit a bug in Junos with regards to show route | display xml rpc (I've opened a bug internally).

The proper format for what you want is:

<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>


You're also able to pass in any RPC variables when using the table get() function.  This is very well documented, so try to address that.

Because of that you're able to do what you need with a single Table/View.

Here is a working example of what you need (I'm also not certain that community string is correct, but it's what I got out of the XML guide):


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')]]


Thank you again for using our framework.

-Rick

Ansel Gaddy

unread,
Feb 21, 2015, 4:11:11 PM2/21/15
to junos-p...@googlegroups.com
Rick,

This worked perfectly.

Running some quick tests between the two, the yml method always seems to be faster.

<user>$ python test.py
Test get_route_information - Elapsed time was 2.36913990974 seconds
Test bgpNeighborTable yml - Elapsed time was 1.14147186279 seconds


if __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()


The level of support from you and your colleagues continues to be amazing.

Thanks again.
-Ansel

Ansel Gaddy

unread,
Feb 22, 2015, 3:33:29 PM2/22/15
to junos-p...@googlegroups.com
Also, the community property needed a little tweaking.

---
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>
...
Reply all
Reply to author
Forward
0 new messages