00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef __tora_packet_h__
00042 #define __tora_packet_h__
00043
00044 #include "config.h"
00045 #include "packet.h"
00046
00047
00048
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
00055
00056 class Height {
00057 public:
00058 Height(int ID) : tau(-1.0), oid(-1), r(-1), delta(-1), id(ID) {}
00059
00060
00061
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;
00077 }
00078
00079
00080
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;
00093 nsaddr_t oid;
00094 int r;
00095 int delta;
00096 nsaddr_t id;
00097 };
00098
00099
00100
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
00114
00115 struct hdr_tora {
00116 u_int16_t th_type;
00117 u_int16_t reserved;
00118 nsaddr_t th_dst;
00119
00120
00121 static int offset_;
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
00156