Deciding on the inheritance structure is a matter of personal choice, but is likely to be related to the layer at which the agent will operate and its assumptions on lower layer functionality. The simplest type of Agent, connectionless datagram-oriented transport, is the Agent/UDP base class. Traffic generators can easily be connected to UDP Agents. For protocols wishing to use a connection-oriented stream transport (like TCP), the various TCP Agents could be used. Finally, if a new transport or ``sub-transport'' protocol is to be developed, using Agent as the base class would likely be the best choice. In our example, we'll use Agent as the base class, given that we are constructing an agent logically belonging to the IP layer (or just above it).
We may use the following class definitions:
class ECHO_Timer; class ECHO_Agent : public Agent { public: ECHO_Agent(); int command(int argc, const char*const* argv); protected: void timeout(int); void sendit(); double interval_; ECHO_Timer echo_timer_; }; class ECHO_Timer : public TimerHandler { public: ECHO_Timer(ECHO_Agent *a) : TimerHandler() { a_ = a; } protected: virtual void expire(Event *e); ECHO_Agent *a_; };