5.4.2 Multicast Classifiers

The multicast classifier classifies packets according to both source and destination (group) addresses. It maintains a (chained hash) table mapping source/group pairs to slot numbers. When a packet arrives containing a source/group unknown to the classifier, it invokes an Otcl procedure []Node::new-group to add an entry to its table. This OTcl procedure may use the method set-hash to add new (source, group, slot) 3-tuples to the classifier's table. The multicast classifier is defined in ~ns/classifier-mcast.cc as follows:

        static class MCastClassifierClass : public TclClass {
        public:
                MCastClassifierClass() : TclClass("Classifier/Multicast") {}
                TclObject* create(int argc, const char*const* argv) {
                        return (new MCastClassifier());
                }
        } class_mcast_classifier;

        class MCastClassifier : public Classifier {
        public:
                MCastClassifier();
                ~MCastClassifier();
        protected:
                int command(int argc, const char*const* argv);
                int classify(Packet *const p);
                int findslot();
                void set_hash(nsaddr_t src, nsaddr_t dst, int slot);
                int hash(nsaddr_t src, nsaddr_t dst) const {
                        u_int32_t s = src ^ dst;
                        s ^= s \>\> 16;
                        s ^= s \>\> 8;
                        return (s & 0xff);
                }
                struct hashnode {
                        int slot;
                        nsaddr_t src;
                        nsaddr_t dst;
                        hashnode* next;
                };
                hashnode* ht_[256];
                const hashnode* lookup(nsaddr_t src, nsaddr_t dst) const;
        };

        int MCastClassifier::classify(Packet *const pkt)
        {
                IPHeader *h = IPHeader::access(pkt-\>bits());
                nsaddr_t src = h-\>src() \>\> 8; /*XXX*/
                nsaddr_t dst = h-\>dst();
                const hashnode* p = lookup(src, dst);
                if (p == 0) {
                        /*
                         * Didn't find an entry.
                         * Call tcl exactly once to install one.
                         * If tcl doesn't come through then fail.
                         */
                        Tcl::instance().evalf("%s new-group %u %u", name(), src, dst);
                        p = lookup(src, dst);
                        if (p == 0)
                                return (-1);
                }
                return (p-\>slot);
        }
The MCastClassifier implements a chained hash table and applies a hash function on both the packet source and destination addresses. The hash function returns the slot number to index the slot_ table in the underlying object. A hash miss implies packet delivery to a previously-unknown group; OTcl is called to handle the situation. The OTcl code is expected to insert an appropriate entry into the hash table.



Tom Henderson 2014-12-17