next up previous contents
Next: Initialization Up: Example Protocol Previous: Example Protocol

Header Files

By convention, the header information required by ASP is organized into two files: asp.h and asp_internal.h. File asp.h contains only definitions required by other protocols; protocols that depend on ASP must include asp.h in order to use these definitions. In the case of ASP, asp.h defines the ASP port to be an unsigned short (16-bit value).

/* 
 * asp.h
 */

typedef u_short ASPport;

File asp_internal.h contains ASP-specific definitions that other protocols do not need to know about. For example, it defines the format of the ASP header ( ASPhdr), protocol-specific state information ( ProtlState), and session-specific state information ( SessnState).

/* 
 * asp_internal.h 
 */
#include "xkernel.h"
#include "ip.h"
#include "asp.h"

/* ASP message header definition */

typedef struct header {
    ASPport sport;  /* source port      */
    ASPport dport;  /* destination port */
    u_short ulen;   /* ASP length       */
} ASPhdr;

#define HLEN (sizeof(ASPhdr))

/* protocol and session states */

typedef struct pstate {
    Map activemap;
    Map passivemap;
} ProtlState;

typedef struct sstate {
    ASPhdr hdr;
} SessnState;

/* active and passive maps */

typedef struct {
    Sessn   lls;
    ASPport localport;
    ASPport remoteport;
} ActiveId;

typedef ASPport PassiveId;

#define ACTIVE_MAP_SIZE  101
#define PASSIVE_MAP_SIZE 23

/* UPI function declarations */

void            asp_init(Protl);
static Sessn    aspOpen(Protl, Protl, Protl, Part *);
static XkReturn aspOpenEnable(Protl, Protl, Protl, Part *);
static XkReturn aspDemux(Protl, Sessn, Msg *);
static XkHandle aspPush(Sessn, Msg *);
static XkReturn aspPop(Sessn, Sessn, Msg *, void *);
static Sessn    aspCreateSessn(Protl, Protl, Protl, ActiveId *);
static XkReturn aspClose(Sessn);
static int      aspControlProtl(Protl, int, char *, int) ;
static int      aspControlSessn(Sessn, int, char *, int) ;
static Part     *aspGetParticipants(Sessn);

/* internal function declarations */

static void     getproc_protl(Protl);
static void     getproc_sessn(Sessn);
static long     aspHdrLoad(ASPhdr *, char *, long);
static void     aspHdrStore(ASPhdr *, char *, long);

/* trace variable used in conjunction with xTrace stmts */
int traceaspp;

One of the main definitions contained in asp_internal.h concerns the demultiplexing function. In particular, the state associated with the ASP protocol object includes two maps: activemap and passivemap. The former map is used by ASP's demux routine to map incoming messages to an existing session. It uses ActiveId as the demultiplexing key. Although conceptually the active map key is given by the 4-tuple described above, in practice, we take advantage of the fact that the underlying IP session already corresponds to a local/remote host pair, and we use this session object in lieu of these two IP addresses.

The second map--- passivemap---is used to record high-level protocols that have done a passive open on ASP. In this case, the corresponding key that is used to search this map, called the PassiveId, is given by the ASP port on which the local protocol has done an xOpenEnable.

The session state contains a header template which is copied to the front of outgoing messages. The ASP message header consists of local and remote port numbers, and a field indicating the length of the data message plus ASP header.



Larry Peterson
Wed Feb 21 13:58:06 MST 1996