IOS XE Architecture and Programmability Jeff McLaughlin, Principal TME
Cisco Spark How Questions? Use Cisco Spark to communicate with the speaker after the session 1. Find this session in the Cisco Live Mobile App 2. Click Join the Discussion 3. Install Spark or go directly to the space 4. Enter messages/questions in the space cs.co/ciscolivebot# 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Agenda Introduction Why Programmability? IOS XE Evolution Database Architecture Data Models Application Hosting Conclusion
Computing in the 1990s... 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 5
2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 6
2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 7
Configuring a BGP neighbor then... router# config t router(config)# router bgp 100 router(config-bgp)# neighbor 1.1.1.1 remote-as 100 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 8
Configuring a BGP neighbor now... router# config t router(config)# router bgp 100 router(config-bgp)# neighbor 1.1.1.1 remote-as 100 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 9
Has anything really changed? 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 10
OS 6.0 released "Top Gun" released 1986 IOS XE 3.x BinOS 2007 Polaris IOS XE 16.x 2015 1984 Cisco founded Prince Harry born 1993 IOS 9.x Windows 3.1 2010 IOS XE 3.x NOVA 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 11
Why programmability?
Why automation and programmability? Administrator Needs to configure hostname switch1 int g0/0 ip address 10.1.1.11/24 vlan 100,200,300... hostname switch6 int g0/0 ip address 10.1.1.16/24 vlan 100,200,300 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 13
Notepad is the most common automation tool. It s just a very bad automation tool.... Programmability Reason #1 Do repetitive and tedious tasks more easily 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 14
52037606 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored if error counters too high: then shutdown interface* * pseudo-code Programmability Reason #2 Programmatic Control of network devices 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 15
party apps Cisco ISE NETCONF REST API Catalyst switches DNA Center Programmability Reason #3 Interaction between network devices and other systems 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 16
Transactionality int g0/0 ip address 10.1.1.0/24 no shutdown router bgp 65001 router-id 172.17.1.99 bgp log-neighbor-changes neighbor 192.168.1.2 remote-as 40000 neighbor 192.168.3.2 remote-as 50000 address-family ipv4 unicast neighbor 192.168.1.2 activate network 172.17.1.0 mask 255.255.255.0 exit-address-family Programmability Reason #4 Stop bad configuration being committed to devices 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 17
Operational Simplification How to find the red user's switch/port? 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 18
Operational Simplification # ping 172.16.100.101 # show arp i 172.16.100.101 # show mac address-table address 001a.a24d.5141 # show cdp neighbor g0/1 detail How to find the red user's switch/port? 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 19
Operational Simplification # show mac address-table address 001a.a24d.5141 # show cdp neighbor g0/10 detail How to find the red user's switch/port? 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 20
Operational Simplification How to find the red user's switch/port? # show mac address-table address 001a.a24d.5141 Vlan Mac Address Type Ports ---- ----------- -------- ----- 244 001a.a24d.5141 DYNAMIC Gi0/15 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 21
Operational Simplification Programmability Reason #5 Automate complex troubleshooting tasks 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 22
IOS XE Evolution
Classic IOS Challenges Monolithic Process not independent of one another Unified control/data plane No clean separation between path calc. and forwarding Common Memory Config/oper data centralized, not easily shared 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 24
Classic vs. IOS XE Architecture Classic IOS IOS XE 16.x Feature Components IOSd IOSd IOSd IOS Sub- Systems Hosted Apps LXC LXC VM Common Infra Module Drivers Kernel Common Infra Module Drivers Kernel IOS XE DB 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 25
IOS XE: Linux-based OS Standard operating system Easier development process Hosting of other applications 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 26
IOS XE: Capability for restartable Processes Independent processes instead of monolithic Config/State stored external to process Some development still in progress 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 27
IOS XE: Database Architecture Separation of config/oper data from processes Clearly structured data <<enumeration>> crimson_linestate Easy export of structured data enumeration literals LINE_UP LINE_DOWN LINE_ADMIN_DOWN 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 28
Structured Data
Structured vs Unstructured Data Un-structured Structured John Smith 42 14155551212 What is this? His age? The year he graduated college? Meaning of life, the universe & everything? Name: Age: Phone: Keys John Smith 42 +1-415-555-1212 Values 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 30
Hierarchical Structured Data (XML-like) First User Second User { { <user1> <name>john Smith</name> <age>42</age> <phone>+1-415-555-1212</phone> </user1> <user2> <name>sarah Kim</name> <age>27</age> <phone>+1-718-555-1212</phone> </user2> 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 31
Ancient unstructured data COULDYOUREADITIFWEWROTELIKETHIS WITHNOPUNCTUATIONITISHARDTOFIGUR EOUTWHEREONEWORDORSENTENCEBE GINSORENDSANDITISNOTEASYTOSEPAR ATEOUTALLTHEELEMENTSOFTHETEXTTH ANKGOODNESSSOMEONECAMEUPWITHA BETTERWAY 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 32
Note inconsistent key format! switch1# sh int e1/10 Ethernet1/10 is up Hardware: 1000/10000 Ethernet, address: 0005.73d0.9331 (bia 0005.73d0.9331) Description: To UCS-11 MTU 1500 bytes, BW 1000000 Kbit, DLY 10 usec, reliability 255/255, txload 1/255, rxload 1/255 Switchport monitor is off EtherType is 0x8100 Last link flapped 8week(s) 2day(s) Last clearing of "show interface" counters 1d02h 30 seconds input rate 944 bits/sec, 118 bytes/sec, 0 packets/sec 30 seconds output rate 3110376 bits/sec, 388797 bytes/sec, 5221 packets/sec CLI = Unstructured Data 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 33
Configuration vs. Operational data Configuration data tells the device what to do. It is data that you see in a show run. Operational data tells us how a device is operating, from show commands other than show run. # sh run int g0/0 interface GigabitEthernet0/0 description Management Interface vrf forwarding Mgmt-vrf ip address 172.26.244.49 255.255.255.0 # sh int g0/0 GigabitEthernet0/0 is up, line protocol up Hardware is RP management port Description: Management Interface We can write configuration data (think conf t ), and we can read configuration data (think show run ). Operational data is read-only. Some data can be read either as config data or operational data! 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 34
Database Architecture
What data does IOS XE need to store? BGP Configuration Data IP Address: 172.26.244.110 Remote ASN: 65010 Description: Lab Internal BGP peer MD5 password: cisco123 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 36
What data does IOS XE need to store? BGP Operational Data State: ACTIVE Peer uptime: 2d10h32m Messages Sent/Received: 14533/15830 Routes Sent/Received: 252/174 <internal operational data> 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 37
BGP Code IOS Memory /* BGP neighbor structure. */ typedef struct peer { char *desc; /* Description of the peer. */ unsigned short port; /* Destination port for peer */ char *host; /* Printable address of the peer.*/ time_t uptime; /* Last Up/Down time */ time_t readtime; /* Last read time */ time_t resettime; /* Last reset time */...etc... } Interfaces AAA STP EEM SSH BGP Unused IPSec STP QoS ACLs SLA OSPF WCCP Note: Memory for a process is probably not going to be contiguous! Simplified for slide. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 38
Database Architecture Goals Database BGP Code BGP State BGP Code Decouple state from the code that is managing it. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 39
Database Architecture Goals Database BGP Code Process Restartability while retaining process data 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 40
Database Architecture Goals Database BGP Code Process Restartability while retaining process data 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 41
Database Architecture Goals Database BGP Code Process Restartability while retaining process data 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 42
Database Architecture Goals Database BGP Code OSPF Code Standardized Read/Write from multiple processes 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 43
Database Architecture Goals DB TDL -> YANG NETCONF/RESTCONF Standardized data structure for easy export 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 44
YANG Data Models
Open Programmable APIs Simplified View NETCONF RESTCONF gnmi/grpc CLI NETCONF RESTCONF gnmi grpc Protocols Parser Data Model YANG Models Device Features Interface BGP QoS ACL Device Features 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 46
XML vs JSON <interfaces xmlns:= [ ]yang:ietf-interfaces > <interface> <name>eth0</name> <type>ethernetcsmacd</type> <location>0</location> <enabled>true</enabled> <if-index>2</if-index> </interface> </interfaces> NETCONF { } "ietf-interfaces:interfaces": { "interface": [ { "name": "eth0, "type": "ethernetcsmacd, "location": "0, "enabled": true, "if-index": 2 } ] } NETCONF/RESTCONF 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 47
Error! Sends <interface>gigabit 1/0</interface> <ifaddr>10.0.0.1/24</ifaddr> Expecting Expecting: <interface> <name>gigabit 1/0</name> <address>10.0.0.1/24</address> </interface> 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 48
So why do we need YANG? <interface>ethernet 0/0</interface> <name>switch1 to UCS1</name> <ipaddr>1.1.1.1/24</ipaddr> <name>ethernet 0/0</name> <descr>switch1 to UCS1</descr> <ip>1.1.1.1/24</ip> Question: Which of these is correct? Answer: They all are! <ifname>ethernet 0/0</ifname> <ifalias>switch1 to UCS1</ifalias> <ifaddr>1.1.1.1/24</ifaddr> 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 49
YANG Data Models container ip { list vrf { leaf rd } } vrf red rd 1:1 <vrf>red</vrf> <rd>1:1</rd> YANG Model Data XML Data YANG models do not contain data or XML. YANG models are like templates used to generate consistent XML. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 50
YANG Data Models <vrf>red</vrf> <rd>1:1</rd> container ip { list vrf { leaf rd } } vrf red rd 1:1 XML YANG Model Data { vrf : red rd : 1:1 } JSON YANG models can be used as a template for generating structured data in many different formats. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 51
YANG Configuration Model Example* container ip { YANG list vrf { description "Configure an IP VPN Routing/Forwarding instance"; } } leaf name { type string; } leaf rd { description "Specify Route Distinguisher"; type rd-type; } <ip> <vrf> <name>vrf_red</name> <rd>65000:1</rd> </vrf> <vrf> <name>vrf_green</name> <rd>65000:2</rd> </vrf> </ip> ip vrf vrf_red rd 65001:1! ip vrf vrf_green rd 65001:2! XML CLI * Note: YANG model simplified for clarity 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 52
So why is this: <ip> <vrf> <name>vrf_red</name> <rd>65000:1</rd> </vrf> <vrf> <name>vrf_green</name> <rd>65000:2</rd> </vrf> </ip>...better than this? ip vrf vrf_red rd 65001:1! ip vrf vrf_green rd 65001:2! 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 53
CLI ip vrf vrf_red rd 65001:1! ip vrf vrf_green rd 65001:2! Good for human consumption Unstructured from a machine perspective 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 54
YANG-structured data <ip> <vrf> <name>vrf_red</name> <rd>65000:1</rd> </vrf> <vrf> <name>vrf_green</name> <rd>65000:2</rd> </vrf> </ip> Designed for machine consumption Directly convertible to/from Python dicts! 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 55
Where are YANG models? 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 56
Where are YANG models? Models installed on device automatically with IOS-XE. On some devices/versions, can be updated independently 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 57
Where are YANG models? Models installed on device automatically with IOS-XE. On some devices/versions, can be updated independently https://github.com/yangmodels/yang/tree/master/vendor/cisco Also can be downloaded from GitHub. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 58
Who defines the YANG models? Vendors Standards Bodies Only work on specific vendor devices Greater feature coverage Can be OS-unique (IOS-XE, XR, etc.) Multi-vendor support More limited feature coverage Allow vendor-specific extensions Sometimes called "native" 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 59
Important Point! Cisco s data models and IETF/OpenConfig data models are just two ways of doing the same thing. <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"> <interface> <name>gigabitethernet 1/0/24</name> <description>configured by NETCONF!</description> </interface> </interfaces> IETF-defined model Both of these do exactly the same thing! <native xmlns="http://cisco.com/ns/yang/cisco-ios-xe-native"> <interface> <GigabitEthernet> <name>1/0/24</name> <description>configured by NETCONF!</description> </GigabitEthernet> </interface> </native> Cisco-defined native model 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 60
Important Point! Cisco s data models and IETF/OpenConfig data models are just two ways of doing the same thing. <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"> <interface> <name>gigabitethernet 1/0/24</name> <description>configured by NETCONF!</description> </interface> </interfaces> switch# show run interface g1/0/24 interface Both of these GigabitEthernet do exactly the 1/0/24 same thing! description Configured by NETCONF! <native xmlns="http://cisco.com/ns/yang/cisco-ios-xe-native"> <interface> <GigabitEthernet> <name>1/0/24</name> <description>configured by NETCONF!</description> </GigabitEthernet> </interface> </native> IETF-defined model Cisco-defined native model 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 61
Finding and using YANG models
YangExplorer: A Cisco tool for exploring models Available at: https://github.com/ciscodevnet/yang -explorer Or just Google: "cisco yangexplorer" 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 63
YangExplorer: A Cisco tool for exploring models 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 64
YangExplorer: A Cisco tool for exploring models Models on device 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 65
YangExplorer: A Cisco tool for exploring models Models on device Models subscribed on YangExplorer 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 66
2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 67
Finding a model, method 1 Either scroll through the model list or search for a specific model. Click RPC. The XML is displayed. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 68
Finding a model, method 1 Either scroll through the model list or search for a specific model. Click RPC. The XML is displayed. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 69
Finding a model, method 1 Either scroll through the model list or search for a specific model. Click RPC. The XML is displayed. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 70
Model-Driven Telemetry
Real World Telemetry 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 72
Where Data Is Created Where Data Is Useful SNMP syslog Interface up/down Instantaneous config Instantaneous topology Flow fingerprints Routes CLI NMS Applications Controller Network Element 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 73
SNMP Polling SNMP Get SNMP Response...wait 5 mins... SNMP Get SNMP Response...wait 5 mins... SNMP Get SNMP Response 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 74
NETCONF-based Telemetry (Periodic) NETCONF Session YANG Push...wait 5 secs......wait 5 secs... 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 75
Periodic subscription t t t t t t t Counters / Measures 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 76
NETCONF-based Telemetry (On-Change) NETCONF Session Model Subscription (Event) On Change Push 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 77
On-change subscription t t t t t t t State / Configuration / Identifiers 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 78
Telemetry Demo
Application Hosting
IOx IOx Orchestration LXC LXC VM Multiple apps App 1 App 2 App 3 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 81
REST REST External Management Tools IOx Client Fog Director On-Box Management Tools CLI Local Manager REST Cisco Application Framework (CAF)/IOx LXC Linux Process VM Linux Process Kernel Host OS (IOS XE Kernel) 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 82
More to come Enhancing Fabric functionality through Hosted Apps 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 83
On-Box Python
On-box Python Scripting CLI NETCONF Syslog Guestshell Container 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 85
Advantages On-Box Access CLI directly on device Trigger syslog messages Interact with Embedded Event Manager Access device bootflash Power-On Auto-Provisioning (ZTP) Use interactive Python shell 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 86
Enabling on-box Python jemclaug-hh15-c3850-2#conf t Enter configuration commands, one per line. End with CNTL/Z. jemclaug-hh15-c3850-(config)#iox jemclaug-hh15-c3850-(config)#^z jemclaug-hh15-c3850-2#guestshell? destroy Disable and uninstall the guest shell service package disable Disable the guest shell service package enable Enable the guest shell service run Execute/run program in the guest shell <cr> jemclaug-hh15-c3850-2#guestshell enable The process for the command is not responding or is otherwise unavailable jemclaug-hh15-c3850-2#guestshell enable Guestshell enabled successfully with tracefile support IOX is the container manager, similar to Docker. Wait for IOX to enable Success! Python read for use. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 87
On-box CLI APIs jemclaug-hh15-c3850-2#guestshell run python >>> from cli import cli >>> cli('sh iox') '\niox Infrastructure Summary:\n------------ ---------------\niox service (CAF) : Running \niox service (HA) : Running \niox service (IOxman) : Running \nlibvirtd : Running \n' cli Run cli command and return the raw output of the command 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 88
On-box CLI APIs >>> from cli import clip >>> clip('sh iox') IOx Infrastructure Summary: --------------------------- IOx service (CAF) : Running IOx service (HA) : Running IOx service (IOxman) : Running Libvirtd : Running clip Print the output of a CLI command. (Formatted) >>> 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 89
Catalyst 3850 EEM 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 90
Catalyst 3850 1 User changes device config EEM 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 91
Catalyst 3850 EEM 2 Change detected by EEM 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 92
Catalyst 3850 EEM 3 EEM Triggers on-box Python script 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 93
4 Python script diffs configs and sends diff to Spark Catalyst 3850 EEM 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 94
3 Spark posts diff to room Catalyst 3850 EEM 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 95
In Closing
Thanks to engineers who helped! Pratap Pereira Albert Mak Fan Sun Marc Faggion Everything good came from them, any faults or errors are my own. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 97
How do I learn Python? Automate the Boring Stuff with Python, Al Sweigart Great introduction to Python focused on automation. (Not specifically network automation.) Covers Python 3.0 only. Assumes zero knowledge. Read Excel docs, generate PDFs, etc. Highly recommended. Real Python. http://realpython.com Three-part course. Begins with basics assuming no knowledge. Covers Python 2.7 and 3.0. Parts II and III focus on web development with Python. Covers flask, Django, jinja2 templates. Many resources on the web site for free. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 98
Cisco DevNet Learning Labs Sandboxes API Documentation Python, YDK, REST And More! http://developer.cisco.com 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 99
Identify one problem you can solve with a script Start small Copy and modify scripts from DevNet (developer.cisco.com) 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 100
Cisco Spark How Questions? Use Cisco Spark to communicate with the speaker after the session 1. Find this session in the Cisco Live Mobile App 2. Click Join the Discussion 3. Install Spark or go directly to the space 4. Enter messages/questions in the space cs.co/ciscolivebot# 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Please complete your Online Session Evaluations after each session Complete 4 Session Evaluations & the Overall Conference Evaluation (available from Thursday) to receive your Cisco Live T-shirt All surveys can be completed via the Cisco Live Mobile App or the Communication Stations Complete Your Online Session Evaluation Don t forget: Cisco Live sessions will be available for viewing on-demand after the event at www.ciscolive.com/global/on-demand-library/. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Continue Your Education Demos in the Cisco campus Walk-in Self-Paced Labs Tech Circle Meet the Engineer 1:1 meetings Related sessions 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 103
Thank you