Move a customer to another path between the same two POPs

Alien waves and leased fiber pairs sit on one fiber (b.link), so they move to
another working fiber between the same cities, under the rules for selling
capacity on it. Circuits have no link of their own, so moving one pins it to a
list of cities (b.pin), which routing follows while every link on it is up. When
one is down the circuit follows routing, and it comes back by itself.

The window lists the most diverse options first, compared by trench. Moves are
free and instant, and contracts keep their price.
This commit is contained in:
Christopher Hawker 2026-11-06 20:52:48 +11:00
parent ef6bd750ea
commit 93d7c87dc7
18 changed files with 431 additions and 9 deletions

View file

@ -14,6 +14,7 @@ All notable changes to this project are documented here. The project follows
- Big networks no longer freeze for a moment at every new game day, above all with a NOC intern on duty. The intern now plans cache boxes, router ports and PNIs for every POP in one pass. On a network of 190 POPs the intern's shift held the page for about a tenth of a second on a computer and half a second on a phone; it now takes a few thousandths, and a whole day holds the page a quarter as long. The game plays exactly as before.
- A low-latency boutique with a lot of its own fiber no longer stalls every day while it times its finance routes. On a big fiber network that check held the page for about a third of a second and now takes a few hundredths; checking customers who want a path without subsea or under a latency limit got quicker too. The game plays exactly as before.
- The NOC intern no longer holds a big network for more than half a second each time it weighs taking out a spare wave. Before it decides, it checks every customer promised diverse paths, no subsea or a latency limit, and on a network of 390 POPs that check now takes a few hundredths of a second. Spotting new sovereign cloud and trading offers is about ten times quicker too, and the game plays exactly as before.
- You can now move a customer to another path between the same two POPs, with the most diverse options listed first. Alien waves and leased fiber pairs move to another fiber, and circuits can be pinned to a path of your choice, falling back to normal routing while a link on it is down.
## [3.2.0] — 2026-11-07

View file

@ -31,7 +31,7 @@ hoisted across files, and top-level statements run in path order. Find code by n
| `30-networks/` | Other ASes (`NETS`), rival exchanges (`XIX`), the long tail, traffic shares (`NSH`) |
| `40-progress/` | Customer types (`BIZ_T`), `LEVELS` and their requirements, `GOALS`; the per-save ruleset (`S.rules`, `rule()`, `PRESETS`, `chaosMul()`, `leadDays()`) |
| `50-state.js` | The globals `S`, `R`, `UI`; `emptyR()` |
| `60-features/` | Banks and loans, scenarios and the weekly challenge, puzzles and the published weekly puzzle, conferences, the tutorial, traceroute, the share card, `newGame()`, the offer trial (`autoOffer()`), standing orders (`S.ops`, `opsDay()`, run from `dayTick()`), the sales desk (`S.sales`, `salesDay()`, `salesShape()` on new offers, orbit ones through `pieSlShape()`; signing for you: `S.slAuto`, `slAutoDay()`; renewal haggles: `S.slAuto.ren`, `slRenDay()`) |
| `60-features/` | Moving a customer to another path (`37-customer-paths.js`), banks and loans, scenarios and the weekly challenge, puzzles and the published weekly puzzle, conferences, the tutorial, traceroute, the share card, `newGame()`, the offer trial (`autoOffer()`), standing orders (`S.ops`, `opsDay()`, run from `dayTick()`), the sales desk (`S.sales`, `salesDay()`, `salesShape()` on new offers, orbit ones through `pieSlShape()`; signing for you: `S.slAuto`, `slAutoDay()`; renewal haggles: `S.slAuto.ren`, `slRenDay()`) |
| `70-rules/` | Formatting helpers and market rules: exchanges, PNIs, the peering desk (requests answered by policy), peering policy and snubs, DE-KICKS, sold-out routes, hot ports and the Tier 1/2/3 rank |
| `80-simulation/` | Dijkstra, RouteScript, where a DDoS flood goes (`ddosLoad()`/`ddosAfter()`, called by `compute()`), `compute()`, monthly prices, `sanitize()`/`migrate()`, customer requirements, events, the customer lifecycle (contracts, renewals, the bandwidth market, why customers leave), geography pricing and latency, second sites and service |
| `85-incidents/` | `addInc()`, DDoS attacks (targets, sizes, scoring, the NOC card) and scrubbing, `failureRun()`/`fireFailure()`, `clearInc()`, `fireEvent()`, the chaos monkey, cable ships (`50-cable-ships.js`: a subsea cut sends a club ship from its port along the cable routes; voyages in `S.fleet`, drawn by `96-map/88-cable-ships.js`) |

View file

@ -55,8 +55,8 @@ const TABS = ['cust', 'up', 'peer', 'links'];
const LEFT = ['nets', 'noc', 'deals', 'goals'];
const PRESETS = ['freeze', 'oncall', 'bgp'];
// How often a button is pressed against the others on screen: what changes the network often, looking around rarely.
const BUILD = /^(buy\w*|pni\w*All|pni|peer|peerAll|unpeer|cache|cacheSite|rmCache|buildLink|buildPop|launchBB|accept|decline|dropBiz|takeLoan|repayLoan|lag[TPI]x?|setPref|setCarry|setStandby|setMetric|togglePrem|cleanPipe|sacrif|rs|foundIx|myIxUp|addRouter|rmRouter|upRouter|addSite|rmSite|siteSet|decomToggle|rmLink|upLink|addParallel|cancel\w*|upVxc|buyNni|rmNni|buildScrub|scrubUp|rmScrub|addGen|regen|addCh|rmCh|addPair|upSys|spares|layShip|crews|fixInc|seaPackage|subUpgrade|orderCable|orderDf|ownCab|opsHire|opsToggle|opsParam|opsCap|opsPop|opsTpl|opsNewPop|popStdSet|coreSet|teRecipe|dkOptOut|dkStay|utility\w*|listFiber|unlistFiber|leaseSwap|custGo|confGo|confSponsor|seatBuy|charter|cnPrem|applyCn|ad|ddosAuto|pz(Pop|RmPop|Link|AddPar|Tier|RmLink|RtAdd|RtRm|RtModel|Route|Via|Div)|setRoute|route|via|metricSet)$/;
const UIACT = /^(tab|dashTab|leftTab|\w*Sort|\w*Filter|pniGrp|trace\w*|focusCity|findGo|selLink|dashLink|logAll|tailTog|listMore|netFocus|netFilter|meetGo|phoneTab|dashClose|connF|connCity|connNet|connFor|custF|custCity|popGo|popsReg|opsOpen|decomOpen|linkCheck)$/;
const BUILD = /^(buy\w*|pni\w*All|pni|peer|peerAll|unpeer|cache|cacheSite|rmCache|buildLink|buildPop|launchBB|accept|decline|dropBiz|pathMove|pathPin|pathAuto|takeLoan|repayLoan|lag[TPI]x?|setPref|setCarry|setStandby|setMetric|togglePrem|cleanPipe|sacrif|rs|foundIx|myIxUp|addRouter|rmRouter|upRouter|addSite|rmSite|siteSet|decomToggle|rmLink|upLink|addParallel|cancel\w*|upVxc|buyNni|rmNni|buildScrub|scrubUp|rmScrub|addGen|regen|addCh|rmCh|addPair|upSys|spares|layShip|crews|fixInc|seaPackage|subUpgrade|orderCable|orderDf|ownCab|opsHire|opsToggle|opsParam|opsCap|opsPop|opsTpl|opsNewPop|popStdSet|coreSet|teRecipe|dkOptOut|dkStay|utility\w*|listFiber|unlistFiber|leaseSwap|custGo|confGo|confSponsor|seatBuy|charter|cnPrem|applyCn|ad|ddosAuto|pz(Pop|RmPop|Link|AddPar|Tier|RmLink|RtAdd|RtRm|RtModel|Route|Via|Div)|setRoute|route|via|metricSet)$/;
const UIACT = /^(tab|dashTab|leftTab|\w*Sort|\w*Filter|pniGrp|trace\w*|focusCity|findGo|selLink|dashLink|logAll|tailTog|listMore|netFocus|netFilter|meetGo|phoneTab|dashClose|connF|connCity|connNet|connFor|custF|custCity|popGo|popsReg|opsOpen|decomOpen|linkCheck|pathOpen)$/;
const DW = { launchBB: 4, accept: 4, buyTransit: 3, pni: 3, buyIx: 3, setPref: 4, cache: 2, peerAll: 2, setCarry: 2, takeLoan: 2 };
const weight = (b) => (BUILD.test(b.act) ? 8 : UIACT.test(b.act) ? 0.3 : 1);

View file

