{ "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": "bcc356a5", "metadata": {}, "source": [ "#### Routing and Forwarding Tables" ] }, { "cell_type": "markdown", "id": "ce547ed3", "metadata": {}, "source": [ "This category of questions allows you to query the RIBs and FIBs computed\n", "by Batfish.\n" ] }, { "cell_type": "markdown", "id": "7be29277", "metadata": {}, "source": [ "* [Routes](#Routes)\n", "* [BGP RIB](#BGP-RIB)\n", "* [EVPN RIB](#EVPN-RIB)\n", "* [Longest Prefix Match](#Longest-Prefix-Match)" ] }, { "cell_type": "code", "execution_count": 3, "id": "5fd8572b", "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": "aee4c56c", "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": "c4b19f3e", "metadata": {}, "source": [ "##### Routes" ] }, { "cell_type": "markdown", "id": "5de29ac1", "metadata": {}, "source": [ "Returns routing tables." ] }, { "cell_type": "markdown", "id": "7cf9235b", "metadata": {}, "source": [ "Shows routes for specified RIB, VRF, and node(s)." ] }, { "cell_type": "markdown", "id": "20fc470c", "metadata": {}, "source": [ "###### **Inputs**" ] }, { "cell_type": "markdown", "id": "ffddb3c6", "metadata": {}, "source": [ "Name | Description | Type | Optional | Default Value\n", "--- | --- | --- | --- | --- \n", "nodes | Return routes on nodes matching this specifier. | [NodeSpec](../specifiers.md#node-specifier) | True | \n", "network | Return routes for networks matching this prefix. | str | True | \n", "prefixMatchType | Use this prefix matching criterion: EXACT, LONGEST_PREFIX_MATCH, LONGER_PREFIXES, SHORTER_PREFIXES. | str | True | EXACT\n", "protocols | Return routes for protocols matching this specifier. | [RoutingProtocolSpec](../specifiers.md#routing-protocol-specifier) | True | \n", "vrfs | Return routes on VRFs matching this name or regex. | str | True | \n", "rib | Only return routes from a given protocol RIB. | str | True | " ] }, { "cell_type": "markdown", "id": "299b2967", "metadata": {}, "source": [ "###### **Invocation**" ] }, { "cell_type": "code", "execution_count": 5, "id": "011b884d", "metadata": {}, "outputs": [], "source": [ "result = bf.q.routes().answer().frame()" ] }, { "cell_type": "markdown", "id": "7413b3ba", "metadata": {}, "source": [ "###### **Return Value**" ] }, { "cell_type": "markdown", "id": "63b87986", "metadata": {}, "source": [ "Name | Description | Type\n", "--- | --- | ---\n", "Node | Node | str\n", "VRF | VRF name | str\n", "Network | Network for this route | str\n", "Next_Hop | Route's Next Hop | [NextHop](../datamodel.rst#pybatfish.datamodel.route.NextHop)\n", "Next_Hop_IP | Route's Next Hop IP | str\n", "Next_Hop_Interface | Route's Next Hop Interface | str\n", "Protocol | Route's Protocol | str\n", "Metric | Route's Metric | int\n", "Admin_Distance | Route's Admin distance | int\n", "Tag | Tag for this route | int" ] }, { "cell_type": "markdown", "id": "c07894ce", "metadata": {}, "source": [ "Print the first 5 rows of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 6, "id": "7b29d69c", "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", " \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", "
NodeVRFNetworkNext_HopNext_Hop_IPNext_Hop_InterfaceProtocolMetricAdmin_DistanceTag
0as1border1default1.0.1.0/24interface GigabitEthernet0/0NoneGigabitEthernet0/0connected00None
1as1border1default1.0.1.1/32interface GigabitEthernet0/0NoneGigabitEthernet0/0local00None
2as1border1default1.0.2.0/24interface GigabitEthernet0/0 ip 1.0.1.21.0.1.2GigabitEthernet0/0ospf2110None
3as1border1default1.1.1.1/32interface Loopback0NoneLoopback0connected00None
4as1border1default1.2.2.2/32interface GigabitEthernet0/0 ip 1.0.1.21.0.1.2GigabitEthernet0/0ospf3110None
\n", "
" ], "text/plain": [ " Node VRF Network Next_Hop Next_Hop_IP Next_Hop_Interface Protocol Metric Admin_Distance Tag\n", "0 as1border1 default 1.0.1.0/24 interface GigabitEthernet0/0 None GigabitEthernet0/0 connected 0 0 None\n", "1 as1border1 default 1.0.1.1/32 interface GigabitEthernet0/0 None GigabitEthernet0/0 local 0 0 None\n", "2 as1border1 default 1.0.2.0/24 interface GigabitEthernet0/0 ip 1.0.1.2 1.0.1.2 GigabitEthernet0/0 ospf 2 110 None\n", "3 as1border1 default 1.1.1.1/32 interface Loopback0 None Loopback0 connected 0 0 None\n", "4 as1border1 default 1.2.2.2/32 interface GigabitEthernet0/0 ip 1.0.1.2 1.0.1.2 GigabitEthernet0/0 ospf 3 110 None" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.head(5)" ] }, { "cell_type": "markdown", "id": "22d5b0d4", "metadata": {}, "source": [ "Print the first row of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 7, "id": "99bd784f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Node as1border1\n", "VRF default\n", "Network 1.0.1.0/24\n", "Next_Hop interface GigabitEthernet0/0\n", "Next_Hop_IP None\n", "Next_Hop_Interface GigabitEthernet0/0\n", "Protocol connected\n", "Metric 0\n", "Admin_Distance 0\n", "Tag None\n", "Name: 0, dtype: object" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.iloc[0]" ] }, { "cell_type": "code", "execution_count": 8, "id": "d2e30c49", "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": "4b04474d", "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": "1785fa54", "metadata": {}, "source": [ "##### BGP RIB" ] }, { "cell_type": "markdown", "id": "716912fd", "metadata": {}, "source": [ "Returns routes in the BGP RIB." ] }, { "cell_type": "markdown", "id": "344836f7", "metadata": {}, "source": [ "Shows BGP routes for specified VRF and node(s). This question is not available in Batfish containers on dockerhub prior to March 29, 2021." ] }, { "cell_type": "markdown", "id": "dcda6fc2", "metadata": {}, "source": [ "###### **Inputs**" ] }, { "cell_type": "markdown", "id": "d4e8d5e4", "metadata": {}, "source": [ "Name | Description | Type | Optional | Default Value\n", "--- | --- | --- | --- | --- \n", "nodes | Examine routes on nodes matching this specifier. | [NodeSpec](../specifiers.md#node-specifier) | True | \n", "network | Examine routes for networks matching this prefix. | str | True | \n", "prefixMatchType | Use this prefix matching criterion: EXACT, LONGEST_PREFIX_MATCH, LONGER_PREFIXES, SHORTER_PREFIXES. | str | True | EXACT\n", "vrfs | Examine routes on VRFs matching this name or regex. | str | True | \n", "status | Examine routes whose status matches this specifier. | [BgpRouteStatusSpec](../specifiers.md#bgp-route-status-specifier) | True | " ] }, { "cell_type": "markdown", "id": "e73fc141", "metadata": {}, "source": [ "###### **Invocation**" ] }, { "cell_type": "code", "execution_count": 10, "id": "2d189603", "metadata": {}, "outputs": [], "source": [ "result = bf.q.bgpRib().answer().frame()" ] }, { "cell_type": "markdown", "id": "9ffbfbe9", "metadata": {}, "source": [ "###### **Return Value**" ] }, { "cell_type": "markdown", "id": "ea38b572", "metadata": {}, "source": [ "Name | Description | Type\n", "--- | --- | ---\n", "Node | Node | str\n", "VRF | VRF name | str\n", "Network | Network for this route | str\n", "Status | Route's statuses | List of str\n", "Next_Hop | Route's Next Hop | [NextHop](../datamodel.rst#pybatfish.datamodel.route.NextHop)\n", "Next_Hop_IP | Route's Next Hop IP | str\n", "Next_Hop_Interface | Route's Next Hop Interface | str\n", "Protocol | Route's Protocol | str\n", "AS_Path | Route's AS path | str\n", "Metric | Route's Metric | int\n", "Local_Pref | Route's Local Preference | int\n", "Communities | Route's List of communities | List of str\n", "Origin_Protocol | Route's Origin protocol | str\n", "Origin_Type | Route's Origin type | str\n", "Originator_Id | Route's Originator ID | str\n", "Received_From_IP | IP of the neighbor who sent this route | str\n", "Received_Path_Id | Route's Received Path ID | int\n", "Cluster_List | Route's Cluster List | Set of int\n", "Tunnel_Encapsulation_Attribute | Route's BGP Tunnel Encapsulation Attribute | str\n", "Weight | Route's BGP Weight | int\n", "Tag | Tag for this route | int" ] }, { "cell_type": "markdown", "id": "1bf6c3fc", "metadata": {}, "source": [ "Print the first 5 rows of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 11, "id": "37f733ad", "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", " \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", " \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", " \n", " \n", " \n", " \n", "
NodeVRFNetworkStatusNext_HopNext_Hop_IPNext_Hop_InterfaceProtocolAS_PathMetricLocal_PrefCommunitiesOrigin_ProtocolOrigin_TypeOriginator_IdReceived_From_IPReceived_Path_IdCluster_ListTunnel_Encapsulation_AttributeWeightTag
0as1border1default1.0.1.0/24['BEST']discardNonenull_interfacebgp0100[]connectedigp1.1.1.10.0.0.0NoneNoneNone32768None
1as1border1default1.0.2.0/24['BEST']ip 1.0.1.21.0.1.2dynamicbgp2100[]ospfigp1.1.1.10.0.0.0NoneNoneNone32768None
2as1border1default2.128.0.0/16['BEST']ip 10.12.11.210.12.11.2dynamicbgp250350['2:1']bgpigp2.1.1.110.12.11.2NoneNoneNone0None
3as1border1default3.0.1.0/24['BEST']ip 10.13.22.310.13.22.3dynamicibgp350350['3:1']ibgpigp1.2.2.21.10.1.11[17432833]None0None
4as1border1default3.0.2.0/24['BEST']ip 10.13.22.310.13.22.3dynamicibgp350350['3:1']ibgpigp1.2.2.21.10.1.11[17432833]None0None
\n", "
" ], "text/plain": [ " Node VRF Network Status Next_Hop Next_Hop_IP Next_Hop_Interface Protocol AS_Path Metric Local_Pref Communities Origin_Protocol Origin_Type Originator_Id Received_From_IP Received_Path_Id Cluster_List Tunnel_Encapsulation_Attribute Weight Tag\n", "0 as1border1 default 1.0.1.0/24 ['BEST'] discard None null_interface bgp 0 100 [] connected igp 1.1.1.1 0.0.0.0 None None None 32768 None\n", "1 as1border1 default 1.0.2.0/24 ['BEST'] ip 1.0.1.2 1.0.1.2 dynamic bgp 2 100 [] ospf igp 1.1.1.1 0.0.0.0 None None None 32768 None\n", "2 as1border1 default 2.128.0.0/16 ['BEST'] ip 10.12.11.2 10.12.11.2 dynamic bgp 2 50 350 ['2:1'] bgp igp 2.1.1.1 10.12.11.2 None None None 0 None\n", "3 as1border1 default 3.0.1.0/24 ['BEST'] ip 10.13.22.3 10.13.22.3 dynamic ibgp 3 50 350 ['3:1'] ibgp igp 1.2.2.2 1.10.1.1 1 [17432833] None 0 None\n", "4 as1border1 default 3.0.2.0/24 ['BEST'] ip 10.13.22.3 10.13.22.3 dynamic ibgp 3 50 350 ['3:1'] ibgp igp 1.2.2.2 1.10.1.1 1 [17432833] None 0 None" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.head(5)" ] }, { "cell_type": "markdown", "id": "58a68b6d", "metadata": {}, "source": [ "Print the first row of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 12, "id": "75037654", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Node as1border1\n", "VRF default\n", "Network 1.0.1.0/24\n", "Status ['BEST']\n", "Next_Hop discard\n", "Next_Hop_IP None\n", "Next_Hop_Interface null_interface\n", "Protocol bgp\n", "AS_Path \n", "Metric 0\n", "Local_Pref 100\n", "Communities []\n", "Origin_Protocol connected\n", "Origin_Type igp\n", "Originator_Id 1.1.1.1\n", "Received_From_IP 0.0.0.0\n", "Received_Path_Id None\n", "Cluster_List None\n", "Tunnel_Encapsulation_Attribute None\n", "Weight 32768\n", "Tag None\n", "Name: 0, dtype: object" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.iloc[0]" ] }, { "cell_type": "code", "execution_count": 13, "id": "cc5b335d", "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": "3c3002fa", "metadata": { "nbsphinx": "hidden" }, "outputs": [ { "data": { "text/plain": [ "'aristaevpn'" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bf.set_snapshot('aristaevpn')" ] }, { "cell_type": "markdown", "id": "842dbe90", "metadata": {}, "source": [ "##### EVPN RIB" ] }, { "cell_type": "markdown", "id": "526eb0cd", "metadata": {}, "source": [ "Returns routes in the EVPN RIB." ] }, { "cell_type": "markdown", "id": "63a37145", "metadata": {}, "source": [ "Shows EVPN routes for specified VRF and node(s). This question is not available in Batfish containers on dockerhub prior to March 29, 2021." ] }, { "cell_type": "markdown", "id": "27aee7d6", "metadata": {}, "source": [ "###### **Inputs**" ] }, { "cell_type": "markdown", "id": "7bd22140", "metadata": {}, "source": [ "Name | Description | Type | Optional | Default Value\n", "--- | --- | --- | --- | --- \n", "nodes | Examine routes on nodes matching this specifier. | [NodeSpec](../specifiers.md#node-specifier) | True | \n", "network | Examine routes for networks matching this prefix. | str | True | \n", "prefixMatchType | Use this prefix matching criterion: EXACT, LONGEST_PREFIX_MATCH, LONGER_PREFIXES, SHORTER_PREFIXES. | str | True | EXACT\n", "vrfs | Examine routes on VRFs matching this name or regex. | str | True | " ] }, { "cell_type": "markdown", "id": "0d6c5af4", "metadata": {}, "source": [ "###### **Invocation**" ] }, { "cell_type": "code", "execution_count": 15, "id": "277e27d6", "metadata": {}, "outputs": [], "source": [ "result = bf.q.evpnRib().answer().frame()" ] }, { "cell_type": "markdown", "id": "e3c06e30", "metadata": {}, "source": [ "###### **Return Value**" ] }, { "cell_type": "markdown", "id": "3917efee", "metadata": {}, "source": [ "Name | Description | Type\n", "--- | --- | ---\n", "Node | Node | str\n", "VRF | VRF name | str\n", "Network | Network for this route | str\n", "Status | Route's statuses | List of str\n", "Route_Distinguisher | Route distinguisher | str\n", "Next_Hop | Route's Next Hop | [NextHop](../datamodel.rst#pybatfish.datamodel.route.NextHop)\n", "Next_Hop_IP | Route's Next Hop IP | str\n", "Next_Hop_Interface | Route's Next Hop Interface | str\n", "Protocol | Route's Protocol | str\n", "AS_Path | Route's AS path | str\n", "Metric | Route's Metric | int\n", "Local_Pref | Route's Local Preference | int\n", "Communities | Route's List of communities | List of str\n", "Origin_Protocol | Route's Origin protocol | str\n", "Origin_Type | Route's Origin type | str\n", "Originator_Id | Route's Originator ID | str\n", "Received_Path_Id | Route's Received Path ID | int\n", "Cluster_List | Route's Cluster List | Set of int\n", "Tunnel_Encapsulation_Attribute | Route's BGP Tunnel Encapsulation Attribute | str\n", "Weight | Route's BGP Weight | int\n", "Tag | Tag for this route | int" ] }, { "cell_type": "markdown", "id": "cfc4530e", "metadata": {}, "source": [ "Print the first 5 rows of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 16, "id": "c10c66b0", "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", " \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", " \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", " \n", " \n", " \n", " \n", "
NodeVRFNetworkStatusRoute_DistinguisherNext_HopNext_Hop_IPNext_Hop_InterfaceProtocolAS_PathMetricLocal_PrefCommunitiesOrigin_ProtocolOrigin_TypeOriginator_IdReceived_Path_IdCluster_ListTunnel_Encapsulation_AttributeWeightTag
0dc1-bl1adefault10.1.10.0/24['BEST']192.168.255.3:15001vni 15001 vtep 192.168.254.3Nonedynamicbgp65001 651010100['2:15001:15001']bgpigp192.168.255.1NoneNoneNone0None
1dc1-bl1adefault10.1.10.0/24['BEST']192.168.255.4:15001vni 15001 vtep 192.168.254.4Nonedynamicbgp65001 651020100['2:15001:15001']bgpigp192.168.255.1NoneNoneNone0None
2dc1-bl1adefault10.1.10.0/24['BEST']192.168.255.5:15001vni 15001 vtep 192.168.254.4Nonedynamicbgp65001 651020100['2:15001:15001']bgpigp192.168.255.1NoneNoneNone0None
3dc1-bl1adefault10.1.11.0/24['BEST']192.168.255.5:15001vni 15001 vtep 192.168.254.4Nonedynamicbgp65001 651020100['2:15001:15001']bgpigp192.168.255.1NoneNoneNone0None
4dc1-bl1adefault10.1.11.0/24['BEST']192.168.255.4:15001vni 15001 vtep 192.168.254.4Nonedynamicbgp65001 651020100['2:15001:15001']bgpigp192.168.255.1NoneNoneNone0None
\n", "
" ], "text/plain": [ " Node VRF Network Status Route_Distinguisher Next_Hop Next_Hop_IP Next_Hop_Interface Protocol AS_Path Metric Local_Pref Communities Origin_Protocol Origin_Type Originator_Id Received_Path_Id Cluster_List Tunnel_Encapsulation_Attribute Weight \\\n", "0 dc1-bl1a default 10.1.10.0/24 ['BEST'] 192.168.255.3:15001 vni 15001 vtep 192.168.254.3 None dynamic bgp 65001 65101 0 100 ['2:15001:15001'] bgp igp 192.168.255.1 None None None 0 \n", "1 dc1-bl1a default 10.1.10.0/24 ['BEST'] 192.168.255.4:15001 vni 15001 vtep 192.168.254.4 None dynamic bgp 65001 65102 0 100 ['2:15001:15001'] bgp igp 192.168.255.1 None None None 0 \n", "2 dc1-bl1a default 10.1.10.0/24 ['BEST'] 192.168.255.5:15001 vni 15001 vtep 192.168.254.4 None dynamic bgp 65001 65102 0 100 ['2:15001:15001'] bgp igp 192.168.255.1 None None None 0 \n", "3 dc1-bl1a default 10.1.11.0/24 ['BEST'] 192.168.255.5:15001 vni 15001 vtep 192.168.254.4 None dynamic bgp 65001 65102 0 100 ['2:15001:15001'] bgp igp 192.168.255.1 None None None 0 \n", "4 dc1-bl1a default 10.1.11.0/24 ['BEST'] 192.168.255.4:15001 vni 15001 vtep 192.168.254.4 None dynamic bgp 65001 65102 0 100 ['2:15001:15001'] bgp igp 192.168.255.1 None None None 0 \n", "\n", " Tag \n", "0 None \n", "1 None \n", "2 None \n", "3 None \n", "4 None " ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.head(5)" ] }, { "cell_type": "markdown", "id": "4a1286f3", "metadata": {}, "source": [ "Print the first row of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 17, "id": "7a6e0ef0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Node dc1-bl1a\n", "VRF default\n", "Network 10.1.10.0/24\n", "Status ['BEST']\n", "Route_Distinguisher 192.168.255.3:15001\n", "Next_Hop vni 15001 vtep 192.168.254.3\n", "Next_Hop_IP None\n", "Next_Hop_Interface dynamic\n", "Protocol bgp\n", "AS_Path 65001 65101\n", "Metric 0\n", "Local_Pref 100\n", "Communities ['2:15001:15001']\n", "Origin_Protocol bgp\n", "Origin_Type igp\n", "Originator_Id 192.168.255.1\n", "Received_Path_Id None\n", "Cluster_List None\n", "Tunnel_Encapsulation_Attribute None\n", "Weight 0\n", "Tag None\n", "Name: 0, dtype: object" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.iloc[0]" ] }, { "cell_type": "code", "execution_count": 18, "id": "cfa63fc6", "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": "5c5372f1", "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": "8e1e5678", "metadata": {}, "source": [ "##### Longest Prefix Match" ] }, { "cell_type": "markdown", "id": "f40cf2b1", "metadata": {}, "source": [ "Returns routes that are longest prefix match for a given IP address." ] }, { "cell_type": "markdown", "id": "44e66048", "metadata": {}, "source": [ "Return longest prefix match routes for a given IP in the RIBs of specified nodes and VRFs." ] }, { "cell_type": "markdown", "id": "ed864d38", "metadata": {}, "source": [ "###### **Inputs**" ] }, { "cell_type": "markdown", "id": "16221f87", "metadata": {}, "source": [ "Name | Description | Type | Optional | Default Value\n", "--- | --- | --- | --- | --- \n", "ip | IP address to run LPM on. | str | False | \n", "nodes | Examine routes on nodes matching this specifier. | [NodeSpec](../specifiers.md#node-specifier) | True | .*\n", "vrfs | Examine routes on VRFs matching this name or regex. | str | True | .*" ] }, { "cell_type": "markdown", "id": "887acf91", "metadata": {}, "source": [ "###### **Invocation**" ] }, { "cell_type": "code", "execution_count": 20, "id": "149e5f02", "metadata": {}, "outputs": [], "source": [ "result = bf.q.lpmRoutes(ip='2.34.201.10').answer().frame()" ] }, { "cell_type": "markdown", "id": "092d9b95", "metadata": {}, "source": [ "###### **Return Value**" ] }, { "cell_type": "markdown", "id": "d4c8a6b5", "metadata": {}, "source": [ "Name | Description | Type\n", "--- | --- | ---\n", "Node | Node where the route is present | str\n", "VRF | VRF where the route is present | str\n", "Ip | IP that was being matched on | str\n", "Network | The longest-prefix network that matched | str\n", "Num_Routes | Number of routes that matched (in case of ECMP) | int" ] }, { "cell_type": "markdown", "id": "8a0ed974", "metadata": {}, "source": [ "Print the first 5 rows of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 21, "id": "a6255f63", "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", " \n", " \n", " \n", " \n", " \n", " \n", "
NodeVRFIpNetworkNum_Routes
0as2border1default2.34.201.102.34.201.0/242
1as2border2default2.34.201.102.34.201.0/242
2as2core1default2.34.201.102.34.201.0/241
3as2core2default2.34.201.102.34.201.0/241
4as2dept1default2.34.201.102.34.201.0/241
\n", "
" ], "text/plain": [ " Node VRF Ip Network Num_Routes\n", "0 as2border1 default 2.34.201.10 2.34.201.0/24 2\n", "1 as2border2 default 2.34.201.10 2.34.201.0/24 2\n", "2 as2core1 default 2.34.201.10 2.34.201.0/24 1\n", "3 as2core2 default 2.34.201.10 2.34.201.0/24 1\n", "4 as2dept1 default 2.34.201.10 2.34.201.0/24 1" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.head(5)" ] }, { "cell_type": "markdown", "id": "0e5e175b", "metadata": {}, "source": [ "Print the first row of the returned Dataframe" ] }, { "cell_type": "code", "execution_count": 22, "id": "941570f9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Node as2border1\n", "VRF default\n", "Ip 2.34.201.10\n", "Network 2.34.201.0/24\n", "Num_Routes 2\n", "Name: 0, dtype: object" ] }, "execution_count": 22, "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.10.17" } }, "nbformat": 4, "nbformat_minor": 2 }