38.7.2.0.3 Advertising the Distance

Each agent must add additional information to each request/repair that it sends out. The base SRMAgent../ns-2/srm.cc invokes the virtual method []addExtendedHeaders../ns-2/srm.hSRMAgent::addExtendedHeaders for each SRM packet that it sends out. The method is invoked after adding the SRM packet headers, and before the packet is transmitted. The adaptive SRM agent overloads []addExtendedHeaders../ns-2/srm.hASRMAgent::addExtendedHeaders to specify its distances in the additional headers. When sending a request, that agent unequivocally knows the identity of the sender. As an example, the definition of []addExtendedHeaders for the adaptive SRM agent is:
        void addExtendedHeaders(Packet* p) {
                SRMinfo* sp;
                hdr_srm*  sh = (hdr_srm*) p-\>access(off_srm_);
                hdr_asrm* seh = (hdr_asrm*) p-\>access(off_asrm_);
                switch (sh-\>type()) {
                case SRM_RQST:
                        sp = get_state(sh-\>sender());
                        seh-\>distance() = sp-\>distance_;
                        break;
                \ldots
                }
        }

Similarly, the method []parseExtendedHeaders../ns-2/srm.hASRMAgent::parseExtendedHeaders is invoked every time an SRM packet is received. It sets the agent member variable pdistance_ to the distance advertised by the peer that sent the message. The member variable is bound to an instance variable of the same name, so that the peer distance can be accessed by the appropriate instance procedures. The corresponding []parseExtendedHeaders method for the Adaptive SRM agent is simply:

        void parseExtendedHeaders(Packet* p) {
                hdr_asrm* seh = (hdr_asrm*) p-\>access(off_asrm_);
                pdistance_ = seh-\>distance();
        }

Finally, the adaptive SRM agent's extended headers are defined as hdr_asrm../ns-2/srm.h. The header declaration is identical to declaring other packet headers in ns. Unlike most other packet headers, these are not automatically available in the packet. The interpreted constructor../ns-2/srm-adaptive.tclAgent/SRM/Adaptive::init for the first adaptive agent will add the header to the packet format. For example, the start of the constructor for the Agent/SRM/Adaptive agent is:

        Agent/SRM/Adaptive set done_ 0
        Agent/SRM/Adaptive instproc init args {
            if ![$class set done_] {
                set pm [[Simulator instance] set packetManager_]
                TclObject set off_asrm_ [$pm allochdr aSRM]
                $class set done_ 1
            }

            eval $self next $args
            \ldots
        }

Tom Henderson 2014-12-17