From 70bcf103dac32f838b8160995df21039c5943bd9 Mon Sep 17 00:00:00 2001 From: Joseph <162703152+josephnef@users.noreply.github.com> Date: Tue, 10 Nov 2026 11:00:24 +0300 Subject: [PATCH 1/2] =?UTF-8?q?cell=20M6:=20DAPS=20across=20channels=20?= =?UTF-8?q?=E2=80=94=20sequential=20uplink=20visits=20to=20the=20target's?= =?UTF-8?q?=20channel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Uplink DAPS needs the target to hear the UE's source identity, which it cannot on another channel: with the source killed mid-handover, every uplink from the kill to the switch was lost. - UE (CELL_UE_DAPS_VISIT [1]): between accepting an inter-frequency handover and its switch, the UE visits the target's channel once a superframe, in its idle time after its uplink slot. It airs a copy of its uplink beacon clear of the target's active span, holds 4 ms (send_packet only queues), and retunes back. The loop runs every 30 ms in that window. - F1 v14: Uplink carries its reception instant (net_us). The CU maps a copy heard by another cell's DU to the UE's last own uplink slot (Handover.h ul_seq_for_copy) from the source's phase and the UE's position, so a visit dedups with the source's copy. - The switch clears the TSF step hold. A hold set before it counts in the source's superframes: a visit just before the switch left the uplink 40 ms off for 9 superframes, and the target's TA loop took ~12 s to settle. - DUs log each forwarded other-identity copy (cell.daps.fwd); the CU logs each mapped copy (ran.ul_copy). Rig (testrig m6_daps_xch.sh, 2 runs per case, all pass), source killed at the accept: - with visits, 0 uplinks lost before the switch (no visits: 13); - 2 lost at the switch itself; - without a fault, the visits cost the source nothing. The measgap, same-channel DAPS, handover and three-cell crossing runs pass. Co-Authored-By: Claude Opus 5.5 (1M context) --- docs/cell-m6.md | 75 ++++++++++++++++++-- examples/cell/main.cpp | 127 ++++++++++++++++++++++++++++++++-- src/cell/F1.h | 9 ++- src/cell/Handover.h | 15 ++++ tests/cell_m6_selftest.cpp | 18 ++++- tools/ran-controller/main.cpp | 20 ++++++ 6 files changed, 251 insertions(+), 13 deletions(-) diff --git a/docs/cell-m6.md b/docs/cell-m6.md index 15941dba..0702e0ff 100644 --- a/docs/cell-m6.md +++ b/docs/cell-m6.md @@ -1175,6 +1175,74 @@ ramps, the A3 at its defaults, there and back: two handovers per run). - **Not duplicated:** the source does not keep airing to the UE after the switch, and the UE takes DL frames only from its serving cell. +## DAPS across channels (sequential, uplink) + +Uplink DAPS needs the target DU to hear the UE's uplink under its source +identity. Across channels it cannot: the UE has one radio, tuned to the +source. With the source killed mid-handover, every uplink from the kill to +the switch was lost (the three-cell crossing: 12–14). + +**The visit** (`examples/cell`, `CELL_UE_DAPS_VISIT` [1]): +- **When:** between accepting an inter-frequency handover and its switch, + the UE visits the target's channel once a superframe, through the one + before the switch. +- **What it does:** after its own uplink slot, it retunes to the target's + channel and airs a copy of its uplink beacon there, at an instant clear of + the target cell's active span. It then retunes back before its serving + beacon. +- **The window:** it is the idle part of the UE's own grid, so the source + link loses nothing. Its own hardware beacon fires at its uplink slot, + outside the window. +- **Holding the channel:** `send_packet` only queues the frame, so the UE + holds the target channel 4 ms after queuing it. There is no per-frame TX + report on Kestrel; without the hold, 9 of 10 copies were lost. +- **Loop cadence:** during the window the UE loop runs every 30 ms, not + 100 ms, so the next superframe's visit is in reach after one ends + ~75 ms into its superframe. + +**Its sequence number at the CU** (F1 v14): +- The target DU forwards the copy as before (`daps_ids`, area tag), now with + its reception instant on the network timebase (`Uplink.net_us`). +- A copy heard by another cell's DU is mapped by the CU to the UE's last + own uplink slot at or before it (`Handover.h` `ul_seq_for_copy`), using + the source cell's phase and the UE's uplink position from the source's + report. +- The visit, sent ~30 ms after the slot and possibly in the next network + superframe, therefore dedups with the source's copy of the same uplink. + The UE needs no global clock. + +**The switch clears the TSF step hold.** A hold set after a gap or a visit +counts in the source's superframes. A visit just before the switch carried +it ~9 superframes into the target's count, so the UE's uplink stayed 40 ms +off. The target's TA loop took that for propagation delay, and it took +~12 s to settle. + +**Rig result** (testrig `scripts/m6_daps_xch.sh`): 2 runs per case, all pass. Cell 1 is on ch149 and cell 2 on ch157 (phase +60000); the A3 at its defaults hands UE1 over 1 → 2, with the CU's DL +stream on. + +| uplinks missing at the CU around the switch | before the switch | at the switch | +|---|---|---| +| source killed at the accept, visits | **0, 0** | 2, 2 | +| source killed at the accept, no visits | 13, 13 | 2, 2 | +| no fault, visits | 0, 0 | 1, 1 | + +- **20–21 visits per handover**, every one sent and back; deaf time + 55.6–57.2 ms each. +- **They cost the source nothing:** without a fault, DU1 heard UE1's uplink + in every superframe from the accept to the switch, in slot 100 %. +- **The switch's own cost:** the switch superframe (with the source dead, + nobody hears it) and the next. The first uplink after the UE's beacon + restart on the target is lost, as after a suspend gap; why is not + established. +- **Every run:** the target heard the UE in slot 99.9 %, and DL DAPS lost no + PDU. +- **What the first runs found:** besides the TX hold, the loop cadence and + the step hold (above), visits stopping two superframes before the switch + left those two uncovered. +- **Regression:** the inter-frequency measurement-gap handover, same-channel + DAPS, the plain and fault handovers and the three-cell crossing pass. + ## Replay of a signed neighbour list A signature proves who wrote a beacon, not when it was aired, so the @@ -1313,10 +1381,9 @@ replay checks caught it in the signed-list run: UE2 reported cell 1 in only ## Not covered yet -- **DAPS beyond same channel:** the different-channel (sequential) - variant, with its retune and deaf-time budget. The downlink is duplicated - through the target's buffer, but not received from both DUs at once (see - the downlink duplication section). +- **DAPS across channels, receiving:** the uplink is duplicated + sequentially (visits) and the downlink through the target's buffer. The + UE never receives the target's DL before the switch. - **More than three cells, and a full tour:** the rig runs three cells, with handovers among them and a UE crossing 1 → 2 → 3. The way back into cell 1 is out of reach of the DUs' 20 dB TX range on this rig. Re-phasing diff --git a/examples/cell/main.cpp b/examples/cell/main.cpp index ced31dbf..234eac12 100644 --- a/examples/cell/main.cpp +++ b/examples/cell/main.cpp @@ -107,6 +107,12 @@ // the superframe after. Decided at the UEs' // floor gap bound CELL_UE_GAP_RETUNE_US [26000] / // CELL_UE_GAP_GUARD_US [2000], read by the DU too. +// CELL_UE_DAPS_VISIT [1] UE: between accepting an INTER-FREQUENCY handover +// and its switch, visit the target's channel once a +// superframe (after its uplink slot, in its idle +// time) to air a copy of its uplink there: the +// target DU forwards it to the CU (sequential DAPS; +// cell.ue.daps_visit) // CELL_SECS [60] run time // DU service mode (M4, #258) — set CELL_REF_PTP to hold this DU's beacon grid // to a PTP hardware clock (src/cell/TsfDiscipline.h; needs a Tight sync tier, @@ -1312,8 +1318,8 @@ int run_du(IRadio *dev, const Cfg &c) { u.du = c.cell; u.cell = cell; u.ue = ue; - u.seq = devourer::cell::ul_seq_from_network_time( - *at + static_cast(dc.phase_us) + net_off.load() * P, P); + u.net_us = *at + static_cast(dc.phase_us) + net_off.load() * P; + u.seq = devourer::cell::ul_seq_from_network_time(u.net_us, P); u.rssi_dbm = static_cast(static_cast(p.RxAtrib.rssi[0]) - 110); send_f1(devourer::cell::f1::encode_uplink(u, f1_mac)); }; @@ -1406,8 +1412,13 @@ int run_du(IRadio *dev, const Cfg &c) { static_cast(p.RxAtrib.snr[0]) / 2.0 /* raw dB*2 */, now_ms()); fwd = daps_on && daps_ids.count({oc, ou}) > 0; } - if (fwd) + if (fwd) { forward_ul(oc, ou, p); + char l[140]; + snprintf(l, sizeof l, "{\"ev\":\"cell.daps.fwd\",\"cell\":%u,\"ue\":%u,\"rssi\":%d}", oc, ou, + static_cast(p.RxAtrib.rssi[0]) - 110); + emit(l); + } return; } } @@ -2806,6 +2817,10 @@ int run_ue(IRadio *dev, const Cfg &c) { /* Suspend gaps (MeasGap.h): one in this many superframes (0 = off); the DU * must run the same value (it skips this UE's DL then). */ const int64_t gap_suspend_every = envl("CELL_GAP_SUSPEND_SF", 0, 0, 100000); + /* DAPS across channels (sequential): between accepting an inter-frequency + * handover and its switch, visit the target's channel once a superframe to + * air a copy of the uplink there (the target DU forwards it to the CU). */ + const bool daps_visit = envl("CELL_UE_DAPS_VISIT", 1, 0, 1) != 0; const int64_t mr_every_ms = envl("CELL_UE_MR_MS", 1000, 100, 60000); auto ue_ms = [] { return std::chrono::duration_cast( @@ -3123,9 +3138,15 @@ int run_ue(IRadio *dev, const Cfg &c) { int64_t last_susp_sf = -1; bool susp_infeasible = false; bool had_susp_prev = false; /* last pass had neighbours only a suspend gap reaches */ + std::vector last_bcn; /* the uplink beacon frame on air (for DAPS visits) */ + int64_t last_visit_sf = -1; + uint64_t visits = 0, visits_ok = 0; uint64_t susp_gaps = 0, susp_heard = 0, susp_fail = 0; while (std::chrono::steady_clock::now() < deadline) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + /* A DAPS-visit window: passes 30 ms apart, so the next superframe's + * visit is in reach after one ends ~75 ms into its superframe. */ + const bool visiting = daps_visit && ho_pending && ho_pending->channel != 0 && ho_pending->channel != cur_ch; + std::this_thread::sleep_for(std::chrono::milliseconds(visiting ? 30 : 100)); uint64_t t = 0, f = 0; if (!dev->ReadTsfAndFreeRun(t, f)) continue; @@ -3236,6 +3257,12 @@ int run_ue(IRadio *dev, const Cfg &c) { nbrs.clear(); /* the new serving cell airs its own list */ have_serv_phase = false; /* another serving grid */ serv_switched = true; + /* A hold set before the switch (after a gap or a DAPS visit) is on + * the source's superframe count: never carried into the target's — + * the switch must place the uplink at once (a held step left it + * 40 ms off for 9 superframes, and the target's TA loop took that + * for delay). */ + no_step_until_sf = -1; serv_off_run = 0; have_nbrs_gen = false; gap_parked.clear(); @@ -3604,6 +3631,8 @@ int run_ue(IRadio *dev, const Cfg &c) { } const bool ok = beaconing ? dev->UpdateBeaconPayload(b.data(), b.size()) : dev->StartBeacon(b.data(), b.size(), c.tu); + if (ok) + last_bcn = b; if (!ok) { fprintf(stderr, "UE beacon %s failed\n", beaconing ? "update" : "start"); continue; @@ -3772,6 +3801,89 @@ int run_ue(IRadio *dev, const Cfg &c) { } return true; }; + /* A sequential-DAPS visit (inter-frequency handover staged, before its + * switch): in superframe S, after this UE's uplink slot, retune to the + * target's channel, air a copy of the uplink beacon at an instant clear of + * the target cell's active span, and retune back before the serving + * beacon. Its own beacon fires at its uplink slot, outside the window. */ + if (daps_visit && ho_pending && ho_pending->channel != 0 && ho_pending->channel != cur_ch && + beaconing && !last_bcn.empty() && grid && g) { + const int64_t sfn = du_now / P; + const auto &sl = grid->slots(); + const int64_t ul_end = sl[g->ul_slot].start_us + sl[g->ul_slot].len_us; + int64_t span = 0; /* the grid's active span (the target runs the same grid) */ + for (const auto &x : sl) + span = std::max(span, x.start_us + x.len_us); + const int64_t o_t = ((-ho_pending->tsf_delta_us) % P + P) % P; /* the target's TBTT here */ + /* send_packet only queues: the copy is given kVisitHoldUs on the target's + * channel to leave (no per-frame TX report on Kestrel) before the + * retune back — else it is flushed, or aired late on the wrong one. */ + constexpr int64_t kVisitHoldUs = 4000; + const int64_t lo = ul_end + gap_guard_us + gap_retune_us, + hi = P - gap_guard_us - gap_retune_us - kVisitHoldUs - 1000; + auto in_target = [&](int64_t v) { + const int64_t d = ((v - o_t) % P + P) % P; + return d < span + 1000 || d > P - 1000; + }; + std::optional v; + for (int64_t x = lo; x <= hi && !v; x += 500) + if (!in_target(x)) + v = x; + const auto now_du = serving_now(); + for (const int64_t S : {sfn, sfn + 1}) { + if (!v || !now_du || S <= last_visit_sf || + static_cast(S) >= ho_pending->effective_sf) /* through the one before the switch */ + continue; + const int64_t go = S * P + *v - gap_retune_us - gap_guard_us; /* leave the serving channel */ + if (go - *now_du <= 1000 || go - *now_du >= 2 * P) + continue; + last_visit_sf = S; + std::this_thread::sleep_for(std::chrono::microseconds(go - *now_du)); + const auto g0 = std::chrono::steady_clock::now(); + bool out_ok = true, sent = false; + try { + dev->FastRetune(ho_pending->channel); + } catch (const std::exception &) { + out_ok = false; + } + const auto g1 = std::chrono::steady_clock::now(); + if (out_ok) { + if (const auto t_now = serving_now(); t_now && *t_now < S * P + *v) + std::this_thread::sleep_for(std::chrono::microseconds(S * P + *v - *t_now)); + auto pkt = build_dl_radiotap(6); + pkt.insert(pkt.end(), last_bcn.begin(), last_bcn.end()); + sent = dev->send_packet(pkt.data(), pkt.size()); + std::this_thread::sleep_for(std::chrono::microseconds(kVisitHoldUs)); + } + bool back_ok = false; + for (int k = 0; k < 3 && !back_ok; ++k) { + try { + dev->FastRetune(cur_ch); + back_ok = true; + } catch (const std::exception &) { + } + } + const auto g2 = std::chrono::steady_clock::now(); + if (!back_ok) { + if (beaconing && dev->StopBeacon()) + beaconing = false; + retune_to = cur_ch; + } + no_step_until_sf = S + 4; /* as after a gap */ + ++visits; + visits_ok += out_ok && back_ok && sent ? 1 : 0; + char l[260]; + snprintf(l, sizeof l, + "{\"ev\":\"cell.ue.daps_visit\",\"ue\":%d,\"sf\":%lld,\"at_us\":%lld,\"ch\":%u," + "\"sent\":%d,\"out_us\":%lld,\"deaf_us\":%lld,\"ok\":%d}", + me, (long long)S, (long long)*v, ho_pending->channel, sent ? 1 : 0, + (long long)std::chrono::duration_cast(g1 - g0).count(), + (long long)std::chrono::duration_cast(g2 - g0).count(), + out_ok && back_ok ? 1 : 0); + emit(l); + break; + } + } if ((gap_every_sf > 0 || gap_suspend_every > 0) && !ho_pending && !ho_back) { std::vector other, susp; const int64_t sfn = du_now / P; @@ -3925,14 +4037,14 @@ int run_ue(IRadio *dev, const Cfg &c) { dev->StopRxLoop(); rx.join(); dev->ClearAckResponder(); - char l[640]; + char l[700]; snprintf(l, sizeof l, "{\"ev\":\"cell.ue.done\",\"ue\":%u,\"steps\":%ld,\"step_fails\":%ld," "\"listen_from_sf\":%lld,\"listen_to_sf\":%lld,\"dl_new\":%llu,\"dl_dup\":%llu," "\"keyed\":%d,\"gm_ok\":%llu,\"gm_refused\":%llu,\"nbr_refused\":{\"stale\":%llu," "\"unlisted\":%llu,\"phase\":%llu},\"dl_pdus\":{\"delivered\":%llu,\"duplicates\":%llu," "\"missing\":%llu,\"stale\":%llu,\"top\":%lld},\"suspend_gaps\":{\"n\":%llu,\"heard\":%llu," - "\"fail\":%llu}}", + "\"fail\":%llu},\"daps_visits\":{\"n\":%llu,\"ok\":%llu}}", me_a.load(), steps, step_fails, (long long)listen_from, (long long)listen_to, (unsigned long long)dl_new, (unsigned long long)dl_dup, auth ? 1 : 0, (unsigned long long)gm_ok, (unsigned long long)gm_refused, @@ -3941,7 +4053,8 @@ int run_ue(IRadio *dev, const Cfg &c) { (unsigned long long)dl_stream.duplicates(), (unsigned long long)dl_stream.missing_total(), (unsigned long long)dl_stream.stale(), dl_stream.top() ? (long long)*dl_stream.top() : -1LL, (unsigned long long)susp_gaps, - (unsigned long long)susp_heard, (unsigned long long)susp_fail); + (unsigned long long)susp_heard, (unsigned long long)susp_fail, (unsigned long long)visits, + (unsigned long long)visits_ok); emit(l); return 0; } diff --git a/src/cell/F1.h b/src/cell/F1.h index 74b2004a..2699d8fa 100644 --- a/src/cell/F1.h +++ b/src/cell/F1.h @@ -79,7 +79,8 @@ namespace devourer::cell::f1 { * Report with phase_us < 0 asks for one. */ /* 12: Downlink (CU -> DU, the CU's DL PDUs; DAPS duplicates them). 13: * Report carries the DU's suspend-gap period. */ -constexpr uint8_t kVersion = 13; /* v13: Report.gap_suspend_sf */ +/* 14: Uplink carries its reception instant (net_us). */ +constexpr uint8_t kVersion = 14; /* v14: Uplink.net_us */ constexpr size_t kTagLen = 8; constexpr size_t kMaxFixed = 8; constexpr size_t kMaxPositions = kMaxUesPerCell; @@ -624,6 +625,10 @@ struct UplinkFwd { uint16_t du = 0; uint16_t cell = 0, ue = 0; uint32_t seq = 0; + /* The reception instant on the network timebase (us): the CU maps a copy + * heard by another cell's DU to the UE's own uplink slot (Handover.h + * ul_seq_for_copy) — a sequential-DAPS visit sends it later. */ + int64_t net_us = 0; int8_t rssi_dbm = 0; bool operator==(const UplinkFwd &) const = default; }; @@ -635,6 +640,7 @@ inline std::vector encode_uplink(const UplinkFwd &u, const Mac &mac) { put(m, u.cell, 2); put(m, u.ue, 2); put(m, u.seq, 4); + put(m, static_cast(u.net_us), 8); m.push_back(static_cast(u.rssi_dbm)); return seal(std::move(m), mac); } @@ -650,6 +656,7 @@ inline std::optional decode_uplink(const uint8_t *p, size_t n, const u.cell = static_cast(r.get(2)); u.ue = static_cast(r.get(2)); u.seq = static_cast(r.get(4)); + u.net_us = static_cast(r.get(8)); u.rssi_dbm = static_cast(r.get(1)); if (!r.ok || r.i != r.n) return std::nullopt; diff --git a/src/cell/Handover.h b/src/cell/Handover.h index 0cb8d353..3b74aa7a 100644 --- a/src/cell/Handover.h +++ b/src/cell/Handover.h @@ -455,6 +455,21 @@ inline uint32_t ul_seq_from_network_time(int64_t t_net_us, int64_t period_us) { return static_cast(t_net_us / period_us); } +/* DAPS across channels: a copy of a UE's uplink heard by ANOTHER cell's DU + * may have been sent later in the superframe (a sequential-DAPS visit to the + * target's channel, after the UE's own uplink slot), not at its slot. Its seq + * is that of the UE's last uplink-slot instant at or before the reception: + * the slot is at `phase_us + ul_start_us` of every superframe of its serving + * cell (network time). `early_us` absorbs a copy heard slightly BEFORE the + * slot instant (timing advance), so a copy at the slot itself maps there too. */ +inline uint32_t ul_seq_for_copy(int64_t t_net_us, int64_t phase_us, int64_t ul_start_us, int64_t period_us, + int64_t early_us = 5000) { + const int64_t off = phase_us + ul_start_us; + const int64_t x = t_net_us + early_us - off; + const int64_t k = (x >= 0 ? x : x - period_us + 1) / period_us; /* floor */ + return ul_seq_from_network_time(k * period_us + off, period_us); +} + } /* namespace devourer::cell */ #endif /* DEVOURER_CELL_HANDOVER_H */ diff --git a/tests/cell_m6_selftest.cpp b/tests/cell_m6_selftest.cpp index 87374813..fc11150f 100644 --- a/tests/cell_m6_selftest.cpp +++ b/tests/cell_m6_selftest.cpp @@ -443,9 +443,25 @@ int main() { CHECK(ul_seq_from_network_time(1000 * P + 50000 + 3, P) == ul_seq_from_network_time(1000 * P + 50000 - 4, P)); CHECK(ul_seq_from_network_time(1001 * P + 7, P) == ul_seq_from_network_time(1000 * P + 7, P) + 1); + /* DAPS across channels: a copy heard later in the superframe (a visit to + * the target's channel) maps to the UE's own uplink slot; one at the slot + * (incl. a timing advance) maps there too; the next slot is the next seq. */ + { + const int64_t ph = 51200, ul = 16500; /* slot instant at 67700 in each superframe */ + const int64_t S = 1000 * P; + const uint32_t at_slot = ul_seq_for_copy(S + 67700, ph, ul, P); + CHECK(at_slot == ul_seq_from_network_time(S + 67700, P)); + CHECK(ul_seq_for_copy(S + 67700 - 400, ph, ul, P) == at_slot); /* TA: heard 0.4 ms early */ + CHECK(ul_seq_for_copy(S + 67700 + 40000, ph, ul, P) == at_slot); /* a visit 40 ms later: next */ + CHECK(ul_seq_from_network_time(S + 67700 + 40000, P) == at_slot + 1); /* ... the raw seq would differ */ + CHECK(ul_seq_for_copy(S + 67700 + P, ph, ul, P) == at_slot + 1); /* the next slot */ + CHECK(ul_seq_for_copy(S + 67700 + P - 6000, ph, ul, P) == at_slot); /* still before it */ + /* phase 0: slot at 16500 of the same network superframe */ + CHECK(ul_seq_for_copy(S + 16500 + 50000, 0, ul, P) == ul_seq_from_network_time(S, P)); + } /* F1 v5 Uplink round trip. */ const Mac k = fake_mac(3); - f1::UplinkFwd u{2, 1, 1, 123456, -61}; + f1::UplinkFwd u{2, 1, 1, 123456, 17521968566LL * 102400 + 51200, -61}; const auto w = f1::encode_uplink(u, k); CHECK(f1::peek_type(w.data(), w.size()) == f1::Type::Uplink); auto du = f1::decode_uplink(w.data(), w.size(), k); diff --git a/tools/ran-controller/main.cpp b/tools/ran-controller/main.cpp index 8b7d74cf..912d1133 100644 --- a/tools/ran-controller/main.cpp +++ b/tools/ran-controller/main.cpp @@ -534,7 +534,27 @@ int main() { known = known || ul.stream_id({u->cell, u->ue}).has_value(); } if (known) { + /* A copy heard by ANOTHER cell's DU (DAPS: the target hearing the + * source identity) may be a sequential-DAPS visit, sent after the + * UE's own uplink slot on the target's channel: its seq is that of + * the slot (Handover.h ul_seq_for_copy), from the serving cell's + * phase and the UE's uplink position in its last report. */ + if (u->du != u->cell) + if (auto sd = dus.find(u->cell); sd != dus.end() && sd->second.rep.period_us > 0) + for (const auto &a : sd->second.rep.ues) + if (a.ue == u->ue && a.pos >= 1 && a.pos <= sd->second.rep.positions.size()) { + u->seq = devourer::cell::ul_seq_for_copy( + u->net_us, sd->second.rep.phase_us, sd->second.rep.positions[a.pos - 1].ul.start_us, + sd->second.rep.period_us); + break; + } + const uint32_t raw_seq = static_cast(u->net_us / std::max(1, dus.count(u->du) ? dus.at(u->du).rep.period_us : 102400)); const auto r = ul.deliver({u->cell, u->ue}, u->seq, u->du); + if (u->du != u->cell) + emit("{\"ev\":\"ran.ul_copy\",\"du\":" + std::to_string(u->du) + ",\"cell\":" + + std::to_string(u->cell) + ",\"ue\":" + std::to_string(u->ue) + ",\"raw\":" + + std::to_string(raw_seq) + ",\"seq\":" + std::to_string(u->seq) + ",\"fresh\":" + + (r.fresh ? "1" : "0") + "}"); ul_seen[r.stream] = std::chrono::steady_clock::now(); ul_name[r.stream] = {u->cell, u->ue}; if (r.fresh) { From df4607c07831396f807af8da39e607990585033c Mon Sep 17 00:00:00 2001 From: Joseph <162703152+josephnef@users.noreply.github.com> Date: Tue, 10 Nov 2026 12:07:58 +0300 Subject: [PATCH 2/2] =?UTF-8?q?cell=20M6=20DAPS=20across=20channels:=20rev?= =?UTF-8?q?iew=20fixes=20=E2=80=94=20whole=20send=20clear=20of=20the=20tar?= =?UTF-8?q?get,=20late/overrun=20visits=20skipped,=20every=20copy=20mapped?= =?UTF-8?q?,=20short=20step=20hold?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - A visit instant is taken only if the whole send (queued through the 4 ms hold, with guards) is clear of the target's active span, across the superframe boundary. - A late wake skips the visit. An outbound retune that overran the instant skips the send and retunes back (cell.ue.daps_visit_skip). Both retunes feed gap_retune_us. - The CU maps every forwarded uplink, the serving DU's own copies included, from the identity's last-known slot (kept 30 s from the latest report naming it). Copies of one uplink share a seq even next to a network-superframe boundary, and a late copy after the source released the UE still maps. Selftest for the boundary case. - A visit holds TSF steps only through its own superframe (not four, which froze them for the whole window); held steps are counted. Rig (m6_daps_xch.sh 2 runs per case, all pass): with visits, 0 uplinks lost before the switch (15 without), no visit skipped. Regression: same-channel DAPS, the handovers, the two-cell crossing with a source failure, measgap and the three-cell crossing with one all pass. Co-Authored-By: Claude Opus 5.5 (1M context) --- docs/cell-m6.md | 34 +++++++++++++------ examples/cell/main.cpp | 63 +++++++++++++++++++++++++++-------- tests/cell_m6_selftest.cpp | 7 ++++ tools/ran-controller/main.cpp | 31 ++++++++++++----- 4 files changed, 102 insertions(+), 33 deletions(-) diff --git a/docs/cell-m6.md b/docs/cell-m6.md index 0702e0ff..3c751ed0 100644 --- a/docs/cell-m6.md +++ b/docs/cell-m6.md @@ -1199,14 +1199,27 @@ the switch was lost (the three-cell crossing: 12–14). - **Loop cadence:** during the window the UE loop runs every 30 ms, not 100 ms, so the next superframe's visit is in reach after one ends ~75 ms into its superframe. +- **What a visit checks:** + - the whole send, from queuing through the hold, must be clear of the + target's active span; + - a late wake skips the visit; + - an outbound retune that overran the instant skips the send and retunes + straight back (`cell.ue.daps_visit_skip`); + - both retunes feed the adaptive bound. +- **The step hold:** a visit holds TSF steps only through its own + superframe; steps held are counted in `cell.ue.done`. **Its sequence number at the CU** (F1 v14): - The target DU forwards the copy as before (`daps_ids`, area tag), now with its reception instant on the network timebase (`Uplink.net_us`). -- A copy heard by another cell's DU is mapped by the CU to the UE's last - own uplink slot at or before it (`Handover.h` `ul_seq_for_copy`), using - the source cell's phase and the UE's uplink position from the source's - report. +- The CU maps EVERY forwarded uplink to the UE's last own uplink slot at or + before it (`Handover.h` `ul_seq_for_copy`), the serving DU's own copies + included. It uses the identity's last-known slot (its cell's phase and its + uplink position from the latest report naming it, kept 30 s). +- Mapping every copy keeps both copies of one uplink on one seq even with + the slot next to a network-superframe boundary, where a timing advance + puts the serving copy before it. A copy arriving after the source released + the UE still maps. - The visit, sent ~30 ms after the slot and possibly in the next network superframe, therefore dedups with the source's copy of the same uplink. The UE needs no global clock. @@ -1223,12 +1236,12 @@ stream on. | uplinks missing at the CU around the switch | before the switch | at the switch | |---|---|---| -| source killed at the accept, visits | **0, 0** | 2, 2 | -| source killed at the accept, no visits | 13, 13 | 2, 2 | -| no fault, visits | 0, 0 | 1, 1 | +| source killed at the accept, visits | **0, 0** | 1, 2 | +| source killed at the accept, no visits | 15, 15 | 2, 2 | +| no fault, visits | 0, 0 | 2, 1 | -- **20–21 visits per handover**, every one sent and back; deaf time - 55.6–57.2 ms each. +- **20–21 visits per handover**, every one sent and back, none skipped; + deaf time 55.6–56.8 ms each. - **They cost the source nothing:** without a fault, DU1 heard UE1's uplink in every superframe from the accept to the switch, in slot 100 %. - **The switch's own cost:** the switch superframe (with the source dead, @@ -1241,7 +1254,8 @@ stream on. the step hold (above), visits stopping two superframes before the switch left those two uncovered. - **Regression:** the inter-frequency measurement-gap handover, same-channel - DAPS, the plain and fault handovers and the three-cell crossing pass. + DAPS, the plain and fault handovers, the two-cell crossing with a source + failure, and the three-cell crossing with one all pass. ## Replay of a signed neighbour list diff --git a/examples/cell/main.cpp b/examples/cell/main.cpp index 234eac12..fb2b62f3 100644 --- a/examples/cell/main.cpp +++ b/examples/cell/main.cpp @@ -3140,7 +3140,7 @@ int run_ue(IRadio *dev, const Cfg &c) { bool had_susp_prev = false; /* last pass had neighbours only a suspend gap reaches */ std::vector last_bcn; /* the uplink beacon frame on air (for DAPS visits) */ int64_t last_visit_sf = -1; - uint64_t visits = 0, visits_ok = 0; + uint64_t visits = 0, visits_ok = 0, steps_held = 0; uint64_t susp_gaps = 0, susp_heard = 0, susp_fail = 0; while (std::chrono::steady_clock::now() < deadline) { /* A DAPS-visit window: passes 30 ms apart, so the next superframe's @@ -3657,6 +3657,7 @@ int run_ue(IRadio *dev, const Cfg &c) { * in the next pass; 20 gaps without one lost nothing. The mechanism is * not established; the step simply waits a few superframes. */ if (step != 0 && du_now / P < no_step_until_sf) { + ++steps_held; } else if (step != 0) { /* The offset changes only on a write, so the loop's (t, f) pair gives * the offset this step must produce. */ @@ -3821,13 +3822,19 @@ int run_ue(IRadio *dev, const Cfg &c) { constexpr int64_t kVisitHoldUs = 4000; const int64_t lo = ul_end + gap_guard_us + gap_retune_us, hi = P - gap_guard_us - gap_retune_us - kVisitHoldUs - 1000; - auto in_target = [&](int64_t v) { - const int64_t d = ((v - o_t) % P + P) % P; - return d < span + 1000 || d > P - 1000; + /* The whole send — queued at v, airing any time during the hold — must + * stay clear of the target cell's active span (1 ms guards). */ + auto clear_of_target = [&](int64_t a, int64_t b) { + for (int64_t x = a; x <= b; x += 250) { + const int64_t d = ((x - o_t) % P + P) % P; + if (d < span + 1000 || d > P - 1000) + return false; + } + return true; }; std::optional v; for (int64_t x = lo; x <= hi && !v; x += 500) - if (!in_target(x)) + if (clear_of_target(x - 500, x + kVisitHoldUs + 1000)) v = x; const auto now_du = serving_now(); for (const int64_t S : {sfn, sfn + 1}) { @@ -3839,6 +3846,18 @@ int run_ue(IRadio *dev, const Cfg &c) { continue; last_visit_sf = S; std::this_thread::sleep_for(std::chrono::microseconds(go - *now_du)); + auto skip = [&](const char *why, int64_t late_us) { + char l[200]; + snprintf(l, sizeof l, + "{\"ev\":\"cell.ue.daps_visit_skip\",\"ue\":%d,\"sf\":%lld,\"why\":\"%s\",\"late_us\":%lld}", + me, (long long)S, why, (long long)late_us); + emit(l); + }; + /* Woke late: the window was planned for `go` only (as run_gap). */ + if (const auto woke = serving_now(); !woke || *woke - go > gap_guard_us / 2) { + skip("late", woke ? *woke - go : -1); + break; + } const auto g0 = std::chrono::steady_clock::now(); bool out_ok = true, sent = false; try { @@ -3848,13 +3867,23 @@ int run_ue(IRadio *dev, const Cfg &c) { } const auto g1 = std::chrono::steady_clock::now(); if (out_ok) { - if (const auto t_now = serving_now(); t_now && *t_now < S * P + *v) - std::this_thread::sleep_for(std::chrono::microseconds(S * P + *v - *t_now)); - auto pkt = build_dl_radiotap(6); - pkt.insert(pkt.end(), last_bcn.begin(), last_bcn.end()); - sent = dev->send_packet(pkt.data(), pkt.size()); - std::this_thread::sleep_for(std::chrono::microseconds(kVisitHoldUs)); + /* The outbound retune may overrun: send only if the instant is + * still (about) ahead — the copy must not slide into the target's + * span, nor the return past the serving beacon. */ + const auto t_now = serving_now(); + const int64_t at = S * P + *v; + if (!t_now || *t_now > at + 1000) { + skip("retune_overrun", t_now ? *t_now - at : -1); + } else { + if (*t_now < at) + std::this_thread::sleep_for(std::chrono::microseconds(at - *t_now)); + auto pkt = build_dl_radiotap(6); + pkt.insert(pkt.end(), last_bcn.begin(), last_bcn.end()); + sent = dev->send_packet(pkt.data(), pkt.size()); + std::this_thread::sleep_for(std::chrono::microseconds(kVisitHoldUs)); + } } + const auto g1b = std::chrono::steady_clock::now(); bool back_ok = false; for (int k = 0; k < 3 && !back_ok; ++k) { try { @@ -3869,7 +3898,13 @@ int run_ue(IRadio *dev, const Cfg &c) { beaconing = false; retune_to = cur_ch; } - no_step_until_sf = S + 4; /* as after a gap */ + /* The bound only grows with what was measured (as for gaps). */ + gap_retune_us = std::max( + {gap_retune_us, std::chrono::duration_cast(g1 - g0).count(), + std::chrono::duration_cast(g2 - g1b).count()}); + /* Steps wait only out this superframe (visits come every one: a + * longer hold would freeze them for the whole window). */ + no_step_until_sf = S + 1; ++visits; visits_ok += out_ok && back_ok && sent ? 1 : 0; char l[260]; @@ -4044,7 +4079,7 @@ int run_ue(IRadio *dev, const Cfg &c) { "\"keyed\":%d,\"gm_ok\":%llu,\"gm_refused\":%llu,\"nbr_refused\":{\"stale\":%llu," "\"unlisted\":%llu,\"phase\":%llu},\"dl_pdus\":{\"delivered\":%llu,\"duplicates\":%llu," "\"missing\":%llu,\"stale\":%llu,\"top\":%lld},\"suspend_gaps\":{\"n\":%llu,\"heard\":%llu," - "\"fail\":%llu},\"daps_visits\":{\"n\":%llu,\"ok\":%llu}}", + "\"fail\":%llu},\"daps_visits\":{\"n\":%llu,\"ok\":%llu},\"steps_held\":%llu}", me_a.load(), steps, step_fails, (long long)listen_from, (long long)listen_to, (unsigned long long)dl_new, (unsigned long long)dl_dup, auth ? 1 : 0, (unsigned long long)gm_ok, (unsigned long long)gm_refused, @@ -4054,7 +4089,7 @@ int run_ue(IRadio *dev, const Cfg &c) { (unsigned long long)dl_stream.stale(), dl_stream.top() ? (long long)*dl_stream.top() : -1LL, (unsigned long long)susp_gaps, (unsigned long long)susp_heard, (unsigned long long)susp_fail, (unsigned long long)visits, - (unsigned long long)visits_ok); + (unsigned long long)visits_ok, (unsigned long long)steps_held); emit(l); return 0; } diff --git a/tests/cell_m6_selftest.cpp b/tests/cell_m6_selftest.cpp index fc11150f..09caddcd 100644 --- a/tests/cell_m6_selftest.cpp +++ b/tests/cell_m6_selftest.cpp @@ -456,6 +456,13 @@ int main() { CHECK(ul_seq_from_network_time(S + 67700 + 40000, P) == at_slot + 1); /* ... the raw seq would differ */ CHECK(ul_seq_for_copy(S + 67700 + P, ph, ul, P) == at_slot + 1); /* the next slot */ CHECK(ul_seq_for_copy(S + 67700 + P - 6000, ph, ul, P) == at_slot); /* still before it */ + /* The slot 200 us after a network-superframe boundary: the serving + * copy heard 400 us early (timing advance) is in the PREVIOUS raw + * superframe, a visit 30 ms later in the slot's — mapping BOTH (the CU + * maps every copy) gives one seq. */ + CHECK(ul_seq_for_copy(S - 200, 0, 200, P) == ul_seq_for_copy(S + 30200, 0, 200, P)); + CHECK(ul_seq_for_copy(S - 200, 0, 200, P) == ul_seq_from_network_time(S, P)); + CHECK(ul_seq_from_network_time(S - 200, P) + 1 == ul_seq_from_network_time(S, P)); /* raw differ */ /* phase 0: slot at 16500 of the same network superframe */ CHECK(ul_seq_for_copy(S + 16500 + 50000, 0, ul, P) == ul_seq_from_network_time(S, P)); } diff --git a/tools/ran-controller/main.cpp b/tools/ran-controller/main.cpp index 912d1133..a80bf703 100644 --- a/tools/ran-controller/main.cpp +++ b/tools/ran-controller/main.cpp @@ -388,6 +388,14 @@ int main() { std::deque recent; /* the last RAN_DL_DAPS_BACKLOG sns sent */ }; std::map, DlStream> dls; + /* Per UE identity (cell, ue): where its uplink slot sits (its cell's phase + * and period, the slot's start on the grid), from the latest report that + * listed it — what a forwarded copy is mapped to (Handover.h + * ul_seq_for_copy); kept 30 s past the last report naming it. */ + struct UlSlot { + int64_t phase_us = 0, period_us = 0, ul_start_us = 0, at_ms = 0; + }; + std::map, UlSlot> ul_slot; auto dl_undup = [&](const devourer::cell::HoCommand &cmd) { if (auto d = dls.find({cmd.source, cmd.ue}); d != dls.end()) d->second.dup.reset(); @@ -539,15 +547,15 @@ int main() { * UE's own uplink slot on the target's channel: its seq is that of * the slot (Handover.h ul_seq_for_copy), from the serving cell's * phase and the UE's uplink position in its last report. */ - if (u->du != u->cell) - if (auto sd = dus.find(u->cell); sd != dus.end() && sd->second.rep.period_us > 0) - for (const auto &a : sd->second.rep.ues) - if (a.ue == u->ue && a.pos >= 1 && a.pos <= sd->second.rep.positions.size()) { - u->seq = devourer::cell::ul_seq_for_copy( - u->net_us, sd->second.rep.phase_us, sd->second.rep.positions[a.pos - 1].ul.start_us, - sd->second.rep.period_us); - break; - } + /* Every copy, the serving DU's own too: the two copies of one + * uplink must get the same seq even with the slot next to a + * network-superframe boundary (a timing advance puts the + * serving copy before it). From the identity's last-known slot, + * so a copy that arrives after the source released the UE still + * maps. */ + if (auto m = ul_slot.find({u->cell, u->ue}); m != ul_slot.end() && ms_now() - m->second.at_ms < 30000) + u->seq = devourer::cell::ul_seq_for_copy(u->net_us, m->second.phase_us, m->second.ul_start_us, + m->second.period_us); const uint32_t raw_seq = static_cast(u->net_us / std::max(1, dus.count(u->du) ? dus.at(u->du).rep.period_us : 102400)); const auto r = ul.deliver({u->cell, u->ue}, u->seq, u->du); if (u->du != u->cell) @@ -647,6 +655,11 @@ int main() { d.rep = *r; d.addr = from; d.at = std::chrono::steady_clock::now(); + if (r->period_us > 0) + for (const auto &a : r->ues) + if (a.pos >= 1 && a.pos <= r->positions.size()) + ul_slot[{r->du, a.ue}] = {r->phase_us, r->period_us, r->positions[a.pos - 1].ul.start_us, + ms_now()}; if (first) { char a[INET_ADDRSTRLEN] = {}; inet_ntop(AF_INET, &from.sin_addr, a, sizeof a);