napalm-automation-community / napalm-ros

MikroTik RouterOS NAPALM driver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get_bgp_neighbors and get_bgp_neighbors_detail error

Dacesilian opened this issue · comments

Description of Issue/Question

get_interfaces_counters doesn't work. It reproduces error:

GET /api/dcim/devices/2/napalm/?method=get_...

{
    "get_bgp_neighbors": {
        "error": "Method get_bgp_neighbors failed: 'prefix-count'"
    }
}
{
    "get_bgp_neighbors_detail": {
        "error": "Method get_bgp_neighbors_detail failed: 'established'"
    }
}

Setup

napalm-ros version

Installed first with pip and then also from this github and used: python3 ./setup.py install

napalm-ros==1.0.0

ROS version

"vendor": "MikroTik",
"model": "RB4011iGS+",
"os_version": "6.47.6 (stable)",

Hi.

Napalm as far as I know doesn't expose any HTTP api. Please run the same command from cli / ipython. I need exact exception so I can help.

Hello, I was able to reproduce this error in Python.

Run script:

import napalm
from napalm_ros import ros

router_ip = '10.0.0.1'
router_port = 8728
router_user = 'user'
router_pass = 'pass'

driver = napalm.get_network_driver('ros')

print('Connecting to', router_ip, "on port", router_port, "as", router_user)

device = driver(hostname=router_ip, username=router_user,
                    password=router_pass, optional_args={'port': router_port})

device.open()

print(device.get_bgp_neighbors())

Reproduces error:

Connecting to 10.0.0.1 on port 8728 as user
Traceback (most recent call last):
  File "napalm_ros_test.py", line 18, in <module>
    print(device.get_bgp_neighbors())
  File "...LocalCache\local-packages\Python38\site-packages\napalm_ros\ros.py", line 110, in get_bgp_neighbors
    "accepted_prefixes": peer["prefix-count"],
KeyError: 'prefix-count'

Similar with get_bgp_neighbors_detail():

napalm_ros\ros.py", line 145, in get_bgp_neighbors_detail
    "up": peer["established"],
KeyError: 'established'

Thanks.

I wonder how it is possible that bgp peer doesn't have any prefix-count ? Is this connection established ? Please check this in cli on the device.

I am unable to reproduce this problem on a CCR1009 running 6.47.8 using napalm-ros==1.0.0. @Dacesilian can you please inspect the api response directly with librouteros as follows (replacing user/pass/ip where applicable):

>>> from librouteros import connect
>>> from pprint import pprint
>>> api = connect(
...     username='username',
...     password='password',
...     host='10.0.0.1',
... )
>>> for row in api('/routing/bgp/peer/print'):
...     pprint(row)

I am curious what keys you get back from the api call. I think it should clue us in on how to fix this.

I suspect that MikroTik in their infinite wisdom decided to not show established at all when peer is not connected ....

wow, yeah thats exactly what is going on:

{'.id': '*0',
 'address-families': 'ip',
 'as-override': False,
 'default-originate': 'never',
 'disabled': True,
 'hold-time': '30s',
 'in-filter': 'access-plus-in',
 'instance': 'default',
 'keepalive-time': '10s',
 'multihop': False,
 'name': 'ACCESS_PLUS',
 'nexthop-choice': 'default',
 'out-filter': 'access-plus-out',
 'passive': False,
 'remote-address': '<redacted>',
 'remote-as': <redacted>,
 'remove-private-as': False,
 'route-reflect': False,
 'tcp-md5-key': '',
 'ttl': 255,
 'use-bfd': False}

I can make a patch for this.

There are many columns missing in some records; and in others, there is established False present.
/routing/bgp/peer/print output examples:

{'.id': '*7',
 'address-families': 'ip',
 'as-override': False,
 'as4-capability': True,
 'default-originate': 'never',
 'disabled': False,
 'established': True,
 'hold-time': '3m',
 'in-filter': 'bgp-in',
 'instance': 'default',
 'local-address': '10.0.0.1',
 'multihop': False,
 'name': 'peer-name',
 'nexthop-choice': 'default',
 'out-filter': 'bgp-out',
 'passive': False,
 'prefix-count': 10,
 'refresh-capability': True,
 'remote-address': '10.0.0.2',
 'remote-as': 65123,
 'remote-hold-time': '4m',
 'remote-id': '10.0.0.1',
 'remove-private-as': True,
 'route-reflect': False,
 'state': 'established',
 'tcp-md5-key': '',
 'ttl': 255,
 'updates-received': 208,
 'updates-sent': 8,
 'uptime': '1w1h1m9s',
 'use-bfd': False,
 'used-hold-time': '3m',
 'used-keepalive-time': '1m',
 'withdrawn-received': 1,
 'withdrawn-sent': 0}
{'.id': '*1',
 'address-families': 'ip',
 'as-override': False,
 'default-originate': 'never',
 'disabled': True,
 'hold-time': '3m',
 'in-filter': '',
 'instance': 'default',
 'multihop': False,
 'name': 'shaper-peer',
 'nexthop-choice': 'default',
 'out-filter': '',
 'passive': False,
 'remote-address': '10.0.0.1',
 'remote-as': 64123,
 'remove-private-as': False,
 'route-reflect': False,
 'tcp-md5-key': '',
 'ttl': 'default',
 'use-bfd': False}
{'.id': '*9',
 'address-families': 'ip',
 'as-override': False,
 'default-originate': 'never',
 'disabled': False,
 'established': False,
 'hold-time': '3m',
 'in-filter': '',
 'instance': 'default',
 'multihop': False,
 'name': 'kubernetes',
 'nexthop-choice': 'default',
 'out-filter': '',
 'passive': False,
 'remote-address': '10.0.0.1',
 'remote-as': 65123,
 'remove-private-as': False,
 'route-reflect': False,
 'state': 'active',
 'tcp-md5-key': '',
 'ttl': 'default',
 'use-bfd': False}

Thx for fixing and reporting.