The constructor for the DV agent../ns-2/route-proto.tclAgent/rtProto/DV::init initializes a number of instance variables; each agent stores an array, indexed by the destination node handle, of the preference and metric, the interface (or link) to the next hop, and the remote peer incident on the interface, for the best route to each destination computed by the agent. The agent creates these instance variables, and then schedules sending its first update within the first 0.5 seconds of simulation start.
Each agent stores the list of its peers indexed by the handle of the peer node. Each peer is a separate peer structure that holds the address of the peer agent, the metric and preference of the route to each destination advertised by that peer. We discuss the rtPeer structure later when discuss the route architecture. The peer structures are initialized by the procedure []add-peer../ns-2/route-proto.tclAgent/rtProto/DV::add-peer invoked by []init-all.
The routine []send-periodic-update../ns-2/route-proto.tclAgent/rtProto/DV::send-periodic-update invokes []send-updates to send the actual updates. It then reschedules sending the next periodic update after advertInterval jittered slightly to avoid possible synchronization effects.
[]send-updates../ns-2/route-proto.tclAgent/rtProto/DV::send-updates will send updates to a select set of peers. If any of the routes at that node have changed, or for periodic updates, the procedure will send updates to all peers. Otherwise, if some incident links have just recovered, the procedure will send updates to the adjacent peers on those incident links only.
[]send-updates uses the procedure []send-to-peer../ns-2/route-proto.tclAgent/rtProto/DV::send-to-peer to send the actual updates. This procedure packages the update, taking the split-horizon and poison reverse mechanisms into account. It invokes the instproc-like, []send-update (Note the singular case)../ns-2/rtProto.ccrtProtoDV::command to send the actual update. The actual route update is stored in the class variable msg_ indexed by a non-decreasing integer as index. The instproc-like only sends the index to msg_ to the remote peer. This eliminates the need to convert from OTcl strings to alternate formats and back.
When a peer receives a route update../ns-2/route-proto.tclAgent/rtProto/DV::recv-update it first checks to determine if the update from differs from the previous ones. The agent will compute new routes if the update contains new information.
Tom Henderson 2011-11-05