diff --git a/src/game/80-simulation/30-compute.js b/src/game/80-simulation/30-compute.js index f02c48a..ccdfa59 100644 --- a/src/game/80-simulation/30-compute.js +++ b/src/game/80-simulation/30-compute.js @@ -52,7 +52,17 @@ function compute(){ // Customer demand per city, added up in S.biz order (what filtering S.biz for each city would give). const bizBw={};for(const b of S.biz){const T=BIZ_T[b.type];if(!T.l2&&!T.fiber&&(!T.event||eventLive(b))){const v=bizBw[b.city];bizBw[b.city]=(v===undefined?0:v)+b.bw;}} // Traffic shares by network index, and their sums, for each share table (and with Russia's throttle). - const shArr=new Map(),shSum=new Map(),DEMTO=new Float64Array(NN),loc=scnRule('local'),scrubRoom={},atkBy={},junkGroups=[],bhCities=new Set(ddosAll().filter(a=>a.bh).map(a=>a.city));R2.haul=[];R2.ddos=[];for(const a of ddosAll())for(const part of ddosSlices(a))(atkBy[part.city]||(atkBy[part.city]=[])).push(part); + const shArr=new Map(),shSum=new Map(),DEMTO=new Float64Array(NN),loc=scnRule('local'),scrubRoom={},atkBy={},junkGroups=[],bhCities=new Set(ddosAll().filter(a=>a.bh).map(a=>a.city));R2.haul=[];R2.ddos=[]; + /* Floods first, before any real traffic and in the order the attacks started, so no POP's place in S.pops decides who + gets a full port. Each slice is the flood entering in one city (mitigated and scrubbed there); what leaks is junk at + the victim, pinned to the port it came in on, so it loads that port, the backbone between them and the victim's router. */ + // A port the victim cannot be reached from (down, or no backbone to it) still fills with the junk arriving there. + const VIC={};for(const a of ddosAll()){const v=a.city;(VIC[v]||(VIC[v]=[])).push(a); + for(const part of ddosSlices(a)){const c=part.city;(atkBy[c]||(atkBy[c]=[])).push(part); + const m=ddosMitigation(part,{},bhCities.has(v),false),group={m,flows:[]};R2.ddos.push(m);junkGroups.push(group);if(!popUp(c))m.offline=true; + const src=popUp(v)&&SPD[v][CIDX[c]]0?q.g/m.leak:0});}} + else for(let j=0;jday?1.4:1);const biz=bizBw[c]??0;const d0=eye+biz; // Goggle video is throttled in Russia (#70): people there get half of it, so they ask for half. It is not @@ -64,13 +74,8 @@ function compute(){ // A shaped attack: `rtbh` is the player pulling the plug on the victim IP (junk gone, customer dark too); // `edge` is the crude RouteScript `blackhole ddos` filter (junk gone, 10% of real traffic with it). Flowspec // (a standing licence) and a scrubbing center each knock the flood down before it reaches the sim. - const attacks=atkBy[c]||[],rtbh=bhCities.has(c),edge=!!(attacks.length&&TRX&&TRX.blackhole&&!rtbh); - let dd=0; - for(const atk of attacks){const m=ddosMitigation(atk,{},bhCities.has((atk.parent||atk).city),false);R2.ddos.push(m);dd+=m.leak; - const group={m,flows:[]};junkGroups.push(group); - if(atk.entries?.length){for(const q of m.ingress){const f=flow(c,ci,cn,0,q.g,false,true);f.pin=q.entry.k+':'+q.entry.id;group.flows.push({f,share:m.leak>0?q.g/m.leak:0});}} - else for(let j=0;jm.attack.city===c))m.offline=true;continue;} + const attacks=VIC[c]||[],rtbh=bhCities.has(c),edge=!!(attacks.length&&TRX&&TRX.blackhole&&!rtbh); + if(!popUp(c))continue; const bh=rtbh||edge; if(edge)R2.teBlack+=attacks.reduce((n,a)=>n+a.gbps,0)+d*0.1;if(rtbh)R2.teBlack+=attacks.reduce((n,a)=>n+a.gbps,0)+d; R2.cityBlocked=R2.cityBlocked||{}; diff --git a/tests/ddos-floods.test.js b/tests/ddos-floods.test.js index 7b6adad..3c26cce 100644 --- a/tests/ddos-floods.test.js +++ b/tests/ddos-floods.test.js @@ -15,3 +15,26 @@ test('a flood entering over a PNI with NetChill competes on that PNI at its own assert.deepEqual(errors, []); } }); + +// Frankfurt has the eyeballs and no transit; all transit is in Amsterdam, 100G of wave away. +const remoteIngress = (ev, flip) => { + ev("ACT.start({});S.cash=1e9;S.nextFail=1e9;S.nextEvent=1e9;ACT.buildPop({city:'ams'});ACT.launchBB({city:'fra'});S.links.push({id:'L',a:'fra',b:'ams',kind:'wave',tier:1,km:400,mo:1,cut:0});ACT.buyTransit({city:'ams',net:NETS.find(n=>sellsAt(n,'ams')).id,tier:1})"); + if (flip) ev("const p=S.pops;S.pops={ams:p.ams,fra:p.fra}"); + ev("compute()"); +}; + +test('a flood entering in another city crosses the backbone to its victim, whatever order the POPs were built in', () => { + const out = []; + for (const flip of [false, true]) { + const { ev, errors } = load({ seed: 5 }); + remoteIngress(ev, flip); + assert.ok(ev("sfOf(R,'fra')") > 0.95, 'fine before the attack'); + ev("S.day=60;S.ev.ddos={id:'a',city:'fra',vec:'http',gbps:300,start:S.day,until:S.day+3,entry:{k:'distributed',lab:''},entries:[{k:'t',id:S.transit[0].id,city:'ams',share:1}]};compute()"); + assert.equal(ev('R.load.L'), 100, 'the junk fills the wave to the victim'); + assert.ok(ev("R.nodeLoad.fra") >= 100, "and the victim's router"); + assert.ok(ev("sfOf(R,'fra')") < 0.05, 'the victim goes dark'); + out.push(ev("JSON.stringify([R.load.L,R.useT[S.transit[0].id],sfOf(R,'fra')])")); + assert.deepEqual(errors, []); + } + assert.equal(out[0], out[1], 'POP build order does not change the outcome'); +});