-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement software version capability for BGP
https://datatracker.ietf.org/doc/html/draft-abraitis-bgp-version-capability This is already implemented by FRR, GoBGP, freertr, Wireshark, some more. E.g.: ``` $ vtysh -c 'show bgp neighbor 127.0.0.1 json' | jq '."127.0.0.1".neighborCapabilities.softwareVersion' { "advertisedSoftwareVersion": "FRRouting/10.2-dev-MyOwnFRRVersion-g8ca262943f", "receivedSoftwareVersion": "ExaBGP/feature/bgp_software_version_capability-e510e8c6b4d6c8651" } ``` Signed-off-by: Donatas Abraitis <[email protected]>
- Loading branch information
Showing
7 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/exabgp/bgp/message/open/capability/software_version.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# encoding: utf-8 | ||
""" | ||
software_version.py | ||
Copyright (c) 2024 Donatas Abraitis. All rights reserved. | ||
License: 3-clause BSD. (See the COPYRIGHT file) | ||
""" | ||
|
||
# https://datatracker.ietf.org/doc/html/draft-abraitis-bgp-version-capability | ||
|
||
|
||
from exabgp.bgp.message.open.capability.capability import Capability | ||
from exabgp.version import version | ||
|
||
|
||
@Capability.register() | ||
class SoftwareVersion(Capability): | ||
ID = Capability.CODE.SOFTRWARE_VERSION | ||
SOFTWARE_VERSION_MAX_LEN = 64 | ||
|
||
def __init__(self): | ||
self.software_version = f"ExaBGP/{version}" | ||
|
||
def __str__(self): | ||
return f'SoftwareVersion({self.software_version})' | ||
|
||
def json(self): | ||
return f'{ "software-version": "{self.software_version}" }' | ||
|
||
def extract(self): | ||
software_version = self.software_version.encode('utf-8') | ||
if len(software_version) > self.SOFTWARE_VERSION_MAX_LEN: | ||
software_version = software_version[: self.SOFTWARE_VERSION_MAX_LEN] | ||
return [bytes([len(software_version)]) + software_version] | ||
|
||
@staticmethod | ||
def unpack_capability(instance, data, capability=None): # pylint: disable=W0613 | ||
l1 = data[0] | ||
instance.software_version = data[1 : l1 + 1].decode('utf-8') | ||
return instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters