Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

hdr_sr.h

Go to the documentation of this file.
00001 // Copyright (c) 2000 by the University of Southern California
00002 // All rights reserved.
00003 //
00004 // Permission to use, copy, modify, and distribute this software and its
00005 // documentation in source and binary forms for non-commercial purposes
00006 // and without fee is hereby granted, provided that the above copyright
00007 // notice appear in all copies and that both the copyright notice and
00008 // this permission notice appear in supporting documentation. and that
00009 // any documentation, advertising materials, and other materials related
00010 // to such distribution and use acknowledge that the software was
00011 // developed by the University of Southern California, Information
00012 // Sciences Institute.  The name of the University may not be used to
00013 // endorse or promote products derived from this software without
00014 // specific prior written permission.
00015 //
00016 // THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about
00017 // the suitability of this software for any purpose.  THIS SOFTWARE IS
00018 // PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
00019 // INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00020 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 //
00022 // Other copyrights might apply to parts of this software and are so
00023 // noted when applicable.
00024 //
00025 // Ported from CMU/Monarch's code, appropriate copyright applies.  
00026 
00027 /* -*- c++ -*-
00028    hdr_sr.h
00029 
00030    source route header
00031    
00032 */
00033 #ifndef sr_hdr_h
00034 #define sr_hdr_h
00035 
00036 #include <assert.h>
00037 
00038 #include <packet.h>
00039 
00040 #define SR_HDR_SZ 4             // size of constant part of hdr
00041 
00042 #define MAX_SR_LEN 16           // longest source route we can handle
00043 #define MAX_ROUTE_ERRORS 3      // how many route errors can fit in one pkt?
00044 
00045 struct sr_addr {
00046         int addr_type;          /* same as hdr_cmn in packet.h */
00047         nsaddr_t addr;
00048 
00049         /*
00050          * Metrics that I want to collect at each node
00051          */
00052         double  Pt_;
00053 };
00054 
00055 struct link_down {
00056         int addr_type;          /* same as hdr_cmn in packet.h */
00057         nsaddr_t tell_addr;     // tell this host
00058         nsaddr_t from_addr;     // that from_addr host can no longer
00059         nsaddr_t to_addr;       // get packets to to_addr host
00060 };
00061 
00062 
00063 /* ======================================================================
00064    DSR Packet Types
00065    ====================================================================== */
00066 struct route_request {
00067         int     req_valid_;     /* request header is valid? */
00068         int     req_id_;        /* unique request identifier */
00069         int     req_ttl_;       /* max propagation */
00070 };
00071 
00072 struct route_reply {
00073         int     rep_valid_;     /* reply header is valid? */
00074         int     rep_rtlen_;     /* # hops in route reply */
00075         struct sr_addr  rep_addrs_[MAX_SR_LEN];
00076 };
00077 
00078 struct route_error {
00079         int     err_valid_;     /* error header is valid? */
00080         int     err_count_;     /* number of route errors */
00081         struct link_down err_links_[MAX_ROUTE_ERRORS];
00082 };
00083 
00084 /* ======================================================================
00085    DSR Flow State Draft Stuff
00086    ====================================================================== */
00087 
00088 struct flow_error {
00089         nsaddr_t  flow_src;
00090         nsaddr_t  flow_dst;
00091         u_int16_t flow_id;  /* not valid w/ default flow stuff */
00092 };
00093 
00094 struct flow_header {
00095         int flow_valid_;
00096         int hopCount_;
00097         unsigned short flow_id_;
00098 };
00099 
00100 struct flow_timeout {
00101         int flow_timeout_valid_;
00102         unsigned long timeout_;  // timeout in seconds...
00103 };
00104 
00105 struct flow_unknown {
00106         int flow_unknown_valid_;
00107         int err_count_;
00108         struct flow_error err_flows_[MAX_ROUTE_ERRORS];
00109 };
00110 
00111 // default flow unknown errors
00112 struct flow_default_err {
00113         int flow_default_valid_;
00114         int err_count_;
00115         struct flow_error err_flows_[MAX_ROUTE_ERRORS];
00116 };
00117 
00118 /* ======================================================================
00119    DSR Header
00120    ====================================================================== */
00121 class hdr_sr {
00122 private:
00123         int valid_;             /* is this header actually in the packet? 
00124                                    and initialized? */
00125         int salvaged_;  /* packet has been salvaged? */
00126 
00127         int num_addrs_;
00128         int cur_addr_;
00129         struct sr_addr addrs_[MAX_SR_LEN];
00130 
00131         struct route_request    sr_request_;
00132         struct route_reply      sr_reply_;
00133         struct route_error      sr_error_;
00134 
00135         struct flow_header      sr_flow_;
00136         struct flow_timeout     sr_ftime_;
00137         struct flow_unknown     sr_funk_;
00138         struct flow_default_err sr_fdef_unk;
00139 
00140 public:
00141         static int offset_;             /* offset for this header */
00142         inline int& offset() { return offset_; }
00143         inline static hdr_sr* access(const Packet* p) {
00144                 return (hdr_sr*)p->access(offset_);
00145         }
00146         inline int& valid() { return valid_; }
00147         inline int& salvaged() { return salvaged_; }
00148         inline int& num_addrs() { return num_addrs_; }
00149         inline int& cur_addr() { return cur_addr_; }
00150 
00151         inline int valid() const { return valid_; }
00152         inline int salvaged() const { return salvaged_; }
00153         inline int num_addrs() const { return num_addrs_; }
00154         inline int cur_addr() const { return cur_addr_; }
00155         inline struct sr_addr* addrs() { return addrs_; }
00156 
00157         inline int& route_request() {return sr_request_.req_valid_; }
00158         inline int& rtreq_seq() {return sr_request_.req_id_; }
00159         inline int& max_propagation() {return sr_request_.req_ttl_; }
00160 
00161         inline int& route_reply() {return sr_reply_.rep_valid_; }
00162         inline int& route_reply_len() {return sr_reply_.rep_rtlen_; }
00163         inline struct sr_addr* reply_addrs() {return sr_reply_.rep_addrs_; }
00164 
00165         inline int& route_error() {return sr_error_.err_valid_; }
00166         inline int& num_route_errors() {return sr_error_.err_count_; }
00167         inline struct link_down* down_links() {return sr_error_.err_links_; }
00168 
00169         // Flow state stuff, ych 5/2/01
00170         inline int &flow_header() { return sr_flow_.flow_valid_; }
00171         inline u_int16_t &flow_id() { return sr_flow_.flow_id_; }
00172         inline int &hopCount() { return sr_flow_.hopCount_; }
00173 
00174         inline int &flow_timeout() { return sr_ftime_.flow_timeout_valid_; }
00175         inline unsigned long &flow_timeout_time() { return sr_ftime_.timeout_; }
00176 
00177         inline int &flow_unknown() { return sr_funk_.flow_unknown_valid_; }
00178         inline int &num_flow_unknown() { return sr_funk_.err_count_; }
00179         inline struct flow_error *unknown_flows() { return sr_funk_.err_flows_; }
00180 
00181         inline int &flow_default_unknown() { return sr_fdef_unk.flow_default_valid_; }
00182         inline int &num_default_unknown() { return sr_fdef_unk.err_count_; }
00183         inline struct flow_error *unknown_defaults() { return sr_fdef_unk.err_flows_; }
00184 
00185         inline int size() {
00186                 int sz = 0;
00187                 if (num_addrs_ || route_request() || 
00188                     route_reply() || route_error() ||
00189                     flow_timeout() || flow_unknown() || flow_default_unknown())
00190                         sz += SR_HDR_SZ;
00191 
00192                 if (num_addrs_)                 sz += 4 * (num_addrs_ - 1);
00193                 if (route_reply())              sz += 5 + 4 * route_reply_len();
00194                 if (route_request())            sz += 8;
00195                 if (route_error())              sz += 16 * num_route_errors();
00196                 if (flow_timeout())             sz += 4;
00197                 if (flow_unknown())             sz += 14 * num_flow_unknown();
00198                 if (flow_default_unknown())     sz += 12 * num_default_unknown();
00199 
00200                 if (flow_header())              sz += 4;
00201 
00202                 sz = ((sz+3)&(~3)); // align...
00203                 assert(sz >= 0);
00204 #if 0
00205                 printf("Size: %d (%d %d %d %d %d %d %d %d %d)\n", sz,
00206                         (num_addrs_ || route_request() ||
00207                         route_reply() || route_error() ||
00208                         flow_timeout() || flow_unknown() || 
00209                         flow_default_unknown()) ? SR_HDR_SZ : 0,
00210                         num_addrs_ ? 4 * (num_addrs_ - 1) : 0,
00211                         route_reply() ? 5 + 4 * route_reply_len() : 0,
00212                         route_request() ? 8 : 0,
00213                         route_error() ? 16 * num_route_errors() : 0,
00214                         flow_timeout() ? 4 : 0,
00215                         flow_unknown() ? 14 * num_flow_unknown() : 0,
00216                         flow_default_unknown() ? 12 * num_default_unknown() : 0,
00217                         flow_header() ? 4 : 0);
00218 #endif
00219 
00220                 return sz;
00221         }
00222 
00223         // End Flow State stuff
00224 
00225         inline nsaddr_t& get_next_addr() { 
00226                 assert(cur_addr_ < num_addrs_);
00227                 return (addrs_[cur_addr_ + 1].addr);
00228         }
00229 
00230         inline int& get_next_type() {
00231                 assert(cur_addr_ < num_addrs_);
00232                 return (addrs_[cur_addr_ + 1].addr_type);
00233         }
00234 
00235         inline void append_addr(nsaddr_t a, int type) {
00236                 assert(num_addrs_ < MAX_SR_LEN-1);
00237                 addrs_[num_addrs_].addr_type = type;
00238                 addrs_[num_addrs_++].addr = a;
00239         }
00240 
00241         inline void init() {
00242                 valid_ = 1;
00243                 salvaged_ = 0;
00244                 num_addrs_ = 0;
00245                 cur_addr_ = 0;
00246 
00247                 route_request() = 0;
00248                 route_reply() = 0;
00249                 route_reply_len() = 0;
00250                 route_error() = 0;
00251                 num_route_errors() = 0;
00252 
00253                 flow_timeout() = 0;
00254                 flow_unknown() = 0;
00255                 flow_default_unknown() = 0;
00256                 flow_header() = 0;
00257         }
00258 
00259 #if 0
00260 #ifdef DSR_CONST_HDR_SZ
00261   /* used to estimate the potential benefit of removing the 
00262      src route in every packet */
00263         inline int size() { 
00264                 return SR_HDR_SZ;
00265         }
00266 #else
00267         inline int size() { 
00268                 int sz = SR_HDR_SZ +
00269                         4 * (num_addrs_ - 1) +
00270                         4 * (route_reply() ? route_reply_len() : 0) +
00271                         8 * (route_error() ? num_route_errors() : 0);
00272                 assert(sz >= 0);
00273                 return sz;
00274         }
00275 #endif // DSR_CONST_HDR_SZ
00276 #endif // 0
00277 
00278   void dump(char *);
00279   char* dump();
00280 };
00281 
00282 
00283 #endif // sr_hdr_h

Generated on Tue Apr 20 12:14:19 2004 for NS2.26SourcesOriginal by doxygen 1.3.3