def VerifySessionsBgpNgpfPy():
    # This API will loop through all Topology Groups for bgp configuration and
    # verify all of its sessions.
    #
    # Returns 0 if all sessions are UP.
    # Returns a list of local Ip addresses that are down.

    for topology in ixNet.getList(ixNet.getRoot(), 'topology'):
        for deviceGroup in ixNet.getList(topology, 'deviceGroup'):
            for ethernet in ixNet.getList(deviceGroup, 'ethernet'):
                for ipv4 in ixNet.getList(ethernet, 'ipv4'):
                     for bgp in ixNet.getList(ipv4, 'bgpIpv4Peer'):
                        print '\nVerifying BGP sessions:', bgp
                        sessionStatusList = ixNet.getAttribute(bgp, '-sessionStatus')
                        localIpList = ixNet.getAttribute(bgp, '-localIpv4Ver2')
                        if 'down' in sessionStatusList:
                            duplicateIndexes = [index for index,element in enumerate(sessionStatusList) if element == 'down']
                            returnList = []
                            for eachIndex in duplicateIndexes:
                                localIpAddress = localIpList[eachIndex]
                                returnList.append(localIpAddress)
                                print 'Local IP Address is down:', localIpAddress
                            return returnList
                        else:
                            return 0