The Netsukuku Project  0.0.9
An Alternative routing method
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
qspn-empiric.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 /*These define are used to activate/deactivate the different parts of QSPN*/
20 #undef Q_BACKPRO
21 #define Q_OPEN
22 #undef NO_JOINT
23 
24 /*
25  * Map stuff
26  * Here below there are all the structures and defines you can find in map.h,
27  * but here are slightly modified.
28  */
29 
30 #define MAXGROUPNODE 20
31 #define MAXROUTES 5
32 #define MAXRTT 10 /*Max node <--> node rtt (in sec)*/
33 #define MAXLINKS MAXROUTES
34 
35 /*** flags ***/
36 #define MAP_ME 1 /*The root_node, in other words, me ;)*/
37 #define MAP_VOID (1<<1) /*It indicates a non existent node*/
38 #define MAP_HNODE (1<<2) /*Hooking node. The node is currently
39  hooking*/
40 #define MAP_BNODE (1<<3) /*The node is a border_node. If this
41  flag is set to a root_node, this means
42  that we are a bnode at the root_node's
43  level*/
44 #define MAP_ERNODE (1<<4) /*It is an External Rnode*/
45 #define MAP_GNODE (1<<5) /*It is a gnode*/
46 #define MAP_RNODE (1<<6) /*If a node has this set, it is one of the rnodes*/
47 #define MAP_UPDATE (1<<7) /*If it is set, the corresponding route
48  in the krnl will be updated*/
49 #define QSPN_CLOSED (1<<8) /*This flag is set only to the rnodes,
50  it puts a link in a QSPN_CLOSED state*/
51 #define QSPN_OPENED (1<<9) /*It puts a link in a QSPN_OPEN state*/
52 #define QSPN_OLD (1<<10) /*If a node isn't updated by the current
53  qspn_round it is marked with QSPN_ROUND.
54  If in the next qspn_round the same node
55  isn't updated it is removed from the map.*/
56 #define QSPN_STARTER (1<<11) /*The root node is marked with this flag
57  if it is a qspn_starter*/
58 #define QSPN_OPENER (1<<12) /*If the root_node sent a new qspn_open
59  it is a qspn_opener*/
60 #define QSPN_BACKPRO (1<<13)
61 
62 typedef struct
63 {
64  u_short flags;
65  int *r_node; /*It's the pointer to the struct of the
66  r_node in the map*/
67  struct timeval rtt; /*node <-> r_node round trip time
68  (in millisec)*/
69  struct timeval trtt;
70 }map_rnode;
71 
72 typedef struct
73 {
74  u_int flags;
75  u_int brdcast[MAXGROUPNODE];
76  u_short links; /*Number of r_nodes*/
77  map_rnode *r_node; /*These structs will be kept in ascending
78  order considering their rnode_t.rtt*/
79 }map_node;
80 
82  { INT_TYPE_32BIT, INT_TYPE_32BIT, INT_TYPE_32BIT },
83  { 0, sizeof(int), sizeof(int)*2 },
84  { 1, 1, 1 }
85  };
86 #define MAP_RNODE_PACK_SZ (sizeof(int *)+sizeof(u_int)*2)
89  { 0, sizeof(short), sizeof(short)+sizeof(int) },
90  { 1, 1, 1 }
91  };
92 
93 #define MAP_NODE_PACK_SZ (sizeof(u_short)*2 + sizeof(u_int))
94 
95 #define MAXRNODEBLOCK (MAXLINKS * MAXGROUPNODE * sizeof(map_rnode))
96 #define MAXRNODEBLOCK_PACK_SZ (MAXLINKS * MAXGROUPNODE * MAP_RNODE_PACK_SZ)
97 #define INTMAP_END(mapstart) ((sizeof(map_node)*MAXGROUPNODE)+(mapstart))
98 
99 struct int_map_hdr
100 {
101  u_char root_node;
102  size_t int_map_sz;
103  size_t rblock_sz;
104 }_PACKED_;
107  { sizeof(char), sizeof(char)+sizeof(size_t) },
108  { 1, 1 }
109  };
110 #define INT_MAP_BLOCK_SZ(int_map_sz, rblock_sz) (sizeof(struct int_map_hdr)+(int_map_sz)+(rblock_sz))
111 
112 
113 /*
114  * * Qspn-empiric stuff begins here * *
115  */
116 
117 
118 pthread_mutex_t mutex[MAXGROUPNODE];
120 
121 
123 
124 /*This struct keeps tracks of the qspn_pkts sent or received by our rnodes*/
126 {
127  int q_id; /*qspn_id*/
128  u_short replier[MAXGROUPNODE]; /*Who has sent these repliesi (qspn_sub_id)*/
129  u_short flags[MAXGROUPNODE];
131 
132 struct qstat
133 {
138 };
139 
145 
146 
147 #define OP_REQUEST 82
148 #define OP_CLOSE OP_REQUEST
149 #define OP_OPEN 28
150 #define OP_REPLY 69
151 #define OP_BACKPRO 66
152 
153 #define QPKT_REPLY 1
154 
155 struct q_pkt
156 {
157  int q_id;
158  int q_sub_id;
159  short from;
160  short to;
162  char op;
163  char flags;
164  short *tracer;
165  short routes;
166 };
167 
170 
171 struct q_opt
172 {
173  struct q_pkt q;
174  int sleep;
175  int join;
176 };
177 
178 void thread_joint(int joint, void * (*start_routine)(void *), void *nopt);
179 void gen_rnd_map(int start_node, int back_link, int back_link_rtt);
180 int print_map(map_node *map, char *map_file);
181 void *show_temp_stat(void *);
182 void print_data(char *file);
183 int store_tracer_pkt(struct q_opt *qopt);
184 void *send_qspn_backpro(void *argv);
185 void *send_qspn_reply(void *argv);
186 void *send_qspn_pkt(void *argv);
u_int flags
Definition: qspn-empiric.h:74
short rt_stat[20][20]
Definition: qspn-empiric.h:143
int q_id
Definition: qspn-empiric.h:127
size_t rblock_sz
Definition: map.h:153
void print_data(char *file)
Definition: qspn-empiric.c:1082
void * send_qspn_pkt(void *argv)
Definition: qspn-empiric.c:847
int qspn_replies
Definition: qspn-empiric.h:136
struct qspn_queue * qspn_q[20]
INT_INFO map_node_iinfo
Definition: qspn-empiric.h:87
INT_INFO int_map_hdr_iinfo
Definition: qspn-empiric.h:105
struct qstat gbl_stat
Definition: qspn-empiric.h:141
int join
Definition: qspn-empiric.h:175
Definition: map.h:74
void thread_joint(int joint, void *(*start_routine)(void *), void *nopt)
Definition: qspn-empiric.c:519
int q_sub_id
Definition: qspn-empiric.h:158
#define INT_TYPE_16BIT
Definition: endianness.h:36
Definition: map.h:149
size_t int_map_sz
Definition: map.h:152
Definition: qspn-empiric.h:125
short from
Definition: qspn-empiric.h:159
Definition: qspn-empiric.h:171
Definition: map.h:125
int total_pkts
Definition: qspn-empiric.h:134
char flags
Definition: qspn-empiric.h:163
int print_map(map_node *map, char *map_file)
Definition: qspn-empiric.c:1028
Definition: qspn-empiric.h:132
short to
Definition: qspn-empiric.h:160
int pkt_dbc[20]
Definition: qspn-empiric.h:169
int broadcast
Definition: qspn-empiric.h:161
int total_threads
Definition: qspn-empiric.h:119
int sleep
Definition: qspn-empiric.h:174
Definition: qspn-empiric.h:155
INT_INFO map_rnode_iinfo
Definition: qspn-empiric.h:81
char op
Definition: qspn-empiric.h:162
struct int_map_hdr _PACKED_
map_node * int_map
Definition: qspn-empiric.h:122
u_short flags
Definition: qspn-empiric.h:64
int disable_joint
Definition: qspn-empiric.h:119
#define MAXGROUPNODE
Definition: qspn-empiric.h:30
int time_stat
Definition: qspn-empiric.h:140
void * send_qspn_reply(void *argv)
Definition: qspn-empiric.c:728
struct q_pkt q
Definition: qspn-empiric.h:173
#define INT_INFO
Definition: endianness.h:90
int qspn_backpro
Definition: qspn-empiric.h:137
int qspn_requests
Definition: qspn-empiric.h:135
u_short replier[20]
Definition: qspn-empiric.h:128
struct qstat node_stat[20]
Definition: qspn-empiric.h:142
void gen_rnd_map(int start_node, int back_link, int back_link_rtt)
Definition: qspn-empiric.c:552
struct q_pkt ** pkt_db[20]
Definition: qspn-empiric.h:168
u_short flags[20]
Definition: qspn-empiric.h:129
short rt_total[20]
Definition: qspn-empiric.h:144
void * send_qspn_backpro(void *argv)
Definition: qspn-empiric.c:680
#define INT_TYPE_32BIT
Definition: endianness.h:35
pthread_mutex_t mutex[20]
Definition: qspn-empiric.h:118
int store_tracer_pkt(struct q_opt *qopt)
Definition: qspn-empiric.c:646
short routes
Definition: qspn-empiric.h:165
short * tracer
Definition: qspn-empiric.h:164
u_char root_node
Definition: map.h:151
int q_id
Definition: qspn-empiric.h:157
void * show_temp_stat(void *)
Definition: qspn-empiric.c:1014