blob: 1e95676bb49eb3baa69e8f9a0c1379381e9c9f27 [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
jjako193e8b12003-11-10 12:31:41 +000027#define QUEUE_SIZE 1024 /* Size of retransmission queue */
jjako52c24142002-12-16 13:33:51 +000028#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 */
jjakob7b93fc2004-01-09 11:56:48 +000033 uint8_t type; /* The type of packet */
jjako08d331d2003-10-13 20:33:30 +000034 void *cbp; /* Application specific pointer */
jjako52c24142002-12-16 13:33:51 +000035 union gtp_packet p; /* The packet stored */
36 int l; /* Length of the packet */
jjako08d331d2003-10-13 20:33:30 +000037 int fd; /* Socket packet was sent to / received from */
jjako52c24142002-12-16 13:33:51 +000038 struct sockaddr_in peer;/* Address packet was sent to / received from */
39 struct qmsg_t *seqnext; /* Pointer to next in sequence hash list */
40 int next; /* Pointer to the next in queue. -1: Last */
41 int prev; /* Pointer to the previous in queue. -1: First */
42 int this; /* Pointer to myself */
43 time_t timeout; /* When do we retransmit this packet? */
44 int retrans; /* How many times did we retransmit this? */
45};
46
47struct queue_t {
48 struct qmsg_t qmsga[QUEUE_SIZE]; /* Array holding signalling messages */
49 void *hashseq[QUEUE_HASH_SIZE]; /* Hash array */
50 int next; /* Next location in queue to use */
51 int first; /* First packet in queue (oldest timeout) */
52 int last; /* Last packet in queue (youngest timeout) */
53};
54
55
56/* Allocates and initialises new queue structure */
57int queue_new(struct queue_t **queue);
58/* Deallocates queue structure */
59int queue_free(struct queue_t *queue);
60/* Find a new queue element. Return EOF if allready full */
61int queue_newmsg(struct queue_t *queue, struct qmsg_t **qmsg,
62 struct sockaddr_in *peer, uint16_t seq);
63/* Remove an element from the queue. */
64int queue_freemsg(struct queue_t *queue, struct qmsg_t *qmsg);
65/* Move an element to the back of the queue */
66int queue_back(struct queue_t *queue, struct qmsg_t *qmsg);
67/* Get the first element in the queue (oldest) */
68int queue_getfirst(struct queue_t *queue, struct qmsg_t **qmsg);
69/* Get the element with a particular sequence number */
70int queue_seqget(struct queue_t *queue, struct qmsg_t **qmsg,
71 struct sockaddr_in *peer, uint16_t seq);
72/* Free message based on sequence number */
73int queue_freemsg_seq(struct queue_t *queue, struct sockaddr_in *peer,
jjako08d331d2003-10-13 20:33:30 +000074 uint16_t seq, uint8_t *type, void **cbp);
jjako52c24142002-12-16 13:33:51 +000075
76
77#endif /* !_QUEUE_H */
78