IP Lookup and Range Searching Haim Kaplan Tel Aviv University - - PowerPoint PPT Presentation

ip lookup and range searching
SMART_READER_LITE
LIVE PREVIEW

IP Lookup and Range Searching Haim Kaplan Tel Aviv University - - PowerPoint PPT Presentation

IP Lookup and Range Searching Haim Kaplan Tel Aviv University Joint with: Lars Arge, Pankaj Agarwal, Moshik Hershcovitch, Eyal Molad, Bob Tarjan, Ke Yi Longest Prefix Forwarding Packet has a destination address Router identifies the


slide-1
SLIDE 1

IP Lookup and Range Searching

Haim Kaplan Tel Aviv University

Joint with: Lars Arge, Pankaj Agarwal, Moshik Hershcovitch, Eyal Molad, Bob Tarjan, Ke Yi

slide-2
SLIDE 2

Longest Prefix Forwarding

– Packet has a destination address – Router identifies the longest prefix of the destination address to find the next hop

4.0.0.0/8 4.83.128.0/17 12.0.0.0/8 12.34.158.0/24 126.255.103.0/24 12.34.158.5 destination forwarding table

  • utgoing link
slide-3
SLIDE 3

The table is dynamic

4.0.0.0/8 4.83.128.0/17 12.0.0.0/8 12.34.158.0/24 126.255.103.0/24 12.34.158.5 destination forwarding table

  • utgoing link

132.66.235.0/24 4.0.0.0/8

Routing protocols insert and delete prefixes

slide-4
SLIDE 4

Given a set of strings S = {p1,...,pn} (prefixes) build a data structure such that Given a string q we can find (efficiently) the longest prefix of q in S

The longest prefix problem

Updates – insert or delete a prefix

slide-5
SLIDE 5

We can model this as follows

0.0.0.0 255.255.255.255

IP address

Each segment corresponds to a prefix

slide-6
SLIDE 6

Segments are nested

0.0.0.0 255.255.255.255

IP address

slide-7
SLIDE 7

A packet is a point

0.0.0.0 255.255.255.255

IP address

Want the shortest segment that contains the packet

slide-8
SLIDE 8

Want to be able to insert/delete segments

0.0.0.0 255.255.255.255

IP address

slide-9
SLIDE 9

Want to be able to insert/delete segments

0.0.0.0 255.255.255.255

IP address

slide-10
SLIDE 10

Want to be able to insert/delete segments

0.0.0.0 255.255.255.255

IP address

slide-11
SLIDE 11

Discussion

  • In the segment-stabbing problem we assume

that we can compare endpoints in O(1) time

  • This may be reasonable if strings are short
  • It is less reasonable if we try to solve the

longest prefix problem for arbitrary strings

slide-12
SLIDE 12

Results (1) (SWAT 2008, HK)

  • A very simple data structure for shortest

segment in a nested family O(log(n)) time, and O(logB(n)) I/Os per op

  • A data structure for longest prefix in a

collection of arbitrary strings O(log(n) + |q|) time and O(logB(n) + |q|/B) I/Os per op both take linear space

slide-13
SLIDE 13

Generalizations (1)

Given a set S of nested segments, each with priority assigned to it, build a structure that allows efficient queries of the from:

  • Given a point x find segment with minimum priority

containing it.

5 7 1 3 9

  • Updates – insert or delete a segment

x

slide-14
SLIDE 14

Generalizations (2)

5 1 7 3 9

  • Updates – insert or delete a segment

Given a set S of nested segments, each with priority assigned to it, build a structure that allows efficient queries of the from:

  • Given a point x find segment with minimum priority

containing it.

slide-15
SLIDE 15

Motivation for the general problem

  • Firewalls
  • Rules are intervals/prefixes
  • In case several rules apply to a packet

then decide by priority

slide-16
SLIDE 16

Results (2) (STOC 2003,KMT)

  • A simple data structure for nested

segments with priorities O(log(n)) time per op, O(n) space (uses dynamic trees)

  • A data structure for general segments

O(log(n)) time per query/insert but delete takes O(log(n)loglog(n)) time, O(nloglog(n)) space

