diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a183c5..fd6c7f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Fabric (NNI) ports now grow like your other ports: buy them at 10G, 100G or 400G (as fast as your router takes), and bundle up to eight into a LAG when one is not enough (#140). A fabric customer is no longer accepted, by hand or automatically, when its bandwidth would not fit on the port as well (#307). - Your own subsea cables now land right on the city's dot, also in Fujairah, Dubai, Karachi, Barcelona, Osaka and other cities the map shifts slightly so they do not overlap (#305). - Starting a new network no longer leaves the last one's "New POP!" and money pop-ups frozen all over the map until a reload. diff --git a/site/i18n/de.js b/site/i18n/de.js index 4ea2cb0..2e28851 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -1018,7 +1018,6 @@ "city_panel.pay_a_bigger_network_per_gbps":"Bezahl ein größeres Netz pro Gbps, und es trägt deinen Traffic ins ganze Internet. Abgerechnet wird nach dem 95. Perzentil der letzten 30 Tage, mit 20 % Commit und einer Portgebühr. Spitzen wie DDoS treiben deine Rechnung hoch.", "city_panel.peer_at_ix_without_building_a":"Peere am {ix}, ohne einen POP zu bauen. Bestell hier eine virtuelle Verbindung von einem deiner POPs über {fabs}.", "city_panel.port_cost_mo_mo":"{port} {cost} + {mo}/Monat", -"city_panel.port_port_price_mo":"{port}-Port · {price}/Monat", "city_panel.port_port_price_mo_197d":"{port}-Port {price}/Monat", "city_panel.power_cuts_are_covered":"Stromausfälle sind abgedeckt.", "city_panel.price_per_gbps_month_billed_on":"${price} pro Gbps / Monat · abgerechnet nach 95. Perzentil", diff --git a/site/i18n/es.js b/site/i18n/es.js index c702e7e..056ce73 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -1016,7 +1016,6 @@ "city_panel.pay_a_bigger_network_per_gbps":"Paga a una red mayor por Gbps y lleva tu tráfico a todo internet. Se factura sobre el percentil 95 de los últimos 30 días, con un compromiso del 20 % y una cuota de puerto. Los picos como los DDoS suben la factura.", "city_panel.peer_at_ix_without_building_a":"Haz peering en {ix} sin construir un POP. Pide aquí un circuito virtual desde uno de tus POPs por {fabs}.", "city_panel.port_cost_mo_mo":"{port} {cost} + {mo}/mes", -"city_panel.port_port_price_mo":"Puerto {port} · {price}/mes", "city_panel.port_port_price_mo_197d":"Puerto {port} {price}/mes", "city_panel.power_cuts_are_covered":"Los cortes de luz están cubiertos.", "city_panel.price_per_gbps_month_billed_on":"${price} por Gbps / mes · facturado al percentil 95", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 2691495..6938c0e 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -1016,7 +1016,6 @@ "city_panel.pay_a_bigger_network_per_gbps":"Paie un plus gros réseau au Gbps et il transporte ton trafic vers tout Internet. Facturé au 95e percentile des 30 derniers jours, avec un engagement de 20 % et des frais de port. Les pics comme les DDoS font grimper ta facture.", "city_panel.peer_at_ix_without_building_a":"Fais du peering sur {ix} sans construire de POP. Commande ici un circuit virtuel depuis un de tes POP via {fabs}.", "city_panel.port_cost_mo_mo":"{port} {cost} + {mo}/mois", -"city_panel.port_port_price_mo":"Port {port} · {price}/mois", "city_panel.port_port_price_mo_197d":"Port {port} {price}/mois", "city_panel.power_cuts_are_covered":"Les coupures de courant sont couvertes.", "city_panel.price_per_gbps_month_billed_on":"${price} par Gbps / mois · facturé au 95e percentile", diff --git a/site/i18n/it.js b/site/i18n/it.js index b266267..6b15279 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -1016,7 +1016,6 @@ "city_panel.pay_a_bigger_network_per_gbps":"Paga una rete più grande a Gbps e lei porta il tuo traffico verso tutta internet. Fatturato al 95° percentile degli ultimi 30 giorni, con un commit del 20% e un canone di porta. I picchi come i DDoS alzano la bolletta.", "city_panel.peer_at_ix_without_building_a":"Fai peering a {ix} senza costruire un POP. Ordina un circuito virtuale fin qui da uno dei tuoi POP tramite {fabs}.", "city_panel.port_cost_mo_mo":"{port} {cost} + {mo}/mese", -"city_panel.port_port_price_mo":"Porta {port} · {price}/mese", "city_panel.port_port_price_mo_197d":"Porta {port} {price}/mese", "city_panel.power_cuts_are_covered":"I blackout sono coperti.", "city_panel.price_per_gbps_month_billed_on":"${price} per Gbps / mese · fatturato al 95° percentile", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index 04430bb..092eea4 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -1016,7 +1016,6 @@ "city_panel.pay_a_bigger_network_per_gbps":"Pague por Gbps a uma rede maior e ela leva seu tráfego para a internet inteira. Cobrado pelo percentil 95 dos últimos 30 dias, com commit de 20% e taxa de porta. Picos como DDoS aumentam sua conta.", "city_panel.peer_at_ix_without_building_a":"Faça peering em {ix} sem construir um POP. Peça aqui um circuito virtual a partir de um dos seus POPs via {fabs}.", "city_panel.port_cost_mo_mo":"{port} {cost} + {mo}/mês", -"city_panel.port_port_price_mo":"Porta {port} · {price}/mês", "city_panel.port_port_price_mo_197d":"Porta {port} {price}/mês", "city_panel.power_cuts_are_covered":"Quedas de energia estão cobertas.", "city_panel.price_per_gbps_month_billed_on":"${price} por Gbps / mês · cobrado no percentil 95", diff --git a/src/agent/20-commands.js b/src/agent/20-commands.js index c243ed2..225e060 100644 --- a/src/agent/20-commands.js +++ b/src/agent/20-commands.js @@ -134,8 +134,11 @@ const API_CMD={ doc:'Hold a link in reserve: its capacity fills last.'}, /* ---------- fabrics and VXCs ---------- */ buyNni:{args:[['city','cityId'],['prov','fabId'],['tier','nniTier']], - quote:a=>({setup:NNI[a.tier]?NNI[a.tier].mo:undefined,monthly:NNI[a.tier]?NNI[a.tier].mo:undefined}), - doc:'Take a port on an interconnection fabric. Monthly. A higher tier upgrades unless the circuits on it already exceed the smaller port.'}, + quote:a=>{const ex=nniPort(a.city,a.prov),n=ex?(ex.n||1):1,m=NNI[a.tier]?NNI[a.tier].mo*n:undefined;return {setup:m,monthly:m};}, + doc:'Take a port on an interconnection fabric, at any port speed the router takes. Monthly, the first month up front. A higher tier upgrades every member of the port.'}, + lagNni:{args:[['city','cityId'],['prov','fabId'],['d','step']],watch:['nni'], + quote:a=>{const pt=nniPort(a.city,a.prov),m=pt&&a.d>0&&NNI[pt.tier]?NNI[pt.tier].mo:0;return {setup:m,monthly:m};}, + doc:'Add (d:1) or remove (d:-1) a member of the fabric port\'s LAG: same speed, one more router port, up to 8. Removing is rejected while the circuits would not fit.'}, rmNni:{args:[['city','cityId'],['prov','fabId']], doc:'Give the fabric port back. Rejected while circuits still use it.'}, buyVxc:{args:[['a','cityId'],['b','cityId'],['prov','fabId'],['t','vxcTier']], diff --git a/src/game/10-catalog/40-ports.js b/src/game/10-catalog/40-ports.js index 1f6f6d1..8712607 100644 --- a/src/game/10-catalog/40-ports.js +++ b/src/game/10-catalog/40-ports.js @@ -1,4 +1,4 @@ -/* Ports are finite. Every transit, IX, PNI and cache port, every wave and every fibre channel +/* Ports are finite. Every transit, IX, PNI, fabric 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; // Cache boxes sit behind an aggregation switch: one router port carries as many 100G boxes as its speed holds @@ -21,7 +21,8 @@ function portsUsed(c,g){let u=0; 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+=cachePorts(c,[],g)+(S.nni||[]).filter(x=>x.city===c).length; + for(const x of S.nni||[])if(x.city===c)u+=PORT_SLOT(x.tier)*(x.n||1); + u+=cachePorts(c,[],g); 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; @@ -31,6 +32,6 @@ const popIdle=c=>{const p=S.pops[c];return !!p&&!p.bb&&portsUsed(c)===0&&!S.biz. 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 tr('ports.a_wave_here_is_faster_than',{pn:G.pn}); - if([...S.transit,...S.pni].some(t=>t.city===c&&!t.pz&&t.tier>G.maxP)||ixIdsIn(c).some(x=>S.ixp[x]!==undefined&&!S.myIx[x]&&S.ixp[x]>G.maxP))return tr('ports.a_port_here_is_bigger_than',{pn:G.pn}); + if([...S.transit,...S.pni,...(S.nni||[])].some(t=>t.city===c&&!t.pz&&t.tier>G.maxP)||ixIdsIn(c).some(x=>S.ixp[x]!==undefined&&!S.myIx[x]&&S.ixp[x]>G.maxP))return tr('ports.a_port_here_is_bigger_than',{pn: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 tr('ports.a_fibre_here_uses_optics_this'); if(portsUsed(c,g)>portsMax(c,g))return tr('ports.you_use_u_ports_here_and',{u:fmtPorts(portsUsed(c,g)),r:p.routers||1,model:G.n,max:portsMax(c,g)});return '';} diff --git a/src/game/10-catalog/50-dark-fiber.js b/src/game/10-catalog/50-dark-fiber.js index b03c36a..f6a3889 100644 --- a/src/game/10-catalog/50-dark-fiber.js +++ b/src/game/10-catalog/50-dark-fiber.js @@ -33,7 +33,11 @@ const FABS=[ {id:'ccn',name:'Consolation Connect',col:'#8E44AD',cities:['icn','lon','fra','ams','mrs','bom','sin','hkg','tok','syd','lag','jnb'],blurb:tr('dark_fiber.strong_in_asia_and_africa_every')}, ]; const FAB=Object.fromEntries(FABS.map(f=>[f.id,f])); -const NNI=[{n:'10G',g:10,mo:500},{n:'100G',g:100,mo:1200}]; +/* A fabric port (NNI) comes in 10G, 100G or 400G, as fast as the router takes (portOk), and bundles into a LAG like + any other port (#140): more than 400G is more members. Fabrics sell nothing faster. Monthly, the first month up + front; cheaper per Gbps the faster it is. 10G and 100G keep the prices they always had. */ +const NNI_MO=[500,1200,3000]; +const NNI=NNI_MO.map((mo,i)=>({n:PORT[i].n,g:PORT[i].g,mo})); const VXC=[{n:'10G',g:10,m:1},{n:'50G',g:50,m:2.4},{n:'100G',g:100,m:3.6}]; const vxcMo=(km,sub,t)=>Math.round((150+km*0.12)*VXC[t].m*(sub?2:1)); const MET={prefer:{l:tr('common.prefer'),f:0.5},normal:{l:tr('common.normal'),f:1},avoid:{l:tr('common.avoid'),f:4},backup:{l:tr('common.backup_only'),f:60}}; diff --git a/src/game/80-simulation/30-compute.js b/src/game/80-simulation/30-compute.js index 236f877..8a86bc5 100644 --- a/src/game/80-simulation/30-compute.js +++ b/src/game/80-simulation/30-compute.js @@ -355,7 +355,7 @@ function computeMoney(R2){ C.pops=Object.entries(S.pops).reduce((a,[c,p])=>a+popMo(c)+((p.routers||1)-1)*ROUTER_MO+cageMo(p.routers)+(p.routers||1)*RG[p.rgen||0].mo+(p.gen?GEN_MO:0),0); C.optical=S.links.filter(l=>l.kind==='df').reduce((a,l)=>a+(l.ready>S.day?0:ampCount(l.km)*AMP_MO*(l.own&&isRdm(l.sys)&&!l.sub?Math.max(1,l.pairs|0):1)+(l.regen|0)*REGEN_MO)+(l.spares?Math.round(150+(l.ch||[]).length*80):0),0); C.links=S.links.reduce((a,l)=>a+(l.mo||0),0); - C.nni=(S.nni||[]).reduce((a,x)=>a+NNI[x.tier].mo,0); + C.nni=(S.nni||[]).reduce((a,x)=>a+nniMo(x),0); const htd=histToday();C.transit=S.transit.reduce((a,t)=>{const q=p95(t,R2.useT[t.id]||0,htd);R2.p95[t.id]=q;return a+transitMo(t,q);},0); C.ix=Object.keys(S.ixp).reduce((a,c)=>a+ixMo(c),0); C.pni=S.pni.reduce((a,p)=>a+pniMo(p,R2.usePni[p.id]||0),0); diff --git a/src/game/80-simulation/40-billing.js b/src/game/80-simulation/40-billing.js index f228005..b7dae0d 100644 --- a/src/game/80-simulation/40-billing.js +++ b/src/game/80-simulation/40-billing.js @@ -12,4 +12,7 @@ const krFee=(t,q)=>CITY[t.city].kr&&scnRule('sender')?Math.round(q*KR_FEE):0; function pniMo(p,use){if(!pniOn(p))return 0;return (p.g1?Math.round(PORT[0].pni/2):PORT[p.tier].pni)*(p.n||1)+(NET[p.net].pol==='paid'&&!paidFree(NET[p.net])?NET[p.net].paidFee:0)+(NET[p.net].perG?Math.round(NET[p.net].perG*use):0);} function ixMo(c){return S.myIx[c]?Math.round(myFab(c).mo*((S.ixSite||{})[c]==='ab'?1.5:1)):ixPortMo(c,S.ixp[c])*((S.ixn||{})[c]||1)+dkAddonMo(c);} function nniPort(c,prov){return (S.nni||[]).find(x=>x.city===c&&x.prov===prov);} +// What a fabric port can book: its speed times its members, a LAG at 95% like every bundle (lagCap). +function nniCap(pt){return pt&&NNI[pt.tier]?lagCap(NNI[pt.tier].g,pt.n):0;} +const nniMo=x=>NNI[x.tier]?NNI[x.tier].mo*(x.n||1):0; function repayCost(l,B){return B.equity?Math.round(l.amount*3):Math.round(Math.max(l.bal,B.crypto&&l.got?l.got:0)*1.02);} diff --git a/src/game/80-simulation/50-sanitize.js b/src/game/80-simulation/50-sanitize.js index 244437d..ce06274 100644 --- a/src/game/80-simulation/50-sanitize.js +++ b/src/game/80-simulation/50-sanitize.js @@ -123,7 +123,7 @@ function migrate(s){sanitize(s); for(const b of [...s.biz,...s.offers])if(Array.isArray(b.reqs))b.reqs=b.reqs.filter(k=>!REQS[k]||!REQS[k].can||(isCity(b.city)&&(!b.city2||isCity(b.city2))&&REQS[k].can(b,s)));if(s.ltv!==2){for(const l of s.links)if(l.kind==='wave'&&l.tier>=3)l.tier=Math.min(LT.length-1,l.tier+1);s.ltv=2;}if(s.dk){s.dk.m=s.dk.m||{};s.dk.add=s.dk.add||{};s.dk.ret=s.dk.ret||{};s.dk.retUsed=s.dk.retUsed||{};}s.hist=s.hist||[];s.loans=s.loans||[];s.loanOffers=s.loanOffers||[];s.loanStrikes=s.loanStrikes||0;for(const l of s.links||[])if(!l.kind)l.kind='wave'; for(const c in s.pops){const p=s.pops[c];if(p.rgen===undefined){let g=0;const need=(i,key)=>{const k=RG.findIndex(r=>r[key]>=i);if(k>g)g=k;}; for(const l of s.links||[])if((l.a===c||l.b===c)&&l.kind==='wave')need(l.tier,'maxLT'); - for(const t of s.transit||[])if(t.city===c)need(t.tier,'maxP');for(const x of s.pni||[])if(x.city===c)need(x.tier,'maxP');if(s.ixp&&s.ixp[c]!==undefined)need(s.ixp[c],'maxP');p.rgen=g;}}for(const b of s.biz||[])if(!b.reqs)b.reqs=BIZ_T[b.type]&&BIZ_T[b.type].div?['diverse']:[];for(const o of s.offers||[])if(!o.reqs)o.reqs=[];if(!s.lvl)s.lvl=1;s.nni=s.nni||[];s.cnLic=s.cnLic||{state:'none'};s.ev=s.ev||{};for(const l of s.links){if(!l.kind)l.kind='wave';if(l.mo===undefined)l.mo=Math.round(waveMo(l.km,l.sub,l.tier)*(l.mult||1));}for(const c in s.pops){if(!s.pops[c].routers)s.pops[c].routers=1;} + for(const t of s.transit||[])if(t.city===c)need(t.tier,'maxP');for(const x of s.pni||[])if(x.city===c)need(x.tier,'maxP');if(s.ixp&&s.ixp[c]!==undefined)need(s.ixp[c],'maxP');p.rgen=g;}}for(const b of s.biz||[])if(!b.reqs)b.reqs=BIZ_T[b.type]&&BIZ_T[b.type].div?['diverse']:[];for(const o of s.offers||[])if(!o.reqs)o.reqs=[];if(!s.lvl)s.lvl=1;s.nni=(Array.isArray(s.nni)?s.nni:[]).filter(x=>x&&own(FAB,x.prov)&&isCity(x.city)&&Number.isInteger(x.tier)&&!!NNI[x.tier]);for(const x of s.nni){const n=Math.floor(+x.n||1);if(n>1)x.n=Math.min(LAG_MAX,n);else delete x.n;}s.cnLic=s.cnLic||{state:'none'};s.ev=s.ev||{};for(const l of s.links){if(!l.kind)l.kind='wave';if(l.mo===undefined)l.mo=Math.round(waveMo(l.km,l.sub,l.tier)*(l.mult||1));}for(const c in s.pops){if(!s.pops[c].routers)s.pops[c].routers=1;} {const all=NETS.map(n=>n.id),seen=Array.isArray(s.seen)?s.seen.filter(x=>typeof x==='string'):null,fresh=seen?all.filter(id=>!seen.includes(id)):all; if(fresh.length&&(s.day||0)>0){const g=s.grace&&s.grace.until>s.day?s.grace:{nets:[]};s.grace={until:s.day+GRACE_DAYS,nets:[...new Set(g.nets.concat(fresh))],fresh:seen?fresh.length:0};} s.seen=all;} diff --git a/src/game/80-simulation/60-requirements.js b/src/game/80-simulation/60-requirements.js index ca97bd6..784a72d 100644 --- a/src/game/80-simulation/60-requirements.js +++ b/src/game/80-simulation/60-requirements.js @@ -1,7 +1,7 @@ const GRACE_DAYS=60; const REQS={ lat:{only:true,l2:true,bonus:0,l:o=>tr('requirements.one_way_latency_within_max_ms',{max:o.latMax,best:(()=>{const v=R.l2lat[o.id]!==undefined?R.l2lat[o.id]:bestLat(o.city,o.city2);return isFinite(v)?v.toFixed(1)+' ms':tr('common.no_path')})()}),ok:b=>(R.l2lat[b.id]!==undefined?R.l2lat[b.id]:bestLat(b.city,b.city2))<=b.latMax}, - nni:{only:true,bonus:0,l:o=>tr('requirements.comes_in_over_fab_needs_your',{fab:FAB[o.prov]?FAB[o.prov].name:'?',city:CITY[o.city].name,bw:fmtG(o.bw)}),ok:b=>{const pt=nniPort(b.city,b.prov);return !!pt&&nniUsed(b.city,b.prov)<=NNI[pt.tier].g+1e-9;}}, + nni:{only:true,bonus:0,l:o=>tr('requirements.comes_in_over_fab_needs_your',{fab:FAB[o.prov]?FAB[o.prov].name:'?',city:CITY[o.city].name,bw:fmtG(o.bw)}),ok:b=>{const pt=nniPort(b.city,b.prov);return !!pt&&nniUsed(b.city,b.prov)+(S.biz.includes(b)?0:b.bw)<=nniCap(pt)+1e-9;}}, diverse:{l:tr('requirements.two_paths_that_share_no_trench'),bonus:.25,l2:true,can:(b,s=S)=>diversityPossible(b.city,b.city2,s),ok:b=>R.div[b.id]!==undefined?!!R.div[b.id]:diversePaths(b.city,b.city2)}, sharks:{l:tr('requirements.afraid_of_sharks_needs_a_path'),bonus:.2,l2:true,ok:b=>terrestrialPath(b.city,b.city2),can:b=>!!b.city2&&!isSub(b.city,b.city2)}, nocog:{l:tr('requirements.refuses_cogentle_transit_anywhere_on'),bonus:.15,ok:()=>!S.transit.some(t=>t.net==='cog')}, diff --git a/src/game/90-actions/60-links.js b/src/game/90-actions/60-links.js index d9d1ffe..9848304 100644 --- a/src/game/90-actions/60-links.js +++ b/src/game/90-actions/60-links.js @@ -23,14 +23,22 @@ Object.assign(ACT,{ 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:(jn?jn.k: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,tr('links.wave_lit',{wave:LT[tier].n}),'#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&&!portGate(city,1))return;if(ex&&nniUsed(city,prov)>NNI[tier].g){toast(tr('links.too_many_circuits_for_a_smaller'),'bad');return;}if(!spend(NNI[tier].mo))return;if(ex)ex.tier=tier;else S.nni.push({id:uid(),city,prov,tier});toast(tr('links.fab_port_is_up_in_city',{fab:esc(FAB[prov].name),city:CITY[city].name}),'good');after();}, + // A new fabric port, or every member of one upgraded to a faster speed (#140): as fast as the router takes. + 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),n=ex?(ex.n||1):1;if(ex&&tier<=ex.tier)return; + if(!portOk(city,tier)){toast(tr('actions.your_router_can_t_take_a',{port:NNI[tier].n}),'bad');sfx('err');return;} + if(!portGate(city,(PORT_SLOT(tier)-(ex?PORT_SLOT(ex.tier):0))*n)||!spend(NNI[tier].mo*n))return;if(ex)ex.tier=tier;else S.nni.push({id:uid(),city,prov,tier});toast(tr('links.fab_port_is_up_in_city',{fab:esc(FAB[prov].name),city:CITY[city].name}),'good');after();}, + // A fabric port bundles into a LAG like transit and PNIs (#140): a member at the same speed, on a router port of its own. + lagNni:({city,prov,d})=>{d=+d;if(d!==1&&d!==-1)return;const pt=nniPort(city,prov);if(!pt||!NNI[pt.tier])return;const n=(pt.n||1)+d;if(n<1||n>LAG_MAX)return; + if(d>0){if(!portOk(city,pt.tier)){toast(tr('actions.your_router_can_t_take_a',{port:NNI[pt.tier].n}),'bad');sfx('err');return;}if(!portGate(city,PORT_SLOT(pt.tier))||!spend(NNI[pt.tier].mo))return;} + else if(nniUsed(city,prov)>lagCap(NNI[pt.tier].g,n)+1e-9){toast(tr('links.too_many_circuits_for_a_smaller'),'bad');sfx('err');return;} + if(n>1)pt.n=n;else delete pt.n;sfx('build');after();}, rmNni:({city,prov})=>{if(nniUsed(city,prov)>0){toast(tr('links.cancel_the_circuits_on_this_port'),'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;if(!CITY[a]||!CITY[b]||noTalk(a,b))return;const g=VXC[t].g,pa=nniPort(a,prov);if(!pa||nniUsed(a,prov)+g>NNI[pa.tier].g){toast(tr('links.not_enough_room_on_your_fabric'),'bad');sfx('err');return;} - if(S.pops[b]){const pb=nniPort(b,prov);if(!pb||nniUsed(b,prov)+g>NNI[pb.tier].g){toast(tr('links.not_enough_room_on_your_fab',{fab:esc(FAB[prov].name),city:CITY[b].name}),'bad');sfx('err');return;}} + buyVxc:({a,b,prov,t})=>{t=+t;if(!CITY[a]||!CITY[b]||noTalk(a,b))return;const g=VXC[t].g,pa=nniPort(a,prov);if(!pa||nniUsed(a,prov)+g>nniCap(pa)+1e-9){toast(tr('links.not_enough_room_on_your_fabric'),'bad');sfx('err');return;} + if(S.pops[b]){const pb=nniPort(b,prov);if(!pb||nniUsed(b,prov)+g>nniCap(pb)+1e-9){toast(tr('links.not_enough_room_on_your_fab',{fab:esc(FAB[prov].name),city:CITY[b].name}),'bad');sfx('err');return;}} const km=kmBetween(a,b),sub=isSub(a,b),mo=vxcMo(km,sub,t);if(!spend(mo))return;S.links.push({id:uid(),a,b,kind:'vxc',prov,vt:t,km,sub,mo,cut:0,day:S.day});closeModal(); toast(tr('links.circuit_up_in_59_seconds_vxc',{vxc:VXC[t].n,fab:esc(FAB[prov].name),a:CITY[a].name,b:CITY[b].name})+(S.pops[b]?'':' '+tr('links.now_grab_an_ix_port_there')),'good');if(!S.pops[b])selectCity(b);after();}, - upVxc:({id,t})=>{t=+t;const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='vxc'||!VXC[t]||t<=l.vt)return;const extra=VXC[t].g-VXC[l.vt].g;for(const c of [l.a,l.b]){const pt=nniPort(c,l.prov);if(pt&&nniUsed(c,l.prov)+extra>NNI[pt.tier].g){toast(tr('links.fabric_port_in_city_is_full',{city:CITY[c].name}),'bad');sfx('err');return;}}const mo=vxcMo(l.km,l.sub,t);if(!spend(mo))return;l.vt=t;l.mo=mo;after();}, + upVxc:({id,t})=>{t=+t;const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='vxc'||!VXC[t]||t<=l.vt)return;const extra=VXC[t].g-VXC[l.vt].g;for(const c of [l.a,l.b]){const pt=nniPort(c,l.prov);if(pt&&nniUsed(c,l.prov)+extra>nniCap(pt)+1e-9){toast(tr('links.fabric_port_in_city_is_full',{city:CITY[c].name}),'bad');sfx('err');return;}}const mo=vxcMo(l.km,l.sub,t);if(!spend(mo))return;l.vt=t;l.mo=mo;after();}, cancelVxc:({id})=>{if(UI.confirm!==id){UI.confirm=id;renderPanel();return;}S.links=S.links.filter(l=>l.id!==id);prunePairMet();const rem=remoteCities();for(const c in S.ixp){if(!S.pops[ixCity(c)]&&!rem.includes(ixCity(c))){delete S.ixp[c];delete S.rs[c];for(const k in S.peers)if(k.endsWith('@'+c))delete S.peers[k];}}UI.sel=null;UI.confirm=null;after();}, setPref:({kind,id,v})=>{if(!own(PREF,v))return;if(kind!=='t'&&kind!=='p'&&!(isIx(id)&&S.ixp[id]!==undefined))return;if(kind==='t'){const t=S.transit.find(x=>x.id===id);if(t)t.pref=v;}else if(kind==='p'){const x=S.pni.find(y=>y.id===id);if(x)x.pref=v;}else{S.ixPref=S.ixPref||{};S.ixPref[id]=v;}sfx('click');after();}, setMetric:({id,v})=>{if(v!=='custom'&&!own(MET,v))return;const l=S.links.find(x=>x.id===id);if(!l)return;const m=S.pairMet||(S.pairMet={}),k=edgeKey(l); diff --git a/src/game/93-ui/50-city-panel.js b/src/game/93-ui/50-city-panel.js index 17993d9..ed2eb74 100644 --- a/src/game/93-ui/50-city-panel.js +++ b/src/game/93-ui/50-city-panel.js @@ -97,8 +97,10 @@ function cityPanel(c){ if(fabs.length){h+=`

${tr('city_panel.interconnection_fabrics_nni')}

${tr('city_panel.buy_a_port_on_a_fabric')}

`; for(const f of fabs){const pt=nniPort(c,f.id),used=nniUsed(c,f.id); h+=`
${esc(f.name)}
${esc(f.blurb)}
`; - if(pt){const cap=NNI[pt.tier].g;h+=`
${tr('city_panel.port_port_price_mo',{port:NNI[pt.tier].n,price:fmt$(NNI[pt.tier].mo)})}${tr('city_panel.g_of_circuits',{g:fmtG(used)})}
${btn(tr('common.new_circuit'),'openVxc',{from:c,prov:f.id},'pink sm')}${pt.tier<1?btn(tr('common.upgrade_port_price_mo',{port:NNI[1].n,price:fmt$(NNI[1].mo)}),'buyNni',{city:c,prov:f.id,tier:1},'sm'):''}${btn(tr('common.remove_port'),'rmNni',{city:c,prov:f.id},'ghost sm')}
`;} - else h+=`
${NNI.map((N,i)=>btn(tr('city_panel.port_port_price_mo_197d',{port:N.n,price:fmt$(N.mo)}),'buyNni',{city:c,prov:f.id,tier:i},'sm',S.cash`; + // Every speed the router takes, every member a LAG may have (#140), as for transit and PNIs. + if(pt){const n=pt.n||1,N=NNI[pt.tier],cap=nniCap(pt),up=(N2,i)=>{const a={port:N2.n,cost:fmt$(N2.mo*n),mo:fmt$(N2.mo*n)};return btn(n>1?tr('common.upgrade_all_to_port_cost_mo',a):tr('common.upgrade_port_price_mo',{port:N2.n,price:fmt$(N2.mo)}),'buyNni',{city:c,prov:f.id,tier:i},'sm',S.cash${lagName(pt.tier,n)} · ${portMo(N.mo*n)}${tr('city_panel.g_of_circuits',{g:fmtG(used)})} / ${fmtG(cap)}
${btn(tr('common.new_circuit'),'openVxc',{from:c,prov:f.id},'pink sm')}${NNI.map((N2,i)=>i>pt.tier&&portShown(i)?up(N2,i):'').join('')}${n1?btn(tr('common.member'),'lagNni',{city:c,prov:f.id,d:-1},'ghost sm'):''}${btn(tr('common.remove_port'),'rmNni',{city:c,prov:f.id},'ghost sm')}
`;} + else h+=`
${NNI.map((N,i)=>portShown(i)?btn(tr('city_panel.port_port_price_mo_197d',{port:N.n,price:fmt$(N.mo)}),'buyNni',{city:c,prov:f.id,tier:i},'sm',S.cash`; h+=`
`;} h+=`
`;} h+=`

${tr('city_panel.fiber_from_city',{city:C.name})}

${tr('city_panel.drag_from_this_router_to_any')}

`; diff --git a/src/game/94-dashboard/40-connections.js b/src/game/94-dashboard/40-connections.js index 568a32b..8a894a9 100644 --- a/src/game/94-dashboard/40-connections.js +++ b/src/game/94-dashboard/40-connections.js @@ -11,7 +11,7 @@ function conns(){const out=[],pn=(tier,n)=>(n||1)>1?`${n}×${PORT[tier].n} LAG`: for(const c in S.ixp){const ses=ixSessions(c),mine=!!S.myIx[c];out.push({k:'ix',id:c,city:ixCity(c),net:null,nets:[...ses],name:ixName(c),port:mine?tr('common.your_exchange'):pn(S.ixp[c],(S.ixn||{})[c]),cap:ixCap(c),use:R.useIx[c]||0,mo:ixMo(c),mine,down:!!(S.ev.ixdown&&S.ev.ixdown[c]>S.day),low:(S.ixPref&&S.ixPref[c])==='low',note:trn('connections.n_peering_session',ses.size)+(isRemote(c)?' · '+tr('common.remote'):'')});} const cg={};for(const x of S.caches){const key=x.city+'|'+x.net;(cg[key]=cg[key]||[]).push(x);} for(const key in cg){const g=cg[key],x=g[0];out.push({k:'c',id:x.id,n:g.length,city:x.city,net:x.net,name:NET[x.net].cache.name,port:trn('common.n_box',g.length),cap:g.reduce((a,y)=>a+cacheG(y),0),use:g.reduce((a,y)=>a+(R.useCache[y.id]||0),0),mo:g.reduce((a,y)=>a+cacheMo(y),0),down:!popUp(x.city),low:false,note:tr('common.from_net',{net:NET[x.net].name})});} - for(const x of S.nni||[])if(FAB[x.prov]&&NNI[x.tier])out.push({k:'nni',id:x.city+'|'+x.prov,city:x.city,net:null,name:FAB[x.prov].name,port:NNI[x.tier].n,cap:NNI[x.tier].g,use:nniUsed(x.city,x.prov),mo:NNI[x.tier].mo,down:!popUp(x.city),low:false,note:tr('connections.virtual_circuits_and_fabric')}); + for(const x of S.nni||[])if(FAB[x.prov]&&NNI[x.tier])out.push({k:'nni',id:x.city+'|'+x.prov,city:x.city,net:null,name:FAB[x.prov].name,port:pn(x.tier,x.n),cap:nniCap(x),use:nniUsed(x.city,x.prov),mo:nniMo(x),down:!popUp(x.city),low:false,note:tr('connections.virtual_circuits_and_fabric')}); return out;} // Cancel straight from the list, with the same "Really?" step as the POP panel. // Grow a connection from the list: the next port size and one more LAG member, same actions and prices as the POP panel. @@ -26,7 +26,9 @@ function connUp(r){if(r.mine)return '';const nx=t=>PORT[t+1]&&portShown(t+1)?t+1 if(i>=0)h+=btn(tr('common.upgrade_port_price',{port:PORT[i].n,price:portMo(ixPortMo(c,i)*n)}),'buyIx',{city:c,tier:i},'sm',(!!S.pops[city]&&!portOk(city,i))||(!S.pops[city]&&i>1)); if(S.pops[city]&&!S.myIx[c]&&n=0){const c=NNI[i].mo*n;h+=btn(n>1?tr('common.upgrade_all_to_port_cost_mo',{port:NNI[i].n,cost:fmt$(c),mo:fmt$(c)}):tr('common.upgrade_port_price_mo',{port:NNI[i].n,price:fmt$(c)}),'buyNni',{city,prov,tier:i},'sm',S.cash1?tr('common.box_6ee3'):r.k==='nni'?tr('common.remove_port'):tr('common.remove'),'connCancel',{k:r.k,id:r.id},on?'red sm':'ghost sm');} diff --git a/src/game/94-dashboard/90-noc-window.js b/src/game/94-dashboard/90-noc-window.js index db66bed..d833449 100644 --- a/src/game/94-dashboard/90-noc-window.js +++ b/src/game/94-dashboard/90-noc-window.js @@ -6,7 +6,7 @@ const NOC_HB=3000,NOC_LOST=10000,NOC_GAP=1000; // What a click in the window does: changes only its own view, or runs in the game. Every button the dashboard draws is in one list. const NOC_LOCAL=['chartToggle','connCity','connF','connNet','connSort','custCity','custF','custSort','dashClose','dashSort','dashTab','listMore','popsReg','popsSort']; -const NOC_GO=['buyIx','buyNni','buyTransit','cache','connCancel','custGo','dashLink','goConn','lagIx','lagP','lagT','leaseSwap','netFocus','opsOpen','pni','pniAllOpen','popGo']; +const NOC_GO=['buyIx','buyNni','buyTransit','cache','connCancel','custGo','dashLink','goConn','lagIx','lagNni','lagP','lagT','leaseSwap','netFocus','opsOpen','pni','pniAllOpen','popGo']; const NOC={win:false,id:null,ctl:null,st:null,stId:null,peer:false,until:0,dirty:false,sent:0,speed:1,hid:false,yoAt:0,gone:false}; {const id=RW_IN?null:new URLSearchParams(location.search).get('noc');if(slotOkId(id)){NOC.win=true;NOC.id=id;}} if(!RW_IN)try{if(typeof BroadcastChannel==='function'){NOC.ctl=new BroadcastChannel('sot-noc');NOC.ctl.onmessage=e=>{const m=e.data;if(!m||typeof m!=='object'||!slotOkId(m.id))return;if(NOC.win)nocWinMsg(m);else nocGameMsg(m);};}}catch(e){} diff --git a/src/game/95-modals/90-fiber-modals.js b/src/game/95-modals/90-fiber-modals.js index 9e66fc7..7e7b619 100644 --- a/src/game/95-modals/90-fiber-modals.js +++ b/src/game/95-modals/90-fiber-modals.js @@ -22,7 +22,7 @@ function dfModalBody(a,b,km,pop){ function openVxcModal({from,to,prov}){ let rows='';const row=(f,a,b)=>{const km=kmBetween(a,b),sub=isSub(a,b),pb=S.pops[b]?nniPort(b,f.id):null,remote=!S.pops[b]; const label=remote?tr('fiber_modals.remote_peering_at_ix_discouraged',{ix:esc(CITY[b].ix)}):pb?tr('common.your_pop'):tr('fiber_modals.your_pop_needs_a_fabric_port'); - const freeA=nniPort(a,f.id)?NNI[nniPort(a,f.id).tier].g-nniUsed(a,f.id):0,freeB=remote?1e9:pb?NNI[pb.tier].g-nniUsed(b,f.id):0; + const freeA=nniCap(nniPort(a,f.id))-nniUsed(a,f.id),freeB=remote?1e9:pb?nniCap(pb)-nniUsed(b,f.id):0; return `
${CITY[a].name} → ${CITY[b].name}
${label} · ${km.toLocaleString()} km${sub?' '+tr('common.subsea'):''}
${VXC.map((V,t)=>btn(`${V.n} ${tr('common.price_mo',{price:fmt$(vxcMo(km,sub,t))})}`,'buyVxc',{a,b,prov:f.id,t},'sm',(!remote&&!pb)||V.g>freeA||V.g>freeB||S.cash
`;}; for(const f of FABS){if(prov&&f.id!==prov)continue; diff --git a/src/i18n/en.js b/src/i18n/en.js index c34f7df..778aa46 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -1017,7 +1017,6 @@ "city_panel.pay_a_bigger_network_per_gbps":"Pay a bigger network per Gbps and it carries your traffic to the whole internet. Billed on the 95th percentile of the last 30 days, with a 20% commit and a port fee. Spikes like DDoS raise your bill.", "city_panel.peer_at_ix_without_building_a":"Peer at {ix} without building a POP. Order a virtual circuit here from one of your POPs over {fabs}.", "city_panel.port_cost_mo_mo":"{port} {cost} + {mo}/mo", -"city_panel.port_port_price_mo":"{port} port · {price}/mo", "city_panel.port_port_price_mo_197d":"{port} port {price}/mo", "city_panel.power_cuts_are_covered":"Power cuts are covered.", "city_panel.price_per_gbps_month_billed_on":"${price} per Gbps / month · billed on 95th percentile", diff --git a/tests/issues.test.js b/tests/issues.test.js index 9e4f696..b55b995 100644 --- a/tests/issues.test.js +++ b/tests/issues.test.js @@ -770,7 +770,8 @@ test('connections in the NOC dashboard can be upgraded and grown into LAGs right assert.equal(ev("S.ixp.ams"), 2); assert.ok(tap('buyNni')); assert.equal(ev("S.nni[0].tier"), 1); - assert.equal(ev("document.querySelector('#dashCard [data-act=\"buyNni\"]')"), null, 'no upgrade past the biggest fabric port'); + assert.ok(tap('lagNni'), 'a fabric port bundles into a LAG too (#140)'); + assert.equal(ev("S.nni[0].n"), 2); assert.equal(ev("document.getElementById('dash').hidden"), false); assert.deepEqual(errors, []); }); diff --git a/tests/mcp-commands.test.js b/tests/mcp-commands.test.js index 6e5a562..f88e4ae 100644 --- a/tests/mcp-commands.test.js +++ b/tests/mcp-commands.test.js @@ -220,7 +220,7 @@ test('a dry run prices every command that has a price, and changes nothing', () addGen: { city: 'fra' }, addSite: { city: 'fra' }, buyTransit: { city: 'fra', net: 'cog', tier: 2 }, lagT: { id: ev('S.transit[0].id'), d: 1 }, cleanPipe: { id: ev('S.transit[0].id') }, buyIx: { city: 'ams', tier: 1 }, foundIx: { city: 'nyc' }, myIxUp: { city: 'nyc' }, pni: { city: 'fra', net: 'lvl', tier: 1 }, cache: { city: 'fra', net: 'nfx' }, buildLink: { a: 'fra', b: 'nyc', tier: 1 }, upLink: { id: wave, tier: 2 }, - rmLink: { id: wave }, buyNni: { city: 'fra', prov: fab, tier: 0 }, buyVxc: { a: 'fra', b: 'ams', prov: fab, t: 0 }, upVxc: { id: wave, t: 1 }, + rmLink: { id: wave }, buyNni: { city: 'fra', prov: fab, tier: 0 }, lagNni: { city: 'fra', prov: fab, d: 1 }, buyVxc: { a: 'fra', b: 'ams', prov: fab, t: 0 }, upVxc: { id: wave, t: 1 }, orderDf: { a: 'fra', b: 'ams', source: 'lease', system: 'lite' }, orderCable: { a: 'lis', b: 'nyc' }, subUpgrade: { id: df, k: 'terminal' }, crews: { id: df }, addCh: { id: df, o: 'zr4' }, addPair: { id: df }, upSys: { id: df }, regen: { id: df, d: 1 }, buySpare: { o: 'zr4' }, sellSpare: { o: 'zr4' }, setChCount: { id: df, o: 'zr4', n: 2 }, repayLoan: { id: 'none' }, buildScrub: { city: 'ams', tier: 1 }, scrubUp: { city: 'fra', tier: 1 }, diff --git a/tests/nni.test.js b/tests/nni.test.js new file mode 100644 index 0000000..ad84b1b --- /dev/null +++ b/tests/nni.test.js @@ -0,0 +1,138 @@ +// Fabric ports (NNI) are ports like any other (#140): 10G, 100G or 400G as far as the router takes it, bundled into a +// LAG up to LAG_MAX, a router port per member. A customer coming in over the fabric is only accepted, by hand or automatically, when its +// own bandwidth fits on the port as well as what is booked there already (#307). +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { load } = require('./harness'); + +// Frankfurt, with a POP, money, and a fabric that is there; the router as given (Rusty Router: 100G at most). +function open(rg) { + const h = load({ seed: 140 }); + h.ev("ACT.start({});S.cash=1e9;S.lvl=6;for(const g of GOALS)S.done[g.id]=0;window.FB=FABS.find(f=>f.cities.includes('fra')).id;S.pops.fra.rgen=0;S.pops.fra.routers=1"); + if (rg !== undefined) h.ev(`S.pops.fra.rgen=${rg}`); + return h; +} +const fast = (maxP) => `RG.findIndex(r=>r.maxP>=${maxP}&&r.ports>=40)`; +const port = (ev) => JSON.parse(ev("JSON.stringify(nniPort('fra',FB)||null)")); +const live = (id, bw) => `S.biz.push({id:'${id}',type:'fabip',city:'fra',prov:FB,bw:${bw},rate:110,reqs:['nni'],mood:100,since:S.day,name:'Fab ${id}'});compute()`; +const offer = (id, bw) => `S.offers.push({id:'${id}',type:'fabip',city:'fra',prov:FB,bw:${bw},rate:110,reqs:['nni'],exp:S.day+30,name:'Offer ${id}',start:S.day,dur:365})`; + +test('10G, 100G and 400G, priced so a faster port costs less per Gbps; 10G and 100G keep their prices', () => { + const { ev } = open(); + const t = JSON.parse(ev('JSON.stringify({nni:NNI,port:PORT.map(p=>[p.n,p.g])})')); + assert.deepEqual(t.nni.map((x) => [x.n, x.g]), t.port.slice(0, 3), 'the port speeds up to 400G, and no faster'); + assert.deepEqual(t.nni.slice(0, 2).map((x) => x.mo), [500, 1200], 'the sizes saves already have cost what they did'); + for (let i = 1; i < t.nni.length; i++) { + assert.ok(t.nni[i].mo > t.nni[i - 1].mo, `${t.nni[i].n} costs more`); + assert.ok(t.nni[i].mo / t.nni[i].g < t.nni[i - 1].mo / t.nni[i - 1].g, `but less per Gbps than ${t.nni[i - 1].n}`); + } +}); + +test('a fabric port is as fast as the router takes, up to 400G', () => { + const { ev, errors } = open(); + ev('ACT.buyNni({city:"fra",prov:FB,tier:2})'); + assert.equal(port(ev), null, 'a 100G router cannot take a 400G fabric port'); + ev('ACT.buyNni({city:"fra",prov:FB,tier:1})'); + assert.equal(port(ev).tier, 1); + ev(`S.pops.fra.rgen=${fast(5)};ACT.buyNni({city:"fra",prov:FB,tier:5});ACT.buyNni({city:"fra",prov:FB,tier:3})`); + assert.equal(port(ev).tier, 1, 'even a 3.2T router gets no fabric port faster than 400G'); + ev('ACT.buyNni({city:"fra",prov:FB,tier:2})'); + assert.equal(port(ev).tier, 2); + assert.equal(ev('nniCap(nniPort("fra",FB))'), 400); + // A router that cannot take 400G would strand it, so the model change is refused. + assert.match(ev("modelFits('fra',RG.findIndex(r=>r.maxP===1))"), /bigger than/); + assert.deepEqual(errors, []); +}); + +test('a fabric port bundles into a LAG: same speed, a router port each, 95% of the sum, every member billed', () => { + const { ev, errors } = open(undefined); + ev(`S.pops.fra.rgen=${fast(2)};ACT.buyNni({city:"fra",prov:FB,tier:2})`); + const before = JSON.parse(ev("JSON.stringify({u:portsUsed('fra'),c:R.cost.nni})")); + for (let i = 0; i < 3; i++) ev('ACT.lagNni({city:"fra",prov:FB,d:1})'); + ev('compute()'); + assert.equal(port(ev).n, 4); + assert.equal(ev('nniCap(nniPort("fra",FB))'), 400 * 4 * 0.95); + assert.equal(ev("portsUsed('fra')"), before.u + 3, 'a router port per member'); + assert.equal(ev('R.cost.nni'), 4 * 3000, 'four members, four monthly prices'); + for (let i = 0; i < 10; i++) ev('ACT.lagNni({city:"fra",prov:FB,d:1})'); + assert.equal(port(ev).n, ev('LAG_MAX'), 'up to LAG_MAX, like every LAG'); + assert.equal(ev('nniCap(nniPort("fra",FB))'), 400 * ev('LAG_MAX') * 0.95, 'more than 400G is more members'); + assert.deepEqual(errors, []); +}); + +test('upgrading a LAG moves and pays for every member', () => { + const { ev, errors } = open(); + ev('ACT.buyNni({city:"fra",prov:FB,tier:1});ACT.lagNni({city:"fra",prov:FB,d:1});ACT.lagNni({city:"fra",prov:FB,d:1})'); + ev(`S.pops.fra.rgen=${fast(2)};S.cash=1e9;ACT.buyNni({city:"fra",prov:FB,tier:2})`); + assert.equal(ev('S.cash'), 1e9 - 3 * ev('NNI[2].mo')); + assert.deepEqual([port(ev).tier, port(ev).n], [2, 3]); + assert.deepEqual(errors, []); +}); + +test('a member only comes off when what the port carries still fits', () => { + const { ev, errors } = open(); + ev('ACT.buyNni({city:"fra",prov:FB,tier:1});ACT.lagNni({city:"fra",prov:FB,d:1})'); + ev(live('b1', 150)); + ev('ACT.lagNni({city:"fra",prov:FB,d:-1})'); + assert.equal(port(ev).n, 2, '150G does not fit on one 100G member'); + ev('S.biz=S.biz.filter(b=>b.id!=="b1");ACT.lagNni({city:"fra",prov:FB,d:-1})'); + assert.equal(port(ev).n, undefined, 'back to a single port'); + assert.deepEqual(errors, []); +}); + +test('a fabric customer is only accepted when its own bandwidth fits on the port too (#307)', () => { + const { ev, errors } = open(); + ev('ACT.buyNni({city:"fra",prov:FB,tier:1})'); + ev(live('b1', 80)); + ev(offer('o1', 30)); + assert.equal(ev("reqOk(S.offers.find(o=>o.id==='o1'))"), false, '80G booked + 30G asked > 100G'); + assert.equal(ev("autoOffer(S.offers.find(o=>o.id==='o1'))"), null, 'so it is not auto-accepted'); + ev(offer('o2', 20)); + assert.equal(ev("reqOk(S.offers.find(o=>o.id==='o2'))"), true, '80G + 20G fits'); + // Once accepted, a customer counts once, not twice. + ev("ACT.accept({id:'o2'});compute()"); + assert.equal(ev("reqOk(S.biz.find(b=>b.id==='o2'))"), true); + assert.equal(ev("nniUsed('fra',FB)"), 100); + // A LAG member makes room for the one that did not fit. + ev('ACT.lagNni({city:"fra",prov:FB,d:1})'); + assert.equal(ev("reqOk(S.offers.find(o=>o.id==='o1'))"), true); + assert.deepEqual(errors, []); +}); + +test('the city panel offers the speeds the router takes, up to 400G, and LAG members', () => { + const { ev, dom, errors } = open(undefined); + ev(`S.pops.fra.rgen=${fast(2)};selectCity('fra');UI.tab='links';renderPanel()`); + const buy = () => [...dom.window.document.querySelectorAll('#panelBody [data-act="buyNni"]')].filter((b) => JSON.parse(b.dataset.args).prov === ev('FB')); + const tiers = buy().map((b) => [JSON.parse(b.dataset.args).tier, b.disabled]); + assert.ok(tiers.length >= 3, 'more than the old two sizes'); + assert.deepEqual(tiers.map(([t]) => t), [0, 1, 2], '10G, 100G and 400G: nothing faster'); + assert.ok(tiers.every(([, d]) => !d), 'this router takes all three'); + ev('S.pops.fra.rgen=RG.findIndex(r=>r.maxP===1);renderPanel()'); + assert.deepEqual(buy().map((b) => [JSON.parse(b.dataset.args).tier, b.disabled]), [[0, false], [1, false], [2, true]], 'a 100G router shows 400G, but not for sale'); + ev(`S.pops.fra.rgen=${fast(2)}`); + ev('ACT.buyNni({city:"fra",prov:FB,tier:2});renderPanel()'); + assert.ok(dom.window.document.querySelector('#panelBody [data-act="lagNni"]'), 'a LAG member'); + assert.match(dom.window.document.querySelector('#panelBody').textContent, /400G port/); + ev('ACT.lagNni({city:"fra",prov:FB,d:1});renderPanel()'); + assert.match(dom.window.document.querySelector('#panelBody').textContent, /2×400G LAG/); + assert.deepEqual(errors, []); +}); + +test('saves: fabric ports that make no sense are dropped, LAGs are kept in bounds, old ports are unchanged', () => { + const { ev, errors } = open(); + ev('ACT.buyNni({city:"fra",prov:FB,tier:1})'); + const s = JSON.parse(ev('JSON.stringify(S)')); + s.nni.push({ id: 'x1', city: 'fra', prov: 'nope', tier: 0 }, { id: 'x2', city: 'zzz', prov: s.nni[0].prov, tier: 0 }, + { id: 'x3', city: 'fra', prov: s.nni[0].prov, tier: 99 }, { id: 'x4', city: 'fra', prov: s.nni[0].prov, tier: '1' }, null); + s.nni[0].n = 50; + ev(`S=migrate(${JSON.stringify(s)});compute()`); + const n = JSON.parse(ev('JSON.stringify(S.nni)')); + assert.equal(n.length, 1, 'only the real port is left'); + assert.equal(n[0].tier, 1); + assert.equal(n[0].n, ev('LAG_MAX')); + s.nni = [{ id: 'old', city: 'fra', prov: s.nni[0].prov, tier: 0 }]; + ev(`S=migrate(${JSON.stringify(s)});compute()`); + assert.deepEqual(JSON.parse(ev('JSON.stringify(S.nni)')), [{ id: 'old', city: 'fra', prov: s.nni[0].prov, tier: 0 }]); + assert.equal(ev('R.cost.nni'), 500, 'a 10G port from before costs what it did'); + assert.deepEqual(errors, []); +});