Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-mangin committed Oct 31, 2023
1 parent 099847f commit a46d986
Show file tree
Hide file tree
Showing 46 changed files with 183 additions and 175 deletions.
3 changes: 0 additions & 3 deletions src/exabgp/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import sys
import exabgp.version

if __name__ == '__main__':
from exabgp.application.main import main

Expand Down
1 change: 1 addition & 0 deletions src/exabgp/application/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ def one(checks, state):

checks = 0
state = states.INIT

# Do cleanups on SIGTERM
def sigterm_handler(signum, frame): # pylint: disable=W0612,W0613
exabgp(states.EXIT)
Expand Down
8 changes: 3 additions & 5 deletions src/exabgp/bgp/message/update/attribute/aspath.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# =================================================================== ASPath (2)
# only 2-4% of duplicated data therefore it is not worth to cache


class SET(list):
ID = 0x01
NAME = "as-set"
Expand Down Expand Up @@ -82,10 +83,7 @@ def __init__(self, as_path=[], data=None):

def __eq__(self, other):
return (
self.ID == other.ID
and self.FLAG == other.FLAG
and self.ASN4 == other.ASN4
and self.aspath == other.aspath
self.ID == other.ID and self.FLAG == other.FLAG and self.ASN4 == other.ASN4 and self.aspath == other.aspath
)

def __ne__(self, other):
Expand Down Expand Up @@ -146,7 +144,7 @@ def __repr__(self):
def string(self):
parts = []
for content in self.aspath:
part = "%s %s %s" % (content.HEAD, " ".join((str(_) for _ in content)), content.TAIL)
part = "%s %s %s" % (content.HEAD, " ".join((str(_) for _ in content)), content.TAIL)
parts.append(part)
return " ".join(parts)

Expand Down
10 changes: 7 additions & 3 deletions src/exabgp/bgp/message/update/attribute/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,13 @@ def pack(self, negotiated, with_default=True):
Attribute.CODE.AS_PATH: lambda left, right: ASPath([])
if left == right
else ASPath(
[SEQUENCE([
local_asn,
]),],
[
SEQUENCE(
[
local_asn,
]
),
],
),
Attribute.CODE.LOCAL_PREF: lambda left, right: LocalPreference(100) if left == right else NOTHING,
}
Expand Down
7 changes: 6 additions & 1 deletion src/exabgp/bgp/message/update/attribute/bgpls/linkstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ class GenericLSID(BaseLS):
MERGE = True

def __init__(self, content):
BaseLS.__init__(self, [content, ])
BaseLS.__init__(
self,
[
content,
],
)

