Prefer keeps the say at its own POP only, and the direct ranks stop slowing the game day

Review of #205:

- Prefer no longer switches the carrier-direct rule off for the whole network.
  A POP with a Prefer-marked transit port keeps what Prefer says; every other
  POP keeps the rule. compute(), traceroute and the reference loop in the tests
  all use the same per-POP rule, and a new test covers it (New York and Chicago,
  Prefer on one POP's Tell-Ya port).
- dayTick() cost. The harness is neutral (the same page on both sides differs by
  1%), but the cost was real: the four extra rank passes inside compute()'s main
  loop made V8 deoptimise compute() 954 times in 30 game days against 46 on main.
  The direct ranks now run in a small function of their own, in the plain way the
  reference loop does (their lists are one carrier's ports), so the main loop is
  the one main has, and the setup moved out of compute(). 61 deopts instead of 954.
- Italian: "Porta qui" read as "port here" next to "Porta più vicina"; it is
  "Instrada qui" now, and "Ogni POP instrada il traffico..." matches.
- Help text: says that real BGP carries the traffic from every POP (the shorter
  AS path beats IGP distance), that Carry here does that here, and that Nearest
  port is the default. All six languages.
This commit is contained in:
Christopher Hawker 2026-11-01 20:07:23 +11:00
parent b8845413d3
commit eb78d7104e
14 changed files with 77 additions and 23 deletions

View file

@ -77,6 +77,34 @@ test('Prefer, Backup only and RouteScript keep the say they had', () => {
assert.deepEqual(g.errors, []);
});
// New York and Chicago, both with eyeballs, a Level Tree and a Tell-Ya port each, and a 100G wave between them.
function bothPops() {
const g = load();
g.ev(`ACT.pickStart({city:'nyc'});ACT.start({});S.cash=1e9;ACT.buildPop({city:'chi'});
UI.via=null;UI.route='same';UI.lmode=null;openLinkModal('nyc','chi');ACT.buildLink({tier:1});closeModal();
for(const c of ['nyc','chi']){ACT.launchBB({city:c});S.pops[c].bb.d=40;ACT.buyTransit({city:c,net:'lvl',tier:1});ACT.buyTransit({city:c,net:'tly',tier:1});}compute()`);
g.p = (carrier, city) => port(g.ev, carrier, city);
return g;
}
test('a Prefer-marked port keeps the say at its own POP only; the other POPs still use their own carrier ports', () => {
const { ev, p, errors } = bothPops();
const lvlNyc = p('lvl', 'nyc'), lvlChi = p('lvl', 'chi'), tlyNyc = p('tly', 'nyc'), tlyChi = p('tly', 'chi');
assert.ok(via(ev, lvlNyc, 'lvl') > 1 && via(ev, lvlChi, 'lvl') > 1, 'each POP sends Level Tree traffic out of its own Level Tree port');
assert.equal(via(ev, tlyNyc, 'lvl') + via(ev, tlyChi, 'lvl'), 0, 'and none of it out of Tell-Ya');
const chicago = via(ev, lvlChi, 'lvl');
ev(`ACT.setPref({kind:'t',id:'${tlyNyc}',v:'high'});compute()`);
assert.ok(via(ev, tlyNyc, 'lvl') > 1 && via(ev, lvlNyc, 'lvl') === 0, 'New York: Prefer on Tell-Ya takes Level Tree traffic too, as it always did');
assert.ok(Math.abs(via(ev, lvlChi, 'lvl') - chicago) < 1e-6 && via(ev, tlyChi, 'lvl') === 0, 'Chicago: still its own Level Tree port, not hauled across to the Prefer port');
// Traceroute says the same.
assert.match(ev("traceroute('nyc',{net:'lvl'}).why"), /Tell-Ya.*New York/, 'traceroute from New York');
assert.match(ev("traceroute('chi',{net:'lvl'}).why"), /Level Tree.*Chicago.*straight to Level Tree/, 'and from Chicago');
// Take the Prefer away again: back to each POP on its own carrier's port.
ev(`ACT.setPref({kind:'t',id:'${tlyNyc}',v:'normal'});compute()`);
assert.ok(via(ev, lvlNyc, 'lvl') > 1 && via(ev, tlyNyc, 'lvl') === 0);
assert.deepEqual(errors, []);
});
test('from a POP without the carrier\'s port, traffic uses the nearest port, or crosses your network when the port carries', () => {
const { ev, lvl, tly, link, errors } = twoPops();
ev("S.te=null");

View file

@ -3,13 +3,16 @@
// Without Auto-TE, an exit whose shortest path from this POP is already full fits nothing, so it counts as
// unusable, like a full exit (#210).
module.exports = `
// A carrier's own port (dr) is also a plain transit exit. A POP with a Prefer-marked transit port keeps what Prefer
// says, and a port not set to carry only takes its own POP's traffic.
const PH=new Set(E.filter(x=>x.k==='t'&&x.pref==='high').map(x=>CIDX[x.city]));
const dr=(e,f)=>{if(e.k!=='t'||PH.has(f.ci)||eff(e,f.n)!==3)return 0;const t=directTier(e.net,f.n);return t?DIRECT_RANK[t][e.carry?0:1]:0;};
for(const pass of PASSES||[null])for(const rank of RANKS){
for(f of flows){
if(f.rem<=1e-6||(rank===0&&!f.cache)||(pass&&!pass(f)))continue;
Dv=SDi[f.ci];Pv=SPi[f.ci];PP=walked[f.ci]||(walked[f.ci]=[]);vis++;
// A carrier's own port (dr) is also a plain transit exit; one not set to carry only takes its own POP's traffic.
const candidates=E.filter(e=>e.used<e.cap&&e.ok(f.n)&&
((TR?eff(e,f.n):base(e,f.n))===rank||(dr(e,f.n)||-1)===rank)&&
((TR?eff(e,f.n):base(e,f.n))===rank||(dr(e,f)||-1)===rank)&&
(rank!==DIRECT_RANK[1][1]&&rank!==DIRECT_RANK[2][1]||CIDX[e.city]===f.ci)&&Dv[CIDX[e.city]]<Infinity&&!gone(e))
.sort((a,b)=>(a.pref==='high'?0:1)-(b.pref==='high'?0:1)||Dv[CIDX[a.city]]-Dv[CIDX[b.city]]);
for(let i=0;i<candidates.length&&f.rem>1e-6;){

View file

@ -39,6 +39,8 @@ test('indexed routing matches the simple allocation loop across network changes'
"S.transit.filter(t=>t.net==='lvl').forEach((t,i)=>{if(i%2===0)t.carry=true})",
"S.transit.filter(t=>t.net==='tly').forEach(t=>{t.carry=true})",
"S.transit.filter(t=>t.net==='lvl').forEach((t,i)=>{t.pref=i%2?'low':'normal'})",
// Prefer keeps the say at its own POP: the POPs with a Prefer-marked port skip the carrier-direct rule, the others keep it.
"S.transit.forEach((t,i)=>{if(t.net!=='lvl')t.pref=i%3===0?'high':'normal'})",
"S.pni.forEach((p,i)=>p.pref=i%3===0?'high':i%3===1?'low':'normal')",
"S.te={on:true,script:''};S.core={lv:2,run:2,legacy:true}",
"S.te.script='prefer pni for goggle\\nspill at 80%\\navoid transit for netchill'",