seriesoftubes/tests/helpers/reference-allocation.js
Christopher Hawker ac5928d41d A carrier's own transit port takes its traffic, with a Carry here switch for other POPs
Transit ports at a POP shared load by free capacity whatever the traffic
was for, so Level Tree's own traffic went out of a Tell-Ya port about
half the time. Traffic bound for a carrier, or for a network that buys
transit from it, now goes out of that carrier's port at the same POP
first (the shorter AS path). Each such port is still an ordinary transit
exit, so POPs without one use it when nothing nearer has room.

A new switch on each transit port, Carry here, pulls that traffic from
every POP across your network to this port. The default, Nearest port,
keeps using the closest transit port from POPs that have no port of the
carrier. The switch only shows when another carrier's port could take
the traffic instead.

Prefer-marked ports, Backup only, RouteScript and Auto-TE keep their say,
and any Prefer-marked transit port switches the rule off. Traceroute
follows the same rule and says why it picked an exit. The setting is
repaired in sanitize(); old saves load with it off.

The routing reference test now has several carriers sharing POPs, ports
that carry, backup ports and RouteScript, and its reference loop knows
the new ranks.
2026-10-29 21:16:21 +11:00

20 lines
1.2 KiB
JavaScript

// Deliberately scan all exits for every flow, without byRank, local-city
// shortcuts or first-group selection. Stable sorting preserves E order on ties.
module.exports = `
for(const pass of PASSES||[null])for(const rank of RANKS){
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++;
// A carrier's own port (dr) is also a plain transit exit; one not set to carry only takes its own POP's traffic.
const candidates=E.filter(e=>e.used<e.cap&&e.ok(f.n)&&
((TR?eff(e,f.n):base(e))===rank||(dr(e,f.n)||-1)===rank)&&
(rank!==DIRECT_RANK[1][1]&&rank!==DIRECT_RANK[2][1]||CIDX[e.city]===f.ci)&&Dv[CIDX[e.city]]<Infinity)
.sort((a,b)=>(a.pref==='high'?0:1)-(b.pref==='high'?0:1)||Dv[CIDX[a.city]]-Dv[CIDX[b.city]]);
for(let i=0;i<candidates.length&&f.rem>1e-6;){
let j=i+1;while(j<candidates.length&&(candidates[j].pref==='high')===(candidates[i].pref==='high')&&
Math.abs(Dv[CIDX[candidates[j].city]]-Dv[CIDX[candidates[i].city]])<1e-6)j++;
sendGroup(candidates.slice(i,j));i=j;
}
}
}
`;