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 }