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 | * |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * Queue.c |
| 14 | * Reliable delivery of signalling messages |
| 15 | */ |
| 16 | |
| 17 | #ifndef _QUEUE_H |
| 18 | #define _QUEUE_H |
| 19 | |
jjako | 0fe0df0 | 2004-09-17 11:30:40 +0000 | [diff] [blame] | 20 | #define QUEUE_DEBUG 0 /* Print debug information */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 21 | |
jjako | 0fe0df0 | 2004-09-17 11:30:40 +0000 | [diff] [blame] | 22 | #define QUEUE_SIZE 1024 /* Size of retransmission queue */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 23 | #define QUEUE_HASH_SIZE 65536 /* Size of hash table (2^16) */ |
| 24 | |
| 25 | struct qmsg_t { /* Holder for queued packets */ |
| 26 | int state; /* 0=empty, 1=full */ |
| 27 | uint16_t seq; /* The sequence number */ |
jjako | 0fe0df0 | 2004-09-17 11:30:40 +0000 | [diff] [blame] | 28 | uint8_t type; /* The type of packet */ |
jjako | 08d331d | 2003-10-13 20:33:30 +0000 | [diff] [blame] | 29 | void *cbp; /* Application specific pointer */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 30 | union gtp_packet p; /* The packet stored */ |
| 31 | int l; /* Length of the packet */ |
jjako | 08d331d | 2003-10-13 20:33:30 +0000 | [diff] [blame] | 32 | int fd; /* Socket packet was sent to / received from */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 33 | struct sockaddr_in peer;/* Address packet was sent to / received from */ |
| 34 | struct qmsg_t *seqnext; /* Pointer to next in sequence hash list */ |
| 35 | int next; /* Pointer to the next in queue. -1: Last */ |
| 36 | int prev; /* Pointer to the previous in queue. -1: First */ |
| 37 | int this; /* Pointer to myself */ |
| 38 | time_t timeout; /* When do we retransmit this packet? */ |
| 39 | int retrans; /* How many times did we retransmit this? */ |
| 40 | }; |
| 41 | |
| 42 | struct queue_t { |
| 43 | struct qmsg_t qmsga[QUEUE_SIZE]; /* Array holding signalling messages */ |
| 44 | void *hashseq[QUEUE_HASH_SIZE]; /* Hash array */ |
| 45 | int next; /* Next location in queue to use */ |
| 46 | int first; /* First packet in queue (oldest timeout) */ |
| 47 | int last; /* Last packet in queue (youngest timeout) */ |
| 48 | }; |
| 49 | |
| 50 | |
| 51 | /* Allocates and initialises new queue structure */ |
| 52 | int queue_new(struct queue_t **queue); |
| 53 | /* Deallocates queue structure */ |
| 54 | int queue_free(struct queue_t *queue); |
| 55 | /* Find a new queue element. Return EOF if allready full */ |
| 56 | int queue_newmsg(struct queue_t *queue, struct qmsg_t **qmsg, |
| 57 | struct sockaddr_in *peer, uint16_t seq); |
| 58 | /* Remove an element from the queue. */ |
| 59 | int queue_freemsg(struct queue_t *queue, struct qmsg_t *qmsg); |
| 60 | /* Move an element to the back of the queue */ |
| 61 | int queue_back(struct queue_t *queue, struct qmsg_t *qmsg); |
| 62 | /* Get the first element in the queue (oldest) */ |
| 63 | int queue_getfirst(struct queue_t *queue, struct qmsg_t **qmsg); |
| 64 | /* Get the element with a particular sequence number */ |
| 65 | int queue_seqget(struct queue_t *queue, struct qmsg_t **qmsg, |
| 66 | struct sockaddr_in *peer, uint16_t seq); |
| 67 | /* Free message based on sequence number */ |
| 68 | int queue_freemsg_seq(struct queue_t *queue, struct sockaddr_in *peer, |
jjako | 08d331d | 2003-10-13 20:33:30 +0000 | [diff] [blame] | 69 | uint16_t seq, uint8_t *type, void **cbp); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 70 | |
| 71 | |
| 72 | #endif /* !_QUEUE_H */ |
| 73 | |