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 2011-11-05