Redundancy check routes once, against the live routing (#62)
This commit is contained in:
parent
ed4d029ba1
commit
499862b140
2 changed files with 28 additions and 3 deletions
|
|
@ -34,10 +34,11 @@ function vxcPanel(l){
|
|||
return h;
|
||||
}
|
||||
function prefCtl(kind,id,cur){cur=cur||'normal';return `<div class="btns"><span class="meta" style="align-self:center">${tr('common.egress')}</span>${Object.keys(PREF).map(v=>btn(PREF[v],'setPref',{kind,id,v},cur===v?'pink sm':'ghost sm')).join('')}</div>`;}
|
||||
// Trial routing is isolated from the live save, counters and scenic-route memory.
|
||||
// Trial routing is isolated from the live save, counters and scenic-route memory. "Before" is the live routing, which
|
||||
// after() keeps current, so a check costs one compute() on a big network, not two.
|
||||
function linkTrial(id){const save=S,live=R,hot=UI.hotMap,cache=TE_CACHE;
|
||||
try{S=JSON.parse(JSON.stringify(save));const l=S.links.find(x=>x.id===id);if(!l||linkDown(l))return null;
|
||||
compute();const before=R;l.cut=S.day+1;compute();
|
||||
try{const l0=save.links.find(x=>x.id===id);if(!l0||linkDown(l0))return null;
|
||||
S=JSON.parse(JSON.stringify(save));const l=S.links.find(x=>x.id===id),before=live;l.cut=S.day+1;compute();
|
||||
const allowed=new Set(Object.keys(S.pops).filter(popUp).concat(remoteCities())),adj={};
|
||||
for(const x of S.links)if(!linkDown(x)&&allowed.has(x.a)&&allowed.has(x.b)){(adj[x.a]=adj[x.a]||[]).push(x.b);(adj[x.b]=adj[x.b]||[]).push(x.a);}
|
||||
const seen=new Set([l.a]),q=[l.a];for(let i=0;i<q.length;i++)for(const c of adj[q[i]]||[])if(!seen.has(c)){seen.add(c);q.push(c);}
|
||||
|
|
|
|||
24
tests/link-trial.test.js
Normal file
24
tests/link-trial.test.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// #62 on a big network: a redundancy check routes once (the failed link), and uses the live routing as "before".
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
test('#62 a redundancy check computes only the trial, and matches comparing two fresh routings', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});S.cash=1e8;ACT.buildPop({city:'bde'});ACT.buildPop({city:'ams'});S.biz=[{id:'circuit',name:'Test Circuit',type:'l2vpn',city:'fra',city2:'bde',bw:80,rate:1,reqs:[]}]");
|
||||
ev("S.links=[{id:'main',a:'fra',b:'bde',kind:'wave',tier:1,km:100,mo:100,cut:0},{id:'a',a:'fra',b:'ams',kind:'wave',tier:0,km:100,mo:100,cut:0},{id:'b',a:'ams',b:'bde',kind:'wave',tier:0,km:100,mo:100,cut:0}];compute()");
|
||||
ev("window.__n=0;window.__c=compute;compute=function(){window.__n++;return window.__c.apply(this,arguments);}");
|
||||
const t = JSON.parse(ev("JSON.stringify(linkTrial('main'))"));
|
||||
assert.equal(ev('window.__n'), 1, 'one routing pass per check');
|
||||
assert.equal(t.split, false);
|
||||
assert.equal(t.loss, 70);
|
||||
assert.equal(ev("linkTrial('nope')"), null);
|
||||
assert.equal(ev('window.__n'), 1, 'an unknown link costs nothing');
|
||||
ev('compute=window.__c');
|
||||
// the old way: route the copy twice, before and after the cut
|
||||
const old = ev(`(()=>{const save=S,live=R;try{S=JSON.parse(JSON.stringify(save));compute();const b=R;S.links[0].cut=S.day+1;compute();
|
||||
const g=c=>Math.max(0,(b.citySrv[c]||0)-(R.citySrv[c]||0)),l2=Math.max(0,(b.l2.circuit||0)-(R.l2.circuit||0));
|
||||
return Object.keys(S.pops).reduce((a,c)=>a+(g(c)>.01?g(c):0),0)+(l2>.01?l2:0);}finally{S=save;R=live;}})()`);
|
||||
assert.equal(t.loss, old);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue