WHAT'S NEW?
Loading...

Cidr generation algorithm (when ips under provider's domain)

Intro

Today I want to share with you a way I found very useful to generate cidrs using the IPNetwork library from GitHub.

I like the approach I took in here as the idea is to hit the biggest subnets with most ips in use an then go down until the smallest subnets with less ips in. I create groups by the first two octets of the ips provided basically because providers always have a range of these ips.

Tests

In the following algorithm, I use a completely different approach which I've tested with different IP populations. In one of the test, I passed into the function 55 inconsistent ips (remember my limit is 50 cidrs) which using the original code above ends up returning very wide cidrs (/8, /16). With the new algorithm, I only get /32, which is 100% optimisation update. I know 5 are wasted but this scenario is not real under an Internet provider subnet environment.

In a second test, I passed again real production data. The result is very good as I get rid of all the the "/7" and the nine "/8" (161 millions of ips) and now I only get one "/16" (65k ips) as the worst cidr. This is also a huge improvement considering this is real data and I'm basically getting the same result.

The rest are real ranges but still small (21, 24, 28) and orphaned ips (32). Still room for improvement as we don't reach the AWS limit of 50 by 28 free slots.

Solution

Here some code

Results


By moving from the default approach of using IPNetwork.Supernet() method into this, I found out that the generation improved enormously. I moved from 184M available ips in my cidr domain to just 40k available ips. That a HUGE improvemnt right?

Conclusion

I definitely recommend this algorithm to generate cidrs based on ips assigned by a particular provider as these providers typically move in a certain range.

0 comments:

Post a Comment