From e8dd9805266e211fc39570856b464b6f4fd41913 Mon Sep 17 00:00:00 2001
From: "Davis, Duane T" <dtdavi1@nps.edu>
Date: Wed, 16 Nov 2016 15:36:00 -0800
Subject: [PATCH] LIB: ***DO NOT MERGE INTO MASTER*** Simulated lossy comms
 added to acs_socket

---
 ap_lib/src/ap_lib/acs_socket.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/ap_lib/src/ap_lib/acs_socket.py b/ap_lib/src/ap_lib/acs_socket.py
index eb81956..657ba72 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)
 
-- 
GitLab