Skip to content
Snippets Groups Projects
Commit e8dd9805 authored by Davis, Duane T's avatar Davis, Duane T Committed by Davis, Duane T
Browse files

LIB: ***DO NOT MERGE INTO MASTER*** Simulated lossy comms added to acs_socket

parent cac94e15
No related branches found
No related tags found
No related merge requests found
Pipeline #1048 failed
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment