00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * Copyright (c) 1997 Regents of the University of California. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 3. All advertising materials mentioning features or use of this software 00015 * must display the following acknowledgement: 00016 * This product includes software developed by the Computer Systems 00017 * Engineering Group at Lawrence Berkeley Laboratory. 00018 * 4. Neither the name of the University nor of the Laboratory may be used 00019 * to endorse or promote products derived from this software without 00020 * specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00025 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00028 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00029 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00031 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00032 * SUCH DAMAGE. 00033 * 00034 * Ported from CMU/Monarch's code 00035 * 00036 * $Header: /cvsroot/nsnam/ns-2/imep/imep_spec.h,v 1.4 2006/02/21 15:20:18 mahrenho Exp $ 00037 */ 00038 00039 #ifndef __imep_spec_h__ 00040 #define __imep_spec_h__ 00041 00042 #include <sys/types.h> 00043 00044 #include <stddef.h> // for the offsetof() macro 00045 00046 00047 // ********************************************************************** 00048 #ifdef COMMENT_ONLY 00049 00050 The Internet MANET Encapsulation Protocol (IMEP) consists of five 00051 different mechanisms: 00052 Link/Connection Status Sensing 00053 Control Message Aggregation 00054 Broadcast Reliability 00055 Network-layer Address Resolution 00056 Security Authentication 00057 00058 04AUG98 - jgb - For now, I am going to implement the first three mechanisms 00059 as the last two are not really necessary for the present 00060 simulation work. 00061 00062 #endif /* COMMENT_ONLY */ 00063 00064 00065 // ********************************************************************** 00066 // Link/Connection Status Sensing 00067 00068 00069 // IMEP may be configured to run in the following "connection 00070 // notification" modes. 00071 #define MODE_BIDIRECTIONAL 0x01 00072 #define MODE_UNIDIRECTIONAL 0x02 00073 00074 // Link status 00075 #define LINK_DOWN 0x00 00076 #define LINK_IN 0x01 00077 #define LINK_OUT 0x02 00078 #define LINK_BI (LINK_IN | LINK_OUT) 00079 00080 // XXX - The values for these constants are not specified by the IMEP draft. 00081 #define BEACON_PERIOD 1.0 // seconds 00082 #define BEACON_JITTER 0.010 // seconds 00083 #define MAX_BEACON_TIME (BEACON_PERIOD * 3) 00084 00085 // ********************************************************************** 00086 // Control Message Aggregation 00087 00088 // XXX - The values for these constants are not specified by the IMEP draft. 00089 #define MAX_TRANSMIT_WAIT_TIME_LOWP 0.250 // seconds 00090 #define MIN_TRANSMIT_WAIT_TIME_LOWP 0.150 00091 #define MAX_TRANSMIT_WAIT_TIME_HIGHP 0.010 // seconds 00092 #define MIN_TRANSMIT_WAIT_TIME_HIGHP 0.000 00093 00094 // ********************************************************************** 00095 // Broadcast Reliability 00096 #define RETRANS_PERIOD 0.500 // seconds 00097 #define MAX_REXMITS 2 00098 #define MAX_RETRANS_TIME (RETRANS_PERIOD * (MAX_REXMITS + 1)) 00099 00100 00101 // ********************************************************************** 00102 // Protocol Message Format 00103 00104 struct hdr_imep { 00105 u_int8_t imep_version : 4; 00106 u_int8_t imep_block_flags : 4; 00107 u_int16_t imep_length; 00108 00109 // Header access methods 00110 static int offset_; // required by PacketHeaderManager 00111 inline static int& offset() { return offset_; } 00112 inline static hdr_imep* access(const Packet* p) { 00113 return (hdr_imep*) p->access(offset_); 00114 } 00115 }; 00116 00117 /* hdr_imep actually takes 4 bytes, not 3, b/c we aren't packing the 00118 two bitfields into 1 byte */ 00119 00120 #define IMEP_VERSION_0 0x00 00121 #define IMEP_VERSION IMEP_VERSION_0 00122 #define BLOCK_FLAG_ACK 0x08 00123 #define BLOCK_FLAG_HELLO 0x04 00124 #define BLOCK_FLAG_OBJECT 0x02 00125 #define BLOCK_FLAG_UNUSED 0x01 00126 00127 /* I'd rather not deal with alignment issues in this code, so I've 00128 just padded out the IMEP structs to be word aligned. The sizes of 00129 packets will be slightly inflated, but the packet formats in the IMEP 00130 draft are really odd --- I can't imagine anyone actually implementing them, 00131 and they'd need to be padded out or redone in real life. -dam */ 00132 00133 struct imep_ack { 00134 u_int8_t ack_seqno; 00135 u_int8_t r1; 00136 u_int16_t r2; 00137 u_int32_t ack_ipaddr; 00138 }; 00139 00140 struct imep_ack_block { 00141 u_int8_t ab_num_acks; 00142 u_int8_t r1; 00143 u_int16_t r2; 00144 char ab_ack_list[1]; // placeholder 00145 }; 00146 00147 struct imep_hello { 00148 u_int32_t hello_ipaddr; 00149 }; 00150 00151 struct imep_hello_block { 00152 u_int8_t hb_num_hellos; 00153 u_int8_t r1; 00154 u_int16_t r2; 00155 char hb_hello_list[1]; // placeholder 00156 }; 00157 00158 struct imep_object { 00159 u_int16_t o_length; 00160 // The IMEP spec uses the first bit to determine if this field 00161 // is 8 or 16 bits. I fix its length at 16 bits to keep 00162 // things simple. 00163 char o_data[1]; // placeholder 00164 }; 00165 00166 /* define the size of the an imep_object without the following bytes of o_data, 00167 Use this instead of sizeof(struct imep_object) 00168 */ 00169 #define IMEP_OBJECT_SIZE offsetof(struct imep_object, o_data[0]) 00170 00171 struct imep_object_block { 00172 u_int8_t ob_sequence; 00173 u_int8_t ob_protocol_type : 4; 00174 u_int8_t ob_num_objects : 7; 00175 u_int8_t ob_num_responses : 5; 00176 char ob_object_list[1]; // placeholder 00177 }; 00178 /* Use this instead of sizeof(struct imep_object_block) */ 00179 #define IMEP_OBJECT_BLOCK_SIZE offsetof(struct imep_object_block, ob_object_list[0]) 00180 00181 00182 #define PROTO_RESERVED 0x00 00183 #define PROTO_NARP 0x01 00184 #define PROTO_RNARP 0x01 00185 #define PROTO_TORA 0x02 00186 00187 // The "response list" follows the "object list" in an IMEP packet. 00188 struct imep_response { 00189 u_int32_t resp_ipaddr; 00190 }; 00191 00192 #endif /* __imep_spec_h__ */