00001 /* 00002 Copyright (c) 1997, 1998 Carnegie Mellon University. All Rights 00003 Reserved. 00004 00005 Permission to use, copy, modify, and distribute this 00006 software and its documentation is hereby granted (including for 00007 commercial or for-profit use), provided that both the copyright notice and this permission notice appear in all copies of the software, derivative works, or modified versions, and any portions thereof, and that both notices appear in supporting documentation, and that credit is given to Carnegie Mellon University in all publications reporting on direct or indirect use of this code or its derivatives. 00008 00009 ALL CODE, SOFTWARE, PROTOCOLS, AND ARCHITECTURES DEVELOPED BY THE CMU 00010 MONARCH PROJECT ARE EXPERIMENTAL AND ARE KNOWN TO HAVE BUGS, SOME OF 00011 WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS 00012 SOFTWARE OR OTHER INTELLECTUAL PROPERTY IN ITS ``AS IS'' CONDITION, 00013 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 00014 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00015 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 00016 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00017 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00018 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 00019 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00020 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00021 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE OR 00022 INTELLECTUAL PROPERTY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00023 DAMAGE. 00024 00025 Carnegie Mellon encourages (but does not require) users of this 00026 software or intellectual property to return any improvements or 00027 extensions that they make, and to grant Carnegie Mellon the rights to redistribute these changes without encumbrance. 00028 00029 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. 00030 */ 00031 00032 00033 #ifndef __aodv_packet_h__ 00034 #define __aodv_packet_h__ 00035 00036 //#include <config.h> 00037 //#include "aodv.h" 00038 #define AODV_MAX_ERRORS 100 00039 00040 00041 /* ===================================================================== 00042 Packet Formats... 00043 ===================================================================== */ 00044 #define AODVTYPE_HELLO 0x01 00045 #define AODVTYPE_RREQ 0x02 00046 #define AODVTYPE_RREP 0x04 00047 #define AODVTYPE_RERR 0x08 00048 #define AODVTYPE_RREP_ACK 0x10 00049 00050 /* 00051 * AODV Routing Protocol Header Macros 00052 */ 00053 #define HDR_AODV(p) ((struct hdr_aodv*)hdr_aodv::access(p)) 00054 #define HDR_AODV_REQUEST(p) ((struct hdr_aodv_request*)hdr_aodv::access(p)) 00055 #define HDR_AODV_REPLY(p) ((struct hdr_aodv_reply*)hdr_aodv::access(p)) 00056 #define HDR_AODV_ERROR(p) ((struct hdr_aodv_error*)hdr_aodv::access(p)) 00057 #define HDR_AODV_RREP_ACK(p) ((struct hdr_aodv_rrep_ack*)hdr_aodv::access(p)) 00058 00059 /* 00060 * General AODV Header - shared by all formats 00061 */ 00062 struct hdr_aodv { 00063 u_int8_t ah_type; 00064 /* 00065 u_int8_t ah_reserved[2]; 00066 u_int8_t ah_hopcount; 00067 */ 00068 // Header access methods 00069 static int offset_; // required by PacketHeaderManager 00070 inline static int& offset() { return offset_; } 00071 inline static hdr_aodv* access(const Packet* p) { 00072 return (hdr_aodv*) p->access(offset_); 00073 } 00074 }; 00075 00076 struct hdr_aodv_request { 00077 u_int8_t rq_type; // Packet Type 00078 u_int8_t reserved[2]; 00079 u_int8_t rq_hop_count; // Hop Count 00080 u_int32_t rq_bcast_id; // Broadcast ID 00081 00082 nsaddr_t rq_dst; // Destination IP Address 00083 u_int32_t rq_dst_seqno; // Destination Sequence Number 00084 nsaddr_t rq_src; // Source IP Address 00085 u_int32_t rq_src_seqno; // Source Sequence Number 00086 00087 double rq_timestamp; // when REQUEST sent; 00088 // used to compute route discovery latency 00089 00090 // This define turns on gratuitous replies- see aodv.cc for implementation contributed by 00091 // Anant Utgikar, 09/16/02. 00092 //#define RREQ_GRAT_RREP 0x80 00093 00094 inline int size() { 00095 int sz = 0; 00096 /* 00097 sz = sizeof(u_int8_t) // rq_type 00098 + 2*sizeof(u_int8_t) // reserved 00099 + sizeof(u_int8_t) // rq_hop_count 00100 + sizeof(double) // rq_timestamp 00101 + sizeof(u_int32_t) // rq_bcast_id 00102 + sizeof(nsaddr_t) // rq_dst 00103 + sizeof(u_int32_t) // rq_dst_seqno 00104 + sizeof(nsaddr_t) // rq_src 00105 + sizeof(u_int32_t); // rq_src_seqno 00106 */ 00107 sz = 7*sizeof(u_int32_t); 00108 assert (sz >= 0); 00109 return sz; 00110 } 00111 }; 00112 00113 struct hdr_aodv_reply { 00114 u_int8_t rp_type; // Packet Type 00115 u_int8_t reserved[2]; 00116 u_int8_t rp_hop_count; // Hop Count 00117 nsaddr_t rp_dst; // Destination IP Address 00118 u_int32_t rp_dst_seqno; // Destination Sequence Number 00119 nsaddr_t rp_src; // Source IP Address 00120 double rp_lifetime; // Lifetime 00121 00122 double rp_timestamp; // when corresponding REQ sent; 00123 // used to compute route discovery latency 00124 00125 inline int size() { 00126 int sz = 0; 00127 /* 00128 sz = sizeof(u_int8_t) // rp_type 00129 + 2*sizeof(u_int8_t) // rp_flags + reserved 00130 + sizeof(u_int8_t) // rp_hop_count 00131 + sizeof(double) // rp_timestamp 00132 + sizeof(nsaddr_t) // rp_dst 00133 + sizeof(u_int32_t) // rp_dst_seqno 00134 + sizeof(nsaddr_t) // rp_src 00135 + sizeof(u_int32_t); // rp_lifetime 00136 */ 00137 sz = 6*sizeof(u_int32_t); 00138 assert (sz >= 0); 00139 return sz; 00140 } 00141 00142 }; 00143 00144 struct hdr_aodv_error { 00145 u_int8_t re_type; // Type 00146 u_int8_t reserved[2]; // Reserved 00147 u_int8_t DestCount; // DestCount 00148 // List of Unreachable destination IP addresses and sequence numbers 00149 nsaddr_t unreachable_dst[AODV_MAX_ERRORS]; 00150 u_int32_t unreachable_dst_seqno[AODV_MAX_ERRORS]; 00151 00152 inline int size() { 00153 int sz = 0; 00154 /* 00155 sz = sizeof(u_int8_t) // type 00156 + 2*sizeof(u_int8_t) // reserved 00157 + sizeof(u_int8_t) // length 00158 + length*sizeof(nsaddr_t); // unreachable destinations 00159 */ 00160 sz = (DestCount*2 + 1)*sizeof(u_int32_t); 00161 assert(sz); 00162 return sz; 00163 } 00164 00165 }; 00166 00167 struct hdr_aodv_rrep_ack { 00168 u_int8_t rpack_type; 00169 u_int8_t reserved; 00170 }; 00171 00172 // for size calculation of header-space reservation 00173 union hdr_all_aodv { 00174 hdr_aodv ah; 00175 hdr_aodv_request rreq; 00176 hdr_aodv_reply rrep; 00177 hdr_aodv_error rerr; 00178 hdr_aodv_rrep_ack rrep_ack; 00179 }; 00180 00181 #endif /* __aodv_packet_h__ */
1.3.3