Use Case - Return Hop List of a Path in Third-party System

In a third-party system that supports scripts, you can test the end-to-end path reachability via NetBrain APIs. If path calculation succeeds, the whole hop list of the path will be returned; if path calculation failed, the failure result and failure point will be returned.

Workflow

The pseudo-code below describes the main flow in the API script to return hop list of a path.

1. Login into NetBrain session and get system token.
2. Set the operation tenant and domain.
3. Get the default gateway information of Source IP.
4. Calculate Path and get task ID.
5. Query path information based on the task ID.
6. Logout the session.

API Script

You can refer to the script below to call relative APIs. This sample script first imports a python library maintained by NetBrain and you need to write your own one in practical use.

import netbrain_restful_lib as api
 
nb_url = "http(s)://<IP address of NetBrain Web Server>/"
user = "NetBrain"
pwd = "Netbrain"
tenantName ='Initial Tenant'
domainName = 'Integration'
 
# Step1: Login into NetBrain session and get system token.
token = api.loginSession(nb_url, user, pwd)
print(api.getTenants(nb_url, token))
print(api.getDomains(nb_url, token))
# [{'tenantId': 'cb36f82b-4126-2fef-5310-c3a66f3dae4d', 'tenantName': 'Initial Tenant'},
# {'tenantId': '1aae7b92-520f-4d22-96ed-9ccc77ab5678', 'tenantName': 'TenantName'}]
# [{'domainId': '6f9be63d-2290-4121-ae8b-c8fdb53a56ec', 'domainName': 'Integration'}]
tenantId = "cb36f82b-4126-2fef-5310-c3a66f3dae4d"
domainId = "6f9be63d-2290-4121-ae8b-c8fdb53a56ec"
 
# Step2: Set the operation tenant and domain.
print(api.loginDomain(nb_url, token, tenantId, domainId))
# loginDomain: Login successfully!
 
# Step3: Get the default gateway information of Source IP.
sourceIP = "10.30.8.108"
api.GetGatewayInfo(nb_url, token, sourceIP)
# [{'ip': '10.30.8.105', 'devName': 'HSRP', 'intfName': '21'},
# {'ip': '10.30.8.106', 'devName': 'NBCNBJ-SW1', 'intfName': 'Vlan2100'},
# {'ip': '10.30.8.107', 'devName': 'NBCNBJ-SW2', 'intfName': 'Vlan2100'}]
 
# Step4: Calculate Path and get task ID.
sourcePort = 80
sourceGwIP = "10.30.8.105"
sourceGwDev = "HSRP"
sourceGwIntf = "21"
destIP = "10.30.7.108"
destPort = 80
pathAnalysisSet = 1
protocol = 4
isLive = False
 
path_param={
        "sourceIP":sourceIP,                # IP address of the source device.
        "sourcePort":sourcePort,            # TCP/UDP protocol port, such as 23 for telnet. This parameter can be null. 
        "sourceGwDev":sourceGwDev,          # Hostname of the gateway device.
        "sourceGwIP":sourceGwIP,            # Ip address of the gateway device.
        "sourceGwIntf":sourceGwIntf,        # Name of the gateway interface.
        "destIP":destIP,                    # IP address of the destination device.
        "destPort":destPort,                # TCP/UDP protocol port, such as 23 for telnet. This parameter can be null.         
        "pathAnalysisSet":pathAnalysisSet,  # 1:L3 Path; 2:L2 Path; 3:L3 Active Path
        "protocol":protocol,                # Specify the application protocol, check online help, such as 4 for IPv4.
        "isLive":isLive                     # False: Current Baseline; True: Live access
}
api.CalPath(nb_url, token, path_param)
# Path task ID: ab3f5241-24db-4b9a-bf3c-1def89fb4599
 
# Step5: Query path information based on the task ID.
taskID = "ab3f5241-24db-4b9a-bf3c-1def89fb4599"
api.GetPathResult(nb_url, token, taskID)
# [{'hopId': '5e9b740e-16f9-41a5-9fe3-928479110cbe', 'srcDeviceName': '10.30.8.108', 'inboundInterface': '', 'mediaName': '10.30.8.104/29\r\nHSRP: 21(10.30.8.105)', 'dstDeviceName': 'NBCNBJ-SW1', 'outboundInterface': 'Vlan2100', 'nextHopIdList': ['a144f294-4311-445e-9aff-a80f3562e8a0']},
# {'hopId': 'a144f294-4311-445e-9aff-a80f3562e8a0', 'srcDeviceName': 'NBCNBJ-SW1', 'inboundInterface': 'Vlan1', 'mediaName': '10.30.8.24/29', 'dstDeviceName': 'NBCNBJ-SRX2', 'outboundInterface': 'reth1.0', 'nextHopIdList': ['0d436e76-43e3-4620-bd96-3c88007feb88']},
# {'hopId': '0d436e76-43e3-4620-bd96-3c88007feb88', 'srcDeviceName': 'NBCNBJ-SRX2', 'inboundInterface': 'reth0.0', 'mediaName': '10.30.8.16/29', 'dstDeviceName': 'NBCNBJ-R1', 'outboundInterface': 'ge-0/0/2.0', 'nextHopIdList': ['ca4107dc-5b44-4892-9ba1-c4094917d857']},
# {'hopId': 'ca4107dc-5b44-4892-9ba1-c4094917d857', 'srcDeviceName': 'NBCNBJ-R1', 'inboundInterface': 'ge-0/0/1.10', 'mediaName': '10.30.7.32/29', 'dstDeviceName': 'AT&T-AS7018', 'outboundInterface': 'ge-0/0/1.10-10.30.7.33', 'nextHopIdList': ['8e4982de-f53b-41cc-bdcd-58c22c63e81b']},
# {'hopId': '8e4982de-f53b-41cc-bdcd-58c22c63e81b', 'srcDeviceName': 'AT&T-AS7018', 'inboundInterface': 'FastEthernet1/0.10-10.30.7.17(blue)', 'mediaName': '10.30.7.16/29\r\nVRF:blue', 'dstDeviceName': 'NBUSMA-R1', 'outboundInterface': 'FastEthernet1/0.10', 'nextHopIdList': ['c263e983-f247-4d06-8497-6c0d12c8ca19']},
# {'hopId': 'c263e983-f247-4d06-8497-6c0d12c8ca19', 'srcDeviceName': 'NBUSMA-R1', 'inboundInterface': 'FastEthernet2/0', 'mediaName': '10.30.7.104/29', 'dstDeviceName': 'NBUSMA-R2', 'outboundInterface': 'FastEthernet2/0', 'nextHopIdList': []},
# {'hopId': 'ea019ad9-1b18-4658-8d22-cf7b41dbc6ad', 'srcDeviceName': '10.30.8.108', 'inboundInterface': '', 'mediaName': '10.30.8.104/29\r\nHSRP: 21(10.30.8.105)', 'dstDeviceName': 'NBCNBJ-SW2', 'outboundInterface': 'Vlan2100', 'nextHopIdList': ['80ec41b1-d4b4-4f84-b18f-335e22aa6937']},
# {'hopId': '80ec41b1-d4b4-4f84-b18f-335e22aa6937', 'srcDeviceName': 'NBCNBJ-SW2', 'inboundInterface': 'Vlan1', 'mediaName': '10.30.8.24/29', 'dstDeviceName': 'NBCNBJ-SRX2', 'outboundInterface': 'reth1.0', 'nextHopIdList': ['0d436e76-43e3-4620-bd96-3c88007feb88']}]
 
 
# Step6: Logout the session.
print(api.logoutSession(nb_url, token))
# Session logout successfully!