summaryrefslogtreecommitdiffstats
path: root/tests/topotests/lib/bmp_collector/bgp/open/__init__.py
blob: e1e6b51f642917bc01a4e80ab6a6a489c4064935 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# SPDX-License-Identifier: ISC

# Copyright 2023 6WIND S.A.
# Authored by Farid Mihoub <farid.mihoub@6wind.com>
#
import ipaddress
import struct


class BGPOpen:
    UNPACK_STR = "!16sHBBHH4sB"

    @classmethod
    def dissect(cls, data):
        (
            marker,
            length,
            open_type,
            version,
            my_as,
            hold_time,
            bgp_id,
            optional_params_len,
        ) = struct.unpack_from(cls.UNPACK_STR, data)

        data = data[struct.calcsize(cls.UNPACK_STR) + optional_params_len :]

        # XXX: parse optional parameters

        return data, {
            "version": version,
            "my_as": my_as,
            "hold_time": hold_time,
            "bgp_id": ipaddress.ip_address(bgp_id),
            "optional_params_len": optional_params_len,
        }