LLDP neighbor graphing

In this section, we will use the example of mapping out LLDP neighbors to illustrate a problem-solving pattern that has helped me over the years:

  1. Modularize each task into smaller pieces, if possible. In our example, we can combine a few steps, but if we break them into smaller pieces, we will be able to reuse and improve them easily.
  2. Use an automation tool to interact with the network devices, but keep the more complex logic aside at the management station. For example, the router has provided an LLDP neighbor output that is a bit messy. In this case, we will stick with the working command and the output and use a Python script at the management station to parse and receive the output we need.
  1. When presented with choices for the same task, pick the one that can be reused. In our example, we can use low-level Pexpect, Paramiko, or Ansible playbooks to query the routers. In my opinion, it will be easier to reuse Ansible in future, so that is what I have picked.

To get started, since LLDP is not enabled on the routers by default, we will need to configure them on the devices first. By now, we know we have a number of options to choose from; in this case, I chose the Ansible playbook with the ios_config module for the task. The hosts file consists of five routers:

$ cat hosts
[devices]
r1 ansible_hostname=172.16.1.218
r2 ansible_hostname=172.16.1.219
r3 ansible_hostname=172.16.1.220
r5-tor ansible_hostname=172.16.1.221
r6-edge ansible_hostname=172.16.1.222

The cisco_config_lldp.yml playbook consists of one play with variables embedded in the playbook to configure the LLDP:

<skip>
vars:
cli:
host: "{{ ansible_hostname }}"
username: cisco
password: cisco
transport: cli tasks:
- name: enable LLDP run
ios_config:
lines: lldp run
provider: "{{ cli }}"
<skip>

After a few seconds, to allow LLDP exchange, we can verify that LLDP is indeed active on the routers:

r1#show lldp neighbors

Capability codes: (R) Router, (B) Bridge, (T) Telephone, (C) DOCSIS Cable Device (W) WLAN Access Point, (P) Repeater, (S) Station, (O) Other

Device ID Local Intf Hold-time Capability Port ID
r2.virl.info Gi0/0 120 R Gi0/0
r3.virl.info Gi0/0 120 R Gi0/0
r5-tor.virl.info Gi0/0 120 R Gi0/0
r5-tor.virl.info Gi0/1 120 R Gi0/1
r6-edge.virl.info Gi0/2 120 R Gi0/1
r6-edge.virl.info Gi0/0 120 R Gi0/0

Total entries displayed: 6

In the output, you will see that G0/0 is configured as the MGMT interface; therefore, you will see LLDP peers as if they are on a flat management network. What we really care about is the G0/1 and G0/2 interfaces connected to other peers. This knowledge will come in handy as we prepare to parse the output and construct our topology graph.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.182.66