${initials(f)}${CITY[a].name} → ${CITY[b].name}
${label} · ${km.toLocaleString()} km${sub?' '+tr('common.subsea'):''}
${VXC.map((V,t)=>btn(`${V.n} ${tr('common.price_mo',{price:fmt$(vxcMo(km,sub,t))})}`,'buyVxc',{a,b,prov:f.id,t},'sm',(!remote&&!pb)||V.g>freeA||V.g>freeB||S.cash
`;};
for(const f of FABS){if(prov&&f.id!==prov)continue;
diff --git a/src/i18n/en.js b/src/i18n/en.js
index c34f7df..778aa46 100644
--- a/src/i18n/en.js
+++ b/src/i18n/en.js
@@ -1017,7 +1017,6 @@
"city_panel.pay_a_bigger_network_per_gbps":"Pay a bigger network per Gbps and it carries your traffic to the whole internet. Billed on the 95th percentile of the last 30 days, with a 20% commit and a port fee. Spikes like DDoS raise your bill.",
"city_panel.peer_at_ix_without_building_a":"Peer at {ix} without building a POP. Order a virtual circuit here from one of your POPs over {fabs}.",
"city_panel.port_cost_mo_mo":"{port}
{cost} + {mo}/mo",
-"city_panel.port_port_price_mo":"{port} port · {price}/mo",
"city_panel.port_port_price_mo_197d":"{port} port
{price}/mo",
"city_panel.power_cuts_are_covered":"Power cuts are covered.",
"city_panel.price_per_gbps_month_billed_on":"${price} per Gbps / month · billed on 95th percentile",
diff --git a/tests/issues.test.js b/tests/issues.test.js
index 9e4f696..b55b995 100644
--- a/tests/issues.test.js
+++ b/tests/issues.test.js
@@ -770,7 +770,8 @@ test('connections in the NOC dashboard can be upgraded and grown into LAGs right
assert.equal(ev("S.ixp.ams"), 2);
assert.ok(tap('buyNni'));
assert.equal(ev("S.nni[0].tier"), 1);
- assert.equal(ev("document.querySelector('#dashCard [data-act=\"buyNni\"]')"), null, 'no upgrade past the biggest fabric port');
+ assert.ok(tap('lagNni'), 'a fabric port bundles into a LAG too (#140)');
+ assert.equal(ev("S.nni[0].n"), 2);
assert.equal(ev("document.getElementById('dash').hidden"), false);
assert.deepEqual(errors, []);
});
diff --git a/tests/mcp-commands.test.js b/tests/mcp-commands.test.js
index 6e5a562..f88e4ae 100644
--- a/tests/mcp-commands.test.js
+++ b/tests/mcp-commands.test.js
@@ -220,7 +220,7 @@ test('a dry run prices every command that has a price, and changes nothing', ()
addGen: { city: 'fra' }, addSite: { city: 'fra' }, buyTransit: { city: 'fra', net: 'cog', tier: 2 }, lagT: { id: ev('S.transit[0].id'), d: 1 },
cleanPipe: { id: ev('S.transit[0].id') }, buyIx: { city: 'ams', tier: 1 }, foundIx: { city: 'nyc' }, myIxUp: { city: 'nyc' },
pni: { city: 'fra', net: 'lvl', tier: 1 }, cache: { city: 'fra', net: 'nfx' }, buildLink: { a: 'fra', b: 'nyc', tier: 1 }, upLink: { id: wave, tier: 2 },
- rmLink: { id: wave }, buyNni: { city: 'fra', prov: fab, tier: 0 }, buyVxc: { a: 'fra', b: 'ams', prov: fab, t: 0 }, upVxc: { id: wave, t: 1 },
+ rmLink: { id: wave }, buyNni: { city: 'fra', prov: fab, tier: 0 }, lagNni: { city: 'fra', prov: fab, d: 1 }, buyVxc: { a: 'fra', b: 'ams', prov: fab, t: 0 }, upVxc: { id: wave, t: 1 },
orderDf: { a: 'fra', b: 'ams', source: 'lease', system: 'lite' }, orderCable: { a: 'lis', b: 'nyc' }, subUpgrade: { id: df, k: 'terminal' },
crews: { id: df }, addCh: { id: df, o: 'zr4' }, addPair: { id: df }, upSys: { id: df }, regen: { id: df, d: 1 }, buySpare: { o: 'zr4' }, sellSpare: { o: 'zr4' },
setChCount: { id: df, o: 'zr4', n: 2 }, repayLoan: { id: 'none' }, buildScrub: { city: 'ams', tier: 1 }, scrubUp: { city: 'fra', tier: 1 },
diff --git a/tests/nni.test.js b/tests/nni.test.js
new file mode 100644
index 0000000..ad84b1b
--- /dev/null
+++ b/tests/nni.test.js
@@ -0,0 +1,138 @@
+// Fabric ports (NNI) are ports like any other (#140): 10G, 100G or 400G as far as the router takes it, bundled into a
+// LAG up to LAG_MAX, a router port per member. A customer coming in over the fabric is only accepted, by hand or automatically, when its
+// own bandwidth fits on the port as well as what is booked there already (#307).
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const { load } = require('./harness');
+
+// Frankfurt, with a POP, money, and a fabric that is there; the router as given (Rusty Router: 100G at most).
+function open(rg) {
+ const h = load({ seed: 140 });
+ h.ev("ACT.start({});S.cash=1e9;S.lvl=6;for(const g of GOALS)S.done[g.id]=0;window.FB=FABS.find(f=>f.cities.includes('fra')).id;S.pops.fra.rgen=0;S.pops.fra.routers=1");
+ if (rg !== undefined) h.ev(`S.pops.fra.rgen=${rg}`);
+ return h;
+}
+const fast = (maxP) => `RG.findIndex(r=>r.maxP>=${maxP}&&r.ports>=40)`;
+const port = (ev) => JSON.parse(ev("JSON.stringify(nniPort('fra',FB)||null)"));
+const live = (id, bw) => `S.biz.push({id:'${id}',type:'fabip',city:'fra',prov:FB,bw:${bw},rate:110,reqs:['nni'],mood:100,since:S.day,name:'Fab ${id}'});compute()`;
+const offer = (id, bw) => `S.offers.push({id:'${id}',type:'fabip',city:'fra',prov:FB,bw:${bw},rate:110,reqs:['nni'],exp:S.day+30,name:'Offer ${id}',start:S.day,dur:365})`;
+
+test('10G, 100G and 400G, priced so a faster port costs less per Gbps; 10G and 100G keep their prices', () => {
+ const { ev } = open();
+ const t = JSON.parse(ev('JSON.stringify({nni:NNI,port:PORT.map(p=>[p.n,p.g])})'));
+ assert.deepEqual(t.nni.map((x) => [x.n, x.g]), t.port.slice(0, 3), 'the port speeds up to 400G, and no faster');
+ assert.deepEqual(t.nni.slice(0, 2).map((x) => x.mo), [500, 1200], 'the sizes saves already have cost what they did');
+ for (let i = 1; i < t.nni.length; i++) {
+ assert.ok(t.nni[i].mo > t.nni[i - 1].mo, `${t.nni[i].n} costs more`);
+ assert.ok(t.nni[i].mo / t.nni[i].g < t.nni[i - 1].mo / t.nni[i - 1].g, `but less per Gbps than ${t.nni[i - 1].n}`);
+ }
+});
+
+test('a fabric port is as fast as the router takes, up to 400G', () => {
+ const { ev, errors } = open();
+ ev('ACT.buyNni({city:"fra",prov:FB,tier:2})');
+ assert.equal(port(ev), null, 'a 100G router cannot take a 400G fabric port');
+ ev('ACT.buyNni({city:"fra",prov:FB,tier:1})');
+ assert.equal(port(ev).tier, 1);
+ ev(`S.pops.fra.rgen=${fast(5)};ACT.buyNni({city:"fra",prov:FB,tier:5});ACT.buyNni({city:"fra",prov:FB,tier:3})`);
+ assert.equal(port(ev).tier, 1, 'even a 3.2T router gets no fabric port faster than 400G');
+ ev('ACT.buyNni({city:"fra",prov:FB,tier:2})');
+ assert.equal(port(ev).tier, 2);
+ assert.equal(ev('nniCap(nniPort("fra",FB))'), 400);
+ // A router that cannot take 400G would strand it, so the model change is refused.
+ assert.match(ev("modelFits('fra',RG.findIndex(r=>r.maxP===1))"), /bigger than/);
+ assert.deepEqual(errors, []);
+});
+
+test('a fabric port bundles into a LAG: same speed, a router port each, 95% of the sum, every member billed', () => {
+ const { ev, errors } = open(undefined);
+ ev(`S.pops.fra.rgen=${fast(2)};ACT.buyNni({city:"fra",prov:FB,tier:2})`);
+ const before = JSON.parse(ev("JSON.stringify({u:portsUsed('fra'),c:R.cost.nni})"));
+ for (let i = 0; i < 3; i++) ev('ACT.lagNni({city:"fra",prov:FB,d:1})');
+ ev('compute()');
+ assert.equal(port(ev).n, 4);
+ assert.equal(ev('nniCap(nniPort("fra",FB))'), 400 * 4 * 0.95);
+ assert.equal(ev("portsUsed('fra')"), before.u + 3, 'a router port per member');
+ assert.equal(ev('R.cost.nni'), 4 * 3000, 'four members, four monthly prices');
+ for (let i = 0; i < 10; i++) ev('ACT.lagNni({city:"fra",prov:FB,d:1})');
+ assert.equal(port(ev).n, ev('LAG_MAX'), 'up to LAG_MAX, like every LAG');
+ assert.equal(ev('nniCap(nniPort("fra",FB))'), 400 * ev('LAG_MAX') * 0.95, 'more than 400G is more members');
+ assert.deepEqual(errors, []);
+});
+
+test('upgrading a LAG moves and pays for every member', () => {
+ const { ev, errors } = open();
+ ev('ACT.buyNni({city:"fra",prov:FB,tier:1});ACT.lagNni({city:"fra",prov:FB,d:1});ACT.lagNni({city:"fra",prov:FB,d:1})');
+ ev(`S.pops.fra.rgen=${fast(2)};S.cash=1e9;ACT.buyNni({city:"fra",prov:FB,tier:2})`);
+ assert.equal(ev('S.cash'), 1e9 - 3 * ev('NNI[2].mo'));
+ assert.deepEqual([port(ev).tier, port(ev).n], [2, 3]);
+ assert.deepEqual(errors, []);
+});
+
+test('a member only comes off when what the port carries still fits', () => {
+ const { ev, errors } = open();
+ ev('ACT.buyNni({city:"fra",prov:FB,tier:1});ACT.lagNni({city:"fra",prov:FB,d:1})');
+ ev(live('b1', 150));
+ ev('ACT.lagNni({city:"fra",prov:FB,d:-1})');
+ assert.equal(port(ev).n, 2, '150G does not fit on one 100G member');
+ ev('S.biz=S.biz.filter(b=>b.id!=="b1");ACT.lagNni({city:"fra",prov:FB,d:-1})');
+ assert.equal(port(ev).n, undefined, 'back to a single port');
+ assert.deepEqual(errors, []);
+});
+
+test('a fabric customer is only accepted when its own bandwidth fits on the port too (#307)', () => {
+ const { ev, errors } = open();
+ ev('ACT.buyNni({city:"fra",prov:FB,tier:1})');
+ ev(live('b1', 80));
+ ev(offer('o1', 30));
+ assert.equal(ev("reqOk(S.offers.find(o=>o.id==='o1'))"), false, '80G booked + 30G asked > 100G');
+ assert.equal(ev("autoOffer(S.offers.find(o=>o.id==='o1'))"), null, 'so it is not auto-accepted');
+ ev(offer('o2', 20));
+ assert.equal(ev("reqOk(S.offers.find(o=>o.id==='o2'))"), true, '80G + 20G fits');
+ // Once accepted, a customer counts once, not twice.
+ ev("ACT.accept({id:'o2'});compute()");
+ assert.equal(ev("reqOk(S.biz.find(b=>b.id==='o2'))"), true);
+ assert.equal(ev("nniUsed('fra',FB)"), 100);
+ // A LAG member makes room for the one that did not fit.
+ ev('ACT.lagNni({city:"fra",prov:FB,d:1})');
+ assert.equal(ev("reqOk(S.offers.find(o=>o.id==='o1'))"), true);
+ assert.deepEqual(errors, []);
+});
+
+test('the city panel offers the speeds the router takes, up to 400G, and LAG members', () => {
+ const { ev, dom, errors } = open(undefined);
+ ev(`S.pops.fra.rgen=${fast(2)};selectCity('fra');UI.tab='links';renderPanel()`);
+ const buy = () => [...dom.window.document.querySelectorAll('#panelBody [data-act="buyNni"]')].filter((b) => JSON.parse(b.dataset.args).prov === ev('FB'));
+ const tiers = buy().map((b) => [JSON.parse(b.dataset.args).tier, b.disabled]);
+ assert.ok(tiers.length >= 3, 'more than the old two sizes');
+ assert.deepEqual(tiers.map(([t]) => t), [0, 1, 2], '10G, 100G and 400G: nothing faster');
+ assert.ok(tiers.every(([, d]) => !d), 'this router takes all three');
+ ev('S.pops.fra.rgen=RG.findIndex(r=>r.maxP===1);renderPanel()');
+ assert.deepEqual(buy().map((b) => [JSON.parse(b.dataset.args).tier, b.disabled]), [[0, false], [1, false], [2, true]], 'a 100G router shows 400G, but not for sale');
+ ev(`S.pops.fra.rgen=${fast(2)}`);
+ ev('ACT.buyNni({city:"fra",prov:FB,tier:2});renderPanel()');
+ assert.ok(dom.window.document.querySelector('#panelBody [data-act="lagNni"]'), 'a LAG member');
+ assert.match(dom.window.document.querySelector('#panelBody').textContent, /400G port/);
+ ev('ACT.lagNni({city:"fra",prov:FB,d:1});renderPanel()');
+ assert.match(dom.window.document.querySelector('#panelBody').textContent, /2×400G LAG/);
+ assert.deepEqual(errors, []);
+});
+
+test('saves: fabric ports that make no sense are dropped, LAGs are kept in bounds, old ports are unchanged', () => {
+ const { ev, errors } = open();
+ ev('ACT.buyNni({city:"fra",prov:FB,tier:1})');
+ const s = JSON.parse(ev('JSON.stringify(S)'));
+ s.nni.push({ id: 'x1', city: 'fra', prov: 'nope', tier: 0 }, { id: 'x2', city: 'zzz', prov: s.nni[0].prov, tier: 0 },
+ { id: 'x3', city: 'fra', prov: s.nni[0].prov, tier: 99 }, { id: 'x4', city: 'fra', prov: s.nni[0].prov, tier: '1' }, null);
+ s.nni[0].n = 50;
+ ev(`S=migrate(${JSON.stringify(s)});compute()`);
+ const n = JSON.parse(ev('JSON.stringify(S.nni)'));
+ assert.equal(n.length, 1, 'only the real port is left');
+ assert.equal(n[0].tier, 1);
+ assert.equal(n[0].n, ev('LAG_MAX'));
+ s.nni = [{ id: 'old', city: 'fra', prov: s.nni[0].prov, tier: 0 }];
+ ev(`S=migrate(${JSON.stringify(s)});compute()`);
+ assert.deepEqual(JSON.parse(ev('JSON.stringify(S.nni)')), [{ id: 'old', city: 'fra', prov: s.nni[0].prov, tier: 0 }]);
+ assert.equal(ev('R.cost.nni'), 500, 'a 10G port from before costs what it did');
+ assert.deepEqual(errors, []);
+});