Parsing: A Network Automation skill you must develop
When you begin your journey into an automated network, you may not need to act on operative data such as show commands, but as you rapidly go on your journey, you will need to be able to transform data into something that can be used by other systems.
Unfortunately, not all of us have been able to replace our “legacy” network equipment with all the new network products with APIs, telemetry transmission, etc. which will help us to interact with our network through coding.
Currently, it is common for telco companies to have a hybrid device environment in which state-of-the-art network elements (offering new technologies services) coexist with legacy devices. These legacy devices are necessary to be kept due to the fact that they cannot be migrated to new technologies because of support contracts or geographical coverage, among others.
Let’s discuss why data parsing is beneficial and why we need it
Why do I need structured data about my CLI (command line interface) ?
We could state that parsing is the act of translating a language (not structured data that humans can read) into another language (structure data that a computer can handle).
Let’s take the following command output as an example:
unstructured_data = “”” 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 S2 Fa0/13 120 B Gi0/13 Cisco-switch-1 Gi1/0/7 120 Gi0/1 Juniper-switch1 Gi2/0/1 120 B,R 666 Juniper-switch1 Gi1/0/1 120 B,R 531Total entries displayed: 4 “”” |
---|
Thanks to information parsing methodologies we could be able to generate a data structure containing only the information we will need at a specific moment, such as a list of neighbors with access to their name and intf. This structure will allows us to manipulate it in a coding language like Python:
neighbors = [ {“name”: “S2”, “intf”: “Fa0/13”}, {“name”: “Cisco-switch-1”, “intf”: “Gi1/0/7”}, {“name”: “Juniper-switch1”, “intf”: “Gi2/0/1”}, {“name”: “Juniper-switch1”, “intf”: “Gi1/0/1”}, ] for neighbor in neighbors: print(f“Neighbor {neighbor[‘name’]} is seen on {neighbor[‘intf’]}”) Neighbor S2 is seen on Fa0/13 Neighbor Cisco-switch-1 is seen on Gi1/0/7 Neighbor Juniper-switch1 is seen on Gi2/0/1 Neighbor Juniper-switch1 is seen on Gi1/0/1 |
---|
Once we have transformed this information into structured data, we can analyze this data and make meaningful comparisons.
We can therefore assess if visible neighbors match the expected interfaces in the current environment with some kind of external truth. This verification may be fundamental to make sure there is an adequate configuration in the correct interfaces for every device.
In addition, we could validate that there are no unexpected additional neighbors. Parsing strategies give us the possibility to model data in structures to solve particular situations in every domain we are in.
Some use cases about why it is useful to transform not structured data into structured data:
- Capacity for storing structured data in a Time Series Database (TSDB) for telemetry and analysis which can help for identifying the cause of a problem the network is having.
- Taking specific actions according to the operative data gathered from the devices, such as bringing down an interface or bringing up a BGP peer.
- Making sure that each device is operatively compliant, for example, checking that each device recognizes the correct neighbors in each of its interfaces.
Summary
There are different tools that allow us to translate not structured data, which is easy to understand by humans and convenient to be displayed on a screen.
Nevertheless, the need to automate operations makes this kind of data inconvenient in the way they are displayed. This is why parsing becomes so useful. It allows us to generate structures of data which can model any kind of information and effectively interact with them.