UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 757 B
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.calculateCidrSplits=calculateCidrSplits;var core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp};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(core_1()).UnscopedValidationError(`IP space of size /${rootNetmask} not big enough to allocate subnets of sizes ${netmasks.map(x=>`/${x}`)}`);return ret}function nextMultiple(current,multiple){return Math.ceil(current/multiple)*multiple}