Attacks arrive as on 1.36 again: drop the distributed multi-ingress flood model

Frederic's call for 2.0: keep #153's fixes, NOC breakdown, new vectors, gaming risk
and overlapping attacks, but not the per-port model. It split every flood over each
ingress port with traffic (over a thousand on a big network), stored them all in the
save, routed one pinned flow per port, and with it came the build-order and
victim-scoring bugs found in review.

Each attack is again one entry port at the victim (a.entry): upstream clean-pipe,
Flowspec on the victim's router, IX blackholing, a sacrificial PNI and RouteScript
filter it in that order (ddosMitigation), then scrubbing; what leaks is junk at the
victim spread like its traffic, exactly as on main. Saves from 2.0 builds with
a.entries load: sanitize drops the shares and a 'distributed' entry becomes 'edge'.
Removed: R.ingressPorts, ddosEntries/ddosFold/ddosSlices/ddosCities/ddosHasIx, pinned
flows (and the pinned-rank handling in routing and its reference), the mixed-TCAM
line and the 'across N ports' message, and their tests; the scrubbing source-city
test now uses two victims sharing one center. CHANGELOG #153 bullets describe what
ships and credit #153.
This commit is contained in:
Frederic Jung 2026-10-28 20:53:58 +01:00
parent b5cba3e591
commit d56039695c
No known key found for this signature in database
16 changed files with 112 additions and 238 deletions

View file

