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 * basic formats, constants and datatypes for TORA pkts. 00037 * 00038 * $Header: /nfs/jade/vint/CVSROOT/ns-2/tora/tora_packet.h,v 1.3 2000/09/01 03:04:12 haoboy Exp $ 00039 */ 00040 00041 #ifndef __tora_packet_h__ 00042 #define __tora_packet_h__ 00043 00044 #include "config.h" 00045 #include "packet.h" 00046 00047 /* 00048 * TORA Routing Protocol Header Macros 00049 */ 00050 #define HDR_TORA_QRY(p) ((struct hdr_tora_qry*)hdr_tora::access(p)) 00051 #define HDR_TORA_UPD(p) ((struct hdr_tora_upd*)hdr_tora::access(p)) 00052 #define HDR_TORA_CLR(p) ((struct hdr_tora_clr*)hdr_tora::access(p)) 00053 00054 // why do we have Height defined here? seems like there oughta be a better 00055 // place. -dam 9/30/98 00056 class Height { 00057 public: 00058 Height(int ID) : tau(-1.0), oid(-1), r(-1), delta(-1), id(ID) {} 00059 00060 /* 00061 * Status Functions. 00062 */ 00063 inline int isZero() { 00064 return (tau == 0.0 && oid == 0 && r == 0 && delta == 0); 00065 } 00066 inline int isNull() { 00067 return (tau == -1.0 && oid == -1 && r == -1 && delta == -1); 00068 } 00069 inline int compare(Height *h) { 00070 if(h->tau > tau) return 1; if(tau > h->tau) return -1; 00071 if(h->oid > oid) return 1; if(oid > h->oid) return -1; 00072 if(h->r > r) return 1; if(r > h->r) return -1; 00073 if(h->delta > delta) return 1; if(delta > h->delta) return -1; 00074 if(h->id > id) return 1; if(id > h->id) return -1; 00075 00076 return 0; // heights equal 00077 } 00078 00079 /* 00080 * Update Functions 00081 */ 00082 inline void Zero() { tau = 0.0; oid = 0; r = 0; delta = 0; } 00083 00084 inline void Null() { tau = -1.0; oid = -1; r = -1; delta = -1; } 00085 00086 void update(Height *h) 00087 { 00088 tau = h->tau; oid = h->oid; r = h->r; 00089 delta = h->delta; id = h->id; 00090 } 00091 00092 double tau; // Time the reference level was created 00093 nsaddr_t oid; // id of the router that created the ref level 00094 int r; // Flag indicating a reflected ref level 00095 int delta; // Value used in propagation of a ref level 00096 nsaddr_t id; // Unique id of the router 00097 }; 00098 00099 /* ====================================================================== 00100 Packet Formats 00101 ====================================================================== */ 00102 #define TORA_HDR_LEN 32 00103 00104 #define TORATYPE_QRY 0x01 00105 #define TORATYPE_UPD 0x02 00106 #define TORATYPE_CLR 0x04 00107 00108 #define QRY_HDR_LEN (IP_HDR_LEN + sizeof(struct hdr_tora_qry)) 00109 #define UPD_HDR_LEN (IP_HDR_LEN + sizeof(struct hdr_tora_upd)) 00110 #define CLR_HDR_LEN (IP_HDR_LEN + sizeof(struct hdr_tora_clr)) 00111 00112 /* 00113 * General TORA Header - shared by all formats 00114 */ 00115 struct hdr_tora { 00116 u_int16_t th_type; 00117 u_int16_t reserved; 00118 nsaddr_t th_dst; 00119 00120 // Header access methods 00121 static int offset_; // required by PacketHeaderManager 00122 inline static int& offset() { return offset_; } 00123 inline static hdr_tora* access(const Packet* p) { 00124 return (hdr_tora*) p->access(offset_); 00125 } 00126 }; 00127 00128 struct hdr_tora_qry { 00129 u_int16_t tq_type; 00130 u_int16_t reserved; 00131 nsaddr_t tq_dst; 00132 }; 00133 00134 struct hdr_tora_upd { 00135 u_int16_t tu_type; 00136 u_int16_t reserved; 00137 nsaddr_t tu_dst; 00138 00139 double tu_tau; 00140 nsaddr_t tu_oid; 00141 int tu_r; 00142 int tu_delta; 00143 nsaddr_t tu_id; 00144 }; 00145 00146 struct hdr_tora_clr { 00147 u_int16_t tc_type; 00148 u_int16_t reserved; 00149 nsaddr_t tc_dst; 00150 00151 double tc_tau; 00152 int tc_oid; 00153 }; 00154 00155 #endif /* __tora_packet_h__ */ 00156
1.4.6