@ -1759,6 +1759,30 @@
"core.vendor_zoo":"Hersteller-Zoo",
"core.your_auto_te_predates_backbones":"Dein Auto-TE wurde installiert, bevor Backbones eine Technik hatten, also läuft es wie immer. Wechselst du das Backbone, gelten die neuen Regeln.",
"core.your_backbone_now_runs_lv":"Dein Backbone läuft jetzt mit {lv}.",
"customer_paths.fiber_label":"{name} · {km} km",
"customer_paths.fits_only_g_of_bw":"Passen nur {g} von {bw}",
"customer_paths.fully_diverse":"Komplett divers",
"customer_paths.its_spare_pairs_are_taken":"Die freien Paare sind schon vermietet",
"customer_paths.let_routing_choose_again":"Wieder das Routing entscheiden lassen",
"customer_paths.move":"Umziehen",
"customer_paths.move_name":"{name} umziehen",
"customer_paths.move_to_another_path":"Auf einen anderen Pfad umziehen",
"customer_paths.name_follows_routing_again":"<b>{name}</b> folgt wieder dem Routing.",
"customer_paths.name_moved_to_fiber":"<b>{name}</b> ist auf {fiber} umgezogen.",
"customer_paths.name_now_rides_path":"<b>{name}</b> läuft jetzt über {path}.",
"customer_paths.no_other_path":"Zwischen {a} und {b} gibt es gerade keinen anderen funktionierenden Pfad.",
"customer_paths.no_other_working_fiber":"Zwischen {a} und {b} gibt es keine andere funktionierende Glasfaser. Bau eine, dann kannst du diesen Kunden darauf umziehen.",
"customer_paths.not_enough_free_channels":"Zu wenig freie Kanäle: {free} frei, {n} nötig",
"customer_paths.now_on":"Aktuell auf",
"customer_paths.only_your_own_fiber_rents_pairs":"Nur deine eigene Glasfaser kann Paare vermieten",
"customer_paths.over_the_ms_budget":"Über dem Budget von {ms} ms",
"customer_paths.path_facts":"{km} km · {ms} ms",
"customer_paths.pinned_to_path":"Festgelegt auf {path}",
"customer_paths.routing_chooses_this_circuit":"Das Routing wählt den Pfad dieses Circuits zwischen {a} und {b} jeden Tag neu. Ein Umzug legt ihn kostenlos auf den gewählten Pfad fest. Fällt ein Link auf diesem Pfad aus, folgt er dem Routing, bis der Link wieder da ist.",
"customer_paths.same_trench":"Gleicher Graben",
"customer_paths.shares_n_spans":{"one":"Teilt {n} Abschnitt","other":"Teilt {n} Abschnitte"},
"customer_paths.that_path_is_down":"Dieser Pfad ist down, vorerst folgt er dem Routing",
"customer_paths.this_customer_rides_one_fiber":"Dieser Kunde läuft über eine Glasfaser zwischen {a} und {b}. Der Umzug auf eine andere ist kostenlos und passiert sofort.",
"customers.attacks_on_city_are_hauled_to":"Angriffe auf {city} werden zum Scrubbing nach {to} geschleppt: +{ms} ms",
"customers.everyone_who_pays_you_happiest_last":"Alle, die dich bezahlen, die Zufriedensten zuletzt. Unter 60 % fangen sie an zu meckern, unter 30 % sind sie wütend, und bei 0 % kündigen sie.",
"customers.from_unhappy_customers":"von unzufriedenen Kunden",

View file

@ -1757,6 +1757,30 @@
"core.vendor_zoo":"Zoológico de fabricantes",
"core.your_auto_te_predates_backbones":"Tu Auto-TE se instaló antes de que los backbones tuvieran una tecnología, así que funciona como siempre. Cambiar el backbone pasa a las reglas nuevas.",
"core.your_backbone_now_runs_lv":"Tu backbone ahora corre {lv}.",
"customer_paths.fiber_label":"{name} · {km} km",
"customer_paths.fits_only_g_of_bw":"Solo caben {g} de {bw}",
"customer_paths.fully_diverse":"Totalmente diversa",
"customer_paths.its_spare_pairs_are_taken":"Sus pares libres ya están alquilados",
"customer_paths.let_routing_choose_again":"Que el enrutamiento vuelva a elegir",
"customer_paths.move":"Mover",
"customer_paths.move_name":"Mover a {name}",
"customer_paths.move_to_another_path":"Mover a otra ruta",
"customer_paths.name_follows_routing_again":"<b>{name}</b> vuelve a seguir el enrutamiento.",
"customer_paths.name_moved_to_fiber":"<b>{name}</b> se ha movido a {fiber}.",
"customer_paths.name_now_rides_path":"<b>{name}</b> ahora va por {path}.",
"customer_paths.no_other_path":"Ahora mismo no hay otra ruta operativa entre {a} y {b}.",
"customer_paths.no_other_working_fiber":"No hay otra fibra operativa entre {a} y {b}. Construye una y podrás mover a este cliente a ella.",
"customer_paths.not_enough_free_channels":"No hay canales libres suficientes: {free} libres, necesita {n}",
"customer_paths.now_on":"Ahora en",
"customer_paths.only_your_own_fiber_rents_pairs":"Solo tu propia fibra puede alquilar pares",
"customer_paths.over_the_ms_budget":"Supera el presupuesto de {ms} ms",
"customer_paths.path_facts":"{km} km · {ms} ms",
"customer_paths.pinned_to_path":"Fijado a {path}",
"customer_paths.routing_chooses_this_circuit":"El enrutamiento elige cada día la ruta de este circuito entre {a} y {b}. Moverlo lo fija a la ruta que elijas, gratis. Mientras un enlace de esa ruta esté caído, seguirá el enrutamiento hasta que vuelva.",
"customer_paths.same_trench":"Misma zanja",
"customer_paths.shares_n_spans":{"one":"Comparte {n} tramo","other":"Comparte {n} tramos"},
"customer_paths.that_path_is_down":"Esa ruta está caída, así que de momento sigue el enrutamiento",
"customer_paths.this_customer_rides_one_fiber":"Este cliente va por una fibra entre {a} y {b}. Moverlo a otra es gratis e inmediato.",
"customers.attacks_on_city_are_hauled_to":"los ataques a {city} se desvían a {to} para depurarlos: +{ms} ms",
"customers.everyone_who_pays_you_happiest_last":"Todos los que te pagan, los más felices al final. Por debajo del 60 % empiezan a quejarse, por debajo del 30 % están furiosos y al 0 % cancelan.",
"customers.from_unhappy_customers":"de clientes descontentos",

View file

@ -1757,6 +1757,30 @@
"core.vendor_zoo":"Zoo de constructeurs",
"core.your_auto_te_predates_backbones":"Ton Auto-TE a été installé avant que les backbones aient une technologie, il tourne donc comme toujours. Changer de backbone passe aux nouvelles règles.",
"core.your_backbone_now_runs_lv":"Ton backbone tourne maintenant en {lv}.",
"customer_paths.fiber_label":"{name} · {km} km",
"customer_paths.fits_only_g_of_bw":"Seuls {g} sur {bw} passent",
"customer_paths.fully_diverse":"Totalement diversifié",
"customer_paths.its_spare_pairs_are_taken":"Ses paires libres sont déjà louées",
"customer_paths.let_routing_choose_again":"Laisser le routage choisir à nouveau",
"customer_paths.move":"Déplacer",
"customer_paths.move_name":"Déplacer {name}",
"customer_paths.move_to_another_path":"Déplacer vers un autre chemin",
"customer_paths.name_follows_routing_again":"<b>{name}</b> suit de nouveau le routage.",
"customer_paths.name_moved_to_fiber":"<b>{name}</b> a été déplacé vers {fiber}.",
"customer_paths.name_now_rides_path":"<b>{name}</b> passe maintenant par {path}.",
"customer_paths.no_other_path":"Il n'y a pas d'autre chemin en service entre {a} et {b} pour le moment.",
"customer_paths.no_other_working_fiber":"Il n'y a pas d'autre fibre en service entre {a} et {b}. Construis-en une et tu pourras y déplacer ce client.",
"customer_paths.not_enough_free_channels":"Pas assez de canaux libres : {free} libres, il en faut {n}",
"customer_paths.now_on":"Actuellement sur",
"customer_paths.only_your_own_fiber_rents_pairs":"Seule ta propre fibre peut louer des paires",
"customer_paths.over_the_ms_budget":"Au-delà du budget de {ms} ms",
"customer_paths.path_facts":"{km} km · {ms} ms",
"customer_paths.pinned_to_path":"Épinglé sur {path}",
"customer_paths.routing_chooses_this_circuit":"Le routage choisit chaque jour le chemin de ce circuit entre {a} et {b}. Le déplacer l'épingle gratuitement sur le chemin de ton choix. Tant qu'un lien de ce chemin est coupé, il suit le routage jusqu'au retour du lien.",
"customer_paths.same_trench":"Même tranchée",
"customer_paths.shares_n_spans":{"one":"Partage {n} tronçon","other":"Partage {n} tronçons"},
"customer_paths.that_path_is_down":"Ce chemin est coupé, il suit donc le routage pour l'instant",
"customer_paths.this_customer_rides_one_fiber":"Ce client passe par une fibre entre {a} et {b}. Le déplacer vers une autre est gratuit et immédiat.",
"customers.attacks_on_city_are_hauled_to":"les attaques sur {city} sont acheminées vers {to} pour le scrubbing : +{ms} ms",
"customers.everyone_who_pays_you_happiest_last":"Tous ceux qui te paient, les plus contents en dernier. Sous 60 % ils commencent à râler, sous 30 % ils sont furieux, et à 0 % ils résilient.",
"customers.from_unhappy_customers":"venant des clients mécontents",

