Changeset 692 for trunk/cgi-bin/main.cgi


Ignore:
Timestamp:
02/11/15 18:43:22 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Start adding support for advisory "reserved block" assignments - when
creating a new assignment, flag an equal-sized block ahead or behind
to expand the assignment in the future. See #24.

  • free block assignment
  • guided assignment (still needs tweaking to dodge existing reserved blocks)
  • note flagged blocks in free block list
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/main.cgi

    r691 r692  
    410410
    411411  my $cidr;
     412  my $resv;   # Reserved for expansion.
    412413  my $alloc_from;
    413414  my $fbid = $webvar{fbid};
     
    443444      $alloc_from = new NetAddr::IP $webvar{allocfrom};
    444445      $webvar{maskbits} = $cidr->masklen;
     446      # Some additional checks are needed for reserving free space
     447      if ($webvar{reserve}) {
     448        if ($cidr == $alloc_from) {
     449# We could still squirm and fiddle to try to find a way to reserve space, but the storage model for
     450# IPDB means that all continguous free space is kept in the smallest number of strict CIDR netblocks
     451# possible.  (In theory.)  If the request and the freeblock are the same, it is theoretically impossible
     452# to reserve an equivalent-sized block either ahead or behind the requested one, because the pair
     453# together would never be a strict CIDR block.
     454          $page->param(warning => "Can't reserve space for expansion;  free block and requested allocation are the same.");
     455          delete $webvar{reserve};
     456        } else {
     457          # Find which new free block will match the reqested block.
     458          # Take the requested mask, shift by one
     459          my $tmpmask = $webvar{maskbits};
     460          $tmpmask--;
     461          # find the subnets with that mask in the selected free block
     462          my @pieces = $alloc_from->split($tmpmask);
     463          foreach my $slice (@pieces) {
     464            if ($slice->contains($cidr)) {
     465              # For the subnet that contains the requested block, split that in two,
     466              # and flag/cache the one that's not the requested block.
     467              my @bits = $slice->split($webvar{maskbits});
     468              if ($bits[0] == $cidr) {
     469                $resv = $bits[1];
     470              } else {
     471                $resv = $bits[0];
     472              }
     473            }
     474          }
     475        }
     476      } # reserve block check
     477
    445478    } else { # done with direct freeblocks assignment
    446479
     
    465498          }
    466499          $failmsg .= "You will have to route another superblock to $webvar{pop}<br>\n".
    467                 "from one of the master blocks or chose a smaller blocksize.";
     500                "from one of the master blocks";
     501          if ($webvar{reserve}) {
     502            $failmsg .= ', choose a smaller blocksize, or uncheck "Reserve space for expansion".';
     503          } else {
     504            $failmsg .= " or chose a smaller blocksize.";
     505          }
    468506        }
    469507      }
    470508
    471 ## fixme:  add rdepth?
     509      # if requesting extra space "reserved for expansion", we need to find a free
     510      # block at least double the size of the request.
     511      if ($webvar{reserve}) {
     512        $webvar{maskbits}--;
     513      }
     514
    472515      ($fbid,$cidr,$p_id) = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype},
    473516        $webvar{city}, $webvar{pop}, (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
     
    478521      $cidr = new NetAddr::IP $cidr;
    479522
    480 # this chunk now specific to "guided" allocation;  freeblock-select can now slice-n-dice on its own.     
    481523      $alloc_from = "$cidr";
     524
     525      # when autofinding a block to allocate from, use the first piece of the found
     526      # block for the allocation, and the next piece for the "reserved for expansion".
     527      if ($webvar{reserve}) {
     528        # reset the mask to the real requested one, now that we've got a
     529        # block large enough for the request plus reserve
     530        $webvar{maskbits}++;
     531        ($cidr,$resv) = $cidr->split($webvar{maskbits});
     532      }
     533
    482534      # If the block to be allocated is smaller than the one we found,
    483535      # figure out the "real" block to be allocated.
     
    524576## end node hack
    525577
     578  # reserve for expansion
     579  $page->param(reserve => $webvar{reserve});
     580  # probably just preventing a little log noise doing this;  could just set the param
     581  # all the time since it won't be shown if the reserve param above isn't set.
     582#  if ($webvar{reserve}) {
     583    $page->param(resvblock => $resv);
     584#  }
     585
    526586  # Stick in the allocation data
    527587  $page->param(alloc_type => $webvar{alloctype});
     
    592652        cidr            => $webvar{fullcidr},
    593653        fbid            => $webvar{fbid},
     654        reserve         => $webvar{reserve},
    594655        parent          => $webvar{parent},
    595656        custid          => $webvar{custid},
Note: See TracChangeset for help on using the changeset viewer.