@ -3,85 +3,75 @@ const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
test('a flood entering over a PNI with NetChill competes on that PNI at its own rank, as real traffic does', () => {
for (const net of ['nfx', 'lvl']) {
const { ev, errors } = load();
ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=5000;S.pops.fra.rgen=RG.length-1;S.pops.fra.routers=8");
ev(`S.transit=[];S.ixp={};S.peers={};S.grace=null;S.pni=[{id:'pa',net:'${net}',city:'fra',tier:1}];compute()`);
assert.equal(ev(`R.netEg.${net}.p`), 100, 'the 100G PNI is full of real traffic');
ev("S.ev.ddos={id:'x',city:'fra',vec:'http',gbps:100,start:S.day,until:S.day+5,entries:[{k:'p',id:'pa',city:'fra',share:1}]};compute()");
assert.equal(ev('R.usePni.pa'), 100);
assert.ok(!(ev(`R.netEg.${net}?.p||0`) > 1), `${net}: the junk is not routed behind the real traffic as if it were a cone route`);
assert.deepEqual(errors, []);
}
});
// Frankfurt has the eyeballs and no transit; all transit is in Amsterdam, 100G of wave away.
const remoteIngress = (ev, flip) => {
const remoteTransit = (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', () => {
test('a flood loads the backbone and the victim as on main, whatever order the POPs were built in', () => {
const out = [];
for (const flip of [false, true]) {
const { ev, errors } = load({ seed: 5 });
remoteIngress(ev, flip);
remoteTransit(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");
ev("S.day=60;ddosAttack();Object.assign(S.ev.ddos,{city:'fra',vec:'http',gbps:300});compute()");
assert.equal(ev('S.ev.ddos.entries'), undefined, 'no per-port shares');
assert.equal(ev('R.load.L'), 100, 'the junk fills the wave between the transit and 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.equal(ev("sfOf(R,'ams')"), 1);
out.push(ev("JSON.stringify([R.load.L,Object.values(R.useT)[0],sfOf(R,'fra'),R.ddos.length])"));
assert.deepEqual(errors, []);
}
assert.equal(out[0], out[1], 'POP build order does not change the outcome');
});
test('the same flood lands exactly as it does on main (one entry port, the victim\'s router filters it)', () => {
const { ev, errors } = load({ seed: 5 });
remoteTransit(ev, false);
ev("S.pops.fra.rgen=RG.findIndex(r=>r.fs===2);S.day=60;S.ev.ddos={id:'a',city:'fra',vec:'dns',gbps:200,start:S.day,until:S.day+3,entry:{k:'t',id:S.transit[0].id,lab:''},bh:false};compute()");
// Full Flowspec leaves 15%: 30G of junk on the 100G wave, next to Frankfurt's own traffic.
assert.ok(Math.abs(ev('R.ddos[0].leak') - 30) < 1e-9);
assert.ok(Math.abs(ev("R.ef[edgeKey(S.links[0])].net.junk") - 30) < 1e-6);
assert.deepEqual(errors, []);
});
test('an attack is held or lost at its victim; other POPs and their DDoS-protected customers are not charged', () => {
const { ev, errors } = load({ seed: 5 });
ev("ACT.start({});S.cash=1e9;S.lvl=6;S.nextFail=1e9;S.nextEvent=1e9;ACT.buildPop({city:'nyc'});for(const c of ['fra','nyc']){S.pops[c].bb={d:50};S.pops[c].rgen=3}");
ev("S.transit=[{id:'tf',city:'fra',net:'cog',tier:2},{id:'tn',city:'nyc',net:'cog',tier:1}];S.scrubs=[{city:'fra',tier:1}];S.scrubMode='always'");
// New York is struggling on its own (a 10G port for 50G of eyeballs), and has a DDoS-protected customer.
ev("S.transit=[{id:'tf',city:'fra',net:'cog',tier:2},{id:'tn',city:'nyc',net:'cog',tier:0}];S.scrubs=[{city:'fra',tier:1}];S.scrubMode='always'");
// New York is struggling on its own (a 10G port for 200G of eyeballs), and has a DDoS-protected customer.
ev("S.pops.nyc.bb.d=200;S.biz.push({id:'sc',type:'scrub',name:'Shield',city:'nyc',bw:1,rate:1000,mood:80,since:0})");
ev("S.day=60;S.ev.ddos={id:'a',city:'fra',vec:'http',gbps:20,start:S.day,until:S.day+3,entry:{k:'distributed',lab:''},entries:[{k:'t',id:'tf',city:'fra',share:.5},{k:'t',id:'tn',city:'nyc',share:.5}]};compute()");
ev("S.day=60;S.ev.ddos={id:'a',city:'fra',vec:'http',gbps:20,start:S.day,until:S.day+3,entry:{k:'t',id:'tf',lab:''}};compute()");
assert.ok(ev("sfOf(R,'nyc')") < 0.85, 'New York is under water anyway');
assert.ok(ev("sfOf(R,'fra')") >= 0.97, 'the victim is fine');
assert.equal(ev('ddosSf(S.ev.ddos)'), ev("sfOf(R,'fra')"));
const cash = ev('S.cash');
ev('dayTick()');
assert.deepEqual(JSON.parse(ev('JSON.stringify(S.ev.ddos.sla||[])')), [], 'no SLA payout for a customer in another city');
assert.equal(ev('S.stats.sla||0'), 0);
ev('S.day=S.ev.ddos.until;ddosExpire()');
assert.equal(ev('S.stats.ddosOk||0'), 1, 'held at the victim');
assert.equal(ev('S.stats.ddosLost||0'), 0);
assert.ok(cash > 0);
assert.deepEqual(errors, []);
});
test('an attack keeps its biggest ingress ports and folds the long tail, so saves stay small', () => {
const { ev, errors } = load({ seed: 5 });
ev("ACT.start({});S.cash=1e9;S.lvl=6;for(const c of ['fra','ams','lon','par'])if(!S.pops[c])ACT.buildPop({city:c});for(const c in S.pops){S.pops[c].bb={d:100};S.pops[c].rgen=3}");
ev("S.transit=[];const nets=NETS.filter(n=>n.type!=='t1').slice(0,40);for(const c in S.pops)for(const n of nets.slice(0,8))S.pni.push({id:n.id+'@'+c,net:n.id,city:c,tier:1});compute()");
ev("S.day=60;S.ddosStarts=[];ddosAttack()");
const ports = ev('ddosEntries().length');
assert.ok(ports > 20, `many ports carry traffic (${ports})`);
const en = JSON.parse(ev('JSON.stringify(S.ev.ddos.entries)'));
assert.equal(en.length, 13, 'twelve named ports and one remainder');
assert.equal(en.at(-1).k, 'rest');
assert.equal(en.at(-1).city, ev('S.ev.ddos.city'));
assert.ok(Math.abs(en.reduce((n, x) => n + x.share, 0) - 1) < 1e-9);
assert.match(ev("S.inc.at(-1).msg"), new RegExp(`across ${ports} transit and peering ports`), 'the message still counts every port');
// The remainder is routed like the rest of the flood, and survives a save.
ev('compute()');
assert.ok(Math.abs(ev('R.ddos.reduce((n,m)=>n+m.reaching,0)') - ev('S.ev.ddos.gbps')) < 1e-6);
ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()');
assert.equal(ev('S.ev.ddos.entries.length'), 13);
// An old save with every port is folded on load.
ev("S.ev.ddos.entries=Array.from({length:300},(_,i)=>({k:'p',id:'x'+i,city:'fra',lab:'',share:1}));S=migrate(JSON.parse(JSON.stringify(S)))");
assert.equal(ev('S.ev.ddos.entries.length'), 13);
assert.equal(ev("S.ev.ddos.entries.find(e=>e.k==='rest').share.toFixed(4)"), (288/300).toFixed(4));
test('fourteen attacks on a big network keep the save small, and 2.0 beta saves with per-port shares still load', () => {
const fs = require('node:fs'), path = require('node:path');
const fx = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8'));
const { ev, errors } = load({ seed: 3 });
ev(`S=migrate(JSON.parse(${JSON.stringify(JSON.stringify(fx.S || fx))}));UI.started=true;compute()`);
const before = ev('JSON.stringify(S).length');
ev("S.day=Math.max(S.day,50);for(let i=0;i<14;i++){S.ddosStarts=[];ddosAttack(false);}compute()");
assert.equal(ev('ddosAll().length'), 14);
assert.ok(ev('JSON.stringify(S).length') - before < 10000, 'a few hundred bytes per attack');
// A beta save spread each attack over every port: the shares are dropped and the attack carries on.
ev("S.ev.ddos.entries=Array.from({length:300},(_,i)=>({k:'p',id:'x'+i,city:S.ev.ddos.city,lab:'',share:1}));S.ev.ddos.entry={k:'distributed',lab:'Distributed ingress'};S=migrate(JSON.parse(JSON.stringify(S)));compute()");
assert.equal(ev('S.ev.ddos.entries'), undefined);
assert.equal(ev('S.ev.ddos.entry.k'), 'edge');
assert.equal(ev('ddosAll().length'), 14);
assert.match(ev('ddosPanel()'), /Live attack/);
assert.deepEqual(errors, []);
});