{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "nbsphinx": "hidden" }, "outputs": [], "source": [ "import pandas as pd\n", "from pybatfish.client.session import Session\n", "from pybatfish.datamodel import *\n", "\n", "pd.set_option(\"display.width\", 300) \n", "pd.set_option(\"display.max_columns\", 30) \n", "pd.set_option(\"display.max_rows\", 1000) \n", "pd.set_option(\"display.max_colwidth\", None)\n", "\n", "# Configure all pybatfish loggers to use WARN level\n", "import logging\n", "logging.getLogger('pybatfish').setLevel(logging.WARN)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "nbsphinx": "hidden" }, "outputs": [], "source": [ "bf = Session(host=\"localhost\")\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Snapshot Input" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This category of questions allows you to learn how well Batfish\n", "understands your network snapshot.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* [Snapshot Initialization Issues](#Snapshot-Initialization-Issues)\n", "* [Snapshot Input File Parse Status](#Snapshot-Input-File-Parse-Status)\n", "* [Snapshot Input File Parse Warnings](#Snapshot-Input-File-Parse-Warnings)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "nbsphinx": "hidden" }, "outputs": [ { "data": { "text/plain": [ "'generate_questions'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bf.set_network('generate_questions')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "nbsphinx": "hidden" }, "outputs": [ { "data": { "text/plain": [ "'generate_questions'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bf.set_snapshot('generate_questions')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Snapshot Initialization Issues" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Returns issues encountered when processing the snapshot." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Reports issues encountered by Batfish, including failure to recognize certain lines in the configuration, lack of support for certain features, and errors when converting to vendor-independent models." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### **Inputs**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### **Invocation**" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "result = bf.q.initIssues().answer().frame()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### **Return Value**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Name | Description | Type\n", "--- | --- | ---\n", "Nodes | The nodes that were converted (if applicable) | List of str\n", "Source_Lines | The files and lines that caused the issues (if applicable) | List of [FileLines](../datamodel.rst#pybatfish.datamodel.primitives.FileLines)\n", "Type | The type of issues identified | str\n", "Details | Details about the issues identified | str\n", "Line_Text | The text of the input files that caused the issues (if applicable) | str\n", "Parser_Context | Batfish parser state when issues were encountered (if applicable) | str" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print the first 5 rows of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NodesSource_LinesTypeDetailsLine_TextParser_Context
0['as1border1']NoneConvert warning (redflag)No virtual address set for VRRP on interface: 'GigabitEthernet0/0'NoneNone
\n", "
" ], "text/plain": [ " Nodes Source_Lines Type Details Line_Text Parser_Context\n", "0 ['as1border1'] None Convert warning (redflag) No virtual address set for VRRP on interface: 'GigabitEthernet0/0' None None" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.head(5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print the first row of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Nodes ['as1border1']\n", "Source_Lines None\n", "Type Convert warning (redflag)\n", "Details No virtual address set for VRRP on interface: 'GigabitEthernet0/0'\n", "Line_Text None\n", "Parser_Context None\n", "Name: 0, dtype: object" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.iloc[0]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "nbsphinx": "hidden" }, "outputs": [ { "data": { "text/plain": [ "'generate_questions'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bf.set_network('generate_questions')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "nbsphinx": "hidden" }, "outputs": [ { "data": { "text/plain": [ "'generate_questions'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bf.set_snapshot('generate_questions')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Snapshot Input File Parse Status" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Displays file parse status." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For each file in a snapshot, returns the host(s) that were produced by the file and the parse status: pass, fail, partially parsed." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### **Inputs**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### **Invocation**" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "result = bf.q.fileParseStatus().answer().frame()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### **Return Value**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Name | Description | Type\n", "--- | --- | ---\n", "File_Name | The file that was parsed | str\n", "Status | The status of the parsing operation | str\n", "File_Format | The detected format of the file | str\n", "Nodes | Names of nodes produced from this file | List of str" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print the first 5 rows of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
File_NameStatusFile_FormatNodes
0configs/as1border1.cfgPASSEDCISCO_IOS['as1border1']
1configs/as1border2.cfgPASSEDCISCO_IOS['as1border2']
2configs/as1core1.cfgPASSEDCISCO_IOS['as1core1']
3configs/as2border1.cfgPASSEDCISCO_IOS['as2border1']
4configs/as2border2.cfgPASSEDCISCO_IOS['as2border2']
\n", "
" ], "text/plain": [ " File_Name Status File_Format Nodes\n", "0 configs/as1border1.cfg PASSED CISCO_IOS ['as1border1']\n", "1 configs/as1border2.cfg PASSED CISCO_IOS ['as1border2']\n", "2 configs/as1core1.cfg PASSED CISCO_IOS ['as1core1']\n", "3 configs/as2border1.cfg PASSED CISCO_IOS ['as2border1']\n", "4 configs/as2border2.cfg PASSED CISCO_IOS ['as2border2']" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.head(5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print the first row of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "File_Name configs/as1border1.cfg\n", "Status PASSED\n", "File_Format CISCO_IOS\n", "Nodes ['as1border1']\n", "Name: 0, dtype: object" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.iloc[0]" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "nbsphinx": "hidden" }, "outputs": [ { "data": { "text/plain": [ "'generate_questions'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bf.set_network('generate_questions')" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "nbsphinx": "hidden" }, "outputs": [ { "data": { "text/plain": [ "'generate_questions'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bf.set_snapshot('generate_questions')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Snapshot Input File Parse Warnings" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Returns warnings that occurred when parsing the snapshot." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Return warnings such as failure to recognize certain lines and lack of support for certain features." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### **Inputs**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Name | Description | Type | Optional | Default Value\n", "--- | --- | --- | --- | --- \n", "aggregateDuplicates | Whether to aggregate duplicate results. | bool | True | " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### **Invocation**" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "result = bf.q.parseWarning().answer().frame()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###### **Return Value**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Name | Description | Type\n", "--- | --- | ---\n", "Filename | The file that was parsed | str\n", "Line | The line number in the input file that caused the warning | int\n", "Text | The text of the input that caused the warning | str\n", "Parser_Context | The context of the Batfish parser when the warning occurred | str\n", "Comment | An optional comment explaining more information about the warning | str" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print the first 5 rows of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FilenameLineTextParser_ContextComment
\n", "
" ], "text/plain": [ "Empty DataFrame\n", "Columns: [Filename, Line, Text, Parser_Context, Comment]\n", "Index: []" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.head(5)" ] } ], "metadata": { "celltoolbar": "Edit Metadata", "hide_input": false, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 2 }