• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/um-olsr-0.8.8/backup/OLSR_pkt.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Francisco J. Ros                                *
00003  *   fjrm@dif.um.es                                                        *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program 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 General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00026 
00027 #ifndef __OLSR_pkt_h__
00028 #define __OLSR_pkt_h__
00029 
00030 #include <packet.h>
00031 
00032 /********** Message types **********/
00033 
00035 #define OLSR_HELLO_MSG          1
00036 
00037 #define OLSR_TC_MSG             2
00038 
00039 #define OLSR_MID_MSG            3
00040 
00041 /********** Packets stuff **********/
00042 
00044 #define PKT_OLSR(p)             OLSR_pkt::access(p)
00045 
00053 #ifdef OLSR_IPv6
00054 #define ADDR_SIZE       16
00055 #else
00056 #define ADDR_SIZE       4
00057 #endif
00058 
00060 #define OLSR_MAX_MSGS           4
00061 
00063 #define OLSR_MAX_HELLOS         12
00064 
00066 #define OLSR_MAX_ADDRS          64
00067 
00069 #define OLSR_PKT_HDR_SIZE       4
00070 
00072 #define OLSR_MSG_HDR_SIZE       12
00073 
00075 #define OLSR_HELLO_HDR_SIZE     4
00076 
00078 #define OLSR_HELLO_MSG_HDR_SIZE 4
00079 
00081 #define OLSR_TC_HDR_SIZE        4
00082 
00084 typedef struct OLSR_hello_msg {
00085 
00087         u_int8_t        link_code_;
00089         u_int8_t        reserved_;
00091         u_int16_t       link_msg_size_;
00093         nsaddr_t        nb_iface_addrs_[OLSR_MAX_ADDRS];
00095         int             count;
00096         
00097         inline u_int8_t&        link_code()             { return link_code_; }
00098         inline u_int8_t&        reserved()              { return reserved_; }
00099         inline u_int16_t&       link_msg_size()         { return link_msg_size_; }
00100         inline nsaddr_t&        nb_iface_addr(int i)    { return nb_iface_addrs_[i]; }
00101         
00102         inline u_int32_t size() { return OLSR_HELLO_MSG_HDR_SIZE + count*ADDR_SIZE; }
00103 
00104 } OLSR_hello_msg;
00105 
00107 typedef struct OLSR_hello {
00108 
00110         u_int16_t       reserved_;
00112         u_int8_t        htime_;
00114         u_int8_t        willingness_;
00116         OLSR_hello_msg  hello_body_[OLSR_MAX_HELLOS];
00118         int             count;
00119         
00120         inline u_int16_t&       reserved()              { return reserved_; }
00121         inline u_int8_t&        htime()                 { return htime_; }
00122         inline u_int8_t&        willingness()           { return willingness_; }
00123         inline OLSR_hello_msg&  hello_msg(int i)        { return hello_body_[i]; }
00124         
00125         inline u_int32_t size() {
00126                 u_int32_t sz = OLSR_HELLO_HDR_SIZE;
00127                 for (int i = 0; i < count; i++)
00128                         sz += hello_msg(i).size();
00129                 return sz;
00130         }
00131         
00132 } OLSR_hello;
00133 
00135 typedef struct OLSR_tc {
00136 
00138         u_int16_t       ansn_;
00140         u_int16_t       reserved_;
00142         nsaddr_t        nb_main_addrs_[OLSR_MAX_ADDRS];
00144         int             count;
00145         
00146         inline  u_int16_t&      ansn()                  { return ansn_; }
00147         inline  u_int16_t&      reserved()              { return reserved_; }
00148         inline  nsaddr_t&       nb_main_addr(int i)     { return nb_main_addrs_[i]; }
00149         
00150         inline  u_int32_t size() { return OLSR_TC_HDR_SIZE + count*ADDR_SIZE; }
00151 
00152 } OLSR_tc;
00153 
00155 typedef struct OLSR_mid {
00156 
00158         nsaddr_t        iface_addrs_[OLSR_MAX_ADDRS];
00160         int             count;
00161         
00162         inline nsaddr_t&        iface_addr(int i)       { return iface_addrs_[i]; }
00163         
00164         inline u_int32_t        size()                  { return count*ADDR_SIZE; }
00165         
00166 } OLSR_mid;
00167 
00169 typedef struct OLSR_msg {
00170 
00171         u_int8_t        msg_type_;      
00172         u_int8_t        vtime_;         
00173         u_int16_t       msg_size_;      
00174         nsaddr_t        orig_addr_;     
00175         u_int8_t        ttl_;           
00176         u_int8_t        hop_count_;     
00177         u_int16_t       msg_seq_num_;   
00178         union {
00179                 OLSR_hello      hello_;
00180                 OLSR_tc         tc_;
00181                 OLSR_mid        mid_;
00182         } msg_body_;                    
00183         
00184         inline  u_int8_t&       msg_type()      { return msg_type_; }
00185         inline  u_int8_t&       vtime()         { return vtime_; }
00186         inline  u_int16_t&      msg_size()      { return msg_size_; }
00187         inline  nsaddr_t&       orig_addr()     { return orig_addr_; }
00188         inline  u_int8_t&       ttl()           { return ttl_; }
00189         inline  u_int8_t&       hop_count()     { return hop_count_; }
00190         inline  u_int16_t&      msg_seq_num()   { return msg_seq_num_; }
00191         inline  OLSR_hello&     hello()         { return msg_body_.hello_; }
00192         inline  OLSR_tc&        tc()            { return msg_body_.tc_; }
00193         inline  OLSR_mid&       mid()           { return msg_body_.mid_; }
00194         
00195         inline u_int32_t size() {
00196                 u_int32_t sz = OLSR_MSG_HDR_SIZE;
00197                 if (msg_type() == OLSR_HELLO_MSG)
00198                         sz += hello().size();
00199                 else if (msg_type() == OLSR_TC_MSG)
00200                         sz += tc().size();
00201                 else if (msg_type() == OLSR_MID_MSG)
00202                         sz += mid().size();
00203                 return sz;
00204         }
00205 
00206 } OLSR_msg;
00207 
00209 typedef struct OLSR_pkt {
00210 
00211         u_int16_t       pkt_len_;                       
00212         u_int16_t       pkt_seq_num_;                   
00213         OLSR_msg        pkt_body_[OLSR_MAX_MSGS];       
00214         int             count;                          
00215         
00216         inline  u_int16_t&      pkt_len()       { return pkt_len_; }
00217         inline  u_int16_t&      pkt_seq_num()   { return pkt_seq_num_; }
00218         inline  OLSR_msg&       msg(int i)      { return pkt_body_[i]; }
00219         
00220         static int offset_;
00221         inline static int& offset() { return offset_; }
00222         inline static struct OLSR_pkt* access(const Packet* p) {
00223                 return (struct OLSR_pkt*)p->access(offset_);
00224         }
00225 
00226 } OLSR_pkt;
00227 
00228 #endif

Generated on Tue Aug 10 2010 16:16:09 for ns-2.33 by  doxygen 1.7.1