{
"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",
"id": "50b6c5b5",
"metadata": {},
"source": [
"#### Routing Protocol Sessions and Policies"
]
},
{
"cell_type": "markdown",
"id": "1d3a55cf",
"metadata": {},
"source": [
"This category of questions reveals information regarding which routing\n",
"protocol sessions are compatibly configured and which ones are\n",
"established. It also allows to you analyze BGP routing policies.\n"
]
},
{
"cell_type": "markdown",
"id": "a0247a87",
"metadata": {},
"source": [
"* [BGP Session Compatibility](#BGP-Session-Compatibility)\n",
"* [BGP Session Status](#BGP-Session-Status)\n",
"* [BGP Edges](#BGP-Edges)\n",
"* [OSPF Session Compatibility](#OSPF-Session-Compatibility)\n",
"* [OSPF Edges](#OSPF-Edges)\n",
"* [Test Route Policies](#Test-Route-Policies)\n",
"* [Search Route Policies](#Search-Route-Policies)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "2b4f9e1a",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_network('generate_questions')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "3db3a144",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_snapshot('generate_questions')"
]
},
{
"cell_type": "markdown",
"id": "9d986d1d",
"metadata": {},
"source": [
"##### BGP Session Compatibility"
]
},
{
"cell_type": "markdown",
"id": "91b813c3",
"metadata": {},
"source": [
"Returns the compatibility of configured BGP sessions."
]
},
{
"cell_type": "markdown",
"id": "333ec150",
"metadata": {},
"source": [
"Checks the settings of each configured BGP peering and reports any issue with those settings locally or incompatiblity with its remote counterparts. Each row represents one configured BGP peering on a node and contains information about the session it is meant to establish. For dynamic peers, there is one row per compatible remote peer. Statuses that indicate an independently misconfigured peerings include NO_LOCAL_AS, NO_REMOTE_AS, NO_LOCAL_IP (for eBGP single-hop peerings), LOCAL_IP_UNKNOWN_STATICALLY (for iBGP or eBGP multi-hop peerings), NO_REMOTE_IP (for point-to-point peerings), and NO_REMOTE_PREFIX (for dynamic peerings). INVALID_LOCAL_IP indicates that the peering's configured local IP does not belong to any active interface on the node; UNKNOWN_REMOTE indicates that the configured remote IP is not present in the network. A locally valid point-to-point peering is deemed HALF_OPEN if it has no compatible remote peers, UNIQUE_MATCH if it has exactly one compatible remote peer, or MULTIPLE_REMOTES if it has multiple compatible remote peers. A locally valid dynamic peering is deemed NO_MATCH_FOUND if it has no compatible remote peers, or DYNAMIC_MATCH if it has at least one compatible remote peer."
]
},
{
"cell_type": "markdown",
"id": "4997e44c",
"metadata": {},
"source": [
"###### **Inputs**"
]
},
{
"cell_type": "markdown",
"id": "527e9f44",
"metadata": {},
"source": [
"Name | Description | Type | Optional | Default Value\n",
"--- | --- | --- | --- | --- \n",
"nodes | Include sessions whose first node matches this specifier. | [NodeSpec](../specifiers.md#node-specifier) | True | \n",
"remoteNodes | Include sessions whose second node matches this specifier. | [NodeSpec](../specifiers.md#node-specifier) | True | \n",
"status | Only include sessions for which compatibility status matches this specifier. | [BgpSessionCompatStatusSpec](../specifiers.md#bgp-session-compat-status-specifier) | True | \n",
"type | Only include sessions that match this specifier. | [BgpSessionTypeSpec](../specifiers.md#bgp-session-type-specifier) | True | "
]
},
{
"cell_type": "markdown",
"id": "e541d890",
"metadata": {},
"source": [
"###### **Invocation**"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "1c8139c8",
"metadata": {},
"outputs": [],
"source": [
"result = bf.q.bgpSessionCompatibility().answer().frame()"
]
},
{
"cell_type": "markdown",
"id": "eb5a2704",
"metadata": {},
"source": [
"###### **Return Value**"
]
},
{
"cell_type": "markdown",
"id": "8095902b",
"metadata": {},
"source": [
"Name | Description | Type\n",
"--- | --- | ---\n",
"Node | The node where this session is configured | str\n",
"VRF | The VRF in which this session is configured | str\n",
"Local_AS | The local AS of the session | int\n",
"Local_Interface | Local interface of the session | [Interface](../datamodel.rst#pybatfish.datamodel.primitives.Interface)\n",
"Local_IP | The local IP of the session | str\n",
"Remote_AS | The remote AS or list of ASes of the session | str\n",
"Remote_Node | Remote node for this session | str\n",
"Remote_Interface | Remote interface for this session | [Interface](../datamodel.rst#pybatfish.datamodel.primitives.Interface)\n",
"Remote_IP | Remote IP or prefix for this session | str\n",
"Address_Families | Address Families participating in this session | Set of str\n",
"Session_Type | The type of this session | str\n",
"Configured_Status | Configured status | str"
]
},
{
"cell_type": "markdown",
"id": "76778e9b",
"metadata": {},
"source": [
"Print the first 5 rows of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a58a1795",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Node | \n",
" VRF | \n",
" Local_AS | \n",
" Local_Interface | \n",
" Local_IP | \n",
" Remote_AS | \n",
" Remote_Node | \n",
" Remote_Interface | \n",
" Remote_IP | \n",
" Address_Families | \n",
" Session_Type | \n",
" Configured_Status | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" as1border1 | \n",
" default | \n",
" 1 | \n",
" None | \n",
" None | \n",
" 666 | \n",
" None | \n",
" None | \n",
" 3.2.2.2 | \n",
" [] | \n",
" EBGP_SINGLEHOP | \n",
" NO_LOCAL_IP | \n",
"
\n",
" \n",
" | 1 | \n",
" as1border1 | \n",
" default | \n",
" 1 | \n",
" None | \n",
" 1.1.1.1 | \n",
" 1 | \n",
" as1core1 | \n",
" None | \n",
" 1.10.1.1 | \n",
" ['IPV4_UNICAST'] | \n",
" IBGP | \n",
" UNIQUE_MATCH | \n",
"
\n",
" \n",
" | 2 | \n",
" as1border1 | \n",
" default | \n",
" 1 | \n",
" None | \n",
" None | \n",
" 555 | \n",
" None | \n",
" None | \n",
" 5.6.7.8 | \n",
" [] | \n",
" EBGP_SINGLEHOP | \n",
" NO_LOCAL_IP | \n",
"
\n",
" \n",
" | 3 | \n",
" as1border1 | \n",
" default | \n",
" 1 | \n",
" None | \n",
" 10.12.11.1 | \n",
" 2 | \n",
" as2border1 | \n",
" None | \n",
" 10.12.11.2 | \n",
" ['IPV4_UNICAST'] | \n",
" EBGP_SINGLEHOP | \n",
" UNIQUE_MATCH | \n",
"
\n",
" \n",
" | 4 | \n",
" as1border2 | \n",
" default | \n",
" 1 | \n",
" None | \n",
" 10.14.22.1 | \n",
" 4 | \n",
" None | \n",
" None | \n",
" 10.14.22.4 | \n",
" [] | \n",
" EBGP_SINGLEHOP | \n",
" UNKNOWN_REMOTE | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Node VRF Local_AS Local_Interface Local_IP Remote_AS Remote_Node Remote_Interface Remote_IP Address_Families Session_Type Configured_Status\n",
"0 as1border1 default 1 None None 666 None None 3.2.2.2 [] EBGP_SINGLEHOP NO_LOCAL_IP\n",
"1 as1border1 default 1 None 1.1.1.1 1 as1core1 None 1.10.1.1 ['IPV4_UNICAST'] IBGP UNIQUE_MATCH\n",
"2 as1border1 default 1 None None 555 None None 5.6.7.8 [] EBGP_SINGLEHOP NO_LOCAL_IP\n",
"3 as1border1 default 1 None 10.12.11.1 2 as2border1 None 10.12.11.2 ['IPV4_UNICAST'] EBGP_SINGLEHOP UNIQUE_MATCH\n",
"4 as1border2 default 1 None 10.14.22.1 4 None None 10.14.22.4 [] EBGP_SINGLEHOP UNKNOWN_REMOTE"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.head(5)"
]
},
{
"cell_type": "markdown",
"id": "6f9180e4",
"metadata": {},
"source": [
"Print the first row of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "98dce7b9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Node as1border1\n",
"VRF default\n",
"Local_AS 1\n",
"Local_Interface None\n",
"Local_IP None\n",
"Remote_AS 666\n",
"Remote_Node None\n",
"Remote_Interface None\n",
"Remote_IP 3.2.2.2\n",
"Address_Families []\n",
"Session_Type EBGP_SINGLEHOP\n",
"Configured_Status NO_LOCAL_IP\n",
"Name: 0, dtype: object"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.iloc[0]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "dd636241",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_network('generate_questions')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "ad7a9246",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_snapshot('generate_questions')"
]
},
{
"cell_type": "markdown",
"id": "6534a9fc",
"metadata": {},
"source": [
"##### BGP Session Status"
]
},
{
"cell_type": "markdown",
"id": "218f5d46",
"metadata": {},
"source": [
"Returns the dynamic status of configured BGP sessions."
]
},
{
"cell_type": "markdown",
"id": "1ffd9232",
"metadata": {},
"source": [
"Checks whether configured BGP peerings can be established. Each row represents one configured BGP peering and contains information about the session it is configured to establish. For dynamic peerings, one row is shown per compatible remote peer. Possible statuses for each session are NOT_COMPATIBLE, ESTABLISHED, and NOT_ESTABLISHED. NOT_COMPATIBLE sessions are those where one or both peers are misconfigured; the BgpSessionCompatibility question provides further insight into the nature of the configuration error. NOT_ESTABLISHED sessions are those that are configured compatibly but will not come up because peers cannot reach each other (e.g., due to being blocked by an ACL). ESTABLISHED sessions are those that are compatible and are expected to come up."
]
},
{
"cell_type": "markdown",
"id": "443afeb6",
"metadata": {},
"source": [
"###### **Inputs**"
]
},
{
"cell_type": "markdown",
"id": "f4a19c65",
"metadata": {},
"source": [
"Name | Description | Type | Optional | Default Value\n",
"--- | --- | --- | --- | --- \n",
"nodes | Include sessions whose first node matches this specifier. | [NodeSpec](../specifiers.md#node-specifier) | True | \n",
"remoteNodes | Include sessions whose second node matches this specifier. | [NodeSpec](../specifiers.md#node-specifier) | True | \n",
"status | Only include sessions for which status matches this specifier. | [BgpSessionStatusSpec](../specifiers.md#bgp-session-status-specifier) | True | \n",
"type | Only include sessions that match this specifier. | [BgpSessionTypeSpec](../specifiers.md#bgp-session-type-specifier) | True | "
]
},
{
"cell_type": "markdown",
"id": "0b6a52fb",
"metadata": {},
"source": [
"###### **Invocation**"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "26a4aa83",
"metadata": {},
"outputs": [],
"source": [
"result = bf.q.bgpSessionStatus().answer().frame()"
]
},
{
"cell_type": "markdown",
"id": "b29c1880",
"metadata": {},
"source": [
"###### **Return Value**"
]
},
{
"cell_type": "markdown",
"id": "91618579",
"metadata": {},
"source": [
"Name | Description | Type\n",
"--- | --- | ---\n",
"Node | The node where this session is configured | str\n",
"VRF | The VRF in which this session is configured | str\n",
"Local_AS | The local AS of the session | int\n",
"Local_Interface | Local interface of the session | [Interface](../datamodel.rst#pybatfish.datamodel.primitives.Interface)\n",
"Local_IP | The local IP of the session | str\n",
"Remote_AS | The remote AS or list of ASes of the session | str\n",
"Remote_Node | Remote node for this session | str\n",
"Remote_Interface | Remote interface for this session | [Interface](../datamodel.rst#pybatfish.datamodel.primitives.Interface)\n",
"Remote_IP | Remote IP or prefix for this session | str\n",
"Address_Families | Address Families participating in this session | Set of str\n",
"Session_Type | The type of this session | str\n",
"Established_Status | Established status | str"
]
},
{
"cell_type": "markdown",
"id": "02a3a548",
"metadata": {},
"source": [
"Print the first 5 rows of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "b29afa8f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Node | \n",
" VRF | \n",
" Local_AS | \n",
" Local_Interface | \n",
" Local_IP | \n",
" Remote_AS | \n",
" Remote_Node | \n",
" Remote_Interface | \n",
" Remote_IP | \n",
" Address_Families | \n",
" Session_Type | \n",
" Established_Status | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" as1border1 | \n",
" default | \n",
" 1 | \n",
" None | \n",
" None | \n",
" 666 | \n",
" None | \n",
" None | \n",
" 3.2.2.2 | \n",
" [] | \n",
" EBGP_SINGLEHOP | \n",
" NOT_COMPATIBLE | \n",
"
\n",
" \n",
" | 1 | \n",
" as1border1 | \n",
" default | \n",
" 1 | \n",
" None | \n",
" 1.1.1.1 | \n",
" 1 | \n",
" as1core1 | \n",
" None | \n",
" 1.10.1.1 | \n",
" ['IPV4_UNICAST'] | \n",
" IBGP | \n",
" ESTABLISHED | \n",
"
\n",
" \n",
" | 2 | \n",
" as1border1 | \n",
" default | \n",
" 1 | \n",
" None | \n",
" None | \n",
" 555 | \n",
" None | \n",
" None | \n",
" 5.6.7.8 | \n",
" [] | \n",
" EBGP_SINGLEHOP | \n",
" NOT_COMPATIBLE | \n",
"
\n",
" \n",
" | 3 | \n",
" as1border1 | \n",
" default | \n",
" 1 | \n",
" None | \n",
" 10.12.11.1 | \n",
" 2 | \n",
" as2border1 | \n",
" None | \n",
" 10.12.11.2 | \n",
" ['IPV4_UNICAST'] | \n",
" EBGP_SINGLEHOP | \n",
" ESTABLISHED | \n",
"
\n",
" \n",
" | 4 | \n",
" as1border2 | \n",
" default | \n",
" 1 | \n",
" None | \n",
" 10.14.22.1 | \n",
" 4 | \n",
" None | \n",
" None | \n",
" 10.14.22.4 | \n",
" [] | \n",
" EBGP_SINGLEHOP | \n",
" NOT_COMPATIBLE | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Node VRF Local_AS Local_Interface Local_IP Remote_AS Remote_Node Remote_Interface Remote_IP Address_Families Session_Type Established_Status\n",
"0 as1border1 default 1 None None 666 None None 3.2.2.2 [] EBGP_SINGLEHOP NOT_COMPATIBLE\n",
"1 as1border1 default 1 None 1.1.1.1 1 as1core1 None 1.10.1.1 ['IPV4_UNICAST'] IBGP ESTABLISHED\n",
"2 as1border1 default 1 None None 555 None None 5.6.7.8 [] EBGP_SINGLEHOP NOT_COMPATIBLE\n",
"3 as1border1 default 1 None 10.12.11.1 2 as2border1 None 10.12.11.2 ['IPV4_UNICAST'] EBGP_SINGLEHOP ESTABLISHED\n",
"4 as1border2 default 1 None 10.14.22.1 4 None None 10.14.22.4 [] EBGP_SINGLEHOP NOT_COMPATIBLE"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.head(5)"
]
},
{
"cell_type": "markdown",
"id": "f05999fd",
"metadata": {},
"source": [
"Print the first row of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "178ac84c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Node as1border1\n",
"VRF default\n",
"Local_AS 1\n",
"Local_Interface None\n",
"Local_IP None\n",
"Remote_AS 666\n",
"Remote_Node None\n",
"Remote_Interface None\n",
"Remote_IP 3.2.2.2\n",
"Address_Families []\n",
"Session_Type EBGP_SINGLEHOP\n",
"Established_Status NOT_COMPATIBLE\n",
"Name: 0, dtype: object"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.iloc[0]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "288b046d",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_network('generate_questions')"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "101da480",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_snapshot('generate_questions')"
]
},
{
"cell_type": "markdown",
"id": "8ed5b611",
"metadata": {},
"source": [
"##### BGP Edges"
]
},
{
"cell_type": "markdown",
"id": "8f4093dc",
"metadata": {},
"source": [
"Returns BGP adjacencies."
]
},
{
"cell_type": "markdown",
"id": "62941a48",
"metadata": {},
"source": [
"Lists all BGP adjacencies in the network."
]
},
{
"cell_type": "markdown",
"id": "2aa9a992",
"metadata": {},
"source": [
"###### **Inputs**"
]
},
{
"cell_type": "markdown",
"id": "d5436727",
"metadata": {},
"source": [
"Name | Description | Type | Optional | Default Value\n",
"--- | --- | --- | --- | --- \n",
"nodes | Include adjacencies whose first node matches this name or regex. | [NodeSpec](../specifiers.md#node-specifier) | True | .*\n",
"remoteNodes | Include adjacencies whose second node matches this name or regex. | [NodeSpec](../specifiers.md#node-specifier) | True | .*"
]
},
{
"cell_type": "markdown",
"id": "f9e3b6c6",
"metadata": {},
"source": [
"###### **Invocation**"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "bd52895d",
"metadata": {},
"outputs": [],
"source": [
"result = bf.q.bgpEdges().answer().frame()"
]
},
{
"cell_type": "markdown",
"id": "0ceef017",
"metadata": {},
"source": [
"###### **Return Value**"
]
},
{
"cell_type": "markdown",
"id": "0641fb37",
"metadata": {},
"source": [
"Name | Description | Type\n",
"--- | --- | ---\n",
"Node | Node from which the edge originates | str\n",
"IP | IP at the side of originator | str\n",
"Interface | Interface at which the edge originates | str\n",
"AS_Number | AS Number at the side of originator | str\n",
"Remote_Node | Node at which the edge terminates | str\n",
"Remote_IP | IP at the side of the responder | str\n",
"Remote_Interface | Interface at which the edge terminates | str\n",
"Remote_AS_Number | AS Number at the side of responder | str"
]
},
{
"cell_type": "markdown",
"id": "2ed92976",
"metadata": {},
"source": [
"Print the first 5 rows of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "7330a8b0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Node | \n",
" IP | \n",
" Interface | \n",
" AS_Number | \n",
" Remote_Node | \n",
" Remote_IP | \n",
" Remote_Interface | \n",
" Remote_AS_Number | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" as1border2 | \n",
" 1.2.2.2 | \n",
" None | \n",
" 1 | \n",
" as1core1 | \n",
" 1.10.1.1 | \n",
" None | \n",
" 1 | \n",
"
\n",
" \n",
" | 1 | \n",
" as1core1 | \n",
" 1.10.1.1 | \n",
" None | \n",
" 1 | \n",
" as1border1 | \n",
" 1.1.1.1 | \n",
" None | \n",
" 1 | \n",
"
\n",
" \n",
" | 2 | \n",
" as2dist2 | \n",
" 2.1.3.2 | \n",
" None | \n",
" 2 | \n",
" as2core2 | \n",
" 2.1.2.2 | \n",
" None | \n",
" 2 | \n",
"
\n",
" \n",
" | 3 | \n",
" as3border2 | \n",
" 3.2.2.2 | \n",
" None | \n",
" 3 | \n",
" as3core1 | \n",
" 3.10.1.1 | \n",
" None | \n",
" 3 | \n",
"
\n",
" \n",
" | 4 | \n",
" as3border1 | \n",
" 10.23.21.3 | \n",
" None | \n",
" 3 | \n",
" as2border2 | \n",
" 10.23.21.2 | \n",
" None | \n",
" 2 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Node IP Interface AS_Number Remote_Node Remote_IP Remote_Interface Remote_AS_Number\n",
"0 as1border2 1.2.2.2 None 1 as1core1 1.10.1.1 None 1\n",
"1 as1core1 1.10.1.1 None 1 as1border1 1.1.1.1 None 1\n",
"2 as2dist2 2.1.3.2 None 2 as2core2 2.1.2.2 None 2\n",
"3 as3border2 3.2.2.2 None 3 as3core1 3.10.1.1 None 3\n",
"4 as3border1 10.23.21.3 None 3 as2border2 10.23.21.2 None 2"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.head(5)"
]
},
{
"cell_type": "markdown",
"id": "2ffaaaee",
"metadata": {},
"source": [
"Print the first row of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "5d364e8c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Node as1border2\n",
"IP 1.2.2.2\n",
"Interface None\n",
"AS_Number 1\n",
"Remote_Node as1core1\n",
"Remote_IP 1.10.1.1\n",
"Remote_Interface None\n",
"Remote_AS_Number 1\n",
"Name: 0, dtype: object"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.iloc[0]"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "9ab149e5",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_network('generate_questions')"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "043ca403",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_snapshot('generate_questions')"
]
},
{
"cell_type": "markdown",
"id": "edacf462",
"metadata": {},
"source": [
"##### OSPF Session Compatibility"
]
},
{
"cell_type": "markdown",
"id": "1357fd83",
"metadata": {},
"source": [
"Returns compatible OSPF sessions."
]
},
{
"cell_type": "markdown",
"id": "b9a8777d",
"metadata": {},
"source": [
"Returns compatible OSPF sessions in the network. A session is compatible if the interfaces involved are not shutdown and do run OSPF, are not OSPF passive and are associated with the same OSPF area."
]
},
{
"cell_type": "markdown",
"id": "974e9959",
"metadata": {},
"source": [
"###### **Inputs**"
]
},
{
"cell_type": "markdown",
"id": "9369bd7c",
"metadata": {},
"source": [
"Name | Description | Type | Optional | Default Value\n",
"--- | --- | --- | --- | --- \n",
"nodes | Include nodes matching this name or regex. | [NodeSpec](../specifiers.md#node-specifier) | True | \n",
"remoteNodes | Include remote nodes matching this name or regex. | [NodeSpec](../specifiers.md#node-specifier) | True | \n",
"statuses | Only include sessions matching this status specifier. | [OspfSessionStatusSpec](../specifiers.md#ospf-session-status-specifier) | True | "
]
},
{
"cell_type": "markdown",
"id": "7f60f4a2",
"metadata": {},
"source": [
"###### **Invocation**"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "81a78e9a",
"metadata": {},
"outputs": [],
"source": [
"result = bf.q.ospfSessionCompatibility().answer().frame()"
]
},
{
"cell_type": "markdown",
"id": "b54db217",
"metadata": {},
"source": [
"###### **Return Value**"
]
},
{
"cell_type": "markdown",
"id": "9817e98b",
"metadata": {},
"source": [
"Name | Description | Type\n",
"--- | --- | ---\n",
"Interface | Interface | [Interface](../datamodel.rst#pybatfish.datamodel.primitives.Interface)\n",
"VRF | VRF | str\n",
"IP | Ip | str\n",
"Area | Area | int\n",
"Remote_Interface | Remote Interface | [Interface](../datamodel.rst#pybatfish.datamodel.primitives.Interface)\n",
"Remote_VRF | Remote VRF | str\n",
"Remote_IP | Remote IP | str\n",
"Remote_Area | Remote Area | int\n",
"Session_Status | Status of the OSPF session | str"
]
},
{
"cell_type": "markdown",
"id": "63ffa108",
"metadata": {},
"source": [
"Print the first 5 rows of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "9a2b274b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Interface | \n",
" VRF | \n",
" IP | \n",
" Area | \n",
" Remote_Interface | \n",
" Remote_VRF | \n",
" Remote_IP | \n",
" Remote_Area | \n",
" Session_Status | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" as2core2[GigabitEthernet0/0] | \n",
" default | \n",
" 2.12.22.2 | \n",
" 1 | \n",
" as2border2[GigabitEthernet1/0] | \n",
" default | \n",
" 2.12.22.1 | \n",
" 1 | \n",
" ESTABLISHED | \n",
"
\n",
" \n",
" | 1 | \n",
" as2core2[GigabitEthernet1/0] | \n",
" default | \n",
" 2.12.12.2 | \n",
" 1 | \n",
" as2border1[GigabitEthernet2/0] | \n",
" default | \n",
" 2.12.12.1 | \n",
" 1 | \n",
" ESTABLISHED | \n",
"
\n",
" \n",
" | 2 | \n",
" as2border1[GigabitEthernet1/0] | \n",
" default | \n",
" 2.12.11.1 | \n",
" 1 | \n",
" as2core1[GigabitEthernet0/0] | \n",
" default | \n",
" 2.12.11.2 | \n",
" 1 | \n",
" ESTABLISHED | \n",
"
\n",
" \n",
" | 3 | \n",
" as2border1[GigabitEthernet2/0] | \n",
" default | \n",
" 2.12.12.1 | \n",
" 1 | \n",
" as2core2[GigabitEthernet1/0] | \n",
" default | \n",
" 2.12.12.2 | \n",
" 1 | \n",
" ESTABLISHED | \n",
"
\n",
" \n",
" | 4 | \n",
" as2core2[GigabitEthernet3/0] | \n",
" default | \n",
" 2.23.21.2 | \n",
" 1 | \n",
" as2dist1[GigabitEthernet1/0] | \n",
" default | \n",
" 2.23.21.3 | \n",
" 1 | \n",
" ESTABLISHED | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Interface VRF IP Area Remote_Interface Remote_VRF Remote_IP Remote_Area Session_Status\n",
"0 as2core2[GigabitEthernet0/0] default 2.12.22.2 1 as2border2[GigabitEthernet1/0] default 2.12.22.1 1 ESTABLISHED\n",
"1 as2core2[GigabitEthernet1/0] default 2.12.12.2 1 as2border1[GigabitEthernet2/0] default 2.12.12.1 1 ESTABLISHED\n",
"2 as2border1[GigabitEthernet1/0] default 2.12.11.1 1 as2core1[GigabitEthernet0/0] default 2.12.11.2 1 ESTABLISHED\n",
"3 as2border1[GigabitEthernet2/0] default 2.12.12.1 1 as2core2[GigabitEthernet1/0] default 2.12.12.2 1 ESTABLISHED\n",
"4 as2core2[GigabitEthernet3/0] default 2.23.21.2 1 as2dist1[GigabitEthernet1/0] default 2.23.21.3 1 ESTABLISHED"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.head(5)"
]
},
{
"cell_type": "markdown",
"id": "f6764b7b",
"metadata": {},
"source": [
"Print the first row of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "621b8dc7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Interface as2core2[GigabitEthernet0/0]\n",
"VRF default\n",
"IP 2.12.22.2\n",
"Area 1\n",
"Remote_Interface as2border2[GigabitEthernet1/0]\n",
"Remote_VRF default\n",
"Remote_IP 2.12.22.1\n",
"Remote_Area 1\n",
"Session_Status ESTABLISHED\n",
"Name: 0, dtype: object"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.iloc[0]"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "e8e40fec",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_network('generate_questions')"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "ada72f2c",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_snapshot('generate_questions')"
]
},
{
"cell_type": "markdown",
"id": "b5d72e49",
"metadata": {},
"source": [
"##### OSPF Edges"
]
},
{
"cell_type": "markdown",
"id": "f15fbe5c",
"metadata": {},
"source": [
"Returns OSPF adjacencies."
]
},
{
"cell_type": "markdown",
"id": "bf8af6a1",
"metadata": {},
"source": [
"Lists all OSPF adjacencies in the network."
]
},
{
"cell_type": "markdown",
"id": "f8a00ae1",
"metadata": {},
"source": [
"###### **Inputs**"
]
},
{
"cell_type": "markdown",
"id": "fa928512",
"metadata": {},
"source": [
"Name | Description | Type | Optional | Default Value\n",
"--- | --- | --- | --- | --- \n",
"nodes | Include adjacencies 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",
"id": "d50f90cc",
"metadata": {},
"source": [
"###### **Invocation**"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "14f1c70e",
"metadata": {},
"outputs": [],
"source": [
"result = bf.q.ospfEdges().answer().frame()"
]
},
{
"cell_type": "markdown",
"id": "5dbe209b",
"metadata": {},
"source": [
"###### **Return Value**"
]
},
{
"cell_type": "markdown",
"id": "acc0bb13",
"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",
"id": "358e2409",
"metadata": {},
"source": [
"Print the first 5 rows of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "566cf191",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Interface | \n",
" Remote_Interface | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" as1border1[GigabitEthernet0/0] | \n",
" as1core1[GigabitEthernet1/0] | \n",
"
\n",
" \n",
" | 1 | \n",
" as1core1[GigabitEthernet1/0] | \n",
" as1border1[GigabitEthernet0/0] | \n",
"
\n",
" \n",
" | 2 | \n",
" as1border2[GigabitEthernet1/0] | \n",
" as1core1[GigabitEthernet0/0] | \n",
"
\n",
" \n",
" | 3 | \n",
" as1core1[GigabitEthernet0/0] | \n",
" as1border2[GigabitEthernet1/0] | \n",
"
\n",
" \n",
" | 4 | \n",
" as2border1[GigabitEthernet1/0] | \n",
" as2core1[GigabitEthernet0/0] | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Interface Remote_Interface\n",
"0 as1border1[GigabitEthernet0/0] as1core1[GigabitEthernet1/0]\n",
"1 as1core1[GigabitEthernet1/0] as1border1[GigabitEthernet0/0]\n",
"2 as1border2[GigabitEthernet1/0] as1core1[GigabitEthernet0/0]\n",
"3 as1core1[GigabitEthernet0/0] as1border2[GigabitEthernet1/0]\n",
"4 as2border1[GigabitEthernet1/0] as2core1[GigabitEthernet0/0]"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.head(5)"
]
},
{
"cell_type": "markdown",
"id": "efdd2435",
"metadata": {},
"source": [
"Print the first row of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "1a23ee62",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Interface as1border1[GigabitEthernet0/0]\n",
"Remote_Interface as1core1[GigabitEthernet1/0]\n",
"Name: 0, dtype: object"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.iloc[0]"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "beecdab3",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_network('generate_questions')"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "6f6679c0",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_snapshot('generate_questions')"
]
},
{
"cell_type": "markdown",
"id": "eee9b06c",
"metadata": {},
"source": [
"##### Test Route Policies"
]
},
{
"cell_type": "markdown",
"id": "bc9c6c05",
"metadata": {},
"source": [
"Evaluates the processing of a route by a given policy."
]
},
{
"cell_type": "markdown",
"id": "8513de3b",
"metadata": {},
"source": [
"Find how the specified route is processed through the specified routing policies."
]
},
{
"cell_type": "markdown",
"id": "90131724",
"metadata": {},
"source": [
"###### **Inputs**"
]
},
{
"cell_type": "markdown",
"id": "8e29cfae",
"metadata": {},
"source": [
"Name | Description | Type | Optional | Default Value\n",
"--- | --- | --- | --- | --- \n",
"nodes | Only examine filters on nodes matching this specifier. | [NodeSpec](../specifiers.md#node-specifier) | True | \n",
"policies | Only consider policies that match this specifier. | [RoutingPolicySpec](../specifiers.md#routing-policy-specifier) | True | \n",
"inputRoutes | The BGP route announcements to test the policy on. | List of [BgpRoute](../datamodel.rst#pybatfish.datamodel.route.BgpRoute) | False | \n",
"direction | The direction of the route, with respect to the device (IN/OUT). | str | False | \n",
"bgpSessionProperties | The BGP session properties to use when testing routes. | [BgpSessionProperties](../datamodel.rst#pybatfish.datamodel.route.BgpSessionProperties) | True | "
]
},
{
"cell_type": "markdown",
"id": "12f67804",
"metadata": {},
"source": [
"###### **Invocation**"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "9dc252dc",
"metadata": {},
"outputs": [],
"source": [
"result = bf.q.testRoutePolicies(policies='/as1_to_/', direction='in', inputRoutes=list([BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[[64512, 64513], [64514]], communities=['64512:42', '64513:21'])])).answer().frame()"
]
},
{
"cell_type": "markdown",
"id": "501f94d2",
"metadata": {},
"source": [
"###### **Return Value**"
]
},
{
"cell_type": "markdown",
"id": "6cdfd157",
"metadata": {},
"source": [
"Name | Description | Type\n",
"--- | --- | ---\n",
"Node | The node that has the policy | str\n",
"Policy_Name | The name of this policy | str\n",
"Input_Route | The input route | [BgpRoute](../datamodel.rst#pybatfish.datamodel.route.BgpRoute)\n",
"Action | The action of the policy on the input route | str\n",
"Output_Route | The output route, if any | [BgpRoute](../datamodel.rst#pybatfish.datamodel.route.BgpRoute)\n",
"Difference | The difference between the input and output routes, if any | [BgpRouteDiffs](../datamodel.rst#pybatfish.datamodel.route.BgpRouteDiffs)\n",
"Trace | Route policy trace that shows which clauses/terms matched the input route. If the trace is empty, either nothing matched or tracing is not yet been implemented for this policy type. This is an experimental feature whose content and format is subject to change. | List of [TraceTree](../datamodel.rst#pybatfish.datamodel.acl.TraceTree)"
]
},
{
"cell_type": "markdown",
"id": "ea689206",
"metadata": {},
"source": [
"Print the first 5 rows of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "188a988a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Node | \n",
" Policy_Name | \n",
" Input_Route | \n",
" Action | \n",
" Output_Route | \n",
" Difference | \n",
" Trace | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" as1border1 | \n",
" as1_to_as2 | \n",
" BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['64512:42', '64513:21'], localPreference=0, metric=0, nextHopIp=None, sourceProtocol=None, tag=0, weight=0) | \n",
" DENY | \n",
" None | \n",
" None | \n",
" | \n",
"
\n",
" \n",
" | 1 | \n",
" as1border1 | \n",
" as1_to_as3 | \n",
" BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['64512:42', '64513:21'], localPreference=0, metric=0, nextHopIp=None, sourceProtocol=None, tag=0, weight=0) | \n",
" DENY | \n",
" None | \n",
" None | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" as1border2 | \n",
" as1_to_as2 | \n",
" BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['64512:42', '64513:21'], localPreference=0, metric=0, nextHopIp=None, sourceProtocol=None, tag=0, weight=0) | \n",
" DENY | \n",
" None | \n",
" None | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" as1border2 | \n",
" as1_to_as3 | \n",
" BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['64512:42', '64513:21'], localPreference=0, metric=0, nextHopIp=None, sourceProtocol=None, tag=0, weight=0) | \n",
" DENY | \n",
" None | \n",
" None | \n",
" | \n",
"
\n",
" \n",
" | 4 | \n",
" as1border2 | \n",
" as1_to_as4 | \n",
" BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['64512:42', '64513:21'], localPreference=0, metric=0, nextHopIp=None, sourceProtocol=None, tag=0, weight=0) | \n",
" PERMIT | \n",
" BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['1:4', '64512:42', '64513:21'], localPreference=0, metric=50, nextHopIp=None, sourceProtocol=None, tag=0, weight=0) | \n",
" BgpRouteDiffs(diffs=[BgpRouteDiff(fieldName='communities', oldValue='[64512:42, 64513:21]', newValue='[1:4, 64512:42, 64513:21]'), BgpRouteDiff(fieldName='metric', oldValue='0', newValue='50')]) | \n",
" - Matched route-map as1_to_as4 clause 2 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Node Policy_Name \\\n",
"0 as1border1 as1_to_as2 \n",
"1 as1border1 as1_to_as3 \n",
"2 as1border2 as1_to_as2 \n",
"3 as1border2 as1_to_as3 \n",
"4 as1border2 as1_to_as4 \n",
"\n",
" Input_Route \\\n",
"0 BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['64512:42', '64513:21'], localPreference=0, metric=0, nextHopIp=None, sourceProtocol=None, tag=0, weight=0) \n",
"1 BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['64512:42', '64513:21'], localPreference=0, metric=0, nextHopIp=None, sourceProtocol=None, tag=0, weight=0) \n",
"2 BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['64512:42', '64513:21'], localPreference=0, metric=0, nextHopIp=None, sourceProtocol=None, tag=0, weight=0) \n",
"3 BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['64512:42', '64513:21'], localPreference=0, metric=0, nextHopIp=None, sourceProtocol=None, tag=0, weight=0) \n",
"4 BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['64512:42', '64513:21'], localPreference=0, metric=0, nextHopIp=None, sourceProtocol=None, tag=0, weight=0) \n",
"\n",
" Action \\\n",
"0 DENY \n",
"1 DENY \n",
"2 DENY \n",
"3 DENY \n",
"4 PERMIT \n",
"\n",
" Output_Route \\\n",
"0 None \n",
"1 None \n",
"2 None \n",
"3 None \n",
"4 BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['1:4', '64512:42', '64513:21'], localPreference=0, metric=50, nextHopIp=None, sourceProtocol=None, tag=0, weight=0) \n",
"\n",
" Difference Trace \n",
"0 None \n",
"1 None \n",
"2 None \n",
"3 None \n",
"4 BgpRouteDiffs(diffs=[BgpRouteDiff(fieldName='communities', oldValue='[64512:42, 64513:21]', newValue='[1:4, 64512:42, 64513:21]'), BgpRouteDiff(fieldName='metric', oldValue='0', newValue='50')]) - Matched route-map as1_to_as4 clause 2 "
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.head(5)"
]
},
{
"cell_type": "markdown",
"id": "9939f830",
"metadata": {},
"source": [
"Print the first row of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "3fb48829",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Node as1border1\n",
"Policy_Name as1_to_as2\n",
"Input_Route BgpRoute(network='10.0.0.0/24', originatorIp='4.4.4.4', originType='egp', protocol='bgp', asPath=[{'asns': [64512, 64513], 'confederation': False}, {'asns': [64514], 'confederation': False}], communities=['64512:42', '64513:21'], localPreference=0, metric=0, nextHopIp=None, sourceProtocol=None, tag=0, weight=0)\n",
"Action DENY\n",
"Output_Route None\n",
"Difference None\n",
"Trace \n",
"Name: 0, dtype: object"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.iloc[0]"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "a9cc0c4d",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_network('generate_questions')"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "4a87dedd",
"metadata": {
"nbsphinx": "hidden"
},
"outputs": [
{
"data": {
"text/plain": [
"'generate_questions'"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bf.set_snapshot('generate_questions')"
]
},
{
"cell_type": "markdown",
"id": "4cf06d5d",
"metadata": {},
"source": [
"##### Search Route Policies"
]
},
{
"cell_type": "markdown",
"id": "031dac67",
"metadata": {},
"source": [
"Finds route announcements for which a route policy has a particular behavior."
]
},
{
"cell_type": "markdown",
"id": "8b36a3a8",
"metadata": {},
"source": [
"This question finds route announcements for which a route policy has a particular behavior. The behaviors can be: that the policy permits the route (`permit`) or that it denies the route (`deny`). Constraints can be imposed on the input route announcements of interest and, in the case of a `permit` action, also on the output route announcements of interest. Route policies are selected using node and policy specifiers, which might match multiple policies. In this case, a (possibly different) answer will be found for each policy. _Note:_ This question currently does not support all of the route policy features that Batfish supports. The question only supports common forms of matching on prefixes, communities, and AS-paths, as well as common forms of setting communities, the local preference, and the metric. The question logs all unsupported features that it encounters as warnings. Due to unsupported features, it is possible for the question to return no answers even for route policies that can in fact exhibit the specified behavior."
]
},
{
"cell_type": "markdown",
"id": "a2b5069f",
"metadata": {},
"source": [
"###### **Inputs**"
]
},
{
"cell_type": "markdown",
"id": "7345d0dc",
"metadata": {},
"source": [
"Name | Description | Type | Optional | Default Value\n",
"--- | --- | --- | --- | --- \n",
"nodes | Only examine policies on nodes matching this specifier. | [NodeSpec](../specifiers.md#node-specifier) | True | \n",
"policies | Only consider policies that match this specifier. | [RoutingPolicySpec](../specifiers.md#routing-policy-specifier) | True | \n",
"inputConstraints | Constraints on the set of input BGP route announcements to consider. | [BgpRouteConstraints](../datamodel.rst#pybatfish.datamodel.route.BgpRouteConstraints) | True | \n",
"action | The behavior to be evaluated. Specify exactly one of `permit` or `deny`. | str | True | \n",
"outputConstraints | Constraints on the set of output BGP route announcements to consider. | [BgpRouteConstraints](../datamodel.rst#pybatfish.datamodel.route.BgpRouteConstraints) | True | \n",
"perPath | (deprecated) Run the analysis separately for each execution path of a route map. This option is deprecated in favor of 'pathOption'. | bool | True | \n",
"pathOption | If set to 'per_path' run the analysis separately for each execution path. If set to `non_overlap` run the analysis separately for each execution path but greedily attempt to produce a different prefix for each advertisement to cover each path. This analysis may not produce results for all paths. If set to `single` (or null) the analysis will produce a single advertisement that meets the input and output constraints along one path through the route map. | str | True | "
]
},
{
"cell_type": "markdown",
"id": "39a43f5b",
"metadata": {},
"source": [
"###### **Invocation**"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "948b24b1",
"metadata": {},
"outputs": [],
"source": [
"result = bf.q.searchRoutePolicies(nodes='/^as1/', policies='/as1_to_/', inputConstraints=BgpRouteConstraints(prefix=[\"10.0.0.0/8:8-32\", \"172.16.0.0/28:28-32\", \"192.168.0.0/16:16-32\"]), action='permit').answer().frame()"
]
},
{
"cell_type": "markdown",
"id": "5d0f5450",
"metadata": {},
"source": [
"###### **Return Value**"
]
},
{
"cell_type": "markdown",
"id": "d188078e",
"metadata": {},
"source": [
"Name | Description | Type\n",
"--- | --- | ---\n",
"Node | The node that has the policy | str\n",
"Policy_Name | The name of this policy | str\n",
"Input_Route | The input route | [BgpRoute](../datamodel.rst#pybatfish.datamodel.route.BgpRoute)\n",
"Action | The action of the policy on the input route | str\n",
"Output_Route | The output route, if any | [BgpRoute](../datamodel.rst#pybatfish.datamodel.route.BgpRoute)\n",
"Difference | The difference between the input and output routes, if any | [BgpRouteDiffs](../datamodel.rst#pybatfish.datamodel.route.BgpRouteDiffs)\n",
"Trace | Route policy trace that shows which clauses/terms matched the input route. If the trace is empty, either nothing matched or tracing is not yet been implemented for this policy type. This is an experimental feature whose content and format is subject to change. | List of [TraceTree](../datamodel.rst#pybatfish.datamodel.acl.TraceTree)"
]
},
{
"cell_type": "markdown",
"id": "c742c4c7",
"metadata": {},
"source": [
"Print the first 5 rows of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "5fcef004",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Node | \n",
" Policy_Name | \n",
" Input_Route | \n",
" Action | \n",
" Output_Route | \n",
" Difference | \n",
" Trace | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" as1border2 | \n",
" as1_to_as4 | \n",
" BgpRoute(network='10.0.0.0/8', originatorIp='0.0.0.0', originType='egp', protocol='bgp', asPath=[], communities=[], localPreference=100, metric=0, nextHopIp='0.0.0.1', sourceProtocol=None, tag=0, weight=0) | \n",
" PERMIT | \n",
" BgpRoute(network='10.0.0.0/8', originatorIp='0.0.0.0', originType='egp', protocol='bgp', asPath=[], communities=['1:4'], localPreference=100, metric=50, nextHopIp='0.0.0.1', sourceProtocol=None, tag=0, weight=0) | \n",
" BgpRouteDiffs(diffs=[BgpRouteDiff(fieldName='communities', oldValue='[]', newValue='[1:4]'), BgpRouteDiff(fieldName='metric', oldValue='0', newValue='50')]) | \n",
" - Matched route-map as1_to_as4 clause 2 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Node Policy_Name Input_Route Action \\\n",
"0 as1border2 as1_to_as4 BgpRoute(network='10.0.0.0/8', originatorIp='0.0.0.0', originType='egp', protocol='bgp', asPath=[], communities=[], localPreference=100, metric=0, nextHopIp='0.0.0.1', sourceProtocol=None, tag=0, weight=0) PERMIT \n",
"\n",
" Output_Route \\\n",
"0 BgpRoute(network='10.0.0.0/8', originatorIp='0.0.0.0', originType='egp', protocol='bgp', asPath=[], communities=['1:4'], localPreference=100, metric=50, nextHopIp='0.0.0.1', sourceProtocol=None, tag=0, weight=0) \n",
"\n",
" Difference Trace \n",
"0 BgpRouteDiffs(diffs=[BgpRouteDiff(fieldName='communities', oldValue='[]', newValue='[1:4]'), BgpRouteDiff(fieldName='metric', oldValue='0', newValue='50')]) - Matched route-map as1_to_as4 clause 2 "
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result.head(5)"
]
},
{
"cell_type": "markdown",
"id": "17488f63",
"metadata": {},
"source": [
"Print the first row of the returned Dataframe"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "98a92681",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Node as1border2\n",
"Policy_Name as1_to_as4\n",
"Input_Route BgpRoute(network='10.0.0.0/8', originatorIp='0.0.0.0', originType='egp', protocol='bgp', asPath=[], communities=[], localPreference=100, metric=0, nextHopIp='0.0.0.1', sourceProtocol=None, tag=0, weight=0)\n",
"Action PERMIT\n",
"Output_Route BgpRoute(network='10.0.0.0/8', originatorIp='0.0.0.0', originType='egp', protocol='bgp', asPath=[], communities=['1:4'], localPreference=100, metric=50, nextHopIp='0.0.0.1', sourceProtocol=None, tag=0, weight=0)\n",
"Difference BgpRouteDiffs(diffs=[BgpRouteDiff(fieldName='communities', oldValue='[]', newValue='[1:4]'), BgpRouteDiff(fieldName='metric', oldValue='0', newValue='50')])\n",
"Trace - Matched route-map as1_to_as4 clause 2\n",
"Name: 0, dtype: object"
]
},
"execution_count": 37,
"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.9.17"
}
},
"nbformat": 4,
"nbformat_minor": 2
}