Wiselib
|
00001 /*************************************************************************** 00002 ** This file is part of the generic algorithm library Wiselib. ** 00003 ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project. ** 00004 ** ** 00005 ** The Wiselib is free software: you can redistribute it and/or modify ** 00006 ** it under the terms of the GNU Lesser General Public License as ** 00007 ** published by the Free Software Foundation, either version 3 of the ** 00008 ** License, or (at your option) any later version. ** 00009 ** ** 00010 ** The Wiselib is distributed in the hope that it will be useful, ** 00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** 00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 00013 ** GNU Lesser General Public License for more details. ** 00014 ** ** 00015 ** You should have received a copy of the GNU Lesser General Public ** 00016 ** License along with the Wiselib. ** 00017 ** If not, see <http://www.gnu.org/licenses/>. ** 00018 ***************************************************************************/ 00019 #ifndef __ALGORITHMS_ROUTING_OLSR_BROADCAST_TC_MSG_H__ 00020 #define __ALGORITHMS_ROUTING_OLSR_BROADCAST_TC_MSG_H__ 00021 00022 #include "util/serialization/simple_types.h" 00023 00024 namespace wiselib 00025 { 00026 00027 00028 template<typename OsModel_P, 00029 typename Radio_P, 00030 typename RoutingTableEntry_P> 00031 class OlsrBroadcastTcMessage 00032 { 00033 public: 00034 00035 typedef OsModel_P OsModel; 00036 typedef Radio_P Radio; 00037 typedef RoutingTableEntry_P RoutingTableEntry; 00038 typedef typename Radio::block_data_t block_data_t; 00039 typedef typename Radio::node_id_t node_id_t; 00040 // -------------------------------------------------------------------- 00041 inline OlsrBroadcastTcMessage(); 00042 // -------------------------------------------------------------------- 00043 00044 inline uint8_t msg_id() 00045 { return read<OsModel, block_data_t, uint8_t>( buffer ); } 00046 00047 inline uint8_t vtime() 00048 { return read<OsModel, block_data_t, uint8_t>( buffer + VTIME_POS); } 00049 00050 inline uint16_t msg_size() 00051 { return read<OsModel, block_data_t, uint16_t>( buffer + MSG_SIZE_POS); } 00052 00053 inline node_id_t originator_addr() 00054 { return read<OsModel, block_data_t, uint32_t>( buffer + ORIGINATOR_ADDR_POS); } 00055 00056 inline uint8_t ttl() 00057 { return read<OsModel, block_data_t, uint8_t>( buffer + TTL_POS); } 00058 00059 inline uint8_t hop_count() 00060 { return read<OsModel, block_data_t, uint8_t>( buffer + HOP_COUNT_POS); } 00061 00062 inline uint16_t msg_seq_num() 00063 { return read<OsModel, block_data_t, uint16_t>( buffer + MSG_SEQ_POS); } 00064 00065 inline uint16_t ansn() 00066 { return read<OsModel, block_data_t, uint16_t>( buffer + ANSN_POS); } 00067 00068 inline node_id_t adv_neighbor_addr_list( int index ) 00069 //{ return buffer + ADV_NEIGHBOR_ADDR_LIST_POS + index; } 00070 { 00071 unsigned char* a = NULL; 00072 char* b = NULL; 00073 a = buffer + ADV_NEIGHBOR_ADDR_LIST_POS + index; 00074 b = (char*)a; 00075 char c = *b; 00076 return int(c); 00077 } 00078 00079 inline uint8_t adv_neighbor_addr_list_size() 00080 { return read<OsModel, block_data_t, uint8_t>( buffer + ADV_NEIGHBOR_ADDR_LIST_POS); } 00081 00082 inline size_t buffer_size() 00083 { return ADV_NEIGHBOR_ADDR_LIST_POS + 1 + adv_neighbor_addr_list_size(); } 00084 00085 // -------------------------------------------------------------------- 00086 inline void set_msg_id( uint8_t id ) 00087 { write<OsModel, block_data_t, uint8_t>( buffer, id ); } 00088 00089 inline void set_vtime(uint8_t vtime) 00090 { write<OsModel, block_data_t, uint8_t>( buffer + VTIME_POS, vtime); } 00091 00092 inline void set_msg_size(uint16_t msg_size) 00093 { write<OsModel, block_data_t, uint16_t>( buffer + MSG_SIZE_POS, msg_size); } 00094 00095 inline void set_originator_addr(uint32_t originator_addr) 00096 { write<OsModel, block_data_t, uint32_t>( buffer + ORIGINATOR_ADDR_POS, originator_addr); } 00097 00098 inline void set_ttl(uint8_t ttl) 00099 { write<OsModel, block_data_t, uint8_t>( buffer + TTL_POS, ttl); } 00100 00101 inline void set_hop_count(uint8_t hop_count) 00102 { write<OsModel, block_data_t, uint8_t>( buffer + HOP_COUNT_POS, hop_count); } 00103 00104 inline void set_msg_seq_num(uint16_t msg_sequence) 00105 { write<OsModel, block_data_t, uint16_t>( buffer + MSG_SEQ_POS, msg_sequence); } 00106 00107 inline void set_ansn(uint16_t ansn) 00108 { write<OsModel, block_data_t, uint16_t>( buffer + ANSN_POS, ansn); } 00109 00110 inline void set_adv_neighbor_addr_list(int count, node_id_t* data ) 00111 { memcpy( buffer + ADV_NEIGHBOR_ADDR_LIST_POS + (count-1)*4, data, 4 ); } 00112 00113 // -------------------------------------------------------------------- 00114 00115 private: 00116 enum data_positions 00117 { 00118 MSG_ID_POS = 0, 00119 VTIME_POS = 1, 00120 MSG_SIZE_POS = 2, 00121 ORIGINATOR_ADDR_POS = 4, 00122 TTL_POS = 8, 00123 HOP_COUNT_POS = 9, 00124 MSG_SEQ_POS = 10, 00125 ANSN_POS = 12, 00126 ADV_NEIGHBOR_ADDR_LIST_POS = 14 00127 }; 00128 00129 block_data_t buffer[Radio::MAX_MESSAGE_LENGTH]; 00130 }; 00131 // ----------------------------------------------------------------------- 00132 template<typename OsModel_P, 00133 typename Radio_P, 00134 typename RoutingTableEntry_P> 00135 OlsrBroadcastTcMessage<OsModel_P, Radio_P, RoutingTableEntry_P>:: 00136 OlsrBroadcastTcMessage() 00137 { 00138 // Initialization of the msg_id and etc. 00139 // Assignment of the value is given at the instantiation of class BroadcastTcMessage 00140 set_msg_id(0); 00141 set_vtime(0); 00142 set_msg_size(0); 00143 set_originator_addr( Radio::NULL_NODE_ID ); 00144 set_ttl(0); 00145 set_hop_count(0); 00146 set_msg_seq_num(0); 00147 set_ansn(0); 00148 } 00149 00150 } 00151 #endif