slide-17
SLIDE 17
  • A data structure for general segments

O(log(n)) time per query/insert but delete takes O(log(n)loglog(n)) time, O(nloglog(n)) space

  • O(logB(n)) I/Os per operation

Results (3) (SODA 2005, AAY)

slide-18
SLIDE 18

Results (4) extension to 2D (M’03)

  • Query  point in R2

– (Sender IP, receiver IP)

  • interval  rectangle with priority

5 9 7

We can keep the query time logarithmic for nested rectangles

slide-19
SLIDE 19

Previous work: Networking community

  • Specific for IP addresses, assume RAM,

bounds often depend on W: the length of the address (Sahni & Kim : O(n) space O(log n) time per op, complicated, still use RAM)

  • trie based solutions
  • hash based solutions
slide-20
SLIDE 20

Previous work: Theory community

  • Feldman & Muthukrishnan (2000), Thorup (2003)

use RAM to get query time below O(log(n))

  • Thorup: O(l) query time O(n1/l) update time, O(n)

space for general priority stabbing

slide-21
SLIDE 21
  • An update time of O(log2(n)) using

O(nlog(n)) space is easy !

Lets get started...

slide-22
SLIDE 22

Classical solution: Segment tree

Construct a balanced binary tree over the basic intervals

4 6 2 9 1 A B C D E F G I J K H L M 7 E G L I K H M J F B A D C

slide-23
SLIDE 23

Place segment s in every node v such that s “covers v” but does not “cover p(v)”

4 6 2 9 1 A B C D E F G I J K H L M 7 E G L K H M J F B A D C I

slide-24
SLIDE 24

Place segment s in every node v such that s “covers v” but does not “cover p(v)”

4 6 2 9 1 A B C D E F G I J K H L M 7 E G L K H M J F B A D C I

slide-25
SLIDE 25

4 6 2 9 1 A B C D E F G I J K H L M 7 E G L K H M J F B A D

Traverse the path to the leaf containg x – O(log(n)) nodes.

C I x

Query

slide-26
SLIDE 26

4 6 2 9 1 A B C D E F G I J K H L M 7 x

In each node choose the min segment. Find the minimum among those. O(log(n)) time

E G L K H M J F B A D C I

Query

slide-27
SLIDE 27

Segment tree - Insert

4 6 2 9 1 A B C D E F G I J K H L M 7 10

Insert two new leaves Add a segment in O(logn) nodes

E G L K H M J F B A D C I

slide-28
SLIDE 28

4 6 2 9 1 A B C D E F G I J K H L M 7 10 E’ E’’

Insert two new leaves Add a segment in O(logn) nodes

G L K H M J F B A D C E’’ E’ I

slide-29
SLIDE 29

4 6 2 9 1 A B C D E F G I J K H L M 7 10 E’ E’’

Insert two new leaves Add a segment in O(logn) nodes

G L K M J F B A D C E’’ E’ H’ H’’ I H’ H’’

slide-30
SLIDE 30

4 6 2 9 1 A B C D E F G I J K H L M 7 10 E’ E’’ H’ H’’

Insert two new leaves Add a segment in O(logn) nodes delete in analogous need a secondary heap at each node  O(log2n) per update

G L K M J F B A D C E’’ E’ H’ H’’ I

slide-31
SLIDE 31

? ?

We have to compute the segments which are mapped to the nodes around the point of rotation

To rebalance we have to make rotations

 y x B C A x A y B C

? ?

To amortize away this work use weight balance trees (BB[α ])

slide-32
SLIDE 32

Summary: segment tree

O(log2(n)) Delete O(log2(n)) Insert O(log(n)) Query

slide-33
SLIDE 33

Results (1) (SWAT 2008, HK)

  • A very simple data structure for shortest

segment (in a nested family) O(log(n)) time, and O(logB(n)) I/Os per op

  • A data structure for longest prefix in a

collection of arbitrary strings O(log(n) + |q|) time and O(logB(n) + |q|/B) I/Os per op both take linear space

slide-34
SLIDE 34

Shortest nested segment

A B C D F j E G I K L H M G L K H M J F B A D C E I

slide-35
SLIDE 35