View file

@ -1757,6 +1757,30 @@
"core.vendor_zoo":"Zoo dei vendor",
"core.your_auto_te_predates_backbones":"Il tuo Auto-TE è stato installato prima che i backbone avessero una tecnologia, quindi funziona come ha sempre fatto. Cambiare il backbone passa alle nuove regole.",
"core.your_backbone_now_runs_lv":"Il tuo backbone ora gira su {lv}.",
"customer_paths.fiber_label":"{name} · {km} km",
"customer_paths.fits_only_g_of_bw":"Ci stanno solo {g} su {bw}",
"customer_paths.fully_diverse":"Totalmente diverso",
"customer_paths.its_spare_pairs_are_taken":"Le sue coppie libere sono già affittate",
"customer_paths.let_routing_choose_again":"Lascia di nuovo scegliere al routing",
"customer_paths.move":"Sposta",
"customer_paths.move_name":"Sposta {name}",
"customer_paths.move_to_another_path":"Sposta su un altro percorso",
"customer_paths.name_follows_routing_again":"<b>{name}</b> segue di nuovo il routing.",
"customer_paths.name_moved_to_fiber":"<b>{name}</b> spostato su {fiber}.",
"customer_paths.name_now_rides_path":"<b>{name}</b> ora passa per {path}.",
"customer_paths.no_other_path":"Al momento non c'è un altro percorso funzionante tra {a} e {b}.",
"customer_paths.no_other_working_fiber":"Non c'è un'altra fibra funzionante tra {a} e {b}. Costruiscine una e potrai spostarci questo cliente.",
"customer_paths.not_enough_free_channels":"Canali liberi insufficienti: {free} liberi, ne servono {n}",
"customer_paths.now_on":"Ora su",
"customer_paths.only_your_own_fiber_rents_pairs":"Solo la tua fibra può affittare coppie",
"customer_paths.over_the_ms_budget":"Oltre il budget di {ms} ms",
"customer_paths.path_facts":"{km} km · {ms} ms",
"customer_paths.pinned_to_path":"Fissato su {path}",
"customer_paths.routing_chooses_this_circuit":"Il routing sceglie ogni giorno il percorso di questo circuito tra {a} e {b}. Spostarlo lo fissa gratis sul percorso che scegli. Finché un link di quel percorso è giù, segue il routing fino al suo ritorno.",
"customer_paths.same_trench":"Stessa trincea",
"customer_paths.shares_n_spans":{"one":"Condivide {n} tratta","other":"Condivide {n} tratte"},
"customer_paths.that_path_is_down":"Quel percorso è giù, quindi per ora segue il routing",
"customer_paths.this_customer_rides_one_fiber":"Questo cliente passa su una fibra tra {a} e {b}. Spostarlo su un'altra è gratis e immediato.",
"customers.attacks_on_city_are_hauled_to":"gli attacchi su {city} vengono portati a {to} per lo scrubbing: +{ms} ms",
"customers.everyone_who_pays_you_happiest_last":"Tutti quelli che ti pagano, i più contenti in fondo. Sotto il 60% iniziano a brontolare, sotto il 30% sono furiosi, e a 0% disdicono.",
"customers.from_unhappy_customers":"dai clienti scontenti",

View file

@ -1757,6 +1757,30 @@
"core.vendor_zoo":"Zoológico de fornecedores",
"core.your_auto_te_predates_backbones":"Seu Auto-TE foi instalado antes de os backbones terem uma tecnologia, então ele funciona como sempre. Mudar o backbone passa para as regras novas.",
"core.your_backbone_now_runs_lv":"Seu backbone agora roda {lv}.",
"customer_paths.fiber_label":"{name} · {km} km",
"customer_paths.fits_only_g_of_bw":"Só cabem {g} de {bw}",
"customer_paths.fully_diverse":"Totalmente diverso",
"customer_paths.its_spare_pairs_are_taken":"Os pares livres já estão alugados",
"customer_paths.let_routing_choose_again":"Deixar o roteamento escolher de novo",
"customer_paths.move":"Mover",
"customer_paths.move_name":"Mover {name}",
"customer_paths.move_to_another_path":"Mover para outro caminho",
"customer_paths.name_follows_routing_again":"<b>{name}</b> volta a seguir o roteamento.",
"customer_paths.name_moved_to_fiber":"<b>{name}</b> movido para {fiber}.",
"customer_paths.name_now_rides_path":"<b>{name}</b> agora passa por {path}.",
"customer_paths.no_other_path":"Agora não há outro caminho funcionando entre {a} e {b}.",
"customer_paths.no_other_working_fiber":"Não há outra fibra funcionando entre {a} e {b}. Construa uma e você poderá mover este cliente para ela.",
"customer_paths.not_enough_free_channels":"Canais livres insuficientes: {free} livres, precisa de {n}",
"customer_paths.now_on":"Agora em",
"customer_paths.only_your_own_fiber_rents_pairs":"Só a sua própria fibra pode alugar pares",
"customer_paths.over_the_ms_budget":"Acima do orçamento de {ms} ms",
"customer_paths.path_facts":"{km} km · {ms} ms",
"customer_paths.pinned_to_path":"Fixado em {path}",
"customer_paths.routing_chooses_this_circuit":"O roteamento escolhe todo dia o caminho deste circuito entre {a} e {b}. Movê-lo o fixa no caminho que você escolher, de graça. Enquanto um link desse caminho estiver fora, ele segue o roteamento até o link voltar.",
"customer_paths.same_trench":"Mesma vala",
"customer_paths.shares_n_spans":{"one":"Compartilha {n} trecho","other":"Compartilha {n} trechos"},
"customer_paths.that_path_is_down":"Esse caminho está fora, então por enquanto segue o roteamento",
"customer_paths.this_customer_rides_one_fiber":"Este cliente passa por uma fibra entre {a} e {b}. Movê-lo para outra é grátis e imediato.",
"customers.attacks_on_city_are_hauled_to":"os ataques em {city} são levados a {to} para scrubbing: +{ms} ms",
"customers.everyone_who_pays_you_happiest_last":"Todo mundo que te paga, os mais felizes por último. Abaixo de 60% começam a reclamar, abaixo de 30% ficam furiosos, e em 0% cancelam.",
"customers.from_unhappy_customers":"de clientes insatisfeitos",

View file

