{if(!a||typeof a!=='object'||!isCity(a.city)||!s.pops[a.city]||!own(DDOS_VEC,a.vec))return null;
a.id=sid(a.id);a.gbps=Math.max(0,num(a.gbps,2));a.until=num(a.until,s.day);a.bh=!!a.bh;a.ixbh=!!a.ixbh;a.start=Math.max(0,Math.min(s.day,num(a.start,s.day)));a.until=Math.min(a.until,a.start+Math.ceil(7*SPICY_LONG));
- if(Array.isArray(a.entries)){a.entries=a.entries.slice(0,3000).filter(en=>en&&isCity(en.city)&&Number.isFinite(+en.share)&&+en.share>0&&(en.k==='rest'||['t','ix','p'].includes(en.k)&&typeof en.id==='string')).map(en=>en.k==='rest'?{k:'rest',city:en.city,share:+en.share}:{k:en.k,id:en.id.slice(0,40),city:en.city,lab:String(en.lab||'').slice(0,60),share:+en.share});const sum=a.entries.reduce((n,en)=>n+en.share,0);if(Number.isFinite(sum)&&sum>0){for(const en of a.entries)en.share/=sum;a.entries=ddosFold(a.entries,a.city);}else delete a.entries;}else delete a.entries;
+ delete a.entries; // 2.0 betas spread attacks over every ingress port; they arrive on one again
a.sla=Array.isArray(a.sla)?a.sla.filter(x=>typeof x==='string').slice(0,s.biz.length):[];
- if(!a.entry||typeof a.entry!=='object')a.entry={k:'edge',lab:''};else{a.entry.lab=String(a.entry.lab||'').slice(0,60);a.entry.id=a.entry.id==null?undefined:String(a.entry.id).slice(0,40);}return a;};
+ if(!a.entry||typeof a.entry!=='object'||!['t','ix','p','edge'].includes(a.entry.k))a.entry={k:'edge',lab:''};else{a.entry.lab=String(a.entry.lab||'').slice(0,60);a.entry.id=a.entry.id==null?undefined:String(a.entry.id).slice(0,40);}return a;};
const attacks=[s.ev.ddos,...(Array.isArray(s.ev.ddosMore)?s.ev.ddosMore:[])].map(repairAttack).filter(Boolean).slice(0,14);
if(attacks.length)s.ev.ddos=attacks[0];else delete s.ev.ddos;s.ev.ddosMore=attacks.slice(1);
s.ddosStarts=(Array.isArray(s.ddosStarts)?s.ddosStarts:attacks.map(a=>a.start)).filter(d=>typeof d==='number'||typeof d==='string').map(Number).filter(d=>Number.isFinite(d)&&d>s.day-7&&d<=s.day).sort((a,b)=>a-b).slice(-14);
diff --git a/src/game/85-incidents/10-incidents-and-ddos.js b/src/game/85-incidents/10-incidents-and-ddos.js
index f1e9df7..a7a9624 100644
--- a/src/game/85-incidents/10-incidents-and-ddos.js
+++ b/src/game/85-incidents/10-incidents-and-ddos.js
@@ -24,35 +24,21 @@ const HARMLESS=[
function lagsN(){const o=[];for(const t of S.transit)if((t.n||1)>=2&&!(t.down>S.day))o.push({k:'t',id:t.id,o:t,n:t.n,lab:tr('incidents_and_ddos.name_transit_lag_in_city',{name:NET[t.net].name,city:CITY[t.city].name})});
for(const p of S.pni)if((p.n||1)>=2)o.push({k:'p',id:p.id,o:p,n:p.n,lab:tr('incidents_and_ddos.pni_lag_with_name_in_city',{name:NET[p.net].name,city:CITY[p.city].name})});
for(const x in S.ixp){const n=(S.ixn||{})[x]||1;if(n>=2&&!S.myIx[x])o.push({k:'ix',id:x,n,lab:ixNamesCity(x)?tr('incidents_and_ddos.ix_lag',{ix:ixName(x)}):tr('incidents_and_ddos.ix_lag_in_city',{ix:ixName(x),city:CITY[ixCity(x)].name})});}return o;}
-// Where the junk comes in: one of the city's live uplinks, or just "the edge" if it has none yet.
-// The primary slot remains compatible with older saves; every system uses the full live set.
+// Several attacks can be live at once: the primary slot keeps older saves compatible, the rest overlap it.
function ddosAll(s=S,live=true){return [s.ev.ddos,...(s.ev.ddosMore||[])].filter(a=>a&&(!live||a.until>s.day));}
const ddosFind=id=>ddosAll().find(a=>id===undefined||a.id===id);
function ddosDrop(a){const left=ddosAll(S,false).filter(x=>x!==a);S.ev.ddos=left[0]||null;S.ev.ddosMore=left.slice(1);}
function ddosExpire(){for(const a of ddosAll(S,false))if(a.until<=S.day||!S.pops[a.city]){ddosDone(a);ddosDrop(a);}}
-function ddosEntries(){const ports=Object.values(R.ingressPorts||{}).filter(p=>p.cap>0),busy=ports.some(p=>p.traffic>1e-6),weight=p=>busy?p.traffic:p.cap,total=ports.reduce((n,p)=>n+weight(p),0);
- return total>0?ports.filter(p=>weight(p)>0).map(p=>({k:p.k,id:p.id,city:p.city,lab:p.lab,share:weight(p)/total})):[];}
-// A save keeps the biggest ingress ports by name; the long tail is one share (k:'rest') that arrives over the victim's
-// usual exits, so a big network's attacks do not each carry hundreds of ports.
-const DDOS_KEEP=12;
-function ddosFold(entries,city){const L=entries.slice().sort((a,b)=>b.share-a.share);if(L.length<=DDOS_KEEP+1)return L;
- const top=L.slice(0,DDOS_KEEP),rest=L.slice(DDOS_KEEP).reduce((n,en)=>n+en.share,0);if(rest>0)top.push({k:'rest',city,share:rest});return top;}
-function ddosSlices(a){if(!a.entries?.length)return [a];const groups={};
- for(const en of a.entries){const c=S.pops[en.city]?en.city:a.city;(groups[c]||(groups[c]=[])).push(en);}
- return Object.entries(groups).map(([city,entries])=>({...a,parent:a,city,entries,gbps:a.gbps*entries.reduce((n,en)=>n+en.share,0)}));}
-const ddosCities=a=>[...new Set([a.city,...(a.entries||[]).map(en=>en.city)])].filter(c=>S.pops[c]);
-const ddosHasIx=a=>ddosCities(a).some(hasIxAt);
// An attack is held or lost at its victim: the junk lands there, and other POPs' bad days are not the attacker's doing.
const ddosSf=a=>sfOf(R,a.city);
-function ddosReport(a){const ms=(R.ddos||[]).filter(m=>m.attack===a||m.attack.parent===a);if(!ms.length)return ddosMitigation(a);
- const parts={};for(const m of ms)for(const x of m.sp?.parts||[]){const q=parts[x.city]||(parts[x.city]={city:x.city,tier:x.tier,a:0,cleaned:0});q.a+=x.a;q.cleaned+=x.cleaned;}
- return {attack:a,blackhole:ms.some(m=>m.blackhole),upstream:ms.some(m=>m.upstream),reaching:ms.reduce((n,m)=>n+m.reaching,0),flowspec:ms.reduce((n,m)=>n+m.flowspec,0),fsMissing:ms.some(m=>m.fsMissing),filtered:ms.reduce((n,m)=>n+m.filtered,0),sp:Object.keys(parts).length?{parts:Object.values(parts)}:null,near:ms.find(m=>m.near)?.near||null,leak:ms.reduce((n,m)=>n+m.leak,0)};}
+function ddosReport(a){return (R.ddos||[]).find(m=>m.attack===a)||ddosMitigation(a);}
+// Where the junk comes in: one of the city's live uplinks, or just "the edge" if it has none yet.
function ddosEntry(c){const o=[];
for(const t of S.transit)if(t.city===c&&!(t.down>S.day))o.push({k:'t',id:t.id,lab:tr('common.net_transit',{net:NET[t.net].name})});
for(const x of ixIdsIn(c))if(S.ixp[x]!==undefined)o.push({k:'ix',id:x,lab:tr('common.ix_peering',{ix:ixName(x)})});
for(const p of S.pni)if(p.city===c)o.push({k:'p',id:p.id,lab:tr('common.pni_with_net',{net:NET[p.net].name})});
return o.length?pick(o):{k:'edge',lab:''};}
-// Flowspec capability at each ingress POP: 0 none, 1 basic, 2 full.
+// Flowspec capability of a POP's router: 0 none, 1 basic, 2 full.
const fsAt=c=>{const p=S.pops[c];return p?(RG[p.rgen||0].fs||0):0;};
// Scrubbing removes attack traffic up to the center's capacity; overflow leaks. On-demand
// does nothing for the first couple of days while traffic is being diverted.
@@ -63,18 +49,16 @@ const scrubFar=c=>{for(const a of ddosAll())if(a.city===c){const q=(R.haul||[]).
function scrubPlan(atk,g=atk.gbps||0,room={},take=null){if(!scrubEngaged(atk))return null;const c=atk.city;const parts=[];
for(const x of S.scrubs.filter(x=>popUp(x.city)&&(x.city===c||pathExists(c,x.city))).sort((a,b)=>(a.city===c?0:kmBetween(c,a.city))-(b.city===c?0:kmBetween(c,b.city)))){if(g<=0)break;const cap=SCRUB_TIERS[x.tier||0].g,a=Math.min(g,room[x.city]??cap);if(a<=0)continue;const cleaned=take?take(x,a):a;room[x.city]=(room[x.city]??cap)-cleaned;parts.push({city:x.city,tier:x.tier||0,a,cleaned});g-=cleaned;}
return parts.length?{parts,leak:g}:null;}
-// One accounting pipeline for routing and the NOC: upstream -> edge -> scrubbing -> leakage.
-function ddosMitigation(a,room={},blackhole=a.bh,plan=true){const entries=a.entries?.length?a.entries:[{...(a.entry||{}),share:1}],total=entries.reduce((n,en)=>n+en.share,0),ingress=[];
- let upstream=false,reaching=0,g=0,flowspec=0,fsMissing=false;
- for(const en of entries){const t=en.k==='t'?S.transit.find(x=>x.id===en.id):null,p=en.k==='p'?S.pni.find(x=>x.id===en.id):null,clean=!!(t&&t.clean);
- upstream=upstream||clean;let part=blackhole?0:a.gbps*en.share/total*(clean?0.1:1);reaching+=part;
- if(DDOS_VEC[a.vec]?.fs){const cap=fsAt(S.pops[en.city]?en.city:a.city),before=part;part*=FS_RES[cap];flowspec+=before-part;if(cap===0&&before>0)fsMissing=true;}
- if(a.ixbh&&hasIxAt(a.city))part*=0.5;
- if(p&&p.sacrif)part=Math.min(part,liveCap(pniG(p),p.city,p.site,p.n)*0.9);
- if(teRules()?.blackhole&&!blackhole)part=0;
- g+=part;ingress.push({entry:en,g:part});}
+// One accounting pipeline for routing and the NOC: upstream -> edge -> scrubbing -> leakage. The junk comes in on one
+// port of the victim (a.entry) and is filtered by the victim's own router.
+function ddosMitigation(a,room={},blackhole=a.bh,plan=true){const en=a.entry||{},t=en.k==='t'?S.transit.find(x=>x.id===en.id):null,p=en.k==='p'?S.pni.find(x=>x.id===en.id):null,upstream=!!(t&&t.clean);
+ const reaching=blackhole?0:a.gbps*(upstream?0.1:1);let g=reaching,flowspec=0;
+ if(DDOS_VEC[a.vec]?.fs){g*=FS_RES[fsAt(a.city)];flowspec=reaching-g;}
+ if(a.ixbh&&hasIxAt(a.city))g*=0.5;
+ if(p&&p.sacrif)g=Math.min(g,liveCap(pniG(p),p.city,p.site,p.n)*0.9);
+ if(teRules()?.blackhole&&!blackhole)g=0;
const filtered=reaching-g,sp=plan&&g>0?scrubPlan(a,g,room):null;
- return {attack:a,blackhole,upstream,reaching,flowspec,fsMissing,filtered,ingress,sp,leak:sp?sp.leak:g};}
+ return {attack:a,blackhole,upstream,reaching,flowspec,filtered,sp,leak:sp?sp.leak:g};}
// The NOC's live attack view: what is hitting you, what each tool would do about it right now, and the buttons.
function ddosPanel(){return S?ddosAll().filter(a=>S.pops[a.city]).map(ddosOne).join(''):'';}
function ddosOne(a){
@@ -85,7 +69,6 @@ function ddosOne(a){
:m.upstream?'✓ '+tr('incidents_and_ddos.after_upstream_scrubbing_g',{g:fmtG(m.reaching)}):'';
const fsLine=!V.fs?'— '+tr('incidents_and_ddos.flowspec_cannot_catch_vec',{vec:esc(V.n)})
:m.flowspec<=1e-6?'— '+tr('incidents_and_ddos.no_flowspec_filtering_ingress')
- :m.fsMissing?'~ '+tr('incidents_and_ddos.flowspec_dropping_g_some_ingress',{g:fmtG(m.flowspec)})
:'✓ '+tr('incidents_and_ddos.flowspec_dropping_g',{g:fmtG(m.flowspec)});
const used=c=>(R.ddos||[m]).reduce((n,q)=>n+(q.sp?.parts||[]).filter(x=>x.city===c).reduce((t,x)=>t+x.cleaned,0),0);
const scrOne=x=>{const T=SCRUB_TIERS[x.tier],q=hl(x),total=used(x.city);
@@ -107,6 +90,6 @@ function ddosOne(a){
${scrLine}
${haulLine?`${haulLine}
`:''}
${m.leak>1e-6?'~ '+tr('incidents_and_ddos.g_is_leaking_through',{g:fmtG(m.leak)}):'✓ '+tr('incidents_and_ddos.attack_fully_mitigated')}
`}
- ${m.blackhole?btn(tr('common.stop_blackholing'),'unrtbh',{id:a.id},'ghost sm'):btn(tr('incidents_and_ddos.blackhole_the_target_rtbh'),'rtbh',{id:a.id},'red sm')}${ddosHasIx(a)&&!m.blackhole?btn(a.ixbh?tr('incidents_and_ddos.ix_blackhole_on'):tr('incidents_and_ddos.ix_blackhole_half_honour_it'),'ixbh',{id:a.id},a.ixbh?'green sm':'sm'):''}${btn(tr('incidents_and_ddos.hackback_3000tm_20k'),'hackback',{id:a.id},'sm',S.cash<20000)}
+ ${m.blackhole?btn(tr('common.stop_blackholing'),'unrtbh',{id:a.id},'ghost sm'):btn(tr('incidents_and_ddos.blackhole_the_target_rtbh'),'rtbh',{id:a.id},'red sm')}${hasIxAt(a.city)&&!m.blackhole?btn(a.ixbh?tr('incidents_and_ddos.ix_blackhole_on'):tr('incidents_and_ddos.ix_blackhole_half_honour_it'),'ixbh',{id:a.id},a.ixbh?'green sm':'sm'):''}${btn(tr('incidents_and_ddos.hackback_3000tm_20k'),'hackback',{id:a.id},'sm',S.cash<20000)}
${tr('incidents_and_ddos.rtbh_is_free_and_instant_but')}
`;
return h;}
diff --git a/src/game/85-incidents/20-failures.js b/src/game/85-incidents/20-failures.js
index 404b912..d688fe6 100644
--- a/src/game/85-incidents/20-failures.js
+++ b/src/game/85-incidents/20-failures.js
@@ -148,10 +148,10 @@ function ddosAttack(recompute=true){const type='ddos',fl=scnRule('ddos');ddosExp
const c=pick(Object.keys(S.pops)),vec=pick(ddosVectors()),V=DDOS_VEC[vec];
const gbps=ddosSize(vec);
const dur=1+Math.floor(Math.random()*(1+6*ddosPressure())),entry=ddosEntry(c);
- const ports=ddosEntries(),entries=ddosFold(ports,c),a={id:uid(),city:c,vec,gbps,until:S.day+dur,entry:entries.length>1?{k:'distributed',lab:tr('common.distributed_ingress')}:entries[0]||entry,entries,bh:false,start:S.day};
+ const a={id:uid(),city:c,vec,gbps,until:S.day+dur,entry,bh:false,start:S.day};
if(!S.ev.ddos)S.ev.ddos=a;else(S.ev.ddosMore||(S.ev.ddosMore=[])).push(a);
const soaked=(V.fs&&fsAt(c))||hasScrub();
- const how=ports.length>1?tr('failures.across_n_transit_and_peering_ports',{n:ports.length}):entry&&entry.lab?tr('failures.in_via_e',{e:entry.lab}):'';
+ const how=entry&&entry.lab?tr('failures.in_via_e',{e:entry.lab}):'';
const msg=tr('failures.a_size_vec_attack_is_hitting',{size:fmtG(gbps),vec:V.n,city:CITY[c].name,how})+' '+(soaked?tr('failures.your_mitigation_is_eating_most_of'):tr('failures.junk_traffic_is_eating_your_capacity'));
if(fl)a.who=pick(FLOOD_WHO);
addInc({type,ref:c,atk:a.id,until:S.day+dur,msg:fl?msg+' '+tr('failures.attacker_who',{who:tr(a.who)}):msg,cost:0});
diff --git a/src/game/90-actions/80-security-and-china.js b/src/game/90-actions/80-security-and-china.js
index 9e7fd87..3cba21f 100644
--- a/src/game/90-actions/80-security-and-china.js
+++ b/src/game/90-actions/80-security-and-china.js
@@ -7,7 +7,7 @@ Object.assign(ACT,{
rmScrub:({city})=>{if(!S.scrubs.some(x=>x.city===city))return;if(UI.confirm!=='scrub:'+city){UI.confirm='scrub:'+city;renderAll();return;}S.scrubs=S.scrubs.filter(x=>x.city!==city);if(!hasScrub())S.scrubMode='always';UI.confirm=null;after();},
cleanPipe:({id})=>{const t=S.transit.find(x=>x.id===id);if(!t)return;t.clean=!t.clean;toast(t.clean?tr('security_and_china.clean_pipe_add_on_enabled_on',{net:NET[t.net].name,mo:fmt$(cleanMo(t))}):tr('security_and_china.clean_pipe_add_on_removed_from',{net:NET[t.net].name}),t.clean?'good':'');after();},
sacrif:({id})=>{const p=S.pni.find(x=>x.id===id);if(!p)return;p.sacrif=!p.sacrif;toast(p.sacrif?tr('security_and_china.net_pni_is_now_a_sacrificial',{net:NET[p.net].name}):tr('security_and_china.net_pni_is_back_to_normal',{net:NET[p.net].name}),p.sacrif?'good':'');after();},
- ixbh:({id}={})=>{const a=ddosFind(id);if(!a){toast(tr('security_and_china.no_attack_to_blackhole_right_now'),'');return;}if(!ddosHasIx(a)){toast(tr('security_and_china.no_ix_in_city_to_announce',{city:CITY[a.city].name}),'bad');sfx('err');return;}a.ixbh=!a.ixbh;toast(a.ixbh?tr('security_and_china.ix_blackhole_announced_in_city_about',{city:ddosCities(a).filter(hasIxAt).map(c=>CITY[c].name).join(', ')}):tr('security_and_china.ix_blackhole_withdrawn'),a.ixbh?'good':'');sfx('alert');after();},
+ ixbh:({id}={})=>{const a=ddosFind(id);if(!a){toast(tr('security_and_china.no_attack_to_blackhole_right_now'),'');return;}if(!hasIxAt(a.city)){toast(tr('security_and_china.no_ix_in_city_to_announce',{city:CITY[a.city].name}),'bad');sfx('err');return;}a.ixbh=!a.ixbh;toast(a.ixbh?tr('security_and_china.ix_blackhole_announced_in_city_about',{city:CITY[a.city].name}):tr('security_and_china.ix_blackhole_withdrawn'),a.ixbh?'good':'');sfx('alert');after();},
rtbh:({id}={})=>{const a=ddosFind(id);if(!a){toast(tr('security_and_china.no_attack_to_blackhole_right_now'),'');return;}a.bh=true;S.stats.rtbh=(S.stats.rtbh||0)+1;toast(tr('security_and_china.rtbh_announced_you_blackholed_the',{city:CITY[a.city].name}),'bad');sfx('alert');after();},
unrtbh:({id}={})=>{const a=ddosFind(id);if(!a)return;for(const x of ddosAll())if(x.city===a.city)x.bh=false;toast(tr('security_and_china.blackhole_withdrawn_city_is',{city:CITY[a.city].name}),'');after();},
hackback:({id}={})=>{const a=ddosFind(id);if(!a||a.until<=S.day){toast(tr('security_and_china.nothing_to_hack_back_right_now'),'');return;}if(!spend(20000))return;S.stats.hackback=(S.stats.hackback||0)+1;
diff --git a/src/i18n/en.js b/src/i18n/en.js
index 9e5308b..309e046 100644
--- a/src/i18n/en.js
+++ b/src/i18n/en.js
@@ -909,7 +909,6 @@
"common.demand":"Demand",
"common.deploy":"Deploy",
"common.deployed":"deployed",
-"common.distributed_ingress":"Distributed ingress",
"common.diverse":"diverse",
"common.diverse_route":"diverse route",
"common.dns_reflection":"DNS reflection",
@@ -1634,7 +1633,6 @@
"failures.a_trawler_off_ostend_dragged_its":"A trawler off Ostend dragged its gear straight through your {a}–{b} cable. The North Sea is about thirty metres deep and full of boats.",
"failures.a_visiting_engineer_from_london":"A visiting engineer from London brought Marmite to the {city} NOC. Diplomatic relations broke down, and so did your router while everyone argued.",
"failures.a_wind_farm_service_vessel_dropped":"A wind-farm service vessel dropped anchor on your {a}–{b} cable. It was there to fix a turbine.",
-"failures.across_n_transit_and_peering_ports":", across {n} transit and peering ports",
"failures.all_n_links_in_that_trench":"All {n} links in that trench went down with it.",
"failures.an_automation_script_in_city_ran":"An automation script in {city} ran “sed” on the whole config instead of one line. Every interface is now named “TODO”.",
"failures.an_earthquake_shook_your_a_b":"An earthquake shook your {a}–{b} fiber loose somewhere above 4,000 metres.",
@@ -2008,7 +2006,6 @@
"incidents_and_ddos.edge_filters_dropping_g":"Edge filters dropping: {g}",
"incidents_and_ddos.flowspec_cannot_catch_vec":"Flowspec cannot catch {vec}",
"incidents_and_ddos.flowspec_dropping_g":"Flowspec dropping: {g}",
-"incidents_and_ddos.flowspec_dropping_g_some_ingress":"Flowspec dropping: {g}; some ingress routers have no TCAM",
"incidents_and_ddos.g_is_leaking_through":"{g} is leaking through",
"incidents_and_ddos.hackback_3000tm_20k":"HackBack 3000™ $20k",
"incidents_and_ddos.it_was_dns":"It was DNS",
diff --git a/tests/ddos-floods.test.js b/tests/ddos-floods.test.js
index 29d1e4b..98efc9f 100644
--- a/tests/ddos-floods.test.js
+++ b/tests/ddos-floods.test.js
@@ -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, []);
});
diff --git a/tests/game.test.js b/tests/game.test.js
index ad9c729..5102de3 100644
--- a/tests/game.test.js
+++ b/tests/game.test.js
@@ -4,8 +4,8 @@ const { load, seed } = require('./harness');
test('daily DDoS spawns share one routing calculation and score their first active day', () => {
const { ev, errors } = load();
- // The busier DDoS schedule needs spicy chaos (BGP at 3 a.m.) or gaming customers.
- ev("ACT.start({});S.rules=makeRules('bgp');S.cash=1e9;S.day=50;S.nextFail=1e9;S.nextEvent=1e9;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=200;ACT.buyTransit({city:'fra',net:'cog',tier:1});compute();window.__compute=compute;window.__random=Math.random;window.__computes=0;compute=()=>{window.__computes++;window.__compute()};Math.random=()=>0;dayTick();compute=window.__compute;Math.random=window.__random");
+ // The busier daily DDoS schedule comes with gaming customers.
+ ev("ACT.start({});S.biz=[{type:'game',id:'g',name:'G',city:'fra',bw:1,rate:1,reqs:[]}];S.cash=1e9;S.day=50;S.nextFail=1e9;S.nextEvent=1e9;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=200;ACT.buyTransit({city:'fra',net:'cog',tier:1});compute();window.__compute=compute;window.__random=Math.random;window.__computes=0;compute=()=>{window.__computes++;window.__compute()};Math.random=()=>0;dayTick();compute=window.__compute;Math.random=window.__random");
assert.equal(ev('ddosAll().length'), 2, 'both daily spawn opportunities were used');
assert.equal(ev('window.__computes'), 1, 'daily spawns do not reroute the whole network individually');
assert.ok(ev('ddosAll().every(a=>a.worst===ddosSf(a))'), 'first-day service is recorded after routing');
@@ -209,7 +209,7 @@ test('Flowspec is a router-model capability, and each tool answers a flood', ()
test('a distributed SYN flood reports actual Flowspec drops and sends only the remainder to scrubbing', () => {
const { ev, errors } = load();
- ev("ACT.start({});S.scrubs=[{city:'fra',tier:0}];S.scrubMode='always';S.ev.ddos={id:'syn',city:'fra',vec:'syn',gbps:30.2,start:0,until:7,entries:[{k:'edge',city:'fra',share:1}]};compute()");
+ ev("ACT.start({});S.scrubs=[{city:'fra',tier:0}];S.scrubMode='always';S.ev.ddos={id:'syn',city:'fra',vec:'syn',gbps:30.2,start:0,until:7,entry:{k:'edge',lab:''}};compute()");
assert.equal(ev('ddosReport(S.ev.ddos).flowspec'), 0);
assert.equal(ev('ddosReport(S.ev.ddos).sp.parts[0].cleaned'), 30.2);
assert.match(ev('ddosPanel()'), /— No Flowspec filtering: ingress routers have no TCAM/);
@@ -230,29 +230,22 @@ test('a distributed SYN flood reports actual Flowspec drops and sends only the r
assert.deepEqual(errors, []);
});
-test('Flowspec accounts for each ingress router, upstream cleaning and other edge filters separately', () => {
+test('Flowspec, upstream cleaning and other edge filters are each accounted for separately', () => {
const { ev, errors } = load();
- ev("ACT.start({});S.cash=1e9;S.lvl=6;ACT.buildPop({city:'nyc'});S.pops.nyc.rgen=3;S.transit=[{id:'tf',city:'fra',net:'cog',tier:1},{id:'tn',city:'nyc',net:'cog',tier:1}];S.scrubs=[{city:'fra',tier:0},{city:'nyc',tier:0}];S.ev.ddos={id:'syn',city:'fra',vec:'syn',gbps:30.2,start:0,until:7,entries:[{k:'t',id:'tf',city:'fra',share:0.5},{k:'t',id:'tn',city:'nyc',share:0.5}]};compute()");
- assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-12.835)<1e-9);
- assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).sp.parts.reduce((n,x)=>n+x.cleaned,0)')-17.365)<1e-9);
- assert.match(ev('ddosPanel()'), /~ Flowspec dropping: 12\.8 Gbps; some ingress routers have no TCAM/);
- assert.match(ev('ddosPanel()'), /Scrubbing in Frankfurt: 15\.1 Gbps \/ 100G/);
- assert.match(ev('ddosPanel()'), /Scrubbing in New York: 2\.3 Gbps \/ 100G/);
- assert.equal(ev('ddosMitigation(S.ev.ddos).flowspec'), ev('ddosReport(S.ev.ddos).flowspec'), 'uncached reports also filter at the ingress instead of the target');
- ev('S.transit[1].clean=true;compute()');
- assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).reaching')-16.61)<1e-9);
- assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-1.2835)<1e-9);
- assert.match(ev('ddosPanel()'), /✓ After upstream scrubbing: 16\.6 Gbps/);
- assert.match(ev('ddosPanel()'), /~ Flowspec dropping: 1\.3 Gbps/);
- ev("S.pops.fra.rgen=3;S.ixp={fra:1,nyc:1};S.ev.ddos.ixbh=true;compute()");
- assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-14.1185)<1e-9);
- assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).filtered-ddosReport(S.ev.ddos).flowspec')-1.24575)<1e-9);
- assert.match(ev('ddosPanel()'), /✓ Flowspec dropping: 14\.1 Gbps/);
- assert.match(ev('ddosPanel()'), /✓ Edge filters dropping: 1\.2 Gbps/);
+ ev("ACT.start({});S.cash=1e9;S.lvl=6;S.pops.fra.rgen=1;S.transit=[{id:'tf',city:'fra',net:'cog',tier:1}];S.scrubs=[{city:'fra',tier:0}];S.ev.ddos={id:'syn',city:'fra',vec:'syn',gbps:30.2,start:0,until:7,entry:{k:'t',id:'tf'}};compute()");
+ assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-18.12)<1e-9);
+ assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).sp.parts[0].cleaned')-12.08)<1e-9);
+ assert.match(ev('ddosPanel()'), /✓ Flowspec dropping: 18\.1 Gbps/);
+ ev('S.transit[0].clean=true;compute()');
+ assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).reaching')-3.02)<1e-9, 'clean pipe leaves a tenth');
+ assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-1.812)<1e-9);
+ assert.match(ev('ddosPanel()'), /✓ After upstream scrubbing: 3\.0 Gbps/);
+ ev("S.ixp={fra:1};S.ev.ddos.ixbh=true;compute()");
+ assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).filtered-ddosReport(S.ev.ddos).flowspec')-0.604)<1e-9);
+ assert.match(ev('ddosPanel()'), /✓ Edge filters dropping: 0\.6 Gbps/);
assert.ok(ev('Math.abs(ddosReport(S.ev.ddos).reaching-ddosReport(S.ev.ddos).filtered-ddosReport(S.ev.ddos).sp.parts.reduce((n,x)=>n+x.cleaned,0)-ddosReport(S.ev.ddos).leak)<1e-9'));
assert.deepEqual(errors, []);
});
-
test('RTBH blackholes the victim, and HackBack 3000 is a gamble', () => {
const { ev } = load();
ev("ACT.start({});S.cash=1e8;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=120;ACT.buyTransit({city:'fra',net:'cog',tier:1});compute()");
@@ -793,8 +786,8 @@ test('DDoS frequency rises with level and signed gaming customers, with a rollin
assert.ok(base < early && early < level && level < gaming && gaming <= 7);
ev("S.offers=Array.from({length:50},()=>({type:'game'}));S.biz=[];S.lvl=1");
assert.equal(ev('ddosRate()'), base, 'unsigned offers do not attract attacks');
- // Force every random spawn opportunity (with spicy chaos on), then verify each rolling seven-day window.
- ev("S.rules=makeRules('bgp');");
+ // Force every random spawn opportunity (gamers on board), then verify each rolling seven-day window.
+ ev("S.biz=[{type:'game',city:'fra'}];");
ev('window.__starts=[];window.__oldRandom=Math.random;Math.random=()=>0');
for (let day = 50; day < 66; day++) {
ev(`S.day=${day};ddosTick();window.__starts.push(...ddosAll().filter(a=>a.start===S.day).map(a=>a.start))`);
@@ -832,39 +825,6 @@ test('DDoS sizes use a smaller non-gaming baseline and preserve unbounded Flood
assert.deepEqual(errors, []);
});
-test('distributed attacks follow normal transit and peering traffic across regions', () => {
- const { ev, errors } = load();
- ev("ACT.start({});S.cash=1e9;S.lvl=6;ACT.buildPop({city:'nyc'});for(const c of ['fra','nyc']){S.pops[c].rgen=3;S.pops[c].bb={d:c==='fra'?100:300}}S.transit=[{id:'tf',city:'fra',net:'cog',tier:2},{id:'tn',city:'nyc',net:'cog',tier:2}];S.pni=[{id:'pf',city:'fra',net:'ggl',tier:1}];S.ixp={nyc:1};S.rs={nyc:true};compute();window.__normal=JSON.stringify(R.ingressPorts);ddosAttack()");
- const normal = JSON.parse(ev('window.__normal'));
- const entries = JSON.parse(ev('JSON.stringify(ddosAll()[0].entries)'));
- const total = Object.values(normal).reduce((n,p)=>n+p.traffic,0);
- assert.ok(entries.some(p=>p.k==='t') && entries.some(p=>p.k==='p') && entries.some(p=>p.k==='ix'));
- assert.deepEqual([...new Set(entries.map(p=>p.city))].sort(), ['fra','nyc']);
- for (const en of entries) assert.ok(Math.abs(en.share-normal[en.k+':'+en.id].traffic/total)<1e-9);
- assert.ok(Math.abs(entries.reduce((n,en)=>n+en.share,0)-1)<1e-9);
- assert.match(ev('ddosPanel()'), /Live attack:/);
- assert.doesNotMatch(ev('ddosPanel()'), /ports: .*regions:/, 'keep regional detail out of the live attack card');
- ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()');
- assert.equal(ev('S.ev.ddos.entries.length'), entries.length, 'distributed shares survive a save round trip');
- assert.deepEqual(errors, []);
-});
-
-test('distributed ingress applies upstream scrubbing only to its own port and uses regional centers', () => {
- const { ev, errors } = load();
- ev("ACT.start({});S.cash=1e9;S.lvl=6;ACT.buildPop({city:'nyc'});for(const c of ['fra','nyc']){S.pops[c].rgen=3;S.pops[c].bb={d:100}}S.transit=[{id:'tf',city:'fra',net:'cog',tier:2,clean:true},{id:'tn',city:'nyc',net:'cog',tier:2}];S.scrubs=[{city:'fra',tier:0}];S.ev.ddos={id:'spread',city:'fra',vec:'http',gbps:1000,start:0,until:7,entries:[{k:'t',id:'tf',city:'fra',share:0.25},{k:'t',id:'tn',city:'nyc',share:0.75}]};compute()");
- assert.equal(ev('ddosReport(S.ev.ddos).reaching'), 775);
- assert.equal(ev('ddosReport(S.ev.ddos).leak'), 750);
- assert.equal(ev('R.useT.tn'), 400, 'the uncleaned flood fills its own ingress port');
- assert.ok(ev('R.useT.tf') < 200, 'it cannot spill into the cleaned port');
- assert.match(ev('ddosPanel()'), /✓ After upstream scrubbing: 775 Gbps/);
- assert.match(ev('ddosPanel()'), /~ 750 Gbps is leaking through/);
- ev("S.scrubs.push({city:'nyc',tier:1});compute()");
- assert.equal(ev('ddosReport(S.ev.ddos).leak'), 0);
- assert.match(ev('ddosPanel()'), /✓ Scrubbing in Frankfurt: 25\.0 Gbps \/ 100G/);
- assert.match(ev('ddosPanel()'), /✓ Scrubbing in New York: 750 Gbps \/ 1T/);
- assert.deepEqual(errors, []);
-});
-
test('scrubbing hauls retain their real source on each link when several cities use one center', () => {
const { ev, errors, dom } = load();
ev(`ACT.start({});S.cash=1e9;S.lvl=6;for(const c of ['prg','ber'])ACT.buildPop({city:c});
@@ -875,8 +835,8 @@ test('scrubbing hauls retain their real source on each link when several cities
{id:'pb',a:'prg',b:'ber',kind:'wave',tier:2,km:280,mo:100}];
S.transit=[{id:'tp',city:'prg',net:'cog',tier:2},{id:'tb',city:'ber',net:'cog',tier:2}];
S.scrubs=[{city:'fra',tier:1}];
- S.ev.ddos={id:'spread',city:'ber',vec:'ack',gbps:100,start:0,until:7,
- entries:[{k:'t',id:'tp',city:'prg',share:.5},{k:'t',id:'tb',city:'ber',share:.5}]};compute()`);
+ S.ev.ddos={id:'b',city:'ber',vec:'ack',gbps:50,start:0,until:7,entry:{k:'t',id:'tb'}};
+ S.ev.ddosMore=[{id:'p',city:'prg',vec:'ack',gbps:50,start:0,until:7,entry:{k:'t',id:'tp'}}];compute()`);
const sources = id => JSON.parse(ev(`JSON.stringify(Object.entries(R.ef[edgeKey(S.links.find(l=>l.id==='${id}'))].eg)
.filter(([key])=>key.startsWith('scrub:')).map(([key,g])=>({city:R.egDesc[key].city,g})).sort((a,b)=>a.city.localeCompare(b.city)))`));
assert.equal(ev('R.load.pb||0'), 0, 'Berlin does not feed the Prague link');
@@ -892,8 +852,8 @@ test('scrubbing hauls retain their real source on each link when several cities
assert.deepEqual(JSON.parse(ev('JSON.stringify([...UI.feed])')), ['prg'], 'the map highlights the same source as the inspected link');
row.querySelector('[data-act="goEgress"]').click();
assert.equal(ev('UI.sel.id'), 'prg', 'Open goes to the actual source city');
- // Reordering ingress and adding an overlapping flood must not change the attribution.
- ev("S.ev.ddos.entries.reverse();S.ev.ddosMore=[{...S.ev.ddos,id:'overlap',gbps:20,entries:S.ev.ddos.entries.slice().reverse()}];compute()");
+ // Swapping the attacks' order and adding an overlapping flood must not change the attribution.
+ ev("S.ev.ddosMore.push(S.ev.ddos,{...S.ev.ddos,id:'overlap',gbps:20});S.ev.ddos=S.ev.ddosMore.shift();compute()");
assert.deepEqual(sources('fp1').map(x=>x.city), ['prg']);
assert.deepEqual(sources('fb').map(x=>x.city), ['ber']);
// When Berlin's direct link fails, its haul really does join Prague's route.
@@ -914,29 +874,9 @@ function setupScrubLatency(ev) {
S.transit=[{id:'tf',city:'fra',net:'cog',tier:2},{id:'tn',city:'nyc',net:'cog',tier:2}];
S.scrubs=[{city:'fra',tier:0},{city:'par',tier:0}];
S.ev.ddos={id:'par-flood',city:'par',vec:'dns',gbps:33.8,start:0,until:7,
- entries:[{k:'t',id:'tf',city:'fra',share:0.65},{k:'t',id:'tn',city:'nyc',share:0.35}]};compute()`);
+ entry:{k:'edge',lab:''}};compute()`);
}
-test('distributed ingress does not give a locally protected victim a remote scrubbing latency', () => {
- const { ev, errors, dom } = load();
- setupScrubLatency(ev);
- assert.ok(ev("R.haul.some(q=>q.city==='nyc'&&q.to==='par'&&q.ms>60)"), 'the remote ingress still travels to its scrubbing center');
- assert.equal(ev('ddosReport(S.ev.ddos).sp.parts.length'), 2, 'both centers clean the distributed flood');
- assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-20.28)<1e-9);
- assert.equal(ev('ddosReport(S.ev.ddos).leak'), 0);
- Object.defineProperty(dom.window, 'innerWidth', { value: 360, configurable: true });
- ev("UI.left='noc';UI.leftOpen=true;renderLeft()");
- const text = dom.window.document.getElementById('left').textContent;
- assert.match(text, /Live attack: Paris/);
- assert.match(text, /Scrubbing in Frankfurt: 8\.8 Gbps/);
- assert.match(text, /Scrubbing in Paris: 4\.7 Gbps/);
- assert.doesNotMatch(text, /Scrubbing traffic hauled over your backbone|\+\d+(\.\d+)? ms/);
- // A local center is still nearest when it is full and other centers take overflow.
- ev("S.ev.ddos.vec='ack';S.ev.ddos.gbps=300;compute()");
- assert.doesNotMatch(ev('ddosOne(S.ev.ddos)'), /Scrubbing traffic hauled over your backbone/);
- assert.deepEqual(errors, []);
-});
-
test('each attack shows only the nearest scrubbing detour using precise one-way link latency', () => {
const { ev, errors } = load();
setupScrubLatency(ev);
@@ -946,11 +886,11 @@ test('each attack shows only the nearest scrubbing detour using precise one-way
assert.equal((card.match(/Scrubbing traffic hauled over your backbone/g)||[]).length, 1);
assert.match(card, /✓ Scrubbing traffic hauled over your backbone: Paris → Frankfurt \(\+3\.1 ms\)/);
// An overlapping attack has its own victim and nearest center.
- ev("S.ev.ddosMore=[{id:'other',city:'ams',vec:'ack',gbps:10,start:0,until:7,entries:[{k:'t',id:'tn',city:'nyc',share:1}]}];compute()");
+ ev("S.ev.ddosMore=[{id:'other',city:'ams',vec:'ack',gbps:10,start:0,until:7,entry:{k:'edge',lab:''}}];compute()");
assert.doesNotMatch(ev('ddosOne(S.ev.ddosMore[0])'), /Scrubbing traffic hauled over your backbone/);
assert.match(ev('ddosOne(S.ev.ddos)'), /Paris → Frankfurt \(\+3\.1 ms\)/);
// Ignore a failed nearby center and use the live path to Amsterdam.
- ev("S.pops.fra.down=10;S.links.push({id:'pa',a:'par',b:'ams',kind:'wave',tier:3,km:2000,mo:100});S.ev.ddos.entries=[{k:'edge',city:'par',share:1}];compute()");
+ ev("S.pops.fra.down=10;S.links.push({id:'pa',a:'par',b:'ams',kind:'wave',tier:3,km:2000,mo:100});compute()");
assert.match(ev('ddosOne(S.ev.ddos)'), /Paris → Amsterdam \(\+13\.0 ms\)/);
ev('S.ev.ddos.bh=true;compute()');
assert.doesNotMatch(ev('ddosOne(S.ev.ddos)'), /Scrubbing traffic hauled over your backbone/);
@@ -970,17 +910,6 @@ test('a constrained remote haul leaves scrubbing capacity for the next overlappi
assert.deepEqual(errors, []);
});
-test('distributed attack statistics survive an ingress outage and corrupted saved shares', () => {
- const { ev, errors } = load();
- ev("ACT.start({});S.cash=1e9;S.lvl=6;ACT.buildPop({city:'nyc'});S.ev.ddos={id:'spread',city:'fra',vec:'http',gbps:1000,start:0,until:7,entries:[{k:'t',id:'a',city:'fra',share:0.25},{k:'t',id:'b',city:'nyc',share:0.75}]};S.pops.nyc.down=5;compute()");
- assert.equal(ev('ddosReport(S.ev.ddos).reaching'), 1000);
- assert.equal(ev('ddosReport(S.ev.ddos).leak'), 1000);
- ev("S.ev.ddos.entries.push({k:'t',id:'bad',city:'unknown',share:5},{k:'t',id:'bad2',city:'fra',share:-1});S=migrate(JSON.parse(JSON.stringify(S)));compute()");
- assert.equal(ev('S.ev.ddos.entries.length'), 2);
- assert.equal(ev('S.ev.ddos.entries.reduce((n,en)=>n+en.share,0)'), 1);
- assert.deepEqual(errors, []);
-});
-
test('RackNet and TeamSpooked require signed gaming customers, bypass Flowspec, and stay within a third of the current size range', () => {
const { ev, errors } = load();
ev("ACT.start({});S.cash=1e9;S.lvl=13;S.pops.fra.bb={d:150000};ACT.buyTransit({city:'fra',net:'cog',tier:2});compute()");
@@ -1004,7 +933,7 @@ test('RackNet and TeamSpooked require signed gaming customers, bypass Flowspec,
assert.deepEqual(errors, []);
});
-test('normal DDoS starts average half an attack per week without gaming and never exceed a seven-per-week expected rate', () => {
+test('gamers\' DDoS starts rise gradually from half an attack per week and never exceed a seven-per-week expected rate', () => {
const { ev, errors } = load();
ev("ACT.start({});S.rules=makeRules('bgp');S.day=50");
const checks = JSON.parse(ev(`
@@ -1020,9 +949,9 @@ test('normal DDoS starts average half an attack per week without gaming and neve
JSON.stringify(out)
`));
for(const row of checks){
+ if(row.games===0){assert.equal(row.observed,0,'without gamers attacks stay on the failure schedule');continue;}
assert.ok(Math.abs(row.observed-row.expected)<=0.0011, JSON.stringify(row));
- if(row.games===0)assert.equal(row.observed,0.5);
- else assert.ok(row.expected>0.5&&row.expected<=7);
+ assert.ok(row.expected>0.5&&row.expected<=7);
}
assert.ok(checks[3].expected>checks[2].expected, 'level increases gaming frequency');
assert.ok(checks[4].expected>checks[3].expected, 'more gaming customers increase frequency');
@@ -1116,7 +1045,7 @@ test('Flood Season retains its existing size quantiles and escalation when norma
assert.deepEqual(errors, []);
});
-test('the busier DDoS schedule needs spicy chaos or gaming customers; otherwise attacks come as before', () => {
+test('the busier DDoS schedule needs gaming customers; otherwise attacks come with the other incidents', () => {
const { ev, errors } = load();
ev("ACT.start({});S.cash=1e9;S.day=50;S.lvl=13;S.biz=[];S.nextFail=1e9;S.nextEvent=1e9");
const ticks = () => ev("(()=>{const old=Math.random,oa=ddosAttack;let n=0;ddosAttack=()=>{n++};Math.random=()=>0;try{for(let i=0;i<30;i++)ddosTick();}finally{Math.random=old;ddosAttack=oa;}return n;})()");
@@ -1127,14 +1056,15 @@ test('the busier DDoS schedule needs spicy chaos or gaming customers; otherwise
ev("S.biz=[{type:'game',city:'fra',bw:5,rate:1,reqs:[]}]");
assert.ok(ticks() > 0, 'gaming customers bring their own attacks');
ev("S.biz=[];S.rules=makeRules('bgp')");
- assert.ok(ticks() > 0, 'spicy chaos brings more attacks');
+ assert.equal(ticks(), 0, 'spicy chaos alone has no daily schedule: it doubles the incident one');
ev("S.rules=makeRules('freeze')");
assert.equal(ticks(), 0, 'Change Freeze has no attacks on either schedule');
ev("S.biz=[{type:'game',city:'fra',bw:5,rate:1,reqs:[]}]");
assert.equal(ticks(), 0, 'not even with gamers');
assert.ok(ev("(()=>{const old=Math.random;try{for(let i=0;i<200;i++){const r=i/200;Math.random=()=>r;S.ev.ddos=null;S.ev.ddosMore=[];S.ddosStarts=[];fireFailure();if(ddosAll().length)return false;}return true;}finally{Math.random=old;S.inc=[];}})()"), 'and fireFailure never rolls one');
- ev("S.rules=makeRules('bgp');S.biz=[]");
- assert.ok(ev("(()=>{const old=Math.random;try{for(let i=0;i<200;i++){const r=i/200;Math.random=()=>r;S.ev.ddos=null;S.ev.ddosMore=[];S.ddosStarts=[];fireFailure();if(ddosAll().length)return false;}return true;}finally{Math.random=old;S.inc=[];}})()"), 'spicy attacks come from their own schedule only, never twice');
+ ev("S.rules=makeRules('oncall');S.biz=[{type:'game',city:'fra',bw:5,rate:1,reqs:[]}]");
+ assert.ok(ev("(()=>{const old=Math.random;try{for(let i=0;i<200;i++){const r=i/200;Math.random=()=>r;S.ev.ddos=null;S.ev.ddosMore=[];S.ddosStarts=[];fireFailure();if(ddosAll().length)return false;}return true;}finally{Math.random=old;S.inc=[];}})()"), 'gamers\' attacks come from their own schedule only, never twice');
+ ev("S.biz=[]");
ev("S.rules=makeRules('oncall')");
// Flood Season, not spicy: one flood at a time, 3 to 7 days apart, however old the scenario is.
ev("ACT.startScn({id:'flood',sure:1});S.biz=[]");
diff --git a/tests/helpers/reference-allocation.js b/tests/helpers/reference-allocation.js
index 00da767..a69d199 100644
--- a/tests/helpers/reference-allocation.js
+++ b/tests/helpers/reference-allocation.js
@@ -5,8 +5,8 @@ module.exports = `
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++;
- const candidates=E.filter(e=>e.usede.used(a.pref==='high'?0:1)-(b.pref==='high'?0:1)||Dv[CIDX[a.city]]-Dv[CIDX[b.city]]);
for(let i=0;i1e-6;){
let j=i+1;while(j