12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}* $classifier i<strong>ns</strong>tall $slot $node*/if (strcmp(argv[1], "i<strong>ns</strong>tall") == 0) {int slot = <strong>at</strong>oi(argv[2]);NsObject* node = (NsObject*)TclObject::lookup(argv[3]);i<strong>ns</strong>tall(slot, node);return (TCL_OK);}}return (NsObject::comm<strong>and</strong>(argc, argv));When a classifier recv()’s a packet, it h<strong>and</strong>s it to the classify() method. This is defined differently in each type ofclassifier derived from the base class. <strong>The</strong> usual form<strong>at</strong> is for the classify() method to determine <strong>and</strong> return a slot indexinto the table of slots. If the index is valid, <strong>and</strong> points to a valid TclObject, the classifier will h<strong>and</strong> the packet to th<strong>at</strong> objectusing th<strong>at</strong> object’s recv() method. If the index is not valid, the classifier will invoke the i<strong>ns</strong>tance procedure no-slot{} to<strong>at</strong>tempt to popul<strong>at</strong>e the table correctly. However, in the base class Classifier::no-slot{} prints <strong>and</strong> error message<strong>and</strong> termin<strong>at</strong>es execution.<strong>The</strong> comm<strong>and</strong>() method provides the following i<strong>ns</strong>tproc-likes to the interpreter:• clear{〈slot〉} clears the entry in a particular slot.• i<strong>ns</strong>tallNext{〈object〉} i<strong>ns</strong>talls the object in the next available slot, <strong>and</strong> retur<strong>ns</strong> the slot number.Note th<strong>at</strong> this i<strong>ns</strong>tproc-like is overloaded by an i<strong>ns</strong>tance procedure of the same name th<strong>at</strong> stores a reference to the objectstored. This then helps quick query of the objects i<strong>ns</strong>talled in the classifier from OTcl.• slot{〈index〉} retur<strong>ns</strong> the object stored in the specified slot.• i<strong>ns</strong>tall{〈index〉, 〈object〉} i<strong>ns</strong>talls the specified 〈object〉 <strong>at</strong> the slot 〈index〉.Note th<strong>at</strong> this i<strong>ns</strong>tproc-like too is overloaded by an i<strong>ns</strong>tance procedure of the same name th<strong>at</strong> stores a reference to theobject stored. This is also to quickly query of the objects i<strong>ns</strong>talled in the classifier from OTcl.5.4.1 Address ClassifiersAn address classifier is used in supporting unicast packet forwarding. It applies a bitwise shift <strong>and</strong> mask oper<strong>at</strong>ion to apacket’s destin<strong>at</strong>ion address to produce a slot number. <strong>The</strong> slot number is returned from the classify() method. <strong>The</strong>class AddressClassifier (defined in ~<strong>ns</strong>/classifier-addr.cc) ide defined as follows:class AddressClassifier : public Classifier {public:AddressClassifier() : mask_(~0), shift_(0) {bind("mask_", (int*)&mask_);bind("shift_", &shift_);}protected:int classify(Packet *co<strong>ns</strong>t p) {IPHeader *h = IPHeader::access(p->bits());return ((h->dst() >> shift_) & mask_);}<strong>ns</strong>addr_t mask_;int shift_;53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!