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.

bmap.h 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* This file is part of Netsukuku system
  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. #ifndef BMAP_H
  19. #define BMAP_H
  20. #include "gmap.h"
  21. #define BMAP_UPDATE MAP_UPDATE /* At each new qspn_round all the bnodes flags are set
  22. to BMAP_UPDATE, thus when tracer_store_pkt() updates
  23. them for the first time during the new round, it
  24. deletes their rnodes. */
  25. /*
  26. * map_bnode is the struct used to create the "map border node".
  27. * This map keeps all the border node of the map, making it easy to retrieve
  28. * the gnode they are linked to.
  29. * It is indentical to the map_node but, as always there are some little
  30. * differences:
  31. *
  32. * uint16_t links; is the number of gnodes the bnode is
  33. * linked to.
  34. * map_rnode *r_node; r_node[x].r_node, in this case, points
  35. * to the position of the bnode's gnode in
  36. * the ext_map.
  37. * u_int brdcast; Where this node is in the int/ext_map.
  38. * The position is stored in the usual
  39. * pos_from_node() format. (Yep, a dirty hack)
  40. *
  41. * So you are asking why I didn't made a new struct for the bmap. Well, I don't
  42. * want to [re]write all the functions to handle the map, for example
  43. * rnode_add,rnode_del, save_map, etc... it's a pain, just for a little map and
  44. * moreover it adds new potential bugs. In conclusion: laziness + fear == hacks++;
  45. *
  46. */
  47. typedef map_node map_bnode;
  48. #define MAP_BNODE_PACK_SZ MAP_NODE_PACK_SZ
  49. #define MAXGROUPBNODE MAXGROUPNODE /*the maximum number of bnodes in
  50. a gnode is equal to the maximum
  51. number of nodes */
  52. #define MAXBNODE_LINKS (MAXGROUPNODE*2) /*The maximum number of gnodes a
  53. bnode is linked to */
  54. #define MAXBNODE_RNODEBLOCK (MAXBNODE_LINKS*MAXGROUPBNODE*MAP_RNODE_PACK_SZ)
  55. /*
  56. * These defines make the life easier, so instead of writing int_map_hdr I
  57. * write bnode_map_hdr. Cool eh? ^_^.
  58. */
  59. #define bnode_ptr brdcast /*Don't kill me */
  60. #define bnode_map_hdr int_map_hdr
  61. #define bnode_map_sz int_map_sz
  62. /*
  63. * The bnode map uses only `me.cur_quadg.levels-1' levels, because each level of
  64. * the bmap points to the upper one, therefore the last level is ignored.
  65. */
  66. #define BMAP_LEVELS(levels) (levels-1)
  67. #define BMAP_MAX_LEVELS (BMAP_LEVELS(MAX_LEVELS))
  68. #define GET_BMAP_LEVELS(family) (BMAP_LEVELS(GET_LEVELS((family))))
  69. /*
  70. * border node block: this is the block which keeps the gnodes linked to the
  71. * `bnode' border_node. When a bnode has to add his entry in the tracer_pkt it
  72. * encapsulates the bnode_block at the end of the packet, in this way it is
  73. * possible to know all the gnodes linked to the bnode's gnode.
  74. * Note: It is possible that the packet passes trough many bnodes, in this case
  75. * the bnode block is always put at the end, ex:
  76. * |pkt_hdr|brdcast_hdr|tracer_hdr|tracer_chunks|bnode_hdr|bnode_chunks|bnode_hdr|bnode_chunks|...
  77. * and so on.
  78. *
  79. * The bblock is also used to store the Internet gateways, see igs.h for more
  80. * details.
  81. */
  82. typedef struct {
  83. u_char bnode_levels;
  84. u_short links; /*The number of linked gnode */
  85. } _PACKED_ bnode_hdr;
  86. INT_INFO bnode_hdr_iinfo = { 1, {INT_TYPE_16BIT}, {sizeof(char)}, {1} };
  87. /*
  88. * This is part of the bnode_hdr.
  89. *
  90. * u_char bnode[bnode_levels]; The bnode this bnode_block belongs to.
  91. */
  92. #define BNODE_HDR_SZ(levels) (sizeof(bnode_hdr)+sizeof(u_char)*(levels))
  93. typedef struct {
  94. /* The `bnode_hdr.bnode' borders on the `gnode' of `level'th level with
  95. * a round trip time which is stored in `rtt'. */
  96. u_char gnode;
  97. u_char level;
  98. u_int rtt;
  99. } _PACKED_ bnode_chunk;
  100. #define BNODEBLOCK_SZ(levels, links) (BNODE_HDR_SZ((levels)) + \
  101. (sizeof(bnode_chunk)*(links)))
  102. INT_INFO bnode_chunk_iinfo =
  103. { 1, {INT_TYPE_32BIT}, {sizeof(char) * 2}, {1} };
  104. /*
  105. * This is the header placed on top of all the bnode_map blocks.
  106. * So the bnode maps final block is:
  107. *
  108. * bnode_maps_hdr
  109. *
  110. * ---------
  111. * bnode_map_hdr
  112. * bnode_map_block
  113. * ---------
  114. * bnode_map_hdr
  115. * bnode_map_block
  116. * ---------
  117. *
  118. * ...
  119. */
  120. struct bnode_maps_hdr {
  121. u_char levels;
  122. size_t bmaps_block_sz;
  123. } _PACKED_;
  124. INT_INFO bnode_maps_hdr_iinfo =
  125. { 1, {INT_TYPE_32BIT}, {sizeof(char)}, {1} };
  126. /* * * Functions' declaration * * */
  127. void bmap_levels_init(u_char levels, map_bnode *** bmap,
  128. u_int ** bmap_nodes);
  129. void bmap_levels_free(map_bnode ** bmap, u_int * bmap_nodes);
  130. void bmap_counter_init(u_char levels, u_int ** bnodes_closed,
  131. u_int ** bnodes_opened);
  132. void bmap_counter_free(u_int * bnodes_closed, u_int * bnodes_opened);
  133. void bmap_counter_reset(u_char levels, u_int * counter);
  134. int map_add_bnode(map_bnode ** bmap, u_int * bmap_nodes, u_int bnode,
  135. u_int links);
  136. map_bnode *map_bnode_del(map_bnode * bmap, u_int * bmap_nodes,
  137. map_bnode * bnode);
  138. int bmap_del_rnode_by_level(map_bnode *, int, map_gnode **, int);
  139. int map_find_bnode(map_bnode * bmap, int bmap_nodes, int node);
  140. int map_find_bnode_rnode(map_bnode * bmap, int bmap_nodes, void *n);
  141. int map_count_bnode_rnode(map_bnode * bmap, int bmap_nodes, void *n);
  142. int bmaps_count_bnode_rnode(map_bnode ** bmap, int *bmap_nodes, int levels,
  143. void *n);
  144. int map_del_bnode_rnode(map_bnode ** bmap, int *bmap_nodes, void *n);
  145. int bmaps_del_bnode_rnode(map_bnode ** bmap, int *bmap_nodes, int levels,
  146. void *n);
  147. void map_set_bnode_flag(map_bnode * bmap, int bmap_nodes, int flags);
  148. void bmaps_set_bnode_flag(map_bnode ** bmap, int *bmap_nodes, int levels,
  149. int flags);
  150. char *pack_all_bmaps(map_bnode **, u_int *, map_gnode **, quadro_group,
  151. size_t *);
  152. map_bnode **unpack_all_bmaps(char *, u_char, map_gnode **, u_int **, int,
  153. int);
  154. int save_bmap(map_bnode **, u_int *, map_gnode **, quadro_group, char *);
  155. map_bnode **load_bmap(char *, map_gnode **, u_char, u_int **);
  156. #endif /*BMAP_H */