• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/aodv/aodv_packet.h

00001 /*
00002 Copyright (c) 1997, 1998 Carnegie Mellon University.  All Rights
00003 Reserved. 
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007 
00008 1. Redistributions of source code must retain the above copyright notice,
00009 this list of conditions and the following disclaimer.
00010 2. Redistributions in binary form must reproduce the above copyright notice,
00011 this list of conditions and the following disclaimer in the documentation
00012 and/or other materials provided with the distribution.
00013 3. The name of the author may not be used to endorse or promote products
00014 derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00017 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00018 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00019 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00021 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00022 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00023 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00024 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00025 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 The AODV code developed by the CMU/MONARCH group was optimized and tuned by Samir Das and Mahesh Marina, University of Cincinnati. The work was partially done in Sun Microsystems.
00028 */
00029 
00030 
00031 #ifndef __aodv_packet_h__
00032 #define __aodv_packet_h__
00033 
00034 //#include <config.h>
00035 //#include "aodv.h"
00036 #define AODV_MAX_ERRORS 100
00037 
00038 
00039 /* =====================================================================
00040    Packet Formats...
00041    ===================================================================== */
00042 #define AODVTYPE_HELLO          0x01
00043 #define AODVTYPE_RREQ           0x02
00044 #define AODVTYPE_RREP           0x04
00045 #define AODVTYPE_RERR           0x08
00046 #define AODVTYPE_RREP_ACK       0x10
00047 
00048 /*
00049  * AODV Routing Protocol Header Macros
00050  */
00051 #define HDR_AODV(p)             ((struct hdr_aodv*)hdr_aodv::access(p))
00052 #define HDR_AODV_REQUEST(p)     ((struct hdr_aodv_request*)hdr_aodv::access(p))
00053 #define HDR_AODV_REPLY(p)       ((struct hdr_aodv_reply*)hdr_aodv::access(p))
00054 #define HDR_AODV_ERROR(p)       ((struct hdr_aodv_error*)hdr_aodv::access(p))
00055 #define HDR_AODV_RREP_ACK(p)    ((struct hdr_aodv_rrep_ack*)hdr_aodv::access(p))
00056 
00057 /*
00058  * General AODV Header - shared by all formats
00059  */
00060 struct hdr_aodv {
00061         u_int8_t        ah_type;
00062         /*
00063         u_int8_t        ah_reserved[2];
00064         u_int8_t        ah_hopcount;
00065         */
00066                 // Header access methods
00067         static int offset_; // required by PacketHeaderManager
00068         inline static int& offset() { return offset_; }
00069         inline static hdr_aodv* access(const Packet* p) {
00070                 return (hdr_aodv*) p->access(offset_);
00071         }
00072 };
00073 
00074 struct hdr_aodv_request {
00075         u_int8_t        rq_type;        // Packet Type
00076         u_int8_t        reserved[2];
00077         u_int8_t        rq_hop_count;   // Hop Count
00078         u_int32_t       rq_bcast_id;    // Broadcast ID
00079 
00080         nsaddr_t        rq_dst;         // Destination IP Address
00081         u_int32_t       rq_dst_seqno;   // Destination Sequence Number
00082         nsaddr_t        rq_src;         // Source IP Address
00083         u_int32_t       rq_src_seqno;   // Source Sequence Number
00084 
00085         double          rq_timestamp;   // when REQUEST sent;
00086                                         // used to compute route discovery latency
00087 
00088   // This define turns on gratuitous replies- see aodv.cc for implementation contributed by
00089   // Anant Utgikar, 09/16/02.
00090   //#define RREQ_GRAT_RREP      0x80
00091 
00092   inline int size() { 
00093   int sz = 0;
00094   /*
00095         sz = sizeof(u_int8_t)           // rq_type
00096              + 2*sizeof(u_int8_t)       // reserved
00097              + sizeof(u_int8_t)         // rq_hop_count
00098              + sizeof(double)           // rq_timestamp
00099              + sizeof(u_int32_t)        // rq_bcast_id
00100              + sizeof(nsaddr_t)         // rq_dst
00101              + sizeof(u_int32_t)        // rq_dst_seqno
00102              + sizeof(nsaddr_t)         // rq_src
00103              + sizeof(u_int32_t);       // rq_src_seqno
00104   */
00105         sz = 7*sizeof(u_int32_t);
00106         assert (sz >= 0);
00107         return sz;
00108   }
00109 };
00110 
00111 struct hdr_aodv_reply {
00112         u_int8_t        rp_type;        // Packet Type
00113         u_int8_t        reserved[2];
00114         u_int8_t        rp_hop_count;           // Hop Count
00115         nsaddr_t        rp_dst;                 // Destination IP Address
00116         u_int32_t       rp_dst_seqno;           // Destination Sequence Number
00117         nsaddr_t        rp_src;                 // Source IP Address
00118         double          rp_lifetime;            // Lifetime
00119 
00120         double          rp_timestamp;           // when corresponding REQ sent;
00121                                                 // used to compute route discovery latency
00122                                                 
00123   inline int size() { 
00124   int sz = 0;
00125   /*
00126         sz = sizeof(u_int8_t)           // rp_type
00127              + 2*sizeof(u_int8_t)       // rp_flags + reserved
00128              + sizeof(u_int8_t)         // rp_hop_count
00129              + sizeof(double)           // rp_timestamp
00130              + sizeof(nsaddr_t)         // rp_dst
00131              + sizeof(u_int32_t)        // rp_dst_seqno
00132              + sizeof(nsaddr_t)         // rp_src
00133              + sizeof(u_int32_t);       // rp_lifetime
00134   */
00135         sz = 6*sizeof(u_int32_t);
00136         assert (sz >= 0);
00137         return sz;
00138   }
00139 
00140 };
00141 
00142 struct hdr_aodv_error {
00143         u_int8_t        re_type;                // Type
00144         u_int8_t        reserved[2];            // Reserved
00145         u_int8_t        DestCount;                 // DestCount
00146         // List of Unreachable destination IP addresses and sequence numbers
00147         nsaddr_t        unreachable_dst[AODV_MAX_ERRORS];   
00148         u_int32_t       unreachable_dst_seqno[AODV_MAX_ERRORS];   
00149 
00150   inline int size() { 
00151   int sz = 0;
00152   /*
00153         sz = sizeof(u_int8_t)           // type
00154              + 2*sizeof(u_int8_t)       // reserved
00155              + sizeof(u_int8_t)         // length
00156              + length*sizeof(nsaddr_t); // unreachable destinations
00157   */
00158         sz = (DestCount*2 + 1)*sizeof(u_int32_t);
00159         assert(sz);
00160         return sz;
00161   }
00162 
00163 };
00164 
00165 struct hdr_aodv_rrep_ack {
00166         u_int8_t        rpack_type;
00167         u_int8_t        reserved;
00168 };
00169 
00170 // for size calculation of header-space reservation
00171 union hdr_all_aodv {
00172   hdr_aodv          ah;
00173   hdr_aodv_request  rreq;
00174   hdr_aodv_reply    rrep;
00175   hdr_aodv_error    rerr;
00176   hdr_aodv_rrep_ack rrep_ack;
00177 };
00178 
00179 #endif /* __aodv_packet_h__ */

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