1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
/*
* Copyright (c) 1997 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Ported from CMU/Monarch's code
*
* basic formats, constants and datatypes for TORA pkts.
*
* $Header: /cvsroot/nsnam/ns-2/tora/tora_packet.h,v 1.3 2000/09/01 03:04:12 haoboy Exp $
*/
#ifndef __tora_packet_h__
#define __tora_packet_h__
#include "config.h"
#include "packet.h"
/*
* TORA Routing Protocol Header Macros
*/
#define HDR_TORA_QRY(p) ((struct hdr_tora_qry*)hdr_tora::access(p))
#define HDR_TORA_UPD(p) ((struct hdr_tora_upd*)hdr_tora::access(p))
#define HDR_TORA_CLR(p) ((struct hdr_tora_clr*)hdr_tora::access(p))
// why do we have Height defined here? seems like there oughta be a better
// place. -dam 9/30/98
class Height {
public:
Height(int ID) : tau(-1.0), oid(-1), r(-1), delta(-1), id(ID) {}
/*
* Status Functions.
*/
inline int isZero() {
return (tau == 0.0 && oid == 0 && r == 0 && delta == 0);
}
inline int isNull() {
return (tau == -1.0 && oid == -1 && r == -1 && delta == -1);
}
inline int compare(Height *h) {
if(h->tau > tau) return 1; if(tau > h->tau) return -1;
if(h->oid > oid) return 1; if(oid > h->oid) return -1;
if(h->r > r) return 1; if(r > h->r) return -1;
if(h->delta > delta) return 1; if(delta > h->delta) return -1;
if(h->id > id) return 1; if(id > h->id) return -1;
return 0; // heights equal
}
/*
* Update Functions
*/
inline void Zero() { tau = 0.0; oid = 0; r = 0; delta = 0; }
inline void Null() { tau = -1.0; oid = -1; r = -1; delta = -1; }
void update(Height *h)
{
tau = h->tau; oid = h->oid; r = h->r;
delta = h->delta; id = h->id;
}
double tau; // Time the reference level was created
nsaddr_t oid; // id of the router that created the ref level
int r; // Flag indicating a reflected ref level
int delta; // Value used in propagation of a ref level
nsaddr_t id; // Unique id of the router
};
/* ======================================================================
Packet Formats
====================================================================== */
#define TORA_HDR_LEN 32
#define TORATYPE_QRY 0x01
#define TORATYPE_UPD 0x02
#define TORATYPE_CLR 0x04
#define QRY_HDR_LEN (IP_HDR_LEN + sizeof(struct hdr_tora_qry))
#define UPD_HDR_LEN (IP_HDR_LEN + sizeof(struct hdr_tora_upd))
#define CLR_HDR_LEN (IP_HDR_LEN + sizeof(struct hdr_tora_clr))
/*
* General TORA Header - shared by all formats
*/
struct hdr_tora {
u_int16_t th_type;
u_int16_t reserved;
nsaddr_t th_dst;
// Header access methods
static int offset_; // required by PacketHeaderManager
inline static int& offset() { return offset_; }
inline static hdr_tora* access(const Packet* p) {
return (hdr_tora*) p->access(offset_);
}
};
struct hdr_tora_qry {
u_int16_t tq_type;
u_int16_t reserved;
nsaddr_t tq_dst;
};
struct hdr_tora_upd {
u_int16_t tu_type;
u_int16_t reserved;
nsaddr_t tu_dst;
double tu_tau;
nsaddr_t tu_oid;
int tu_r;
int tu_delta;
nsaddr_t tu_id;
};
struct hdr_tora_clr {
u_int16_t tc_type;
u_int16_t reserved;
nsaddr_t tc_dst;
double tc_tau;
int tc_oid;
};
#endif /* __tora_packet_h__ */
|