next up previous contents index
Next: 29.8 SRM objects Up: 29.7.2 Adaptive Timers Previous: 29.7.2.0.2 Sending a Message

29.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.h SRMAgent::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.h ASRMAgent::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.h ASRMAgent::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 . Unlike most other packet headers, these are not automatically available in the packet. The interpreted constructor../ns-2/srm-adaptive.tcl Agent/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
        }


next up previous contents index
Next: 29.8 SRM objects Up: 29.7.2 Adaptive Timers Previous: 29.7.2.0.2 Sending a Message

2000-08-24