Currently there is no support in class Agent to transmit user data. There are two ways to transmit a serialized ADU through transport agents. First, for UDP agent (and all agents derived from there), we can derive from class UDP and add a new method send(int nbytes, char *userdata) to pass user data from Application to Agent. To pass data from an Agent to an Application is somewhat trickier: each agent has a pointer to its attached application, we dynamically cast this pointer to an AppConnector and then call AppConnector::process_data().
As an example, we illustrate how class httpsInvalAgent is implemented. It is based on UDP, and is intended to deliver web cache invalidation messages (ns/webcache/inval-agent.h). It is defined as:
class httpsInvalAgent : public Agent { public: httpsInvalAgent(); virtual void recv(Packet *, Handler *); virtual void send(int realsize, AppData* data); protected: int off_inv_; };
Here recv(Packet*, Handler*) overridden to extract user data, and a new send(int, AppData*) is provided to include user data in packetes. An application (httpsApp) is attached to an httpsInvalAgent using Agent::attachApp() (a dynamic cast is needed). In send(), the following code is used to write user data from AppData to the user data area in a packet:
Packet *pkt = allocpkt(data-\>size()); hdr_inval *ih = (hdr_inval *)pkt-\>access(off_inv_); ih-\>size() = data-\>size(); char *p = (char *)pkt-\>accessdata(); data-\>pack(p);
In recv(), the following code is used to read user data from packet and to deliver to the attached application:
hdr_inval *ih = (hdr_inval *)pkt-\>access(off_inv_); ((httpsApp*)app_)-\>process_data(ih-\>size(), (char *)pkt-\>accessdata()); Packet::free(pkt);
Tom Henderson 2014-12-17