Shortest nested segment

A B C D F j E G I K L

Use a segment tree as before

H M G L K H M J F B A D C E I

slide-36
SLIDE 36

Main observation

A B C D F j E G I K L H M

We can maintain only the shortest among all segments mapped to a node

G L K H M J F B A D C E I

slide-37
SLIDE 37

A B C D F j E G I K L H M

Observe (1) – any segment appears somewhere Observe (2) – Only

  • ne among a pair of

siblings has a segment

G L K H M J F B A D C E I

slide-38
SLIDE 38

A B C D F j E G I K L H M

As before in O(log(n)) time

x G L K H M J F B A D C E I

Query

slide-39
SLIDE 39

Insert

A B C D F j E G I K L H M G L K H M J F B A D C E I

slide-40
SLIDE 40

A B C D F j E G I K L H M C’ C’’ G L K H M J F B A D E C’ C’’ I

slide-41
SLIDE 41

A B C D F j E G I K L H M C’ C’’ I’ I’’ G L K H M J F B A D E C’ C’’ I’ I’’

slide-42
SLIDE 42

A B C D F j E G I K L H M C’ C’’ I’ I’’ G L K H M J F B A D E C’ C’’ I’ I’’

slide-43
SLIDE 43

A B C D F j E G I K L H M C’ C’’ I’ I’’ G L K H M J F B A D E C’ C’’ I’ I’’

slide-44
SLIDE 44

Rotations ?

 y x B C A x A y B C

? ? ? ?

slide-45
SLIDE 45

Shortest Nested Segments - Rotations

 y x B C A x A y B C

? ? ? ?

slide-46
SLIDE 46

 y x B C A x A y B C

?

? ? ?

Shortest Nested Segments - Rotations

slide-47
SLIDE 47

 y x B C A x A y B C  y x B C A x A y B C  y x B C A x A y B C  y x B C A x A y B C y x B C A Impossible

slide-48
SLIDE 48

Delete

G L K H M J F B A D E C’ C’’ I’ I’’ A B D F j E G K L H M C’ C’’ I’ I’’

slide-49
SLIDE 49

Delete

G L K H M J F B A D E C’ C’’ I’ I’’ A B D F j E G K L H M C’ C’’ I’ I’’

slide-50
SLIDE 50

A B D F j E G K L H M C’ C’’ I’ I’’

Delete

G L K H M J F B A D E C’ C’’ I’ I’’

slide-51
SLIDE 51

A B D F j E G K L H M C’ C’’ I’ I’’

Delete

G L K H M J F B A D E C’ C’’ I’ I’’

slide-52
SLIDE 52

Results (1) (SWAT 2008, HK)

  • A very simple data structure for shortest

segment (in a nested family) O(log(n)) time, and O(logB(n)) I/Os per op

  • A data structure for longest prefix in a

collection of arbitrary strings O(log(n) + |q|) time and O(logB(n) + |q|/B) I/Os per op both take linear space

slide-53
SLIDE 53

M N O A B C E G L F H I M N I O D J K L J K I G H F E D B A

Use the B-tree as a segment tree

C

slide-54
SLIDE 54

Keep only the shortest at each node

A B C E G L F H I M N I O D J K M N O L J K I G H F E D B A C

slide-55
SLIDE 55

Same as before. O(logB(n)) I/Os. A B C E G L F H I M N I O D J K

Query

x M N O L J K I G H F E D B A C

slide-56
SLIDE 56

A B C E G L F H I M N I O D J K

Insert

M N O L J K I G H F E D B A C

slide-57
SLIDE 57

K A B C E G L F H I M N I O D J K C’ C’’ K’K’’ K’’ M N O L J I G H F E D C’ B A C’’

slide-58
SLIDE 58

K A B C E G L F H I M N I O D J K C’ C’’ K’K’’ K’’ M N O L J I G H F E D C’ B A C’’

slide-59
SLIDE 59

A

Split/merge/borrow analogous to rotations

B C D E 

V

A B C

V1

D E

V2

? ? ? ? ? ? ?

slide-60
SLIDE 60

A

Split/merge/borrow analogous to rotations

B C D E 

V

