Make router ports finite and add more router models

Every port, wave and fibre channel now takes a router port, and new ports
are refused when a POP is full. POPs take up to six routers, and six new
models can be swapped in from the Infra tab, including the Arrrhipster
7280R-ish and 7800R-ish.
This commit is contained in:
Frederic Jung 2026-10-24 06:40:08 +02:00
parent 5e88e44a0a
commit 0e5abd5c6a
No known key found for this signature in database
3 changed files with 104 additions and 27 deletions

View file

@ -6,6 +6,15 @@ All notable changes to this project are documented here. The project follows
## [Unreleased]
- Router ports are finite. Every transit, IX, PNI and cache port, every wave
and every fibre channel takes a router port; 10G ports ride a breakout,
four to a port. The Infra tab shows how many are left, and plugging in more
than you have is refused.
- More routers: up to six per POP, and six new models to swap in from the
Infra tab: Mikrowtik CCR-ish, Sonic the Whitebox 32 (cheap, crashes more),
Arrrhipster 7280R-ish and 7800R-ish (lots of ports, deep buffers, boots in
minutes), Disco 8K-ish (licence keys for everything) and Knockia 7750-ish.
A swap that would not fit what is already plugged in is refused.
- New cities: Milan, Rome, Palermo, Lisbon and Athens in Europe; Atlanta,
Denver, Phoenix, Boston, Houston and Salt Lake City in the US. New cables
land with them (Lisbon to Brazil, Africa and the US Southeast; Genoa to

View file

@ -491,10 +491,16 @@ const myFab=c=>MYIX_FAB[Math.min(MYIX_FAB.length-1,Math.max(0,(S.myIx[c]&&S.myIx
const LT=[{n:'10G',g:10,m:1},{n:'100G',g:100,m:2.8},{n:'400G',g:400,m:6},{n:'800G',g:800,m:9},{n:'1.6T',g:1600,m:13},{n:'6.4T',g:6400,m:28,note:'handed off as 4×1.6T'}];
const PORT=[{n:'10G',g:10,setup:500,tmo:150,ix:400,pni:200},{n:'100G',g:100,setup:1500,tmo:400,ix:1500,pni:350},{n:'400G',g:400,setup:4000,tmo:900,ix:4000,pni:600},{n:'800G',g:800,setup:8000,tmo:1600,ix:7000,pni:1000},{n:'1.6T',g:1600,setup:16000,tmo:2800,ix:12000,pni:1600}];
const RG=[
{n:'Rusty Router 9000',pn:'100G',cap:400,cost:0,mo:0,maxLT:1,maxP:1,lvl:1,boot:6,slowP:10,chip:'a mystery ASIC',blurb:'Bought used on eBuy. The fans sound like a jet engine.'},
{n:'Edge Lord 400',pn:'400G',cap:3200,cost:30000,mo:1000,maxLT:2,maxP:2,lvl:2,boot:11,slowP:20,chip:'merchant silicon',blurb:'Sharp, edgy, and finally speaks 400G and 400ZR+.'},
{n:'Chonk 800',pn:'800G',cap:12800,cost:90000,mo:3000,maxLT:3,maxP:3,lvl:3,boot:25,slowP:45,chip:'Junipurr PacketOinker™',blurb:'An absolute unit with 800G ports, built around the Junipurr PacketOinker™ forwarding chip. Oinks at line rate. Takes 800ZR+ optics.'},
{n:'Absolute Unit 1.6T',pn:'1.6T',cap:51200,cost:250000,mo:8000,maxLT:5,maxP:4,lvl:4,boot:40,slowP:60,chip:'PacketOinker² (two pigs, one chassis)',blurb:'1.6T ports, its own weather system and two PacketOinker² chips per line card. Takes 6.4T waves as 4×1.6T. Needs a forklift.'},
{n:'Rusty Router 9000',pn:'100G',cap:400,cost:0,mo:0,maxLT:1,maxP:1,ports:8,cls:0,lvl:1,boot:6,slowP:10,chip:'a mystery ASIC',blurb:'Bought used on eBuy. The fans sound like a jet engine.'},
{n:'Edge Lord 400',pn:'400G',cap:3200,cost:30000,mo:1000,maxLT:2,maxP:2,ports:24,cls:1,lvl:2,boot:11,slowP:20,chip:'merchant silicon',blurb:'Sharp, edgy, and finally speaks 400G and 400ZR+.'},
{n:'Chonk 800',pn:'800G',cap:12800,cost:90000,mo:3000,maxLT:3,maxP:3,ports:36,cls:2,lvl:3,boot:25,slowP:45,chip:'Junipurr PacketOinker™',blurb:'An absolute unit with 800G ports, built around the Junipurr PacketOinker™ forwarding chip. Oinks at line rate. Takes 800ZR+ optics.'},
{n:'Absolute Unit 1.6T',pn:'1.6T',cap:51200,cost:250000,mo:8000,maxLT:5,maxP:4,ports:40,cls:3,lvl:4,boot:40,slowP:60,chip:'PacketOinker² (two pigs, one chassis)',blurb:'1.6T ports, its own weather system and two PacketOinker² chips per line card. Takes 6.4T waves as 4×1.6T. Needs a forklift.'},
{n:'Mikrowtik CCR-ish',pn:'100G',cap:300,cost:4000,mo:150,maxLT:1,maxP:1,ports:16,cls:0,lvl:1,boot:2,slowP:5,badge:'M',chip:'a few dozen ARM cores',blurb:'Costs less than lunch and has twice the ports of the Rusty. Configuring it takes longer than the lunch.'},
{n:'Sonic the Whitebox 32',pn:'400G',cap:3200,cost:14000,mo:400,maxLT:2,maxP:2,ports:32,cls:1,lvl:2,boot:9,slowP:25,flaky:true,badge:'W',chip:'Tomahawk-ish merchant silicon',blurb:'A bare-metal switch running open-source SONiC-ish. Saves a fortune, until it crashes and there is nobody to call.'},
{n:'Arrrhipster 7280R-ish',pn:'400G',cap:4800,cost:42000,mo:1300,maxLT:2,maxP:2,ports:48,cls:1,lvl:2,boot:3,slowP:2,badge:'A',chip:'Jerry-cho deep-buffer silicon',blurb:'Fixed config, deep buffers, a well-groomed beard and an eyepatch. Runs EOS, the Extensible Operating Ship. Boots before your oat-milk flat white is ready, and ships a Python shell nobody asked for.'},
{n:'Arrrhipster 7800R-ish',pn:'800G',cap:16000,cost:130000,mo:4200,maxLT:3,maxP:3,ports:96,cls:2,lvl:3,boot:7,slowP:4,badge:'A',chip:'Jerry-cho³ deep-buffer silicon',blurb:'The modular one. Ninety-six 800G ports, buffers deep enough to lose a ship in, and a vinyl-only release notes policy. Arrr.'},
{n:'Disco 8K-ish',pn:'800G',cap:12800,cost:80000,mo:4800,maxLT:3,maxP:3,ports:64,cls:2,lvl:3,boot:20,slowP:35,badge:'D',chip:'Silly-con One',blurb:'Cheap to buy, expensive to own: licence keys for every port, every feature and, rumour has it, the fans. Smart Licensing phones home every week.'},
{n:'Knockia 7750-ish',pn:'1.6T',cap:40000,cost:200000,mo:7000,maxLT:5,maxP:4,ports:56,cls:3,lvl:4,boot:30,slowP:15,badge:'K',chip:'FP-ish network processor',blurb:'Finnish engineering: indestructible, extremely thorough, and the CLI only speaks hierarchical config. Boots like a Nordic sunrise.'}
];
/* Some routers take forever to boot. Each POP's chassis has a personality per model: most come
back in minutes, a few sit through every line card self-test known to the vendor. */
@ -502,6 +508,27 @@ const SLOW_BOOT=['is oinking through the self-test of every PacketOinker on ever
function slowBoot(c){const p=S.pops[c];if(!p)return false;const g=p.rgen||0;return hstr(c+'|boot|'+g+'|'+S.asn)%100<RG[g].slowP;}
function bootMin(c){const p=S.pops[c],G=RG[(p&&p.rgen)||0];return slowBoot(c)?G.boot*9+40:G.boot;}
const routerCost=g=>Math.round(ROUTER_COST+RG[g].cost*0.8);
const RMAX=6;
/* Ports are finite. Every transit, IX, PNI and cache port, every wave and every fibre channel
takes a router port. 10G ports ride a breakout cable, four to a port. */
const PORT_SLOT=i=>i===0?0.25:1;
function portsUsed(c){let u=0;
for(const l of S.links){if(l.a!==c&&l.b!==c||l.kind==='vxc')continue;u+=l.kind==='df'?(l.ch||[]).length:1;}
for(const t of S.transit)if(t.city===c)u+=PORT_SLOT(t.tier)*(t.n||1);
for(const x of S.pni)if(x.city===c)u+=PORT_SLOT(x.tier)*(x.n||1);
for(const x of ixIdsIn(c))if(S.ixp[x]!==undefined&&!S.myIx[x])u+=PORT_SLOT(S.ixp[x])*((S.ixn||{})[x]||1);
if(S.myIx[c])u+=1;
u+=S.caches.filter(x=>x.city===c).length+(S.nni||[]).filter(x=>x.city===c).length;
return u;}
function portsMax(c,g,rt){const p=S.pops[c];if(!p)return 0;return RG[g===undefined?(p.rgen||0):g].ports*(rt||p.routers||1);}
function portGate(c,add){if(!S.pops[c]||add<=0)return true;const u=portsUsed(c),m=portsMax(c);if(u+add<=m+1e-9)return true;
toast(`<b>No free router ports in ${esc(CITY[c].name)}.</b><br>${fmtPorts(u)} of ${m} in use. Add a router, or swap to a model with more ports (Infra tab).`,'bad');sfx('err');return false;}
const fmtPorts=u=>Number.isInteger(u)?String(u):u.toFixed(2).replace(/0+$/,'');
function modelFits(c,g){const G=RG[g],p=S.pops[c];if(!p)return '';
if(S.links.some(l=>(l.a===c||l.b===c)&&l.kind==='wave'&&l.tier>G.maxLT))return `A wave here is faster than ${G.pn}.`;
if([...S.transit,...S.pni].some(t=>t.city===c&&t.tier>G.maxP)||ixIdsIn(c).some(x=>S.ixp[x]!==undefined&&!S.myIx[x]&&S.ixp[x]>G.maxP))return `A port here is bigger than ${G.pn}.`;
if(S.links.some(l=>(l.a===c||l.b===c)&&l.kind==='df'&&(l.ch||[]).some(o=>OPT[o]&&OPT[o].rg>G.cls)))return 'A fibre here uses optics this model cannot take.';
if(portsUsed(c)>portsMax(c,g))return `You use ${fmtPorts(portsUsed(c))} ports here and ${p.routers||1} × ${G.n} only has ${portsMax(c,g)}.`;return '';}
// dark fiber & optical gear
const DF_SYS={
lite:{n:'Rainbow-in-a-Box DWDM',max:16,cost:25000,lvl:2,blurb:'Fixed mux plus amplifiers. Up to 16 channels, no remote switching.'},
@ -1529,7 +1556,7 @@ function sanitize(s){
s.priceMul=num(s.priceMul,1);s.nextFail=num(s.nextFail,s.day+45);s.nextEvent=num(s.nextEvent,s.day+40);s.lvl=int(s.lvl,1,4,1);s.neg=int(s.neg,0,1e7,0);s.loanStrikes=int(s.loanStrikes,0,1e3,0);
for(const k of Object.keys(s.stats)){const v=s.stats[k];if(k==='by'||k==='f'){if(!v||typeof v!=='object')s.stats[k]={};else for(const j of Object.keys(v))v[j]=num(v[j],0);}else if(typeof v!=='boolean')s.stats[k]=num(v,0);}
for(const k of ['survived','incidents','peak'])s.stats[k]=num(s.stats[k],0);
for(const c of Object.keys(s.pops)){const p=s.pops[c];if(!isCity(c)||!p||typeof p!=='object'){delete s.pops[c];continue;}p.routers=int(p.routers,1,4,1);if(p.rgen!==undefined)p.rgen=int(p.rgen,0,RG.length-1,0);p.down=num(p.down,0);if(p.bb&&typeof p.bb==='object')p.bb.d=num(p.bb.d,0);else p.bb=null;}
for(const c of Object.keys(s.pops)){const p=s.pops[c];if(!isCity(c)||!p||typeof p!=='object'){delete s.pops[c];continue;}p.routers=int(p.routers,1,RMAX,1);if(p.rgen!==undefined)p.rgen=int(p.rgen,0,RG.length-1,0);p.down=num(p.down,0);if(p.bb&&typeof p.bb==='object')p.bb.d=num(p.bb.d,0);else p.bb=null;}
if(!isCity(s.home))s.home=Object.keys(s.pops)[0]||'fra';
const tier=v=>int(v,0,PORT.length-1,0),lag=v=>int(v,1,LAG_MAX,1),sid=v=>String(v==null?uid():v).slice(0,40);
s.links=s.links.filter(l=>l&&isCity(l.a)&&isCity(l.b)&&l.a!==l.b).map(l=>{l.id=sid(l.id);l.km=num(l.km,kmBetween(l.a,l.b));l.mo=num(l.mo,0);l.cut=num(l.cut,0);if(l.kind!=='df'&&l.kind!=='vxc')l.kind='wave';if(l.kind==='wave')l.tier=int(l.tier,0,LT.length-1,0);if(l.cable&&!own(CAB,l.cable))l.cable=null;if(l.kind==='vxc'&&!own(VXC,l.vt))l.vt=0;if(l.kind==='df'){if(!own(DF_SYS,l.sys))l.sys='lite';l.ch=Array.isArray(l.ch)?l.ch.filter(o=>own(OPT,o)):[];l.ready=num(l.ready,0);}if(l.metric&&!own(MET,l.metric))l.metric='normal';return l;});
@ -1671,7 +1698,10 @@ function siteCtl(k,id,c,cur){const p=S.pops[c];if(!p||!p.site2)return '';cur=cur
function portOk(c,i){const p=S.pops[c];return i<=RG[p?(p.rgen||0):0].maxP;}
function waveOk(a,b,i){return [a,b].every(c=>i<=RG[S.pops[c]?(S.pops[c].rgen||0):0].maxLT);}
function waveNeed(i){const g=RG.find(r=>r.maxLT>=i);return g?g.n:'?';}
function portNote(c){const p=S.pops[c];if(!p)return '';const g=p.rgen||0;return g<RG.length-1&&RG[g].maxP<PORT.length-1?`<p class="note" style="margin-top:0">Your ${esc(RG[g].n)} here tops out at ${RG[g].pn} ports. Bigger ports need a router upgrade (Infra tab).</p>`:'';}
function routerModels(c){const p=S.pops[c],g=p.rgen||0,rt=p.routers||1;
return `<div style="margin-top:6px">${RG.map((M,i)=>{if(i===g)return '';const why=modelFits(c,i),lk=M.lvl>lvl();
return `<div class="row"><span class="logo" style="--c:${M.badge?'#2C7A7B':'#FF4F9A'}">${M.badge||'R'+(M.cls+1)}</span><div class="grow"><div class="nm">${esc(M.n)} <span class="meta">${M.pn} · ${M.ports} ports · ${fmtG(M.cap)} · boots in ~${M.boot} min${M.flaky?' · crashes more':''}</span></div><div class="meta">${esc(M.blurb)}</div>${why?`<div class="why">${esc(why)}</div>`:''}</div>${btn(lk?`Level ${M.lvl}`:`Swap <small>${fmt$(M.cost*rt)} + ${fmt$(M.mo*rt)}/mo</small>`,'upRouter',{city:c,g:i},'sm',lk||!!why||S.cash<M.cost*rt)}</div>`;}).join('')}</div>`;}
function portNote(c){const p=S.pops[c];if(!p)return '';const g=p.rgen||0;return RG[g].maxP<PORT.length-1?`<p class="note" style="margin-top:0">Your ${esc(RG[g].n)} here tops out at ${RG[g].pn} ports. Bigger ports need a router upgrade (Infra tab).</p>`:'';}
function sfOf(r,c){const d=r.cityDem[c]||0;return d<=1e-6?1:clamp(r.citySrv[c]/d,0,1);}
/* ---------- failures & events ---------- */
@ -1755,7 +1785,7 @@ function fireFailure(){
const msg=vn(l)&&Math.random()<0.8?pick([`Another of Vietnam’s subsea cables is broken: your ${A}–${B} link. The repair ship will come after the holidays. Which holidays is unclear.`,`Your ${A}–${B} cable broke in the same spot as last time. The repair crew recognised it.`]):!l.sub&&(l.a==='drw'||l.b==='drw')&&Math.random()<0.7?pick([`A crocodile took a bite out of your ${A}–${B} fiber. It was not impressed.`,`Termites ate the duct on ${A}–${B}. Then the fiber. Then the replacement duct.`]):tw(l)&&Math.random()<0.8?pick([`A cargo ship “forgot” to raise its anchor and dragged it across your ${A}–${B} cable. The owners are very sorry, and somewhat hard to reach.`,`Another anchor, another cut: your ${A}–${B} cable. The ship’s flag changed twice during the investigation.`,`A fishing boat with an unusually heavy anchor cut ${A}–${B}. It was not fishing.`]):!l.sub&&andesPair(l.a,l.b)?pick([`A landslide in the Andes buried your ${A}–${B} fiber.`,`Snow closed the mountain pass, and the repair crew with it: ${A}–${B} is down.`,`An earthquake shook your ${A}–${B} fiber loose somewhere above 4,000 metres.`,`A llama herd trampled the fiber marker on ${A}–${B}. Then a backhoe found the fiber.`]):!l.sub&&(CITY[l.a].india||CITY[l.b].india)?pick([`Road widening near ${A} cut your fiber to ${B}. It is always road widening.`,`The monsoon flooded a manhole on ${A}–${B}. The fiber is now underwater, as is the manhole.`,`A JCB-ish digger found your ${A}–${B} fiber. A different JCB-ish digger is coming to fix it.`]):l.sub?pick([`A curious shark bit your subsea cable ${A}–${B}.`,`A ship dragged its anchor across your ${A}–${B} cable.`,`An undersea landslide snapped ${A}–${B}.`]):pick([`A backhoe found your fiber between ${A} and ${B}.`,`Squirrels chewed through ${A}–${B}. They regret nothing.`,`Road works cut ${A}–${B}. Nobody called before digging.`]);
addInc({type,ref:tr,until:S.day+dur,msg:msg+(hit.length>1?` All ${hit.length} links in that trench went down with it.`:''),cost:Math.max(4000,Math.round(hit.reduce((a,x)=>a+x.mo,0)*0.5))});
}else if(type==='crash'||type==='power'){
const c=pick(Object.keys(S.pops).flatMap(x=>type==='power'&&(CITY[x].za||CITY[x].blackout)?[x,x,x]:[x])),pp=S.pops[c],slow=slowBoot(c),dur=(type==='crash'?2+Math.floor(Math.random()*2):3+Math.floor(Math.random()*3))*(type==='crash'&&S.ev.sanction>S.day?2:1)+(slow?2+Math.floor(Math.random()*3):0);
const c=pick(Object.keys(S.pops).flatMap(x=>type==='power'&&(CITY[x].za||CITY[x].blackout)?[x,x,x]:type==='crash'&&RG[S.pops[x].rgen||0].flaky?[x,x,x]:[x])),pp=S.pops[c],slow=slowBoot(c),dur=(type==='crash'?2+Math.floor(Math.random()*2):3+Math.floor(Math.random()*3))*(type==='crash'&&S.ev.sanction>S.day?2:1)+(slow?2+Math.floor(Math.random()*3):0);
if(type==='crash'&&(pp.routers||1)>=2){pp.rdown=S.day+dur;S.stats.incidents++;S.stats.survived++;toast(`<b>Router crash in ${CITY[c].name}</b><br>One router panicked and its twin took over.${slow?` The crashed one ${esc(pick(SLOW_BOOT))}.`:''} Capacity there is down one router for ${dur} days.`,'good');sfx('alert');return;}
if(type==='power'&&!pp.gen&&pp.site2){const sd=Math.random()<0.5?'a':'b';addInc({type:'site',ref:c,site:sd,until:S.day+dur,msg:`${CITY[c].za?'Load shedding':'A power cut'} took out ${siteName(c,sd)} in ${CITY[c].name}. ${siteName(c,sd==='a'?'b':'a')} kept going, so the POP runs at half capacity. Anything plugged in only at the dark site is offline.`,cost:5000,fix:'Rent a generator'});S.stats.survived++;return;}
if(type==='power'&&pp.gen&&CITY[c].blackout){S.stats.incidents++;S.stats.survived++;S.stats.shed=(S.stats.shed||0)+1;toast(`<b>Blackout in ${CITY[c].name}</b><br>The grid went dark again. Your generator started on the first try, like it always does here.`,'good');sfx('alert');return;}
@ -1950,7 +1980,7 @@ const BADGES=[
{id:'unsub',i:'📭',t:'Unsubscribed',d:'Opt out of 3 auto-enrolled add-ons.',r:'r',ok:()=>(st().optouts||0)>=3},
{id:'read',i:'💔',t:'Left on Read',d:'Get de-peered by a big network.',r:'r',ok:()=>(st().depeered||0)>=1},
{id:'couch',i:'🛋️',t:'Peering From the Couch',d:'Peer at an IX remotely.',r:'r',ok:()=>Object.keys(S.ixp).some(c=>isRemote(c)&&ixSessions(c).size>0)},
{id:'oink',i:'🐖',t:'Pig Whisperer',d:'Run a slow-booting PacketOinker chassis.',r:'r',ok:()=>Object.keys(S.pops).some(c=>(S.pops[c].rgen||0)>=2&&slowBoot(c))},
{id:'oink',i:'🐖',t:'Pig Whisperer',d:'Run a slow-booting PacketOinker chassis.',r:'r',ok:()=>Object.keys(S.pops).some(c=>/Oinker/.test(RG[S.pops[c].rgen||0].chip)&&slowBoot(c))},
{id:'gap',i:'🌴',t:'Mind the Gap',d:'Link Panama City and Bogotá.',r:'r',ok:()=>S.links.some(l=>[l.a,l.b].includes('pan')&&[l.a,l.b].includes('bog'))},
{id:'andes',i:'🏔️',t:'Over the Mountains',d:'Build fiber across the Andes.',r:'r',ok:()=>S.links.some(l=>!l.sub&&andesPair(l.a,l.b))},
{id:'duo',i:'🏜️',t:'Duopoly Customer',d:'Buy a wave inside the UAE.',r:'r',ok:()=>S.links.some(l=>uaePair(l.a,l.b))},
@ -2046,12 +2076,12 @@ const ACT={
buildPop:({city})=>{if(S.pops[city])return;if(cnCity(city)&&!cnOk()){toast('<b>You need a license first.</b><br>Foreign networks need a joint venture to build in mainland China.','bad');sfx('err');return;}if(!spend(popCost(city)))return;S.pops[city]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false};floater(CITY[city].x,CITY[city].y-30,'New POP!','#FF4F9A');UI.tab='cust';after();},
launchBB:({city})=>{const p=S.pops[city];if(!p||p.bb)return;const C=CITY[city];if(!spend(bbCost(city)))return;p.bb={d:Math.max(8,C.P*0.03)};floater(C.x,C.y-30,'Eyeballs online!','#16A866');after();},
ad:({city})=>{const p=S.pops[city];if(!p||!p.bb)return;if(!spend(8000))return;p.boost=S.day+30;floater(CITY[city].x,CITY[city].y-30,'Ad campaign!','#FF8A3D');after();},
buyTransit:({city,net,tier})=>{tier=+tier;if(scnRule('noTransit')){toast('<b>No transit in this scenario.</b><br>Peering, PNIs, caches and your own fiber only.','bad');sfx('err');return;}if(!S.pops[city]||!NET[net]||!NET[net].price||!NET[net].pops.includes(city)||!PORT[tier])return;if(!portOk(city,tier)){toast(`<b>Your router can't take a ${PORT[tier].n} port.</b><br>Upgrade it in the Infra tab.`,'bad');sfx('err');return;}const ex=S.transit.find(t=>t.city===city&&t.net===net);if(ex&&tier<=ex.tier)return;if(!spend(PORT[tier].setup*(ex&&ex.n||1)))return;if(ex)ex.tier=tier;else S.transit.push({id:uid(),city,net,tier,down:0});toast(`<b>${esc(NET[net].name)} transit is live in ${CITY[city].name}.</b><br>Full table received: ~1,000,000 routes.`,'good');after();},
lagT:({id,d})=>{d=+d;if(d!==1&&d!==-1)return;const t=S.transit.find(x=>x.id===id);if(!t)return;const n=(t.n||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0){if(!portOk(t.city,t.tier))return;if(!spend(PORT[t.tier].setup))return;}t.n=n;if(n<2&&t.site==='ab')t.site='a';toast(+d>0?`<b>LAG member added.</b><br>${esc(NET[t.net].name)} in ${CITY[t.city].name} is now ${lagName(t.tier,n)}.`:`<b>LAG member removed.</b>`,'good');after();},
lagP:({id,d})=>{d=+d;if(d!==1&&d!==-1)return;const p=S.pni.find(x=>x.id===id);if(!p)return;const n=(p.n||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0&&!spend(1500+PORT[p.tier].setup/2))return;p.n=n;if(n<2&&p.site==='ab')p.site='a';sfx('build');after();},
lagIx:({city,d})=>{d=+d;if(d!==1&&d!==-1)return;if(!isIx(city)||S.ixp[city]===undefined||S.myIx[city]||!S.pops[ixCity(city)])return;S.ixn=S.ixn||{};const n=(S.ixn[city]||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0&&!spend(ixPortMo(city,S.ixp[city])))return;S.ixn[city]=n;if(n<2&&S.ixSite&&S.ixSite[city]==='ab')S.ixSite[city]='a';sfx('build');after();},
buyTransit:({city,net,tier})=>{tier=+tier;if(scnRule('noTransit')){toast('<b>No transit in this scenario.</b><br>Peering, PNIs, caches and your own fiber only.','bad');sfx('err');return;}if(!S.pops[city]||!NET[net]||!NET[net].price||!NET[net].pops.includes(city)||!PORT[tier])return;if(!portOk(city,tier)){toast(`<b>Your router can't take a ${PORT[tier].n} port.</b><br>Upgrade it in the Infra tab.`,'bad');sfx('err');return;}const ex=S.transit.find(t=>t.city===city&&t.net===net);if(ex&&tier<=ex.tier)return;if(!portGate(city,ex?(PORT_SLOT(tier)-PORT_SLOT(ex.tier))*(ex.n||1):PORT_SLOT(tier)))return;if(!spend(PORT[tier].setup*(ex&&ex.n||1)))return;if(ex)ex.tier=tier;else S.transit.push({id:uid(),city,net,tier,down:0});toast(`<b>${esc(NET[net].name)} transit is live in ${CITY[city].name}.</b><br>Full table received: ~1,000,000 routes.`,'good');after();},
lagT:({id,d})=>{d=+d;if(d!==1&&d!==-1)return;const t=S.transit.find(x=>x.id===id);if(!t)return;const n=(t.n||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0){if(!portOk(t.city,t.tier)||!portGate(t.city,PORT_SLOT(t.tier)))return;if(!spend(PORT[t.tier].setup))return;}t.n=n;if(n<2&&t.site==='ab')t.site='a';toast(+d>0?`<b>LAG member added.</b><br>${esc(NET[t.net].name)} in ${CITY[t.city].name} is now ${lagName(t.tier,n)}.`:`<b>LAG member removed.</b>`,'good');after();},
lagP:({id,d})=>{d=+d;if(d!==1&&d!==-1)return;const p=S.pni.find(x=>x.id===id);if(!p)return;const n=(p.n||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0&&(!portGate(p.city,PORT_SLOT(p.tier))||!spend(1500+PORT[p.tier].setup/2)))return;p.n=n;if(n<2&&p.site==='ab')p.site='a';sfx('build');after();},
lagIx:({city,d})=>{d=+d;if(d!==1&&d!==-1)return;if(!isIx(city)||S.ixp[city]===undefined||S.myIx[city]||!S.pops[ixCity(city)])return;S.ixn=S.ixn||{};const n=(S.ixn[city]||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0&&(!portGate(ixCity(city),PORT_SLOT(S.ixp[city]))||!spend(ixPortMo(city,S.ixp[city]))))return;S.ixn[city]=n;if(n<2&&S.ixSite&&S.ixSite[city]==='ab')S.ixSite[city]='a';sfx('build');after();},
cancelTransit:({id})=>{if(UI.confirm!==id){UI.confirm=id;renderPanel();return;}S.transit=S.transit.filter(t=>t.id!==id);UI.confirm=null;after();},
buyIx:({city,tier,signed})=>{tier=+tier;if(!PORT[tier]||!ixName(city)||(!S.pops[ixCity(city)]&&(!remoteCities().includes(ixCity(city))||tier>1))||(S.ixp[city]!==undefined&&tier<=S.ixp[city]))return;if(S.pops[ixCity(city)]&&!portOk(ixCity(city),tier)){toast(`<b>Your router can't take a ${PORT[tier].n} port.</b><br>Upgrade it in the Infra tab.`,'bad');sfx('err');return;}
buyIx:({city,tier,signed})=>{tier=+tier;if(!PORT[tier]||!ixName(city)||(!S.pops[ixCity(city)]&&(!remoteCities().includes(ixCity(city))||tier>1))||(S.ixp[city]!==undefined&&tier<=S.ixp[city]))return;if(S.pops[ixCity(city)]&&!portOk(ixCity(city),tier)){toast(`<b>Your router can't take a ${PORT[tier].n} port.</b><br>Upgrade it in the Infra tab.`,'bad');sfx('err');return;}{const h0=S.ixp[city]!==undefined;if(!S.myIx[city]&&!portGate(ixCity(city),h0?(PORT_SLOT(tier)-PORT_SLOT(S.ixp[city]))*((S.ixn||{})[city]||1):PORT_SLOT(tier)))return;}
if(isDk(city)&&S.ixp[city]===undefined&&!signed){const dk=dkState();if(dk.stall>S.day){toast(`<b>DE-KICKS sales is still "aligning".</b><br>They will get back to you in ${dk.stall-S.day} days.`,'bad');sfx('err');return;}dk.lastQ=dk.lastQ||{};const lq=dk.lastQ[city];dk.q={city,tier,m:lq&&lq.until>S.day?lq.m:dkQuoteMult(),h:lq&&lq.until>S.day?lq.h:0};dk.lastQ[city]={m:dk.q.m,h:dk.q.h,until:S.day+90};dkQuoteModal();return;}const had=S.ixp[city]!==undefined;if(!spend(ixPortMo(city,tier)*(had?((S.ixn||{})[city]||1):1)))return;S.ixp[city]=tier;if(!had)toast(S.pops[ixCity(city)]?`<b>Port up at ${esc(ixName(city))}!</b><br>Now request peering, or join the route server.`:`<b>Remote port up at ${esc(ixName(city))}.</b><br>It came through a reseller, so expect a markup, a crowded port and some networks that won't talk to you. The route server is your friend here.`,'good');after();},
cancelIx:({city,sure})=>{if(UI.confirm!=='ix'+city){UI.confirm='ix'+city;renderPanel();return;}
if(isDk(city)&&!sure){const dk=dkState();if(!dk.retUsed[city]){openModal(`<div class="eyebrow">DE-KICKS Group · Customer Success</div><h2 style="font-size:26px">Wait! Before you go…</h2><p class="tagline">We value our partnership too much to let a little thing like price get in the way.</p><div class="kv"><span>Retention offer</span><b>40% off for 6 months</b></div><p class="note">After that, the normal price returns, plus a small loyalty administration fee.</p><div class="btns">${btn('Stay, take the discount','dkStay',{city},'pink')}${btn('Leave anyway','cancelIx',{city,sure:1},'ghost')}</div>`);return;}}
@ -2097,10 +2127,10 @@ const ACT={
peerAll:({city})=>{if(!isIx(city)||S.ixp[city]===undefined)return;const set=ixSessions(city);let n=0;for(const id of ixMembers(city))if(!set.has(id)&&peerOk(id,'ix',city).ok){S.peers[id+'@'+city]=true;n++;}if(!n)return;toast(`<b>${n} new session${n===1?'':'s'} at ${esc(ixName(city))}.</b><br>Small networks, but they add up, and they all count towards the club.`,'good');sfx('build');after();},
tailTog:()=>{UI.tailOpen=!UI.tailOpen;renderLeft();},
pni:({city,net,tier})=>{tier=+tier;if(!S.pops[city]||!NET[net]||!NET[net].pops.includes(city)||!PORT[tier])return;if(!portOk(city,tier)){toast(`<b>Your router can't take a ${PORT[tier].n} port.</b><br>Upgrade it in the Infra tab.`,'bad');sfx('err');return;}const r=peerOk(net,'pni',city);if(!r.ok){toast(`<b>${esc(NET[net].name)} declined the PNI.</b><br>${esc(r.why)}`,'bad');sfx('err');return;}if(S.conf&&S.conf.until>S.day)S.stats.beerPni=1;
const ex=S.pni.find(p=>p.city===city&&p.net===net);if(ex&&tier<=ex.tier)return;if(!spend((1500+PORT[tier].setup/2)*(ex&&ex.n||1)))return;if(ex)ex.tier=tier;else S.pni.push({id:uid(),city,net,tier});
const ex=S.pni.find(p=>p.city===city&&p.net===net);if(ex&&tier<=ex.tier)return;if(!portGate(city,ex?(PORT_SLOT(tier)-PORT_SLOT(ex.tier))*(ex.n||1):PORT_SLOT(tier)))return;if(!spend((1500+PORT[tier].setup/2)*(ex&&ex.n||1)))return;if(ex)ex.tier=tier;else S.pni.push({id:uid(),city,net,tier});
toast(`<b>PNI with ${esc(NET[net].name)} is up.</b><br>A cross-connect in ${esc(CITY[city].dc)}. Private and fast.`,'good');after();},
cancelPni:({id})=>{if(UI.confirm!==id){UI.confirm=id;renderPanel();return;}S.pni=S.pni.filter(p=>p.id!==id);UI.confirm=null;after();},
cache:({city,net})=>{const n=NET[net];if(!n||!n.cache||!S.pops[city]||S.caches.filter(x=>x.city===city&&x.net===net).length>=4)return;if((R.demTo[net]||0)<n.cache.min){toast(`<b>${esc(n.name)} says not yet.</b><br>Send them ${n.cache.min}+ Gbps first.`,'bad');sfx('err');return;}
cache:({city,net})=>{const n=NET[net];if(!n||!n.cache||!S.pops[city]||S.caches.filter(x=>x.city===city&&x.net===net).length>=4)return;if((R.demTo[net]||0)<n.cache.min){toast(`<b>${esc(n.name)} says not yet.</b><br>Send them ${n.cache.min}+ Gbps first.`,'bad');sfx('err');return;}if(!portGate(city,1))return;
S.caches.push({id:uid(),city,net});toast(`<b>${esc(n.cache.name)} installed in ${CITY[city].name}!</b><br>${esc(n.name)} shipped it for free. You pay ${fmt$(CACHE_MO)}/mo power.`,'good');sfx('build');after();},
rmCache:({id})=>{S.caches=S.caches.filter(c=>c.id!==id);after();},
accept:({id})=>{const o=S.offers.find(x=>x.id===id);if(!o)return;if(!bHas(o)){toast('<b>You need a POP in every city on the contract first.</b>','bad');return;}
@ -2121,11 +2151,11 @@ const ACT={
if((cnCity(a)||cnCity(b))&&!cnOk())return;
if(!waveOk(a,b,tier)){toast(`<b>A ${LT[tier].n} wave needs ${esc(waveNeed(tier))} routers at both ends.</b>`,'bad');sfx('err');return;}
const wr=waveRoute(a,b,mult,border);if(!wr){toast('<b>No cable available for that route right now.</b>','bad');sfx('err');return;}const base=Math.round(waveMo(wr.km,wr.sub,tier)*wr.wm),cost=base+(S.pops[b]?0:popCost(b));
if(!spend(cost))return;if(!S.pops[b])S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false};
if(!portGate(a,1)||!portGate(b,1))return;if(!spend(cost))return;if(!S.pops[b])S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false};
const id=uid();const l={id,a,b,kind:'wave',border,premium:border&&!!UI.cnPrem&&(a==='hkg'||b==='hkg'),tier,km:wr.km,sub:wr.sub,cable:wr.cab,mo:base,mult:wr.wm,trench:wr.cab?'cab:'+wr.cab:(same?(sib[0].trench||sib[0].id):id),cut:0,day:S.day};S.links.push(l);closeModal();
if(sib.length){UI.sel={type:'link',id};}else{UI.sel={type:'city',id:b};UI.tab='cust';}
floater((CITY[a].x+CITY[a].x+wrapDx(CITY[a].x,CITY[b].x))/2,(CITY[a].y+CITY[b].y)/2-20,`${LT[tier].n} lit!`,'#FF4F9A');after();},
buyNni:({city,prov,tier})=>{tier=+tier;if(!NNI[tier]||!isCity(city)||!own(FAB,prov)||!FAB[prov].cities.includes(city)||!S.pops[city])return;const ex=nniPort(city,prov);if(ex&&tier<=ex.tier)return;if(ex&&nniUsed(city,prov)>NNI[tier].g){toast('<b>Too many circuits</b> for a smaller port.','bad');return;}if(!spend(NNI[tier].mo))return;if(ex)ex.tier=tier;else S.nni.push({id:uid(),city,prov,tier});toast(`<b>${esc(FAB[prov].name)} port is up in ${CITY[city].name}.</b><br>Now order virtual circuits to other cities on their fabric.`,'good');after();},
buyNni:({city,prov,tier})=>{tier=+tier;if(!NNI[tier]||!isCity(city)||!own(FAB,prov)||!FAB[prov].cities.includes(city)||!S.pops[city])return;const ex=nniPort(city,prov);if(ex&&tier<=ex.tier)return;if(!ex&&!portGate(city,1))return;if(ex&&nniUsed(city,prov)>NNI[tier].g){toast('<b>Too many circuits</b> for a smaller port.','bad');return;}if(!spend(NNI[tier].mo))return;if(ex)ex.tier=tier;else S.nni.push({id:uid(),city,prov,tier});toast(`<b>${esc(FAB[prov].name)} port is up in ${CITY[city].name}.</b><br>Now order virtual circuits to other cities on their fabric.`,'good');after();},
rmNni:({city,prov})=>{if(nniUsed(city,prov)>0){toast('<b>Cancel the circuits on this port first.</b>','bad');sfx('err');return;}S.nni=S.nni.filter(x=>!(x.city===city&&x.prov===prov));after();},
openVxc:(a)=>openVxcModal(a),
buyVxc:({a,b,prov,t})=>{t=+t;const g=VXC[t].g,pa=nniPort(a,prov);if(!pa||nniUsed(a,prov)+g>NNI[pa.tier].g){toast('<b>Not enough room on your fabric port.</b> Upgrade it first.','bad');sfx('err');return;}
@ -2145,9 +2175,10 @@ const ACT={
setRoute:({id,m})=>{if(!own(RT,m))return;const b=S.biz.find(x=>x.id===id);if(b){b.route=m;sfx('click');after();}},
route:({r})=>{UI.route=r;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
addParallel:({id})=>{const l=S.links.find(x=>x.id===id);if(l)openLinkModal(l.a,l.b);},
addRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)>=4)return;if(!spend(routerCost(p.rgen||0)))return;p.routers=(p.routers||1)+1;floater(CITY[city].x,CITY[city].y-30,'Router added','#FF4F9A');after();},
rmRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)<=1)return;p.routers--;after();},
upRouter:({city})=>{const p=S.pops[city];if(!p)return;const g=(p.rgen||0)+1;if(!RG[g])return;if(RG[g].lvl>lvl()){toast(`<b>${esc(RG[g].n)} unlocks at customer level ${RG[g].lvl}.</b>`,'bad');sfx('err');return;}
addRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)>=RMAX)return;if(!spend(routerCost(p.rgen||0)))return;p.routers=(p.routers||1)+1;floater(CITY[city].x,CITY[city].y-30,'Router added','#FF4F9A');after();},
models:()=>{UI.models=!UI.models;renderPanel();},
rmRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)<=1)return;if(portsUsed(city)>portsMax(city,undefined,p.routers-1)){toast(`<b>Unplug something first.</b><br>${fmtPorts(portsUsed(city))} ports are in use, and one router fewer only has ${portsMax(city,undefined,p.routers-1)}.`,'bad');sfx('err');return;}p.routers--;after();},
upRouter:({city,g})=>{const p=S.pops[city];if(!p)return;g=g===undefined?RG[p.rgen||0].cls+1:+g;if(!RG[g]||g===(p.rgen||0))return;{const why=modelFits(city,g);if(why){toast(`<b>The ${esc(RG[g].n)} won't fit.</b><br>${esc(why)}`,'bad');sfx('err');return;}}if(RG[g].lvl>lvl()){toast(`<b>${esc(RG[g].n)} unlocks at customer level ${RG[g].lvl}.</b>`,'bad');sfx('err');return;}
const rt=p.routers||1;if(!spend(RG[g].cost*rt))return;p.rgen=g;
if(rt===1){const sl=slowBoot(city),dd=sl?3:1;p.down=Math.max(p.down||0,S.day+dd);addInc({type:'maint',ref:city,until:S.day+dd,msg:sl?`Swapping the only router in ${CITY[city].name} for a ${RG[g].n}. The new one ${pick(SLOW_BOOT)}. Back in ${dd} days.`:`Swapping the only router in ${CITY[city].name} for a ${RG[g].n}. Maintenance window: back tomorrow.`,cost:0});toast(`<b>Maintenance window in ${CITY[city].name}</b><br>${sl?`One router, and this one takes forever to boot. Back in ${dd} days.`:'One router means downtime during the swap. Back tomorrow.'}`,'bad');}
else toast(`<b>Rolling upgrade in ${CITY[city].name}</b><br>${rt} × ${esc(RG[g].n)}, swapped one at a time. Zero downtime.`,'good');
@ -2163,7 +2194,7 @@ const ACT={
const l={id,a,b,kind:'df',own,sys,ch:[],km,sub:!!sc,cable:sc?sc.cid:null,mo:own?Math.round(km*0.15):dfLeaseMo(km),trench:sc?'cab:'+sc.cid:id,cut:0,day:S.day,ready:S.day+(own?dfBuildDays(km):30),spares:false};
S.links.push(l);closeModal();UI.sel={type:'link',id};
toast(own?`<b>Groundbreaking!</b><br>Your own fiber from ${CITY[a].name} to ${CITY[b].name}. Permits and digging take about ${dfBuildDays(km)} days.`:`<b>Dark fiber IRU signed.</b><br>${CITY[a].name}–${CITY[b].name} will be spliced and handed over in about 30 days.`,'goal');after();},
addCh:({id,o})=>{const l=S.links.find(x=>x.id===id),O=OPT[o];if(!l||!O||l.kind!=='df')return;const why=chWhy(l,o);if(why){toast(`<b>Can't add ${O.n}.</b><br>${esc(why)}`,'bad');sfx('err');return;}if(!spend(optCost(o)))return;(l.ch=l.ch||[]).push(o);floater((CITY[l.a].x+CITY[l.b].x)/2,(CITY[l.a].y+CITY[l.b].y)/2-20,`+${O.n}`,'#FF4F9A');after();},
addCh:({id,o})=>{const l=S.links.find(x=>x.id===id),O=OPT[o];if(!l||!O||l.kind!=='df')return;const why=chWhy(l,o);if(why){toast(`<b>Can't add ${O.n}.</b><br>${esc(why)}`,'bad');sfx('err');return;}if(!portGate(l.a,1)||!portGate(l.b,1))return;if(!spend(optCost(o)))return;(l.ch=l.ch||[]).push(o);floater((CITY[l.a].x+CITY[l.b].x)/2,(CITY[l.a].y+CITY[l.b].y)/2-20,`+${O.n}`,'#FF4F9A');after();},
rmCh:({id,o})=>{const l=S.links.find(x=>x.id===id);if(!l)return;const i=(l.ch||[]).lastIndexOf(o);if(i>=0)l.ch.splice(i,1);after();},
upSys:({id})=>{const l=S.links.find(x=>x.id===id);if(!l||l.sys==='roadm'||lvl()<3)return;if(!spend(DF_SYS.roadm.cost))return;l.sys='roadm';if(l.ready<=S.day){l.eqDown=S.day+1;toast('<b>Line system swap</b><br>All channels are dark for a day while the ROADMs go in.','bad');}after();},
spares:({id})=>{const l=S.links.find(x=>x.id===id);if(!l)return;l.spares=!l.spares;sfx('click');after();},
@ -2206,7 +2237,7 @@ function dfAllowed(a,b){if(isSub(a,b))return !!subDfCable(a,b);return cnCity(a)=
function optCost(o){return Math.round(OPT[o].cost*(S&&S.ev&&S.ev.tariff>S.day?1.4:1));}
function chWhy(l,o){const O=OPT[o];if(O.lvl>lvl())return `Unlocks at customer level ${O.lvl}.`;if(O.sys==='roadm'&&l.sys!=='roadm')return 'Needs a ROADMaster 9000 line system.';if(l.km>O.reach)return `Reach is ${O.reach.toLocaleString()} km; this route is ${l.km.toLocaleString()} km.`;
if((l.ch||[]).length+soldSlots(l)>=DF_SYS[l.sys].max)return `${DF_SYS[l.sys].n} is full (${DF_SYS[l.sys].max} channels${soldSlots(l)?`, ${soldSlots(l)} sold to customers`:''}).`;
for(const c of [l.a,l.b]){const p=S.pops[c];if(p&&(p.rgen||0)<O.rg)return `Needs ${RG[O.rg].n} routers at both ends (${CITY[c].name}).`;}return '';}
for(const c of [l.a,l.b]){const p=S.pops[c];if(p&&RG[p.rgen||0].cls<O.rg)return `Needs ${RG[O.rg].n} routers at both ends (${CITY[c].name}).`;}return '';}
function bbCost(c){return 15000+CITY[c].P*20;}
function after(){if(S)purgeInc();compute();checkGoals();renderAll();save();}
const isTablet=()=>innerWidth>760&&innerWidth<=1200;
@ -2390,14 +2421,16 @@ function cityPanel(c){
h+=`</section>`;
}else{
const ls=S.links.filter(l=>l.a===c||l.b===c);
const rt=p.routers||1,g=p.rgen||0,G=RG[g],nl=R.nodeLoad[c]||0,nc=R.nodeCap[c]||nodeCap(c),N=RG[g+1];
const rt=p.routers||1,g=p.rgen||0,G=RG[g],nl=R.nodeLoad[c]||0,nc=R.nodeCap[c]||nodeCap(c),N=g===G.cls?RG[G.cls+1]:null,Ni=N?G.cls+1:-1,pu=portsUsed(c),pm=portsMax(c);
h+=`<section><h3>Routers</h3><p class="lead">The model sets your fastest interface and how much this POP can forward. More routers add capacity and survive crashes.</p>
<div class="row"><span class="logo" style="--c:#FF4F9A">R${g+1}</span><div class="grow"><div class="nm">${rt} × ${esc(G.n)}</div><div class="meta">Up to ${G.pn} interfaces · ${fmtG(G.cap)} per router · ${esc(G.blurb)}</div></div></div>
<div class="row"><span class="logo" style="--c:#FF4F9A">R${g+1}</span><div class="grow"><div class="nm">${rt} × ${esc(G.n)}</div><div class="meta">Up to ${G.pn} interfaces · ${G.ports} ports and ${fmtG(G.cap)} per router · ${esc(G.blurb)}</div></div></div>
<div class="kv"><span>Router ports</span><b>${fmtPorts(pu)} / ${pm} in use</b></div><div class="bar ${barCls(pu/pm)}"><i style="width:${Math.min(100,pu/pm*100)}%"></i></div>${pu>=pm?`<p class="why">Every port is taken. Add a router or swap to a model with more ports before you plug in anything new.</p>`:''}
<div class="kv"><span>Forwarding chip</span><b>${esc(G.chip)}</b></div><div class="kv"><span>Boot time</span><b>${slowBoot(c)?`<span style="color:var(--bad)">~${bootMin(c)} min · a slow one</span>`:`~${bootMin(c)} min`}</b></div>${slowBoot(c)?`<p class="note">This chassis takes forever to boot: crashes last longer, and swapping the only router here takes 3 days. A second router hides it.</p>`:''}
<div class="kv"><span>Forwarding load</span><b>${fmtG(nl)} / ${fmtG(nc)}</b></div><div class="bar ${barCls(nl/nc)}"><i style="width:${Math.min(100,nl/nc*100)}%"></i></div>
${nl>=nc*0.95?`<p class="why">Maxed out. Traffic here is being dropped.</p>`:''}
<div class="btns">${N?btn(N.lvl>lvl()?`${esc(N.n)} <small>level ${N.lvl}</small>`:`Upgrade to ${esc(N.n)} <small>${fmt$(N.cost*rt)} + ${fmt$(N.mo*rt)}/mo</small>`,'upRouter',{city:c},'pink',N.lvl>lvl()||S.cash<N.cost*rt):''}${rt<4?btn(`Add router <small>${fmt$(routerCost(g))} + ${fmt$(ROUTER_MO+G.mo)}/mo</small>`,'addRouter',{city:c},'',S.cash<routerCost(g)):''}${rt>1?btn('Remove one','rmRouter',{city:c},'ghost sm'):''}</div>
${N?`<p class="note">${rt>1?'Rolling upgrade: one router at a time, no downtime.':'With one router, the upgrade needs a maintenance window: this POP goes dark for a day.'}</p>`:''}
<div class="btns">${N?btn(N.lvl>lvl()?`${esc(N.n)} <small>level ${N.lvl}</small>`:`Upgrade to ${esc(N.n)} <small>${fmt$(N.cost*rt)} + ${fmt$(N.mo*rt)}/mo</small>`,'upRouter',{city:c,g:Ni},'pink',N.lvl>lvl()||S.cash<N.cost*rt):''}${btn(UI.models?'Hide other models':'Other models','models',{},'ghost sm')}${rt<RMAX?btn(`Add router <small>${fmt$(routerCost(g))} + ${fmt$(ROUTER_MO+G.mo)}/mo</small>`,'addRouter',{city:c},'',S.cash<routerCost(g)):''}${rt>1?btn('Remove one','rmRouter',{city:c},'ghost sm'):''}</div>
${UI.models?routerModels(c):''}
${N||UI.models?`<p class="note">${rt>1?'Rolling upgrade: one router at a time, no downtime.':'With one router, the upgrade needs a maintenance window: this POP goes dark for a day.'}</p>`:''}
<p class="note">${rt>=2?'A crash here only costs one router’s capacity for a few days.':'One router is a single point of failure.'}</p></section>
<section><h3>Metro diversity</h3>${p.site2?(()=>{const up=s=>[...S.transit.filter(t=>t.city===c&&onSite(t.site,s)).map(t=>NET[t.net].name+' transit'+(t.site==='ab'?' (split)':'')),...S.pni.filter(x=>x.city===c&&onSite(x.site,s)).map(x=>'PNI '+NET[x.net].name+(x.site==='ab'?' (split)':'')),...ixIdsIn(c).filter(x=>S.ixp[x]!==undefined&&!S.myIx[x]&&onSite((S.ixSite||{})[x],s)).map(x=>ixName(x)+' port'+((S.ixSite||{})[x]==='ab'?' (split)':'')),...(s==='a'?S.caches.filter(x=>x.city===c).map(x=>NET[x.net].cache.name):[])];
const row=s=>{const dn=siteDown(c,s),u=up(s);return `<div class="row"><span class="logo" style="--c:${s==='a'?'#FF4F9A':'#7B61FF'}">${s.toUpperCase()}</span><div class="grow"><div class="nm">${esc(siteName(c,s))}${dn?' <span class="tag restrictive">DOWN</span>':''}</div><div class="meta">${u.length?esc(u.join(', ')):'Nothing plugged in here yet'}</div></div></div>`;};
@ -2903,7 +2936,7 @@ function drawCity(C,sx,sy,sc,now,lyOverride){
if(p.gen){ctx.fillStyle='#FFD23F';rr(-27,-1,9,11,2);ctx.fill();ctx.stroke();}
ctx.fillStyle=down?'#8A91A8':'#FF4F9A';rr(-17,-7,34,16,6);ctx.fill();ctx.stroke();
if(!down&&(R.nodeLoad[C.id]||0)>=(R.nodeCap[C.id]||1e12)*0.95){for(let i=0;i<3;i++){const t=(now/700+i/3)%1;ctx.fillStyle=`rgba(90,98,130,${0.55*(1-t)})`;ctx.beginPath();ctx.arc(6+i*3,-12-t*18,3+t*4,0,7);ctx.fill();}}
if((p.rgen||0)>0){ctx.fillStyle='#FFD23F';ctx.beginPath();ctx.arc(17,-7,6,0,7);ctx.fill();ctx.lineWidth=1.8;ctx.stroke();ctx.fillStyle='#1E2640';ctx.font='900 8px Nunito, sans-serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(String((p.rgen||0)+1),17,-6.5);ctx.lineWidth=2.2;}
if((p.rgen||0)>0){const G=RG[p.rgen||0];ctx.fillStyle=G.badge?'#7CFFB2':'#FFD23F';ctx.beginPath();ctx.arc(17,-7,6,0,7);ctx.fill();ctx.lineWidth=1.8;ctx.stroke();ctx.fillStyle='#1E2640';ctx.font='900 8px Nunito, sans-serif';ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillText(G.badge||String(G.cls+1),17,-6.5);ctx.lineWidth=2.2;}
const sf=sfOf(R,C.id);
for(let i=0;i<4;i++){const on=down?false:(((now/(160+i*37))|0)+i)%3!==0;ctx.fillStyle=down?'#3B4260':on?(sf<0.9?'#FF4D5E':'#7CFFB2'):'#2A3150';ctx.beginPath();ctx.arc(-10+i*6.6,1,2.1,0,7);ctx.fill();}
if(down){ctx.fillStyle='#fff';ctx.font='900 14px "Baloo 2", sans-serif';ctx.textAlign='center';ctx.fillText('zzz',20,-14);}

View file

@ -287,3 +287,38 @@ test('Voda-Phony only peers for money now, and EU price wars cut port prices', (
assert.ok(ev("ixPortMo('ams',1)") < ev("__b"), 'price cut');
assert.deepEqual(errors, []);
});
test('router ports are finite: plugging in fills them, more routers or bigger models add room', () => {
const { ev, errors } = load();
ev("ACT.start({});S.cash=1e9;S.lvl=4;for(const g of GOALS)S.done[g.id]=0;ACT.buildPop({city:'ams'})");
assert.equal(ev("portsMax('ams')"), 8, 'one Rusty has 8 ports');
ev("for(const n of ['cog','lvl','tly','ntt','drz','tng'])ACT.buyTransit({city:'ams',net:n,tier:1});ACT.buyIx({city:'ams',tier:1});ACT.buyIx({city:'ams~2',tier:1})");
assert.equal(ev("portsUsed('ams')"), 8);
ev("ACT.buyIx({city:'ams~3',tier:1})");
assert.equal(ev("S.ixp['ams~3']"), undefined, 'no ninth port');
assert.match(ev("document.getElementById('toasts').textContent"), /No free router ports/);
ev("ACT.buyIx({city:'ams~3',tier:0})");
assert.equal(ev("S.ixp['ams~3']"), undefined, 'not even a 10G breakout');
ev("ACT.addRouter({city:'ams'})");
assert.equal(ev("portsMax('ams')"), 16);
ev("ACT.buyIx({city:'ams~3',tier:0})");
assert.equal(ev("S.ixp['ams~3']"), 0);
assert.equal(ev("portsUsed('ams')"), 8.25, '10G rides a breakout');
ev("ACT.rmRouter({city:'ams'})");
assert.equal(ev("S.pops.ams.routers"), 2, 'cannot remove a router whose ports are in use');
const arr = ev("RG.findIndex(r=>/Arrrhipster 7280/.test(r.n))");
assert.ok(arr > 0);
ev(`ACT.upRouter({city:'ams',g:${arr}})`);
assert.equal(ev("S.pops.ams.rgen"), arr, 'swapped to the Arrrhipster');
assert.equal(ev("portsMax('ams')"), 96);
assert.equal(ev("bootMin('ams')") < 30, true, 'boots fast');
ev("selectCity('ams');ACT.tab({t:'infra'});ACT.models()");
assert.match(ev("document.getElementById('panelBody').textContent"), /Knockia/);
const mk = ev("RG.findIndex(r=>/Mikrowtik/.test(r.n))");
ev("ACT.buyTransit({city:'ams',net:'cog',tier:2})");
assert.equal(ev("S.transit.find(t=>t.net==='cog'&&t.city==='ams').tier"), 2);
ev(`ACT.upRouter({city:'ams',g:${mk}})`);
assert.equal(ev("S.pops.ams.rgen"), arr, 'a smaller model that cannot fit is refused');
assert.ok(ev("RG.every(r=>r.ports>0&&r.cls>=0&&r.maxP<PORT.length)"));
assert.deepEqual(errors, []);
});