Grafalgo
Library of useful data structures and algorithms
|
00001 // Header file for longest matching prefix data structure. 00002 // This version just uses a list. Replace with something 00003 // efficient when time permits. 00004 00005 #ifndef LONGESTMATCHPREFIX_H 00006 #define LONGESTMATCHPREFIX_H 00007 00008 #include "stdinc.h" 00009 #include "misc.h" 00010 00011 class LongestMatchPrefix { 00012 public: 00013 LongestMatchPrefix(int=100); 00014 ~LongestMatchPrefix(); 00015 int lookup(ipa_t); // return the next hop for given addr 00016 bool insert(ipa_t,int,int); // insert (prefix,next hop) pair 00017 void remove(ipa_t,int); // remove a pair 00018 void print(); // print the set of pairs 00019 private: 00020 int N; // max number of pairs 00021 int n; // current number of pairs 00022 00023 struct nodeItem { 00024 ipa_t pref; // ip address 00025 short len; // length of prefix (in bits) 00026 short nexthop; // associated nexthop value 00027 } *vec; // vector of pairs 00028 }; 00029 00030 #endif