You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

qspn-empiric.h 5.3KB

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