CLI OSPFv2 LSDB Data Plugin
CLI OSPFv2 LSDB Data Plugin can process network devices CLI output of OSPFv2 LSDB content to populate N2G drawing with OSPF topology nodes and links.
CLI output from devices parsed using TTP Templates into a dictionary structure.
After parsing, results processed further to form a dictionary of nodes and links keyed
by unique nodes and links identifiers wit values being nodes dictionaries and for links
it is a list of dictionaries of links between same pair of nodes. For nodes OSPF RID
used as a unique ID, for links it is sorted tuple of source
, target
and label
keys’ values. This structure helps to eliminate duplicates.
Next step is post processing, such as packing links between nodes. By default cli_ospf_data tries to match and pack nodes based on the IP addresses and their subnets, it checks if IP addresses are part of same subnet using prefix lengths - 31, 30, 29, … 22 - if IP addresses happens to be part of same subnet, link packed in one link.
Last step is to populate N2G drawing with new nodes and links using from_dict
method.
Features Supported
Support matrix
Platform Name |
Router LSA |
OSPF Peers |
External LSA |
Summary LSA |
interface config |
interface state |
---|---|---|---|---|---|---|
cisco_ios |
YES |
— |
— |
— |
— |
— |
cisco_xr |
YES |
— |
— |
— |
— |
— |
cisco_nxos |
— |
— |
— |
— |
— |
— |
huawei |
YES |
— |
— |
— |
— |
— |
Required Commands output
cisco_ios:
show ip ospf database router
- mandatory, used to source nodes and links for topologyshow ip ospf database summary
show ip ospf database external
cisco_xr:
show ospf database router
- mandatory, used to source nodes and links for topologyshow ospf database summary
show ospf database external
huawei:
display ospf lsdb router
- mandatory, used to source nodes and links for topology
Sample usage
Code to populate yEd diagram object with OSPF LSDB sourced nodes and links:
from N2G import cli_l2_data, yed_diagram
data = {"cisco_xr": ['''
RP/0/RP0/CPU0:router-1#show ospf database router
OSPF Router with ID (10.0.1.1) (Process ID 1)
Router Link States (Area 0.0.0.0)
LS age: 406
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 10.0.1.1
Advertising Router: 10.0.1.1
LS Seq Number: 8000010c
Checksum: 0x24dd
Length: 132
Number of Links: 9
Link connected to: another Router (point-to-point)
(Link ID) Neighboring Router ID: 10.0.1.4
(Link Data) Router Interface address: 0.0.0.12
Number of TOS metrics: 0
TOS 0 Metrics: 1100
Link connected to: another Router (point-to-point)
(Link ID) Neighboring Router ID: 10.0.1.2
(Link Data) Router Interface address: 0.0.0.10
Number of TOS metrics: 0
TOS 0 Metrics: 1100
Routing Bit Set on this LSA
LS age: 1604
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 10.0.1.2
Advertising Router: 10.0.1.2
LS Seq Number: 8000010b
Checksum: 0xdc96
Length: 132
Number of Links: 9
Link connected to: another Router (point-to-point)
(Link ID) Neighboring Router ID: 10.0.1.3
(Link Data) Router Interface address: 0.0.0.52
Number of TOS metrics: 0
TOS 0 Metrics: 1100
Link connected to: another Router (point-to-point)
(Link ID) Neighboring Router ID: 10.0.1.4
(Link Data) Router Interface address: 0.0.0.53
Number of TOS metrics: 0
TOS 0 Metrics: 1100
''']
}
drawing = yed_diagram()
drawer = cli_ospf_data(drawing)
drawer.work(data)
drawer.drawing.dump_file()
API Reference
- class N2G.plugins.data.cli_ospf_data.cli_ospf_data(drawing, ttp_vars: Optional[dict] = None, ip_lookup_data: Optional[dict] = None, add_connected: bool = False, ptp_filter: Optional[list] = None, add_data: bool = True)
Main class to instantiate OSPFv2 LSDB CLI Data Plugin object.
- Parameters
drawing – (obj) N2G Diagram object
ttp_vars – (dict) Dictionary to use as vars attribute while instantiating TTP parser object
ip_lookup_data – (dict or str) IP Lookup dictionary or OS path to CSV file
add_connected – (bool) if True, will add connected subnets as nodes, default is False
ptp_filter – (list) list of glob patterns to filter point-to-point links based on link IP
add_data – (bool) if True (default) adds data information to nodes and links
ip_lookup_data
dictionary must be keyed by OSPF RID IP address, with values being dictionary which must containhostname
key with optional additional keys to use for N2G diagram module node, e.g.label
,top_label
,bottom_label
,interface``etc. If ``ip_lookup_data
is an OS path to CSV file, that file’s first column header must beip
, file must containhostname
column, other columns values set to N2G diagram module node attributes, e.g.label
,top_label
,bottom_label
,interface
etc.If lookup data contains
interface
key, it will be added to link label.Sample ip_lookup_data dictionary:
{ "1.1.1.1": { "hostname": "router-1", "bottom_label": "1 St address, City X", "interface": "Gi1" } }
Sample ip_lookup_data CSV file:
ip,hostname,bottom_label,interface 1.1.1.1,router-1,"1 St address, City X",Gi1
ptp_filter
default list of patterns are:0*
- Cisco MPLS TE forwarding adjacencies links112*
- huawei DCN OSPF links
- work(data)
Method to parse OSPF LSDB data and add nodes and links to N2G drawing.
- Parameters
data – (dict or str) dictionary keyed by platform name or OS path string to directories with text files
If data is dictionary, keys must correspond to “Platform” column in Supported platforms 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
device’s 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/