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.

<strong>The</strong> classify() method is pure virtual, indic<strong>at</strong>ing the class Classifier is to be used only as a base class. <strong>The</strong> alloc()method dynamically alloc<strong>at</strong>es enough space in the table to hold the specified number of slots. <strong>The</strong> i<strong>ns</strong>tall() <strong>and</strong> clear()methods add or remove objects from the table. <strong>The</strong> recv() method <strong>and</strong> the OTcl interface are implemented as follows in~<strong>ns</strong>/classifier.cc:/** objects only ever see "packet" events, which come either* from an incoming link or a local agent (i.e., packet source).*/void Classifier::recv(Packet* p, H<strong>and</strong>ler*){NsObject* node;int cl = classify(p);if (cl < 0 || cl >= <strong>ns</strong>lot_ || (node = slot_[cl]) == 0) {Tcl::i<strong>ns</strong>tance().evalf("%s no-slot %d", name(), cl);Packet::free(p);return;}node->recv(p);}int Classifier::comm<strong>and</strong>(int argc, co<strong>ns</strong>t char*co<strong>ns</strong>t* argv){Tcl& tcl = Tcl::i<strong>ns</strong>tance();if (argc == 3) {/** $classifier clear $slot*/if (strcmp(argv[1], "clear") == 0) {int slot = <strong>at</strong>oi(argv[2]);clear(slot);return (TCL_OK);}/** $classifier i<strong>ns</strong>tallNext $node*/if (strcmp(argv[1], "i<strong>ns</strong>tallNext") == 0) {int slot = maxslot_ + 1;NsObject* node = (NsObject*)TclObject::lookup(argv[2]);i<strong>ns</strong>tall(slot, node);tcl.resultf("%u", slot);return TCL_OK;}if (strcmp(argv[1], "slot") == 0) {int slot = <strong>at</strong>oi(argv[2]);if ((slot >= 0) || (slot < <strong>ns</strong>lot_)) {tcl.resultf("%s", slot_[slot]->name());return TCL_OK;}tcl.resultf("Classifier: no object <strong>at</strong> slot %d", slot);return (TCL_ERROR);}} else if (argc == 4) {/*52

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

Saved successfully!

Ooh no, something went wrong!