{
"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": [
"#### Topology"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This caterogy of questions is intended to retrieve the network topology\n",
"used by Batfish. This topology is a combination of information in the\n",
"snapshot and inference logic (e.g., which interfaces are layer3 neighbors).\n",
"Currently, Layer 3 topology can be retrieved.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* [User Provided Layer 1 Topology](#User-Provided-Layer-1-Topology)\n",
"* [Layer 3 Topology](#Layer-3-Topology)"
]
},
{
"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": [
"'aristaevpn'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_snapshot('aristaevpn')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### User Provided Layer 1 Topology"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Returns normalized Layer 1 edges that were input to Batfish."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lists Layer 1 edges after potentially normalizing node and interface names. All node names are lower-cased, and for nodes that appear in the snapshot, interface names are canonicalized based on the vendor. All input edges are in the output, including nodes and interfaces that do not appear in the snapshot."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###### **Inputs**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Name | Description | Type | Optional | Default Value\n",
"--- | --- | --- | --- | --- \n",
"nodes | Include edges whose first node matches this name or regex. | [NodeSpec](../specifiers.md#node-specifier) | True | .*\n",
"remoteNodes | Include edges whose second node matches this name or regex. | [NodeSpec](../specifiers.md#node-specifier) | True | .*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###### **Invocation**"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"result = bf.q.userProvidedLayer1Edges().answer().frame()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###### **Return Value**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Name | Description | Type\n",
"--- | --- | ---\n",
"Interface | Interface from which the edge originates | [Interface](../datamodel.rst#pybatfish.datamodel.primitives.Interface)\n",
"Remote_Interface | Interface at which the edge terminates | [Interface](../datamodel.rst#pybatfish.datamodel.primitives.Interface)"
]
},
{
"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",
" Interface | \n",
" Remote_Interface | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" dc1-leaf2a[Ethernet1] | \n",
" dc1-spine1[Ethernet2] | \n",
"
\n",
" \n",
" | 1 | \n",
" dc1-leaf2b[Ethernet1] | \n",
" dc1-spine1[Ethernet3] | \n",
"
\n",
" \n",
" | 2 | \n",
" dc1-leaf2b[Ethernet2] | \n",
" dc1-spine2[Ethernet3] | \n",
"
\n",
" \n",
" | 3 | \n",
" dc1-svc3b[Ethernet6] | \n",
" dc1-l2leaf5b[Ethernet2] | \n",
"
\n",
" \n",
" | 4 | \n",
" dc1-leaf2a[Ethernet4] | \n",
" dc1-leaf2b[Ethernet4] | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Interface Remote_Interface\n",
"0 dc1-leaf2a[Ethernet1] dc1-spine1[Ethernet2]\n",
"1 dc1-leaf2b[Ethernet1] dc1-spine1[Ethernet3]\n",
"2 dc1-leaf2b[Ethernet2] dc1-spine2[Ethernet3]\n",
"3 dc1-svc3b[Ethernet6] dc1-l2leaf5b[Ethernet2]\n",
"4 dc1-leaf2a[Ethernet4] dc1-leaf2b[Ethernet4]"
]
},
"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": [
"Interface dc1-leaf2a[Ethernet1]\n",
"Remote_Interface dc1-spine1[Ethernet2]\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": [
"##### Layer 3 Topology"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Returns Layer 3 links."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lists all Layer 3 edges in the network."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###### **Inputs**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Name | Description | Type | Optional | Default Value\n",
"--- | --- | --- | --- | --- \n",
"nodes | Include edges whose first node matches this name or regex. | [NodeSpec](../specifiers.md#node-specifier) | True | .*\n",
"remoteNodes | Include edges whose second node matches this name or regex. | [NodeSpec](../specifiers.md#node-specifier) | True | .*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###### **Invocation**"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"result = bf.q.layer3Edges().answer().frame()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###### **Return Value**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Name | Description | Type\n",
"--- | --- | ---\n",
"Interface | Interface from which the edge originates | [Interface](../datamodel.rst#pybatfish.datamodel.primitives.Interface)\n",
"IPs | IPs | Set of str\n",
"Remote_Interface | Interface at which the edge terminates | [Interface](../datamodel.rst#pybatfish.datamodel.primitives.Interface)\n",
"Remote_IPs | Remote IPs | Set 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",
" Interface | \n",
" IPs | \n",
" Remote_Interface | \n",
" Remote_IPs | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" as1border1[GigabitEthernet0/0] | \n",
" ['1.0.1.1'] | \n",
" as1core1[GigabitEthernet1/0] | \n",
" ['1.0.1.2'] | \n",
"
\n",
" \n",
" | 1 | \n",
" as1border1[GigabitEthernet1/0] | \n",
" ['10.12.11.1'] | \n",
" as2border1[GigabitEthernet0/0] | \n",
" ['10.12.11.2'] | \n",
"
\n",
" \n",
" | 2 | \n",
" as1border2[GigabitEthernet0/0] | \n",
" ['10.13.22.1'] | \n",
" as3border2[GigabitEthernet0/0] | \n",
" ['10.13.22.3'] | \n",
"
\n",
" \n",
" | 3 | \n",
" as1border2[GigabitEthernet1/0] | \n",
" ['1.0.2.1'] | \n",
" as1core1[GigabitEthernet0/0] | \n",
" ['1.0.2.2'] | \n",
"
\n",
" \n",
" | 4 | \n",
" as1core1[GigabitEthernet0/0] | \n",
" ['1.0.2.2'] | \n",
" as1border2[GigabitEthernet1/0] | \n",
" ['1.0.2.1'] | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Interface IPs Remote_Interface Remote_IPs\n",
"0 as1border1[GigabitEthernet0/0] ['1.0.1.1'] as1core1[GigabitEthernet1/0] ['1.0.1.2']\n",
"1 as1border1[GigabitEthernet1/0] ['10.12.11.1'] as2border1[GigabitEthernet0/0] ['10.12.11.2']\n",
"2 as1border2[GigabitEthernet0/0] ['10.13.22.1'] as3border2[GigabitEthernet0/0] ['10.13.22.3']\n",
"3 as1border2[GigabitEthernet1/0] ['1.0.2.1'] as1core1[GigabitEthernet0/0] ['1.0.2.2']\n",
"4 as1core1[GigabitEthernet0/0] ['1.0.2.2'] as1border2[GigabitEthernet1/0] ['1.0.2.1']"
]
},
"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": [
"Interface as1border1[GigabitEthernet0/0]\n",
"IPs ['1.0.1.1']\n",
"Remote_Interface as1core1[GigabitEthernet1/0]\n",
"Remote_IPs ['1.0.1.2']\n",
"Name: 0, dtype: object"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.iloc[0]"
]
}
],
"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
}