CLI L2 Data Plugin

CLI L2 Data Plugin can produce diagrams based on OSI model layer 2 information, hence the name “layer 2”. This plugin builds network diagrams with relationships and nodes using CDP and LLDP protocols neighbors information. In addition, adding L1/L2 related data to diagram elements.

CLI L2 Data Plugin uses TTP templates to parse show commands output and transform them in Python dictionary structure. That structure processed further to build a dictionary compatible with N2G’s diagram plugins from_dict method. That method used to populate diagrams with devices and links information.

In addition to parsing relationships for CDP and LLDP protocols, L2 Data Plugin can help to manipulate diagrams by combining links based on certain criteria, adding additional information to elements meta data and adding unknown (to CDP and LLDP) but connected nodes to diagram.

Features Supported

Support matrix

Platform Name CDP peers LLDP peers interface config interface state LAG links links grouping node facts Add all connected Combine peers
cisco_ios YES YES YES YES YES YES YES YES YES
cisco_xr YES YES YES YES YES YES YES YES
cisco_nxos YES YES YES YES YES YES YES YES YES
huawei YES YES YES YES YES YES

Features Description

  • CDP peers - adds links and nodes for CDP neighbors
  • LLDP peers - adds links and nodes for LLDP neighbors
  • interface config - adds interfaces configuration to links data
  • interface state - add links state information to links data
  • LAG links - combines links based on LAG membership
  • links grouping - groups links between nodes
  • node facts - adds information to nodes for vlans configuration
  • Add all connected - add nodes for connected interfaces that has no peers via CDP or LLDP
  • Combine peers - groups CDP/LLDP peers behind same port by adding “L2” node

Required Commands output

cisco_ios, cisco_xr, cisco_nxos:

  • show cdp neighbor details and/or show lldp neighbor details - mandatory
  • show running-configuration - optional, used for LAG and interfaces config
  • show interface - optional, used for interfaces state and to add all connected nodes

huawei:

  • display lldp neighbor details - mandatory
  • display current-configuration - optional, used for LAG and interfaces config
  • display interface - optional, used for interfaces state and to add all connected nodes

Sample Usage

Code to populate yEd diagram object with CDP and LLDP sourced nodes and links:

from N2G import cli_l2_data, yed_diagram

data = {"cisco_ios": ['''
switch-1#show cdp neighbors detail
-------------------------
Device ID: switch-2
Entry address(es):
  IP address: 10.2.2.2
Platform: cisco WS-C6509,  Capabilities: Router Switch IGMP
Interface: GigabitEthernet4/6,  Port ID (outgoing port): GigabitEthernet1/5

-------------------------
Device ID: switch-3
Entry address(es):
  IP address: 10.3.3.3
Platform: cisco WS-C3560-48TS,  Capabilities: Switch IGMP
Interface: GigabitEthernet1/1,  Port ID (outgoing port): GigabitEthernet0/1

-------------------------
Device ID: switch-4
Entry address(es):
  IP address: 10.4.4.4
Platform: cisco WS-C3560-48TS,  Capabilities: Switch IGMP
Interface: GigabitEthernet1/2,  Port ID (outgoing port): GigabitEthernet0/10

switch-1#show run
interface GigabitEthernet4/6
 description switch-2: access
 switchport
 switchport access vlan 2150
 switchport mode access
 spanning-tree portfast edge
!
interface GigabitEthernet1/1
 description switch-3:Gi0/1
 switchport
 switchport trunk allowed vlan 1771,1887
 switchport mode trunk
 mtu 9216
!
interface GigabitEthernet1/2
 description SW4 Routing Peering
 vrf forwarding VRF1
 ip address 10.0.0.1 255.255.255.0
    ''',
    '''
switch-2#show cdp neighbors detail
-------------------------
Device ID: switch-1
Entry address(es):
  IP address: 10.1.1.1
Platform: cisco WS-C6509,  Capabilities: Router Switch IGMP
Interface: GigabitEthernet1/5,  Port ID (outgoing port): GigabitEthernet4/6

switch-2#show run
interface GigabitEthernet1/5
 description switch-1: access
 switchport
 switchport access vlan 2150
 switchport mode access
 spanning-tree portfast edge
    ''']
    }

config = {
    "add_interfaces_data": True,
    "group_links": False,
    "add_lag": False,
    "add_all_connected": False,
    "combine_peers": False,
    "platforms": ["_all_"]
}

drawing_l2 = yed_diagram()
drawer = cli_l2_data(drawing_l2, **config)
drawer.work(data)
drawer.drawing.dump_file()

API Reference

class N2G.plugins.data.cli_l2_data.cli_l2_data(drawing, ttp_vars=None, add_interfaces_data=True, group_links=False, add_lag=False, add_all_connected=False, combine_peers=False, skip_lag=True, platforms=None)

Class to instantiate L2 (layer two) data plugin to process CDP and LLDP neighbors together with devices’ running configuration and state and produce diagram out of it.

Parameters:
  • drawing – (obj) N2G drawing object instantiated using drawing module e.g. yed_diagram or drawio_diagram
  • ttp_vars – (dict) dictionary to use as TTP parser object template variables
  • platforms – (list) - list of platform names to process e.g. cisco_ios, cisco_xr etc, default is _all_
  • add_interfaces_data – (bool) default True, add interfaces configuration and state data to links
  • group_links – (bool) default False, group links between nodes
  • add_lag – (bool) default False, add LAG/MLAG links to diagram
  • add_all_connected – (bool) default False, add all nodes connected to devices based on interfaces state
  • combine_peers` – (bool) default False, combine CDP/LLDP peers behind same interface by adding L2 node
  • skip_lag – (bool) default True, skip CDP peers for LAG, some platforms send CDP/LLDP PDU from LAG ports
work(data)

Method to parse text data and add nodes and links to N2G drawing.

Parameters:data – (dict or str) dictionary or OS path string to directories with text files

If data is dictionary, keys must correspond to “Platform” column in Features Supported section table, values are lists of text items to process.

Data dictionary sample:

data = {
    "cisco_ios" : ["h1", "h2"],
    "cisco_ios": ["h3", "h4"],
    "cisco_nxos": ["h5", "h6"],
    ...etc...
}

Where hX devices show commands output.

If data is an OS path directory string, child directories’ names must correspond to Platform column in Features Supported section table. Each child directory should contain text files with show commands output for each device, names of files are arbitrary, but output should contain device prompt to extract device hostname.

Directories structure sample:

├───folder_with_data
    ├───cisco_ios
    │       switch1.txt
    │       switch2.txt
    └───cisco_nxos
            nxos_switch_1.txt
            nxos_switch_2.txt

To point N2G to above location data attribute string can be /var/data/n2g/folder_with_data/