How to use the pybatfish.question.bfq.traceroute function in pybatfish

To help you get started, we’ve selected a few pybatfish examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github networkop / arista-network-ci / tests / batfish / leaf-3.py View on Github external
spines = set(loopbacks[loopbacks['Node'].str.contains('spine')]['IP'])
    mpath = len(spines)

    logging.info("Progress: Analyzing traceroute from Leaf-3 to Leaf-1 and Leaf-2")
    # Set up the resulting data structure
    troute = dict()
    for leaf in leaves:
        troute[leaf] = dict()

    # Build headers for traceroute flows
    for leaf in leaves:
        troute[leaf]['header'] = header(srcIps=localIP,dstIps=leaf)

    # Ask questions about traceroute
    for leaf,data in troute.items():
        troute[leaf]['trace'] = bfq.traceroute(startLocation=fromNode, headers=data['header']).answer()
    
    # Get first flow disposition for traces
    for leaf,data in troute.items():
        troute[leaf]['result'] = data['trace'].get('answerElements')[0]['rows'][0]['Traces'][0]['disposition']

    # Get traceroute paths to reach Leaf-1 and  Leaf-2
    for leaf,data in troute.items():
        troute[leaf]['paths'] = data['trace'].get('answerElements')[0]['rows'][0]['Traces']

    # Get traceroute hops to reach Leaf-1 and Leaf-2
    for leaf,data in troute.items():
        troute[leaf]['hops'] = data['trace'].get('answerElements')[0]['rows'][0]['Traces'][0].get('hops',[])

    # Now let's check that the traceroute behaves as we expect
    for leaf, data in troute.items():
        if data['result'] != 'ACCEPTED':