Skip to content
Extraits de code Groupes Projets
Valider 02aa55ef rédigé par thomer's avatar thomer
Parcourir les fichiers

0

parent 25fccfae
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -50,6 +50,7 @@ LookupIPRoute2::push(int, Packet *p)
add_route_handler("2.2.0.0 255.255.0.0 2.2.2.2", this, (void *)0, (ErrorHandler *)0);
add_route_handler("2.244.0.0 255.255.0.0 3.3.3.3", this, (void *)0, (ErrorHandler *)0);
add_route_handler("2.0.0.0 255.255.0.0 4.4.4.4", this, (void *)0, (ErrorHandler *)0);
del_route_handler("2.1.3.0 255.255.0.0", this, (void *)0, (ErrorHandler *)0);
click_chatter("Lookup for %x", ntohl(a.saddr()));
*/
......
......@@ -18,7 +18,7 @@
IPTable2::IPTable2()
: entries(0), dirty(true)
: entries(0)
{
radix = new Radix;
}
......@@ -49,7 +49,7 @@ IPTable2::add(unsigned dst, unsigned mask, unsigned gw)
}
// Deletes an entry from the stupid routing table. Radix is now dirty.
// Deletes an entry from the stupid routing table.
void
IPTable2::del(unsigned dst, unsigned mask)
{
......@@ -57,7 +57,7 @@ IPTable2::del(unsigned dst, unsigned mask)
if(_v[i]._valid && (_v[i]._dst == dst) && (_v[i]._mask == mask)) {
_v[i]._valid = 0;
entries--;
dirty = true;
radix->del(dst & mask);
return;
}
}
......@@ -85,14 +85,8 @@ IPTable2::get(int i, unsigned &dst, unsigned &mask, unsigned &gw)
bool
IPTable2::lookup(unsigned dst, unsigned &gw, int &index)
{
if(!entries)
return false;
// Use timer.
if(dirty)
build();
index = radix->lookup(dst);
if(!entries || !radix->lookup(dst, index))
goto nomatch;
// Consider this a match if dst is part of range described by routing table.
if((dst & _v[index]._mask) == (_v[index]._dst & _v[index]._mask)) {
......@@ -100,11 +94,13 @@ IPTable2::lookup(unsigned dst, unsigned &gw, int &index)
return true;
}
nomatch:
gw = index = 0;
return false;
}
#if 0
void
IPTable2::build()
{
......@@ -122,8 +118,8 @@ IPTable2::build()
}
entries = _v.size();
dirty = false;
}
#endif
// generate Vector template instance
#include "vector.cc"
......
......@@ -36,9 +36,6 @@ private:
int entries;
Radix *radix;
// is radix up-to-date?
bool dirty;
};
#endif
......@@ -22,6 +22,7 @@ Radix::Radix()
root = new struct node;
root->info = root->key = 0;
root->bit_idx = KEYSIZE-1;
root->valid = false;
root->left = root->right = root;
}
......@@ -63,6 +64,7 @@ Radix::insert(KEYTYPE v, INFOTYPE info)
t->key = v;
t->bit_idx = i;
t->info = info;
t->valid = true;
if(bits(v, t->bit_idx, 1) == 0) {
t->left = t;
......@@ -80,10 +82,30 @@ Radix::insert(KEYTYPE v, INFOTYPE info)
// Returns info based on key
INFOTYPE
Radix::lookup(KEYTYPE v)
bool
Radix::lookup(KEYTYPE v, INFOTYPE &info)
{
return(node_lookup(v)->info);
struct node *t;
t = node_lookup(v);
if(t->valid) {
info = t->info;
return(true);
} else
return(false);
}
void
Radix::del(KEYTYPE v)
{
struct node *t;
t = node_lookup(v);
// Only delete if this is an exact match
if(t->key == v)
t->valid = false;
}
......
......@@ -16,7 +16,8 @@ public:
~Radix();
void insert(KEYTYPE v, INFOTYPE info);
INFOTYPE lookup(KEYTYPE v);
void del(KEYTYPE v);
bool lookup(KEYTYPE v, INFOTYPE &info);
private:
struct node {
......@@ -24,6 +25,7 @@ private:
int bit_idx;
struct node *left, *right;
bool valid;
INFOTYPE info;
};
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter