Received: from reif.ripe.net by ncc.ripe.net with SMTP
	id AA15850 (5.65a/NCC-2.2); Sat, 7 May 1994 10:14:02 +0200
Received: from localhost.ripe.net by reif.ripe.net with SMTP
	id AA04549 (5.65a/NCC-2.2); Sat, 7 May 1994 10:14:01 +0200
Message-Id: <9405070814.AA04549@reif.ripe.net>
To: Marten Terpstra <terpstra@ripe.net>, Tony Bates <tony@ripe.net>
Subject: Database Indexing fro Classless Adresses
Cc: Geza Turchanyi <Geza.Turchanyi@ripe.net>
From: Daniel Karrenberg <Daniel.Karrenberg@ripe.net>
X-Organization: RIPE Network Coordination Centre
X-Phone: +31 20 592 5065
Date: Sat, 07 May 1994 10:14:01 +0200
Sender: Daniel.Karrenberg@ripe.net


Folks,

here are some thoughts about that problem. I think this solves
it well enough for the time. Comments?

Daniel



RIPE DB Indexing for classless addresses and general address ranges


A rough design for a viable indexing system.

This treats only bit aligned classless addresses. General ranges
can multiply indexed at their component bit aligned parts.


	Definitions

Classless Address = CLA = Prefix/Length

Prefix = PREF

Length = LEN

Less Specific Address = LSP 
A LSP of an address A has a smaller LEN than A and 
PREF(LSP(A)) is the same as the first LEN(LSP(A)) bits of PREF(A).

More Specific Address = MSP
A MSP of an address A has a greater LEN than A and
the first LEN bits of PREF(MSP(A)) are the same as PREF(A).


	Some Bounds

The number of LSPs of an address A is less than LEN(A),
which is less than 32 for any address. These can
easily be enumerated and so can be the database entries of them.

The number of MSPs of an address A is less than 
the sum of 2**(32-i) for i=LEN(A)...32.

While the number of MSPs can be huge, 
the number of less specific *database entries* of
another database entry is
is bounded by the number of databse entries itself.
This in the worst case: all but one datbase entries having the same
LEN and the remaining one being less specific.
This is a much more favourable bound as the current number
of database entries with an address is definitely bounded by
10**4 and can be assumed to be bounded by 10**6 for some time to
come.


	Data Structure

Suppose two indexes

OBJECT(CLA) points to the objects with CLA.
The number of objects pointed to is low.

MSPNXL(CLA) points to a list of the CLAs of all MSPs on 
the next existing level down.
The next exisiting level (NXL) is the next more specific level on that
path of the binary tree where a database entry exists. NXL is 
greater than LEN(CLA) but not necessarily by one as the tree is
populated sparsely. Also not every CLA pointed to by an entry in 
MSPNXL is necessarily on the same level (has the same LEN).
MSPNXL(CLA) is empty if there are no more specifics.
MSPNXL(CLA) is sorted by PREF.
There will always be MSPNXL(0/0) to catch CLAs with no
less specifics. This is probably going to be the biggest list.

The number of CLAs pointd to by a member of MSPNXL(CLA) is 
bounded by the number of distinct CLAs in the database (see above)
and not by the number of possible MSP(CLA)s.


	Representation

CLAs can be represented by PREF and LEN values assuming contiguous masks.
Most tight packing is 32bit PREF and 5bit LEN.
Externally this can be rounded to 40bits = 5 bytes.
This means that a file with a list of all CLAs in the 
datbase is bounded by 10**6 * 5 which is roughly 5MB.

OBJECT(CLA) can be represented as a DBM index.

MSPNXL(CLA) can be represented as a DBM index with an 
escape mechanism for too large lists. The escape will
point to a plain file containing the list.

Internal representation to be discussed.


	Algorithms


Operation FINDLSPS(CLA):

foreach  ( L = LSP(CLA) )  { # can be enumerated

	if ( OBJECT(CLA) )
		return it;
}

This is of O(1) as there are at most 31 LSP(CLA).


Operation INSCLA(CLA): Inserting a CLA 

foreach  ( L = LSP(CLA) )  {

	if  ( MSPNXL(L) ) { 	# MSPNXL(0/0) is guaranteed to exist

		if ( MSPNXL(L) contains MSPs(CLA) ) {
			create MSPNXL(CLA)
			copy MSPs(CLA) into MSPNXL(CLA)
			delete MSPs(CLA) from MXPNXL(L)
		}

		insert CLA into MSPNXL(L)

	}
}

This is of O(1) as there are at most 31 LSP(CLA).



Operation DELCLA(CLA): Deleting a CLA


foreach  ( L = LSP(CLA) )  {

	if  ( MSPNXL(L) ) { 	# MSPNXL(0/0) is guaranteed to exist

		delete CLA from MSPNXL(L)

		if ( MSPNXL(CLA) exists ) {
			copy MSPNXL(CLA) to MSPNXL(L)
			delete MXPNXL(CLA);
		}
	}
}

This is of O(1) as there are at most 31 LSP(CLA).


Operation FINDMSPS: Finding MSPs(CLA).

foreach ( M = MSPXNL(CLA) ) {

		if ( MSPXNL(M) ) {

			FINDMSPS(M); # recurse

		}
		else {
			return OBJECTS(M);
		}
}

The number of elements in MSPXNL(CLA) is bounded by the number 
CLAs in the DB.
The number of levels of recursion is bounded by 32.
No time to do a better eval but it is good enough!
