Preface What this book covers What you need for this book Who this book is for Conventions Reader feedback Customer support Downloading the example code Downloading the color images of this book Errata Piracy Questions Review of TCP/IP Protocol Suite and Python Language The internet overview Servers, hosts, and network components The rise of datacenter Enterprise datacenters Cloud datacenters Edge datacenters The OSI model Client server models Network protocol suites The Transmission Control Protocol (TCP) Functions and Characteristics of TCP TCP messages and data transfer User Datagram Protocol (UDP) The Internet Protocol (IP) The IP NAT and security IP routing concepts Python language overview Python versions Operating system Running a Python program Python built-In types The None type Numerics Sequences Mapping Sets Python operators Python control flow tools Python functions Python classes Python modules and packages Summary Low-Level Network Device Interactions The challenges of CLI Constructing a virtual lab Cisco Virtual Internet Routing Lab (VIRL) VIRL tips Cisco DevNet and dCloud GNS3 Python Pexpect Library Installation The Pexpect overview Our first Expect program More Pexpect features Pexpect and SSH Putting things together for Pexpect The Python Paramiko library Installating Paramiko The Paramiko overview Our first Paramiko program More Paramiko features Paramiko for Servers Putting things together for Paramiko Looking ahead Downsides of Pexpect and Paramiko compared to other tools Idempotent network device interaction Bad automation speeds bad things up Summary API and Intent-Driven Networking Infrastructure as the Python code Screen scraping versus API structured output Data modeling for infrastructure as code The Cisco API and ACI Cisco NX-API Lab Software Installation and Device Preparation NX-API examples Cisco and YANG model The Cisco ACI The Python API for Juniper networks Juniper and NETCONF Device Preparation Juniper NETCONF examples Juniper PyEZ for developers Installation and preparation PyEZ examples The Arista Python API The Arista eAPI management The eAPI preparation eAPI examples The Arista Pyeapi library The Pyeapi installation Pyeapi examples Vendor neutral libraries Summary The Python Automation Framework - Ansible Basics A quick Ansible example The control node installation Your first Ansible playbook The Public key authorization The inventory file Our first playbook The advantages of Ansible Agentless Idempotent Simple and extensible The vendor Support The Ansible architecture YAML Inventories Variables Templates with Jinja2 Ansible networking modules Local connections and facts Provider arguments The Ansible Cisco example The Ansible Juniper example The Ansible Arista example Summary The Python Automation Framework - Ansible Advance Topics Ansible conditionals The when clause Network module conditional Ansible loops Standard loops Looping over dictionaries Templates The Jinja2 template Jinja2 loops The Jinja2 conditional Group and host variables Group variables Host variables The Ansible vault The Ansible include and roles The Ansible include statement Ansible roles Writing your own custom module The first custom module The second custom module Summary Network Security with Python The lab setup Python Scapy Installing Scapy Interactive examples Sniffing The TCP port scan The ping collection Common attacks Scapy resources Access lists Implementing access lists with Ansible MAC access lists The syslog search Searching with regular expressions Other tools Private VLANs UFW with Python Summary Network Monitoring with Python - Part 1 Lab setup SNMP Setup PySNMP Python visualization Matplotlib Installation Matplotlib - the first example Matplotlib for SNMP results Additional Matplotlib resources Pygal Installation Pygal - the first example Pygal for SNMP results Additional Pygal resources Python for Cacti Installation Python script as an input source Summary Network Monitoring with Python - Part 2 Graphviz Lab setup Installation Graphviz examples Python with Graphviz examples LLDP neighbor graphing Information retrieval Python parser script Final playbook Flow-based monitoring NetFlow parsing with Python Python socket and struct ntop traffic monitoring Python extension for ntop sFlow SFlowtool and sFlow-RT with Python Elasticsearch (ELK stack) Setting up a hosted ELK service The logstash format Python helper script for Logstash formatting Summary Building Network Web Services with Python Comparing Python web frameworks Flask and lab setup Introduction to Flask The HTTPie client URL routing URL variables URL generation The jsonify return Network s API Flask-SQLAlchemy Network content API Devices API The device ID API Network dynamic operations Asynchronous operations Security Additional resources Summary OpenFlow Basics Lab setup Introducing OpenFlow Basic operations OpenFlow 1.0 vs 1.3 Mininet The Ryu controller with Python Open vSwitch commands The Ryu firewall application Layer 2 OpenFlow switch Planning your application Application components The POX controller Summary Advanced OpenFlow Topics Setup OpenFlow operations with Ryu Packet inspection Static router Mininet topology Ryu controller code Ryu flow installation Ryu packet generation Final result Router with API Ryu controller with API API usage examples BGP router with OpenFlow Lab router setup Python with the BGP speaker library Ryu BGP application Firewall with OpenFlow Summary OpenStack, OpenDaylight, and NFV OpenStack OpenStack overview Networking in OpenStack Trying out OpenStack OpenDaylight OpenDaylight programming overview OpenDaylight example Summary Hybrid SDN Preparing the network Familiarize yourself with the existing framework and tools Network standardization Create minimum viable products Relentlessly experiment Greenfield deployment Controller redundancy Multiple controller example BGP migration example Migration segmentation VIRL and Mininet setup Cisco device configuration Ryu BGP speaker Mininet and REST Router Result and verification More BGP example Examine the JSONRPC over WebSocket Monitoring integration Secure TLS connection Physical switch selection Lab OpenFlow switches Incumbent vendor switches Whitebox Switches Summary