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.

5.4.5 Replic<strong>at</strong>or<strong>The</strong> replic<strong>at</strong>or is different from the other classifiers we have described earlier, in th<strong>at</strong> it does not use the classify function.R<strong>at</strong>her, it simply uses the classifier as a table of n slots; it overloads the recv() method to produce n copies of a packet, th<strong>at</strong>are delivered to all n objects referenced in the table.To support multicast packet forwarding, a classifier receiving a multicast packet from source S destined for group G computesa hash function h(S, G) giving a “slot number” in the classifier’s object table. In multicast delivery, the packet must be copiedonce for each link leading to nodes subscribed to G minus one. Production of additional copies of the packet is performed bya Replic<strong>at</strong>or class, defined in replic<strong>at</strong>or.cc:/** A replic<strong>at</strong>or is not really a packet classifier but* we simply find convenience in leveraging its slot table.* (this object used to implement fan-out on a multicast* router as well as broadcast LANs)*/class Replic<strong>at</strong>or : public Classifier {public:Replic<strong>at</strong>or();void recv(Packet*, H<strong>and</strong>ler* h = 0);virtual int classify(Packet* co<strong>ns</strong>t) {};protected:int ignore_;};void Replic<strong>at</strong>or::recv(Packet* p, H<strong>and</strong>ler*){IPHeader *iph = IPHeader::access(p->bits());if (maxslot_ < 0) {if (!ignore_)Tcl::i<strong>ns</strong>tance().evalf("%s drop %u %u", name(),iph->src(), iph->dst());Packet::free(p);return;}for (int i = 0; i < maxslot_; ++i) {NsObject* o = slot_[i];if (o != 0)o->recv(p->copy());}/* we know th<strong>at</strong> maxslot is non-null */slot_[maxslot_]->recv(p);}As we can see from the code, this class does not really classify packets. R<strong>at</strong>her, it replic<strong>at</strong>es a packet, one for each entry inits table, <strong>and</strong> delivers the copies to each of the nodes listed in the table. <strong>The</strong> last entry in the table gets the “original” packet.Since the classify() method is pure virtual in the base class, the replic<strong>at</strong>or defines an empty classify() method.57

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

Saved successfully!

Ooh no, something went wrong!