diff --git a/ap_lib/src/ap_lib/acs_socket.py b/ap_lib/src/ap_lib/acs_socket.py index eb819562a3f278f4676f10fa02af2faecce62d49..657ba727a18b7cf9c2062cd29644fda6908558f2 100644 --- a/ap_lib/src/ap_lib/acs_socket.py +++ b/ap_lib/src/ap_lib/acs_socket.py @@ -140,7 +140,8 @@ class Socket(): # Mapping IDs to IPs: mapped_ids[id] = ip_address def __init__(self, my_id, udp_port, device=None, my_ip=None, bcast_ip=None, mapped_ids=None, - send_only=False, promisc=False, bcast_bind=False): + send_only=False, promisc=False, bcast_bind=False, + sim_loss_rt=0.5): # Instance variables self._port = udp_port # UDP port for send/recv self._id = my_id # Local entity ID (0..255 currently) @@ -151,6 +152,7 @@ class Socket(): self._sock = None # UDP socket self._sendonly = send_only # Don't bind a port self._promisc = promisc # Receive packets not for me + self._sim_loss_rt = sim_loss_rt # Simulated comms receipt loss rate # Reliability variables self._rel_resend = ReliableResend(self) @@ -322,6 +324,10 @@ class Socket(): # If anything goes wrong below, return False so caller knows # there may be more packets to receive try: + # Simulate dropping packets due to lossy comms + if random.random() <= self._sim_loss_rt: + return False + # Parse message msg = messages.Message.parse(data)