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