def __repr__(self):
return "Attribute with code [ %s ] not implemented" % (self.TLV)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def unpack(cls, data):
if t != 1161:
raise Notify(3, 5, "Invalid sub-TLV type: {}".format(t))
if l == 3:
sids.append([range_size, unpack('!I', bytes([0]) + data[7 : l + 7])[0] & 0xfffff])
sids.append([range_size, unpack('!I', bytes([0]) + data[7 : l + 7])[0] & 0xFFFFF])
elif l == 4:
# XXX: really we are reading 7+ but then re-parsing it again ??
sids.append([range_size, unpack('!I', data[7 : l + 7])[0]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# draft-fm-bess-service-chaining


@ExtendedCommunity.register
class ConsistentHashSortOrder(ExtendedCommunity):
COMMUNITY_TYPE = 0x03
Expand Down
7 changes: 1 addition & 6 deletions src/exabgp/bgp/message/update/attribute/sr/srv6/l2service.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ def pack(self):
length = len(subtlvs_packed) + 1
reserved = 0

return (
pack("!B", self.TLV)
+ pack("!H", length)
+ pack("!B", reserved)
+ subtlvs_packed
)
return pack("!B", self.TLV) + pack("!H", length) + pack("!B", reserved) + subtlvs_packed

def __str__(self):
return "l2-service [ " + ", ".join([str(subtlv) for subtlv in self.subtlvs]) + " ]"
Expand Down
7 changes: 1 addition & 6 deletions src/exabgp/bgp/message/update/attribute/sr/srv6/l3service.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ def pack(self):
length = len(subtlvs_packed) + 1
reserved = 0

return (
pack("!B", self.TLV)
+ pack("!H", length)
+ pack("!B", reserved)
+ subtlvs_packed
)
return pack("!B", self.TLV) + pack("!H", length) + pack("!B", reserved) + subtlvs_packed

def __str__(self):
return "l3-service [ " + ", ".join([str(subtlv) for subtlv in self.subtlvs]) + " ]"
Expand Down
8 changes: 4 additions & 4 deletions src/exabgp/bgp/message/update/nlri/bgpls/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ def __init__(
self.neigh_addrs = neigh_addrs if neigh_addrs else []
self.iface_addrs = iface_addrs if iface_addrs else []
self.link_ids = link_ids if link_ids else []
self.topology_ids = topology_ids if topology_ids else []
self.topology_ids = topology_ids if topology_ids else []
self.nexthop = nexthop
self.route_d = route_d
self._packed = packed

@classmethod
def unpack_nlri(cls, data, rd):
proto_id = unpack('!B', data[0:1])[0]
# FIXME: all these list should probably be defined in the objects
# FIXME: all these list should probably be defined in the objects
iface_addrs = []
neigh_addrs = []
link_identifiers = []
Expand All @@ -105,8 +105,8 @@ def unpack_nlri(cls, data, rd):

while tlvs:
tlv_type, tlv_length = unpack('!HH', tlvs[:4])
value = tlvs[4: 4 + tlv_length]
tlvs = tlvs[4 + tlv_length:]
value = tlvs[4 : 4 + tlv_length]
tlvs = tlvs[4 + tlv_length :]

if tlv_type == 256:
local_node = []
Expand Down
4 changes: 2 additions & 2 deletions src/exabgp/bgp/message/update/nlri/bgpls/prefixv4.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def unpack_nlri(cls, data, rd):

while tlvs:
tlv_type, tlv_length = unpack('!HH', tlvs[:4])
value = tlvs[4: 4 + tlv_length]
tlvs = tlvs[4 + tlv_length:]
value = tlvs[4 : 4 + tlv_length]
tlvs = tlvs[4 + tlv_length :]

if tlv_type == 256:
local_node = []
Expand Down
4 changes: 2 additions & 2 deletions src/exabgp/bgp/message/update/nlri/bgpls/prefixv6.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def unpack_nlri(cls, data, rd):

while tlvs:
tlv_type, tlv_length = unpack('!HH', tlvs[:4])
value = tlvs[4: 4 + tlv_length]
tlvs = tlvs[4 + tlv_length:]
value = tlvs[4 : 4 + tlv_length]
tlvs = tlvs[4 + tlv_length :]

if tlv_type == 256:
local_node = []
Expand Down
17 changes: 9 additions & 8 deletions src/exabgp/bgp/message/update/nlri/bgpls/tlvs/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def unpack(cls, data, igp):
node_type, length = unpack('!HH', data[0:4])
packed = data[: 4 + length]
payload = packed[4:]
remaining = data[4 + length:]
remaining = data[4 + length :]

node_id = None
dr_id = None
Expand Down Expand Up @@ -82,12 +82,11 @@ def unpack(cls, data, igp):
# identifier enables the decoder to determine the node_typee
# of the node: sec 3.2.1.4.
if node_type == 515:

# IS-IS non-pseudonode
if igp in (1, 2):
if length not in (6, 7):
raise Exception(cls._error_tlvs[node_type])
node_id = ISO.unpack_sysid(payload),
node_id = (ISO.unpack_sysid(payload),)
if length == 7:
psn = unpack('!B', payload[6:7])[0]
return cls(node_id, node_type, psn, dr_id, packed), remaining
Expand All @@ -96,15 +95,17 @@ def unpack(cls, data, igp):
if igp in (3, 5, 6, 227):
if length not in (4, 8):
raise Exception(cls._error_tlvs[node_type])
node_id = IP.unpack(payload[:4]),
node_id = (IP.unpack(payload[:4]),)
if length == 8:
dr_id = IP.unpack(payload[4:8])
return cls(node_id, node_type, psn, dr_id, packed), remaining

raise Exception("unknown node descriptor sub-tlv ({}, {})".format(
f'node-type: {node_type}',
f'igp: {igp}',
))
raise Exception(
"unknown node descriptor sub-tlv ({}, {})".format(
f'node-type: {node_type}',
f'igp: {igp}',
)
)

def json(self, compact=None):
node = None
Expand Down
3 changes: 2 additions & 1 deletion src/exabgp/bgp/message/update/nlri/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def short(self):
def __str__(self):
return self.short()


# Components ..............................


Expand Down Expand Up @@ -603,7 +604,7 @@ def _rules(self):
if idx and not rule.operations & NumericOperator.AND:
r_str.append(' ')
# ugly hack as dynamic languages are what they are and use used __str__ in the past
r_str.append(rule.short() if hasattr(rule,'short') else str(rule))
r_str.append(rule.short() if hasattr(rule, 'short') else str(rule))
line = ''.join(r_str)
if len(r_str) > 1:
line = '[ %s ]' % line
Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/bgp/message/update/nlri/mup/dsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def unpack(cls, data, afi):
size = data_len - 8
if not size in [4, 16]:
raise Notify(3, 5, "Invalid IP size, expect 4 or 16 octets. accuracy size %d" % size)
ip = IP.unpack(data[8: 8 + size])
ip = IP.unpack(data[8 : 8 + size])

return cls(rd, ip, afi)

Expand Down
6 changes: 3 additions & 3 deletions src/exabgp/bgp/message/update/nlri/mup/nlri.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ def unpack_nlri(cls, afi, safi, bgp, action, addpath):
end = length + 4
key = "%s:%s" % (arch, code)
if key in cls.registered:
klass = cls.registered[key].unpack(bgp[4 : end], afi)
klass = cls.registered[key].unpack(bgp[4:end], afi)
else:
klass = GenericMUP(arch, afi, code, bgp[4 : end])
klass = GenericMUP(arch, afi, code, bgp[4:end])
klass.CODE = code
klass.action = action
klass.addpath = addpath

return klass, bgp[end :]
return klass, bgp[end:]

def _raw(self):
return ''.join('%02X' % _ for _ in self.pack_nlri())
Expand Down
10 changes: 3 additions & 7 deletions src/exabgp/bgp/message/update/nlri/mup/t1st.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ def __str__(self):

def pack_index(self):
# removed teid, qfi, endpointip
packed = (
self.rd.pack()
+ pack('!B',self.ipprefix_len)
+ self.ipprefix.pack()
)
packed = self.rd.pack() + pack('!B', self.ipprefix_len) + self.ipprefix.pack()
return pack('!BHB', self.ARCHTYPE, self.CODE, len(packed)) + packed

def index(self):
Expand Down Expand Up @@ -154,7 +150,7 @@ def unpack(cls, data, afi):
if ip_remainder != 0:
ip_offset += 1

ip = data[9: 9 + ip_offset]
ip = data[9 : 9 + ip_offset]
ip_size = 4 if afi != AFI.ipv6 else 16
ip_padding = ip_size - ip_offset
if ip_padding != 0 and 0 < ip_padding:
Expand All @@ -163,7 +159,7 @@ def unpack(cls, data, afi):
size = ip_offset
ipprefix = IP.unpack(ip)
size += 9
teid = int.from_bytes(data[size: size + 4], "big")
teid = int.from_bytes(data[size : size + 4], "big")
size += 4
qfi = data[size]
size += 1
Expand Down
6 changes: 3 additions & 3 deletions src/exabgp/bgp/message/update/nlri/mup/t2st.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _pack(self, packed=None):
self._packed = packed
return packed

teid_packed = pack('!I',self.teid)
teid_packed = pack('!I', self.teid)
offset = self.teid_len // 8
remainder = self.teid_len % 8
if remainder != 0:
Expand All @@ -118,10 +118,10 @@ def unpack(cls, data, afi):
if not (0 <= teid_len <= 32):
raise Exception("teid len is %d, but len range 0 ~ 32" % teid_len)

endpoint_ip = IP.unpack(data[9: 9 + size])
endpoint_ip = IP.unpack(data[9 : 9 + size])
size += 9
if 0 < teid_len:
teid = int.from_bytes(data[size: ], "big")
teid = int.from_bytes(data[size:], "big")
else:
teid = 0
return cls(rd, endpoint_ip_len, endpoint_ip, teid, teid_len, afi)
Expand Down
1 change: 0 additions & 1 deletion src/exabgp/bgp/message/update/nlri/rtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def pack_nlri(self, negotiated=None):

@classmethod
def unpack_nlri(cls, afi, safi, bgp, action, addpath):

length = bgp[0]

if length == 0:
Expand Down
1 change: 0 additions & 1 deletion src/exabgp/bgp/message/update/nlri/vpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def _unique():

@NLRI.register(AFI.l2vpn, SAFI.vpls)
class VPLS(NLRI):

# XXX: Should take AFI, SAFI and OUT.direction as parameter to match other NLRI
def __init__(self, rd, endpoint, base, offset, size):
NLRI.__init__(self, AFI.l2vpn, SAFI.vpls)
Expand Down
2 changes: 1 addition & 1 deletion src/exabgp/bgp/neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def remove_self(self, changes):
neighbor_self = self.ip_self(change.nlri.afi)
change.nlri.nexthop = neighbor_self
if Attribute.CODE.NEXT_HOP in change.attributes:
change.attributes[Attribute.CODE.NEXT_HOP] = NextHop(str(neighbor_self),neighbor_self.pack())
change.attributes[Attribute.CODE.NEXT_HOP] = NextHop(str(neighbor_self), neighbor_self.pack())
return change

def __str__(self):
Expand Down
3 changes: 3 additions & 0 deletions src/exabgp/configuration/announce/mup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def post(self):
def check(self):
return True


def mup(tokeniser, afi, safi):
muptype = tokeniser()
if "mup-isd" == muptype:
Expand Down Expand Up @@ -112,10 +113,12 @@ def mup(tokeniser, afi, safi):

return [change]


@ParseAnnounce.register('mup', 'extend-name', 'ipv4')
def mup_ip_v4(tokeniser):
return mup(tokeniser, AFI.ipv4, SAFI.mup)


@ParseAnnounce.register('mup', 'extend-name', 'ipv6')
def mup_ip_v6(tokeniser):
return mup(tokeniser, AFI.ipv6, SAFI.mup)
2 changes: 2 additions & 0 deletions src/exabgp/configuration/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def display_message(neighbor, message):
print("unknown type %d", kind)
return False


# =================================================================== check_nlri
#

Expand Down Expand Up @@ -281,6 +282,7 @@ def display_nlri(neighbor, routes):
print(nlri.json())
return True


# =================================================================== check_open
#

Expand Down
Loading

0 comments on commit a46d986

Please sign in to comment.