Monday, March 2, 2009

Classifiers

A classifier is a multi-target packet forwarder. It classifies incoming packets into categories, and forwards packets in the same categories to the same object.

Main characteristic:
  • A classifier installs the target in its array slot_
  • A classifier is an NsObject. Therefore, it receives a packet using its function recv(p,h).
  • When receiving a packet p, it looks for a matching slot (i.e., node = find(p)) and forward th packet to the object installed in that slot (i.e., node->recv(p,h))
  • Function finds looks for a slot (i.e., cl) with matching criterion, using function classify(p).
  • Function classify(p) returns a slot with matching criterion. It is defined in the derived class.
void Classifier::recv(Packet* p, Handler* h)
{
NsObject* node = find(p);
if (node == NULL) {
Packet::free(p);
return;
}
node->recv(p,h);
}

NsObject* Classifier::find(Packet* p)
{
NsObject* node = NULL;
int cl = classify(p);
if (cl <>= nslot_ || (node = slot_[cl]) == 0) {
/*There is no potential target in the slot;*/
}
return (node);
}
Example: Suppose we would like to forward packets with port "i" to the same object.
1. Install NsObject in slot_[i] of the classifier
2. Make function classify(p) return the port number of "p"

For more information about Classifiers, see Chapter 6 in the following book from Springer:

T. Issaraiyakul and E. Hossain, "Introduction to Network Simulator NS2", Springer 2008.
http://www.springer.com/engineering/signals/book/978-0-387-71759-3

You may also find the following website useful:
http://www.ece.ubc.ca/~teerawat/NS2.htm

No comments: