in src/logic/Packer.js [29:64]
pack(space, subnets) {
const sortedSubnets = this.sortSubnets(subnets);
let currentIp = IPUtils.netStart(IPUtils.dotToDec(space.net), space.mask);
const endIp = IPUtils.netEnd(currentIp, space.mask);
const packedNets = [];
for (let i = 0; i < sortedSubnets.length; i++) {
const subnet = sortedSubnets[i];
const fit = this.fit(currentIp, endIp, subnet);
if (fit.fit) {
packedNets.push({
name: subnet.name,
mask: subnet.mask,
netStart: currentIp,
netEnd: fit.end,
description: subnet.description,
vpcName: subnet.vpcName,
subnetRangeName: subnet.subnetRangeName,
type: subnet.type,
});
currentIp = fit.end + 1;
} else {
// Couldn't fit
return {
state: 'bad',
};
}
}
const freeRanges=this.findEmptyRanges(space, currentIp);
return {
state: 'ok',
packedNets: packedNets,
freeRanges: freeRanges,
};
}