// IPv6-only broadband with 464XLAT and NAT64, next to CGNAT (src/game/60-features/34-ipv6-only.js, the address space in // 33-address-space.js): a city's home routers are swapped over some days, paid as they go in; its homes then hold no IPv4 // of their own, only a share of the NAT64 pool at a wider ratio than CGNAT, and grumble less. Rule ip4, like the rest. const test = require('node:test'); const assert = require('node:assert/strict'); const { load } = require('./harness'); const { lit } = require('../scripts/lib/js-literal'); // Frankfurt on On-call, plenty of cash, nothing breaking, 1,300 homes on the starting /21. const BASE = "ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.rules=makeRules('oncall');S.cash=1e8;for(const g of GOALS)S.done[g.id]=0;S.lvl=9;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.offers=[];S.biz=[];" + "ACT.launchBB({city:'fra'});S.pops.fra.rgen=3;ACT.buyTransit({city:'fra',net:'lvl',tier:3});S.pops.fra.bb.d=130;compute()"; function game(t, opts) { const h = load(opts); t.after(() => h.dom.window.close()); h.ev(BASE); return h; } const J = (ev, x) => JSON.parse(ev(`JSON.stringify(${x})`)); // Days of the swap without the rest of the day (homes stay put): the day's IPv4 step, as dayPost runs it. const days = (ev, n) => ev(`for(let i=0;i<${n};i++){S.day++;ip4Day(S.day)}compute()`); const host = (ev, id, bw) => ev(`S.biz.push(${lit({ id, city: 'fra', city2: null, reqs: [], name: 'H ' + id, type: 'host', bw, rate: 60, mood: 100, since: 0 })});compute()`); const panel = (ev, dom, c = 'fra') => { ev(`selectCity('${c}');UI.tab='cust';renderPanel()`); return dom.window.document.getElementById('panelBody'); }; test('going IPv6-only frees exactly what the address math says, the NAT64 pool before dual-stack homes', (t) => { const { ev, errors } = game(t); let u = J(ev, 'ip4Use()'); assert.deepEqual([u.T, u.H, u.H6, u.p6, u.cg, u.free], [2048, 1300, 0, 0, 0, 2048 - 82], '1,300 dual-stack homes, all public; free counts them at 1:16'); // The city panel promises it: 1,300 homes at 1:128 take 11 addresses instead of 82. assert.equal(ev("ip6Free('fra')"), 82 - 11); ev("ACT.ip6Go({city:'fra'})"); days(ev, 37); u = J(ev, 'ip4Use()'); assert.deepEqual([u.H, u.H6, u.Hd, u.p6, u.cg, u.free], [1300, 1300, 0, 11, 0, 2048 - 11], 'every home on the NAT64 pool'); assert.equal(u.free - (2048 - 82), 71, 'freed exactly what it said'); // Two cities: Frankfurt IPv6-only, Amsterdam dual stack, a /23 customer. The pool comes off first, then the dual-stack // homes take what is left and the rest go behind CGNAT. ev("ACT.buildPop({city:'ams'});ACT.launchBB({city:'ams'});S.pops.fra.bb.d=100;S.pops.ams.bb.d=160;compute()"); host(ev, 'h1', 80); u = J(ev, 'ip4Use()'); assert.deepEqual([u.B, u.H6, u.p6, u.Hd], [512, 1000, 8, 1600]); assert.equal(u.cg, Math.ceil((1600 - (1536 - 8)) * 16 / 15), 'dual-stack homes get what the pool leaves'); assert.equal(u.free, 2048 - 512 - 8 - 100); assert.ok(u.H - u.H6 - u.cg + Math.ceil(u.cg / 16) + u.p6 <= 1536, 'public homes, the CGNAT pool and the NAT64 pool fit the space'); // What Amsterdam would free is what the address space then frees. const f = ev("ip6Free('ams')"), free0 = u.free; assert.equal(f, 100 - (Math.ceil(2600 / 128) - 8)); ev("ACT.ip6Go({city:'ams'})"); days(ev, ev("S.pops.ams.bb.v6e-S.day")); assert.equal(J(ev, 'ip4Use()').free, free0 + f); assert.equal(J(ev, 'ip4Use()').cg, 0); assert.deepEqual(errors, []); }); test('the swap: its cost and days, paid as the routers go in, new homes on the new router, stopped with nothing back', (t) => { const { ev, dom, errors } = game(t); // 1,300 homes: $4 a router, 30 days and one more for every 200 homes. assert.deepEqual([ev("ip6Cost('fra')"), ev("ip6Days('fra')")], [5200, 37]); const cash0 = ev('S.cash'); ev("ACT.ip6Go({city:'fra'})"); assert.equal(ev('S.pops.fra.bb.v6e'), ev('S.day') + 37); assert.equal(ev('S.cash'), cash0, 'nothing paid up front'); assert.match(dom.window.document.getElementById('toasts').textContent, /Swapping 1,300 home routers in Frankfurt for IPv6-only ones: about 37 days/); days(ev, 10); assert.ok(Math.abs(ev('S.pops.fra.bb.v6') - 10 / 37) < 1e-9, 'an even share a day'); assert.ok(Math.abs(cash0 - ev('S.cash') - 5200 * 10 / 37) < 1e-4, 'paid for the routers that went in'); // Homes that join during the swap get the new router from the start, at the same price, paid the day they join. let c = ev('S.cash'); ev('ip6Grow(Object.assign(S.pops.fra.bb,{d:260}),130)'); assert.ok(Math.abs(ev('S.pops.fra.bb.v6') - (1 - (27 / 37) / 2)) < 1e-9); assert.ok(Math.abs(c - ev('S.cash') - 1300 * 4) < 1e-6, '1,300 new homes, 1,300 routers'); ev('S.pops.fra.bb.d=130;S.pops.fra.bb.v6=10/37;S.cash=' + c); // Stopped: the swapped homes stay, nothing comes back, nothing more is paid. const cash1 = ev('S.cash'); ev("ACT.ip6Stop({city:'fra'})"); assert.equal(ev('S.pops.fra.bb.v6e'), undefined); assert.equal(ev('S.cash'), cash1); days(ev, 30); assert.deepEqual([ev('S.cash'), ev('S.pops.fra.bb.v6')], [cash1, 10 / 37]); assert.match(dom.window.document.getElementById('toasts').textContent, /Stopped the swap in Frankfurt at 27% of homes/); // After a stop, new homes are dual stack again, and cost nothing. ev('ip6Grow(Object.assign(S.pops.fra.bb,{d:260}),130)'); assert.ok(Math.abs(ev('S.pops.fra.bb.v6') - 5 / 37) < 1e-9); assert.equal(ev('S.cash'), cash1); // Resumed: the rest, at the same price a router, and it finishes on its day. const left = ev('2600*(1-S.pops.fra.bb.v6)'); assert.equal(ev("ip6Cost('fra')"), Math.round(left * 4 / 100) * 100); assert.equal(ev("ip6Days('fra')"), 30 + Math.ceil(left / 200)); const cash2 = ev('S.cash'), n = ev("ip6Days('fra')"); ev("ACT.ip6Go({city:'fra'})"); days(ev, n - 1); assert.ok(ev('S.pops.fra.bb.v6') < 1); days(ev, 1); assert.deepEqual([ev('S.pops.fra.bb.v6'), ev('S.pops.fra.bb.v6e')], [1, undefined]); assert.ok(Math.abs(cash2 - ev('S.cash') - left * 4) < 1e-4, 'the whole rest, router by router'); assert.match(dom.window.document.getElementById('toasts').textContent, /Frankfurt is IPv6-only/); // Done: new homes come IPv6-only and pay for their router, even short of cash (a new home needs one today), and the // swap cannot start again. c = ev('S.cash'); ev('ip6Grow(Object.assign(S.pops.fra.bb,{d:400}),260)'); assert.equal(ev('S.pops.fra.bb.v6'), 1); assert.ok(Math.abs(c - ev('S.cash') - 1400 * 4) < 1e-6); ev('S.cash=100;ip6Grow(Object.assign(S.pops.fra.bb,{d:410}),400)'); assert.deepEqual([ev('S.pops.fra.bb.v6'), ev('S.pops.fra.bb.v6e'), Math.round(ev('S.cash'))], [1, undefined, 100 - 400], 'still IPv6-only, not a stopped swap'); ev('S.cash=1e8'); ev("document.getElementById('toasts').innerHTML='';ACT.ip6Go({city:'fra'})"); assert.match(dom.window.document.getElementById('toasts').textContent, /already/); assert.deepEqual(errors, []); }); test('the swap waits while cash is short, and the real day runs it with the city growing', (t) => { const { ev, dom, errors } = game(t); // Starting needs only the first day's routers on hand ($5,200 over 37 days), not the whole swap. ev('S.cash=Math.ceil(ip6First("fra"))-1'); assert.equal(panel(ev, dom).querySelector('[data-act="ip6Go"]').disabled, true); ev("ACT.ip6Go({city:'fra'})"); assert.equal(ev('S.pops.fra.bb.v6e'), undefined, 'not even a day of routers: no start'); ev('S.cash=Math.ceil(ip6First("fra"))'); assert.ok(ev('S.cash') < ev('ip6Cost("fra")') / 10); assert.equal(panel(ev, dom).querySelector('[data-act="ip6Go"]').disabled, false); ev("ACT.ip6Go({city:'fra'});S.cash=50"); const e = ev('S.pops.fra.bb.v6e'); days(ev, 3); assert.deepEqual([ev('S.pops.fra.bb.v6') || 0, ev('S.pops.fra.bb.v6e'), ev('S.cash')], [0, e + 3, 50], 'no router it cannot pay for: the end slides'); assert.match(panel(ev, dom).textContent, /Waiting for cash/); ev('S.cash=1e8'); // The whole day, homes and all: the share only rises, and the swap ends on its day. ev('for(let i=0;i<20;i++)dayTick()'); const v = ev('S.pops.fra.bb.v6'); assert.ok(v > 20 / 37 - 0.01 && v < 1, 'about 20 of 37 days done: ' + v); ev('while(S.pops.fra.bb.v6e)dayTick()'); assert.equal(ev('S.pops.fra.bb.v6'), 1); assert.equal(ev('S.day'), e + 3); const d = ev('S.pops.fra.bb.d'); ev('for(let i=0;i<30;i++)dayTick()'); assert.ok(ev('S.pops.fra.bb.d') !== d && ev('S.pops.fra.bb.v6') === 1, 'homes come and go, all IPv6-only'); assert.deepEqual(errors, []); }); test('a city that goes IPv6-only the day it launches pays a router for every home it grows into', (t) => { const { ev, errors } = game(t); // A fresh launch: 180 homes, so the swap itself is cheap. ev("S.pops.fra.bb.d=bbStart('fra');compute()"); assert.deepEqual([ev('S.pops.fra.bb.d*10'), ev("ip6Cost('fra')")], [180, 700]); ev("ACT.ip6Go({city:'fra'})"); // A year of real days: count every dollar the swap and the new homes' routers take. ev("window.__paid=0;window.__shrank=false;for(const f of ['ip6Grow','ip6Day']){const g=window[f];window[f]=(...a)=>{const c=S.cash;g(...a);__paid+=c-S.cash;};}"); ev('for(let i=0;i<365;i++){const d=S.pops.fra.bb.d;dayTick();if(S.pops.fra.bb.d 5000 && ev('__shrank') === false, 'it grew all year: ' + homes); assert.equal(ev('S.pops.fra.bb.v6'), 1); assert.ok(Math.abs(ev('__paid') - homes * 4) < 1e-3, `a router for each of its ${homes} homes, as a city switching now would pay: ${ev('__paid')}`); assert.deepEqual(errors, []); }); test('before the swap, the city panel says what it does to the monthly IPv4 bill', (t) => { const { ev, dom, errors } = game(t); // Day 0: every home has a public address and there is no IPv4 bill; going IPv6-only adds NAT64 gateways and refunds. const eye = 'R.rev.eyeballs'; const mo = ev(`ip6Mo('fra',${eye})`), before = ev('R.cost.ip4') || 0; assert.equal(before, 0); assert.ok(mo > 300 && mo < 400, 'gateways for 130 Gbps and 1% of the bill back: ' + mo); assert.match(panel(ev, dom).textContent, new RegExp(`Your IPv4 bill goes up by \\$${Math.round(mo)}/mo \\(NAT64 gateways and refunds\\)\\. No home is behind CGNAT yet: this pays off once your IPv4 runs short\\.`)); assert.match(panel(ev, dom).textContent, /Homes that join later get one too, at \$4 each\./); // Exactly what the bill does once it is done. ev('S.pops.fra.bb.v6=1;compute()'); assert.ok(Math.abs(ev('R.cost.ip4') - mo) <= 0.5, 'the bill moves by what the panel said'); // Squeezed into a /24 at 1:64, most homes are behind CGNAT: going IPv6-only saves money, and says so. ev("delete S.pops.fra.bb.v6;S.ip4.b=[{id:'x',len:24,k:'rir',d:0}];S.ip4.nat=64;compute()"); const save = ev(`ip6Mo('fra',${eye})`), cost = ev('R.cost.ip4'); assert.ok(save < 0, 'CGNAT boxes and refunds it no longer pays: ' + save); const txt = panel(ev, dom).textContent; assert.match(txt, new RegExp(`Your IPv4 bill goes down by \\$${Math.round(-save)}/mo \\(fewer CGNAT boxes and refunds\\)\\.`)); assert.doesNotMatch(txt, /No home is behind CGNAT yet/); ev('S.pops.fra.bb.v6=1;compute()'); assert.ok(Math.abs(ev('R.cost.ip4') - (cost + save)) <= 1, 'the bill moves by what the panel said'); assert.deepEqual(errors, []); }); test('out of space: the advice names the sharing that is left to stretch, CGNAT, NAT64 or both', (t) => { const { ev, dom, errors } = game(t); const toasts = () => dom.window.document.getElementById('toasts').textContent; const bank = () => { ev('ACT.ip4Open()'); const s = dom.window.document.querySelector('#bankCard .bank-ip4').textContent; ev('ACT.bankClose()'); return s; }; // 10,000 homes, every one IPv6-only, on a /24 a host customer takes whole: only the NAT64 pool is short. ev("S.pops.fra.bb.d=1000;S.pops.fra.bb.v6=1;S.ip4.b=[{id:'x',len:24,k:'rir',d:0}];compute()"); host(ev, 'h', 64); let u = J(ev, 'ip4Use()'); assert.deepEqual([u.H6, u.Hd, u.cg, u.p6, u.over], [10000, 0, 0, 79, 1]); ev('ip4Day(S.day)'); assert.match(toasts(), /Out of IPv4\.\s*Even at 128 homes per address, your NAT64 pool can't fit every IPv6-only home/); assert.doesNotMatch(toasts(), /CGNAT/); assert.match(bank(), /don't fit even at 128 IPv6-only homes per NAT64 address/); // Raising the CGNAT ratio would free nothing, so the advice does not suggest it. ev("document.getElementById('toasts').innerHTML='';S.offers=[{id:'o1',city:'fra',city2:null,reqs:[],name:'Offer',type:'dia',bw:10,rate:60}];ACT.accept({id:'o1'})"); assert.match(toasts(), /put more IPv6-only homes on each NAT64 address\./); ev("document.getElementById('toasts').innerHTML='';ip4Busy()"); assert.match(toasts(), /put more IPv6-only homes on each NAT64 address or get another block first/); // Half the homes dual stack: both ratios help, and both are named. ev("S.pops.fra.bb.v6=0.5;S.ip4.w=0;compute();document.getElementById('toasts').innerHTML='';ip4Day(S.day)"); u = J(ev, 'ip4Use()'); assert.ok(u.H6 > 0 && u.Hd > 0 && u.over > 0); assert.match(toasts(), /Even at 16 homes per address behind CGNAT and 128 on NAT64, not every home fits/); assert.match(bank(), /don't fit even at 16 homes per CGNAT address and 128 per NAT64 address/); ev("document.getElementById('toasts').innerHTML='';ip4Busy()"); assert.match(toasts(), /put more homes on each CGNAT or NAT64 address or get another block first/); // No IPv6-only homes: CGNAT, as it always said. ev("delete S.pops.fra.bb.v6;S.ip4.w=0;compute();document.getElementById('toasts').innerHTML='';ip4Day(S.day);ip4Busy()"); assert.match(toasts(), /Even at 16 homes per address, CGNAT can't fit everyone/); assert.match(toasts(), /put more homes behind CGNAT or get another block first/); assert.match(bank(), /don't fit even at 16 homes per address\./); assert.deepEqual(errors, []); }); test('the CGNAT ratio and the warnings count only the dual-stack homes, after the NAT64 pool', (t) => { const { ev, errors } = game(t); // 1,300 homes, every one IPv6-only, on a /24 with a host customer on a /25: 128 addresses left, the pool takes 11. ev("S.pops.fra.bb.v6=1;S.ip4.b=[{id:'x',len:24,k:'rir',d:0}];compute()"); host(ev, 'h', 32); let u = J(ev, 'ip4Use()'); assert.deepEqual([u.T - u.B, u.p6, u.Hd], [128, 11, 0]); // No home is behind CGNAT, so a narrower CGNAT ratio needs no room (counting all 1,300 homes, 1:8 would need 163). ev("ACT.ip4Nat({v:'8'})"); assert.equal(ev('S.ip4.nat'), 8); // Homes behind CGNAT: the warning rearms once the dual-stack homes fit public again next to the pool, though all the // homes together would not. ev("S.biz=[];S.ip4.nat=16;S.pops.fra.bb.v6=0;S.ip4.w=0;compute();ip4Day(S.day)"); assert.equal(ev('S.ip4.w'), 1, 'homes behind CGNAT'); ev('S.pops.fra.bb.v6=0.85;compute();ip4Day(S.day)'); u = J(ev, 'ip4Use()'); assert.ok(u.T - u.B - u.p6 >= u.Hd * 1.05 && u.T - u.B < u.H * 1.05, JSON.stringify(u)); assert.equal(ev('S.ip4.w'), 0, 'room to spare for the dual-stack homes: it rearms'); // Out of space (the host back, 1:8): it rearms once the pool and the CGNAT homes fit with room, whatever all the homes // at 1:8 would take. host(ev, 'h2', 32); ev('S.ip4.nat=8;S.pops.fra.bb.v6=0;compute();ip4Day(S.day)'); assert.ok(J(ev, 'ip4Use()').over > 0 && (ev('S.ip4.w') & 2) === 2, 'out of space at 1:8'); ev('S.pops.fra.bb.v6=1;compute();ip4Day(S.day)'); u = J(ev, 'ip4Use()'); assert.ok(u.T - u.B >= u.need * 1.1 && u.T - u.B < Math.ceil(u.H / u.r) * 1.1, JSON.stringify(u)); assert.equal(ev('S.ip4.w') & 2, 0, 'the pool fits with room: it rearms'); assert.deepEqual(errors, []); }); test('NAT64 refunds: well under CGNAT at the same ratio, never zero, smaller as the world goes IPv6', (t) => { const { ev, errors } = game(t); assert.deepEqual(J(ev, '[IP4_N64,IP4_N640]'), [[64, 128, 256], 128]); assert.ok(J(ev, 'IP4_N64.every(r=>IP4_ANNOY64[r]>0&&IP4_ANNOY64[r] 1000 && b.u.H6 === 0); const cgHome = b.refund / b.u.cg; assert.ok(Math.abs(cgHome - eye / 1300 * 0.04) < 1e-9); ev("ACT.ip4Nat64({v:'64'});S.pops.fra.bb.v6=1;compute()"); b = J(ev, 'ip4Bill(R.rev.eyeballs)'); assert.deepEqual([b.u.cg, b.u.H6, b.u.p6, b.u.over], [0, 1300, Math.ceil(1300 / 64), 0]); const v6Home = b.refund / b.u.H6; assert.ok(v6Home > 0 && v6Home < cgHome / 5, `an IPv6-only home ${v6Home} against one behind CGNAT ${cgHome}`); assert.ok(Math.abs(b.refund - eye * 0.006) < 1e-9); assert.equal(ev('R.cost.ip4'), Math.round(b.box + b.box64 + b.refund), 'the gateways and refunds are on the bill'); assert.ok(Math.abs(b.box64 - 130 * 0.55 * 2) < 1e-9, 'NAT64 costs what CGNAT does per Gbps of IPv4 it carries'); // Ten years on: less IPv4 to translate, fewer refunds; CGNAT's grumbling per home stays. ev('S.day=3652;compute()'); const late = J(ev, 'ip4Bill(R.rev.eyeballs)'); assert.ok(late.refund / ev('R.rev.eyeballs') < 0.006 && late.refund > 0); assert.ok(late.box64 < b.box64); ev("S.pops.fra.bb.v6=0;compute()"); const lateCg = J(ev, 'ip4Bill(R.rev.eyeballs)'); assert.ok(Math.abs(lateCg.refund / lateCg.u.cg - ev('R.rev.eyeballs') / 1300 * 0.04) < 1e-9); // A narrower NAT64 ratio is refused when the signed customers would not fit; a wider one never is. ev("S.pops.fra.bb.v6=1;S.ip4.b=[{id:'x',len:24,k:'rir',d:0}];S.biz=[];ACT.ip4Nat64({v:'256'});compute()"); assert.equal(ev('S.ip4.n64'), 256); host(ev, 'big', 40); // a /24: nothing left ev("ACT.ip4Nat64({v:'64'})"); assert.equal(ev('S.ip4.n64'), 256, 'needs 21 addresses it does not have'); ev('S.biz=[];compute();ACT.ip4Nat64({v:"64"})'); assert.equal(ev('S.ip4.n64'), 64); assert.deepEqual(errors, []); }); test('the world goes IPv6: 55% IPv4 on day 0, two points less a year, down to a floor', (t) => { const { ev, dom, errors } = game(t); assert.equal(ev('ip4V4(0)'), 0.55); assert.equal(ev('ip4V4()'), ev('ip4V4(S.day)')); const ys = [0, 1, 2, 5, 10, 20, 40].map((y) => ev(`ip4V4(${y * 365.2425})`)); for (let i = 1; i < ys.length; i++) assert.ok(ys[i] <= ys[i - 1], 'never back up: ' + ys); assert.ok(Math.abs(ys[1] - 0.53) < 1e-9 && Math.abs(ys[4] - 0.35) < 1e-9, 'two points a year: ' + ys); assert.equal(ys[6], 0.2, 'a floor: some things never leave IPv4'); assert.ok(Math.abs(ev('ip4V4(181)') - ev('ip4V4(180)')) < 1e-4, 'a gentle slope, no jumps'); // CGNAT gets cheaper with it: the same homes behind it, ten years apart. ev("S.ip4.b=[{id:'x',len:24,k:'rir',d:0}];compute()"); const box0 = J(ev, 'ip4Bill(0)').box; ev('S.day=3652;compute()'); assert.ok(Math.abs(J(ev, 'ip4Bill(0)').box - box0 * ev('ip4V4(3652)') / 0.55) < 1e-9); // The address space says how far the world has come. ev('ACT.ip4Open()'); assert.match(dom.window.document.querySelector('#bankCard .bank-ip4').textContent, /IPv6 share of home traffic this year65%/); assert.deepEqual(errors, []); }); test('rule off means no effect: no button, no swap, no pool, no bill', (t) => { const { ev, dom, errors } = game(t); ev("S.rules=makeRules('freeze');compute()"); assert.equal(ev('ip4On()'), false); const p = panel(ev, dom); assert.doesNotMatch(p.textContent, /IPv6-only|464XLAT/); assert.equal(p.querySelector('[data-act="ip6Go"]'), null); ev("ACT.ip6Go({city:'fra'})"); assert.equal(ev('S.pops.fra.bb.v6e'), undefined, 'refused'); assert.match(dom.window.document.getElementById('toasts').textContent, /IPv4 is plentiful/); // Even with the fields in place (a scenario that dropped the rule), nothing moves and nothing is billed. ev('S.pops.fra.bb.v6=0.5;S.pops.fra.bb.v6e=S.day+10;compute()'); const cash = ev('S.cash'); ev('for(let i=0;i<5;i++){S.day++;ip4Day(S.day);ip6Day(S.day)}ip6Grow(Object.assign(S.pops.fra.bb,{d:200}),130);compute()'); assert.deepEqual([ev('S.pops.fra.bb.v6'), ev('S.cash'), ev('R.cost.ip4')], [0.5, cash, undefined]); ev("ACT.ip6Stop({city:'fra'});ACT.ip4Nat64({v:'64'})"); assert.deepEqual([ev('!!S.pops.fra.bb.v6e'), ev('S.ip4.n64')], [true, 128]); assert.deepEqual(errors, []); }); test('saves: an old one loads unchanged, a swap in progress round-trips, garbage is repaired', (t) => { const { ev, errors } = game(t); ev("ACT.buildPop({city:'ams'});ACT.launchBB({city:'ams'});compute()"); // An old save: no NAT64 ratio, no IPv6-only homes. Its homes and its money are what they were. ev('delete S.ip4.n64;window.__m=[R.revMo,R.costMo]'); const bbs = 'JSON.stringify(Object.entries(S.pops).map(([c,p])=>[c,p.bb]))', pops = ev(bbs); ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()'); assert.equal(ev(bbs), pops, 'no new field in any city'); assert.equal(ev('S.ip4.n64'), 128); assert.deepEqual([ev('R.revMo'), ev('R.costMo')], J(ev, '__m')); // Mid-swap: every field as it was. ev("ACT.ip6Go({city:'fra'})"); days(ev, 5); ev("ACT.ip4Nat64({v:'256'})"); const before = ev('JSON.stringify([S.pops,S.ip4])'); ev('S=sanitize(JSON.parse(JSON.stringify(S)))'); assert.equal(ev('JSON.stringify([S.pops,S.ip4])'), before); // Garbage. const fix = (bb) => J(ev, `(()=>{S.pops.ams.bb=${lit(bb)};S=sanitize(JSON.parse(JSON.stringify(S)));return S.pops.ams.bb;})()`); const day = ev('S.day'); assert.deepEqual(fix({ d: 50, v6: 'x', v6e: 'soon' }), { d: 50 }); assert.deepEqual(fix({ d: 50, v6: -1 }), { d: 50 }); assert.deepEqual(fix({ d: 50, v6: 5, v6e: day + 9 }), { d: 50, v6: 1 }, 'done is done'); assert.deepEqual(fix({ d: 50, v6: 0.25, v6e: -40 }), { d: 50, v6: 0.25, v6e: day }, 'a past end: it finishes on the next day'); assert.deepEqual(fix({ d: 50, v6e: 1e12 }), { d: 50, v6e: day + 3650 }); ev("S.ip4.n64=7;S=sanitize(JSON.parse(JSON.stringify(S)))"); assert.equal(ev('S.ip4.n64'), 128); // A POP closed and built again starts dual stack: its homes and their routers left with it. ev("S.pops.ams.bb={d:50,v6:1};decommission(['ams']);ACT.buildPop({city:'ams'});ACT.launchBB({city:'ams'})"); assert.equal(ev('S.pops.ams.bb.v6'), undefined); assert.deepEqual(errors, []); }); test('the agent prices the swap and says why it cannot start', (t) => { const { ev, errors } = game(t, { agent: true }); assert.deepEqual(J(ev, "API_CMD.ip6Go.quote({city:'fra'})"), { setup: 5200, days: 37, monthly: Math.round(ev("ip6Mo('fra',R.rev.eyeballs)")), blocked: [] }); assert.ok(J(ev, "API_CMD.ip6Go.quote({city:'fra'})").monthly > 0, 'nothing behind CGNAT yet: it only adds'); ev("ACT.ip6Go({city:'fra'})"); assert.match(J(ev, "API_CMD.ip6Go.quote({city:'fra'})").blocked[0], /already under way/); assert.match(J(ev, "API_CMD.ip6Go.quote({city:'nyc'})").blocked[0], /Launch broadband here first/); assert.deepEqual(errors, []); }); test('on a phone: the swap in the city sheet and the NAT64 ratio in the bank, portrait and landscape', (t) => { const { ev, dom, errors } = game(t); for (const [w, hgt] of [[360, 740], [740, 360]]) { ev(`window.innerWidth=${w};window.innerHeight=${hgt};S.pops.fra.bb={d:130};compute()`); assert.equal(ev('isPhone()'), true); let p = panel(ev, dom); const go = p.querySelector('[data-act="ip6Go"]'); assert.ok(go && go.closest('.btns'), 'the button in a wrapping row'); assert.match(go.textContent, /Go IPv6-only \$5\.2k/); assert.match(p.textContent, /Swaps 1,300 home routers in about 37 days, paid as they go in, and frees 71 addresses for new customers\./); ev("ACT.ip6Go({city:'fra'})"); days(ev, 3); p = panel(ev, dom); assert.ok(p.querySelector('[data-act="ip6Stop"]').closest('.btns')); assert.match(p.textContent, /IPv6-only \(464XLAT\)8% of homes/); ev('ACT.ip4Open()'); const sec = dom.window.document.querySelector('#bankCard .bank-ip4'); const sel = sec.querySelector('select[data-chg="ip4Nat64"]'); assert.ok(sel && sel.closest('.ops-sel'), 'the NAT64 ratio stacks like the CGNAT one'); assert.deepEqual([...sel.options].map((o) => [o.value, o.selected]), [['64', false], ['128', true], ['256', false]]); for (const b of sec.querySelectorAll('button')) assert.ok(b.closest('.btns'), 'every button in a wrapping row: ' + b.textContent); // The three groups once some homes are IPv6-only: 1,300 homes, 3/37 of them on NAT64 (a pool of one address). assert.match(sec.textContent, /Broadband homes1,300Homes with their own address1,194Homes behind CGNAT0IPv6-only homes \(464XLAT\)106, NAT64 pool 1/); ev('ACT.bankClose()'); } assert.deepEqual(errors, []); }); test('no raw labels: the swap, the address space and the news, in every language', (t) => { for (const lang of ['en', 'de', 'es', 'fr', 'it', 'pt']) { const { ev, dom, errors } = load(lang === 'en' ? {} : { lang }); ev(BASE); const doc = dom.window.document; let txt = ''; const look = () => { txt += doc.getElementById('panelBody').textContent + doc.getElementById('toasts').textContent; }; ev("ACT.buildPop({city:'ams'});ACT.launchBB({city:'ams'});S.pops.ams.bb.d=1;S.ip4.b=[{id:'x',len:24,k:'rir',d:0}];compute()"); panel(ev, dom); look(); ev("ACT.ip6Go({city:'fra'})"); days(ev, 2); ev('S.cash=0'); panel(ev, dom); look(); ev("S.cash=1e8;ACT.ip6Stop({city:'fra'})"); panel(ev, dom); look(); ev("ACT.ip6Go({city:'fra'});ACT.ip6Go({city:'fra'})"); days(ev, 40); panel(ev, dom); look(); ev("ACT.ip6Go({city:'fra'});ACT.ip6Go({city:'bos'})"); look(); ev("ACT.ip4Open()"); txt += doc.getElementById('bankCard').textContent; ev("ACT.bankClose();ACT.dash({});ACT.dashTab({k:'overview'})"); txt += doc.getElementById('dashCard').textContent; assert.match(txt, /464XLAT/, lang); assert.doesNotMatch(txt, /\bip[46]\.[a-z0-9_]+|\{[a-z]+\}|undefined|NaN/, lang); assert.deepEqual(errors, [], lang); dom.window.close(); } });