Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

BIRD output not parsed #12

Closed
timrabl opened this issue Dec 17, 2020 · 1 comment
Closed

BIRD output not parsed #12

timrabl opened this issue Dec 17, 2020 · 1 comment

Comments

@timrabl
Copy link

timrabl commented Dec 17, 2020

In the course of today's hyperglass installation, the following error occurred when querying any BGP route of the BIRD router:

The query completed, but no results were found.

System environment

Hyperglass operating system: Docker container with alpine Linux Version 3.9
Hyperglass version: 1.0.0b64
Hyperglass python version: 3.6.12

Hyperglass-agent operating system: Ubuntu Linux 18.04 (Bionic Beaver)
Hyperglass-agent version: 0.1.6
Hyperglass-agent python version: 3.6.12
BIRD Version: 1.6.3

Setup

The queries are sent from the Hyperglass (installed in a Docker Container) encrypted to the hyperglass agent installed on a BIRD router / Ubuntu Linux 18.04 (Bionic Beaver). The connection between hyperglass and hyperglass-agent is established and working (ping and traceroute are working).

After a bit of reading code, I think I found the error in nos_utils/bird.py

Assuming the bird output generated with birdc "show route all where 8.8.8.0/24 ~ net like the following, the parse_bird_output() in bird.py mentioned above returns an empty newline.

BIRD data:

BIRD 1.6.3 ready.
0.0.0.0/0          via 1.2.3.4 on wan [router01 00:00:00 from 1.2.3.4] * (100/?) [i]
    Type: BGP unicast univ
    BGP.origin: IGP
    BGP.as_path:
    BGP.next_hop: 1.2.3.4
    BGP.local_pref: 100
                via 1.2.3.4 on wan [router02 00:00:00 from 1.2.3.4] (100/?) [i]
    Type: BGP unicast univ
    BGP.origin: IGP
    BGP.as_path:
    BGP.next_hop: 1.2.3.4
    BGP.local_pref: 100

Local test script:

Tested the parse_bird_output() locally, with the following:

#!/usr/bin/env python3

data: str = """BIRD 1.6.3 ready.
0.0.0.0/0          via 1.2.3.4 on wan [router01 00:00:00 from 1.2.3.4] * (100/?) [i]
    Type: BGP unicast univ
    BGP.origin: IGP
    BGP.as_path:
    BGP.next_hop: 1.2.3.4
    BGP.local_pref: 100
                via 1.2.3.4 on wan [router02 00:00:00 from 1.2.3.4] (100/?) [i]
    Type: BGP unicast univ
    BGP.origin: IGP
    BGP.as_path:
    BGP.next_hop: 1.2.3.4
    BGP.local_pref: 100
"""

def parse_bird_output(raw):
    """Parse raw BIRD output and return parsed output.
    Arguments:
        raw {str} -- Raw BIRD output
        query_data {object} -- Validated query object
        not_found {str} -- Lookup not found message template
    Returns:
        str -- Parsed output
    """

    def remove_ready(lines):
        for line in lines:
            if not re.match(r".*(BIRD \d+\.\d+\.?\d* ready\.).*", line):
                yield line.strip()

    raw_split = re.split(r"(Table)", raw.strip())

    if not raw_split:
        lines = 'Not found !'
    else:
        lines = raw_split

    output = "\n".join(remove_ready(lines))
    return output

print(*parse_bird_output(data))

Log output:

2020-12-17 18:19:21.793 | DEBUG    | hyperglass_agent.execute:run_query:40 - Query: query_type='bgp_route' vrf='default' afi='ipv4_default' source=IPv4Address('1.2.3.4') target='8.8.8.0/24'
2020-12-17 18:19:21.794 | DEBUG    | hyperglass_agent.execute:run_query:55 - Formatted Command: birdc "show route all where 8.8.8.0/24 ~ net"
2020-12-17 18:19:22.674 | DEBUG    | hyperglass_agent.execute:run_query:70 - Parser: parse_bird_output
2020-12-17 18:19:22.677 | DEBUG    | hyperglass_agent.nos_utils.bird:parse_bird_output:87 - Parsed output:

2020-12-17 18:19:22.679 | DEBUG    | hyperglass_agent.api.web:query_entrypoint:98 - Query Output:
@thatmattlove
Copy link
Owner

Hi there,

Really sorry for not responding to this sooner.

Starting in hyperglass v1.0.0-beta.76, I've started deprecating hyperglass-agent. Moving forward, FRR & BIRD can be interacted with in the same manner as any other device, i.e. via SSH. See here for details/caveats). Everything will still work as-is for now, but I'd encourage you to try moving to frr_ssh/bird_ssh as the nos (and of course, let me know of any problems via a new hyperglass issue).

I'm going to go ahead and close this issue out.

Thanks,
Matt

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants