IP-Lookup and Packet Classification, IIAdvanced Algorithms & Data Structures
Lecture Theme 8
Prof. Dr. Th. OttmannSummer Semester 2006
2
Overview
The IP-table lookup problem
Geometric interpretation of the problem
Solution using Priority Search Trees
Solution using min augmented range trees, loser trees
3
128.9.16.0/21128.9.172.0/21
128.9.176.0/24
Routing lookup: Find the longest matching prefix (the most specific route) among all prefixes that match the destination address.Geometric view: For a given point p, find the smallest interval stabbed by p.
0 232-1
128.9.0.0/16142.12.0.0/19
65.0.0.0/8
128.9.16.14
LMP-Matching
4
0 5 10 15 0 5 10 15
A
BC
D
A
B
C
D
p = (d, d)
10
5d
0 5 10 15 0 5 10 15
A
BC
D
A
B
C
D
p = (d, d)
10
5d
Mapping intervals to points
Assumption: All points have pairwise distinct x-coordinates Map point (x, y) to ((x, – y), y)
Interval (l, r) is mapped to point (r, l) below the main diagonal.
5
Disjoint intervals
B
A B
A
X and Y represent disjoint intervals⇔ There is no point p on the diagonal, s.t. p ≼ X und p ≼ Y
6
Geometric interpretation of interval-inclusion
A
B
A
B
A ⊒ B Interval A = (lA, rA) includes interval B = (lB, rB) iff. point A is right below point B A B ⋟
B ⊑ A ⇔ A ⊒ B ⇔ point B left above point A ⇔ B ≼ A
7
Overlapping intervals
C
p
D
C
D
X and Y represent overlapping intervals⇔ There is a point p on the diagonal, s.t. p ≼ X and p ≼ Y , but X and Y are incomparable with resp. to ≼
8
Nested intervals
B
C
A
B
p
A
D
C
X is smallest intervall, that contains point p⇔ p ≼ X and for all Y with p ≼ Y : X ≼ Y
Observation: Sets of nested intervals stabbed by a point are totally ordered with resp. to ≼ Points closer to the diagonal represent smaller intervals.
D
9
Equivalent Query
For a given p, find the leftmost point whose x-value is greater than or equal to p and whose y-value is less than or equal to p.
p
p
Since the original intervals are nested, the topmost-leftmost point is also the leftmost one!
10
Geometric view of IP-table lookup
Find a representation of a (dynamic) set of intervals such that the following operations can be carried out efficiently:
• Insertion of an interval
• Deletion of an interval
• For a given point p: Find the smallest interval stabbed by p (LMP-query)
Assumptions:
Set of intervals is a nested set.
Every newly inserted interval does not overlap with any interval in the set.
Conflict test: For a given interval test whether or not it overlaps (is in conflict) with any interval already in the set.
11
Geometric Solution of the IP-lookup-problem
Maintain a set of points in the plane (below the main diagonal) s.t. the following operations can be carried out efficiently:
• insertion of points• deletion of points• minXinRectagle queries (corresponds to topmost-leftmost queries)
minXinRectangle(l, r, y0)
Data structures used:
• Priority-search-trees (Lu/Sahni, IEEE TC, 2004)• Min-augmented-search-trees• Priority-search-pennats
(Lauer, Ottmann, Datta: Update efficient data structures for dynamic IP router tables, IJFCS, to appear)
12
Priority Search TreesPriority Search trees are a 1.5-dim structure for the storage of points, they support the following operations :
Insertion of a point Deletion of a point South-grounded range queries
13
83, 8
32 4 56, 9
6 71
2, 41
4, 53
5, 45 7
1, 22
8, 36
7, 14
Priority Search Tree
Priority search trees are - binary leaf search trees for the x-coordinates of the points. - min heaps for the y-coordinates of the points.
14
l
y0
r
Executable in O(log n) time.
minXinRectangle(l, r, y0)
Find topmost leftmost (orleftmost topmost) point inthe range (l, r , y0)
p
l
y0
Well defined, if intervalls are nested,otherwise not!
r
15
15,1
40
4,2
9
33,4
28
1
1,3
1
6,10
1317,35
302,4
2
17 28
17,9
17
Finding topmost leftmost points in PST
17
Balanced trees as skeletons of PSTs
q
x´
p
x
1 2
3
x
x´
1
2 3
Rotation preserves the x-order,but may destroy the y-order of points.
18
Min-augmented range treesTwo data structures in one:
Leaf-search tree on x-coordinates of points
Min-tournament tree on y-coordinates of points
8, 33, 82, 7 4, 5 5, 4 6, 9 7, 11, 2
2 53
45
17
22
16
14
8, 33, 82, 7 4, 5 5, 4 6, 9 7, 11, 2
2 53
45
17
22
16
14
1
19
MinXinRectangle(l, r, y0)
l r
Split node
Search for the boundary values l, r.Find the leftmost umbrella node with a min-field ≤ y0.
Proceed to the left son of the current node, if its min-field is ≤ y0,
and to the right son, otherwise. Return the point at the leaf.
MinXinRectangle(l, r, y0) can be found in time O(height of tree).
Maintaining
min-fields
under rotations
ua
wc
vb
xd
1 2
ye
3 ye
wc
v’d
x’b
32
ua
1
A
AB
B
ua
wc
vb
xd
1 2
ye
3 ye
wc
v’d
x’b
32
ua
1
A
AB
B
x´= xv´= min {w, y}
21
Topped loser tree• n nodes for n elements
• still a search tree
• but: no heap!
I
D P
Italien 1
Niederlande 3
Argentinien 2 Spanien 4
Deutschland 5 Frankreich 6 Polen 7 USA 8
U
A F N S
22
Topped loser tree• The tree is a semi-heap: each node dominates one of its subtrees
(the subtree where it originally came from)
• To see where a node came from,check its split key!
I
D P
Italien 1
Niederlande 3
Argentinien 2 Spanien 4
Deutschland 5 Frankreich 6 Polen 7 USA 8
U
A F N S
23
D, 5A
F, 6F
P, 7N
U, 8S
A, 2D
S, 4P
N, 3I
U, 8F, 6D, 5 I, 1 N, 3 P, 7 S, 4A, 2
I, 1U
Priority search pennant (Hinze 2001)
label key
strength priority
24
3, 82, 4 4, 5 5, 4 6, 9
7, 1
1, 2
2, 41
3, 83
6, 95
4, 52
5, 46
1, 24
7, 18
Example with points in planekey = x-coordinate
priority = y-coordinate
25
18, 918
4, 103
13, 510
16, 415
3, 41
9, 137
14, 813
20, 616
7, 84
10, 214
1, 39
15, 120
5, 25
Example: insertion of (5, 2)
26
18, 918
4, 103
13, 510
16, 415
3, 41
9, 137
14, 813
20, 616
7, 84
10, 214
1, 39
15, 120
5, 25
Example: insertion of (5, 2)
27
18, 918
4, 103
13, 510
16, 415
3, 41
9, 137
14, 813
20, 616
7, 84
10, 214
5, 29
15, 120
1, 35
Example: insertion of (5, 2)
28
18, 918
4, 103
13, 510
16, 415
3, 41
9, 137
14, 813
20, 616
1, 34
10, 214
5, 29
15, 120
7, 85
Example: insertion of (5, 2)
29
18, 918
4, 103
13, 510
16, 415
3, 41
9, 137
14, 813
20, 616
1, 34
10, 214
5, 29
15, 120
7, 85
Example: insertion of (5, 2)
30
Comparison: PST - PSP
Priority Search Tree(s. McCreight 1985)
Binary leaf search tree for x-coordinates
Min-heap for y-coordinates
Insertion, Deletion of points: O(log n)
Range query: O(log n + k) where k is the size of the answer
Min-X-in-Rectangle: O(log n)
Priority Search Pennant (s. Hinze 2001)
Binary leaf search tree for x-coordinates
Semi-heap for y-coordinates
Insertion, Deletion of points: O(log n)
Range query: Θ(k·(log n - log k + 1)) where k is the size of the answer
Min-X-in-Rectangle: ???
31
MinXinRectangle(xleft, xright, ytop) query• Let Min store the best node that has been found so far.• Examine node N:
1) If N satisfies the search condition (xleft ≤ xN < xMin AND yN ≤ ytop),set Min = N.
2) Proceed with N.left only if necessary, i.e. if
a) the left subtree contains big enough x-values: sN ≥ xleft AND
b) the left subtree may contain small enough y-values:
yN ≤ ytop OR N originates from its right subtree
3) Proceed with N.right only if necessary, i.e. if
c) the right subtree contains small enough x-values: sN < xMin AND
d) the right subtree may contain small enough y-values:
yN ≤ ytop OR N originates from its left subtree
depth-first search (in preorder) with pruning
32
MinXinRectangle-query
MinXinRectangle (xleft, xright, ytop) Min = dummy_node(xright); inspect (root, xleft, ytop); return Min
inspect(N, xleft, ytop) if (yN ytop AND xN xleft AND xN xMin) Min = N;
(1) if sN xleft AND (yN ytop OR xN > sN)) inspect(N.left, xleft, ytop);
(2) if sN < xMin AND (yN ytop OR xN sN) inspect(N.right, xleft, ytop)
A node satisfying (1) and (2) during its first visit (in the preordertraversal of nodes) is called a potential fork.A node is an actual fork, if both of ist children are inspected during the search.
33
xNsN
xRsR
sN sRxleft xMin
xR
xW
xW
N
W
R
xNsN
xLsL
sNsLxMinxleft
xL
xW
xW
N
W
L
xNsN
xRsR
sN sRxleft xMin
xR
xW
xW
N
W
R
xNsN
xLsL
sNsLxMinxleft
xL
xW
xW
N
W
L
Lemma: Let N be a fork for MinXinRectangle(xleft, xright, ytop). Then there are nopotential (or actual) forks in the right (left) subtree.
The „winning“ point of each subtree is found in a node W outside that subtree!
Theorem: There is at most one fork on the search path of a MinXinRectangle(xleft, xright, ytop) query carried out on a PSP.
MART,PSP
–
Summary
Theorem: Min-augmented Range trees and Priority-search pennants allow to represent a dynamic set S of n points in the plane with the following properties:The data structure allows updates and to answer MinXinRectangle(l, r, y0) queries in O(log n) time. The data
structures occupy O(n) space.
Note: The data structures can be based on an arbitrary scheme of balanced binary leaf search trees.
PSP and MARTs can be used (instaed of PST) to solve the dynamic version of the IP lookup problem without changing the time complexity of the lookup and update operations.
37
vu
u
v
Existence of left-overlapping range
x y
u v
(y, x)
Check whether
minXinRectangle(u, v-1, u-1)
exists
38
vu
u
v
Existence of right-overlapping range
x y
u v
(y, x)
u x ≤ v y
Query range not south-grounded!
Query: Does the range contain a point with ordinate-value u?
40
vu
u
v
Existence of right-overlapping range
Check whether
minXinRectangle(v+1, , v)
returns a point P s.t. yP u
x y
u v
u x ≤ v y
Note: Leftmost point in rangeis also topmost one!
41
Comparison of PST, MART, and PSP
PST MART PSP
Size for n points 2n-1 nodes 2n-1 nodes n nodes
Node size 3 fields 2 fields 3 fields
Single rotation O(log n) O(1) O(1)
Balancing Restricted Flexible Flexible
Maximum height 2 · (log2 n + 1) 1.44… · (log2 n + 1) 1.44… · log2 n + 1
42
Further work
• Experimental comparison of PST, MART, PSP for IP lookup
• Decouple updates, restructurings (rotations), and lookup operations
• Use a different tie-breaking rule (arbitrary priorities instead of most specific rule)
• Extension to higher dimensions
• Conflict detection:
1 dim: general ranges (not nested)
2 dim
Find output sensitiver solution for
offline problem: report all conflicts in a given set of ranges,
online problem: report all conflicts with a query range.