BGP Peer Templates
BGP Peer Templates
BGP Peer Templates
When Cisco introduced peer groups for BGP neighbors, their intention was to associate
neighbors which shared routing policies in an effort to optimize CPU utilization. A side
effect of peer-group configuration is reduced syntax. For example, consider the
following verbose configuration:
These twelve lines become only eight after implementing a peer group, removing much
redundancy from the original configuration:
Unfortunately, because simplified syntax was never the primary goal of peer groups,
they can still be rather unwieldy when attempting to configure neighbors with similar, but
not identical, routing policies.
Around the same time dynamic update peer groups were introduced, Cisco also
debuted BGP peer templates. With the burden of CPU optimization delegated to
dynamic update peer groups, peer templates introduced a much more flexible,
hierarchical peer configuration scheme. There are two types of peer templates: session
templates and policy templates.
Session templates affect the actual BGP session with a neighboring router, whereas
policy templates affect protocol-specific (NLRI) policy (e.g. IPv4 versus IPv6). The
following table lists which parameters are defined in each type of template (as of IOS
12.4T):
Two peer groups have been created: one for IBGP neighbors, and one for EBGP
neighbors. Each group defines some unique session characteristics, but they both also
have one in common (the BGP timers configuration). Because of the way peer groups
work (again, they were originally intended only for CPU optimization), common
attributes must be replicated across peer groups, introducing redundancy in the
configuration.
Admittedly, with only four neighbors and only two significant classifications (EBGP and IBGP), the
improvement might not seem all that drastic. But consider the efficiency afforded when configuring
dozens of BGP peers in a similar matter.
The above example demonstrates peer session templates at work. As you might have guessed,
peer policytemplates work very similarly:
Policy template inheritance works the same way, but with the inherit peer-
policy command.
Template:IBGP, index:2
Local policies:0x1, Inherited polices:0x20
This template inherits:
BGP-All index:1 flags:0x0
Locally configured session commands:
remote-as 65200
Inherited session commands:
timers 30 300
Template:EBGP, index:3
Local policies:0x800, Inherited polices:0x20
This template inherits:
BGP-All index:1 flags:0x0
Locally configured session commands:
ttl-security hops 1
Inherited session commands:
timers 30 300
Some networks have a lot of BGP neighbors. This may sound like a service provider
problem, but it affects the enterprise as well. Think of the newer data center
technologies that use a spine/leaf topology. These include VxLAN/EVPN
and Fabricpath. Each point-to-point network in the topology has a BGP neighbor
relationship configured. This can result in a lot of neighbor configuration.
The way to improve on this is to group neighbors together. There are three ways to
group neighbors:
1. Peer-Groups
2. Dynamic Update Peer-Groups
3. Peer-Templates
The good news is that peer-templates are here to save the day! They were designed
with config reduction in mind. A template is a block of reusable configuration. One
template can inherit settings from another template. This solves the issue of having
neighbors with similar config. Each peer can have one template assigned. Template
inheritance creates a hierarchy of settings. If there is a need to vary from the template
hierarchy, use manual configuration. Manual settings always override template settings.
Templates may not decrease the number of lines of config. It depends on how complex
the environment it. Even so, they can help improve the structure of the configuration.
Session Template – Controls neighbor settings, such as TTL security, timers and
so on
Policy Template – Controls address family settings
Configuration
To see templates in action, we’re going to create a lab. Take a look at the topology
below. There is a core router, which needs to peer with five different routers. For
simplicity, all routers are in the same Autonomous System (65535).
R1, R2, and R3 are ‘Service Provider-1’ routers. Routers R4 and R5 belong to ‘Service
Provider-2’. These descriptions should be added to the neighbor config. Service
provider 1 uses 10/30s timers, while Service provider 2 uses 20/60s timers.
Remote-as
Local-as
Description
Timers
To keep the lab below simple, the routers are pre-configured, and the core router needs
to be configured. The core router already has its interfaces configured.
Without Peer-Templates
With Peer-Templates
The config has a better structure with a peer-template for all the common features.
With a Peer-Template
Core#sh run | sec router
router bgp 65000
template peer-session MyTemplate
remote-as 65535
local-as 65535
exit-peer-session
!
bgp log-neighbor-changes
neighbor 10.10.10.2 inherit peer-session MyTemplate
neighbor 10.10.10.2 description Provider-1
neighbor 10.10.10.2 timers 10 30
neighbor 10.10.20.2 inherit peer-session MyTemplate
neighbor 10.10.20.2 description Provider-1
neighbor 10.10.20.2 timers 10 30
neighbor 10.10.30.2 inherit peer-session MyTemplate
neighbor 10.10.30.2 description Provider-1
neighbor 10.10.30.2 timers 10 30
neighbor 10.10.40.2 inherit peer-session MyTemplate
neighbor 10.10.40.2 description Provider-2
neighbor 10.10.40.2 timers 20 60
neighbor 10.10.50.2 inherit peer-session MyTemplate
neighbor 10.10.50.2 description Provider-2
neighbor 10.10.50.2 timers 20 60
Inheritance
The structure is improved further by adding inheritable templates. In the case below,
there are now three templates:
As you can see, this doesn’t always decrease the number of lines of config. It does
make things more structured and orderly.
Template Inheritance