The Netsukuku Project  0.0.9
An Alternative routing method
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
qspn.h
Go to the documentation of this file.
1 /* This file is part of Netsukuku
2  * (c) Copyright 2004 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3  *
4  * This source code is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  *
9  * This source code is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * Please refer to the GNU Public License for more details.
13  *
14  * You should have received a copy of the GNU Public License along with
15  * this source code; if not, write to:
16  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 
19 #ifndef QSPN_H
20 #define QSPN_H
21 
22 #include "gmap.h"
23 
24 #define QSPN_WAIT_ROUND 32 /*This is a crucial value. It is the number of
25  seconds to be waited before the next qspn_round
26  can be sent*/
27 #define QSPN_WAIT_ROUND_MS QSPN_WAIT_ROUND*1000
28 #define QSPN_WAIT_DELTA_MS 64 /*If a qspn_round is sent while
29  qspn_round_left() < QSPN_WAIT_DELTA_MS,
30  then it is acceptable*/
31 
32 #ifdef DEBUG
33 #undef QSPN_WAIT_ROUND
34 #define QSPN_WAIT_ROUND 8
35 #endif
36 
37 /*Wait time bound to a specific level: y = (w/2)*x + w/(x+1) */
38 #define QSPN_WAIT_ROUND_LVL(level) ((level)*(QSPN_WAIT_ROUND/2) + \
39  QSPN_WAIT_ROUND/((level)+1))
40 #define QSPN_WAIT_ROUND_MS_LVL(level) (QSPN_WAIT_ROUND_LVL(level)*1000)
41 
42 /* The delta grows in this way: y = x*(w/2) + 2*w*x + w; */
43 #define QSPN_WAIT_DELTA_MS_LVL(level) ((level)*(QSPN_WAIT_DELTA_MS/2) + \
44  2*QSPN_WAIT_DELTA_MS*(level) + QSPN_WAIT_DELTA_MS)
45 
46 
47 /* This list keeps tracks of the qspn_pkts sent or
48  * received by our rnodes*/
50 {
52 
53  map_node * rnode; /* the rnode this buf is referring to */
54  u_int replies; /* How many replies we forwarded/sent
55  to `rnode' */
56  u_char * replier; /* Who has sent these replies (qspn_sub_id) */
57  u_short * flags;
58 };
59 
60 
61 /*
62  * * * Global vars * * *
63  */
64 
65 struct qspn_buffer **qspn_b; /*It is sizeof(struct qspn_buffer *)*levels big*/
66 
67 int *qspn_send_mutex; /*It is sizeof(int)*levels big.*/
68 
69 #define GCOUNT_LEVELS (MAX_LEVELS-ZERO_LEVEL+UNITY_LEVEL)
70 /*
71  * qspn_gnode_count[x] is the number of nodes present in the gnode
72  * me.cur_quadg.gnode[x], it is updated at each qspn_round.
73  * Use the _EL() macro!
74  */
76 
77 /* gcount of the previous qspn_round */
79 
80 
81 /*
82  * * Functions declaration * *
83  */
84 void qspn_time_reset(int start_level, int end_level, int levels);
85 void qspn_reset_counters(u_char levels);
86 void qspn_reset(u_char levels);
87 void qspn_init(u_char levels);
88 void qspn_free(void);
89 void qspn_set_map_vars(u_char level, map_node **map, map_node **root_node,
90  int *root_node_pos, map_gnode **gmap);
91 
92 void qspn_b_clean(u_char level);
93 int qspn_b_add(struct qspn_buffer *qb, u_char replier, u_short flags);
94 int qspn_b_find_reply(struct qspn_buffer *qb, int sub_id);
96 int qspn_b_del_dead_rnodes(struct qspn_buffer **qb, map_node *root_node);
98 
99 int qspn_round_left(u_char level);
100 void update_qspn_time(u_char level, u_int new_qspn_time);
101 
102 void qspn_inc_gcount(u_int *gcount, int level, int inc);
103 void qspn_dec_gcount(u_int *gcount, int level, int dec);
104 void qspn_reset_gcount(u_int *gcount, int level, int value);
105 void qspn_backup_gcount(u_int *old_gcount, int *gcount);
106 
107 void qspn_new_round(u_char level, int new_qspn_id, u_int new_qspn_time);
108 
109 int qspn_send(u_char level);
110 int qspn_close(PACKET rpkt);
111 int qspn_open(PACKET rpkt);
112 
113 #endif /*QSPN_H*/
void update_qspn_time(u_char level, u_int new_qspn_time)
Definition: qspn.c:267
int qspn_b_find_reply(struct qspn_buffer *qb, int sub_id)
Definition: qspn.c:175
int qspn_b_add(struct qspn_buffer *qb, u_char replier, u_short flags)
Definition: qspn.c:154
struct qspn_buffer * qspn_b_find_rnode(struct qspn_buffer *qb, map_node *rnode)
Definition: qspn.c:167
void qspn_b_clean(u_char level)
Definition: qspn.c:133
int qspn_b_del_dead_rnodes(struct qspn_buffer **qb, map_node *root_node)
Definition: qspn.c:193
int * qspn_send_mutex
Definition: qspn.h:67
Definition: map.h:125
int qspn_send(u_char level)
Definition: qspn.c:579
void qspn_reset_counters(u_char levels)
Definition: qspn.c:84
#define GCOUNT_LEVELS
Definition: qspn.h:69
u_int qspn_gnode_count[((14+(1+1))-1+1)]
Definition: qspn.h:75
int qspn_close(PACKET rpkt)
Definition: qspn.c:838
map_node * rnode
Definition: qspn.h:53
void qspn_backup_gcount(u_int *old_gcount, int *gcount)
Definition: qspn.c:360
void qspn_time_reset(int start_level, int end_level, int levels)
Definition: qspn.c:65
void qspn_reset(u_char levels)
Definition: qspn.c:92
void qspn_reset_gcount(u_int *gcount, int level, int value)
Definition: qspn.c:346
void qspn_inc_gcount(u_int *gcount, int level, int inc)
Definition: qspn.c:307
Definition: qspn.h:49
void qspn_new_round(u_char level, int new_qspn_id, u_int new_qspn_time)
Definition: qspn.c:478
void qspn_b_del_all_dead_rnodes(void)
Definition: qspn.c:211
int qspn_round_left(u_char level)
Definition: qspn.c:226
u_short * flags
Definition: qspn.h:57
u_int replies
Definition: qspn.h:54
Definition: pkts.h:118
#define LLIST_HDR(_struct)
Definition: llist.c:44
int flags
Definition: if.c:39
u_char * replier
Definition: qspn.h:56
void qspn_free(void)
Definition: qspn.c:121
u_int qspn_old_gcount[((14+(1+1))-1+1)]
Definition: qspn.h:78
Definition: gmap.h:37
void qspn_set_map_vars(u_char level, map_node **map, map_node **root_node, int *root_node_pos, map_gnode **gmap)
Definition: qspn.c:38
int qspn_open(PACKET rpkt)
Definition: qspn.c:1089
struct qspn_buffer ** qspn_b
Definition: qspn.h:65
void qspn_init(u_char levels)
Definition: qspn.c:101
void qspn_dec_gcount(u_int *gcount, int level, int dec)
Definition: qspn.c:327