jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 30 | struct qmsg_t { /* Holder for queued packets */ |
| 31 | int state; /* 0=empty, 1=full */ |
| 32 | uint16_t seq; /* The sequence number */ |
jjako | 08d331d | 2003-10-13 20:33:30 +0000 | [diff] [blame] | 33 | u_int8_t type; /* The type of packet */ |
| 34 | void *cbp; /* Application specific pointer */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 35 | union gtp_packet p; /* The packet stored */ |
| 36 | int l; /* Length of the packet */ |
jjako | 08d331d | 2003-10-13 20:33:30 +0000 | [diff] [blame] | 37 | int fd; /* Socket packet was sent to / received from */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 38 | 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 | |
| 47 | struct 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 */ |
| 57 | int queue_new(struct queue_t **queue); |
| 58 | /* Deallocates queue structure */ |
| 59 | int queue_free(struct queue_t *queue); |
| 60 | /* Find a new queue element. Return EOF if allready full */ |
| 61 | int 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. */ |
| 64 | int queue_freemsg(struct queue_t *queue, struct qmsg_t *qmsg); |
| 65 | /* Move an element to the back of the queue */ |
| 66 | int queue_back(struct queue_t *queue, struct qmsg_t *qmsg); |
| 67 | /* Get the first element in the queue (oldest) */ |
| 68 | int queue_getfirst(struct queue_t *queue, struct qmsg_t **qmsg); |
| 69 | /* Get the element with a particular sequence number */ |
| 70 | int 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 */ |
| 73 | int queue_freemsg_seq(struct queue_t *queue, struct sockaddr_in *peer, |
jjako | 08d331d | 2003-10-13 20:33:30 +0000 | [diff] [blame] | 74 | uint16_t seq, uint8_t *type, void **cbp); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 75 | |
| 76 | |
| 77 | #endif /* !_QUEUE_H */ |
| 78 | |