BGP and peer templates

January 16, 2017

BGP peer templates are used to summarise configuration options for re-use on multiple BGP peers. This enables the setup of a BGP peer to be made simple, and any changes to the templates will affect all peers using it.

Configuring peer templates

Peer templates are divided into session and policy templates. It is possible to use one of each on a neighbouring peer. The difference between the templates is the ability to create inheritance only with policy templates. This means you can create a very general policy template which can be used as a basis for more specific templates.

An example can illustrate the advantage of using peer templates:

Without peer templates:

router bgp 100
    neighbor 10.0.0.1 remote-as 200
    neighbor 10.0.0.1 password OurPassword
    neighbor 10.0.0.1 soft-configuration in
    neighbor 10.0.0.1 prefix-list BGP-in in
    neighbor 10.0.0.1 send-community both
    neighbor 10.0.0.1 route-map LPREF-out
    neighbor 10.0.0.1 default-originate

Assuming we have created one session template and one policy template:

router bgp 100
    neighbor 10.0.0.1 inherit peer-session BGP
    neighbor 10.0.0.1 inherit peer-policy BGP

The peer templates we make will look like this:

router bgp 100
    template peer-session BGP
     remote-as 200
     password OurPassword
    exit-peer-session
!
    template peer-policy BGP
     prefix-list BGP-in in
     soft-configuration inbound
     send-community both
     route-map LPREF
     default-originate
    exit-peer-policy

And with the ability to inherit within the policy templates it is possible to create some really clever setups, making the creation of new peers very simple. One example where using policy templates can be beneficial is if you purposely want to move traffic from one node to another. By setting up a route-map for adjusting route selection it is possible completely drain a device for traffic by simply adjusting a value and forcing a BGP refresh.

Overriding options

It is also possible to override values in the templates by adding them as a separate option on the neighborship. One example is using prefix-lists in the peer policy. If you use the general prefix list as standard, suddenly a customer arrives where it is necessary to use a custom prefix-list.

router bgp 100
    neighbor 10.0.0.1 inherit peer-session BGP
    neighbor 10.0.0.1 prefix-list Customer-A-in in
    neighbor 10.0.0.1 inherit peer-policy BGP

In this case the Customer-A-in prefix-list will override the prefix-list in the peer-policy BGP.

Inheritance

The peer-policy template is able to inherit seven levels of templates. This makes it possible to build a powerful and very flexible template configuration. In the peer configuration it will still only be one inherit statement for the peer-policy, and then the peer-policy template will be the one inheriting the next templates. Session templates are not able to inherit any other templates.

BGP peer templates are the preferred option for grouping BGP configuration for peers. Previously BGP peer groups has been used for this functionality, but the flexibility of templates has made it the top choice. It is not possible to use both peer groups and peer templates in the same neighbor configuration.

Summary

BGP peer templates is an advanced feature for grouping policies and applying them to BGP peers. In a small environment the gains of using this feature may be small, but in an evironment with many BGP sessions this feature can save plenty of configuration as well as provide a consistent policy implementation.

Resources:
Cisco documentation on BGP peer templates
PacketLife on BGP peer templates

733