@ -262,7 +262,13 @@ const API_CMD={
dropBiz:{args:[['id','entityId']],confirm:'double',
doc:'Terminate a signed customer. Rejected once an event contract\'s event has started.'},
setRoute:{args:[['id','entityId'],['m','routeMode']],watch:['biz.#id'],
doc:'How a customer\'s traffic is routed: normal follows metrics, fast takes the lowest latency, scenic the quietest links.'},
doc:'How a customer\'s traffic is routed: normal follows metrics, fast takes the lowest latency, scenic the quietest links. Clears a pinned path.'},
pathMove:{args:[['id','entityId'],['link','entityId']],watch:['biz.#id'],
doc:'Move a fiber customer (alien wave, dark fiber pair, fiber pairs) to another working fiber between the same two cities. Free. Rejected if that fiber has no room for it.'},
pathPin:{args:[['id','entityId'],['via','string']],watch:['biz.#id'],
doc:'Pin a circuit to a path: via is its city ids in order, comma-separated, from the customer\'s city to its city2, every hop a working link. Free. While a link on it is down the circuit follows routing.'},
pathAuto:{args:[['id','entityId']],watch:['biz.#id'],
doc:'Unpin a circuit, so routing chooses its path again.'},
/* ---------- traffic engineering ---------- */
buyTE:{args:[],quote:a=>({setup:TE_COST,monthly:TE_MO,blocked:coreTE()||(S&&S.te)?[]:[tr('core.auto_te_needs_an_rsvp_te_or')]}),
doc:'Buy the Auto-TE controller, which spills overflow onto alternate paths. Level 3+, and it needs an RSVP-TE-or-higher backbone.'},
@ -491,6 +497,7 @@ const API_VIEW={
focusCity:{args:[['city','cityId']],doc:'Select and centre a city.'},
selLink:{args:[['id','entityId']],doc:'Select a link.'},
custGo:{args:[['id','entityId']],doc:'Jump from the dashboard to a customer.'},
pathOpen:{args:[['id','entityId']],doc:'Open the window listing the other paths a customer can move to: fibers for a fiber customer, routes for a circuit. pathMove and pathPin make the move.'},
listMore:{args:[['k','listPage']],doc:'Show another page of the dashboard list.'},
custF:{args:[['v','string']],doc:'Filter the customers list.'},
custCity:{args:[['v','string']],doc:'Filter the customers list by city.'},

View file

@ -0,0 +1,66 @@
/* ---------- moving a customer to another path between the same two POPs ---------- */
/* Fiber customers (an alien wave, leased pairs) sit on one fiber, b.link, so they move to a parallel one. Circuits have
no link of their own: routing picks their path every day. Moving one pins it to a list of cities, b.pin. While a link
on the pin is down it follows routing, as a protected wave would, and it comes back by itself. */
const PATH_ALT=3,PATH_FAR=1000;
const pathKind=b=>{const T=BIZ_T[b.type];if(pzOn()||!T||capPend(b)||!b.city2)return '';return T.fiber?(b.link?'fiber':''):T.l2&&!b.sites?'circuit':'';};
const trenchOf=l=>l.kind==='vxc'?'fab:'+l.prov:(l.trench||l.id);
const pathCity=c=>CITY[c].name,pathStr=p=>p.map(pathCity).join(' → ');
const samePair=(l,a,b)=>(l.a===a&&l.b===b)||(l.a===b&&l.b===a);
const fibLab=l=>tr('customer_paths.fiber_label',{name:l.cname?esc(l.cname):capName(l),km:Math.round(l.km).toLocaleString()});
// Why this fiber cannot take this customer, in the same terms as the offers for it.
function fiberNo(b,l){if(b.type==='wwave'){const n=b.slots||1,free=freeCh(l);return free>=n?'':tr('customer_paths.not_enough_free_channels',{free:Math.max(0,free),n});}
if(!l.own)return tr('customer_paths.only_your_own_fiber_rents_pairs');
if(b.type==='dfpair')return pairFree(l)?'':tr('customer_paths.its_spare_pairs_are_taken');
return S.biz.some(x=>x!==b&&x.link===l.id&&['pairs','capfib','dfpair'].includes(x.type))?tr('customer_paths.its_spare_pairs_are_taken'):'';}
// The working fibers it could go to, those on another trench first.
function fiberTargets(b){const cur=S.links.find(l=>l.id===b.link),t=cur?trenchOf(cur):'';
return S.links.filter(l=>l.kind==='df'&&l.id!==b.link&&samePair(l,b.city,b.city2)&&l.ready<=S.day&&!(l.cut>S.day)&&!(l.eqDown>S.day))
.map(l=>({l,diverse:trenchOf(l)!==t,no:fiberNo(b,l)})).sort((x,y)=>(y.diverse-x.diverse)||(!!x.no-!!y.no)||x.l.km-y.l.km);}
// The live backbone by city pair, as compute() sees it: every link of a pair is one edge.
function pathEdges(){const E={},N={};for(const l of S.links){if(linkDown(l)||!popUp(l.a)||!popUp(l.b))continue;const k=edgeKey(l);let e=E[k];
if(!e){e=E[k]={k,a:l.a,b:l.b,w:Infinity,km:Infinity,lat:Infinity,cap:0,load:0,ts:new Set()};(N[l.a]=N[l.a]||[]).push(e);(N[l.b]=N[l.b]||[]).push(e);}
e.w=Math.min(e.w,pairW(k,l.km));e.km=Math.min(e.km,l.km);e.lat=Math.min(e.lat,linkLat(l));e.cap+=capOf(l);e.load+=(R.load&&R.load[l.id])||0;e.ts.add(trenchOf(l));}
return {E,N};}
const hopKey=(a,b)=>a<b?a+'|'+b:b+'|'+a;
// The cheapest path from a to b, as a list of cities.
function pathWalk(G,a,b,cost){const dist={[a]:0},prev={},done=new Set();for(;;){let u=null,ud=Infinity;for(const k in dist)if(!done.has(k)&&dist[k]<ud){u=k;ud=dist[k];}if(u===null||u===b)break;done.add(u);
for(const e of G.N[u]||[]){const v=e.a===u?e.b:e.a,nd=ud+cost(e);if(nd<(dist[v]??Infinity)){dist[v]=nd;prev[v]=u;}}}
if(dist[b]===undefined)return null;const p=[b];while(p[0]!==a)p.unshift(prev[p[0]]);return p;}
const pathHops=(G,p)=>{const o=[];for(let i=1;i<p.length;i++){const e=G.E[hopKey(p[i-1],p[i])];if(!e)return null;o.push(e);}return o;};
const pinUp=b=>!!pathHops(pathEdges(),b.pin);
// Where the circuit runs today. Scenic circuits remember it; the others take the shortest path of their kind.
function pathNow(b,G){if(b.pin&&pathHops(G,b.pin))return b.pin;
const r=R.l2route&&R.l2route[b.id+'>'+b.city+'>'+b.city2];if(r&&r[0]){const p=r[0].ns.slice();if(p[0]!==b.city)p.reverse();if(pathHops(G,p))return p;}
return pathWalk(G,b.city,b.city2,b.route==='fast'?e=>e.lat+0.05:e=>e.w);}
// Paths that avoid what is in use: each one is priced as if every trench already used were nearly unusable, so the next
// one is the most diverse there is, sharing a trench only if there is no way round it.
function circuitTargets(b){const G=pathEdges(),now=pathNow(b,G);if(!now)return {now:null,alts:[]};
const hops=pathHops(G,now)||[],used=new Set(),seen=new Set([now.join()]),own=new Set(hops.map(e=>e.k)),got=R.l2&&R.l2[b.id]||0,alts=[];
const nowT=new Set();for(const e of hops)for(const t of e.ts){nowT.add(t);used.add(t);}
for(let i=0;i<PATH_ALT+1&&alts.length<PATH_ALT;i++){const p=pathWalk(G,b.city,b.city2,e=>{for(const t of e.ts)if(used.has(t))return (e.w+1)*PATH_FAR;return e.w+1;});if(!p)break;
const h=pathHops(G,p);for(const e of h)for(const t of e.ts)used.add(t);if(seen.has(p.join()))continue;seen.add(p.join());
alts.push({p,shared:h.filter(e=>[...e.ts].some(t=>nowT.has(t))).length,km:h.reduce((a,e)=>a+e.km,0),lat:h.reduce((a,e)=>a+e.lat+0.05,0),
room:Math.max(0,Math.min(...h.map(e=>e.cap-e.load+(own.has(e.k)?got:0))))});}
alts.sort((x,y)=>x.shared-y.shared||x.lat-y.lat);return {now,alts};}
// The pin as compute() walks it. Null while a link on it is down, and routing takes over.
function pinRoute(p,edges){const path=[];for(let i=1;i<p.length;i++){const e=edges[hopKey(p[i-1],p[i])];if(!e)return null;path.push(e);}return {path,ni:p.map(x=>CIDX[x]),share:1};}
// Under a customer in the panels.
function pathCtl(b){if(!pathKind(b))return '';
const pin=b.pin?`<div class="meta">${tr('customer_paths.pinned_to_path',{path:esc(pathStr(b.pin))})}${pinUp(b)?'':` · <b style="color:var(--bad)">${tr('customer_paths.that_path_is_down')}</b>`}</div>`:'';
return `${pin}<div class="btns">${btn(tr('customer_paths.move_to_another_path'),'pathOpen',{id:b.id},'ghost sm')}</div>`;}
function pathModal(b){const a=pathCity(b.city),z=pathCity(b.city2),k=pathKind(b);let h=`<div style="display:flex;align-items:center"><h2 style="font-size:24px">${tr('customer_paths.move_name',{name:esc(b.name)})}</h2><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div>`;
const row=(nm,meta,tag,button)=>`<div class="row"><div class="grow"><div class="nm">${nm}${tag?` <span class="tag st">${tag}</span>`:''}</div>${meta?`<div class="meta">${meta}</div>`:''}</div>${button}</div>`;
if(k==='fiber'){const cur=S.links.find(l=>l.id===b.link),T=fiberTargets(b);
h+=`<p class="lead" style="margin-top:6px">${tr('customer_paths.this_customer_rides_one_fiber',{a,b:z})}</p>`;
if(cur)h+=`<div class="kv"><span>${tr('customer_paths.now_on')}</span><b>${fibLab(cur)}</b></div>`;
if(!T.length)h+=`<p class="empty">${tr('customer_paths.no_other_working_fiber',{a,b:z})}</p>`;
for(const t of T)h+=row(fibLab(t.l),t.no,t.diverse?tr('customer_paths.fully_diverse'):tr('customer_paths.same_trench'),btn(tr('customer_paths.move'),'pathMove',{id:b.id,link:t.l.id},'sm',!!t.no));}
else{const {now,alts}=circuitTargets(b);
h+=`<p class="lead" style="margin-top:6px">${tr('customer_paths.routing_chooses_this_circuit',{a,b:z})}</p>`;
if(now)h+=`<div class="kv"><span>${tr('customer_paths.now_on')}</span><b>${esc(pathStr(now))}</b></div>`;
if(b.pin)h+=`<div class="btns">${btn(tr('customer_paths.let_routing_choose_again'),'pathAuto',{id:b.id},'ghost sm')}</div>`;
if(!alts.length)h+=`<p class="empty">${tr('customer_paths.no_other_path',{a,b:z})}</p>`;
for(const t of alts){const warn=[t.room<b.bw?`<b style="color:var(--bad)">${tr('customer_paths.fits_only_g_of_bw',{g:fmtG(t.room),bw:fmtG(b.bw)})}</b>`:'',b.latMax&&t.lat>b.latMax?`<b style="color:var(--bad)">${tr('customer_paths.over_the_ms_budget',{ms:b.latMax})}</b>`:''].filter(Boolean).join(' · ');
h+=row(esc(pathStr(t.p)),tr('customer_paths.path_facts',{km:Math.round(t.km).toLocaleString(),ms:t.lat.toFixed(1)})+(warn?' · '+warn:''),t.shared?trn('customer_paths.shares_n_spans',t.shared):tr('customer_paths.fully_diverse'),btn(tr('customer_paths.move'),'pathPin',{id:b.id,via:t.p.join()},'sm'));}}
openModal(h);}

View file

@ -146,7 +146,7 @@ function compute(){RW.gen++;
if(!seen[b])return null;const path=[];let v=b;while(v!==a){const l=prev[v];path.push(l);v=CIDX[l.a]===v?CIDX[l.b]:CIDX[l.a];}return path;};
const disjointI=(A,B)=>{const a=CIDX[A],b=CIDX[B],p1=bfsI(a,b,null);return !!p1&&!!bfsI(a,b,new Set(p1.map(srlg)));};
for(const k in edges){const e=edges[k];let ld=0;for(const l of e.links)ld+=(R.load&&R.load[l.id])||0;e.pl=ld;}
const l2Routes=(A,B,b)=>{const m=b.route||'normal',Ai=CIDX[A],Bi=CIDX[B];
const l2Routes=(A,B,b)=>{if(b.pin){const r=pinRoute(b.pin,edges);if(r)return [r];}const m=b.route||'normal',Ai=CIDX[A],Bi=CIDX[B];
if(PX&&m==='fast')return pieFast(PX,fastSP,A,B,b,wLat);
if(m!=='scenic')return [{...walkI(m==='fast'?(fastSP[A]||(fastSP[A]=dijkstra(adj,Ai,wLat))).P:SPP[A],Ai,Bi),share:1}];
const ek='l2:'+b.id,own=e=>(R.efg&&R.efg[e.id]&&R.efg[e.id].get(ek))||0;

View file

@ -54,7 +54,7 @@ function sanitize(s){
for(const k of Object.keys(s.peers)){const [n,c]=k.split('@');if(!isNet(n)||!isIx(c))delete s.peers[k];}
for(const c of Object.keys(s.myIx)){const m=s.myIx[c];if(!isCity(c)||!m||typeof m!=='object'){delete s.myIx[c];continue;}m.members=Array.isArray(m.members)?m.members.filter(isNet):[];m.name=String(m.name||tr('common.your_ix')).slice(0,40);m.next=num(m.next,s.day);m.fab=int(m.fab,0,MYIX_FAB.length-1,0);}
const okBiz=b=>b&&own(BIZ_T,b.type)&&(!BIZ_T[b.type].nni||own(FAB,b.prov))&&isCity(b.city)&&(!b.city2||isCity(b.city2))&&(!b.sites||Array.isArray(b.sites)&&b.sites.every(isCity));
const fixBiz=b=>{b.id=sid(b.id);b.name=String(b.name||tr('common.customer')).slice(0,80);b.bw=num(b.bw,1);b.rate=num(b.rate,0);if(b.fee!==undefined)b.fee=num(b.fee,0);if(b.start!==undefined)b.start=num(b.start,0);if(b.dur!==undefined)b.dur=num(b.dur,1);if(b.slots!==undefined)b.slots=num(b.slots,0);if(b.what!==undefined)b.what=String(b.what).slice(0,200);if(b.broker!==undefined)b.broker=!!b.broker;if(!Array.isArray(b.reqs))b.reqs=[];b.reqs=b.reqs.filter(r=>own(REQS,r));if(b.mood!==undefined)b.mood=num(b.mood,100);if(b.pm!==undefined)b.pm=num(b.pm,b.mood||100);if(b.exp!==undefined)b.exp=num(b.exp,0);if(b.latMax!=null)b.latMax=num(b.latMax,10);if(b.route&&!own(RT,b.route))b.route='normal';if(b.due!==undefined)b.due=num(b.due,0);if(b.win!==undefined)b.win=num(b.win,180);if(b.live!==undefined)b.live=!!b.live;if(b.link!==undefined&&typeof b.link!=='string')delete b.link;return b;};
const fixBiz=b=>{b.id=sid(b.id);b.name=String(b.name||tr('common.customer')).slice(0,80);b.bw=num(b.bw,1);b.rate=num(b.rate,0);if(b.fee!==undefined)b.fee=num(b.fee,0);if(b.start!==undefined)b.start=num(b.start,0);if(b.dur!==undefined)b.dur=num(b.dur,1);if(b.slots!==undefined)b.slots=num(b.slots,0);if(b.what!==undefined)b.what=String(b.what).slice(0,200);if(b.broker!==undefined)b.broker=!!b.broker;if(!Array.isArray(b.reqs))b.reqs=[];b.reqs=b.reqs.filter(r=>own(REQS,r));if(b.mood!==undefined)b.mood=num(b.mood,100);if(b.pm!==undefined)b.pm=num(b.pm,b.mood||100);if(b.exp!==undefined)b.exp=num(b.exp,0);if(b.latMax!=null)b.latMax=num(b.latMax,10);if(b.route&&!own(RT,b.route))b.route='normal';if(b.due!==undefined)b.due=num(b.due,0);if(b.win!==undefined)b.win=num(b.win,180);if(b.live!==undefined)b.live=!!b.live;if(b.link!==undefined&&typeof b.link!=='string')delete b.link;if(b.pin!==undefined){const p=b.pin;if(!Array.isArray(p)||p.length<2||p.length>64||!p.every(isCity)||new Set(p).size!==p.length||!BIZ_T[b.type].l2||b.sites||p[0]!==b.city||p[p.length-1]!==b.city2)delete b.pin;}return b;};
{const ids=new Map(s.links.map(l=>[l.id,l]));s.biz=s.biz.filter(okBiz).map(b=>clFix(s,unpackBiz(fixBiz(b),ids)));}s.offers=s.offers.filter(okBiz).map(fixBiz);
// Contracts (#178): the bandwidth market an offer was priced in, who referred it, and the month-by-month tally.
for(const o of s.offers){if(!(typeof o.mk==='number'&&o.mk>0&&o.mk<=5))delete o.mk;if(typeof o.ref!=='string')delete o.ref;if(o.refN!==undefined)o.refN=String(o.refN).slice(0,80);}clFixState(s);salesFix(s);

View file

@ -0,0 +1,13 @@
Object.assign(ACT,{
pathOpen:({id})=>{const b=S.biz.find(x=>x.id===id);if(b&&pathKind(b))pathModal(b);},
pathMove:({id,link})=>{const b=S.biz.find(x=>x.id===id),l=b&&pathKind(b)==='fiber'&&fiberTargets(b).find(t=>t.l.id===link&&!t.no);if(!l)return;
// A carrier already renting waves on that fiber: one contract, as when it orders more there.
const more=b.type==='wwave'&&S.biz.find(x=>x!==b&&x.type==='wwave'&&x.link===link&&x.name===b.name);
if(more){more.slots=(more.slots||0)+(b.slots||0);more.rate+=b.rate;more.since=Math.min(more.since??0,b.since??0);more.mood=Math.min(more.mood??100,b.mood??100);more.what=wwWhat(l.l,more.slots);S.biz=S.biz.filter(x=>x!==b);}
else{b.link=link;if(b.type==='wwave')b.what=wwWhat(l.l,b.slots||1);}
closeModal();toast(tr('customer_paths.name_moved_to_fiber',{name:esc(b.name),fiber:fibLab(l.l)}),'good');sfx('build');after();},
pathPin:({id,via})=>{const b=S.biz.find(x=>x.id===id);if(!b||pathKind(b)!=='circuit'||typeof via!=='string')return;const p=via.split(',');
if(p.length<2||p[0]!==b.city||p[p.length-1]!==b.city2||new Set(p).size!==p.length||!pathHops(pathEdges(),p))return;
b.pin=p;closeModal();toast(tr('customer_paths.name_now_rides_path',{name:esc(b.name),path:esc(pathStr(p))}),'good');sfx('build');after();},
pathAuto:({id})=>{const b=S.biz.find(x=>x.id===id);if(!b||!b.pin)return;delete b.pin;closeModal();toast(tr('customer_paths.name_follows_routing_again',{name:esc(b.name)}),'good');sfx('click');after();},
});

View file

@ -9,7 +9,7 @@ Object.assign(ACT,{
routingOpen:()=>{if(S&&!pzOn())routingModal();},
coreSet:({v})=>{if(!S.core)return;v=+v;if(!(v>=0&&v<=S.core.lv)||(v===S.core.run&&!S.core.legacy))return;S.core.run=v;delete S.core.legacy;sfx('click');after();},
via:({v})=>{UI.via=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
setRoute:({id,m})=>{if(!own(RT,m))return;const b=S.biz.find(x=>x.id===id);if(b){b.route=m;sfx('click');after();}},
setRoute:({id,m})=>{if(!own(RT,m))return;const b=S.biz.find(x=>x.id===id);if(b){b.route=m;delete b.pin;sfx('click');after();}},
route:({r})=>{UI.route=r;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
addParallel:({id})=>{const l=S.links.find(x=>x.id===id);if(l)openLinkModal(l.a,l.b);},
popStdSet:({city})=>{const p=S.pops[city];if(!p||pzOn())return;S.popStd={g:p.rgen||0,rt:p.routers||1};toast(tr('pop_std.new_pops_now_start_with',{n:S.popStd.rt,model:esc(RG[S.popStd.g].n)}),'good');sfx('click');after();},

View file

@ -37,7 +37,7 @@ function cityPanel(c){
h+=`</section><section><h3>${tr('common.business_customers')}</h3>`;
const bz=S.biz.filter(b=>bCities(b).includes(c));
if(!bz.length)h+=`<p class="empty">${tr('city_panel.no_businesses_yet_offers_pop_up')}</p>`;
for(const b of bz)h+=`<div class="row"><div class="grow"><div class="nm">${esc(b.name)}</div><div class="meta">${esc(BIZ_T[b.type].l)}${b.city2?` ${CITY[b.city].name} ⇄ ${CITY[b.city2].name}`:''} · ${bTerms(b)}${clTermTxt(b)?' · '+clTermTxt(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)?' · <b style="color:var(--bad)">'+tr('city_panel.fiber_is_down')+'</b>':''}${BIZ_T[b.type].event&&eventLive(b)?` · <b>${tr('city_panel.serving_v',{v:pct(sfOf(R,b.city))})}</b>`:''}${b.type==='scrub'&&!hasScrub()?' · <b style="color:var(--bad)">'+tr('common.needs_a_scrubbing_center')+'</b>':''}${S.day-(b.since||0)<15?` · <b>${tr('common.provisioning_n_d_grace',{n:15-(S.day-(b.since||0))})}</b>`:''}</div>${bRisk(b)}${reqList(b)}${BIZ_T[b.type].l2?routeCtl(b):''}<div class="bar ${b.mood<30?'bad':b.mood<65?'warn':''}"><i style="width:${b.mood}%"></i></div><div class="meta">${tr('common.happiness_p',{p:Math.round(b.mood)})}</div></div>${btn(UI.confirm===b.id?tr('common.really_drop'):tr('common.drop'),'dropBiz',{id:b.id},'ghost sm')}</div>`;
for(const b of bz)h+=`<div class="row"><div class="grow"><div class="nm">${esc(b.name)}</div><div class="meta">${esc(BIZ_T[b.type].l)}${b.city2?` ${CITY[b.city].name} ⇄ ${CITY[b.city2].name}`:''} · ${bTerms(b)}${clTermTxt(b)?' · '+clTermTxt(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)?' · <b style="color:var(--bad)">'+tr('city_panel.fiber_is_down')+'</b>':''}${BIZ_T[b.type].event&&eventLive(b)?` · <b>${tr('city_panel.serving_v',{v:pct(sfOf(R,b.city))})}</b>`:''}${b.type==='scrub'&&!hasScrub()?' · <b style="color:var(--bad)">'+tr('common.needs_a_scrubbing_center')+'</b>':''}${S.day-(b.since||0)<15?` · <b>${tr('common.provisioning_n_d_grace',{n:15-(S.day-(b.since||0))})}</b>`:''}</div>${bRisk(b)}${reqList(b)}${BIZ_T[b.type].l2?routeCtl(b):''}${pathCtl(b)}<div class="bar ${b.mood<30?'bad':b.mood<65?'warn':''}"><i style="width:${b.mood}%"></i></div><div class="meta">${tr('common.happiness_p',{p:Math.round(b.mood)})}</div></div>${btn(UI.confirm===b.id?tr('common.really_drop'):tr('common.drop'),'dropBiz',{id:b.id},'ghost sm')}</div>`;
h+=`</section>`+offersHere(c);
}else if(UI.tab==='up'){
h+=portNote(c)+latNote(c);

View file

@ -122,7 +122,7 @@ function dfPanel(l){
<div class="kv"><span>${tr('common.latency')}</span><b>${tr('common.ms_ms_one_way',{ms:linkLat(l).toFixed(1)})}</b></div><div class="kv"><span>${l.own?tr('link_panels.right_of_way_upkeep'):tr('common.iru_lease')}</span><b>${tr('common.price_mo',{price:fmt$(l.mo)})}</b></div><div class="kv"><span>${tr('link_panels.n_amp_huts',{n:amps})}</span><b>${tr('common.price_mo',{price:fmt$(amps*AMP_MO)})}</b></div>${!bld&&!(l.ch||[]).length?`<p class="why">${tr('link_panels.this_fiber_is_dark_add_optics')}</p>`:''}</section>`;
if(!bld){const sold=S.biz.filter(b=>b.link===l.id&&(b.type==='wwave'||b.type==='mwave'||b.type==='dfpair'||b.type==='pairs')),off=S.offers.find(o=>o.link===l.id),fc=freeCh(l);
h+=`<section><h3>${tr('link_panels.selling_spare_capacity')}</h3><p class="lead">${tr('link_panels.other_carriers_rent_what_you_do')}</p>
<div class="kv"><span>${tr('common.free_channels')}</span><b>${fc} / ${chMax(l)}</b></div>${sold.map(b=>`<div class="row"><div class="grow"><div class="nm">${esc(b.name)}</div><div class="meta">${esc(b.what||BIZ_T[b.type].l)} · ${tr('common.price_mo',{price:fmt$(b.rate)})}</div></div></div>`).join('')}
<div class="kv"><span>${tr('common.free_channels')}</span><b>${fc} / ${chMax(l)}</b></div>${sold.map(b=>`<div class="row"><div class="grow"><div class="nm">${esc(b.name)}</div><div class="meta">${esc(b.what||BIZ_T[b.type].l)} · ${tr('common.price_mo',{price:fmt$(b.rate)})}</div>${pathCtl(b)}</div></div>`).join('')}
${off?`<div class="row"><div class="grow"><div class="nm">${esc(off.name)}</div><div class="meta">${esc(off.what)} · ${tr('common.price_mo',{price:fmt$(off.rate)})} · ${tr('ui.n_d_left',{n:off.exp-S.day})}${off.broker?' · '+tr('link_panels.via_a_capacity_broker'):''}</div></div>${btn(tr('common.accept'),'accept',{id:off.id},'pink sm')}</div>`:brListHtml(l,fc)}</section>`;}
h+=`<section><h3>${tr('common.optics')}</h3><p class="lead">${tr('link_panels.each_channel_is_a_pair_of')}</p>`;
if(l.own&&l.sub&&!l.seat)h+=subUpgradePanel(l);

View file

@ -1758,6 +1758,30 @@
"core.vendor_zoo":"Vendor zoo",
"core.your_auto_te_predates_backbones":"Your Auto-TE was installed before backbones had a technology, so it runs as it always did. Changing the backbone switches to the new rules.",
"core.your_backbone_now_runs_lv":"Your backbone now runs {lv}.",
"customer_paths.fiber_label":"{name} · {km} km",
"customer_paths.fits_only_g_of_bw":"Fits only {g} of {bw}",
"customer_paths.fully_diverse":"Fully diverse",
"customer_paths.its_spare_pairs_are_taken":"Its spare pairs are already rented",
"customer_paths.let_routing_choose_again":"Let routing choose again",
"customer_paths.move":"Move",
"customer_paths.move_name":"Move {name}",
"customer_paths.move_to_another_path":"Move to another path",
"customer_paths.name_follows_routing_again":"<b>{name}</b> follows routing again.",
"customer_paths.name_moved_to_fiber":"<b>{name}</b> moved to {fiber}.",
"customer_paths.name_now_rides_path":"<b>{name}</b> now rides {path}.",
"customer_paths.no_other_path":"There is no other working path between {a} and {b} right now.",
"customer_paths.no_other_working_fiber":"There is no other working fiber between {a} and {b}. Build one, and you can move this customer onto it.",
"customer_paths.not_enough_free_channels":"Not enough free channels: {free} free, needs {n}",
"customer_paths.now_on":"Now on",
"customer_paths.only_your_own_fiber_rents_pairs":"Only your own fiber can rent out pairs",
"customer_paths.over_the_ms_budget":"Over the {ms} ms budget",
"customer_paths.path_facts":"{km} km · {ms} ms",
"customer_paths.pinned_to_path":"Pinned to {path}",
"customer_paths.routing_chooses_this_circuit":"Routing chooses this circuit's path between {a} and {b} every day. Moving it pins it to the path you pick, for free. While a link on that path is down, it follows routing until the link is back.",
"customer_paths.same_trench":"Same trench",
"customer_paths.shares_n_spans":{"one":"Shares {n} span","other":"Shares {n} spans"},
"customer_paths.that_path_is_down":"That path is down, so it follows routing for now",
"customer_paths.this_customer_rides_one_fiber":"This customer rides one fiber between {a} and {b}. Moving it to another one is free and happens at once.",
"customers.attacks_on_city_are_hauled_to":"attacks on {city} are hauled to {to} for scrubbing: +{ms} ms",
"customers.everyone_who_pays_you_happiest_last":"Everyone who pays you, happiest last. Below 60% they start to grumble, below 30% they are furious, and at 0% they cancel.",
"customers.from_unhappy_customers":"from unhappy customers",

View file

@ -0,0 +1,191 @@
// Moving a customer to another path between the same two POPs: fiber customers to another fiber, circuits by a pin.
const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
const { lit } = require('../scripts/lib/js-literal');
// New York and Ashburn, with Boston as the way round, for the test's sake. Fiber a is the direct one, on its own trench;
// b runs beside it in the same trench; c is direct on another trench; d and e go through Boston on trenches of their own.
const fib = (id, a, z, km, trench, n = 8) => `S.links.push({id:'${id}',a:'${a}',b:'${z}',kind:'df',own:true,sys:'roadm',pairs:1,ch:Array(${n}).fill('zr4'),km:${km},sub:false,cable:null,mo:1,trench:'${trench}',cut:0,day:0,ready:0,spares:false});`;
const BASE = "ACT.start({});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;S.lvl=13;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.rules=makeRules('freeze');" +
"for(const c of ['nyc','ash','bos'])if(!S.pops[c])S.pops[c]={day:0,bb:null,boost:0,down:0,routers:4,gen:false,rgen:RG.length-3};S.links=[];" +
fib('a', 'nyc', 'ash', 350, 'ta') + fib('b', 'nyc', 'ash', 350, 'ta') + fib('c', 'ash', 'nyc', 420, 'tc') + fib('d', 'nyc', 'bos', 130, 'td') + fib('e', 'bos', 'ash', 220, 'te');
const hasCities = (ev) => ev("['nyc','ash','bos'].every(isCity)");
const wave = "S.biz.push({id:'w',type:'wwave',name:'Zay-No Fiber',city:'nyc',city2:'ash',link:'a',slots:2,bw:1,rate:9000,reqs:[],mood:80,since:0,day:0,route:'normal',what:'x'});";
const pair = (type, id = 'p', link = 'a') => `S.biz.push({id:'${id}',type:'${type}',name:'A Customer ${id}',city:'nyc',city2:'ash',link:'${link}',slots:0,bw:1,rate:9000,reqs:[],mood:80,since:0,day:0,route:'normal',what:'x'});`;
const circuit = (bw = 100) => `S.biz.push({id:'k',type:'l2vpn',name:'Big Circuit',city:'nyc',city2:'ash',bw:${bw},rate:10,reqs:[],mood:80,since:0,day:0,route:'normal'});`;
function game(t, extra = '') { const h = load({ seed: 777 }); t.after(() => h.dom.window.close());
h.ev(BASE); assert.equal(hasCities(h.ev), true); h.ev(extra + 'compute();'); return h; }
const biz = (ev, id, k) => ev(`S.biz.find(b=>b.id===${lit(id)}).${k}`);
const modal = (ev) => ev("document.getElementById('modal').textContent");
test('a wave moves to another fiber: free, its channels go with it, and the first choice is on another trench', (t) => {
const { ev, errors } = game(t, wave);
const cash = ev('S.cash');
assert.deepEqual(JSON.parse(ev("JSON.stringify(fiberTargets(S.biz[0]).map(x=>[x.l.id,x.diverse,x.no]))")), [['c', true, ''], ['b', false, '']]);
assert.equal(ev("soldSlots(S.links.find(l=>l.id==='a'))"), 2);
ev("ACT.pathOpen({id:'w'})");
assert.match(modal(ev), /Fully diverse/); assert.match(modal(ev), /Same trench/);
ev("ACT.pathMove({id:'w',link:'c'})");
assert.equal(biz(ev, 'w', 'link'), 'c');
assert.equal(ev("soldSlots(S.links.find(l=>l.id==='a'))"), 0);
assert.equal(ev("soldSlots(S.links.find(l=>l.id==='c'))"), 2);
assert.equal(ev('S.cash'), cash, 'free');
assert.equal(biz(ev, 'w', 'rate'), 9000, 'the contract stands');
assert.equal(ev("document.getElementById('modal').hidden"), true);
assert.deepEqual(errors, []);
});
test('a wave needs room on the new fiber; a move is checked again when it is made', (t) => {
const { ev, errors } = game(t, wave + "S.links.find(l=>l.id==='c').ch=Array(63).fill('zr4');");
const c = JSON.parse(ev("JSON.stringify(fiberTargets(S.biz[0]).find(x=>x.l.id==='c'))"));
assert.match(c.no, /1 free, needs 2/);
ev("ACT.pathMove({id:'w',link:'c'})");
assert.equal(biz(ev, 'w', 'link'), 'a', 'refused');
for (const link of ['a', 'd', 'nope']) { ev(`ACT.pathMove({id:'w',link:${lit(link)}})`); assert.equal(biz(ev, 'w', 'link'), 'a', `${link}: not a fiber it can go to`); }
assert.deepEqual(errors, []);
});
test('a carrier already renting waves on the new fiber ends up with one contract', (t) => {
const { ev, errors } = game(t, wave + "S.biz.push({id:'w2',type:'wwave',name:'Zay-No Fiber',city:'nyc',city2:'ash',link:'c',slots:3,bw:1,rate:1000,reqs:[],mood:90,since:5,day:0,route:'normal',what:'x'});");
ev("ACT.pathMove({id:'w',link:'c'})");
assert.equal(ev("S.biz.filter(b=>b.type==='wwave').length"), 1);
assert.equal(biz(ev, 'w2', 'slots'), 5); assert.equal(biz(ev, 'w2', 'rate'), 10000); assert.equal(biz(ev, 'w2', 'mood'), 80, 'the unhappier of the two'); assert.equal(biz(ev, 'w2', 'since'), 0);
assert.match(biz(ev, 'w2', 'what'), /5/);
assert.deepEqual(errors, []);
});
test('fiber pairs follow the same rules as signing them: your own fiber, and pairs still free', (t) => {
for (const type of ['dfpair', 'pairs', 'capfib']) {
const { ev, errors } = game(t, pair(type) + pair('pairs', 'q', 'b') + "S.links.find(l=>l.id==='e').x=1;");
const T = JSON.parse(ev("JSON.stringify(Object.fromEntries(fiberTargets(S.biz[0]).map(x=>[x.l.id,x.no])))"));
assert.equal(T.c, '', `${type} can go to the free fiber`);
assert.match(T.b, /already rented/, `${type} cannot join a fiber whose pairs are sold`);
ev("ACT.pathMove({id:'p',link:'b'})"); assert.equal(biz(ev, 'p', 'link'), 'a');
ev("ACT.pathMove({id:'p',link:'c'})"); assert.equal(biz(ev, 'p', 'link'), 'c');
assert.deepEqual(errors, []);
}
const { ev } = game(t, pair('dfpair') + "S.links.find(l=>l.id==='c').own=false;");
assert.match(ev("fiberTargets(S.biz[0]).find(x=>x.l.id==='c').no"), /your own fiber/);
});
test('only working fibers are offered, and a customer on a cut fiber can be moved off it', (t) => {
const { ev, errors } = game(t, wave + "S.links.find(l=>l.id==='a').cut=S.day+9;S.links.find(l=>l.id==='b').eqDown=S.day+9;" + fib('f', 'nyc', 'ash', 300, 'tf') + "S.links.at(-1).ready=S.day+5;");
assert.equal(ev("fiberOk(S.biz[0])"), false);
assert.deepEqual(JSON.parse(ev("JSON.stringify(fiberTargets(S.biz[0]).map(x=>x.l.id))")), ['c']);
ev("ACT.pathMove({id:'w',link:'c'})");
assert.equal(ev("fiberOk(S.biz[0])"), true);
ev("S.links.find(l=>l.id==='c').ready=S.day+5;");
assert.deepEqual(JSON.parse(ev("JSON.stringify(fiberTargets(S.biz[0]).map(x=>x.l.id))")), [], 'nothing left');
ev("ACT.pathOpen({id:'w'})");
assert.match(modal(ev), /no other working fiber/);
assert.deepEqual(errors, []);
});
test('a pinned circuit rides its path, and takes the load off the direct fibers', (t) => {
const { ev, errors } = game(t, circuit(100));
const cash = ev('S.cash');
const load = () => JSON.parse(ev("JSON.stringify(Object.fromEntries(['a','b','c','d','e'].map(i=>[i,R.load[i]||0])))"));
const direct = load();
assert.equal(Math.round(direct.a + direct.b + direct.c), 100, 'by default it takes the direct edge');
assert.equal(Math.round(direct.d), 0);
const T = JSON.parse(ev("JSON.stringify(circuitTargets(S.biz[0]))"));
assert.deepEqual(T.now, ['nyc', 'ash']);
assert.deepEqual(T.alts.map((x) => x.p), [['nyc', 'bos', 'ash']]);
assert.equal(T.alts[0].shared, 0, 'nothing in common with the direct fibers');
ev("ACT.pathOpen({id:'k'})");
assert.match(modal(ev), /Fully diverse/);
ev("ACT.pathPin({id:'k',via:'nyc,bos,ash'})");
const on = load();
assert.equal(Math.round(on.a + on.b + on.c), 0);
assert.equal(Math.round(on.d), 100); assert.equal(Math.round(on.e), 100);
assert.equal(ev("R.l2.k"), 100);
assert.ok(ev('R.l2lat.k') > 0);
assert.equal(ev('S.cash'), cash, 'free');
assert.deepEqual(errors, []);
});
test('a pin falls back to routing while a link on it is down, comes back by itself, and can be undone', (t) => {
const { ev, errors } = game(t, circuit(100) + "S.biz[0].pin=['nyc','bos','ash'];");
assert.equal(ev('Math.round(R.load.d)'), 100);
ev("S.links.find(l=>l.id==='e').cut=S.day+9;compute();");
assert.equal(ev('Math.round(R.load.d||0)'), 0, 'off the broken path');
assert.equal(ev('R.l2.k'), 100, 'and the customer keeps its service');
assert.deepEqual(JSON.parse(ev('JSON.stringify(S.biz[0].pin)')), ['nyc', 'bos', 'ash'], 'the pin is kept');
assert.equal(ev('pinUp(S.biz[0])'), false);
assert.match(ev('pathCtl(S.biz[0])'), /That path is down/);
ev("S.links.find(l=>l.id==='e').cut=0;compute();");
assert.equal(ev('Math.round(R.load.d)'), 100, 'back by itself');
assert.doesNotMatch(ev('pathCtl(S.biz[0])'), /That path is down/);
ev("ACT.pathOpen({id:'k'})");
assert.match(modal(ev), /Let routing choose again/);
ev("ACT.pathAuto({id:'k'})");
assert.equal(ev("S.biz[0].pin===undefined"), true);
assert.equal(ev('Math.round(R.load.d||0)'), 0);
assert.deepEqual(errors, []);
});
test('choosing a route mode unpins; a bad path is refused; SD-WANs, pending deals and puzzles have no move', (t) => {
const { ev, errors } = game(t, circuit(100));
for (const via of ['nyc,ash,bos', 'bos,nyc,ash', 'nyc', 'nyc,nowhere,ash', 'nyc,bos,nyc,ash', 'nyc,ash,ash']) {
ev(`ACT.pathPin({id:'k',via:${lit(via)}})`);
assert.equal(ev('S.biz[0].pin===undefined'), true, via);
}
ev("ACT.pathPin({id:'k',via:null})"); ev("ACT.pathPin({id:'k',via:7})"); ev("ACT.pathPin({id:'nope',via:'nyc,ash'})");
assert.equal(ev('S.biz[0].pin===undefined'), true);
ev("S.links=S.links.filter(l=>l.id!=='e');compute();ACT.pathPin({id:'k',via:'nyc,bos,ash'})");
assert.equal(ev('S.biz[0].pin===undefined'), true, 'a hop with no link');
ev("ACT.pathPin({id:'k',via:'nyc,ash'})");
assert.equal(ev('S.biz[0].pin.length'), 2);
ev("ACT.setRoute({id:'k',m:'fast'})");
assert.equal(ev('S.biz[0].pin===undefined'), true);
assert.equal(ev("pathKind({type:'mtrain',city:'nyc',city2:'ash',sites:['nyc','ash']})"), '');
assert.equal(ev("pathKind({type:'capw',city:'nyc',city2:'ash',due:9,live:false})"), '', 'not delivered yet');
assert.equal(ev("pathKind({type:'capw',city:'nyc',city2:'ash',due:9,live:true})"), 'circuit');
assert.equal(ev("pathKind({type:'l2vpn',city:'nyc'})"), '', 'no second city');
assert.equal(ev("pathKind({type:'wwave',city:'nyc',link:'a'})"), '', 'no second city');
assert.equal(ev("pathKind({type:'wwave',city:'nyc',city2:'ash'})"), '', 'no fiber yet');
assert.deepEqual(errors, []);
});
test('with no way round, the most diverse path shares what it must and says so', (t) => {
// Boston reaches Ashburn only over the direct fibers' trench.
const { ev, errors } = game(t, circuit(100) + "S.links.find(l=>l.id==='e').trench='ta';S.links=S.links.filter(l=>l.id!=='c');");
const T = JSON.parse(ev('JSON.stringify(circuitTargets(S.biz[0]))'));
assert.deepEqual(T.alts.map((x) => [x.p, x.shared]), [[['nyc', 'bos', 'ash'], 1]]);
ev("ACT.pathOpen({id:'k'})");
assert.match(modal(ev), /Shares 1 span/);
assert.deepEqual(errors, []);
});
test('the window warns when a path is too small or too slow for the customer', (t) => {
const { ev, errors } = game(t, circuit(1e6) + "S.biz[0].latMax=0.1;");
ev("ACT.pathOpen({id:'k'})");
assert.match(modal(ev), /Fits only/);
assert.match(modal(ev), /Over the 0.1 ms budget/);
assert.deepEqual(errors, []);
});
test('saves: a pin survives a reload, and a bad one is dropped, leaving old saves alone', (t) => {
const { ev, errors } = game(t, circuit(100) + "S.biz[0].pin=['nyc','bos','ash'];");
const again = (pin) => ev(`(()=>{const s=JSON.parse(JSON.stringify(packSave(S)));s.biz[0].pin=${lit(pin)};return JSON.stringify(migrate(s).biz[0].pin);})()`);
assert.deepEqual(JSON.parse(again(['nyc', 'bos', 'ash'])), ['nyc', 'bos', 'ash']);
for (const bad of ['nyc', [], ['nyc'], ['nyc', 'nowhere', 'ash'], ['bos', 'ash'], ['nyc', 'bos'], ['nyc', 'bos', 'nyc', 'ash'], [1, 2], { a: 1 }])
assert.equal(again(bad), undefined, JSON.stringify(bad));
assert.equal(ev("(()=>{const s=JSON.parse(JSON.stringify(packSave(S)));delete s.biz[0].pin;return migrate(s).biz[0].pin===undefined;})()"), true);
// Not a circuit: no pin.
assert.equal(ev("(()=>{const s=JSON.parse(JSON.stringify(packSave(S)));s.biz[0].type='wwave';s.biz[0].pin=['nyc','ash'];return migrate(s).biz[0].pin===undefined;})()"), true);
// A stale pin (a POP on it was closed) does no harm: routing carries the circuit.
ev("delete S.pops.bos;S.links=S.links.filter(l=>l.a!=='bos'&&l.b!=='bos');compute();");
assert.equal(ev('R.l2.k'), 100);
assert.deepEqual(errors, []);
});
test('the buttons are in the panels: under a customer in its city, and on the fiber it rents', (t) => {
const { ev, errors } = game(t, wave + circuit(100));
ev("UI.tab='cust';UI.sel={type:'city',id:'nyc'};selectCity('nyc');UI.tab='cust';renderPanel();");
assert.equal(ev("document.querySelectorAll('#panel [data-act=pathOpen]').length"), 2);
ev("selectLink('a');renderPanel();");
assert.equal(ev("[...document.querySelectorAll('#panel [data-act=pathOpen]')].length"), 1);
assert.deepEqual(errors, []);
});