A B C

V1

D E

V2

slide-61
SLIDE 61

Results (1) (SWAT 2008, HK)

  • A very simple data structure for shortest

segment (in a nested family) O(log(n)) time, and O(logB(n)) I/Os per op

  • A data structure for longest prefix in a

collection of arbitrary strings O(log(n) + |q|) time and O(logB(n) + |q|/B) I/Os per op both take linear space

slide-62
SLIDE 62

Combine

  • Combine with the string B-tree of

Ferragina and Grossi (JACM 99)

slide-63
SLIDE 63

a b a a c a b c c c R

A Patricia trie of the keys

3 a b a a c a b c c c L a b a a c a b R a b b a c a b b a L a b b a c a b b a R a b R 5 8 11 a a c a c R R L 10 R L b R A4R A8R A9L A9R A7R A10L A10R A2R A1 - a A6 - abaaabbccc A2 - ab A3 - aba A4 - abaaabb A5 - abaaabbaa A8 - abaacabaaa A10 - abbacabba A9 - abaacabccc A7 - abaacab

R R

slide-64
SLIDE 64

Results (2) (STOC 2003,KMT)

  • A simple data structure for nested

segments with priorities O(log(n)) time per op, O(n) space (uses dynamic trees)

  • A data structure for general segments

O(log(n)) time per query/insert but delete takes O(log(n)loglog(n)) time, O(nloglog(n)) space

slide-65
SLIDE 65

1 5 7 9 8

7 2 1 2 9 5 8

2 2

Containment tree: The parent of a segment v is the smallest segment containing v

slide-66
SLIDE 66

Nested Intervals

1 5 7 9 8

7 2 1 2 9 5 8

2

Query: Starting node s = smallest interval containing the query point Relevant priorities are on the path from s to the root.

2

Problem: path may be long…

x

slide-67
SLIDE 67

1 5 7 9 2 8

7 2 1 2 9 5 8

2

Want to use a dynamic tree to represent the containment tree.

Dynamic trees know how to do that

slide-68
SLIDE 68

Dynamic trees

find min along path link cut

O(log n) time per

  • peration
slide-69
SLIDE 69

1 5 7 9 2 8

7 2 1 2 9 5 8

2

Use a dynamic tree to represent the containment tree Problem: Updates => Many cuts & links

slide-70
SLIDE 70

Insert

slide-71
SLIDE 71

Binarization

1 5 7 9 2 2 4

7 2 1 2 9 5 4 Leftmost child of v => Left child of v Any other child of v => right child of its left sibling

9 7 5

∞ ∞ ∞ Adjust costs: Left edge => priority of parent Right edge => ∞ Node v => node v

slide-72
SLIDE 72

Insert (Cont.)

Constant number of links and cuts

slide-73
SLIDE 73

Summary

  • Containment tree C

– Query = min cost on path from starting point to root

  • Represent C by binarized version B
  • Represent B by dynamic tree D
  • How do you find the point to start the

query ?

  • How do you find the edges to cut ?
slide-74
SLIDE 74

How do you start the query ?

1 5 7 9 2 2 4 7 9

Use a balanced search tree on the endpoints

1

Min(Mincost(



),
pri(



))

slide-75
SLIDE 75

query (cont)

1 5 7 9 2 2 4 7 9 1

Mincost(



)

slide-76
SLIDE 76

Results (2) (STOC 2003,KMT)

  • A simple data structure for nested

segments with priorities O(log(n)) time per op, O(n) space (uses dynamic trees)

  • A data structure for general segments

O(log(n)) time per query/insert but delete takes O(log(n)loglog(n)) time, O(nloglog(n)) space

slide-77
SLIDE 77
  • A data structure for general segments

O(log(n)) time per query/insert but delete takes O(log(n)loglog(n)) time, O(nloglog(n)) space

  • O(logB(n)) I/Os per operation

Results (3) (SODA 2005, AAY)

slide-78
SLIDE 78

Further research

  • Cache oblivious solution for strings

(static solution by Brodal & Fagerberg SODA’06)

  • Simplify the solutions
  • Implement the shortest segment data

structure

  • Better solutions for higher dimensions