I
I
ITF2019-06-30 14:02:43
Computer networks
ITF, 2019-06-30 14:02:43

What is the algorithm for partitioning the network into subnets of the specified size?

Actually it turned out to write your own "bicycle" of dividing the network into a given number of segments.
But I ran into a wall when you still need to take into account the size of the subnet.
For example, the source network:
192.168.0.0/24 (256 addresses)
For example, you need to split it into:
5 segments: 30, 30, 30, 2, 2
I came across the partitioning algorithm with "squares".
This is when you divide the network into 2 parts and until there is a subnet for the smallest segment.
But with this method, for example, I cannot break it into 4 subnets, where I break the 4th into smaller ones.
It turns out that 30 will go to the network with a /25 mask, the second 30 will go with a /26 mask, the third 30 will go with a /27 mask, 2 with /28 and 2 more with /29.
What is actually not "economical", especially if you specify a large source network (for example / 16), has its own limit on the number of segments. And the supply of unused addresses is too large.
Who can tell me how this can be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2019-06-30
@Rsa97

Summarizing the problem somewhat, we get the following:
- at the input there is a list of available subnets (possibly from one element) and a list of subnet sizes that need to be selected;
- at the output, you need to get the selected subnets and a list of the remaining unallocated subnets.
1. Find the mask of the required subnet mask := 32 - ⌈log 2 (size + 2)⌉. 2. We are looking for a subNet subnet in the list of free subnets with a maximum mask less than or equal to mask.
3. If not found, then it is impossible to select a subnet, return an error.
4. While the subNet mask is less than mask, remove subNet from the free list, split it into two subnets, add the resulting subnets to the free list, take one of them as subNet.
5. If the subNet mask is equal to mask, then select the subnet, remove it from the free list, and return the result.
Example:

Вход: список подсетей = [192.168.0.0/24], размер = 30
mask = 32-ceil(log2(32)) = 27
после поиска subNet = 192.168.0.0/24
24 < 27 => список подсетей = [192.168.0.0/25, 192.168.0.128/25], subNet = 192.168.0.0/25
25 < 27 => список подсетей = [192.168.0.0/26, 192.168.0.64/26, 192.168.0.128/25], subNet = 192.168.0.0/26
26 < 27 => список подсетей = [192.168.0.0/27, 192.168.0.32/27, 192.168.0.64/26, 192.168.0.128/25], subNet = 192.168.0.0/27
27 == 27 => список подсетей = [192.168.0.32/27, 192.168.0.64/26, 192.168.0.128/25], выделенная подсеть = 192.168.0.0/27

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question