diff --git a/CHANGELOG.md b/CHANGELOG.md index 4de926b..e23157d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Traffic now leaves your network at the nearest peering, so a PNI in London no longer pulls New York's traffic across the Atlantic when the New York IX reaches the same network (#298). Where a PNI and an IX port reach a network in the same city, the PNI still goes first, and RouteScript's `prefer pni` still hauls everything to your PNIs. - 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). - Pressing Space to play again after a pause now picks up at the speed you were playing, not always at 1× (#299). - 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). diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index ecb6155..255955b 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -128,14 +128,15 @@ never freezes the game. (`S.pairMet`) and sets the edge's weight; Dijkstra gives shortest paths from each POP. Links on standby (`l.standby`) add their capacity to the edge, but when loads are handed back to links the active ones fill first and standby links take the rest. -2. Builds the exit list `E`: embedded caches (rank 0), PNIs (1), IX ports (2), +2. Builds the exit list `E`: embedded caches (rank 0), PNIs and IX ports (2, both peering), transit (3). Each exit has a capacity, the networks it can reach (`ok(net)`) and an egress preference (`high`, `normal`, `low` = backup only). A transit port can also be set to carry (`t.carry`): see step 4. 3. Builds flows: for every POP, its demand (eyeballs and customers) split across destination networks by their traffic share (`NSH`, with regional variants for China, Russia and Korea). Incidents can add junk flows or scale demand. -4. Routes flows rank by rank: the nearest usable exit first, ECMP across equal exits, +4. Routes flows rank by rank: the nearest usable exit first, ECMP across equal exits (a PNI goes before an + IX port at the same distance: `PNI_TIE`, #298), consuming link, router (`nodeCap`) and exit capacity. A carrier's own transit port also goes first, before plain transit, for traffic bound for that carrier or for a network that buys transit from it (`25-direct-egress.js`: the shorter AS path): always at its own POP, and from every diff --git a/site/i18n/de.js b/site/i18n/de.js index 2e28851..07f7bcb 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -3815,7 +3815,7 @@ "routescript.done_i_vibe_checked_your_bgp":"Fertig! Ich habe deinem BGP einen Vibe-Check verpasst. Deploye es sofort: Probeläufe sind was für Leute, die an sich zweifeln.", "routescript.drain_a_pop_and_steer_around":"Zieh den Traffic von einem POP ab und leite um einen seiner Links herum, bevor du daran arbeitest. Ersetz die Namen durch die, an denen du arbeitest.", "routescript.during_an_attack_rtbh_the_target":"Während eines Angriffs das Ziel upstream blackholen (RTBH). Alle anderen sind gerettet; das Ziel ist offline, bis du die Regel entfernst.", -"routescript.every_gigabit_leaving_your_network":"Jedes Gigabit, das dein Netz verlässt, wählt einen Ausgang: einen PNI, einen IX-Port oder einen Transit-Port. Ohne Eingriff nimmt es den günstigsten mit freiem Platz: erst PNI, dann IX, dann Transit. RouteScript ändert diese Wahl, so wie Local-Pref, AS-Path-Prepending und Wartungs-Drains auf echten Routern.", +"routescript.every_gigabit_leaving_your_network_picks":"Jedes Gigabit, das dein Netz verlässt, wählt einen Ausgang: einen PNI, einen IX-Port oder einen Transit-Port. Ohne Eingriff nimmt es das nächste Peering mit freiem Platz (in derselben Stadt den PNI vor dem IX-Port) und Transit erst, wenn kein Peering es nehmen kann. RouteScript ändert diese Wahl, so wie Local-Pref, AS-Path-Prepending und Wartungs-Drains auf echten Routern.", "routescript.filled_in_from_your_network_as":"Ausgefüllt mit deinem Netz, wie es gerade ist. Lade eins, lies es, prüfe es, dann deploye es.", "routescript.for_a_ddos_rtbh_the_target":"Bei einem DDoS: Blackhole das Ziel upstream und stell Geschäftskunden an erste Stelle. Das Ziel ist so lange offline, also entferne es, wenn der Angriff vorbei ist.", "routescript.great_question_here_is_a_production":"Tolle Frage! Hier ist ein produktionsreifes Skript, maßgeschneidert für deinen Live-Traffic. Ich habe es gründlich geprüft.", diff --git a/site/i18n/es.js b/site/i18n/es.js index 056ce73..94bf014 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -3813,7 +3813,7 @@ "routescript.done_i_vibe_checked_your_bgp":"¡Listo! He hecho un vibe-check de tu BGP. Despliégalo ya: las pruebas en seco son para quienes dudan de sí mismos.", "routescript.drain_a_pop_and_steer_around":"Drena un POP y desvía el tráfico de uno de sus enlaces antes de trabajar en él. Cambia los nombres por los de lo que estés tocando.", "routescript.during_an_attack_rtbh_the_target":"Durante un ataque, haz blackhole al objetivo aguas arriba (RTBH). Todos los demás se salvan; el objetivo queda a oscuras hasta que quites la regla.", -"routescript.every_gigabit_leaving_your_network":"Cada gigabit que sale de tu red elige una salida: un PNI, un puerto IX o un puerto de tránsito. Si no haces nada, toma la más barata con sitio: primero PNI, luego el IX, luego el tránsito. RouteScript cambia esas elecciones, como hacen local-pref, el prepend de AS-path y los drenajes de mantenimiento en routers reales.", +"routescript.every_gigabit_leaving_your_network_picks":"Cada gigabit que sale de tu red elige una salida: un PNI, un puerto IX o un puerto de tránsito. Si no haces nada, toma el peering más cercano con sitio (en la misma ciudad, el PNI antes que el puerto IX), y el tránsito solo cuando ningún peering puede llevarlo. RouteScript cambia esas elecciones, como hacen local-pref, el prepend de AS-path y los drenajes de mantenimiento en routers reales.", "routescript.filled_in_from_your_network_as":"Rellenado con tu red tal como está ahora mismo. Carga uno, léelo, compruébalo y luego despliega.", "routescript.for_a_ddos_rtbh_the_target":"Para un DDoS: haz blackhole al objetivo aguas arriba y prioriza a los clientes empresariales. El objetivo queda a oscuras mientras dure, así que quítalo cuando acabe el ataque.", "routescript.great_question_here_is_a_production":"¡Gran pregunta! Aquí tienes un script listo para producción, a medida de tu tráfico en vivo. Lo he revisado a fondo.", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 6938c0e..b42fb50 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -3813,7 +3813,7 @@ "routescript.done_i_vibe_checked_your_bgp":"Voilà ! J’ai fait un vibe check de votre BGP. Déployez tout de suite : les dry runs, c’est pour ceux qui doutent d’eux-mêmes.", "routescript.drain_a_pop_and_steer_around":"Videz un POP et contournez un de ses liens avant d’y toucher. Remplacez les noms par ceux sur lesquels vous travaillez.", "routescript.during_an_attack_rtbh_the_target":"Pendant une attaque, blackhole la cible en amont (RTBH). Tous les autres sont sauvés ; la cible est coupée jusqu’à ce que tu retires la règle.", -"routescript.every_gigabit_leaving_your_network":"Chaque gigabit qui quitte votre réseau choisit une sortie : une PNI, un port IX ou un port de transit. Livré à lui-même, il prend la moins chère qui a de la place : PNI d’abord, puis l’IX, puis le transit. RouteScript change ces choix, comme le font local-pref, l’AS-path prepending et les drains de maintenance sur de vrais routeurs.", +"routescript.every_gigabit_leaving_your_network_picks":"Chaque gigabit qui quitte votre réseau choisit une sortie : une PNI, un port IX ou un port de transit. Livré à lui-même, il prend le peering le plus proche qui a de la place (dans une même ville, la PNI avant le port IX), et le transit seulement quand aucun peering ne peut le prendre. RouteScript change ces choix, comme le font local-pref, l’AS-path prepending et les drains de maintenance sur de vrais routeurs.", "routescript.filled_in_from_your_network_as":"Remplis à partir de votre réseau tel qu’il est en ce moment. Chargez-en un, lisez-le, vérifiez-le, puis déployez.", "routescript.for_a_ddos_rtbh_the_target":"Pour un DDoS : blackhole la cible en amont et sers d’abord les clients professionnels. La cible est coupée tant que ça dure, alors retire-le quand l’attaque est finie.", "routescript.great_question_here_is_a_production":"Excellente question ! Voici un script prêt pour la production, taillé pour votre trafic. Je l’ai vérifié minutieusement.", diff --git a/site/i18n/it.js b/site/i18n/it.js index 6b15279..f863965 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -3813,7 +3813,7 @@ "routescript.done_i_vibe_checked_your_bgp":"Fatto! Ho fatto un vibe check al tuo BGP. Fai subito il deploy: i dry run sono per chi dubita di sé.", "routescript.drain_a_pop_and_steer_around":"Svuota un POP e aggira uno dei suoi link prima di metterci le mani. Cambia i nomi con quelli su cui stai lavorando.", "routescript.during_an_attack_rtbh_the_target":"Durante un attacco, metti il bersaglio in blackhole a monte (RTBH). Tutti gli altri sono salvi; il bersaglio resta al buio finché non togli la regola.", -"routescript.every_gigabit_leaving_your_network":"Ogni gigabit che esce dalla tua rete sceglie un’uscita: una PNI, una porta IX o una porta di transito. Se lo lasci fare, prende la più economica con spazio libero: prima PNI, poi IX, poi transito. RouteScript cambia queste scelte, come fanno local-pref, AS-path prepending e drain di manutenzione sui router veri.", +"routescript.every_gigabit_leaving_your_network_picks":"Ogni gigabit che esce dalla tua rete sceglie un’uscita: una PNI, una porta IX o una porta di transito. Se lo lasci fare, prende il peering più vicino con spazio libero (nella stessa città, la PNI prima della porta IX), e il transito solo quando nessun peering può prenderlo. RouteScript cambia queste scelte, come fanno local-pref, AS-path prepending e drain di manutenzione sui router veri.", "routescript.filled_in_from_your_network_as":"Compilati dalla tua rete così com’è adesso. Caricane uno, leggilo, controllalo, poi fai il deploy.", "routescript.for_a_ddos_rtbh_the_target":"Per un DDoS: metti il bersaglio in blackhole a monte e servi prima i clienti business. Il bersaglio resta al buio finché dura, quindi toglila quando l’attacco è finito.", "routescript.great_question_here_is_a_production":"Ottima domanda! Ecco uno script pronto per la produzione, su misura per il tuo traffico. L’ho controllato a fondo.", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index 092eea4..1486c04 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -3813,7 +3813,7 @@ "routescript.done_i_vibe_checked_your_bgp":"Pronto! Fiz um vibe check no seu BGP. Faça o deploy agora mesmo: dry run é para quem duvida de si.", "routescript.drain_a_pop_and_steer_around":"Esvazie um POP e desvie de um dos links dele antes de mexer. Troque os nomes pelos que você vai mexer.", "routescript.during_an_attack_rtbh_the_target":"Durante um ataque, coloque o alvo em blackhole no upstream (RTBH). Todo mundo é salvo; o alvo fica fora do ar até você remover a regra.", -"routescript.every_gigabit_leaving_your_network":"Todo gigabit que sai da sua rede escolhe uma saída: uma PNI, uma porta de IX ou uma porta de trânsito. Por conta própria, ele pega a mais barata que tem espaço: PNI primeiro, depois IX, depois trânsito. O RouteScript muda essas escolhas, como local-pref, AS-path prepending e drains de manutenção fazem em roteadores de verdade.", +"routescript.every_gigabit_leaving_your_network_picks":"Todo gigabit que sai da sua rede escolhe uma saída: uma PNI, uma porta de IX ou uma porta de trânsito. Por conta própria, ele pega o peering mais próximo que tem espaço (na mesma cidade, a PNI antes da porta de IX), e trânsito só quando nenhum peering consegue levar. O RouteScript muda essas escolhas, como local-pref, AS-path prepending e drains de manutenção fazem em roteadores de verdade.", "routescript.filled_in_from_your_network_as":"Preenchidos a partir da sua rede como ela está agora. Carregue um, leia, verifique e depois faça o deploy.", "routescript.for_a_ddos_rtbh_the_target":"Para um DDoS: coloque o alvo em blackhole no upstream e priorize os clientes empresariais. O alvo fica fora do ar enquanto durar, então remova quando o ataque acabar.", "routescript.great_question_here_is_a_production":"Ótima pergunta! Aqui está um script pronto para produção, sob medida para o seu tráfego. Eu verifiquei tudo com cuidado.", diff --git a/src/game/30-networks/40-traffic-shares.js b/src/game/30-networks/40-traffic-shares.js index 8883887..3f525c4 100644 --- a/src/game/30-networks/40-traffic-shares.js +++ b/src/game/30-networks/40-traffic-shares.js @@ -19,6 +19,9 @@ const CONE={},CONE_S={},DOWN={}; const ANC={};for(const n of NETS){const o=[],q=(n.up||[]).slice();while(q.length){const u=q.shift();if(o.includes(u)||!NETS.some(x=>x.id===u))continue;o.push(u);q.push(...(NETS.find(x=>x.id===u).up||[]));}ANC[n.id]=o;} // The networks a PNI with each network reaches: its customer cone. CONE_RANK: where routing tries a peer's cone. const PNI_NETS=CONE,CONE_RANK=2.5; +/* PNIs and IX ports are both peering (#298): traffic leaves at the nearest one, not over the ocean to a PNI. At the same + distance the PNI goes first: an IX port counts as this much further away, far below any link's weight. */ +const PNI_TIE=1e-3; for(const X of XIX){X.members=NETS.filter(n=>Array.isArray(n.ix)&&n.ix.includes(X.id)||!n.tail&&(X.core?X.core.includes(n.id):(n.ix==='ALL'||Array.isArray(n.ix)&&n.ix.includes(X.c))&&hstr(n.id+'|'+X.id)%100<(n.ix==='ALL'?72:X.take*100))).map(n=>n.id);} const NSH={}; {const t=NETS.reduce((a,n)=>a+n.share,0); NETS.forEach(n=>NSH[n.id]=n.share/t);} // After Glitch leaves Korea, Seoul viewers watch half as much of it and the rest moves to everyone else. diff --git a/src/game/60-features/50-traceroute.js b/src/game/60-features/50-traceroute.js index 89900cd..61e94e4 100644 --- a/src/game/60-features/50-traceroute.js +++ b/src/game/60-features/50-traceroute.js @@ -13,7 +13,7 @@ function trPaths(src,mode){const live=S.links.filter(l=>!linkDown(l)),rem=remote function trExits(net){const day=S.day,ev=S.ev,leak=ev.leak&&ev.leak.until>day?ev.leak.net:null,out=[]; for(const x of S.caches)if(x.net===net&&popUp(x.city)&&!siteDown(x.city,'a'))out.push({k:'c',rank:0,city:x.city,pref:'normal',lab:tr('common.name_cache',{name:NET[net].cache.name}),used:R.useCache[x.id]||0,cap:cacheG(x)}); // A peer's customer cone (#85): one AS hop more, so tried after direct peering and before transit, as in compute(). - for(const p of S.pni)if(CONE_S[p.net].has(net)&&pniOn(p)&&popUp(p.city)&&liveN(p.city,p.site,p.n))out.push({k:'p',rank:p.net===net?1:CONE_RANK,via:p.net===net?null:p.net,city:p.city,pref:p.pref||'normal',lab:tr('common.pni_with_net',{net:NET[p.net].name}),used:R.usePni[p.id]||0,cap:liveCap(pniG(p),p.city,p.site,p.n)}); + for(const p of S.pni)if(CONE_S[p.net].has(net)&&pniOn(p)&&popUp(p.city)&&liveN(p.city,p.site,p.n))out.push({k:'p',rank:p.net===net?2:CONE_RANK,via:p.net===net?null:p.net,city:p.city,pref:p.pref||'normal',lab:tr('common.pni_with_net',{net:NET[p.net].name}),used:R.usePni[p.id]||0,cap:liveCap(pniG(p),p.city,p.site,p.n)}); for(const c in S.ixp){const ses=ixSessions(c),via=ses.has(net)?null:ANC[net].find(u=>ses.has(u))||null;if((ses.has(net)||via)&&(popUp(ixCity(c))||remoteCities().includes(ixCity(c)))&&!(ev.ixdown&&ev.ixdown[c]>day))out.push({k:'ix',rank:via?CONE_RANK:2,via,city:ixCity(c),id:c,pref:(S.ixPref&&S.ixPref[c])||'normal',lab:tr('common.ix_peering',{ix:ixName(c)}),used:R.useIx[c]||0,cap:ixCap(c)});} for(const t of S.transit)if(popUp(t.city)&&!(t.down>day)&&liveN(t.city,t.site,t.n)&&net!==leak&&!((ev.depeer>day||scnRule('spat'))&&t.net==='cog'&&net==='ggl'))out.push({k:'t',rank:3,city:t.city,pref:t.pref||'normal',carry:!!t.carry,lab:tr('traceroute.name_transit',{name:NET[t.net].name}),tnet:t.net,used:R.useT[t.id]||0,cap:liveCap(PORT[t.tier].g,t.city,t.site,t.n)}); return out;} @@ -32,7 +32,7 @@ function traceroute(src,to,mode){mode=TR_MODES.includes(mode)?mode:'normal';cons // carries, except from a POP with a Prefer-marked transit port, where Prefer keeps the say. const hiHere=S.transit.some(t=>t.city===src&&t.pref==='high'&&popUp(t.city)&&!(t.down>S.day)&&liveN(t.city,t.site,t.n)),dtier=e=>hiHere||e.k!=='t'||e.pref==='low'?0:directTier(e.tnet,N.id); const rk=e=>{const r=e.pref==='low'?4:e.rank,t=dtier(e);return t&&(e.carry||e.city===src)?Math.min(r,DIRECT_RANK[t][e.carry?0:1]):r;}; - ex.sort((a,b)=>rk(a)-rk(b)||(a.pref==='high'?0:1)-(b.pref==='high'?0:1)||P.dist[a.city]-P.dist[b.city]); + ex.sort((a,b)=>rk(a)-rk(b)||(a.pref==='high'?0:1)-(b.pref==='high'?0:1)||P.dist[a.city]+(a.k==='ix'?PNI_TIE:0)-P.dist[b.city]-(b.k==='ix'?PNI_TIE:0)); const e=ex.find(x=>x.used({r,f:r.fit( L.push(tr('common.confidence_100'));return {src:L.join('\n'),ai,say:pick(AI_SAY)};} function teHelpModal(){const rule=(code,what)=>`
${code}
${what}
`; openModal(`
${tr('routescript.auto_te_controller')}

${tr('routescript.how_routescript_works')}

-

${tr('routescript.every_gigabit_leaving_your_network')}

+

${tr('routescript.every_gigabit_leaving_your_network_picks')}

${tr('routescript.writing_a_script')}

  • ${tr('routescript.one_rule_per_line_a_starts')}
  • ${tr('routescript.networks_providers_and_cities_go_by')}
  • diff --git a/src/game/80-simulation/29-route-cache.js b/src/game/80-simulation/29-route-cache.js index 7f134dc..7b8e93b 100644 --- a/src/game/80-simulation/29-route-cache.js +++ b/src/game/80-simulation/29-route-cache.js @@ -34,7 +34,7 @@ function rcExitKey(gk,E,flags){let k=gk+'#'+flags; const rcIx=(L,E)=>{const a=new Int32Array(L.length);for(let i=0;i{const L=new Array(a.length);for(let i=0;ie.hp===0);L.at=new Map();for(const e of L){const h=L.at.get(e.ci);if(h)h.push(e);else L.at.set(e.ci,[e]);}} +function exIdx(L){L.hi=L.some(e=>e.hp===0);L.mx=L.some(e=>e.dt>0)&&L.some(e=>e.dt===0);L.at=new Map();for(const e of L){const h=L.at.get(e.ci);if(h)h.push(e);else L.at.set(e.ci,[e]);}} // What reaching networks gave R (taken right after compute() worked it out, before anything else adds to R). function rcReachTake(R2){return {reachable:{...R2.reachable},nt:{...R2.nt},cone:{...R2.cone},reach:R2.reach,reachNT:R2.reachNT};} function rcReachPut(X,R2){const r=X.reach;Object.assign(R2.reachable,r.reachable);Object.assign(R2.nt,r.nt);Object.assign(R2.cone,r.cone);R2.reach=r.reach;R2.reachNT=r.reachNT;} diff --git a/src/game/80-simulation/30-compute.js b/src/game/80-simulation/30-compute.js index 8a86bc5..c71854d 100644 --- a/src/game/80-simulation/30-compute.js +++ b/src/game/80-simulation/30-compute.js @@ -22,7 +22,7 @@ function flDefine(R2,c){const {NF,FREM,FCI,FNJ,FCA,FBZ,FGT,FGI,FGP,FGH,FTI,FII,E /* Every exit has the same fields in the same order, whatever its kind, so the routing loop reads them from one object shape (exits of six shapes made each property read there a slow lookup). */ function mkEx(k,id,city,cap,rank,pref,lab,ok,nets,net){return {k,net,id,city,lab,cap,used:0,rank,pref,ok,nets,dir:null,clean:false,prem:false,carry:false,prep:false,sac:false,pnc:false, - ek:'',J:0,byC:null,desc:null,dup:false,told:false,hp:1,ci:0,cn:false,vis:0,ts:-1,xi:0,kx:EXK.indexOf(k),fac:undefined};} + ek:'',J:0,byC:null,desc:null,dup:false,told:false,hp:1,dt:0,ci:0,cn:false,vis:0,ts:-1,xi:0,kx:EXK.indexOf(k),fac:undefined};} // The exit kinds by number (mkEx's kx), for what routing adds up per kind in typed arrays. const EXK=['t','ix','p','c']; function compute(){RW.gen++; @@ -56,7 +56,7 @@ function compute(){RW.gen++; let all=set;for(const id of set)if(DOWN[id].length){if(all===set)all=new Set(set);for(const x of DOWN[id])all.add(x);} const x=mkEx('ix',c,ct,ixCap(c),2,(S.ixPref&&S.ixPref[c])||'normal',labOf(N_('common.ix_peering'),'ix',ixName(c)),n=>all.has(n),all);x.dir=all===set?null:set;E.push(x);} for(const p of S.pni){if(!pniOn(p)||!popUp(p.city)||!liveN(p.city,p.site,p.n))continue;R2.sessions++; - const x=mkEx('p',p.id,p.city,liveCap(pniG(p),p.city,p.site,p.n)*lagF(p)*(p.sacrif?0.5:1),1,p.pref||'normal',labOf(N_('common.pni_with_net'),'net',NET[p.net].name),n=>CONE_S[p.net].has(n),CONE[p.net],p.net);x.sac=!!p.sacrif;x.pnc=!!NET[p.net].cn;E.push(x);} + const x=mkEx('p',p.id,p.city,liveCap(pniG(p),p.city,p.site,p.n)*lagF(p)*(p.sacrif?0.5:1),2,p.pref||'normal',labOf(N_('common.pni_with_net'),'net',NET[p.net].name),n=>CONE_S[p.net].has(n),CONE[p.net],p.net);x.sac=!!p.sacrif;x.pnc=!!NET[p.net].cn;E.push(x);} for(const c of S.caches){if(!popUp(c.city)||siteDown(c.city,c.site==='b'?'b':'a'))continue;E.push(mkEx('c',c.id,c.city,cacheG(c),0,'normal',labOf(N_('common.name_cache'),'name',NET[c.net].cache.name),n=>n===c.net,[c.net]));} // After an update adds networks, a free courtesy route reaches the new ones you have no other way to (#46). R2.graceNets=0;if(S.grace&&S.grace.until>day){const gs=new Set(S.grace.nets.filter(n=>NET[n]&&!E.some(e=>e.k!=='c'&&e.ok(n)))),hc=popUp(S.home)?S.home:pops.find(popUp); @@ -74,7 +74,7 @@ function compute(){RW.gen++; // TSL: a slot per transit port id, for what it carries to each network (R.tNet, added up in TNA). const ekN={},TSL=new Map();(()=>{for(const e of E){e.ek=e.k+':'+e.id;ekN[e.ek]=(ekN[e.ek]||0)+1;} // dup: shares its key with another exit (a hand-edited save), so R.egDesc shows whichever pushed last. - for(let i=0;i1;e.told=false;e.hp=e.pref==='high'?0:1;e.ci=CIDX[e.city];e.cn=cnCity(e.city);e.vis=0;e.ts=-1;if(e.k==='t'){let t=TSL.get(e.id);if(t===undefined)TSL.set(e.id,t=TSL.size);e.ts=t;} + for(let i=0;i1;e.told=false;e.hp=e.pref==='high'?0:1;e.dt=e.k==='ix'?PNI_TIE:0;e.ci=CIDX[e.city];e.cn=cnCity(e.city);e.vis=0;e.ts=-1;if(e.k==='t'){let t=TSL.get(e.id);if(t===undefined)TSL.set(e.id,t=TSL.size);e.ts=t;} if(XC)continue; // Index loops or forEach (same order): for…of here made an iterator result per exit and network. const ns=e.nets||NET_IDS;if(Array.isArray(ns)){for(let q=0;qokAdd(e,n));} @@ -218,7 +218,8 @@ function compute(){RW.gen++; R.egT and R.netEg list them in; both are written back after routing. */ const EGT=new Float64Array(4),EGO=[],NEA=new Float64Array(NN*4),NEO=[]; // An exit the flow can still try: not visited yet, not full when the flow started, reachable, and not on a saturated path. - const usable=e=>e.vis!==vis&&e.useda.hp-b.hp||Dv[a.ci]-Dv[b.ci]; + // byDist: (Da-Db)+(dta-dtb), so exits of one kind at one distance compare as exactly equal and keep their order. + const usable=e=>e.vis!==vis&&e.useda.hp-b.hp||Dv[a.ci]-Dv[b.ci]+(a.dt-b.dt); // Push up to `want` along one path to exit e; returns what fitted. Index loops: for…of allocates an iterator until optimised. Capacity only shrinks while routing, so a // path with one full link or node fits nothing for the rest of this pass: mark it, and later tries cost nothing // (most tries are into paths that filled up earlier). @@ -278,7 +279,7 @@ function compute(){RW.gen++; if(LOC){const here=lst.at.get(fci);if(!here)continue;for(let h=0;h1e-6;){let j=i+1;while(j1e-6;){let j=i+1;while(j=e.cap||gone(e)){full++;continue;}const d=Dv[e.ci];if(d===Infinity)continue;const h=e.hp; + for(let li=0,LN=lst.length;li=e.cap||gone(e)){full++;continue;}const d=Dv[e.ci]+e.dt;if(d===Infinity)continue;const h=e.hp; if(h=lst.length&&full){let k=0;for(let li=0;li1){gc[fci]=NOG;continue;} if(GN>1)sortD(G,GN);gc[fci]=G.slice(0,GN);}} @@ -316,7 +317,7 @@ function compute(){RW.gen++; if(FREM[F]<=1e-6)continue; REST.length=0;for(let li=0;li1e-6;){ - let j=i+1;while(jx.k==='t'&&x.pref==='high').map(x=>CIDX[x.city])); const dr=(e,ci,n)=>{if(e.k!=='t'||PH.has(ci)||eff(e,n)!==3)return 0;const t=directTier(e.net,n);return t?DIRECT_RANK[t][e.carry?0:1]:0;}; + // An IX port counts as a hair further than a PNI in the same place (#298). + const tie=e=>e.k==='ix'?PNI_TIE:0; for(const pass of PASSES)for(const rank of RANKS){ for(F=0;Fe.used(a.pref==='high'?0:1)-(b.pref==='high'?0:1)||Dv[CIDX[a.city]]-Dv[CIDX[b.city]]); + .sort((a,b)=>(a.pref==='high'?0:1)-(b.pref==='high'?0:1)||Dv[CIDX[a.city]]-Dv[CIDX[b.city]]+(tie(a)-tie(b))); for(let i=0;i1e-6;){ let j=i+1;while(j assert.ok(Math.abs(a - b) < 1e-6, `${m}: ${a} vs ${b}`); + +test('#298 traffic leaves at the nearest peering, not over the Atlantic to a PNI', () => { + const { ev, dom, errors } = load(); + try { + ev(net); + const nyc = ev('R.useIx.nyc'), pni = ev('R.usePni.pl'); + assert.ok(nyc > 0, 'New York sends NetChill traffic out at its own IX'); + assert.ok(pni > 0, 'Frankfurt and London still use the London PNI'); + near(ev('R.load.ln||0'), 0, 'nothing crosses the Atlantic'); + near(nyc + pni, ev('R.netEg.nfx.p+R.netEg.nfx.ix'), 'all of it is served by peering'); + // Backup only still means backup only: the PNI takes nothing while the IX has room. + ev("S.pni[0].pref='low';compute()"); + near(ev('R.usePni.pl||0'), 0, 'a backup-only PNI waits'); + // RouteScript can still pull every gigabit onto the PNI, the way local-pref would. + ev("S.pni[0].pref='normal';S.core={lv:2,run:2,legacy:true};S.te={on:true,script:'prefer pni for netchill'};compute()"); + assert.ok(ev('teRules()'), 'the rule is active'); + near(ev('R.useIx.nyc||0'), 0, 'prefer pni hauls New York to London again'); + assert.ok(ev('R.load.ln') > 0); + assert.deepEqual(errors, []); + } finally { dom.window.close(); } +}); + +test('#298 in the same city the PNI goes first, and the IX port takes what does not fit', () => { + const { ev, dom, errors } = load(); + try { + ev(net + ";ACT.buyIx({city:'lon',tier:1,signed:true});S.peers['nfx@lon']=true;compute()"); + const lon = ev('R.useIx.lon||0'), pni = ev('R.usePni.pl'); + near(lon, 0, 'the London IX port carries none of it while the PNI has room'); + assert.ok(pni > 0); + near(ev('R.load.ln||0'), 0, 'New York still uses its own IX'); + // The traceroute shows the same choice. + assert.match(ev("traceroute('lon',{net:'nfx'}).text"), /pni-/i, 'London traces out over the PNI'); + assert.doesNotMatch(ev("traceroute('nyc',{net:'nfx'}).text"), /pni-/i, 'New York traces out over its IX'); + // A PNI too small for London and Frankfurt: the rest goes to the London IX, not across the ocean. + ev("S.pni[0].g1=true;compute()"); + const cap = ev("liveCap(pniG(S.pni[0]),'lon',S.pni[0].site,S.pni[0].n)"); + assert.ok(ev('R.usePni.pl') <= cap + 1e-6 && ev('R.usePni.pl') > cap * 0.99, 'the PNI fills up'); + assert.ok(ev('R.useIx.lon') > 0, 'the IX port takes the rest'); + near(ev('R.load.ln||0'), 0); + assert.deepEqual(errors, []); + } finally { dom.window.close(); } +}); diff --git a/tests/speed.test.js b/tests/speed.test.js index 9f1a008..c90ae89 100644 --- a/tests/speed.test.js +++ b/tests/speed.test.js @@ -289,7 +289,7 @@ test('the map is not drawn while the dashboard covers the whole screen', () => { function plainCompute(ev) { const src = ev('compute.toString()'); let plain = src - .replace('if(!lst.hi&&ALONE[fci])', 'if(false)') + .replace('if(!lst.hi&&!lst.mx&&ALONE[fci])', 'if(false)') .replace('if(!GN){\n // One scan', 'if(false){\n // One scan') .replace('const ns=e.nets||NET_IDS;', 'const ns=NET_IDS;') .replace('if(P.dead)return 0;', '').replaceAll('if(r<=1e-6){P.dead=1;return 0;}', '')