Express fiber: light a wave through a city without its router (#58)

An express lightpath runs from A to C over your own or IRU dark fibers
A-B, B-C (up to six) and passes B through its ROADM as light: ports only
at its two ends, no hop in B, the fibers' latency added up. It takes one
channel slot on every fiber it rides, needs a ROADM line system on each,
and an optic that makes the whole run between regen sites. Routing, the
route worker, traceroute, diverse paths and saves see it as a link A-C.

A cut, a build, an amp or ROADM failure or a line system swap on any
fiber under it darkens it; backhoes and the chaos monkey still find
fibers that only carry expresses. "Express to..." on a fiber and an
Express tab in the link window plan one, with reach, slots per fiber and
the price. The intern's optics order leaves fibers that only carry
expresses bare, decom never hands one back, and the build standard keeps
a fiber's line system while an express on it carries traffic.
This commit is contained in:
jvanvik 2026-11-07 01:06:30 +01:00
parent eac0604300
commit 8e1f2d66a5
41 changed files with 883 additions and 53 deletions

View file

@ -0,0 +1,48 @@
/* Express lightpaths (#58): the panel of one, the section on a dark fiber's panel (what rides it, where it chains on)
and the Express tab of the link window (70-link-modal.js). The rules are in 80-simulation/65-express.js. */
const xpSpanName=s=>`${CITY[s.a].name} ⇄ ${CITY[s.b].name}`;
// Why an express is dark today, fiber by fiber.
function xpDarkWhy(l){const sp=xpSpans(l);if(!sp)return [tr('express.dark_gone')];const d=S.day,out=[];
for(const s of sp){const n=xpSpanName(s);if(linkCut(s))out.push(tr('express.dark_cut',{span:n}));else if(s.ready>d)out.push(trn('express.dark_building',s.ready-d,{span:n}));else if(s.eqDown>d)out.push(tr('express.dark_system',{span:n}));}
if(!out.length)out.push(tr('express.dark_reach'));return out;}
// One fiber of a path: whose it is, how long, the slots left for express channels.
const xpSpanMeta=s=>`${s.own?tr('common.own_dark_fiber'):tr('common.leased_iru')} · ${Math.round(s.km).toLocaleString()} km · ${tr('express.free_slots',{n:Math.max(0,xpFree(s)),max:chMax(s)})}`;
// An optic's settings over a run, as the fiber panel lists them.
const xpModes=(o,run)=>OPT[o].modes.map(([g,r])=>tr('link_panels.g_to_km_km',{g:fmtG(g),km:r.toLocaleString()})).join(' · ')+` · ${xpOptG(o,run)?tr('express.runs_at',{g:fmtG(xpOptG(o,run))}):tr('express.out_of_reach')}`;
function xpPanel(l){const sp=xpSpans(l),load=R.load[l.id]||0,cap=capOf(l),u=cap?load/cap:0,down=linkDown(l),A=CITY[l.a].name,B=CITY[l.b].name,run=sp?xpRunKm(sp):0,ch=l.ch||[];
let h=`<div class="ph"><div><div class="eyebrow">${tr('express.eyebrow',{km:Math.round(l.km).toLocaleString()})}</div><h2>${A} ⇄ ${B}</h2></div><button class="x" data-act="closePanel" aria-label="${tr('common.close')}">×</button></div><div class="scroll">`;
if(down)h+=`<section><h3 style="color:var(--bad)">${tr('common.dark_6bf5')}</h3>${xpDarkWhy(l).map(t=>`<p class="lead">${t}</p>`).join('')}</section>`;
h+=`<section><h3>${tr('common.capacity')}</h3><div class="kv"><span>${trn('express.n_channels',ch.length)}</span><b>${fmtG(load)} / ${fmtG(cap)}</b></div><div class="bar ${barCls(u)}"><i style="width:${Math.min(100,u*100)}%"></i></div>
<div class="kv"><span>${tr('common.latency')}</span><b>${tr('common.ms_ms_one_way',{ms:linkLat(l).toFixed(1)})}</b></div><div class="kv"><span>${tr('express.optical_run')}</span><b>${run.toLocaleString()} km</b></div>
<p class="note">${tr('express.passes',{via:esc(xpVia(l))})}</p></section>`;
if(sp)h+=`<section><h3>${tr('express.its_fibers')}</h3>${sp.map(s=>`<div class="row"><div class="grow"><div class="nm">${xpSpanName(s)} ${linkCut(s)?'<span class="tag restrictive">'+tr('common.cut')+'</span>':''}</div><div class="meta">${xpSpanMeta(s)}</div></div>${btn(tr('common.open'),'selLink',{id:s.id},'ghost sm')}</div>`).join('')}<p class="note">${tr('express.slot_note')}</p></section>`;
if(sp){h+=`<section><h3>${tr('common.optics')}</h3>`;
for(const k of Object.keys(OPT)){const O=OPT[k],n=ch.filter(x=>x===k).length;if(!n&&!techOk('opt',k,O.lvl))continue;const why=xpWhy(l.a,l.b,sp,k),c=xpCost(sp,k,false),spn=spareN(k);
h+=`<div class="row"><div class="grow"><div class="nm">${O.n}</div><div class="meta">${xpModes(k,run)}${n?` · <b>${tr('link_panels.n_lit',{n})}</b>`:''}${spn?` · ${trn('link_panels.n_spare_on_the_shelf',spn)}`:''}</div>${why?`<div class="why">${esc(why)}</div>`:''}</div>${n&&ch.length>1?btn('−','xpCh',{id:l.id,o:k,d:-1},'ghost sm'):''}${btn(`+ <small>${spn?tr('link_panels.spare_price',{price:fmt$(c)}):fmt$(c)}</small>`,'xpCh',{id:l.id,o:k,d:1},'sm',!!why||S.cash<c)}</div>`;}
h+=`<p class="note">${tr('link_panels.unplugged_optics_go_on_the_spares')}</p></section>`;}
h+=`${trafficSection(l)}${metricSection(l)}<section>${btn(UI.confirm===l.id?tr('link_panels.really_give_it_up'):tr('express.tear_down'),'rmLink',{id:l.id},'ghost sm')}<p class="note">${tr('express.tear_down_note')}</p></section></div>`;
return h;}
// Where an express can go from this fiber: through either end and on over your other ROADM fibers.
function xpTargets(l){const out=[];for(const [x,y] of [[l.a,l.b],[l.b,l.a]])for(const p of xpPaths(x,null,l,6))if(xpRunKm(p.sp)<=xpReachMax())out.push({from:x,...p});
return out.sort((p,q)=>p.km-q.km).slice(0,6);}
// On a dark fiber's panel: the expresses riding it, and where one could go from here.
function xpDfSection(l){if(l.sub)return '';const on=xpOver(l.id),rdm=isRdm(l.sys),tg=rdm?xpTargets(l):[];
// Without a ROADMaster the hint is only worth showing where another fiber of yours meets this one.
const near=!rdm&&S.links.some(x=>x!==l&&x.kind==='df'&&!x.sub&&[x.a,x.b].some(c=>c===l.a||c===l.b));
if(!on.length&&!tg.length&&!near)return '';
let h=`<section><h3>${tr('express.title')}</h3><p class="lead">${tr('express.lead')}</p>`;
if(!rdm)h+=`<p class="why">${tr('express.needs_roadm')}</p>`;
if(on.length)h+=`<h4 class="sub4">${tr('express.riding_here')}</h4>`+on.map(x=>`<div class="row"><div class="grow"><div class="nm">${CITY[x.a].name} ⇄ ${CITY[x.b].name} ${linkDown(x)?'<span class="tag restrictive">'+tr('common.dark')+'</span>':''}</div><div class="meta">${capName(x)} · ${trn('express.n_channels',(x.ch||[]).length)} · ${tr('express.city_via',{via:esc(xpVia(x))})}</div></div>${btn(tr('common.open'),'selLink',{id:x.id},'ghost sm')}</div>`).join('')+`<p class="note">${tr('express.riding_note')}</p>`;
if(tg.length)h+=`<h4 class="sub4">${tr('express.express_to')}</h4>`+tg.map(t=>{const cs=xpCities(t.from,t.sp);return `<div class="row"><div class="grow"><div class="nm">${CITY[t.from].name} → ${CITY[t.to].name}</div><div class="meta">${tr('express.via_km',{via:cs.slice(1,-1).map(c=>CITY[c].name).join(', '),km:Math.round(t.km).toLocaleString()})}</div></div>${btn(tr('express.plan'),'xpOpen',{a:t.from,b:t.to,via:t.sp.map(s=>s.id).join(',')},'pink sm')}</div>`;}).join('');
return h+`</section>`;}
// The link window's Express tab: the ways your fibers chain from a to b, shortest first, an optic per button. Optic
// names are long: they go above the reason, not in the narrow column a wave's '400G' fits in.
function xpModalBody(a,b,routes){let h=`<p class="lead" style="margin-top:8px">${tr('express.modal_lead',{a:CITY[a].name,b:CITY[b].name})}</p>`;
for(const r of routes){const sp=r.sp,ids=sp.map(s=>s.id),cs=xpCities(a,sp),run=xpRunKm(sp),old=xpFind(a,b,ids),lat=sp.reduce((x,s)=>x+linkLat(s),0);
h+=`<h4 class="sub4">${tr('express.via_km',{via:cs.slice(1,-1).map(c=>CITY[c].name).join(', '),km:Math.round(r.km).toLocaleString()})}</h4>
${sp.map(s=>`<div class="meta">${xpSpanName(s)} · ${xpSpanMeta(s)}</div>`).join('')}
<div class="kv"><span>${tr('express.optical_run')}</span><b>${run.toLocaleString()} km</b></div><div class="kv"><span>${tr('common.latency')}</span><b>${tr('common.ms_ms_one_way',{ms:lat.toFixed(1)})}</b></div>
${old?`<p class="note">${trn('express.already',(old.ch||[]).length)}</p>`:''}
<div class="tiers">${Object.keys(OPT).filter(k=>techOk('opt',k,OPT[k].lvl)).map(k=>{const O=OPT[k],why=xpWhy(a,b,sp,k),c=xpCost(sp,k,!old),g=xpOptG(k,run);
return `<button class="tierbtn" data-act="xpBuild" data-args="${esc(JSON.stringify({a,b,via:ids.join(','),o:k}))}"${why||S.cash<c?' disabled':''}><span class="grow"><span class="onm">${O.n}</span><span class="meta">${why?esc(why):tr('express.runs_at',{g:fmtG(g)})}</span></span><span class="pr num">${fmt$(c)}</span></button>`;}).join('')}</div>`;}
return h+`<p class="note">${tr('express.modal_note',{price:fmt$(XP_PASS)})}</p>`;}