netlab Multi-Platform Custom Configuration Templates

In the Building a BGP Anycast Lab I described how you could use custom configuration templates to extend the netlab functionality.

That example used Cisco IOS… but what if you want to test the same functionality on multiple platforms? netlab provides a nice trick: the custom configuration template could point to a directory with platform-specific templates. Let me show you how that works…

We’ll start with the BGP anycast topology, but change the lab devices to a mix of Cisco IOS, Arista EOS, and Cumulus VX:

  • Most devices will run Cisco IOSv
  • One of the leaf switches and one of the anycast nodes will run Arista EOS
  • Another anycast node will run Cumulus VX
Physical lab topology

Physical lab topology

Lab topology definition
module: [ ospf, bgp ]
defaults.bgp.attributes.node.anycast: { type: ipv4, use: prefix }

bgp:
  as_list:
    65000:
      members: [ l1, l2, l3, s1 ]
      rr: [ s1 ]
    65101:
      members: [ a1,a2,a3 ]

defaults.device: iosv

nodes: 
  l1:
  l2:
    device: eos
  l3:
  s1:
  a1:
  a2:
    device: eos
  a3:
    device: cumulus

links: [ s1-l1, s1-l2, s1-l3, l2-a1, l2-a2, l3-a3 ]

Now for the multi-platform custom configuration trick: we’ll specify directories instead of template file names in group config attributes (read the BGP anycast blog post for more details).

Using directories as custom configuration templates
groups:
  as65000:
    config: [ bgp-addpath ]
  as65101:
    config: [ bgp-anycast ]
    node_data:
      bgp.anycast: 10.42.42.42/32
      bgp.advertise_loopback: False

The final lab topology file is available on GitHub.

We’ll have three files within the bgp-anycast directory: ios.j2, eos.j2 and cumulus.j2:

Custom configuration template for Cisco IOS (bgp-anycast/ios.j2)
{% if bgp is defined and bgp.anycast is defined %}
interface loopback 42
 ip address {{ bgp.anycast|ipaddr('address') }} {{ bgp.anycast|ipaddr('netmask') }}
!
router bgp {{ bgp.as }}
 address-family ipv4
  network {{ bgp.anycast|ipaddr('address') }} mask {{ bgp.anycast|ipaddr('netmask') }}
{% endif %}
Custom configuration template for Arista EOS (bgp-anycast/eos.j2)
{% if bgp is defined and bgp.anycast is defined %}
interface loopback 42
 ip address {{ bgp.anycast }}
!
router bgp {{ bgp.as }}
 address-family ipv4
  network {{ bgp.anycast|ipaddr('0') }}
{% endif %}
Custom configuration template for Cumulus VX (bgp-anycast/cumulus.j2)
{% if bgp is defined and bgp.anycast is defined %}
interface lo
 ip address {{ bgp.anycast }} label anycast
!
router bgp {{ bgp.as }}
 address-family ipv4
  network {{ bgp.anycast|ipaddr('0') }}
{% endif %}

Ansible playbook printout generated during the lab initialization (using netlab up -q command) displays the templates used to configure lab devices – as you can see, every platform uses a different configuration template.

# ios_config: deploying bgp-anycast from /home/pipi/net101/multi-platform/bgp-anycast/bgp-anycast/ios.j2 ******************
  * a1                         - changed=True --  ---------------------------------------------
...
# eos_config: deploying bgp-anycast from /home/pipi/net101/multi-platform/bgp-anycast/bgp-anycast/eos.j2 ******************
  * a2                         - changed=True --  ---------------------------------------------
.....
# run vtysh to import bgp-anycast config from /home/pipi/net101/multi-platform/bgp-anycast/bgp-anycast/cumulus.j2 *********
  * a3                         - changed=True --  ---------------------------------------------
...
# ios_config: deploying bgp-addpath from /home/pipi/net101/multi-platform/bgp-anycast/bgp-addpath/ios.j2 ******************
  * l1                         - changed=True --  ---------------------------------------------
...
# eos_config: deploying bgp-addpath from /home/pipi/net101/multi-platform/bgp-anycast/bgp-addpath/eos.j2 ******************
  * l2                         - changed=True --  ---------------------------------------------
...
# ios_config: deploying bgp-addpath from /home/pipi/net101/multi-platform/bgp-anycast/bgp-addpath/ios.j2 ******************
  * l3                         - changed=True --  ---------------------------------------------
...
# ios_config: deploying bgp-addpath from /home/pipi/net101/multi-platform/bgp-anycast/bgp-addpath/ios.j2 ******************
  * s1                         - changed=True --  ---------------------------------------------

Want to test this functionality on your own? Install netlab (and a bunch of other stuff), download the lab topology and custom configuration templates from GitHub, and execute netlab up.

Add comment
Sidebar