CAIDA / pybgpstream

Python bindings for BGPStream
https://bgpstream.caida.org
BSD 2-Clause "Simplified" License
29 stars 23 forks source link

extract origin from as-path #42

Closed hhaootian closed 3 years ago

hhaootian commented 3 years ago

Based on the tutorial, we can extract origin as:

ases = elem.fields["as-path"].split(" ")
origin = ases[-1]

However, I'm seeing some cases that we might extract wrong origin, for example: rib|R|1617098401.000000|routeviews|route-views.sydney|None|None|4739|45.127.172.20|37.142.0.0/17|45.127.172.20|4739 7545 6453 12849 {12849,21450}|4739:0|None|None

This also happens in 'updates' record type. update|A|1617098751.000000|routeviews|route-views.sydney|None|None|58511|45.127.172.149|94.131.240.0/20|45.127.172.149|58511 44600 {6939,29491,35297,49720}|58511:200 58511:9007|None|None

Using the origin extraction shown above, we would get {12849,21450} and {6939,29491,35297,49720}.

Codes to duplicate this error:

stream = pybgpstream.BGPStream(
    from_time = "2021-03-30 10:00:00", until_time = "2021-03-30 10:30:00 UTC",
    collectors = ["route-views.sydney"],
    record_type = "ribs"
)

for rec in stream.records():
    for elem in rec:
        ases = elem.fields['as-path'].split(" ")
        if len(ases) > 0:
            origin = ases[-1]
            if "{" in origin:
                print(elem)
realdah commented 3 years ago

Hi tian, I found this online, and also replied in canvas. https://github.com/CAIDA/bgpstream/issues/12