From 8e3638147dbabead3a520a32fb39e7a57b9cd9e8 Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Thu, 24 Jan 2019 12:27:18 +0100
Subject: [PATCH] basic simulator: workaround: skip first simulation's frames

Due to some unknown bug in the eNB (or UE, or both), the first frames
are not correctly generated (or handled), which leads to a bad behavior
of the simulator in some cases (seen with 100 RBs: the UE reads a bad
MIB and switches to 25 RBs, which results in a deadlock in the
tcp_bridge_oai driver).

Let's "fix" this problem by skipping (in the driver) some frames at the
beginning of the simulation.
---
 targets/ARCH/tcp_bridge/tcp_bridge_oai.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/targets/ARCH/tcp_bridge/tcp_bridge_oai.c b/targets/ARCH/tcp_bridge/tcp_bridge_oai.c
index b0f131de917..a7bb8c00bfa 100644
--- a/targets/ARCH/tcp_bridge/tcp_bridge_oai.c
+++ b/targets/ARCH/tcp_bridge/tcp_bridge_oai.c
@@ -354,6 +354,29 @@ int tcp_bridge_ue_first_read(openair0_device *device, openair0_timestamp *timest
     abort();
   }
 
+  /* Due to some unknown bug in the eNB (or UE, or both), the first frames
+   * are not correctly generated (or handled), which leads to a bad behavior
+   * of the simulator in some cases (seen with 100 RBs: the UE reads a bad
+   * MIB and switches to 25 RBs, which results in a deadlock in this driver).
+   * Let's skip 10 frames to avoid this issue.
+   */
+  for (int i = 0; i < 10 * 10; i++) {
+    memset(b, 0, t->samples_per_subframe * 4);
+    n = fullwrite(t->sock, b, t->samples_per_subframe * 4);
+
+    if (n != t->samples_per_subframe * 4) {
+      printf("tcp_bridge: write error ret %d error %s\n", n, strerror(errno));
+      abort();
+    }
+
+    n = fullread(t->sock, b, t->samples_per_subframe * 4);
+
+    if (n != t->samples_per_subframe * 4) {
+      printf("tcp_bridge: read error ret %d error %s\n", n, strerror(errno));
+      abort();
+    }
+  }
+
   device->trx_read_func = tcp_bridge_read_ue;
   return tcp_bridge_read_ue(device, timestamp, buff, nsamps, cc);
 }
-- 
GitLab