UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 691 B
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.calculateCidrSplits=void 0;function calculateCidrSplits(rootNetmask,netmasks){const ret=new Array;let offset=0;for(const netmask of netmasks){const size=Math.pow(2,32-netmask);offset=nextMultiple(offset,size);const count=Math.pow(2,netmask-rootNetmask);ret.push({count,netmask,index:offset/size}),offset+=size}if(offset>Math.pow(2,32-rootNetmask))throw new Error(`IP space of size /${rootNetmask} not big enough to allocate subnets of sizes ${netmasks.map(x=>`/${x}`)}`);return ret}exports.calculateCidrSplits=calculateCidrSplits;function nextMultiple(current,multiple){return Math.ceil(current/multiple)*multiple}