Add bulk PNI ordering across networks and POPs

Add two actions to the NOC Traffic tab:
- Order PNIs with one network at every shared POP.
- Order PNIs with all eligible networks at every shared POP, including
  long-tail peers.

Both actions offer a selectable port size and preview new connections,
upgrades, total setup costs, additional monthly charges and blocked sites.
Upgrade smaller PNIs while preserving larger connections, pending orders
and existing LAG members. Reserve router capacity across the batch and
account for pending speed and LAG augments to avoid overbooking ports.

Require the full setup budget before placing any orders. Reuse normal
peering policies, minimum port sizes and provisioning delays, then
recompute and save once for the entire batch. Keep large global previews
compact with collapsible network and blocked-connection lists.

Translate the new UI into all five supported languages and add tests for
single-network and global ordering, capacity, budgets, repeated clicks,
save migration, and mobile keyboard interaction.

Validation:
- Build and translation checks pass.
- 308 of 309 tests pass. The existing subsea reach test also fails on
  origin/main because the Windows locale uses a dot as the thousands
  separator where the assertion expects a comma.
- Chromium desktop and phone checks pass with the supplied save.
- Big-network benchmark against origin/main: dashboard tabs take
  16.8 -> 17.6 ms on desktop and 77.1 -> 80.7 ms on a simulated phone
  (median of 15 runs). Routing results are identical, with no slowdowns
  beyond the benchmark's noise threshold.
This commit is contained in:
logfro 2026-10-28 01:44:17 +01:00
parent ad94833ad1
commit 4932b3f93a
12 changed files with 442 additions and 7 deletions

View file

@ -0,0 +1,23 @@
/* Single and bulk orders share the same checks, prices and provisioning. */
function pniQuote(city,net,tier,reserved=0){tier=+tier;const g1=tier===-1;if(g1)tier=0;
if(!S||!S.pops[city]||!isNet(net)||!NET[net].pops.includes(city)||!Number.isInteger(tier)||!PORT[tier]||(g1&&!pniG1(net)))return null;
const ex=S.pni.find(p=>p.city===city&&p.net===net);
if(ex&&(g1||!pniOn(ex)||ex.up||(!(ex.g1&&tier===0)&&tier<=ex.tier)))return null;
const cost=g1?PNI_G1_COST:(1500+PORT[tier].setup/2)*(ex&&ex.n||1),slots=ex?(PORT_SLOT(tier)-PORT_SLOT(ex.tier))*(ex.n||1):PORT_SLOT(tier);
let why='';if(!portOk(city,tier))why=tr('actions.your_router_can_t_take_a',{port:PORT[tier].n});
else{const r=peerOk(net,'pni',city);if(!r.ok)why=tr('sites_peering_caches.net_declined_the_pni_why',{net:esc(NET[net].name),why:esc(r.why)});
else if(!g1&&tier<pniMin(net))why=tr('sites_peering_caches.net_does_not_do_port_pnis',{net:esc(NET[net].name),port:PORT[tier].n});
else if(slots>0&&portsUsed(city)+reserved+slots>portsMax(city)+1e-9)why=tr('ports.no_free_router_ports_in_city',{city:esc(CITY[city].name),u:fmtPorts(portsUsed(city)+reserved),m:portsMax(city)});}
return {city,net,tier,g1,ex,cost,slots,why};}
function pniPlace(q){const {city,net,tier,g1,ex}=q,lead=pniLead(net);
if(S.conf&&S.conf.until>S.day)S.stats.beerPni=1;
if(ex)ex.up={tier,n:ex.n||1,ready:S.day+lead,g1:false};else S.pni.push({id:uid(),city,net,tier,g1:g1||undefined,ready:S.day+lead});
return lead;}
function pniBatch(net,tier){tier=+tier;const all=net===null;if(!S||(!all&&!isNet(net))||!Number.isInteger(tier)||(tier===-1?all||!pniG1(net):!PORT[tier]||!portShown(tier)))return null;
const shared=[],orders=[],blocked=[],reserved={};let kept=0,cost=0,mo=0;
// Pending augments and earlier orders in this batch already own their future ports.
for(const p of S.pni)if(p.up)reserved[p.city]=(reserved[p.city]||0)+Math.max(0,PORT_SLOT(p.up.tier)*(p.up.n||1)-PORT_SLOT(p.tier)*(p.n||1));
for(const n of all?NETS:[NET[net]])for(const city of n.pops){if(!S.pops[city])continue;shared.push(city);
const q=pniQuote(city,n.id,tier,reserved[city]||0);if(!q){kept++;continue;}if(q.why){blocked.push(q);continue;}orders.push(q);cost+=q.cost;reserved[city]=(reserved[city]||0)+q.slots;
mo+=pniMo({net:n.id,tier:q.tier,g1:q.g1,n:q.ex&&q.ex.n},0)-(q.ex?pniMo(q.ex,0):0);}
return {shared,orders,blocked,kept,cost,mo};}