blob: 076a3ef0ea631c864ae334e8a89666b0b5a7282a [file] [log] [blame]
jjako52c24142002-12-16 13:33:51 +00001/*
2 * OpenGGSN - Gateway GPRS Support Node
3 * Copyright (C) 2002 Mondru AB.
4 *
5 * The contents of this file may be used under the terms of the GNU
6 * General Public License Version 2, provided that the above copyright
7 * notice and this permission notice is included in all copies or
8 * substantial portions of the software.
9 *
10 * The initial developer of the original code is
11 * Jens Jakobsen <jj@openggsn.org>
12 *
13 * Contributor(s):
14 *
15 */
16
17/*
18 * Queue.c
19 * Reliable delivery of signalling messages
20 */
21
22#ifndef _QUEUE_H
23#define _QUEUE_H
24
25#define QUEUE_DEBUG 0 /* Print debug information */
26
27#define QUEUE_SIZE 256 /* Size of retransmission queue */
28#define QUEUE_HASH_SIZE 65536 /* Size of hash table (2^16) */
29
30struct qmsg_t { /* Holder for queued packets */
31 int state; /* 0=empty, 1=full */
32 uint16_t seq; /* The sequence number */
33 u_int8_t type; /* The type of packet */
34 void *aid; /* Application specific pointer */
35 union gtp_packet p; /* The packet stored */
36 int l; /* Length of the packet */
37 struct sockaddr_in peer;/* Address packet was sent to / received from */
38 struct qmsg_t *seqnext; /* Pointer to next in sequence hash list */
39 int next; /* Pointer to the next in queue. -1: Last */
40 int prev; /* Pointer to the previous in queue. -1: First */
41 int this; /* Pointer to myself */
42 time_t timeout; /* When do we retransmit this packet? */
43 int retrans; /* How many times did we retransmit this? */
44};
45
46struct queue_t {
47 struct qmsg_t qmsga[QUEUE_SIZE]; /* Array holding signalling messages */
48 void *hashseq[QUEUE_HASH_SIZE]; /* Hash array */
49 int next; /* Next location in queue to use */
50 int first; /* First packet in queue (oldest timeout) */
51 int last; /* Last packet in queue (youngest timeout) */
52};
53
54
55/* Allocates and initialises new queue structure */
56int queue_new(struct queue_t **queue);
57/* Deallocates queue structure */
58int queue_free(struct queue_t *queue);
59/* Find a new queue element. Return EOF if allready full */
60int queue_newmsg(struct queue_t *queue, struct qmsg_t **qmsg,
61 struct sockaddr_in *peer, uint16_t seq);
62/* Remove an element from the queue. */
63int queue_freemsg(struct queue_t *queue, struct qmsg_t *qmsg);
64/* Move an element to the back of the queue */
65int queue_back(struct queue_t *queue, struct qmsg_t *qmsg);
66/* Get the first element in the queue (oldest) */
67int queue_getfirst(struct queue_t *queue, struct qmsg_t **qmsg);
68/* Get the element with a particular sequence number */
69int queue_seqget(struct queue_t *queue, struct qmsg_t **qmsg,
70 struct sockaddr_in *peer, uint16_t seq);
71/* Free message based on sequence number */
72int queue_freemsg_seq(struct queue_t *queue, struct sockaddr_in *peer,
73 uint16_t seq, uint8_t *type, void **aid);
74
75
76#endif /* !_QUEUE_H */
77