Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gabe fix ipallocation #181

Merged
merged 3 commits into from
Jul 18, 2014
Merged

Gabe fix ipallocation #181

merged 3 commits into from
Jul 18, 2014

Conversation

byxorna
Copy link
Contributor

@byxorna byxorna commented Jul 18, 2014

@maddalab @Primer42 This is an attempt to fix fix broken IP allocation in ranges larger than a /24 when the last address in a /24 is consumed (and incorrectly identified as a local maxima).

This makes sure that the localMax address in the set of consumed addresses (what we increment to get the next address) does not have a neighbor to its right while crossing octet boundaries properly, and does not land on the last address of the range.

Testable with:

import util._

val calc = IpAddressCalc(2886737920L,4294963200L, Some("172.16.32.100") )

def gabefunc(calc: IpAddressCalc, sortedAddresses: List[Long]): Option[Long] = {
    val minAddress = calc.minAddressAsLong
    val maxAddress = calc.maxAddressAsLong
    lazy val localMaximaAddresses = for {
      i <- Range(0, sortedAddresses.size-1).inclusive.toStream
      curr = sortedAddresses(i)
      next = sortedAddresses.lift(i+1)
      nextAddress = calc.incrementAddressUnchecked(curr)
      if (next.map{_ > nextAddress}.getOrElse(true))
      if (curr < calc.maxAddressAsLong)
    } yield curr

    localMaximaAddresses.headOption
}

gabefunc(calc, List(2886741130L,2886741131L,2886741134L)) //Some(.139) 2886741131L
gabefunc(calc, List(2886742010L,2886742011L,2886742012L,2886742013L)) //Some(.253) 2886742013L
gabefunc(calc, List(2886742010L,2886742011L,2886742012L,2886742013L,2886742014L)) //None, .47.254 range is used to end (start at front)
gabefunc(calc, List(2886738173L,2886738174L)) //172.16.32.254 is used, should return 2886738174L (.254 to increment to .1)
gabefunc(calc, List(2886738173L,2886738174L,2886738177L)) //172.16.32.254, 33.1 is used, Should return 2886738177L (.33.1)
gabefunc(calc, List(2886738173L,2886738174L,2886738178L)) //172.16.32.254, 33.2 is used, Should return 2886738174L to increment to 33.1

// address should not have an allocated address logically after it
if (next.map{_ > nextAddress}.getOrElse(true))
// address should not be the last address in the IP range
if (curr < calc.maxAddressAsLong)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use the val assigned earlier and avoid the function call.

@yl3w
Copy link
Contributor

yl3w commented Jul 18, 2014

lgtm

@byxorna
Copy link
Contributor Author

byxorna commented Jul 18, 2014

@maddalab fixed up for the missed precomputed maxAddress.

byxorna added a commit that referenced this pull request Jul 18, 2014
@byxorna byxorna merged commit a827683 into master Jul 18, 2014
@william-richard william-richard deleted the gabe-fix-ipallocation branch September 9, 2014 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants