Skip to content

Commit

Permalink
#4964: Modify traffexam to be able to emit LACP data units
Browse files Browse the repository at this point in the history
* Added new traffexam endpoint (/address/<idnr>/lacp)
  • Loading branch information
pkazlenka committed Feb 10, 2023
1 parent 41c0cdd commit 858b771
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
22 changes: 11 additions & 11 deletions src-python/lab-service/traffexam/kilda/traffexam/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ def __call__(self, iface, push_entry):

def _encode(self, entry):
# entry -> b'10011010'
actor_state_binary = functools.reduce(lambda a, b: a + b, map(self._bool_to_byte, [entry.expired,
entry.defaulted,
entry.distributing,
entry.collecting,
entry.synchronization,
entry.aggregation,
entry.lacp_timeout,
entry.lacp_activity]))
actor_state_binary = functools.reduce(lambda a, b: a + b, map(self._bool_to_str, [entry.expired,
entry.defaulted,
entry.distributing,
entry.collecting,
entry.synchronization,
entry.aggregation,
entry.lacp_timeout,
entry.lacp_activity]))
# Kilda ignores everything except lacp actor state. If this changes - expand this method with more fields
return Ether() / SlowProtocol() / lacp.LACP(actor_state=actor_state_binary)
return Ether() / SlowProtocol() / lacp.LACP(actor_state=int(actor_state_binary, 2))

@staticmethod
def _bool_to_byte(boolean):
return b'1' if boolean else b'0'
def _bool_to_str(boolean):
return '1' if boolean else '0'


class ARPPush(Abstract):
Expand Down
20 changes: 10 additions & 10 deletions src-python/lab-service/traffexam/kilda/traffexam/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,16 @@ def __init__(self, mac_address, port_number, chassis_id, ttl, **fields):


class LACPPush(Abstract):
def __init__(self, fields):
super().__init__(**fields)
# self.expired = payload.expired
# self.defaulted = payload.defaulted
# self.distributing = payload.distributing
# self.collecting = payload.collecting
# self.synchronization = payload.synchronization
# self.aggregation = payload.aggregation
# self.lacp_timeout = payload.lacp_timeout
# self.lacp_activity = payload.lacp_activity
def __init__(self, payload):
super().__init__(**{})
self.expired = payload["expired"]
self.defaulted = payload["defaulted"]
self.distributing = payload["distributing"]
self.collecting = payload["collecting"]
self.synchronization = payload["synchronization"]
self.aggregation = payload["aggregation"]
self.lacp_timeout = payload["lacp_timeout"]
self.lacp_activity = payload["lacp_activity"]


class ARPPush(Abstract):
Expand Down
5 changes: 0 additions & 5 deletions src-python/lab-service/traffexam/kilda/traffexam/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,11 @@ def address_emmit_lldp_packet(idnr):
def address_emmit_lacp_packet(idnr):
address = _address_lookup(unpack_idnr(idnr))
payload = bottle.request.json
if payload is None:
payload = {}

try:
push_entry = model.LACPPush(payload)
get_context().action.lacp_push(address.iface, push_entry)
except ValueError as e:
return bottle.HTTPError(400, 'Invalid LACP payload - {}'.format(e))
except Exception as e:
return bottle.HTTPError(500, 'Unexpected error - {}'.format(e))
return {
'lacp_push': {
'sent_packets': 1}}
Expand Down

0 comments on commit 858b771

Please sign in to comment.