Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 85 additions & 4 deletions docs/cell-m6.md
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,88 @@ 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.
- **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`).
- 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.

**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** | 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, 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,
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, the two-cell crossing with a source
failure, and the three-cell crossing with one all pass.

## Replay of a signed neighbour list

A signature proves who wrote a beacon, not when it was aired, so the
Expand Down Expand Up @@ -1313,10 +1395,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
Expand Down
162 changes: 155 additions & 7 deletions examples/cell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<int64_t>(dc.phase_us) + net_off.load() * P, P);
u.net_us = *at + static_cast<int64_t>(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<int8_t>(static_cast<int>(p.RxAtrib.rssi[0]) - 110);
send_f1(devourer::cell::f1::encode_uplink(u, f1_mac));
};
Expand Down Expand Up @@ -1406,8 +1412,13 @@ int run_du(IRadio *dev, const Cfg &c) {
static_cast<double>(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<int>(p.RxAtrib.rssi[0]) - 110);
emit(l);
}
return;
}
}
Expand Down Expand Up @@ -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<std::chrono::milliseconds>(
Expand Down Expand Up @@ -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<uint8_t> last_bcn; /* the uplink beacon frame on air (for DAPS visits) */
int64_t last_visit_sf = -1;
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) {
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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -3628,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. */
Expand Down Expand Up @@ -3772,6 +3802,123 @@ 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<int64_t>(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;
/* 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<int64_t> v;
for (int64_t x = lo; x <= hi && !v; x += 500)
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}) {
if (!v || !now_du || S <= last_visit_sf ||
static_cast<uint64_t>(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));
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 {
dev->FastRetune(ho_pending->channel);
} catch (const std::exception &) {
out_ok = false;
}
const auto g1 = std::chrono::steady_clock::now();
if (out_ok) {
/* 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 {
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;
}
/* The bound only grows with what was measured (as for gaps). */
gap_retune_us = std::max<int64_t>(
{gap_retune_us, std::chrono::duration_cast<std::chrono::microseconds>(g1 - g0).count(),
std::chrono::duration_cast<std::chrono::microseconds>(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];
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<std::chrono::microseconds>(g1 - g0).count(),
(long long)std::chrono::duration_cast<std::chrono::microseconds>(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<devourer::cell::Neighbour> other, susp;
const int64_t sfn = du_now / P;
Expand Down Expand Up @@ -3925,14 +4072,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},\"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,
Expand All @@ -3941,7 +4088,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, (unsigned long long)steps_held);
emit(l);
return 0;
}
Expand Down
9 changes: 8 additions & 1 deletion src/cell/F1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand All @@ -635,6 +640,7 @@ inline std::vector<uint8_t> 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<uint64_t>(u.net_us), 8);
m.push_back(static_cast<uint8_t>(u.rssi_dbm));
return seal(std::move(m), mac);
}
Expand All @@ -650,6 +656,7 @@ inline std::optional<UplinkFwd> decode_uplink(const uint8_t *p, size_t n, const
u.cell = static_cast<uint16_t>(r.get(2));
u.ue = static_cast<uint16_t>(r.get(2));
u.seq = static_cast<uint32_t>(r.get(4));
u.net_us = static_cast<int64_t>(r.get(8));
u.rssi_dbm = static_cast<int8_t>(r.get(1));
if (!r.ok || r.i != r.n)
return std::nullopt;
Expand Down
Loading
Loading