public
Description: A class that helps ISP's subnet their IPv4 and IPv6 address space.
Homepage: http://scie.nti.st
Clone URL: git://github.com/up_the_irons/ip_allocator.git
Click here to lend your support to: ip_allocator and make a donation at www.pledgie.com !
ip_allocator / README
100644 144 lines (92 sloc) 3.699 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
======================
Welcome to IPAllocator
======================
 
:Author: Garry Dolley
:Date: 01-14-2009
:Version: v0.1
 
A class that helps ISP's subnet their IPv4 and IPv6 address space.
 
Example uses include:
 
  * Allocating IPs to customers
  * Allocating subnets to downstream networks
  * Allocating subnets for internal use
 
Default allocation strategy uses the "centermost" scheme of RFC 3531.
 
RFC 3531 is a generalization of RFC 1219 ("On the Assignment of Subnet
Numbers"). Its first intended use is for IPv6, but can be used for any
bit length addressing scheme (e.g. IPv4).
 
When allocating IPs, we want to balance two goals:
 
  * Minimize fragmentation of blocks
 
    - For example, if you have a /19, and you allocate several /24's and /25's,
      you still want a /23 and /22 to be available if needed.
      
      You don't want the /24's and /25's to be allocated in such a way that
      they are subnets of all the available /22's, thus making no further /22's
      available for reassignment.
 
  * Allow existing allocations to "grow" into larger allocations by simply
    changing the subnet mask, instead of allocating a second, non-contiguous
    block.
 
    - This lessens the number of distinct routes seen by routing protocols,
      which places less burden on routers and saves FIB space.
 
Of these, minimizing fragmentation of blocks is given higher priority.
 
The latest code is available on GitHub:
 
  * git://github.com/up_the_irons/ip_allocator.git
 
Status
------
 
A very young class. Current specs pass, but more are needed, especially for
edge cases and IPv6. Correctness testing is incomplete. Performance has not
been touched.
 
Makes use of NetAddr module and is not optimized for speed.
 
Requirements
------------
 
* RubyGems
* NetAddr
 
Installation
------------
 
Install NetAddr gem from RubyForge::
 
  gem install -r netaddr
 
Put this code somewhere and require it in your code::
 
  require 'rubygems'
  require 'ip_allocator'
 
Example
-------
 
::
 
  require 'rubygems'
  require 'ip_allocator'
 
  @supernet = NetAddr::CIDR.create('208.79.88.0/21')
  
  @allocated = [NetAddr::CIDR.create('208.79.89.0/25'),
                NetAddr::CIDR.create('208.79.91.0/24')]
  
  @allocator = IPAllocator.new(@supernet, @allocated)
 
  # Give me a /24
  @allocator.first_unused(24).to_s => '208.79.88.0/24'
 
TODO
----
 
* Specs
 
  - Correctness
  - IPv6
 
* Some performance testing
 
Author
------
 
Garry C. Dolley
 
gdolley [at] NOSPAM- ucla.edu
 
AIM: garry97531
 
IRC: up_the_irons in #pledgie, #git, #caboose on Freenode (and usually many
other channels)
 
Formatting
----------
 
This README is formatted in reStructredText [RST]_. It has the best
correlation between what a document looks like as plain text vs. its
formatted output (HTML, LaTeX, etc...). What I like best is, markup doesn't
look like markup, even though it is.
 
.. [RST] http://docutils.sourceforge.net/rst.html
 
RDoc sucks.
 
Copyright
---------
 
Copyright (c) 2009 Garry C. Dolley
 
IPAllocator is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
 
IPAllocator is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License along with
IPAllocator; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA