From d56039695c9174e808a72ec190453240c1341854 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Wed, 28 Oct 2026 20:53:58 +0100 Subject: [PATCH] Attacks arrive as on 1.36 again: drop the distributed multi-ingress flood model Frederic's call for 2.0: keep #153's fixes, NOC breakdown, new vectors, gaming risk and overlapping attacks, but not the per-port model. It split every flood over each ingress port with traffic (over a thousand on a big network), stored them all in the save, routed one pinned flow per port, and with it came the build-order and victim-scoring bugs found in review. Each attack is again one entry port at the victim (a.entry): upstream clean-pipe, Flowspec on the victim's router, IX blackholing, a sacrificial PNI and RouteScript filter it in that order (ddosMitigation), then scrubbing; what leaks is junk at the victim spread like its traffic, exactly as on main. Saves from 2.0 builds with a.entries load: sanitize drops the shares and a 'distributed' entry becomes 'edge'. Removed: R.ingressPorts, ddosEntries/ddosFold/ddosSlices/ddosCities/ddosHasIx, pinned flows (and the pinned-rank handling in routing and its reference), the mixed-TCAM line and the 'across N ports' message, and their tests; the scrubbing source-city test now uses two victims sharing one center. CHANGELOG #153 bullets describe what ships and credit #153. --- CHANGELOG.md | 20 +-- site/i18n/de.js | 3 - site/i18n/es.js | 3 - site/i18n/fr.js | 3 - site/i18n/it.js | 3 - site/i18n/pt.js | 3 - src/game/80-simulation/30-compute.js | 33 ++--- src/game/80-simulation/50-sanitize.js | 4 +- .../85-incidents/10-incidents-and-ddos.js | 45 ++---- src/game/85-incidents/20-failures.js | 4 +- src/game/90-actions/80-security-and-china.js | 2 +- src/i18n/en.js | 3 - tests/ddos-floods.test.js | 84 +++++------ tests/game.test.js | 134 +++++------------- tests/helpers/reference-allocation.js | 4 +- tests/routing-reference.test.js | 2 +- 16 files changed, 112 insertions(+), 238 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f13ceb4..ebd3011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,16 +18,16 @@ All notable changes to this project are documented here. The project follows - Check a selected link’s redundancy against current demand: see disconnected endpoints, additional service loss and full fallback links without changing the live network. - Links can now use a custom routing metric, set either as a multiplier or as an exact cost. Pick Custom under Routing metric to fine-tune where your traffic goes; it explains how a link's cost is worked out and what each preset comes to on that link. - Prices now follow how connected each city really is, based on PeeringDB and Hurricane Electric data. Transit costs up to 1.8× more in cities where few networks are present, a POP costs 1.25× to 1.5× where there is little or no carrier-neutral data center, and countries with thousands of networks, like Brazil and the US, bring more ISP customers. Big hubs such as Frankfurt, Amsterdam, New York and São Paulo keep their prices. -- Attacks are more varied: sizes, lengths and ingress ports change from one attack to the next, and several can hit at once. Hosting game servers or cloud gaming makes attacks more frequent, as it does in real life. -- The link traffic breakdown now shows the correct source city for scrubbing traffic. Cities using the same center no longer overwrite each other's labels. -- Live attacks now show one scrubbing detour from the attacked city to its nearest active scrubbing center, using the links' one-way latency. -- Game server and cloud gaming customers now carry a “Gaming attracts attacks” note on their offers and customer lists, so you can see the DDoS risk before signing them. -- Live attacks now show how much traffic Flowspec actually drops at the ingress routers. Routers without TCAM no longer claim to filter attacks, mixed router capabilities are called out, and Flowspec drops are counted separately from other edge filters. -- Hosting game servers or cloud gaming brings RackNet and TeamSpooked attacks. Both bypass Flowspec and require dedicated mitigation. -- Flood Season keeps sending ever larger attacks when you keep playing after winning or running out of time. Finishing the challenge no longer switches the floods off. -- Each live attack in the NOC now shows incoming bandwidth, upstream scrubbing, edge filtering, scrubbing-center use and any traffic still leaking through. -- DDoS bandwidth now adds up: upstream scrubbing, edge filters and scrubbing centers work in sequence. The NOC uses the same figures as traffic routing, including floods that cannot reach a remote center. -- Attacks can now use Memcached amplification or an ACK flood. Flowspec catches the former; the latter need mitigation. +- Attacks are more varied: sizes and lengths change from one attack to the next, and several can hit at once, each with its own controls in the NOC. Hosting game servers or cloud gaming makes attacks more frequent, as it does in real life (#153). +- The link traffic breakdown now shows the correct source city for scrubbing traffic. Cities using the same center no longer overwrite each other's labels (#153). +- Live attacks now show one scrubbing detour from the attacked city to its nearest active scrubbing center, using the links' one-way latency (#153). +- Game server and cloud gaming customers now carry a “Gaming attracts attacks” note on their offers and customer lists, so you can see the DDoS risk before signing them (#153). +- Live attacks now show how much traffic Flowspec actually drops. Routers without TCAM no longer claim to filter attacks, and Flowspec drops are counted separately from other edge filters (#153). +- Hosting game servers or cloud gaming brings RackNet and TeamSpooked attacks. Both bypass Flowspec and require dedicated mitigation (#153). +- Flood Season keeps sending ever larger attacks when you keep playing after winning or running out of time. Finishing the challenge no longer switches the floods off (#153). +- Each live attack in the NOC now shows incoming bandwidth, upstream scrubbing, edge filtering, scrubbing-center use and any traffic still leaking through (#153). +- DDoS bandwidth now adds up: upstream scrubbing, edge filters and scrubbing centers work in sequence. The NOC uses the same figures as traffic routing, including floods that cannot reach a remote center (#153). +- Attacks can now use Memcached amplification or an ACK flood. Flowspec catches the former; the latter need mitigation (#153). - Set the number of each optic model directly on land and subsea fiber links. Apply a whole change at once, with its total price shown before buying; removed optics return to the spares shelf. - Order PNIs with one network or every network at all shared POPs from the NOC Traffic tab: choose a port size, review the total cost, and add missing connections or upgrade smaller ones in one go. Each network keeps its own smallest PNI size and delivery time. - Utilities join route servers and request eligible peers across every joined IX, install missing PoP redundancy hardware and balance caches between sites, and request a cache from each eligible provider at each site. diff --git a/site/i18n/de.js b/site/i18n/de.js index c6b6e91..47eb899 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -910,7 +910,6 @@ "common.demand":"Nachfrage", "common.deploy":"Deployen", "common.deployed":"deployt", -"common.distributed_ingress":"Verteilter Eingang", "common.diverse":"redundant", "common.diverse_route":"redundante Route", "common.dns_reflection":"DNS-Reflection", @@ -1635,7 +1634,6 @@ "failures.a_trawler_off_ostend_dragged_its":"Ein Trawler vor Ostende hat sein Netz direkt durch dein Kabel {a}–{b} gezogen. Die Nordsee ist etwa dreißig Meter tief und voller Boote.", "failures.a_visiting_engineer_from_london":"Ein Gast-Ingenieur aus London hat Marmite ins NOC in {city} mitgebracht. Die diplomatischen Beziehungen sind zusammengebrochen, und dein Router auch, während alle stritten.", "failures.a_wind_farm_service_vessel_dropped":"Ein Windpark-Serviceschiff hat auf deinem Kabel {a}–{b} Anker geworfen. Es war da, um eine Turbine zu reparieren.", -"failures.across_n_transit_and_peering_ports":", über {n} Transit- und Peering-Ports", "failures.all_n_links_in_that_trench":"Alle {n} Links in diesem Graben sind mit ausgefallen.", "failures.an_automation_script_in_city_ran":"Ein Automatisierungsskript in {city} hat „sed“ auf die ganze Config losgelassen statt auf eine Zeile. Jedes Interface heißt jetzt „TODO“.", "failures.an_earthquake_shook_your_a_b":"Ein Erdbeben hat deine Glasfaser {a}–{b} irgendwo oberhalb von 4.000 Metern losgerüttelt.", @@ -2009,7 +2007,6 @@ "incidents_and_ddos.edge_filters_dropping_g":"Edge-Filter verwerfen: {g}", "incidents_and_ddos.flowspec_cannot_catch_vec":"Flowspec fängt {vec} nicht ab", "incidents_and_ddos.flowspec_dropping_g":"Flowspec verwirft: {g}", -"incidents_and_ddos.flowspec_dropping_g_some_ingress":"Flowspec verwirft: {g}; manche Eingangs-Router haben kein TCAM", "incidents_and_ddos.g_is_leaking_through":"{g} kommen trotzdem durch", "incidents_and_ddos.hackback_3000tm_20k":"HackBack 3000™ $20k", "incidents_and_ddos.it_was_dns":"Es war DNS", diff --git a/site/i18n/es.js b/site/i18n/es.js index 4ab93d8..c5e8b29 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -908,7 +908,6 @@ "common.demand":"Demanda", "common.deploy":"Desplegar", "common.deployed":"desplegado", -"common.distributed_ingress":"Entrada distribuida", "common.diverse":"diversa", "common.diverse_route":"ruta diversa", "common.dns_reflection":"Reflexión DNS", @@ -1633,7 +1632,6 @@ "failures.a_trawler_off_ostend_dragged_its":"Un arrastrero frente a Ostende arrastró sus aparejos directo por tu cable {a}–{b}. El Mar del Norte tiene unos treinta metros de profundidad y está lleno de barcos.", "failures.a_visiting_engineer_from_london":"Un ingeniero visitante de Londres llevó Marmite al NOC de {city}. Se rompieron las relaciones diplomáticas, y tu router también mientras todos discutían.", "failures.a_wind_farm_service_vessel_dropped":"Un barco de servicio de un parque eólico echó el ancla sobre tu cable {a}–{b}. Estaba allí para arreglar una turbina.", -"failures.across_n_transit_and_peering_ports":", por {n} puertos de tránsito y peering", "failures.all_n_links_in_that_trench":"Los {n} enlaces de esa zanja cayeron con ella.", "failures.an_automation_script_in_city_ran":"Un script de automatización en {city} ejecutó «sed» sobre toda la configuración en lugar de una línea. Ahora todas las interfaces se llaman «TODO».", "failures.an_earthquake_shook_your_a_b":"Un terremoto soltó tu fibra {a}–{b} en algún punto por encima de los 4000 metros.", @@ -2007,7 +2005,6 @@ "incidents_and_ddos.edge_filters_dropping_g":"Filtros en el borde descartan: {g}", "incidents_and_ddos.flowspec_cannot_catch_vec":"Flowspec no puede atrapar {vec}", "incidents_and_ddos.flowspec_dropping_g":"Flowspec descarta: {g}", -"incidents_and_ddos.flowspec_dropping_g_some_ingress":"Flowspec descarta: {g}; algunos routers de entrada no tienen TCAM", "incidents_and_ddos.g_is_leaking_through":"{g} se cuelan igualmente", "incidents_and_ddos.hackback_3000tm_20k":"HackBack 3000™ $20k", "incidents_and_ddos.it_was_dns":"Era el DNS", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 26a6ad8..30a346d 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -908,7 +908,6 @@ "common.demand":"Demande", "common.deploy":"Déployer", "common.deployed":"déployé", -"common.distributed_ingress":"Arrivée distribuée", "common.diverse":"diversifié", "common.diverse_route":"chemin diversifié", "common.dns_reflection":"réflexion DNS", @@ -1633,7 +1632,6 @@ "failures.a_trawler_off_ostend_dragged_its":"Un chalutier au large d’Ostende a traîné son chalut en plein sur ton câble {a}–{b}. La mer du Nord fait une trentaine de mètres de fond et grouille de bateaux.", "failures.a_visiting_engineer_from_london":"Un ingénieur de passage venu de Londres a apporté de la Marmite au NOC de {city}. Les relations diplomatiques ont rompu, et ton routeur aussi, pendant que tout le monde se disputait.", "failures.a_wind_farm_service_vessel_dropped":"Un navire de maintenance d’un parc éolien a jeté l’ancre sur ton câble {a}–{b}. Il était là pour réparer une éolienne.", -"failures.across_n_transit_and_peering_ports":", via {n} ports de transit et de peering", "failures.all_n_links_in_that_trench":"Les {n} liens de cette tranchée sont tombés avec elle.", "failures.an_automation_script_in_city_ran":"Un script d’automatisation à {city} a lancé « sed » sur toute la config au lieu d’une ligne. Toutes les interfaces s’appellent maintenant « TODO ».", "failures.an_earthquake_shook_your_a_b":"Un séisme a déboîté ta fibre {a}–{b} quelque part au-dessus de 4 000 mètres.", @@ -2007,7 +2005,6 @@ "incidents_and_ddos.edge_filters_dropping_g":"Filtres en bordure : {g} supprimés", "incidents_and_ddos.flowspec_cannot_catch_vec":"Flowspec ne peut pas arrêter {vec}", "incidents_and_ddos.flowspec_dropping_g":"Flowspec supprime {g}", -"incidents_and_ddos.flowspec_dropping_g_some_ingress":"Flowspec supprime {g} ; certains routeurs d’entrée n’ont pas de TCAM", "incidents_and_ddos.g_is_leaking_through":"{g} passent encore", "incidents_and_ddos.hackback_3000tm_20k":"HackBack 3000™ $20k", "incidents_and_ddos.it_was_dns":"C’était le DNS", diff --git a/site/i18n/it.js b/site/i18n/it.js index b2547d1..a4b5b11 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -908,7 +908,6 @@ "common.demand":"Domanda", "common.deploy":"Deploy", "common.deployed":"in produzione", -"common.distributed_ingress":"Ingresso distribuito", "common.diverse":"diversificato", "common.diverse_route":"percorso diverso", "common.dns_reflection":"riflessione DNS", @@ -1633,7 +1632,6 @@ "failures.a_trawler_off_ostend_dragged_its":"Un peschereccio al largo di Ostenda ha trascinato le reti dritte sul tuo cavo {a}–{b}. Il Mare del Nord è profondo una trentina di metri e pieno di barche.", "failures.a_visiting_engineer_from_london":"Un ingegnere in visita da Londra ha portato la Marmite nel NOC di {city}. Le relazioni diplomatiche sono saltate, e mentre tutti litigavano è saltato anche il tuo router.", "failures.a_wind_farm_service_vessel_dropped":"Una nave di servizio di un parco eolico ha gettato l'ancora sul tuo cavo {a}–{b}. Era lì per riparare una turbina.", -"failures.across_n_transit_and_peering_ports":", su {n} porte di transit e peering", "failures.all_n_links_in_that_trench":"Tutti i {n} link in quello scavo sono caduti insieme.", "failures.an_automation_script_in_city_ran":"Uno script di automazione a {city} ha lanciato “sed” su tutta la config invece che su una riga. Ora ogni interfaccia si chiama “TODO”.", "failures.an_earthquake_shook_your_a_b":"Un terremoto ha scollegato la tua fibra {a}–{b} da qualche parte sopra i 4.000 metri.", @@ -2007,7 +2005,6 @@ "incidents_and_ddos.edge_filters_dropping_g":"Filtri al bordo: {g} scartati", "incidents_and_ddos.flowspec_cannot_catch_vec":"Flowspec non può fermare {vec}", "incidents_and_ddos.flowspec_dropping_g":"Flowspec scarta {g}", -"incidents_and_ddos.flowspec_dropping_g_some_ingress":"Flowspec scarta {g}; alcuni router di ingresso non hanno TCAM", "incidents_and_ddos.g_is_leaking_through":"{g} superano le difese", "incidents_and_ddos.hackback_3000tm_20k":"HackBack 3000™ $20k", "incidents_and_ddos.it_was_dns":"Era il DNS", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index a05f651..4ac6bb9 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -908,7 +908,6 @@ "common.demand":"Demanda", "common.deploy":"Deploy", "common.deployed":"em produção", -"common.distributed_ingress":"Entrada distribuída", "common.diverse":"diverso", "common.diverse_route":"rota diversa", "common.dns_reflection":"reflexão DNS", @@ -1633,7 +1632,6 @@ "failures.a_trawler_off_ostend_dragged_its":"Um barco de arrasto ao largo de Ostende arrastou as redes bem em cima do seu cabo {a}–{b}. O Mar do Norte tem uns trinta metros de profundidade e é cheio de barcos.", "failures.a_visiting_engineer_from_london":"Um engenheiro de Londres em visita levou Marmite para o NOC de {city}. As relações diplomáticas caíram, e seu roteador também, enquanto todo mundo discutia.", "failures.a_wind_farm_service_vessel_dropped":"Um navio de serviço de um parque eólico jogou âncora no seu cabo {a}–{b}. Ele estava lá para consertar uma turbina.", -"failures.across_n_transit_and_peering_ports":", por {n} portas de transit e peering", "failures.all_n_links_in_that_trench":"Todos os {n} links daquela vala caíram junto.", "failures.an_automation_script_in_city_ran":"Um script de automação em {city} rodou “sed” na config inteira em vez de uma linha. Toda interface agora se chama “TODO”.", "failures.an_earthquake_shook_your_a_b":"Um terremoto soltou sua fibra {a}–{b} em algum ponto acima de 4.000 metros.", @@ -2007,7 +2005,6 @@ "incidents_and_ddos.edge_filters_dropping_g":"Filtros de borda descartando: {g}", "incidents_and_ddos.flowspec_cannot_catch_vec":"Flowspec não consegue filtrar {vec}", "incidents_and_ddos.flowspec_dropping_g":"Flowspec descarta {g}", -"incidents_and_ddos.flowspec_dropping_g_some_ingress":"Flowspec descarta {g}; alguns roteadores de entrada não têm TCAM", "incidents_and_ddos.g_is_leaking_through":"{g} estão passando", "incidents_and_ddos.hackback_3000tm_20k":"HackBack 3000™ $20k", "incidents_and_ddos.it_was_dns":"Foi o DNS", diff --git a/src/game/80-simulation/30-compute.js b/src/game/80-simulation/30-compute.js index 09cd6ce..4a0f2eb 100644 --- a/src/game/80-simulation/30-compute.js +++ b/src/game/80-simulation/30-compute.js @@ -39,7 +39,7 @@ function compute(){ // ok() cannot change during one compute, so ask each exit once per network, not once per flow and rank. // okBy[net] lists the exits that reach it in E's order, like E.filter(e=>e.ok(net)). const okBy={};for(const id of NET_IDS)okBy[id]=[]; - R2.ingressPorts={};const ekN={};for(const e of E){e.ek=e.k+':'+e.id;if(e.k!=='c'){const p=R2.ingressPorts[e.ek]||(R2.ingressPorts[e.ek]={k:e.k,id:e.id,city:e.city,lab:e.lab,cap:0,traffic:0});p.cap+=e.cap;}ekN[e.ek]=(ekN[e.ek]||0)+1;} + const ekN={};for(const e of E){e.ek=e.k+':'+e.id;ekN[e.ek]=(ekN[e.ek]||0)+1;} // dup: shares its key with another exit (a hand-edited save), so R.egDesc shows whichever pushed last. for(const e of E){e.desc={lab:e.lab,city:e.city,k:e.k};e.dup=ekN[e.ek]>1;e.told=false;e.hp=e.pref==='high'?0:1;e.ci=CIDX[e.city];e.cn=cnCity(e.city);e.vis=0;for(const n of e.nets||NET_IDS){const L=okBy[n];if(L&&L[L.length-1]!==e&&e.ok(n))L.push(e);}} for(const n of NETS){R2.reachable[n.id]=okBy[n.id].some(e=>e.rank>0);if(R2.reachable[n.id])R2.reach+=NSH[n.id];if(okBy[n.id].some(e=>e.rank>0&&e.k!=='t')){R2.nt[n.id]=1;R2.reachNT+=NSH[n.id]; @@ -52,18 +52,8 @@ function compute(){ // Customer demand per city, added up in S.biz order (what filtering S.biz for each city would give). const bizBw={};for(const b of S.biz){const T=BIZ_T[b.type];if(!T.l2&&!T.fiber&&(!T.event||eventLive(b))){const v=bizBw[b.city];bizBw[b.city]=(v===undefined?0:v)+b.bw;}} // Traffic shares by network index, and their sums, for each share table (and with Russia's throttle). - const shArr=new Map(),shSum=new Map(),DEMTO=new Float64Array(NN),loc=scnRule('local'),scrubRoom={},atkBy={},junkGroups=[],bhCities=new Set(ddosAll().filter(a=>a.bh).map(a=>a.city));R2.haul=[];R2.ddos=[]; - /* Floods first, before any real traffic and in the order the attacks started, so no POP's place in S.pops decides who - gets a full port. Each slice is the flood entering in one city (mitigated and scrubbed there); what leaks is junk at - the victim, pinned to the port it came in on, so it loads that port, the backbone between them and the victim's router. */ - // A port the victim cannot be reached from (down, or no backbone to it) still fills with the junk arriving there. - const VIC={};for(const a of ddosAll()){const v=a.city;(VIC[v]||(VIC[v]=[])).push(a); - for(const part of ddosSlices(a)){const c=part.city;(atkBy[c]||(atkBy[c]=[])).push(part); - const m=ddosMitigation(part,{},bhCities.has(v),false),group={m,flows:[]};R2.ddos.push(m);junkGroups.push(group);if(!popUp(c))m.offline=true; - const src=popUp(v)&&SPD[v][CIDX[c]]0?q.g/m.leak:0;if(q.entry.k==='rest'){for(let j=0;ja.bh).map(a=>a.city));R2.haul=[];R2.ddos=[]; + const VIC={};for(const a of ddosAll())(VIC[a.city]||(VIC[a.city]=[])).push(a); for(const c of Object.keys(S.pops)){ const p=S.pops[c],ci=CIDX[c],cn=cnCity(c),SH=cn?NSH_CN:ruCity(c)?NSH_RU:CITY[c].kr&&S.krExit?NSH_KRX:NSH;const eye=(p.bb?p.bb.d:0)*viral*(cn&&ev.golden>day?1.4:1);const biz=bizBw[c]??0;const d0=eye+biz; // Goggle video is throttled in Russia (#70): people there get half of it, so they ask for half. It is not @@ -76,6 +66,10 @@ function compute(){ // `edge` is the crude RouteScript `blackhole ddos` filter (junk gone, 10% of real traffic with it). Flowspec // (a standing licence) and a scrubbing center each knock the flood down before it reaches the sim. const attacks=VIC[c]||[],rtbh=bhCities.has(c),edge=!!(attacks.length&&TRX&&TRX.blackhole&&!rtbh); + // The junk heads for the victim over its usual exits, spread like its traffic. How much is left after the edge + // tools and scrubbing is only known once hauls to remote centers are routed, so the flows are sized after that. + for(const atk of attacks){const m=ddosMitigation(atk,{},rtbh,false),group={m,flows:[]};R2.ddos.push(m);junkGroups.push(group);if(!popUp(c)){m.offline=true;continue;} + for(let j=0;jn+a.gbps,0)+d*0.1;if(rtbh)R2.teBlack+=attacks.reduce((n,a)=>n+a.gbps,0)+d; @@ -145,14 +139,14 @@ function compute(){ for(const m of R2.ddos){const atk=m.attack,A=atk.city,Ai=CIDX[A]; m.sp=!m.offline&&m.leak>0?scrubPlan(atk,m.leak,scrubRoom,(x,want)=>{const B=x.city,Bi=CIDX[B];if(A===B)return want;let h=0,ms=null; if(popUp(A)&&popUp(B)&&SPD[A]&&SPD[A][Bi]0?want*take/total:0;ms=path.reduce((n,e)=>n+e.lat,0)*2; + const v=R2.cityDem[A]*0.1*want/Math.max(m.leak,1)/VIC[A].length,total=want+v,take=Math.max(0,Math.min(total,room));h=total>0?want*take/total:0;ms=path.reduce((n,e)=>n+e.lat,0)*2; // Sources sharing a center need separate labels in link breakdowns and map highlights. const ek='scrub:'+A+'>'+B;R2.egDesc[ek]={lab:labOf(N_('compute.attack_hauled_to_scrubbing_in_city'),'city',CITY[B].name),city:A,k:'l2'}; for(const i of ni)if(HAS[i])nodeTake(i,take);for(const l of path){l.res-=take;l.ld+=take;carry(l,ek,NN,Ai,take);}} R2.haul.push({city:A,to:B,tier:x.tier||0,a:want,h,ms,attack:atk.id});return h;}):null; if(m.sp){m.leak=m.sp.leak; - // The card describes the victim's nearest center, separately from distributed ingress hauling above. - const c=(atk.parent||atk).city;let near=scrubNear.get(c);if(near===undefined){near=null; + // The card describes the victim's nearest center. + const c=atk.city;let near=scrubNear.get(c);if(near===undefined){near=null; for(const x of S.scrubs)if(popUp(x.city)&&SPD[c]&&SPD[c][CIDX[x.city]]n+e.lat,0);if(!near||mse.res<=1e-3||(HAS[v]&&NRES[v]<=1e-3),dst); if(D[dst]===Infinity||D[dst]>2*base+60){teCache.set(key,false);return null;} const Q=walkI(P,src,dst);teCache.set(key,Q);return Q;}; - const ingressE={};for(const e of E)(ingressE[e.ek]||(ingressE[e.ek]=[])).push(e); /* A network in a peer's customer cone, reached through that peer (#85): after every network you peer with directly (its AS path is one hop longer) and before transit. */ const base=(e,n)=>e.pref==='low'?4:e.rank>0&&e.rank<3&&coneOf(e,n)?CONE_RANK:e.rank; @@ -180,9 +173,6 @@ function compute(){ const byRank={},RSET=new Set();for(const id of NET_IDS){const m=byRank[id]={};for(const e of okBy[id]){const r=TR?eff(e,id):base(e,id);RSET.add(r);(m[r]||(m[r]=[])).push(e);} for(const r in m){const L=m[r],key=L.map(e=>e.xi).join(','),o=LIST.get(key);if(o){m[r]=o;continue;} let V=L;if(NCOMP>1){const cs=[];for(const e of L){const k=COMP[e.ci];if(k>=0)(cs[k]||(cs[k]=[])).push(e);}for(const s of cs)if(s)idx(s);V={cs};}else idx(L);LIST.set(key,V);m[r]=V;}} - // Attack flows pinned to their entry port route at the port's own rank: no network to be in a cone of, and RouteScript - // may have left that rank with no list. - const pr=e=>e.pref==='low'?4:e.rank;for(const f of flows)if(f.pin)for(const e of ingressE[f.pin]||[])RSET.add(pr(e)); // The flow being routed, and from its POP: distances, arriving edges and the paths walked so far, by city index. let f=null,Dv=null,Pv=null,PP=null,vis=0;const walked=[],G=[],REST=[],NEG=[]; // An exit the flow can still try: not visited yet, not full when the flow started, and reachable from the POP. @@ -198,7 +188,7 @@ function compute(){ const ek=e.ek,nr=f.nr,ci=f.ci;if(!e.told||e.dup){R2.egDesc[ek]=e.desc;e.told=true;} for(const l of path){l.res-=amt;l.ld+=amt;carry(l,ek,nr,ci,amt);} e.used+=amt;f.rem-=amt; - if(!f.junk){if(e.k!=='c')R2.ingressPorts[ek].traffic+=amt;let ok=amt;const cf=f.cn,ce=e.cn,cn=f.ncn; + if(!f.junk){let ok=amt;const cf=f.cn,ce=e.cn,cn=f.ncn; if(cf!==ce||(cf&&!cn)||(!cf&&cn&&e.k==='t')){const prem=(e.k==='t'&&e.prem)||(e.k==='p'&&e.pnc)||path.some(x=>x.links&&x.links.some(y=>y.premium));const loss=prem?0.03:(ev.gfw>day?0.35:0.2);R2.gfwLost+=amt*loss;R2.gfwCross+=amt;ok=amt*(1-loss);} SRV[f.ci]+=ok;R2.served+=ok;if(f.bz)R2.bizSrv[f.c]+=ok;if(e.rank<=2)R2.peered+=ok;if(e.k==='t'){const m=R2.tNet[e.id]||(R2.tNet[e.id]={});m[f.n]=(m[f.n]||0)+ok; // Backhaul to transit: users notice the round trip to the exit. Up to 20 ms (about 1,500 km) is free, then @@ -231,7 +221,6 @@ function compute(){ for(let fi=0,FN=flows.length;fi{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