${esc(o.name)}
${esc(BIZ_T[o.type].l)} · ${CITY[o.city].name}${o.city2?' ⇄ '+CITY[o.city2].name:''} · ${bTerms(o)} · ${tr('ui.n_d_left',{n:o.exp-S.day})}${(o.reqs||[]).length?` · ${trn('hud_and_panels.n_special_requirement',o.reqs.length)}`:''}
${reqList(o)}
+ h+=`
${esc(o.name)}
${esc(BIZ_T[o.type].l)} · ${CITY[o.city].name}${o.city2?' ⇄ '+CITY[o.city2].name:''} · ${bTerms(o)} · ${tr('ui.n_d_left',{n:o.exp-S.day})}${(o.reqs||[]).length?` · ${trn('hud_and_panels.n_special_requirement',o.reqs.length)}`:''}
${bRisk(o)}${reqList(o)}
${has?btn(tr('common.accept'),'accept',{id:o.id},'green sm'):btn(tr('common.go_there'),'focusCity',{city:bCities(o).find(c=>!S.pops[c])},'ghost sm')}${btn(tr('common.decline'),'decline',{id:o.id},'ghost sm')}
${has?'':`
${tr('hud_and_panels.needs_a_pop_in_cities',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}
`}
`;}
}else if(UI.left==='noc'){
h+=`
${btn(tr('hud_and_panels.open_noc_dashboard'),'dash',{},'pink')}${btn(tr('common.connections'),'connOpen',{},'')}${btn(tr('common.traceroute'),'trace',{},'')}
`;
diff --git a/src/game/93-ui/50-city-panel.js b/src/game/93-ui/50-city-panel.js
index d3f0638..9850053 100644
--- a/src/game/93-ui/50-city-panel.js
+++ b/src/game/93-ui/50-city-panel.js
@@ -35,7 +35,7 @@ function cityPanel(c){
h+=`
${tr('common.business_customers')}
`;
const bz=S.biz.filter(b=>bCities(b).includes(c));
if(!bz.length)h+=`${tr('city_panel.no_businesses_yet_offers_pop_up')}
`;
- for(const b of bz)h+=`${esc(b.name)}
${esc(BIZ_T[b.type].l)}${b.city2?` ${CITY[b.city].name} ⇄ ${CITY[b.city2].name}`:''} · ${bTerms(b)}${BIZ_T[b.type].l2?` · ${b.sites?tr('city_panel.carrying_g_per_site',{g:fmtG(R.l2[b.id]||0)}):tr('city_panel.carrying_g',{g:fmtG(R.l2[b.id]||0)})}`:''}${BIZ_T[b.type].fiber&&!fiberOk(b)?' · '+tr('city_panel.fiber_is_down')+'':''}${BIZ_T[b.type].event&&eventLive(b)?` · ${tr('city_panel.serving_v',{v:pct(sfOf(R,b.city))})}`:''}${b.type==='scrub'&&!hasScrub()?' · '+tr('common.needs_a_scrubbing_center')+'':''}${S.day-(b.since||0)<15?` · ${tr('common.provisioning_n_d_grace',{n:15-(S.day-(b.since||0))})}`:''}
${reqList(b)}${BIZ_T[b.type].l2?routeCtl(b):''}
${tr('common.happiness_p',{p:Math.round(b.mood)})}
${btn(UI.confirm===b.id?tr('common.really_drop'):tr('common.drop'),'dropBiz',{id:b.id},'ghost sm')}
`;
+ for(const b of bz)h+=`${esc(b.name)}
${esc(BIZ_T[b.type].l)}${b.city2?` ${CITY[b.city].name} ⇄ ${CITY[b.city2].name}`:''} · ${bTerms(b)}${BIZ_T[b.type].l2?` · ${b.sites?tr('city_panel.carrying_g_per_site',{g:fmtG(R.l2[b.id]||0)}):tr('city_panel.carrying_g',{g:fmtG(R.l2[b.id]||0)})}`:''}${BIZ_T[b.type].fiber&&!fiberOk(b)?' · '+tr('city_panel.fiber_is_down')+'':''}${BIZ_T[b.type].event&&eventLive(b)?` · ${tr('city_panel.serving_v',{v:pct(sfOf(R,b.city))})}`:''}${b.type==='scrub'&&!hasScrub()?' · '+tr('common.needs_a_scrubbing_center')+'':''}${S.day-(b.since||0)<15?` · ${tr('common.provisioning_n_d_grace',{n:15-(S.day-(b.since||0))})}`:''}
${bRisk(b)}${reqList(b)}${BIZ_T[b.type].l2?routeCtl(b):''}
${tr('common.happiness_p',{p:Math.round(b.mood)})}
${btn(UI.confirm===b.id?tr('common.really_drop'):tr('common.drop'),'dropBiz',{id:b.id},'ghost sm')}
`;
h+=``+offersHere(c);
}else if(UI.tab==='up'){
h+=portNote(c)+latNote(c);
diff --git a/src/game/93-ui/70-link-panels.js b/src/game/93-ui/70-link-panels.js
index 353ce18..7e9f19b 100644
--- a/src/game/93-ui/70-link-panels.js
+++ b/src/game/93-ui/70-link-panels.js
@@ -121,7 +121,7 @@ function dfPanel(l){
}
function offersHere(c){
const os=S.offers.filter(o=>bCities(o).includes(c));if(!os.length)return '';
- return `
${tr('common.offers_here')}
${os.map(o=>`${esc(o.name)}
${esc(BIZ_T[o.type].l)}${o.city2?` ${CITY[o.city].name} ⇄ ${CITY[o.city2].name}`:''} · ${bTerms(o)} · ${tr('ui.n_d_left',{n:o.exp-S.day})}
${R.reach<0.99&&!BIZ_T[o.type].l2?`
${tr('link_panels.they_need_the_full_internet_your',{pct:pct(R.reach)})}
`:''}${o.type==='scrub'&&!hasScrub()?`
${tr('link_panels.needs_your_own_scrubbing_center')}
`:''}${reqList(o)}${bHas(o)?'':`
${tr('link_panels.needs_a_pop_in_cities_too',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}
`}
${bHas(o)?btn(tr('common.accept'),'accept',{id:o.id},'green sm'):''}${btn(tr('common.no'),'decline',{id:o.id},'ghost sm')}
`).join('')}`;
+ return `
${tr('common.offers_here')}
${os.map(o=>`${esc(o.name)}
${esc(BIZ_T[o.type].l)}${o.city2?` ${CITY[o.city].name} ⇄ ${CITY[o.city2].name}`:''} · ${bTerms(o)} · ${tr('ui.n_d_left',{n:o.exp-S.day})}
${R.reach<0.99&&!BIZ_T[o.type].l2?`
${tr('link_panels.they_need_the_full_internet_your',{pct:pct(R.reach)})}
`:''}${o.type==='scrub'&&!hasScrub()?`
${tr('link_panels.needs_your_own_scrubbing_center')}
`:''}${bRisk(o)}${reqList(o)}${bHas(o)?'':`
${tr('link_panels.needs_a_pop_in_cities_too',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}
`}
${bHas(o)?btn(tr('common.accept'),'accept',{id:o.id},'green sm'):''}${btn(tr('common.no'),'decline',{id:o.id},'ghost sm')}
`).join('')}`;
}
function linkPanel(id){
const l=S.links.find(x=>x.id===id);if(!l){UI.sel=null;return '';}
diff --git a/src/game/94-dashboard/10-progress.js b/src/game/94-dashboard/10-progress.js
index a2ce390..be14c3a 100644
--- a/src/game/94-dashboard/10-progress.js
+++ b/src/game/94-dashboard/10-progress.js
@@ -12,8 +12,8 @@ const SCN_PROG={stg:()=>[{l:tr('common.reach'),v:R.reach,max:0.45,txt:`${pct(R.r
darien:()=>[...['bog','lim','scl','sao'].map(c=>pChk(tr('progress.pop_in_city',{city:CITY[c].name}),!!S.pops[c])),pSrv(150)],
gangnam:()=>[pReach(),pSrv(200)],
fttb:()=>[...AU_BB.map(c=>pChk(tr('progress.broadband_in_city',{city:CITY[c].name}),!!(S.pops[c]&&S.pops[c].bb))),{l:tr('common.cables_overseas'),v:Math.min(2,auExits()),max:2,txt:`${auExits()} / 2`}],
- flood:()=>{const ok=S.stats.ddosOk||0,big=S.stats.ddosOkBig||0,a=S.ev.ddos&&S.ev.ddos.until>S.day?S.ev.ddos:null;
- return [{l:tr('common.floods_held'),v:ok,max:20,txt:`${ok} / 20`},{l:tr('progress.terabit_floods_held'),v:big,max:5,txt:`${big} / 5`},{l:tr('progress.floods_that_got_through'),v:0,max:0,txt:String(S.stats.ddosLost||0)}].concat(a?[{l:tr('progress.under_attack_now'),v:0,max:0,txt:`${fmtG(a.gbps)} · ${CITY[a.city].name} · ${pct(a.worst===undefined?1:a.worst)}`}]:[]);},baltic:()=>[{l:tr('progress.days_in_a_row_with_99'),v:S.stats.clean||0,max:90,txt:tr('progress.n_of_m',{n:S.stats.clean||0,m:90})}]};
+ flood:()=>{const ok=S.stats.ddosOk||0,big=S.stats.ddosOkBig||0,attacks=ddosAll();
+ return [{l:tr('common.floods_held'),v:ok,max:20,txt:`${ok} / 20`},{l:tr('progress.terabit_floods_held'),v:big,max:5,txt:`${big} / 5`},{l:tr('progress.floods_that_got_through'),v:0,max:0,txt:String(S.stats.ddosLost||0)}].concat(attacks.map(a=>({l:tr('progress.under_attack_now'),v:0,max:0,txt:`${fmtG(a.gbps)} · ${CITY[a.city].name} · ${pct(a.worst===undefined?1:a.worst)}`})));},baltic:()=>[{l:tr('progress.days_in_a_row_with_99'),v:S.stats.clean||0,max:90,txt:tr('progress.n_of_m',{n:S.stats.clean||0,m:90})}]};
function scnProg(){const sc=S&&S.scn;if(!sc)return null;
if(sc.id==='weekly')return {goal:tr('common.serve_as_much_traffic_as_you'),items:[{l:tr('progress.your_score_peak_traffic'),v:0,max:0,txt:fmtG(S.stats.peak||0)}],f:Math.min(1,S.day/sc.days)};
const def=SCN.find(x=>x.id===sc.id),fn=SCN_PROG[sc.id];if(!def)return null;let items=[];try{items=fn?fn():[];}catch(e){items=[];}
diff --git a/src/game/94-dashboard/30-customers.js b/src/game/94-dashboard/30-customers.js
index 54dd168..8ff718e 100644
--- a/src/game/94-dashboard/30-customers.js
+++ b/src/game/94-dashboard/30-customers.js
@@ -30,5 +30,5 @@ function custSection(){const F=UI.kf||{};let h=`
b.pm===undefined||Math.abs(b.mood-b.pm)<0.05?'':b.mood>b.pm?'
▲':'
▼';
const sorts=[['mood',tr('common.happiness')],['mo',tr('common.per_month')],['name',tr('common.name')],['city',tr('common.where')]];
h+=`
${sorts.map(([k,l])=>btn(l+(sk===k?(dir>0?' ▲':' ▼'):''),'custSort',{k},sk===k?'pink sm':'ghost sm')).join('')}
`;
- h+=rows.slice(0,listN('cust')).map(b=>{const why=bizWhy(b),grace=S.day-(b.since||0)<15;return `
${esc(b.name)} ${esc(BIZ_T[b.type].l)}
${esc(where(b))} · ${BIZ_T[b.type].event?esc(bTerms(b)):tr('common.price_mo',{price:fmt$(bizMo(b))})}${grace?` · ${tr('common.provisioning_n_d_grace',{n:15-(S.day-(b.since||0))})}`:''}
${why.length?`
${why.map(esc).join(' · ')}
`:''}
${tr('common.happiness_p',{p:Math.round(b.mood)})}${trend(b)}
${btn(tr('common.open'),'custGo',{id:b.id},'ghost sm')}
`;}).join('');
+ h+=rows.slice(0,listN('cust')).map(b=>{const why=bizWhy(b),grace=S.day-(b.since||0)<15;return `
${esc(b.name)} ${esc(BIZ_T[b.type].l)}
${esc(where(b))} · ${BIZ_T[b.type].event?esc(bTerms(b)):tr('common.price_mo',{price:fmt$(bizMo(b))})}${grace?` · ${tr('common.provisioning_n_d_grace',{n:15-(S.day-(b.since||0))})}`:''}
${bRisk(b)}${why.length?`
${why.map(esc).join(' · ')}
`:''}
${tr('common.happiness_p',{p:Math.round(b.mood)})}${trend(b)}
${btn(tr('common.open'),'custGo',{id:b.id},'ghost sm')}
`;}).join('');
return h+listMore('cust',rows.length,n=>trn('customers.n_more_customer',n))+`
`;}
diff --git a/src/i18n/en.js b/src/i18n/en.js
index f04c34a..d3a0b76 100644
--- a/src/i18n/en.js
+++ b/src/i18n/en.js
@@ -779,6 +779,7 @@
"common.95th_percentile":"95th percentile",
"common.about_average":"about average",
"common.accept":"Accept",
+"common.ack_flood":"ACK flood",
"common.ad_campaign":"Ad campaign!",
"common.africa":"Africa",
"common.all_cities":"All cities",
@@ -902,6 +903,7 @@
"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",
@@ -1059,6 +1061,7 @@
"common.may":"May",
"common.member":"− member",
"common.member_fef5":"Member",
+"common.memcached_amplification":"Memcached amplification",
"common.merchant_silicon":"merchant silicon",
"common.mercury":"Mercury",
"common.metaverse_platform":"Metaverse platform",
@@ -1161,6 +1164,7 @@
"common.price_lock":"Price lock",
"common.price_mo":"{price}/mo",
"common.provisioning_n_d_grace":"provisioning, {n}d grace",
+"common.racknet":"RackNet",
"common.rank":"Rank",
"common.rare":"Rare",
"common.reach":"Reach",
@@ -1275,6 +1279,7 @@
"common.subsea_cables":"Subsea cables",
"common.supply_chain":"Supply chain",
"common.syn_flood":"SYN flood",
+"common.teamspooked":"TeamSpooked",
"common.terrestrial":"terrestrial",
"common.terrestrial_19e4":"Terrestrial",
"common.terrestrial_fiber":"Terrestrial fiber",
@@ -1406,6 +1411,7 @@
"customers.you_need_a_pop_in_every":"
You need a POP in every city on the contract first.",
"customers_and_events.bw_extra_for_d_days_when":"{bw} extra for {d} days, {when} · pays {fee} when it is over",
"customers_and_events.day_n_of_d":"day {n} of {d}",
+"customers_and_events.gaming_attracts_attacks":"Gaming attracts attacks",
"customers_and_events.n_fiber_pairs_in_your_a":"{n} fiber pairs in your {a}–{b} trench. Trenching was the expensive part, so they want all of it",
"customers_and_events.n_sites_list_bw_per_site":"{n} sites: {list} · {bw} per site · {price}/mo",
"customers_and_events.name_at_site":"{name} at {site}",
@@ -1622,6 +1628,7 @@
"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.",
@@ -1984,13 +1991,17 @@
"incidents_and_ddos.a_leap_second_convinced_one_of":"A leap second convinced one of your routers it is 1970. Uptime now reads minus 56 years. Traffic is fine.",
"incidents_and_ddos.a_route_you_withdrew_in_year":"A route you withdrew in Year 1 is still visible somewhere in the internet. Nobody knows where. It is fine. Probably.",
"incidents_and_ddos.a_two_hour_meeting_about_router":"A two-hour meeting about router hostnames ended with a vote for “router-final-v2-NEW”.",
+"incidents_and_ddos.after_upstream_scrubbing_g":"After upstream scrubbing: {g}",
"incidents_and_ddos.an_auditor_asked_for_a_network":"An auditor asked for a network diagram. You sent the game map. They approved it.",
+"incidents_and_ddos.attack_fully_mitigated":"Attack fully mitigated",
"incidents_and_ddos.blackhole_the_target_rtbh":"Blackhole the target (RTBH)",
"incidents_and_ddos.blackholed_the_junk_is_gone_and":"Blackholed: the junk is gone, and so is {city}. The attack got what it wanted.",
"incidents_and_ddos.contained_on_your_sacrificial_net":"Contained on your sacrificial {net} PNI",
-"incidents_and_ddos.flowspec_cannot_catch_an_vec":"Flowspec cannot catch an {vec} (application layer)",
-"incidents_and_ddos.flowspec_on_your_model_is_dropping":"Flowspec on your {model} is dropping {vec} at the edge",
-"incidents_and_ddos.flowspec_on_your_model_trims_vec":"Flowspec on your {model} trims {vec}, but its TCAM is small",
+"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",
"incidents_and_ddos.ix_blackhole_half_honour_it":"IX blackhole
~half honour it",
@@ -2001,29 +2012,29 @@
"incidents_and_ddos.load_bearing_typo":"Load-bearing typo",
"incidents_and_ddos.management_declared_a_change_freeze":"Management declared a change freeze. Someone made a change to announce the change freeze.",
"incidents_and_ddos.name_transit_lag_in_city":"{name} transit LAG in {city}",
-"incidents_and_ddos.net_is_scrubbing_it_upstream_clean":"{net} is scrubbing it upstream (clean-pipe)",
+"incidents_and_ddos.no_flowspec_filtering_ingress":"No Flowspec filtering: ingress routers have no TCAM",
"incidents_and_ddos.no_scrubbing_center":"No scrubbing center",
+"incidents_and_ddos.no_scrubbing_needed_after_edge":"No scrubbing needed after edge mitigation",
"incidents_and_ddos.on_demand_scrubbing_diverting_live":"On-demand scrubbing diverting, live in {n}d",
"incidents_and_ddos.open_to_work":"Open to work",
"incidents_and_ddos.pni_lag_with_name_in_city":"PNI LAG with {name} in {city}",
-"incidents_and_ddos.reaching_your_network_g":"Reaching your network: {g}",
"incidents_and_ddos.rtbh_is_free_and_instant_but":"RTBH is free and instant, but it drops everything to the victim, attack and customer alike. An IX blackhole keeps the customer up but only about half the members honour it. HackBack 3000™ by Skynot AI sometimes ends it, and sometimes flattens an innocent and earns you a fine.",
+"incidents_and_ddos.scrubbing_centers_unavailable_or_at":"Scrubbing centers unavailable or at capacity",
+"incidents_and_ddos.scrubbing_in_city_used_capacity":"Scrubbing in {city}: {used} / {capacity}",
+"incidents_and_ddos.scrubbing_traffic_hauled_over_your":"Scrubbing traffic hauled over your backbone: {city} → {to} (+{ms} ms)",
"incidents_and_ddos.size_vec_entry_n_d_left":"{size} · {vec}{entry} · {n}d left",
"incidents_and_ddos.someone_deleted_the_dns_record_for":"Someone deleted the DNS record for the internal wiki. The runbook for fixing DNS was on the wiki.",
"incidents_and_ddos.someone_named_a_vlan_prodcution_it":"Someone named a VLAN “prodcution”. It is now load-bearing and can never be renamed.",
"incidents_and_ddos.the_tls_certificate_on_your_noc":"The TLS certificate on your NOC dashboard expired. Nobody can see any graphs, so technically there are no problems.",
+"incidents_and_ddos.this_attack_g":"This attack: {g}",
"incidents_and_ddos.ticket_of_the_week":"Ticket of the week",
-"incidents_and_ddos.tier_scrubbing_in_city_is_cleaning":"{tier} scrubbing in {city} is cleaning it, hauled over your backbone (+{ms} ms)",
-"incidents_and_ddos.tier_scrubbing_in_city_is_cleaning_a8f6":"{tier} scrubbing in {city} is cleaning it",
"incidents_and_ddos.vendor_support_asked_you_to_try":"Vendor support asked you to “try turning it off and on again”. For the router you already rebooted. Ticket closed.",
"incidents_and_ddos.you_found_a_10g_link_in":"You found a 10G link in the inventory that nobody ordered, nobody pays for, and that carries 3 Gbps of something.",
"incidents_and_ddos.your_backbone_can_only_haul_g":"Your backbone can only haul {g} of it to {city}: the rest is not scrubbed",
"incidents_and_ddos.your_ip_address_spreadsheet_hit_1":"Your IP address spreadsheet hit 1,048,576 rows. Excel has opinions.",
"incidents_and_ddos.your_ipv6_traffic_grew_400_from":"Your IPv6 traffic grew 400%. From one packet to five.",
-"incidents_and_ddos.your_model_here_has_no_flowspec":"Your {model} here has no Flowspec TCAM",
"incidents_and_ddos.your_monitoring_system_went_down_you":"Your monitoring system went down. You found out because nothing alerted. Very peaceful week.",
"incidents_and_ddos.your_peering_coordinator_updated":"Your peering coordinator updated their profile to “open to work”. Three Tier 1s suddenly want to chat. Nothing happened, but it felt nice.",
-"incidents_and_ddos.your_scrubbing_centers_are_full_g":"Your scrubbing centers are full: {g} leaks past",
"incidents_and_ddos.your_upstream_support_line_plays_the":"Your upstream support line plays the same 11 seconds of hold music. Your on-call engineer can now hum it in four keys.",
"install.before_you_start":"Before you start",
"install.best_played_as_an_app":"Best played as an app",
diff --git a/tests/game.test.js b/tests/game.test.js
index a02b2c4..490b817 100644
--- a/tests/game.test.js
+++ b/tests/game.test.js
@@ -2,6 +2,16 @@ const test = require('node:test');
const assert = require('node:assert/strict');
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 (or gaming customers): stand in for the chaos rule here.
+ ev("window.rule=k=>k==='chaos'?'spicy':undefined;ACT.start({});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');
+ assert.deepEqual(errors, []);
+});
+
test('page boots to the title screen without errors', () => {
const { ev, errors } = load();
assert.equal(ev("document.getElementById('modal').hidden"), false);
@@ -197,6 +207,52 @@ test('Flowspec is a router-model capability, and each tool answers a flood', ()
assert.deepEqual(errors, []);
});
+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()");
+ 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/);
+ assert.match(ev('ddosPanel()'), /✓ Scrubbing in Frankfurt: 30\.2 Gbps \/ 100G/);
+ assert.doesNotMatch(ev('ddosPanel()'), /✓ Flowspec|After upstream scrubbing|Reaching your network/);
+ for (const [router, dropped, scrubbed] of [[1,18.12,12.08], [3,25.67,4.53]]) {
+ ev(`S.pops.fra.rgen=${router};compute()`);
+ assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).flowspec')-dropped)<1e-9);
+ assert.ok(Math.abs(ev('ddosReport(S.ev.ddos).sp.parts[0].cleaned')-scrubbed)<1e-9);
+ assert.match(ev('ddosPanel()'), new RegExp('✓ Flowspec dropping: '+dropped.toFixed(1).replace('.', '\\.')+' Gbps'));
+ assert.match(ev('ddosPanel()'), new RegExp('Scrubbing in Frankfurt: '+scrubbed.toFixed(1).replace('.', '\\.')+' Gbps / 100G'));
+ assert.doesNotMatch(ev('ddosPanel()'), /no TCAM|Edge filters dropping/);
+ }
+ ev("S.ev.ddos.vec='ack';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()'), /— Flowspec cannot catch ACK flood/);
+ assert.deepEqual(errors, []);
+});
+
+test('Flowspec accounts for each ingress router, upstream cleaning and other edge filters 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/);
+ 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()");
@@ -593,3 +649,495 @@ test('a custom metric belongs to the city pair, like the presets, and a standby
assert.equal(ev("FK in S.pairMet"), false);
assert.deepEqual(errors, []);
});
+
+
+test('Memcached amplification and ACK flood are available without gaming customers and respect Flowspec', () => {
+ const { ev, errors } = load();
+ ev("ACT.start({});S.cash=1e8;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=200;ACT.buyTransit({city:'fra',net:'cog',tier:1});RG[0].fs=2");
+ assert.equal(ev('S.biz.length'), 0);
+ assert.equal(ev('DDOS_VEC.memcached.fs'), true);
+ assert.equal(ev('DDOS_VEC.ack.fs'), false);
+ ev("S.ev.ddos={city:'fra',vec:'ack',gbps:300,until:S.day+3,start:S.day};compute()");
+ const ack = ev('R.served');
+ assert.match(ev('ddosPanel()'), /ACK flood/);
+ assert.doesNotMatch(ev('ddosPanel()'), /application layer/);
+ ev("S.ev.ddos.vec='memcached';compute()");
+ assert.ok(ev('R.served') > ack, 'Flowspec filters Memcached but cannot filter ACK');
+ for (const vec of ['memcached', 'ack']) {
+ ev(`const old=Math.random;Math.random=()=>(${['dns','ntp','memcached','ack'].indexOf(vec)}+0.1)/ddosVectors().length;ddosAttack();Math.random=old`);
+ assert.equal(ev('ddosAll().at(-1).vec'), vec, 'the generator can select each new vector');
+ }
+ assert.deepEqual(errors, []);
+});
+
+
+test('DDoS accounting conserves attack bandwidth through upstream, edge and local scrubbing', () => {
+ const { ev, errors } = load();
+ ev("ACT.start({});S.cash=1e9;ACT.launchBB({city:'fra'});ACT.buyTransit({city:'fra',net:'cog',tier:1});S.pops.fra.bb.d=100;S.scrubs=[{city:'fra',tier:1}];S.transit[0].clean=true;S.ev.ddos={city:'fra',vec:'http',gbps:1842,until:5,start:0,entry:{k:'t',id:S.transit[0].id}};compute()");
+ assert.ok(Math.abs(ev('R.ddos[0].reaching') - 184.2) < 1e-9);
+ assert.equal(ev('R.ddos[0].sp.parts[0].cleaned'), ev('R.ddos[0].reaching'));
+ assert.equal(ev('R.ddos[0].leak'), 0, 'the 1T center cleans the upstream remainder');
+ assert.doesNotMatch(ev('ddosPanel()'), /842 Gbps of attack traffic leaks/);
+ ev('S.transit[0].clean=false;compute()');
+ assert.equal(ev('R.ddos[0].reaching'), 1842);
+ assert.equal(ev('R.ddos[0].leak'), 842);
+ for (const setup of ["S.transit[0].clean=true", "RG[0].fs=2;S.ev.ddos.vec='dns'", "S.scrubs=[]"]) {
+ ev(setup+';compute()');
+ assert.ok(ev('Math.abs(R.ddos[0].reaching-R.ddos[0].filtered-(R.ddos[0].sp?.parts.reduce((n,x)=>n+x.cleaned,0)||0)-R.ddos[0].leak)<1e-9'));
+ assert.ok(ev('R.ddos[0].leak<=R.ddos[0].reaching'));
+ }
+ // On-demand diversion must also work for an attack which began on day zero.
+ ev("S.scrubs=[{city:'fra',tier:1}];S.scrubMode='ondemand';S.day=2;compute()");
+ assert.equal(ev('R.ddos[0].leak'), 0);
+ assert.deepEqual(errors, []);
+});
+
+
+test('the NOC integrates DDoS mitigation totals into each live attack card without duplicate summaries on phones', () => {
+ const { ev, errors, dom } = load();
+ ev('ACT.start({})');
+ Object.defineProperty(dom.window, 'innerWidth', { value: 360, configurable: true });
+ ev("S.cash=1e9;ACT.buyTransit({city:'fra',net:'cog',tier:1});S.transit[0].clean=true;S.scrubs=[{city:'fra',tier:1}];S.ev.ddos={city:'fra',vec:'http',gbps:3840,until:5,start:0,entry:{k:'t',id:S.transit[0].id}};compute();UI.left='noc';UI.leftOpen=true;renderLeft()");
+ const card = () => dom.window.document.querySelector('[data-act="rtbh"], [data-act="unrtbh"]').closest('.inc');
+ const text = () => card().textContent;
+ assert.match(card().querySelector('.nm').textContent, /🚨 Live attack: Frankfurt/);
+ assert.equal(dom.window.document.querySelector('.ddos-stats'), null, 'use the existing attack card');
+ assert.doesNotMatch(text(), /DDoS mitigation status|Attack size:|3840 Gbps|This attack:/);
+ assert.equal(text().match(/3\.84 Tbps/g).length, 1, 'the attack size appears once');
+ assert.match(text(), /✓ After upstream scrubbing: 384 Gbps/);
+ assert.equal(text().match(/After upstream scrubbing/g).length, 1, 'show the upstream remainder once');
+ assert.doesNotMatch(text(), /Reaching your network|reaching your network|Upstream scrubbing active/);
+ assert.match(text(), /✓ Scrubbing in Frankfurt: 384 Gbps \/ 1T/);
+ assert.match(text(), /✓ Attack fully mitigated/);
+ ev('S.transit[0].clean=false;compute();renderLeft()');
+ assert.doesNotMatch(text(), /After upstream scrubbing|Reaching your network/);
+ assert.equal(text().match(/3\.84 Tbps/g).length, 1, 'inactive upstream scrubbing does not repeat the attack size');
+ assert.match(text(), /✓ Scrubbing in Frankfurt: 1\.00 Tbps \/ 1T/);
+ assert.match(text(), /~ 2\.84 Tbps is leaking through/);
+ assert.equal(text().match(/leaking through/g).length, 1, 'show the mitigation outcome once');
+ assert.doesNotMatch(text(), /Upstream scrubbing|Attack fully mitigated|leaks past mitigation/);
+ ev("S.transit[0].clean=true;S.pops.fra.rgen=3;S.ev.ddos.vec='dns';compute();renderLeft()");
+ assert.match(text(), /✓ Flowspec dropping: 326 Gbps/);
+ assert.doesNotMatch(text(), /Edge filters dropping/);
+ assert.match(text(), /✓ Scrubbing in Frankfurt: 57\.6 Gbps \/ 1T/);
+ assert.match(text(), /✓ Attack fully mitigated/);
+ ev('ACT.rtbh();renderLeft()');
+ assert.match(text(), /~ Blackholed: the junk is gone, and so is Frankfurt/);
+ assert.equal(text().match(/Blackholed:/g).length, 1);
+ assert.doesNotMatch(text(), /After upstream scrubbing|reaching your network|scrubbing in Frankfurt|Attack fully mitigated|leaking through/i);
+ assert.ok(card().querySelector('[data-act="unrtbh"]'), 'the existing controls stay in the card');
+ assert.deepEqual(errors, []);
+});
+
+test('overlapping floods share scrubbing capacity, have separate controls, and finish independently', () => {
+ const { ev, errors, dom } = load();
+ ev("ACT.start({});S.cash=1e9;S.nextFail=1e9;S.nextEvent=1e9;ACT.buyTransit({city:'fra',net:'cog',tier:1});S.scrubs=[{city:'fra',tier:1}];S.ev.ddos={id:'one',city:'fra',vec:'http',gbps:700,start:0,until:3};S.ev.ddosMore=[{id:'two',city:'fra',vec:'http',gbps:700,start:0,until:5}];compute();UI.left='noc';UI.leftOpen=true;renderLeft()");
+ assert.equal(ev('R.ddos.length'), 2);
+ assert.equal(ev('R.ddos.reduce((n,m)=>n+(m.sp?.parts.reduce((v,x)=>v+x.cleaned,0)||0),0)'), 1000);
+ assert.equal(ev('R.ddos.reduce((n,m)=>n+m.leak,0)'), 400, 'one center cannot spend its capacity twice');
+ const cards = [...dom.window.document.querySelectorAll('[data-act="rtbh"]')].map(b=>b.closest('.inc'));
+ assert.equal(cards.length, 2);
+ assert.match(cards[1].textContent, /✓ Scrubbing in Frankfurt: 1\.00 Tbps \/ 1T · This attack: 300 Gbps/);
+ ev("ACT.rtbh({id:'two'})");
+ assert.equal(ev("S.ev.ddos.bh||false"), false, 'the selected attack gets the control');
+ assert.equal(ev('S.ev.ddosMore[0].bh'), true);
+ assert.ok(ev('R.ddos.every(m=>m.leak===0)'), 'blackholing a target city drops every flood to it');
+ ev("ACT.unrtbh({id:'one'});const old=Math.random;Math.random=()=>0.1;ACT.hackback({id:'two'});Math.random=old");
+ assert.equal(ev('ddosAll().length'), 1, 'hack-back ends only the selected attack');
+ ev('S.day=3;ddosExpire();compute()');
+ assert.equal(ev('ddosAll().length'), 0);
+ assert.equal(ev('(S.stats.ddosOk||0)+(S.stats.ddosLost||0)'), 2, 'both attacks scored once');
+ ev('ddosExpire()');
+ assert.equal(ev('(S.stats.ddosOk||0)+(S.stats.ddosLost||0)'), 2);
+ assert.deepEqual(errors, []);
+});
+
+test('overlapping DDoS saves round trip and legacy attacks migrate safely', () => {
+ const { ev, errors } = load();
+ ev("ACT.start({});S.ev.ddos={city:'fra',vec:'dns',gbps:'80',until:7,start:0};delete S.ev.ddosMore;delete S.ddosStarts;S=migrate(JSON.parse(JSON.stringify(S)))");
+ assert.equal(ev('ddosAll().length'), 1);
+ assert.equal(ev('S.ev.ddos.gbps'), 80);
+ assert.equal(ev('S.ev.ddosMore.length'), 0);
+ assert.deepEqual(JSON.parse(ev('JSON.stringify(S.ddosStarts)')), [0]);
+ ev("S.ev.ddosMore=[{id:'overlap',city:'fra',vec:'ack',gbps:50,until:5,start:0,sla:['customer']},null,{city:'bad',vec:'dns'}, {city:'fra',vec:'unknown'}];S.ddosStarts=[0,'bad',Infinity,-9,99];S=migrate(JSON.parse(JSON.stringify(S)))");
+ assert.equal(ev('ddosAll().length'), 2);
+ assert.equal(ev('S.ev.ddosMore[0].id'), 'overlap');
+ assert.deepEqual(JSON.parse(ev('JSON.stringify(S.ddosStarts)')), [0]);
+ ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()');
+ assert.equal(ev('R.ddos.length'), 2);
+ assert.deepEqual(errors, []);
+});
+
+test('simultaneous attacks each bill their protected customer only once', () => {
+ const { ev, errors } = load();
+ ev("ACT.start({});S.cash=1e9;S.nextFail=1e9;S.nextEvent=1e9;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=200;ACT.buyTransit({city:'fra',net:'cog',tier:1});S.biz=[{id:'protected',name:'Shield',city:'fra',type:'scrub',bw:5,rate:900,mood:100,since:0,reqs:[]}];S.ev.ddos={id:'one',city:'fra',vec:'http',gbps:6000,start:0,until:7};S.ev.ddosMore=[{id:'two',city:'fra',vec:'http',gbps:6000,start:0,until:7}];compute();dayTick()");
+ assert.equal(ev('S.stats.sla'), 2, 'same-day attacks have separate SLA identities');
+ ev('S=migrate(JSON.parse(JSON.stringify(S)));dayTick()');
+ assert.equal(ev('S.stats.sla'), 2, 'reloading does not pay the same credits twice');
+ assert.deepEqual(errors, []);
+});
+
+test('DDoS frequency rises with level and signed gaming customers, with a rolling weekly ceiling', () => {
+ const { ev, errors } = load();
+ ev("ACT.start({});S.day=50;S.lvl=1;S.biz=[]");
+ const base = ev('ddosRate()');
+ assert.equal(base, 0.5);
+ ev('S.lvl=13');
+ assert.equal(ev('ddosRate()'), base, 'level alone does not increase the non-gaming rate');
+ ev("S.biz=[{type:'game',city:'fra'}];S.lvl=1");
+ const early = ev('ddosRate()');
+ ev('S.lvl=13');
+ const level = ev('ddosRate()');
+ ev("S.biz=Array.from({length:20},(_,i)=>({type:i%2?'cgame':'game',city:'fra'}))");
+ const gaming = ev('ddosRate()');
+ 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("window.rule=k=>k==='chaos'?'spicy':undefined;");
+ 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))`);
+ assert.ok(ev('S.ddosStarts.length') <= 14);
+ }
+ ev('Math.random=window.__oldRandom');
+ const starts = JSON.parse(ev('JSON.stringify(window.__starts)'));
+ for (let day = 50; day < 66; day++) assert.ok(starts.filter(d=>d>day-7&&d<=day).length <= 14);
+ assert.ok(starts.length > 14, 'the allowance renews as starts leave the rolling window');
+ ev('for(let i=0;i<30;i++)ddosAttack()');
+ assert.equal(ev('S.ddosStarts.length'), 14, 'manual and incident starts cannot bypass the cap');
+ assert.deepEqual(errors, []);
+});
+
+test('DDoS sizes use a smaller non-gaming baseline and preserve unbounded Flood Season scaling', () => {
+ const { ev, errors } = load();
+ ev('ACT.start({});S.lvl=13;R.demand=150000;S.biz=[]');
+ assert.equal(ev('ddosSizeMean()'), 20000);
+ ev("S.scn={id:'flood',rules:{ddos:true}};S.day=365");
+ assert.equal(ev('ddosSizeMean()'), 400000);
+ ev('S.day=730');
+ assert.equal(ev('ddosSizeMean()'), 600000, 'Flood Season keeps growing after completion');
+ ev('S.scn=null;R.demand=300000');
+ assert.equal(ev('ddosSizeMean()'), 40000, 'larger networks can draw still larger attacks');
+ ev('S.lvl=1');
+ const early = ev('ddosSizeMax()');
+ ev('S.lvl=13');
+ const late = ev('ddosSizeMax()');
+ ev("S.biz=[{type:'game',city:'fra'}]");
+ assert.ok(early < late && late < ev('ddosSizeMax()'));
+ // Fixed quantiles show longer durations as both level and gaming exposure rise.
+ ev('window.__oldRandom=Math.random;Math.random=()=>0.95;S.lvl=1;S.biz=[];ddosAttack();window.__earlyDur=ddosAll().at(-1).until-S.day;S.lvl=13;S.biz=Array.from({length:40},()=>({type:\'game\',city:\'fra\',bw:0,rate:0}));ddosAttack();Math.random=window.__oldRandom');
+ assert.ok(ev('ddosAll().at(-1).until-S.day') > ev('window.__earlyDur'));
+ assert.equal(ev('ddosAll().at(-1).until-S.day'), 7);
+ 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});
+ for(const c in S.pops)S.pops[c].rgen=3;
+ S.links=[{id:'fp1',a:'fra',b:'prg',kind:'wave',tier:2,km:409,mo:100},
+ {id:'fp2',a:'fra',b:'prg',kind:'wave',tier:2,km:409,mo:100},
+ {id:'fb',a:'fra',b:'ber',kind:'wave',tier:2,km:420,mo:100},
+ {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()`);
+ 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');
+ assert.deepEqual(sources('fp1').map(x=>x.city), ['prg']);
+ assert.deepEqual(sources('fb').map(x=>x.city), ['ber']);
+ assert.ok(sources('fp1')[0].g>0 && sources('fb')[0].g>0);
+ assert.ok(Math.abs(sources('fp1')[0].g-ev('R.load.fp1+R.load.fp2'))<1e-9, 'the grouped record covers both parallel links exactly');
+ ev("selectLink('fp1');draw(0)");
+ const row = [...dom.window.document.querySelectorAll('#panelBody .row')].find(x=>x.querySelector('.nm')?.textContent==='Attack hauled to scrubbing in Frankfurt');
+ assert.ok(row);
+ assert.match(row.querySelector('.meta').textContent, /^Prague · /);
+ assert.equal(JSON.parse(row.querySelector('[data-act="goEgress"]').dataset.args).city, 'prg');
+ 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()");
+ 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.
+ ev('S.links.find(l=>l.id==="fb").cut=S.day+1;compute()');
+ assert.ok(ev('R.load.pb')>0);
+ assert.deepEqual(sources('fp1').map(x=>x.city), ['ber','prg']);
+ assert.deepEqual(sources('pb').map(x=>x.city), ['ber']);
+ assert.ok(Math.abs(sources('fp1').reduce((n,x)=>n+x.g,0)-ev('R.load.fp1+R.load.fp2'))<1e-9, 'shared-path totals still equal the actual link load');
+ assert.deepEqual(errors, []);
+});
+
+function setupScrubLatency(ev) {
+ ev(`ACT.start({});S.cash=1e9;S.lvl=6;for(const c of ['par','nyc','ams'])ACT.buildPop({city:c});
+ for(const c in S.pops)S.pops[c].rgen=RG.findIndex(g=>g.fs===1);
+ S.links=[{id:'pf',a:'par',b:'fra',kind:'wave',tier:3,km:620/1.3,mo:100},
+ {id:'fn',a:'fra',b:'nyc',kind:'wave',tier:3,km:6000,mo:100},
+ {id:'fa',a:'fra',b:'ams',kind:'wave',tier:3,km:200,mo:100}];
+ 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()`);
+}
+
+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);
+ ev("for(const c in S.pops)S.pops[c].rgen=3;S.scrubs=[{city:'fra',tier:0},{city:'ams',tier:0}];S.ev.ddos.vec='ack';S.ev.ddos.gbps=230;compute()");
+ assert.equal(ev('ddosReport(S.ev.ddos).sp.parts.length'), 2, 'capacity spills between centers');
+ const card = ev('ddosOne(S.ev.ddos)');
+ 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()");
+ 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()");
+ 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/);
+ ev('S.ev.ddos.bh=false;S.scrubMode="ondemand";compute()');
+ assert.doesNotMatch(ev('ddosOne(S.ev.ddos)'), /Scrubbing traffic hauled over your backbone/);
+ assert.deepEqual(errors, []);
+});
+
+test('a constrained remote haul leaves scrubbing capacity for the next overlapping flood', () => {
+ 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.links=[{id:'thin',a:'nyc',b:'fra',kind:'wave',tier:1,km:6000,mo:100}];S.scrubs=[{city:'fra',tier:1}];S.ev.ddos={id:'far',city:'nyc',vec:'http',gbps:600,start:0,until:7};S.ev.ddosMore=[{id:'near',city:'fra',vec:'http',gbps:900,start:0,until:7}];compute()");
+ const clean = JSON.parse(ev('JSON.stringify(R.ddos.map(m=>({id:m.attack.id,clean:m.sp?.parts.reduce((n,x)=>n+x.cleaned,0)||0,leak:m.leak})))'));
+ assert.equal(clean.find(m=>m.id==='near').clean, 900);
+ assert.ok(clean.find(m=>m.id==='far').clean <= 100);
+ assert.ok(clean.reduce((n,m)=>n+m.clean,0) <= 1000);
+ for (const m of clean) assert.equal(m.clean+m.leak, m.id==='near'?900:600);
+ 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()");
+ assert.equal(ev("ddosVectors().includes('racknet')||ddosVectors().includes('teamspooked')"), false);
+ ev("S.offers=[{type:'game'}]");
+ assert.equal(ev("ddosVectors().includes('racknet')"), false, 'an unsigned offer does not introduce gaming attacks');
+ ev("S.biz=[{type:'game',id:'gamer',name:'Gamer',city:'fra',bw:0,rate:0}];compute()");
+ for (const vec of ['racknet','teamspooked']) {
+ assert.equal(ev(`DDOS_VEC.${vec}.fs`), false);
+ const sizeMax = ev('ddosSizeMax()/3');
+ ev(`const old=Math.random;let n=0;Math.random=()=>n++===1?(ddosVectors().indexOf('${vec}')+0.5)/ddosVectors().length:0.999999;ddosAttack();Math.random=old`);
+ assert.equal(ev('ddosAll().at(-1).vec'), vec);
+ assert.ok(ev('ddosAll().at(-1).gbps') <= sizeMax);
+ assert.ok(ev('ddosAll().at(-1).gbps') > sizeMax*(1-0.00002), 'the upper randomized quantile approaches the one-third limit, including rare spikes');
+ }
+ ev("S.biz[0].type='cgame'");
+ assert.equal(ev("ddosVectors().includes('teamspooked')"), true, 'cloud gaming also attracts these vectors');
+ ev('S.biz=[]');
+ assert.equal(ev("ddosVectors().includes('teamspooked')"), false);
+ assert.equal(ev('ddosAll().length'), 2, 'existing attacks finish naturally after the gaming customer leaves');
+ assert.deepEqual(errors, []);
+});
+
+test('normal DDoS starts average half an attack per week without gaming and never exceed a seven-per-week expected rate', () => {
+ const { ev, errors } = load();
+ ev("window.rule=k=>k==='chaos'?'spicy':undefined;ACT.start({});S.day=50");
+ const checks = JSON.parse(ev(`
+ const oldAttack=ddosAttack,oldRandom=Math.random,out=[];
+ try {
+ for(const [level,games] of [[1,0],[13,0],[1,1],[13,1],[13,10],[13,1000]]){
+ S.lvl=level;S.biz=Array.from({length:games},()=>({type:'game'}));
+ let starts=0,draw=0;ddosAttack=()=>{starts++};Math.random=()=>((draw++)+0.5)/14000;
+ for(let day=0;day<7000;day++)ddosTick();
+ out.push({level,games,expected:ddosRate(),observed:starts/1000});
+ }
+ } finally {ddosAttack=oldAttack;Math.random=oldRandom;}
+ JSON.stringify(out)
+ `));
+ for(const row of checks){
+ 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(checks[3].expected>checks[2].expected, 'level increases gaming frequency');
+ assert.ok(checks[4].expected>checks[3].expected, 'more gaming customers increase frequency');
+ assert.ok(checks[3].expected<0.8, 'one gaming customer does not suddenly add several attacks per week, even at the last level');
+ assert.deepEqual(errors, []);
+});
+
+test('normal attack sizes match the one- and fifty-gamer targets while frequency rises gradually', () => {
+ const { ev, errors } = load();
+ ev('ACT.start({})');
+ const samples = JSON.parse(ev(`
+ const oldRandom=Math.random,out=[];
+ try {
+ for(const [level,demand] of [[1,0],[3,1850],[LEVELS.length,LV_REQ.at(-1).pk]]){
+ const counts=[];
+ for(const games of [0,1,2,5,10,20,50,100,1000]){
+ S.lvl=level;S.biz=Array.from({length:games},(_,i)=>({id:'g'+i,type:i%2?'cgame':'game',city:'fra',bw:0,rate:0}));
+ const vectors=ddosVectors();let sum=0;
+ for(let i=0;i
draw++===1?(i+0.5)/vectors.length:roll;
+ ddosAttack(false);sum+=weight*S.ev.ddos.gbps;
+ }
+ counts.push({games,mean:sum/vectors.length,rate:ddosRate()});
+ }
+ out.push({level,demand,counts});
+ }
+ } finally {Math.random=oldRandom;}
+ JSON.stringify(out)
+ `));
+ for(const row of samples){
+ const [plain,first]=row.counts,fifty=row.counts.find(c=>c.games===50),hundred=row.counts.find(c=>c.games===100),many=row.counts.at(-1);
+ assert.ok(Math.abs(first.mean-plain.mean*3)<0.003, 'the first gamer triples the overall mean, allowing only bandwidth rounding: '+JSON.stringify(row));
+ assert.ok(Math.abs(fifty.mean-plain.mean*8)<0.01, 'fifty gamers bring eightfold sizes, allowing only bandwidth rounding');
+ assert.ok(hundred.mean>first.mean*3, 'growth continues across dozens of gaming customers');
+ assert.ok(hundred.mean>plain.mean*10 && hundred.mean6 && many.rate<=7);
+ for(let i=1;irow.counts[i-1].mean, 'each sampled count increases actual spawned attack sizes');
+ assert.ok(row.counts[i].rate>row.counts[i-1].rate, 'each sampled count increases frequency');
+ }
+ }
+ assert.ok(Math.abs(samples[0].counts[0].mean-1)<0.001, 'the minimum-demand baseline still permits small attacks');
+ assert.ok(Math.abs(samples[1].counts[0].mean-740/13)<0.001, 'the 1.85 Tbps non-gaming example keeps its average');
+ assert.ok(Math.abs(samples[2].counts[0].mean-samples[2].demand*4/3/10)<0.001);
+ assert.deepEqual(errors, []);
+});
+
+test('normal attack sizes cover a broad ordinary range and a two-percent large tail without raising the mean', () => {
+ const { ev, errors } = load();
+ ev('ACT.start({});S.lvl=3;S.biz=[];R.demand=1850');
+ const distribution = JSON.parse(ev(`
+ const oldRandom=Math.random,ordinary=[],large=[];let sum=0;
+ try {
+ for(let i=0;i<10000;i++){
+ Math.random=()=>(i+0.5)/10000;
+ const g=ddosSize('syn');sum+=g;(g>100?large:ordinary).push(g);
+ }
+ } finally {Math.random=oldRandom;}
+ JSON.stringify({ordinary:{n:ordinary.length,min:Math.min(...ordinary),max:Math.max(...ordinary)},
+ large:{n:large.length,min:Math.min(...large),max:Math.max(...large),near500:large.some(g=>g>=490&&g<=510)},mean:sum/10000})
+ `));
+ assert.equal(distribution.ordinary.n, 9800);
+ assert.equal(distribution.large.n, 200);
+ assert.ok(distribution.ordinary.min>=8.9 && distribution.ordinary.min<10);
+ assert.ok(distribution.ordinary.max>85 && distribution.ordinary.max<=89.1);
+ assert.ok(distribution.ordinary.max/distribution.ordinary.min>9.9);
+ assert.ok(distribution.large.min>=356 && distribution.large.max<=535);
+ assert.ok(distribution.large.near500, 'the example network can occasionally face a roughly 500 Gbps flood');
+ assert.ok(Math.abs(distribution.mean-740/13)<0.001, 'the rare tail preserves the previous 56.923 Gbps average');
+ // Verify that real spawns use both bands, not just the standalone sampler.
+ for (const [roll,minimum,maximum] of [[0.49,8.9,89.1],[0.99,356,535]]) {
+ ev(`S.ev.ddos=null;S.ev.ddosMore=[];S.ddosStarts=[];R.demand=1850;const old=Math.random;let n=0;Math.random=()=>{const i=n++;return i===1?(ddosVectors().indexOf('syn')+0.5)/ddosVectors().length:i===2?${roll}:0.5};try{ddosAttack()}finally{Math.random=old}`);
+ assert.equal(ev('S.ev.ddos.vec'), 'syn');
+ assert.ok(ev('S.ev.ddos.gbps')>=minimum && ev('S.ev.ddos.gbps')<=maximum);
+ }
+ assert.deepEqual(errors, []);
+});
+
+test('Flood Season retains its existing size quantiles and escalation when normal attacks gain rare spikes', () => {
+ const { ev, errors } = load();
+ ev("ACT.start({});S.scn={id:'flood',rules:{ddos:true}};S.lvl=3;S.biz=[];R.demand=1850");
+ for (const [day,expected] of [[0,[700,1400,2099]],[365,[1400,2800,4199]],[730,[2100,4200,6299]]]) {
+ ev(`S.day=${day}`);
+ const actual = JSON.parse(ev("const old=Math.random;let sizes;try{sizes=[0,0.5,0.999999].map(r=>{Math.random=()=>r;return ddosSize('syn')})}finally{Math.random=old}JSON.stringify(sizes)"));
+ assert.deepEqual(actual, expected);
+ }
+ assert.deepEqual(errors, []);
+});
+
+test('the busier DDoS schedule needs spicy chaos or gaming customers; otherwise attacks come as before', () => {
+ 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;})()");
+ assert.equal(ticks(), 0, 'no spicy chaos, no gamers: no extra schedule');
+ // DDoS stays one of the regular incidents instead: fireFailure can still roll one.
+ // DDoS stays one of the regular incidents instead: some roll of fireFailure() still starts one.
+ 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 true;}return false;}finally{Math.random=old;}})()"), 'fireFailure can start an attack');
+ ev("S.ev.ddos=null;S.ev.ddosMore=[];S.ddosStarts=[];S.inc=[]");
+ 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=[];window.rule=k=>k==='chaos'?'spicy':'calm'");
+ assert.ok(ticks() > 0, 'spicy chaos brings more attacks');
+ ev("window.rule=k=>k==='chaos'?'calm':undefined");
+ assert.equal(ticks(), 0, 'any other chaos setting keeps them as on main');
+ // Flood Season, not spicy: one flood at a time, 3 to 7 days apart, however old the scenario is.
+ ev("delete window.rule;ACT.startScn({id:'flood',sure:1});S.biz=[]");
+ const gaps = JSON.parse(ev("(()=>{const o=[];for(const d of [0,1000])for(const r of [0,0.999]){S.day=d;const old=Math.random;Math.random=()=>r;o.push(floodGap());Math.random=old;}return JSON.stringify(o);})()"));
+ assert.deepEqual(gaps, [3, 7, 3, 7]);
+ ev("S.scn.nextDdos=S.day;ddosTick()");
+ assert.equal(ev('ddosAll().length'), 1);
+ ev("S.scn.nextDdos=S.day;ddosTick()");
+ assert.equal(ev('ddosAll().length'), 1, 'the next flood waits for the last one to end');
+ assert.deepEqual(errors, []);
+});
diff --git a/tests/helpers/reference-allocation.js b/tests/helpers/reference-allocation.js
index a5c557c..52e6af4 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= 3, 'starts with bigger gear unlocked');
// a few weeks in: several attacks start on their own schedule
let n = 0;
- for (let i = 0; i < 40; i++) { ev('dayTick()'); if (ev('!!(S.ev.ddos&&S.ev.ddos.start===S.day)')) n++; }
+ for (let i = 0; i < 40; i++) { ev('dayTick()'); if (ev('ddosAll().some(a=>a.start===S.day)')) n++; }
assert.ok(n >= 4, `attacks keep coming (${n} in 40 days)`);
assert.ok(ev('(S.stats.ddosOk||0)+(S.stats.ddosLost||0)') >= 3, 'finished attacks are scored');
// scoring: held only if service stayed at 97%+
@@ -468,3 +468,29 @@ test('RouteScript: help, ready-made scripts and the AI button', () => {
ev("UI.dtab='overview';renderAll()");
assert.deepEqual(errors, []);
});
+
+
+test('Flood Season keeps attacking and escalating after both success and timeout', () => {
+ for (const outcome of ['done', 'failed']) {
+ const { ev, errors, dom } = load();
+ ev("ACT.startScn({id:'flood',sure:1});S.cash=1e9;S.nextFail=1e9;S.nextEvent=1e9");
+ if (outcome === 'done') ev('S.stats.ddosOk=20;S.stats.ddosOkBig=5;S.day=100');
+ else ev('S.day=365');
+ ev('scnTick(S.day)');
+ assert.ok(ev(`!!S.scn.${outcome}`));
+ assert.ok([...dom.window.document.querySelectorAll('#modal [data-act="closeModal"]')].some(b=>b.textContent==='Keep playing'));
+ ev('ACT.closeModal();S.scn.nextDdos=S.day+1;dayTick()');
+ assert.equal(ev('S.ev.ddos.start'), ev('S.day'), 'Keep playing still spawns attacks');
+ const before = ev('S.day');
+ ev('S.scn.nextDdos=S.day+1;S.day+=8;dayTick()');
+ assert.ok(ev('ddosAll().at(-1).start') > before, 'subsequent attacks keep coming');
+ // Escalating frequency belongs to spicy chaos (stood in for here); calmer games keep the old 3 to 7 days.
+ ev("window.rule=k=>k==='chaos'?'spicy':undefined");
+ const gaps = JSON.parse(ev('const old=Math.random;Math.random=()=>0.5;S.day=0;const early=floodGap();S.day=1000;const late=floodGap();Math.random=old;JSON.stringify([early,late])'));
+ assert.ok(gaps[1] < gaps[0], 'frequency keeps increasing with scenario age');
+ const sizes = JSON.parse(ev('const old=Math.random;Math.random=()=>0.9;S.day=0;ddosAttack();const early=ddosAll().at(-1).gbps;S.day=1000;ddosAttack();const late=ddosAll().at(-1).gbps;Math.random=old;JSON.stringify([early,late])'));
+ assert.ok(sizes[1] > sizes[0], 'intensity keeps increasing with scenario age');
+ assert.deepEqual(errors, []);
+ dom.window.close();
+ }
+});
diff --git a/tests/routing-reference.test.js b/tests/routing-reference.test.js
index 8742007..8a239ad 100644
--- a/tests/routing-reference.test.js
+++ b/tests/routing-reference.test.js
@@ -38,6 +38,7 @@ test('indexed routing matches the simple allocation loop across network changes'
"S.te.script='prefer transit Cogentle\\nprepend transit Cogentle 2\\nprotect customers'",
"S.ev.rpki={nets:['ggl','nfx'],until:S.day+3};S.ev.depeer=S.day+3",
"S.ev.ddos={city:'fra',until:S.day+3,gbps:300,vec:'syn',entry:{k:'edge'}}",
+ "S.ev.ddos.entries=[{k:'t',id:'transit0',city:'fra',share:.4},{k:'t',id:'transit4',city:'nyc',share:.6}]",
"S.links[0].eqDown=S.day+2;S.links[1].cut=S.day+2;S.links[2].loss={until:S.day+2,f:0.5}",
"S.links[4].chFail={until:S.day+2,o:'tp16'};S.links[6].ch.push('zr4');S.links[8].regen=2",
"S.day+=4;S.pni.splice(0,20);S.caches.splice(0,10);S.transit[0].pref='high'",
diff --git a/tests/services.test.js b/tests/services.test.js
index 5379cdc..9ba8bc5 100644
--- a/tests/services.test.js
+++ b/tests/services.test.js
@@ -9,6 +9,30 @@ function network(ev) {
ev("const L=(a,b,t,v)=>{UI.via=v||null;openLinkModal(a,b);ACT.buildLink({tier:t});};L('fra','ams',3);L('fra','par',3);L('ams','lon',2,'uly');closeModal()");
}
+test('gaming offers and signed customers show their DDoS risk in Deals, city panels and customer lists', () => {
+ const { ev, errors, dom } = load();
+ ev("ACT.start({});S.cash=1e9;ACT.buyTransit({city:'fra',net:'cog',tier:1});S.offers=['game','cgame','host'].map(type=>({id:type,city:'fra',name:type,bw:5,rate:100,reqs:[],exp:S.day+30,type}));UI.left='deals';UI.leftOpen=true;renderLeft()");
+ const notes = (root, action) => {
+ const buttons = [...root.querySelectorAll(`[data-act="${action}"]`)];
+ assert.equal(buttons.length, 3);
+ for (const button of buttons) {
+ const id = JSON.parse(button.dataset.args).id;
+ const count = (button.closest('.row').textContent.match(/Gaming attracts attacks/g)||[]).length;
+ assert.equal(count, id==='game'||id==='cgame'?1:0, `risk note for ${id}`);
+ }
+ };
+ assert.equal(ev('gamingCount()'), 0, 'offers disclose future risk before signing');
+ notes(dom.window.document.getElementById('leftBody'), 'accept');
+ ev("selectCity('fra');ACT.tab({t:'cust'})");
+ notes(dom.window.document.getElementById('panelBody'), 'accept');
+ ev("for(const id of ['game','cgame','host'])ACT.accept({id});UI.tab='cust';renderPanel()");
+ assert.equal(ev('gamingCount()'), 2, 'the note uses the same customer classification as the attack calculation');
+ notes(dom.window.document.getElementById('panelBody'), 'dropBiz');
+ ev('ACT.custOpen({})');
+ notes(dom.window.document.getElementById('custSec'), 'custGo');
+ assert.deepEqual(errors, []);
+});
+
test('event networks pay in full when the crowd is served, nothing up front', () => {
const { ev, errors } = load();
seed(ev, 4);