PNIs and IX ports are both peering: traffic leaves at the nearest one (#298)
Routing tried every PNI (rank 1) before any IX port (rank 2), like a local-pref above peering, so a PNI in London pulled New York's traffic across the Atlantic even with the same network at the New York IX. PNIs now route at rank 2 with the IX ports, nearest first. At the same distance the PNI goes first: an IX port counts as PNI_TIE (0.001) further away, far below any link weight (at least 1). Distances compare as (Da-Db)+(dta-dtb) so exits at one distance stay exactly equal, and the POP-local shortcut skips lists that mix PNIs and IX ports. Backup only and RouteScript's prefer pni keep their say. The traceroute, the reference allocation in the tests and the RouteScript help follow.
This commit is contained in:
parent
7c65b9e7ed
commit
f303f29f22
16 changed files with 86 additions and 24 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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<x.cap*0.999)||ex[0];walk(P.path(e.city));
|
||||
const direct=e.k==='t'&&rk(e)<3?' '+(dtier(e)===1?tr('traceroute.the_carrier_s_own_port_beats_other',{net:N.name}):tr('traceroute.net_buys_transit_from_carrier_so_that',{net:N.name,carrier:NET[e.tnet].name})):'';
|
||||
let asPath=[S.asn];
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ function aiSlop(bad){const ai=pick(AI_NAMES),fits=TE_RECIPES.map(r=>({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)=>`<dt><code>${code}</code></dt><dd>${what}</dd>`;
|
||||
openModal(`<div style="display:flex;align-items:center"><div><div class="eyebrow">${tr('routescript.auto_te_controller')}</div><h2 style="font-size:26px">${tr('routescript.how_routescript_works')}</h2></div><button class="x" data-act="teBack" aria-label="${tr('common.close')}">×</button></div>
|
||||
<div class="tehelp"><p class="tagline">${tr('routescript.every_gigabit_leaving_your_network')}</p>
|
||||
<div class="tehelp"><p class="tagline">${tr('routescript.every_gigabit_leaving_your_network_picks')}</p>
|
||||
<h3>${tr('routescript.writing_a_script')}</h3><ul>
|
||||
<li>${tr('routescript.one_rule_per_line_a_starts')}</li>
|
||||
<li>${tr('routescript.networks_providers_and_cities_go_by')}</li>
|
||||
|
|
|
|||
|
|
@ -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<L.length;i++)a[i]=L[i].xi;return a;};
|
||||
const rcEx=(a,E)=>{const L=new Array(a.length);for(let i=0;i<a.length;i++)L[i]=E[a[i]];return L;};
|
||||
// Each list knows whether it holds a preferred exit (hi) and its exits by city (at), in list order.
|
||||
function exIdx(L){L.hi=L.some(e=>e.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;}
|
||||
|
|
|
|||
|
|
@ -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;i<E.length;i++){const e=E[i];e.xi=i;e.J=0;e.byC=null;e.desc=null;e.dup=ekN[e.ek]>1;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;i<E.length;i++){const e=E[i];e.xi=i;e.J=0;e.byC=null;e.desc=null;e.dup=ekN[e.ek]>1;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;q<ns.length;q++)okAdd(e,ns[q]);}else ns.forEach(n=>okAdd(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.used<e.cap&&Dv[e.ci]<Infinity&&!gone(e),byDist=(a,b)=>a.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.used<e.cap&&Dv[e.ci]<Infinity&&!gone(e),byDist=(a,b)=>a.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;h<here.length;h++)if(usable(here[h]))REST.push(here[h]);}
|
||||
else for(let li=0;li<lst.length;li++)if(usable(lst[li]))REST.push(lst[li]);
|
||||
sortD(REST);
|
||||
for(let i=0;i<REST.length&&FREM[F]>1e-6;){let j=i+1;while(j<REST.length&&REST[j].hp===REST[i].hp&&Math.abs(Dv[REST[j].ci]-Dv[REST[i].ci])<1e-6)j++;sendGroup(REST,i,j);i=j;}}};
|
||||
for(let i=0;i<REST.length&&FREM[F]>1e-6;){let j=i+1;while(j<REST.length&&REST[j].hp===REST[i].hp&&Math.abs(Dv[REST[j].ci]-Dv[REST[i].ci]+(REST[j].dt-REST[i].dt))<1e-6)j++;sendGroup(REST,i,j);i=j;}}};
|
||||
/* One rank of one pass over every flow. Each hot loop of compute() sits in a function of its own: V8 optimises a small
|
||||
function quickly and keeps it, while compute() as a whole is too big to optimise cheaply (it would run unoptimised,
|
||||
boxing every number, and be compiled again and again in the background). The tables of a flow's city (distances,
|
||||
|
|
@ -295,7 +296,7 @@ function compute(){RW.gen++;
|
|||
and no other city at distance 0, the usable ones here are exactly the first group, already in order.
|
||||
The group is G[0..GN): emptying an array (length=0) gives back its storage, and the next push allocates it again. */
|
||||
GN=0;
|
||||
if(!lst.hi&&ALONE[fci]){const here=lst.at.get(fci);if(here)for(let h=0;h<here.length;h++){const e=here[h];if(e.used<e.cap&&!gone(e))G[GN++]=e;}}
|
||||
if(!lst.hi&&!lst.mx&&ALONE[fci]){const here=lst.at.get(fci);if(here)for(let h=0;h<here.length;h++){const e=here[h];if(e.used<e.cap&&!gone(e))G[GN++]=e;}}
|
||||
if(!GN){
|
||||
// One scan: the best (preference, distance) so far and, in list order, the exits within 1e-6 of it. The best
|
||||
// distance only goes down, so dropping the ones it leaves behind gives exactly the exits a second scan would.
|
||||
|
|
@ -306,9 +307,9 @@ function compute(){RW.gen++;
|
|||
const gc=lst.gc||(lst.gc=[]),c=gc[fci];
|
||||
if(c!==undefined&&allRoom(c)){if(!c.length)continue;for(let k=0;k<c.length;k++)G[GN++]=c[k];}else{
|
||||
let bh=2,bd=Infinity,full=0;
|
||||
for(let li=0,LN=lst.length;li<LN;li++){const e=lst[li];if(e.used>=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<LN;li++){const e=lst[li];if(e.used>=e.cap||gone(e)){full++;continue;}const d=Dv[e.ci]+e.dt;if(d===Infinity)continue;const h=e.hp;
|
||||
if(h<bh){bh=h;bd=d;GN=0;G[GN++]=e;}
|
||||
else if(h===bh){if(d<bd){bd=d;let k=0;for(let gi=0;gi<GN;gi++){const x=G[gi];if(Dv[x.ci]-d<1e-6)G[k++]=x;}GN=k;G[GN++]=e;}else if(d-bd<1e-6)G[GN++]=e;}}
|
||||
else if(h===bh){if(d<bd){bd=d;let k=0;for(let gi=0;gi<GN;gi++){const x=G[gi];if(Dv[x.ci]+x.dt-d<1e-6)G[k++]=x;}GN=k;G[GN++]=e;}else if(d-bd<1e-6)G[GN++]=e;}}
|
||||
if(full*4>=lst.length&&full){let k=0;for(let li=0;li<lst.length;li++){const e=lst[li];if(e.used<e.cap)lst[k++]=e;}lst.length=k;}
|
||||
if(bh>1){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;li<lst.length;li++)if(usable(lst[li]))REST.push(lst[li]);sortD(REST);
|
||||
for(let i=0;i<REST.length&&FREM[F]>1e-6;){
|
||||
let j=i+1;while(j<REST.length&&REST[j].hp===REST[i].hp&&Math.abs(Dv[REST[j].ci]-Dv[REST[i].ci])<1e-6)j++;
|
||||
let j=i+1;while(j<REST.length&&REST[j].hp===REST[i].hp&&Math.abs(Dv[REST[j].ci]-Dv[REST[i].ci]+(REST[j].dt-REST[i].dt))<1e-6)j++;
|
||||
sendGroup(REST,i,j);i=j;
|
||||
}
|
||||
}};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue